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>
<email>rotter.martinos@gmail.com</email>
</author>
<style></style>
<style/>
<markup>PGh0bWw+IDxoZWFkPiA8c3R5bGU+cHJle3doaXRlLXNwYWNlOnByZS13cmFwfS5oZWFkZXJ0ZXh0
e2ZvbnQtc2l6ZToxOXB4O21hcmdpbi1ib3R0b206MTBweH0uaGVhZGVye2ZvbnQtc2l6ZToxNXB4
Oy13ZWJraXQtdHJhbnNpdGlvbjpiYWNrZ3JvdW5kIDFzIGVhc2Utb3V0O2JhY2tncm91bmQ6LXdl

View File

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

View File

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

View File

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

View File

@ -69,8 +69,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>100</width>
<height>30</height>
<width>666</width>
<height>399</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
@ -115,7 +115,7 @@
<enum>QTabWidget::North</enum>
</property>
<property name="currentIndex">
<number>2</number>
<number>0</number>
</property>
<widget class="QWidget" name="m_tabIconSkin">
<attribute name="title">
@ -147,91 +147,101 @@
<rect>
<x>0</x>
<y>0</y>
<width>436</width>
<height>196</height>
<width>662</width>
<height>371</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout">
<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 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">
<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="0" column="1">
<widget class="QComboBox" name="m_cmbIconTheme"/>
</item>
<item row="1" column="0">
<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>
<item row="1" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Skins</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="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>
</item>
</layout>
@ -640,8 +650,20 @@
<height>16777215</height>
</size>
</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">
<number>-1</number>
<number>0</number>
</property>
<item>
<property name="text">

View File

@ -14,10 +14,6 @@ QPointer<SkinFactory> SkinFactory::s_instance;
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() {
qDebug("Destroying SkinFactory instance.");
}
@ -36,14 +32,7 @@ void SkinFactory::loadCurrentSkin() {
Skin skin_data = getSkinInfo(skin_name_from_settings, &skin_parsed);
if (skin_parsed) {
loadSkinFromData(skin_data.m_rawData, skin_name_from_settings);
foreach (QString style, skin_data.m_stylesNames) {
if (qApp->setStyle(style) != 0) {
qDebug("Style '%s' loaded.", qPrintable(style));
break;
}
}
loadSkinFromData(skin_data);
// Set this 'Skin' object as active one.
m_currentSkin = skin_data;
@ -51,23 +40,23 @@ void SkinFactory::loadCurrentSkin() {
qDebug("Skin '%s' loaded.", qPrintable(skin_name_from_settings));
}
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));
}
}
bool SkinFactory::loadSkinFromData(QString skin_data, const QString &skin_path) {
QStringList skin_parts = skin_path.split('/', QString::SkipEmptyParts);
bool SkinFactory::loadSkinFromData(const Skin &skin) {
QStringList skin_parts = skin.m_baseName.split('/', QString::SkipEmptyParts);
// Skin does not contain leading folder name or the actual skin file name.
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.",
qPrintable(skin_path));
qPrintable(skin.m_baseName));
return false;
}
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.
@ -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
// images within the QSS file.
QString parsed_data = skin_data.replace("##",
APP_SKIN_PATH + "/" + skin_folder + "/images");
qApp->setStyleSheet(parsed_data);
QString raw_data = skin.m_rawData;
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;
}
@ -91,11 +94,7 @@ void SkinFactory::setCurrentSkinName(const QString &skin_name) {
QString SkinFactory::getSelectedSkinName() {
return Settings::getInstance()->value(APP_CFG_GUI,
"skin",
"base/vergilius.xml").toString();
}
QString SkinFactory::getCurrentSkinName() {
return m_currentSkin.m_baseName;
APP_SKIN_DEFAULT).toString();
}
QString SkinFactory::getCurrentMarkup() {
@ -112,6 +111,7 @@ Skin SkinFactory::getSkinInfo(const QString &skin_name, bool *ok) {
if (ok) {
*ok = false;
}
return skin;
}
@ -128,7 +128,7 @@ Skin SkinFactory::getSkinInfo(const QString &skin_name, bool *ok) {
// Obtain style name.
query.setQuery("string(/skin/style)");
query.evaluateTo(&styles);
skin.m_stylesNames = styles.remove("\n").split(",");
skin.m_stylesNames = styles.remove("\n").split(",", QString::SkipEmptyParts);
// Obtain author.
query.setQuery("string(/skin/author/name)");

View File

@ -20,6 +20,13 @@ struct 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 {
Q_OBJECT
@ -29,7 +36,7 @@ class SkinFactory : public QObject {
// Loads the skin from give skin_data.
// NOTE: Extra relative path escaping is done for loading of
// external resources.
bool loadSkinFromData(QString skin_data, const QString &skin_path);
bool loadSkinFromData(const Skin &skin);
public:
// Singleton getter.
@ -41,10 +48,6 @@ class SkinFactory : public QObject {
// Loads skin name from settings and sets it as active.
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.
QString getCurrentMarkup();