kalarm

eventlistviewbase.h

00001 /*
00002  *  eventlistviewbase.h  -  base classes for widget showing list of events
00003  *  Program:  kalarm
00004  *  Copyright (C) 2004, 2005 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 
00079     signals:
00080         void                   itemDeleted();
00081         void                   findActive(bool);
00082 
00083     protected:
00084         virtual void           populate() = 0;         // populate the list with all desired events
00085         virtual EventListViewItemBase* createItem(const KAEvent&) = 0;   // only used by default addEntry() method
00086         virtual bool           shouldShowEvent(const KAEvent&) const  { return true; }
00087         EventListViewItemBase* addEntry(const KAEvent&, bool setSize = false, bool reselect = false);
00088         EventListViewItemBase* addEntry(EventListViewItemBase*, bool setSize, bool reselect);
00089         EventListViewItemBase* updateEntry(EventListViewItemBase*, const KAEvent& newEvent, bool setSize = false, bool reselect = false);
00090         void                   addLastColumn(const QString& title);
00091         virtual void           showEvent(QShowEvent*);
00092         virtual void           resizeEvent(QResizeEvent*);
00093 
00094     private:
00095         void                   deleteEntry(EventListViewItemBase*, bool setSize = false);
00096         void                   findNext(bool forward);
00097 
00098         Find*                  mFind;                 // alarm search object
00099         int                    mLastColumn;           // index to last column
00100         int                    mLastColumnHeaderWidth;
00101 };
00102 
00103 
00104 class EventListViewItemBase : public QListViewItem
00105 {
00106     public:
00107         EventListViewItemBase(EventListViewBase* parent, const KAEvent&);
00108         const KAEvent&         event() const             { return mEvent; }
00109         QPixmap*               eventIcon() const;
00110         int                    lastColumnWidth() const   { return mLastColumnWidth; }
00111         EventListViewItemBase* nextSibling() const       { return (EventListViewItemBase*)QListViewItem::nextSibling(); }
00112         static int             iconWidth();
00113 
00114     protected:
00115         void                   setLastColumnText();
00116         virtual QString        lastColumnText() const = 0;   // get the text to display in the last column
00117 
00118     private:
00119         static QPixmap*        mTextIcon;
00120         static QPixmap*        mFileIcon;
00121         static QPixmap*        mCommandIcon;
00122         static QPixmap*        mEmailIcon;
00123         static int             mIconWidth;        // maximum width of any icon
00124 
00125         KAEvent                mEvent;            // the event for this item
00126         int                    mLastColumnWidth;  // width required to display message column
00127 };
00128 
00129 #endif // EVENTLISTVIEWBASE_H
00130 
KDE Home | KDE Accessibility Home | Description of Access Keys