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