diff --git a/libs/resourcewidgets/KisStorageChooserWidget.cpp b/libs/resourcewidgets/KisStorageChooserWidget.cpp index fd2343f461..c8b4ebb494 100644 --- a/libs/resourcewidgets/KisStorageChooserWidget.cpp +++ b/libs/resourcewidgets/KisStorageChooserWidget.cpp @@ -1,106 +1,115 @@ /* 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 #include #include #include #include #include #include "KisStorageChooserWidget.h" #include "KisStorageModel.h" #include KisStorageChooserDelegate::KisStorageChooserDelegate(QObject *parent) : QAbstractItemDelegate(parent) { } void KisStorageChooserDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { - QString location = index.data(Qt::UserRole + KisStorageModel::Location).value(); - bool active = index.data(Qt::UserRole + KisStorageModel::Active).value(); + if (!index.isValid()) return; - if (option.state & QStyle::State_Selected) { - painter->fillRect(option.rect, option.palette.highlight()); - } + painter->save(); + QString location = index.data(Qt::UserRole + KisStorageModel::Location).value(); + location = location.split("/").last(); + location = location.split(".").first(); + location = location.split("_").join(" "); + bool active = index.data(Qt::UserRole + KisStorageModel::Active).value(); QString storageType = index.data(Qt::UserRole + KisStorageModel::StorageType).value(); QPixmap picture = QPixmap(option.decorationSize); if (storageType == "Folder") { picture = koIcon("document-open").pixmap(option.decorationSize); } else if (storageType == "Memory") { picture = koIcon("document-new").pixmap(option.decorationSize); } else { picture = koIcon("bundle_archive").pixmap(option.decorationSize); } if (location.isEmpty()) { location = QString::number(index.row()); } + QColor penColor(option.palette.text().color()); - if (!active) { - penColor.setAlphaF(0.6); - } - painter->setPen(penColor); - painter->drawText(option.rect, 0, location); - if (!active) { - QApplication::style()->drawControl(QStyle::CE_PushButton, &option, painter, 0); + QStyleOptionViewItem opt = option; + + if (active) { + opt.state = QStyle::State_Sunken; } + QApplication::style()->drawPrimitive(QStyle::PE_PanelButtonTool, &opt, painter); + + painter->setPen(penColor); + painter->drawImage(option.rect.topLeft(), picture.toImage(), picture.rect()); + QRect text = option.rect; + text.setLeft(text.left()+option.decorationSize.width()+2); + painter->drawText(text, 0, location); + + painter->restore(); } QSize KisStorageChooserDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { int w = 400; int h = option.decorationSize.height(); return QSize(w, h); } KisStorageChooserWidget::KisStorageChooserWidget(QWidget *parent) : KisPopupButton(parent) { QListView *view = new QListView(this); view->setModel(KisStorageModel::instance()); - view->setIconSize(QSize(32, 32)); + view->setIconSize(QSize(64, 64)); view->setItemDelegate(new KisStorageChooserDelegate(this)); view->setSelectionMode(QAbstractItemView::SingleSelection); connect(view, SIGNAL(clicked(QModelIndex)), this, SLOT(activated(QModelIndex))); this->setPopupWidget(view); } void KisStorageChooserWidget::activated(const QModelIndex &index) { if (!index.isValid()) return; bool active = index.data(Qt::UserRole + KisStorageModel::Active).value(); KisStorageModel::instance()->setData(index, !active, Qt::CheckStateRole); } KisStorageChooserWidget::~KisStorageChooserWidget() { }