You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.5 KiB
C++

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <context.h>
#include <iplugin.h>
#include <QPushButton>
#include <QVBoxLayout>
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();
}
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()
{
Context::instance().openDb("/home/jony/db.db");
}