kalarm

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 <qvaluelist.h>
00027 #include <klistview.h>
00028 
00029 #include "alarmevent.h"
00030 
00031 class QPixmap;
00032 class EventListViewItemBase;
00033 class Find;
00034 
00035 
00036 class EventListViewBase : public KListView
00037 {
00038         Q_OBJECT
00039     public:
00040         typedef QValueList<EventListViewBase*>              InstanceList;
00041         typedef QValueListIterator<EventListViewBase*>      InstanceListIterator;
00042         typedef QValueListConstIterator<EventListViewBase*> InstanceListConstIterator;
00043 
00044         EventListViewBase(QWidget* parent = 0, const char* name = 0);
00045         virtual ~EventListViewBase()  { }
00046         EventListViewItemBase* getEntry(const QString& eventID) const;
00047         void                   addEvent(const KAEvent& e)  { addEvent(e, instances(), this); }
00048         void                   modifyEvent(const KAEvent& e)
00049                                                       { modifyEvent(e.id(), e, instances(), this); }
00050         void                   modifyEvent(const QString& oldEventID, const KAEvent& newEvent)
00051                                                       { modifyEvent(oldEventID, newEvent, instances(), this); }
00052         void                   deleteEvent(const QString& eventID)  { deleteEvent(eventID, instances()); }
00053         static void            addEvent(const KAEvent&, const InstanceList&, EventListViewBase* selectionView);
00054         static void            modifyEvent(const KAEvent& e, const InstanceList& list, EventListViewBase* selectionView)
00055                                                       { modifyEvent(e.id(), e, list, selectionView); }
00056         static void            modifyEvent(const QString& oldEventID, const KAEvent& newEvent, const InstanceList&, EventListViewBase* selectionView);
00057         static void            deleteEvent(const QString& eventID, const InstanceList&);
00058         static void            undeleteEvent(const QString& oldEventID, const KAEvent& event, const InstanceList& list, EventListViewBase* selectionView)
00059                                                       { modifyEvent(oldEventID, event, list, selectionView); }
00060         void                   resizeLastColumn();
00061         int                    itemHeight();
00062         EventListViewItemBase* currentItem() const    { return (EventListViewItemBase*)KListView::currentItem(); }
00063         EventListViewItemBase* firstChild() const     { return (EventListViewItemBase*)KListView::firstChild(); }
00064         bool                   anySelected() const;    // are any items selected?
00065         const KAEvent*         selectedEvent() const;
00066         EventListViewItemBase* selectedItem() const;
00067         QValueList<EventListViewItemBase*> selectedItems() const;
00068         int                    selectedCount() const;
00069         int                    lastColumn() const     { return mLastColumn; }
00070         virtual QString        whatsThisText(int column) const = 0;
00071         virtual InstanceList   instances() = 0; // return all instances
00072 
00073     public slots:
00074         void                   refresh();
00075         virtual void           slotFind();
00076         virtual void           slotFindNext()         { findNext(true); }
00077         virtual void           slotFindPrev()         { findNext(false); }
00078         virtual void           slotSelectAll();
00079         virtual void           slotDeselect();
00080 
00081     signals:
00082         void                   itemDeleted();
00083         void                   findActive(bool);
00084 
00085     protected:
00086         virtual void           populate() = 0;         // populate the list with all desired events
00087         virtual EventListViewItemBase* createItem(const KAEvent&) = 0;   // only used by default addEntry() method
00088         virtual bool           shouldShowEvent(const KAEvent&) const  { return true; }
00089         EventListViewItemBase* addEntry(const KAEvent&, bool setSize = false, bool reselect = false);
00090         EventListViewItemBase* addEntry(EventListViewItemBase*, bool setSize, bool reselect);
00091         EventListViewItemBase* updateEntry(EventListViewItemBase*, const KAEvent& newEvent, bool setSize = false, bool reselect = false);
00092         void                   addLastColumn(const QString& title);
00093         virtual void           showEvent(QShowEvent*);
00094         virtual void           resizeEvent(QResizeEvent*);
00095 
00096     private:
00097         void                   deleteEntry(EventListViewItemBase*, bool setSize = false);
00098         void                   findNext(bool forward);
00099 
00100         Find*                  mFind;                 // alarm search object
00101         int                    mLastColumn;           // index to last column
00102         int                    mLastColumnHeaderWidth;
00103 };
00104 
00105 
00106 class EventListViewItemBase : public QListViewItem
00107 {
00108     public:
00109         EventListViewItemBase(EventListViewBase* parent, const KAEvent&);
00110         const KAEvent&         event() const             { return mEvent; }
00111         QPixmap*               eventIcon() const;
00112         int                    lastColumnWidth() const   { return mLastColumnWidth; }
00113         EventListViewItemBase* nextSibling() const       { return (EventListViewItemBase*)QListViewItem::nextSibling(); }
00114         static int             iconWidth();
00115 
00116     protected:
00117         void                   setLastColumnText();
00118         virtual QString        lastColumnText() const = 0;   // get the text to display in the last column
00119 
00120     private:
00121         static QPixmap*        mTextIcon;
00122         static QPixmap*        mFileIcon;
00123         static QPixmap*        mCommandIcon;
00124         static QPixmap*        mEmailIcon;
00125         static int             mIconWidth;        // maximum width of any icon
00126 
00127         KAEvent                mEvent;            // the event for this item
00128         int                    mLastColumnWidth;  // width required to display message column
00129 };
00130 
00131 #endif // EVENTLISTVIEWBASE_H
00132 
KDE Home | KDE Accessibility Home | Description of Access Keys