Applets
bookmarksdelegate.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "bookmarksdelegate.h"
00022
00023 #include <cmath>
00024 #include <math.h>
00025
00026
00027 #include <QModelIndex>
00028 #include <QMouseEvent>
00029 #include <QPainter>
00030 #include <QStyleOptionViewItem>
00031
00032
00033 #include <KDebug>
00034 #include <KGlobal>
00035 #include <KColorScheme>
00036 #include <KIcon>
00037 #include <KIconLoader>
00038
00039
00040 #include <Plasma/PaintUtils>
00041 #include <Plasma/Theme>
00042
00043
00044 class BookmarksDelegatePrivate
00045 {
00046 public:
00047 BookmarksDelegatePrivate() {
00048 }
00049
00050 ~BookmarksDelegatePrivate() {
00051 }
00052 };
00053
00054
00055
00056
00057 BookmarksDelegate::BookmarksDelegate(QObject *parent)
00058 : QStyledItemDelegate(parent),
00059 d(new BookmarksDelegatePrivate)
00060 {
00061 }
00062
00063 BookmarksDelegate::~BookmarksDelegate()
00064 {
00065 delete d;
00066 }
00067
00068 void BookmarksDelegate::paint(QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
00069 {
00070 QStyledItemDelegate::paint(painter, option, index);
00071
00072 if (option.state & (QStyle::State_MouseOver | QStyle::State_Selected)) {
00073 QRect destroyIconRect = QStyle::alignedRect(option.direction,
00074 option.decorationPosition == QStyleOptionViewItem::Left ?
00075 Qt::AlignRight : Qt::AlignLeft,
00076 QSize(option.rect.height(), option.rect.height()),
00077 option.rect);
00078 painter->drawPixmap(destroyIconRect, KIcon("list-remove").pixmap(KIconLoader::SizeSmall, KIconLoader::SizeSmall));
00079 }
00080 }
00081
00082 bool BookmarksDelegate::editorEvent(QEvent *event,
00083 QAbstractItemModel *model,
00084 const QStyleOptionViewItem &option,
00085 const QModelIndex &index)
00086 {
00087 QRect destroyIconRect = QStyle::alignedRect(option.direction,
00088 option.decorationPosition == QStyleOptionViewItem::Left ?
00089 Qt::AlignRight : Qt::AlignLeft,
00090 QSize(option.rect.height(), option.rect.height()),
00091 option.rect);
00092
00093 if (event->type() == QEvent::MouseButtonPress) {
00094 QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
00095
00096 if (destroyIconRect.contains(mouseEvent->pos())) {
00097 emit destroyBookmark(index);
00098 return true;
00099 }
00100 }
00101
00102 return QStyledItemDelegate::editorEvent(event, model, option, index);
00103 }
00104