diff --git a/MainWindow.cpp b/MainWindow.cpp index 81b57dd..0bcbb76 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -1,6 +1,8 @@ #include #include "MainWindow.h" +#include + MainWindow::MainWindow (QWidget *parent) : QMainWindow (parent) { setWindowFlags(Qt::FramelessWindowHint); @@ -85,6 +87,7 @@ int main (int argc, char **argv) { QApplication app(argc, argv); + QSettings settings ("XMMS2", "Promoe"); MainWindow *mw = new MainWindow (NULL); @@ -96,7 +99,12 @@ main (int argc, char **argv) * SkinChanged signal that will cause * all widgets to get their pixmaps */ - mw->getSkin ()->setSkin ("./CleanAMP/"); + if (!settings.contains ("skin/path")) { + settings.setValue ("skin/path", "./CleanAMP/"); + } + + mw->getSkin ()->setSkin (settings.value("skin/path").toString ()); + mw->show (); mw->setPL (playlistwin); diff --git a/Skin.cpp b/Skin.cpp index 69c3238..ab9aa97 100644 --- a/Skin.cpp +++ b/Skin.cpp @@ -100,6 +100,24 @@ Skin::setSkin (QString name) emit skinChanged(this); } +QPixmap +Skin::getPixmap (QString f, QDir dir) +{ + /* check for files in zip and check if file exists */ + + dir.setFilter (QDir::Files); + + QFileInfoList list = dir.entryInfoList(); + for (int i = 0; i < list.size(); ++i) { + QFileInfo fileInfo = list.at(i); + if (fileInfo.fileName().toLower() == f) { + return QPixmap (fileInfo.filePath()); + } + } + + return QPixmap (0,0); +} + QPixmap * Skin::getPixmap (string file) diff --git a/Skin.h b/Skin.h index 1c15e5d..71be846 100644 --- a/Skin.h +++ b/Skin.h @@ -19,6 +19,7 @@ class Skin : public QWidget ~Skin(); void setSkin (QString name); + static QPixmap getPixmap (QString, QDir); const QPixmap getItem (uint part) const { return m_items->value(part); } const QPixmap getPls (uint part) const { return m_playlist->value(part); } diff --git a/SkinChooser.cpp b/SkinChooser.cpp new file mode 100644 index 0000000..cdc20ca --- /dev/null +++ b/SkinChooser.cpp @@ -0,0 +1,64 @@ +#include "MainWindow.h" +#include "Skin.h" +#include "SkinChooser.h" + +#include +#include +#include + +SkinChooser::SkinChooser (QWidget *parent) : QMainWindow (parent) +{ + m_mw = dynamic_cast(parent); + QWidget *c = new QWidget (this); + setCentralWidget (c); + + m_vbox = new QVBoxLayout (c); + QLabel *label = new QLabel ("Available skins...", c); + label->setFont (QFont ("Helvetica", 16)); + m_vbox->addWidget (label); + + m_skin = new SkinList (c); + m_vbox->addWidget (m_skin); + + resize (500, 300); + +} + +SkinList::SkinList (QWidget *parent) : QListWidget (parent) +{ + + setIconSize (QSize (137, 58)); + + QString path; + path.append (QDir::homePath()); + path.append ("/.xmms2/clients/promoe/skins/"); + QDir d; + + d.setPath (path); + d.setFilter (QDir::Dirs); + + QFileInfoList list = d.entryInfoList(); + for (int i = 0; i < list.size(); ++i) { + QFileInfo fileInfo = list.at(i); + QDir dir (fileInfo.filePath()); + QPixmap p = Skin::getPixmap ("main.bmp", dir); + if (!p.isNull()) { + new QListWidgetItem (QIcon (p), dir.dirName(), this); + } + } + + connect (this, SIGNAL (itemClicked (QListWidgetItem *)), this, SLOT (changeSkin (QListWidgetItem *))); +} + +void +SkinList::changeSkin (QListWidgetItem *item) +{ + QSettings settings; + + SkinChooser *sc = dynamic_cast(window()); + qDebug ("change skin to %s", qPrintable (item->text())); + sc->getMW()->getSkin ()->setSkin (QDir::homePath()+"/.xmms2/clients/promoe/skins/"+item->text()); + + settings.setValue ("skin/path", QDir::homePath()+"/.xmms2/clients/promoe/skins/"+item->text()); +} + diff --git a/SkinChooser.h b/SkinChooser.h new file mode 100644 index 0000000..629d3d1 --- /dev/null +++ b/SkinChooser.h @@ -0,0 +1,33 @@ +#include "MainWindow.h" + +#include +#include +#include +#include + +class SkinList : public QListWidget +{ + Q_OBJECT + public: + SkinList (QWidget *parent); + ~SkinList () {} + + public slots: + void changeSkin (QListWidgetItem *item); +}; + +class SkinChooser : public QMainWindow +{ + public: + SkinChooser (QWidget *parent); + ~SkinChooser () {} + MainWindow *getMW (void) { return m_mw; } + + private: + QVBoxLayout *m_vbox; + SkinList *m_skin; + QLabel *m_label; + MainWindow *m_mw; + +}; + diff --git a/TitleBar.cpp b/TitleBar.cpp index c49526a..80363c7 100644 --- a/TitleBar.cpp +++ b/TitleBar.cpp @@ -1,6 +1,9 @@ #include "MainWindow.h" #include "TitleBar.h" #include "Display.h" +#include "SkinChooser.h" + +#include TitleBar::TitleBar (QWidget *parent, bool shaded) : PixWidget (parent) { @@ -11,6 +14,7 @@ TitleBar::TitleBar (QWidget *parent, bool shaded) : PixWidget (parent) setMaximumSize (275, 14); m_menubtn = new Button (this, Skin::MENUBUTTON_0, Skin::MENUBUTTON_1); + connect (m_menubtn, SIGNAL (clicked ()), this, SLOT (showMenu ())); m_menubtn->move(6, 3); m_minimize = new Button (this, Skin::MINIMIZE_0, Skin::MINIMIZE_1); @@ -27,6 +31,40 @@ TitleBar::TitleBar (QWidget *parent, bool shaded) : PixWidget (parent) } +void +TitleBar::showMenu (void) +{ + QMenu qm(this); + + QAction *a; + + a = new QAction (tr ("Theme settings"), this); + a->setShortcut (tr ("Alt+T")); + connect (a, SIGNAL (triggered ()), this, SLOT (showTheme ())); + qm.addAction (a); + a = new QAction (tr ("Application settings"), this); + a->setShortcut (tr ("Alt+A")); + qm.addAction (a); + a = new QAction (tr ("Server settings"), this); + a->setShortcut (tr ("Alt+S")); + qm.addAction (a); + qm.addSeparator (); + a = new QAction (tr ("Quit"), this); + a->setShortcut (tr ("Ctrl+Q")); + connect (a, SIGNAL (triggered ()), qApp, SLOT (quit ())); + qm.addAction (a); + + qm.exec(QPoint (window()->pos().x()+6, window()->pos().y()+3)); + +} + +void +TitleBar::showTheme () +{ + SkinChooser *sk = new SkinChooser (window()); + sk->show(); +} + void TitleBar::setPixmaps (Skin *skin) { diff --git a/TitleBar.h b/TitleBar.h index 9f1b388..7c51291 100644 --- a/TitleBar.h +++ b/TitleBar.h @@ -18,6 +18,8 @@ class TitleBar : public PixWidget public slots: void setPixmaps (Skin *skin); + void showMenu (void); + void showTheme (void); protected: void mouseDoubleClickEvent (QMouseEvent *event); diff --git a/promoe.pro b/promoe.pro index 0b44e36..e54bfed 100644 --- a/promoe.pro +++ b/promoe.pro @@ -15,7 +15,8 @@ SOURCES += XmmsQT4.cpp \ PlayStatus.cpp \ ShadedDisplay.cpp \ Playlist.cpp \ - PlaylistList.cpp + PlaylistList.cpp \ + SkinChooser.cpp HEADERS += XmmsQT4.h \ PixWidget.h \ @@ -34,7 +35,8 @@ HEADERS += XmmsQT4.h \ PlayStatus.h \ ShadedDisplay.h \ Playlist.h \ - PlaylistList.h + PlaylistList.h \ + SkinChooser.h CONFIG += link_pkgconfig CONFIG += debug warn_on