korganizer

koagendaitem.h

00001 /*
00002     This file is part of KOrganizer.
00003 
00004     Copyright (c) 2000,2001,2003 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 #ifndef KOAGENDAITEM_H
00026 #define KOAGENDAITEM_H
00027 
00028 #include "cellitem.h"
00029 
00030 #include <tqdatetime.h>
00031 
00032 class TQToolTipGroup;
00033 class TQDragEnterEvent;
00034 class TQDropEvent;
00035 
00036 namespace KCal {
00037 class Calendar;
00038 class Incidence;
00039 }
00040 using namespace KCal;
00041 class KOAgendaItem;
00042 
00043 struct MultiItemInfo
00044 {
00045   int mStartCellXLeft, mStartCellXRight;
00046   int mStartCellYTop, mStartCellYBottom;
00047   KOAgendaItem *mFirstMultiItem;
00048   KOAgendaItem *mPrevMultiItem;
00049   KOAgendaItem *mNextMultiItem;
00050   KOAgendaItem *mLastMultiItem;
00051 };
00052 
00053 /*
00054   The KOAgendaItem has to make sure that it receives all mouse events, which are
00055   to be used for dragging and resizing. That means it has to be installed as
00056   eventfiler for its children, if it has children, and it has to pass mouse
00057   events from the cildren to itself. See eventFilter().
00058 
00059 
00060   Some comments on the movement of multi-day items:
00061   Basically, the agenda items are arranged in two implicit double-linked lists.
00062   The mMultiItemInfo works like before to describe the currently viewed
00063   multi-item.
00064   When moving, new events might need to be added to the beginning or the end of
00065   the multi-item sequence, or events might need to be hidden. I cannot just
00066   delete this items, since I have to restore/show them if the move is reset
00067   (i.e. if a drag started). So internally, I keep another doubly-linked list
00068   which is longer than the one defined by mMultiItemInfo, but includes the
00069   multi-item sequence, too.
00070 
00071   The mStartMoveInfo stores the first and last item of the multi-item sequence
00072   when the move started. The prev and next members of mStartMoveInfo are used
00073   for that longer sequence including all (shown and hidden) items.
00074 */
00075 class KOAgendaItem : public TQWidget, public KOrg::CellItem
00076 {
00077     Q_OBJECT
00078   TQ_OBJECT
00079   public:
00080     KOAgendaItem( Calendar *calendar, Incidence *incidence, const TQDate &qd,
00081                   TQWidget *parent,
00082                   int itemPos, int itemCount,
00083                   const char *name = 0, WFlags f = 0 );
00084 
00085     int cellXLeft() const { return mCellXLeft; }
00086     int cellXRight() const { return mCellXRight; }
00087     int cellYTop() const { return mCellYTop; }
00088     int cellYBottom() const { return mCellYBottom; }
00089     int cellHeight() const;
00090     int cellWidth() const;
00091 
00092     int itemPos() const { return mItemPos; }
00093     int itemCount() const { return mItemCount; }
00094 
00095     void setCellXY(int X, int YTop, int YBottom);
00096     void setCellY(int YTop, int YBottom);
00097     void setCellX(int XLeft, int XRight);
00098     void setCellXRight(int xright);
00099 
00101     void startMove();
00103     void resetMove();
00105     void endMove();
00106 
00107     void moveRelative(int dx,int dy);
00108     void expandTop(int dy);
00109     void expandBottom(int dy);
00110     void expandLeft(int dx);
00111     void expandRight(int dx);
00112 
00113     bool isMultiItem();
00114     KOAgendaItem *prevMoveItem() const { return (mStartMoveInfo)?(mStartMoveInfo->mPrevMultiItem):0; }
00115     KOAgendaItem *nextMoveItem() const { return (mStartMoveInfo)?(mStartMoveInfo->mNextMultiItem):0; }
00116     MultiItemInfo *moveInfo() const { return mStartMoveInfo; }
00117     void setMultiItem(KOAgendaItem *first,KOAgendaItem *prev,
00118                       KOAgendaItem *next, KOAgendaItem *last);
00119     KOAgendaItem *prependMoveItem(KOAgendaItem*);
00120     KOAgendaItem *appendMoveItem(KOAgendaItem*);
00121     KOAgendaItem *removeMoveItem(KOAgendaItem*);
00122     KOAgendaItem *firstMultiItem() const { return (mMultiItemInfo)?(mMultiItemInfo->mFirstMultiItem):0; }
00123     KOAgendaItem *prevMultiItem() const { return (mMultiItemInfo)?(mMultiItemInfo->mPrevMultiItem):0; }
00124     KOAgendaItem *nextMultiItem() const { return (mMultiItemInfo)?(mMultiItemInfo->mNextMultiItem):0; }
00125     KOAgendaItem *lastMultiItem() const { return (mMultiItemInfo)?(mMultiItemInfo->mLastMultiItem):0; }
00126 
00127     bool dissociateFromMultiItem();
00128 
00129     bool setIncidence( Incidence * );
00130     Incidence *incidence() const { return mIncidence; }
00131     TQDate itemDate() { return mDate; }
00132 
00134     void setItemDate( const TQDate &qd );
00135 
00136     void setText ( const TQString & text ) { mLabelText = text; }
00137     TQString text () { return mLabelText; }
00138 
00139     static TQToolTipGroup *toolTipGroup();
00140 
00141     TQPtrList<KOAgendaItem> conflictItems();
00142     void setConflictItems(TQPtrList<KOAgendaItem>);
00143     void addConflictItem(KOAgendaItem *ci);
00144 
00145     TQString label() const;
00146 
00147     bool overlaps( KOrg::CellItem * ) const;
00148 
00149     void setResourceColor( const TQColor& color ) { mResourceColor = color; }
00150     TQColor resourceColor() {return mResourceColor;}
00151   signals:
00152     void removeAgendaItem( KOAgendaItem* );
00153     void showAgendaItem( KOAgendaItem* );
00154 
00155   public slots:
00156     void updateIcons();
00157     void select(bool=true);
00158     void addAttendee( const TQString & );
00159 
00160   protected:
00161     void dragEnterEvent(TQDragEnterEvent *e);
00162     void dropEvent(TQDropEvent *e);
00163     void paintEvent(TQPaintEvent *e);
00164     void paintFrame(TQPainter *p, const TQColor &color);
00165     void paintEventIcon(TQPainter *p, int &x, int ft);
00166     void paintTodoIcon(TQPainter *p, int &x, int ft);
00167     void paintAlarmIcon(TQPainter *p, int &x, int ft);
00168 
00169     // paint all visible icons
00170     void paintIcons(TQPainter *p, int &x, int ft);
00171 
00175     void startMovePrivate();
00176     void resetMovePrivate();
00177     void endMovePrivate();
00178 
00179 
00180   private:
00181     int mCellXLeft, mCellXRight;
00182     int mCellYTop, mCellYBottom;
00183 
00184     Calendar *mCalendar;
00185     Incidence *mIncidence; // corresponding event or todo
00186     TQDate mDate; //date this events occurs (for recurrence)
00187     TQString mLabelText;
00188     bool mIconAlarm, mIconRecur, mIconReadonly;
00189     bool mIconReply, mIconGroup, mIconGroupTentative;
00190     bool mIconOrganizer, mSpecialEvent;
00191 
00192     // For incidences that expand through more than 1 day
00193     // Will be 1 for single day incidences
00194     int mItemPos;
00195     int mItemCount;
00196 
00197     // Multi item pointers
00198     MultiItemInfo* mMultiItemInfo;
00199   protected:
00200     // Variables to remember start position
00201     MultiItemInfo* mStartMoveInfo;
00202     //Color of the resource
00203     TQColor mResourceColor;
00204   private:
00205     static TQToolTipGroup *mToolTipGroup;
00206 
00207     bool mSelected;
00208     TQPtrList<KOAgendaItem> mConflictItems;
00209 
00210     static TQPixmap *alarmPxmp;
00211     static TQPixmap *recurPxmp;
00212     static TQPixmap *readonlyPxmp;
00213     static TQPixmap *replyPxmp;
00214     static TQPixmap *groupPxmp;
00215     static TQPixmap *groupPxmpTentative;
00216     static TQPixmap *organizerPxmp;
00217 };
00218 
00219 #endif