From cbfa6d042ba883d68897c1db56ba8b68127b08f0 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Wed, 11 Oct 2017 12:18:15 +0200 Subject: [PATCH] Change proeprly font - requires app restart. --- src/core/feedsmodel.cpp | 16 +++++++----- src/core/feedsmodel.h | 20 ++++++--------- src/core/messagesmodel.cpp | 27 ++++++-------------- src/core/messagesmodel.h | 5 +--- src/gui/settings/settingsfeedsmessages.cpp | 7 ++++-- src/services/abstract/rootitem.cpp | 29 +--------------------- src/services/abstract/rootitem.h | 10 -------- 7 files changed, 32 insertions(+), 82 deletions(-) diff --git a/src/core/feedsmodel.cpp b/src/core/feedsmodel.cpp index ca167d218..ba1033463 100755 --- a/src/core/feedsmodel.cpp +++ b/src/core/feedsmodel.cpp @@ -60,6 +60,7 @@ FeedsModel::FeedsModel(QObject* parent) : QAbstractItemModel(parent), m_itemHeig << /*: Feed list header "titles" column tooltip.*/ tr("Titles of feeds/categories.") << /*: Feed list header "counts" column tooltip.*/ tr("Counts of unread/all mesages."); + setupFonts(); updateItemHeight(); } @@ -478,16 +479,19 @@ void FeedsModel::onItemDataChanged(const QList& items) { notifyWithCounts(); } -int FeedsModel::itemHeight() const { - return m_itemHeight; -} - -void FeedsModel::setItemHeight(int item_height) { - m_itemHeight = item_height; +void FeedsModel::setupFonts() { + m_normalFont = Application::font("FeedsView"); + m_boldFont = m_normalFont; + m_boldFont.setBold(true); } void FeedsModel::updateItemHeight() { m_itemHeight = qApp->settings()->value(GROUP(GUI), SETTING(GUI::HeightRowFeeds)).toInt(); + + if (m_itemHeight > 0) { + m_boldFont.setPixelSize(int(m_itemHeight * 0.6)); + m_normalFont.setPixelSize(int(m_itemHeight * 0.6)); + } } void FeedsModel::reloadWholeLayout() { diff --git a/src/core/feedsmodel.h b/src/core/feedsmodel.h index 8ac49282c..cc2bd0689 100755 --- a/src/core/feedsmodel.h +++ b/src/core/feedsmodel.h @@ -102,10 +102,6 @@ class FeedsModel : public QAbstractItemModel { // Access to root item. RootItem* rootItem() const; - int itemHeight() const; - void setItemHeight(int item_height); - void updateItemHeight(); - public slots: void loadActivatedServiceAccounts(); @@ -171,6 +167,10 @@ class FeedsModel : public QAbstractItemModel { // NOTE: View will probably expand dropped index. void requireItemValidationAfterDragDrop(const QModelIndex& source_index); + private: + void updateItemHeight(); + void setupFonts(); + private: RootItem* m_rootItem; int m_itemHeight; @@ -178,18 +178,14 @@ class FeedsModel : public QAbstractItemModel { QList m_headerData; QList m_tooltipData; QIcon m_countsIcon; + QFont m_normalFont; + QFont m_boldFont; }; inline QVariant FeedsModel::data(const QModelIndex& index, int role) const { switch (role) { - case Qt::SizeHintRole: { - if (m_itemHeight > 0) { - return QSize(-1, m_itemHeight); - } - else { - return QVariant(); - } - } + case Qt::FontRole: + return itemForIndex(index)->countOfUnreadMessages() > 0 ? m_boldFont : m_normalFont; default: return itemForIndex(index)->data(index.column(), role);; diff --git a/src/core/messagesmodel.cpp b/src/core/messagesmodel.cpp index e0e66d05a..a8c3ca72c 100755 --- a/src/core/messagesmodel.cpp +++ b/src/core/messagesmodel.cpp @@ -51,16 +51,15 @@ void MessagesModel::setupIcons() { m_unreadIcon = qApp->icons()->fromTheme(QSL("mail-mark-unread")); } -int MessagesModel::itemHeight() const { - return m_itemHeight; -} - -void MessagesModel::setItemHeight(int item_height) { - m_itemHeight = item_height; -} - void MessagesModel::updateItemHeight() { m_itemHeight = qApp->settings()->value(GROUP(GUI), SETTING(GUI::HeightRowMessages)).toInt(); + + if (m_itemHeight > 0) { + m_boldFont.setPixelSize(int(m_itemHeight * 0.6)); + m_normalFont.setPixelSize(int(m_itemHeight * 0.6)); + m_boldStrikedFont.setPixelSize(int(m_itemHeight * 0.6)); + m_normalStrikedFont.setPixelSize(int(m_itemHeight * 0.6)); + } } void MessagesModel::repopulate() { @@ -299,18 +298,6 @@ QVariant MessagesModel::data(const QModelIndex& idx, int role) const { return QVariant(); } - case Qt::SizeHintRole: { - if (m_itemHeight > 0) { - QSize siz = QSqlQueryModel::data(idx, Qt::SizeHintRole).toSize(); - - siz.setHeight(m_itemHeight); - return siz; - } - else { - return QVariant(); - } - } - case Qt::DecorationRole: { const int index_column = idx.column(); diff --git a/src/core/messagesmodel.h b/src/core/messagesmodel.h index d5075a3cc..8f9a448b4 100755 --- a/src/core/messagesmodel.h +++ b/src/core/messagesmodel.h @@ -85,10 +85,6 @@ class MessagesModel : public QSqlQueryModel, public MessagesModelSqlLayer { // Loads messages of given feeds. void loadMessages(RootItem* item); - int itemHeight() const; - void setItemHeight(int item_height); - void updateItemHeight(); - public slots: // NOTE: These methods DO NOT actually change data in the DB, just in the model. @@ -97,6 +93,7 @@ class MessagesModel : public QSqlQueryModel, public MessagesModelSqlLayer { bool setMessageReadById(int id, RootItem::ReadStatus read); private: + void updateItemHeight(); void setupHeaderData(); void setupFonts(); void setupIcons(); diff --git a/src/gui/settings/settingsfeedsmessages.cpp b/src/gui/settings/settingsfeedsmessages.cpp index fe4071665..eb6ea9c51 100755 --- a/src/gui/settings/settingsfeedsmessages.cpp +++ b/src/gui/settings/settingsfeedsmessages.cpp @@ -39,6 +39,11 @@ SettingsFeedsMessages::SettingsFeedsMessages(Settings* settings, QWidget* parent initializeMessageDateFormats(); GuiUtilities::setLabelAsNotice(*m_ui->label_9, false); + connect(m_ui->m_spinHeightRowsMessages, static_cast(&QSpinBox::valueChanged), + this, &SettingsFeedsMessages::requireRestart); + connect(m_ui->m_spinHeightRowsFeeds, static_cast(&QSpinBox::valueChanged), + this, &SettingsFeedsMessages::requireRestart); + connect(m_ui->m_checkAutoUpdateNotification, &QCheckBox::toggled, this, &SettingsFeedsMessages::dirtifySettings); connect(m_ui->m_checkAutoUpdate, &QCheckBox::toggled, this, &SettingsFeedsMessages::dirtifySettings); connect(m_ui->m_checkKeppMessagesInTheMiddle, &QCheckBox::toggled, this, &SettingsFeedsMessages::dirtifySettings); @@ -162,11 +167,9 @@ void SettingsFeedsMessages::saveSettings() { qApp->mainForm()->tabWidget()->feedMessageViewer()->loadMessageViewerFonts(); qApp->feedReader()->updateAutoUpdateStatus(); - qApp->feedReader()->feedsModel()->updateItemHeight(); qApp->feedReader()->feedsModel()->reloadWholeLayout(); qApp->feedReader()->messagesModel()->updateDateFormat(); - qApp->feedReader()->messagesModel()->updateItemHeight(); qApp->feedReader()->messagesModel()->reloadWholeLayout(); onEndSaveSettings(); } diff --git a/src/services/abstract/rootitem.cpp b/src/services/abstract/rootitem.cpp index 985928ac1..e27430687 100755 --- a/src/services/abstract/rootitem.cpp +++ b/src/services/abstract/rootitem.cpp @@ -29,9 +29,7 @@ RootItem::RootItem(RootItem* parent_item) : QObject(nullptr), m_kind(RootItemKind::Root), m_id(NO_PARENT_CATEGORY), m_customId(QSL("")), m_title(QString()), m_description(QString()), m_icon(QIcon()), m_creationDate(QDateTime()), - m_childItems(QList()), m_parentItem(parent_item) { - setupFonts(); -} + m_childItems(QList()), m_parentItem(parent_item) {} RootItem::RootItem(const RootItem& other) : RootItem(nullptr) { setTitle(other.title()); @@ -120,12 +118,6 @@ void RootItem::updateCounts(bool including_total_count) { } } -void RootItem::setupFonts() { - m_normalFont = Application::font("FeedsView"); - m_boldFont = m_normalFont; - m_boldFont.setBold(true); -} - int RootItem::row() const { if (m_parentItem) { return m_parentItem->m_childItems.indexOf(const_cast(this)); @@ -176,9 +168,6 @@ QVariant RootItem::data(int column, int role) const { return QVariant(); } - case Qt::FontRole: - return countOfUnreadMessages() > 0 ? m_boldFont : m_normalFont; - case Qt::DisplayRole: if (column == FDS_MODEL_TITLE_INDEX) { return m_title; @@ -437,22 +426,6 @@ void RootItem::setDescription(const QString& description) { m_description = description; } -QFont RootItem::normalFont() const { - return m_normalFont; -} - -void RootItem::setNormalFont(const QFont& normal_font) { - m_normalFont = normal_font; -} - -QFont RootItem::boldFont() const { - return m_boldFont; -} - -void RootItem::setBoldFont(const QFont& bold_font) { - m_boldFont = bold_font; -} - bool RootItem::removeChild(RootItem* child) { return m_childItems.removeOne(child); } diff --git a/src/services/abstract/rootitem.h b/src/services/abstract/rootitem.h index 53194efcc..1321ccc6b 100755 --- a/src/services/abstract/rootitem.h +++ b/src/services/abstract/rootitem.h @@ -208,12 +208,6 @@ class RootItem : public QObject { QString description() const; void setDescription(const QString& description); - QFont normalFont() const; - void setNormalFont(const QFont& normal_font); - - QFont boldFont() const; - void setBoldFont(const QFont& bold_font); - // NOTE: For standard feed/category, this WILL equal to id(). QString customId() const; int customNumericId() const; @@ -225,8 +219,6 @@ class RootItem : public QObject { ServiceRoot* toServiceRoot() const; private: - void setupFonts(); - RootItemKind::Kind m_kind; int m_id; QString m_customId; @@ -234,8 +226,6 @@ class RootItem : public QObject { QString m_description; QIcon m_icon; QDateTime m_creationDate; - QFont m_normalFont; - QFont m_boldFont; QList m_childItems; RootItem* m_parentItem;