diff --git a/libs/resourcewidgets/CMakeLists.txt b/libs/resourcewidgets/CMakeLists.txt index d855837d52..4fa8739118 100644 --- a/libs/resourcewidgets/CMakeLists.txt +++ b/libs/resourcewidgets/CMakeLists.txt @@ -1,42 +1,43 @@ add_subdirectory(dbexplorer) set(kritaresourcewidgets_LIB_SRCS KisIconToolTip.cpp KisResourceItemChooserContextMenu.cpp KisResourceItemChooser.cpp KisResourceItemChooserSync.cpp KisResourceItemDelegate.cpp + KisResourceItemListView.cpp KisResourceItemView.cpp KisTagChooserWidget.cpp KisTagFilterWidget.cpp KisTagToolButton.cpp KisResourceTaggingManager.cpp ) add_library(kritaresourcewidgets SHARED ${kritaresourcewidgets_LIB_SRCS}) generate_export_header(kritaresourcewidgets BASE_NAME kritaresourcewidgets) target_link_libraries(kritaresourcewidgets PUBLIC Qt5::Core Qt5::Widgets PRIVATE Qt5::Sql kritaversion kritaglobal kritaplugin kritastore kritaresources kritawidgetutils KF5::ConfigCore KF5::WidgetsAddons KF5::CoreAddons KF5::I18n ) set_target_properties(kritaresourcewidgets PROPERTIES VERSION ${GENERIC_KRITA_LIB_VERSION} SOVERSION ${GENERIC_KRITA_LIB_SOVERSION} ) install(TARGETS kritaresourcewidgets ${INSTALL_TARGETS_DEFAULT_ARGS} ) diff --git a/libs/resourcewidgets/KisResourceItemDelegate.cpp b/libs/resourcewidgets/KisResourceItemDelegate.cpp index b96641dc7c..90370a1e7c 100644 --- a/libs/resourcewidgets/KisResourceItemDelegate.cpp +++ b/libs/resourcewidgets/KisResourceItemDelegate.cpp @@ -1,88 +1,91 @@ /* This file is part of the KDE project * Copyright (C) 2008 Jan Hambrecht * Copyright (C) 2018 Boudewijn Rempt * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "KisResourceItemDelegate.h" #include #include #include "KisResourceModel.h" KisResourceItemDelegate::KisResourceItemDelegate(QObject *parent) : QAbstractItemDelegate(parent) , m_checkerPainter(4) { } void KisResourceItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem & option, const QModelIndex &index) const { if (!index.isValid()) return; painter->save(); if (option.state & QStyle::State_Selected) { painter->fillRect(option.rect, option.palette.highlight()); } - QRect innerRect = option.rect.adjusted(2, 1, -2, -1); + QRect innerRect = option.rect.adjusted(2, 2, -2, -2); QImage thumbnail = index.data(Qt::DecorationRole).value(); + if (thumbnail.isNull()) { + thumbnail = index.data(Qt::UserRole + KisResourceModel::Image).value(); + } QSize imageSize = thumbnail.size(); painter->setRenderHint(QPainter::SmoothPixmapTransform, true); QString resourceType = index.data(Qt::UserRole + KisResourceModel::ResourceType).toString(); // XXX: don't use a hardcoded string here to identify the resource type if (resourceType == ResourceType::Gradients) { m_checkerPainter.paint(*painter, innerRect); thumbnail = thumbnail.scaled(innerRect.width(), innerRect.height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); painter->drawImage(innerRect.topLeft(), thumbnail); } else if (resourceType == ResourceType::Patterns) { painter->fillRect(innerRect, Qt::white); // no checkers, they are confusing with patterns. if (imageSize.height() > innerRect.height() || imageSize.width() > innerRect.width()) { thumbnail = thumbnail.scaled(innerRect.width(), innerRect.height(), Qt::KeepAspectRatio, Qt::SmoothTransformation); } painter->fillRect(innerRect, QBrush(thumbnail)); } else { painter->fillRect(innerRect, Qt::white); // no checkers, they are confusing with patterns. if (imageSize.height() > innerRect.height() || imageSize.width() > innerRect.width()) { thumbnail = thumbnail.scaled(innerRect.width(), innerRect.height(), Qt::KeepAspectRatio, Qt::SmoothTransformation); } QPoint topleft(innerRect.topLeft()); if (thumbnail.width() < innerRect.width()) { topleft.setX(topleft.x() + (innerRect.width() - thumbnail.width()) / 2); } if (thumbnail.height() < innerRect.height()) { topleft.setY(topleft.y() + (innerRect.height() - thumbnail.height()) / 2); } painter->drawImage(topleft, thumbnail); } painter->restore(); } QSize KisResourceItemDelegate::sizeHint(const QStyleOptionViewItem &optionItem, const QModelIndex &) const { return optionItem.decorationSize; } diff --git a/libs/resourcewidgets/KisResourceItemListView.cpp b/libs/resourcewidgets/KisResourceItemListView.cpp new file mode 100644 index 0000000000..3279da81a3 --- /dev/null +++ b/libs/resourcewidgets/KisResourceItemListView.cpp @@ -0,0 +1,44 @@ +/* This file is part of the KDE project + * Copyright (C) 2019 Wolthera van Hövell tot Westerflier + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "KisResourceItemListView.h" + +KisResourceItemListView::KisResourceItemListView(QWidget *parent): QListView(parent) +{ + setSelectionMode(QAbstractItemView::SingleSelection); + setContextMenuPolicy(Qt::DefaultContextMenu); + setViewMode(QListView::IconMode); + setGridSize(QSize(64, 64)); + setIconSize(QSize(64, 64)); + setResizeMode(QListView::Adjust); + setUniformItemSizes(true); + + QScroller *scroller = KisKineticScroller::createPreconfiguredScroller(this); + if (scroller) { + connect(scroller, SIGNAL(stateChanged(QScroller::State)), this, SLOT(slotScrollerStateChange(QScroller::State))); + } + + connect(this, SIGNAL(clicked(QModelIndex)), SIGNAL(currentResourceClicked(const QModelIndex &))); +} + +void KisResourceItemListView::setItemSize(QSize size) +{ + setGridSize(size); + setIconSize(size); +} diff --git a/libs/resourcewidgets/KisResourceItemListView.h b/libs/resourcewidgets/KisResourceItemListView.h new file mode 100644 index 0000000000..879b3f2629 --- /dev/null +++ b/libs/resourcewidgets/KisResourceItemListView.h @@ -0,0 +1,60 @@ +/* This file is part of the KDE project + * Copyright (C) 2019 Wolthera van Hövell tot Westerflier + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef KISRESOURCEITEMLISTVIEW_H +#define KISRESOURCEITEMLISTVIEW_H + +#include +#include + +#include + +#include "kritaresourcewidgets_export.h" + +class KRITARESOURCEWIDGETS_EXPORT KisResourceItemListView : public QListView +{ + Q_OBJECT + +public: + KisResourceItemListView(QWidget *parent = nullptr); + + /** + * @brief setItemSize + * convenience function which sets both the icon and the grid size + * to the same value. + * @param size - the size you wish either to be. + */ + void setItemSize(QSize size); + +public Q_SLOTS: + void slotScrollerStateChange(QScroller::State state){ KisKineticScroller::updateCursor(this, state); } + +Q_SIGNALS: + + void sigSizeChanged(); + +Q_SIGNALS: + + void currentResourceChanged(const QModelIndex &); + void currentResourceClicked(const QModelIndex &); + + void contextMenuRequested(const QPoint &); +}; + +#endif // KISRESOURCEITEMLISTVIEW_H diff --git a/libs/resourcewidgets/dbexplorer/DlgDbExplorer.cpp b/libs/resourcewidgets/dbexplorer/DlgDbExplorer.cpp index fdc28f1f0e..6f796f89d7 100644 --- a/libs/resourcewidgets/dbexplorer/DlgDbExplorer.cpp +++ b/libs/resourcewidgets/dbexplorer/DlgDbExplorer.cpp @@ -1,172 +1,173 @@ /* * Copyright (c) 2018 Boudewijn Rempt * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "DlgDbExplorer.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include +#include DlgDbExplorer::DlgDbExplorer(QWidget *parent) : KoDialog(parent) { setCaption(i18n("Resources Cache Database Explorer")); setButtons(Ok); m_page = new WdgDbExplorer(this); Q_CHECK_PTR(m_page); setMainWidget(m_page); m_resourceTypeModel = new KisResourceTypeModel(this); m_tagModel = new KisTagModel("", this); { TableModel *storagesModel = new TableModel(this, QSqlDatabase::database()); TableDelegate *storagesDelegate = new TableDelegate(m_page->tableStorages); storagesModel->setTable("storages"); storagesModel->setHeaderData(0, Qt::Horizontal, i18n("Id")); storagesModel->setHeaderData(1, Qt::Horizontal, i18n("Type")); storagesModel->setRelation(1, QSqlRelation("storage_types", "id", "name")); storagesModel->setHeaderData(2, Qt::Horizontal, i18n("Location")); storagesModel->setHeaderData(3, Qt::Horizontal, i18n("Creation Date")); storagesModel->addDateTimeColumn(3); storagesDelegate->addDateTimeColumn(3); storagesModel->setHeaderData(4, Qt::Horizontal, i18n("Preinstalled")); storagesModel->addBooleanColumn(4); storagesDelegate->addBooleanColumn(4); storagesModel->setHeaderData(5, Qt::Horizontal, i18n("Active")); storagesModel->addBooleanColumn(5); storagesDelegate->addBooleanColumn(5); storagesModel->select(); m_page->tableStorages->setModel(storagesModel); m_page->tableStorages->hideColumn(0); m_page->tableStorages->setItemDelegate(storagesDelegate); - m_page->tableStorages->setSelectionMode(QAbstractItemView::SingleSelection);; + m_page->tableStorages->setSelectionMode(QAbstractItemView::SingleSelection); m_page->tableStorages->resizeColumnsToContents(); } { KisResourceModel *resourcesModel = KisResourceModelProvider::resourceModel(ResourceType::Gradients); m_page->tableResources->setModel(resourcesModel); m_page->tableResources->hideColumn(0); - m_page->tableResources->setSelectionMode(QAbstractItemView::SingleSelection);; + m_page->tableResources->setSelectionMode(QAbstractItemView::SingleSelection); m_page->cmbResourceTypes->setModel(KisResourceModelProvider::resourceModel(ResourceType::Gradients)); m_page->cmbResourceTypes->setModelColumn(KisResourceTypeModel::Name); } { TableModel *tagsModel = new TableModel(this, QSqlDatabase::database()); TableDelegate *tagsDelegate = new TableDelegate(m_page->tableStorages); tagsDelegate->setEditable(true); tagsModel->setTable("tags"); tagsModel->setHeaderData(0, Qt::Horizontal, i18n("Id")); tagsModel->setHeaderData(1, Qt::Horizontal, i18n("Type")); tagsModel->setRelation(1, QSqlRelation("resource_types", "id", "name")); tagsModel->setHeaderData(2, Qt::Horizontal, i18n("Tag")); tagsModel->setHeaderData(3, Qt::Horizontal, i18n("Name")); tagsModel->setHeaderData(4, Qt::Horizontal, i18n("Comment")); tagsModel->setHeaderData(5, Qt::Horizontal, i18n("Active")); tagsModel->addBooleanColumn(5); tagsDelegate->addBooleanColumn(5); tagsModel->select(); m_page->tableTags->setModel(tagsModel); m_page->tableTags->hideColumn(0); m_page->tableTags->setItemDelegate(tagsDelegate); m_page->tableTags->setSelectionMode(QAbstractItemView::SingleSelection); m_page->tableTags->resizeColumnsToContents(); } { QSqlTableModel *versionModel = new QSqlTableModel(this, QSqlDatabase::database()); versionModel->setTable("version_information"); versionModel->setHeaderData(0, Qt::Horizontal, "id"); versionModel->setHeaderData(1, Qt::Horizontal, "database_version"); versionModel->setHeaderData(2, Qt::Horizontal, "krita_version"); versionModel->setHeaderData(3, Qt::Horizontal, "creation_date"); versionModel->select(); QSqlRecord r = versionModel->record(0); m_page->lblDatabaseVersion->setText(r.value("database_version").toString()); m_page->lblKritaVersion->setText(r.value("krita_version").toString()); m_page->lblCreationDate->setText(r.value("creation_date").toString()); } { m_page->cmbRvResourceTypes->setModel(m_resourceTypeModel); m_page->cmbRvResourceTypes->setModelColumn(KisResourceTypeModel::Name); connect(m_page->cmbRvResourceTypes, SIGNAL(activated(int)), SLOT(slotRvResourceTypeSelected(int))); m_page->cmbRvTags->setModelColumn(KisTagModel::Name); m_page->cmbRvTags->setModel(m_tagModel); connect(m_page->cmbRvTags, SIGNAL(activated(int)), SLOT(slotRvTagSelected(int))); m_page->cmbRvResourceTypes->setCurrentIndex(0); slotRvResourceTypeSelected(0); m_page->resourceItemView->setItemDelegate(new KisResourceItemDelegate(this)); m_page->resourceItemView->setSelectionMode(QAbstractItemView::SingleSelection); } } DlgDbExplorer::~DlgDbExplorer() { } void DlgDbExplorer::slotRvResourceTypeSelected(int index) { QModelIndex idx = m_page->cmbRvResourceTypes->model()->index(index, KisResourceTypeModel::ResourceType); QString resourceType = idx.data(Qt::DisplayRole).toString(); qDebug() << resourceType; m_tagModel->setResourceType(idx.data(Qt::DisplayRole).toString()); KisResourceModel *resourceModel = KisResourceModelProvider::resourceModel(resourceType); KisTagFilterResourceProxyModel *tagFilterModel = new KisTagFilterResourceProxyModel(this); tagFilterModel->setSourceModel(resourceModel); - KisResourceGridProxyModel *resourceProxyModel = new KisResourceGridProxyModel(this); - resourceProxyModel->setSourceModel(tagFilterModel); - resourceProxyModel->setRowStride(10); + //KisResourceGridProxyModel *resourceProxyModel = new KisResourceGridProxyModel(this); + //resourceProxyModel->setSourceModel(tagFilterModel); + //resourceProxyModel->setRowStride(10); - m_page->resourceItemView->setModel(resourceProxyModel); + m_page->resourceItemView->setModel(tagFilterModel); } void DlgDbExplorer::slotRvTagSelected(int index) { qDebug() << "selected tag" << index; } diff --git a/libs/resourcewidgets/dbexplorer/WdgDbExplorer.ui b/libs/resourcewidgets/dbexplorer/WdgDbExplorer.ui index 3d8238b0c7..7f8fb493da 100644 --- a/libs/resourcewidgets/dbexplorer/WdgDbExplorer.ui +++ b/libs/resourcewidgets/dbexplorer/WdgDbExplorer.ui @@ -1,220 +1,212 @@ WdgDbExplorer 0 0 975 545 4 Storages Resources TextLabel lblThumbnail Versions Tags Schema Information Database Version TextLabel Krita Version TextLabel Creation Date TextLabel Resource View Resource Type: Tag: 0 0 - - - - 0 - 2 - - - + Qt::Vertical 20 40 KComboBox QComboBox
kcombobox.h
- KisResourceItemView - QWidget -
KisResourceItemView.h
- 1 + KisResourceItemListView + QListView +
KisResourceItemListView.h