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 <qscrollview.h>
00028 #include <qtimer.h>
00029 #include <qguardedptr.h>
00030 #include <libkcal/incidencebase.h>
00031 
00032 #include "calendarview.h"
00033 
00034 class QPopupMenu;
00035 class QTime;
00036 class QLabel;
00037 class KConfig;
00038 class KOAgenda;
00039 class KOAgendaItem;
00040 
00041 namespace KOrg {
00042   class IncidenceChangerBase;
00043 }
00044 using namespace KOrg;
00045 
00046 namespace KCal {
00047   class Event;
00048   class Todo;
00049   class Calendar;
00050   class ResourceCalendar;
00051 }
00052 using namespace KCal;
00053 
00054 class MarcusBains : public QFrame
00055 {
00056   Q_OBJECT
00057   public:
00058     MarcusBains( KOAgenda *agenda = 0, const char *name = 0 );
00059     void updateLocationRecalc( bool recalculate = false );
00060     virtual ~MarcusBains();
00061 
00062   public slots:
00063     void updateLocation();
00064 
00065   private:
00066     int todayColumn();
00067     QTimer *minutes;
00068     QLabel *mTimeBox;
00069     KOAgenda *agenda;
00070     QTime mOldTime;
00071     int mOldToday;
00072 };
00073 
00074 class KOAgenda : public QScrollView
00075 {
00076   Q_OBJECT
00077   public:
00078     KOAgenda ( int columns, int rows, int columnSize, CalendarView *calendarView,
00079                QWidget *parent=0, const char *name = 0, WFlags f = 0 );
00080 
00081     KOAgenda ( int columns, CalendarView *calendarView, QWidget *parent = 0,
00082                const char *name = 0, WFlags f = 0 );
00083     virtual ~KOAgenda();
00084 
00085     Incidence *selectedIncidence() const;
00086     QDate selectedIncidenceDate() const;
00091     const QString lastSelectedUid() const;
00092 
00093     virtual bool eventFilter ( QObject *, QEvent * );
00094 
00095     QPoint contentsToGrid ( const QPoint &pos ) const;
00096     QPoint gridToContents ( const QPoint &gpos ) const;
00097 
00098     int timeToY ( const QTime &time );
00099     QTime gyToTime ( int y );
00100 
00101     QMemArray<int> minContentsY();
00102     QMemArray<int> maxContentsY();
00103 
00104     int visibleContentsYMin();
00105     int visibleContentsYMax();
00106 
00107     void setStartTime( const QTime &startHour );
00108 
00109     KOAgendaItem *insertItem ( Incidence *incidence, const QDate &qd, int X, int YTop,
00110                                int YBottom );
00111     KOAgendaItem *insertAllDayItem ( Incidence *event, const QDate &qd, int XBegin,
00112                                      int XEnd );
00113     void insertMultiItem ( Event *event, const QDate &qd, int XBegin, int XEnd,
00114                            int YTop, int YBottom );
00115 
00120     void removeIncidence( Incidence *incidence );
00121 
00122     void changeColumns( int columns );
00123 
00124     int columns() { return mColumns; }
00125     int rows() { return mRows; }
00126 
00127     double gridSpacingX() const { return mGridSpacingX; }
00128     double gridSpacingY() const { return mGridSpacingY; }
00129 
00130 //    virtual QSizePolicy sizePolicy() const;
00131 
00132     void clear();
00133 
00135     virtual int minimumWidth() const;
00137     void updateConfig();
00138 
00139     void checkScrollBoundaries();
00140 
00141     void setHolidayMask( QMemArray<bool> * );
00142 
00143     void setDateList( const DateList &selectedDates );
00144     DateList dateList() const;
00145 
00146     void setTypeAheadReceiver( QObject * );
00147     QObject *typeAheadReceiver() const;
00148     void finishTypeAhead();
00149 
00150     void setCalendar( Calendar*cal ) { mCalendar = cal; }
00151     void setIncidenceChanger( IncidenceChangerBase *changer ) { mChanger = changer; }
00152 
00153   public slots:
00154     void scrollUp();
00155     void scrollDown();
00156 
00157     void checkScrollBoundaries( int );
00158 
00160     void deselectItem();
00161 
00162     void clearSelection();
00163 
00169     void selectItem( KOAgendaItem * );
00173     void selectItemByUID( const QString& uid );
00174     bool removeAgendaItem( KOAgendaItem *item );
00175     void showAgendaItem( KOAgendaItem *item );
00176 
00177   signals:
00178     void newEventSignal( ResourceCalendar *res, const QString &subResource );
00179     void newTimeSpanSignal( const QPoint &, const QPoint & );
00180     void newStartSelectSignal();
00181 
00182     void showIncidenceSignal( Incidence * );
00183     void editIncidenceSignal( Incidence * );
00184     void deleteIncidenceSignal( Incidence * );
00185     void showIncidencePopupSignal( Calendar *, Incidence *, const QDate &);
00186     void showNewEventPopupSignal();
00187 
00188     void itemModified( KOAgendaItem *item );
00189     void incidenceSelected( Incidence *, const QDate & );
00190     void startMultiModify( const QString & );
00191     void endMultiModify();
00192 
00193     void lowerYChanged( int );
00194     void upperYChanged( int );
00195 
00196     void startDragSignal(Incidence *);
00197     void droppedToDo( Todo*todo, const QPoint &gpos, bool allDay );
00198 
00199     void enableAgendaUpdate( bool enable );
00200     void zoomView( const int delta, const QPoint &pos, const Qt::Orientation );
00201 
00202     void mousePosSignal(const QPoint &pos);
00203     void enterAgenda();
00204     void leaveAgenda();
00205 
00206     void gridSpacingYChanged( double );
00207 
00208   private:
00209     enum MouseActionType { NOP, MOVE, SELECT,
00210                            RESIZETOP, RESIZEBOTTOM, RESIZELEFT, RESIZERIGHT };
00211 
00212   protected:
00213     void drawContents( QPainter *p, int cx, int cy, int cw, int ch );
00214     int columnWidth( int column );
00215     virtual void resizeEvent ( QResizeEvent * );
00216 
00218     virtual bool eventFilter_mouse ( QObject *, QMouseEvent * );
00219 #ifndef QT_NO_WHEELEVENT
00220 
00221     virtual bool eventFilter_wheel ( QObject *, QWheelEvent * );
00222 #endif
00223 
00224     virtual bool eventFilter_key ( QObject *, QKeyEvent * );
00225 
00227     virtual bool eventFilter_drag( QObject *, QDropEvent * );
00228 
00235     MouseActionType isInResizeArea( bool horizontal, const QPoint &pos, KOAgendaItem *item );
00238     bool ptInSelection( QPoint gpos ) const;
00239 
00240 
00242     void startSelectAction( const QPoint &viewportPos );
00243 
00245     void performSelectAction( const QPoint &viewportPos );
00246 
00248     void endSelectAction( const QPoint &viewportPos );
00249 
00251     void startItemAction(const QPoint& viewportPos);
00252 
00254     void performItemAction(const QPoint& viewportPos);
00255 
00257     void endItemAction();
00258 
00260     void setNoActionCursor( KOAgendaItem *moveItem, const QPoint &viewportPos );
00265     void setActionCursor( int actionType, bool acting=false );
00266 
00268     double calcSubCellWidth( KOAgendaItem *item );
00270     void placeAgendaItem( KOAgendaItem *item, double subCellWidth );
00272     void placeSubCells( KOAgendaItem *placeItem );
00274     void adjustItemPosition( KOAgendaItem *item );
00275 
00279     void keyPressEvent( QKeyEvent * );
00280 
00281     void calculateWorkingHours();
00282 
00283     virtual void contentsMousePressEvent ( QMouseEvent * );
00284 
00285     void emitNewEventForSelection();
00286 
00287   protected slots:
00289     void deleteItemsToDelete();
00294     void resizeAllContents();
00295 
00296   private:
00297     void init();
00298     void marcus_bains();
00299     bool mAllDayMode;
00300 
00301     // We need the calendar for drag'n'drop and for paint the ResourceColor
00302     Calendar *mCalendar;
00303 
00304     // Width and height of agenda cells. mDesiredGridSpacingY is the height
00305     // set in the config. The actual height might be larger since otherwise
00306     // more than 24 hours might be displayed.
00307     double mGridSpacingX;
00308     double mGridSpacingY;
00309     double mDesiredGridSpacingY;
00310 
00311     // size of border, where mouse action will resize the KOAgendaItem
00312     int mResizeBorderWidth;
00313 
00314     // size of border, where mouse mve will cause a scroll of the agenda
00315     int mScrollBorderWidth;
00316     int mScrollDelay;
00317     int mScrollOffset;
00318 
00319     QTimer mScrollUpTimer;
00320     QTimer mScrollDownTimer;
00321 
00322     // Number of Columns/Rows of agenda grid
00323     int mColumns;
00324     int mRows;
00325 
00326     // Cells to store Move and Resize coordiantes while performing the action
00327     QPoint mStartCell;
00328     QPoint mEndCell;
00329 
00330     // Working Hour coordiantes
00331     bool mWorkingHoursEnable;
00332     QMemArray<bool> *mHolidayMask;
00333     int mWorkingHoursYTop;
00334     int mWorkingHoursYBottom;
00335 
00336     // Selection
00337     bool mHasSelection;
00338     QPoint mSelectionStartPoint;
00339     QPoint mSelectionStartCell;
00340     QPoint mSelectionEndCell;
00341 
00342     // List of dates to be displayed
00343     DateList mSelectedDates;
00344 
00345     // The KOAgendaItem, which has been right-clicked last
00346     QGuardedPtr<KOAgendaItem> mClickedItem;
00347 
00348     // The KOAgendaItem, which is being moved/resized
00349     QGuardedPtr<KOAgendaItem> mActionItem;
00350 
00351     // Currently selected item
00352     QGuardedPtr<KOAgendaItem> mSelectedItem;
00353     // Uid of the last selected item. Used for reselecting in situations
00354     // where the selected item points to a no longer valid incidence, for
00355     // example during resource reload.
00356     QString mSelectedUid;
00357 
00358     // The Marcus Bains Line widget.
00359     MarcusBains *mMarcusBains;
00360 
00361     MouseActionType mActionType;
00362 
00363     bool mItemMoved;
00364 
00365     // List of all Items contained in agenda
00366     QPtrList<KOAgendaItem> mItems;
00367     QPtrList<KOAgendaItem> mItemsToDelete;
00368 
00369     QPopupMenu *mItemPopup; // Right mouse button popup menu for KOAgendaItems
00370 
00371     int mOldLowerScrollValue;
00372     int mOldUpperScrollValue;
00373 
00374     bool mTypeAhead;
00375     QObject *mTypeAheadReceiver;
00376     QPtrList<QEvent> mTypeAheadEvents;
00377 
00378     bool mReturnPressed;
00379     KOrg::IncidenceChangerBase *mChanger;
00380 
00381     CalendarView *mCalendarView;
00382 };
00383 
00384 #endif // KOAGENDA_H
KDE Home | KDE Accessibility Home | Description of Access Keys