korganizer

koagendaview.h
00001 /*
00002     This file is part of KOrganizer.
00003 
00004     Copyright (c) 2000,2001,2003 Cornelius Schumacher <schumacher@kde.org>
00005     Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00006 
00007     This program is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020 
00021     As a special exception, permission is given to link this program
00022     with any edition of TQt, and distribute the resulting executable,
00023     without including the source code for TQt in the source distribution.
00024 */
00025 #ifndef KOAGENDAVIEW_H
00026 #define KOAGENDAVIEW_H
00027 
00028 #include <tqscrollview.h>
00029 #include <tqlabel.h>
00030 
00031 #include <libkcal/calendar.h>
00032 
00033 #include "calprinter.h"
00034 #include "calendarview.h"
00035 
00036 #include "agendaview.h"
00037 
00038 class TQHBox;
00039 class TQPushButton;
00040 class TQBoxLayout;
00041 
00042 class KOAgenda;
00043 class KOAgendaItem;
00044 class TimeLabels;
00045 class TDEConfig;
00046 
00047 namespace KOrg {
00048   class IncidenceChangerBase;
00049 }
00050 
00051 class EventIndicator : public TQFrame
00052 {
00053     Q_OBJECT
00054   
00055   public:
00056     enum Location { Top, Bottom };
00057     EventIndicator( Location loc = Top, TQWidget *parent = 0,
00058                     const char *name = 0 );
00059     virtual ~EventIndicator();
00060 
00061     void changeColumns( int columns );
00062 
00063     void enableColumn( int column, bool enable );
00064 
00065   protected:
00066     void drawContents( TQPainter * );
00067 
00068   private:
00069     int mColumns;
00070     Location mLocation;
00071     TQPixmap mPixmap;
00072     TQMemArray<bool> mEnabled;
00073 };
00074 
00075 class KOAlternateLabel : public TQLabel
00076 {
00077     Q_OBJECT
00078   
00079   public:
00080     KOAlternateLabel( const TQString &shortlabel, const TQString &longlabel,
00081                       const TQString &extensivelabel = TQString(),
00082                       TQWidget *parent = 0, const char *name = 0 );
00083     ~KOAlternateLabel();
00084 
00085     virtual TQSize minimumSizeHint() const;
00086 
00087     enum TextType { Short = 0, Long = 1, Extensive = 2 };
00088     TextType largestFittingTextType() const;
00089     void setFixedType( TextType type );
00090 
00091   public slots:
00092     void useShortText();
00093     void useLongText();
00094     void useExtensiveText();
00095     void useDefaultText();
00096 
00097   protected:
00098     virtual void resizeEvent( TQResizeEvent * );
00099     virtual void squeezeTextToLabel();
00100     bool mTextTypeFixed;
00101     TQString mShortText, mLongText, mExtensiveText;
00102 };
00103 
00108 class KOAgendaView : public KOrg::AgendaView, public KCal::Calendar::Observer
00109 {
00110     Q_OBJECT
00111   
00112   public:
00113     KOAgendaView( Calendar *cal,
00114                   CalendarView *calendarView,
00115                   TQWidget *parent = 0,
00116                   const char *name = 0,
00117                   bool isSideBySide = false );
00118     virtual ~KOAgendaView();
00119 
00121     virtual int maxDatesHint();
00122 
00124     virtual int currentDateCount();
00125 
00127     virtual Incidence::List selectedIncidences();
00128 
00130     virtual DateList selectedIncidenceDates();
00131 
00133     virtual bool eventDurationHint(TQDateTime &startDt, TQDateTime &endDt, bool &allDay);
00134 
00136     void clearView();
00137 
00138     KOrg::CalPrinterBase::PrintType printType();
00139 
00141     TQDateTime selectionStart() { return mTimeSpanBegin; }
00143     TQDateTime selectionEnd() { return mTimeSpanEnd; }
00145     bool selectedIsAllDay() { return mTimeSpanInAllDay; }
00147     void deleteSelectedDateTime();
00149     bool selectedIsSingleCell();
00150 
00151     void setTypeAheadReceiver( TQObject * );
00152 
00153     KOAgenda* agenda() const { return mAgenda; }
00154     TQSplitter* splitter() const { return mSplitterAgenda; }
00155     TQFrame *dayLabels() const { return mDayLabels; }
00156 
00157     /* reimplmented from KCal::Calendar::Observer */
00158     void calendarIncidenceAdded( Incidence *incidence );
00159     void calendarIncidenceChanged( Incidence *incidence );
00160     void calendarIncidenceDeleted( Incidence *incidence );
00161 
00162   public slots:
00163     virtual void updateView();
00164     virtual void updateConfig();
00165     virtual void showDates( const TQDate &start, const TQDate &end );
00166     virtual void showIncidences( const Incidence::List &incidenceList, const TQDate &date );
00167 
00168     void insertIncidence( Incidence *incidence, const TQDate &curDate );
00169     void changeIncidenceDisplayAdded( Incidence *incidence );
00170     void changeIncidenceDisplay( Incidence *incidence, int mode );
00171 
00172     void clearSelection();
00173 
00174     void startDrag( Incidence * );
00175 
00176     void readSettings();
00177     void readSettings( TDEConfig * );
00178     void writeSettings( TDEConfig * );
00179 
00180     void setContentsPos( int y );
00181 
00182     void setExpandedButton( bool expanded );
00183 
00184     void finishTypeAhead();
00185 
00187     void slotTodoDropped( Todo *, const TQPoint &, bool );
00188 
00189     void enableAgendaUpdate( bool enable );
00190     void setIncidenceChanger( KOrg::IncidenceChangerBase *changer );
00191 
00192     void zoomInHorizontally( const TQDate& date=TQDate() );
00193     void zoomOutHorizontally( const TQDate& date=TQDate() );
00194 
00195     void zoomInVertically( );
00196     void zoomOutVertically( );
00197 
00198     void zoomView( const int delta, const TQPoint &pos,
00199 
00200     const Qt::Orientation orient=Qt::Horizontal );
00201 
00202     void clearTimeSpanSelection();
00203 
00204     void resourcesChanged();
00205 
00206   signals:
00207     void toggleExpand();
00208     void zoomViewHorizontally(const TQDate &, int count );
00209 
00210     void timeSpanSelectionChanged();
00211 
00212   protected:
00214     void fillAgenda( const TQDate &startDate );
00215 
00217     void fillAgenda();
00218 
00219     void connectAgenda( KOAgenda*agenda, TQPopupMenu*popup, KOAgenda* otherAgenda );
00220 
00222     void createDayLabels( bool force );
00223 
00227     void setHolidayMasks();
00228 
00229     void removeIncidence( Incidence * );
00234     void updateEventIndicators();
00235 
00236     void updateTimeBarWidth();
00237 
00238     virtual void resizeEvent( TQResizeEvent *resizeEvent );
00239 
00240   protected slots:
00242     void updateEventDates( KOAgendaItem *item );
00244     void doUpdateItem();
00245 
00246     void updateEventIndicatorTop( int newY );
00247     void updateEventIndicatorBottom( int newY );
00248 
00250     void newTimeSpanSelected( const TQPoint &start, const TQPoint &end );
00252     void newTimeSpanSelectedAllDay( const TQPoint &start, const TQPoint &end );
00253 
00254     void updateDayLabelSizes();
00255 
00256   private:
00257     bool filterByResource( Incidence *incidence );
00258     void displayIncidence( Incidence *incidence );
00259 
00260   private:
00261     // view widgets
00262     TQFrame *mDayLabels;
00263     TQHBox *mDayLabelsFrame;
00264     TQBoxLayout *mLayoutDayLabels;
00265     TQPtrList<KOAlternateLabel> mDateDayLabels;
00266     TQFrame *mAllDayFrame;
00267     KOAgenda *mAllDayAgenda;
00268     KOAgenda *mAgenda;
00269     TimeLabels *mTimeLabels;
00270     TQWidget *mDummyAllDayLeft;
00271     TQSplitter *mSplitterAgenda;
00272     TQPushButton *mExpandButton;
00273 
00274     DateList mSelectedDates;  // List of dates to be displayed
00275     DateList mSaveSelectedDates; // Save the list of dates between updateViews
00276     int mViewType;
00277 
00278     KOEventPopupMenu *mAgendaPopup;
00279     KOEventPopupMenu *mAllDayAgendaPopup;
00280 
00281     EventIndicator *mEventIndicatorTop;
00282     EventIndicator *mEventIndicatorBottom;
00283 
00284     TQMemArray<int> mMinY;
00285     TQMemArray<int> mMaxY;
00286 
00287     TQMemArray<bool> mHolidayMask;
00288 
00289     TQPixmap mExpandedPixmap;
00290     TQPixmap mNotExpandedPixmap;
00291 
00292     TQDateTime mTimeSpanBegin;
00293     TQDateTime mTimeSpanEnd;
00294     bool mTimeSpanInAllDay;
00295     bool mAllowAgendaUpdate;
00296 
00297     Incidence *mUpdateItem;
00298 
00299     bool mIsSideBySide;
00300     bool mPendingChanges;
00301 
00302     // the current date is inserted into mSelectedDates in the constructor
00303     // however whe should only show events when setDates is called, otherwise
00304     // we see day view with current date for a few milisecs, then we see something else
00305     // because someone called setDates with the real dates that should be displayed.
00306     // Other solution would be not initializing mSelectedDates in the ctor, but that requires
00307     // lots of changes in koagenda.cpp and koagendaview.cpp
00308     bool mAreDatesInitialized;
00309 };
00310 
00311 #endif