Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 5dbc226ab96b55c0ff318ddb389cb361ec2f9c96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
   mainwindow.cc
   This file is part of the Project::OSiRiON zone editor 
   and is distributed under the terms and conditions of 
   the GNU General Public License version 2
*/

#include "mainwindow.h"
#include "editorwindow.h"

namespace editor
{

/**
 * @brief MainWindow is the application's main window.
 * The main window contains a QMdiArea that manages ZoneEditor children
 * */
MainWindow::MainWindow()
{
	// set window title
	setWindowTitle(tr("Project::OSiRiON zone editor"));
	
	// initialize MDI (multiple document interface) area
	mainwindow_mdiarea = new QMdiArea();
	mainwindow_mdiarea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
	mainwindow_mdiarea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
	setCentralWidget(mainwindow_mdiarea);

	// initialize actions
	init_actions();
	
	// initialize menu bar
	init_menu();

}

void MainWindow::init_actions()
{
	// File -> New
	action_new = new QAction( tr("&New..."), this);
	action_new->setShortcuts(QKeySequence::New);
	action_new->setStatusTip(tr("Create a new zone"));
	connect(action_new, SIGNAL(triggered()), this, SLOT(slot_new()));
	
	// File -> Open
	action_open = new QAction( tr("&Open..."), this);
	action_open->setShortcuts(QKeySequence::Open);
	action_open->setStatusTip(tr("Open an existing zone"));
	connect(action_open, SIGNAL(triggered()), this, SLOT(slot_open()));
	
	// File -> Quit
	action_quit = new QAction(tr("&Quit"), this);
	action_quit->setShortcuts(QKeySequence::Quit);
	action_quit->setStatusTip(tr("Exit the application"));
	connect(action_quit, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));
}

void MainWindow::init_menu()
{
	mainwindow_filemenu = menuBar()->addMenu(tr("&File"));
	mainwindow_filemenu->addAction(action_new);
	mainwindow_filemenu->addAction(action_open);
	mainwindow_filemenu->addSeparator();
	mainwindow_filemenu->addAction(action_quit);

	mainwindow_editmenu = menuBar()->addMenu(tr("&Edit"));
}

void MainWindow::add_child()
{
	// create a child widget
	EditorWindow *child_widget = new EditorWindow();

	// add the widget to the MDI area,
	// this will wrap an QMdiSubWindow around it
	mainwindow_mdiarea->addSubWindow(child_widget);
	
	child_widget->show();
}

void MainWindow::slot_new()
{
	add_child();
}

void MainWindow::slot_open()
{
	QString filename = QFileDialog::getOpenFileName(this);
     
	if (!filename.isEmpty()) {
		add_child();
	}
}


}