Change proeprly font - requires app restart.

This commit is contained in:
Martin Rotter 2017-10-11 12:18:15 +02:00
parent c759c0d6fd
commit cbfa6d042b
7 changed files with 32 additions and 82 deletions

View File

@ -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<RootItem*>& 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() {

View File

@ -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<QString> m_headerData;
QList<QString> 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);;

View File

@ -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();

View File

@ -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();

View File

@ -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<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged),
this, &SettingsFeedsMessages::requireRestart);
connect(m_ui->m_spinHeightRowsFeeds, static_cast<void (QSpinBox::*)(int)>(&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();
}

View File

@ -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<RootItem*>()), m_parentItem(parent_item) {
setupFonts();
}
m_childItems(QList<RootItem*>()), 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<RootItem*>(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);
}

View File

@ -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<RootItem*> m_childItems;
RootItem* m_parentItem;