Newer
Older
raoul
committed
#include "main.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
raoul
committed
ui->setupUi(this);
addTab();
ui->tabWidget->removeTab(0);
raoul
committed
delete ui;
}
void MainWindow::keyPressEvent(QKeyEvent* event)
{
raoul
committed
// TODO manage program-level shortcuts
// else forward to active document key handler
ui->openGLWidget->keyPressEvent(event);
}
void MainWindow::keyReleaseEvent(QKeyEvent* event)
{
raoul
committed
// TODO manage program-level shortcuts
// else forward to active document key handler
ui->openGLWidget->keyReleaseEvent(event);
raoul
committed
void MainWindow::addTab()
raoul
committed
QWidget* newtab = new QWidget();
newtab->setObjectName(QStringLiteral("newtab"));
QGridLayout * newGridLayout = new QGridLayout(newtab);
newGridLayout->setSpacing(6);
newGridLayout->setContentsMargins(11, 11, 11, 11);
newGridLayout->setObjectName(QStringLiteral("newGridLayout"));
newGridLayout->setHorizontalSpacing(0);
newGridLayout->setContentsMargins(0, 0, 0, 0);
OE_interfaceDisplay* newOpenGLWidget = new OE_interfaceDisplay(newtab);
newOpenGLWidget->setObjectName(QStringLiteral("newOpenGLWidget"));
newOpenGLWidget->setMouseTracking(true);
newOpenGLWidget->setAcceptDrops(true);
newGridLayout->addWidget(newOpenGLWidget, 0, 0, 1, 1);
int newIndex = ui->tabWidget->addTab(newtab, QString("newtab"));
ui->tabWidget->setTabText(ui->tabWidget->indexOf(newtab), QApplication::translate("MainWindow", "Design", nullptr));
raoul
committed
OE_root* newRoot = new OE_root();
newRoot->document = new OE_document();
newRoot->interfaceDisplay = newOpenGLWidget;
newRoot->interfaceDisplay->setDocument(newRoot->document);
newRoot->display = newRoot->interfaceDisplay;
newRoot->controller = new OE_controller(newRoot->display, newRoot->document);
newRoot->controller->initNewDocument();
newRoot->display->setController(newRoot->controller);
QVariant rootPointerProperty(QVariant::fromValue(static_cast<void*>(newRoot)));
ui->tabWidget->widget(newIndex)->setProperty("OEroot", rootPointerProperty);
raoul
committed
ui->tabWidget->setCurrentIndex(newIndex);
update();
}
raoul
committed
OE_interfaceDisplay* MainWindow::getItfDisplay()
{
QWidget* widget = ui->tabWidget->currentWidget();
OE_root* root = static_cast<OE_root*>(widget->property("OEroot").value<void*>());
return root->interfaceDisplay;
}
raoul
committed
void MainWindow::on_tabWidget_tabCloseRequested(int index)
{
// TODO some brain and warn if loss of data
QWidget* widget = ui->tabWidget->widget(index);
OE_root* root = static_cast<OE_root*>(widget->property("OEroot").value<void*>());
delete root->document;
delete root->controller;
delete root;
ui->tabWidget->removeTab(index);
if (ui->tabWidget->count() == 0)
addTab();
raoul
committed
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
void MainWindow::on_actionNew_triggered()
{
addTab();
}
void MainWindow::on_actionClose_triggered()
{
on_tabWidget_tabCloseRequested(ui->tabWidget->currentIndex());
}
void MainWindow::on_actionOpen_triggered()
{ // TODO real call to a load function, not a fake key event
QKeyEvent fakeKey(QKeyEvent::Type::KeyPress, Qt::Key_O, Qt::KeyboardModifier::ControlModifier);
getItfDisplay()->key(&fakeKey);
}
void MainWindow::on_actionSave_triggered()
{ // TODO real call to a save function, not a fake key event
QKeyEvent fakeKey(QKeyEvent::Type::KeyPress, Qt::Key_S, Qt::KeyboardModifier::ControlModifier);
getItfDisplay()->key(&fakeKey);
}
void MainWindow::on_actionLine_triggered()
{ // TODO real call to a save function, not a fake key event
QKeyEvent fakeKey(QKeyEvent::Type::KeyPress, Qt::Key_L, Qt::KeyboardModifier::NoModifier);
getItfDisplay()->key(&fakeKey);
}
void MainWindow::on_actionUndo_triggered()
{
QKeyEvent fakeKey(QKeyEvent::Type::KeyPress, Qt::Key_Z, Qt::KeyboardModifier::ControlModifier);
getItfDisplay()->key(&fakeKey);
}
void MainWindow::on_actionRedo_triggered()
{
QKeyEvent fakeKey(QKeyEvent::Type::KeyPress, Qt::Key_Z, Qt::KeyboardModifier::ControlModifier|Qt::KeyboardModifier::ShiftModifier);
getItfDisplay()->key(&fakeKey);
}
void MainWindow::on_actionBirail_triggered()
{
QKeyEvent fakeKey(QKeyEvent::Type::KeyPress, Qt::Key_B, Qt::KeyboardModifier::NoModifier);
getItfDisplay()->key(&fakeKey);
}
void MainWindow::on_actionPattern1_triggered()
{
QKeyEvent fakeKey(QKeyEvent::Type::KeyPress, Qt::Key_1, Qt::KeyboardModifier::KeypadModifier);
getItfDisplay()->key(&fakeKey);
}
void MainWindow::on_actionPattern2_triggered()
{
QKeyEvent fakeKey(QKeyEvent::Type::KeyPress, Qt::Key_2, Qt::KeyboardModifier::KeypadModifier);
getItfDisplay()->key(&fakeKey);
}
void MainWindow::on_actionPattern3_triggered()
{
QKeyEvent fakeKey(QKeyEvent::Type::KeyPress, Qt::Key_3, Qt::KeyboardModifier::KeypadModifier);
getItfDisplay()->key(&fakeKey);
}
void MainWindow::on_actionPattern4_triggered()
{
QKeyEvent fakeKey(QKeyEvent::Type::KeyPress, Qt::Key_4, Qt::KeyboardModifier::KeypadModifier);
getItfDisplay()->key(&fakeKey);
}
void MainWindow::on_actionPattern5_triggered()
{
QKeyEvent fakeKey(QKeyEvent::Type::KeyPress, Qt::Key_5, Qt::KeyboardModifier::KeypadModifier);
getItfDisplay()->key(&fakeKey);
}
void MainWindow::on_actionPattern6_triggered()
{
QKeyEvent fakeKey(QKeyEvent::Type::KeyPress, Qt::Key_6, Qt::KeyboardModifier::KeypadModifier);
getItfDisplay()->key(&fakeKey);
}
void MainWindow::on_actionPattern7_triggered()
{
QKeyEvent fakeKey(QKeyEvent::Type::KeyPress, Qt::Key_7, Qt::KeyboardModifier::KeypadModifier);
getItfDisplay()->key(&fakeKey);
}
void MainWindow::on_actionPattern8_triggered()
{
QKeyEvent fakeKey(QKeyEvent::Type::KeyPress, Qt::Key_8, Qt::KeyboardModifier::KeypadModifier);
getItfDisplay()->key(&fakeKey);
}
void MainWindow::on_actionPattern9_triggered()
{
QKeyEvent fakeKey(QKeyEvent::Type::KeyPress, Qt::Key_9, Qt::KeyboardModifier::KeypadModifier);
getItfDisplay()->key(&fakeKey);
}
void MainWindow::on_tabWidget_currentChanged(int index)
{
if (index >= 0)
{
// Ugly hack because OE_actions can't work on multiple documents (shame on you)
QWidget* widget = ui->tabWidget->widget(index);
OE_root* root = static_cast<OE_root*>(widget->property("OEroot").value<void*>());
OE_actions::setCurrentDocument(root->document);
}
}
void MainWindow::on_actionCloseCurve_triggered()
{
QKeyEvent fakeKey(QKeyEvent::Type::KeyPress, Qt::Key_C, Qt::KeyboardModifier::NoModifier);
getItfDisplay()->key(&fakeKey);
}
void MainWindow::on_actionReverse_curve_R_triggered()
{
QKeyEvent fakeKey(QKeyEvent::Type::KeyPress, Qt::Key_R, Qt::KeyboardModifier::NoModifier);
getItfDisplay()->key(&fakeKey);
}
void MainWindow::on_actionFill_triggered()
raoul
committed
QKeyEvent fakeKey(QKeyEvent::Type::KeyPress, Qt::Key_F, Qt::KeyboardModifier::NoModifier);
getItfDisplay()->key(&fakeKey);