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