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