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 Qt, and distribute the resulting executable,
00023     without including the source code for Qt 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   public:
00079     KOAgendaItem( Calendar *calendar, Incidence *incidence, const TQDate &qd,
00080                   TQWidget *parent,
00081                   int itemPos, int itemCount,
00082                   const char *name = 0, WFlags f = 0 );
00083 
00084     int cellXLeft() const { return mCellXLeft; }
00085     int cellXRight() const { return mCellXRight; }
00086     int cellYTop() const { return mCellYTop; }
00087     int cellYBottom() const { return mCellYBottom; }
00088     int cellHeight() const;
00089     int cellWidth() const;
00090 
00091     int itemPos() const { return mItemPos; }
00092     int itemCount() const { return mItemCount; }
00093 
00094     void setCellXY(int X, int YTop, int YBottom);
00095     void setCellY(int YTop, int YBottom);
00096     void setCellX(int XLeft, int XRight);
00097     void setCellXRight(int xright);
00098 
00100     void startMove();
00102     void resetMove();
00104     void endMove();
00105 
00106     void moveRelative(int dx,int dy);
00107     void expandTop(int dy);
00108     void expandBottom(int dy);
00109     void expandLeft(int dx);
00110     void expandRight(int dx);
00111 
00112     bool isMultiItem();
00113     KOAgendaItem *prevMoveItem() const { return (mStartMoveInfo)?(mStartMoveInfo->mPrevMultiItem):0; }
00114     KOAgendaItem *nextMoveItem() const { return (mStartMoveInfo)?(mStartMoveInfo->mNextMultiItem):0; }
00115     MultiItemInfo *moveInfo() const { return mStartMoveInfo; }
00116     void setMultiItem(KOAgendaItem *first,KOAgendaItem *prev,
00117                       KOAgendaItem *next, KOAgendaItem *last);
00118     KOAgendaItem *prependMoveItem(KOAgendaItem*);
00119     KOAgendaItem *appendMoveItem(KOAgendaItem*);
00120     KOAgendaItem *removeMoveItem(KOAgendaItem*);
00121     KOAgendaItem *firstMultiItem() const { return (mMultiItemInfo)?(mMultiItemInfo->mFirstMultiItem):0; }
00122     KOAgendaItem *prevMultiItem() const { return (mMultiItemInfo)?(mMultiItemInfo->mPrevMultiItem):0; }
00123     KOAgendaItem *nextMultiItem() const { return (mMultiItemInfo)?(mMultiItemInfo->mNextMultiItem):0; }
00124     KOAgendaItem *lastMultiItem() const { return (mMultiItemInfo)?(mMultiItemInfo->mLastMultiItem):0; }
00125 
00126     bool dissociateFromMultiItem();
00127 
00128     bool setIncidence( Incidence * );
00129     Incidence *incidence() const { return mIncidence; }
00130     TQDate itemDate() { return mDate; }
00131 
00133     void setItemDate( const TQDate &qd );
00134 
00135     void setText ( const TQString & text ) { mLabelText = text; }
00136     TQString text () { return mLabelText; }
00137 
00138     static TQToolTipGroup *toolTipGroup();
00139 
00140     TQPtrList<KOAgendaItem> conflictItems();
00141     void setConflictItems(TQPtrList<KOAgendaItem>);
00142     void addConflictItem(KOAgendaItem *ci);
00143 
00144     TQString label() const;
00145 
00146     bool overlaps( KOrg::CellItem * ) const;
00147 
00148     void setResourceColor( const TQColor& color ) { mResourceColor = color; }
00149     TQColor resourceColor() {return mResourceColor;}
00150   signals:
00151     void removeAgendaItem( KOAgendaItem* );
00152     void showAgendaItem( KOAgendaItem* );
00153 
00154   public slots:
00155     void updateIcons();
00156     void select(bool=true);
00157     void addAttendee( const TQString & );
00158 
00159   protected:
00160     void dragEnterEvent(TQDragEnterEvent *e);
00161     void dropEvent(TQDropEvent *e);
00162     void paintEvent(TQPaintEvent *e);
00163     void paintFrame(TQPainter *p, const TQColor &color);
00164     void paintEventIcon(TQPainter *p, int &x, int ft);
00165     void paintTodoIcon(TQPainter *p, int &x, int ft);
00166     void paintAlarmIcon(TQPainter *p, int &x, int ft);
00167 
00168     // paint all visible icons
00169     void paintIcons(TQPainter *p, int &x, int ft);
00170 
00174     void startMovePrivate();
00175     void resetMovePrivate();
00176     void endMovePrivate();
00177 
00178 
00179   private:
00180     int mCellXLeft, mCellXRight;
00181     int mCellYTop, mCellYBottom;
00182 
00183     Calendar *mCalendar;
00184     Incidence *mIncidence; // corresponding event or todo
00185     TQDate mDate; //date this events occurs (for recurrence)
00186     TQString mLabelText;
00187     bool mIconAlarm, mIconRecur, mIconReadonly;
00188     bool mIconReply, mIconGroup, mIconGroupTentative;
00189     bool mIconOrganizer, mSpecialEvent;
00190 
00191     // For incidences that expand through more than 1 day
00192     // Will be 1 for single day incidences
00193     int mItemPos;
00194     int mItemCount;
00195 
00196     // Multi item pointers
00197     MultiItemInfo* mMultiItemInfo;
00198   protected:
00199     // Variables to remember start position
00200     MultiItemInfo* mStartMoveInfo;
00201     //Color of the resource
00202     TQColor mResourceColor;
00203   private:
00204     static TQToolTipGroup *mToolTipGroup;
00205 
00206     bool mSelected;
00207     TQPtrList<KOAgendaItem> mConflictItems;
00208 
00209     static TQPixmap *alarmPxmp;
00210     static TQPixmap *recurPxmp;
00211     static TQPixmap *readonlyPxmp;
00212     static TQPixmap *replyPxmp;
00213     static TQPixmap *groupPxmp;
00214     static TQPixmap *groupPxmpTentative;
00215     static TQPixmap *organizerPxmp;
00216 };
00217 
00218 #endif