• 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
alarmlistview.cpp
Go to the documentation of this file.
1 /*
2  * alarmlistview.cpp - widget showing list of alarms
3  * Program: kalarm
4  * Copyright © 2007,2008,2010 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 "alarmlistview.h"
23 
24 #ifdef USE_AKONADI
25 #define ALARM_LIST_MODEL AlarmListModel
26 #else
27 #include "eventlistmodel.h"
28 #include "alarmlistfiltermodel.h"
29 #define ALARM_LIST_MODEL EventListModel
30 #endif
31 
32 #include <ksharedconfig.h>
33 #include <kconfiggroup.h>
34 #include <kglobal.h>
35 
36 #include <QHeaderView>
37 #include <QApplication>
38 
39 
40 AlarmListView::AlarmListView(const QByteArray& configGroup, QWidget* parent)
41  : EventListView(parent),
42  mConfigGroup(configGroup)
43 {
44  setEditOnSingleClick(true);
45  connect(header(), SIGNAL(sectionMoved(int,int,int)), SLOT(sectionMoved()));
46 }
47 
48 void AlarmListView::setModel(QAbstractItemModel* model)
49 {
50  EventListView::setModel(model);
51  KConfigGroup config(KGlobal::config(), mConfigGroup.constData());
52  QByteArray settings = config.readEntry("ListHead", QByteArray());
53  if (!settings.isEmpty())
54  header()->restoreState(settings);
55  header()->setMovable(true);
56  header()->setStretchLastSection(false);
57  header()->setResizeMode(ALARM_LIST_MODEL::TimeColumn, QHeaderView::ResizeToContents);
58  header()->setResizeMode(ALARM_LIST_MODEL::TimeToColumn, QHeaderView::ResizeToContents);
59  header()->setResizeMode(ALARM_LIST_MODEL::RepeatColumn, QHeaderView::ResizeToContents);
60  header()->setResizeMode(ALARM_LIST_MODEL::ColourColumn, QHeaderView::Fixed);
61  header()->setResizeMode(ALARM_LIST_MODEL::TypeColumn, QHeaderView::Fixed);
62  header()->setResizeMode(ALARM_LIST_MODEL::TextColumn, QHeaderView::Stretch);
63  header()->setStretchLastSection(true); // necessary to ensure ResizeToContents columns do resize to contents!
64  const int margin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin);
65  header()->resizeSection(ALARM_LIST_MODEL::ColourColumn, viewOptions().fontMetrics.lineSpacing() * 3 / 4);
66  header()->resizeSection(ALARM_LIST_MODEL::TypeColumn, ALARM_LIST_MODEL::iconWidth() + 2*margin + 2);
67 }
68 
69 /******************************************************************************
70 * Called when the column order is changed.
71 * Save the new order for restoration on program restart.
72 */
73 void AlarmListView::sectionMoved()
74 {
75  KConfigGroup config(KGlobal::config(), mConfigGroup.constData());
76  config.writeEntry("ListHead", header()->saveState());
77  config.sync();
78 }
79 
80 /******************************************************************************
81 * Set which time columns are to be displayed.
82 */
83 void AlarmListView::selectTimeColumns(bool time, bool timeTo)
84 {
85  if (!time && !timeTo)
86  return; // always show at least one time column
87 // bool changed = false;
88  bool hidden = header()->isSectionHidden(ALARM_LIST_MODEL::TimeColumn);
89  if (time && hidden)
90  {
91  // Unhide the time column
92  header()->setSectionHidden(ALARM_LIST_MODEL::TimeColumn, false);
93 // changed = true;
94  }
95  else if (!time && !hidden)
96  {
97  // Hide the time column
98  header()->setSectionHidden(ALARM_LIST_MODEL::TimeColumn, true);
99 // changed = true;
100  }
101  hidden = header()->isSectionHidden(ALARM_LIST_MODEL::TimeToColumn);
102  if (timeTo && hidden)
103  {
104  // Unhide the time-to-alarm column
105  header()->setSectionHidden(ALARM_LIST_MODEL::TimeToColumn, false);
106 // changed = true;
107  }
108  else if (!timeTo && !hidden)
109  {
110  // Hide the time-to-alarm column
111  header()->setSectionHidden(ALARM_LIST_MODEL::TimeToColumn, true);
112 // changed = true;
113  }
114 // if (changed)
115 // {
116 // resizeLastColumn();
117 // triggerUpdate(); // ensure scroll bar appears if needed
118 // }
119 }
120 
121 /*
122 void AlarmListView::dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
123 {
124  for (int col = topLeft.column(); col < bottomRight.column(); ++col)
125  {
126  if (col != header()->resizeMode(col) == QHeaderView::ResizeToContents)
127  resizeColumnToContents(col);
128  }
129 }
130 */
131 #include "moc_alarmlistview.cpp"
132 // vim: et sw=4:
saveState
KDEPIM_EXPORT void saveState(QWidget *widget, KConfigGroup &config)
QWidget
QHeaderView::setMovable
void setMovable(bool movable)
AlarmListView::selectTimeColumns
void selectTimeColumns(bool time, bool timeTo)
Definition: alarmlistview.cpp:83
QByteArray
AlarmListView::AlarmListView
AlarmListView(const QByteArray &configGroup, QWidget *parent=0)
Definition: alarmlistview.cpp:40
EventListView
Definition: eventlistview.h:37
QHeaderView::restoreState
bool restoreState(const QByteArray &state)
QStyle::pixelMetric
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const =0
alarmlistfiltermodel.h
QHeaderView::resizeSection
void resizeSection(int logicalIndex, int size)
QHeaderView::isSectionHidden
bool isSectionHidden(int logicalIndex) const
AlarmListView::setModel
virtual void setModel(QAbstractItemModel *)
Definition: alarmlistview.cpp:48
QByteArray::constData
const char * constData() const
eventlistmodel.h
QWidget::fontMetrics
QFontMetrics fontMetrics() const
QApplication::style
QStyle * style()
alarmlistview.h
QTreeView::setModel
virtual void setModel(QAbstractItemModel *model)
kalarm.h
QHeaderView::setResizeMode
void setResizeMode(ResizeMode mode)
QAbstractItemView::viewOptions
virtual QStyleOptionViewItem viewOptions() const
QAbstractItemModel
QTreeView::header
QHeaderView * header() const
QHeaderView::setStretchLastSection
void setStretchLastSection(bool stretch)
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QHeaderView::setSectionHidden
void setSectionHidden(int logicalIndex, bool hide)
QFontMetrics::lineSpacing
int lineSpacing() const
EventListView::setEditOnSingleClick
void setEditOnSingleClick(bool e)
Definition: eventlistview.h:64
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