Some advancements in skins/styles settings.

This commit is contained in:
Martin Rotter 2016-09-12 07:41:12 +02:00
parent 0f81da750e
commit a5357da410
15 changed files with 120 additions and 129 deletions

File diff suppressed because one or more lines are too long

View File

@ -2,6 +2,7 @@
————— —————
Added: Added:
▪ Qt "styles" are now configurable via settings and not hardcoded in "skin" files. Default "style" is now "Fusion" and can be changed to anything else in settings.
Changed: Changed:
▪ Made some tweaks regarding bug #41. Number of new messages is now determined in feed downloader working thread too. ▪ Made some tweaks regarding bug #41. Number of new messages is now determined in feed downloader working thread too.

View File

@ -124,6 +124,7 @@
#define APP_QUIT_INSTANCE "-q" #define APP_QUIT_INSTANCE "-q"
#define APP_IS_RUNNING "app_is_running" #define APP_IS_RUNNING "app_is_running"
#define APP_SKIN_DEFAULT "base/vergilius.xml" #define APP_SKIN_DEFAULT "base/vergilius.xml"
#define APP_STYLE_DEFAULT "Fusion"
#define APP_THEME_DEFAULT "Faenza" #define APP_THEME_DEFAULT "Faenza"
#define APP_NO_THEME "" #define APP_NO_THEME ""
#define APP_THEME_SUFFIX ".png" #define APP_THEME_SUFFIX ".png"

View File

