summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArno <arno@disconnect.de>2017-02-19 10:36:55 +0100
committerArno <arno@disconnect.de>2017-02-19 10:36:55 +0100
commit803959759a66d01d44d9e07b38f4220a93e57a2c (patch)
tree61f6faa0365c48a0d56a1692229e58291082062e
parent71ff4a5edade412a2d1b191eaf3f7dcd61da3e13 (diff)
downloadBeetPlayer-803959759a66d01d44d9e07b38f4220a93e57a2c.tar.gz
BeetPlayer-803959759a66d01d44d9e07b38f4220a93e57a2c.tar.bz2
BeetPlayer-803959759a66d01d44d9e07b38f4220a93e57a2c.zip
Added Menus and Globals
-rw-r--r--BeetPlayer.pro6
-rw-r--r--beetplayer.cpp35
-rw-r--r--beetplayer.h6
-rw-r--r--beetplayer.qrc1
-rw-r--r--chastity_belt.pngbin0 -> 850 bytes
-rw-r--r--globals.cpp22
-rw-r--r--globals.h25
-rw-r--r--indexerwidget.cpp22
-rw-r--r--indexerwidget.h9
9 files changed, 123 insertions, 3 deletions
diff --git a/BeetPlayer.pro b/BeetPlayer.pro
index 52d0cd2..ee39671 100644
--- a/BeetPlayer.pro
+++ b/BeetPlayer.pro
@@ -26,11 +26,13 @@ DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += main.cpp\
beetplayer.cpp \
configurationdialog.cpp \
- indexerwidget.cpp
+ indexerwidget.cpp \
+ globals.cpp
HEADERS += beetplayer.h \
configurationdialog.h \
- indexerwidget.h
+ indexerwidget.h \
+ globals.h
LIBS += -ltag
diff --git a/beetplayer.cpp b/beetplayer.cpp
index 4e4c532..5402b80 100644
--- a/beetplayer.cpp
+++ b/beetplayer.cpp
@@ -3,10 +3,13 @@
#include <QMessageBox>
#include <QApplication>
#include <QHBoxLayout>
+#include <QAction>
+#include <QMenuBar>
#include "beetplayer.h"
#include "configurationdialog.h"
#include "indexerwidget.h"
+#include "globals.h"
BeetPlayer::BeetPlayer(QWidget *parent, Qt::WindowFlags f) : QMainWindow(parent, f) {
//general setup
@@ -14,11 +17,17 @@ BeetPlayer::BeetPlayer(QWidget *parent, Qt::WindowFlags f) : QMainWindow(parent,
setMinimumWidth(1024);
setMinimumHeight(768);
openDatabase();
+ createGlobalActions();
//tabs
mTab = new QTabWidget;
IndexerWidget *indexer = new IndexerWidget;
mTab->addTab(indexer, tr("Indexer"));
+ connect(mTab, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)));
+ menuBar()->clear();
+ foreach(QMenu* m, indexer->menus()){
+ menuBar()->addMenu(m);
+ }
//layout
QHBoxLayout *mainLayout = new QHBoxLayout;
@@ -26,6 +35,12 @@ BeetPlayer::BeetPlayer(QWidget *parent, Qt::WindowFlags f) : QMainWindow(parent,
setCentralWidget(mTab);
}
+void BeetPlayer::tabChanged(int tab){
+ if(tab == 0){ //replace with indexer
+ //do something;;
+ }
+}
+
void BeetPlayer::openDatabase(){
QSettings s;
QString dbhost = s.value("dbhost").toString();
@@ -49,3 +64,23 @@ void BeetPlayer::openDatabase(){
}
}
}
+
+void BeetPlayer::createGlobalActions(){
+ QAction *quitA = new QAction(tr("Quit"), this);
+ quitA->setShortcut(tr("CTRL+Q"));
+ connect(quitA, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));
+ quitA->setData(Globals::QuitAction);
+ Globals::instance()->addAction(quitA);
+ QAction *configA = new QAction(QIcon(":/chastity_belt.png"), tr("Configure..."), this);
+ connect(configA, SIGNAL(triggered()), this, SLOT(configure()));
+ configA->setData(Globals::ConfigAction);
+ Globals::instance()->addAction(configA);
+}
+
+void BeetPlayer::configure(){
+ ConfigurationDialog w(this);
+ int res = w.exec();
+ if(res == QDialog::Accepted){
+ openDatabase();
+ }
+}
diff --git a/beetplayer.h b/beetplayer.h
index e92012f..f5169d9 100644
--- a/beetplayer.h
+++ b/beetplayer.h
@@ -9,9 +9,15 @@ class BeetPlayer : public QMainWindow {
enum Tabs { Player = 0, Indexer = 1 };
explicit BeetPlayer(QWidget *parent = 0, Qt::WindowFlags f = 0);
+ public slots:
+ void tabChanged(int tab);
+ void configure();
+
private:
void openDatabase();
+ void createGlobalActions();
QTabWidget *mTab;
+ QHash<int, QVector<QMenu*>> mMenus;
};
#endif // BEETPLAYER_H
diff --git a/beetplayer.qrc b/beetplayer.qrc
index bcf3057..3d5b764 100644
--- a/beetplayer.qrc
+++ b/beetplayer.qrc
@@ -2,5 +2,6 @@
<qresource prefix="/">
<file>beetplayer_icon.png</file>
<file>beetplayer.png</file>
+ <file>chastity_belt.png</file>
</qresource>
</RCC>
diff --git a/chastity_belt.png b/chastity_belt.png
new file mode 100644
index 0000000..ebe3390
--- /dev/null
+++ b/chastity_belt.png
Binary files differ
diff --git a/globals.cpp b/globals.cpp
new file mode 100644
index 0000000..dc4bbb2
--- /dev/null
+++ b/globals.cpp
@@ -0,0 +1,22 @@
+#include <QAction>
+
+#include "globals.h"
+
+Globals *Globals::mInstance = nullptr;
+
+Globals *Globals::instance(){
+ if(!mInstance){
+ mInstance = new Globals;
+ }
+ return mInstance;
+}
+
+void Globals::addAction(QAction *a){
+ mActions.insert(a->data().toInt(), a);
+}
+
+QAction *Globals::action(int actionType){
+ return mActions.value(actionType);
+}
+
+Globals::Globals() {}
diff --git a/globals.h b/globals.h
new file mode 100644
index 0000000..f659088
--- /dev/null
+++ b/globals.h
@@ -0,0 +1,25 @@
+#ifndef GLOBALS_H
+#define GLOBALS_H
+
+#include <QObject>
+#include <QHash>
+
+class QAction;
+
+class Globals : public QObject {
+ Q_OBJECT
+ public:
+ enum ActionType { QuitAction = 0, ConfigAction = 1 };
+ static Globals *instance();
+ void addAction(QAction *a);
+ QAction *action(int actionType);
+
+ private:
+ Globals();
+ Globals(const Globals &other);
+ Globals &operator=(const Globals &other);
+ static Globals *mInstance;
+ QHash<int, QAction*> mActions;
+};
+
+#endif // GLOBALS_H
diff --git a/indexerwidget.cpp b/indexerwidget.cpp
index 337f20c..84f2598 100644
--- a/indexerwidget.cpp
+++ b/indexerwidget.cpp
@@ -7,9 +7,12 @@
#include <QCursor>
#include <QSqlQuery>
#include <QFileInfo>
+#include <QAction>
+#include <QMenu>
#include "taglib/tag.h"
#include "indexerwidget.h"
+#include "globals.h"
IndexerWidget::IndexerWidget(QWidget *parent) : QWidget(parent) {
//widgets
@@ -29,6 +32,9 @@ IndexerWidget::IndexerWidget(QWidget *parent) : QWidget(parent) {
connect(mReader, SIGNAL(message(QString)), this, SLOT(addToLog(QString)));
connect(mReader, SIGNAL(errorMsg(QString)), this, SLOT(addToError(QString)));
+ //misc
+ createMenus();
+
//layout
QVBoxLayout *mainLayout = new QVBoxLayout;
QHBoxLayout *buttonLayout = new QHBoxLayout;
@@ -60,6 +66,22 @@ void IndexerWidget::addToError(QString msg){
mError->append(msg);
}
+void IndexerWidget::createMenus(){
+ QMenu *fileMenu = new QMenu(tr("&File"));
+ mStartIndexingA = new QAction(tr("&Start indexing"), this);
+ connect(mStartIndexingA, SIGNAL(triggered()), this, SLOT(startIndexing()));
+ fileMenu->addAction(mStartIndexingA);
+ mStopIndexingA = new QAction(tr("Sto&p indexing"), this);
+ connect(mStopIndexingA, SIGNAL(triggered()), this, SLOT(stopIndexing()));
+ fileMenu->addAction(mStopIndexingA);
+ fileMenu->addSeparator();
+ fileMenu->addAction(Globals::instance()->action(Globals::QuitAction));
+ mMenus.append(fileMenu);
+ QMenu *editMenu = new QMenu(tr("&Edit"));
+ editMenu->addAction(Globals::instance()->action(Globals::ConfigAction));
+ mMenus.append(editMenu);
+}
+
BeetReader::BeetReader() : mCanceled(false){
mDb = QSqlDatabase::database("beetplayerdb");
diff --git a/indexerwidget.h b/indexerwidget.h
index 9bcb62d..aa3c1d3 100644
--- a/indexerwidget.h
+++ b/indexerwidget.h
@@ -8,6 +8,9 @@
#include "taglib/fileref.h"
+class QMenu;
+class QAction;
+
class QTextEdit;
class BeetReader;
struct BeetObject;
@@ -16,6 +19,7 @@ class IndexerWidget : public QWidget {
Q_OBJECT
public:
explicit IndexerWidget(QWidget *parent = 0);
+ QVector<QMenu*> menus() { return mMenus; }
public slots:
void startIndexing();
@@ -24,10 +28,13 @@ class IndexerWidget : public QWidget {
void addToError(QString msg);
private:
+ void createMenus();
QTextEdit *mLog;
QTextEdit *mError;
+ QVector<QMenu*> mMenus;
+ QAction *mStartIndexingA;
+ QAction *mStopIndexingA;
BeetReader *mReader;
-
};
class BeetReader : public QThread {