kalarm

alarmlistview.h
00001 /*
00002  *  alarmlistview.h  -  widget showing list of outstanding alarms
00003  *  Program:  kalarm
00004  *  Copyright © 2001-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 ALARMLISTVIEW_H
00022 #define ALARMLISTVIEW_H
00023 
00024 #include "kalarm.h"
00025 #include "eventlistviewbase.h"
00026 
00027 class AlarmListView;
00028 class AlarmListTooltip;
00029 
00030 
00031 class AlarmListViewItem : public EventListViewItemBase
00032 {
00033     public:
00034         AlarmListViewItem(AlarmListView* parent, const KAEvent&, const TQDateTime& now);
00035         TQTime               showTimeToAlarm(bool show);
00036         void                updateTimeToAlarm(const TQDateTime& now, bool forceDisplay = false);
00037         virtual void        paintCell(TQPainter*, const TQColorGroup&, int column, int width, int align);
00038         AlarmListView*      alarmListView() const         { return (AlarmListView*)listView(); }
00039         bool                messageTruncated() const      { return mMessageTruncated; }
00040         int                 messageColWidthNeeded() const { return mMessageColWidth; }
00041         static int          typeIconWidth(AlarmListView*);
00042         // Overridden base class methods
00043         AlarmListViewItem*  nextSibling() const           { return (AlarmListViewItem*)TQListViewItem::nextSibling(); }
00044         virtual TQString     key(int column, bool ascending) const;
00045     protected:
00046         virtual TQString     lastColumnText() const        { return alarmText(event()); }
00047     private:
00048         TQString             alarmText(const KAEvent&) const;
00049         TQString             alarmTimeText(const DateTime&) const;
00050         TQString             timeToAlarmText(const TQDateTime& now) const;
00051 
00052         static int          mTimeHourPos;       // position of hour within time string, or -1 if leading zeroes included
00053         static int          mDigitWidth;        // display width of a digit
00054         TQString             mDateTimeOrder;     // controls ordering of date/time column
00055         TQString             mRepeatOrder;       // controls ordering of repeat column
00056         TQString             mColourOrder;       // controls ordering of colour column
00057         TQString             mTypeOrder;         // controls ordering of alarm type column
00058         mutable int         mMessageColWidth;   // width needed to display complete message text
00059         mutable bool        mMessageTruncated;  // multi-line message text has been truncated for the display
00060         bool                mTimeToAlarmShown;  // relative alarm time is displayed
00061 };
00062 
00063 
00064 class AlarmListView : public EventListViewBase
00065 {
00066         Q_OBJECT
00067         TQ_OBJECT       // needed by TQObject::isA() calls
00068     public:
00069         enum ColumnIndex {    // default column order
00070             TIME_COLUMN, TIME_TO_COLUMN, REPEAT_COLUMN, COLOUR_COLUMN, TYPE_COLUMN, MESSAGE_COLUMN,
00071             COLUMN_COUNT
00072         };
00073 
00074         AlarmListView(const TQValueList<int>& order, TQWidget* parent = 0, const char* name = 0);
00075         ~AlarmListView();
00076         void                   showExpired(bool show)      { mShowExpired = show; }
00077         bool                   showingExpired() const      { return mShowExpired; }
00078         bool                   showingTimeTo() const       { return columnWidth(mColumn[TIME_TO_COLUMN]); }
00079         void                   selectTimeColumns(bool time, bool timeTo);
00080         void                   updateTimeToAlarms(bool forceDisplay = false);
00081         bool                   expired(AlarmListViewItem*) const;
00082         bool                   drawMessageInColour() const            { return mDrawMessageInColour; }
00083         void                   setDrawMessageInColour(bool inColour)  { mDrawMessageInColour = inColour; }
00084         TQValueList<int>        columnOrder() const;
00085         int                    column(ColumnIndex i) const { return mColumn[i]; }
00086         static bool            dragging()                  { return mDragging; }
00087         // Overridden base class methods
00088         static void            addEvent(const KAEvent&, EventListViewBase*);
00089         static void            modifyEvent(const KAEvent& e, EventListViewBase* selectionView)
00090                                      { EventListViewBase::modifyEvent(e.id(), e, mInstanceList, selectionView); }
00091         static void            modifyEvent(const TQString& oldEventID, const KAEvent& newEvent, EventListViewBase* selectionView)
00092                                      { EventListViewBase::modifyEvent(oldEventID, newEvent, mInstanceList, selectionView); }
00093         static void            deleteEvent(const TQString& eventID)
00094                                      { EventListViewBase::deleteEvent(eventID, mInstanceList); }
00095         static void            undeleteEvent(const TQString& oldEventID, const KAEvent& event, EventListViewBase* selectionView)
00096                                      { EventListViewBase::modifyEvent(oldEventID, event, mInstanceList, selectionView); }
00097         AlarmListViewItem*     getEntry(const TQString& eventID)  { return (AlarmListViewItem*)EventListViewBase::getEntry(eventID); }
00098         AlarmListViewItem*     currentItem() const    { return (AlarmListViewItem*)EventListViewBase::currentItem(); }
00099         AlarmListViewItem*     firstChild() const     { return (AlarmListViewItem*)EventListViewBase::firstChild(); }
00100         AlarmListViewItem*     selectedItem() const   { return (AlarmListViewItem*)EventListViewBase::selectedItem(); }
00101         virtual void           setSelected(TQListViewItem* item, bool selected)      { EventListViewBase::setSelected(item, selected); }
00102         virtual void           setSelected(AlarmListViewItem* item, bool selected)  { EventListViewBase::setSelected(item, selected); }
00103         virtual InstanceList   instances()            { return mInstanceList; }
00104 
00105     protected:
00106         virtual void           populate();
00107         EventListViewItemBase* createItem(const KAEvent&);
00108         virtual TQString        whatsThisText(int column) const;
00109         virtual bool           shouldShowEvent(const KAEvent& e) const  { return mShowExpired || !e.expired(); }
00110         AlarmListViewItem*     addEntry(const KAEvent& e, bool setSize = false)
00111                                        { return addEntry(e, TQDateTime::currentDateTime(), setSize); }
00112         AlarmListViewItem*     updateEntry(AlarmListViewItem* item, const KAEvent& newEvent, bool setSize = false)
00113                                        { return (AlarmListViewItem*)EventListViewBase::updateEntry(item, newEvent, setSize); }
00114         virtual void           contentsMousePressEvent(TQMouseEvent*);
00115         virtual void           contentsMouseMoveEvent(TQMouseEvent*);
00116         virtual void           contentsMouseReleaseEvent(TQMouseEvent*);
00117 
00118     private:
00119         AlarmListViewItem*     addEntry(const KAEvent&, const TQDateTime& now, bool setSize = false, bool reselect = false);
00120 
00121         static InstanceList    mInstanceList;         // all current instances of this class
00122         static bool            mDragging;
00123         int                    mColumn[COLUMN_COUNT]; // initial position of each column
00124         int                    mTimeColumnHeaderWidth;
00125         int                    mTimeToColumnHeaderWidth;
00126         AlarmListTooltip*      mTooltip;              // tooltip for showing full text of alarm messages
00127         TQPoint                 mMousePressPos;        // where the mouse left button was last pressed
00128         bool                   mMousePressed;         // true while the mouse left button is pressed
00129         bool                   mDrawMessageInColour;
00130         bool                   mShowExpired;          // true to show expired alarms
00131 };
00132 
00133 #endif // ALARMLISTVIEW_H
00134