SVN_SILENT made messages (.desktop file) - always resolve ours
[kdepim.git] / kalarm / alarmlistview.cpp
blobe788cfaf301f55af89136712e543be076ebe6bb9
1 /*
2 * alarmlistview.cpp - widget showing list of alarms
3 * Program: kalarm
4 * Copyright © 2007,2008,2010 by David Jarvie <djarvie@kde.org>
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.
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.
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.
21 #include "kalarm.h"
22 #include "alarmlistview.h"
24 #include <ksharedconfig.h>
25 #include <kconfiggroup.h>
27 #include <QHeaderView>
28 #include <QApplication>
31 AlarmListView::AlarmListView(const QByteArray& configGroup, QWidget* parent)
32 : EventListView(parent),
33 mConfigGroup(configGroup)
35 setEditOnSingleClick(true);
36 connect(header(), &QHeaderView::sectionMoved, this, &AlarmListView::sectionMoved);
39 void AlarmListView::setModel(QAbstractItemModel* model)
41 EventListView::setModel(model);
42 KConfigGroup config(KSharedConfig::openConfig(), mConfigGroup.constData());
43 QByteArray settings = config.readEntry("ListHead", QByteArray());
44 if (!settings.isEmpty())
45 header()->restoreState(settings);
46 header()->setMovable(true);
47 header()->setStretchLastSection(false);
48 header()->setResizeMode(AlarmListModel::TimeColumn, QHeaderView::ResizeToContents);
49 header()->setResizeMode(AlarmListModel::TimeToColumn, QHeaderView::ResizeToContents);
50 header()->setResizeMode(AlarmListModel::RepeatColumn, QHeaderView::ResizeToContents);
51 header()->setResizeMode(AlarmListModel::ColourColumn, QHeaderView::Fixed);
52 header()->setResizeMode(AlarmListModel::TypeColumn, QHeaderView::Fixed);
53 header()->setResizeMode(AlarmListModel::TextColumn, QHeaderView::Stretch);
54 header()->setStretchLastSection(true); // necessary to ensure ResizeToContents columns do resize to contents!
55 const int margin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin);
56 header()->resizeSection(AlarmListModel::ColourColumn, viewOptions().fontMetrics.lineSpacing() * 3 / 4);
57 header()->resizeSection(AlarmListModel::TypeColumn, AlarmListModel::iconWidth() + 2*margin + 2);
60 /******************************************************************************
61 * Called when the column order is changed.
62 * Save the new order for restoration on program restart.
64 void AlarmListView::sectionMoved()
66 KConfigGroup config(KSharedConfig::openConfig(), mConfigGroup.constData());
67 config.writeEntry("ListHead", header()->saveState());
68 config.sync();
71 /******************************************************************************
72 * Set which time columns are to be displayed.
74 void AlarmListView::selectTimeColumns(bool time, bool timeTo)
76 if (!time && !timeTo)
77 return; // always show at least one time column
78 // bool changed = false;
79 bool hidden = header()->isSectionHidden(AlarmListModel::TimeColumn);
80 if (time && hidden)
82 // Unhide the time column
83 header()->setSectionHidden(AlarmListModel::TimeColumn, false);
84 // changed = true;
86 else if (!time && !hidden)
88 // Hide the time column
89 header()->setSectionHidden(AlarmListModel::TimeColumn, true);
90 // changed = true;
92 hidden = header()->isSectionHidden(AlarmListModel::TimeToColumn);
93 if (timeTo && hidden)
95 // Unhide the time-to-alarm column
96 header()->setSectionHidden(AlarmListModel::TimeToColumn, false);
97 // changed = true;
99 else if (!timeTo && !hidden)
101 // Hide the time-to-alarm column
102 header()->setSectionHidden(AlarmListModel::TimeToColumn, true);
103 // changed = true;
105 // if (changed)
106 // {
107 // resizeLastColumn();
108 // triggerUpdate(); // ensure scroll bar appears if needed
109 // }
113 void AlarmListView::dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
115 for (int col = topLeft.column(); col < bottomRight.column(); ++col)
117 if (col != header()->resizeMode(col) == QHeaderView::ResizeToContents)
118 resizeColumnToContents(col);
123 // vim: et sw=4: