• 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
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.moc"
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 <QMouseEvent>
38 #include <QApplication>
39 
40 
41 AlarmListView::AlarmListView(const QByteArray& configGroup, QWidget* parent)
42  : EventListView(parent),
43  mConfigGroup(configGroup)
44 {
45  setEditOnSingleClick(true);
46  connect(header(), SIGNAL(sectionMoved(int,int,int)), SLOT(sectionMoved()));
47 }
48 
49 void AlarmListView::setModel(QAbstractItemModel* model)
50 {
51  EventListView::setModel(model);
52  KConfigGroup config(KGlobal::config(), mConfigGroup.constData());
53  QByteArray settings = config.readEntry("ListHead", QByteArray());
54  if (!settings.isEmpty())
55  header()->restoreState(settings);
56  header()->setMovable(true);
57  header()->setStretchLastSection(false);
58  header()->setResizeMode(ALARM_LIST_MODEL::TimeColumn, QHeaderView::ResizeToContents);
59  header()->setResizeMode(ALARM_LIST_MODEL::TimeToColumn, QHeaderView::ResizeToContents);
60  header()->setResizeMode(ALARM_LIST_MODEL::RepeatColumn, QHeaderView::ResizeToContents);
61  header()->setResizeMode(ALARM_LIST_MODEL::ColourColumn, QHeaderView::Fixed);
62  header()->setResizeMode(ALARM_LIST_MODEL::TypeColumn, QHeaderView::Fixed);
63  header()->setResizeMode(ALARM_LIST_MODEL::TextColumn, QHeaderView::Stretch);
64  header()->setStretchLastSection(true); // necessary to ensure ResizeToContents columns do resize to contents!
65  const int margin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin);
66  header()->resizeSection(ALARM_LIST_MODEL::ColourColumn, viewOptions().fontMetrics.lineSpacing() * 3 / 4);
67  header()->resizeSection(ALARM_LIST_MODEL::TypeColumn, ALARM_LIST_MODEL::iconWidth() + 2*margin + 2);
68 }
69 
70 /******************************************************************************
71 * Called when the column order is changed.
72 * Save the new order for restoration on program restart.
73 */
74 void AlarmListView::sectionMoved()
75 {
76  KConfigGroup config(KGlobal::config(), mConfigGroup.constData());
77  config.writeEntry("ListHead", header()->saveState());
78  config.sync();
79 }
80 
81 /******************************************************************************
82 * Set which time columns are to be displayed.
83 */
84 void AlarmListView::selectTimeColumns(bool time, bool timeTo)
85 {
86  if (!time && !timeTo)
87  return; // always show at least one time column
88 // bool changed = false;
89  bool hidden = header()->isSectionHidden(ALARM_LIST_MODEL::TimeColumn);
90  if (time && hidden)
91  {
92  // Unhide the time column
93  header()->setSectionHidden(ALARM_LIST_MODEL::TimeColumn, false);
94 // changed = true;
95  }
96  else if (!time && !hidden)
97  {
98  // Hide the time column
99  header()->setSectionHidden(ALARM_LIST_MODEL::TimeColumn, true);
100 // changed = true;
101  }
102  hidden = header()->isSectionHidden(ALARM_LIST_MODEL::TimeToColumn);
103  if (timeTo && hidden)
104  {
105  // Unhide the time-to-alarm column
106  header()->setSectionHidden(ALARM_LIST_MODEL::TimeToColumn, false);
107 // changed = true;
108  }
109  else if (!timeTo && !hidden)
110  {
111  // Hide the time-to-alarm column
112  header()->setSectionHidden(ALARM_LIST_MODEL::TimeToColumn, true);
113 // changed = true;
114  }
115 // if (changed)
116 // {
117 // resizeLastColumn();
118 // triggerUpdate(); // ensure scroll bar appears if needed
119 // }
120 }
121 
122 /*
123 void AlarmListView::dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
124 {
125  for (int col = topLeft.column(); col < bottomRight.column(); ++col)
126  {
127  if (col != header()->resizeMode(col) == QHeaderView::ResizeToContents)
128  resizeColumnToContents(col);
129  }
130 }
131 */
132 
133 // vim: et sw=4:
saveState
KDEPIM_EXPORT void saveState(QWidget *widget, KConfigGroup &config)
AlarmListView::selectTimeColumns
void selectTimeColumns(bool time, bool timeTo)
Definition: alarmlistview.cpp:84
AlarmListView::AlarmListView
AlarmListView(const QByteArray &configGroup, QWidget *parent=0)
Definition: alarmlistview.cpp:41
EventListView
Definition: eventlistview.h:37
QWidget
alarmlistfiltermodel.h
AlarmListView::setModel
virtual void setModel(QAbstractItemModel *)
Definition: alarmlistview.cpp:49
eventlistmodel.h
kalarm.h
EventListView::setEditOnSingleClick
void setEditOnSingleClick(bool e)
Definition: eventlistview.h:64
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