@ -76,13 +76,14 @@ void FormSettings::applySettings() {
QStringList panels_for_restart; QStringList panels_for_restart;
foreach (SettingsPanel *panel, m_panels) { foreach (SettingsPanel *panel, m_panels) {
if (panel->requiresRestart()) {
panels_for_restart.append(panel->title().toLower());
}
if (panel->isDirty()) { if (panel->isDirty()) {
panel->saveSettings(); panel->saveSettings();
} }
if (panel->requiresRestart()) {
panels_for_restart.append(panel->title().toLower());
panel->setRequiresRestart(false);
}
} }
if (!panels_for_restart.isEmpty()) { if (!panels_for_restart.isEmpty()) {

View File

@ -29,6 +29,7 @@
#include "gui/statusbar.h" #include "gui/statusbar.h"
#include <QDropEvent> #include <QDropEvent>
#include <QStyleFactory>
SettingsGui::SettingsGui(Settings *settings, QWidget *parent) : SettingsPanel(settings, parent), m_ui(new Ui::SettingsGui) { SettingsGui::SettingsGui(Settings *settings, QWidget *parent) : SettingsPanel(settings, parent), m_ui(new Ui::SettingsGui) {
@ -69,9 +70,8 @@ SettingsGui::SettingsGui(Settings *settings, QWidget *parent) : SettingsPanel(se
connect(m_ui->m_editorFeedsToolbar, &ToolBarEditor::setupChanged, this, &SettingsGui::dirtifySettings); connect(m_ui->m_editorFeedsToolbar, &ToolBarEditor::setupChanged, this, &SettingsGui::dirtifySettings);
connect(m_ui->m_editorMessagesToolbar, &ToolBarEditor::setupChanged, this, &SettingsGui::dirtifySettings); connect(m_ui->m_editorMessagesToolbar, &ToolBarEditor::setupChanged, this, &SettingsGui::dirtifySettings);
connect(m_ui->m_editorStatusbar, &ToolBarEditor::setupChanged, this, &SettingsGui::dirtifySettings); connect(m_ui->m_editorStatusbar, &ToolBarEditor::setupChanged, this, &SettingsGui::dirtifySettings);
connect(m_ui->m_listStyles, &QListWidget::currentItemChanged, this, &SettingsGui::dirtifySettings);
connect(m_ui->m_treeSkins, &QTreeWidget::currentItemChanged, this, &SettingsGui::onSkinSelected);
connect(m_ui->m_treeSkins, &QTreeWidget::currentItemChanged, this, &SettingsGui::requireRestart);
connect(m_ui->m_cmbSelectToolBar, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), m_ui->m_stackedToolbars, &QStackedWidget::setCurrentIndex); connect(m_ui->m_cmbSelectToolBar, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), m_ui->m_stackedToolbars, &QStackedWidget::setCurrentIndex);
} }
@ -152,7 +152,6 @@ void SettingsGui::loadSettings() {
if (skin.m_baseName == selected_skin) { if (skin.m_baseName == selected_skin) {
m_ui->m_treeSkins->setCurrentItem(new_item); m_ui->m_treeSkins->setCurrentItem(new_item);
m_ui->m_lblActiveContents->setText(skin.m_visibleName);
} }
} }
@ -163,6 +162,18 @@ void SettingsGui::loadSettings() {
m_ui->m_treeSkins->setCurrentItem(m_ui->m_treeSkins->topLevelItem(0)); m_ui->m_treeSkins->setCurrentItem(m_ui->m_treeSkins->topLevelItem(0));
} }
// Load styles.
foreach (const QString &style_name, QStyleFactory::keys()) {
m_ui->m_listStyles->addItem(style_name);
}
QList<QListWidgetItem*> items = m_ui->m_listStyles->findItems(settings()->value(GROUP(GUI), SETTING(GUI::Style)).toString(),
Qt::MatchFixedString);
if (!items.isEmpty()) {
m_ui->m_listStyles->setCurrentItem(items.at(0));
}
// Load tab settings. // Load tab settings.
m_ui->m_checkCloseTabsMiddleClick->setChecked(settings()->value(GROUP(GUI), SETTING(GUI::TabCloseMiddleClick)).toBool()); m_ui->m_checkCloseTabsMiddleClick->setChecked(settings()->value(GROUP(GUI), SETTING(GUI::TabCloseMiddleClick)).toBool());
m_ui->m_checkCloseTabsDoubleClick->setChecked(settings()->value(GROUP(GUI), SETTING(GUI::TabCloseDoubleClick)).toBool()); m_ui->m_checkCloseTabsDoubleClick->setChecked(settings()->value(GROUP(GUI), SETTING(GUI::TabCloseDoubleClick)).toBool());
@ -222,7 +233,7 @@ void SettingsGui::saveSettings() {
} }
// Save and activate new skin. // Save and activate new skin.
if (m_ui->m_treeSkins->selectedItems().size() > 0) { if (!m_ui->m_treeSkins->selectedItems().isEmpty()) {
const Skin active_skin = m_ui->m_treeSkins->currentItem()->data(0, Qt::UserRole).value<Skin>(); const Skin active_skin = m_ui->m_treeSkins->currentItem()->data(0, Qt::UserRole).value<Skin>();
if (qApp->skins()->selectedSkinName() != active_skin.m_baseName) { if (qApp->skins()->selectedSkinName() != active_skin.m_baseName) {
@ -231,6 +242,18 @@ void SettingsGui::saveSettings() {
} }
} }
// Set new style.
if (!m_ui->m_listStyles->selectedItems().isEmpty()) {
const QString new_style = m_ui->m_listStyles->currentItem()->text();
const QString old_style = qApp->settings()->value(GROUP(GUI), SETTING(GUI::Style)).toString();
if (old_style != new_style) {
requireRestart();
}
qApp->settings()->setValue(GROUP(GUI), GUI::Style, new_style);
}
// Save tab settings. // Save tab settings.
settings()->setValue(GROUP(GUI), GUI::TabCloseMiddleClick, m_ui->m_checkCloseTabsMiddleClick->isChecked()); settings()->setValue(GROUP(GUI), GUI::TabCloseMiddleClick, m_ui->m_checkCloseTabsMiddleClick->isChecked());
settings()->setValue(GROUP(GUI), GUI::TabCloseDoubleClick, m_ui->m_checkCloseTabsDoubleClick->isChecked()); settings()->setValue(GROUP(GUI), GUI::TabCloseDoubleClick, m_ui->m_checkCloseTabsDoubleClick->isChecked());
@ -246,12 +269,3 @@ void SettingsGui::saveSettings() {
onEndSaveSettings(); onEndSaveSettings();
} }
void SettingsGui::onSkinSelected(QTreeWidgetItem *current, QTreeWidgetItem *previous) {
Q_UNUSED(previous)
if (current != nullptr) {
const Skin skin = current->data(0, Qt::UserRole).value<Skin>();
m_ui->m_lblSelectedContents->setText(skin.m_visibleName);
}
}

View File

@ -41,9 +41,6 @@ class SettingsGui : public SettingsPanel {
// Does check of controls before dialog can be submitted. // Does check of controls before dialog can be submitted.
bool eventFilter(QObject *obj, QEvent *e); bool eventFilter(QObject *obj, QEvent *e);
private slots:
void onSkinSelected(QTreeWidgetItem *current, QTreeWidgetItem *previous);
private: private:
Ui::SettingsGui *m_ui; Ui::SettingsGui *m_ui;
}; };

View File

@ -66,15 +66,6 @@
</rect> </rect>
</property> </property>
<layout class="QFormLayout" name="formLayout"> <layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="0" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Icons</string>
</property>
<layout class="QFormLayout" name="formLayout_8">
<property name="fieldGrowthPolicy"> <property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum> <enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property> </property>
@ -91,16 +82,24 @@
<item row="0" column="1"> <item row="0" column="1">
<widget class="QComboBox" name="m_cmbIconTheme"/> <widget class="QComboBox" name="m_cmbIconTheme"/>
</item> </item>
</layout> <item row="1" column="0">
<widget class="QLabel" name="m_lblStyle">
<property name="text">
<string>Style</string>
</property>
</widget> </widget>
</item> </item>
<item row="1" column="0" colspan="2"> <item row="1" column="1">
<widget class="QGroupBox" name="groupBox_2"> <widget class="QListWidget" name="m_listStyles"/>
<property name="title"> </item>
<string>Skins</string> <item row="2" column="0">
<widget class="QLabel" name="m_lblSkin">
<property name="text">
<string>Skin</string>
</property> </property>
<layout class="QFormLayout" name="formLayout_9"> </widget>
<item row="0" column="0" colspan="2"> </item>
<item row="2" column="1">
<widget class="QTreeWidget" name="m_treeSkins"> <widget class="QTreeWidget" name="m_treeSkins">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding"> <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
@ -130,37 +129,6 @@
</column> </column>
</widget> </widget>
</item> </item>
<item row="1" column="0">
<widget class="QLabel" name="m_lblActiveCaption">
<property name="text">
<string>Active skin:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="m_lblActiveContents">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="m_lblSelectedCaption">
<property name="text">
<string>Selected skin:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="m_lblSelectedContents">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</widget> </widget>
@ -385,6 +353,23 @@
<container>1</container> <container>1</container>
</customwidget> </customwidget>
</customwidgets> </customwidgets>
<tabstops>
<tabstop>m_tabUi</tabstop>
<tabstop>m_scrollIconSkins</tabstop>
<tabstop>m_cmbIconTheme</tabstop>
<tabstop>m_listStyles</tabstop>
<tabstop>m_treeSkins</tabstop>
<tabstop>m_checkHideWhenMinimized</tabstop>
<tabstop>m_checkHidden</tabstop>
<tabstop>m_checkEnableNotifications</tabstop>
<tabstop>m_checkNewTabDoubleClick</tabstop>
<tabstop>m_checkHideTabBarIfOneTabVisible</tabstop>
<tabstop>m_checkCloseTabsDoubleClick</tabstop>
<tabstop>m_checkCloseTabsMiddleClick</tabstop>
<tabstop>m_cmbToolbarButtonStyle</tabstop>
<tabstop>m_cmbSelectToolBar</tabstop>
<tabstop>m_grpTray</tabstop>
</tabstops>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>

View File

