Newer
Older
raoul
committed
#include "main.h"
#include "machine.h"
#include <QSerialPortInfo>
#include <QDebug>
#include <qtmaterialtooltabs_internal.h>
#include "qtmaterialiconbutton.h"
#include "qtmaterialtoggle.h"
#include "qtmaterialcheckbox.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
raoul
committed
ui->setupUi(this);
raoul
committed
addTab();
ui->tabWidget->removeTab(0);
connect(machine.get(), &Machine::connectionChanged, this, &MainWindow::on_machineConnectionChanged);
connect(machine.get(), &Machine::stateChanged, this, &MainWindow::on_machineStateChanged);
raoul
committed
delete ui;
}
void MainWindow::keyPressEvent(QKeyEvent* event)
{
QWidget* widget = ui->tabWidget->currentWidget();
OE_root* root = static_cast<OE_root*>(widget->property("OEroot").value<void*>());
root->display->keyPressEvent(event);
}
void MainWindow::keyReleaseEvent(QKeyEvent* event)
{
QWidget* widget = ui->tabWidget->currentWidget();
OE_root* root = static_cast<OE_root*>(widget->property("OEroot").value<void*>());
root->display->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);
//opengl window overlay
QBoxLayout *openglWidgetLayout = new QHBoxLayout;
newOpenGLWidget->setLayout(openglWidgetLayout);
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
openglWidgetLayout->setSpacing(0);
openglWidgetLayout->setMargin(0);
openglWidgetLayout->setContentsMargins(0, 0, 0, 0);
//left tool tab
QWidget* m_leftToolTab = leftToolTab();
openglWidgetLayout->addWidget(m_leftToolTab);
openglWidgetLayout->setStretch(0, 0);
//viewport top bar (viewport options)
QBoxLayout *topGlWindowLayout = topGlWindowBar();
openglWidgetLayout->addLayout(topGlWindowLayout);
openglWidgetLayout->setStretch(1, 0);
openglWidgetLayout->addStretch(1);
//viewport top bar (viewport options)
QBoxLayout *stitchParamLayout = stitchParam();
openglWidgetLayout->addLayout(stitchParamLayout);
openglWidgetLayout->setStretch(3, 0);
QVBoxLayout *stitchesList = new QVBoxLayout();
stitchesList->setMargin(0);
stitchesList->setSpacing(0);
stitchesList->setContentsMargins(0,0,0,0);
QtMaterialFlatButton* button = new QtMaterialFlatButton("here soon the stitches list");
button->setFont(QFont("Roboto", 8, QFont::Medium));
button->setUseThemeColors(true);
button->setRole(Material::Role::Primary);
button->setBackgroundMode(Qt::BGMode::OpaqueMode);
button->setSizePolicy(QSizePolicy ::Expanding , QSizePolicy ::Expanding );
button->setHaloVisible(false);
button->setMinimumHeight(150);
stitchesList->addWidget(button);
openglWidgetLayout->addLayout(stitchesList);
openglWidgetLayout->setStretch(4, 0);
raoul
committed
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();
raoul
committed
newRoot->interfaceDisplay = newOpenGLWidget;
newRoot->interfaceDisplay->setDocument(newRoot->document);
raoul
committed
newRoot->display = newRoot->interfaceDisplay;
newRoot->controller = new OE_controller(newRoot->display, newRoot->document);
raoul
committed
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();
}
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
QtMaterialIconButton* MainWindow::setIconButton(QString iconFile, const char * method = NULL)
{
QIcon icon;
icon.addFile(iconFile, QSize(), QIcon::Normal, QIcon::Off);
QtMaterialIconButton* button = new QtMaterialIconButton(icon);
button->setUseThemeColors(false);
button->setIconSize(QSize(25,25));
if (method)
connect(button, SIGNAL(clicked(bool)), this, method);
return button;
}
QBoxLayout* MainWindow::topGlWindowBar()
{
QHBoxLayout *topGlWindowLayout = new QHBoxLayout;
topGlWindowLayout->setAlignment(Qt::AlignTop);
topGlWindowLayout->setSpacing(4);
topGlWindowLayout->setMargin(3);
topGlWindowLayout->addWidget(setIconButton(":/resources/zoom_selection.svg"));
topGlWindowLayout->addWidget(setIconButton(":/resources/zoom_document.svg"));
topGlWindowLayout->addSpacing(8);
topGlWindowLayout->addWidget(setIconButton(":/resources/grid.svg"));
topGlWindowLayout->addWidget(setIconButton(":/resources/show_curve.svg"));
topGlWindowLayout->addWidget(setIconButton(":/resources/show_stitch.svg"));
topGlWindowLayout->addSpacing(8);
topGlWindowLayout->addWidget(setIconButton(":/resources/select_curve.svg"));
topGlWindowLayout->addWidget(setIconButton(":/resources/select_stitch.svg"));
return topGlWindowLayout;
}
QBoxLayout* MainWindow::stitchParam()
{
QVBoxLayout *topGlWindowLayout = new QVBoxLayout;
topGlWindowLayout->setAlignment(Qt::AlignTop);
topGlWindowLayout->addWidget(new QtMaterialToggle());
QtMaterialCheckBox* m_checkBox = new QtMaterialCheckBox();
m_checkBox->setText("param2");
m_checkBox->setIconSize(QSize(5,5));
topGlWindowLayout->addWidget(m_checkBox);
topGlWindowLayout->setAlignment(m_checkBox, Qt::AlignCenter);
topGlWindowLayout->addWidget(new QtMaterialFlatButton("param3"));
return topGlWindowLayout;
}
QWidget* MainWindow::leftToolTab()
QWidget* m_drawerleft = new QWidget();
m_drawerleft->setFixedWidth(150);
m_drawerleft->setSizePolicy(QSizePolicy ::Fixed , QSizePolicy ::Expanding );
//QtMaterialDrawer* m_drawerleft = new QtMaterialDrawer();
//m_drawerleft->setParent(widget);
QVBoxLayout *drawerLeftLayout = new QVBoxLayout;
//m_drawerleft->setDrawerLayout(drawerLeftLayout);
m_drawerleft->setLayout(drawerLeftLayout);
drawerLeftLayout->setMargin(0);
drawerLeftLayout->setContentsMargins(0,0,0,0);
QtMaterialToolTabs *tabs = new QtMaterialToolTabs;
tabs->setSizePolicy(QSizePolicy ::Expanding , QSizePolicy ::Expanding );
drawerLeftLayout->addWidget(tabs);
//drawerLeftLayout->setAlignment(tabs, Qt::AlignHCenter);
tabs->setFont(QFont("Roboto", 10, QFont::Medium));
addFilesTools(tabs);
addGuidesTools(tabs);
addStitchTools(tabs);
addThreadTools(tabs);
addMachineTools(tabs);
drawerLeftLayout->setStretch(0,1);
m_drawerleft->setContentsMargins(0, 0, 0, 0);
//m_drawerleft->setOverlayMode(false);
//m_drawerleft->setClickOutsideToClose(false);
m_drawerleft->setEnabled(true);
//m_drawerleft->setDrawerWidth(150);
//m_drawerleft->setAnchor(Qt::AnchorLeft);
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
}
QtMaterialFlatButton* MainWindow::setButton(QString name, const char * method = NULL)
{
QtMaterialFlatButton* button = new QtMaterialFlatButton(name);
button->setFont(QFont("Roboto", 8, QFont::Medium));
button->setUseThemeColors(true);
button->setHaloVisible(false);
button->setMinimumHeight(0);
if (method)
connect(button, SIGNAL(clicked(bool)), this, method);
return button;
}
void MainWindow::addFilesTools(QtMaterialToolTabs *tabs)
{
QtMaterialToolTab* curTab = tabs->addTab("Files");
QVBoxLayout *toolLayout = new QVBoxLayout(curTab->content());
toolLayout->setMargin(0);
toolLayout->setSpacing(0);
toolLayout->setContentsMargins(0,0,0,0);
toolLayout->addWidget(setButton("New", SLOT(on_actionNew_triggered())));
toolLayout->addWidget(setButton("Open", SLOT(on_actionOpen_triggered())));
toolLayout->addWidget(setButton("Append"));
toolLayout->addWidget(setButton("Save as"));
toolLayout->addStretch();
}
void MainWindow::addGuidesTools(QtMaterialToolTabs *tabs)
{
QtMaterialToolTab* curTab = tabs->addTab("Curves");
QVBoxLayout *toolLayout = new QVBoxLayout(curTab->content());
toolLayout->setMargin(0);
toolLayout->setSpacing(0);
toolLayout->setContentsMargins(0,0,0,0);
toolLayout->addWidget(setButton("Close", SLOT(on_actionCloseCurve_triggered())));
toolLayout->addWidget(setButton("Reverse", SLOT(on_actionReverse_curve_R_triggered())));
QHBoxLayout *turnLayout = new QHBoxLayout(curTab->content());
toolLayout->addLayout(turnLayout);
turnLayout->addWidget(setButton("Turn: "));
turnLayout->addWidget(setButton("Right"));
turnLayout->addWidget(setButton("Left"));
turnLayout->addWidget(setButton("360°"));
toolLayout->addWidget(setButton("Add curve"));
toolLayout->addStretch();
}
void MainWindow::addStitchTools(QtMaterialToolTabs *tabs)
{
QtMaterialToolTab* curTab = tabs->addTab("Stitches");
QVBoxLayout *toolLayout = new QVBoxLayout(curTab->content());
toolLayout->setMargin(0);
toolLayout->setSpacing(0);
toolLayout->setContentsMargins(0,0,0,0);
toolLayout->addWidget(setButton("New line", SLOT(on_actionLine_triggered())));
toolLayout->addWidget(setButton("New birail", SLOT(on_actionBirail_triggered())));
toolLayout->addWidget(setButton("New fill", SLOT(on_actionFill_triggered())));
toolLayout->addWidget(setButton("Reverse selected"));
toolLayout->addStretch();
QLabel* label = new QLabel("-- Paterns favorite --");
label->setFont(QFont("Roboto", 8, QFont::Medium));
label->setAlignment(Qt::AlignCenter);
toolLayout->addWidget(label);
QGridLayout * paternLayout = new QGridLayout();
toolLayout->addLayout(paternLayout);
paternLayout->addWidget(setButton("1",SLOT(on_actionPattern1_triggered())),0,0,1,1);
paternLayout->addWidget(setButton("2",SLOT(on_actionPattern2_triggered())),0,1,1,1);
paternLayout->addWidget(setButton("3",SLOT(on_actionPattern3_triggered())),0,2,1,1);
paternLayout->addWidget(setButton("4",SLOT(on_actionPattern4_triggered())),0,3,1,1);
paternLayout->addWidget(setButton("5",SLOT(on_actionPattern5_triggered())),0,4,1,1);
paternLayout->addWidget(setButton("6",SLOT(on_actionPattern6_triggered())),1,0,1,1);
paternLayout->addWidget(setButton("7",SLOT(on_actionPattern7_triggered())),1,1,1,1);
paternLayout->addWidget(setButton("8",SLOT(on_actionPattern8_triggered())),1,2,1,1);
paternLayout->addWidget(setButton("9",SLOT(on_actionPattern9_triggered())),1,3,1,1);
paternLayout->addWidget(setButton("10",SLOT(on_actionPattern9_triggered())),1,4,1,1);
}
void MainWindow::addThreadTools(QtMaterialToolTabs *tabs)
{
QtMaterialToolTab* curTab = tabs->addTab("Threads");
QVBoxLayout *toolLayout = new QVBoxLayout(curTab->content());
toolLayout->setMargin(0);
toolLayout->setSpacing(0);
toolLayout->setContentsMargins(0,0,0,0);
toolLayout->addWidget(setButton("New thread from lib"));
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
toolLayout->addStretch();
QLabel* label = new QLabel("-- Used threads --");
label->setFont(QFont("Roboto", 8, QFont::Medium));
label->setAlignment(Qt::AlignCenter);
toolLayout->addWidget(label);
QGridLayout * paternLayout = new QGridLayout();
toolLayout->addLayout(paternLayout);
paternLayout->addWidget(setButton("1",SLOT(on_actionPattern1_triggered())),0,0,1,1);
paternLayout->addWidget(setButton("2",SLOT(on_actionPattern2_triggered())),0,1,1,1);
paternLayout->addWidget(setButton("3",SLOT(on_actionPattern3_triggered())),0,2,1,1);
paternLayout->addWidget(setButton("4",SLOT(on_actionPattern4_triggered())),0,3,1,1);
paternLayout->addWidget(setButton("5",SLOT(on_actionPattern5_triggered())),0,4,1,1);
paternLayout->addWidget(setButton("6",SLOT(on_actionPattern5_triggered())),1,0,1,1);
paternLayout->addWidget(setButton("+",SLOT(on_actionPattern5_triggered())),1,1,1,1);
}
void MainWindow::addTechnicalTools(QtMaterialToolTabs *tabs)
{
QtMaterialToolTab* curTab = tabs->addTab("Technical");
QVBoxLayout *toolLayout = new QVBoxLayout(curTab->content());
toolLayout->setMargin(0);
toolLayout->setSpacing(0);
toolLayout->setContentsMargins(0,0,0,0);
toolLayout->addWidget(setButton("underlay"));
toolLayout->addWidget(setButton("Push/pull"));
toolLayout->addWidget(setButton("cut link"));
toolLayout->addWidget(setButton("set speed"));
toolLayout->addStretch();
}
void MainWindow::addMachineTools(QtMaterialToolTabs *tabs)
{
QtMaterialToolTab* curTab = tabs->addTab("Machine control");
QVBoxLayout *toolLayout = new QVBoxLayout(curTab->content());
toolLayout->setMargin(0);
toolLayout->setSpacing(0);
toolLayout->setContentsMargins(0,0,0,0);
toolLayout->addWidget(setButton("Connect", SLOT(on_actionConnectToMachine_triggered(bool checked))));
toolLayout->addWidget(setButton("Push", SLOT(on_actionMachineLoad_triggered())));
toolLayout->addWidget(setButton("Run", SLOT(on_actionMachineRun_triggered())));
toolLayout->addStretch();
}
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;
}
void MainWindow::sendKeyPulse(Qt::Key key, Qt::KeyboardModifiers modifiers)
{
QKeyEvent fakeKeyPress(QKeyEvent::Type::KeyPress, key, modifiers);
getItfDisplay()->key(&fakeKeyPress);
QKeyEvent fakeKeyRelease(QKeyEvent::Type::KeyRelease, key, modifiers);
getItfDisplay()->key(&fakeKeyRelease);
}
raoul
committed
void MainWindow::on_tabWidget_tabCloseRequested(int index)
{
// TODO some brain and warn if loss of data
if (ui->tabWidget->count() == 1)
addTab();
raoul
committed
QWidget* widget = ui->tabWidget->widget(index);
OE_root* root = static_cast<OE_root*>(widget->property("OEroot").value<void*>());
raoul
committed
delete root->controller;
delete root;
ui->tabWidget->removeTab(index);
raoul
committed
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
sendKeyPulse(Qt::Key_O, Qt::KeyboardModifier::ControlModifier);
raoul
committed
}
void MainWindow::on_actionSave_triggered()
{ // TODO real call to a save function, not a fake key event
sendKeyPulse(Qt::Key_S, Qt::KeyboardModifier::ControlModifier);
raoul
committed
}
void MainWindow::on_actionLine_triggered()
{ // TODO real call to a save function, not a fake key event
sendKeyPulse(Qt::Key_L, Qt::KeyboardModifier::NoModifier);
raoul
committed
}
void MainWindow::on_actionUndo_triggered()
{
sendKeyPulse(Qt::Key_Z, Qt::KeyboardModifier::ControlModifier);
raoul
committed
}
void MainWindow::on_actionRedo_triggered()
{
sendKeyPulse(Qt::Key_Z, Qt::KeyboardModifier::ControlModifier|Qt::KeyboardModifier::ShiftModifier);
raoul
committed
}
void MainWindow::on_actionBirail_triggered()
{
sendKeyPulse(Qt::Key_B, Qt::KeyboardModifier::NoModifier);
raoul
committed
}
void MainWindow::on_actionPattern1_triggered() { sendKeyPulse(Qt::Key_1, Qt::KeyboardModifier::KeypadModifier); }
void MainWindow::on_actionPattern2_triggered() { sendKeyPulse(Qt::Key_2, Qt::KeyboardModifier::KeypadModifier); }
void MainWindow::on_actionPattern3_triggered() { sendKeyPulse(Qt::Key_3, Qt::KeyboardModifier::KeypadModifier); }
void MainWindow::on_actionPattern4_triggered() { sendKeyPulse(Qt::Key_4, Qt::KeyboardModifier::KeypadModifier); }
void MainWindow::on_actionPattern5_triggered() { sendKeyPulse(Qt::Key_5, Qt::KeyboardModifier::KeypadModifier); }
void MainWindow::on_actionPattern6_triggered() { sendKeyPulse(Qt::Key_6, Qt::KeyboardModifier::KeypadModifier); }
void MainWindow::on_actionPattern7_triggered() { sendKeyPulse(Qt::Key_7, Qt::KeyboardModifier::KeypadModifier); }
void MainWindow::on_actionPattern8_triggered() { sendKeyPulse(Qt::Key_8, Qt::KeyboardModifier::KeypadModifier); }
void MainWindow::on_actionPattern9_triggered() { sendKeyPulse(Qt::Key_9, Qt::KeyboardModifier::KeypadModifier); }
raoul
committed
void MainWindow::on_tabWidget_currentChanged(int index)
{
if (index >= 0)
{ // Discard previous modifiers on that widget
QKeyEvent fakeKey(QKeyEvent::Type::KeyRelease, Qt::Key_Escape, Qt::KeyboardModifier::NoModifier);
getItfDisplay()->key(&fakeKey);
raoul
committed
}
}
void MainWindow::on_actionCloseCurve_triggered()
{
sendKeyPulse(Qt::Key_C, Qt::KeyboardModifier::NoModifier);
raoul
committed
}
void MainWindow::on_actionReverse_curve_R_triggered()
{
sendKeyPulse(Qt::Key_R, Qt::KeyboardModifier::NoModifier);
raoul
committed
}
void MainWindow::on_actionFill_triggered()
sendKeyPulse(Qt::Key_F, Qt::KeyboardModifier::NoModifier);
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
void MainWindow::on_actionConnectToMachine_triggered(bool checked)
{
QString msg;
//msg += checked ? QString::fromUtf8("[ Connected ] ") : QString::fromUtf8("[Disconnected] ");
//msg += QString("Seq %1. Status %2. Space %3/%4. Pos (%5, %6). Point %7. tSensor %8")
// .arg(42,5).arg(7).arg(800,5).arg(1016,-5).arg(24,5).arg(32,-5).arg(301,4).arg(123);
//status.setText(msg);
if (checked)
{
QList<QSerialPortInfo> ports = QSerialPortInfo::availablePorts();
if (ports.size())
{
machine->connectPort(ports.front().portName());
for (const QSerialPortInfo& port : ports)
{
qDebug() << port.portName() << ". " << port.description() << ". " << port.manufacturer() << ". "
<< port.vendorIdentifier() << ". " << port.productIdentifier();
}
}
}
else
{
machine->disconnectPort();
}
}
void MainWindow::on_machineConnectionChanged(bool connected)
{
if (!connected)
{
QString msg = status.text().replace("[ Connected ]", "[Disconnected]");
status.setText(msg);
}
ui->actionMachineRun->setEnabled(connected);
ui->actionMachineLoad->setEnabled(connected);
}
void MainWindow::on_machineStateChanged(Machine::SlaveInfo info)
{
QString msg;
msg = QString("[ Connected ] Seq %1. Status %2. Space %3/%4. Pos (%5, %6). Point %7")
.arg(info.sequence,5)
.arg(info.status)
.arg(info.spaceSize-info.freeSpace,5).arg(info.spaceSize,-5)
.arg(info.posX,5).arg(info.posY,-5)
.arg(info.nPoint,4);
status.setText(msg);
printf("%s\n",msg.toStdString().c_str());
}
void MainWindow::on_actionMachineRun_triggered()
{
if (machine)
machine->startMove();
}
void MainWindow::on_actionMachineLoad_triggered()
{
if (machine)
{
QWidget* widget = ui->tabWidget->currentWidget();
OE_root* root = static_cast<OE_root*>(widget->property("OEroot").value<void*>());
root->controller->sendInstPoint(machine.get());
}
}