summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2018-05-23 20:01:34 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2018-05-23 20:01:47 +0200
commit5f3f9fabf5ad2e1cda638612c3cf863045765a3b (patch)
tree95460541a4ea2609ba8b3d896a7f0c713ed48bfb
parent8d551ed344a9bfa7f0b96a8677aca570d8c7c407 (diff)
Add instrument dialog (currently only with it's name).
-rw-r--r--icons/edit_instrument.pngbin0 -> 2327 bytes
-rw-r--r--src/Makefile.am2
-rw-r--r--src/dgedit.qrc1
-rw-r--r--src/instrumentdialog.cc77
-rw-r--r--src/instrumentdialog.h49
-rw-r--r--src/mainwindow.cc49
-rw-r--r--src/mainwindow.h1
-rw-r--r--src/project.cc5
-rw-r--r--src/project.h2
-rw-r--r--src/projectdialog.cc2
-rw-r--r--src/projectdialog.h2
11 files changed, 188 insertions, 2 deletions
diff --git a/icons/edit_instrument.png b/icons/edit_instrument.png
new file mode 100644
index 0000000..d365f4a
--- /dev/null
+++ b/icons/edit_instrument.png
Binary files differ
diff --git a/src/Makefile.am b/src/Makefile.am
index ba33043..c3852c3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -23,6 +23,7 @@ dgedit_SOURCES = \
canvastoolthreshold.cc \
canvaswidget.cc \
filelist.cc \
+ instrumentdialog.cc \
instrumentwidget.cc \
itemeditor.cc \
localehandler.cc \
@@ -48,6 +49,7 @@ EXTRA_DIST = \
canvastoolthreshold.h \
canvaswidget.h \
filelist.h \
+ instrumentdialog.h \
instrumentwidget.h \
itemeditor.h \
localehandler.h \
diff --git a/src/dgedit.qrc b/src/dgedit.qrc
index b4f16a1..4e76459 100644
--- a/src/dgedit.qrc
+++ b/src/dgedit.qrc
@@ -5,6 +5,7 @@
<file>../icons/file.png</file>
<file>../icons/instrument.png</file>
<file>../icons/add_instrument.png</file>
+ <file>../icons/edit_instrument.png</file>
<file>../icons/remove_instrument.png</file>
<file>../icons/channel.png</file>
<file>../icons/add_channel.png</file>
diff --git a/src/instrumentdialog.cc b/src/instrumentdialog.cc
new file mode 100644
index 0000000..09b3e82
--- /dev/null
+++ b/src/instrumentdialog.cc
@@ -0,0 +1,77 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * instrumentdialog.cc
+ *
+ * Wed May 23 17:35:09 CEST 2018
+ * Copyright 2018 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "instrumentdialog.h"
+
+#include <QGridLayout>
+
+#include <QLabel>
+#include <QLineEdit>
+#include <QPushButton>
+
+#include <QFileDialog>
+#include <QDialogButtonBox>
+
+#include "project.h"
+
+InstrumentDialog::InstrumentDialog(QWidget* parent, Instrument& instrument)
+ : QDialog(parent)
+ , instrument(instrument)
+{
+ setWindowModality(Qt::ApplicationModal);
+ setWindowTitle(tr("Instrument Dialog"));
+ setMinimumWidth(300);
+
+ auto layout = new QGridLayout();
+ setLayout(layout);
+
+ int idx = 0;
+
+ name = new QLineEdit();
+ name->setText(instrument.getInstrumentName());
+ layout->addWidget(new QLabel(tr("Name of the instrument:")), idx, 0, 1, 2);
+ idx++;
+ layout->addWidget(name, idx, 0);
+ idx++;
+
+ auto buttons =
+ new QDialogButtonBox(QDialogButtonBox::Ok |
+ QDialogButtonBox::Cancel |
+ QDialogButtonBox::Apply);
+ connect(buttons, SIGNAL(accepted()), this, SLOT(apply()));
+ connect(buttons, SIGNAL(accepted()), this, SLOT(accept()));
+ connect(buttons, SIGNAL(rejected()), this, SLOT(reject()));
+ connect(buttons->button(QDialogButtonBox::Apply), SIGNAL(clicked()),
+ this, SLOT(apply()));
+ layout->addWidget(buttons, idx, 0, 1, 2);
+}
+
+void InstrumentDialog::apply()
+{
+ // Only send out one update signal
+ Project::RAIIBulkUpdate bulkUpdate(instrument.getProject());
+ instrument.setInstrumentName(name->text());
+}
diff --git a/src/instrumentdialog.h b/src/instrumentdialog.h
new file mode 100644
index 0000000..c89b8af
--- /dev/null
+++ b/src/instrumentdialog.h
@@ -0,0 +1,49 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * instrumentdialog.h
+ *
+ * Wed May 23 17:35:09 CEST 2018
+ * Copyright 2018 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#pragma once
+
+#include <QDialog>
+#include <QLineEdit>
+
+class Instrument;
+
+class InstrumentDialog
+ : public QDialog
+{
+ Q_OBJECT
+public:
+ InstrumentDialog(QWidget* parent, Instrument& instrument);
+ ~InstrumentDialog() = default;
+
+private slots:
+ void apply();
+
+private:
+ QLineEdit* name{nullptr};
+
+ Instrument& instrument;
+};
diff --git a/src/mainwindow.cc b/src/mainwindow.cc
index 61ea9bb..92a91e7 100644
--- a/src/mainwindow.cc
+++ b/src/mainwindow.cc
@@ -37,9 +37,11 @@
#include <QFileDialog>
#include <QToolBar>
#include <QToolButton>
+#include <QMessageBox>
#include "settings.h"
#include "projectdialog.h"
+#include "instrumentdialog.h"
#include "projectserialiser.h"
#include "instrumentwidget.h"
@@ -94,8 +96,12 @@ MainWindow::MainWindow(Settings& settings)
auto rem = new QToolButton();
rem->setIcon(QPixmap(":icons/remove_instrument.png"));
connect(rem, SIGNAL(clicked()), this, SLOT(removeInstrument()));
+ auto edt = new QToolButton();
+ edt->setIcon(QPixmap(":icons/edit_instrument.png"));
+ connect(edt, SIGNAL(clicked()), this, SLOT(editInstrument()));
tools->addWidget(add);
tools->addWidget(rem);
+ tools->addWidget(edt);
instrument_list = new QListWidget();
connect(instrument_list, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
this, SLOT(instrumentDoubleClicked(QListWidgetItem*)));
@@ -158,7 +164,10 @@ void MainWindow::addInstrument()
{
auto id = project.createInstrument();
auto& instrument = project.getInstrument(id);
- instrument.setInstrumentName(tr("New instrument"));
+
+ InstrumentDialog dlg(this, instrument);
+ dlg.show();
+ dlg.exec();
auto item = new QListWidgetItem();
item->setIcon(QPixmap(":icons/instrument.png"));
@@ -167,13 +176,51 @@ void MainWindow::addInstrument()
instrument_list->addItem(item);
}
+void MainWindow::editInstrument()
+{
+ auto items = instrument_list->selectedItems();
+ for(auto item : items)
+ {
+ auto id = item->data(Qt::UserRole).toInt();
+
+ auto& instrument = project.getInstrument(id);
+
+ InstrumentDialog dlg(this, instrument);
+ dlg.show();
+ dlg.exec();
+
+ item->setText(instrument.getInstrumentName());
+
+ // Also update tab name if open
+ for(int i = 0; i < tab_widget->count(); ++i)
+ {
+ if(tab_widget->widget(i)->property("id").toInt() == id)
+ {
+ tab_widget->setTabText(i, instrument.getInstrumentName());
+ }
+ }
+ }
+}
+
void MainWindow::removeInstrument()
{
+ int ret =
+ QMessageBox::question(this, tr("Delete Instrument"),
+ tr("Are you sure you want to delete the selected "
+ "instrument?"),
+ QMessageBox::Yes | QMessageBox::No |
+ QMessageBox::Cancel);
+ if(ret != QMessageBox::Yes)
+ {
+ return;
+ }
+
auto items = instrument_list->selectedItems();
for(auto item : items)
{
auto id = item->data(Qt::UserRole).toInt();
+ // Also close tab if open.
for(int i = 0; i < tab_widget->count(); ++i)
{
if(tab_widget->widget(i)->property("id").toInt() == id)
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 79cb5ad..d9ab062 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -46,6 +46,7 @@ public:
public slots:
void addInstrument();
+ void editInstrument();
void removeInstrument();
void instrumentDoubleClicked(QListWidgetItem *item);
diff --git a/src/project.cc b/src/project.cc
index 727673a..8a1338c 100644
--- a/src/project.cc
+++ b/src/project.cc
@@ -95,6 +95,11 @@ void Instrument::setFileList(const AudioFileList& file_list)
}
}
+Project& Instrument::getProject()
+{
+ return project;
+}
+
void Project::bulkUpdateBegin()
{
++update_count;
diff --git a/src/project.h b/src/project.h
index 03d482b..2b172ea 100644
--- a/src/project.h
+++ b/src/project.h
@@ -51,6 +51,8 @@ public:
AudioFileList getFileList() const;
void setFileList(const AudioFileList& file_list);
+ Project& getProject();
+
private:
friend class ProjectSerialiser;
diff --git a/src/projectdialog.cc b/src/projectdialog.cc
index 3734b42..c52d110 100644
--- a/src/projectdialog.cc
+++ b/src/projectdialog.cc
@@ -35,6 +35,8 @@
#include <QFileDialog>
#include <QDialogButtonBox>
+#include "project.h"
+
ProjectDialog::ProjectDialog(QWidget* parent, Project& project)
: QDialog(parent)
, project(project)
diff --git a/src/projectdialog.h b/src/projectdialog.h
index 7d2093d..a6fc646 100644
--- a/src/projectdialog.h
+++ b/src/projectdialog.h
@@ -29,7 +29,7 @@
#include <QDialog>
#include <QLineEdit>
-#include "project.h"
+class Project;
class ProjectDialog
: public QDialog