-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
154 lines (125 loc) · 4.56 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "Widgets/projectfileswidget.h"
#include "ui_palletewidget.h"
#include "Base/elementtoolbutton.h"
#include <Qt>
#include <QGraphicsView>
#include <QAbstractButton>
const int InsertTextButton = 10;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
// Important ordering
setupMenus();
setupActions();
palleteWidget = new PalleteWidget(this);
addDockWidget(Qt::LeftDockWidgetArea, palleteWidget);
setupToolBox();
// end
m_projectFilesMode = new ProjectFileModel(this);
m_projectFilesMode->setRootPath("");
projectFilesWidget = new ProjectFilesWidget(m_projectFilesMode, m_projectFilesModelMenu, this);
addDockWidget(Qt::RightDockWidgetArea, projectFilesWidget);
scenes.append(new DiagramScene(m_itemMenu, this));
scenes.first()->name = "Test tab";
ui->tabWidget->addTab(new QGraphicsView(scenes.first()), scenes.first()->name);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::setupMenus()
{
m_projectFilesModelMenu = new QMenu("File", this);
m_itemMenu = new QMenu(this);
}
void MainWindow::setupActions()
{
QAction *action = new QAction(tr("Save"), this);
action->setIcon(QIcon(":/images/save.png"));
m_projectFilesModelMenu->addAction(action);
}
void MainWindow::toolboxButtonGroupClicked(int id)
{
QList<QAbstractButton *> buttons = toolboxButtonGroup->buttons();
foreach (QAbstractButton *button, buttons)
{
if (toolboxButtonGroup->button(id) != button)
button->setChecked(false);
}
if (id == InsertTextButton)
{
activeScene()->setMode(DiagramScene::InsertText);
}
else
{
activeScene()->setItemType(DiagramItem::DiagramType(id));
activeScene()->setMode(DiagramScene::InsertItem);
}
}
DiagramScene* MainWindow::activeScene()
{
return scenes.first();
}
void MainWindow::setupToolBox()
{
toolboxButtonGroup = new QButtonGroup(this);
toolboxButtonGroup->setExclusive(false);
connect(toolboxButtonGroup, SIGNAL(buttonClicked(int)),
this, SLOT(toolboxButtonGroupClicked(int)));
QGridLayout *layout = new QGridLayout;
layout->addWidget(new ElementToolButton(QPixmap(), toolboxButtonGroup, "Prvy Button", this));
palleteWidget->ui->modelPage->setLayout(layout);
//! [21]
/*
QToolButton *textButton = new QToolButton;
textButton->setCheckable(true);
buttonGroup->addButton(textButton, InsertTextButton);
textButton->setIcon(QIcon(QPixmap(":/images/textpointer.png")
.scaled(30, 30)));
textButton->setIconSize(QSize(50, 50));
QGridLayout *textLayout = new QGridLayout;
textLayout->addWidget(textButton, 0, 0, Qt::AlignHCenter);
textLayout->addWidget(new QLabel(tr("Text")), 1, 0, Qt::AlignCenter);
QWidget *textWidget = new QWidget;
textWidget->setLayout(textLayout);
layout->addWidget(textWidget, 1, 1);
layout->setRowStretch(3, 10);
layout->setColumnStretch(2, 10);
QWidget *itemWidget = new QWidget;
itemWidget->setLayout(layout);
backgroundButtonGroup = new QButtonGroup(this);
connect(backgroundButtonGroup, SIGNAL(buttonClicked(QAbstractButton*)),
this, SLOT(backgroundButtonGroupClicked(QAbstractButton*)));
QGridLayout *backgroundLayout = new QGridLayout;
backgroundLayout->addWidget(createBackgroundCellWidget(tr("Blue Grid"),
":/images/background1.png"), 0, 0);
backgroundLayout->addWidget(createBackgroundCellWidget(tr("White Grid"),
":/images/background2.png"), 0, 1);
backgroundLayout->addWidget(createBackgroundCellWidget(tr("Gray Grid"),
":/images/background3.png"), 1, 0);
backgroundLayout->addWidget(createBackgroundCellWidget(tr("No Grid"),
":/images/background4.png"), 1, 1);
backgroundLayout->setRowStretch(2, 10);
backgroundLayout->setColumnStretch(2, 10);
QWidget *backgroundWidget = new QWidget;
backgroundWidget->setLayout(backgroundLayout);
//! [22]
toolBox = new QToolBox;
toolBox->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Ignored));
toolBox->setMinimumWidth(itemWidget->sizeHint().width());
toolBox->addItem(itemWidget, tr("Basic Flowchart Shapes"));
toolBox->addItem(backgroundWidget, tr("Backgrounds"));*/
}
void MainWindow::on_actionNew_Project_triggered()
{
/*if (newProjectWizard)
{
delete newProjectWizard;
}*/
newProjectWizard = new NewProjectWizard(this);
newProjectWizard->show();
}