2 Copyright 2008 Marco Martin <notmart@gmail.com>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
21 #include "bookmarksdelegate.h"
27 #include <QModelIndex>
28 #include <QMouseEvent>
30 #include <QStyleOptionViewItem>
35 #include <KColorScheme>
37 #include <KIconLoader>
40 #include <Plasma/PaintUtils>
41 #include <Plasma/Theme>
44 class BookmarksDelegatePrivate
47 BookmarksDelegatePrivate() {
50 ~BookmarksDelegatePrivate() {
57 BookmarksDelegate::BookmarksDelegate(QObject
*parent
)
58 : QStyledItemDelegate(parent
),
59 d(new BookmarksDelegatePrivate
)
63 BookmarksDelegate::~BookmarksDelegate()
68 void BookmarksDelegate::paint(QPainter
*painter
, const QStyleOptionViewItem
& option
, const QModelIndex
& index
) const
70 QStyledItemDelegate::paint(painter
, option
, index
);
72 if (option
.state
& (QStyle::State_MouseOver
| QStyle::State_Selected
)) {
73 QRect destroyIconRect
= QStyle::alignedRect(option
.direction
,
74 option
.decorationPosition
== QStyleOptionViewItem::Left
?
75 Qt::AlignRight
: Qt::AlignLeft
,
76 QSize(option
.rect
.height(), option
.rect
.height()),
78 painter
->drawPixmap(destroyIconRect
, KIcon("list-remove").pixmap(KIconLoader::SizeSmall
, KIconLoader::SizeSmall
));
82 bool BookmarksDelegate::editorEvent(QEvent
*event
,
83 QAbstractItemModel
*model
,
84 const QStyleOptionViewItem
&option
,
85 const QModelIndex
&index
)
87 QRect destroyIconRect
= QStyle::alignedRect(option
.direction
,
88 option
.decorationPosition
== QStyleOptionViewItem::Left
?
89 Qt::AlignRight
: Qt::AlignLeft
,
90 QSize(option
.rect
.height(), option
.rect
.height()),
93 if (event
->type() == QEvent::MouseButtonPress
) {
94 QMouseEvent
*mouseEvent
= static_cast<QMouseEvent
*>(event
);
96 if (destroyIconRect
.contains(mouseEvent
->pos())) {
97 emit
destroyBookmark(index
);
102 return QStyledItemDelegate::editorEvent(event
, model
, option
, index
);