Newer
Older
#include "OE_ui_stitchlist.h"
#include "lib/qtmaterialtheme.h"
#include <iostream>
OE_ui_stitchList::OE_ui_stitchList(MainWindow* window, OE_root* root)
this->root = root;
this->window = window;
this->setSelectionMode(QAbstractItemView::ExtendedSelection);
setDragEnabled(true);
setDragDropMode(QAbstractItemView::InternalMove);
viewport()->setAcceptDrops(true);
setDropIndicatorShown(true);
setDefaultDropAction(Qt::TargetMoveAction);
setMinimumSize(100,0);
setDragDropMode(QAbstractItemView::InternalMove);
model = new QStandardItemModel();
listdelegate = new ListviewDelegate();
setItemDelegate(listdelegate);
setModel(model);
//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*)));
showMaximized();
void OE_ui_stitchList::addItem(QColor color, QIcon icon, QIcon type, QIcon pattern, int stitchCount)
QStandardItem *item = new QStandardItem();
item->setData(color,ListviewDelegate::threadRole);
item->setData(QString::number(model->rowCount()+1),ListviewDelegate::IndexRole);
item->setData(QString::number(stitchCount),ListviewDelegate::NbpointsRole);
item->setData(icon,ListviewDelegate::IconRole);
item->setData(type,ListviewDelegate::typeRole);
item->setData(pattern,ListviewDelegate::patternole);
item->setFlags(item->flags() & ~(Qt::ItemIsDropEnabled));//& ~Qt::ItemIsDragEnabled);
model->appendRow(item);
void OE_ui_stitchList::addItem(QColor color, int stitchCount)
{
QStandardItem *item = new QStandardItem();
item->setData(color,ListviewDelegate::threadRole);
item->setData(QString::number(stitchCount),ListviewDelegate::NbpointsRole);
item->setFlags(item->flags() & ~(Qt::ItemIsDropEnabled));// & ~Qt::ItemIsDragEnabled);
model->appendRow(item);
}
void OE_ui_stitchList::addStitch(OE_stitchs* stitch)
{
QColor threadColor = stitch->getThread()->getColor();
OE_linkstitch* tmpLinkStitch = dynamic_cast<OE_linkstitch*>(stitch);
if (tmpLinkStitch)
{
return;
}
OE_linestitch* tmpLineStitch = dynamic_cast<OE_linestitch*>(stitch);
if (tmpLineStitch)
{
static QIcon lineStitchIcon = QIcon(":/resources/line_stitch.svg");
addItem(threadColor, lineStitchIcon, lineStitchIcon, lineStitchIcon, stitch->getNpts());
return;
}
OE_birailstitch* tmpBirailStitch = dynamic_cast<OE_birailstitch*>(stitch);
if (tmpBirailStitch)
{
static QIcon birailStitchIcon = QIcon(":/resources/birail_stitch.svg");
addItem(threadColor, birailStitchIcon, birailStitchIcon, birailStitchIcon, stitch->getNpts());
return;
}
OE_fillstitch* tmpFillStitch = dynamic_cast<OE_fillstitch*>(stitch);
if (tmpFillStitch)
{
static QIcon fillStitchIcon = QIcon(":/resources/fill_stitch.svg");
addItem(threadColor, fillStitchIcon, fillStitchIcon, fillStitchIcon, stitch->getNpts());
return;
}
OE_staticstitch* tmpStaticStitch = dynamic_cast<OE_staticstitch*>(stitch);
if (tmpStaticStitch)
{
static QIcon staticStitchIcon = QIcon(":/resources/static_stitch.svg");
addItem(threadColor, staticStitchIcon, staticStitchIcon, staticStitchIcon, stitch->getNpts());
return;
}
//root->document->stitchs
//root->document->selectedStitchs
}
void OE_ui_stitchList::refreshStitches()
{
if (root->interfaceDisplay->getDocument())
{
model->clear();
for (auto stitch : root->interfaceDisplay->getDocument()->stitchs)
{
addStitch(stitch);
}
}
}
void OE_ui_stitchList::on_refreshStitchList()
{
refreshStitches();
}
void OE_ui_stitchList::on_refreshStitch(OE_stitchs* stitch)
{
refreshStitches();