mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
added auto-selection of aspect ratio in posts view
This commit is contained in:
parent
af16659783
commit
062f0eb195
@ -158,6 +158,20 @@ void ChannelPostThumbnailView::init(const RsGxsChannelPost& post)
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ChannelPostThumbnailView::AspectRatio ChannelPostThumbnailView::bestAspectRatio()
|
||||||
|
{
|
||||||
|
if(mPostImage->originalImage().isNull())
|
||||||
|
return ASPECT_RATIO_1_1;
|
||||||
|
|
||||||
|
float as = mPostImage->originalImage().height() / (float)mPostImage->originalImage().width() ;
|
||||||
|
|
||||||
|
if(as < 0.8)
|
||||||
|
return ASPECT_RATIO_16_9;
|
||||||
|
else if(as < 1.15)
|
||||||
|
return ASPECT_RATIO_1_1;
|
||||||
|
else
|
||||||
|
return ASPECT_RATIO_2_3;
|
||||||
|
}
|
||||||
QSize ChannelPostThumbnailView::actualSize() const
|
QSize ChannelPostThumbnailView::actualSize() const
|
||||||
{
|
{
|
||||||
QFontMetricsF fm(font());
|
QFontMetricsF fm(font());
|
||||||
|
@ -46,6 +46,8 @@ public:
|
|||||||
QPixmap extractCroppedScaledPicture() const;
|
QPixmap extractCroppedScaledPicture() const;
|
||||||
void updateView();
|
void updateView();
|
||||||
|
|
||||||
|
const QPixmap& originalImage() const { return mFullImage ; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QMouseEvent *ev) override;
|
void mousePressEvent(QMouseEvent *ev) override;
|
||||||
void mouseReleaseEvent(QMouseEvent *ev) override;
|
void mouseReleaseEvent(QMouseEvent *ev) override;
|
||||||
@ -108,6 +110,13 @@ public:
|
|||||||
// The label however has a correct size. It seems that Qt doesn't like widgets with horizontal aspect ratio and forces the size accordingly.
|
// The label however has a correct size. It seems that Qt doesn't like widgets with horizontal aspect ratio and forces the size accordingly.
|
||||||
|
|
||||||
QSize actualSize() const ;
|
QSize actualSize() const ;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief bestAspectRatio
|
||||||
|
* Computes the preferred aspect ratio for the image in the post. The default is 1:1.
|
||||||
|
* \return the prefered aspect ratio
|
||||||
|
*/
|
||||||
|
AspectRatio bestAspectRatio() ;
|
||||||
private:
|
private:
|
||||||
static const float DEFAULT_SIZE_IN_FONT_HEIGHT ;
|
static const float DEFAULT_SIZE_IN_FONT_HEIGHT ;
|
||||||
|
|
||||||
|
@ -108,6 +108,7 @@ public:
|
|||||||
std::vector<std::pair<time_t,RsGxsMessageId> > getPostVersions(const RsGxsMessageId& mid) const;
|
std::vector<std::pair<time_t,RsGxsMessageId> > getPostVersions(const RsGxsMessageId& mid) const;
|
||||||
|
|
||||||
uint32_t getNumberOfPosts() { return mPosts.size() ; }
|
uint32_t getNumberOfPosts() { return mPosts.size() ; }
|
||||||
|
const RsGxsChannelPost& post(uint32_t i) const { return mPosts[i]; }
|
||||||
|
|
||||||
// This method will asynchroneously update the data
|
// This method will asynchroneously update the data
|
||||||
void updateChannel(const RsGxsGroupId& channel_group_id);
|
void updateChannel(const RsGxsGroupId& channel_group_id);
|
||||||
|
@ -145,13 +145,13 @@ void ChannelPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem &
|
|||||||
|
|
||||||
pixmap = pixmap.copy(QRect(0,0,w.actualSize().width(),w.actualSize().height()));
|
pixmap = pixmap.copy(QRect(0,0,w.actualSize().width(),w.actualSize().height()));
|
||||||
|
|
||||||
if(index.row()==0 && index.column()==0)
|
// if(index.row()==0 && index.column()==0)
|
||||||
{
|
// {
|
||||||
QFile file("yourFile.png");
|
// QFile file("yourFile.png");
|
||||||
file.open(QIODevice::WriteOnly);
|
// file.open(QIODevice::WriteOnly);
|
||||||
pixmap.save(&file, "PNG");
|
// pixmap.save(&file, "PNG");
|
||||||
file.close();
|
// file.close();
|
||||||
}
|
// }
|
||||||
|
|
||||||
if(mUseGrid || index.column()==0)
|
if(mUseGrid || index.column()==0)
|
||||||
{
|
{
|
||||||
@ -787,6 +787,25 @@ void GxsChannelPostsWidgetWithModel::postChannelPostLoad()
|
|||||||
ui->channelFiles_TV->sortByColumn(0, Qt::AscendingOrder);
|
ui->channelFiles_TV->sortByColumn(0, Qt::AscendingOrder);
|
||||||
|
|
||||||
ui->infoPosts->setText(QString::number(mChannelPostsModel->getNumberOfPosts()) + " / " + QString::number(mGroup.mMeta.mVisibleMsgCount));
|
ui->infoPosts->setText(QString::number(mChannelPostsModel->getNumberOfPosts()) + " / " + QString::number(mGroup.mMeta.mVisibleMsgCount));
|
||||||
|
|
||||||
|
// now compute aspect ratio for posts. We do that by looking at the 5 latest posts and compute the best aspect ratio for them.
|
||||||
|
|
||||||
|
std::vector<uint32_t> ar_votes(3,0);
|
||||||
|
|
||||||
|
for(uint32_t i=0;i<std::min(mChannelPostsModel->getNumberOfPosts(),5u);++i)
|
||||||
|
{
|
||||||
|
const RsGxsChannelPost& post = mChannelPostsModel->post(i);
|
||||||
|
ChannelPostThumbnailView v(post,ChannelPostThumbnailView::FLAG_SHOW_TEXT);
|
||||||
|
|
||||||
|
++ar_votes[ static_cast<uint32_t>( v.bestAspectRatio() )];
|
||||||
|
}
|
||||||
|
int best=0;
|
||||||
|
for(uint32_t i=0;i<3;++i)
|
||||||
|
if(ar_votes[i] > ar_votes[best])
|
||||||
|
best = i;
|
||||||
|
|
||||||
|
mChannelPostsDelegate->setAspectRatio(static_cast<ChannelPostThumbnailView::AspectRatio>(best));
|
||||||
|
mChannelPostsModel->triggerViewUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GxsChannelPostsWidgetWithModel::updateDisplay(bool complete)
|
void GxsChannelPostsWidgetWithModel::updateDisplay(bool complete)
|
||||||
|
Loading…
Reference in New Issue
Block a user