eventlistviewbase.h
00001 /* 00002 * eventlistviewbase.h - base classes for widget showing list of events 00003 * Program: kalarm 00004 * Copyright (c) 2004-2006 by David Jarvie <software@astrojar.org.uk> 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License along 00017 * with this program; if not, write to the Free Software Foundation, Inc., 00018 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #ifndef EVENTLISTVIEWBASE_H 00022 #define EVENTLISTVIEWBASE_H 00023 00024 #include "kalarm.h" 00025 00026 #include <tqvaluelist.h> 00027 #include <tdelistview.h> 00028 00029 #include "alarmevent.h" 00030 00031 class TQPixmap; 00032 class EventListViewItemBase; 00033 class Find; 00034 00035 00036 class EventListViewBase : public TDEListView 00037 { 00038 Q_OBJECT 00039 00040 public: 00041 typedef TQValueList<EventListViewBase*> InstanceList; 00042 typedef TQValueListIterator<EventListViewBase*> InstanceListIterator; 00043 typedef TQValueListConstIterator<EventListViewBase*> InstanceListConstIterator; 00044 00045 EventListViewBase(TQWidget* parent = 0, const char* name = 0); 00046 virtual ~EventListViewBase() { } 00047 EventListViewItemBase* getEntry(const TQString& eventID) const; 00048 void addEvent(const KAEvent& e) { addEvent(e, instances(), this); } 00049 void modifyEvent(const KAEvent& e) 00050 { modifyEvent(e.id(), e, instances(), this); } 00051 void modifyEvent(const TQString& oldEventID, const KAEvent& newEvent) 00052 { modifyEvent(oldEventID, newEvent, instances(), this); } 00053 void deleteEvent(const TQString& eventID) { deleteEvent(eventID, instances()); } 00054 static void addEvent(const KAEvent&, const InstanceList&, EventListViewBase* selectionView); 00055 static void modifyEvent(const KAEvent& e, const InstanceList& list, EventListViewBase* selectionView) 00056 { modifyEvent(e.id(), e, list, selectionView); } 00057 static void modifyEvent(const TQString& oldEventID, const KAEvent& newEvent, const InstanceList&, EventListViewBase* selectionView); 00058 static void deleteEvent(const TQString& eventID, const InstanceList&); 00059 static void undeleteEvent(const TQString& oldEventID, const KAEvent& event, const InstanceList& list, EventListViewBase* selectionView) 00060 { modifyEvent(oldEventID, event, list, selectionView); } 00061 void resizeLastColumn(); 00062 int itemHeight(); 00063 EventListViewItemBase* currentItem() const { return (EventListViewItemBase*)TDEListView::currentItem(); } 00064 EventListViewItemBase* firstChild() const { return (EventListViewItemBase*)TDEListView::firstChild(); } 00065 bool anySelected() const; // are any items selected? 00066 const KAEvent* selectedEvent() const; 00067 EventListViewItemBase* selectedItem() const; 00068 TQValueList<EventListViewItemBase*> selectedItems() const; 00069 int selectedCount() const; 00070 int lastColumn() const { return mLastColumn; } 00071 virtual TQString whatsThisText(int column) const = 0; 00072 virtual InstanceList instances() = 0; // return all instances 00073 00074 public slots: 00075 void refresh(); 00076 virtual void slotFind(); 00077 virtual void slotFindNext() { findNext(true); } 00078 virtual void slotFindPrev() { findNext(false); } 00079 virtual void slotSelectAll(); 00080 virtual void slotDeselect(); 00081 00082 signals: 00083 void itemDeleted(); 00084 void findActive(bool); 00085 00086 protected: 00087 virtual void populate() = 0; // populate the list with all desired events 00088 virtual EventListViewItemBase* createItem(const KAEvent&) = 0; // only used by default addEntry() method 00089 virtual bool shouldShowEvent(const KAEvent&) const { return true; } 00090 EventListViewItemBase* addEntry(const KAEvent&, bool setSize = false, bool reselect = false); 00091 EventListViewItemBase* addEntry(EventListViewItemBase*, bool setSize, bool reselect); 00092 EventListViewItemBase* updateEntry(EventListViewItemBase*, const KAEvent& newEvent, bool setSize = false, bool reselect = false); 00093 void addLastColumn(const TQString& title); 00094 virtual void showEvent(TQShowEvent*); 00095 virtual void resizeEvent(TQResizeEvent*); 00096 00097 private: 00098 void deleteEntry(EventListViewItemBase*, bool setSize = false); 00099 void findNext(bool forward); 00100 00101 Find* mFind; // alarm search object 00102 int mLastColumn; // index to last column 00103 int mLastColumnHeaderWidth; 00104 }; 00105 00106 00107 class EventListViewItemBase : public TQListViewItem 00108 { 00109 public: 00110 EventListViewItemBase(EventListViewBase* parent, const KAEvent&); 00111 const KAEvent& event() const { return mEvent; } 00112 TQPixmap* eventIcon() const; 00113 int lastColumnWidth() const { return mLastColumnWidth; } 00114 EventListViewItemBase* nextSibling() const { return (EventListViewItemBase*)TQListViewItem::nextSibling(); } 00115 static int iconWidth(); 00116 00117 protected: 00118 void setLastColumnText(); 00119 virtual TQString lastColumnText() const = 0; // get the text to display in the last column 00120 00121 private: 00122 static TQPixmap* mTextIcon; 00123 static TQPixmap* mFileIcon; 00124 static TQPixmap* mCommandIcon; 00125 static TQPixmap* mEmailIcon; 00126 static int mIconWidth; // maximum width of any icon 00127 00128 KAEvent mEvent; // the event for this item 00129 int mLastColumnWidth; // width required to display message column 00130 }; 00131 00132 #endif // EVENTLISTVIEWBASE_H 00133