summaryrefslogtreecommitdiffstats
path: root/korganizer/koagendaview.h
blob: 647dcafcb451805d6e9846e3562f8b7a7e0ed71b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
/*
    This file is part of KOrganizer.

    Copyright (c) 2000,2001,2003 Cornelius Schumacher <schumacher@kde.org>
    Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

    As a special exception, permission is given to link this program
    with any edition of TQt, and distribute the resulting executable,
    without including the source code for TQt in the source distribution.
*/
#ifndef KOAGENDAVIEW_H
#define KOAGENDAVIEW_H

#include <tqscrollview.h>
#include <tqlabel.h>

#include <libkcal/calendar.h>

#include "calprinter.h"
#include "calendarview.h"

#include "agendaview.h"

class TQHBox;
class TQPushButton;
class TQBoxLayout;

class KOAgenda;
class KOAgendaItem;
class TimeLabels;
class KConfig;

namespace KOrg {
  class IncidenceChangerBase;
}

class EventIndicator : public TQFrame
{
    Q_OBJECT
  TQ_OBJECT
  public:
    enum Location { Top, Bottom };
    EventIndicator( Location loc = Top, TQWidget *parent = 0,
                    const char *name = 0 );
    virtual ~EventIndicator();

    void changeColumns( int columns );

    void enableColumn( int column, bool enable );

  protected:
    void drawContents( TQPainter * );

  private:
    int mColumns;
    Location mLocation;
    TQPixmap mPixmap;
    TQMemArray<bool> mEnabled;
};

class KOAlternateLabel : public TQLabel
{
    Q_OBJECT
  TQ_OBJECT
  public:
    KOAlternateLabel( const TQString &shortlabel, const TQString &longlabel,
                      const TQString &extensivelabel = TQString(),
                      TQWidget *parent = 0, const char *name = 0 );
    ~KOAlternateLabel();

    virtual TQSize tqminimumSizeHint() const;

    enum TextType { Short = 0, Long = 1, Extensive = 2 };
    TextType largestFittingTextType() const;
    void setFixedType( TextType type );

  public slots:
    void useShortText();
    void useLongText();
    void useExtensiveText();
    void useDefaultText();

  protected:
    virtual void resizeEvent( TQResizeEvent * );
    virtual void squeezeTextToLabel();
    bool mTextTypeFixed;
    TQString mShortText, mLongText, mExtensiveText;
};

/**
  KOAgendaView is the agenda-like view used to display events in a single one or
  multi-day view.
*/
class KOAgendaView : public KOrg::AgendaView, public KCal::Calendar::Observer
{
    Q_OBJECT
  TQ_OBJECT
  public:
    KOAgendaView( Calendar *cal,
                  CalendarView *calendarView,
                  TQWidget *parent = 0,
                  const char *name = 0,
                  bool isSideBySide = false );
    virtual ~KOAgendaView();

    /** Returns maximum number of days supported by the koagendaview */
    virtual int maxDatesHint();

    /** Returns number of currently shown dates. */
    virtual int tqcurrentDateCount();

    /** returns the currently selected events */
    virtual Incidence::List selectedIncidences();

    /** returns the currently selected events */
    virtual DateList selectedIncidenceDates();

    /** return the default start/end date/time for new events   */
    virtual bool eventDurationHint(TQDateTime &startDt, TQDateTime &endDt, bool &allDay);

    /** Remove all events from view */
    void clearView();

    KOrg::CalPrinterBase::PrintType printType();

    /** start-datetime of selection */
    TQDateTime selectionStart() { return mTimeSpanBegin; }
    /** end-datetime of selection */
    TQDateTime selectionEnd() { return mTimeSpanEnd; }
    /** returns true if selection is for whole day */
    bool selectedIsAllDay() { return mTimeSpanInAllDay; }
    /** make selected start/end invalid */
    void deleteSelectedDateTime();
    /** returns if only a single cell is selected, or a range of cells */
    bool selectedIsSingleCell();

    void setTypeAheadReceiver( TQObject * );

    KOAgenda* agenda() const { return mAgenda; }
    TQSplitter* splitter() const { return mSplitterAgenda; }
    TQFrame *dayLabels() const { return mDayLabels; }

    /* reimplmented from KCal::Calendar::Observer */
    void calendarIncidenceAdded( Incidence *incidence );
    void calendarIncidenceChanged( Incidence *incidence );
    void calendarIncidenceDeleted( Incidence *incidence );

  public slots:
    virtual void updateView();
    virtual void updateConfig();
    virtual void showDates( const TQDate &start, const TQDate &end );
    virtual void showIncidences( const Incidence::List &incidenceList, const TQDate &date );

