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

Applets

notifierview.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2007 by Alexis Ménard <darktears31@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 #include "notifierview.h"
00021 
00022 // Qt
00023 
00024 #include <QtGui/QMouseEvent>
00025 #include <QtGui/QPainter>
00026 #include <QtGui/QPaintEvent>
00027 #include <QtGui/QScrollBar>
00028 #include <QtGui/QHeaderView>
00029 
00030 //KDE
00031 #include <KDebug>
00032 #include <KIconLoader>
00033 
00034 //Plasma
00035 #include <plasma/delegate.h>
00036 
00037 using namespace Notifier;
00038 
00039 NotifierView::NotifierView(QWidget *parent)
00040     : QTreeView(parent)
00041 {
00042     setIconSize(QSize(KIconLoader::SizeMedium, KIconLoader::SizeMedium));
00043     setRootIsDecorated(false);
00044     setHeaderHidden(true);
00045     setMouseTracking(true);
00046 }
00047 
00048 NotifierView::~NotifierView()
00049 {
00050 
00051 }
00052 
00053 void NotifierView::resizeEvent(QResizeEvent * event)
00054 {
00055     //the columns after the first are squares KIconLoader::SizeMedium x KIconLoader::SizeMedium,
00056     //the first column takes all the remaining space
00057     if (header()->count() > 0) {
00058         const int newWidth = event->size().width() -
00059                              (header()->count()-1)*(sizeHintForRow(0));
00060         header()->resizeSection(0, newWidth);
00061     }
00062 }
00063 
00064 void NotifierView::mouseMoveEvent(QMouseEvent *event)
00065 {
00066     const QModelIndex itemUnderMouse = indexAt(event->pos());
00067     if (itemUnderMouse != m_hoveredIndex && itemUnderMouse.isValid() &&
00068         state() == NoState) {
00069         update(itemUnderMouse);
00070         update(m_hoveredIndex);
00071 
00072         m_hoveredIndex = itemUnderMouse;
00073         setCurrentIndex(m_hoveredIndex);
00074     } else if (!itemUnderMouse.isValid()) {
00075         m_hoveredIndex = QModelIndex();
00076         setCurrentIndex(m_hoveredIndex);
00077     }
00078 
00079     QAbstractItemView::mouseMoveEvent(event);
00080 }
00081 
00082 void NotifierView::leaveEvent(QEvent *event)
00083 {
00084     const QModelIndex oldHoveredIndex = m_hoveredIndex;
00085     m_hoveredIndex = QModelIndex();
00086     setCurrentIndex(m_hoveredIndex);
00087     update(oldHoveredIndex);
00088 }
00089 
00090 QModelIndex NotifierView::moveCursor(CursorAction cursorAction,Qt::KeyboardModifiers modifiers )
00091 {
00092     m_hoveredIndex = QModelIndex();
00093 
00094     return QTreeView::moveCursor(cursorAction, modifiers );
00095 }
00096 
00097 void NotifierView::paintEvent(QPaintEvent *event)
00098 {
00099     if (!model()) {
00100         return;
00101     }
00102 
00103     QPainter painter(viewport());
00104     painter.setRenderHint(QPainter::Antialiasing);
00105 
00106     const int rows = model()->rowCount(rootIndex());
00107     const int cols = header()->count();
00108     //kDebug() << "painting" << rows << "rows" << cols << "columns";
00109 
00110     for (int i = 0; i < rows; ++i) {
00111         for (int j = 0; j < cols; ++j) {
00112             const QModelIndex index = model()->index(i, j, rootIndex());
00113             const QRect itemRect = visualRect(index);
00114 
00115             if (event->region().contains(itemRect)) {
00116                 QStyleOptionViewItem option = viewOptions();
00117                 option.rect = itemRect;
00118 
00119                 if (selectionModel()->isSelected(index)) {
00120                     option.state |= QStyle::State_Selected;
00121                 }
00122                 if (index == m_hoveredIndex) {
00123                     option.state |= QStyle::State_MouseOver;
00124                 }
00125                 if (index == currentIndex()) {
00126                     option.state |= QStyle::State_HasFocus;
00127                 }
00128 
00129                 itemDelegate(index)->paint(&painter,option,index);
00130             }
00131         }
00132     }
00133 }
00134 
00135 #include "notifierview.moc"

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
  •   libplasma
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.4
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