korganizer

komonthview.h
1 /*
2  This file is part of KOrganizer.
3 
4  Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
5  Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 
21  As a special exception, permission is given to link this program
22  with any edition of TQt, and distribute the resulting executable,
23  without including the source code for TQt in the source distribution.
24 */
25 
26 #ifndef _KOMONTHVIEW_H
27 #define _KOMONTHVIEW_H
28 
29 #include <tqlistbox.h>
30 #include <tqptrvector.h>
31 #include <tqtooltip.h>
32 #include "koeventview.h"
33 
34 class KNoScrollListBox;
35 class MonthViewCell;
36 
37 class KOMonthCellToolTip : public TQToolTip
38 {
39  public:
40  KOMonthCellToolTip (TQWidget* parent, Calendar *calendar, const TQDate &date, KNoScrollListBox* lv, MonthViewCell* cl);
41 
42  protected:
43  void maybeTip( const TQPoint & pos);
44 
45  private:
46  Calendar *mCalendar;
47  TQDate mDate;
48  KNoScrollListBox* eventlist;
49  MonthViewCell* cell;
50 };
51 
52 
53 class KNoScrollListBox: public TQListBox
54 {
55  Q_OBJECT
56 
57  public:
58  KNoScrollListBox(TQWidget *parent=0, const char *name=0);
59  ~KNoScrollListBox() {}
60 
61  void setBackground( bool primary, bool workday );
62 
63  signals:
64  void shiftDown();
65  void shiftUp();
66  void rightClick();
67 
68  protected slots:
69  void keyPressEvent(TQKeyEvent *);
70  void keyReleaseEvent(TQKeyEvent *);
71  void mousePressEvent(TQMouseEvent *);
72  void resizeEvent(TQResizeEvent *);
73  void contentsMouseDoubleClickEvent( TQMouseEvent * e );
74 
75  private:
76  bool mSqueezing;
77 };
78 
79 
80 class MonthViewItem: public TQListBoxItem
81 {
82  public:
83  MonthViewItem( Incidence *, const TQDateTime &qd, const TQString & title );
84 
85  void setEvent(bool on) { mEvent = on; }
86  void setTodo(bool on) { mTodo = on; }
87  void setTodoDone(bool on) { mTodoDone = on; }
88  void setRecur(bool on) { mRecur = on; }
89  void setAlarm(bool on) { mAlarm = on; }
90  void setReply(bool on) { mReply = on; }
91 
92  void setPalette(const TQPalette &p) { mPalette = p; }
93  TQPalette palette() const { return mPalette; }
94 
95  Incidence *incidence() const { return mIncidence; }
96  TQDateTime incidenceDateTime() { return mDateTime; }
97 
98  void setResourceColor( TQColor& color ) { mResourceColor = color; }
99  TQColor &resourceColor() { return mResourceColor; }
100  protected:
101  virtual void paint(TQPainter *);
102  virtual int height(const TQListBox *) const;
103  virtual int width(const TQListBox *) const;
104  //Color of the resource
105  TQColor mResourceColor;
106  private:
107  bool mEvent;
108  bool mTodo;
109  bool mTodoDone;
110  bool mRecur;
111  bool mAlarm;
112  bool mReply;
113 
114  TQPixmap mEventPixmap;
115  TQPixmap mBirthdayPixmap;
116  TQPixmap mAnniversaryPixmap;
117  TQPixmap mTodoPixmap;
118  TQPixmap mTodoDonePixmap;
119  TQPixmap mAlarmPixmap;
120  TQPixmap mRecurPixmap;
121  TQPixmap mReplyPixmap;
122 
123  TQPalette mPalette;
124  TQDateTime mDateTime;
125 
126  Incidence *mIncidence;
127  TQColor catColor() const;
128 };
129 
130 
131 class KOMonthView;
132 
137 class MonthViewCell : public TQWidget
138 {
139  Q_OBJECT
140 
141  public:
142  class CreateItemVisitor;
144 
145  TQString holidayString( ) { return mHolidayString; }
146 
148  void setDate( const TQDate & );
150  TQDate date() const;
151 
153  KOMonthView *monthView() { return mMonthView; }
154 
162  void setPrimary( bool primary );
166  bool isPrimary() const;
167 
169  void setHoliday( bool );
175  void setHolidayString( const TQString &name );
176 
177  void updateCell();
185  void addIncidence( Incidence *incidence, MonthViewCell::CreateItemVisitor&v, int multiDay = 0 );
190  void removeIncidence( Incidence * );
191 
192  void updateConfig();
193 
194  void enableScrollBars( bool );
195 
196  Incidence *selectedIncidence();
197  TQDate selectedIncidenceDate();
198 
199  void deselect();
200 
201  signals:
202  void defaultAction( Incidence * );
208  void newEventSignal( ResourceCalendar *res,const TQString &subResource,
209  const TQDate &date );
210 
211  public slots:
212  void select();
213 
214  protected:
215  void setFrameWidth();
216  void resizeEvent( TQResizeEvent * );
217 
218  protected slots:
219  void defaultAction( TQListBoxItem * );
220  void contextMenu( TQListBoxItem * );
221 
222  private:
223  KOMonthView *mMonthView;
224 
225  TQDate mDate;
226  bool mPrimary;
227  bool mHoliday;
228  TQString mHolidayString;
229 
230  TQLabel *mLabel;
231  KNoScrollListBox *mItemList;
232 
233  bool isSelected;
234 
235  TQSize mLabelSize;
236 // TQPalette mOriginalPalette;
237  TQPalette mHolidayPalette;
238  TQPalette mStandardPalette;
239  TQPalette mTodayPalette;
240 };
241 
250 {
251  Q_OBJECT
252 
253  public:
254  KOMonthView(Calendar *cal, TQWidget *parent = 0, const char *name = 0 );
255  ~KOMonthView();
256 
258  virtual int maxDatesHint();
259 
261  virtual int currentDateCount();
262 
265 
268 
269  virtual TQDateTime selectionStart();
270 
271  virtual TQDateTime selectionEnd();
272 
273  virtual bool eventDurationHint(TQDateTime &startDt, TQDateTime &endDt, bool &allDay);
274 
275  public slots:
276  virtual void updateView();
277  virtual void updateConfig();
278  virtual void showDates(const TQDate &start, const TQDate &end);
279  virtual void showIncidences( const Incidence::List &incidenceList, const TQDate &date );
280 
281  void changeIncidenceDisplay(Incidence *, int);
282  void changeIncidenceDisplayAdded(Incidence *, MonthViewCell::CreateItemVisitor&);
283 
284  void clearSelection();
285 
286  void showEventContextMenu( Calendar *, Incidence *, const TQDate & );
287  void showGeneralContextMenu();
288 
289  void setSelectedCell( MonthViewCell * );
290 
291  protected slots:
292  void processSelectionChange();
293 
294  protected:
295  void resizeEvent(TQResizeEvent *);
296 
297  void viewChanged();
298  void updateDayLabels();
299 
300  private:
301  void showLabel( bool show );
302 
303  class GetDateVisitor;
304  int mDaysPerWeek;
305  int mNumWeeks;
306  int mNumCells;
307  int mWeekStartDay;
308 
309  TQPtrVector<MonthViewCell> mCells;
310  TQMap<TQDate,MonthViewCell *> mDateToCell;
311  TQPtrVector<TQLabel> mDayLabels;
312 
313  bool mShortDayLabels;
314  int mWidthLongDayLabel;
315 
316  TQDate mStartDate;
317  TQDate mSelectedDate;
318 
319  MonthViewCell *mSelectedCell;
320 
321  KOEventPopupMenu *mEventContextMenu;
322  TQLabel *mLabel;
323 };
324 
325 #endif