korganizer

komonthview.h

00001 /*
00002     This file is part of KOrganizer.
00003 
00004     Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
00005     Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00006 
00007     This program is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020 
00021     As a special exception, permission is given to link this program
00022     with any edition of TQt, and distribute the resulting executable,
00023     without including the source code for TQt in the source distribution.
00024 */
00025 
00026 #ifndef _KOMONTHVIEW_H
00027 #define _KOMONTHVIEW_H
00028 
00029 #include <tqlistbox.h>
00030 #include <tqptrvector.h>
00031 #include <tqtooltip.h>
00032 #include "koeventview.h"
00033 
00034 class KNoScrollListBox;
00035 
00036 class KOMonthCellToolTip : public TQToolTip
00037 {
00038   public:
00039     KOMonthCellToolTip (TQWidget* parent, Calendar *calendar, const TQDate &date, KNoScrollListBox* lv );
00040 
00041   protected:
00042     void maybeTip( const TQPoint & pos);
00043 
00044   private:
00045     Calendar *mCalendar;
00046     TQDate mDate;
00047     KNoScrollListBox* eventlist;
00048 };
00049 
00050 
00051 class KNoScrollListBox: public TQListBox
00052 {
00053     Q_OBJECT
00054   
00055   public:
00056     KNoScrollListBox(TQWidget *parent=0, const char *name=0);
00057     ~KNoScrollListBox() {}
00058 
00059     void setBackground( bool primary, bool workday );
00060 
00061   signals:
00062     void shiftDown();
00063     void shiftUp();
00064     void rightClick();
00065 
00066   protected slots:
00067     void keyPressEvent(TQKeyEvent *);
00068     void keyReleaseEvent(TQKeyEvent *);
00069     void mousePressEvent(TQMouseEvent *);
00070     void resizeEvent(TQResizeEvent *);
00071     void contentsMouseDoubleClickEvent( TQMouseEvent * e );
00072 
00073   private:
00074     bool mSqueezing;
00075 };
00076 
00077 
00078 class MonthViewItem: public TQListBoxItem
00079 {
00080   public:
00081     MonthViewItem( Incidence *, const TQDateTime &qd, const TQString & title );
00082 
00083     void setEvent(bool on) { mEvent = on; }
00084     void setTodo(bool on)  { mTodo  = on; }
00085     void setTodoDone(bool on) { mTodoDone = on; }
00086     void setRecur(bool on) { mRecur = on; }
00087     void setAlarm(bool on) { mAlarm = on; }
00088     void setReply(bool on) { mReply = on; }
00089 
00090     void setPalette(const TQPalette &p) { mPalette = p; }
00091     TQPalette palette() const { return mPalette; }
00092 
00093     Incidence *incidence() const { return mIncidence; }
00094     TQDateTime incidenceDateTime() { return mDateTime; }
00095 
00096     void setResourceColor( TQColor& color ) { mResourceColor = color; }
00097     TQColor &resourceColor() { return mResourceColor; }
00098   protected:
00099     virtual void paint(TQPainter *);
00100     virtual int height(const TQListBox *) const;
00101     virtual int width(const TQListBox *) const;
00102     //Color of the resource
00103     TQColor mResourceColor;
00104   private:
00105     bool mEvent;
00106     bool mTodo;
00107     bool mTodoDone;
00108     bool mRecur;
00109     bool mAlarm;
00110     bool mReply;
00111 
00112     TQPixmap mEventPixmap;
00113     TQPixmap mBirthdayPixmap;
00114     TQPixmap mAnniversaryPixmap;
00115     TQPixmap mTodoPixmap;
00116     TQPixmap mTodoDonePixmap;
00117     TQPixmap mAlarmPixmap;
00118     TQPixmap mRecurPixmap;
00119     TQPixmap mReplyPixmap;
00120 
00121     TQPalette mPalette;
00122     TQDateTime mDateTime;
00123 
00124     Incidence *mIncidence;
00125     TQColor catColor() const;
00126 };
00127 
00128 
00129 class KOMonthView;
00130 
00135 class MonthViewCell : public TQWidget
00136 {
00137     Q_OBJECT
00138   
00139   public:
00140     class CreateItemVisitor;
00141     MonthViewCell( KOMonthView * );
00142 
00144     void setDate( const TQDate & );
00146     TQDate date() const;
00147 
00149     KOMonthView *monthView() { return mMonthView; }
00150 
00158     void setPrimary( bool primary );
00162     bool isPrimary() const;
00163 
00165     void setHoliday( bool );
00171     void setHolidayString( const TQString &name );
00172 
00173     void updateCell();
00181     void addIncidence( Incidence *incidence, MonthViewCell::CreateItemVisitor&v, int multiDay = 0 );
00186     void removeIncidence( Incidence * );
00187 
00188     void updateConfig();
00189 
00190     void enableScrollBars( bool );
00191 
00192     Incidence *selectedIncidence();
00193     TQDate selectedIncidenceDate();
00194 
00195     void deselect();
00196 
00197   signals:
00198     void defaultAction( Incidence * );
00204     void newEventSignal( ResourceCalendar *res,const TQString &subResource,
00205                          const TQDate &date );
00206 
00207   public slots:
00208     void select();
00209 
00210   protected:
00211     void setFrameWidth();
00212     void resizeEvent( TQResizeEvent * );
00213 
00214   protected slots:
00215     void defaultAction( TQListBoxItem * );
00216     void contextMenu( TQListBoxItem * );
00217 
00218   private:
00219     KOMonthView *mMonthView;
00220 
00221     TQDate mDate;
00222     bool mPrimary;
00223     bool mHoliday;
00224     TQString mHolidayString;
00225 
00226     TQLabel *mLabel;
00227     KNoScrollListBox *mItemList;
00228 
00229     bool isSelected;
00230 
00231     TQSize mLabelSize;
00232 //    TQPalette mOriginalPalette;
00233     TQPalette mHolidayPalette;
00234     TQPalette mStandardPalette;
00235     TQPalette mTodayPalette;
00236 };
00237 
00245 class KOMonthView: public KOEventView
00246 {
00247     Q_OBJECT
00248   
00249   public:
00250     KOMonthView(Calendar *cal, TQWidget *parent = 0, const char *name = 0 );
00251     ~KOMonthView();
00252 
00254     virtual int maxDatesHint();
00255 
00257     virtual int currentDateCount();
00258 
00260     virtual Incidence::List selectedIncidences();
00261 
00263     virtual DateList selectedIncidenceDates();
00264 
00265     virtual TQDateTime selectionStart();
00266 
00267     virtual TQDateTime selectionEnd();
00268 
00269     virtual bool eventDurationHint(TQDateTime &startDt, TQDateTime &endDt, bool &allDay);
00270 
00271   public slots:
00272     virtual void updateView();
00273     virtual void updateConfig();
00274     virtual void showDates(const TQDate &start, const TQDate &end);
00275     virtual void showIncidences( const Incidence::List &incidenceList, const TQDate &date );
00276 
00277     void changeIncidenceDisplay(Incidence *, int);
00278     void changeIncidenceDisplayAdded(Incidence *, MonthViewCell::CreateItemVisitor&);
00279 
00280     void clearSelection();
00281 
00282     void showEventContextMenu( Calendar *, Incidence *, const TQDate & );
00283     void showGeneralContextMenu();
00284 
00285     void setSelectedCell( MonthViewCell * );
00286 
00287   protected slots:
00288     void processSelectionChange();
00289 
00290   protected:
00291     void resizeEvent(TQResizeEvent *);
00292 
00293     void viewChanged();
00294     void updateDayLabels();
00295 
00296   private:
00297     void showLabel( bool show );
00298       
00299     class GetDateVisitor;
00300     int mDaysPerWeek;
00301     int mNumWeeks;
00302     int mNumCells;
00303     int mWeekStartDay;
00304 
00305     TQPtrVector<MonthViewCell> mCells;
00306     TQMap<TQDate,MonthViewCell *> mDateToCell;
00307     TQPtrVector<TQLabel> mDayLabels;
00308 
00309     bool mShortDayLabels;
00310     int mWidthLongDayLabel;
00311 
00312     TQDate mStartDate;
00313     TQDate mSelectedDate;
00314 
00315     MonthViewCell *mSelectedCell;
00316 
00317     KOEventPopupMenu *mEventContextMenu;
00318     TQLabel *mLabel;
00319 };
00320 
00321 #endif