not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / plasma / applets / webbrowser / bookmarksdelegate.cpp
blobb9ff37a9fc54831cfd781fe46fc7b4adc3abd3d7
1 /*
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.
20 // Own
21 #include "bookmarksdelegate.h"
23 #include <cmath>
24 #include <math.h>
26 // Qt
27 #include <QModelIndex>
28 #include <QMouseEvent>
29 #include <QPainter>
30 #include <QStyleOptionViewItem>
32 // KDE
33 #include <KDebug>
34 #include <KGlobal>
35 #include <KColorScheme>
36 #include <KIcon>
37 #include <KIconLoader>
39 // plasma
40 #include <Plasma/PaintUtils>
41 #include <Plasma/Theme>
44 class BookmarksDelegatePrivate
46 public:
47 BookmarksDelegatePrivate() {
50 ~BookmarksDelegatePrivate() {
57 BookmarksDelegate::BookmarksDelegate(QObject *parent)
58 : QStyledItemDelegate(parent),
59 d(new BookmarksDelegatePrivate)
63 BookmarksDelegate::~BookmarksDelegate()
65 delete d;
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()),
77 option.rect);
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()),
91 option.rect);
93 if (event->type() == QEvent::MouseButtonPress) {
94 QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
96 if (destroyIconRect.contains(mouseEvent->pos())) {
97 emit destroyBookmark(index);
98 return true;
102 return QStyledItemDelegate::editorEvent(event, model, option, index);