korganizer

koagendaitem.h
1 /*
2  This file is part of KOrganizer.
3 
4  Copyright (c) 2000,2001,2003 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 #ifndef KOAGENDAITEM_H
26 #define KOAGENDAITEM_H
27 
28 #include "cellitem.h"
29 
30 #include <tqdatetime.h>
31 
32 class TQToolTipGroup;
33 class TQDragEnterEvent;
34 class TQDropEvent;
35 
36 namespace KCal {
37 class Calendar;
38 class Incidence;
39 }
40 using namespace KCal;
41 class KOAgendaItem;
42 
43 struct MultiItemInfo
44 {
45  int mStartCellXLeft, mStartCellXRight;
46  int mStartCellYTop, mStartCellYBottom;
47  KOAgendaItem *mFirstMultiItem;
48  KOAgendaItem *mPrevMultiItem;
49  KOAgendaItem *mNextMultiItem;
50  KOAgendaItem *mLastMultiItem;
51 };
52 
53 /*
54  The KOAgendaItem has to make sure that it receives all mouse events, which are
55  to be used for dragging and resizing. That means it has to be installed as
56  eventfiler for its children, if it has children, and it has to pass mouse
57  events from the cildren to itself. See eventFilter().
58 
59 
60  Some comments on the movement of multi-day items:
61  Basically, the agenda items are arranged in two implicit double-linked lists.
62  The mMultiItemInfo works like before to describe the currently viewed
63  multi-item.
64  When moving, new events might need to be added to the beginning or the end of
65  the multi-item sequence, or events might need to be hidden. I cannot just
66  delete this items, since I have to restore/show them if the move is reset
67  (i.e. if a drag started). So internally, I keep another doubly-linked list
68  which is longer than the one defined by mMultiItemInfo, but includes the
69  multi-item sequence, too.
70 
71  The mStartMoveInfo stores the first and last item of the multi-item sequence
72  when the move started. The prev and next members of mStartMoveInfo are used
73  for that longer sequence including all (shown and hidden) items.
74 */
75 class KOAgendaItem : public TQWidget, public KOrg::CellItem
76 {
77  TQ_OBJECT
78 
79  public:
80  KOAgendaItem( Calendar *calendar, Incidence *incidence, const TQDate &qd,
81  TQWidget *parent,
82  int itemPos, int itemCount,
83  const char *name = 0, WFlags f = 0 );
84 
85  int cellXLeft() const { return mCellXLeft; }
86  int cellXRight() const { return mCellXRight; }
87  int cellYTop() const { return mCellYTop; }
88  int cellYBottom() const { return mCellYBottom; }
89  int cellHeight() const;
90  int cellWidth() const;
91 
92  int itemPos() const { return mItemPos; }
93  int itemCount() const { return mItemCount; }
94 
95  void setCellXY(int X, int YTop, int YBottom);
96  void setCellY(int YTop, int YBottom);
97  void setCellX(int XLeft, int XRight);
98  void setCellXRight(int xright);
99 
101  void startMove();
103  void resetMove();
105  void endMove();
106 
107  void moveRelative(int dx,int dy);
108  void expandTop(int dy);
109  void expandBottom(int dy);
110  void expandLeft(int dx);
111  void expandRight(int dx);
112 
113  bool isMultiItem();
114  KOAgendaItem *prevMoveItem() const { return (mStartMoveInfo)?(mStartMoveInfo->mPrevMultiItem):0; }
115  KOAgendaItem *nextMoveItem() const { return (mStartMoveInfo)?(mStartMoveInfo->mNextMultiItem):0; }
116  MultiItemInfo *moveInfo() const { return mStartMoveInfo; }
117  void setMultiItem(KOAgendaItem *first,KOAgendaItem *prev,
118  KOAgendaItem *next, KOAgendaItem *last);
119  KOAgendaItem *prependMoveItem(KOAgendaItem*);
120  KOAgendaItem *appendMoveItem(KOAgendaItem*);
121  KOAgendaItem *removeMoveItem(KOAgendaItem*);
122  KOAgendaItem *firstMultiItem() const { return (mMultiItemInfo)?(mMultiItemInfo->mFirstMultiItem):0; }
123  KOAgendaItem *prevMultiItem() const { return (mMultiItemInfo)?(mMultiItemInfo->mPrevMultiItem):0; }
124  KOAgendaItem *nextMultiItem() const { return (mMultiItemInfo)?(mMultiItemInfo->mNextMultiItem):0; }
125  KOAgendaItem *lastMultiItem() const { return (mMultiItemInfo)?(mMultiItemInfo->mLastMultiItem):0; }
126 
127  bool dissociateFromMultiItem();
128 
129  bool setIncidence( Incidence * );
130  Incidence *incidence() const { return mIncidence; }
131  TQDate itemDate() { return mDate; }
132 
134  void setItemDate( const TQDate &qd );
135 
136  void setText ( const TQString & text ) { mLabelText = text; }
137  TQString text () { return mLabelText; }
138 
139  static TQToolTipGroup *toolTipGroup();
140 
141  TQPtrList<KOAgendaItem> conflictItems();
142  void setConflictItems(TQPtrList<KOAgendaItem>);
143  void addConflictItem(KOAgendaItem *ci);
144 
145  TQString label() const;
146 
147  bool overlaps( KOrg::CellItem * ) const;
148 
149  void setResourceColor( const TQColor& color ) { mResourceColor = color; }
150  TQColor resourceColor() {return mResourceColor;}
151  signals:
152  void removeAgendaItem( KOAgendaItem* );
153  void showAgendaItem( KOAgendaItem* );
154 
155  public slots:
156  void updateIcons();
157  void select(bool=true);
158  void addAttendee( const TQString & );
159 
160  protected:
161  void dragEnterEvent(TQDragEnterEvent *e);
162  void dropEvent(TQDropEvent *e);
163  void paintEvent(TQPaintEvent *e);
164  void paintFrame(TQPainter *p, const TQColor &color);
165  void paintEventIcon(TQPainter *p, int &x, int ft);
166  void paintTodoIcon(TQPainter *p, int &x, int ft);
167  void paintAlarmIcon(TQPainter *p, int &x, int ft);
168 
169  // paint all visible icons
170  void paintIcons(TQPainter *p, int &x, int ft);
171 
175  void startMovePrivate();
176  void resetMovePrivate();
177  void endMovePrivate();
178 
179 
180  private:
181  int mCellXLeft, mCellXRight;
182  int mCellYTop, mCellYBottom;
183 
184  Calendar *mCalendar;
185  Incidence *mIncidence; // corresponding event or todo
186  TQDate mDate; //date this events occurs (for recurrence)
187  TQString mLabelText;
188  bool mIconAlarm, mIconRecur, mIconReadonly;
189  bool mIconReply, mIconGroup, mIconGroupTentative;
190  bool mIconOrganizer, mSpecialEvent;
191 
192  // For incidences that expand through more than 1 day
193  // Will be 1 for single day incidences
194  int mItemPos;
195  int mItemCount;
196 
197  // Multi item pointers
198  MultiItemInfo* mMultiItemInfo;
199  protected:
200  // Variables to remember start position
201  MultiItemInfo* mStartMoveInfo;
202  //Color of the resource
203  TQColor mResourceColor;
204  private:
205  static TQToolTipGroup *mToolTipGroup;
206 
207  bool mSelected;
208  TQPtrList<KOAgendaItem> mConflictItems;
209 
210  static TQPixmap *alarmPxmp;
211  static TQPixmap *recurPxmp;
212  static TQPixmap *readonlyPxmp;
213  static TQPixmap *replyPxmp;
214  static TQPixmap *groupPxmp;
215  static TQPixmap *groupPxmpTentative;
216  static TQPixmap *organizerPxmp;
217 };
218 
219 #endif