summaryrefslogtreecommitdiffabout
path: root/korganizer/komonthview.h
blob: bca76e553527d96b316adc599e4427f211eaf15d (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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
/*
    This file is part of KOrganizer.
    Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>

    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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#ifndef _KOMONTHVIEW_H
#define _KOMONTHVIEW_H

#include <qlabel.h>
#include <q3frame.h>
#include <qdatetime.h>
#include <q3listbox.h>
#include <qpoint.h>
#include <q3widgetstack.h>
#include <qlayout.h>
#include <qtimer.h>
#include <q3intdict.h>
#include <qpushbutton.h>
#include <q3valuelist.h>
#include <q3ptrvector.h>
//Added by qt3to4:
#include <QResizeEvent>
#include <QFocusEvent>
#include <QMouseEvent>
#include <Q3PtrList>
#include <Q3PopupMenu>
#include <QKeyEvent>

#include <libkcal/calendar.h>
#include <libkcal/event.h>

#include "koeventview.h"
#include "navigatorbar.h"

#ifdef DESKTOP_VERSION
class QToolTipGroup; 
#endif

class KNOWhatsThis; 
class MonthViewCell; 
class KOWeekButton : public QPushButton
{
    Q_OBJECT
  public:
    KOWeekButton( QWidget *parent=0, const char *name=0 ) :
      QPushButton( parent, name) 
    {
      connect( this, SIGNAL( clicked() ),
               SLOT( bottonClicked() )); 
      mNumber = -1;
    }
    void setWeekNum ( int num ) {mNumber = num; setText( QString::number ( num ));}
    int getWeekNum() { return mNumber;}
    signals:
    void selectWeekNum ( int );
private: 
    void focusInEvent ( QFocusEvent * ){;}
    int mNumber;
    void keyPressEvent ( QKeyEvent * e )
    {
        e->ignore();     
    }

private slots :
    void bottonClicked() { if ( mNumber > 0 ) emit selectWeekNum ( mNumber ); }
};

class KNoScrollListBox: public Q3ListBox
{
    Q_OBJECT
  public:
    KNoScrollListBox(QWidget *parent=0, const char *name=0);
    ~KNoScrollListBox();
    QString getWhatsThisText(QPoint p) ;

  signals:
    void shiftDown();
    void shiftUp();
    void rightClick();
    void nextCell();
    void prevCell();
    void highlightIncidence( Incidence * , MonthViewCell*, int );
 protected:
    bool mBlockDeselect;
   protected slots:
    void oneDown();
    void keyPressEvent(QKeyEvent *);
    void keyReleaseEvent(QKeyEvent *);
    void mousePressEvent(QMouseEvent *); 
    void focusInEvent ( QFocusEvent * );
    void focusOutEvent ( QFocusEvent * ); 

 private:
    bool resetOnFocusIn;
    KNOWhatsThis * mWT;
};


class MonthViewItem: public Q3ListBoxItem
{
  public:
    MonthViewItem( Incidence *,const QString & title );
    void recycle( Incidence *incidence, const QString & s);
    void setRecur(bool on) { mRecur = on; }
    void setAlarm(bool on) { mAlarm = on; }
    void setReply(bool on) { mReply = on; }
    void setMoreInfo(bool on) { mInfo = on; }
    void setMultiDay(int type) { mMultiday = type; }
    int multiDay() { return mMultiday; }
    void setMultiDayPos(int type) { mdayPos = type; }
    int gettMultiDayPos() { return mdayPos; }
    void setBlockRepaint(bool on) { mblockRepaint = on; }
    bool setHighlighted( Incidence * );

    void setPalette(const QPalette &p) { mPalette = p; }
    QPalette palette() const { return mPalette; }
    bool setHighlightedFalse();
    Incidence *incidence() const { return mIncidence; }

  protected:
    virtual void paint(QPainter *);
    virtual int height(const Q3ListBox *) const;
    virtual int width(const Q3ListBox *) const;

  private:
    int mdayPos;
    bool isWeekItem;
    bool mblockRepaint;
    int mMultiday;
    bool mRecur;
    bool mAlarm;
    bool mReply;
    bool mInfo;
    bool mDisplayHighlighted;

    QPalette mPalette;
    QDate mDate;

    Incidence *mIncidence;
};


class KOMonthView;

class MonthViewCell : public KNoScrollListBox
{
    Q_OBJECT
  public:
    MonthViewCell(KOMonthView *,QWidget* );
    ~MonthViewCell() {mAvailItemList.setAutoDelete( true );}

    void setDate( const QDate & );
    QDate date() const;

    void setPrimary( bool );
    bool isPrimary() const;

    void setHoliday( bool );
    void setHoliday( const QString & );

    void updateCell();
    void startUpdateCell();
    void finishUpdateCell();
    int insertEvent(Event *);
    void insertTodo(Todo *);

    void updateConfig( bool bigFont = false );

    void enableScrollBars( bool );

    Incidence *selectedIncidence();
    QDate selectedIncidenceDate();
    QPushButton * dateLabel() { return mLabel; }
    bool doHighLight( Incidence *);
    void deselect();
    void select();
#ifdef DESKTOP_VERSION
    static QToolTipGroup *toolTipGroup(); 
#endif
  signals:
    void defaultAction( Incidence * );
    void newEventSignal( QDateTime );
    void showDaySignal( QDate );
    
  protected:
    QStringList mToolTip;
    void resizeEvent( QResizeEvent * );

public slots:
    void showDay();
    void deHighLight();
    void repaintfinishUpdateCell();
  protected slots: 
    void defaultAction( Q3ListBoxItem * );
    void contextMenu( Q3ListBoxItem * );
    void selection( Q3ListBoxItem * );
    void cellClicked( Q3ListBoxItem * );
    void newEvent();
    
  private:
    int mdayCount;
    Q3PtrList <MonthViewItem> mAvailItemList; 
    KOMonthView *mMonthView;
    int currentPalette; 
  
    QDate mDate;
    bool mPrimary;
    bool mHoliday;
    QString mHolidayString;
    
    //QLabel *mLabel;
    QPushButton *mLabel;
    //QListBox *mItemList;
#ifdef DESKTOP_VERSION
    static QToolTipGroup *mToolTipGroup; 
#endif 
    QSize mLabelSize;
    QSize mLabelBigSize;
    QPalette mHolidayPalette;
    QPalette mStandardPalette;
    QPalette mPrimaryPalette;
    QPalette mNonPrimaryPalette;
    void setMyPalette();
    QPalette  getPalette ();
    
};


class KOMonthView: public KOEventView
{
    Q_OBJECT
  public:
    KOMonthView(Calendar *cal, QWidget *parent = 0, const char *name = 0 );
    ~KOMonthView();

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

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

    /** returns the currently selected events */
    virtual Q3PtrList<Incidence> selectedIncidences();

    /** returns dates of the currently selected events */
    virtual DateList selectedDates();
#if 0
    virtual void printPreview(CalPrinter *calPrinter,
                              const QDate &, const QDate &);
#endif
    bool isMonthView() { return !mShowWeekView; }
    bool isUpdatePossible() { return updatePossible; }

    MonthViewCell * selectedCell();
    bool skipResize; 
    NavigatorBar* navigatorBar() { return mNavigatorBar ;}
    void clearList();
  public slots:
    void incidenceHighlighted( Incidence *, MonthViewCell*, int );
    void nextCell();
    void prevCell();
    virtual void updateView();
    virtual void updateConfig();
    virtual void showDates(const QDate &start, const QDate &end);
    virtual void showEvents(Q3PtrList<Event> eventList);

    void changeEventDisplay(Event *, int);

    void clearSelection();

    void showContextMenu( Incidence * );

    void setSelectedCell( MonthViewCell * );
    void setPopupCell( MonthViewCell * );
    void switchView();
    void setKeyBFocus();

  protected slots:
    void catChanged( Incidence * );
    void setKeyBoardFocus();
    void slotNewTodo();
    void slotNewEvent();
    void slotEditJournal();
    void slotComputeLayout();
    void selectInternalWeekNum ( int );
    void processSelectionChange();
 signals:
    void nextMonth();
    void prevMonth();
    void selectWeekNum ( int );
    void selectMonth ();
    void showDaySignal( QDate );
    void newTodoSignal( QDateTime, bool );
    void showJournalSignal( int,QDate );
  protected:
    void resizeEvent(QResizeEvent *);
    void viewChanged();
    void updateDayLabels();
    int mapWeekLayout( int, bool );

  private:
    int mKBFcounter;
    QTimer* mComputeLayoutTimer;
    NavigatorBar* mNavigatorBar;
    int currentWeek();
    bool clPending;
    Q3WidgetStack * mWidStack;
    QWidget* mMonthView;
    QWidget* mWeekView;
    bool mShowWeekView;
    bool updatePossible;
    int mDaysPerWeek;
    int mNumWeeks;
    int mNumCells;
    //bool mWeekStartsMonday;
    bool mShowSatSunComp;
    void computeLayout();
    void computeLayoutWeek();
    void doComputeLayoutWeek();

    Q3PtrVector<MonthViewCell> mCells;
    Q3PtrVector<QLabel> mDayLabels;
    Q3PtrVector<KOWeekButton> mWeekLabels;
    Q3PtrVector<MonthViewCell> mCellsW;
    Q3PtrVector<QLabel> mDayLabelsW;
    Q3PtrVector<KOWeekButton> mWeekLabelsW;

    bool mShortDayLabelsM;
    bool mShortDayLabelsW;
    int mWidthLongDayLabel;

    QDate mStartDate;

    MonthViewCell *mSelectedCell;
    MonthViewCell *mPopupCell;
    bool mFlagKeyPressed;
    KOEventPopupMenu *mContextMenu;
    Q3PopupMenu *mNewItemMenu;
    void keyPressEvent ( QKeyEvent * ) ;
    void keyReleaseEvent ( QKeyEvent * ) ;

};

#endif