    void insertIncidence( Incidence *incidence, const TQDate &curDate );
    void changeIncidenceDisplayAdded( Incidence *incidence );
    void changeIncidenceDisplay( Incidence *incidence, int mode );

    void clearSelection();

    void startDrag( Incidence * );

    void readSettings();
    void readSettings( KConfig * );
    void writeSettings( KConfig * );

    void setContentsPos( int y );

    void setExpandedButton( bool expanded );

    void finishTypeAhead();

    /** reschedule the todo  to the given x- and y- coordinates. Third parameter determines all-day (no time specified) */
    void slotTodoDropped( Todo *, const TQPoint &, bool );

    void enableAgendaUpdate( bool enable );
    void setIncidenceChanger( KOrg::IncidenceChangerBase *changer );

    void zoomInHorizontally( const TQDate& date=TQDate() );
    void zoomOutHorizontally( const TQDate& date=TQDate() );

    void zoomInVertically( );
    void zoomOutVertically( );

    void zoomView( const int delta, const TQPoint &pos,

    const Qt::Orientation orient=Qt::Horizontal );

    void clearTimeSpanSelection();

    void resourcesChanged();

  signals:
    void toggleExpand();
    void zoomViewHorizontally(const TQDate &, int count );

    void timeSpanSelectionChanged();

  protected:
    /** Fill agenda beginning with date startDate */
    void fillAgenda( const TQDate &startDate );

    /** Fill agenda using the current set value for the start date */
    void fillAgenda();

    void connectAgenda( KOAgenda*agenda, TQPopupMenu*popup, KOAgenda* otherAgenda );

    /** Create labels for the selected dates. */
    void createDayLabels( bool force );

    /**
      Set the masks on the agenda widgets indicating, which days are holidays.
    */
    void setHolidayMasks();

    void removeIncidence( Incidence * );
    /**
      Updates the event indicators after a certain incidence was modified or
      removed.
    */
    void updateEventIndicators();

    void updateTimeBarWidth();

    virtual void resizeEvent( TQResizeEvent *resizeEvent );

  protected slots:
    /** Update event belonging to agenda item */
    void updateEventDates( KOAgendaItem *item );
    /** update just the display of the given incidence, called by a single-shot timer */
    void doUpdateItem();

    void updateEventIndicatorTop( int newY );
    void updateEventIndicatorBottom( int newY );

    /** Updates data for selected timespan */
    void newTimeSpanSelected( const TQPoint &start, const TQPoint &end );
    /** Updates data for selected timespan for all day event*/
    void newTimeSpanSelectedAllDay( const TQPoint &start, const TQPoint &end );

    void updateDayLabelSizes();

  private:
    bool filterByResource( Incidence *incidence );
    void displayIncidence( Incidence *incidence );

  private:
    // view widgets
    TQFrame *mDayLabels;
    TQHBox *mDayLabelsFrame;
    TQBoxLayout *mLayoutDayLabels;
    TQPtrList<KOAlternateLabel> mDateDayLabels;
    TQFrame *mAllDayFrame;
    KOAgenda *mAllDayAgenda;
    KOAgenda *mAgenda;
    TimeLabels *mTimeLabels;
    TQWidget *mDummyAllDayLeft;
    TQSplitter *mSplitterAgenda;
    TQPushButton *mExpandButton;

    DateList mSelectedDates;  // List of dates to be displayed
    DateList mSaveSelectedDates; // Save the list of dates between updateViews
    int mViewType;

    KOEventPopupMenu *mAgendaPopup;
    KOEventPopupMenu *mAllDayAgendaPopup;

    EventIndicator *mEventIndicatorTop;
    EventIndicator *mEventIndicatorBottom;

    TQMemArray<int> mMinY;
    TQMemArray<int> mMaxY;

    TQMemArray<bool> mHolidayMask;

    TQPixmap mExpandedPixmap;
    TQPixmap mNotExpandedPixmap;

    TQDateTime mTimeSpanBegin;
    TQDateTime mTimeSpanEnd;
    bool mTimeSpanInAllDay;
    bool mAllowAgendaUpdate;

    Incidence *mUpdateItem;

    bool mIsSideBySide;
    bool mPendingChanges;

    // the current date is inserted into mSelectedDates in the constructor
    // however whe should only show events when setDates is called, otherwise
    // we see day view with current date for a few milisecs, then we see something else
    // because someone called setDates with the real dates that should be displayed.
    // Other solution would be not initializing mSelectedDates in the ctor, but that requires
    // lots of changes in koagenda.cpp and koagendaview.cpp
    bool mAreDatesInitialized;
};

#endif