summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/datenavigatorcontainer.cpp2
-rw-r--r--korganizer/kodaymatrix.cpp58
2 files changed, 45 insertions, 15 deletions
diff --git a/korganizer/datenavigatorcontainer.cpp b/korganizer/datenavigatorcontainer.cpp
index d09f484..b9bd1b9 100644
--- a/korganizer/datenavigatorcontainer.cpp
+++ b/korganizer/datenavigatorcontainer.cpp
@@ -1,229 +1,229 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 3
4 Copyright (c) 2001,2002,2003 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2001,2002,2003 Cornelius Schumacher <schumacher@kde.org>
5 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com> 5 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
6 6
7 This program is free software; you can redistribute it and/or modify 7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or 9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 10 (at your option) any later version.
11 11
12 This program is distributed in the hope that it will be useful, 12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 15 GNU General Public License for more details.
16 16
17 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software 18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 20
21 As a special exception, permission is given to link this program 21 As a special exception, permission is given to link this program
22 with any edition of Qt, and distribute the resulting executable, 22 with any edition of Qt, and distribute the resulting executable,
23 without including the source code for Qt in the source distribution. 23 without including the source code for Qt in the source distribution.
24*/ 24*/
25 25
26#include <kdebug.h> 26#include <kdebug.h>
27#include <klocale.h> 27#include <klocale.h>
28 28
29//#include "koglobals.h" 29//#include "koglobals.h"
30#include "navigatorbar.h" 30#include "navigatorbar.h"
31#include "kdatenavigator.h" 31#include "kdatenavigator.h"
32 32
33#include <kcalendarsystem.h> 33#include <kcalendarsystem.h>
34 34
35#include "datenavigatorcontainer.h" 35#include "datenavigatorcontainer.h"
36 36
37DateNavigatorContainer::DateNavigatorContainer( QWidget *parent, 37DateNavigatorContainer::DateNavigatorContainer( QWidget *parent,
38 const char *name ) 38 const char *name )
39 : QWidget( parent, name ), mCalendar( 0 ), 39 : QWidget( parent, name ), mCalendar( 0 ),
40 mHorizontalCount( 1 ), mVerticalCount( 1 ) 40 mHorizontalCount( 1 ), mVerticalCount( 1 )
41{ 41{
42 mExtraViews.setAutoDelete( true ); 42 mExtraViews.setAutoDelete( true );
43 43
44 mNavigatorView = new KDateNavigator( this, name ); 44 mNavigatorView = new KDateNavigator( this, name );
45 45
46 connectNavigatorView( mNavigatorView ); 46 connectNavigatorView( mNavigatorView );
47} 47}
48 48
49DateNavigatorContainer::~DateNavigatorContainer() 49DateNavigatorContainer::~DateNavigatorContainer()
50{ 50{
51} 51}
52 52
53void DateNavigatorContainer::connectNavigatorView( KDateNavigator *v ) 53void DateNavigatorContainer::connectNavigatorView( KDateNavigator *v )
54{ 54{
55 connect( v, SIGNAL( datesSelected( const KCal::DateList & ) ), 55 connect( v, SIGNAL( datesSelected( const KCal::DateList & ) ),
56 SIGNAL( datesSelected( const KCal::DateList & ) ) ); 56 SIGNAL( datesSelected( const KCal::DateList & ) ) );
57#if 0 57#if 0
58 connect( v, SIGNAL( incidenceDropped( Incidence *, const QDate & ) ), 58 connect( v, SIGNAL( incidenceDropped( Incidence *, const QDate & ) ),
59 SIGNAL( incidenceDropped( Incidence *, const QDate & ) ) ); 59 SIGNAL( incidenceDropped( Incidence *, const QDate & ) ) );
60 connect( v, SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ), 60 connect( v, SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ),
61 SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ) ); 61 SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ) );
62#endif 62#endif
63 connect( v, SIGNAL( weekClicked( const QDate & ) ), 63 connect( v, SIGNAL( weekClicked( const QDate & ) ),
64 SIGNAL( weekClicked( const QDate & ) ) ); 64 SIGNAL( weekClicked( const QDate & ) ) );
65 65
66 connect( v, SIGNAL( goPrevious() ), SIGNAL( goPrevious() ) ); 66 connect( v, SIGNAL( goPrevious() ), SIGNAL( goPrevious() ) );
67 connect( v, SIGNAL( goNext() ), SIGNAL( goNext() ) ); 67 connect( v, SIGNAL( goNext() ), SIGNAL( goNext() ) );
68 68
69 connect( v, SIGNAL( goNextMonth() ), SIGNAL( goNextMonth() ) ); 69 connect( v, SIGNAL( goNextMonth() ), SIGNAL( goNextMonth() ) );
70 connect( v, SIGNAL( goPrevMonth() ), SIGNAL( goPrevMonth() ) ); 70 connect( v, SIGNAL( goPrevMonth() ), SIGNAL( goPrevMonth() ) );
71 connect( v, SIGNAL( goNextYear() ), SIGNAL( goNextYear() ) ); 71 connect( v, SIGNAL( goNextYear() ), SIGNAL( goNextYear() ) );
72 connect( v, SIGNAL( goPrevYear() ), SIGNAL( goPrevYear() ) ); 72 connect( v, SIGNAL( goPrevYear() ), SIGNAL( goPrevYear() ) );
73 73
74 connect( v, SIGNAL( monthSelected( int ) ), SIGNAL( monthSelected( int ) ) ); 74 connect( v, SIGNAL( monthSelected( int ) ), SIGNAL( monthSelected( int ) ) );
75} 75}
76 76
77void DateNavigatorContainer::setCalendar( Calendar *cal ) 77void DateNavigatorContainer::setCalendar( Calendar *cal )
78{ 78{
79 mCalendar = cal; 79 mCalendar = cal;
80 mNavigatorView->setCalendar( cal ); 80 mNavigatorView->setCalendar( cal );
81 KDateNavigator *n; 81 KDateNavigator *n;
82 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { 82 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
83 n->setCalendar( cal ); 83 n->setCalendar( cal );
84 } 84 }
85} 85}
86 86
87void DateNavigatorContainer::updateDayMatrix() 87void DateNavigatorContainer::updateDayMatrix()
88{ 88{
89 mNavigatorView->updateDayMatrix(); 89 mNavigatorView->updateDayMatrix();
90 KDateNavigator *n; 90 KDateNavigator *n;
91 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { 91 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
92 n->updateDayMatrix(); 92 n->updateDayMatrix();
93 } 93 }
94} 94}
95 95
96void DateNavigatorContainer::updateToday() 96void DateNavigatorContainer::updateToday()
97{ 97{
98 qDebug("DateNavigatorContainer::updateToday() NOT IMPL "); 98 qDebug("DateNavigatorContainer::updateToday() NOT IMPL ");
99#if 0 99#if 0
100 mNavigatorView->updateToday(); 100 mNavigatorView->updateToday();
101 KDateNavigator *n; 101 KDateNavigator *n;
102 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { 102 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
103 n->updateToday(); 103 n->updateToday();
104 } 104 }
105#endif 105#endif
106} 106}
107 107
108void DateNavigatorContainer::updateView() 108void DateNavigatorContainer::updateView()
109{ 109{
110 mNavigatorView->updateView(); 110 mNavigatorView->updateView();
111 KDateNavigator *n; 111 KDateNavigator *n;
112 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { 112 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
113 n->updateView(); 113 n->updateView();
114 } 114 }
115} 115}
116 116
117void DateNavigatorContainer::updateConfig() 117void DateNavigatorContainer::updateConfig()
118{ 118{
119 mNavigatorView->updateConfig(); 119 mNavigatorView->updateConfig();
120 KDateNavigator *n; 120 KDateNavigator *n;
121 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { 121 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
122 n->updateConfig(); 122 n->updateConfig();
123 } 123 }
124} 124}
125 125
126void DateNavigatorContainer::selectDates( const DateList &dateList ) 126void DateNavigatorContainer::selectDates( const DateList &dateList )
127{ 127{
128 mNavigatorView->selectDates( dateList ); 128 mNavigatorView->selectDates( dateList );
129 setBaseDates(); 129 setBaseDates();
130 if ( mExtraViews.count() ) { 130 if ( mExtraViews.count() ) {
131 KDateNavigator *view = mExtraViews.at( 0 ); 131 KDateNavigator *view = mExtraViews.at( 0 );
132 view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end())); 132 view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end()));
133 view->dayMatrix()->repaint(); 133 view->dayMatrix()->repaint();
134 } 134 }
135} 135}
136 136
137void DateNavigatorContainer::setBaseDates() 137void DateNavigatorContainer::setBaseDates()
138{ 138{
139 KCal::DateList dateList = mNavigatorView->selectedDates(); 139 KCal::DateList dateList = mNavigatorView->selectedDates();
140 if ( dateList.isEmpty() ) { 140 if ( dateList.isEmpty() ) {
141 kdError() << "DateNavigatorContainer::selectDates() empty list." << endl; 141 kdError() << "DateNavigatorContainer::selectDates() empty list." << endl;
142 } 142 }
143 QDate baseDate = dateList.first(); 143 QDate baseDate = dateList.first();
144 KDateNavigator *n; 144 KDateNavigator *n;
145 bool doRepaint = false; // skip first repaint 145 bool doRepaint = false; // skip first repaint
146 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { 146 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
147 baseDate = baseDate.addDays( baseDate.daysInMonth () ); 147 baseDate = baseDate.addDays( baseDate.daysInMonth () - baseDate.day() +1 );
148 n->setBaseDate( baseDate, doRepaint ); 148 n->setBaseDate( baseDate, doRepaint );
149 doRepaint = true; 149 doRepaint = true;
150 } 150 }
151} 151}
152 152
153void DateNavigatorContainer::resizeEvent( QResizeEvent * e ) 153void DateNavigatorContainer::resizeEvent( QResizeEvent * e )
154{ 154{
155#if 0 155#if 0
156 kdDebug(5850) << "DateNavigatorContainer::resizeEvent()" << endl; 156 kdDebug(5850) << "DateNavigatorContainer::resizeEvent()" << endl;
157 kdDebug(5850) << " CURRENT SIZE: " << size() << endl; 157 kdDebug(5850) << " CURRENT SIZE: " << size() << endl;
158 kdDebug(5850) << " MINIMUM SIZEHINT: " << minimumSizeHint() << endl; 158 kdDebug(5850) << " MINIMUM SIZEHINT: " << minimumSizeHint() << endl;
159 kdDebug(5850) << " SIZEHINT: " << sizeHint() << endl; 159 kdDebug(5850) << " SIZEHINT: " << sizeHint() << endl;
160 kdDebug(5850) << " MINIMUM SIZE: " << minimumSize() << endl; 160 kdDebug(5850) << " MINIMUM SIZE: " << minimumSize() << endl;
161#endif 161#endif
162 QSize minSize = mNavigatorView->yourSizeHint(); 162 QSize minSize = mNavigatorView->yourSizeHint();
163 163
164// kdDebug(5850) << " NAVIGATORVIEW minimumSizeHint: " << minSize << endl; 164// kdDebug(5850) << " NAVIGATORVIEW minimumSizeHint: " << minSize << endl;
165 165
166 int verticalCount = size().height() / minSize.height(); 166 int verticalCount = size().height() / minSize.height();
167 int horizontalCount = size().width() / minSize.width(); 167 int horizontalCount = size().width() / minSize.width();
168 //qDebug(" wattdatt %d new %d %d ", size().width() ,e->size().width() , minSize.width() ); 168 //qDebug(" wattdatt %d new %d %d ", size().width() ,e->size().width() , minSize.width() );
169 //qDebug("COUNT %d %d %d %d ", verticalCount, horizontalCount , mVerticalCount, mHorizontalCount ); 169 //qDebug("COUNT %d %d %d %d ", verticalCount, horizontalCount , mVerticalCount, mHorizontalCount );
170 if ( horizontalCount != mHorizontalCount || 170 if ( horizontalCount != mHorizontalCount ||
171 verticalCount != mVerticalCount ) { 171 verticalCount != mVerticalCount ) {
172 uint count = horizontalCount * verticalCount; 172 uint count = horizontalCount * verticalCount;
173 if ( count == 0 ) { 173 if ( count == 0 ) {
174 mNavigatorView->resize( minSize ); 174 mNavigatorView->resize( minSize );
175 return; 175 return;
176 } 176 }
177 177
178 while ( count > ( mExtraViews.count() + 1 ) ) { 178 while ( count > ( mExtraViews.count() + 1 ) ) {
179 KDateNavigator *n = new KDateNavigator( this ); 179 KDateNavigator *n = new KDateNavigator( this );
180 n->setMonthSignalOffset ( mExtraViews.count()+1 ); 180 n->setMonthSignalOffset ( mExtraViews.count()+1 );
181 mExtraViews.append( n ); 181 mExtraViews.append( n );
182 n->setCalendar( mCalendar ); 182 n->setCalendar( mCalendar );
183 setBaseDates(); 183 setBaseDates();
184 connectNavigatorView( n ); 184 connectNavigatorView( n );
185 n->show(); 185 n->show();
186 } 186 }
187 187
188 while ( count < ( mExtraViews.count() + 1 ) ) { 188 while ( count < ( mExtraViews.count() + 1 ) ) {
189 mExtraViews.removeLast(); 189 mExtraViews.removeLast();
190 } 190 }
191 191
192 mHorizontalCount = horizontalCount; 192 mHorizontalCount = horizontalCount;
193 mVerticalCount = verticalCount; 193 mVerticalCount = verticalCount;
194 } 194 }
195 195
196 int height = size().height() / verticalCount; 196 int height = size().height() / verticalCount;
197 int width = size().width() / horizontalCount; 197 int width = size().width() / horizontalCount;
198 198
199 NavigatorBar *bar = mNavigatorView->navigatorBar(); 199 NavigatorBar *bar = mNavigatorView->navigatorBar();
200 if ( horizontalCount > 1 ) bar->showButtons( true, false ); 200 if ( horizontalCount > 1 ) bar->showButtons( true, false );
201 else bar->showButtons( true, true ); 201 else bar->showButtons( true, true );
202 202
203 mNavigatorView->setGeometry(0, 203 mNavigatorView->setGeometry(0,
204 0, width, height ); 204 0, width, height );
205 for( uint i = 0; i < mExtraViews.count(); ++i ) { 205 for( uint i = 0; i < mExtraViews.count(); ++i ) {
206 int x = ( i + 1 ) % horizontalCount; 206 int x = ( i + 1 ) % horizontalCount;
207 int y = ( i + 1 ) / horizontalCount; 207 int y = ( i + 1 ) / horizontalCount;
208 208
209 KDateNavigator *view = mExtraViews.at( i ); 209 KDateNavigator *view = mExtraViews.at( i );
210 bar = view->navigatorBar(); 210 bar = view->navigatorBar();
211 if ( y > 0 ) bar->showButtons( false, false ); 211 if ( y > 0 ) bar->showButtons( false, false );
212 else { 212 else {
213 if ( x + 1 == horizontalCount ) bar->showButtons( false, true ); 213 if ( x + 1 == horizontalCount ) bar->showButtons( false, true );
214 else bar->showButtons( false, false ); 214 else bar->showButtons( false, false );
215 } 215 }
216 view->setGeometry( x * width, 216 view->setGeometry( x * width,
217 y * height, width, height ); 217 y * height, width, height );
218 } 218 }
219} 219}
220 220
221QSize DateNavigatorContainer::minimumSizeHint() const 221QSize DateNavigatorContainer::minimumSizeHint() const
222{ 222{
223 return mNavigatorView->minimumSizeHint(); 223 return mNavigatorView->minimumSizeHint();
224} 224}
225 225
226QSize DateNavigatorContainer::sizeHint() const 226QSize DateNavigatorContainer::sizeHint() const
227{ 227{
228 return mNavigatorView->sizeHint(); 228 return mNavigatorView->sizeHint();
229} 229}
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp
index 1cde616..619ae39 100644
--- a/korganizer/kodaymatrix.cpp
+++ b/korganizer/kodaymatrix.cpp
@@ -1,768 +1,798 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Eitzenberger Thomas <thomas.eitzenberger@siemens.at> 3 Copyright (c) 2001 Eitzenberger Thomas <thomas.eitzenberger@siemens.at>
4 Parts of the source code have been copied from kdpdatebutton.cpp 4 Parts of the source code have been copied from kdpdatebutton.cpp
5 5
6 This program is free software; you can redistribute it and/or modify 6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by 7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or 8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version. 9 (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15 15
16 You should have received a copy of the GNU General Public License 16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software 17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 19
20 As a special exception, permission is given to link this program 20 As a special exception, permission is given to link this program
21 with any edition of Qt, and distribute the resulting executable, 21 with any edition of Qt, and distribute the resulting executable,
22 without including the source ode for Qt in the source distribution. 22 without including the source ode for Qt in the source distribution.
23*/ 23*/
24 24
25#include <qevent.h> 25#include <qevent.h>
26#include <qpainter.h> 26#include <qpainter.h>
27#include <qptrlist.h> 27#include <qptrlist.h>
28#include <qtimer.h> 28#include <qtimer.h>
29#include <qwhatsthis.h> 29#include <qwhatsthis.h>
30 30
31#include <kglobal.h> 31#include <kglobal.h>
32#include <kdebug.h> 32#include <kdebug.h>
33#include <klocale.h> 33#include <klocale.h>
34 34
35#include <libkcal/vcaldrag.h> 35#include <libkcal/vcaldrag.h>
36#include <libkcal/icaldrag.h> 36#include <libkcal/icaldrag.h>
37#include <libkcal/dndfactory.h> 37#include <libkcal/dndfactory.h>
38#include <libkcal/calendarresources.h> 38#include <libkcal/calendarresources.h>
39#include <libkcal/resourcecalendar.h> 39#include <libkcal/resourcecalendar.h>
40#include <kresources/resourceselectdialog.h> 40#include <kresources/resourceselectdialog.h>
41 41
42#include <kcalendarsystem.h> 42#include <kcalendarsystem.h>
43 43
44#ifndef KORG_NOPLUGINS 44#ifndef KORG_NOPLUGINS
45#include "kocore.h" 45#include "kocore.h"
46#endif 46#endif
47#include "koprefs.h" 47#include "koprefs.h"
48#include "koglobals.h" 48#include "koglobals.h"
49 49
50#include "kodaymatrix.h" 50#include "kodaymatrix.h"
51 51
52// ============================================================================ 52// ============================================================================
53// D Y N A M I C T I P 53// D Y N A M I C T I P
54// ============================================================================ 54// ============================================================================
55 55
56DynamicTip::DynamicTip( QWidget * parent ) 56DynamicTip::DynamicTip( QWidget * parent )
57 : QToolTip( parent ) 57 : QToolTip( parent )
58{ 58{
59 matrix = (KODayMatrix*)parent; 59 matrix = (KODayMatrix*)parent;
60} 60}
61 61
62class KODaymatrixWhatsThis :public QWhatsThis 62class KODaymatrixWhatsThis :public QWhatsThis
63{ 63{
64public: 64public:
65 KODaymatrixWhatsThis( KODayMatrix* view ) : QWhatsThis( view ),_view (view) { }; 65 KODaymatrixWhatsThis( KODayMatrix* view ) : QWhatsThis( view ),_view (view) { };
66 66
67protected: 67protected:
68 virtual QString text( const QPoint& p ) 68 virtual QString text( const QPoint& p )
69 { 69 {
70 return _view->getWhatsThisText( p ) ; 70 return _view->getWhatsThisText( p ) ;
71 } 71 }
72private: 72private:
73 KODayMatrix * _view; 73 KODayMatrix * _view;
74}; 74};
75 75
76void DynamicTip::maybeTip( const QPoint &pos ) 76void DynamicTip::maybeTip( const QPoint &pos )
77{ 77{
78 //calculate which cell of the matrix the mouse is in 78 //calculate which cell of the matrix the mouse is in
79 QRect sz = matrix->frameRect(); 79 QRect sz = matrix->frameRect();
80 int dheight = sz.height()*7 / 42; 80 int dheight = sz.height()*7 / 42;
81 int dwidth = sz.width() / 7; 81 int dwidth = sz.width() / 7;
82 int row = pos.y()/dheight; 82 int row = pos.y()/dheight;
83 int col = pos.x()/dwidth; 83 int col = pos.x()/dwidth;
84 84
85 QRect rct(col*dwidth, row*dheight, dwidth, dheight); 85 QRect rct(col*dwidth, row*dheight, dwidth, dheight);
86 86
87// kdDebug() << "DynamicTip::maybeTip matrix cell index [" << 87// kdDebug() << "DynamicTip::maybeTip matrix cell index [" <<
88// col << "][" << row << "] => " <<(col+row*7) << endl; 88// col << "][" << row << "] => " <<(col+row*7) << endl;
89 89
90 //show holiday names only 90 //show holiday names only
91 QString str = matrix->getHolidayLabel(col+row*7); 91 QString str = matrix->getHolidayLabel(col+row*7);
92 if (str.isEmpty()) return; 92 if (str.isEmpty()) return;
93 tip(rct, str); 93 tip(rct, str);
94} 94}
95 95
96 96
97// ============================================================================ 97// ============================================================================
98// K O D A Y M A T R I X 98// K O D A Y M A T R I X
99// ============================================================================ 99// ============================================================================
100 100
101const int KODayMatrix::NOSELECTION = -1000; 101const int KODayMatrix::NOSELECTION = -1000;
102const int KODayMatrix::NUMDAYS = 42; 102const int KODayMatrix::NUMDAYS = 42;
103 103
104KODayMatrix::KODayMatrix( QWidget *parent, const char *name ) 104KODayMatrix::KODayMatrix( QWidget *parent, const char *name )
105 : QFrame( parent, name ), mCalendar( 0 ) 105 : QFrame( parent, name ), mCalendar( 0 )
106 106
107#if 0 107#if 0
108KODayMatrix::KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const char *name) : 108KODayMatrix::KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const char *name) :
109 QFrame(parent, name) 109 QFrame(parent, name)
110#endif 110#endif
111{ 111{
112 new KODaymatrixWhatsThis(this); 112 new KODaymatrixWhatsThis(this);
113 mPendingUpdateBeforeRepaint = false; 113 mPendingUpdateBeforeRepaint = false;
114 mouseDown = false; 114 mouseDown = false;
115 // initialize dynamic arrays 115 // initialize dynamic arrays
116 bDays.resize ( NUMDAYS ); 116 bDays.resize ( NUMDAYS );
117 days = new QDate[NUMDAYS]; 117 days = new QDate[NUMDAYS];
118 daylbls = new QString[NUMDAYS]; 118 daylbls = new QString[NUMDAYS];
119 events = new int[NUMDAYS]; 119 events = new int[NUMDAYS];
120 mToolTip = new DynamicTip(this); 120 mToolTip = new DynamicTip(this);
121 121
122 // set default values used for drawing the matrix 122 // set default values used for drawing the matrix
123 mDefaultBackColor = palette().active().base(); 123 mDefaultBackColor = palette().active().base();
124 mDefaultTextColor = palette().active().foreground(); 124 mDefaultTextColor = palette().active().foreground();
125 mDefaultTextColorShaded = getShadedColor(mDefaultTextColor); 125 mDefaultTextColorShaded = getShadedColor(mDefaultTextColor);
126 mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor); 126 mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor);
127 mSelectedDaysColor = QColor("white"); 127 mSelectedDaysColor = QColor("white");
128 mTodayMarginWidth = 2; 128 mTodayMarginWidth = 2;
129 mSelEnd = mSelStart = NOSELECTION; 129 mSelEnd = mSelStart = NOSELECTION;
130 130
131 setAcceptDrops(true); 131 setAcceptDrops(true);
132 //setFont( QFont("Arial", 10) ); 132 //setFont( QFont("Arial", 10) );
133 133
134 mUpdateTimer = new QTimer( this ); 134 mUpdateTimer = new QTimer( this );
135 connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() )); 135 connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() ));
136 mRepaintTimer = new QTimer( this ); 136 mRepaintTimer = new QTimer( this );
137 connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() )); 137 connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() ));
138 mDayChanged = false; 138 mDayChanged = false;
139 updateView(); 139 updateView();
140} 140}
141QString KODayMatrix::getWhatsThisText( QPoint p ) 141QString KODayMatrix::getWhatsThisText( QPoint p )
142{ 142{
143 143
144 int tmp = getDayIndexFrom(p.x(), p.y()); 144 int tmp = getDayIndexFrom(p.x(), p.y());
145 if ( tmp < 0 || tmp > NUMDAYS-1 || !mCalendar ) 145 if ( tmp < 0 || tmp > NUMDAYS-1 || !mCalendar )
146 return QString(); 146 return QString();
147 QDate mDate = days[tmp]; 147 QDate mDate = days[tmp];
148 QPtrList<Event> eventlist = mCalendar->events(mDate); 148 QPtrList<Event> eventlist = mCalendar->events(mDate);
149 Event *event; 149 Event *event;
150 QStringList mToolTip; 150 QStringList mToolTip;
151 for(event=eventlist.first();event != 0;event=eventlist.next()) { 151 for(event=eventlist.first();event != 0;event=eventlist.next()) {
152 QString mToolTipText; 152 QString mToolTipText;
153 QString text; 153 QString text;
154 int multiday = 0;// 1 = start, 2 = midddle, 3 = end day 154 int multiday = 0;// 1 = start, 2 = midddle, 3 = end day
155 if (event->isMultiDay()) { 155 if (event->isMultiDay()) {
156 QString prefix = "<->";multiday = 2; 156 QString prefix = "<->";multiday = 2;
157 QString time; 157 QString time;
158 if ( event->doesRecur() ) { 158 if ( event->doesRecur() ) {
159 if ( event->recursOn( mDate) ) { 159 if ( event->recursOn( mDate) ) {
160 prefix ="->" ;multiday = 1; 160 prefix ="->" ;multiday = 1;
161 } 161 }
162 else { 162 else {
163 int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); 163 int days = event->dtStart().date().daysTo ( event->dtEnd().date() );
164 if ( event->recursOn( mDate.addDays( -days)) ) { 164 if ( event->recursOn( mDate.addDays( -days)) ) {
165 prefix ="<-" ;multiday = 3; 165 prefix ="<-" ;multiday = 3;
166 } 166 }
167 } 167 }
168 } else { 168 } else {
169 if (mDate == event->dtStart().date()) { 169 if (mDate == event->dtStart().date()) {
170 prefix ="->" ;multiday = 1; 170 prefix ="->" ;multiday = 1;
171 } else if (mDate == event->dtEnd().date()) { 171 } else if (mDate == event->dtEnd().date()) {
172 prefix ="<-" ;multiday = 3; 172 prefix ="<-" ;multiday = 3;
173 } 173 }
174 } 174 }
175 if ( !event->doesFloat() ) { 175 if ( !event->doesFloat() ) {
176 if ( mDate == event->dtStart().date () ) 176 if ( mDate == event->dtStart().date () )
177 time = KGlobal::locale()->formatTime(event->dtStart().time())+" "; 177 time = KGlobal::locale()->formatTime(event->dtStart().time())+" ";
178 else if ( mDate == event->dtEnd().date () ) 178 else if ( mDate == event->dtEnd().date () )
179 time = KGlobal::locale()->formatTime(event->dtEnd().time())+" "; 179 time = KGlobal::locale()->formatTime(event->dtEnd().time())+" ";
180 180
181 } 181 }
182 text = time + event->summary(); 182 text = time + event->summary();
183 mToolTipText += prefix + text; 183 mToolTipText += prefix + text;
184 } else { 184 } else {
185 if (event->doesFloat()) { 185 if (event->doesFloat()) {
186 text = event->summary(); 186 text = event->summary();
187 mToolTipText += text; 187 mToolTipText += text;
188 } 188 }
189 else { 189 else {
190 text = KGlobal::locale()->formatTime(event->dtStart().time()); 190 text = KGlobal::locale()->formatTime(event->dtStart().time());
191 text += " " + event->summary(); 191 text += " " + event->summary();
192 mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); 192 mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary();
193 } 193 }
194 } 194 }
195 mToolTip.append( mToolTipText ); 195 mToolTip.append( mToolTipText );
196 } 196 }
197 mToolTip.sort(); 197 mToolTip.sort();
198 return "<b>"+KGlobal::locale()->formatDate(days[tmp]) + "</b><br>" + mToolTip.join("<br>"); 198 return "<b>"+KGlobal::locale()->formatDate(days[tmp]) + "</b><br>" + mToolTip.join("<br>");
199} 199}
200void KODayMatrix::setCalendar( Calendar *cal ) 200void KODayMatrix::setCalendar( Calendar *cal )
201{ 201{
202 mCalendar = cal; 202 mCalendar = cal;
203 203
204 setAcceptDrops( mCalendar ); 204 setAcceptDrops( mCalendar );
205 205
206 updateEvents(); 206 updateEvents();
207} 207}
208 208
209QColor KODayMatrix::getShadedColor(QColor color) 209QColor KODayMatrix::getShadedColor(QColor color)
210{ 210{
211 QColor shaded; 211 QColor shaded;
212 int h=0; 212 int h=0;
213 int s=0; 213 int s=0;
214 int v=0; 214 int v=0;
215 color.hsv(&h,&s,&v); 215 color.hsv(&h,&s,&v);
216 s = s/4; 216 s = s/4;
217 v = 192+v/4; 217 v = 192+v/4;
218 shaded.setHsv(h,s,v); 218 shaded.setHsv(h,s,v);
219 219
220 return shaded; 220 return shaded;
221} 221}
222 222
223KODayMatrix::~KODayMatrix() 223KODayMatrix::~KODayMatrix()
224{ 224{
225 delete [] days; 225 delete [] days;
226 delete [] daylbls; 226 delete [] daylbls;
227 delete [] events; 227 delete [] events;
228 delete mToolTip; 228 delete mToolTip;
229} 229}
230 230
231/* 231/*
232void KODayMatrix::setStartDate(QDate start) 232void KODayMatrix::setStartDate(QDate start)
233{ 233{
234 updateView(start); 234 updateView(start);
235} 235}
236*/ 236*/
237 237
238void KODayMatrix::addSelectedDaysTo(DateList& selDays) 238void KODayMatrix::addSelectedDaysTo(DateList& selDays)
239{ 239{
240 240
241 if (mSelStart == NOSELECTION) { 241 if (mSelStart == NOSELECTION) {
242 return; 242 return;
243 } 243 }
244 244
245 //cope with selection being out of matrix limits at top (< 0) 245 //cope with selection being out of matrix limits at top (< 0)
246 int i0 = mSelStart; 246 int i0 = mSelStart;
247 if (i0 < 0) { 247 if (i0 < 0) {
248 for (int i = i0; i < 0; i++) { 248 for (int i = i0; i < 0; i++) {
249 selDays.append(days[0].addDays(i)); 249 selDays.append(days[0].addDays(i));
250 } 250 }
251 i0 = 0; 251 i0 = 0;
252 } 252 }
253 253
254 //cope with selection being out of matrix limits at bottom (> NUMDAYS-1) 254 //cope with selection being out of matrix limits at bottom (> NUMDAYS-1)
255 if (mSelEnd > NUMDAYS-1) { 255 if (mSelEnd > NUMDAYS-1) {
256 for (int i = i0; i <= NUMDAYS-1; i++) { 256 for (int i = i0; i <= NUMDAYS-1; i++) {
257 selDays.append(days[i]); 257 selDays.append(days[i]);
258 } 258 }
259 for (int i = NUMDAYS; i < mSelEnd; i++) { 259 for (int i = NUMDAYS; i < mSelEnd; i++) {
260 selDays.append(days[0].addDays(i)); 260 selDays.append(days[0].addDays(i));
261 } 261 }
262 262
263 // apply normal routine to selection being entirely within matrix limits 263 // apply normal routine to selection being entirely within matrix limits
264 } else { 264 } else {
265 for (int i = i0; i <= mSelEnd; i++) { 265 for (int i = i0; i <= mSelEnd; i++) {
266 selDays.append(days[i]); 266 selDays.append(days[i]);
267 } 267 }
268 } 268 }
269} 269}
270 270
271void KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end) 271void KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end)
272{ 272{
273 mSelStart = startdate.daysTo(start); 273 mSelStart = startdate.daysTo(start);
274 if ( mSelStart < 0 )
275 mSelStart = 0;
274 mSelEnd = startdate.daysTo(end); 276 mSelEnd = startdate.daysTo(end);
277 if ( mSelEnd < 0 )
278 clearSelection();
275} 279}
276void KODayMatrix::clearSelection() 280void KODayMatrix::clearSelection()
277{ 281{
278 mSelEnd = mSelStart = NOSELECTION; 282 mSelEnd = mSelStart = NOSELECTION;
279} 283}
280 284
281 285
282void KODayMatrix::recalculateToday() 286void KODayMatrix::recalculateToday()
283{ 287{
284 today = -1; 288 today = -1;
285 for (int i=0; i<NUMDAYS; i++) { 289 for (int i=0; i<NUMDAYS; i++) {
286 events[i] = 0; 290 events[i] = 0;
287 days[i] = startdate.addDays(i); 291 days[i] = startdate.addDays(i);
288 daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] )); 292 daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] ));
289 293
290 // if today is in the currently displayed month, hilight today 294 // if today is in the currently displayed month, hilight today
291 if (days[i].year() == QDate::currentDate().year() && 295 if (days[i].year() == QDate::currentDate().year() &&
292 days[i].month() == QDate::currentDate().month() && 296 days[i].month() == QDate::currentDate().month() &&
293 days[i].day() == QDate::currentDate().day()) { 297 days[i].day() == QDate::currentDate().day()) {
294 today = i; 298 today = i;
295 } 299 }
296 } 300 }
297 // qDebug(QString("Today is visible at %1.").arg(today)); 301 // qDebug(QString("Today is visible at %1.").arg(today));
298} 302}
299 303
300void KODayMatrix::updateView() 304void KODayMatrix::updateView()
301{ 305{
302 updateView(startdate); 306 updateView(startdate);
303} 307}
304void KODayMatrix::repaintViewTimed() 308void KODayMatrix::repaintViewTimed()
305{ 309{
306 mRepaintTimer->stop(); 310 mRepaintTimer->stop();
307 repaint(false); 311 repaint(false);
308} 312}
309void KODayMatrix::updateViewTimed() 313void KODayMatrix::updateViewTimed()
310{ 314{
311 mUpdateTimer->stop(); 315 mUpdateTimer->stop();
312 if ( !mCalendar ) { 316 if ( !mCalendar ) {
313 qDebug("NOT CAL "); 317 qDebug("NOT CAL ");
314 return; 318 return;
315 } 319 }
316 //qDebug("KODayMatrix::updateViewTimed "); 320 //qDebug("KODayMatrix::updateViewTimed ");
317 for(int i = 0; i < NUMDAYS; i++) { 321 for(int i = 0; i < NUMDAYS; i++) {
318 // if events are set for the day then remember to draw it bold 322 // if events are set for the day then remember to draw it bold
319 QPtrList<Event> eventlist = mCalendar->events(days[i]); 323 QPtrList<Event> eventlist = mCalendar->events(days[i]);
320 Event *event; 324 Event *event;
321 int numEvents = eventlist.count(); 325 int numEvents = eventlist.count();
322 QString holiStr = ""; 326 QString holiStr = "";
323 bDays.clearBit(i); 327 bDays.clearBit(i);
324 for(event=eventlist.first();event != 0;event=eventlist.next()) { 328 for(event=eventlist.first();event != 0;event=eventlist.next()) {
325 ushort recurType = event->recurrence()->doesRecur(); 329 ushort recurType = event->recurrence()->doesRecur();
326 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || 330 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) ||
327 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { 331 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) {
328 numEvents--; 332 numEvents--;
329 } 333 }
330 if ( event->categories().contains( i18n("Holiday") ) || event->categories().contains( "Holiday" )) { 334 if ( event->categories().contains( i18n("Holiday") ) || event->categories().contains( "Holiday" )) {
331 if ( !holiStr.isEmpty() ) 335 if ( !holiStr.isEmpty() )
332 holiStr += "\n"; 336 holiStr += "\n";
333 holiStr += event->summary(); 337 holiStr += event->summary();
334 } 338 }
335 if ( event->categories().contains( i18n("Birthday") ) || event->categories().contains( "Birthday" )) { 339 if ( event->categories().contains( i18n("Birthday") ) || event->categories().contains( "Birthday" )) {
336 if ( !holiStr.isEmpty() ) 340 if ( !holiStr.isEmpty() )
337 holiStr += "\n"; 341 holiStr += "\n";
338 holiStr += event->summary(); 342 holiStr += event->summary();
339 bDays.setBit(i); 343 bDays.setBit(i);
340 } 344 }
341 } 345 }
342 events[i] = numEvents; 346 events[i] = numEvents;
343 //if it is a holy day then draw it red. Sundays are consider holidays, too 347 //if it is a holy day then draw it red. Sundays are consider holidays, too
344 if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) || 348 if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) ||
345 !holiStr.isEmpty()) { 349 !holiStr.isEmpty()) {
346 mHolidays[i] = holiStr; 350 mHolidays[i] = holiStr;
347 } else { 351 } else {
348 mHolidays[i] = QString::null; 352 mHolidays[i] = QString::null;
349 } 353 }
350 } 354 }
351 if ( ! mPendingUpdateBeforeRepaint ) 355 if ( ! mPendingUpdateBeforeRepaint )
352 repaint(false); 356 repaint(false);
353} 357}
354void KODayMatrix::updateView(QDate actdate) 358void KODayMatrix::updateView(QDate actdate)
355{ 359{
356 360
357 if ( ! actdate.isValid() ) { 361 if ( ! actdate.isValid() ) {
358 //qDebug("date not valid "); 362 //qDebug("date not valid ");
359 return; 363 return;
360 } 364 }
361 mDayChanged = false; 365 mDayChanged = false;
362 //flag to indicate if the starting day of the matrix has changed by this call 366 //flag to indicate if the starting day of the matrix has changed by this call
363 //mDayChanged = false; 367 //mDayChanged = false;
364 // if a new startdate is to be set then apply Cornelius's calculation 368 // if a new startdate is to be set then apply Cornelius's calculation
365 // of the first day to be shown 369 // of the first day to be shown
366 if (actdate != startdate) { 370 if (actdate != startdate) {
367 // reset index of selection according to shift of starting date from startdate to actdate 371 // reset index of selection according to shift of starting date from startdate to actdate
368 if (mSelStart != NOSELECTION) { 372 if (mSelStart != NOSELECTION) {
369 int tmp = actdate.daysTo(startdate); 373 int tmp = actdate.daysTo(startdate);
370 //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl; 374 //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl;
371 // shift selection if new one would be visible at least partly ! 375 // shift selection if new one would be visible at least partly !
372 376
373 if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) { 377 if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) {
374 // nested if is required for next X display pushed from a different month - correction required 378 // nested if is required for next X display pushed from a different month - correction required
375 // otherwise, for month forward and backward, it must be avoided 379 // otherwise, for month forward and backward, it must be avoided
376 if( mSelStart > NUMDAYS || mSelStart < 0 ) 380 if( mSelStart > NUMDAYS || mSelStart < 0 )
377 mSelStart = mSelStart + tmp; 381 mSelStart = mSelStart + tmp;
378 if( mSelEnd > NUMDAYS || mSelEnd < 0 ) 382 if( mSelEnd > NUMDAYS || mSelEnd < 0 )
379 mSelEnd = mSelEnd + tmp; 383 mSelEnd = mSelEnd + tmp;
380 } 384 }
381 } 385 }
382 startdate = actdate; 386 startdate = actdate;
383 mDayChanged = true; 387 mDayChanged = true;
384 recalculateToday(); 388 recalculateToday();
385 } 389 }
386 //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() ); 390 //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() );
387 if ( !isVisible() ) { 391 if ( !isVisible() ) {
388 mPendingUpdateBeforeRepaint = true; 392 mPendingUpdateBeforeRepaint = true;
389 } else { 393 } else {
390#ifdef DESKTOP_VERSION 394#ifdef DESKTOP_VERSION
391 //mRepaintTimer->start( 150 ); 395 //mRepaintTimer->start( 150 );
392 mUpdateTimer->start( 150 ); 396 mUpdateTimer->start( 150 );
393#else 397#else
394 mRepaintTimer->start( 350 ); 398 mRepaintTimer->start( 350 );
395 mUpdateTimer->start( 1200 ); 399 mUpdateTimer->start( 1200 );
396#endif 400#endif
397 } 401 }
398} 402}
399void KODayMatrix::updateEvents() 403void KODayMatrix::updateEvents()
400{ 404{
401 if ( !mCalendar ) return; 405 if ( !mCalendar ) return;
402 406
403 for( int i = 0; i < NUMDAYS; i++ ) { 407 for( int i = 0; i < NUMDAYS; i++ ) {
404 // if events are set for the day then remember to draw it bold 408 // if events are set for the day then remember to draw it bold
405 QPtrList<Event> eventlist = mCalendar->events( days[ i ] ); 409 QPtrList<Event> eventlist = mCalendar->events( days[ i ] );
406 int numEvents = eventlist.count(); 410 int numEvents = eventlist.count();
407 Event *event; 411 Event *event;
408 for( event = eventlist.first(); event != 0;event=eventlist.next()) { 412 for( event = eventlist.first(); event != 0;event=eventlist.next()) {
409 ushort recurType = event->doesRecur(); 413 ushort recurType = event->doesRecur();
410 414
411 if ( ( recurType == Recurrence::rDaily && 415 if ( ( recurType == Recurrence::rDaily &&
412 !KOPrefs::instance()->mDailyRecur ) || 416 !KOPrefs::instance()->mDailyRecur ) ||
413 ( recurType == Recurrence::rWeekly && 417 ( recurType == Recurrence::rWeekly &&
414 !KOPrefs::instance()->mWeeklyRecur ) ) { 418 !KOPrefs::instance()->mWeeklyRecur ) ) {
415 numEvents--; 419 numEvents--;
416 } 420 }
417 } 421 }
418 events[ i ] = numEvents; 422 events[ i ] = numEvents;
419 } 423 }
420} 424}
421 425
422const QDate& KODayMatrix::getDate(int offset) 426const QDate& KODayMatrix::getDate(int offset)
423{ 427{
424 if (offset < 0 || offset > NUMDAYS-1) { 428 if (offset < 0 || offset > NUMDAYS-1) {
425 qDebug("Wrong offset2 "); 429 qDebug("Wrong offset2 ");
426 return days[0]; 430 return days[0];
427 } 431 }
428 return days[offset]; 432 return days[offset];
429} 433}
430 434
431QString KODayMatrix::getHolidayLabel(int offset) 435QString KODayMatrix::getHolidayLabel(int offset)
432{ 436{
433 if (offset < 0 || offset > NUMDAYS-1) { 437 if (offset < 0 || offset > NUMDAYS-1) {
434 qDebug("Wrong offset1 "); 438 qDebug("Wrong offset1 ");
435 return 0; 439 return 0;
436 } 440 }
437 return mHolidays[offset]; 441 return mHolidays[offset];
438} 442}
439 443
440int KODayMatrix::getDayIndexFrom(int x, int y) 444int KODayMatrix::getDayIndexFrom(int x, int y)
441{ 445{
442 return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ? 446 return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ?
443 6 - x/daysize.width() : x/daysize.width()); 447 6 - x/daysize.width() : x/daysize.width());
444} 448}
445 449
446// ---------------------------------------------------------------------------- 450// ----------------------------------------------------------------------------
447// M O U S E E V E N T H A N D L I N G 451// M O U S E E V E N T H A N D L I N G
448// ---------------------------------------------------------------------------- 452// ----------------------------------------------------------------------------
449 453
450void KODayMatrix::mousePressEvent (QMouseEvent* e) 454void KODayMatrix::mousePressEvent (QMouseEvent* e)
451{ 455{
452 456
453 if ( e->button() == LeftButton ) 457 if ( e->button() == LeftButton )
454 mouseDown = true; 458 mouseDown = true;
455 mSelStart = getDayIndexFrom(e->x(), e->y()); 459 mSelStart = getDayIndexFrom(e->x(), e->y());
456 if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1; 460 if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1;
457 mSelInit = mSelStart; 461 mSelInit = mSelStart;
458} 462}
459 463
460void KODayMatrix::mouseReleaseEvent (QMouseEvent* e) 464void KODayMatrix::mouseReleaseEvent (QMouseEvent* e)
461{ 465{
462 if ( e->button() == LeftButton ) 466 if ( e->button() == LeftButton )
463 if ( ! mouseDown ) { 467 if ( ! mouseDown ) {
464 return; 468 return;
465 } 469 }
466 else 470 else
467 mouseDown = false; 471 mouseDown = false;
468 int tmp = getDayIndexFrom(e->x(), e->y()); 472 int tmp = getDayIndexFrom(e->x(), e->y());
469 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; 473 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1;
470 474
471 if (mSelInit > tmp) { 475 if (mSelInit > tmp) {
472 mSelEnd = mSelInit; 476 mSelEnd = mSelInit;
473 if (tmp != mSelStart) { 477 if (tmp != mSelStart) {
474 mSelStart = tmp; 478 mSelStart = tmp;
475 repaint(false); 479 repaint(false);
476 } 480 }
477 } else { 481 } else {
478 mSelStart = mSelInit; 482 mSelStart = mSelInit;
479 483
480 //repaint only if selection has changed 484 //repaint only if selection has changed
481 if (tmp != mSelEnd) { 485 if (tmp != mSelEnd) {
482 mSelEnd = tmp; 486 mSelEnd = tmp;
483 repaint(false); 487 repaint(false);
484 } 488 }
485 } 489 }
486 490
487 DateList daylist; 491 DateList daylist;
488 if ( mSelStart < 0 ) 492 if ( mSelStart < 0 )
489 mSelStart = 0; 493 mSelStart = 0;
490 for (int i = mSelStart; i <= mSelEnd; i++) { 494 for (int i = mSelStart; i <= mSelEnd; i++) {
491 daylist.append(days[i]); 495 daylist.append(days[i]);
492 } 496 }
493 emit selected((const DateList)daylist); 497 emit selected((const DateList)daylist);
494 498
495} 499}
496 500
497void KODayMatrix::mouseMoveEvent (QMouseEvent* e) 501void KODayMatrix::mouseMoveEvent (QMouseEvent* e)
498{ 502{
499 if ( ! mouseDown ) { 503 if ( ! mouseDown ) {
500 return; 504 return;
501 } 505 }
502 int tmp = getDayIndexFrom(e->x(), e->y()); 506 int tmp = getDayIndexFrom(e->x(), e->y());
503 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; 507 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1;
504 508
505 if (mSelInit > tmp) { 509 if (mSelInit > tmp) {
506 mSelEnd = mSelInit; 510 mSelEnd = mSelInit;
507 if (tmp != mSelStart) { 511 if (tmp != mSelStart) {
508 mSelStart = tmp; 512 mSelStart = tmp;
509 repaint(false); 513 repaint(false);
510 } 514 }
511 } else { 515 } else {
512 mSelStart = mSelInit; 516 mSelStart = mSelInit;
513 517
514 //repaint only if selection has changed 518 //repaint only if selection has changed
515 if (tmp != mSelEnd) { 519 if (tmp != mSelEnd) {
516 mSelEnd = tmp; 520 mSelEnd = tmp;
517 repaint(false); 521 repaint(false);
518 } 522 }
519 } 523 }
520} 524}
521 525
522// ---------------------------------------------------------------------------- 526// ----------------------------------------------------------------------------
523// D R A G ' N D R O P H A N D L I N G 527// D R A G ' N D R O P H A N D L I N G
524// ---------------------------------------------------------------------------- 528// ----------------------------------------------------------------------------
525 529
526void KODayMatrix::dragEnterEvent(QDragEnterEvent *e) 530void KODayMatrix::dragEnterEvent(QDragEnterEvent *e)
527{ 531{
528#ifndef KORG_NODND 532#ifndef KORG_NODND
529 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { 533 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
530 e->ignore(); 534 e->ignore();
531 return; 535 return;
532 } 536 }
533 537
534 // some visual feedback 538 // some visual feedback
535// oldPalette = palette(); 539// oldPalette = palette();
536// setPalette(my_HilitePalette); 540// setPalette(my_HilitePalette);
537// update(); 541// update();
538#endif 542#endif
539} 543}
540 544
541void KODayMatrix::dragMoveEvent(QDragMoveEvent *e) 545void KODayMatrix::dragMoveEvent(QDragMoveEvent *e)
542{ 546{
543#ifndef KORG_NODND 547#ifndef KORG_NODND
544 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { 548 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
545 e->ignore(); 549 e->ignore();
546 return; 550 return;
547 } 551 }
548 552
549 e->accept(); 553 e->accept();
550#endif 554#endif
551} 555}
552 556
553void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/) 557void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/)
554{ 558{
555#ifndef KORG_NODND 559#ifndef KORG_NODND
556// setPalette(oldPalette); 560// setPalette(oldPalette);
557// update(); 561// update();
558#endif 562#endif
559} 563}
560 564
561void KODayMatrix::dropEvent(QDropEvent *e) 565void KODayMatrix::dropEvent(QDropEvent *e)
562{ 566{
563#ifndef KORG_NODND 567#ifndef KORG_NODND
564// kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl; 568// kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl;
565 569
566 if (!mCalendar || !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { 570 if (!mCalendar || !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
567 e->ignore(); 571 e->ignore();
568 return; 572 return;
569 } 573 }
570 574
571 DndFactory factory( mCalendar ); 575 DndFactory factory( mCalendar );
572 Event *event = factory.createDrop(e); 576 Event *event = factory.createDrop(e);
573 577
574 if (event) { 578 if (event) {
575 e->acceptAction(); 579 e->acceptAction();
576 580
577 Event *existingEvent = mCalendar->event(event->uid()); 581 Event *existingEvent = mCalendar->event(event->uid());
578 582
579 if(existingEvent) { 583 if(existingEvent) {
580 // uniquify event 584 // uniquify event
581 event->recreate(); 585 event->recreate();
582/* 586/*
583 KMessageBox::sorry(this, 587 KMessageBox::sorry(this,
584 i18n("Event already exists in this calendar."), 588 i18n("Event already exists in this calendar."),
585 i18n("Drop Event")); 589 i18n("Drop Event"));
586 delete event; 590 delete event;
587 return; 591 return;
588*/ 592*/
589 } 593 }
590// kdDebug() << "Drop new Event" << endl; 594// kdDebug() << "Drop new Event" << endl;
591 // Adjust date 595 // Adjust date
592 QDateTime start = event->dtStart(); 596 QDateTime start = event->dtStart();
593 QDateTime end = event->dtEnd(); 597 QDateTime end = event->dtEnd();
594 int duration = start.daysTo(end); 598 int duration = start.daysTo(end);
595 int idx = getDayIndexFrom(e->pos().x(), e->pos().y()); 599 int idx = getDayIndexFrom(e->pos().x(), e->pos().y());
596 600
597 start.setDate(days[idx]); 601 start.setDate(days[idx]);
598 end.setDate(days[idx].addDays(duration)); 602 end.setDate(days[idx].addDays(duration));
599 603
600 event->setDtStart(start); 604 event->setDtStart(start);
601 event->setDtEnd(end); 605 event->setDtEnd(end);
602 mCalendar->addEvent(event); 606 mCalendar->addEvent(event);
603 607
604 emit eventDropped(event); 608 emit eventDropped(event);
605 } else { 609 } else {
606// kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl; 610// kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl;
607 e->ignore(); 611 e->ignore();
608 } 612 }
609#endif 613#endif
610} 614}
611 615
612// ---------------------------------------------------------------------------- 616// ----------------------------------------------------------------------------
613// P A I N T E V E N T H A N D L I N G 617// P A I N T E V E N T H A N D L I N G
614// ---------------------------------------------------------------------------- 618// ----------------------------------------------------------------------------
615 619
616void KODayMatrix::paintEvent(QPaintEvent * pevent) 620void KODayMatrix::paintEvent(QPaintEvent * pevent)
617{ 621{
618 if ( width() <= 0 || height() <= 0 ) 622 if ( width() <= 0 || height() <= 0 )
619 return; 623 return;
620 if ( mPendingUpdateBeforeRepaint ) { 624 if ( mPendingUpdateBeforeRepaint ) {
621 updateViewTimed(); 625 updateViewTimed();
622 mPendingUpdateBeforeRepaint = false; 626 mPendingUpdateBeforeRepaint = false;
623 } 627 }
624 if ( myPix.width() != width() || myPix.height()!=height() ) { 628 if ( myPix.width() != width() || myPix.height()!=height() ) {
625 myPix.resize(size() ); 629 myPix.resize(size() );
626 } 630 }
627 QPainter p(&myPix); 631 QPainter p(&myPix);
628 p.setFont(font()); 632 p.setFont(font());
629 633
630 QRect sz = frameRect(); 634 QRect sz = frameRect();
631 int dheight = daysize.height(); 635 int dheight = daysize.height();
632 int dwidth = daysize.width(); 636 int dwidth = daysize.width();
633 int row,col; 637 int row,col;
634 int selw, selh; 638 int selw, selh;
635 bool isRTL = KOGlobals::self()->reverseLayout(); 639 bool isRTL = KOGlobals::self()->reverseLayout();
636 640
637 // draw background and topleft frame 641 // draw background and topleft frame
638 p.fillRect(pevent->rect(), mDefaultBackColor); 642 p.fillRect(pevent->rect(), mDefaultBackColor);
639 p.setPen(mDefaultTextColor); 643 p.setPen(mDefaultTextColor);
640 p.drawRect(0, 0, sz.width()+1, sz.height()+1); 644 p.drawRect(0, 0, sz.width()+1, sz.height()+1);
641 645 int mSelStartT = mSelStart;
646 int mSelEndT = mSelEnd;
647 if ( mSelEndT >= NUMDAYS )
648 mSelEndT = NUMDAYS-1;
642 // draw selected days with highlighted background color 649 // draw selected days with highlighted background color
643 if (mSelStart != NOSELECTION) { 650 if (mSelStart != NOSELECTION) {
644 651 bool skip = false;
645 row = mSelStart/7; 652 if ( ! mouseDown ) {
646 col = mSelStart -row*7; 653 int mo = days[20].month();
654 //qDebug("-- %d %d ", mSelStartT, mSelEndT);
655 //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() );
656 if ( days[mSelStartT].month() > mo || days[mSelEndT].month() < mo ) {
657 skip = true;
658 } else {
659 if ( days[mSelStartT].month() != mo ) {
660 int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day();
661 mSelStartT += add +1;
662 }
663 if ( days[mSelEndT].month() != mo ) {
664 int sub = days[mSelEndT].day();
665 mSelEndT -= sub ;
666 }
667 }
668 }
669 if ( ! skip ) {
670 row = mSelStartT/7;
671 col = mSelStartT -row*7;
647 QColor selcol = KOPrefs::instance()->mHighlightColor; 672 QColor selcol = KOPrefs::instance()->mHighlightColor;
648 673
649 if (row == mSelEnd/7) { 674 if (row == mSelEndT/7) {
650 // Single row selection 675 // Single row selection
651 p.fillRect(isRTL ? (7 - (mSelEnd-mSelStart+1) - col)*dwidth : col*dwidth, 676 p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth,
652 row*dheight, (mSelEnd-mSelStart+1)*dwidth, dheight, selcol); 677 row*dheight, (mSelEndT-mSelStartT+1)*dwidth, dheight, selcol);
653 } else { 678 } else {
654 // draw first row to the right 679 // draw first row to the right
655 p.fillRect(isRTL ? 0 : col*dwidth, row*dheight, (7-col)*dwidth, 680 p.fillRect(isRTL ? 0 : col*dwidth, row*dheight, (7-col)*dwidth,
656 dheight, selcol); 681 dheight, selcol);
657 // draw full block till last line 682 // draw full block till last line
658 selh = mSelEnd/7-row; 683 selh = mSelEndT/7-row;
659 if (selh > 1) { 684 if (selh > 1) {
660 p.fillRect(0, (row+1)*dheight, 7*dwidth, (selh-1)*dheight,selcol); 685 p.fillRect(0, (row+1)*dheight, 7*dwidth, (selh-1)*dheight,selcol);
661 } 686 }
662 // draw last block from left to mSelEnd 687 // draw last block from left to mSelEndT
663 selw = mSelEnd-7*(mSelEnd/7)+1; 688 selw = mSelEndT-7*(mSelEndT/7)+1;
664 p.fillRect(isRTL ? (7-selw)*dwidth : 0, (row+selh)*dheight, 689 p.fillRect(isRTL ? (7-selw)*dwidth : 0, (row+selh)*dheight,
665 selw*dwidth, dheight, selcol); 690 selw*dwidth, dheight, selcol);
666 } 691 }
692 }
667 } 693 }
668 694
669 // iterate over all days in the matrix and draw the day label in appropriate colors 695 // iterate over all days in the matrix and draw the day label in appropriate colors
670 QColor actcol = mDefaultTextColorShaded; 696 QColor actcol = mDefaultTextColorShaded;
671 p.setPen(actcol); 697 p.setPen(actcol);
672 QPen tmppen; 698 QPen tmppen;
673 for(int i = 0; i < NUMDAYS; i++) { 699 for(int i = 0; i < NUMDAYS; i++) {
674 row = i/7; 700 row = i/7;
675 col = isRTL ? 6-(i-row*7) : i-row*7; 701 col = isRTL ? 6-(i-row*7) : i-row*7;
676 702
677 // if it is the first day of a month switch color from normal to shaded and vice versa 703 // if it is the first day of a month switch color from normal to shaded and vice versa
678 if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) { 704 if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) {
679 if (actcol == mDefaultTextColorShaded) { 705 if (actcol == mDefaultTextColorShaded) {
680 actcol = mDefaultTextColor; 706 actcol = mDefaultTextColor;
681 } else { 707 } else {
682 actcol = mDefaultTextColorShaded; 708 actcol = mDefaultTextColorShaded;
683 } 709 }
684 p.setPen(actcol); 710 p.setPen(actcol);
685 } 711 }
686 712 if (actcol == mDefaultTextColorShaded) {
713 if ( ! mouseDown ) {
714 continue;
715 }
716 }
687 //Reset pen color after selected days block 717 //Reset pen color after selected days block
688 if (i == mSelEnd+1) { 718 if (i == mSelEndT+1) {
689 p.setPen(actcol); 719 p.setPen(actcol);
690 } 720 }
691 721
692 // if today then draw rectangle around day 722 // if today then draw rectangle around day
693 if (today == i) { 723 if (today == i) {
694 tmppen = p.pen(); 724 tmppen = p.pen();
695 QPen mTodayPen(p.pen()); 725 QPen mTodayPen(p.pen());
696 726
697 mTodayPen.setWidth(mTodayMarginWidth); 727 mTodayPen.setWidth(mTodayMarginWidth);
698 //draw red rectangle for holidays 728 //draw red rectangle for holidays
699 if (!mHolidays[i].isNull()) { 729 if (!mHolidays[i].isNull()) {
700 if (actcol == mDefaultTextColor) { 730 if (actcol == mDefaultTextColor) {
701 mTodayPen.setColor(KOPrefs::instance()->mHolidayColor); 731 mTodayPen.setColor(KOPrefs::instance()->mHolidayColor);
702 } else { 732 } else {
703 mTodayPen.setColor(mHolidayColorShaded); 733 mTodayPen.setColor(mHolidayColorShaded);
704 } 734 }
705 } 735 }
706 //draw gray rectangle for today if in selection 736 //draw gray rectangle for today if in selection
707 if (i >= mSelStart && i <= mSelEnd) { 737 if (i >= mSelStartT && i <= mSelEndT) {
708 QColor grey("grey"); 738 QColor grey("grey");
709 mTodayPen.setColor(grey); 739 mTodayPen.setColor(grey);
710 } 740 }
711 p.setPen(mTodayPen); 741 p.setPen(mTodayPen);
712 p.drawRect(col*dwidth, row*dheight, dwidth, dheight); 742 p.drawRect(col*dwidth, row*dheight, dwidth, dheight);
713 p.setPen(tmppen); 743 p.setPen(tmppen);
714 } 744 }
715 745
716 // if any events are on that day then draw it using a bold font 746 // if any events are on that day then draw it using a bold font
717 if (events[i] > 0) { 747 if (events[i] > 0) {
718 QFont myFont = font(); 748 QFont myFont = font();
719 myFont.setBold(true); 749 myFont.setBold(true);
720 p.setFont(myFont); 750 p.setFont(myFont);
721 } 751 }
722 752
723 // if it is a holiday then use the default holiday color 753 // if it is a holiday then use the default holiday color
724 if (!mHolidays[i].isNull()) { 754 if (!mHolidays[i].isNull()) {
725 if ( bDays.testBit(i) ) { 755 if ( bDays.testBit(i) ) {
726 p.setPen(Qt::green); 756 p.setPen(Qt::green);
727 } else { 757 } else {
728 if (actcol == mDefaultTextColor) { 758 if (actcol == mDefaultTextColor) {
729 p.setPen(KOPrefs::instance()->mHolidayColor); 759 p.setPen(KOPrefs::instance()->mHolidayColor);
730 } else { 760 } else {
731 p.setPen(mHolidayColorShaded); 761 p.setPen(mHolidayColorShaded);
732 } 762 }
733 } 763 }
734 } 764 }
735 765
736 // draw selected days with special color 766 // draw selected days with special color
737 // DO NOT specially highlight holidays in selection ! 767 // DO NOT specially highlight holidays in selection !
738 if (i >= mSelStart && i <= mSelEnd) { 768 if (i >= mSelStartT && i <= mSelEndT) {
739 ;//p.setPen(mSelectedDaysColor); 769 ;//p.setPen(mSelectedDaysColor);
740 } 770 }
741 771
742 p.drawText(col*dwidth, row*dheight, dwidth, dheight, 772 p.drawText(col*dwidth, row*dheight, dwidth, dheight,
743 Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]); 773 Qt::AlignHCenter | Qt::AlignVCenter, daylbls[i]);
744 774
745 // reset color to actual color 775 // reset color to actual color
746 if (!mHolidays[i].isNull()) { 776 if (!mHolidays[i].isNull()) {
747 p.setPen(actcol); 777 p.setPen(actcol);
748 } 778 }
749 // reset bold font to plain font 779 // reset bold font to plain font
750 if (events[i] > 0) { 780 if (events[i] > 0) {
751 QFont myFont = font(); 781 QFont myFont = font();
752 myFont.setBold(false); 782 myFont.setBold(false);
753 p.setFont(myFont); 783 p.setFont(myFont);
754 } 784 }
755 } 785 }
756 bitBlt (this, 0, 0, &myPix, 0 ,0,width(), height() ,CopyROP); 786 bitBlt (this, 0, 0, &myPix, 0 ,0,width(), height() ,CopyROP);
757} 787}
758 788
759// ---------------------------------------------------------------------------- 789// ----------------------------------------------------------------------------
760// R E SI Z E E V E N T H A N D L I N G 790// R E SI Z E E V E N T H A N D L I N G
761// ---------------------------------------------------------------------------- 791// ----------------------------------------------------------------------------
762 792
763void KODayMatrix::resizeEvent(QResizeEvent *) 793void KODayMatrix::resizeEvent(QResizeEvent *)
764{ 794{
765 QRect sz = frameRect(); 795 QRect sz = frameRect();
766 daysize.setHeight(sz.height()*7 / NUMDAYS); 796 daysize.setHeight(sz.height()*7 / NUMDAYS);
767 daysize.setWidth(sz.width() / 7); 797 daysize.setWidth(sz.width() / 7);
768} 798}