/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /*************************************************************************** * mainwindow.cc * * Tue Nov 10 10:21:04 CET 2009 * Copyright 2009 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 "mainwindow.h" #include #include #include #include #include #include #include #include "settings.h" #include "projectdialog.h" #include "projectserialiser.h" #include "instrumentwidget.h" #define MAXVAL 10000000L MainWindow::MainWindow(Settings& settings) : settings(settings) { tab_widget = new QTabWidget(); 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")); QAction* act_new_project = new QAction(tr("&New Project"), this); fileMenu->addAction(act_new_project); connect(act_new_project, SIGNAL(triggered()), this, SLOT(newProject())); QAction* act_load_project = new QAction(tr("&Load Project..."), this); fileMenu->addAction(act_load_project); connect(act_load_project, SIGNAL(triggered()), this, SLOT(loadProject())); QAction* act_save_project = new QAction(tr("&Save Project"), this); fileMenu->addAction(act_save_project); connect(act_save_project, SIGNAL(triggered()), this, SLOT(saveProject())); QAction* act_save_project_as = new QAction(tr("Save Project As..."), this); fileMenu->addAction(act_save_project_as); connect(act_save_project_as, SIGNAL(triggered()), this, SLOT(saveProjectAs())); QAction* act_quit = new QAction(tr("&Quit"), this); fileMenu->addAction(act_quit); connect(act_quit, SIGNAL(triggered()), this, SLOT(close())); instruments_dock = new QDockWidget(tr("Instruments:"), this); 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"}); instruments_dock->setWidget(instrument_list); addDockWidget(Qt::LeftDockWidgetArea, instruments_dock); channels_dock = new QDockWidget(tr("Channels:"), this); channels_dock->setObjectName("channels_dock"); channels_dock->setAllowedAreas(Qt::LeftDockWidgetArea); channels_dock->setFeatures(QDockWidget::DockWidgetMovable); QListWidget* channel_list = new QListWidget(); channel_list->addItems({"AmbL", "AmbR", "Kdrum_back", "Kdrum_front", "Hihat", "OHL", "OHR", "Ride","Snare_bottom", "Snare_top", "Tom1", "Tom2", "Tom3"}); channels_dock->setWidget(channel_list); addDockWidget(Qt::LeftDockWidgetArea, channels_dock); loadSettings(); statusBar()->showMessage(tr("Ready")); connect(&project, SIGNAL(projectChanged()), this, SLOT(projectChanged())); updateWindowTitle(); } MainWindow::~MainWindow() { } void MainWindow::updateWindowTitle() { auto project_string = project.getProjectName(); if(project_string == "") { project_string = tr("[Untitled Project]"); } if(project.getProjectFile() != "") { project_string += " (" + QFileInfo(project.getProjectFile()).fileName() + ")"; } if(project_dirty) { project_string += "*"; } setWindowTitle("DGEdit - " + project_string); } void MainWindow::closeEvent(QCloseEvent*) { saveSettings(); QApplication::quit(); } void MainWindow::loadSettings() { QByteArray state; QByteArray geometry; settings.loadGeometry(state, geometry); restoreGeometry(geometry); restoreState(state); // TODO: lineed_exportp->setText(settings.loadExportPath()); } void MainWindow::saveSettings() { settings.saveGeometry(saveState(), saveGeometry()); // TODO: settings.saveExportPath(lineed_exportp->text()); } void MainWindow::newProject() { ProjectDialog dlg(this, project); dlg.show(); dlg.exec(); } void MainWindow::loadProject() { QString filename = QFileDialog::getOpenFileName(this, tr("Load DGEdit Project"), "", tr("DGEdit Project Files (*.dgedit)")); if(filename == "") { // User clicked cancel return; } QFile file(filename); if(!file.open(QIODevice::ReadOnly)) { return; } QString xml(file.readAll()); file.close(); ProjectSerialiser ser; ser.deserialise(xml, project); project.setProjectFile(filename); project_dirty = false; updateWindowTitle(); statusBar()->showMessage(tr("Loaded")); } void MainWindow::saveProject() { QString filename = project.getProjectFile(); if(filename == "") { saveProjectAs(); return; } QFile file(filename); if(!file.open(QIODevice::WriteOnly)) { return; } ProjectSerialiser ser; auto xml = ser.serialise(project); file.write(xml.toUtf8()); project_dirty = false; updateWindowTitle(); statusBar()->showMessage(tr("Saved")); } void MainWindow::saveProjectAs() { QString filename = QFileDialog::getSaveFileName(this, tr("Save DGEdit Project"), "", tr("DGEdit Project Files (*.dgedit)")); if(filename == "") { // User clicked cancel return; } project.setProjectFile(filename); saveProject(); } void MainWindow::projectChanged() { project_dirty = true; updateWindowTitle(); }