Skip to content
OE_ui_stitchlist.cpp 5.08 KiB
Newer Older
#include "OE_ui_stitchlist.h"
#include "lib/qtmaterialtheme.h"
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*)));
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)
{
3dsman's avatar
3dsman committed
QColor threadColor = stitch->getThread()->getColor();
//OE_color color = stitch->getThread()->getColor();
//QColor threadColor = QColor(color.rgba[0]*255,color.rgba[1]*255,color.rgba[2]*255color.rgba[3]*255);
    OE_linkstitch* tmpLinkStitch = dynamic_cast<OE_linkstitch*>(stitch);
    if (tmpLinkStitch)
    {
3dsman's avatar
3dsman committed
        addItem(threadColor, stitch->getNpts());
        return;
    }

    OE_linestitch* tmpLineStitch = dynamic_cast<OE_linestitch*>(stitch);
    if (tmpLineStitch)
    {
        QIcon lineStitchIcon;
        lineStitchIcon.addFile(":/resources/line_stitch.svg", QSize(), QIcon::Normal, QIcon::Off);
3dsman's avatar
3dsman committed
        addItem(threadColor, lineStitchIcon, lineStitchIcon, lineStitchIcon, stitch->getNpts());
        return;
    }

    OE_birailstitch* tmpBirailStitch = dynamic_cast<OE_birailstitch*>(stitch);
    if (tmpBirailStitch)
    {
        QIcon birailStitchIcon;
        birailStitchIcon.addFile(":/resources/birail_stitch.svg", QSize(), QIcon::Normal, QIcon::Off);
3dsman's avatar
3dsman committed
        addItem(threadColor, birailStitchIcon, birailStitchIcon, birailStitchIcon, stitch->getNpts());
        return;
    }

    OE_fillstitch* tmpFillStitch = dynamic_cast<OE_fillstitch*>(stitch);
    if (tmpFillStitch)
    {
        QIcon fillStitchIcon;
        fillStitchIcon.addFile(":/resources/fill_stitch.svg", QSize(), QIcon::Normal, QIcon::Off);
3dsman's avatar
3dsman committed
        addItem(threadColor, fillStitchIcon, fillStitchIcon, fillStitchIcon, stitch->getNpts());
        return;
    }

    OE_staticstitch* tmpStaticStitch = dynamic_cast<OE_staticstitch*>(stitch);
    if (tmpStaticStitch)
    {
        QIcon staticStitchIcon;
        staticStitchIcon.addFile(":/resources/static_stitch.svg", QSize(), QIcon::Normal, QIcon::Off);
        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::getItems()
{
	//QStandardItem *item = new QStandardItem();
	QIcon icon(this->style()->standardIcon(QStyle::SP_DialogOpenButton));
	QIcon type(this->style()->standardIcon(QStyle::SP_DialogOpenButton));
	QIcon pattern(this->style()->standardIcon(QStyle::SP_DialogOpenButton));
	QIcon lineStitchIcon;
	lineStitchIcon.addFile(":/resources/line_stitch.svg", QSize(), QIcon::Normal, QIcon::Off);
	QIcon birailStitchIcon;
	birailStitchIcon.addFile(":/resources/birail_stitch.svg", QSize(), QIcon::Normal, QIcon::Off);
	QIcon fillStitchIcon;
	fillStitchIcon.addFile(":/resources/fill_stitch.svg", QSize(), QIcon::Normal, QIcon::Off);

	addItem(QColor(Qt::red), icon, lineStitchIcon, pattern, 52);
	addItem(QColor(Qt::red), 8);
	addItem(QColor(Qt::blue), icon, birailStitchIcon, pattern, 485);
	addItem(QColor(Qt::blue), 5);
	addItem(QColor(Qt::blue), icon, fillStitchIcon, pattern, 5885);
}*/

void OE_ui_stitchList::on_refreshStitchList()
{
    refreshStitches();
}
void OE_ui_stitchList::on_refreshStitch(OE_stitchs* stitch)
{
    refreshStitches();