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