Krita Source Code Documentation
Loading...
Searching...
No Matches
wdgtagpreview.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2023 Srirupa Datta <srirupa.sps@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#include "wdgtagpreview.h"
8#include "ui_wdgtagpreview.h"
9#include "KisTagLabel.h"
10
12#include "KoID.h"
13#include <wdgtagselection.h>
14#include <KisTag.h>
15#include <KisTagModelProvider.h>
18#include "KisBundleStorage.h"
19
20
21WdgTagPreview::WdgTagPreview(QString resourceType, KoResourceBundleSP bundle, QWidget *parent) :
22 QWidget(parent),
23 m_ui(new Ui::WdgTagPreview),
24 m_resourceType(resourceType),
25 m_tagsController(0),
26 m_bundle(bundle)
27{
28 m_ui->setupUi(this);
29
30 m_resourceType = (resourceType == "presets" ? ResourceType::PaintOpPresets : resourceType);
31
33 m_ui->verticalLayout_2->addWidget(m_wdgResourcesTags);
34
37
38 connect(m_tagsController, SIGNAL(tagAdded(KoID)), this, SLOT(onTagAdded(KoID)));
39 connect(m_tagsController, SIGNAL(tagRemoved(KoID)), this, SLOT(onTagRemoved(KoID)));
40
42
43 m_ui->widget->setLayout(m_layout);
44
46 for (int i = 0; i < model->rowCount(); ++i) {
47 QModelIndex idx = model->index(i, 0);
48 QString name = model->data(idx, Qt::UserRole + KisAbstractResourceModel::Name).toString();
49 if (name == "All" || name == "All Untagged") continue;
50 KisTagLabel *label = new KisTagLabel(name);
51 m_layout->addWidget(label);
52 }
53
54 if (m_bundle) {
55 KisBundleStorage *bundleStorage = new KisBundleStorage(m_bundle->filename());
56
58 while (tagIter->hasNext()) {
59 tagIter->next();
60 KoID custom = KoID(tagIter->tag()->url(), tagIter->tag()->name());
61 m_tagsController->addTag(custom);
62 }
63 }
64}
65
70
72{
74 KisTagSP tagSP = model->tagForUrl(custom.id());
75
76 for (int i = m_layout->count() - 1; i >= 0; --i) {
77 KisTagLabel *label = qobject_cast<KisTagLabel*>(m_layout->itemAt(i)->widget());
78 if (label && label->getText() == tagSP->name()) {
79 m_layout->removeWidget(label);
80 delete label;
81 }
82 }
83
84 Q_EMIT tagsAdded(tagSP);
85}
87{
89 KisTagSP tagSP = model->tagForUrl(custom.id());
90
91 KisTagLabel *label = new KisTagLabel(tagSP->name());
92 m_layout->addWidget(label);
93
94 Q_EMIT tagsRemoved(tagSP);
95}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
QSharedPointer< KisResourceStorage::TagIterator > tags(const QString &resourceType) override
QString getText()
KisTagSP tagForUrl(const QString &url) const override
Retrieve a tag by url.
void setResourceType(const QString &resourceType)
Definition KoID.h:30
QString id() const
Definition KoID.cpp:63
void onTagAdded(KoID custom)
WdgTagPreview(QString resourceType, KoResourceBundleSP bundle=nullptr, QWidget *parent=nullptr)
Ui::WdgTagPreview * m_ui
QString m_resourceType
void onTagRemoved(KoID custom)
KisTagSelectionWidget * m_wdgResourcesTags
KoResourceBundleSP m_bundle
QLayout * m_layout
void tagsRemoved(KisTagSP tagSP)
void tagsAdded(KisTagSP tagSP)
KisWdgTagSelectionControllerBundleTags * m_tagsController
const QString PaintOpPresets