kalarm

alarmlistview.h
1 /*
2  * alarmlistview.h - widget showing list of outstanding alarms
3  * Program: kalarm
4  * Copyright © 2001-2006 by David Jarvie <software@astrojar.org.uk>
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 #ifndef ALARMLISTVIEW_H
22 #define ALARMLISTVIEW_H
23 
24 #include "kalarm.h"
25 #include "eventlistviewbase.h"
26 
27 class AlarmListView;
28 class AlarmListTooltip;
29 
30 
31 class AlarmListViewItem : public EventListViewItemBase
32 {
33  public:
34  AlarmListViewItem(AlarmListView* parent, const KAEvent&, const TQDateTime& now);
35  TQTime showTimeToAlarm(bool show);
36  void updateTimeToAlarm(const TQDateTime& now, bool forceDisplay = false);
37  virtual void paintCell(TQPainter*, const TQColorGroup&, int column, int width, int align);
38  AlarmListView* alarmListView() const { return (AlarmListView*)listView(); }
39  bool messageTruncated() const { return mMessageTruncated; }
40  int messageColWidthNeeded() const { return mMessageColWidth; }
41  static int typeIconWidth(AlarmListView*);
42  // Overridden base class methods
43  AlarmListViewItem* nextSibling() const { return (AlarmListViewItem*)TQListViewItem::nextSibling(); }
44  virtual TQString key(int column, bool ascending) const;
45  protected:
46  virtual TQString lastColumnText() const { return alarmText(event()); }
47  private:
48  TQString alarmText(const KAEvent&) const;
49  TQString alarmTimeText(const DateTime&) const;
50  TQString timeToAlarmText(const TQDateTime& now) const;
51 
52  static int mTimeHourPos; // position of hour within time string, or -1 if leading zeroes included
53  static int mDigitWidth; // display width of a digit
54  TQString mDateTimeOrder; // controls ordering of date/time column
55  TQString mRepeatOrder; // controls ordering of repeat column
56  TQString mColourOrder; // controls ordering of colour column
57  TQString mTypeOrder; // controls ordering of alarm type column
58  mutable int mMessageColWidth; // width needed to display complete message text
59  mutable bool mMessageTruncated; // multi-line message text has been truncated for the display
60  bool mTimeToAlarmShown; // relative alarm time is displayed
61 };
62 
63 
64 class AlarmListView : public EventListViewBase
65 {
66  TQ_OBJECT
67  // needed by TQObject::isA() calls
68  public:
69  enum ColumnIndex { // default column order
70  TIME_COLUMN, TIME_TO_COLUMN, REPEAT_COLUMN, COLOUR_COLUMN, TYPE_COLUMN, MESSAGE_COLUMN,
71  COLUMN_COUNT
72  };
73 
74  AlarmListView(const TQValueList<int>& order, TQWidget* parent = 0, const char* name = 0);
75  ~AlarmListView();
76  void showExpired(bool show) { mShowExpired = show; }
77  bool showingExpired() const { return mShowExpired; }
78  bool showingTimeTo() const { return columnWidth(mColumn[TIME_TO_COLUMN]); }
79  void selectTimeColumns(bool time, bool timeTo);
80  void updateTimeToAlarms(bool forceDisplay = false);
81  bool expired(AlarmListViewItem*) const;
82  bool drawMessageInColour() const { return mDrawMessageInColour; }
83  void setDrawMessageInColour(bool inColour) { mDrawMessageInColour = inColour; }
84  TQValueList<int> columnOrder() const;
85  int column(ColumnIndex i) const { return mColumn[i]; }
86  static bool dragging() { return mDragging; }
87  // Overridden base class methods
88  static void addEvent(const KAEvent&, EventListViewBase*);
89  static void modifyEvent(const KAEvent& e, EventListViewBase* selectionView)
90  { EventListViewBase::modifyEvent(e.id(), e, mInstanceList, selectionView); }
91  static void modifyEvent(const TQString& oldEventID, const KAEvent& newEvent, EventListViewBase* selectionView)
92  { EventListViewBase::modifyEvent(oldEventID, newEvent, mInstanceList, selectionView); }
93  static void deleteEvent(const TQString& eventID)
94  { EventListViewBase::deleteEvent(eventID, mInstanceList); }
95  static void undeleteEvent(const TQString& oldEventID, const KAEvent& event, EventListViewBase* selectionView)
96  { EventListViewBase::modifyEvent(oldEventID, event, mInstanceList, selectionView); }
97  AlarmListViewItem* getEntry(const TQString& eventID) { return (AlarmListViewItem*)EventListViewBase::getEntry(eventID); }
98  AlarmListViewItem* currentItem() const { return (AlarmListViewItem*)EventListViewBase::currentItem(); }
99  AlarmListViewItem* firstChild() const { return (AlarmListViewItem*)EventListViewBase::firstChild(); }
100  AlarmListViewItem* selectedItem() const { return (AlarmListViewItem*)EventListViewBase::selectedItem(); }
101  virtual void setSelected(TQListViewItem* item, bool selected) { EventListViewBase::setSelected(item, selected); }
102  virtual void setSelected(AlarmListViewItem* item, bool selected) { EventListViewBase::setSelected(item, selected); }
103  virtual InstanceList instances() { return mInstanceList; }
104 
105  protected:
106  virtual void populate();
107  EventListViewItemBase* createItem(const KAEvent&);
108  virtual TQString whatsThisText(int column) const;
109  virtual bool shouldShowEvent(const KAEvent& e) const { return mShowExpired || !e.expired(); }
110  AlarmListViewItem* addEntry(const KAEvent& e, bool setSize = false)
111  { return addEntry(e, TQDateTime::currentDateTime(), setSize); }
112  AlarmListViewItem* updateEntry(AlarmListViewItem* item, const KAEvent& newEvent, bool setSize = false)
113  { return (AlarmListViewItem*)EventListViewBase::updateEntry(item, newEvent, setSize); }
114  virtual void contentsMousePressEvent(TQMouseEvent*);
115  virtual void contentsMouseMoveEvent(TQMouseEvent*);
116  virtual void contentsMouseReleaseEvent(TQMouseEvent*);
117 
118  private:
119  AlarmListViewItem* addEntry(const KAEvent&, const TQDateTime& now, bool setSize = false, bool reselect = false);
120 
121  static InstanceList mInstanceList; // all current instances of this class
122  static bool mDragging;
123  int mColumn[COLUMN_COUNT]; // initial position of each column
124  int mTimeColumnHeaderWidth;
125  int mTimeToColumnHeaderWidth;
126  AlarmListTooltip* mTooltip; // tooltip for showing full text of alarm messages
127  TQPoint mMousePressPos; // where the mouse left button was last pressed
128  bool mMousePressed; // true while the mouse left button is pressed
129  bool mDrawMessageInColour;
130  bool mShowExpired; // true to show expired alarms
131 };
132 
133 #endif // ALARMLISTVIEW_H
134 
KAEvent corresponds to a KCal::Event instance.
Definition: alarmevent.h:232