@ -40,7 +40,6 @@ void SettingsPanel::onBeginSaveSettings() {
void SettingsPanel::onEndSaveSettings() { void SettingsPanel::onEndSaveSettings() {
setIsDirty(false); setIsDirty(false);
setRequiresRestart(false);
} }
void SettingsPanel::dirtifySettings() { void SettingsPanel::dirtifySettings() {

View File

@ -37,6 +37,9 @@ class SettingsPanel : public QWidget {
bool requiresRestart() const; bool requiresRestart() const;
bool isDirty() const; bool isDirty() const;
void setIsDirty(bool is_dirty);
void setRequiresRestart(bool requiresRestart);
protected: protected:
void onBeginLoadSettings(); void onBeginLoadSettings();
void onEndLoadSettings(); void onEndLoadSettings();
@ -51,9 +54,6 @@ class SettingsPanel : public QWidget {
// NOTE: This will be probably called by subclasses when user changes some stuff. // NOTE: This will be probably called by subclasses when user changes some stuff.
void dirtifySettings(); void dirtifySettings();
// These methods should not be probably called by subclasses.
void setIsDirty(bool is_dirty);
void setRequiresRestart(bool requiresRestart);
void requireRestart(); void requireRestart();
signals: signals:

View File

@ -607,7 +607,7 @@ int DatabaseQueries::updateMessages(QSqlDatabase db,
if (db.exec("UPDATE Messages " if (db.exec("UPDATE Messages "
"SET custom_id = (SELECT id FROM Messages t WHERE t.id = Messages.id) " "SET custom_id = (SELECT id FROM Messages t WHERE t.id = Messages.id) "
"WHERE Messages.custom_id IS NULL OR Messages.custom_id = '';").lastError().isValid()) { "WHERE Messages.custom_id IS NULL OR Messages.custom_id = '';").lastError().isValid()) {
qWarning("Failed to set custom ID for all messages."); qWarning("Failed to set custom ID for all messages: '%s'.", qPrintable(db.lastError().text()));
} }
if (!db.commit()) { if (!db.commit()) {

View File

@ -191,7 +191,6 @@ void FeedReader::executeNextAutoUpdate() {
// NOTE: OSD/bubble informing about performing // NOTE: OSD/bubble informing about performing
// of scheduled update can be shown now. // of scheduled update can be shown now.
// TODO: Co dělat v non-GUI módu.
qApp->showGuiMessage(tr("Starting auto-update of some feeds"), qApp->showGuiMessage(tr("Starting auto-update of some feeds"),
tr("I will auto-update %n feed(s).", 0, feeds_for_update.size()), tr("I will auto-update %n feed(s).", 0, feeds_for_update.size()),
QSystemTrayIcon::Information); QSystemTrayIcon::Information);

View File

@ -151,6 +151,10 @@ DVALUE(char*) GUI::IconThemeDef = APP_THEME_DEFAULT;
DKEY GUI::Skin = "skin"; DKEY GUI::Skin = "skin";
DVALUE(char*) GUI::SkinDef = APP_SKIN_DEFAULT; DVALUE(char*) GUI::SkinDef = APP_SKIN_DEFAULT;
DKEY GUI::Style = "style";
DVALUE(char*) GUI::StyleDef = APP_STYLE_DEFAULT;
// General. // General.
DKEY General::ID = "main"; DKEY General::ID = "main";

View File

@ -169,6 +169,9 @@ namespace GUI {
KEY Skin; KEY Skin;
VALUE(char*) SkinDef; VALUE(char*) SkinDef;
KEY Style;
VALUE(char*) StyleDef;
} }
// General. // General.

View File

@ -63,17 +63,11 @@ void SkinFactory::loadCurrentSkin() {
} }
void SkinFactory::loadSkinFromData(const Skin &skin) { void SkinFactory::loadSkinFromData(const Skin &skin) {
// Iterate supported styles and load one.
foreach (const QString &style, skin.m_stylesNames) {
if (qApp->setStyle(style) != 0) {
qDebug("Style '%s' loaded.", qPrintable(style));
break;
}
}
if (!skin.m_rawData.isEmpty()) { if (!skin.m_rawData.isEmpty()) {
qApp->setStyleSheet(skin.m_rawData); qApp->setStyleSheet(skin.m_rawData);
} }
qApp->setStyle(qApp->settings()->value(GROUP(GUI), SETTING(GUI::Style)).toString());
} }
void SkinFactory::setCurrentSkinName(const QString &skin_name) { void SkinFactory::setCurrentSkinName(const QString &skin_name) {
@ -86,7 +80,6 @@ QString SkinFactory::selectedSkinName() const {
Skin SkinFactory::skinInfo(const QString &skin_name, bool *ok) const { Skin SkinFactory::skinInfo(const QString &skin_name, bool *ok) const {
Skin skin; Skin skin;
QString styles;
QFile skin_file(APP_SKIN_PATH + QDir::separator() + skin_name); QFile skin_file(APP_SKIN_PATH + QDir::separator() + skin_name);
QDomDocument dokument; QDomDocument dokument;
@ -103,10 +96,6 @@ Skin SkinFactory::skinInfo(const QString &skin_name, bool *ok) const {
// Obtain visible skin name. // Obtain visible skin name.
skin.m_visibleName = skin_node.namedItem(QSL("name")).toElement().text(); skin.m_visibleName = skin_node.namedItem(QSL("name")).toElement().text();
// Obtain style name.
styles = skin_node.namedItem(QSL("style")).toElement().text();
skin.m_stylesNames = styles.split(',', QString::SkipEmptyParts);
// Obtain author. // Obtain author.
skin.m_author = skin_node.namedItem(QSL("author")).namedItem(QSL("name")).toElement().text(); skin.m_author = skin_node.namedItem(QSL("author")).namedItem(QSL("name")).toElement().text();

View File

@ -27,7 +27,6 @@
struct Skin { struct Skin {
QString m_baseName; QString m_baseName;
QString m_visibleName; QString m_visibleName;
QStringList m_stylesNames;
QString m_author; QString m_author;
QString m_email; QString m_email;
QString m_version; QString m_version;