mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-01-30 00:55:16 +01:00
Work on skins.
This commit is contained in:
parent
8a5ee09118
commit
ecaf277594
@ -6,5 +6,8 @@
|
||||
<email>rotter.martinos@gmail.com</email>
|
||||
</author>
|
||||
<style>fusion,plastique</style>
|
||||
<markup>
|
||||
<html> <head> <style>pre{white-space:pre-wrap}.headertext{font-size:19px;margin-bottom:10px}.header{font-size:15px;-webkit-transition:background 1s ease-out;background:-webkit-gradient(linear,left top,left bottom,color-stop(0%,#45484d),color-stop(100%,#000000));background:-webkit-linear-gradient(top,#45484d 0,#000000 100%);-webkit-border-radius:3px;text-shadow:0 0 1px #fff;filter:dropshadow(color=#ffffff,offx=0,offy=0);padding:8px;margin:5px auto 5px auto;color:white}.header a{color:white}.content{font-size:14px;background:-webkit-gradient(linear,left top,left bottom,color-stop(0%,rgba(238,238,238,0.66)),color-stop(100%,rgba(238,238,238,0.66)));background:-webkit-linear-gradient(top,rgba(238,238,238,0.66) 0,rgba(238,238,238,0.66) 100%);-webkit-border-radius:3px;margin:5px auto 5px auto;padding:8px}.footer{font-size:12px;text-align:center;vertical-align:middle;-webkit-transition:background 1s ease-out;background:-webkit-gradient(linear,left top,left bottom,color-stop(0%,#45484d),color-stop(100%,#000000));background:-webkit-linear-gradient(top,#45484d 0,#000000 100%);-webkit-border-radius:3px;text-shadow:0 0 1px #fff;filter:dropshadow(color=#ffffff,offx=0,offy=0);padding:8px;margin:5px auto 5px auto;color:white}</style> <title>%1</title> </head> <body> <div class=\"header\"> <div class=\"headertext\">%1</div> %2<br> <a href=\"%3\">%3</a> </div> <div class=\"content\"> %4 </div> <div class=\"footer\"> %5 </div> </body> </html>
|
||||
</markup>
|
||||
<data/>
|
||||
</skin>
|
@ -37,6 +37,7 @@
|
||||
#define APP_CFG_CUTS "keyboard"
|
||||
#define APP_CFG_BROWSER "browser"
|
||||
|
||||
#define APP_HTML_MARKUP "styled_pattern.html"
|
||||
#define APP_DB_PATH "data/storage/database.db"
|
||||
#define APP_PREFIX "@CMAKE_INSTALL_PREFIX@"
|
||||
#define APP_REVISION "@APP_REVISION@"
|
||||
|
@ -10,7 +10,6 @@ class TextFactory {
|
||||
virtual ~TextFactory();
|
||||
|
||||
static QString shorten(const QString &input);
|
||||
|
||||
};
|
||||
|
||||
#endif // TEXTFACTORY_H
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include <QStyleOptionFrameV3>
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QWebFrame>
|
||||
#include <QContextMenuEvent>
|
||||
|
||||
@ -8,6 +10,7 @@
|
||||
#include "core/settings.h"
|
||||
#include "core/basewebpage.h"
|
||||
#include "gui/basewebview.h"
|
||||
#include "gui/skinfactory.h"
|
||||
#include "gui/iconthemefactory.h"
|
||||
|
||||
|
||||
@ -96,10 +99,12 @@ void BaseWebView::initializeActions() {
|
||||
}
|
||||
|
||||
void BaseWebView::displayErrorPage() {
|
||||
// TODO: Add better custom error page. Custom htmls are now copied during
|
||||
// "make install" to APP_HTML_PATH. It is needed to setup css absolute
|
||||
// path by replacing "##" with APP_HTML_PATH/css in "compact_text.html".
|
||||
setHtml("error", url());
|
||||
// TODO: Add better custom error page.
|
||||
setHtml(SkinFactory::getInstance()->getCurrentMarkup().arg(tr("Page not found"),
|
||||
"bbb",
|
||||
"ccc",
|
||||
"ddd",
|
||||
"eee"));
|
||||
}
|
||||
|
||||
void BaseWebView::popupContextMenu(const QPoint &pos) {
|
||||
|
@ -42,6 +42,7 @@ class BaseWebView : public QWebView {
|
||||
void popupContextMenu(const QPoint &pos);
|
||||
|
||||
protected:
|
||||
// Initializes all actions.
|
||||
void initializeActions();
|
||||
|
||||
// Creates necessary connections.
|
||||
|
@ -11,8 +11,8 @@
|
||||
|
||||
QPointer<SkinFactory> SkinFactory::s_instance;
|
||||
|
||||
SkinFactory::SkinFactory(QObject *parent)
|
||||
: QObject(parent), m_currentSkin(APP_THEME_SYSTEM) {
|
||||
SkinFactory::SkinFactory(QObject *parent) : QObject(parent) {
|
||||
m_currentSkin = generateDefaultSkin();
|
||||
}
|
||||
|
||||
SkinFactory::~SkinFactory() {
|
||||
@ -29,14 +29,18 @@ SkinFactory *SkinFactory::getInstance() {
|
||||
|
||||
void SkinFactory::loadCurrentSkin() {
|
||||
QString skin_name_from_settings = getSelectedSkinName();
|
||||
bool loaded = false;
|
||||
Skin skin_data = getSkinInfo(skin_name_from_settings, &loaded);
|
||||
|
||||
if (skin_name_from_settings == APP_THEME_SYSTEM) {
|
||||
// NOTE: No need to call qApp->setStylesheet(QString()) here.
|
||||
// User selected default skin for loading.
|
||||
// NOTE: No need to do anything here.
|
||||
qDebug("'Default system skin' loaded.");
|
||||
return;
|
||||
}
|
||||
else if (loaded) {
|
||||
|
||||
bool skin_parsed;
|
||||
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) {
|
||||
@ -46,7 +50,8 @@ void SkinFactory::loadCurrentSkin() {
|
||||
}
|
||||
}
|
||||
|
||||
m_currentSkin = skin_name_from_settings;
|
||||
// Set this 'Skin' object as active one.
|
||||
m_currentSkin = skin_data;
|
||||
|
||||
qDebug("Skin '%s' loaded.", qPrintable(skin_name_from_settings));
|
||||
}
|
||||
@ -56,6 +61,21 @@ void SkinFactory::loadCurrentSkin() {
|
||||
}
|
||||
}
|
||||
|
||||
Skin SkinFactory::generateDefaultSkin() {
|
||||
Skin default_skin;
|
||||
|
||||
default_skin.m_author = "-";
|
||||
default_skin.m_baseName = APP_THEME_SYSTEM;
|
||||
default_skin.m_email = "-";
|
||||
default_skin.m_version = "-";
|
||||
default_skin.m_visibleName = tr("default system skin");
|
||||
|
||||
// NOTE: Used http://www.htmlcompressor.com/compressor/ for compression.
|
||||
default_skin.m_layoutMarkup = "<html> <head> <style>pre{white-space:pre-wrap}.headertext{font-size:19px;margin-bottom:10px}.header{font-size:15px;-webkit-transition:background 1s ease-out;background:-webkit-gradient(linear,left top,left bottom,color-stop(0%,#45484d),color-stop(100%,#000000));background:-webkit-linear-gradient(top,#45484d 0,#000000 100%);-webkit-border-radius:3px;text-shadow:0 0 1px #fff;filter:dropshadow(color=#ffffff,offx=0,offy=0);padding:8px;margin:5px auto 5px auto;color:white}.header a{color:white}.content{font-size:14px;background:-webkit-gradient(linear,left top,left bottom,color-stop(0%,rgba(238,238,238,0.66)),color-stop(100%,rgba(238,238,238,0.66)));background:-webkit-linear-gradient(top,rgba(238,238,238,0.66) 0,rgba(238,238,238,0.66) 100%);-webkit-border-radius:3px;margin:5px auto 5px auto;padding:8px}.footer{font-size:12px;text-align:center;vertical-align:middle;-webkit-transition:background 1s ease-out;background:-webkit-gradient(linear,left top,left bottom,color-stop(0%,#45484d),color-stop(100%,#000000));background:-webkit-linear-gradient(top,#45484d 0,#000000 100%);-webkit-border-radius:3px;text-shadow:0 0 1px #fff;filter:dropshadow(color=#ffffff,offx=0,offy=0);padding:8px;margin:5px auto 5px auto;color:white}</style> <title>%1</title> </head> <body> <div class=\"header\"> <div class=\"headertext\">%1</div> %2<br> <a href=\"%3\">%3</a> </div> <div class=\"content\"> %4 </div> <div class=\"footer\"> %5 </div> </body> </html>";
|
||||
|
||||
return default_skin;
|
||||
}
|
||||
|
||||
bool SkinFactory::loadSkinFromData(QString skin_data, const QString &skin_path) {
|
||||
QStringList skin_parts = skin_path.split('/', QString::SkipEmptyParts);
|
||||
|
||||
@ -95,27 +115,30 @@ QString SkinFactory::getSelectedSkinName() {
|
||||
}
|
||||
|
||||
QString SkinFactory::getCurrentSkinName() {
|
||||
return m_currentSkin;
|
||||
return m_currentSkin.m_baseName;
|
||||
}
|
||||
|
||||
Skin SkinFactory::getSkinInfo(const QString &skin_name, bool *ok) {
|
||||
Skin skin;
|
||||
QString SkinFactory::getCurrentMarkup() {
|
||||
return m_currentSkin.m_layoutMarkup;
|
||||
}
|
||||
|
||||
Skin SkinFactory::getSkinInfo(const QString &skin_name, bool *ok) {
|
||||
if (skin_name == APP_THEME_SYSTEM) {
|
||||
skin.m_author = "-";
|
||||
skin.m_baseName = APP_THEME_SYSTEM;
|
||||
skin.m_email = "-";
|
||||
skin.m_version = "-";
|
||||
skin.m_visibleName = tr("default system skin");
|
||||
|
||||
if (ok != NULL) {
|
||||
*ok = true;
|
||||
}
|
||||
|
||||
return skin;
|
||||
if (m_currentSkin.m_baseName == APP_THEME_SYSTEM) {
|
||||
return m_currentSkin;
|
||||
}
|
||||
else {
|
||||
return generateDefaultSkin();
|
||||
}
|
||||
}
|
||||
|
||||
Skin skin;
|
||||
QXmlQuery query;
|
||||
QString styles;
|
||||
QFile skin_file(APP_SKIN_PATH + QDir::separator() + skin_name);
|
||||
|
||||
if (!skin_file.open(QIODevice::ReadOnly) || !query.setFocus(&skin_file)) {
|
||||
@ -136,7 +159,6 @@ Skin SkinFactory::getSkinInfo(const QString &skin_name, bool *ok) {
|
||||
|
||||
// Obtain style name.
|
||||
query.setQuery("string(/skin/style)");
|
||||
QString styles;
|
||||
query.evaluateTo(&styles);
|
||||
skin.m_stylesNames = styles.remove("\n").split(",");
|
||||
|
||||
@ -155,6 +177,10 @@ Skin SkinFactory::getSkinInfo(const QString &skin_name, bool *ok) {
|
||||
query.evaluateTo(&skin.m_version);
|
||||
skin.m_version = skin.m_version.remove("\n");
|
||||
|
||||
// Obtain layout markup.
|
||||
query.setQuery("string(/skin/markup)");
|
||||
query.evaluateTo(&skin.m_layoutMarkup);
|
||||
|
||||
// Obtain other information.
|
||||
skin.m_baseName = skin_name;
|
||||
|
||||
@ -174,7 +200,7 @@ Skin SkinFactory::getSkinInfo(const QString &skin_name, bool *ok) {
|
||||
QList<Skin> SkinFactory::getInstalledSkins() {
|
||||
QList<Skin> skins;
|
||||
|
||||
skins.append(getSkinInfo(APP_THEME_SYSTEM));
|
||||
skins.append(generateDefaultSkin());
|
||||
|
||||
bool skin_load_ok;
|
||||
QStringList skin_directories = QDir(APP_SKIN_PATH).entryList(QDir::Dirs |
|
||||
|
@ -15,6 +15,7 @@ struct Skin {
|
||||
QString m_email;
|
||||
QString m_version;
|
||||
QString m_rawData;
|
||||
QString m_layoutMarkup;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(Skin)
|
||||
@ -30,6 +31,9 @@ class SkinFactory : public QObject {
|
||||
// external resources.
|
||||
bool loadSkinFromData(QString skin_data, const QString &skin_path);
|
||||
|
||||
// Generates "default" skin.
|
||||
Skin generateDefaultSkin();
|
||||
|
||||
public:
|
||||
// Singleton getter.
|
||||
static SkinFactory *getInstance();
|
||||
@ -40,10 +44,13 @@ class SkinFactory : public QObject {
|
||||
// Loads skin name from settings and sets it as active.
|
||||
void loadCurrentSkin();
|
||||
|
||||
// Return the name of the currently activated skin.
|
||||
// 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();
|
||||
|
||||
// Returns the name of the skin, that should be activated
|
||||
// after application restart.
|
||||
QString getSelectedSkinName();
|
||||
@ -60,7 +67,7 @@ class SkinFactory : public QObject {
|
||||
|
||||
private:
|
||||
// Holds name of the current skin.
|
||||
QString m_currentSkin;
|
||||
Skin m_currentSkin;
|
||||
|
||||
// Singleton.
|
||||
static QPointer<SkinFactory> s_instance;
|
||||
|
Loading…
x
Reference in New Issue
Block a user