16#include <QInputDialog>
17#include <QItemSelectionModel>
18#include <QStringLiteral>
20#include <kconfiggroup.h>
21#include <ksharedconfig.h>
45 : QStyledItemDelegate(parent)
46 , m_bundleManagerProxyModel(proxy)
56 return QSize(100, 30);
61 if (!index.isValid()) {
65 QModelIndex sourceIndex = m_bundleManagerProxyModel->mapToSource(index);
73 QColor bgColor = option.state & QStyle::State_Selected ?
74 qApp->palette().color(QPalette::Highlight) :
75 qApp->palette().color(QPalette::Base);
77 QBrush oldBrush(painter->brush());
78 QPen oldPen = painter->pen();
80 painter->setBrush(QBrush(bgColor));
81 painter->setPen(Qt::NoPen);
82 painter->drawRect(option.rect);
84 QRect paintRect =
kisGrowRect(option.rect, -minMargin);
85 int height = paintRect.height();
91 QColor borderColor = option.state & QStyle::State_Selected ?
92 qApp->palette().color(QPalette::HighlightedText) :
93 qApp->palette().color(QPalette::Text);
94 painter->setBrush(Qt::NoBrush);
95 painter->setPen(QPen(borderColor));
97 QRect borderRect =
kisGrowRect(paintRect, -painter->pen().widthF());
99 painter->drawRect(borderRect);
101 painter->setBrush(oldBrush);
102 painter->setPen(oldPen);
109 QRect iconRect = paintRect;
110 iconRect.setWidth(height);
111 painter->drawImage(iconRect, thumbnail);
113 QRect nameRect = paintRect;
114 nameRect.setX(paintRect.x() + height + textMargin);
115 nameRect.setWidth(paintRect.width() - height - 1.5*textMargin);
117 QColor textColor = option.state & QStyle::State_Selected ?
118 qApp->palette().color(QPalette::HighlightedText) :
119 qApp->palette().color(QPalette::Text);
120 painter->setPen(QPen(textColor));
122 QTextOption textCenterOption;
123 textCenterOption.setAlignment(Qt::AlignVCenter);
124 textCenterOption.setWrapMode(QTextOption::NoWrap);
126 painter->drawText(nameRect, name, textCenterOption);
136 setCaption(i18n(
"Manage Resource Libraries"));
143 m_ui->bnAdd->setText(i18nc(
"In bundle manager; press button to import a resource library",
"Import"));
144 connect(
m_ui->bnAdd, SIGNAL(clicked(
bool)), SLOT(
addBundle()));
147 m_ui->bnToggle->setText(i18nc(
"In bundle manager; press button to deactivate the resource library"
148 "(remove resources from the resource library from the available resources)",
"Deactivate"));
152 m_ui->bnNew->setText(i18nc(
"In bundle manager; press button to create a new bundle",
"Create Bundle"));
156 m_ui->bnEdit->setText(i18nc(
"In bundle manager; press button to edit existing bundle",
"Edit Bundle"));
160 connect(
m_ui->bnSupport, &QPushButton::clicked,
this, &DlgBundleManager::slotShowSupporterBundlesDialog);
162 m_ui->bnSupport->hide();
179 connect(scroller, &QScroller::stateChanged,
this, [&](QScroller::State state) {
184 QItemSelectionModel* selectionModel =
m_ui->listView->selectionModel();
201 warning = i18n(
"You don't have any resource bundles enabled.");
205 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.");
206 QMessageBox::critical(
this, i18nc(
"@title:window",
"Krita"), warning);
211 QMessageBox::warning(
this, i18nc(
"@title:window",
"Krita"), warning + i18n(
"\nOnly your local resources are available."));
220 dlg.
setDefaultDir(QStandardPaths::writableLocation(QStandardPaths::DownloadLocation));
222 {
"application/x-krita-bundle",
"image/x-adobe-brushlibrary",
"application/x-photoshop-style-library"});
225 Q_FOREACH(
const QString &filename, dlg.
filenames()) {
226 if (!filename.isEmpty()) {
227 KisCursorOverrideLock cursorLock(Qt::BusyCursor);
234 if (!storage->valid()) {
236 qWarning() <<
"Attempted to import an invalid bundle!" << filename;
237 QMessageBox::warning(
this,
238 i18nc(
"@title:window",
"Krita"),
239 i18n(
"Could not load bundle %1.", filename));
245 QFileInfo oldFileInfo(filename);
248 QString newName = oldFileInfo.fileName();
249 const QString newLocation = QStringLiteral(
"%1/%2").arg(newDir, newName);
251 QFileInfo newFileInfo(newLocation);
252 if (newFileInfo.exists()) {
254 if (QMessageBox::warning(
256 i18nc(
"@title:window",
"Warning"),
257 i18n(
"There is already a bundle with this name installed. Do you want to overwrite it?"),
258 QMessageBox::Ok | QMessageBox::Cancel)
259 == QMessageBox::Cancel) {
262 QFile::remove(newLocation);
266 QFile::copy(filename, newLocation);
272 qWarning() <<
"Could not add bundle to the storages" << newLocation;
287 dlg.
setDefaultDir(QStandardPaths::writableLocation(QStandardPaths::DownloadLocation));
289 {
"application/x-krita-bundle",
"image/x-adobe-brushlibrary",
"application/x-photoshop-style-library"});
293 Q_FOREACH(
const QString &filename, dlg.
filenames()) {
294 if (!filename.isEmpty()) {
300 if (!storage->valid()) {
301 qApp->restoreOverrideCursor();
302 qWarning() <<
"Attempted to edit an invalid bundle!" << filename;
303 QMessageBox::warning(
this,
304 i18nc(
"@title:window",
"Krita"),
305 i18n(
"Could not load bundle %1.", filename));
306 qApp->setOverrideCursor(Qt::BusyCursor);
312 if (storage.isNull()){
continue;}
313 if (storage->valid()) {
316 qWarning() <<
"Could not add bundle to the storages" << filename;
321 bool importedBundle = bundle->
load();
325 int response = dlgBC->exec();
332void DlgBundleManager::slotShowSupporterBundlesDialog()
341 QModelIndex idx =
m_ui->listView->currentIndex();
344 if (!idx.isValid()) {
351 m_proxyModel->setData(idx, QVariant(!active), Qt::CheckStateRole);
354 m_ui->bnEdit->setEnabled(
false);
356 m_ui->bnEdit->setEnabled(
true);
365 warning = i18n(
"You don't have any resource bundles enabled.");
371 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.");
372 QMessageBox::critical(
this, i18nc(
"@title:window",
"Krita"), warning);
377 QMessageBox::warning(
this, i18nc(
"@title:window",
"Krita"), warning + i18n(
"\nOnly your local resources are available."));
392 m_proxyModel->removeRows(start, end - start + 1, parent);
397 m_proxyModel->insertRows(start, end - start + 1, parent);
415 if (!current.isValid()) {
428 m_ui->bnToggle->setText(i18nc(
"In bundle manager; press button to deactivate the bundle "
429 "(remove resources from the bundle from the available resources)",
"Deactivate"));
430 m_ui->bnEdit->setEnabled(
true);
432 m_ui->bnToggle->setIcon(QIcon());
433 m_ui->bnToggle->setText(i18nc(
"In bundle manager; press button to activate the bundle "
434 "(add resources from the bundle to the available resources)",
"Activate"));
435 m_ui->bnEdit->setEnabled(
false);
444 m_ui->detailsPanel->hide();
445 m_ui->lblDescription->hide();
447 m_ui->BundleSelectedGroupBox->setTitle(storage->name());
451 m_ui->detailsPanel->show();
452 m_ui->lblDescription->show();
456 m_ui->lblCreated->setText(date);
458 m_ui->lblUpdated->setText(date2);
469 m_ui->lblPreview->setPixmap(QPixmap::fromImage(thumbnail));
QList< QString > QStringList
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)