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