Krita Source Code Documentation
Loading...
Searching...
No Matches
StylesSelector Class Reference

#include <kis_dlg_layer_style.h>

+ Inheritance diagram for StylesSelector:

Classes

class  LocationProxyModel
 

Signals

void styleSelected (KisPSDLayerStyleSP style)
 

Public Member Functions

void addNewStyle (const QString &location, const KisPSDLayerStyleSP style)
 
void loadCollection (const QString &fileName)
 
void notifyExternalStyleChanged (const QString &name, const QUuid &uuid)
 
void refillCollections ()
 
 StylesSelector (QWidget *parent)
 

Private Slots

void loadStyles (const QString &name)
 
void selectStyle (QModelIndex current)
 
void slotResourceModelReset ()
 

Private Attributes

LocationProxyModelm_locationsProxyModel
 
KisResourceModelm_resourceModel
 
Ui::WdgStylesSelector ui
 

Detailed Description

Definition at line 204 of file kis_dlg_layer_style.h.

Constructor & Destructor Documentation

◆ StylesSelector()

StylesSelector::StylesSelector ( QWidget * parent)

Definition at line 588 of file kis_dlg_layer_style.cpp.

589 : QWidget(parent)
590{
591 ui.setupUi(this);
592
594 m_locationsProxyModel = new LocationProxyModel(this);
595 m_locationsProxyModel->setSourceModel(m_resourceModel);
597
598 ui.listStyles->setModel(m_locationsProxyModel);
599 ui.listStyles->setModelColumn(KisAbstractResourceModel::Name);
600 // XXX: support editing
601 // KisResourceModel doesn't support data with the EditRole
602 ui.listStyles->setEditTriggers(QAbstractItemView::EditTrigger::NoEditTriggers);
603
604 connect(ui.cmbStyleCollections, SIGNAL(textActivated(QString)), this, SLOT(loadStyles(QString)));
605 connect(ui.listStyles, SIGNAL(clicked(QModelIndex)), this, SLOT(selectStyle(QModelIndex)));
606
608
609 if (ui.cmbStyleCollections->count()) {
610 ui.cmbStyleCollections->setCurrentIndex(0);
612 loadStyles(ui.cmbStyleCollections->currentText());
613 }
614}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
The KisResourceModel class provides the main access to resources. It is possible to filter the resour...
void setEnableFiltering(bool enableFiltering)
void loadStyles(const QString &name)
void selectStyle(QModelIndex current)
Ui::WdgStylesSelector ui
LocationProxyModel * m_locationsProxyModel
KisResourceModel * m_resourceModel
const QString LayerStyles

References connect(), ResourceType::LayerStyles, loadStyles(), m_locationsProxyModel, m_resourceModel, KisAbstractResourceModel::Name, refillCollections(), selectStyle(), StylesSelector::LocationProxyModel::setEnableFiltering(), and ui.

Member Function Documentation

◆ addNewStyle()

void StylesSelector::addNewStyle ( const QString & location,
const KisPSDLayerStyleSP style )

Definition at line 718 of file kis_dlg_layer_style.cpp.

719{
720 // m_resourceModel = new KisResourceModel(ResourceType::LayerStyles, this);
721 // m_locationsProxyModel->setSourceModel(m_resourceModel);
722 // ui.listStyles->setModel(m_locationsProxyModel);
723
725 ui.listStyles->reset();
726 ui.cmbStyleCollections->setCurrentText(location);
727 loadStyles(ui.cmbStyleCollections->currentText());
728 KIS_ASSERT(m_resourceModel->resourceForId(style->resourceId()));
729 ui.listStyles->setCurrentIndex(m_locationsProxyModel->mapFromSource(
730 m_resourceModel->indexForResource(style).siblingAtColumn(ui.listStyles->modelColumn())));
731
732 notifyExternalStyleChanged(style->name(), style->uuid());
733}
KoResourceSP resourceForId(int id) const
QModelIndex indexForResource(KoResourceSP resource) const override
indexFromResource
void notifyExternalStyleChanged(const QString &name, const QUuid &uuid)
#define KIS_ASSERT(cond)
Definition kis_assert.h:33

References KisResourceModel::indexForResource(), KIS_ASSERT, loadStyles(), m_locationsProxyModel, m_resourceModel, notifyExternalStyleChanged(), refillCollections(), KisResourceModel::resourceForId(), and ui.

◆ loadCollection()

void StylesSelector::loadCollection ( const QString & fileName)

Definition at line 684 of file kis_dlg_layer_style.cpp.

