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     void gridSpacingYChanged( double );
00203 
00204   private:
00205     enum MouseActionType { NOP, MOVE, SELECT,
00206                            RESIZETOP, RESIZEBOTTOM, RESIZELEFT, RESIZERIGHT };
00207 
00208   protected:
00209     void drawContents( QPainter *p, int cx, int cy, int cw, int ch );
00210     int columnWidth( int column );
00211     virtual void resizeEvent ( QResizeEvent * );
00212 
00214     virtual bool eventFilter_mouse ( QObject *, QMouseEvent * );
00215 #ifndef QT_NO_WHEELEVENT
00216 
00217     virtual bool eventFilter_wheel ( QObject *, QWheelEvent * );
00218 #endif
00219 
00220     virtual bool eventFilter_key ( QObject *, QKeyEvent * );
00221 
00223     virtual bool eventFilter_drag( QObject *, QDropEvent * );
00224 
00231     MouseActionType isInResizeArea( bool horizontal, const QPoint &pos, KOAgendaItem *item );
00234     bool ptInSelection( QPoint gpos ) const;
00235 
00236 
00238     void startSelectAction( const QPoint &viewportPos );
00239 
00241     void performSelectAction( const QPoint &viewportPos );
00242 
00244     void endSelectAction( const QPoint &viewportPos );
00245 
00247     void startItemAction(const QPoint& viewportPos);
00248 
00250     void performItemAction(const QPoint& viewportPos);
00251 
00253     void endItemAction();
00254 
00256     void setNoActionCursor( KOAgendaItem *moveItem, const QPoint &viewportPos );
00261     void setActionCursor( int actionType, bool acting=false );
00262 
00264     double calcSubCellWidth( KOAgendaItem *item );
00266     void placeAgendaItem( KOAgendaItem *item, double subCellWidth );
00268     void placeSubCells( KOAgendaItem *placeItem );
00270     void adjustItemPosition( KOAgendaItem *item );
00271 
00275     void keyPressEvent( QKeyEvent * );
00276 
00277     void calculateWorkingHours();
00278 
00279     virtual void contentsMousePressEvent ( QMouseEvent * );
00280 
00281     void emitNewEventForSelection();
00282 
00283   protected slots:
00285     void deleteItemsToDelete();
00290     void resizeAllContents();
00291 
00292   private:
00293     void init();
00294     void marcus_bains();
00295     bool mAllDayMode;
00296 
00297     // We need the calendar for drag'n'drop and for paint the ResourceColor
00298     Calendar *mCalendar;
00299 
00300     // Width and height of agenda cells. mDesiredGridSpacingY is the height
00301     // set in the config. The actual height might be larger since otherwise
00302     // more than 24 hours might be displayed.
00303     double mGridSpacingX;
00304     double mGridSpacingY;
00305     double mDesiredGridSpacingY;
00306 
00307     // size of border, where mouse action will resize the KOAgendaItem
00308     int mResizeBorderWidth;
00309 
00310     // size of border, where mouse mve will cause a scroll of the agenda
00311     int mScrollBorderWidth;
00312     int mScrollDelay;
00313     int mScrollOffset;
00314 
00315     QTimer mScrollUpTimer;
00316     QTimer mScrollDownTimer;
00317 
00318     // Number of Columns/Rows of agenda grid
00319     int mColumns;
00320     int mRows;
00321 
00322     // Cells to store Move and Resize coordiantes while performing the action
00323     QPoint mStartCell;
00324     QPoint mEndCell;
00325 
00326     // Working Hour coordiantes
00327     bool mWorkingHoursEnable;
00328     QMemArray<bool> *mHolidayMask;
00329     int mWorkingHoursYTop;
00330     int mWorkingHoursYBottom;
00331 
00332     // Selection
00333     bool mHasSelection;
00334     QPoint mSelectionStartPoint;
00335     QPoint mSelectionStartCell;
00336     QPoint mSelectionEndCell;
00337 
00338     // List of dates to be displayed
00339     DateList mSelectedDates;
00340 
00341     // The KOAgendaItem, which has been right-clicked last
00342     QGuardedPtr<KOAgendaItem> mClickedItem;
00343 
00344     // The KOAgendaItem, which is being moved/resized
00345     QGuardedPtr<KOAgendaItem> mActionItem;
00346 
00347     // Currently selected item
00348     QGuardedPtr<KOAgendaItem> mSelectedItem;
00349     // Uid of the last selected item. Used for reselecting in situations
00350     // where the selected item points to a no longer valid incidence, for
00351     // example during resource reload.
00352     QString mSelectedUid;
00353 
00354     // The Marcus Bains Line widget.
00355     MarcusBains *mMarcusBains;
00356 
00357     MouseActionType mActionType;
00358 
00359     bool mItemMoved;
00360 
00361     // List of all Items contained in agenda
00362     QPtrList<KOAgendaItem> mItems;
00363     QPtrList<KOAgendaItem> mItemsToDelete;
00364 
00365     QPopupMenu *mItemPopup; // Right mouse button popup menu for KOAgendaItems
00366 
00367     int mOldLowerScrollValue;
00368     int mOldUpperScrollValue;
00369 
00370     bool mTypeAhead;
00371     QObject *mTypeAheadReceiver;
00372     QPtrList<QEvent> mTypeAheadEvents;
00373 
00374     bool mReturnPressed;
00375     KOrg::IncidenceChangerBase *mChanger;
00376 };
00377 
00378 #endif // KOAGENDA_H
KDE Home | KDE Accessibility Home | Description of Access Keys