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 203 of file kis_dlg_layer_style.h.

Constructor & Destructor Documentation

◆ StylesSelector()

StylesSelector::StylesSelector ( QWidget * parent)

Definition at line 671 of file kis_dlg_layer_style.cpp.

672 : QWidget(parent)
673{
674 ui.setupUi(this);
675
677 m_locationsProxyModel = new LocationProxyModel(this);
678 m_locationsProxyModel->setSourceModel(m_resourceModel);
680
681 ui.listStyles->setModel(m_locationsProxyModel);
682 ui.listStyles->setModelColumn(KisAbstractResourceModel::Name);
683 // XXX: support editing
684 // KisResourceModel doesn't support data with the EditRole
685 ui.listStyles->setEditTriggers(QAbstractItemView::EditTrigger::NoEditTriggers);
686
687 connect(ui.cmbStyleCollections, SIGNAL(textActivated(QString)), this, SLOT(loadStyles(QString)));
688 connect(ui.listStyles, SIGNAL(clicked(QModelIndex)), this, SLOT(selectStyle(QModelIndex)));
689
691
692 if (ui.cmbStyleCollections->count()) {
693 ui.cmbStyleCollections->setCurrentIndex(0);
695 loadStyles(ui.cmbStyleCollections->currentText());
696 }
697}
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 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 801 of file kis_dlg_layer_style.cpp.

802{
803 // m_resourceModel = new KisResourceModel(ResourceType::LayerStyles, this);
804 // m_locationsProxyModel->setSourceModel(m_resourceModel);
805 // ui.listStyles->setModel(m_locationsProxyModel);
806
808 ui.listStyles->reset();
809 ui.cmbStyleCollections->setCurrentText(location);
810 loadStyles(ui.cmbStyleCollections->currentText());
811 KIS_ASSERT(m_resourceModel->resourceForId(style->resourceId()));
812 ui.listStyles->setCurrentIndex(m_locationsProxyModel->mapFromSource(
813 m_resourceModel->indexForResource(style).siblingAtColumn(ui.listStyles->modelColumn())));
814
815 notifyExternalStyleChanged(style->name(), style->uuid());
816}
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 767 of file kis_dlg_layer_style.cpp.

768{
769 Q_UNUSED(fileName);
770 // TODO: RESOURCES: implement or remove
771 warnKrita << "Collection cannot be loaded, because we do not use collections now; please use KisAslStorage instead.";
772
773 /*
774 if (!QFileInfo(fileName).exists()) {
775 warnKrita << "Loaded style collection doesn't exist!";
776 return;
777 }
778
779 KisPSDLayerStyleCollectionResourceSP collection = KisPSDLayerStyleCollectionResourceSP(new KisPSDLayerStyleCollectionResource(fileName));
780
781 collection->load();
782
783 KoResourceServer<KisPSDLayerStyleCollectionResource> *server = KisResourceServerProvider::instance()->layerStyleCollectionServer();
784 collection->setFilename(server->saveLocation() + '/' + collection->name());
785 server->addResource(collection);
786
787 refillCollections();
788
789 int index = ui.cmbStyleCollections->findText(collection->name());
790 ui.cmbStyleCollections->setCurrentIndex(index);
791 loadStyles(collection->name());
792 */
793}
#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 713 of file kis_dlg_layer_style.cpp.

714{
715 Q_UNUSED(name);
716 Q_UNUSED(uuid);
717 /*
718 int currentIndex = -1;
719
720 for (int i = 0; i < ui.listStyles->count(); i++ ) {
721 StyleItem *item = dynamic_cast<StyleItem*>(ui.listStyles->item(i));
722
723 QString itemName = item->m_style->name();
724
725 if (itemName == name) {
726 bool isDirty = item->m_style->uuid() != uuid;
727
728 if (isDirty) {
729 itemName += "*";
730 }
731
732 currentIndex = i;
733 }
734
735 item->setText(itemName);
736 }
737
738 ui.listStyles->setCurrentRow(currentIndex);
739 */
740}

◆ refillCollections()

void StylesSelector::refillCollections ( )

Definition at line 699 of file kis_dlg_layer_style.cpp.

700{
701 QStringList locationsList;
702 for (int i = 0; i < m_resourceModel->rowCount(); i++) {
703 QModelIndex idx = m_resourceModel->index(i, 0);
704 QString location = m_resourceModel->data(idx, Qt::UserRole + KisAbstractResourceModel::Location).toString();
705 if (!locationsList.contains(location)) {
706 locationsList << location;
707 }
708 }
709 ui.cmbStyleCollections->clear();
710 ui.cmbStyleCollections->addItems(locationsList);
711}

References KisAbstractResourceModel::Location, m_resourceModel, and ui.

◆ selectStyle

void StylesSelector::selectStyle ( QModelIndex current)
privateslot

Definition at line 747 of file kis_dlg_layer_style.cpp.

748{
749
750 // the index is from the proxy model
751 QModelIndex sourceModelIndex = m_locationsProxyModel->mapToSource(current);
752 KoResourceSP resource = m_resourceModel->resourceForIndex(sourceModelIndex);
753 KisPSDLayerStyleSP layerStyle = resource.dynamicCast<KisPSDLayerStyle>();
754 qDebug() << "StylesSelector::selectStyle" << (resource.isNull() ? "(null)" : resource->name()) << (layerStyle.isNull() ? "(null)" : layerStyle->name());
755 if (layerStyle) {
756 Q_EMIT styleSelected(layerStyle);
757 }
758
759 /*
760 StyleItem *item = dynamic_cast<StyleItem*>(current);
761 if (item) {
762 Q_EMIT styleSelected(item->m_style);
763 }
764 */
765}
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 795 of file kis_dlg_layer_style.cpp.

796{
797 ENTER_FUNCTION() << "MODEL RESET!!!";
799}
#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 251 of file kis_dlg_layer_style.h.

◆ m_resourceModel

KisResourceModel* StylesSelector::m_resourceModel
private

Definition at line 252 of file kis_dlg_layer_style.h.

◆ ui

Ui::WdgStylesSelector StylesSelector::ui
private

Definition at line 250 of file kis_dlg_layer_style.h.


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