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
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 ; }
//

View File

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

View File

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

View File

@ -42,6 +42,7 @@ public:
virtual MainPage *qt_page() 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 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
RESOURCES = gui/VOIP_images.qrc lang/VOIP_lang.qrc
RESOURCES = gui/VOIP_images.qrc lang/VOIP_lang.qrc qss/VOIP_qss.qrc
TRANSLATIONS += \
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(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) ;
Q_INIT_RESOURCE(VOIP_images);
Q_INIT_RESOURCE(VOIP_qss);
}
void VOIPPlugin::setInterfaces(RsPlugInInterfaces &interfaces)
@ -164,8 +167,6 @@ void VOIPPlugin::setPlugInHandler(RsPluginHandler *pgHandler)
QIcon *VOIPPlugin::qt_icon() const
{
if (mIcon == NULL) {
Q_INIT_RESOURCE(VOIP_images);
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 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 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/rsversion.h>
#include <retroshare/rsplugin.h>
#include <lang/languagesupport.h>
#include "gui/settings/rsharesettings.h"
#include "gui/gxs/GxsIdDetails.h"
@ -444,50 +445,92 @@ void Rshare::resetLanguageAndStyle()
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)
{
QString locale = QLocale().name();
QString styleSheet;
/* load the default stylesheet */
QFile file(":/qss/stylesheet/qss.default");
if (file.open(QFile::ReadOnly)) {
styleSheet = QLatin1String(file.readAll()) + "\n";
file.close();
}
QStringList names;
names.push_back(""); // RetroShare
/* load locale depended default stylesheet */
file.setFileName(":/qss/stylesheet/qss." + locale);
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(":/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");
/* Get stylesheet from plugins */
if (rsPlugins) {
int count = rsPlugins->nbPlugins();
for (int i = 0; i < count; ++i) {
RsPlugin* plugin = rsPlugins->plugin(i);
if (plugin) {
QString pluginStyleSheetName = QString::fromUtf8(plugin->qt_stylesheet().c_str());
if (!pluginStyleSheetName.isEmpty()) {
names.push_back(QString("%1/%1_").arg(pluginStyleSheetName));
}
}
}
}
foreach (QString name, names) {
/* load the default stylesheet */
QFile file(QString(":/qss/stylesheet/%1qss.default").arg(name));
if (file.open(QFile::ReadOnly)) {
styleSheet += QLatin1String(file.readAll()) + "\n";
file.close();
}
/* load language depended stylesheet */
QFileInfo fileInfo(file.fileName());
file.setFileName(fileInfo.path() + "/" + fileInfo.baseName() + "_" + locale + ".lqss");
/* load locale depended default stylesheet */
file.setFileName(QString(":/qss/stylesheet/%1qss.%2").arg(name, locale));
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)) {
styleSheet += QLatin1String(file.readAll()) + "\n";
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);
}
@ -548,6 +591,7 @@ void Rshare::refreshStyleSheet(QWidget *widget, bool processChildren)
/** Initialize plugins. */
void Rshare::initPlugins()
{
loadStyleSheet(_stylesheet);
LanguageSupport::translatePlugins(_language);
}