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

kalarm

  • sources
  • kde-4.12
  • kdepim
  • kalarm
alarmlistdelegate.cpp
Go to the documentation of this file.
1 /*
2  * alarmlistdelegate.cpp - handles editing and display of alarm list
3  * Program: kalarm
4  * Copyright © 2007-2011 by David Jarvie <djarvie@kde.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 #include "kalarm.h"
22 #include "alarmlistdelegate.moc"
23 
24 #ifdef USE_AKONADI
25 #include "akonadimodel.h"
26 #define ITEM_LIST_MODEL AlarmListModel
27 #else
28 #include "eventlistmodel.h"
29 #define ITEM_LIST_MODEL EventListModel
30 #endif
31 #include "functions.h"
32 
33 #include <kalarmcal/kacalendar.h>
34 
35 #include <kcolorscheme.h>
36 #include <kdebug.h>
37 
38 #include <QAbstractProxyModel>
39 #include <QMouseEvent>
40 #include <QApplication>
41 
42 
43 void AlarmListDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
44 {
45  QStyleOptionViewItem opt = option;
46  if (index.isValid())
47  {
48  if (opt.state & QStyle::State_Selected
49 #ifdef USE_AKONADI
50  && !index.data(AkonadiModel::EnabledRole).toBool())
51 #else
52  && !index.data(EventListModel::EnabledRole).toBool())
53 #endif
54  {
55  // Make the text colour for selected disabled alarms
56  // distinguishable from enabled alarms.
57  KColorScheme::adjustForeground(opt.palette, KColorScheme::InactiveText, QPalette::HighlightedText, KColorScheme::Selection);
58  }
59  switch (index.column())
60  {
61  case ITEM_LIST_MODEL::TimeColumn:
62  {
63  QString str = index.data(Qt::DisplayRole).toString();
64  // Need to pad out spacing to align times without leading zeroes
65  int i = str.indexOf(QLatin1String(" ~")); // look for indicator that leading zeroes are omitted
66  if (i >= 0)
67  {
68  QVariant value;
69  value = index.data(Qt::ForegroundRole);
70  if (value.isValid())
71  opt.palette.setColor(QPalette::Text, value.value<QColor>());
72  int digitWidth = opt.fontMetrics.width(QLatin1Char('0'));
73  QString date = str.left(i + 1);
74  int w = opt.fontMetrics.width(date) + digitWidth;
75  drawDisplay(painter, opt, opt.rect, date);
76  QRect rect(opt.rect);
77  rect.setLeft(rect.left() + w);
78  drawDisplay(painter, opt, rect, str.mid(i + 2));
79  return;
80  }
81  break;
82  }
83  case ITEM_LIST_MODEL::ColourColumn:
84  {
85 #ifdef USE_AKONADI
86  const KAEvent event = static_cast<const ItemListModel*>(index.model())->event(index);
87  if (event.isValid() && event.commandError() != KAEvent::CMD_NO_ERROR)
88 #else
89  const KAEvent* event = static_cast<const EventListFilterModel*>(index.model())->event(index);
90  if (event && event->commandError() != KAEvent::CMD_NO_ERROR)
91 #endif
92  {
93  opt.font.setBold(true);
94  opt.font.setStyleHint(QFont::Serif);
95  opt.font.setPixelSize(opt.rect.height() - 2);
96  }
97  break;
98  }
99  default:
100  break;
101  }
102  }
103  QItemDelegate::paint(painter, opt, index);
104 }
105 
106 QSize AlarmListDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
107 {
108  if (index.isValid())
109  {
110  switch (index.column())
111  {
112  case ITEM_LIST_MODEL::TimeColumn:
113  {
114  int h = option.fontMetrics.lineSpacing();
115  const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
116  int w = 2 * textMargin;
117  QString str = index.data(Qt::DisplayRole).toString();
118  // Need to pad out spacing to align times without leading zeroes
119  int i = str.indexOf(QLatin1String(" ~")); // look for indicator that leading zeroes are omitted
120  if (i >= 0)
121  {
122  int digitWidth = option.fontMetrics.width(QLatin1Char('0'));
123  QString date = str.left(i + 1);
124  w += option.fontMetrics.width(date) + digitWidth + option.fontMetrics.width(str.mid(i + 2));;
125  }
126  else
127  w += option.fontMetrics.width(str);
128  return QSize(w, h);
129  }
130  case ITEM_LIST_MODEL::ColourColumn:
131  {
132  int h = option.fontMetrics.lineSpacing();
133  return QSize(h * 3 / 4, h);
134  }
135  }
136  }
137  return QItemDelegate::sizeHint(option, index);
138 }
139 
140 void AlarmListDelegate::edit(KAEvent* event, EventListView* view)
141 {
142  KAlarm::editAlarm(event, static_cast<AlarmListView*>(view)); // edit alarm (view-only mode if archived or read-only)
143 }
144 
145 // vim: et sw=4:
EventListView
Definition: eventlistview.h:37
date
time_t date() const
AlarmListDelegate::edit
virtual void edit(KAEvent *, EventListView *)
Definition: alarmlistdelegate.cpp:140
akonadimodel.h
eventlistmodel.h
AkonadiModel::EnabledRole
Definition: akonadimodel.h:67
EventListModel::EnabledRole
Definition: eventlistmodel.h:55
AlarmListDelegate::paint
virtual void paint(QPainter *, const QStyleOptionViewItem &, const QModelIndex &) const
Definition: alarmlistdelegate.cpp:43
functions.h
miscellaneous functions
kalarm.h
AlarmListDelegate::sizeHint
virtual QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const
Definition: alarmlistdelegate.cpp:106
ItemListModel
Definition: itemlistmodel.h:38
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:59:10 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kalarm

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

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal