kalarm

eventlistviewbase.h
1 /*
2  * eventlistviewbase.h - base classes for widget showing list of events
3  * Program: kalarm
4  * Copyright (c) 2004-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 EVENTLISTVIEWBASE_H
22 #define EVENTLISTVIEWBASE_H
23 
24 #include "kalarm.h"
25 
26 #include <tqvaluelist.h>
27 #include <tdelistview.h>
28 
29 #include "alarmevent.h"
30 
31 class TQPixmap;
32 class EventListViewItemBase;
33 class Find;
34 
35 
36 class EventListViewBase : public TDEListView
37 {
38  TQ_OBJECT
39 
40  public:
41  typedef TQValueList<EventListViewBase*> InstanceList;
42  typedef TQValueListIterator<EventListViewBase*> InstanceListIterator;
43  typedef TQValueListConstIterator<EventListViewBase*> InstanceListConstIterator;
44 
45  EventListViewBase(TQWidget* parent = 0, const char* name = 0);
46  virtual ~EventListViewBase() { }
47  EventListViewItemBase* getEntry(const TQString& eventID) const;
48  void addEvent(const KAEvent& e) { addEvent(e, instances(), this); }
49  void modifyEvent(const KAEvent& e)
50  { modifyEvent(e.id(), e, instances(), this); }
51  void modifyEvent(const TQString& oldEventID, const KAEvent& newEvent)
52  { modifyEvent(oldEventID, newEvent, instances(), this); }
53  void deleteEvent(const TQString& eventID) { deleteEvent(eventID, instances()); }
54  static void addEvent(const KAEvent&, const InstanceList&, EventListViewBase* selectionView);
55  static void modifyEvent(const KAEvent& e, const InstanceList& list, EventListViewBase* selectionView)
56  { modifyEvent(e.id(), e, list, selectionView); }
57  static void modifyEvent(const TQString& oldEventID, const KAEvent& newEvent, const InstanceList&, EventListViewBase* selectionView);
58  static void deleteEvent(const TQString& eventID, const InstanceList&);
59  static void undeleteEvent(const TQString& oldEventID, const KAEvent& event, const InstanceList& list, EventListViewBase* selectionView)
60  { modifyEvent(oldEventID, event, list, selectionView); }
61  void resizeLastColumn();
62  int itemHeight();
63  EventListViewItemBase* currentItem() const { return (EventListViewItemBase*)TDEListView::currentItem(); }
64  EventListViewItemBase* firstChild() const { return (EventListViewItemBase*)TDEListView::firstChild(); }
65  bool anySelected() const; // are any items selected?
66  const KAEvent* selectedEvent() const;
67  EventListViewItemBase* selectedItem() const;
68  TQValueList<EventListViewItemBase*> selectedItems() const;
69  int selectedCount() const;
70  int lastColumn() const { return mLastColumn; }
71  virtual TQString whatsThisText(int column) const = 0;
72  virtual InstanceList instances() = 0; // return all instances
73 
74  public slots:
75  void refresh();
76  virtual void slotFind();
77  virtual void slotFindNext() { findNext(true); }
78  virtual void slotFindPrev() { findNext(false); }
79  virtual void slotSelectAll();
80  virtual void slotDeselect();
81 
82  signals:
83  void itemDeleted();
84  void findActive(bool);
85 
86  protected:
87  virtual void populate() = 0; // populate the list with all desired events
88  virtual EventListViewItemBase* createItem(const KAEvent&) = 0; // only used by default addEntry() method
89  virtual bool shouldShowEvent(const KAEvent&) const { return true; }
90  EventListViewItemBase* addEntry(const KAEvent&, bool setSize = false, bool reselect = false);
91  EventListViewItemBase* addEntry(EventListViewItemBase*, bool setSize, bool reselect);
92  EventListViewItemBase* updateEntry(EventListViewItemBase*, const KAEvent& newEvent, bool setSize = false, bool reselect = false);
93  void addLastColumn(const TQString& title);
94  virtual void showEvent(TQShowEvent*);
95  virtual void resizeEvent(TQResizeEvent*);
96 
97  private:
98  void deleteEntry(EventListViewItemBase*, bool setSize = false);
99  void findNext(bool forward);
100 
101  Find* mFind; // alarm search object
102  int mLastColumn; // index to last column
103  int mLastColumnHeaderWidth;
104 };
105 
106 
107 class EventListViewItemBase : public TQListViewItem
108 {
109  public:
110  EventListViewItemBase(EventListViewBase* parent, const KAEvent&);
111  const KAEvent& event() const { return mEvent; }
112  TQPixmap* eventIcon() const;
113  int lastColumnWidth() const { return mLastColumnWidth; }
114  EventListViewItemBase* nextSibling() const { return (EventListViewItemBase*)TQListViewItem::nextSibling(); }
115  static int iconWidth();
116 
117  protected:
118  void setLastColumnText();
119  virtual TQString lastColumnText() const = 0; // get the text to display in the last column
120 
121  private:
122  static TQPixmap* mTextIcon;
123  static TQPixmap* mFileIcon;
124  static TQPixmap* mCommandIcon;
125  static TQPixmap* mEmailIcon;
126  static int mIconWidth; // maximum width of any icon
127 
128  KAEvent mEvent; // the event for this item
129  int mLastColumnWidth; // width required to display message column
130 };
131 
132 #endif // EVENTLISTVIEWBASE_H
133 
represents calendar alarms and events
KAEvent corresponds to a KCal::Event instance.
Definition: alarmevent.h:232