implemented save stylesheets feature, but seems not work correctly, need to be fixed.save and load stylsheets works but loading saved stylsheets works at the moment when only opened the Options.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@297 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
defnax 2008-01-16 08:12:16 +00:00
parent fed8983cdb
commit 1b42c9457e
5 changed files with 83 additions and 15 deletions

View File

@ -38,22 +38,26 @@
#endif #endif
/* Rshare's Settings */ /* Retroshare's Settings */
#define SETTING_LANGUAGE "LanguageCode" #define SETTING_LANGUAGE "LanguageCode"
#define SETTING_STYLE "InterfaceStyle" #define SETTING_STYLE "InterfaceStyle"
#define SETTING_SHEETNAME "SheetName"
#define SETTING_DATA_DIRECTORY "DataDirectory" #define SETTING_DATA_DIRECTORY "DataDirectory"
#define SETTING_BWGRAPH_FILTER "StatisticDialog/BWLineFilter" #define SETTING_BWGRAPH_FILTER "StatisticDialog/BWLineFilter"
#define SETTING_BWGRAPH_OPACITY "StatisticDialog/Opacity" #define SETTING_BWGRAPH_OPACITY "StatisticDialog/Opacity"
#define SETTING_BWGRAPH_ALWAYS_ON_TOP "StatisticDialog/AlwaysOnTop" #define SETTING_BWGRAPH_ALWAYS_ON_TOP "StatisticDialog/AlwaysOnTop"
/* Default Rshare Settings */ /* Default Retroshare Settings */
#if defined(Q_WS_MAC) #if defined(Q_WS_MAC)
#define DEFAULT_STYLE "macintosh (aqua)" #define DEFAULT_STYLE "macintosh (aqua)"
#else #else
#define DEFAULT_STYLE "plastique" #define DEFAULT_STYLE "plastique"
#endif #endif
#define DEFAULT_SHEETNAME "Default"
#define DEFAULT_LANGUAGE LanguageSupport::defaultLanguageCode() #define DEFAULT_LANGUAGE LanguageSupport::defaultLanguageCode()
#define DEFAULT_OPACITY 100 #define DEFAULT_OPACITY 100
@ -154,6 +158,16 @@ void RshareSettings::setInterfaceStyle(QString styleKey)
setValue(SETTING_STYLE, styleKey); setValue(SETTING_STYLE, styleKey);
} }
/** Gets the sheetname.*/
QString RshareSettings::getSheetName()
{
return value(SETTING_SHEETNAME, DEFAULT_SHEETNAME).toString();
}
/** Sets the sheetname.*/
void RshareSettings::setSheetName(QString sheet)
{
setValue(SETTING_SHEETNAME, sheet);
}
/** Returns the bandwidth line filter. */ /** Returns the bandwidth line filter. */
uint RshareSettings::getBWGraphFilter() uint RshareSettings::getBWGraphFilter()
@ -249,4 +263,3 @@ void RshareSettings::loadWidgetInformation(QMainWindow *widget, QToolBar *toolBa
loadWidgetInformation(widget); loadWidgetInformation(widget);
} }

View File

@ -78,6 +78,12 @@ public:
/** Sets the interface style key. */ /** Sets the interface style key. */
void setInterfaceStyle(QString styleKey); void setInterfaceStyle(QString styleKey);
/** Sets the stylesheet */
void setSheetName(QString sheet);
/** Gets the stylesheet */
QString getSheetName();
/* Get the destination log file. */ /* Get the destination log file. */
QString getLogFile(); QString getLogFile();
/** Set the destination log file. */ /** Set the destination log file. */

View File

@ -47,7 +47,7 @@ GeneralDialog::GeneralDialog(QWidget *parent)
} }
ui.styleSheetCombo->setCurrentIndex(ui.styleSheetCombo->findText("Default")); ui.styleSheetCombo->setCurrentIndex(ui.styleSheetCombo->findText("Default"));
loadStyleSheet("Default"); //loadStyleSheet("Default");
loadqss(); loadqss();
} }
@ -68,6 +68,7 @@ GeneralDialog::save(QString &errmsg)
_settings->setLanguageCode(languageCode); _settings->setLanguageCode(languageCode);
_settings->setInterfaceStyle(ui.cmboStyle->currentText()); _settings->setInterfaceStyle(ui.cmboStyle->currentText());
_settings->setSheetName(ui.styleSheetCombo->currentText());
/* Set to new style */ /* Set to new style */
Rshare::setStyle(ui.cmboStyle->currentText()); Rshare::setStyle(ui.cmboStyle->currentText());
@ -83,6 +84,23 @@ GeneralDialog::load()
index = ui.cmboStyle->findData(Rshare::style().toLower()); index = ui.cmboStyle->findData(Rshare::style().toLower());
ui.cmboStyle->setCurrentIndex(index); ui.cmboStyle->setCurrentIndex(index);
index = ui.styleSheetCombo->findData(Rshare::stylesheet().toLower());
ui.styleSheetCombo->setCurrentIndex(index);
//index = ui.styleSheetCombo->findData(_settings->getSheetName());
//ui.styleSheetCombo->setCurrentIndex(index);
/* load internal styleSheet */
//QFile file(":/qss/" + (_settings->getSheetName().toLower()) + ".qss");
/** load extern Stylesheets **/
QFile file(QApplication::applicationDirPath() + "/qss/" + (_settings->getSheetName().toLower()) + ".qss");
file.open(QFile::ReadOnly);
QString styleSheet = QLatin1String(file.readAll());
qApp->setStyleSheet(styleSheet);
} }
void GeneralDialog::on_styleSheetCombo_activated(const QString &sheetName) void GeneralDialog::on_styleSheetCombo_activated(const QString &sheetName)
@ -92,8 +110,12 @@ void GeneralDialog::on_styleSheetCombo_activated(const QString &sheetName)
void GeneralDialog::loadStyleSheet(const QString &sheetName) void GeneralDialog::loadStyleSheet(const QString &sheetName)
{ {
/** internal Stylesheets **/
//QFile file(":/qss/" + sheetName.toLower() + ".qss"); //QFile file(":/qss/" + sheetName.toLower() + ".qss");
/** extern Stylesheets **/
QFile file(QApplication::applicationDirPath() + "/qss/" + sheetName.toLower() + ".qss"); QFile file(QApplication::applicationDirPath() + "/qss/" + sheetName.toLower() + ".qss");
file.open(QFile::ReadOnly); file.open(QFile::ReadOnly);
QString styleSheet = QLatin1String(file.readAll()); QString styleSheet = QLatin1String(file.readAll());

View File

@ -34,6 +34,7 @@
/* Available command-line arguments. */ /* Available command-line arguments. */
#define ARG_LANGUAGE "lang" /**< Argument specifying language. */ #define ARG_LANGUAGE "lang" /**< Argument specifying language. */
#define ARG_GUISTYLE "style" /**< Argument specfying GUI style. */ #define ARG_GUISTYLE "style" /**< Argument specfying GUI style. */
#define ARG_GUISTYLESHEET "stylesheet" /**< Argument specfying GUI style. */
#define ARG_RESET "reset" /**< Reset Rshare's saved settings. */ #define ARG_RESET "reset" /**< Reset Rshare's saved settings. */
#define ARG_DATADIR "datadir" /**< Directory to use for data files. */ #define ARG_DATADIR "datadir" /**< Directory to use for data files. */
@ -42,6 +43,7 @@
QMap<QString, QString> Rshare::_args; /**< List of command-line arguments. */ QMap<QString, QString> Rshare::_args; /**< List of command-line arguments. */
QString Rshare::_style; /**< The current GUI style. */ QString Rshare::_style; /**< The current GUI style. */
QString Rshare::_language; /**< The current language. */ QString Rshare::_language; /**< The current language. */
QString Rshare::_stylesheet; /**< The current GUI style. */
bool Rshare::useConfigDir; bool Rshare::useConfigDir;
QString Rshare::configDir; QString Rshare::configDir;
@ -78,13 +80,15 @@ Rshare::Rshare(QStringList args, int &argc, char **argv, QString dir)
/** Set the GUI style appropriately. */ /** Set the GUI style appropriately. */
setStyle(_args.value(ARG_GUISTYLE)); setStyle(_args.value(ARG_GUISTYLE));
/** Set the GUI stylesheet appropriately. */
setSheet(_args.value(ARG_GUISTYLESHEET));
} }
/** Destructor */ /** Destructor */
Rshare::~Rshare() Rshare::~Rshare()
{ {
// delete _help;
//delete _torControl;
} }
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)
@ -120,6 +124,7 @@ Rshare::printUsage(QString errmsg)
out << "\t-"ARG_RESET"\t\tResets ALL stored Rshare settings." << endl; out << "\t-"ARG_RESET"\t\tResets ALL stored Rshare settings." << endl;
out << "\t-"ARG_DATADIR"\tSets the directory Rshare uses for data files"<< endl; out << "\t-"ARG_DATADIR"\tSets the directory Rshare uses for data files"<< endl;
out << "\t-"ARG_GUISTYLE"\t\tSets Rshare's interface style." << endl; out << "\t-"ARG_GUISTYLE"\t\tSets Rshare's interface style." << endl;
out << "\t-"ARG_GUISTYLESHEET"\t\tSets Rshare's stylesheet." << endl;
out << "\t\t\t[" << QStyleFactory::keys().join("|") << "]" << endl; out << "\t\t\t[" << QStyleFactory::keys().join("|") << "]" << endl;
out << "\t-"ARG_LANGUAGE"\t\tSets Rshare's language." << endl; out << "\t-"ARG_LANGUAGE"\t\tSets Rshare's language." << endl;
out << "\t\t\t[" << LanguageSupport::languageCodes().join("|") << "]" << endl; out << "\t\t\t[" << LanguageSupport::languageCodes().join("|") << "]" << endl;
@ -130,6 +135,7 @@ bool
Rshare::argNeedsValue(QString argName) Rshare::argNeedsValue(QString argName)
{ {
return (argName == ARG_GUISTYLE || return (argName == ARG_GUISTYLE ||
argName == ARG_GUISTYLESHEET ||
argName == ARG_LANGUAGE || argName == ARG_LANGUAGE ||
argName == ARG_DATADIR); argName == ARG_DATADIR);
@ -169,7 +175,7 @@ Rshare::validateArguments(QString &errmsg)
if (_args.contains(ARG_HELP)) { if (_args.contains(ARG_HELP)) {
return false; return false;
}*/ }*/
/* Check for a language that Rshare recognizes. */ /* Check for a language that Retroshare recognizes. */
if (_args.contains(ARG_LANGUAGE) && if (_args.contains(ARG_LANGUAGE) &&
!LanguageSupport::isValidLanguageCode(_args.value(ARG_LANGUAGE))) { !LanguageSupport::isValidLanguageCode(_args.value(ARG_LANGUAGE))) {
errmsg = tr("Invalid language code specified: ") + _args.value(ARG_LANGUAGE); errmsg = tr("Invalid language code specified: ") + _args.value(ARG_LANGUAGE);
@ -185,7 +191,7 @@ Rshare::validateArguments(QString &errmsg)
return true; return true;
} }
/** Sets the translation Rshare will use. If one was specified on the /** Sets the translation RetroShare will use. If one was specified on the
* command-line, we will use that. Otherwise, we'll check to see if one was * command-line, we will use that. Otherwise, we'll check to see if one was
* saved previously. If not, we'll default to one appropriate for the system * saved previously. If not, we'll default to one appropriate for the system
* locale. */ * locale. */
@ -205,7 +211,7 @@ Rshare::setLanguage(QString languageCode)
return false; return false;
} }
/** Sets the GUI style Rshare will use. If one was specified on the /** Sets the GUI style RetroShare will use. If one was specified on the
* command-line, we will use that. Otherwise, we'll check to see if one was * command-line, we will use that. Otherwise, we'll check to see if one was
* saved previously. If not, we'll default to one appropriate for the * saved previously. If not, we'll default to one appropriate for the
* operating system. */ * operating system. */
@ -225,6 +231,24 @@ Rshare::setStyle(QString styleKey)
return false; return false;
} }
bool
Rshare::setSheet(QString sheet)
{
/* If no stylesheet was specified, use the previously-saved setting */
if (sheet.isEmpty()) {
RshareSettings settings;
sheet = settings.getSheetName();
}
/* Apply the specified GUI stylesheet */
/*if (QApplication::setSheet(sheet)) {*/
_stylesheet = sheet;
return true;
/*}
return false;*/
}
/** Displays the help page associated with the specified topic. If no topic is /** Displays the help page associated with the specified topic. If no topic is
* specified, then the default help page will be displayed. */ * specified, then the default help page will be displayed. */
/**void /**void

View File

@ -60,6 +60,8 @@ public:
static bool setLanguage(QString languageCode = QString()); static bool setLanguage(QString languageCode = QString());
/** Sets the current GUI style. */ /** Sets the current GUI style. */
static bool setStyle(QString styleKey = QString()); static bool setStyle(QString styleKey = QString());
/** Sets the current GUI stylesheet. */
static bool setSheet(QString sheet = QString());
/** Shows the specified help topic, or the default if empty. */ /** Shows the specified help topic, or the default if empty. */
//static void help(QString topic = QString()); //static void help(QString topic = QString());
@ -67,11 +69,11 @@ public:
static QString language() { return _language; } static QString language() { return _language; }
/** Returns the current GUI style. */ /** Returns the current GUI style. */
static QString style() { return _style; } static QString style() { return _style; }
/** Returns the current GUI stylesheet. */
static QString stylesheet() { return _stylesheet; }
/** Returns Rshare's application version. */ /** Returns Rshare's application version. */
static QString version() { return RSHARE_VERSION; } static QString version() { return RSHARE_VERSION; }
/** Returns Rshare's main TorControl object. */
// static TorControl* torControl() { return _torControl; }
/** Returns the location Rshare uses for its data files. */ /** Returns the location Rshare uses for its data files. */
static QString dataDirectory(); static QString dataDirectory();
@ -101,6 +103,7 @@ private:
static QMap<QString, QString> _args; /**< List of command-line arguments. */ static QMap<QString, QString> _args; /**< List of command-line arguments. */
static QString _style; /**< The current GUI style. */ static QString _style; /**< The current GUI style. */
static QString _stylesheet; /**< The current GUI stylesheet. */
static QString _language; /**< The current language. */ static QString _language; /**< The current language. */
static bool useConfigDir; static bool useConfigDir;