diff options
Diffstat (limited to 'muse2')
-rw-r--r-- | muse2/ChangeLog | 2 | ||||
-rw-r--r-- | muse2/muse/appearance.cpp | 182 | ||||
-rw-r--r-- | muse2/muse/appearance.h | 8 | ||||
-rw-r--r-- | muse2/muse/arranger/arranger.h | 2 | ||||
-rw-r--r-- | muse2/muse/conf.cpp | 3 | ||||
-rw-r--r-- | muse2/muse/gconfig.cpp | 1 | ||||
-rw-r--r-- | muse2/muse/gconfig.h | 1 | ||||
-rw-r--r-- | muse2/muse/widgets/appearancebase.ui | 73 |
8 files changed, 206 insertions, 66 deletions
diff --git a/muse2/ChangeLog b/muse2/ChangeLog index d8f1fb53..4b8bfd2f 100644 --- a/muse2/ChangeLog +++ b/muse2/ChangeLog @@ -1,3 +1,5 @@ +25.12.2010: + - Added fancy background selection widget with live preview to Appearance Settings. (Orcan) 23.12.2010: - MidiTrackInfo is now self-contained. (Tim) Moved all of its members from Arranger into MidiTrackInfo. Removed trackinfo.cpp diff --git a/muse2/muse/appearance.cpp b/muse2/muse/appearance.cpp index 93936e00..db983cae 100644 --- a/muse2/muse/appearance.cpp +++ b/muse2/muse/appearance.cpp @@ -4,8 +4,6 @@ // $Id: appearance.cpp,v 1.11.2.5 2009/11/14 03:37:48 terminator356 Exp $ //========================================================= -#include <stdio.h> - #include <QAbstractButton> #include <QButtonGroup> #include <QColor> @@ -16,6 +14,7 @@ #include <QFile> #include <QFileDialog> #include <QFileInfo> +#include <QPainter> #include <QtGlobal> #include "icons.h" @@ -31,6 +30,42 @@ #include "conf.h" #include "gconfig.h" +int BG_ITEM_HEIGHT = 30; + +class BgPreviewWidget : public QWidget { + QPixmap pixmap; + QString imagefile; + QTreeWidget* t_widget; + int text_h; + int text_w; + + protected: + void paintEvent(QPaintEvent* event) + { + QPainter p(this); + int w = t_widget->width() - 65; + p.drawTiledPixmap(1,1,w,BG_ITEM_HEIGHT-2, pixmap); + + // We can also draw a rectangle behind the text: + //const QPalette& pal = palette(); + //QColor dark = pal.dark().color(); + //p.fillRect(QRect(w/2 - text_w/2,6,text_w + 20,text_h+4), dark); + + QFontMetrics fm = p.fontMetrics(); + text_w = fm.width(imagefile); + text_h = fm.height(); + p.drawText(w/2 - text_w/2,6, text_w + 20, text_h+4, Qt::AlignCenter, imagefile); + QWidget::paintEvent(event); + } + public: + BgPreviewWidget(QString imagepath, QTreeWidget *treewidget) + { + pixmap = QPixmap(imagepath); + imagefile = imagepath.right(imagepath.length() - imagepath.lastIndexOf("/") - 1 ); + t_widget = treewidget; + } + }; + //--------------------------------------------------------- // IdListViewItem //--------------------------------------------------------- @@ -57,7 +92,7 @@ class IdListViewItem : public QTreeWidgetItem { //--------------------------------------------------------- Appearance::Appearance(Arranger* a, QWidget* parent) - : QDialog(parent) + : QDialog(parent, Qt::Window) { setupUi(this); arr = a; @@ -77,12 +112,11 @@ Appearance::Appearance(Arranger* a, QWidget* parent) // ARRANGER + global_bg = new QTreeWidgetItem(backgroundTree, QStringList(tr("Standard")), 0); + global_bg->setFlags(Qt::ItemIsEnabled); + user_bg = new QTreeWidgetItem(backgroundTree, QStringList(tr("Custom")), 0); + user_bg->setFlags(Qt::ItemIsEnabled); /* - currentBg = ::config.canvasBgPixmap; - if (currentBg.isEmpty()) - currentBg = "<none>"; - currentBgLabel->setText(currentBg); - partShownames->setChecked(config->canvasShowPartType & 1); partShowevents->setChecked(config->canvasShowPartType & 2); partShowCakes->setChecked(!(config->canvasShowPartType & 2)); @@ -229,7 +263,8 @@ Appearance::Appearance(Arranger* a, QWidget* parent) connect(applyButton, SIGNAL(clicked()), SLOT(apply())); connect(okButton, SIGNAL(clicked()), SLOT(ok())); connect(cancelButton, SIGNAL(clicked()), SLOT(cancel())); - connect(selectBgButton, SIGNAL(clicked()), SLOT(configBackground())); + connect(addBgButton, SIGNAL(clicked()), SLOT(addBackground())); + connect(removeBgButton, SIGNAL(clicked()), SLOT(removeBackground())); connect(clearBgButton, SIGNAL(clicked()), SLOT(clearBackground())); connect(partShowevents, SIGNAL(toggled(bool)), eventButtonGroup, SLOT(setEnabled(bool))); //updateColor(); @@ -279,11 +314,44 @@ void Appearance::resetValues() palette14->setPalette(pal); pal.setColor(palette15->backgroundRole(), config->palette[15]); palette15->setPalette(pal); - - currentBg = ::config.canvasBgPixmap; - if (currentBg.isEmpty()) - currentBg = tr("<none>"); - currentBgLabel->setText(currentBg); + + global_bg->takeChildren(); + user_bg->takeChildren(); + + QDir bgdir = museGlobalShare + "/wallpapers/"; + QStringList filters; + filters << "*.jpg" << "*.jpeg" << "*.gif"; + bgdir.setNameFilters(filters); + backgroundTree->model()->setData(backgroundTree->model()->index(0,0), + QVariant(QSize(200,BG_ITEM_HEIGHT)), + Qt::SizeHintRole); + QStringList bglist = bgdir.entryList(QDir::Files, QDir::Name); + foreach (const QString &bgfile, bglist) + { + QTreeWidgetItem* item = new QTreeWidgetItem(global_bg, 0); + item->setData(0, Qt::UserRole, QVariant(museGlobalShare + "/wallpapers/" + bgfile)); + BgPreviewWidget* bgw = new BgPreviewWidget(museGlobalShare + "/wallpapers/" + bgfile, backgroundTree); + backgroundTree->setItemWidget(item, 0, bgw); + if (config->canvasBgPixmap == museGlobalShare + "/wallpapers/" + bgfile) + backgroundTree->setCurrentItem(item); + } + + foreach (const QString &bgfile, config->canvasCustomBgList) + { + QTreeWidgetItem* item = new QTreeWidgetItem(user_bg, 0); + BgPreviewWidget* bgw = new BgPreviewWidget(bgfile, backgroundTree); + backgroundTree->setItemWidget(item, 0, bgw); + item->setData(0, Qt::UserRole, QVariant(bgfile)); + if (config->canvasBgPixmap == bgfile) + backgroundTree->setCurrentItem(item); + } + + removeBgButton->setEnabled(false); + + backgroundTree->expandAll(); + connect(backgroundTree, + SIGNAL(itemClicked(QTreeWidgetItem*, int )), + SLOT(bgSelectionChanged(QTreeWidgetItem*))); partShownames->setChecked(config->canvasShowPartType & 1); partShowevents->setChecked(config->canvasShowPartType & 2); @@ -324,6 +392,30 @@ void Appearance::resetValues() } + +//--------------------------------------------------------- +// bgSelectionChanged +//--------------------------------------------------------- + +void Appearance::bgSelectionChanged(QTreeWidgetItem* item) + { + if (item->text(0).length() && lastSelectedBgItem) + { + backgroundTree->setCurrentItem(lastSelectedBgItem); + item = lastSelectedBgItem; + } + + removeBgButton->setEnabled(false); + + QTreeWidgetItem* parent = item->parent(); + if (parent) + if (parent->text(0) == user_bg->text(0)) + removeBgButton->setEnabled(true); + + lastSelectedBgItem = item; + muse->arranger->getCanvas()->setBg(QPixmap(item->data(0, Qt::UserRole).toString())); + } + //--------------------------------------------------------- // Appearance //--------------------------------------------------------- @@ -410,10 +502,16 @@ void Appearance::apply() config->canvasShowPartEvent = showPartEvent; - if (currentBg == tr("<none>")) + QTreeWidgetItem* cbgitem = backgroundTree->currentItem(); + + if (cbgitem) + config->canvasBgPixmap = cbgitem->data(0, Qt::UserRole).toString(); + else config->canvasBgPixmap = QString(); - else - config->canvasBgPixmap = currentBg; + + config->canvasCustomBgList = QStringList(); + for (int i = 0; i < user_bg->childCount(); ++i) + config->canvasCustomBgList << user_bg->child(i)->data(0, Qt::UserRole).toString(); config->styleSheetFile = styleSheetPath->text(); @@ -483,23 +581,48 @@ void Appearance::ok() void Appearance::cancel() { + muse->arranger->getCanvas()->setBg(QPixmap(config->canvasBgPixmap)); close(); } //--------------------------------------------------------- -// configBackground +// removeBackground //--------------------------------------------------------- -void Appearance::configBackground() +void Appearance::removeBackground() { - QString cur(currentBg); - if (cur == tr("<none>")) - cur = museGlobalShare + "/wallpapers"; - currentBg = getImageFileName(cur, image_file_pattern, this, - tr("MusE: load image")); - if (currentBg.isEmpty()) - currentBg = tr("<none>"); - currentBgLabel->setText(currentBg); + QTreeWidgetItem* item = backgroundTree->currentItem(); + muse->arranger->getCanvas()->setBg(QPixmap()); + user_bg->takeChild(user_bg->indexOfChild(item)); + backgroundTree->setCurrentItem (0); + removeBgButton->setEnabled(false); + } + +//--------------------------------------------------------- +// addBackground +//--------------------------------------------------------- + +void Appearance::addBackground() + { + QString cur = getenv("HOME"); + QString user_bgfile = getImageFileName(cur, image_file_pattern, this, + tr("MusE: load image")); + + bool image_exists = false; + for (int i = 0; i < global_bg->childCount(); ++i) + if (global_bg->child(i)->data(0, Qt::UserRole).toString() == user_bgfile) + image_exists = true; + for (int i = 0; i < user_bg->childCount(); ++i) + if (user_bg->child(i)->data(0, Qt::UserRole).toString() == user_bgfile) + image_exists = true; + + if (! image_exists) + { + QTreeWidgetItem* item = new QTreeWidgetItem(user_bg, 0); + item->setData(0, Qt::UserRole, QVariant(user_bgfile)); + BgPreviewWidget* bgw = new BgPreviewWidget(user_bgfile, backgroundTree); + backgroundTree->setItemWidget(item, 0, bgw); + } } //--------------------------------------------------------- @@ -508,8 +631,9 @@ void Appearance::configBackground() void Appearance::clearBackground() { - currentBg = tr("<none>"); - currentBgLabel->setText(currentBg); + muse->arranger->getCanvas()->setBg(QPixmap()); + backgroundTree->setCurrentItem (0); + removeBgButton->setEnabled(false); } //--------------------------------------------------------- diff --git a/muse2/muse/appearance.h b/muse2/muse/appearance.h index daedc2ce..851888b8 100644 --- a/muse2/muse/appearance.h +++ b/muse2/muse/appearance.h @@ -17,9 +17,11 @@ class GlobalConfigValues; class Appearance : public QDialog, public Ui::AppearanceDialogBase { Arranger* arr; QColor* color; - QString currentBg; GlobalConfigValues* config; QButtonGroup* aPalette; + QTreeWidgetItem* user_bg; + QTreeWidgetItem* global_bg; + QTreeWidgetItem* lastSelectedBgItem; Q_OBJECT void updateFonts(); @@ -29,7 +31,8 @@ class Appearance : public QDialog, public Ui::AppearanceDialogBase { void apply(); void ok(); void cancel(); - void configBackground(); + void addBackground(); + void removeBackground(); void clearBackground(); void colorItemSelectionChanged(); void browseStyleSheet(); @@ -52,6 +55,7 @@ class Appearance : public QDialog, public Ui::AppearanceDialogBase { void vsliderChanged(int); void addToPaletteClicked(); void paletteClicked(int); + void bgSelectionChanged(QTreeWidgetItem*); public: Appearance(Arranger*, QWidget* parent=0); diff --git a/muse2/muse/arranger/arranger.h b/muse2/muse/arranger/arranger.h index e86444bf..c8d33a39 100644 --- a/muse2/muse/arranger/arranger.h +++ b/muse2/muse/arranger/arranger.h @@ -145,6 +145,8 @@ class Arranger : public QWidget { CMD_INSERT_PART, CMD_INSERT_EMPTYMEAS }; Arranger(QMainWindow* parent, const char* name = 0); + + PartCanvas* getCanvas() { return canvas; } void setMode(int); void reset(); diff --git a/muse2/muse/conf.cpp b/muse2/muse/conf.cpp index 44b9715c..180578e2 100644 --- a/muse2/muse/conf.cpp +++ b/muse2/muse/conf.cpp @@ -690,6 +690,8 @@ void readConfiguration(Xml& xml, bool readOnlySequencer) config.canvasShowGrid = xml.parseInt(); else if (tag == "canvasBgPixmap") config.canvasBgPixmap = xml.parse1(); + else if (tag == "canvasCustomBgList") + config.canvasCustomBgList = xml.parse1().split(";", QString::SkipEmptyParts); else if (tag == "geometryMain") config.geometryMain = readGeometry(xml, tag); else if (tag == "geometryTransport") @@ -1221,6 +1223,7 @@ void MusE::writeGlobalConfiguration(int level, Xml& xml) const xml.intTag(level, "canvasShowPartEvent", config.canvasShowPartEvent); xml.intTag(level, "canvasShowGrid", config.canvasShowGrid); xml.strTag(level, "canvasBgPixmap", config.canvasBgPixmap); + xml.strTag(level, "canvasCustomBgList", config.canvasCustomBgList.join(";")); xml.colorTag(level, "transportHandleColor", config.transportHandleColor); xml.colorTag(level, "bigtimeForegroundcolor", config.bigTimeForegroundColor); diff --git a/muse2/muse/gconfig.cpp b/muse2/muse/gconfig.cpp index 46f74d5c..f4e07c63 100644 --- a/muse2/muse/gconfig.cpp +++ b/muse2/muse/gconfig.cpp @@ -123,6 +123,7 @@ GlobalConfigValues config = { 5, // canvasShowPartEvent true, // canvasShowGrid; QString(""), // canvasBgPixmap; + QStringList(), // canvasCustomBgList QString(":/style.qss"), // default styleSheetFile QString(""), // style QString("sweep"), // externalWavEditor diff --git a/muse2/muse/gconfig.h b/muse2/muse/gconfig.h index f2287607..f9c2793a 100644 --- a/muse2/muse/gconfig.h +++ b/muse2/muse/gconfig.h @@ -114,6 +114,7 @@ struct GlobalConfigValues { int canvasShowPartEvent; // bool canvasShowGrid; QString canvasBgPixmap; + QStringList canvasCustomBgList; QString styleSheetFile; QString style; diff --git a/muse2/muse/widgets/appearancebase.ui b/muse2/muse/widgets/appearancebase.ui index 7a71f90f..0a23b73c 100644 --- a/muse2/muse/widgets/appearancebase.ui +++ b/muse2/muse/widgets/appearancebase.ui @@ -141,48 +141,52 @@ <property name="title"> <string>Background picture</string> </property> - <layout class="QHBoxLayout"> - <property name="spacing"> - <number>6</number> - </property> - <property name="margin"> - <number>11</number> - </property> + <layout class="QHBoxLayout" name="horizontalLayout_2"> <item> - <widget class="QLabel" name="currentBgLabel"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Expanding" vsizetype="Minimum"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> + <widget class="QTreeWidget" name="backgroundTree"> + <property name="uniformRowHeights"> + <bool>true</bool> </property> - <property name="text"> - <string>bg</string> + <property name="itemsExpandable"> + <bool>true</bool> </property> - <property name="alignment"> - <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> + <property name="allColumnsShowFocus"> + <bool>true</bool> </property> - <property name="wordWrap"> + <attribute name="headerVisible"> <bool>false</bool> - </property> - <property name="indent"> - <number>-1</number> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="selectBgButton"> - <property name="text"> - <string>select...</string> - </property> + </attribute> + <column> + <property name="text"> + <string notr="true">1</string> + </property> + </column> </widget> </item> <item> - <widget class="QPushButton" name="clearBgButton"> - <property name="text"> - <string>clear</string> - </property> - </widget> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <widget class="QPushButton" name="addBgButton"> + <property name="text"> + <string>add</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="removeBgButton"> + <property name="text"> + <string>remove</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="clearBgButton"> + <property name="text"> + <string>clear</string> + </property> + </widget> + </item> + </layout> </item> </layout> </widget> @@ -1469,7 +1473,6 @@ <tabstop>eventPitchbend</tabstop> <tabstop>eventProgramchange</tabstop> <tabstop>eventSpecial</tabstop> - <tabstop>selectBgButton</tabstop> <tabstop>arrGrid</tabstop> <tabstop>themeComboBox</tabstop> <tabstop>styleSheetPath</tabstop> |