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:
▪ 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:
▪ 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_IS_RUNNING "app_is_running"
#define APP_SKIN_DEFAULT "base/vergilius.xml"
#define APP_STYLE_DEFAULT "Fusion"
#define APP_THEME_DEFAULT "Faenza"
#define APP_NO_THEME ""
#define APP_THEME_SUFFIX ".png"

View File

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

View File

@ -29,6 +29,7 @@
#include "gui/statusbar.h"
#include <QDropEvent>
#include <QStyleFactory>
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_editorMessagesToolbar, &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);
}
@ -152,7 +152,6 @@ void SettingsGui::loadSettings() {
if (skin.m_baseName == selected_skin) {
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));
}
// 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.
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());
@ -222,7 +233,7 @@ void SettingsGui::saveSettings() {
}
// 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>();
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.
settings()->setValue(GROUP(GUI), GUI::TabCloseMiddleClick, m_ui->m_checkCloseTabsMiddleClick->isChecked());
settings()->setValue(GROUP(GUI), GUI::TabCloseDoubleClick, m_ui->m_checkCloseTabsDoubleClick->isChecked());
@ -246,12 +269,3 @@ void SettingsGui::saveSettings() {
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.
bool eventFilter(QObject *obj, QEvent *e);
private slots:
void onSkinSelected(QTreeWidgetItem *current, QTreeWidgetItem *previous);
private:
Ui::SettingsGui *m_ui;
};

View File

@ -69,96 +69,64 @@
<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>
<item row="0" column="0">
<widget class="QLabel" name="m_lblIconTheme">
<property name="text">
<string>Icon theme</string>
</property>
<property name="buddy">
<cstring>m_cmbIconTheme</cstring>
</property>
<layout class="QFormLayout" name="formLayout_8">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="m_lblIconTheme">
<property name="text">
<string>Icon theme</string>
</property>
<property name="buddy">
<cstring>m_cmbIconTheme</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="m_cmbIconTheme"/>
</item>
</layout>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Skins</string>
<item row="0" column="1">
<widget class="QComboBox" name="m_cmbIconTheme"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="m_lblStyle">
<property name="text">
<string>Style</string>
</property>
<layout class="QFormLayout" name="formLayout_9">
<item row="0" column="0" colspan="2">
<widget class="QTreeWidget" name="m_treeSkins">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="indentation">
<number>0</number>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<property name="itemsExpandable">
<bool>false</bool>
</property>
<property name="expandsOnDoubleClick">
<bool>false</bool>
</property>
<attribute name="headerMinimumSectionSize">
<number>80</number>
</attribute>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
</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>
<item row="1" column="1">
<widget class="QListWidget" name="m_listStyles"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="m_lblSkin">
<property name="text">
<string>Skin</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QTreeWidget" name="m_treeSkins">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="indentation">
<number>0</number>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<property name="itemsExpandable">
<bool>false</bool>
</property>
<property name="expandsOnDoubleClick">
<bool>false</bool>
</property>
<attribute name="headerMinimumSectionSize">
<number>80</number>
</attribute>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
</item>
</layout>
@ -385,6 +353,23 @@
<container>1</container>
</customwidget>
</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/>
<connections/>
</ui>

View File

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

View File

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

View File

@ -607,7 +607,7 @@ int DatabaseQueries::updateMessages(QSqlDatabase db,
if (db.exec("UPDATE Messages "
"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()) {
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()) {

View File

@ -191,7 +191,6 @@ void FeedReader::executeNextAutoUpdate() {
// NOTE: OSD/bubble informing about performing
// 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"),
tr("I will auto-update %n feed(s).", 0, feeds_for_update.size()),
QSystemTrayIcon::Information);

View File

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

View File

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

View File

@ -63,17 +63,11 @@ void SkinFactory::loadCurrentSkin() {
}
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()) {
qApp->setStyleSheet(skin.m_rawData);
}
qApp->setStyle(qApp->settings()->value(GROUP(GUI), SETTING(GUI::Style)).toString());
}
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 skin;
QString styles;
QFile skin_file(APP_SKIN_PATH + QDir::separator() + skin_name);
QDomDocument dokument;
@ -103,10 +96,6 @@ Skin SkinFactory::skinInfo(const QString &skin_name, bool *ok) const {
// Obtain visible skin name.
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.
skin.m_author = skin_node.namedItem(QSL("author")).namedItem(QSL("name")).toElement().text();

View File

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