#include "mainwindow.h" #include "ui_mainwindow.h" #include #include #include #include #include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); Context::instance().loadPlugins(); int i = 0; foreach (IPlugin *plugin, Context::instance().plugins()) { QPushButton *plugButton = new QPushButton(this); plugButton->setText(plugin->pluginName()); ui->navigation->layout()->addWidget(plugButton); plugButton->setProperty(PLUGIN_INDEX, i); i++; connect(plugButton, SIGNAL(clicked()), this, SLOT(openPlugin()) ); } ((QVBoxLayout*)ui->navigation->layout())->addStretch(1); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_actionExit_triggered() { this->close(); Context::instance().destroy(); } void MainWindow::openPlugin() { QVariant var = QObject::sender()->property(PLUGIN_INDEX); IPlugin *plugin = Context::instance().plugins().at(var.toInt()); for (int i = 0; i < ui->tabWidget->count(); i++) { if (ui->tabWidget->widget(i)->objectName() == plugin->pluginId()) { ui->tabWidget->setCurrentIndex(i); return; } } ui->tabWidget->addTab(plugin->ui(), QIcon(), plugin->pluginName()); ui->tabWidget->widget(ui->tabWidget->count() - 1)->setObjectName(plugin->pluginId()); ui->tabWidget->setCurrentIndex(ui->tabWidget->count() - 1); } void MainWindow::on_actionOpen_database_triggered() { QFileDialog dialog(this); dialog.setNameFilter(tr("Database Files (*.db)")); dialog.setWindowTitle(tr("Open Database")); Context::instance().openDb(dialog.getOpenFileName()); } void MainWindow::on_tabWidget_tabCloseRequested(int index) { ui->tabWidget->removeTab(index); }