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