korganizer

koagenda.h

00001 /*
00002     This file is part of KOrganizer.
00003     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
00004     Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019 
00020     As a special exception, permission is given to link this program
00021     with any edition of Qt, and distribute the resulting executable,
00022     without including the source code for Qt in the source distribution.
00023 */
00024 #ifndef KOAGENDA_H
00025 #define KOAGENDA_H
00026 
00027 #include "koagendaitem.h"
00028 
00029 #include <qscrollview.h>
00030 #include <qtimer.h>
00031 #include <qguardedptr.h>
00032 #include <libkcal/incidencebase.h>
00033 
00034 #include "calendarview.h"
00035 
00036 class QPopupMenu;
00037 class QTime;
00038 class QLabel;
00039 class KConfig;
00040 class KOAgenda;
00041 class KOAgendaItem;
00042 
00043 namespace KOrg {
00044   class IncidenceChangerBase;
00045 }
00046 using namespace KOrg;
00047 
00048 namespace KCal {
00049   class Event;
00050   class Todo;
00051   class Calendar;
00052   class ResourceCalendar;
00053 }
00054 using namespace KCal;
00055 
00056 class MarcusBains : public QFrame
00057 {
00058   Q_OBJECT
00059   public:
00060     MarcusBains( KOAgenda *agenda = 0, const char *name = 0 );
00061     void updateLocationRecalc( bool recalculate = false );
00062     virtual ~MarcusBains();
00063 
00064   public slots:
00065     void updateLocation();
00066 
00067   private:
00068     int todayColumn();
00069     QTimer *minutes;
00070     QLabel *mTimeBox;
00071     KOAgenda *agenda;
00072     QTime mOldTime;
00073     int mOldToday;
00074 };
00075 
00076 class KOAgenda : public QScrollView
00077 {
00078   Q_OBJECT
00079   public:
00080     KOAgenda ( int columns, int rows, int columnSize, CalendarView *calendarView,
00081                QWidget *parent=0, const char *name = 0, WFlags f = 0 );
00082 
00083     KOAgenda ( int columns, CalendarView *calendarView, QWidget *parent = 0,
00084                const char *name = 0, WFlags f = 0 );
00085     virtual ~KOAgenda();
00086 
00087     Incidence *selectedIncidence() const;
00088     QDate selectedIncidenceDate() const;
00093     const QString lastSelectedUid() const;
00094 
00095     virtual bool eventFilter ( QObject *, QEvent * );
00096 
00097     QPoint contentsToGrid ( const QPoint &pos ) const;
00098     QPoint gridToContents ( const QPoint &gpos ) const;
00099 
00100     int timeToY ( const QTime &time );
00101     QTime gyToTime ( int y );
00102 
00103     QMemArray<int> minContentsY();
00104     QMemArray<int> maxContentsY();
00105 
00106     int visibleContentsYMin();
00107     int visibleContentsYMax();
00108 
00109     void setStartTime( const QTime &startHour );
00110 
00111     KOAgendaItem *insertItem ( Incidence *incidence, const QDate &qd, int X, int YTop,
00112                                int YBottom, int itemPos, int itemCount );
00113     KOAgendaItem *insertAllDayItem ( Incidence *event, const QDate &qd, int XBegin,
00114                                      int XEnd );
00115     void insertMultiItem ( Event *event, const QDate &qd, int XBegin, int XEnd,
00116                            int YTop, int YBottom );
00117 
00122     void removeIncidence( Incidence *incidence );
00123 
00124     void changeColumns( int columns );
00125 
00126     int columns() { return mColumns; }
00127     int rows() { return mRows; }
00128 
00129     double gridSpacingX() const { return mGridSpacingX; }
00130     double gridSpacingY() const { return mGridSpacingY; }
00131 
00132 //    virtual QSizePolicy sizePolicy() const;
00133 
00134     void clear();
00135 
00137     virtual int minimumWidth() const;
00139     void updateConfig();
00140 
00141     void checkScrollBoundaries();
00142 
00143     void setHolidayMask( QMemArray<bool> * );
00144 
00145     void setDateList( const DateList &selectedDates );
00146     DateList dateList() const;
00147 
00148     void setTypeAheadReceiver( QObject * );
00149     QObject *typeAheadReceiver() const;
00150     void finishTypeAhead();
00151 
00152     void setCalendar( Calendar*cal ) { mCalendar = cal; }
00153     void setIncidenceChanger( IncidenceChangerBase *changer ) { mChanger = changer; }
00154 
00155   public slots:
00156     void scrollUp();
00157     void scrollDown();
00158 
00159     void checkScrollBoundaries( int );
00160 
00162     void deselectItem();
00163 
00164     void clearSelection();
00165 
00171     void selectItem( KOAgendaItem::GPtr );
00175     void selectItemByUID( const QString& uid );
00176     bool removeAgendaItem( KOAgendaItem::GPtr item );
00177     void showAgendaItem( KOAgendaItem::GPtr item );
00178 
00179   signals:
00180     void newEventSignal( ResourceCalendar *res, const QString &subResource );
00181     void newTimeSpanSignal( const QPoint &, const QPoint & );
00182     void newStartSelectSignal();
00183 
00184     void showIncidenceSignal( Incidence *, const QDate & );
00185     void editIncidenceSignal( Incidence *, const QDate & );
00186     void deleteIncidenceSignal( Incidence * );
00187     void showIncidencePopupSignal( Calendar *, Incidence *, const QDate &);
00188     void showNewEventPopupSignal();
00189 
00190     void itemModified( KOAgendaItem *item );
00191     void incidenceSelected( Incidence *, const QDate & );
00192     void startMultiModify( const QString & );
00193     void endMultiModify();
00194 
00195     void lowerYChanged( int );
00196     void upperYChanged( int );
00197 
00198     void startDragSignal(Incidence *);
00199     void droppedToDo( Todo*todo, const QPoint &gpos, bool allDay );
00200 
00201     void enableAgendaUpdate( bool enable );
00202     void zoomView( const int delta, const QPoint &pos, const Qt::Orientation );
00203 
00204     void mousePosSignal(const QPoint &pos);
00205     void enterAgenda();
00206     void leaveAgenda();
00207 
00208     void gridSpacingYChanged( double );
00209 
00210   private:
00211     enum MouseActionType { NOP, MOVE, SELECT,
00212                            RESIZETOP, RESIZEBOTTOM, RESIZELEFT, RESIZERIGHT };
00213 
00214   protected:
00215     void drawContents( QPainter *p, int cx, int cy, int cw, int ch );
00216     int columnWidth( int column );
00217     virtual void resizeEvent ( QResizeEvent * );
00218 
00220     virtual bool eventFilter_mouse ( QObject *, QMouseEvent * );
00221 #ifndef QT_NO_WHEELEVENT
00222 
00223     virtual bool eventFilter_wheel ( QObject *, QWheelEvent * );
00224 #endif
00225 
00226     virtual bool eventFilter_key ( QObject *, QKeyEvent * );
00227 
00229     virtual bool eventFilter_drag( QObject *, QDropEvent * );
00230 
00237     MouseActionType isInResizeArea( bool horizontal, const QPoint &pos, KOAgendaItem::GPtr item );
00240     bool ptInSelection( QPoint gpos ) const;
00241 
00242 
00244     void startSelectAction( const QPoint &viewportPos );
00245 
00247     void performSelectAction( const QPoint &viewportPos );
00248 
00250     void endSelectAction( const QPoint &viewportPos );
00251 
00253     void startItemAction(const QPoint& viewportPos);
00254 
00256     void performItemAction(const QPoint& viewportPos);
00257 
00259     void endItemAction();
00260 
00262     void setNoActionCursor( KOAgendaItem::GPtr moveItem, const QPoint &viewportPos );
00267     void setActionCursor( int actionType, bool acting=false );
00268 
00270     double calcSubCellWidth( KOAgendaItem::GPtr item );
00272     void placeAgendaItem( KOAgendaItem::GPtr item, double subCellWidth );
00274     void placeSubCells( KOAgendaItem::GPtr placeItem );
00276     void adjustItemPosition( KOAgendaItem::GPtr item );
00277 
00281     void keyPressEvent( QKeyEvent * );
00282 
00283     void calculateWorkingHours();
00284 
00285     virtual void contentsMousePressEvent ( QMouseEvent * );
00286 
00287     void emitNewEventForSelection();
00288 
00289   protected slots:
00291     void deleteItemsToDelete();
00296     void resizeAllContents();
00297 
00298   private:
00299     void init();
00300     void marcus_bains();
00301     bool mAllDayMode;
00302 
00303     // We need the calendar for drag'n'drop and for paint the ResourceColor
00304     Calendar *mCalendar;
00305 
00306     // Width and height of agenda cells. mDesiredGridSpacingY is the height
00307     // set in the config. The actual height might be larger since otherwise
00308     // more than 24 hours might be displayed.
00309     double mGridSpacingX;
00310     double mGridSpacingY;
00311     double mDesiredGridSpacingY;
00312 
00313     // size of border, where mouse action will resize the KOAgendaItem
00314     int mResizeBorderWidth;
00315 
00316     // size of border, where mouse mve will cause a scroll of the agenda
00317     int mScrollBorderWidth;
00318     int mScrollDelay;
00319     int mScrollOffset;
00320 
00321     QTimer mScrollUpTimer;
00322     QTimer mScrollDownTimer;
00323 
00324     // Number of Columns/Rows of agenda grid
00325     int mColumns;
00326     int mRows;
00327 
00328     // Cells to store Move and Resize coordiantes while performing the action
00329     QPoint mStartCell;
00330     QPoint mEndCell;
00331 
00332     // Working Hour coordiantes
00333     bool mWorkingHoursEnable;
00334     QMemArray<bool> *mHolidayMask;
00335     int mWorkingHoursYTop;
00336     int mWorkingHoursYBottom;
00337 
00338     // Selection
00339     bool mHasSelection;
00340     QPoint mSelectionStartPoint;
00341     QPoint mSelectionStartCell;
00342     QPoint mSelectionEndCell;
00343 
00344     // List of dates to be displayed
00345     DateList mSelectedDates;
00346 
00347     // The KOAgendaItem, which has been right-clicked last
00348     KOAgendaItem::GPtr mClickedItem;
00349 
00350     // The KOAgendaItem, which is being moved/resized
00351     KOAgendaItem::GPtr mActionItem;
00352     QPair<ResourceCalendar *, QString> mResPair;
00353 
00354     // Currently selected item
00355     KOAgendaItem::GPtr mSelectedItem;
00356     // Uid of the last selected item. Used for reselecting in situations
00357     // where the selected item points to a no longer valid incidence, for
00358     // example during resource reload.
00359     QString mSelectedUid;
00360 
00361     // The Marcus Bains Line widget.
00362     MarcusBains *mMarcusBains;
00363 
00364     MouseActionType mActionType;
00365 
00366     bool mItemMoved;
00367 
00368     // List of all Items contained in agenda
00369     QValueList<KOAgendaItem::GPtr > mItems;
00370     QValueList<KOAgendaItem::GPtr > mItemsToDelete;
00371 
00372     QPopupMenu *mItemPopup; // Right mouse button popup menu for KOAgendaItems
00373 
00374     int mOldLowerScrollValue;
00375     int mOldUpperScrollValue;
00376 
00377     bool mTypeAhead;
00378     QObject *mTypeAheadReceiver;
00379     QPtrList<QEvent> mTypeAheadEvents;
00380 
00381     bool mReturnPressed;
00382     KOrg::IncidenceChangerBase *mChanger;
00383 
00384     CalendarView *mCalendarView;
00385 };
00386 
00387 #endif // KOAGENDA_H
KDE Home | KDE Accessibility Home | Description of Access Keys