added a factor to scale the font

This commit is contained in:
csoler 2020-09-07 20:49:13 +02:00
parent 149b2c0fbe
commit 660b1c4025
3 changed files with 10 additions and 4 deletions

View File

@ -25,6 +25,7 @@
#include "gui/gxschannels/GxsChannelPostThumbnail.h" #include "gui/gxschannels/GxsChannelPostThumbnail.h"
const float ChannelPostThumbnailView::DEFAULT_SIZE_IN_FONT_HEIGHT = 5.0; const float ChannelPostThumbnailView::DEFAULT_SIZE_IN_FONT_HEIGHT = 5.0;
const float ChannelPostThumbnailView::FONT_SCALE_FACTOR = 2.0;
ChannelPostThumbnailView::ChannelPostThumbnailView(const RsGxsChannelPost& post,uint32_t flags,QWidget *parent) ChannelPostThumbnailView::ChannelPostThumbnailView(const RsGxsChannelPost& post,uint32_t flags,QWidget *parent)
: QWidget(parent),mPostTitle(nullptr),mFlags(flags), mAspectRatio(ASPECT_RATIO_2_3) : QWidget(parent),mPostTitle(nullptr),mFlags(flags), mAspectRatio(ASPECT_RATIO_2_3)
@ -134,7 +135,10 @@ void ChannelPostThumbnailView::init(const RsGxsChannelPost& post)
QFont font = mPostTitle->font(); QFont font = mPostTitle->font();
font.setPointSizeF(DEFAULT_SIZE_IN_FONT_HEIGHT / 5.0 * font.pointSizeF()); if(mFlags & ChannelPostThumbnailView::FLAG_SCALE_FONT)
font.setPointSizeF(FONT_SCALE_FACTOR * DEFAULT_SIZE_IN_FONT_HEIGHT / 5.0 * font.pointSizeF());
else
font.setPointSizeF(FONT_SCALE_FACTOR * DEFAULT_SIZE_IN_FONT_HEIGHT / 5.0 * font.pointSizeF());
if(is_msg_new) if(is_msg_new)
font.setBold(true); font.setBold(true);

View File

@ -85,6 +85,7 @@ public:
static constexpr uint32_t FLAG_NONE = 0x00; static constexpr uint32_t FLAG_NONE = 0x00;
static constexpr uint32_t FLAG_SHOW_TEXT = 0x01; static constexpr uint32_t FLAG_SHOW_TEXT = 0x01;
static constexpr uint32_t FLAG_ALLOW_PAN = 0x02; static constexpr uint32_t FLAG_ALLOW_PAN = 0x02;
static constexpr uint32_t FLAG_SCALE_FONT= 0x04;
// Size of thumbnails as a function of the height of the font. An aspect ratio of 3/4 is good. // Size of thumbnails as a function of the height of the font. An aspect ratio of 3/4 is good.
@ -119,6 +120,7 @@ public:
AspectRatio bestAspectRatio() ; AspectRatio bestAspectRatio() ;
private: private:
static const float DEFAULT_SIZE_IN_FONT_HEIGHT ; static const float DEFAULT_SIZE_IN_FONT_HEIGHT ;
static const float FONT_SCALE_FACTOR ;
float thumbnail_w() const; float thumbnail_w() const;
float thumbnail_h() const; float thumbnail_h() const;

View File

@ -125,7 +125,7 @@ void ChannelPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem &
{ {
// Draw a thumbnail // Draw a thumbnail
uint32_t flags = (mUseGrid)?(ChannelPostThumbnailView::FLAG_SHOW_TEXT):0; uint32_t flags = (mUseGrid)?(ChannelPostThumbnailView::FLAG_SHOW_TEXT | ChannelPostThumbnailView::FLAG_SCALE_FONT):0;
ChannelPostThumbnailView w(post,flags); ChannelPostThumbnailView w(post,flags);
w.setAspectRatio(mAspectRatio); w.setAspectRatio(mAspectRatio);
w.updateGeometry(); w.updateGeometry();
@ -206,7 +206,7 @@ QSize ChannelPostDelegate::sizeHint(const QStyleOptionViewItem& option, const QM
QFontMetricsF fm(option.font); QFontMetricsF fm(option.font);
RsGxsChannelPost post = index.data(Qt::UserRole).value<RsGxsChannelPost>() ; RsGxsChannelPost post = index.data(Qt::UserRole).value<RsGxsChannelPost>() ;
uint32_t flags = (mUseGrid)?(ChannelPostThumbnailView::FLAG_SHOW_TEXT):0; uint32_t flags = (mUseGrid)?(ChannelPostThumbnailView::FLAG_SHOW_TEXT | ChannelPostThumbnailView::FLAG_SCALE_FONT):0;
ChannelPostThumbnailView w(post,flags); ChannelPostThumbnailView w(post,flags);
w.setAspectRatio(mAspectRatio); w.setAspectRatio(mAspectRatio);
@ -798,7 +798,7 @@ void GxsChannelPostsWidgetWithModel::postChannelPostLoad()
for(uint32_t i=0;i<std::min(mChannelPostsModel->getNumberOfPosts(),5u);++i) for(uint32_t i=0;i<std::min(mChannelPostsModel->getNumberOfPosts(),5u);++i)
{ {
const RsGxsChannelPost& post = mChannelPostsModel->post(i); const RsGxsChannelPost& post = mChannelPostsModel->post(i);
ChannelPostThumbnailView v(post,ChannelPostThumbnailView::FLAG_SHOW_TEXT); ChannelPostThumbnailView v(post,ChannelPostThumbnailView::FLAG_SHOW_TEXT | ChannelPostThumbnailView::FLAG_SCALE_FONT);
++ar_votes[ static_cast<uint32_t>( v.bestAspectRatio() )]; ++ar_votes[ static_cast<uint32_t>( v.bestAspectRatio() )];
} }