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