Skip to content
Commits on Source (4)
......@@ -94,6 +94,7 @@ class OE_controller
bool selectStitch(OE_stitchs* stitch, bool replace);
bool selectStitches(std::list<OE_stitchs*> stitches, bool replace);
bool selectStitches(std::list<int> stitchesId, bool replace);
bool unselectStitches(std::list<OE_stitchs*> stitches);
bool clearSelectStitches();
bool clearSelection();
......
......@@ -47,6 +47,7 @@ class OE_interfaceDisplay : public OE_display
virtual bool setDocument(OE_document* document);
virtual bool setController(OE_controller* controller);
OE_document* getDocument();
OE_controller* getController();
virtual void showAll();
......@@ -118,7 +119,11 @@ class OE_interfaceDisplay : public OE_display
bool run;
public slots:
void SetSelectedStitchPattern(int index);
signals:
void stitchSelectionChange();
void refreshStitchList();
void refreshStitch(OE_stitchs* stitch);
......
......@@ -379,6 +379,26 @@ bool OE_controller::selectStitches(std::list<OE_stitchs*> stitches, bool replace
return false;
}
bool OE_controller::selectStitches(std::list<int> stitchesId, bool replace)
{
if (document)
{
std::list<OE_stitchs*> stitches;
std::list<int>::iterator stitchId = stitchesId.begin();
while (stitchId != stitchesId.end())
{
auto l_front = document->stitchs.begin();
std::advance(l_front, *stitchId);
stitches.push_back(*l_front);
stitchId++;
}
addAction(new OE_actionSelectionAddStitches(document, stitches, replace));
return true;
}
return false;
}
bool OE_controller::unselectStitches(std::list<OE_stitchs*> stitches)
{
if (document)
......
......@@ -81,6 +81,11 @@ OE_document* OE_interfaceDisplay::getDocument()
return document;
}
OE_controller* OE_interfaceDisplay::getController()
{
return controller;
}
bool OE_interfaceDisplay::setController(OE_controller* controller)
{
......@@ -113,7 +118,8 @@ bool OE_interfaceDisplay::mouse_Pos(double x, double y)
{
vector_2d bbCenter = controller->getSelectionBoundingBox().getCenter();
float scale = (absMouse-bbCenter).len()/(screenToDocument(clicOldMouse)-bbCenter).len();
controller->editActionScaleSelection(vector_2d(scale,scale));
controller->editActionScaleSelection(vector_2d(scale,scale));
emit refreshStitchList();
return true;
}
......@@ -137,8 +143,9 @@ bool OE_interfaceDisplay::mouse_Pos(double x, double y)
if (editionState == MovePointstitch) //if we're moving a linkstitch control point
{
controller->editActionMovePointLinkStitch(absMove);
controller->editActionMoveGridPointFillStitch(absMove);
return true;
controller->editActionMoveGridPointFillStitch(absMove);
emit refreshStitchList();
return true;
}
//if we're editing the scaleWidth of a linestitch
......@@ -153,22 +160,24 @@ bool OE_interfaceDisplay::mouse_Pos(double x, double y)
{
editionState = TraceSubcurve;
if (oldClosestPoint.t>editClosestPoint.t) controller->editActionAddSubcurvePosSwitchDir();
redraw = true;
redraw = true;
emit refreshStitchList();
}
if (editionState == TraceSubcurve)
{
controller->editActionAddSubcurvePosEnd(editClosestPoint.t);
redraw = true;
redraw = true;
emit refreshStitchList();
}
else if (editionState == MoveSubcurve)
{
controller->editActionSetSubcurvePos(editClosestPoint.t);
redraw = true;
}
if (redraw)
refreshStitchList();
redraw = true;
emit refreshStitchList();
}
return redraw;
}
......@@ -283,11 +292,13 @@ void OE_interfaceDisplay::key(QKeyEvent* event)
{
controller->editActionAddSubcurvePosSwitchDir();
update();
emit refreshStitchList();
}
else if (editionState == MoveSubcurve)
{
controller->editActionSetSubcurvePosSwitchDir();
update();
update();
emit refreshStitchList();
}
}
if(editionState==None)
......@@ -298,6 +309,7 @@ void OE_interfaceDisplay::key(QKeyEvent* event)
{
controller->undoAction();
update();
emit refreshStitchList();
}
}
else if (event->key() == Qt::Key_S && event->modifiers() == Qt::ControlModifier)
......@@ -319,6 +331,7 @@ void OE_interfaceDisplay::key(QKeyEvent* event)
{
loadFile(fileName.toStdString());
update();
emit refreshStitchList();
}
}
else if (event->key() == Qt::Key_Z && event->modifiers() == (Qt::ControlModifier|Qt::ShiftModifier))
......@@ -327,6 +340,7 @@ void OE_interfaceDisplay::key(QKeyEvent* event)
{
controller->redoAction();
update();
emit refreshStitchList();
}
}
else if (event->modifiers() == Qt::NoModifier)
......@@ -337,6 +351,7 @@ void OE_interfaceDisplay::key(QKeyEvent* event)
{
controller->toggleCloseSelectedCurve();
update();
emit refreshStitchList();
}
}
else if (event->key() == Qt::Key_Delete)
......@@ -345,6 +360,7 @@ void OE_interfaceDisplay::key(QKeyEvent* event)
std::list<OE_stitchs*>::iterator it=selectedStitches.begin();
controller->addAction(new OE_actionDelStitch(document, *it));
update();
emit refreshStitchList();
}
else if (event->key() == Qt::Key_Right)
{
......@@ -358,7 +374,8 @@ void OE_interfaceDisplay::key(QKeyEvent* event)
selectedStitches.clear();
selectedStitches.push_back(*it);
controller->clearSelection();
controller->selectStitches(selectedStitches,true);
controller->selectStitches(selectedStitches,true);
emit stitchSelectionChange();
update();
}
}
......@@ -375,7 +392,8 @@ void OE_interfaceDisplay::key(QKeyEvent* event)
selectedStitches.clear();
selectedStitches.push_back(*it);
controller->clearSelection();
controller->selectStitches(selectedStitches,true);
controller->selectStitches(selectedStitches,true);
emit stitchSelectionChange();
update();
}
}
......@@ -391,12 +409,14 @@ void OE_interfaceDisplay::key(QKeyEvent* event)
if (editionState == TraceSubcurve)
{
controller->editActionAddSubcurvePosSwitchDir();
update();
update();
emit refreshStitchList();
}
else if (editionState == MoveSubcurve)
{
controller->editActionSetSubcurvePosSwitchDir();
update();
emit refreshStitchList();
}
}
if(editionState==None)
......@@ -493,6 +513,7 @@ void OE_interfaceDisplay::key(QKeyEvent* event)
{
controller->addAction(new OE_actionScaleSelectedStitchLen(document, 1.1f));
update();
emit refreshStitchList();
}
else
{
......@@ -506,6 +527,7 @@ void OE_interfaceDisplay::key(QKeyEvent* event)
{
controller->addAction(new OE_actionScaleSelectedStitchLen(document, 1.f/1.1f));
update();
emit refreshStitchList();
}
else
{
......@@ -514,49 +536,40 @@ void OE_interfaceDisplay::key(QKeyEvent* event)
}
}
else if (event->key() == Qt::Key_1 && event->modifiers() & Qt::KeypadModifier)
{
controller->addAction(new OE_actionSetSelectedStitchPattern(document, controller->getPattern(0)));
update();
{
SetSelectedStitchPattern(0);
}
else if (event->key() == Qt::Key_2 && event->modifiers() & Qt::KeypadModifier)
{
controller->addAction(new OE_actionSetSelectedStitchPattern(document, controller->getPattern(1)));
update();
{
SetSelectedStitchPattern(1);
}
else if (event->key() == Qt::Key_3 && event->modifiers() & Qt::KeypadModifier)
{
controller->addAction(new OE_actionSetSelectedStitchPattern(document, controller->getPattern(2)));
update();
{
SetSelectedStitchPattern(2);
}
else if (event->key() == Qt::Key_4 && event->modifiers() & Qt::KeypadModifier)
{
controller->addAction(new OE_actionSetSelectedStitchPattern(document, controller->getPattern(3)));
update();
{
SetSelectedStitchPattern(3);
}
else if (event->key() == Qt::Key_5 && event->modifiers() & Qt::KeypadModifier)
{
controller->addAction(new OE_actionSetSelectedStitchPattern(document, controller->getPattern(4)));
update();
{
SetSelectedStitchPattern(4);
}
else if (event->key() == Qt::Key_6 && event->modifiers() & Qt::KeypadModifier)
{
controller->addAction(new OE_actionSetSelectedStitchPattern(document, controller->getPattern(5)));
update();
{
SetSelectedStitchPattern(5);
}
else if (event->key() == Qt::Key_7 && event->modifiers() & Qt::KeypadModifier)
{
controller->addAction(new OE_actionSetSelectedStitchPattern(document, controller->getPattern(6)));
update();
{
SetSelectedStitchPattern(6);
}
else if (event->key() == Qt::Key_8 && event->modifiers() & Qt::KeypadModifier)
{
controller->addAction(new OE_actionSetSelectedStitchPattern(document, controller->getPattern(7)));
update();
{
SetSelectedStitchPattern(7);
}
else if (event->key() == Qt::Key_9 && event->modifiers() & Qt::KeypadModifier)
{
controller->addAction(new OE_actionSetSelectedStitchPattern(document, controller->getPattern(8)));
update();
SetSelectedStitchPattern(8);
}
if (event->key() == Qt::Key_Home)
......@@ -568,6 +581,15 @@ void OE_interfaceDisplay::key(QKeyEvent* event)
}
}
void OE_interfaceDisplay::SetSelectedStitchPattern(int index)
{
if (!controller->getPattern(index))
return;
controller->addAction(new OE_actionSetSelectedStitchPattern(document, controller->getPattern(index)));
update();
emit refreshStitchList();
}
void OE_interfaceDisplay::selectBox()
{
selectedCurves.clear();
......@@ -602,6 +624,7 @@ void OE_interfaceDisplay::selectBox()
}
stitch++;
}
emit stitchSelectionChange();
}
bool OE_interfaceDisplay::checkJoinCurveControl(OE_joincurve* joinCurve, int &index)
......@@ -659,7 +682,7 @@ bool OE_interfaceDisplay::checkPicking()
if (tmpLineStitch)
{
// check generic joinCurve controls
if (checkJoinCurveControl(tmpLineStitch->getJoincurve(), ControlTypeIndex)) return true;
if (checkJoinCurveControl(tmpLineStitch->getJoincurve(), ControlTypeIndex)) return true;
//check picking for linestitch width controller
if (selControlType == ControlTypeIndex && selControlIndex == 0)
......@@ -707,16 +730,19 @@ bool OE_interfaceDisplay::checkPicking()
{
editionState = MovePointstitch;
controller->addAction(new OE_actionMovePointLinkStitch(document, tmpLinkStitch, selControlIndex, vector_2d()));
return true;
}
else if (selControlType == 1)
{
editionState = MovePointstitch;
controller->addAction(new OE_actionAddPointLinkStitch(document, tmpLinkStitch, selControlIndex, absMouse));
return true;
}
else if (selControlType == 2)
{
editionState = DelPointstitch;
controller->addAction(new OE_actionDelPointLinkStitch(document, tmpLinkStitch, selControlIndex));
return true;
}
return false;
}
......@@ -822,7 +848,7 @@ bool OE_interfaceDisplay::drawPicking()
std::list<OE_stitchs*>::iterator it = document->stitchs.begin();
std::advance(it, *ptr);
selectedStitches.push_back(*it);
selectedStitches.push_back(*it);
return true;
}
else if (names==4) //if name count correspond to a stitch sub element (like control point)
......@@ -903,13 +929,15 @@ bool OE_interfaceDisplay::selectApply(std::list<OE_pointcurve*> selectedCurves,
}
else
{
controller->selectStitches(selectedStitches, !modState.testFlag(Qt::ShiftModifier));
controller->selectStitches(selectedStitches, !modState.testFlag(Qt::ShiftModifier));
emit stitchSelectionChange();
}
}
if (!selectedStitches.size() && !selectedCurves.size())
{
controller->clearSelection();
controller->clearSelection();
emit stitchSelectionChange();
}
return true;
......@@ -1003,4 +1031,3 @@ bool OE_interfaceDisplay::draw()
}
return true;
}
......@@ -6,7 +6,8 @@ OE_ui_stitchList::OE_ui_stitchList(MainWindow* window, OE_root* root)
{
this->root = root;
this->window = window;
this->setSelectionMode(QAbstractItemView::ExtendedSelection);
setSelectionMode(QAbstractItemView::ExtendedSelection);
setSelectionBehavior(QAbstractItemView::SelectRows);
setDragEnabled(true);
setDragDropMode(QAbstractItemView::InternalMove);
viewport()->setAcceptDrops(true);
......@@ -25,8 +26,11 @@ OE_ui_stitchList::OE_ui_stitchList(MainWindow* window, OE_root* root)
//getItems();
refreshStitches();
connect(this->root->interfaceDisplay, SIGNAL(refreshStitchList()), this, SLOT(on_refreshStitchList()));
connect(this->root->interfaceDisplay, SIGNAL(refreshStitch(OE_stitchs*)), this, SLOT(on_refreshStitch(OE_stitchs*)));
connect(getInterfaceDisplay(), SIGNAL(refreshStitchList()), this, SLOT(on_refreshStitchList()));
connect(getInterfaceDisplay(), SIGNAL(refreshStitch(OE_stitchs*)), this, SLOT(on_refreshStitch(OE_stitchs*)));
connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(handleSelectionChanged()));
connect(getInterfaceDisplay(), SIGNAL(stitchSelectionChange()), this, SLOT(on_refreshStitchList()));
showMaximized();
......@@ -42,7 +46,7 @@ void OE_ui_stitchList::addItem(QColor color, QIcon icon, QIcon type, QIcon patte
item->setData(QString::number(stitchCount),ListviewDelegate::NbpointsRole);
item->setData(icon,ListviewDelegate::IconRole);
item->setData(type,ListviewDelegate::typeRole);
item->setData(pattern,ListviewDelegate::patternole);
item->setData(pattern,ListviewDelegate::patternRole);
item->setFlags(item->flags() & ~(Qt::ItemIsDropEnabled));//& ~Qt::ItemIsDragEnabled);
model->appendRow(item);
......@@ -109,13 +113,24 @@ void OE_ui_stitchList::addStitch(OE_stitchs* stitch)
void OE_ui_stitchList::refreshStitches()
{
if (root->interfaceDisplay->getDocument())
if (getDocument())
{
model->clear();
for (auto stitch : root->interfaceDisplay->getDocument()->stitchs)
QItemSelection selection;
int id = 0;
for (auto stitch : getDocument()->stitchs)
{
addStitch(stitch);
auto it = std::find(getDocument()->selectedStitchs.begin(), getDocument()->selectedStitchs.end(), stitch);
if(it != getDocument()->selectedStitchs.end())
selection.merge(QItemSelection(model->index(id, 0), model->index(id, 0)), QItemSelectionModel::Select | QItemSelectionModel::Rows);
id++;
}
selectionModel()->blockSignals(true);
selectionModel()->select(selection, QItemSelectionModel::Select | QItemSelectionModel::Rows);
selectionModel()->blockSignals(false);
}
}
......@@ -125,5 +140,44 @@ void OE_ui_stitchList::on_refreshStitchList()
}
void OE_ui_stitchList::on_refreshStitch(OE_stitchs* stitch)
{
refreshStitches();
//refreshStitches();
}
void OE_ui_stitchList::handleSelectionChanged()
{
std::list<int> stitchesId;
foreach(const QModelIndex &index, selectionModel()->selectedIndexes())
stitchesId.push_back(index.row());
getController()->selectStitches(stitchesId, true);
getInterfaceDisplay()->update();
}
void OE_ui_stitchList::keyPressEvent(QKeyEvent *event)
{
if(event->key()==Qt::Key_Right) {
QKeyEvent* eventDown = new QKeyEvent(event->type(), Qt::Key_Down, event->modifiers());
QListView::keyPressEvent(eventDown);
return;
}
if(event->key()==Qt::Key_Left) {
QKeyEvent* eventUp = new QKeyEvent(event->type(), Qt::Key_Up, event->modifiers());
QListView::keyPressEvent(eventUp);
return;
}
QListView::keyPressEvent(event);
}
OE_controller* OE_ui_stitchList::getController()
{
return this->root->interfaceDisplay->getController();
}
OE_interfaceDisplay* OE_ui_stitchList::getInterfaceDisplay()
{
return this->root->interfaceDisplay;
}
OE_document* OE_ui_stitchList::getDocument()
{
return this->root->interfaceDisplay->getDocument();
}
......@@ -7,6 +7,9 @@
#include "listviewdelegate.h"
class MainWindow;
class OE_controller;
class OE_interfaceDisplay;
class OE_document;
class OE_ui_stitchList : public QListView
{
......@@ -15,6 +18,9 @@ public:
OE_ui_stitchList(MainWindow* window, OE_root* root);
void addStitch(OE_stitchs* stitch);
void refreshStitches();
OE_controller* getController();
OE_interfaceDisplay* getInterfaceDisplay();
OE_document* getDocument();
private:
OE_root* root;
MainWindow* window;
......@@ -22,9 +28,11 @@ private:
ListviewDelegate* listdelegate;
void addItem(QColor color, QIcon icon, QIcon type, QIcon pattern, int stitchCount);
void addItem(QColor color, int stitchCount);
void keyPressEvent(QKeyEvent *event);
private slots:
void on_refreshStitchList();
void on_refreshStitch(OE_stitchs* stitch);
void handleSelectionChanged();
};
#endif // OE_UI_STITCHLIST_H
......@@ -64,7 +64,7 @@ void ListviewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
}
QIcon type = qvariant_cast<QIcon>(index.data(typeRole));
QIcon pattern = qvariant_cast<QIcon>(index.data(patternole));
QIcon pattern = qvariant_cast<QIcon>(index.data(patternRole));
QString indexText = qvariant_cast<QString>(index.data(IndexRole));
QString nbPoints = qvariant_cast<QString>(index.data(NbpointsRole));
......
......@@ -11,7 +11,7 @@ public:
virtual ~ListviewDelegate();
// enum datarole {headerTextRole = Qt::UserRole + 100,subHeaderTextrole = Qt::UserRole+101,IconRole = Qt::UserRole+102};
enum datarole {threadRole = Qt::UserRole + 100,IconRole = Qt::UserRole+101,typeRole = Qt::UserRole+102,patternole = Qt::UserRole+103,IndexRole = Qt::UserRole+104,NbpointsRole = Qt::UserRole+105};
enum datarole {threadRole = Qt::UserRole + 100,IconRole = Qt::UserRole+101,typeRole = Qt::UserRole+102,patternRole = Qt::UserRole+103,IndexRole = Qt::UserRole+104,NbpointsRole = Qt::UserRole+105};
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const;
......