comparison main/MainWindow.cpp @ 430:45bfc5962c33 templating

Add some "proper" default templates; ensure default template is updated in menu if our template file disappears
author Chris Cannam
date Wed, 11 May 2011 13:52:00 +0100
parents ba07505d20e2
children ee927c1b7941
comparison
equal deleted inserted replaced
429:5ae2d0f7fe5f 430:45bfc5962c33
1653 1653
1654 QSettings settings; 1654 QSettings settings;
1655 settings.beginGroup("MainWindow"); 1655 settings.beginGroup("MainWindow");
1656 QString deflt = settings.value("sessiontemplate", "").toString(); 1656 QString deflt = settings.value("sessiontemplate", "").toString();
1657 setDefaultSessionTemplate(deflt == "" ? "default" : deflt); 1657 setDefaultSessionTemplate(deflt == "" ? "default" : deflt);
1658 settings.endGroup();
1659 1658
1660 QActionGroup *templatesGroup = new QActionGroup(this); 1659 QActionGroup *templatesGroup = new QActionGroup(this);
1661 1660
1662 QAction *action = new QAction(tr("Default"), this); 1661 bool haveFoundDefault = false;
1663 action->setObjectName("default"); 1662
1664 connect(action, SIGNAL(triggered()), this, SLOT(changeTemplate())); 1663 QAction *defaultAction = new QAction(tr("Default"), this);
1665 action->setCheckable(true); 1664 defaultAction->setObjectName("default");
1666 action->setChecked(deflt == "" || deflt == "default"); 1665 connect(defaultAction, SIGNAL(triggered()), this, SLOT(changeTemplate()));
1667 templatesGroup->addAction(action); 1666 defaultAction->setCheckable(true);
1668 m_templatesMenu->addAction(action); 1667 if (deflt == "" || deflt == "default") {
1668 defaultAction->setChecked(true);
1669 haveFoundDefault = true;
1670 }
1671 templatesGroup->addAction(defaultAction);
1672 m_templatesMenu->addAction(defaultAction);
1669 1673
1670 m_templatesMenu->addSeparator(); 1674 m_templatesMenu->addSeparator();
1675
1676 QAction *action = 0;
1671 1677
1672 QStringList templates = ResourceFinder().getResourceFiles("templates", "svt"); 1678 QStringList templates = ResourceFinder().getResourceFiles("templates", "svt");
1673 1679
1674 bool havePersonal = false; 1680 bool havePersonal = false;
1675 1681
1683 foreach (QString t, byName) { 1689 foreach (QString t, byName) {
1684 if (t.toLower() == "default") continue; 1690 if (t.toLower() == "default") continue;
1685 action = new QAction(t, this); 1691 action = new QAction(t, this);
1686 connect(action, SIGNAL(triggered()), this, SLOT(changeTemplate())); 1692 connect(action, SIGNAL(triggered()), this, SLOT(changeTemplate()));
1687 action->setCheckable(true); 1693 action->setCheckable(true);
1688 action->setChecked(deflt == t); 1694 if (deflt == t) {
1695 action->setChecked(true);
1696 haveFoundDefault = true;
1697 }
1689 templatesGroup->addAction(action); 1698 templatesGroup->addAction(action);
1690 m_templatesMenu->addAction(action); 1699 m_templatesMenu->addAction(action);
1691 } 1700 }
1692 1701
1693 if (!templates.empty()) m_templatesMenu->addSeparator(); 1702 if (!templates.empty()) m_templatesMenu->addSeparator();
1703
1704 if (!haveFoundDefault) {
1705 defaultAction->setChecked(true);
1706 setDefaultSessionTemplate("default");
1707 settings.setValue("sessiontemplate", "");
1708 }
1709
1710 settings.endGroup();
1694 1711
1695 action = new QAction(tr("Save Template from Current Session..."), this); 1712 action = new QAction(tr("Save Template from Current Session..."), this);
1696 connect(action, SIGNAL(triggered()), this, SLOT(saveSessionAsTemplate())); 1713 connect(action, SIGNAL(triggered()), this, SLOT(saveSessionAsTemplate()));
1697 m_templatesMenu->addAction(action); 1714 m_templatesMenu->addAction(action);
1698 1715