Krita Source Code Documentation
Loading...
Searching...
No Matches
page_bundle_saver.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 "page_bundle_saver.h"
8#include "ui_pagebundlesaver.h"
9#include "dlg_create_bundle.h"
10
11#include <kis_config.h>
12#include <KoFileDialog.h>
13
14#include <config-seexpr.h>
15
17 QWizardPage(parent),
18 m_ui(new Ui::PageBundleSaver)
19 , m_bundle(bundle)
20{
21 m_ui->setupUi(this);
22
23 if (m_bundle) {
24 QFileInfo fileInfo(m_bundle->filename());
25 QString directory = fileInfo.path();
26 m_ui->lblSaveLocation->setText(directory);
27
28 m_bundleStorage = new KisBundleStorage(m_bundle->filename());
29 QMap<QString, int> m_count;
31 #if defined HAVE_SEEXPR
32 resourceTypes << ResourceType::SeExprScripts;
33 #endif
35
36 m_resourceCount = "";
37 QSet<QString> set;
38 m_tags = "";
39
40 for (const QString &type : resourceTypes) {
42 int count = 0;
43 while (iter->hasNext()) {
44 iter->next();
45 count++;
46 }
47 m_loaded_count[type] = count;
48 if (count != 0) {
49 m_count[type] = count;
50 m_resourceCount += ResourceName::resourceTypeToName(type) + ": " + QString::number(count) + "<br>";
51 }
52
54 while (tagIter->hasNext()) {
55 tagIter->next();
56 set.insert(tagIter->tag()->name());
57 m_loaded_tags.insert(tagIter->tag()->name());
58 }
59 }
60
61 if (!m_resourceCount.isEmpty()) {
62 m_ui->lblDetails->setText("<b>Resources</b><br>" + m_resourceCount);
63 }
64
65 if (!set.isEmpty()) {
66 m_tags = "<b>Tags</b><br>" + QList(set.begin(), set.end()).join(", ") + "<br>";
67 }
68
69 m_ui->lblDetails->setText(m_ui->lblDetails->text() + m_tags);
70
71
72 } else {
73 KisConfig cfg(true);
74 m_ui->lblSaveLocation->setText(cfg.readEntry<QString>("BundleExportLocation", QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)));
75 }
76
77 connect(m_ui->bnSelectSaveLocation, SIGNAL(clicked()), SLOT(selectSaveLocation()));
78
79}
80
85
87{
88 return m_ui->lblSaveLocation->text();
89}
90
92{
93 KoFileDialog dialog(this, KoFileDialog::OpenDirectory, "resourcebundlesavelocation");
94 dialog.setDefaultDir(m_ui->lblSaveLocation->text());
95 dialog.setCaption(i18n("Select a directory to save the bundle"));
96 QString location = dialog.filename();
97 m_ui->lblSaveLocation->setText(location);
98}
99
101{
102 m_ui->lblSaveLocation->setStyleSheet(QString(" border: 1px solid red"));
103}
104
106{
107 DlgCreateBundle *wizard = qobject_cast<DlgCreateBundle*>(this->wizard());
108 // QString bundleDetails;
109 m_resourceCount = "";
110 QMap<QString, int> map = wizard->m_count;
111 bool resPresent = false;
112 for (auto i = map.cbegin(), end = map.cend(); i != end; ++i) {
113 if (i.value() != 0) {
114 if (!resPresent) {
115 resPresent = true;
116 m_resourceCount = m_resourceCount + "<b>Resources</b>" + "<br>";
117 }
118 m_resourceCount = m_resourceCount + ResourceName::resourceTypeToName(i.key()) + ": " + QString::number(i.value()) + "<br>";
119 }
120 }
121 m_ui->lblDetails->setText(m_resourceCount + m_tags);
122}
123
125{
126 DlgCreateBundle *wizard = qobject_cast<DlgCreateBundle*>(this->wizard());
127 m_tags = "";
128 QSet<QString> set = wizard->m_tags;
129
130 bool tagPresent = false;
131 for (QSet<QString>::const_iterator it = set.constBegin(); it != set.constEnd(); ++it) {
132 if (!tagPresent) {
133 tagPresent = true;
134 m_tags = m_tags + "<b>Tags</b>" + "<br>";
135 }
136 if (std::next(it) == set.constEnd()) {
137 m_tags = m_tags + *it;
138 } else {
139 m_tags = m_tags + *it + ", ";
140 }
141 }
142
143 m_tags = m_tags + "<br>";
144 m_ui->lblDetails->setText(m_resourceCount + m_tags);
145}
146
148{
149 m_ui->lblSaveLocation->setStyleSheet(QString(""));
150}
QList< QString > QStringList
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
QMap< QString, int > m_count
QSet< QString > m_tags
QSharedPointer< KisResourceStorage::ResourceIterator > resources(const QString &resourceType) override
QSharedPointer< KisResourceStorage::TagIterator > tags(const QString &resourceType) override
T readEntry(const QString &name, const T &defaultValue=T())
Definition kis_config.h:789
KisBundleStorage * m_bundleStorage
QMap< QString, int > m_count
QSet< QString > m_loaded_tags
QString saveLocation() const
Ui::PageBundleSaver * m_ui
KoResourceBundleSP m_bundle
QMap< QString, int > m_loaded_count
PageBundleSaver(KoResourceBundleSP bundle=nullptr, QWidget *parent=nullptr)
KRITARESOURCES_EXPORT QString resourceTypeToName(const QString &resourceType)
const QString Palettes
const QString Brushes
const QString GamutMasks
const QString Patterns
const QString SeExprScripts
const QString Gradients
const QString Workspaces
const QString PaintOpPresets