Newer
Older
#include "OE_ui_toolbox.h"
#include <QtWidgets/QFormLayout>
#include <qtmaterialtooltabs_internal.h>
#include "ui_mainwindow.h"
OE_ui_toolBox::OE_ui_toolBox(MainWindow* window, OE_root* root)
{
this->root = root;
this->window = window;
buttonFont = QFont("Roboto", 8, QFont::Medium);
setFixedWidth(150);
setSizePolicy(QSizePolicy ::Fixed , QSizePolicy ::Expanding );
QVBoxLayout *drawerLeftLayout = new QVBoxLayout;
setLayout(drawerLeftLayout);
drawerLeftLayout->setMargin(0);
drawerLeftLayout->setContentsMargins(0,0,0,0);
QtMaterialToolTabs *tabs = new QtMaterialToolTabs;
tabs->setSizePolicy(QSizePolicy ::Expanding , QSizePolicy ::Expanding );
drawerLeftLayout->addWidget(tabs);
tabs->setFont(buttonFont);
addFilesTools(tabs);
setFilesDisplayStyle(getInterfaceDisplay()->style);
setGuidesDisplayStyle(getInterfaceDisplay()->addDisplayStyle());
addStitchTools(tabs);
setStitchDisplayStyle(getInterfaceDisplay()->addDisplayStyle());
addThreadTools(tabs);
setThreadDisplayStyle(getInterfaceDisplay()->addDisplayStyle());
addTechnicalTools(tabs);
setTechnicalDisplayStyle(getInterfaceDisplay()->addDisplayStyle());
addMachineTools(tabs);
setMachineDisplayStyle(getInterfaceDisplay()->addDisplayStyle());
connect(tabs, SIGNAL(currentChanged(int)), this, SLOT(currentTabChanged(int)));
drawerLeftLayout->setStretch(0,1);
setContentsMargins(0, 0, 0, 0);
}
QtMaterialFlatButton* OE_ui_toolBox::setButton(QString name, const QObject *receiver = NULL, const char * method = NULL)
{
QtMaterialFlatButton* button = new QtMaterialFlatButton(name);
button->setFont(buttonFont);
button->setUseThemeColors(true);
button->setHaloVisible(false);
button->setTextAlignment(Qt::AlignLeft);
button->setMinimumHeight(0);
if (method)
connect(button, SIGNAL(clicked(bool)), receiver, method);
QtMaterialFlatButton* OE_ui_toolBox::setButton(QString name,QString iconFile, const QObject *receiver = NULL, const char * method = NULL)
QtMaterialFlatButton* newButton = setButton(name, receiver, method);
QIcon icon;
icon.addFile(iconFile, QSize(), QIcon::Normal, QIcon::Off);
newButton->setIcon(icon);
//newButton->setIconPlacement(Material::ButtonIconPlacement::RightIcon);
return newButton;
}
void OE_ui_toolBox::addFilesTools(QtMaterialToolTabs *tabs)
{
QtMaterialToolTab* curTab = new QtMaterialToolTab("Files");
tabs->addTab(curTab);
QVBoxLayout *toolLayout = new QVBoxLayout(curTab->content());
toolLayout->setMargin(0);
toolLayout->setSpacing(0);
toolLayout->setContentsMargins(0,0,0,0);
toolLayout->addWidget(setButton("New",":/resources/new.svg", this, SLOT(on_actionNew_triggered())));
toolLayout->addWidget(setButton("Open",":/resources/open.svg", this, SLOT(on_actionOpen_triggered())));
toolLayout->addWidget(setButton("Save as",":/resources/save.svg", this, NULL));
toolLayout->addStretch();
}
void OE_ui_toolBox::addGuidesTools(QtMaterialToolTabs *tabs)
{
QtMaterialToolTab* curTab = new QtMaterialToolTab("Curves");
tabs->addTab(curTab);
QVBoxLayout *toolLayout = new QVBoxLayout(curTab->content());
toolLayout->setMargin(0);
toolLayout->setSpacing(0);
toolLayout->setContentsMargins(0,0,0,0);
toolLayout->addWidget(setButton("Close", this, SLOT(on_actionCloseCurve_triggered())));
//toolLayout->addWidget(setButton("Reverse", this, SLOT(on_actionReverse_curve_R_triggered())));
QLabel* label = new QLabel("Turn: ");
label->setFont(buttonFont);
label->setAlignment(Qt::AlignCenter);
toolLayout->addWidget(label);
QHBoxLayout *turnLayout = new QHBoxLayout();//curTab->content());
toolLayout->addLayout(turnLayout);
turnLayout->addWidget(setButton("Right"));
turnLayout->addWidget(setButton("Left"));
turnLayout->addWidget(setButton("360°"));
toolLayout->addWidget(setButton("Add curve"));
toolLayout->addStretch();
}
void OE_ui_toolBox::addStitchTools(QtMaterialToolTabs *tabs)
{
QtMaterialToolTab* curTab = new QtMaterialToolTab("Stitches");
tabs->addTab(curTab);
QVBoxLayout *toolLayout = new QVBoxLayout(curTab->content());
toolLayout->setMargin(0);
toolLayout->setSpacing(0);
toolLayout->setContentsMargins(0,0,0,0);
toolLayout->addWidget(setButton("New line", this, SLOT(on_actionLine_triggered())));
toolLayout->addWidget(setButton("New birail", this, SLOT(on_actionBirail_triggered())));
toolLayout->addWidget(setButton("New fill", this, SLOT(on_actionFill_triggered())));
//toolLayout->addWidget(setButton("Reverse selected", SLOT(on_actionReverse_curve_R_triggered())));
toolLayout->addStretch();
QLabel* label = new QLabel("-- favorite Paterns --");
label->setFont(buttonFont);
label->setAlignment(Qt::AlignCenter);
toolLayout->addWidget(label);
QGridLayout * paternLayout = new QGridLayout();
toolLayout->addLayout(paternLayout);
paternLayout->addWidget(setButton("1", this, SLOT(on_actionPattern1_triggered())),0,0,1,1);
paternLayout->addWidget(setButton("2", this, SLOT(on_actionPattern2_triggered())),0,1,1,1);
paternLayout->addWidget(setButton("3", this, SLOT(on_actionPattern3_triggered())),0,2,1,1);
/*paternLayout->addWidget(setButton("3",SLOT(on_actionPattern3_triggered())),0,2,1,1);
QtMaterialFlatButton* button = new QtMaterialFlatButton("3");
button->setFont(buttonFont);
button->setUseThemeColors(true);
button->setHaloVisible(false);
button->setTextAlignment(Qt::AlignLeft);
button->setMinimumHeight(0);
button->addAction(window->actionPattern3);*/
paternLayout->addWidget(setButton("4", this, SLOT(on_actionPattern4_triggered())),0,3,1,1);
paternLayout->addWidget(setButton("5", this, SLOT(on_actionPattern5_triggered())),0,4,1,1);
paternLayout->addWidget(setButton("6", this, SLOT(on_actionPattern6_triggered())),1,0,1,1);
paternLayout->addWidget(setButton("7", this, SLOT(on_actionPattern7_triggered())),1,1,1,1);
paternLayout->addWidget(setButton("8", this, SLOT(on_actionPattern8_triggered())),1,2,1,1);
paternLayout->addWidget(setButton("9", this, SLOT(on_actionPattern9_triggered())),1,3,1,1);
paternLayout->addWidget(setButton("10", this, SLOT(on_actionPattern9_triggered())),1,4,1,1);
}
void OE_ui_toolBox::addThreadTools(QtMaterialToolTabs *tabs)
{
QtMaterialToolTab* curTab = new QtMaterialToolTab("Threads");
tabs->addTab(curTab);
//curTab->button()->setIcon(icon);
//curTab->button()->setIconSize(QSize(22, 22));
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"));
toolLayout->addStretch();
QLabel* label = new QLabel("-- Used threads --");
label->setFont(buttonFont);
label->setAlignment(Qt::AlignCenter);
toolLayout->addWidget(label);
QGridLayout * paternLayout = new QGridLayout();
toolLayout->addLayout(paternLayout);
paternLayout->addWidget(setButton("1", this, SLOT(on_actionPattern1_triggered())),0,0,1,1);
paternLayout->addWidget(setButton("2", this, SLOT(on_actionPattern2_triggered())),0,1,1,1);
paternLayout->addWidget(setButton("3", this, SLOT(on_actionPattern3_triggered())),0,2,1,1);
paternLayout->addWidget(setButton("4", this, SLOT(on_actionPattern4_triggered())),0,3,1,1);
paternLayout->addWidget(setButton("5", this, SLOT(on_actionPattern5_triggered())),0,4,1,1);
paternLayout->addWidget(setButton("6", this, SLOT(on_actionPattern6_triggered())),1,0,1,1);
paternLayout->addWidget(setButton("+", this, SLOT(on_actionPattern5_triggered())),1,1,1,1);
}
void OE_ui_toolBox::addTechnicalTools(QtMaterialToolTabs *tabs)
{
QtMaterialToolTab* curTab = new QtMaterialToolTab("Technical");
tabs->addTab(curTab);
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 OE_ui_toolBox::addMachineTools(QtMaterialToolTabs *tabs)
{
QtMaterialToolTab* curTab = new QtMaterialToolTab("Machine control");
tabs->addTab(curTab);
QVBoxLayout *toolLayout = new QVBoxLayout(curTab->content());
toolLayout->setMargin(0);
toolLayout->setSpacing(0);
toolLayout->setContentsMargins(0,0,0,0);
toolLayout->addWidget(setButton("Connect", window, SLOT(on_actionConnectToMachine_triggered(bool))));
toolLayout->addWidget(setButton("Push", this, SLOT(on_actionMachineLoad_triggered())));
toolLayout->addWidget(setButton("Run", this, SLOT(on_actionMachineRun_triggered())));
connect(window, SIGNAL(machineConnectionChanged(bool)), this, SLOT(on_machineConnectionChanged(bool)));
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
void OE_ui_toolBox::setFilesDisplayStyle(OE_display::OE_displayStyle* style){};
void OE_ui_toolBox::setGuidesDisplayStyle(OE_display::OE_displayStyle* style)
{
style->selectStitches = false;
}
void OE_ui_toolBox::setStitchDisplayStyle(OE_display::OE_displayStyle* style)
{
style->selectCurves = false;
}
void OE_ui_toolBox::setThreadDisplayStyle(OE_display::OE_displayStyle* style){};
void OE_ui_toolBox::setTechnicalDisplayStyle(OE_display::OE_displayStyle* style){};
void OE_ui_toolBox::setMachineDisplayStyle(OE_display::OE_displayStyle* style)
{
style->drawGrid = false;
style->drawCurves = false;
style->drawStitches = false;
style->drawCommands = true;
};
OE_controller* OE_ui_toolBox::getController()
{
return this->root->interfaceDisplay->getController();
}
OE_interfaceDisplay* OE_ui_toolBox::getInterfaceDisplay()
{
return this->root->interfaceDisplay;
}
OE_document* OE_ui_toolBox::getDocument()
{
return this->root->interfaceDisplay->getDocument();
}
void OE_ui_toolBox::sendKeyPulse(Qt::Key key, Qt::KeyboardModifiers modifiers)
{
QKeyEvent fakeKeyPress(QKeyEvent::Type::KeyPress, key, modifiers);
root->interfaceDisplay->key(&fakeKeyPress);
QKeyEvent fakeKeyRelease(QKeyEvent::Type::KeyRelease, key, modifiers);
root->interfaceDisplay->key(&fakeKeyRelease);
}
void OE_ui_toolBox::currentTabChanged(int tabId)
{
getInterfaceDisplay()->setDisplayStyle(tabId);
getInterfaceDisplay()->update();
}
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
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
342
void OE_ui_toolBox::on_actionNew_triggered()
{
window->addTab();
}
void OE_ui_toolBox::on_actionOpen_triggered()
{ // TODO real call to a load function, not a fake key event
sendKeyPulse(Qt::Key_O, Qt::KeyboardModifier::ControlModifier);
}
void OE_ui_toolBox::on_actionSave_triggered()
{ // TODO real call to a save function, not a fake key event
sendKeyPulse(Qt::Key_S, Qt::KeyboardModifier::ControlModifier);
}
void OE_ui_toolBox::on_actionLine_triggered()
{ // TODO real call to a save function, not a fake key event
sendKeyPulse(Qt::Key_L, Qt::KeyboardModifier::NoModifier);
}
void OE_ui_toolBox::on_actionBirail_triggered()
{
sendKeyPulse(Qt::Key_B, Qt::KeyboardModifier::NoModifier);
}
void OE_ui_toolBox::on_actionFill_triggered()
{
sendKeyPulse(Qt::Key_F, Qt::KeyboardModifier::NoModifier);
}
void OE_ui_toolBox::on_actionPattern1_triggered() { sendKeyPulse(Qt::Key_1, Qt::KeyboardModifier::KeypadModifier); }
void OE_ui_toolBox::on_actionPattern2_triggered() { sendKeyPulse(Qt::Key_2, Qt::KeyboardModifier::KeypadModifier); }
void OE_ui_toolBox::on_actionPattern3_triggered() { sendKeyPulse(Qt::Key_3, Qt::KeyboardModifier::KeypadModifier); }
void OE_ui_toolBox::on_actionPattern4_triggered() { sendKeyPulse(Qt::Key_4, Qt::KeyboardModifier::KeypadModifier); }
void OE_ui_toolBox::on_actionPattern5_triggered() { sendKeyPulse(Qt::Key_5, Qt::KeyboardModifier::KeypadModifier); }
void OE_ui_toolBox::on_actionPattern6_triggered() { sendKeyPulse(Qt::Key_6, Qt::KeyboardModifier::KeypadModifier); }
void OE_ui_toolBox::on_actionPattern7_triggered() { sendKeyPulse(Qt::Key_7, Qt::KeyboardModifier::KeypadModifier); }
void OE_ui_toolBox::on_actionPattern8_triggered() { sendKeyPulse(Qt::Key_8, Qt::KeyboardModifier::KeypadModifier); }
void OE_ui_toolBox::on_actionPattern9_triggered() { sendKeyPulse(Qt::Key_9, Qt::KeyboardModifier::KeypadModifier); }
void OE_ui_toolBox::on_actionCloseCurve_triggered()
{
sendKeyPulse(Qt::Key_C, Qt::KeyboardModifier::NoModifier);
}
/*void OE_ui_toolBox::on_actionReverse_curve_R_triggered()
{
sendKeyPulse(Qt::Key_R, Qt::KeyboardModifier::NoModifier);
}*/
void OE_ui_toolBox::on_actionMachineRun_triggered()
{
window->machineRun();
}
void OE_ui_toolBox::on_actionMachineLoad_triggered()
{
window->machineLoad();
}
void OE_ui_toolBox::on_machineConnectionChanged(bool connected)
{
// ui->actionMachineRun->setEnabled(connected);
// ui->actionMachineLoad->setEnabled(connected);
}