changeset 423:97cd3d2c032a templating

Start to add templates menu; add default template
author Chris Cannam
date Mon, 09 May 2011 11:57:02 +0100
parents 37fb42c2d0e7
children 944167b96d01
files main/MainWindow.cpp main/MainWindow.h sonic-visualiser.qrc templates/default.xml
diffstat 4 files changed, 74 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/main/MainWindow.cpp	Thu Apr 28 15:31:14 2011 +0100
+++ b/main/MainWindow.cpp	Mon May 09 11:57:02 2011 +0100
@@ -30,6 +30,7 @@
 #include "framework/TransformUserConfigurator.h"
 #include "view/ViewManager.h"
 #include "base/Preferences.h"
+#include "base/ResourceFinder.h"
 #include "layer/WaveformLayer.h"
 #include "layer/TimeRulerLayer.h"
 #include "layer/TimeInstantLayer.h"
@@ -430,6 +431,12 @@
 
     menu->addSeparator();
 
+    m_templatesMenu = menu->addMenu(tr("Set Session Open Template"));
+    m_templatesMenu->setTearOffEnabled(true);
+    setupTemplatesMenu();
+
+    menu->addSeparator();
+
     icon = il.load("filesave");
     icon.addPixmap(il.loadPixmap("filesave-22"));
     action = new QAction(icon, tr("&Save Session"), this);
@@ -1623,6 +1630,49 @@
 }
 
 void
+MainWindow::setupTemplatesMenu()
+{
+    m_templatesMenu->clear();
+
+    QSettings settings;
+    settings.beginGroup("MainWindow");
+    QString deflt = settings.value("sessiontemplate", "").toString();
+    setDefaultSessionTemplate(deflt);
+    settings.endGroup();
+
+    QActionGroup *templatesGroup = new QActionGroup(this);
+
+    QAction *action = new QAction(tr("Default"), this);
+    action->setObjectName("default");
+    connect(action, SIGNAL(triggered()), this, SLOT(changeTemplate()));
+    action->setCheckable(true);
+    action->setChecked(deflt == "" || deflt == "default");
+    templatesGroup->addAction(action);
+    m_templatesMenu->addAction(action);
+
+    m_templatesMenu->addSeparator();
+
+    QStringList templates = ResourceFinder().getResourceFiles("templates", "xml");
+    foreach (QString t, templates) {
+        QString tname = QFileInfo(t).baseName();
+        if (tname.toLower() == "default") continue;
+        action = new QAction(tname, this);
+        action->setObjectName(t);
+        connect(action, SIGNAL(triggered()), this, SLOT(changeTemplate()));
+        action->setCheckable(true);
+        action->setChecked(deflt == tname);
+        templatesGroup->addAction(action);
+        m_templatesMenu->addAction(action);
+    }
+
+    if (!templates.empty()) m_templatesMenu->addSeparator();
+
+    action = new QAction(tr("Save Session as New Template..."), this);
+    connect(action, SIGNAL(triggered()), this, SLOT(saveSessionAsTemplate()));
+    m_templatesMenu->addAction(action);
+}
+
+void
 MainWindow::setupRecentTransformsMenu()
 {
     m_recentTransformsMenu->clear();
@@ -2751,6 +2801,12 @@
 }
 
 void
+MainWindow::changeTemplate()
+{
+    //!!!
+}
+
+void
 MainWindow::paneAdded(Pane *pane)
 {
     if (m_overview) m_overview->registerView(pane);
--- a/main/MainWindow.h	Thu Apr 28 15:31:14 2011 +0100
+++ b/main/MainWindow.h	Mon May 09 11:57:02 2011 +0100
@@ -83,6 +83,7 @@
     virtual void openSomething();
     virtual void openLocation();
     virtual void openRecentFile();
+    virtual void changeTemplate();
     virtual void exportAudio();
     virtual void importLayer();
     virtual void exportLayer();
@@ -140,6 +141,7 @@
 
     virtual void setupRecentFilesMenu();
     virtual void setupRecentTransformsMenu();
+    virtual void setupTemplatesMenu();
 
     virtual void playSpeedChanged(int);
     virtual void playSoloToggled();
@@ -190,6 +192,7 @@
     QMenu                   *m_sliceMenu;
     QMenu                   *m_recentFilesMenu;
     QMenu                   *m_recentTransformsMenu;
+    QMenu                   *m_templatesMenu;
     QMenu                   *m_rightButtonMenu;
     QMenu                   *m_rightButtonLayerMenu;
     QMenu                   *m_rightButtonTransformsMenu;
--- a/sonic-visualiser.qrc	Thu Apr 28 15:31:14 2011 +0100
+++ b/sonic-visualiser.qrc	Mon May 09 11:57:02 2011 +0100
@@ -104,6 +104,7 @@
     <file>samples/stick.wav</file>
     <file>samples/strike.wav</file>
     <file>samples/tap.wav</file>
+    <file>templates/default.xml</file>
     <file>templates/testtemplate.xml</file>
     <file>i18n/sonic-visualiser_ru.qm</file>
     <file>i18n/sonic-visualiser_en_GB.qm</file>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/templates/default.xml	Mon May 09 11:57:02 2011 +0100
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE sonic-visualiser>
+<sv>
+<data>
+  <layer id="1" type="timeruler" name="Ruler" model="0"  colourName="Black" colour="#000000" darkBackground="false" />
+  <layer id="2" type="waveform" name="Waveform" model="0"  gain="1" showMeans="1" greyscale="1" channelMode="0" channel="-1" scale="0" aggressive="0" autoNormalize="0" colourName="Black" colour="#000000" darkBackground="false" />
+</data>
+<display>
+  <view centre="0" zoom="1024" followPan="1" followZoom="1" tracking="page"  type="pane" centreLineVisible="1">
+    <layer id="1" type="timeruler" name="Ruler" model="0" visible="true"/>
+    <layer id="2" type="waveform" name="Waveform" model="0" visible="true"/>
+  </view>
+</display>
+</sv>