-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
227 lines (202 loc) · 8.66 KB
/
mainwindow.cpp
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the demonstration applications of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "mainwindow.h"
#include "view.h"
#include "c01graphicsscene.h"
#include "c02toolbutton.h"
#include "c04scenecontext.h"
#include <QMenuBar>
#include <QHBoxLayout>
#include <QSplitter>
#include <QTabWidget>
#include <QtWidgets>
#include <QFrame>
#include <QStyleFactory>
MainWindow::MainWindow(QWidget *parent)
: QWidget(parent)
{
QSplitter *vGlobalHorizontalSplitter = new QSplitter;
vGlobalHorizontalSplitter->setOrientation(Qt::Horizontal);
QWidget *vLeftBox=new QWidget;
QVBoxLayout *vLeftBoxLayout=new QVBoxLayout;
vLeftBoxLayout->setMargin(0);
vLeftBoxLayout->setContentsMargins(0,0,0,0);
vLeftBox->setLayout(vLeftBoxLayout);
vGlobalHorizontalSplitter->addWidget(vLeftBox);
QTabWidget *tabWidget = new QTabWidget;
tabWidget->setTabsClosable(true);
connect(tabWidget, &QTabWidget::tabCloseRequested, this, &MainWindow::tabCloseRequested);
globalContext.setTabWidget(tabWidget);
vGlobalHorizontalSplitter->addWidget(tabWidget);
QVBoxLayout *PrimaryLayout=new QVBoxLayout;
QHBoxLayout *layout = new QHBoxLayout;
QWidget *layoutWidget=new QWidget;
layout->addWidget(vGlobalHorizontalSplitter);
//PrimaryLayout->setStretchFactor(layout,20);
//PrimaryLayout->addLayout(layout);
setLayout(PrimaryLayout);
layoutWidget->setLayout(layout);
/************ Menu Bar *******************************************/
QMenuBar * menuBar= new QMenuBar ;
//-----------
QMenu *fileMenu = menuBar->addMenu(tr("&File"));
//-----------
QAction *newAct = new QAction(tr("&New"), this);;
newAct->setShortcuts(QKeySequence::New);
newAct->setStatusTip(tr("Create a new Projet"));
connect(newAct, &QAction::triggered, this, &MainWindow::newProj);
fileMenu->addAction(newAct);
//-----------
newAct = new QAction(tr("&Open"), this);;
newAct->setShortcuts(QKeySequence::New);
newAct->setStatusTip(tr("Open a file"));
fileMenu->addAction(newAct);
//-----------
newAct = new QAction(tr("&Save"), this);;
newAct->setShortcuts(QKeySequence::New);
newAct->setStatusTip(tr("Save current project"));
fileMenu->addAction(newAct);
//-----------
newAct = new QAction(tr("&Save as"), this);;
newAct->setShortcuts(QKeySequence::New);
newAct->setStatusTip(tr("Save current project as"));
fileMenu->addAction(newAct);
//-----------
newAct = new QAction(tr("&Close"), this);;
newAct->setShortcuts(QKeySequence::New);
newAct->setStatusTip(tr("Close project"));
fileMenu->addAction(newAct);
connect(newAct, &QAction::triggered, this, &MainWindow::closeProj);
//-----------
fileMenu = menuBar->addMenu(tr("&Tools"));
//-----------
fileMenu = menuBar->addMenu(tr("&About"));
//-----------
newAct = new QAction(tr("&About"), this);;
newAct->setShortcuts(QKeySequence::New);
newAct->setStatusTip(tr("Nothing for now"));
fileMenu->addAction(newAct);
//-----------
newAct = new QAction(tr("&Preference"), this);;
newAct->setShortcuts(QKeySequence::New);
newAct->setStatusTip(tr("Settings"));
fileMenu->addAction(newAct);
/************ End Menu Bar *******************************************/
PrimaryLayout->addWidget(menuBar);
menuBar->setFixedHeight(25);
PrimaryLayout->addWidget(layoutWidget);
setWindowTitle(tr("Polygone"));
/******************* nouveau ******************************************/
C02ToolButton *toolButton2=new C02ToolButton;
toolButton2->setIconSize( 30);
toolButton2->setNbIconHorizontal(2);
(toolButton2->addToolButton(C03StateMachineBase::MachineBase,QPixmap(":/select.png"),"select 2"))->setChecked(true);
toolButton2->addToolButton(C03StateMachineBase::MachineBase,QPixmap(":/edit-polygon.png"),"edit polygon 2");
toolButton2->addToolButton(C03StateMachineBase::MachineBase,QPixmap(":/draw-polygon.png"),"create polygon 2");
toolButton2->redraw();
C02ToolButton *toolButton=new C02ToolButton;
toolButton->setIconSize( 30);
toolButton->setNbIconHorizontal(2);
(toolButton->addToolButton(C03StateMachineBase::MachineBase,QPixmap(":/select.png"),"select"))->setChecked(true);
toolButton->addToolButton(toolButton2,QPixmap(":/edit-polygon.png"),"edit polygon");
toolButton->addToolButton(C03StateMachineBase::MachineBase,QPixmap(":/draw-polygon.png"),"create polygon");
toolButton->redraw();
globalContext.setToolButton(toolButton);
QFrame * RemainingPlaceWidget=new QFrame;
RemainingPlaceWidget->setFrameStyle(QFrame::Sunken | QFrame::StyledPanel);
//RemainingPlaceWidget->setFixedHeight(65);
//RemainingPlaceWidget->setMaximumHeight(1000);
vLeftBoxLayout->addWidget(toolButton);
vLeftBoxLayout->addWidget(RemainingPlaceWidget);
//ButtonWidget->setFixedHeight(100);
vLeftBoxLayout->setStretchFactor(RemainingPlaceWidget,20);
/******************* creer les scenes ******************************************/
newProj();
/******************* creer les outils ******************************************/
}
void MainWindow::newProj()
{
C01GraphicsScene *scene;
C04SceneContext *context;
scene = new C01GraphicsScene;
scene->populateScene();
scene->registerToolButton(globalContext.getToolButton());
QSplitter *horSplitter = new QSplitter;
QString name=globalContext.getUnusedName();
int tabIndex=globalContext.getTabWidget()->addTab(horSplitter,name);
globalContext.getTabWidget()->setCurrentIndex(tabIndex);
View* theView=scene->addView(name);
horSplitter->addWidget(theView);
horSplitter->addWidget(scene->addView(name));
context =new C04SceneContext(scene,theView,tabIndex,name);
scene->setSceneContext(context);
globalContext.addContext(context);
globalContext.setCurrentContext(context);
//theView->theGraphicsView()->activateWindow();
connect(scene, &C01GraphicsScene::sceneActive, this, &MainWindow::sceneActive);
theView->theGraphicsView()->setFocus();
globalContext.getToolButton()->restoreDefaultButtons();
}
void MainWindow::tabCloseRequested(int tabIndex)
{
C04SceneContext* ptContext=globalContext.getPt(tabIndex);
if (ptContext!=NULL)
{
globalContext.removeContext(ptContext);
}
}
void MainWindow::closeProj()
{
C04SceneContext* ptContext=globalContext.getCurrentContext();
if (ptContext!=NULL)
{
globalContext.removeContext(ptContext);
}
}
void MainWindow::sceneActive(C04SceneContext* context,bool isActive)
{
QString A;
A.append("Polygone : ");
if(isActive)
{
A.append(context->getFileName());
setWindowTitle(A);
globalContext.setCurrentContext(context);
}
else
{
//A.append("NONE");
//globalContext.setCurrentContext(NULL);
}
setWindowTitle(A);
}