16#include <QInputDialog>
17#include <QItemSelectionModel>
18#include <QStringLiteral>
20#include <kconfiggroup.h>
21#include <ksharedconfig.h>
41 : QStyledItemDelegate(parent)
42 , m_bundleManagerProxyModel(proxy)
52 return QSize(100, 30);
57 if (!index.isValid()) {
61 QModelIndex sourceIndex = m_bundleManagerProxyModel->mapToSource(index);
69 QColor bgColor = option.state & QStyle::State_Selected ?
70 qApp->palette().color(QPalette::Highlight) :
71 qApp->palette().color(QPalette::Base);
73 QBrush oldBrush(painter->brush());
74 QPen oldPen = painter->pen();
76 painter->setBrush(QBrush(bgColor));
77 painter->setPen(Qt::NoPen);
78 painter->drawRect(option.rect);
80 QRect paintRect =
kisGrowRect(option.rect, -minMargin);
81 int height = paintRect.height();
87 QColor borderColor = option.state & QStyle::State_Selected ?
88 qApp->palette().color(QPalette::HighlightedText) :
89 qApp->palette().color(QPalette::Text);
90 painter->setBrush(Qt::NoBrush);
91 painter->setPen(QPen(borderColor));
93 QRect borderRect =
kisGrowRect(paintRect, -painter->pen().widthF());
95 painter->drawRect(borderRect);
97 painter->setBrush(oldBrush);
98 painter->setPen(oldPen);
105 QRect iconRect = paintRect;
106 iconRect.setWidth(height);
107 painter->drawImage(iconRect, thumbnail);
109 QRect nameRect = paintRect;
110 nameRect.setX(paintRect.x() + height + textMargin);
111 nameRect.setWidth(paintRect.width() - height - 1.5*textMargin);
113 QColor textColor = option.state & QStyle::State_Selected ?
114 qApp->palette().color(QPalette::HighlightedText) :
115 qApp->palette().color(QPalette::Text);
116 painter->setPen(QPen(textColor));
118 QTextOption textCenterOption;
119 textCenterOption.setAlignment(Qt::AlignVCenter);
120 textCenterOption.setWrapMode(QTextOption::NoWrap);
122 painter->drawText(nameRect, name, textCenterOption);
132 setCaption(i18n(
"Manage Resource Libraries"));
139 m_ui->bnAdd->setText(i18nc(
"In bundle manager; press button to import a resource library",
"Import"));
143 m_ui->bnToggle->setText(i18nc(
"In bundle manager; press button to deactivate the resource library"
144 "(remove resources from the resource library from the available resources)",
"Deactivate"));
148 m_ui->bnNew->setText(i18nc(
"In bundle manager; press button to create a new bundle",
"Create Bundle"));
152 m_ui->bnEdit->setText(i18nc(
"In bundle manager; press button to edit existing bundle",
"Edit Bundle"));
169 connect(scroller, &QScroller::stateChanged,
this, [&](QScroller::State state) {
174 QItemSelectionModel* selectionModel =
m_ui->listView->selectionModel();
191 warning = i18n(
"You don't have any resource bundles enabled.");
195 warning += i18n(
"\nThere are no brush presets available. Please enable a bundle that has presets before continuing.\nIf there are no bundles, please import a bundle before continuing.");
196 QMessageBox::critical(
this, i18nc(
"@title:window",
"Krita"), warning);
201 QMessageBox::warning(
this, i18nc(
"@title:window",
"Krita"), warning + i18n(
"\nOnly your local resources are available."));
210 dlg.
setDefaultDir(QStandardPaths::writableLocation(QStandardPaths::DownloadLocation));
212 {
"application/x-krita-bundle",
"image/x-adobe-brushlibrary",
"application/x-photoshop-style-library"});
215 Q_FOREACH(
const QString &filename, dlg.
filenames()) {
216 if (!filename.isEmpty()) {
217 KisCursorOverrideLock cursorLock(Qt::BusyCursor);
224 if (!storage->valid()) {
226 qWarning() <<
"Attempted to import an invalid bundle!" << filename;
227 QMessageBox::warning(
this,
228 i18nc(
"@title:window",
"Krita"),
229 i18n(
"Could not load bundle %1.", filename));
235 QFileInfo oldFileInfo(filename);
238 QString newName = oldFileInfo.fileName();
239 const QString newLocation = QStringLiteral(
"%1/%2").arg(newDir, newName);
241 QFileInfo newFileInfo(newLocation);
242 if (newFileInfo.exists()) {
244 if (QMessageBox::warning(
246 i18nc(
"@title:window",
"Warning"),
247 i18n(
"There is already a bundle with this name installed. Do you want to overwrite it?"),
248 QMessageBox::Ok | QMessageBox::Cancel)
249 == QMessageBox::Cancel) {
252 QFile::remove(newLocation);
256 QFile::copy(filename, newLocation);
262 qWarning() <<
"Could not add bundle to the storages" << newLocation;
277 dlg.
setDefaultDir(QStandardPaths::writableLocation(QStandardPaths::DownloadLocation));
279 {
"application/x-krita-bundle",
"image/x-adobe-brushlibrary",
"application/x-photoshop-style-library"});
283 Q_FOREACH(
const QString &filename, dlg.
filenames()) {
284 if (!filename.isEmpty()) {
290 if (!storage->valid()) {
291 qApp->restoreOverrideCursor();
292 qWarning() <<
"Attempted to edit an invalid bundle!" << filename;
293 QMessageBox::warning(
this,
294 i18nc(
"@title:window",
"Krita"),
295 i18n(
"Could not load bundle %1.", filename));
296 qApp->setOverrideCursor(Qt::BusyCursor);
302 if (storage.isNull()){
continue;}
303 if (storage->valid()) {
306 qWarning() <<
"Could not add bundle to the storages" << filename;
311 bool importedBundle = bundle->
load();
315 int response = dlgBC->exec();
323 QModelIndex idx =
m_ui->listView->currentIndex();
326 if (!idx.isValid()) {
333 m_proxyModel->setData(idx, QVariant(!active), Qt::CheckStateRole);
336 m_ui->bnEdit->setEnabled(
false);
338 m_ui->bnEdit->setEnabled(
true);
347 warning = i18n(
"You don't have any resource bundles enabled.");
353 warning += i18n(
"\nThere are no brush presets available. Please enable a bundle that has presets before continuing.\nIf there are no bundles, please import a bundle before continuing.");
354 QMessageBox::critical(
this, i18nc(
"@title:window",
"Krita"), warning);
359 QMessageBox::warning(
this, i18nc(
"@title:window",
"Krita"), warning + i18n(
"\nOnly your local resources are available."));
374 m_proxyModel->removeRows(start, end - start + 1, parent);
379 m_proxyModel->insertRows(start, end - start + 1, parent);
397 if (!current.isValid()) {
410 m_ui->bnToggle->setText(i18nc(
"In bundle manager; press button to deactivate the bundle "
411 "(remove resources from the bundle from the available resources)",
"Deactivate"));
412 m_ui->bnEdit->setEnabled(
true);
414 m_ui->bnToggle->setIcon(QIcon());
415 m_ui->bnToggle->setText(i18nc(
"In bundle manager; press button to activate the bundle "
416 "(add resources from the bundle to the available resources)",
"Activate"));
417 m_ui->bnEdit->setEnabled(
false);
426 m_ui->detailsPanel->hide();
427 m_ui->lblDescription->hide();
429 m_ui->BundleSelectedGroupBox->setTitle(storage->name());
433 m_ui->detailsPanel->show();
434 m_ui->lblDescription->show();
438 m_ui->lblCreated->setText(date);
440 m_ui->lblUpdated->setText(date2);
451 m_ui->lblPreview->setPixmap(QPixmap::fromImage(thumbnail));
QList< QString > QStringList
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
ItemDelegate(QObject *, KisStorageFilterProxyModel *)
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
void slotRowsRemoved(const QModelIndex &parent, int first, int last)
WdgDlgBundleManager * m_ui
void done(int res) override
void updateBundleInformation(QModelIndex idx)
KisStorageFilterProxyModel * m_proxyModel
QPersistentModelIndex lastIndex
void currentCellSelectedChanged(QModelIndex current, QModelIndex previous)
DlgBundleManager(QWidget *parent=0)
void updateToggleButton(bool active)
void slotModelAboutToBeReset()
void slotRowsInserted(const QModelIndex &parent, int first, int last)
bool checkPaintOpAvailable()
bool checkActiveBundlesAvailable()
checkActiveStorages checks whether there is at least one bundle available and at least one paintop pr...
static KisPart * instance()
KisMainWindow * currentMainwindow() const
static KisResourceLocator * instance()
static const QString s_meta_author
static const QString s_meta_creation_date
static const QString s_meta_email
static QString storageTypeToString(StorageType storageType)
static const QString s_meta_license
static QString storageTypeToUntranslatedString(StorageType storageType)
static const QString s_meta_description
static const QString s_meta_dc_date
static const QString s_meta_website
KisResourceStorageSP storageForIndex(QModelIndex index=QModelIndex()) const
@ ByStorageType
Pass a string list of storage types.
void setFilter(FilterType filterType, QVariant filter)
static KisStorageModel * instance()
QVariant data(const QModelIndex &index, int role) const override
A dialog base class with standard buttons and predefined layouts.
QPushButton * button(ButtonCode id) const
void setMainWidget(QWidget *widget)
virtual void setCaption(const QString &caption)
void setButtons(ButtonCodes buttonMask)
@ Close
Show Close-button. (this button closes the dialog)
void setDefaultDir(const QString &defaultDir, bool force=false)
setDefaultDir set the default directory to defaultDir.
QStringList filenames()
Get the file names the user selected in the file dialog.
void setCaption(const QString &caption)
void setMimeTypeFilters(const QStringList &mimeTypeList, QString defaultMimeType=QString())
setMimeTypeFilters Update the list of file filters from mime types.
A KoResourceBundle is a zip file that contains resources, some metadata about the creator of the bund...
bool load()
load : Load this resource.
static QString getAppDataLocation()
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
T kisGrowRect(const T &rect, U offset)
QIcon loadIcon(const QString &name)