korganizer

koagenda.h
1 /*
2  This file is part of KOrganizer.
3  Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4  Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20  As a special exception, permission is given to link this program
21  with any edition of TQt, and distribute the resulting executable,
22  without including the source code for TQt in the source distribution.
23 */
24 #ifndef KOAGENDA_H
25 #define KOAGENDA_H
26 
27 #include <tqscrollview.h>
28 #include <tqtimer.h>
29 #include <tqguardedptr.h>
30 #include <libkcal/incidencebase.h>
31 
32 #include "calendarview.h"
33 
34 class TQPopupMenu;
35 class TQTime;
36 class TQLabel;
37 class TDEConfig;
38 class KOAgenda;
39 class KOAgendaItem;
40 
41 namespace KOrg {
42  class IncidenceChangerBase;
43 }
44 using namespace KOrg;
45 
46 namespace KCal {
47  class Event;
48  class Todo;
49  class Calendar;
50 }
51 using namespace KCal;
52 
53 class MarcusBains : public TQFrame
54 {
55  TQ_OBJECT
56 
57  public:
58  MarcusBains( KOAgenda *agenda = 0, const char *name = 0 );
59  void updateLocationRecalc( bool recalculate = false );
60  virtual ~MarcusBains();
61 
62  public slots:
63  void updateLocation();
64 
65  private:
66  int todayColumn();
67  TQTimer *minutes;
68  TQLabel *mTimeBox;
69  KOAgenda *agenda;
70  TQTime mOldTime;
71  int mOldToday;
72 };
73 
74 class KOAgenda : public TQScrollView
75 {
76  TQ_OBJECT
77 
78  public:
79  KOAgenda ( int columns, int rows, int columnSize, CalendarView *calendarView,
80  TQWidget *parent=0, const char *name = 0, WFlags f = 0 );
81 
82  KOAgenda ( int columns, CalendarView *calendarView, TQWidget *parent = 0,
83  const char *name = 0, WFlags f = 0 );
84  virtual ~KOAgenda();
85 
86  Incidence *selectedIncidence() const;
87  TQDate selectedIncidenceDate() const;
92  const TQString lastSelectedUid() const;
93 
94  virtual bool eventFilter ( TQObject *, TQEvent * );
95 
96  TQPoint contentsToGrid ( const TQPoint &pos ) const;
97  TQPoint gridToContents ( const TQPoint &gpos ) const;
98 
99  int timeToY ( const TQTime &time );
100  TQTime gyToTime ( int y );
101 
102  TQMemArray<int> minContentsY();
103  TQMemArray<int> maxContentsY();
104 
105  int visibleContentsYMin();
106  int visibleContentsYMax();
107 
108  void setStartTime( const TQTime &startHour );
109 
110  KOAgendaItem *insertItem ( Incidence *incidence, const TQDate &qd, int X, int YTop,
111  int YBottom, int itemPos, int itemCount );
112  KOAgendaItem *insertAllDayItem ( Incidence *event, const TQDate &qd, int XBegin,
113  int XEnd );
114  void insertMultiItem ( Event *event, const TQDate &qd, int XBegin, int XEnd,
115  int YTop, int YBottom );
116 
121  void removeIncidence( Incidence *incidence );
122 
123  void changeColumns( int columns );
124 
125  int columns() { return mColumns; }
126  int rows() { return mRows; }
127 
128  double gridSpacingX() const { return mGridSpacingX; }
129  double gridSpacingY() const { return mGridSpacingY; }
130 
131 // virtual TQSizePolicy sizePolicy() const;
132 
133  void clear();
134 
136  virtual int minimumWidth() const;
138  void updateConfig();
139 
140  void checkScrollBoundaries();
141 
142  void setHolidayMask( TQMemArray<bool> * );
143 
144  void setDateList( const DateList &selectedDates );
145  DateList dateList() const;
146 
147  void setTypeAheadReceiver( TQObject * );
148  TQObject *typeAheadReceiver() const;
149  void finishTypeAhead();
150 
151  void setCalendar( Calendar*cal ) { mCalendar = cal; }
152  void setIncidenceChanger( IncidenceChangerBase *changer ) { mChanger = changer; }
153 
154  public slots:
155  void scrollUp();
156  void scrollDown();
157 
158  void checkScrollBoundaries( int );
159 
161  void deselectItem();
162 
163  void clearSelection();
164 
170  void selectItem( KOAgendaItem * );
174  void selectItemByUID( const TQString& uid );
175  bool removeAgendaItem( KOAgendaItem *item );
176  void showAgendaItem( KOAgendaItem *item );
177 
178  signals:
179  void newEventSignal( ResourceCalendar *res, const TQString &subResource );
180  void newTimeSpanSignal( const TQPoint &, const TQPoint & );
181  void newStartSelectSignal();
182 
183  void showIncidenceSignal( Incidence *, const TQDate & );
184  void editIncidenceSignal( Incidence *, const TQDate & );
185  void deleteIncidenceSignal( Incidence * );
186  void showIncidencePopupSignal( Calendar *, Incidence *, const TQDate &);
187  void showNewEventPopupSignal();
188 
189  void itemModified( KOAgendaItem *item );
190  void incidenceSelected( Incidence *, const TQDate & );
191  void startMultiModify( const TQString & );
192  void endMultiModify();
193 
194  void lowerYChanged( int );
195  void upperYChanged( int );
196 
197  void startDragSignal(Incidence *);
198  void droppedToDo( Todo*todo, const TQPoint &gpos, bool allDay );
199 
200  void enableAgendaUpdate( bool enable );
201  void zoomView( const int delta, const TQPoint &pos, const TQt::Orientation );
202 
203  void mousePosSignal(const TQPoint &pos);
204  void enterAgenda();
205  void leaveAgenda();
206 
207  void gridSpacingYChanged( double );
208 
209  private:
210  enum MouseActionType { NOP, MOVE, SELECT,
211  RESIZETOP, RESIZEBOTTOM, RESIZELEFT, RESIZERIGHT };
212 
213  protected:
214  void drawContents( TQPainter *p, int cx, int cy, int cw, int ch );
215  int columnWidth( int column );
216  virtual void resizeEvent ( TQResizeEvent * );
217 
219  virtual bool eventFilter_mouse ( TQObject *, TQMouseEvent * );
220 #ifndef TQT_NO_WHEELEVENT
222  virtual bool eventFilter_wheel ( TQObject *, TQWheelEvent * );
223 #endif
225  virtual bool eventFilter_key ( TQObject *, TQKeyEvent * );
226 
228  virtual bool eventFilter_drag( TQObject *, TQDropEvent * );
229 
236  MouseActionType isInResizeArea( bool horizontal, const TQPoint &pos, KOAgendaItem *item );
239  bool ptInSelection( TQPoint gpos ) const;
240 
241 
243  void startSelectAction( const TQPoint &viewportPos );
244 
246  void performSelectAction( const TQPoint &viewportPos );
247 
249  void endSelectAction( const TQPoint &viewportPos );
250 
252  void startItemAction(const TQPoint& viewportPos);
253 
255  void performItemAction(const TQPoint& viewportPos);
256 
258  void endItemAction();
259 
261  void setNoActionCursor( KOAgendaItem *moveItem, const TQPoint &viewportPos );
266  void setActionCursor( int actionType, bool acting=false );
267 
269  double calcSubCellWidth( KOAgendaItem *item );
271  void placeAgendaItem( KOAgendaItem *item, double subCellWidth );
273  void placeSubCells( KOAgendaItem *placeItem );
275  void adjustItemPosition( KOAgendaItem *item );
276 
280  void keyPressEvent( TQKeyEvent * );
281 
282  void calculateWorkingHours();
283 
284  virtual void contentsMousePressEvent ( TQMouseEvent * );
285 
286  void emitNewEventForSelection();
287 
288  protected slots:
290  void deleteItemsToDelete();
295  void resizeAllContents();
296 
297  private:
298  void init();
299  void marcus_bains();
300  bool mAllDayMode;
301 
302  // We need the calendar for drag'n'drop and for paint the ResourceColor
303  Calendar *mCalendar;
304 
305  // Width and height of agenda cells. mDesiredGridSpacingY is the height
306  // set in the config. The actual height might be larger since otherwise
307  // more than 24 hours might be displayed.
308  double mGridSpacingX;
309  double mGridSpacingY;
310  double mDesiredGridSpacingY;
311 
312  // size of border, where mouse action will resize the KOAgendaItem
313  int mResizeBorderWidth;
314 
315  // size of border, where mouse mve will cause a scroll of the agenda
316  int mScrollBorderWidth;
317  int mScrollDelay;
318  int mScrollOffset;
319 
320  TQTimer mScrollUpTimer;
321  TQTimer mScrollDownTimer;
322 
323  // Number of Columns/Rows of agenda grid
324  int mColumns;
325  int mRows;
326 
327  // Cells to store Move and Resize coordiantes while performing the action
328  TQPoint mStartCell;
329  TQPoint mEndCell;
330 
331  // Working Hour coordiantes
332  bool mWorkingHoursEnable;
333  TQMemArray<bool> *mHolidayMask;
334  int mWorkingHoursYTop;
335  int mWorkingHoursYBottom;
336 
337  // Selection
338  bool mHasSelection;
339  TQPoint mSelectionStartPoint;
340  TQPoint mSelectionStartCell;
341  TQPoint mSelectionEndCell;
342 
343  // List of dates to be displayed
344  DateList mSelectedDates;
345 
346  // The KOAgendaItem, which has been right-clicked last
347  TQGuardedPtr<KOAgendaItem> mClickedItem;
348 
349  // The KOAgendaItem, which is being moved/resized
350  TQGuardedPtr<KOAgendaItem> mActionItem;
351  TQPair<ResourceCalendar *, TQString> mResPair;
352 
353  // Currently selected item
354  TQGuardedPtr<KOAgendaItem> mSelectedItem;
355  // Uid of the last selected item. Used for reselecting in situations
356  // where the selected item points to a no longer valid incidence, for
357  // example during resource reload.
358  TQString mSelectedUid;
359 
360  // The Marcus Bains Line widget.
361  MarcusBains *mMarcusBains;
362 
363  MouseActionType mActionType;
364 
365  bool mItemMoved;
366 
367  // List of all Items contained in agenda
368  TQPtrList<KOAgendaItem> mItems;
369  TQPtrList<KOAgendaItem> mItemsToDelete;
370 
371  TQPopupMenu *mItemPopup; // Right mouse button popup menu for KOAgendaItems
372 
373  int mOldLowerScrollValue;
374  int mOldUpperScrollValue;
375 
376  bool mTypeAhead;
377  TQObject *mTypeAheadReceiver;
378  TQPtrList<TQEvent> mTypeAheadEvents;
379 
380  bool mReturnPressed;
381  KOrg::IncidenceChangerBase *mChanger;
382 
383  CalendarView *mCalendarView;
384 };
385 
386 #endif // KOAGENDA_H
This is the main calendar widget.
Definition: calendarview.h:82