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