Skip to content
Commits on Source (3)
......@@ -121,6 +121,21 @@ class OE_interfaceDisplay : public OE_display
public slots:
void SetSelectedStitchPattern(int index);
void openFile();
void saveFile();
void undo();
void redo();
void closeSelectedCurve();
void deleteSelectedStitches();
void selectNextStitch();
void selectPreviousStitch();
void newLinestitch();
void newBirailstitch();
void newFillstitch();
void scaleSelectedStitchLen(float scale);
void scaleSelectedStitchWidth(float scale);
void zoomOnSelection();
signals:
void stitchSelectionChange();
......
......@@ -284,8 +284,6 @@ void OE_interfaceDisplay::resize(int width, int height)
void OE_interfaceDisplay::key(QKeyEvent* event)
{
static QString writeFilters = QString::fromStdString(OE_document::getWriteDialogFilters());
static QString readFilters = QString::fromStdString(OE_document::getReadDialogFilters());
if (event->type() == QEvent::KeyPress)
modState = event->modifiers();
else
......@@ -308,105 +306,45 @@ void OE_interfaceDisplay::key(QKeyEvent* event)
emit refreshStitchList();
}
}
if(editionState==None)
{
if (event->key() == Qt::Key_Z && event->modifiers() == Qt::ControlModifier)
{
if (controller)
{
controller->undoAction();
update();
emit refreshStitchList();
}
}
else if (event->key() == Qt::Key_S && event->modifiers() == Qt::ControlModifier)
{
if (document)
{
QString fileName = QFileDialog::getSaveFileName(this, "Save design", "", writeFilters);
if (!fileName.isEmpty())
{
document->saveToFile(fileName.toStdString());
}
}
}
else if (event->key() == Qt::Key_O && event->modifiers() == Qt::ControlModifier)
{
QString type;
QString fileName = QFileDialog::getOpenFileName(this, "Open design", "", readFilters, &type);
if (!fileName.isEmpty())
{
loadFile(fileName.toStdString());
update();
emit refreshStitchList();
}
}
else if (event->key() == Qt::Key_Z && event->modifiers() == (Qt::ControlModifier|Qt::ShiftModifier))
{
if (controller)
{
controller->redoAction();
update();
emit refreshStitchList();
}
}
else if (event->modifiers() == Qt::NoModifier)
{
if (event->key() == Qt::Key_C)
{
if (controller)
{
controller->toggleCloseSelectedCurve();
update();
emit refreshStitchList();
}
}
else if (event->key() == Qt::Key_Delete)
{
//TODO create an action to delete all selected stitches
std::list<OE_stitchs*>::iterator it=document->selectedStitchs.begin();
controller->addAction(new OE_actionDelStitch(document, *it));
update();
emit refreshStitchList();
}
else if (event->key() == Qt::Key_Right)
{
std::list<OE_stitchs*>::iterator it=selectedStitches.begin();
if (it != selectedStitches.end())
{
it = std::find (document->stitchs.begin(), document->stitchs.end(), *it);
it++;
if (it != document->stitchs.end())
{
selectedStitches.clear();
selectedStitches.push_back(*it);
controller->clearSelection();
controller->selectStitches(selectedStitches,true);
emit stitchSelectionChange();
update();
}
}
}
else if (event->key() == Qt::Key_Left)
{
std::list<OE_stitchs*>::iterator it=selectedStitches.begin();
if (it != selectedStitches.end())
{
it = std::find (document->stitchs.begin(), document->stitchs.end(), *it);
if (it != document->stitchs.begin())
{
it--;
selectedStitches.clear();
selectedStitches.push_back(*it);
controller->clearSelection();
controller->selectStitches(selectedStitches,true);
emit stitchSelectionChange();
update();
}
}
}
}
}
else if (event->key() == Qt::Key_Z && event->modifiers() == Qt::ControlModifier)
{
undo();
}
else if (event->key() == Qt::Key_S && event->modifiers() == Qt::ControlModifier)
{
saveFile();
}
else if (event->key() == Qt::Key_O && event->modifiers() == Qt::ControlModifier)
{
openFile();
}
else if (event->key() == Qt::Key_Z && event->modifiers() == (Qt::ControlModifier|Qt::ShiftModifier))
{
redo();
}
else if (event->key() == Qt::Key_Y && event->modifiers() == (Qt::ControlModifier))
{
redo();
}
else if (event->modifiers() == Qt::NoModifier)
{
if (event->key() == Qt::Key_C)
{
closeSelectedCurve();
}
else if (event->key() == Qt::Key_Delete)
{
deleteSelectedStitches();
}
else if (event->key() == Qt::Key_Right)
{
selectNextStitch();
}
else if (event->key() == Qt::Key_Left)
{
selectPreviousStitch();
}
}
}
if (event->type() == QEvent::KeyRelease)
......@@ -430,96 +368,37 @@ void OE_interfaceDisplay::key(QKeyEvent* event)
{
if (event->key() == Qt::Key_L)
{
if (controller)
{
controller->newLineStitch(2.5, 2.5, controller->getPattern(0));
document->selectedStitchs.push_back(controller->getLineStitch(-1));
curJoincurve = controller->getLineStitch(-1)->getJoincurve();
closestCurve = controller->getClosestCurve(absMouse, editClosestPoint);
editionState = NewSubcurve;
joincurve_id = 0;
subcurve_id = -1;
update();
emit refreshStitchList();
}
newLinestitch();
}
else if (event->key() == Qt::Key_B)
{
if (controller)
{
controller->newBirailStitch(false, false, 0, 0, 0.7f);
document->selectedStitchs.push_back(controller->getBirailStitch(-1));
curJoincurve = controller->getBirailStitch(-1)->getJoincurve1();
closestCurve = controller->getClosestCurve(absMouse, editClosestPoint);
editionState = NewSubcurve;
joincurve_id = 1;
subcurve_id = -1;
update();
emit refreshStitchList();
}
newBirailstitch();
}
else if (event->key() == Qt::Key_F)
{
if (controller)
{
controller->newFillStitch(1.5f, 0.3f, controller->getPattern(0));
document->selectedStitchs.push_back(controller->getFillStitch(-1));
curJoincurve = controller->getFillStitch(-1)->getJoincurve();
closestCurve = controller->getClosestCurve(absMouse, editClosestPoint);
editionState = NewSubcurve;
joincurve_id = 0;
subcurve_id = -1;
update();
emit refreshStitchList();
}
newFillstitch();
}
/*else if (event->key() == Qt::Key_Enter)
{
if (editionState == NewSubcurve)
{
if (joincurve_id == 0)
{
editionState = None;
curJoincurve = 0;
}
else
{
curJoincurve = controller->getBirailStitch(-1)->getJoincurve2();
closestCurve = controller->getClosestCurve(absMouse, editClosestPoint);
joincurve_id -= 1;
}
}
}*/
else if (event->key() == Qt::Key_Plus && event->modifiers() & Qt::KeypadModifier)
{
if (event->modifiers() & Qt::ControlModifier)
{
controller->addAction(new OE_actionScaleSelectedStitchLen(document, 1.1f));
update();
emit refreshStitchList();
scaleSelectedStitchLen(1.1f);
}
else
{
controller->addAction(new OE_actionScaleSelectedStitchWidth(document, 1.1f));
update();
{
scaleSelectedStitchWidth(1.1f);
}
}
else if (event->key() == Qt::Key_Minus && event->modifiers() & Qt::KeypadModifier)
{
if (event->modifiers() & Qt::ControlModifier)
{
controller->addAction(new OE_actionScaleSelectedStitchLen(document, 1.f/1.1f));
update();
emit refreshStitchList();
{
scaleSelectedStitchLen(1.f/1.1f);
}
else
{
controller->addAction(new OE_actionScaleSelectedStitchWidth(document, 1.f/1.1f));
update();
{
scaleSelectedStitchWidth(1.f/1.1f);
}
}
else if (event->key() == Qt::Key_1 && event->modifiers() & Qt::KeypadModifier)
......@@ -561,8 +440,7 @@ void OE_interfaceDisplay::key(QKeyEvent* event)
if (event->key() == Qt::Key_Home)
{
zoomSelection();
update();
zoomOnSelection();
}
}
}
......@@ -577,6 +455,193 @@ void OE_interfaceDisplay::SetSelectedStitchPattern(int index)
emit refreshStitchList();
}
void OE_interfaceDisplay::openFile()
{
if (editionState!=None)
return;
static QString readFilters = QString::fromStdString(OE_document::getReadDialogFilters());
QString type;
QString fileName = QFileDialog::getOpenFileName(this, "Open design", "", readFilters, &type);
if (!fileName.isEmpty())
{
loadFile(fileName.toStdString());
update();
emit refreshStitchList();
}
}
void OE_interfaceDisplay::saveFile()
{
if (!document || editionState!=None)
return;
static QString writeFilters = QString::fromStdString(OE_document::getWriteDialogFilters());
QString fileName = QFileDialog::getSaveFileName(this, "Save design", "", writeFilters);
if (!fileName.isEmpty())
{
document->saveToFile(fileName.toStdString());
}
}
void OE_interfaceDisplay::undo()
{
if (!controller || editionState!=None)
return;
controller->undoAction();
update();
emit refreshStitchList();
}
void OE_interfaceDisplay::redo()
{
if (!controller || editionState!=None)
return;
controller->redoAction();
update();
emit refreshStitchList();
}
void OE_interfaceDisplay::closeSelectedCurve()
{
if (!controller || editionState!=None)
return;
controller->toggleCloseSelectedCurve();
update();
emit refreshStitchList();
}
void OE_interfaceDisplay::deleteSelectedStitches()
{
if (!controller || editionState!=None)
return;
//TODO create an action to delete all selected stitches
std::list<OE_stitchs*>::iterator it=document->selectedStitchs.begin();
controller->addAction(new OE_actionDelStitch(document, *it));
update();
emit refreshStitchList();
}
void OE_interfaceDisplay::selectNextStitch()
{
if (!controller ||!document || editionState!=None)
return;
std::list<OE_stitchs*>::iterator it=selectedStitches.begin();
if (it == selectedStitches.end())
return;
it = std::find (document->stitchs.begin(), document->stitchs.end(), *it);
it++;
if (it != document->stitchs.end())
{
selectedStitches.clear();
selectedStitches.push_back(*it);
controller->clearSelection();
controller->selectStitches(selectedStitches,true);
update();
emit stitchSelectionChange();
}
}
void OE_interfaceDisplay::selectPreviousStitch()
{
if (!controller ||!document || editionState!=None)
return;
std::list<OE_stitchs*>::iterator it=selectedStitches.begin();
if (it == selectedStitches.end())
return;
it = std::find (document->stitchs.begin(), document->stitchs.end(), *it);
if (it != document->stitchs.begin())
{
it--;
selectedStitches.clear();
selectedStitches.push_back(*it);
controller->clearSelection();
controller->selectStitches(selectedStitches,true);
update();
emit stitchSelectionChange();
}
}
void OE_interfaceDisplay::newLinestitch()
{
if (!controller)
return;
controller->newLineStitch(2.5, 2.5, controller->getPattern(0));
document->selectedStitchs.push_back(controller->getLineStitch(-1));
curJoincurve = controller->getLineStitch(-1)->getJoincurve();
closestCurve = controller->getClosestCurve(absMouse, editClosestPoint);
editionState = NewSubcurve;
joincurve_id = 0;
subcurve_id = -1;
update();
emit refreshStitchList();
}
void OE_interfaceDisplay::newBirailstitch()
{
if (!controller)
return;
controller->newBirailStitch(false, false, 0, 0, 0.7f);
document->selectedStitchs.push_back(controller->getBirailStitch(-1));
curJoincurve = controller->getBirailStitch(-1)->getJoincurve1();
closestCurve = controller->getClosestCurve(absMouse, editClosestPoint);
editionState = NewSubcurve;
joincurve_id = 1;
subcurve_id = -1;
update();
emit refreshStitchList();
}
void OE_interfaceDisplay::newFillstitch()
{
if (!controller)
return;
controller->newFillStitch(1.5f, 0.3f, controller->getPattern(0));
document->selectedStitchs.push_back(controller->getFillStitch(-1));
curJoincurve = controller->getFillStitch(-1)->getJoincurve();
closestCurve = controller->getClosestCurve(absMouse, editClosestPoint);
editionState = NewSubcurve;
joincurve_id = 0;
subcurve_id = -1;
update();
emit refreshStitchList();
}
void OE_interfaceDisplay::scaleSelectedStitchLen(float scale)
{
controller->addAction(new OE_actionScaleSelectedStitchLen(document, scale));
update();
emit refreshStitchList();
}
void OE_interfaceDisplay::scaleSelectedStitchWidth(float scale)
{
controller->addAction(new OE_actionScaleSelectedStitchWidth(document, scale));
update();
}
void OE_interfaceDisplay::zoomOnSelection()
{
zoomSelection();
update();
}
void OE_interfaceDisplay::selectBox()
{
selectedCurves.clear();
......
......@@ -82,9 +82,9 @@ void OE_ui_toolBox::addFilesTools(QtMaterialToolTabs *tabs)
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("Open",":/resources/open.svg", getInterfaceDisplay(), SLOT(openFile())));
toolLayout->addWidget(setButton("Append"));
toolLayout->addWidget(setButton("Save as",":/resources/save.svg", this, NULL));
toolLayout->addWidget(setButton("Save as",":/resources/save.svg", getInterfaceDisplay(), SLOT(saveFile())));
toolLayout->addStretch();
}
......@@ -98,7 +98,7 @@ void OE_ui_toolBox::addGuidesTools(QtMaterialToolTabs *tabs)
toolLayout->setSpacing(0);
toolLayout->setContentsMargins(0,0,0,0);
toolLayout->addWidget(setButton("Close", this, SLOT(on_actionCloseCurve_triggered())));
toolLayout->addWidget(setButton("Close", getInterfaceDisplay(), SLOT(closeSelectedCurve())));
//toolLayout->addWidget(setButton("Reverse", this, SLOT(on_actionReverse_curve_R_triggered())));
QLabel* label = new QLabel("Turn: ");
......@@ -126,9 +126,9 @@ void OE_ui_toolBox::addStitchTools(QtMaterialToolTabs *tabs)
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("New line", getInterfaceDisplay(), SLOT(newLinestitch())));
toolLayout->addWidget(setButton("New birail", getInterfaceDisplay(), SLOT(newBirailstitch())));
toolLayout->addWidget(setButton("New fill", getInterfaceDisplay(), SLOT(newFillstitch())));
//toolLayout->addWidget(setButton("Reverse selected", SLOT(on_actionReverse_curve_R_triggered())));
toolLayout->addStretch();
......@@ -261,69 +261,24 @@ 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();
}
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_actionNew_triggered() { window->addTab();}
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_actionPattern1_triggered() { getInterfaceDisplay()->SetSelectedStitchPattern(0);}
void OE_ui_toolBox::on_actionPattern2_triggered() { getInterfaceDisplay()->SetSelectedStitchPattern(1);}
void OE_ui_toolBox::on_actionPattern3_triggered() { getInterfaceDisplay()->SetSelectedStitchPattern(2);}
void OE_ui_toolBox::on_actionPattern4_triggered() { getInterfaceDisplay()->SetSelectedStitchPattern(3);}
void OE_ui_toolBox::on_actionPattern5_triggered() { getInterfaceDisplay()->SetSelectedStitchPattern(4);}
void OE_ui_toolBox::on_actionPattern6_triggered() { getInterfaceDisplay()->SetSelectedStitchPattern(5);}
void OE_ui_toolBox::on_actionPattern7_triggered() { getInterfaceDisplay()->SetSelectedStitchPattern(6);}
void OE_ui_toolBox::on_actionPattern8_triggered() { getInterfaceDisplay()->SetSelectedStitchPattern(7);}
void OE_ui_toolBox::on_actionPattern9_triggered() { getInterfaceDisplay()->SetSelectedStitchPattern(8);}
/*void OE_ui_toolBox::on_actionReverse_curve_R_triggered()
{
sendKeyPulse(Qt::Key_R, Qt::KeyboardModifier::NoModifier);
}*/
void OE_ui_toolBox::on_actionMachineRun_triggered()
{
......
......@@ -39,18 +39,10 @@ private:
void setTechnicalDisplayStyle(OE_display::OE_displayStyle*);
void setMachineDisplayStyle(OE_display::OE_displayStyle*);
void sendKeyPulse(Qt::Key key, Qt::KeyboardModifiers modifiers);
private slots:
void currentTabChanged(int);
void on_actionNew_triggered();
void on_actionOpen_triggered();
void on_actionSave_triggered();
void on_actionLine_triggered();
void on_actionBirail_triggered();
void on_actionFill_triggered();
void on_actionPattern1_triggered();
void on_actionPattern2_triggered();
......@@ -62,9 +54,6 @@ private slots:
void on_actionPattern8_triggered();
void on_actionPattern9_triggered();
void on_actionCloseCurve_triggered();
//void on_actionReverse_curve_R_triggered();
void on_actionMachineRun_triggered();
void on_actionMachineLoad_triggered();
......