introtduction of the actionmanager
[silence:silence.git] / src / gui / mainwindow.cpp
1 /*
2  * Silence
3  *
4  * Copyright (C) 2009, 2010 Manuel Unglaub <m.unglaub@gmail.com>
5  *
6  * This file is part of Silence.
7  *
8  * Silence is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, version GPLv2 only of the License.
11  *
12  * Silence is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16
17  * You should have received a copy of the GNU General Public License
18  * along with Silence.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #include <kactioncollection.h>
22 #include <kaction.h>
23 #include <klocalizedstring.h>
24 #include <KMenuBar>
25 #include <QApplication>
26 #include "src/controller.h"
27 #include "src/gui/actionmanager.h"
28 #include "src/gui/mainwindow.h"
29 #include "src/gui/widget/nodetypemanager.h"
30
31
32 MainWindow::MainWindow(QWidget *parent)
33         : KXmlGuiWindow(parent)
34 {
35         setWindowTitle(i18n("Silence"));
36         Controller *controller = Controller::create();
37         controller->setMainWindow(this);
38         controller->setActionCollection(actionCollection());
39         controller->setActionManager(new ActionManager(actionCollection()));
40
41
42         centralwidgetstack = new QStackedWidget;
43         setCentralWidget(centralwidgetstack);
44
45         // ContentView
46         contentview = new ContentView;
47         centralwidgetstack->addWidget(contentview);
48         controller->setContentView(contentview);
49
50         nodepropertywidget = new NodePropertyWidget(i18n("Properties"), this);
51         nodepropertywidget->hide();
52         controller->setNodePropertyWidget(nodepropertywidget);
53
54         // the treeview on the left side
55         treeview = new TreeView(i18n("Nodes"), actionCollection(), this);
56         controller->setTreeView(treeview);
57
58         // search sidebar
59         searchnodesidebar = new SearchNodeSidebar(i18n("Search Nodes"), this);
60         controller->setSearchNodeSidebar(searchnodesidebar);
61
62         // navigation sidebar
63         navigationsidebar = new NavigationSidebar(i18nc("title of the navigation sidebar", "Navigation"), this);
64         controller->setNavigationSidebar(navigationsidebar);
65
66         // information sidebar to show the metainfos
67         infosidebar = new InfoSidebar(i18n("Information"), this);
68         controller->setInfoSidebar(infosidebar);
69
70         // docking the widgets
71         addDockWidget(Qt::RightDockWidgetArea, navigationsidebar);
72         addDockWidget(Qt::RightDockWidgetArea, infosidebar);
73         addDockWidget(Qt::LeftDockWidgetArea, treeview);
74         addDockWidget(Qt::LeftDockWidgetArea, treeview);
75         tabifyDockWidget(treeview, searchnodesidebar);
76         addDockWidget(Qt::LeftDockWidgetArea, nodepropertywidget);
77
78         statusbar = new SiStatusBar;
79         setStatusBar(statusbar);
80         controller->setStatusBar(statusbar);
81
82         controller->getTextEdit()->setVisible(false);
83         controller->getRichTextEdit()->setVisible(false);
84
85         viewmenu = new ViewMenu(actionCollection());
86         KAction *action = actionCollection()->addAction(KStandardAction::Quit, "exit");
87         connect(action, SIGNAL(triggered()), qApp, SLOT(quit()));
88
89         setupGUI(QSize(1100, 600), Keys | StatusBar | Save | Create);
90 }
91
92 MainWindow::~MainWindow()
93 {
94         delete contentview;
95         delete centralwidgetstack;
96         delete treeview;
97         delete infosidebar;
98         delete statusbar;
99         delete nodepropertywidget;
100         delete searchnodesidebar;
101
102         delete viewmenu;
103
104         delete Controller::create();
105 }
106
107 void MainWindow::deleteFromCentralWidgetStack(QWidget *widget)
108 {
109         centralwidgetstack->removeWidget(widget);
110         delete widget;
111 }
112
113 void MainWindow::showNodeTypeManagement()
114 {
115         NodeTypeManager *ntm = new NodeTypeManager;
116         centralwidgetstack->addWidget(ntm);
117         centralwidgetstack->setCurrentWidget(ntm);
118         connect(ntm, SIGNAL(exit(QWidget*)), this, SLOT(deleteFromCentralWidgetStack(QWidget*)));
119 }
120
121 void MainWindow::showDialog(QWidget *widget)
122 {
123         centralwidgetstack->addWidget(widget);
124         centralwidgetstack->setCurrentWidget(widget);
125 }
126
127 void MainWindow::removeDialog(QWidget *widget)
128 {
129         centralwidgetstack->removeWidget(widget);
130 }
131
132
133