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