summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2018-05-05 13:03:36 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2018-05-05 13:03:36 +0200
commitd28efb1a504ffbc7ba151a497c20f3063a06077a (patch)
tree7e9176391f8b995390bc4f3489267a02f2af5ebc
parent53905b78f479d8d9d42a8bd6336314031814e52a (diff)
Move handling of settings and locale to their own classes.
-rw-r--r--src/Makefile.am4
-rw-r--r--src/dgedit.cc22
-rw-r--r--src/localehandler.cc49
-rw-r--r--src/localehandler.h40
-rw-r--r--src/mainwindow.cc45
-rw-r--r--src/mainwindow.h6
-rw-r--r--src/settings.cc74
-rw-r--r--src/settings.h46
8 files changed, 234 insertions, 52 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 266bc79..5ce2a58 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -24,12 +24,14 @@ dgedit_SOURCES = \
canvaswidget.cc \
filelist.cc \
itemeditor.cc \
+ localehandler.cc \
mainwindow.cc \
mipmap.cc \
player.cc \
samplesorter.cc \
selection.cc \
selectioneditor.cc \
+ settings.cc \
volumefader.cc \
zoomslider.cc
@@ -43,6 +45,7 @@ EXTRA_DIST = \
canvaswidget.h \
filelist.h \
itemeditor.h \
+ localehandler.h \
mainwindow.h \
mipmap.h \
player.h \
@@ -50,6 +53,7 @@ EXTRA_DIST = \
selection.h \
selectioneditor.h \
sleep.h \
+ settings.h \
volumefader.h \
zoomslider.h \
dgedit.qrc
diff --git a/src/dgedit.cc b/src/dgedit.cc
index c511150..3984f5a 100644
--- a/src/dgedit.cc
+++ b/src/dgedit.cc
@@ -25,31 +25,19 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
#include <QApplication>
-#include <QLocale>
-#include <QTranslator>
-
-#include <iostream>
#include "mainwindow.h"
+#include "settings.h"
+#include "localehandler.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
- QTranslator translator;
- QString locale = QLocale().name().section('_', 0, 0);
- if(!locale.isEmpty() && locale != "C")
- {
- QString file = LOCALEDIR"/dgedit_" + locale + ".qm";
- std::cout << file.toStdString() << std::endl;
- if(QFile::exists(file))
- {
- translator.load(file);
- app.installTranslator(&translator);
- }
- }
+ LocaleHandler locale(app);
- MainWindow wnd;
+ Settings settings;
+ MainWindow wnd(settings);
wnd.show();
return app.exec();
diff --git a/src/localehandler.cc b/src/localehandler.cc
new file mode 100644
index 0000000..6721492
--- /dev/null
+++ b/src/localehandler.cc
@@ -0,0 +1,49 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * localehandler.cc
+ *
+ * Sat May 5 12:39:49 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 "localehandler.h"
+
+#include <iostream>
+
+#include <QApplication>
+//#include <QLocale>
+#include <QTranslator>
+#include <QString>
+#include <QFile>
+
+LocaleHandler::LocaleHandler(QApplication& app)
+{
+ QString locale = QLocale().name().section('_', 0, 0);
+ if(!locale.isEmpty() && locale != "C")
+ {
+ QString file = LOCALEDIR"/dgedit_" + locale + ".qm";
+ if(QFile::exists(file))
+ {
+ translator.load(file);
+ app.installTranslator(&translator);
+ }
+ }
+}
diff --git a/src/localehandler.h b/src/localehandler.h
new file mode 100644
index 0000000..54314e9
--- /dev/null
+++ b/src/localehandler.h
@@ -0,0 +1,40 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * localehandler.h
+ *
+ * Sat May 5 12:39:49 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 <QTranslator>
+
+class QApplication;
+
+class LocaleHandler
+{
+public:
+ LocaleHandler(QApplication& app);
+
+private:
+ QTranslator translator;
+};
diff --git a/src/mainwindow.cc b/src/mainwindow.cc
index 69e4398..4b49325 100644
--- a/src/mainwindow.cc
+++ b/src/mainwindow.cc
@@ -34,7 +34,6 @@
#include <QStatusBar>
#include <QApplication>
#include <QDockWidget>
-#include <QSettings>
#include <QToolBar>
#include <QAction>
#include <QMenuBar>
@@ -51,7 +50,7 @@
#include "volumefader.h"
#include "selectioneditor.h"
#include "zoomslider.h"
-
+#include "settings.h"
#define MAXVAL 10000000L
//#define SINGLESTEP MAXVAL/100000
@@ -67,7 +66,8 @@ static void addTool(QToolBar* toolbar, Canvas* canvas, CanvasTool* tool)
canvas->tools.push_back(tool);
}
-MainWindow::MainWindow()
+MainWindow::MainWindow(Settings& settings)
+ : settings(settings)
{
{
int start = 44100 * 60;
@@ -205,23 +205,6 @@ MainWindow::MainWindow()
loadSettings();
- //QSettings settings("presets.ini", QSettings::IniFormat);
- //QStringList list = settings.childGroups();
- //for(int i = 0; i != list.size(); i++)
- //{
- // QString presetname = list.at(i);
- // Preset p;
- // settings.beginGroup(presetname);
- // p.prefix = settings.value("prefix", "unknown").toString();
- // p.attacklength = settings.value("attacklength", 0).toInt();
- // p.falloff = settings.value("falloff", 0).toInt();
- // p.fadelength = settings.value("fadelength", 0).toInt();
- // settings.endGroup();
- // QVariant v;
- // v.setValue(p);
- // presets->addItem(presetname, v);
- //}
-
statusBar()->showMessage(tr("Ready"));
}
@@ -483,24 +466,18 @@ void MainWindow::closeEvent(QCloseEvent*)
void MainWindow::loadSettings()
{
- QSettings settings;
-
- settings.beginGroup("MainWindow");
- lineed_exportp->setText(settings.value("exportpath", "").toString());
- resize(settings.value("size", QSize(700, 800)).toSize());
- move(settings.value("pos", QPoint(0, 0)).toPoint());
- settings.endGroup();
+ QSize size;
+ QPoint pos;
+ settings.loadGeometry(size, pos);
+ resize(size);
+ move(pos);
+ lineed_exportp->setText(settings.loadExportPath());
}
void MainWindow::saveSettings()
{
- QSettings settings;
-
- settings.beginGroup("MainWindow");
- settings.setValue("exportpath", lineed_exportp->text());
- settings.setValue("size", size());
- settings.setValue("pos", pos());
- settings.endGroup();
+ settings.saveGeometry(size(), pos());
+ settings.saveExportPath(lineed_exportp->text());
}
//void MainWindow::setXScale(float val)
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 265ab31..d1794b6 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -46,6 +46,8 @@
#include "zoomslider.h"
#include "canvaswidget.h"
+class Settings;
+
class Preset
{
public:
@@ -61,7 +63,7 @@ class MainWindow
{
Q_OBJECT
public:
- MainWindow();
+ MainWindow(Settings& settings);
~MainWindow();
public slots:
@@ -120,4 +122,6 @@ private:
Selections selections;
Selections selections_preview;
Player player;
+
+ Settings& settings;
};
diff --git a/src/settings.cc b/src/settings.cc
new file mode 100644
index 0000000..af34b70
--- /dev/null
+++ b/src/settings.cc
@@ -0,0 +1,74 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * settings.cc
+ *
+ * Sat May 5 11:57:00 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 "settings.h"
+
+#include <QSettings>
+
+Settings::Settings()
+{
+}
+
+Settings::~Settings()
+{
+}
+
+void Settings::loadGeometry(QSize& size, QPoint& pos) const
+{
+ QSettings settings;
+
+ settings.beginGroup("MainWindow");
+ size = settings.value("size", QSize(700, 800)).toSize();
+ pos = settings.value("pos", QPoint(0, 0)).toPoint();
+ settings.endGroup();
+}
+
+void Settings::saveGeometry(const QSize& size, const QPoint& pos)
+{
+ QSettings settings;
+
+ settings.beginGroup("MainWindow");
+ settings.setValue("size", size);
+ settings.setValue("pos", pos);
+ settings.endGroup();
+}
+
+QString Settings::loadExportPath() const
+{
+ QSettings settings;
+ settings.beginGroup("MainWindow");
+ QString export_path = settings.value("exportpath", "").toString();
+ settings.endGroup();
+ return export_path;
+}
+
+void Settings::saveExportPath(const QString& export_path)
+{
+ QSettings settings;
+ settings.beginGroup("MainWindow");
+ settings.setValue("exportpath", export_path);
+ settings.endGroup();
+}
diff --git a/src/settings.h b/src/settings.h
new file mode 100644
index 0000000..433edad
--- /dev/null
+++ b/src/settings.h
@@ -0,0 +1,46 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * settings.h
+ *
+ * Sat May 5 11:57:00 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 <QSize>
+#include <QPoint>
+#include <QString>
+
+class Settings
+{
+public:
+ Settings();
+ ~Settings();
+
+ void loadGeometry(QSize& size, QPoint& pos) const;
+ void saveGeometry(const QSize& size, const QPoint& pos);
+
+ QString loadExportPath() const;
+ void saveExportPath(const QString& export_path);
+
+private:
+};