mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-07-25 23:45:49 -04:00
added selection of thumbnail aspect ratio
This commit is contained in:
parent
80875dddd7
commit
bebc9f2863
5 changed files with 168 additions and 48 deletions
|
@ -78,10 +78,11 @@ CreateGxsChannelMsg::CreateGxsChannelMsg(const RsGxsGroupId &cId, RsGxsMessageId
|
||||||
connect(thumbNailCb, SIGNAL(toggled(bool)), this, SLOT(allowAutoMediaThumbNail(bool)));
|
connect(thumbNailCb, SIGNAL(toggled(bool)), this, SLOT(allowAutoMediaThumbNail(bool)));
|
||||||
connect(stackedWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenu(QPoint)));
|
connect(stackedWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenu(QPoint)));
|
||||||
connect(generateCheckBox, SIGNAL(toggled(bool)), generateSpinBox, SLOT(setEnabled(bool)));
|
connect(generateCheckBox, SIGNAL(toggled(bool)), generateSpinBox, SLOT(setEnabled(bool)));
|
||||||
|
connect(aspectRatio_CB,SIGNAL(currentIndexChanged(int)),this,SLOT(changeAspectRatio(int)));
|
||||||
|
|
||||||
generateSpinBox->setEnabled(false);
|
generateSpinBox->setEnabled(false);
|
||||||
|
|
||||||
preview_W->setPixmap(FilesDefs::getPixmapFromQtResourcePath(ChannelPostThumbnailView::CHAN_DEFAULT_IMAGE));
|
preview_W->setPixmap(FilesDefs::getPixmapFromQtResourcePath(ChannelPostThumbnailView::CHAN_DEFAULT_IMAGE),true);
|
||||||
preview_W->setText("[Text preview]");
|
preview_W->setText("[Text preview]");
|
||||||
|
|
||||||
thumbNailCb->setVisible(false);
|
thumbNailCb->setVisible(false);
|
||||||
|
@ -110,6 +111,19 @@ CreateGxsChannelMsg::~CreateGxsChannelMsg()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CreateGxsChannelMsg::changeAspectRatio(int s)
|
||||||
|
{
|
||||||
|
switch(s)
|
||||||
|
{
|
||||||
|
case 0: break;
|
||||||
|
case 1: preview_W->setAspectRatio(ChannelPostThumbnailView::ASPECT_RATIO_1_1);
|
||||||
|
break;
|
||||||
|
case 2: preview_W->setAspectRatio(ChannelPostThumbnailView::ASPECT_RATIO_2_3);
|
||||||
|
break;
|
||||||
|
case 3: preview_W->setAspectRatio(ChannelPostThumbnailView::ASPECT_RATIO_16_9);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
void CreateGxsChannelMsg::contextMenu(QPoint /*point*/)
|
void CreateGxsChannelMsg::contextMenu(QPoint /*point*/)
|
||||||
{
|
{
|
||||||
QList<RetroShareLink> links ;
|
QList<RetroShareLink> links ;
|
||||||
|
@ -734,7 +748,8 @@ void CreateGxsChannelMsg::addThumbnail()
|
||||||
picture = img;
|
picture = img;
|
||||||
|
|
||||||
// to show the selected
|
// to show the selected
|
||||||
preview_W->setPixmap(picture);
|
preview_W->setPixmap(picture, aspectRatio_CB->currentIndex()==0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreateGxsChannelMsg::loadOriginalChannelPostInfo()
|
void CreateGxsChannelMsg::loadOriginalChannelPostInfo()
|
||||||
|
@ -778,7 +793,7 @@ void CreateGxsChannelMsg::loadOriginalChannelPostInfo()
|
||||||
if(post.mThumbnail.mData != NULL)
|
if(post.mThumbnail.mData != NULL)
|
||||||
{
|
{
|
||||||
GxsIdDetails::loadPixmapFromData(post.mThumbnail.mData,post.mThumbnail.mSize,picture,GxsIdDetails::ORIGINAL);
|
GxsIdDetails::loadPixmapFromData(post.mThumbnail.mData,post.mThumbnail.mSize,picture,GxsIdDetails::ORIGINAL);
|
||||||
preview_W->setPixmap(picture);
|
preview_W->setPixmap(picture,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -64,6 +64,7 @@ private slots:
|
||||||
void sendMsg();
|
void sendMsg();
|
||||||
void pasteLink() ;
|
void pasteLink() ;
|
||||||
void contextMenu(QPoint) ;
|
void contextMenu(QPoint) ;
|
||||||
|
void changeAspectRatio(int s);
|
||||||
|
|
||||||
void addThumbnail();
|
void addThumbnail();
|
||||||
void allowAutoMediaThumbNail(bool);
|
void allowAutoMediaThumbNail(bool);
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>736</width>
|
<width>881</width>
|
||||||
<height>271</height>
|
<height>383</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="acceptDrops">
|
<property name="acceptDrops">
|
||||||
|
@ -79,33 +79,29 @@
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="stackedWidgetPage1">
|
<widget class="QWidget" name="stackedWidgetPage1">
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||||
<property name="spacing">
|
|
||||||
<number>6</number>
|
|
||||||
</property>
|
|
||||||
<property name="leftMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="topMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="rightMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="bottomMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
<property name="spacing">
|
<item>
|
||||||
<number>6</number>
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
</property>
|
|
||||||
<property name="sizeConstraint">
|
|
||||||
<enum>QLayout::SetFixedSize</enum>
|
|
||||||
</property>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="ChannelPostThumbnailView" name="preview_W" native="true"/>
|
<widget class="ChannelPostThumbnailView" name="preview_W" native="true"/>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="verticalSpacer_2">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<property name="spacing">
|
<property name="spacing">
|
||||||
|
@ -179,6 +175,30 @@ p, li { white-space: pre-wrap; }
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="aspectRatio_CB">
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Auto</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>1:1</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>3:4</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>16:9</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="addfilepushButton">
|
<widget class="QPushButton" name="addfilepushButton">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
@ -309,7 +329,7 @@ p, li { white-space: pre-wrap; }
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>81</width>
|
<width>84</width>
|
||||||
<height>24</height>
|
<height>24</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
#include "gui/gxschannels/GxsChannelPostThumbnail.h"
|
#include "gui/gxschannels/GxsChannelPostThumbnail.h"
|
||||||
|
|
||||||
ChannelPostThumbnailView::ChannelPostThumbnailView(const RsGxsChannelPost& post,uint32_t flags,QWidget *parent)
|
ChannelPostThumbnailView::ChannelPostThumbnailView(const RsGxsChannelPost& post,uint32_t flags,QWidget *parent)
|
||||||
: QWidget(parent),mFlags(flags),mPostTitle(nullptr)
|
: QWidget(parent),mPostTitle(nullptr),mFlags(flags), mAspectRatio(ASPECT_RATIO_2_3)
|
||||||
{
|
{
|
||||||
// now fill the data
|
// now fill the data
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ ChannelPostThumbnailView::ChannelPostThumbnailView(const RsGxsChannelPost& post,
|
||||||
}
|
}
|
||||||
|
|
||||||
ChannelPostThumbnailView::ChannelPostThumbnailView(QWidget *parent,uint32_t flags)
|
ChannelPostThumbnailView::ChannelPostThumbnailView(QWidget *parent,uint32_t flags)
|
||||||
: QWidget(parent),mFlags(flags)
|
: QWidget(parent),mFlags(flags), mAspectRatio(ASPECT_RATIO_2_3)
|
||||||
{
|
{
|
||||||
init(RsGxsChannelPost());
|
init(RsGxsChannelPost());
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,54 @@ ChannelPostThumbnailView::~ChannelPostThumbnailView()
|
||||||
delete mPostImage;
|
delete mPostImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChannelPostThumbnailView::setText(const QString& s)
|
||||||
|
{
|
||||||
|
if(mPostTitle == NULL)
|
||||||
|
{
|
||||||
|
std::cerr << "(EE) calling setText on a ChannelPostThumbnailView without SHOW_TEXT flag!"<< std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ss;
|
||||||
|
if(s.length() > 30)
|
||||||
|
ss = s.left(30)+"...";
|
||||||
|
else
|
||||||
|
ss =s;
|
||||||
|
|
||||||
|
mPostTitle->setText(ss);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChannelPostThumbnailView::setPixmap(const QPixmap& p, bool guess_aspect_ratio)
|
||||||
|
{
|
||||||
|
mPostImage->setPicture(p);
|
||||||
|
|
||||||
|
if(guess_aspect_ratio)// aspect ratio is automatically guessed.
|
||||||
|
{
|
||||||
|
// compute closest aspect ratio
|
||||||
|
float r = p.width()/(float)p.height();
|
||||||
|
|
||||||
|
if(r < 0.8)
|
||||||
|
setAspectRatio(ChannelPostThumbnailView::ASPECT_RATIO_2_3);
|
||||||
|
else if(r < 1.15)
|
||||||
|
setAspectRatio(ChannelPostThumbnailView::ASPECT_RATIO_1_1);
|
||||||
|
else
|
||||||
|
setAspectRatio(ChannelPostThumbnailView::ASPECT_RATIO_16_9);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChannelPostThumbnailView::setAspectRatio(AspectRatio r)
|
||||||
|
{
|
||||||
|
mAspectRatio = r;
|
||||||
|
|
||||||
|
QFontMetricsF fm(font());
|
||||||
|
int W = THUMBNAIL_OVERSAMPLE_FACTOR * thumbnail_w() * fm.height() ;
|
||||||
|
int H = THUMBNAIL_OVERSAMPLE_FACTOR * thumbnail_h() * fm.height() ;
|
||||||
|
|
||||||
|
mPostImage->setFixedSize(W,H);
|
||||||
|
mPostImage->reset();
|
||||||
|
mPostImage->updateView();
|
||||||
|
}
|
||||||
|
|
||||||
void ChannelPostThumbnailView::init(const RsGxsChannelPost& post)
|
void ChannelPostThumbnailView::init(const RsGxsChannelPost& post)
|
||||||
{
|
{
|
||||||
QString msg = QString::fromUtf8(post.mMeta.mMsgName.c_str());
|
QString msg = QString::fromUtf8(post.mMeta.mMsgName.c_str());
|
||||||
|
@ -70,8 +118,8 @@ void ChannelPostThumbnailView::init(const RsGxsChannelPost& post)
|
||||||
setSizePolicy(QSizePolicy::Maximum,QSizePolicy::Maximum);
|
setSizePolicy(QSizePolicy::Maximum,QSizePolicy::Maximum);
|
||||||
|
|
||||||
QFontMetricsF fm(font());
|
QFontMetricsF fm(font());
|
||||||
int W = THUMBNAIL_OVERSAMPLE_FACTOR * THUMBNAIL_W * fm.height() ;
|
int W = THUMBNAIL_OVERSAMPLE_FACTOR * thumbnail_w() * fm.height() ;
|
||||||
int H = THUMBNAIL_OVERSAMPLE_FACTOR * THUMBNAIL_H * fm.height() ;
|
int H = THUMBNAIL_OVERSAMPLE_FACTOR * thumbnail_h() * fm.height() ;
|
||||||
|
|
||||||
mPostImage->setFixedSize(W,H);
|
mPostImage->setFixedSize(W,H);
|
||||||
|
|
||||||
|
@ -101,6 +149,39 @@ void ChannelPostThumbnailView::init(const RsGxsChannelPost& post)
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float ChannelPostThumbnailView::thumbnail_w() const
|
||||||
|
{
|
||||||
|
switch(mAspectRatio)
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
case ASPECT_RATIO_1_1:
|
||||||
|
case ASPECT_RATIO_UNKNOWN: return 5;
|
||||||
|
|
||||||
|
case ASPECT_RATIO_2_3: return 4;
|
||||||
|
case ASPECT_RATIO_16_9: return 5 * 16.0/9.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
float ChannelPostThumbnailView::thumbnail_h() const
|
||||||
|
{
|
||||||
|
switch(mAspectRatio)
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
case ASPECT_RATIO_1_1:
|
||||||
|
case ASPECT_RATIO_UNKNOWN: return 5;
|
||||||
|
|
||||||
|
case ASPECT_RATIO_2_3: return 6;
|
||||||
|
case ASPECT_RATIO_16_9: return 5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZoomableLabel::reset()
|
||||||
|
{
|
||||||
|
mCenterX = mFullImage.width()/2.0;
|
||||||
|
mCenterX = mFullImage.height()/2.0;
|
||||||
|
mZoomFactor = 1.0/std::max(width() / (float)mFullImage.width(), height()/(float)mFullImage.height());
|
||||||
|
|
||||||
|
updateView();
|
||||||
|
}
|
||||||
void ZoomableLabel::mouseMoveEvent(QMouseEvent *me)
|
void ZoomableLabel::mouseMoveEvent(QMouseEvent *me)
|
||||||
{
|
{
|
||||||
if(!mZoomEnabled)
|
if(!mZoomEnabled)
|
||||||
|
@ -204,3 +285,5 @@ void ZoomableLabel::updateView()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,9 @@ public:
|
||||||
|
|
||||||
void setPicture(const QPixmap& pix);
|
void setPicture(const QPixmap& pix);
|
||||||
void setEnableZoom(bool b) { mZoomEnabled = b; }
|
void setEnableZoom(bool b) { mZoomEnabled = b; }
|
||||||
|
void reset();
|
||||||
QPixmap extractCroppedScaledPicture() const;
|
QPixmap extractCroppedScaledPicture() const;
|
||||||
|
void updateView();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QMouseEvent *ev) override;
|
void mousePressEvent(QMouseEvent *ev) override;
|
||||||
|
@ -51,8 +53,6 @@ protected:
|
||||||
void resizeEvent(QResizeEvent *ev) override;
|
void resizeEvent(QResizeEvent *ev) override;
|
||||||
void wheelEvent(QWheelEvent *me) override;
|
void wheelEvent(QWheelEvent *me) override;
|
||||||
|
|
||||||
void updateView();
|
|
||||||
|
|
||||||
QPixmap mFullImage;
|
QPixmap mFullImage;
|
||||||
|
|
||||||
float mCenterX;
|
float mCenterX;
|
||||||
|
@ -70,6 +70,13 @@ class ChannelPostThumbnailView: public QWidget
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
typedef enum {
|
||||||
|
ASPECT_RATIO_UNKNOWN = 0x00,
|
||||||
|
ASPECT_RATIO_2_3 = 0x01,
|
||||||
|
ASPECT_RATIO_1_1 = 0x02,
|
||||||
|
ASPECT_RATIO_16_9 = 0x03,
|
||||||
|
} AspectRatio;
|
||||||
|
|
||||||
// This variable determines the zoom factor on the text below thumbnails. 2.0 is mostly correct for all screen.
|
// This variable determines the zoom factor on the text below thumbnails. 2.0 is mostly correct for all screen.
|
||||||
static constexpr float THUMBNAIL_OVERSAMPLE_FACTOR = 2.0;
|
static constexpr float THUMBNAIL_OVERSAMPLE_FACTOR = 2.0;
|
||||||
|
|
||||||
|
@ -90,24 +97,18 @@ public:
|
||||||
|
|
||||||
void init(const RsGxsChannelPost& post);
|
void init(const RsGxsChannelPost& post);
|
||||||
|
|
||||||
void setPixmap(const QPixmap& p) { mPostImage->setPicture(p); }
|
void setAspectRatio(AspectRatio r);
|
||||||
|
void setPixmap(const QPixmap& p,bool guess_aspect_ratio) ;
|
||||||
QPixmap getCroppedScaledPicture() const { return mPostImage->extractCroppedScaledPicture() ; }
|
QPixmap getCroppedScaledPicture() const { return mPostImage->extractCroppedScaledPicture() ; }
|
||||||
|
|
||||||
void setText(const QString& s)
|
void setText(const QString& s);
|
||||||
{
|
|
||||||
QString ss;
|
|
||||||
if(s.length() > 30)
|
|
||||||
ss = s.left(30)+"...";
|
|
||||||
else
|
|
||||||
ss =s;
|
|
||||||
|
|
||||||
if(mPostTitle != NULL)
|
|
||||||
mPostTitle->setText(ss);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
float thumbnail_w() const;
|
||||||
|
float thumbnail_h() const;
|
||||||
|
|
||||||
ZoomableLabel *mPostImage;
|
ZoomableLabel *mPostImage;
|
||||||
QLabel *mPostTitle;
|
QLabel *mPostTitle;
|
||||||
uint32_t mFlags;
|
uint32_t mFlags;
|
||||||
|
AspectRatio mAspectRatio;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue