From 4c142f6b4483c191c880b23c84199a3b2022ce01 Mon Sep 17 00:00:00 2001 From: "Tim E. Real" Date: Sun, 21 Nov 2010 03:48:35 +0000 Subject: Style sheet support. See ChangeLog. --- muse2/ChangeLog | 2 ++ muse2/muse/app.cpp | 47 +++++++++++++++++++++++++++++++--- muse2/muse/app.h | 3 ++- muse2/muse/appearance.cpp | 44 +++++++++++++++++++++++++++++-- muse2/muse/appearance.h | 2 ++ muse2/muse/conf.cpp | 3 +++ muse2/muse/gconfig.cpp | 1 + muse2/muse/gconfig.h | 1 + muse2/muse/widgets/appearancebase.ui | 36 +++++++++++++++++++++++--- muse2/muse/widgets/musewidgetsplug.cpp | 1 + 10 files changed, 131 insertions(+), 9 deletions(-) diff --git a/muse2/ChangeLog b/muse2/ChangeLog index b2d4bd33..c506bd1e 100644 --- a/muse2/ChangeLog +++ b/muse2/ChangeLog @@ -5,6 +5,8 @@ shortcutcapturedialogbase, shortcutconfigbase, aboutbox, editsysexdialogbase, editnotedialogbase, editctrlbase (Orcan) - Converted all of editevent.cpp to Qt4 (Orcan) + - Load default compiled-in style-sheet resource :/style.qss in main(). (Tim) + Added style sheet support to Appearance settings, with reset button. 19.11.2010 - Started some conversions of midieditor, pianoroll, drumedit, incl. their QGridLayouts. (Tim) - More icon conversion work (Orcan) diff --git a/muse2/muse/app.cpp b/muse2/muse/app.cpp index fb36c849..8d15ab08 100644 --- a/muse2/muse/app.cpp +++ b/muse2/muse/app.cpp @@ -37,6 +37,9 @@ #include #include #include +#include +#include +#include //Added by qt3to4: #include #include @@ -3546,6 +3549,7 @@ int main(int argc, char* argv[]) stimer->start(6000, true); } } + int i; QString optstr("ahvdDmMsP:Y:py"); @@ -3592,6 +3596,21 @@ int main(int argc, char* argv[]) } } + if(!config.styleSheetFile.isEmpty()) + { + if(debugMsg) + printf("loading style sheet <%s> \n", qPrintable(config.styleSheetFile)); + QFile cf(config.styleSheetFile); + if (cf.open(QIODevice::ReadOnly)) { + QByteArray ss = cf.readAll(); + QString sheet(QString::fromUtf8(ss.data())); + app.setStyleSheet(sheet); + cf.close(); + } + else + printf("loading style sheet <%s> failed\n", qPrintable(config.styleSheetFile)); + } + AL::initDsp(); if (debugMsg) @@ -4073,12 +4092,35 @@ void MusE::configAppearance() // loadTheme //--------------------------------------------------------- -void MusE::loadTheme(QString s) +void MusE::loadTheme(const QString& s) { if (style()->name() != s) QApplication::setStyle(s); } +//--------------------------------------------------------- +// loadStyleSheetFile +//--------------------------------------------------------- + +void MusE::loadStyleSheetFile(const QString& s) +{ + if(s.isEmpty()) + { + qApp->setStyleSheet(s); + return; + } + + QFile cf(s); + if (cf.open(QIODevice::ReadOnly)) { + QByteArray ss = cf.readAll(); + QString sheet(QString::fromUtf8(ss.data())); + qApp->setStyleSheet(sheet); + cf.close(); + } + else + printf("loading style sheet <%s> failed\n", qPrintable(s)); +} + //--------------------------------------------------------- // configChanged // - called whenever configuration has changed @@ -4092,8 +4134,7 @@ void MusE::changeConfig(bool writeFlag) writeGlobalConfiguration(); loadTheme(config.style); QApplication::setFont(config.fonts[0], true); - // Added by Tim. p3.3.6 - //printf("MusE::changeConfig writeFlag:%d emitting configChanged\n", writeFlag); + loadStyleSheetFile(config.styleSheetFile); emit configChanged(); updateConfiguration(); diff --git a/muse2/muse/app.h b/muse2/muse/app.h index 55f81f71..0994f14b 100644 --- a/muse2/muse/app.h +++ b/muse2/muse/app.h @@ -279,7 +279,8 @@ class MusE : public QMainWindow void loadProjectFile(const QString&); void loadProjectFile(const QString&, bool songTemplate, bool loadAll); void toplevelDeleted(unsigned long tl); - void loadTheme(QString); + void loadTheme(const QString&); + void loadStyleSheetFile(const QString&); bool seqRestart(); void loadTemplate(); void showBigtime(bool); diff --git a/muse2/muse/appearance.cpp b/muse2/muse/appearance.cpp index adcc51ba..baf489ea 100644 --- a/muse2/muse/appearance.cpp +++ b/muse2/muse/appearance.cpp @@ -12,6 +12,11 @@ #include #include #include +#include +#include +#include +#include +#include #include "icons.h" #include "appearance.h" @@ -193,6 +198,11 @@ Appearance::Appearance(Arranger* a, QWidget* parent) } */ + openStyleSheet->setIcon(*openIcon); + connect(openStyleSheet, SIGNAL(clicked()), SLOT(browseStyleSheet())); + defaultStyleSheet->setIcon(*openIcon); + connect(defaultStyleSheet, SIGNAL(clicked()), SLOT(setDefaultStyleSheet())); + //--------------------------------------------------- // Fonts //--------------------------------------------------- @@ -228,6 +238,7 @@ Appearance::Appearance(Arranger* a, QWidget* parent) void Appearance::resetValues() { *config = ::config; // init with global config values + styleSheetPath->setText(config->styleSheetFile); updateFonts(); palette0->setPaletteBackgroundColor(config->palette[0]); palette1->setPaletteBackgroundColor(config->palette[1]); @@ -372,13 +383,14 @@ void Appearance::apply() else config->canvasBgPixmap = currentBg; - // Added by Tim. p3.3.9 + config->styleSheetFile = styleSheetPath->text(); + config->fonts[0].setFamily(fontName0->text()); config->fonts[0].setPointSize(fontSize0->value()); config->fonts[0].setItalic(italic0->isChecked()); config->fonts[0].setBold(bold0->isChecked()); - QApplication::setFont(config->fonts[0], true); + QApplication::setFont(config->fonts[0], true); config->fonts[1].setFamily(fontName1->text()); config->fonts[1].setPointSize(fontSize1->value()); @@ -703,6 +715,34 @@ void Appearance::paletteClicked(int id) } } +//--------------------------------------------------------- +// browseStyleSheet +//--------------------------------------------------------- + +void Appearance::browseStyleSheet() +{ + QString path; + if(!config->styleSheetFile.isEmpty()) + { + QFileInfo info(config->styleSheetFile); + path = info.absolutePath(); + } + + QString file = QFileDialog::getOpenFileName(this, tr("Select style sheet"), path, tr("Qt style sheets (*.qss)")); + styleSheetPath->setText(file); +} + + +//--------------------------------------------------------- +// setDefaultStyleSheet +//--------------------------------------------------------- + +void Appearance::setDefaultStyleSheet() +{ + // Set the style sheet to the default compiled-in resource :/style.qss + styleSheetPath->setText(QString(":/style.qss")); +} + //--------------------------------------------------------- // browseFont //--------------------------------------------------------- diff --git a/muse2/muse/appearance.h b/muse2/muse/appearance.h index e2755aef..de0ceb31 100644 --- a/muse2/muse/appearance.h +++ b/muse2/muse/appearance.h @@ -32,6 +32,8 @@ class Appearance : public QDialog, public Ui::AppearanceDialogBase { void configBackground(); void clearBackground(); void colorItemSelectionChanged(); + void browseStyleSheet(); + void setDefaultStyleSheet(); void browseFont(int); void browseFont0(); void browseFont1(); diff --git a/muse2/muse/conf.cpp b/muse2/muse/conf.cpp index 2f55a4a0..a704e245 100644 --- a/muse2/muse/conf.cpp +++ b/muse2/muse/conf.cpp @@ -508,6 +508,8 @@ void readConfiguration(Xml& xml, bool readOnlySequencer) if (tag == "theme") config.style = xml.parse1(); + else if (tag == "styleSheetFile") + config.styleSheetFile = xml.parse1(); else if (tag == "useOldStyleStopShortCut") config.useOldStyleStopShortCut = xml.parseInt(); else if (tag == "moveArmedCheckBox") @@ -1071,6 +1073,7 @@ void MusE::writeGlobalConfiguration(int level, Xml& xml) const //xml.intTag(level, "txDeviceId", txDeviceId); //xml.intTag(level, "rxDeviceId", rxDeviceId); xml.strTag(level, "theme", config.style); + xml.strTag(level, "styleSheetFile", config.styleSheetFile); xml.strTag(level, "externalWavEditor", config.externalWavEditor); xml.intTag(level, "useOldStyleStopShortCut", config.useOldStyleStopShortCut); xml.intTag(level, "moveArmedCheckBox", config.moveArmedCheckBox); diff --git a/muse2/muse/gconfig.cpp b/muse2/muse/gconfig.cpp index be92b6aa..00b89374 100644 --- a/muse2/muse/gconfig.cpp +++ b/muse2/muse/gconfig.cpp @@ -121,6 +121,7 @@ GlobalConfigValues config = { 5, // canvasShowPartEvent true, // canvasShowGrid; QString(""), // canvasBgPixmap; + QString(":/style.qss"), // default styleSheetFile QString(""), // style QString("sweep"), // externalWavEditor false, // useOldStyleStopShortCut diff --git a/muse2/muse/gconfig.h b/muse2/muse/gconfig.h index 454ed05d..ecef559c 100644 --- a/muse2/muse/gconfig.h +++ b/muse2/muse/gconfig.h @@ -113,6 +113,7 @@ struct GlobalConfigValues { int canvasShowPartEvent; // bool canvasShowGrid; QString canvasBgPixmap; + QString styleSheetFile; QString style; QString externalWavEditor; diff --git a/muse2/muse/widgets/appearancebase.ui b/muse2/muse/widgets/appearancebase.ui index ce046b58..dd0c1960 100644 --- a/muse2/muse/widgets/appearancebase.ui +++ b/muse2/muse/widgets/appearancebase.ui @@ -22,7 +22,7 @@ 0 - + Arranger @@ -193,7 +193,7 @@ - + Colors @@ -740,7 +740,7 @@ - + Style/Fonts @@ -834,6 +834,34 @@ + + + + + Style Sheet: + + + + + + + + + + ... + + + + + + + ... + + + + + + Qt::Vertical @@ -1417,6 +1445,8 @@ selectBgButton arrGrid themeComboBox + styleSheetPath + openStyleSheet fontName0 fontName1 fontName2 diff --git a/muse2/muse/widgets/musewidgetsplug.cpp b/muse2/muse/widgets/musewidgetsplug.cpp index 78376536..5aea4c81 100644 --- a/muse2/muse/widgets/musewidgetsplug.cpp +++ b/muse2/muse/widgets/musewidgetsplug.cpp @@ -153,6 +153,7 @@ GlobalConfigValues config = { 5, // canvasShowPartEvent false, // canvasShowGrid; QString(""), // canvasBgPixmap; + QString(""), // styleSheetFile QString(""), // style QString(""), // externalWavEditor //this line was missing 2007-01-08 (willyfoobar) false, // useOldStyleStopShortCut -- cgit v1.2.3