• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Applets

bookmarksdelegate.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2008 Marco Martin <notmart@gmail.com>
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License as published by the Free Software Foundation; either
00007     version 2 of the License, or (at your option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Library General Public License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to
00016     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017     Boston, MA 02110-1301, USA.
00018 */
00019 
00020 // Own
00021 #include "bookmarksdelegate.h"
00022 
00023 #include <cmath>
00024 #include <math.h>
00025 
00026 // Qt
00027 #include <QModelIndex>
00028 #include <QMouseEvent>
00029 #include <QPainter>
00030 #include <QStyleOptionViewItem>
00031 
00032 // KDE
00033 #include <KDebug>
00034 #include <KGlobal>
00035 #include <KColorScheme>
00036 #include <KIcon>
00037 #include <KIconLoader>
00038 
00039 // plasma
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 

Applets

Skip menu "Applets"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal