Work on skins.

This commit is contained in:
Martin Rotter 2013-11-15 11:03:12 +01:00
parent ab01e47501
commit e0e1f0adfd
7 changed files with 147 additions and 120 deletions

View file

@ -5,7 +5,7 @@
<name>Martin Rotter</name> <name>Martin Rotter</name>
<email>rotter.martinos@gmail.com</email> <email>rotter.martinos@gmail.com</email>
</author> </author>
<style></style> <style/>
<markup>PGh0bWw+IDxoZWFkPiA8c3R5bGU+cHJle3doaXRlLXNwYWNlOnByZS13cmFwfS5oZWFkZXJ0ZXh0 <markup>PGh0bWw+IDxoZWFkPiA8c3R5bGU+cHJle3doaXRlLXNwYWNlOnByZS13cmFwfS5oZWFkZXJ0ZXh0
e2ZvbnQtc2l6ZToxOXB4O21hcmdpbi1ib3R0b206MTBweH0uaGVhZGVye2ZvbnQtc2l6ZToxNXB4 e2ZvbnQtc2l6ZToxOXB4O21hcmdpbi1ib3R0b206MTBweH0uaGVhZGVye2ZvbnQtc2l6ZToxNXB4
Oy13ZWJraXQtdHJhbnNpdGlvbjpiYWNrZ3JvdW5kIDFzIGVhc2Utb3V0O2JhY2tncm91bmQ6LXdl Oy13ZWJraXQtdHJhbnNpdGlvbjpiYWNrZ3JvdW5kIDFzIGVhc2Utb3V0O2JhY2tncm91bmQ6LXdl

View file

@ -50,6 +50,7 @@
#define APP_IS_RUNNING "app_is_running" #define APP_IS_RUNNING "app_is_running"
#define APP_THEME_PATH_QRC ":/themes" #define APP_THEME_PATH_QRC ":/themes"
#define APP_SKIN_DEFAULT "base/vergilius.xml"
#if defined(Q_OS_LINUX) #if defined(Q_OS_LINUX)
#define APP_DESKTOP_ENTRY_PATH "@DESKTOP_ENTRY@" #define APP_DESKTOP_ENTRY_PATH "@DESKTOP_ENTRY@"

View file

@ -7,6 +7,7 @@ MessagesModel::MessagesModel(QObject *parent) : QSqlTableModel(parent) {
} }
void MessagesModel::setupHeaderData() { void MessagesModel::setupHeaderData() {
// TODO: Enhance this.
m_headerData << tr("aaa") << m_headerData << tr("aaa") <<
tr("bbb"); tr("bbb");
} }

View file

