comparison src/MainWindow.cpp @ 1:a11a9c04df44

Cut it back a bit
author Chris Cannam
date Fri, 16 Nov 2012 12:02:55 +0000
parents 158f40a613a5
children f8f297008312
comparison
equal deleted inserted replaced
0:158f40a613a5 1:a11a9c04df44
36 #include "view/Overview.h" 36 #include "view/Overview.h"
37 #include "widgets/PropertyBox.h" 37 #include "widgets/PropertyBox.h"
38 #include "widgets/PropertyStack.h" 38 #include "widgets/PropertyStack.h"
39 #include "widgets/AudioDial.h" 39 #include "widgets/AudioDial.h"
40 #include "widgets/IconLoader.h" 40 #include "widgets/IconLoader.h"
41 #include "widgets/LayerTree.h"
42 #include "widgets/ListInputDialog.h" 41 #include "widgets/ListInputDialog.h"
43 #include "widgets/SubdividingMenu.h" 42 #include "widgets/SubdividingMenu.h"
44 #include "widgets/NotifyingPushButton.h" 43 #include "widgets/NotifyingPushButton.h"
45 #include "widgets/KeyReference.h" 44 #include "widgets/KeyReference.h"
46 #include "audioio/AudioCallbackPlaySource.h" 45 #include "audioio/AudioCallbackPlaySource.h"
81 #include <QToolBar> 80 #include <QToolBar>
82 #include <QToolButton> 81 #include <QToolButton>
83 #include <QButtonGroup> 82 #include <QButtonGroup>
84 #include <QInputDialog> 83 #include <QInputDialog>
85 #include <QStatusBar> 84 #include <QStatusBar>
86 #include <QTreeView>
87 #include <QFile> 85 #include <QFile>
88 #include <QFileInfo> 86 #include <QFileInfo>
89 #include <QDir> 87 #include <QDir>
90 #include <QTextStream> 88 #include <QTextStream>
91 #include <QProcess> 89 #include <QProcess>
118 m_rightButtonMenu(0), 116 m_rightButtonMenu(0),
119 m_rightButtonPlaybackMenu(0), 117 m_rightButtonPlaybackMenu(0),
120 m_deleteSelectedAction(0), 118 m_deleteSelectedAction(0),
121 m_ffwdAction(0), 119 m_ffwdAction(0),
122 m_rwdAction(0), 120 m_rwdAction(0),
123 m_layerTreeView(0),
124 m_keyReference(new KeyReference()) 121 m_keyReference(new KeyReference())
125 { 122 {
126 setWindowTitle(QApplication::applicationName()); 123 setWindowTitle(QApplication::applicationName());
127 124
128 UnitDatabase *udb = UnitDatabase::getInstance(); 125 UnitDatabase *udb = UnitDatabase::getInstance();
267 } 264 }
268 265
269 MainWindow::~MainWindow() 266 MainWindow::~MainWindow()
270 { 267 {
271 delete m_keyReference; 268 delete m_keyReference;
272 delete m_layerTreeView;
273 Profiles::getInstance()->dump(); 269 Profiles::getInstance()->dump();
274 } 270 }
275 271
276 void 272 void
277 MainWindow::setupMenus() 273 MainWindow::setupMenus()
302 QToolBar *toolbar = addToolBar(tr("File Toolbar")); 298 QToolBar *toolbar = addToolBar(tr("File Toolbar"));
303 299
304 m_keyReference->setCategory(tr("File and Session Management")); 300 m_keyReference->setCategory(tr("File and Session Management"));
305 301
306 IconLoader il; 302 IconLoader il;
307 303 QIcon icon;
308 QIcon icon = il.load("filenew"); 304 QAction *action;
309 icon.addPixmap(il.loadPixmap("filenew-22"));
310 QAction *action = new QAction(icon, tr("&Clear Session"), this);
311 action->setShortcut(tr("Ctrl+N"));
312 action->setStatusTip(tr("Abandon the current session and start a new one"));
313 connect(action, SIGNAL(triggered()), this, SLOT(newSession()));
314 m_keyReference->registerShortcut(action);
315 menu->addAction(action);
316 toolbar->addAction(action);
317 305
318 icon = il.load("fileopen"); 306 icon = il.load("fileopen");
319 icon.addPixmap(il.loadPixmap("fileopen-22")); 307 icon.addPixmap(il.loadPixmap("fileopen-22"));
320 action = new QAction(icon, tr("&Add File..."), this); 308 action = new QAction(icon, tr("&Open..."), this);
321 action->setShortcut(tr("Ctrl+O")); 309 action->setShortcut(tr("Ctrl+O"));
322 action->setStatusTip(tr("Add a file")); 310 action->setStatusTip(tr("Open a file"));
323 connect(action, SIGNAL(triggered()), this, SLOT(openFile())); 311 connect(action, SIGNAL(triggered()), this, SLOT(openFile()));
324 m_keyReference->registerShortcut(action); 312 m_keyReference->registerShortcut(action);
325 menu->addAction(action); 313 menu->addAction(action);
326 toolbar->addAction(action); 314 toolbar->addAction(action);
327 315
328 action = new QAction(tr("Add Lo&cation..."), this); 316 action = new QAction(tr("Open Lo&cation..."), this);
329 action->setShortcut(tr("Ctrl+Shift+O")); 317 action->setShortcut(tr("Ctrl+Shift+O"));
330 action->setStatusTip(tr("Add a file from a remote URL")); 318 action->setStatusTip(tr("Open a file from a remote URL"));
331 connect(action, SIGNAL(triggered()), this, SLOT(openLocation())); 319 connect(action, SIGNAL(triggered()), this, SLOT(openLocation()));
332 m_keyReference->registerShortcut(action); 320 m_keyReference->registerShortcut(action);
333 menu->addAction(action); 321 menu->addAction(action);
334 322
335 menu->addSeparator(); 323 m_recentFilesMenu = menu->addMenu(tr("Open &Recent"));
336
337 m_recentFilesMenu = menu->addMenu(tr("&Recent Locations"));
338 m_recentFilesMenu->setTearOffEnabled(true); 324 m_recentFilesMenu->setTearOffEnabled(true);
339 setupRecentFilesMenu(); 325 setupRecentFilesMenu();
340 connect(&m_recentFiles, SIGNAL(recentChanged()), 326 connect(&m_recentFiles, SIGNAL(recentChanged()),
341 this, SLOT(setupRecentFilesMenu())); 327 this, SLOT(setupRecentFilesMenu()));
342 328
520 if (!sb) { 506 if (!sb) {
521 action->setChecked(false); 507 action->setChecked(false);
522 statusBar()->hide(); 508 statusBar()->hide();
523 } 509 }
524 settings.endGroup(); 510 settings.endGroup();
525
526 menu->addSeparator();
527
528 action = new QAction(tr("Show La&yer Hierarchy"), this);
529 action->setShortcut(tr("H"));
530 action->setStatusTip(tr("Open a window displaying the hierarchy of panes and layers in this session"));
531 connect(action, SIGNAL(triggered()), this, SLOT(showLayerTree()));
532 m_keyReference->registerShortcut(action);
533 menu->addAction(action);
534 } 511 }
535 512
536 void 513 void
537 MainWindow::setupHelpMenu() 514 MainWindow::setupHelpMenu()
538 { 515 {
541 518
542 m_keyReference->setCategory(tr("Help")); 519 m_keyReference->setCategory(tr("Help"));
543 520
544 IconLoader il; 521 IconLoader il;
545 522
523 QString name = QApplication::applicationName();
524
546 QAction *action = new QAction(il.load("help"), 525 QAction *action = new QAction(il.load("help"),
547 tr("&Help Reference"), this); 526 tr("&Help Reference"), this);
548 action->setShortcut(tr("F1")); 527 action->setShortcut(tr("F1"));
549 action->setStatusTip(tr("Open the reference manual")); 528 action->setStatusTip(tr("Open the %1 reference manual").arg(name));
550 connect(action, SIGNAL(triggered()), this, SLOT(help())); 529 connect(action, SIGNAL(triggered()), this, SLOT(help()));
551 m_keyReference->registerShortcut(action); 530 m_keyReference->registerShortcut(action);
552 menu->addAction(action); 531 menu->addAction(action);
553 532
554 action = new QAction(tr("&Key and Mouse Reference"), this); 533 action = new QAction(tr("&Key and Mouse Reference"), this);
555 action->setShortcut(tr("F2")); 534 action->setShortcut(tr("F2"));
556 action->setStatusTip(tr("Open a window showing the keystrokes you can use")); 535 action->setStatusTip(tr("Open a window showing the keystrokes you can use in %1").arg(name));
557 connect(action, SIGNAL(triggered()), this, SLOT(keyReference())); 536 connect(action, SIGNAL(triggered()), this, SLOT(keyReference()));
558 m_keyReference->registerShortcut(action); 537 m_keyReference->registerShortcut(action);
559 menu->addAction(action); 538 menu->addAction(action);
560 539
561 action = new QAction(tr("Sonic Visualiser on the &Web"), this); 540 action = new QAction(tr("%1 on the &Web").arg(name), this);
562 action->setStatusTip(tr("Open the Sonic Visualiser website")); 541 action->setStatusTip(tr("Open the %1 website").arg(name));
563 connect(action, SIGNAL(triggered()), this, SLOT(website())); 542 connect(action, SIGNAL(triggered()), this, SLOT(website()));
564 menu->addAction(action); 543 menu->addAction(action);
565 544
566 action = new QAction(tr("&About Sonic Visualiser"), this); 545 action = new QAction(tr("&About %1").arg(name), this);
567 action->setStatusTip(tr("Show information about Sonic Visualiser")); 546 action->setStatusTip(tr("Show information about %1").arg(name));
568 connect(action, SIGNAL(triggered()), this, SLOT(about())); 547 connect(action, SIGNAL(triggered()), this, SLOT(about()));
569 menu->addAction(action); 548 menu->addAction(action);
570 } 549 }
571 550
572 void 551 void
920 899
921 QString path = getOpenFileName(FileFinder::AnyFile); 900 QString path = getOpenFileName(FileFinder::AnyFile);
922 901
923 if (path.isEmpty()) return; 902 if (path.isEmpty()) return;
924 903
925 FileOpenStatus status = open(path, CreateAdditionalModel); 904 FileOpenStatus status = open(path, ReplaceSession);
926 905
927 if (status == FileOpenFailed) { 906 if (status == FileOpenFailed) {
928 QMessageBox::critical(this, tr("Failed to open file"), 907 QMessageBox::critical(this, tr("Failed to open file"),
929 tr("<b>File open failed</b><p>File \"%1\" could not be opened").arg(path)); 908 tr("<b>File open failed</b><p>File \"%1\" could not be opened").arg(path));
930 } else if (status == FileOpenWrongMode) { 909 } else if (status == FileOpenWrongMode) {
952 931
953 settings.setValue("lastremote", text); 932 settings.setValue("lastremote", text);
954 933
955 if (text.isEmpty()) return; 934 if (text.isEmpty()) return;
956 935
957 FileOpenStatus status = open(text, CreateAdditionalModel); 936 FileOpenStatus status = open(text, ReplaceSession);
958 937
959 if (status == FileOpenFailed) { 938 if (status == FileOpenFailed) {
960 QMessageBox::critical(this, tr("Failed to open location"), 939 QMessageBox::critical(this, tr("Failed to open location"),
961 tr("<b>Open failed</b><p>URL \"%1\" could not be opened").arg(text)); 940 tr("<b>Open failed</b><p>URL \"%1\" could not be opened").arg(text));
962 } else if (status == FileOpenWrongMode) { 941 } else if (status == FileOpenWrongMode) {
980 } 959 }
981 960
982 QString path = action->text(); 961 QString path = action->text();
983 if (path == "") return; 962 if (path == "") return;
984 963
985 FileOpenStatus status = open(path, CreateAdditionalModel); 964 FileOpenStatus status = open(path, ReplaceSession);
986 965
987 if (status == FileOpenFailed) { 966 if (status == FileOpenFailed) {
988 QMessageBox::critical(this, tr("Failed to open location"), 967 QMessageBox::critical(this, tr("Failed to open location"),
989 tr("<b>Open failed</b><p>File or URL \"%1\" could not be opened").arg(path)); 968 tr("<b>Open failed</b><p>File or URL \"%1\" could not be opened").arg(path));
990 } else if (status == FileOpenWrongMode) { 969 } else if (status == FileOpenWrongMode) {
1020 { 999 {
1021 // if (pane) m_paneStack->setCurrentPane(pane); 1000 // if (pane) m_paneStack->setCurrentPane(pane);
1022 1001
1023 for (QStringList::iterator i = uriList.begin(); i != uriList.end(); ++i) { 1002 for (QStringList::iterator i = uriList.begin(); i != uriList.end(); ++i) {
1024 1003
1025 FileOpenStatus status = open(*i, CreateAdditionalModel); 1004 FileOpenStatus status = open(*i, ReplaceSession);
1026 1005
1027 if (status == FileOpenFailed) { 1006 if (status == FileOpenFailed) {
1028 QMessageBox::critical(this, tr("Failed to open dropped URL"), 1007 QMessageBox::critical(this, tr("Failed to open dropped URL"),
1029 tr("<b>Open failed</b><p>Dropped URL \"%1\" could not be opened").arg(*i)); 1008 tr("<b>Open failed</b><p>Dropped URL \"%1\" could not be opened").arg(*i));
1030 } else if (status == FileOpenWrongMode) { 1009 } else if (status == FileOpenWrongMode) {
1100 settings.setValue("position", pos()); 1079 settings.setValue("position", pos());
1101 settings.endGroup(); 1080 settings.endGroup();
1102 1081
1103 delete m_keyReference; 1082 delete m_keyReference;
1104 m_keyReference = 0; 1083 m_keyReference = 0;
1105
1106 if (m_layerTreeView &&
1107 m_layerTreeView->isVisible()) {
1108 delete m_layerTreeView;
1109 }
1110 1084
1111 closeSession(); 1085 closeSession();
1112 1086
1113 e->accept(); 1087 e->accept();
1114 return; 1088 return;
1543 m_paneStack->setCurrentPane(pane); 1517 m_paneStack->setCurrentPane(pane);
1544 m_rightButtonMenu->popup(position); 1518 m_rightButtonMenu->popup(position);
1545 } 1519 }
1546 1520
1547 void 1521 void
1548 MainWindow::showLayerTree()
1549 {
1550 if (!m_layerTreeView.isNull()) {
1551 m_layerTreeView->show();
1552 m_layerTreeView->raise();
1553 return;
1554 }
1555
1556 //!!! should use an actual dialog class
1557
1558 m_layerTreeView = new QTreeView();
1559 LayerTreeModel *tree = new LayerTreeModel(m_paneStack);
1560 m_layerTreeView->resize(500, 300); //!!!
1561 m_layerTreeView->setModel(tree);
1562 m_layerTreeView->expandAll();
1563 m_layerTreeView->show();
1564 }
1565
1566 void
1567 MainWindow::handleOSCMessage(const OSCMessage &message) 1522 MainWindow::handleOSCMessage(const OSCMessage &message)
1568 { 1523 {
1569 std::cerr << "MainWindow::handleOSCMessage: Not implemented" << std::endl; 1524 std::cerr << "MainWindow::handleOSCMessage: Not implemented" << std::endl;
1570 } 1525 }
1571 1526