From 5f3f9fabf5ad2e1cda638612c3cf863045765a3b Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Wed, 23 May 2018 20:01:34 +0200 Subject: Add instrument dialog (currently only with it's name). --- icons/edit_instrument.png | Bin 0 -> 2327 bytes src/Makefile.am | 2 ++ src/dgedit.qrc | 1 + src/instrumentdialog.cc | 77 ++++++++++++++++++++++++++++++++++++++++++++++ src/instrumentdialog.h | 49 +++++++++++++++++++++++++++++ src/mainwindow.cc | 49 ++++++++++++++++++++++++++++- src/mainwindow.h | 1 + src/project.cc | 5 +++ src/project.h | 2 ++ src/projectdialog.cc | 2 ++ src/projectdialog.h | 2 +- 11 files changed, 188 insertions(+), 2 deletions(-) create mode 100644 icons/edit_instrument.png create mode 100644 src/instrumentdialog.cc create mode 100644 src/instrumentdialog.h diff --git a/icons/edit_instrument.png b/icons/edit_instrument.png new file mode 100644 index 0000000..d365f4a Binary files /dev/null and b/icons/edit_instrument.png 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 @@ ../icons/file.png ../icons/instrument.png ../icons/add_instrument.png + ../icons/edit_instrument.png ../icons/remove_instrument.png ../icons/channel.png ../icons/add_channel.png 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 + +#include +#include +#include + +#include +#include + +#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 +#include + +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 #include #include +#include #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 #include +#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 #include -#include "project.h" +class Project; class ProjectDialog : public QDialog -- cgit v1.2.3