@ -417,7 +417,6 @@ void FormSettings::loadInterface() {
// Load skin. // Load skin.
QList<Skin> installed_skins = SkinFactory::getInstance()->getInstalledSkins(); QList<Skin> installed_skins = SkinFactory::getInstance()->getInstalledSkins();
QString selected_skin = SkinFactory::getInstance()->getSelectedSkinName(); QString selected_skin = SkinFactory::getInstance()->getSelectedSkinName();
QString active_skin = SkinFactory::getInstance()->getCurrentSkinName();
foreach (Skin skin, installed_skins) { foreach (Skin skin, installed_skins) {
QTreeWidgetItem *new_item = new QTreeWidgetItem(QStringList() << QTreeWidgetItem *new_item = new QTreeWidgetItem(QStringList() <<
@ -432,16 +431,17 @@ void FormSettings::loadInterface() {
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);
} }
} }
if (m_ui->m_treeSkins->currentItem() == NULL) { if (m_ui->m_treeSkins->currentItem() == NULL &&
// No skin is selected or currently selected skin is unavailable. m_ui->m_treeSkins->topLevelItemCount() > 0) {
// Currently active skin is NOT available, select another one as selected
// if possible.
m_ui->m_treeSkins->setCurrentItem(m_ui->m_treeSkins->topLevelItem(0)); m_ui->m_treeSkins->setCurrentItem(m_ui->m_treeSkins->topLevelItem(0));
} }
m_ui->m_lblActiveContents->setText(SkinFactory::getInstance()->getSkinInfo(active_skin).m_visibleName);
// Load tab settings. // Load tab settings.
m_ui->m_checkCloseTabsMiddleClick->setChecked(settings->value(APP_CFG_GUI, m_ui->m_checkCloseTabsMiddleClick->setChecked(settings->value(APP_CFG_GUI,
"tab_close_mid_button", "tab_close_mid_button",

View file

@ -69,8 +69,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>100</width> <width>666</width>
<height>30</height> <height>399</height>
</rect> </rect>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout_4"> <layout class="QHBoxLayout" name="horizontalLayout_4">
@ -115,7 +115,7 @@
<enum>QTabWidget::North</enum> <enum>QTabWidget::North</enum>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>2</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="m_tabIconSkin"> <widget class="QWidget" name="m_tabIconSkin">
<attribute name="title"> <attribute name="title">
@ -147,91 +147,101 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>436</width> <width>662</width>
<height>196</height> <height>371</height>
</rect> </rect>
</property> </property>
<layout class="QFormLayout" name="formLayout"> <layout class="QFormLayout" name="formLayout">
<item row="0" column="0"> <property name="fieldGrowthPolicy">
<widget class="QLabel" name="m_lblIconTheme"> <enum>QFormLayout::AllNonFixedFieldsGrow</enum>
<property name="text"> </property>
<string>Icon theme</string> <item row="0" column="0" colspan="2">
</property> <widget class="QGroupBox" name="groupBox">
<property name="buddy"> <property name="title">
<cstring>m_cmbIconTheme</cstring> <string>Icons</string>
</property> </property>
<layout class="QFormLayout" name="formLayout_8">
<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> </widget>
</item> </item>
<item row="0" column="1"> <item row="1" column="0" colspan="2">
<widget class="QComboBox" name="m_cmbIconTheme"/> <widget class="QGroupBox" name="groupBox_2">
</item> <property name="title">
<item row="1" column="0"> <string>Skins</string>
<widget class="QLabel" name="m_lblSkin">
<property name="text">
<string>Skin</string>
</property>
</widget>
</item>
<item row="2" 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="itemsExpandable">
<bool>false</bool>
</property>
<property name="expandsOnDoubleClick">
<bool>false</bool>
</property>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="m_lblActiveCaption">
<property name="text">
<string>Active skin</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="m_lblActiveContents">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="m_lblSelectedCaption">
<property name="text">
<string>Selected skin</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="m_lblSelectedContents">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<widget class="QLabel" name="label">
<property name="text">
<string>Newly selected skin is activated after the applicaton gets restarted!!!</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property> </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="alternatingRowColors">
<bool>false</bool>
</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>
<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> </widget>
</item> </item>
</layout> </layout>
@ -640,8 +650,20 @@
<height>16777215</height> <height>16777215</height>
</size> </size>
</property> </property>
<property name="showDropIndicator" stdset="0">
<bool>false</bool>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="movement">
<enum>QListView::Static</enum>
</property>
<property name="selectionRectVisible">
<bool>false</bool>
</property>
<property name="currentRow"> <property name="currentRow">
<number>-1</number> <number>0</number>
</property> </property>
<item> <item>
<property name="text"> <property name="text">

View file

@ -14,10 +14,6 @@ QPointer<SkinFactory> SkinFactory::s_instance;
SkinFactory::SkinFactory(QObject *parent) : QObject(parent) { SkinFactory::SkinFactory(QObject *parent) : QObject(parent) {
} }
// TODO: Skin "base/vergilius.xml" is now NEEDED for rssguard
// to run. IT IS DEFAULT skin. It sets no styles and stylesheet.
// It just contains markup for webbrowser.
SkinFactory::~SkinFactory() { SkinFactory::~SkinFactory() {
qDebug("Destroying SkinFactory instance."); qDebug("Destroying SkinFactory instance.");
} }
@ -36,14 +32,7 @@ void SkinFactory::loadCurrentSkin() {
Skin skin_data = getSkinInfo(skin_name_from_settings, &skin_parsed); Skin skin_data = getSkinInfo(skin_name_from_settings, &skin_parsed);
if (skin_parsed) { if (skin_parsed) {
loadSkinFromData(skin_data.m_rawData, skin_name_from_settings); loadSkinFromData(skin_data);
foreach (QString style, skin_data.m_stylesNames) {
if (qApp->setStyle(style) != 0) {
qDebug("Style '%s' loaded.", qPrintable(style));
break;
}
}
// Set this 'Skin' object as active one. // Set this 'Skin' object as active one.
m_currentSkin = skin_data; m_currentSkin = skin_data;
@ -51,23 +40,23 @@ void SkinFactory::loadCurrentSkin() {
qDebug("Skin '%s' loaded.", qPrintable(skin_name_from_settings)); qDebug("Skin '%s' loaded.", qPrintable(skin_name_from_settings));
} }
else { else {
qDebug("Skin '%s' not loaded because style name is not specified or skin raw data is missing. Default skin loaded.", qDebug("Skin '%s' not loaded because its data are corrupted. No skin is loaded now!",
qPrintable(skin_name_from_settings)); qPrintable(skin_name_from_settings));
} }
} }
bool SkinFactory::loadSkinFromData(QString skin_data, const QString &skin_path) { bool SkinFactory::loadSkinFromData(const Skin &skin) {
QStringList skin_parts = skin_path.split('/', QString::SkipEmptyParts); QStringList skin_parts = skin.m_baseName.split('/', QString::SkipEmptyParts);
// Skin does not contain leading folder name or the actual skin file name. // Skin does not contain leading folder name or the actual skin file name.
if (skin_parts.size() != 2) { if (skin_parts.size() != 2) {
qDebug("Loading of sking %s failed because skin name does not contain " qDebug("Loading of sking '%s' failed because skin name does not contain "
"base folder name or the actual skin name.", "base folder name or the actual skin name.",
qPrintable(skin_path)); qPrintable(skin.m_baseName));
return false; return false;
} }
else { else {
qDebug("Loading skin '%s'.", qPrintable(skin_path)); qDebug("Loading skin '%s'.", qPrintable(skin.m_baseName));
} }
// Create needed variables and create QFile object representing skin contents. // Create needed variables and create QFile object representing skin contents.
@ -78,9 +67,23 @@ bool SkinFactory::loadSkinFromData(QString skin_data, const QString &skin_path)
// //
// "##" is placeholder for the actual path to skin file. This is needed for using // "##" is placeholder for the actual path to skin file. This is needed for using
// images within the QSS file. // images within the QSS file.
QString parsed_data = skin_data.replace("##", QString raw_data = skin.m_rawData;
APP_SKIN_PATH + "/" + skin_folder + "/images");
qApp->setStyleSheet(parsed_data); if (!raw_data.isEmpty()) {
QString parsed_data = raw_data.replace("##",
APP_SKIN_PATH + "/" +
skin_folder + "/images");
qApp->setStyleSheet(parsed_data);
}
// Iterate supported styles and load one.
foreach (QString style, skin.m_stylesNames) {
if (qApp->setStyle(style) != 0) {
qDebug("Style '%s' loaded.", qPrintable(style));
break;
}
}
return true; return true;
} }
@ -91,11 +94,7 @@ void SkinFactory::setCurrentSkinName(const QString &skin_name) {
QString SkinFactory::getSelectedSkinName() { QString SkinFactory::getSelectedSkinName() {
return Settings::getInstance()->value(APP_CFG_GUI, return Settings::getInstance()->value(APP_CFG_GUI,
"skin", "skin",
"base/vergilius.xml").toString(); APP_SKIN_DEFAULT).toString();
}
QString SkinFactory::getCurrentSkinName() {
return m_currentSkin.m_baseName;
} }
QString SkinFactory::getCurrentMarkup() { QString SkinFactory::getCurrentMarkup() {
@ -112,6 +111,7 @@ Skin SkinFactory::getSkinInfo(const QString &skin_name, bool *ok) {
if (ok) { if (ok) {
*ok = false; *ok = false;
} }
return skin; return skin;
} }
@ -128,7 +128,7 @@ Skin SkinFactory::getSkinInfo(const QString &skin_name, bool *ok) {
// Obtain style name. // Obtain style name.
query.setQuery("string(/skin/style)"); query.setQuery("string(/skin/style)");
query.evaluateTo(&styles); query.evaluateTo(&styles);
skin.m_stylesNames = styles.remove("\n").split(","); skin.m_stylesNames = styles.remove("\n").split(",", QString::SkipEmptyParts);
// Obtain author. // Obtain author.
query.setQuery("string(/skin/author/name)"); query.setQuery("string(/skin/author/name)");

View file

@ -20,6 +20,13 @@ struct Skin {
Q_DECLARE_METATYPE(Skin) Q_DECLARE_METATYPE(Skin)
// TODO: Skin "base/vergilius.xml" is now NEEDED for rssguard
// to run. IT IS DEFAULT skin. It sets no styles and stylesheet.
// It just contains markup for webbrowser.
// NOTE: Check skins "base/vergilius.xml" and "luxuous.xml"
// for skin syntax reference. Note that <markup> and <data> tags
// have contents encoded in Base64.
class SkinFactory : public QObject { class SkinFactory : public QObject {
Q_OBJECT Q_OBJECT
@ -29,7 +36,7 @@ class SkinFactory : public QObject {
// Loads the skin from give skin_data. // Loads the skin from give skin_data.
// NOTE: Extra relative path escaping is done for loading of // NOTE: Extra relative path escaping is done for loading of
// external resources. // external resources.
bool loadSkinFromData(QString skin_data, const QString &skin_path); bool loadSkinFromData(const Skin &skin);
public: public:
// Singleton getter. // Singleton getter.
@ -41,10 +48,6 @@ class SkinFactory : public QObject {
// Loads skin name from settings and sets it as active. // Loads skin name from settings and sets it as active.
void loadCurrentSkin(); void loadCurrentSkin();
// Returns the name of the currently activated skin.
// NOTE: Skin name is formatted as "<folder>/<skin>.xml".
QString getCurrentSkinName();
// Returns contents of current layout markup. // Returns contents of current layout markup.
QString getCurrentMarkup(); QString getCurrentMarkup();