Added stylesheet to plugins.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8563 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2015-06-28 10:11:47 +00:00
parent 686fec496f
commit 3a71b8b662
14 changed files with 101 additions and 33 deletions

View File

@ -176,6 +176,7 @@ class RsPlugin
// Provide buttons for the ChatWidget // Provide buttons for the ChatWidget
virtual ChatWidgetHolder *qt_get_chat_widget_holder(ChatWidget */*chatWidget*/) const { return NULL ; } virtual ChatWidgetHolder *qt_get_chat_widget_holder(ChatWidget */*chatWidget*/) const { return NULL ; }
virtual std::string qt_stylesheet() { return ""; }
virtual QTranslator *qt_translator(QApplication * /* app */, const QString& /* languageCode */, const QString& /* externalDir */ ) const { return NULL ; } virtual QTranslator *qt_translator(QApplication * /* app */, const QString& /* languageCode */, const QString& /* externalDir */ ) const { return NULL ; }
// //

View File

@ -56,8 +56,9 @@ FORMS = gui/FeedReaderDialog.ui \
TARGET = FeedReader TARGET = FeedReader
RESOURCES = gui/FeedReader_images.qrc \ RESOURCES = gui/FeedReader_images.qrc \
lang/FeedReader_lang.qrc lang/FeedReader_lang.qrc \
qss/FeedReader_qss.qrc
TRANSLATIONS += \ TRANSLATIONS += \
lang/FeedReader_ca_ES.ts \ lang/FeedReader_ca_ES.ts \
lang/FeedReader_cs.ts \ lang/FeedReader_cs.ts \

View File

@ -84,6 +84,9 @@ FeedReaderPlugin::FeedReaderPlugin()
mFeedReader = NULL; mFeedReader = NULL;
mNotify = NULL; mNotify = NULL;
mFeedNotify = NULL; mFeedNotify = NULL;
Q_INIT_RESOURCE(FeedReader_images);
Q_INIT_RESOURCE(FeedReader_qss);
} }
void FeedReaderPlugin::setInterfaces(RsPlugInInterfaces &interfaces) void FeedReaderPlugin::setInterfaces(RsPlugInInterfaces &interfaces)
@ -143,8 +146,6 @@ void FeedReaderPlugin::setPlugInHandler(RsPluginHandler *pgHandler)
QIcon *FeedReaderPlugin::qt_icon() const QIcon *FeedReaderPlugin::qt_icon() const
{ {
if (mIcon == NULL) { if (mIcon == NULL) {
Q_INIT_RESOURCE(FeedReader_images);
mIcon = new QIcon(IMAGE_FEEDREADER); mIcon = new QIcon(IMAGE_FEEDREADER);
} }

View File

@ -42,6 +42,7 @@ public:
virtual MainPage *qt_page() const; virtual MainPage *qt_page() const;
virtual QIcon *qt_icon() const; virtual QIcon *qt_icon() const;
virtual std::string qt_stylesheet() { return "FeedReader"; }
virtual QTranslator *qt_translator(QApplication *app, const QString& languageCode, const QString& externalDir) const; virtual QTranslator *qt_translator(QApplication *app, const QString& languageCode, const QString& externalDir) const;
virtual void getPluginVersion(int &major, int &minor, int &build, int &svn_rev) const; virtual void getPluginVersion(int &major, int &minor, int &build, int &svn_rev) const;

View File

@ -0,0 +1 @@
/* Standard stylesheet for FeedReader */

View File

@ -0,0 +1,2 @@
/* Default stylesheet
This file is used as default for all stylesheets and can be overloaded */

View File

@ -0,0 +1,6 @@
<RCC>
<qresource prefix="/qss/stylesheet/FeedReader">
<file>FeedReader_qss.default</file>
<file>FeedReader_Standard.qss</file>
</qresource>
</RCC>

View File

@ -73,7 +73,7 @@ FORMS = gui/AudioInputConfig.ui \
TARGET = VOIP TARGET = VOIP
RESOURCES = gui/VOIP_images.qrc lang/VOIP_lang.qrc RESOURCES = gui/VOIP_images.qrc lang/VOIP_lang.qrc qss/VOIP_qss.qrc
TRANSLATIONS += \ TRANSLATIONS += \
lang/VOIP_ca_ES.ts \ lang/VOIP_ca_ES.ts \

View File

@ -95,6 +95,9 @@ VOIPPlugin::VOIPPlugin()
QObject::connect(mVOIPNotify,SIGNAL(voipAcceptReceived(const RsPeerId&)),mVOIPGUIHandler,SLOT(ReceivedVoipAccept(const RsPeerId&)),Qt::QueuedConnection) ; QObject::connect(mVOIPNotify,SIGNAL(voipAcceptReceived(const RsPeerId&)),mVOIPGUIHandler,SLOT(ReceivedVoipAccept(const RsPeerId&)),Qt::QueuedConnection) ;
QObject::connect(mVOIPNotify,SIGNAL(voipHangUpReceived(const RsPeerId&)),mVOIPGUIHandler,SLOT(ReceivedVoipHangUp(const RsPeerId&)),Qt::QueuedConnection) ; QObject::connect(mVOIPNotify,SIGNAL(voipHangUpReceived(const RsPeerId&)),mVOIPGUIHandler,SLOT(ReceivedVoipHangUp(const RsPeerId&)),Qt::QueuedConnection) ;
QObject::connect(mVOIPNotify,SIGNAL(voipBandwidthInfoReceived(const RsPeerId&,int)),mVOIPGUIHandler,SLOT(ReceivedVoipBandwidthInfo(const RsPeerId&,int)),Qt::QueuedConnection) ; QObject::connect(mVOIPNotify,SIGNAL(voipBandwidthInfoReceived(const RsPeerId&,int)),mVOIPGUIHandler,SLOT(ReceivedVoipBandwidthInfo(const RsPeerId&,int)),Qt::QueuedConnection) ;
Q_INIT_RESOURCE(VOIP_images);
Q_INIT_RESOURCE(VOIP_qss);
} }
void VOIPPlugin::setInterfaces(RsPlugInInterfaces &interfaces) void VOIPPlugin::setInterfaces(RsPlugInInterfaces &interfaces)
@ -164,8 +167,6 @@ void VOIPPlugin::setPlugInHandler(RsPluginHandler *pgHandler)
QIcon *VOIPPlugin::qt_icon() const QIcon *VOIPPlugin::qt_icon() const
{ {
if (mIcon == NULL) { if (mIcon == NULL) {
Q_INIT_RESOURCE(VOIP_images);
mIcon = new QIcon(IMAGE_VOIP); mIcon = new QIcon(IMAGE_VOIP);
} }

View File

@ -43,6 +43,7 @@ class VOIPPlugin: public RsPlugin
virtual ChatWidgetHolder *qt_get_chat_widget_holder(ChatWidget *chatWidget) const ; virtual ChatWidgetHolder *qt_get_chat_widget_holder(ChatWidget *chatWidget) const ;
virtual QIcon *qt_icon() const; virtual QIcon *qt_icon() const;
virtual std::string qt_stylesheet() { return "VOIP"; }
virtual QTranslator *qt_translator(QApplication *app, const QString& languageCode, const QString& externalDir) const; virtual QTranslator *qt_translator(QApplication *app, const QString& languageCode, const QString& externalDir) const;
virtual void qt_sound_events(SoundEvents &events) const; virtual void qt_sound_events(SoundEvents &events) const;

View File

@ -0,0 +1 @@
/* Standard stylesheet for FeedReader */

View File

@ -0,0 +1,2 @@
/* Default stylesheet
This file is used as default for all stylesheets and can be overloaded */

View File

@ -0,0 +1,6 @@
<RCC>
<qresource prefix="/qss/stylesheet/VOIP">
<file>VOIP_qss.default</file>
<file>VOIP_Standard.qss</file>
</qresource>
</RCC>

View File

@ -38,6 +38,7 @@
#include <retroshare/rsinit.h> #include <retroshare/rsinit.h>
#include <retroshare/rsversion.h> #include <retroshare/rsversion.h>
#include <retroshare/rsplugin.h>
#include <lang/languagesupport.h> #include <lang/languagesupport.h>
#include "gui/settings/rsharesettings.h" #include "gui/settings/rsharesettings.h"
#include "gui/gxs/GxsIdDetails.h" #include "gui/gxs/GxsIdDetails.h"
@ -444,50 +445,92 @@ void Rshare::resetLanguageAndStyle()
setSheet(_args.value(ARG_GUISTYLESHEET)); setSheet(_args.value(ARG_GUISTYLESHEET));
} }
// RetroShare:
// Default:
// :/qss/stylesheet/qss.default
// :/qss/stylesheet/qss.<locale>
// Internal:
// :/qss/stylesheet/<name>.qss
// External:
// <ConfigDirectory|DataDirectory>/qss/<name>.qss
// Language depended stylesheet
// <Internal|External>_<locale>.lqss
//
// Plugin:
// Default:
// :/qss/stylesheet/<plugin>/<plugin>_qss.default
// :/qss/stylesheet/<plugin>/<plugin>_qss.<locale>
// Internal:
// :/qss/stylesheet/<plugin>/<plugin>_<name>.qss
// External:
// <ConfigDirectory|DataDirectory>/qss/<plugin>/<plugin>_<name>.qss
// Language depended stylesheet
// <Internal|External>_<locale>.lqss
void Rshare::loadStyleSheet(const QString &sheetName) void Rshare::loadStyleSheet(const QString &sheetName)
{ {
QString locale = QLocale().name(); QString locale = QLocale().name();
QString styleSheet; QString styleSheet;
/* load the default stylesheet */ QStringList names;
QFile file(":/qss/stylesheet/qss.default"); names.push_back(""); // RetroShare
if (file.open(QFile::ReadOnly)) {
styleSheet = QLatin1String(file.readAll()) + "\n";
file.close();
}
/* load locale depended default stylesheet */ /* Get stylesheet from plugins */
file.setFileName(":/qss/stylesheet/qss." + locale); if (rsPlugins) {
if (file.open(QFile::ReadOnly)) { int count = rsPlugins->nbPlugins();
styleSheet = QLatin1String(file.readAll()) + "\n"; for (int i = 0; i < count; ++i) {
file.close(); RsPlugin* plugin = rsPlugins->plugin(i);
} if (plugin) {
QString pluginStyleSheetName = QString::fromUtf8(plugin->qt_stylesheet().c_str());
if (!sheetName.isEmpty()) { if (!pluginStyleSheetName.isEmpty()) {
/* load stylesheet */ names.push_back(QString("%1/%1_").arg(pluginStyleSheetName));
if (sheetName.left(1) == ":") { }
/* internal stylesheet */
file.setFileName(":/qss/stylesheet/" + sheetName.mid(1) + ".qss");
} else {
/* external stylesheet */
file.setFileName(QString::fromUtf8(RsAccounts::ConfigDirectory().c_str()) + "/qss/" + sheetName + ".qss");
if (!file.exists()) {
file.setFileName(QString::fromUtf8(RsAccounts::DataDirectory().c_str()) + "/qss/" + sheetName + ".qss");
} }
} }
}
foreach (QString name, names) {
/* load the default stylesheet */
QFile file(QString(":/qss/stylesheet/%1qss.default").arg(name));
if (file.open(QFile::ReadOnly)) { if (file.open(QFile::ReadOnly)) {
styleSheet += QLatin1String(file.readAll()) + "\n"; styleSheet += QLatin1String(file.readAll()) + "\n";
file.close(); file.close();
}
/* load language depended stylesheet */ /* load locale depended default stylesheet */
QFileInfo fileInfo(file.fileName()); file.setFileName(QString(":/qss/stylesheet/%1qss.%2").arg(name, locale));
file.setFileName(fileInfo.path() + "/" + fileInfo.baseName() + "_" + locale + ".lqss"); if (file.open(QFile::ReadOnly)) {
styleSheet += QLatin1String(file.readAll()) + "\n";
file.close();
}
if (!sheetName.isEmpty()) {
/* load stylesheet */
if (sheetName.left(1) == ":") {
/* internal stylesheet */
file.setFileName(QString(":/qss/stylesheet/%1%2.qss").arg(name, sheetName.mid(1)));
} else {
/* external stylesheet */
file.setFileName(QString("%1/qss/%2%3.qss").arg(QString::fromUtf8(RsAccounts::ConfigDirectory().c_str()), name, sheetName));
if (!file.exists()) {
file.setFileName(QString("%1/qss/%2%3.qss").arg(QString::fromUtf8(RsAccounts::DataDirectory().c_str()), name, sheetName));
}
}
if (file.open(QFile::ReadOnly)) { if (file.open(QFile::ReadOnly)) {
styleSheet += QLatin1String(file.readAll()) + "\n"; styleSheet += QLatin1String(file.readAll()) + "\n";
file.close(); file.close();
/* load language depended stylesheet */
QFileInfo fileInfo(file.fileName());
file.setFileName(fileInfo.path() + "/" + fileInfo.baseName() + "_" + locale + ".lqss");
if (file.open(QFile::ReadOnly)) {
styleSheet += QLatin1String(file.readAll()) + "\n";
file.close();
}
} }
} }
} }
qApp->setStyleSheet(styleSheet); qApp->setStyleSheet(styleSheet);
} }
@ -548,6 +591,7 @@ void Rshare::refreshStyleSheet(QWidget *widget, bool processChildren)
/** Initialize plugins. */ /** Initialize plugins. */
void Rshare::initPlugins() void Rshare::initPlugins()
{ {
loadStyleSheet(_stylesheet);
LanguageSupport::translatePlugins(_language); LanguageSupport::translatePlugins(_language);
} }