diff main/MainWindow.cpp @ 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 eaab4c65c7bc
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);