685{
686 Q_UNUSED(fileName);
687 // TODO: RESOURCES: implement or remove
688 warnKrita << "Collection cannot be loaded, because we do not use collections now; please use KisAslStorage instead.";
689
690 /*
691 if (!QFileInfo(fileName).exists()) {
692 warnKrita << "Loaded style collection doesn't exist!";
693 return;
694 }
695
696 KisPSDLayerStyleCollectionResourceSP collection = KisPSDLayerStyleCollectionResourceSP(new KisPSDLayerStyleCollectionResource(fileName));
697
698 collection->load();
699
700 KoResourceServer<KisPSDLayerStyleCollectionResource> *server = KisResourceServerProvider::instance()->layerStyleCollectionServer();
701 collection->setFilename(server->saveLocation() + '/' + collection->name());
702 server->addResource(collection);
703
704 refillCollections();
705
706 int index = ui.cmbStyleCollections->findText(collection->name());
707 ui.cmbStyleCollections->setCurrentIndex(index);
708 loadStyles(collection->name());
709 */
710}
#define warnKrita
Definition kis_debug.h:87

References warnKrita.

◆ loadStyles

void StylesSelector::loadStyles ( const QString & name)
privateslot

◆ notifyExternalStyleChanged()

void StylesSelector::notifyExternalStyleChanged ( const QString & name,
const QUuid & uuid )

Definition at line 630 of file kis_dlg_layer_style.cpp.

631{
632 Q_UNUSED(name);
633 Q_UNUSED(uuid);
634 /*
635 int currentIndex = -1;
636
637 for (int i = 0; i < ui.listStyles->count(); i++ ) {
638 StyleItem *item = dynamic_cast<StyleItem*>(ui.listStyles->item(i));
639
640 QString itemName = item->m_style->name();
641
642 if (itemName == name) {
643 bool isDirty = item->m_style->uuid() != uuid;
644
645 if (isDirty) {
646 itemName += "*";
647 }
648
649 currentIndex = i;
650 }
651
652 item->setText(itemName);
653 }
654
655 ui.listStyles->setCurrentRow(currentIndex);
656 */
657}

◆ refillCollections()

void StylesSelector::refillCollections ( )

Definition at line 616 of file kis_dlg_layer_style.cpp.

617{
618 QStringList locationsList;
619 for (int i = 0; i < m_resourceModel->rowCount(); i++) {
620 QModelIndex idx = m_resourceModel->index(i, 0);
621 QString location = m_resourceModel->data(idx, Qt::UserRole + KisAbstractResourceModel::Location).toString();
622 if (!locationsList.contains(location)) {
623 locationsList << location;
624 }
625 }
626 ui.cmbStyleCollections->clear();
627 ui.cmbStyleCollections->addItems(locationsList);
628}

References KisAbstractResourceModel::Location, m_resourceModel, and ui.

◆ selectStyle

void StylesSelector::selectStyle ( QModelIndex current)
privateslot

Definition at line 664 of file kis_dlg_layer_style.cpp.

665{
666
667 // the index is from the proxy model
668 QModelIndex sourceModelIndex = m_locationsProxyModel->mapToSource(current);
669 KoResourceSP resource = m_resourceModel->resourceForIndex(sourceModelIndex);
670 KisPSDLayerStyleSP layerStyle = resource.dynamicCast<KisPSDLayerStyle>();
671 qDebug() << "StylesSelector::selectStyle" << (resource.isNull() ? "(null)" : resource->name()) << (layerStyle.isNull() ? "(null)" : layerStyle->name());
672 if (layerStyle) {
673 Q_EMIT styleSelected(layerStyle);
674 }
675
676 /*
677 StyleItem *item = dynamic_cast<StyleItem*>(current);
678 if (item) {
679 Q_EMIT styleSelected(item->m_style);
680 }
681 */
682}
KoResourceSP resourceForIndex(QModelIndex index=QModelIndex()) const override
resourceForIndex returns a properly versioned and id'ed resource object
void styleSelected(KisPSDLayerStyleSP style)
The KisPSDLayerStyle class implements loading, saving and applying the PSD layer effects.

References m_locationsProxyModel, m_resourceModel, KisResourceModel::resourceForIndex(), and styleSelected().

◆ slotResourceModelReset

void StylesSelector::slotResourceModelReset ( )
privateslot

Definition at line 712 of file kis_dlg_layer_style.cpp.

713{
714 ENTER_FUNCTION() << "MODEL RESET!!!";
716}
#define ENTER_FUNCTION()
Definition kis_debug.h:178

References ENTER_FUNCTION, and refillCollections().

◆ styleSelected

void StylesSelector::styleSelected ( KisPSDLayerStyleSP style)
signal

Member Data Documentation

◆ m_locationsProxyModel

LocationProxyModel* StylesSelector::m_locationsProxyModel
private

Definition at line 252 of file kis_dlg_layer_style.h.

◆ m_resourceModel

KisResourceModel* StylesSelector::m_resourceModel
private

Definition at line 253 of file kis_dlg_layer_style.h.

◆ ui

Ui::WdgStylesSelector StylesSelector::ui
private

Definition at line 251 of file kis_dlg_layer_style.h.


The documentation for this class was generated from the following files: