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

kalarm

  • sources
  • kde-4.14
  • 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.h"
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 <QApplication>
39 
40 
41 void AlarmListDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
42 {
43  QStyleOptionViewItem opt = option;
44  if (index.isValid())
45  {
46  if (opt.state & QStyle::State_Selected
47 #ifdef USE_AKONADI
48  && !index.data(AkonadiModel::EnabledRole).toBool())
49 #else
50  && !index.data(EventListModel::EnabledRole).toBool())
51 #endif
52  {
53  // Make the text colour for selected disabled alarms
54  // distinguishable from enabled alarms.
55  KColorScheme::adjustForeground(opt.palette, KColorScheme::InactiveText, QPalette::HighlightedText, KColorScheme::Selection);
56  }
57  switch (index.column())
58  {
59  case ITEM_LIST_MODEL::TimeColumn:
60  {
61  QString str = index.data(Qt::DisplayRole).toString();
62  // Need to pad out spacing to align times without leading zeroes
63  int i = str.indexOf(QLatin1String(" ~")); // look for indicator that leading zeroes are omitted
64  if (i >= 0)
65  {
66  QVariant value;
67  value = index.data(Qt::ForegroundRole);
68  if (value.isValid())
69  opt.palette.setColor(QPalette::Text, value.value<QColor>());
70  int digitWidth = opt.fontMetrics.width(QLatin1Char('0'));
71  QString date = str.left(i + 1);
72  int w = opt.fontMetrics.width(date) + digitWidth;
73  drawDisplay(painter, opt, opt.rect, date);
74  QRect rect(opt.rect);
75  rect.setLeft(rect.left() + w);
76  drawDisplay(painter, opt, rect, str.mid(i + 2));
77  return;
78  }
79  break;
80  }
81  case ITEM_LIST_MODEL::ColourColumn:
82  {
83 #ifdef USE_AKONADI
84  const KAEvent event = static_cast<const ItemListModel*>(index.model())->event(index);
85  if (event.isValid() && event.commandError() != KAEvent::CMD_NO_ERROR)
86 #else
87  const KAEvent* event = static_cast<const EventListFilterModel*>(index.model())->event(index);
88  if (event && event->commandError() != KAEvent::CMD_NO_ERROR)
89 #endif
90  {
91  opt.font.setBold(true);
92  opt.font.setStyleHint(QFont::Serif);
93  opt.font.setPixelSize(opt.rect.height() - 2);
94  }
95  break;
96  }
97  default:
98  break;
99  }
100  }
101  QItemDelegate::paint(painter, opt, index);
102 }
103 
104 QSize AlarmListDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
105 {
106  if (index.isValid())
107  {
108  switch (index.column())
109  {
110  case ITEM_LIST_MODEL::TimeColumn:
111  {
112  int h = option.fontMetrics.lineSpacing();
113  const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1;
114  int w = 2 * textMargin;
115  QString str = index.data(Qt::DisplayRole).toString();
116  // Need to pad out spacing to align times without leading zeroes
117  int i = str.indexOf(QLatin1String(" ~")); // look for indicator that leading zeroes are omitted
118  if (i >= 0)
119  {
120  int digitWidth = option.fontMetrics.width(QLatin1Char('0'));
121  QString date = str.left(i + 1);
122  w += option.fontMetrics.width(date) + digitWidth + option.fontMetrics.width(str.mid(i + 2));;
123  }
124  else
125  w += option.fontMetrics.width(str);
126  return QSize(w, h);
127  }
128  case ITEM_LIST_MODEL::ColourColumn:
129  {
130  int h = option.fontMetrics.lineSpacing();
131  return QSize(h * 3 / 4, h);
132  }
133  }
134  }
135  return QItemDelegate::sizeHint(option, index);
136 }
137 
138 void AlarmListDelegate::edit(KAEvent* event, EventListView* view)
139 {
140  KAlarm::editAlarm(event, static_cast<AlarmListView*>(view)); // edit alarm (view-only mode if archived or read-only)
141 }
142 
143 #include "moc_alarmlistdelegate.cpp"
144 // vim: et sw=4:
QModelIndex
QString::indexOf
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
EventListView
Definition: eventlistview.h:37
date
time_t date() const
QStyle::pixelMetric
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const =0
AlarmListDelegate::edit
virtual void edit(KAEvent *, EventListView *)
Definition: alarmlistdelegate.cpp:138
QVariant::value
T value() const
QItemDelegate::paint
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
QObject::event
virtual bool event(QEvent *e)
akonadimodel.h
QRect
QModelIndex::isValid
bool isValid() const
QItemDelegate::drawDisplay
virtual void drawDisplay(QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect, const QString &text) const
QStyleOptionViewItem
QRect::left
int left() const
QPainter
QItemDelegate::sizeHint
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
eventlistmodel.h
QString
QColor
AkonadiModel::EnabledRole
Definition: akonadimodel.h:65
QSize
QLatin1Char
EventListModel::EnabledRole
Definition: eventlistmodel.h:54
QModelIndex::model
const QAbstractItemModel * model() const
AlarmListDelegate::paint
virtual void paint(QPainter *, const QStyleOptionViewItem &, const QModelIndex &) const
Definition: alarmlistdelegate.cpp:41
QString::mid
QString mid(int position, int n) const
QModelIndex::data
QVariant data(int role) const
QApplication::style
QStyle * style()
QLatin1String
functions.h
miscellaneous functions
kalarm.h
QModelIndex::column
int column() const
QVariant::toBool
bool toBool() const
QString::left
QString left(int n) const
QVariant::isValid
bool isValid() const
AlarmListDelegate::sizeHint
virtual QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const
Definition: alarmlistdelegate.cpp:104
alarmlistdelegate.h
QVariant::toString
QString toString() const
QRect::setLeft
void setLeft(int x)
ItemListModel
Definition: itemlistmodel.h:38
QVariant
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:34:51 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
  • pimprint

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