korganizer Library API Documentation

koagenda.h

00001 /*
00002     This file is part of KOrganizer.
00003     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 
00019     As a special exception, permission is given to link this program
00020     with any edition of Qt, and distribute the resulting executable,
00021     without including the source code for Qt in the source distribution.
00022 */
00023 #ifndef KOAGENDA_H
00024 #define KOAGENDA_H
00025 
00026 #include <qscrollview.h>
00027 #include <qtimer.h>
00028 #include <qguardedptr.h>
00029 #include <libkcal/incidencebase.h>
00030 
00031 class QPopupMenu;
00032 class QTime;
00033 class QLabel;
00034 class KConfig;
00035 class KOAgenda;
00036 class KOAgendaItem;
00037 
00038 using namespace KCal;
00039 namespace KCal {
00040 class Event;
00041 class Todo;
00042 class Calendar;
00043 }
00044 
00045 class MarcusBains : public QFrame {
00046     Q_OBJECT
00047   public:
00048     MarcusBains( KOAgenda *agenda = 0, const char *name = 0 );
00049     virtual ~MarcusBains();
00050 
00051   public slots:
00052     void updateLocation( bool recalculate = false );
00053 
00054   private:
00055     int todayColumn();
00056     QTimer *minutes;
00057     QLabel *mTimeBox;
00058     KOAgenda *agenda;
00059     QTime oldTime;
00060     int oldToday;
00061 };
00062 
00063 
00064 class KOAgenda : public QScrollView
00065 {
00066     Q_OBJECT
00067   public:
00068     KOAgenda ( int columns, int rows, int columnSize, QWidget *parent=0,
00069                const char *name = 0, WFlags f = 0 );
00070     KOAgenda ( int columns, QWidget *parent = 0,
00071                const char *name = 0, WFlags f = 0 );
00072     virtual ~KOAgenda();
00073 
00074     Incidence *selectedIncidence() const;
00075     QDate selectedIncidenceDate() const;
00080     const QString lastSelectedUid() const;
00081 
00082     virtual bool eventFilter ( QObject *, QEvent * );
00083 
00084     QPoint contentsToGrid ( const QPoint &pos ) const;
00085     QPoint gridToContents ( const QPoint &gpos ) const;
00086 
00087     int timeToY ( const QTime &time );
00088     QTime gyToTime ( int y );
00089 
00090     QMemArray<int> minContentsY();
00091     QMemArray<int> maxContentsY();
00092 
00093     void setStartTime( QTime startHour );
00094 
00095     KOAgendaItem *insertItem ( Incidence *incidence, QDate qd, int X, int YTop,
00096                                int YBottom );
00097     KOAgendaItem *insertAllDayItem ( Incidence *event, QDate qd, int XBegin,
00098                                      int XEnd );
00099     void insertMultiItem ( Event *event, QDate qd, int XBegin, int XEnd,
00100                            int YTop, int YBottom );
00101 
00106     void removeIncidence( Incidence *incidence );
00107 
00108     void changeColumns( int columns );
00109 
00110     int columns() { return mColumns; }
00111     int rows() { return mRows; }
00112 
00113     double gridSpacingX() const { return mGridSpacingX; }
00114     double gridSpacingY() const { return mGridSpacingY; }
00115 
00116 //    virtual QSizePolicy sizePolicy() const;
00117 
00118     void clear();
00119 
00121     virtual int minimumWidth() const;
00123     void updateConfig();
00124 
00125     void checkScrollBoundaries();
00126 
00127     void setHolidayMask( QMemArray<bool> * );
00128 
00129     void setDateList( const DateList &selectedDates );
00130     DateList dateList() const;
00131 
00132     void setTypeAheadReceiver( QObject * );
00133     QObject *typeAheadReceiver() const;
00134     void finishTypeAhead();
00135 
00136     void setCalendar( Calendar*cal ) { mCalendar=cal; }
00137 
00138   public slots:
00139     void scrollUp();
00140     void scrollDown();
00141 
00142     void checkScrollBoundaries( int );
00143 
00145     void deselectItem();
00146 
00147     void clearSelection();
00148 
00154     void selectItem( KOAgendaItem * );
00158     void selectItemByUID( const QString& uid );
00159     bool removeAgendaItem( KOAgendaItem *item );
00160     void showAgendaItem( KOAgendaItem *item );
00161 
00162   signals:
00163     void newEventSignal();
00164     void newEventSignal( const QPoint &pos );
00165     void newEventSignal( const QPoint &start, const QPoint &end );
00166     void newTimeSpanSignal( const QPoint &, const QPoint & );
00167     void newStartSelectSignal();
00168 
00169     void showIncidenceSignal( Incidence * );
00170     void editIncidenceSignal( Incidence * );
00171     void deleteIncidenceSignal( Incidence * );
00172     void showIncidencePopupSignal( Incidence *, const QDate &);
00173     void showNewEventPopupSignal();
00174 
00175     void itemModified( KOAgendaItem *item );
00176     void incidenceSelected( Incidence * );
00177     void incidenceChanged( Incidence*, Incidence* );
00178     void incidenceAdded( Incidence* );
00179     void startMultiModify( const QString & );
00180     void endMultiModify();
00181 
00182     void lowerYChanged( int );
00183     void upperYChanged( int );
00184 
00185     void startDragSignal(Incidence *);
00186     void droppedToDo( Todo*todo, const QPoint &gpos, bool allDay );
00187 
00188     void enableAgendaUpdate( bool enable );
00189 
00190   private:
00191     enum MouseActionType { NOP, MOVE, SELECT,
00192                            RESIZETOP, RESIZEBOTTOM, RESIZELEFT, RESIZERIGHT };
00193 
00194   protected:
00195     void drawContents( QPainter *p, int cx, int cy, int cw, int ch );
00196     int columnWidth( int column );
00197     virtual void resizeEvent ( QResizeEvent * );
00198 
00200     virtual bool eventFilter_mouse ( QObject *, QMouseEvent * );
00202     virtual bool eventFilter_key ( QObject *, QKeyEvent * );
00203 
00205     virtual bool eventFilter_drag( QObject *, QDropEvent * );
00206 
00213     MouseActionType isInResizeArea( bool horizontal, const QPoint &pos, KOAgendaItem *item );
00216     bool ptInSelection( QPoint gpos ) const;
00217 
00218 
00220     void startSelectAction( const QPoint &viewportPos );
00221 
00223     void performSelectAction( const QPoint &viewportPos );
00224 
00226     void endSelectAction( const QPoint &viewportPos );
00227 
00229     void startItemAction(const QPoint& viewportPos);
00230 
00232     void performItemAction(const QPoint& viewportPos);
00233 
00235     void endItemAction();
00236 
00238     void setNoActionCursor( KOAgendaItem *moveItem, const QPoint &viewportPos );
00243     void setActionCursor( int actionType, bool acting=false );
00244 
00246     double calcSubCellWidth( KOAgendaItem *item );
00248     void placeAgendaItem( KOAgendaItem *item, double subCellWidth );
00250     void placeSubCells( KOAgendaItem *placeItem );
00252     void adjustItemPosition( KOAgendaItem *item );
00253 
00257     void keyPressEvent( QKeyEvent * );
00258 
00259     void calculateWorkingHours();
00260 
00261     virtual void contentsMousePressEvent ( QMouseEvent * );
00262 
00263     void emitNewEventForSelection();
00264 
00265   protected slots:
00267     void deleteItemsToDelete();
00268 
00269   private:
00270     void init();
00271     void marcus_bains();
00272     bool mAllDayMode;
00273 
00274     // We need the calendar for drag'n'drop
00275     Calendar *mCalendar;
00276 
00277     // Width and height of agenda cells. mDesiredGridSpacingY is the height
00278     // set in the config. The actual height might be larger since otherwise
00279     // more than 24 hours might be displayed.
00280     double mGridSpacingX;
00281     double mGridSpacingY;
00282     double mDesiredGridSpacingY;
00283 
00284     // size of border, where mouse action will resize the KOAgendaItem
00285     int mResizeBorderWidth;
00286 
00287     // size of border, where mouse mve will cause a scroll of the agenda
00288     int mScrollBorderWidth;
00289     int mScrollDelay;
00290     int mScrollOffset;
00291 
00292     QTimer mScrollUpTimer;
00293     QTimer mScrollDownTimer;
00294 
00295     // Number of Columns/Rows of agenda grid
00296     int mColumns;
00297     int mRows;
00298 
00299     // Cells to store Move and Resize coordiantes while performing the action
00300     QPoint mStartCell;
00301     QPoint mEndCell;
00302 
00303     // Working Hour coordiantes
00304     bool mWorkingHoursEnable;
00305     QMemArray<bool> *mHolidayMask;
00306     int mWorkingHoursYTop;
00307     int mWorkingHoursYBottom;
00308 
00309     // Selection
00310     bool mHasSelection;
00311     QPoint mSelectionStartPoint;
00312     QPoint mSelectionStartCell;
00313     QPoint mSelectionEndCell;
00314 
00315     // List of dates to be displayed
00316     DateList mSelectedDates;
00317 
00318     // The KOAgendaItem, which has been right-clicked last
00319     QGuardedPtr<KOAgendaItem> mClickedItem;
00320 
00321     // The KOAgendaItem, which is being moved/resized
00322     QGuardedPtr<KOAgendaItem> mActionItem;
00323 
00324     // Currently selected item
00325     QGuardedPtr<KOAgendaItem> mSelectedItem;
00326     // Uid of the last selected item. Used for reselecting in situations
00327     // where the selected item points to a no longer valid incidence, for
00328     // example during resource reload.
00329     QString mSelectedUid;
00330 
00331     // The Marcus Bains Line widget.
00332     MarcusBains *mMarcusBains;
00333 
00334     MouseActionType mActionType;
00335 
00336     bool mItemMoved;
00337 
00338     // List of all Items contained in agenda
00339     QPtrList<KOAgendaItem> mItems;
00340     QPtrList<KOAgendaItem> mItemsToDelete;
00341 
00342     QPopupMenu *mItemPopup; // Right mouse button popup menu for KOAgendaItems
00343 
00344     int mOldLowerScrollValue;
00345     int mOldUpperScrollValue;
00346 
00347     bool mTypeAhead;
00348     QObject *mTypeAheadReceiver;
00349     QPtrList<QEvent> mTypeAheadEvents;
00350 
00351     bool mReturnPressed;
00352 };
00353 
00354 #endif // KOAGENDA_H
KDE Logo
This file is part of the documentation for korganizer Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 23 22:45:23 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003