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

kalarm

alarmlistdelegate.cpp

Go to the documentation of this file.
00001 /*
00002  *  alarmlistdelegate.cpp  -  handles editing and display of alarm list
00003  *  Program:  kalarm
00004  *  Copyright © 2007,2008 by David Jarvie <djarvie@kde.org>
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License along
00017  *  with this program; if not, write to the Free Software Foundation, Inc.,
00018  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #include "kalarm.h"
00022 
00023 #include <QAbstractProxyModel>
00024 #include <QMouseEvent>
00025 #include <QApplication>
00026 
00027 #include <kdebug.h>
00028 
00029 #include "resources/kcalendar.h"
00030 #include "alarmlistview.h"
00031 #include "alarmresources.h"
00032 #include "eventlistmodel.h"
00033 #include "functions.h"
00034 #include "alarmlistdelegate.moc"
00035 
00036 
00037 void AlarmListDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
00038 {
00039     if (index.isValid()  &&  index.column() == EventListModel::TimeColumn)
00040     {
00041         QString str = index.data(Qt::DisplayRole).toString();
00042         // Need to pad out spacing to align times without leading zeroes
00043         int i = str.indexOf(" ~");    // look for indicator that leading zeroes are omitted
00044         if (i >= 0)
00045         {
00046             QStyleOptionViewItem opt = option;
00047             QVariant value;
00048             value = index.data(Qt::ForegroundRole);
00049             if (value.isValid())
00050                 opt.palette.setColor(QPalette::Text, value.value<QColor>());
00051             int digitWidth = opt.fontMetrics.width("0");
00052             QString date = str.left(i + 1);
00053             int w = opt.fontMetrics.width(date) + digitWidth;
00054             drawDisplay(painter, opt, opt.rect, date);
00055             QRect rect(opt.rect);
00056             rect.setLeft(rect.left() + w);
00057             drawDisplay(painter, opt, rect, str.mid(i + 2));
00058             return;
00059         }
00060     }
00061     QItemDelegate::paint(painter, option, index);
00062 }
00063 
00064 QSize AlarmListDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
00065 {
00066     if (index.isValid())
00067     {
00068         switch (index.column())
00069         {
00070             case EventListModel::TimeColumn:
00071             {
00072                 int h = option.fontMetrics.lineSpacing();
00073                 const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
00074                 int w = 2 * textMargin;
00075                 QString str = index.data(Qt::DisplayRole).toString();
00076                 // Need to pad out spacing to align times without leading zeroes
00077                 int i = str.indexOf(" ~");    // look for indicator that leading zeroes are omitted
00078                 if (i >= 0)
00079                 {
00080                     int digitWidth = option.fontMetrics.width("0");
00081                     QString date = str.left(i + 1);
00082                     w += option.fontMetrics.width(date) + digitWidth + option.fontMetrics.width(str.mid(i + 2));;
00083                 }
00084                 else
00085                     w += option.fontMetrics.width(str);
00086                 return QSize(w, h);
00087             }
00088             case EventListModel::ColourColumn:
00089             {
00090                 int h = option.fontMetrics.lineSpacing();
00091                 return QSize(h * 3 / 4, h);
00092             }
00093         }
00094     }
00095     return QItemDelegate::sizeHint(option, index);
00096 }
00097 
00098 void AlarmListDelegate::edit(KAEvent* event, EventListView* view)
00099 {
00100     KAlarm::editAlarm(event, static_cast<AlarmListView*>(view));   // edit alarm (view-only mode if archived or read-only)
00101 }   

kalarm

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

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  •   doc
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim 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