diff --git a/application/mainwindow.cpp b/application/mainwindow.cpp index e7327da..e7ea1ff 100644 --- a/application/mainwindow.cpp +++ b/application/mainwindow.cpp @@ -19,6 +19,8 @@ MainWindow::MainWindow(QWidget *parent) : m_loginDialog = new LoginDialog(this); + ui->tabWidget->setVisible(false); + QFile styleFile(":/style.css"); if (styleFile.open(QIODevice::ReadOnly | QIODevice::Text)) @@ -29,9 +31,10 @@ MainWindow::MainWindow(QWidget *parent) : connect(m_loginDialog, &LoginDialog::accepted, [this]{ PermissionService service; QSharedPointer u = service.loadUser(m_loginDialog->login()); - m_lblUser->setText(u->name()); - m_loginDialog->reset(); Context::instance().setCurrentUser(u); + + openDashboard(); + m_loginDialog->reset(); }); connect(m_loginDialog, &LoginDialog::rejected, [this]{ @@ -86,11 +89,8 @@ void MainWindow::openPlugin() void MainWindow::on_actionOpen_database_triggered() { - int tabCount = ui->tabWidget->count(); - for (int i = 0; i < tabCount; i++) - { - ui->tabWidget->removeTab(0); - } + closaAllTabs(); + closeDashboard(); QString dbFile = QFileDialog::getOpenFileName(this, "Open Database", "", "Database Files (*.db)"); if (!dbFile.isEmpty()) @@ -104,15 +104,20 @@ void MainWindow::on_actionOpen_database_triggered() void MainWindow::on_tabWidget_tabCloseRequested(int index) { ui->tabWidget->removeTab(index); + + if (ui->tabWidget->count() == 0) + { + ui->dashboard->setVisible(true); + ui->tabWidget->setVisible(false); + + refreshDashboard(); + } } void MainWindow::on_actionLogin_triggered() { - int tabCount = ui->tabWidget->count(); - for (int i = 0; i < tabCount; i++) - { - ui->tabWidget->removeTab(0); - } + closaAllTabs(); + closeDashboard(); QSharedPointer u; Context::instance().setCurrentUser(u); @@ -153,6 +158,9 @@ void MainWindow::on_actionPost_register_triggered() void MainWindow::openPlugin(IPlugin *plugin) { + ui->tabWidget->setVisible(true); + ui->dashboard->setVisible(false); + for (int i = 0; i < ui->tabWidget->count(); i++) { if (ui->tabWidget->widget(i)->objectName() == plugin->pluginId()) { ui->tabWidget->setCurrentIndex(i); @@ -179,6 +187,68 @@ void MainWindow::on_actionCountry_register_triggered() } +void MainWindow::closeDashboard() +{ + foreach (QFrame *dbFrame, m_dbWidgets) { + dbFrame->setVisible(false); + } +} + +void MainWindow::openDashboard() +{ + PermissionEvaluator permEv; + + foreach (IPlugin *plugin, Context::instance().plugins()) { + if (!plugin->dasboardWidgets().isEmpty() + && permEv.hasPermission(plugin->pluginId(), PERM_READ)) { + foreach (QFrame *frame, plugin->dasboardWidgets()) { + if (m_dbWidgets.contains(frame)) + { + frame->setVisible(true); + } + else + { + ui->dbWidget->layout()->addWidget(frame); + m_dbWidgets.append(frame); + } + } + } + } + + if (!Context::instance().currentUser().isNull()) + { + m_lblUser->setText(Context::instance().currentUser()->name()); + ui->labelUser->setText(Context::instance().currentUser()->name()); + } + + refreshDashboard(); +} + +void MainWindow::refreshDashboard() +{ + foreach (QFrame *frame, m_dbWidgets) { + IDashboardWidget *dbWidget = dynamic_cast(frame); + + if (dbWidget != nullptr) + { + dbWidget->refresh(); + } + } +} + +void MainWindow::closaAllTabs() +{ + ui->tabWidget->setVisible(false); + ui->dashboard->setVisible(true); + + int tabCount = ui->tabWidget->count(); + for (int i = 0; i < tabCount; i++) + { + ui->tabWidget->removeTab(0); + } +} + + void MainWindow::on_actionAbout_Qt_triggered() { QMessageBox::aboutQt(this); diff --git a/application/mainwindow.h b/application/mainwindow.h index 717f073..1afc806 100644 --- a/application/mainwindow.h +++ b/application/mainwindow.h @@ -47,7 +47,13 @@ private: Ui::MainWindow *ui; LoginDialog *m_loginDialog; QLabel *m_lblUser; + QList m_dbWidgets; + void openPlugin(IPlugin *plugin); + void closeDashboard(); + void openDashboard(); + void refreshDashboard(); + void closaAllTabs(); // QWidget interface protected: diff --git a/application/mainwindow.ui b/application/mainwindow.ui index 886c2be..a96634f 100644 --- a/application/mainwindow.ui +++ b/application/mainwindow.ui @@ -11,7 +11,7 @@ - MainWindow + Prodejna @@ -52,6 +52,83 @@ + + + + + 0 + 0 + + + + + + + + + + + + + + + + :/icons/login_32.png + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Prodejna 2.0 + + + Qt::AlignCenter + + + + + + @@ -60,7 +137,7 @@ 0 0 1000 - 25 + 20 @@ -144,12 +221,12 @@ - About + &About - About Qt + About &Qt diff --git a/application/style.css b/application/style.css index b099ec7..b06b460 100644 --- a/application/style.css +++ b/application/style.css @@ -21,3 +21,7 @@ min-width: 90px; font: 10pt; } + +#dashboard { + background-color: qlineargradient(spread:pad, x1:0.507, y1:1, x2:0.518, y2:0.291, stop:0 rgba(83, 145, 169, 255), stop:1 rgba(255, 255, 255, 255)); +} diff --git a/core/core.h b/core/core.h index 01ffc69..6741588 100644 --- a/core/core.h +++ b/core/core.h @@ -14,5 +14,6 @@ #include "enums.h" #include "objectbinder.h" #include "helper.h" +#include "idashboardwidget.h" #endif // CORE_H diff --git a/core/core.pro b/core/core.pro index 721cacb..f4381e8 100644 --- a/core/core.pro +++ b/core/core.pro @@ -134,7 +134,8 @@ HEADERS += core.h\ importdialog.h \ importprogress.h \ reporting/variablefiller.h \ - helper.h + helper.h \ + idashboardwidget.h unix { target.path = /usr/lib diff --git a/core/idashboardwidget.h b/core/idashboardwidget.h new file mode 100644 index 0000000..ead363f --- /dev/null +++ b/core/idashboardwidget.h @@ -0,0 +1,10 @@ +#ifndef IDASHBOARDWIDGET_H +#define IDASHBOARDWIDGET_H + +class IDashboardWidget +{ +public: + virtual void refresh() = 0; +}; + +#endif // IDASHBOARDWIDGET_H diff --git a/core/iplugin.h b/core/iplugin.h index b8f620f..83f46e2 100644 --- a/core/iplugin.h +++ b/core/iplugin.h @@ -70,6 +70,10 @@ public: return filled ? m_ui : NULL; } + QList dasboardWidgets() { + return m_dashboardWidgets; + } + virtual QWidget *settingsUi() { return m_settingsUi; } @@ -103,6 +107,7 @@ protected: QWidget *m_settingsUi; IService *m_service; QMap m_translations; + QList m_dashboardWidgets; }; #define PluginInterface_iid "cz.itsolved.prodejna.IPlugin"