summaryrefslogtreecommitdiff
path: root/src/mainwindow.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2018-05-16 21:45:00 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2018-05-16 21:45:00 +0200
commitaf27aa93c6dfae8aeb38b97b5f10c23a80816b29 (patch)
tree7cfb9cc1c2aa491bc5ddbfeef015eaa4deebef50 /src/mainwindow.cc
parent8a3a2834b84ba9cdb4b9c505b124774f14034d27 (diff)
Open/activate instruent tab when double-clicking item in instrument list.
Diffstat (limited to 'src/mainwindow.cc')
-rw-r--r--src/mainwindow.cc54
1 files changed, 37 insertions, 17 deletions
diff --git a/src/mainwindow.cc b/src/mainwindow.cc
index fa64a6a..e7d099d 100644
--- a/src/mainwindow.cc
+++ b/src/mainwindow.cc
@@ -50,21 +50,6 @@ MainWindow::MainWindow(Settings& settings)
tab_widget->setTabsClosable(true);
tab_widget->setMovable(true);
- auto instr_id1 = project.createInstrument();
- auto instr_id2 = project.createInstrument();
- auto instr_id3 = project.createInstrument();
-
- auto& instr1 = project.getInstrument(instr_id1);
- auto& instr2 = project.getInstrument(instr_id2);
- auto& instr3 = project.getInstrument(instr_id3);
-
- tab_widget->addTab(new InstrumentWidget(settings, instr1),
- QPixmap(":icons/instrument.png"), "Snare");
- tab_widget->addTab(new InstrumentWidget(settings, instr2),
- QPixmap(":icons/instrument.png"), "Kick-l");
- tab_widget->addTab(new InstrumentWidget(settings, instr3),
- QPixmap(":icons/instrument.png"), "Floor Tom 1");
-
setCentralWidget(tab_widget);
QMenu* fileMenu = menuBar()->addMenu(tr("&File"));
@@ -94,8 +79,9 @@ MainWindow::MainWindow(Settings& settings)
instruments_dock->setObjectName("instruments_dock");
instruments_dock->setAllowedAreas(Qt::LeftDockWidgetArea);
instruments_dock->setFeatures(QDockWidget::DockWidgetMovable);
- QListWidget* instrument_list = new QListWidget();
- instrument_list->addItems({"Snare", "Kick-l", "Floor Tom 1"});
+ instrument_list = new QListWidget();
+ connect(instrument_list, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
+ this, SLOT(itemDoubleClicked(QListWidgetItem*)));
instruments_dock->setWidget(instrument_list);
addDockWidget(Qt::LeftDockWidgetArea, instruments_dock);
@@ -124,6 +110,28 @@ MainWindow::~MainWindow()
{
}
+void MainWindow::itemDoubleClicked(QListWidgetItem *item)
+{
+ int id = item->data(Qt::UserRole).toInt();
+ auto& instr = project.getInstrument(id);
+
+ for(int i = 0; i < tab_widget->count(); ++i)
+ {
+ if(tab_widget->widget(i)->property("id").toInt() == id)
+ {
+ tab_widget->setCurrentIndex(i);
+ return;
+ }
+ }
+
+ // Tab wasn't open already. Create it.
+ tab_widget->addTab(new InstrumentWidget(settings, instr),
+ QPixmap(":icons/instrument.png"),
+ instr.getInstrumentName());
+ // Make new tab active
+ tab_widget->setCurrentIndex(tab_widget->count() - 1);
+}
+
void MainWindow::updateWindowTitle()
{
auto project_string = project.getProjectName();
@@ -205,6 +213,18 @@ void MainWindow::loadProject()
project_dirty = false;
updateWindowTitle();
+ instrument_list->clear();
+ auto instrument_ids = project.getInstrumentList();
+ for(auto id : instrument_ids)
+ {
+ auto& instrument = project.getInstrument(id);
+ auto item = new QListWidgetItem();
+ item->setIcon(QPixmap(":icons/instrument.png"));
+ item->setText(instrument.getInstrumentName());
+ item->setData(Qt::UserRole, id);
+ instrument_list->addItem(item);
+ }
+
statusBar()->showMessage(tr("Loaded"));
}