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 );
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 
00158   public slots:
00159     void scrollUp();
00160     void scrollDown();
00161 
00162     void checkScrollBoundaries( int );
00163 
00165     void deselectItem();
00166 
00167     void clearSelection();
00168 
00174     void selectItem( KOAgendaItem::GPtr );
00178     void selectItemByUID( const QString& uid );
00179     bool removeAgendaItem( KOAgendaItem::GPtr item );
00180     void showAgendaItem( KOAgendaItem::GPtr item );
00181 
00182   signals:
00183     void newEventSignal( ResourceCalendar *res, const QString &subResource );
00184     void newTimeSpanSignal( const QPoint &, const QPoint & );
00185     void newStartSelectSignal();
00186 
00187     void showIncidenceSignal( Incidence *, const QDate & );
00188     void editIncidenceSignal( Incidence *, const QDate & );
00189     void deleteIncidenceSignal( Incidence * );
00190     void showIncidencePopupSignal( Calendar *, Incidence *, const QDate &);
00191     void showNewEventPopupSignal();
00192 
00193     void incidenceSelected( Incidence *, const QDate & );
00194     void startMultiModify( const QString & );
00195     void endMultiModify();
00196 
00197     void lowerYChanged( int );
00198     void upperYChanged( int );
00199 
00200     void startDragSignal(Incidence *);
00201     void droppedToDo( Todo*todo, const QPoint &gpos, bool allDay );
00202 
00203     void zoomView( const int delta, const QPoint &pos, const Qt::Orientation );
00204 
00205     void mousePosSignal(const QPoint &pos);
00206     void enterAgenda();
00207     void leaveAgenda();
00208 
00209     void gridSpacingYChanged( double );
00210 
00211   private:
00212     enum MouseActionType { NOP, MOVE, SELECT,
00213                            RESIZETOP, RESIZEBOTTOM, RESIZELEFT, RESIZERIGHT };
00214 
00215   protected:
00216     void drawContents( QPainter *p, int cx, int cy, int cw, int ch );
00217     int columnWidth( int column );
00218     virtual void resizeEvent ( QResizeEvent * );
00219 
00221     virtual bool eventFilter_mouse ( QObject *, QMouseEvent * );
00222 #ifndef QT_NO_WHEELEVENT
00223 
00224     virtual bool eventFilter_wheel ( QObject *, QWheelEvent * );
00225 #endif
00226 
00227     virtual bool eventFilter_key ( QObject *, QKeyEvent * );
00228 
00230     virtual bool eventFilter_drag( QObject *, QDropEvent * );
00231 
00238     MouseActionType isInResizeArea( bool horizontal, const QPoint &pos, KOAgendaItem::GPtr item );
00241     bool ptInSelection( QPoint gpos ) const;
00242 
00243 
00245     void startSelectAction( const QPoint &viewportPos );
00246 
00248     void performSelectAction( const QPoint &viewportPos );
00249 
00251     void endSelectAction( const QPoint &viewportPos );
00252 
00254     void startItemAction(const QPoint& viewportPos);
00255 
00257     void performItemAction(const QPoint& viewportPos);
00258 
00260     void endItemAction();
00261 
00263     void setNoActionCursor( KOAgendaItem::GPtr moveItem, const QPoint &viewportPos );
00268     void setActionCursor( int actionType, bool acting=false );
00269 
00271     double calcSubCellWidth( KOAgendaItem::GPtr item );
00273     void placeAgendaItem( KOAgendaItem::GPtr item, double subCellWidth );
00275     void placeSubCells( KOAgendaItem::GPtr placeItem );
00277     void adjustItemPosition( KOAgendaItem::GPtr item );
00278 
00282     void keyPressEvent( QKeyEvent * );
00283 
00284     void calculateWorkingHours();
00285 
00286     virtual void contentsMousePressEvent ( QMouseEvent * );
00287 
00288     void emitNewEventForSelection();
00289 
00290   protected slots:
00292     void deleteItemsToDelete();
00297     void resizeAllContents();
00298 
00299   private:
00300     void init();
00301     void marcus_bains();
00302     bool mAllDayMode;
00303 
00304     // We need the calendar for drag'n'drop and for paint the ResourceColor
00305     Calendar *mCalendar;
00306 
00307     // Width and height of agenda cells. mDesiredGridSpacingY is the height
00308     // set in the config. The actual height might be larger since otherwise
00309     // more than 24 hours might be displayed.
00310     double mGridSpacingX;
00311     double mGridSpacingY;
00312     double mDesiredGridSpacingY;
00313 
00314     // size of border, where mouse action will resize the KOAgendaItem
00315     int mResizeBorderWidth;
00316 
00317     // size of border, where mouse mve will cause a scroll of the agenda
00318     int mScrollBorderWidth;
00319     int mScrollDelay;
00320     int mScrollOffset;
00321 
00322     QTimer mScrollUpTimer;
00323     QTimer mScrollDownTimer;
00324 
00325     // Number of Columns/Rows of agenda grid
00326     int mColumns;
00327     int mRows;
00328 
00329     // Cells to store Move and Resize coordiantes while performing the action
00330     QPoint mStartCell;
00331     QPoint mEndCell;
00332 
00333     // Working Hour coordiantes
00334     bool mWorkingHoursEnable;
00335     QMemArray<bool> *mHolidayMask;
00336     int mWorkingHoursYTop;
00337     int mWorkingHoursYBottom;
00338 
00339     // Selection
00340     bool mHasSelection;
00341     QPoint mSelectionStartPoint;
00342     QPoint mSelectionStartCell;
00343     QPoint mSelectionEndCell;
00344 
00345     // List of dates to be displayed
00346     DateList mSelectedDates;
00347 
00348     // The KOAgendaItem, which has been right-clicked last
00349     KOAgendaItem::GPtr mClickedItem;
00350 
00351     // The KOAgendaItem, which is being moved/resized
00352     KOAgendaItem::GPtr mActionItem;
00353     QPair<ResourceCalendar *, QString> mResPair;
00354 
00355     // Currently selected item
00356     KOAgendaItem::GPtr mSelectedItem;
00357     // Uid of the last selected item. Used for reselecting in situations
00358     // where the selected item points to a no longer valid incidence, for
00359     // example during resource reload.
00360     QString mSelectedUid;
00361 
00362     // The Marcus Bains Line widget.
00363     MarcusBains *mMarcusBains;
00364 
00365     MouseActionType mActionType;
00366 
00367     bool mItemMoved;
00368 
00369     // List of all Items contained in agenda
00370     QValueList<KOAgendaItem::GPtr > mItems;
00371     QValueList<KOAgendaItem::GPtr > mItemsToDelete;
00372 
00373     QPopupMenu *mItemPopup; // Right mouse button popup menu for KOAgendaItems
00374 
00375     int mOldLowerScrollValue;
00376     int mOldUpperScrollValue;
00377 
00378     bool mTypeAhead;
00379     QObject *mTypeAheadReceiver;
00380     QPtrList<QEvent> mTypeAheadEvents;
00381 
00382     bool mReturnPressed;
00383     KOrg::IncidenceChangerBase *mChanger;
00384 
00385     CalendarView *mCalendarView;
00386     KOAgendaView *mAgendaView;
00387 };
00388 
00389 #endif // KOAGENDA_H
KDE Home | KDE Accessibility Home | Description of Access Keys