diff --git a/src/widgets/dialogs/searchchannel/searchchanneldelegate.cpp b/src/widgets/dialogs/searchchannel/searchchanneldelegate.cpp index 364bae3f..d901567b 100644 --- a/src/widgets/dialogs/searchchannel/searchchanneldelegate.cpp +++ b/src/widgets/dialogs/searchchannel/searchchanneldelegate.cpp @@ -1,59 +1,72 @@ /* Copyright (c) 2020 Laurent Montel 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 ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), 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 "searchchanneldelegate.h" +#include +#include #include #include "model/searchchannelmodel.h" SearchChannelDelegate::SearchChannelDelegate(QObject *parent) : QItemDelegate(parent) + , mAddChannel(QIcon::fromTheme(QStringLiteral("list-add"))) { } SearchChannelDelegate::~SearchChannelDelegate() { } void SearchChannelDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { // [M] [M] [M] [M] ([M] = margin) + //TODO add channel type icon too const int iconSize = option.widget->style()->pixelMetric(QStyle::PM_ButtonIconSize); const int margin = 8; const QRect decorationRect(option.rect.x() + margin, option.rect.y(), iconSize, option.rect.height()); const QString text = index.data(SearchChannelModel::ChannelName).toString(); - const QIcon addChannelIcon = QIcon::fromTheme(QStringLiteral("list-add")); const int xText = option.rect.x() + iconSize + 2 * margin; const QRect displayRect(xText, option.rect.y(), option.rect.width() - xText - 2 * margin - iconSize, option.rect.height()); QStyleOptionViewItem optionCopy = option; optionCopy.showDecorationSelected = true; drawBackground(painter, optionCopy, index); const QIcon icon = index.data(SearchChannelModel::IconName).value(); icon.paint(painter, decorationRect, Qt::AlignCenter); const QRect addChannelIconRect(option.rect.width() - iconSize - 2 * margin, option.rect.y(), iconSize, option.rect.height()); - addChannelIcon.paint(painter, addChannelIconRect, Qt::AlignCenter); + mAddChannel.paint(painter, addChannelIconRect, Qt::AlignCenter); drawDisplay(painter, optionCopy, displayRect, text); // this takes care of eliding if the text is too long } + +bool SearchChannelDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) +{ + const QEvent::Type eventType = event->type(); + if (eventType == QEvent::MouseButtonRelease) { + auto *mev = static_cast(event); + //TODO + } + return QItemDelegate::editorEvent(event, model, option, index); +} diff --git a/src/widgets/dialogs/searchchannel/searchchanneldelegate.h b/src/widgets/dialogs/searchchannel/searchchanneldelegate.h index 1cd6f99b..a465c5cc 100644 --- a/src/widgets/dialogs/searchchannel/searchchanneldelegate.h +++ b/src/widgets/dialogs/searchchannel/searchchanneldelegate.h @@ -1,35 +1,38 @@ /* Copyright (c) 2020 Laurent Montel 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 ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), 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 SEARCHCHANNELDELEGATE_H #define SEARCHCHANNELDELEGATE_H #include "libruqolawidgets_private_export.h" #include class LIBRUQOLAWIDGETS_TESTS_EXPORT SearchChannelDelegate : public QItemDelegate { Q_OBJECT public: explicit SearchChannelDelegate(QObject *parent = nullptr); ~SearchChannelDelegate() override; void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; + bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override; +private: + QIcon mAddChannel; }; #endif