summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-03-22 14:59:07 (UTC)
committer zautrix <zautrix>2005-03-22 14:59:07 (UTC)
commit0fe23b2c9b74bac46f409098f950259bffbdbe3c (patch) (unidiff)
tree80b4077661301ee3216217dfcb0bc9fd0a74b7d7
parent03b3e902ed6362d8f72d0acfc5a9be9d9ee1ef21 (diff)
downloadkdepimpi-0fe23b2c9b74bac46f409098f950259bffbdbe3c.zip
kdepimpi-0fe23b2c9b74bac46f409098f950259bffbdbe3c.tar.gz
kdepimpi-0fe23b2c9b74bac46f409098f950259bffbdbe3c.tar.bz2
more layout fixes
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/datenavigatorcontainer.cpp7
-rw-r--r--korganizer/kodaymatrix.cpp2
2 files changed, 4 insertions, 5 deletions
diff --git a/korganizer/datenavigatorcontainer.cpp b/korganizer/datenavigatorcontainer.cpp
index 6de7c45..9720146 100644
--- a/korganizer/datenavigatorcontainer.cpp
+++ b/korganizer/datenavigatorcontainer.cpp
@@ -1,387 +1,386 @@
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#include "koprefs.h" 36#include "koprefs.h"
37 37
38DateNavigatorContainer::DateNavigatorContainer( QWidget *parent, 38DateNavigatorContainer::DateNavigatorContainer( QWidget *parent,
39 const char *name ) 39 const char *name )
40 : QWidget( parent, name ), mCalendar( 0 ), 40 : QWidget( parent, name ), mCalendar( 0 ),
41 mHorizontalCount( 1 ), mVerticalCount( 1 ) 41 mHorizontalCount( 1 ), mVerticalCount( 1 )
42{ 42{
43 mExtraViews.setAutoDelete( true ); 43 mExtraViews.setAutoDelete( true );
44 44
45 mNavigatorView = new KDateNavigator( this, name ); 45 mNavigatorView = new KDateNavigator( this, name );
46 46
47 connectNavigatorView( mNavigatorView ); 47 connectNavigatorView( mNavigatorView );
48 //setSizePolicy( QSizePolicy (QSizePolicy::Expanding,QSizePolicy::Expanding) ); 48 //setSizePolicy( QSizePolicy (QSizePolicy::Expanding,QSizePolicy::Expanding) );
49 mLastDisplayedDN = 0; 49 mLastDisplayedDN = 0;
50} 50}
51 51
52DateNavigatorContainer::~DateNavigatorContainer() 52DateNavigatorContainer::~DateNavigatorContainer()
53{ 53{
54} 54}
55 55
56void DateNavigatorContainer::connectNavigatorView( KDateNavigator *v ) 56void DateNavigatorContainer::connectNavigatorView( KDateNavigator *v )
57{ 57{
58 connect( v, SIGNAL( datesSelected( const KCal::DateList & ) ), 58 connect( v, SIGNAL( datesSelected( const KCal::DateList & ) ),
59 SIGNAL( datesSelected( const KCal::DateList & ) ) ); 59 SIGNAL( datesSelected( const KCal::DateList & ) ) );
60#if 0 60#if 0
61 connect( v, SIGNAL( incidenceDropped( Incidence *, const QDate & ) ), 61 connect( v, SIGNAL( incidenceDropped( Incidence *, const QDate & ) ),
62 SIGNAL( incidenceDropped( Incidence *, const QDate & ) ) ); 62 SIGNAL( incidenceDropped( Incidence *, const QDate & ) ) );
63 connect( v, SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ), 63 connect( v, SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ),
64 SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ) ); 64 SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ) );
65#endif 65#endif
66 connect( v, SIGNAL( weekClicked( const QDate & ) ), 66 connect( v, SIGNAL( weekClicked( const QDate & ) ),
67 SIGNAL( weekClicked( const QDate & ) ) ); 67 SIGNAL( weekClicked( const QDate & ) ) );
68 68
69 connect( v, SIGNAL( goPrevious() ), SIGNAL( goPrevious() ) ); 69 connect( v, SIGNAL( goPrevious() ), SIGNAL( goPrevious() ) );
70 connect( v, SIGNAL( goNext() ), SIGNAL( goNext() ) ); 70 connect( v, SIGNAL( goNext() ), SIGNAL( goNext() ) );
71 71
72 connect( v, SIGNAL( goNextMonth() ), SIGNAL( goNextMonth() ) ); 72 connect( v, SIGNAL( goNextMonth() ), SIGNAL( goNextMonth() ) );
73 connect( v, SIGNAL( goPrevMonth() ), SIGNAL( goPrevMonth() ) ); 73 connect( v, SIGNAL( goPrevMonth() ), SIGNAL( goPrevMonth() ) );
74 connect( v, SIGNAL( goNextYear() ), SIGNAL( goNextYear() ) ); 74 connect( v, SIGNAL( goNextYear() ), SIGNAL( goNextYear() ) );
75 connect( v, SIGNAL( goPrevYear() ), SIGNAL( goPrevYear() ) ); 75 connect( v, SIGNAL( goPrevYear() ), SIGNAL( goPrevYear() ) );
76 76
77 connect( v, SIGNAL( monthSelected( int ) ), SLOT( slotMonthSelected( int ) ) ); 77 connect( v, SIGNAL( monthSelected( int ) ), SLOT( slotMonthSelected( int ) ) );
78} 78}
79 79
80void DateNavigatorContainer::slotMonthSelected( int month ) 80void DateNavigatorContainer::slotMonthSelected( int month )
81{ 81{
82 //qDebug("slotMonthSelected %d ", month); 82 //qDebug("slotMonthSelected %d ", month);
83 QDate baseDate = mNavigatorView->baseDate(); 83 QDate baseDate = mNavigatorView->baseDate();
84 if ( baseDate.month() == month ) 84 if ( baseDate.month() == month )
85 return; 85 return;
86 //qDebug("month %d %d ",baseDate.month(),month); 86 //qDebug("month %d %d ",baseDate.month(),month);
87 QDate date = QDate ( baseDate.year(), baseDate.month() , 15 ); 87 QDate date = QDate ( baseDate.year(), baseDate.month() , 15 );
88 date = date.addDays( -(baseDate.month()-month ) *30 ); 88 date = date.addDays( -(baseDate.month()-month ) *30 );
89 QDate newBase = QDate ( date.year(), date.month() , baseDate.day() ); 89 QDate newBase = QDate ( date.year(), date.month() , baseDate.day() );
90 90
91#if 0 91#if 0
92 mFirstSelectedDate = dateList.first() ; 92 mFirstSelectedDate = dateList.first() ;
93 mSelectedDateCount = dateList.count() ; 93 mSelectedDateCount = dateList.count() ;
94 94
95 KDateNavigator *view = mExtraViews.at( 0 ); 95 KDateNavigator *view = mExtraViews.at( 0 );
96 QDate date = view->baseDate(); 96 QDate date = view->baseDate();
97 97
98 QDate curEnd = date.addDays( (mLastDisplayedDN)*30 +7); 98 QDate curEnd = date.addDays( (mLastDisplayedDN)*30 +7);
99 //qDebug("End %s %s ",lDate.toString().latin1(),curEnd.toString().latin1() ); 99 //qDebug("End %s %s ",lDate.toString().latin1(),curEnd.toString().latin1() );
100 if ( lDate < curEnd && date.addDays( -30 ) < fDate) { 100 if ( lDate < curEnd && date.addDays( -30 ) < fDate) {
101 mNavigatorView->dayMatrix()->setSelectedDaysFrom( fDate , lDate ); 101 mNavigatorView->dayMatrix()->setSelectedDaysFrom( fDate , lDate );
102 mNavigatorView->dayMatrix()->repaint( false ); 102 mNavigatorView->dayMatrix()->repaint( false );
103 for( uint i = 0; i < mLastDisplayedDN; ++i ) { 103 for( uint i = 0; i < mLastDisplayedDN; ++i ) {
104 KDateNavigator *n = mExtraViews.at( i ); 104 KDateNavigator *n = mExtraViews.at( i );
105 if ( n->dayMatrix()->setSelectedDaysFrom( fDate , lDate ) ) { 105 if ( n->dayMatrix()->setSelectedDaysFrom( fDate , lDate ) ) {
106 n->dayMatrix()->repaint( false ); 106 n->dayMatrix()->repaint( false );
107 } 107 }
108 } 108 }
109 return; 109 return;
110 } 110 }
111#endif 111#endif
112 //qDebug("NEW BASE %s", newBase.toString().latin1()); 112 //qDebug("NEW BASE %s", newBase.toString().latin1());
113 mNavigatorView->setBaseDate( newBase ); 113 mNavigatorView->setBaseDate( newBase );
114 QDate last = lastAvailableDate(); 114 QDate last = lastAvailableDate();
115 QDate first = firstAvailableDate(); 115 QDate first = firstAvailableDate();
116 116
117 QDate selFirst = mFirstSelectedDate; 117 QDate selFirst = mFirstSelectedDate;
118 QDate selLast = selFirst.addDays( mSelectedDateCount-1 ); 118 QDate selLast = selFirst.addDays( mSelectedDateCount-1 );
119 if ( selFirst >= first && selLast <= last ) { 119 if ( selFirst >= first && selLast <= last ) {
120 setBaseDates(); 120 setBaseDates();
121 updateDayMatrixDates(); 121 updateDayMatrixDates();
122 } 122 }
123 else { 123 else {
124 setBaseDates(); 124 setBaseDates();
125 updateDayMatrixDates(); 125 updateDayMatrixDates();
126 emit monthSelected( month ); 126 emit monthSelected( month );
127 } 127 }
128} 128}
129void DateNavigatorContainer::setCalendar( Calendar *cal ) 129void DateNavigatorContainer::setCalendar( Calendar *cal )
130{ 130{
131 mCalendar = cal; 131 mCalendar = cal;
132 mNavigatorView->setCalendar( cal ); 132 mNavigatorView->setCalendar( cal );
133 for( uint i = 0; i < mLastDisplayedDN; ++i ) { 133 for( uint i = 0; i < mLastDisplayedDN; ++i ) {
134 KDateNavigator *n = mExtraViews.at( i ); 134 KDateNavigator *n = mExtraViews.at( i );
135 n->setCalendar( cal ); 135 n->setCalendar( cal );
136 } 136 }
137} 137}
138void DateNavigatorContainer::updateDayMatrixDates() 138void DateNavigatorContainer::updateDayMatrixDates()
139{ 139{
140 140
141 QDate fDate = mFirstSelectedDate; 141 QDate fDate = mFirstSelectedDate;
142 QDate lDate = fDate.addDays( mSelectedDateCount - 1 ); 142 QDate lDate = fDate.addDays( mSelectedDateCount - 1 );
143 mNavigatorView->dayMatrix()->setSelectedDaysFrom( fDate , lDate ); 143 mNavigatorView->dayMatrix()->setSelectedDaysFrom( fDate , lDate );
144 mNavigatorView->dayMatrix()->repaint( false ); 144 mNavigatorView->dayMatrix()->repaint( false );
145 for( uint i = 0; i < mLastDisplayedDN; ++i ) { 145 for( uint i = 0; i < mLastDisplayedDN; ++i ) {
146 KDateNavigator *n = mExtraViews.at( i ); 146 KDateNavigator *n = mExtraViews.at( i );
147 if ( n->dayMatrix()->setSelectedDaysFrom( fDate , lDate ) ) { 147 if ( n->dayMatrix()->setSelectedDaysFrom( fDate , lDate ) ) {
148 n->dayMatrix()->repaint( false ); 148 n->dayMatrix()->repaint( false );
149 } 149 }
150 } 150 }
151} 151}
152 152
153void DateNavigatorContainer::updateDayMatrix() 153void DateNavigatorContainer::updateDayMatrix()
154{ 154{
155 mNavigatorView->updateDayMatrix(); 155 mNavigatorView->updateDayMatrix();
156 for( uint i = 0; i < mLastDisplayedDN; ++i ) { 156 for( uint i = 0; i < mLastDisplayedDN; ++i ) {
157 KDateNavigator *n = mExtraViews.at( i ); 157 KDateNavigator *n = mExtraViews.at( i );
158 n->updateDayMatrix(); 158 n->updateDayMatrix();
159 } 159 }
160} 160}
161 161
162void DateNavigatorContainer::updateToday() 162void DateNavigatorContainer::updateToday()
163{ 163{
164 qDebug("DateNavigatorContainer::updateToday() NOT IMPL "); 164 qDebug("DateNavigatorContainer::updateToday() NOT IMPL ");
165#if 0 165#if 0
166 mNavigatorView->updateToday(); 166 mNavigatorView->updateToday();
167 KDateNavigator *n; 167 KDateNavigator *n;
168 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { 168 for( n = mExtraViews.first(); n; n = mExtraViews.next() ) {
169 n->updateToday(); 169 n->updateToday();
170 } 170 }
171#endif 171#endif
172} 172}
173 173
174void DateNavigatorContainer::updateView() 174void DateNavigatorContainer::updateView()
175{ 175{
176 mNavigatorView->updateView(); 176 mNavigatorView->updateView();
177 for( uint i = 0; i < mLastDisplayedDN; ++i ) { 177 for( uint i = 0; i < mLastDisplayedDN; ++i ) {
178 KDateNavigator *n = mExtraViews.at( i ); 178 KDateNavigator *n = mExtraViews.at( i );
179 n->updateView(); 179 n->updateView();
180 } 180 }
181} 181}
182 182
183void DateNavigatorContainer::updateConfig() 183void DateNavigatorContainer::updateConfig()
184{ 184{
185 mNavigatorView->updateConfig(); 185 mNavigatorView->updateConfig();
186 for( uint i = 0; i < mLastDisplayedDN; ++i ) { 186 for( uint i = 0; i < mLastDisplayedDN; ++i ) {
187 KDateNavigator *n = mExtraViews.at( i ); 187 KDateNavigator *n = mExtraViews.at( i );
188 n->updateConfig(); 188 n->updateConfig();
189 } 189 }
190} 190}
191QDate DateNavigatorContainer::lastAvailableDate() const 191QDate DateNavigatorContainer::lastAvailableDate() const
192{ 192{
193 QDate date = mNavigatorView->baseDate(); 193 QDate date = mNavigatorView->baseDate();
194 QDate last = QDate ( date.year(), date.month(), date.daysInMonth() ); 194 QDate last = QDate ( date.year(), date.month(), date.daysInMonth() );
195 int iii = mLastDisplayedDN; 195 int iii = mLastDisplayedDN;
196 if ( mLastDisplayedDN ) 196 if ( mLastDisplayedDN )
197 last = last.addDays( 1); 197 last = last.addDays( 1);
198 while ( iii ) { 198 while ( iii ) {
199 last = last.addDays( last.daysInMonth ()); 199 last = last.addDays( last.daysInMonth ());
200 //qDebug("DATE %s ", last.toString().latin1() ); 200 //qDebug("DATE %s ", last.toString().latin1() );
201 --iii; 201 --iii;
202 } 202 }
203 if ( mLastDisplayedDN ) 203 if ( mLastDisplayedDN )
204 last = last.addDays( -1); 204 last = last.addDays( -1);
205 return last; 205 return last;
206} 206}
207QDate DateNavigatorContainer::firstAvailableDate() const 207QDate DateNavigatorContainer::firstAvailableDate() const
208{ 208{
209 return QDate ( mNavigatorView->baseDate().year(), mNavigatorView->baseDate().month(), 1 ); 209 return QDate ( mNavigatorView->baseDate().year(), mNavigatorView->baseDate().month(), 1 );
210} 210}
211void DateNavigatorContainer::selectDates( const DateList &dateList ) 211void DateNavigatorContainer::selectDates( const DateList &dateList )
212{ 212{
213 mFirstSelectedDate = dateList.first() ; 213 mFirstSelectedDate = dateList.first() ;
214 mSelectedDateCount = dateList.count() ; 214 mSelectedDateCount = dateList.count() ;
215 if ( !mLastDisplayedDN ) { 215 if ( !mLastDisplayedDN ) {
216 mNavigatorView->selectDates( dateList ); 216 mNavigatorView->selectDates( dateList );
217 return; 217 return;
218 } 218 }
219 QDate fDate = dateList.first(); 219 QDate fDate = dateList.first();
220 QDate lDate = dateList.last(); 220 QDate lDate = dateList.last();
221 if ( mLastDisplayedDN <= 2 ) { 221 if ( mLastDisplayedDN <= 2 ) {
222 mNavigatorView->selectDates( dateList ); 222 mNavigatorView->selectDates( dateList );
223 KDateNavigator *view = mExtraViews.at( 0 ); 223 KDateNavigator *view = mExtraViews.at( 0 );
224 QDate bDate = fDate.addDays( fDate.daysInMonth () - fDate.day() +1 ); 224 QDate bDate = fDate.addDays( fDate.daysInMonth () - fDate.day() +1 );
225 view->setBaseDate( bDate, false ); 225 view->setBaseDate( bDate, false );
226 view->dayMatrix()->setSelectedDaysFrom(fDate , lDate); 226 view->dayMatrix()->setSelectedDaysFrom(fDate , lDate);
227 if ( mLastDisplayedDN == 2 ) { 227 if ( mLastDisplayedDN == 2 ) {
228 view = mExtraViews.at( 1 ); 228 view = mExtraViews.at( 1 );
229 bDate = bDate.addDays( bDate.daysInMonth () - bDate.day() +1 ); 229 bDate = bDate.addDays( bDate.daysInMonth () - bDate.day() +1 );
230 view->setBaseDate( bDate, false ); 230 view->setBaseDate( bDate, false );
231 view->dayMatrix()->setSelectedDaysFrom(fDate , lDate); 231 view->dayMatrix()->setSelectedDaysFrom(fDate , lDate);
232 } 232 }
233 return; 233 return;
234 } 234 }
235 //qDebug("%s %s ", lastAvailableDate().toString().latin1(), firstAvailableDate().toString().latin1() ); 235 //qDebug("%s %s ", lastAvailableDate().toString().latin1(), firstAvailableDate().toString().latin1() );
236 //qDebug("End %s %s ",lDate.toString().latin1(),curEnd.toString().latin1() ); 236 //qDebug("End %s %s ",lDate.toString().latin1(),curEnd.toString().latin1() );
237 if ( lDate <= lastAvailableDate() && firstAvailableDate() <= fDate) { 237 if ( lDate <= lastAvailableDate() && firstAvailableDate() <= fDate) {
238 updateDayMatrixDates(); 238 updateDayMatrixDates();
239 return; 239 return;
240 } 240 }
241 mNavigatorView->selectDates( dateList ); 241 mNavigatorView->selectDates( dateList );
242 setBaseDates(); 242 setBaseDates();
243 if ( mLastDisplayedDN ) { 243 if ( mLastDisplayedDN ) {
244 KDateNavigator *view = mExtraViews.at( 0 ); 244 KDateNavigator *view = mExtraViews.at( 0 );
245 view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end())); 245 view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end()));
246 view->dayMatrix()->repaint( false ); 246 view->dayMatrix()->repaint( false );
247 if ( mLastDisplayedDN > 1 ) { 247 if ( mLastDisplayedDN > 1 ) {
248 KDateNavigator *view = mExtraViews.at( 1 ); 248 KDateNavigator *view = mExtraViews.at( 1 );
249 view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end())); 249 view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end()));
250 view->dayMatrix()->repaint( false ); 250 view->dayMatrix()->repaint( false );
251 } 251 }
252 } 252 }
253} 253}
254 254
255void DateNavigatorContainer::setBaseDates() 255void DateNavigatorContainer::setBaseDates()
256{ 256{
257 QDate baseDate = mNavigatorView->baseDate(); 257 QDate baseDate = mNavigatorView->baseDate();
258 bool doRepaint = true; 258 bool doRepaint = true;
259 for( uint i = 0; i < mLastDisplayedDN; ++i ) { 259 for( uint i = 0; i < mLastDisplayedDN; ++i ) {
260 KDateNavigator *n = mExtraViews.at( i ); 260 KDateNavigator *n = mExtraViews.at( i );
261 baseDate = baseDate.addDays( baseDate.daysInMonth () - baseDate.day() +1 ); 261 baseDate = baseDate.addDays( baseDate.daysInMonth () - baseDate.day() +1 );
262 n->setBaseDate( baseDate, doRepaint ); 262 n->setBaseDate( baseDate, doRepaint );
263 } 263 }
264} 264}
265 265
266void DateNavigatorContainer::resizeEvent( QResizeEvent * e ) 266void DateNavigatorContainer::resizeEvent( QResizeEvent * e )
267{ 267{
268#if 0 268#if 0
269 kdDebug(5850) << "DateNavigatorContainer::resizeEvent()" << endl; 269 kdDebug(5850) << "DateNavigatorContainer::resizeEvent()" << endl;
270 kdDebug(5850) << " CURRENT SIZE: " << size() << endl; 270 kdDebug(5850) << " CURRENT SIZE: " << size() << endl;
271 kdDebug(5850) << " MINIMUM SIZEHINT: " << minimumSizeHint() << endl; 271 kdDebug(5850) << " MINIMUM SIZEHINT: " << minimumSizeHint() << endl;
272 kdDebug(5850) << " SIZEHINT: " << sizeHint() << endl; 272 kdDebug(5850) << " SIZEHINT: " << sizeHint() << endl;
273 kdDebug(5850) << " MINIMUM SIZE: " << minimumSize() << endl; 273 kdDebug(5850) << " MINIMUM SIZE: " << minimumSize() << endl;
274#endif 274#endif
275 //QSize minSize = mNavigatorView->sizeHintTwoButtons(); 275 //QSize minSize = mNavigatorView->sizeHintTwoButtons();
276 QSize minSize = mNavigatorView->yourSizeHint(); 276 QSize minSize = mNavigatorView->yourSizeHint();
277 277
278// kdDebug(5850) << " NAVIGATORVIEW minimumSizeHint: " << minSize << endl; 278// kdDebug(5850) << " NAVIGATORVIEW minimumSizeHint: " << minSize << endl;
279 279
280 int verticalCount = size().height() / minSize.height(); 280 int verticalCount = size().height() / minSize.height();
281 int horizontalCount = size().width() / minSize.width(); 281 int horizontalCount = size().width() / minSize.width();
282 //qDebug(" wattdatt %d new %d %d ", size().width() ,e->size().width() , minSize.width() ); 282 //qDebug(" wattdatt %d new %d %d ", size().width() ,e->size().width() , minSize.width() );
283 //qDebug("COUNT %d %d %d %d ", verticalCount, horizontalCount , mVerticalCount, mHorizontalCount ); 283 //qDebug("COUNT %d %d %d %d ", verticalCount, horizontalCount , mVerticalCount, mHorizontalCount );
284 bool fontchange = false; 284 bool fontchange = false;
285 if ( horizontalCount == 1) 285 if ( horizontalCount == 1)
286 horizontalCount = size().width() / mNavigatorView->yourFullSizeHint().width(); 286 horizontalCount = size().width() / mNavigatorView->yourFullSizeHint().width();
287 QFont fo; 287 QFont fo;
288 if ( horizontalCount != mHorizontalCount || 288 if ( horizontalCount != mHorizontalCount ||
289 verticalCount != mVerticalCount ) { 289 verticalCount != mVerticalCount ) {
290 uint count = horizontalCount * verticalCount; 290 uint count = horizontalCount * verticalCount;
291 if ( count == 0 ) { 291 if ( count == 0 ) {
292 bool ok; 292 bool ok;
293 fo = mNavigatorView->yourFontHint( size() , &ok ); 293 fo = mNavigatorView->yourFontHint( size() , &ok );
294 //mNavigatorView->resize( size() ); 294 //mNavigatorView->resize( size() );
295 //if ( ! ok ) 295 //if ( ! ok )
296 // return; 296 // return;
297 int butt = 2; 297 int butt = 2;
298 horizontalCount = size().width() / mNavigatorView->sizeHintTwoButtons( ).width(); 298 horizontalCount = size().width() / mNavigatorView->sizeHintTwoButtons( ).width();
299 if ( horizontalCount <= 1 ) 299 if ( horizontalCount <= 1 )
300 minSize = mNavigatorView->sizeHintTwoButtons( 4 ); 300 minSize = mNavigatorView->sizeHintTwoButtons( 4 );
301 else 301 else
302 minSize = mNavigatorView->sizeHintTwoButtons(); 302 minSize = mNavigatorView->sizeHintTwoButtons();
303 verticalCount = size().height() / minSize.height(); 303 verticalCount = size().height() / minSize.height();
304 horizontalCount = size().width() / minSize.width(); 304 horizontalCount = size().width() / minSize.width();
305 if ( horizontalCount == 0 ) 305 if ( horizontalCount == 0 )
306 horizontalCount = 1; 306 horizontalCount = 1;
307 if ( verticalCount == 0 ) 307 if ( verticalCount == 0 )
308 verticalCount = 1; 308 verticalCount = 1;
309 fontchange = true; 309 fontchange = true;
310 count = horizontalCount * verticalCount; 310 count = horizontalCount * verticalCount;
311 } else { 311 } else {
312 if ( mNavigatorView->fontChanged() ) { 312 if ( mNavigatorView->fontChanged() ) {
313 fontchange = true; 313 fontchange = true;
314 fo = KOPrefs::instance()->mDateNavigatorFont; 314 fo = KOPrefs::instance()->mDateNavigatorFont;
315 mNavigatorView->changeFont( fo ); 315 mNavigatorView->changeFont( fo );
316 mNavigatorView->unsetFontChanged(); 316 mNavigatorView->unsetFontChanged();
317 } 317 }
318 } 318 }
319 319
320 mLastDisplayedDN = horizontalCount*verticalCount-1; 320 mLastDisplayedDN = horizontalCount*verticalCount-1;
321 bool setBaseD = false;
322 while ( count > ( mExtraViews.count() + 1 ) ) { 321 while ( count > ( mExtraViews.count() + 1 ) ) {
323 KDateNavigator *n = new KDateNavigator( this ); 322 KDateNavigator *n = new KDateNavigator( this );
324 n->setMonthSignalOffset ( mExtraViews.count()+1 ); 323 n->setMonthSignalOffset ( mExtraViews.count()+1 );
325 mExtraViews.append( n ); 324 mExtraViews.append( n );
326 n->setCalendar( mCalendar ); 325 n->setCalendar( mCalendar );
327 setBaseD = true;
328 connectNavigatorView( n ); 326 connectNavigatorView( n );
329 n->show(); 327 n->show();
330 } 328 }
331 int iii = 0; 329 int iii = 0;
332 while ( iii < ( mExtraViews.count() ) ) { 330 while ( iii < ( mExtraViews.count() ) ) {
333 if ( iii < count-1 ) 331 if ( iii < count-1 )
334 mExtraViews.at( iii )->show(); 332 mExtraViews.at( iii )->show();
335 else 333 else
336 mExtraViews.at( iii )->hide(); 334 mExtraViews.at( iii )->hide();
337 ++iii; 335 ++iii;
338 } 336 }
339 if ( setBaseD ) 337
340 setBaseDates(); 338 setBaseDates();
341 if ( fontchange ) { 339 if ( fontchange ) {
342 //mNavigatorView->changeFont( fo ); 340 //mNavigatorView->changeFont( fo );
343 uint i; 341 uint i;
344 for( i = 0; i < mExtraViews.count(); ++i ) { 342 for( i = 0; i < mExtraViews.count(); ++i ) {
345 KDateNavigator *view = mExtraViews.at( i ); 343 KDateNavigator *view = mExtraViews.at( i );
346 view->changeFont( fo ); 344 view->changeFont( fo );
347 } 345 }
348 } 346 }
349 mHorizontalCount = horizontalCount; 347 mHorizontalCount = horizontalCount;
350 mVerticalCount = verticalCount; 348 mVerticalCount = verticalCount;
351 349
352 } 350 }
353 //qDebug("COUNT %d ", mExtraViews.count()); 351 //qDebug("COUNT %d ", mExtraViews.count());
354 int height = size().height() / verticalCount; 352 int height = size().height() / verticalCount;
355 int width = size().width() / horizontalCount; 353 int width = size().width() / horizontalCount;
356 354
357 NavigatorBar *bar = mNavigatorView->navigatorBar(); 355 NavigatorBar *bar = mNavigatorView->navigatorBar();
358 if ( horizontalCount > 1 ) bar->showButtons( true, false ); 356 if ( horizontalCount > 1 ) bar->showButtons( true, false );
359 else bar->showButtons( true, true ); 357 else bar->showButtons( true, true );
360 358
361 mNavigatorView->setGeometry(0, 359 mNavigatorView->setGeometry(0,
362 0, width, height ); 360 0, width, height );
363 for( uint i = 0; i < mLastDisplayedDN; ++i ) { 361 for( uint i = 0; i < mLastDisplayedDN; ++i ) {
364 int x = ( i + 1 ) % horizontalCount; 362 int x = ( i + 1 ) % horizontalCount;
365 int y = ( i + 1 ) / horizontalCount; 363 int y = ( i + 1 ) / horizontalCount;
366 364
367 KDateNavigator *view = mExtraViews.at( i ); 365 KDateNavigator *view = mExtraViews.at( i );
368 bar = view->navigatorBar(); 366 bar = view->navigatorBar();
369 if ( y > 0 ) bar->showButtons( false, false ); 367 if ( y > 0 ) bar->showButtons( false, false );
370 else { 368 else {
371 if ( x + 1 == horizontalCount ) bar->showButtons( false, true ); 369 if ( x + 1 == horizontalCount ) bar->showButtons( false, true );
372 else bar->showButtons( false, false ); 370 else bar->showButtons( false, false );
373 } 371 }
374 view->setGeometry( x * width, 372 view->setGeometry( x * width,
375 y * height, width, height ); 373 y * height, width, height );
376 } 374 }
375 //updateDayMatrixDates();
377} 376}
378 377
379QSize DateNavigatorContainer::minimumSizeHint() const 378QSize DateNavigatorContainer::minimumSizeHint() const
380{ 379{
381 return mNavigatorView->minimumSizeHint(); 380 return mNavigatorView->minimumSizeHint();
382} 381}
383 382
384QSize DateNavigatorContainer::sizeHint() const 383QSize DateNavigatorContainer::sizeHint() const
385{ 384{
386 return mNavigatorView->yourSizeHint(); 385 return mNavigatorView->yourSizeHint();
387} 386}
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp
index 3ee1fa7..366e8b8 100644
--- a/korganizer/kodaymatrix.cpp
+++ b/korganizer/kodaymatrix.cpp
@@ -1,874 +1,874 @@
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 ~KODaymatrixWhatsThis() { ; }; 66 ~KODaymatrixWhatsThis() { ; };
67 67
68protected: 68protected:
69 virtual QString text( const QPoint& p ) 69 virtual QString text( const QPoint& p )
70 { 70 {
71 return _view->getWhatsThisText( p ) ; 71 return _view->getWhatsThisText( p ) ;
72 } 72 }
73private: 73private:
74 KODayMatrix * _view; 74 KODayMatrix * _view;
75}; 75};
76 76
77void DynamicTip::maybeTip( const QPoint &pos ) 77void DynamicTip::maybeTip( const QPoint &pos )
78{ 78{
79 //calculate which cell of the matrix the mouse is in 79 //calculate which cell of the matrix the mouse is in
80 QRect sz = matrix->frameRect(); 80 QRect sz = matrix->frameRect();
81 int dheight = sz.height()*7 / 42; 81 int dheight = sz.height()*7 / 42;
82 int dwidth = sz.width() / 7; 82 int dwidth = sz.width() / 7;
83 int row = pos.y()/dheight; 83 int row = pos.y()/dheight;
84 int col = pos.x()/dwidth; 84 int col = pos.x()/dwidth;
85 85
86 QRect rct(col*dwidth, row*dheight, dwidth, dheight); 86 QRect rct(col*dwidth, row*dheight, dwidth, dheight);
87 87
88// kdDebug() << "DynamicTip::maybeTip matrix cell index [" << 88// kdDebug() << "DynamicTip::maybeTip matrix cell index [" <<
89// col << "][" << row << "] => " <<(col+row*7) << endl; 89// col << "][" << row << "] => " <<(col+row*7) << endl;
90 90
91 //show holiday names only 91 //show holiday names only
92 QString str = matrix->getHolidayLabel(col+row*7); 92 QString str = matrix->getHolidayLabel(col+row*7);
93 if (str.isEmpty()) return; 93 if (str.isEmpty()) return;
94 tip(rct, str); 94 tip(rct, str);
95} 95}
96 96
97 97
98// ============================================================================ 98// ============================================================================
99// K O D A Y M A T R I X 99// K O D A Y M A T R I X
100// ============================================================================ 100// ============================================================================
101 101
102const int KODayMatrix::NOSELECTION = -1000; 102const int KODayMatrix::NOSELECTION = -1000;
103const int KODayMatrix::NUMDAYS = 42; 103const int KODayMatrix::NUMDAYS = 42;
104 104
105KODayMatrix::KODayMatrix( QWidget *parent, const char *name ) 105KODayMatrix::KODayMatrix( QWidget *parent, const char *name )
106 : QFrame( parent, name ), mCalendar( 0 ) 106 : QFrame( parent, name , Qt::WRepaintNoErase ), mCalendar( 0 )
107 107
108#if 0 108#if 0
109KODayMatrix::KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const char *name) : 109KODayMatrix::KODayMatrix(QWidget *parent, Calendar* calendar, QDate date, const char *name) :
110 QFrame(parent, name) 110 QFrame(parent, name)
111#endif 111#endif
112{ 112{
113 mKODaymatrixWhatsThis = new KODaymatrixWhatsThis(this); 113 mKODaymatrixWhatsThis = new KODaymatrixWhatsThis(this);
114 mPendingUpdateBeforeRepaint = false; 114 mPendingUpdateBeforeRepaint = false;
115 mouseDown = false; 115 mouseDown = false;
116 // initialize dynamic arrays 116 // initialize dynamic arrays
117 bDays.resize ( NUMDAYS ); 117 bDays.resize ( NUMDAYS );
118 days = new QDate[NUMDAYS]; 118 days = new QDate[NUMDAYS];
119 daylbls = new QString[NUMDAYS]; 119 daylbls = new QString[NUMDAYS];
120 events = new int[NUMDAYS]; 120 events = new int[NUMDAYS];
121 mToolTip = new DynamicTip(this); 121 mToolTip = new DynamicTip(this);
122 122
123 // set default values used for drawing the matrix 123 // set default values used for drawing the matrix
124 mDefaultBackColor = palette().active().base(); 124 mDefaultBackColor = palette().active().base();
125 mDefaultTextColor = palette().active().foreground(); 125 mDefaultTextColor = palette().active().foreground();
126 mDefaultTextColorShaded = getShadedColor(mDefaultTextColor); 126 mDefaultTextColorShaded = getShadedColor(mDefaultTextColor);
127 mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor); 127 mHolidayColorShaded = getShadedColor(KOPrefs::instance()->mHolidayColor);
128 mSelectedDaysColor = QColor("white"); 128 mSelectedDaysColor = QColor("white");
129 mTodayMarginWidth = 2; 129 mTodayMarginWidth = 2;
130 mSelEnd = mSelStart = NOSELECTION; 130 mSelEnd = mSelStart = NOSELECTION;
131 131
132 setAcceptDrops(true); 132 setAcceptDrops(true);
133 //setFont( QFont("Arial", 10) ); 133 //setFont( QFont("Arial", 10) );
134 134
135 mUpdateTimer = new QTimer( this ); 135 mUpdateTimer = new QTimer( this );
136 connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() )); 136 connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( updateViewTimed() ));
137 mRepaintTimer = new QTimer( this ); 137 mRepaintTimer = new QTimer( this );
138 connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() )); 138 connect (mRepaintTimer ,SIGNAL(timeout()), this, SLOT ( repaintViewTimed() ));
139 mDayChanged = false; 139 mDayChanged = false;
140 updateView(); 140 updateView();
141} 141}
142QString KODayMatrix::getWhatsThisText( QPoint p ) 142QString KODayMatrix::getWhatsThisText( QPoint p )
143{ 143{
144 144
145 int tmp = getDayIndexFrom(p.x(), p.y()); 145 int tmp = getDayIndexFrom(p.x(), p.y());
146 if ( tmp < 0 || tmp > NUMDAYS-1 || !mCalendar ) 146 if ( tmp < 0 || tmp > NUMDAYS-1 || !mCalendar )
147 return QString(); 147 return QString();
148 QDate mDate = days[tmp]; 148 QDate mDate = days[tmp];
149 QPtrList<Event> eventlist = mCalendar->events(mDate); 149 QPtrList<Event> eventlist = mCalendar->events(mDate);
150 Event *event; 150 Event *event;
151 QStringList mToolTip; 151 QStringList mToolTip;
152 for(event=eventlist.first();event != 0;event=eventlist.next()) { 152 for(event=eventlist.first();event != 0;event=eventlist.next()) {
153 QString mToolTipText; 153 QString mToolTipText;
154 QString text; 154 QString text;
155 int multiday = 0;// 1 = start, 2 = midddle, 3 = end day 155 int multiday = 0;// 1 = start, 2 = midddle, 3 = end day
156 if (event->isMultiDay()) { 156 if (event->isMultiDay()) {
157 QString prefix = "<->";multiday = 2; 157 QString prefix = "<->";multiday = 2;
158 QString time; 158 QString time;
159 if ( event->doesRecur() ) { 159 if ( event->doesRecur() ) {
160 if ( event->recursOn( mDate) ) { 160 if ( event->recursOn( mDate) ) {
161 prefix ="->" ;multiday = 1; 161 prefix ="->" ;multiday = 1;
162 } 162 }
163 else { 163 else {
164 int days = event->dtStart().date().daysTo ( event->dtEnd().date() ); 164 int days = event->dtStart().date().daysTo ( event->dtEnd().date() );
165 if ( event->recursOn( mDate.addDays( -days)) ) { 165 if ( event->recursOn( mDate.addDays( -days)) ) {
166 prefix ="<-" ;multiday = 3; 166 prefix ="<-" ;multiday = 3;
167 } 167 }
168 } 168 }
169 } else { 169 } else {
170 if (mDate == event->dtStart().date()) { 170 if (mDate == event->dtStart().date()) {
171 prefix ="->" ;multiday = 1; 171 prefix ="->" ;multiday = 1;
172 } else if (mDate == event->dtEnd().date()) { 172 } else if (mDate == event->dtEnd().date()) {
173 prefix ="<-" ;multiday = 3; 173 prefix ="<-" ;multiday = 3;
174 } 174 }
175 } 175 }
176 if ( !event->doesFloat() ) { 176 if ( !event->doesFloat() ) {
177 if ( mDate == event->dtStart().date () ) 177 if ( mDate == event->dtStart().date () )
178 time = KGlobal::locale()->formatTime(event->dtStart().time())+" "; 178 time = KGlobal::locale()->formatTime(event->dtStart().time())+" ";
179 else if ( mDate == event->dtEnd().date () ) 179 else if ( mDate == event->dtEnd().date () )
180 time = KGlobal::locale()->formatTime(event->dtEnd().time())+" "; 180 time = KGlobal::locale()->formatTime(event->dtEnd().time())+" ";
181 181
182 } 182 }
183 text = time + event->summary(); 183 text = time + event->summary();
184 mToolTipText += prefix + text; 184 mToolTipText += prefix + text;
185 } else { 185 } else {
186 if (event->doesFloat()) { 186 if (event->doesFloat()) {
187 text = event->summary(); 187 text = event->summary();
188 mToolTipText += text; 188 mToolTipText += text;
189 } 189 }
190 else { 190 else {
191 text = KGlobal::locale()->formatTime(event->dtStart().time()); 191 text = KGlobal::locale()->formatTime(event->dtStart().time());
192 text += " " + event->summary(); 192 text += " " + event->summary();
193 mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary(); 193 mToolTipText += KGlobal::locale()->formatTime(event->dtStart().time()) +"-"+KGlobal::locale()->formatTime(event->dtEnd().time())+" " + event->summary();
194 } 194 }
195 } 195 }
196 if ( !event->location().isEmpty() ) 196 if ( !event->location().isEmpty() )
197 mToolTipText += " (" + event->location() + ")"; 197 mToolTipText += " (" + event->location() + ")";
198#if QT_VERSION >= 0x030000 198#if QT_VERSION >= 0x030000
199 mToolTipText.replace( '<' , "&lt;" ); 199 mToolTipText.replace( '<' , "&lt;" );
200 mToolTipText.replace( '>' , "&gt;" ); 200 mToolTipText.replace( '>' , "&gt;" );
201#else 201#else
202 if ( mToolTipText.find ('<') >= 0 ) { 202 if ( mToolTipText.find ('<') >= 0 ) {
203 mToolTipText.replace( QRegExp("<") , "&lt;" ); 203 mToolTipText.replace( QRegExp("<") , "&lt;" );
204 } 204 }
205 if ( mToolTipText.find ('>') >= 0 ) { 205 if ( mToolTipText.find ('>') >= 0 ) {
206 mToolTipText.replace( QRegExp(">") , "&gt;" ); 206 mToolTipText.replace( QRegExp(">") , "&gt;" );
207 } 207 }
208#endif 208#endif
209 //qDebug("TTT: %s ", mToolTipText.latin1()); 209 //qDebug("TTT: %s ", mToolTipText.latin1());
210 mToolTip.append( mToolTipText ); 210 mToolTip.append( mToolTipText );
211 } 211 }
212 mToolTip.sort(); 212 mToolTip.sort();
213 return "<b>"+KGlobal::locale()->formatDate(days[tmp]) + "</b><br>" + mToolTip.join("<br>"); 213 return "<b>"+KGlobal::locale()->formatDate(days[tmp]) + "</b><br>" + mToolTip.join("<br>");
214} 214}
215void KODayMatrix::setCalendar( Calendar *cal ) 215void KODayMatrix::setCalendar( Calendar *cal )
216{ 216{
217 mCalendar = cal; 217 mCalendar = cal;
218 218
219 setAcceptDrops( mCalendar ); 219 setAcceptDrops( mCalendar );
220 220
221 updateEvents(); 221 updateEvents();
222} 222}
223 223
224QColor KODayMatrix::getShadedColor(QColor color) 224QColor KODayMatrix::getShadedColor(QColor color)
225{ 225{
226 QColor shaded; 226 QColor shaded;
227 int h=0; 227 int h=0;
228 int s=0; 228 int s=0;
229 int v=0; 229 int v=0;
230 color.hsv(&h,&s,&v); 230 color.hsv(&h,&s,&v);
231 s = s/4; 231 s = s/4;
232 v = 192+v/4; 232 v = 192+v/4;
233 shaded.setHsv(h,s,v); 233 shaded.setHsv(h,s,v);
234 234
235 return shaded; 235 return shaded;
236} 236}
237 237
238KODayMatrix::~KODayMatrix() 238KODayMatrix::~KODayMatrix()
239{ 239{
240 // delete mKODaymatrixWhatsThis; 240 // delete mKODaymatrixWhatsThis;
241 delete [] days; 241 delete [] days;
242 delete [] daylbls; 242 delete [] daylbls;
243 delete [] events; 243 delete [] events;
244 delete mToolTip; 244 delete mToolTip;
245} 245}
246 246
247/* 247/*
248void KODayMatrix::setStartDate(QDate start) 248void KODayMatrix::setStartDate(QDate start)
249{ 249{
250 updateView(start); 250 updateView(start);
251} 251}
252*/ 252*/
253 253
254void KODayMatrix::addSelectedDaysTo(DateList& selDays) 254void KODayMatrix::addSelectedDaysTo(DateList& selDays)
255{ 255{
256 256
257 if (mSelStart == NOSELECTION) { 257 if (mSelStart == NOSELECTION) {
258 return; 258 return;
259 } 259 }
260 260
261 //cope with selection being out of matrix limits at top (< 0) 261 //cope with selection being out of matrix limits at top (< 0)
262 int i0 = mSelStart; 262 int i0 = mSelStart;
263 if (i0 < 0) { 263 if (i0 < 0) {
264 for (int i = i0; i < 0; i++) { 264 for (int i = i0; i < 0; i++) {
265 selDays.append(days[0].addDays(i)); 265 selDays.append(days[0].addDays(i));
266 } 266 }
267 i0 = 0; 267 i0 = 0;
268 } 268 }
269 269
270 //cope with selection being out of matrix limits at bottom (> NUMDAYS-1) 270 //cope with selection being out of matrix limits at bottom (> NUMDAYS-1)
271 if (mSelEnd > NUMDAYS-1) { 271 if (mSelEnd > NUMDAYS-1) {
272 for (int i = i0; i <= NUMDAYS-1; i++) { 272 for (int i = i0; i <= NUMDAYS-1; i++) {
273 selDays.append(days[i]); 273 selDays.append(days[i]);
274 } 274 }
275 for (int i = NUMDAYS; i < mSelEnd; i++) { 275 for (int i = NUMDAYS; i < mSelEnd; i++) {
276 selDays.append(days[0].addDays(i)); 276 selDays.append(days[0].addDays(i));
277 } 277 }
278 278
279 // apply normal routine to selection being entirely within matrix limits 279 // apply normal routine to selection being entirely within matrix limits
280 } else { 280 } else {
281 for (int i = i0; i <= mSelEnd; i++) { 281 for (int i = i0; i <= mSelEnd; i++) {
282 selDays.append(days[i]); 282 selDays.append(days[i]);
283 } 283 }
284 } 284 }
285} 285}
286 286
287bool KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end) 287bool KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end)
288{ 288{
289 bool noSel = (mSelEnd == NOSELECTION && mSelStart == NOSELECTION ); 289 bool noSel = (mSelEnd == NOSELECTION && mSelStart == NOSELECTION );
290 mSelStart = startdate.daysTo(start); 290 mSelStart = startdate.daysTo(start);
291 if ( mSelStart < 0 ) 291 if ( mSelStart < 0 )
292 mSelStart = 0; 292 mSelStart = 0;
293 mSelEnd = startdate.daysTo(end); 293 mSelEnd = startdate.daysTo(end);
294 if ( mSelEnd > NUMDAYS-1 ) 294 if ( mSelEnd > NUMDAYS-1 )
295 mSelEnd = NUMDAYS-1; 295 mSelEnd = NUMDAYS-1;
296 if ( mSelEnd < 0 || mSelStart > NUMDAYS-1 ) { 296 if ( mSelEnd < 0 || mSelStart > NUMDAYS-1 ) {
297 clearSelection(); 297 clearSelection();
298 if ( noSel ) 298 if ( noSel )
299 return false; 299 return false;
300 } 300 }
301 301
302 return true; 302 return true;
303} 303}
304void KODayMatrix::clearSelection() 304void KODayMatrix::clearSelection()
305{ 305{
306 mSelEnd = mSelStart = NOSELECTION; 306 mSelEnd = mSelStart = NOSELECTION;
307} 307}
308 308
309 309
310void KODayMatrix::recalculateToday() 310void KODayMatrix::recalculateToday()
311{ 311{
312 today = -1; 312 today = -1;
313 for (int i=0; i<NUMDAYS; i++) { 313 for (int i=0; i<NUMDAYS; i++) {
314 events[i] = 0; 314 events[i] = 0;
315 days[i] = startdate.addDays(i); 315 days[i] = startdate.addDays(i);
316 daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] )); 316 daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] ));
317 317
318 // if today is in the currently displayed month, hilight today 318 // if today is in the currently displayed month, hilight today
319 if (days[i].year() == QDate::currentDate().year() && 319 if (days[i].year() == QDate::currentDate().year() &&
320 days[i].month() == QDate::currentDate().month() && 320 days[i].month() == QDate::currentDate().month() &&
321 days[i].day() == QDate::currentDate().day()) { 321 days[i].day() == QDate::currentDate().day()) {
322 today = i; 322 today = i;
323 } 323 }
324 } 324 }
325 // qDebug(QString("Today is visible at %1.").arg(today)); 325 // qDebug(QString("Today is visible at %1.").arg(today));
326} 326}
327 327
328void KODayMatrix::updateView() 328void KODayMatrix::updateView()
329{ 329{
330 updateView(startdate); 330 updateView(startdate);
331} 331}
332void KODayMatrix::repaintViewTimed() 332void KODayMatrix::repaintViewTimed()
333{ 333{
334 mRepaintTimer->stop(); 334 mRepaintTimer->stop();
335 repaint(false); 335 repaint(false);
336} 336}
337void KODayMatrix::updateViewTimed() 337void KODayMatrix::updateViewTimed()
338{ 338{
339 mUpdateTimer->stop(); 339 mUpdateTimer->stop();
340 if ( !mCalendar ) { 340 if ( !mCalendar ) {
341 qDebug("NOT CAL "); 341 qDebug("NOT CAL ");
342 return; 342 return;
343 } 343 }
344 //qDebug("KODayMatrix::updateViewTimed "); 344 //qDebug("KODayMatrix::updateViewTimed ");
345 for(int i = 0; i < NUMDAYS; i++) { 345 for(int i = 0; i < NUMDAYS; i++) {
346 // if events are set for the day then remember to draw it bold 346 // if events are set for the day then remember to draw it bold
347 QPtrList<Event> eventlist = mCalendar->events(days[i]); 347 QPtrList<Event> eventlist = mCalendar->events(days[i]);
348 Event *event; 348 Event *event;
349 int numEvents = eventlist.count(); 349 int numEvents = eventlist.count();
350 QString holiStr = ""; 350 QString holiStr = "";
351 bDays.clearBit(i); 351 bDays.clearBit(i);
352 for(event=eventlist.first();event != 0;event=eventlist.next()) { 352 for(event=eventlist.first();event != 0;event=eventlist.next()) {
353 ushort recurType = event->recurrence()->doesRecur(); 353 ushort recurType = event->recurrence()->doesRecur();
354 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || 354 if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) ||
355 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { 355 (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) {
356 numEvents--; 356 numEvents--;
357 } 357 }
358 if ( event->isHoliday()) { 358 if ( event->isHoliday()) {
359 if ( !holiStr.isEmpty() ) 359 if ( !holiStr.isEmpty() )
360 holiStr += "\n"; 360 holiStr += "\n";
361 holiStr += event->summary(); 361 holiStr += event->summary();
362 if ( !event->location().isEmpty() ) 362 if ( !event->location().isEmpty() )
363 holiStr += " (" + event->location() + ")"; 363 holiStr += " (" + event->location() + ")";
364 } 364 }
365 if ( event->isBirthday()) { 365 if ( event->isBirthday()) {
366 if ( !holiStr.isEmpty() ) 366 if ( !holiStr.isEmpty() )
367 holiStr += "\n"; 367 holiStr += "\n";
368 holiStr += i18n("Birthday") + ": "+event->summary(); 368 holiStr += i18n("Birthday") + ": "+event->summary();
369 if ( !event->location().isEmpty() ) 369 if ( !event->location().isEmpty() )
370 holiStr += " (" + event->location() + ")"; 370 holiStr += " (" + event->location() + ")";
371 bDays.setBit(i); 371 bDays.setBit(i);
372 } 372 }
373 } 373 }
374 events[i] = numEvents; 374 events[i] = numEvents;
375 //if it is a holy day then draw it red. Sundays are consider holidays, too 375 //if it is a holy day then draw it red. Sundays are consider holidays, too
376 if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) || 376 if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) ||
377 !holiStr.isEmpty()) { 377 !holiStr.isEmpty()) {
378 mHolidays[i] = holiStr; 378 mHolidays[i] = holiStr;
379 } else { 379 } else {
380 mHolidays[i] = QString::null; 380 mHolidays[i] = QString::null;
381 } 381 }
382 } 382 }
383 if ( ! mPendingUpdateBeforeRepaint ) 383 if ( ! mPendingUpdateBeforeRepaint )
384 repaint(false); 384 repaint(false);
385} 385}
386void KODayMatrix::updateView(QDate actdate) 386void KODayMatrix::updateView(QDate actdate)
387{ 387{
388 388
389 if ( ! actdate.isValid() ) { 389 if ( ! actdate.isValid() ) {
390 //qDebug("date not valid "); 390 //qDebug("date not valid ");
391 return; 391 return;
392 } 392 }
393 mDayChanged = false; 393 mDayChanged = false;
394 //flag to indicate if the starting day of the matrix has changed by this call 394 //flag to indicate if the starting day of the matrix has changed by this call
395 //mDayChanged = false; 395 //mDayChanged = false;
396 // if a new startdate is to be set then apply Cornelius's calculation 396 // if a new startdate is to be set then apply Cornelius's calculation
397 // of the first day to be shown 397 // of the first day to be shown
398 if (actdate != startdate) { 398 if (actdate != startdate) {
399 // reset index of selection according to shift of starting date from startdate to actdate 399 // reset index of selection according to shift of starting date from startdate to actdate
400 if (mSelStart != NOSELECTION) { 400 if (mSelStart != NOSELECTION) {
401 int tmp = actdate.daysTo(startdate); 401 int tmp = actdate.daysTo(startdate);
402 //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl; 402 //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl;
403 // shift selection if new one would be visible at least partly ! 403 // shift selection if new one would be visible at least partly !
404 404
405 if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) { 405 if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) {
406 // nested if is required for next X display pushed from a different month - correction required 406 // nested if is required for next X display pushed from a different month - correction required
407 // otherwise, for month forward and backward, it must be avoided 407 // otherwise, for month forward and backward, it must be avoided
408 if( mSelStart > NUMDAYS || mSelStart < 0 ) 408 if( mSelStart > NUMDAYS || mSelStart < 0 )
409 mSelStart = mSelStart + tmp; 409 mSelStart = mSelStart + tmp;
410 if( mSelEnd > NUMDAYS || mSelEnd < 0 ) 410 if( mSelEnd > NUMDAYS || mSelEnd < 0 )
411 mSelEnd = mSelEnd + tmp; 411 mSelEnd = mSelEnd + tmp;
412 } 412 }
413 } 413 }
414 startdate = actdate; 414 startdate = actdate;
415 mDayChanged = true; 415 mDayChanged = true;
416 recalculateToday(); 416 recalculateToday();
417 } 417 }
418 //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() ); 418 //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() );
419 if ( !isVisible() ) { 419 if ( !isVisible() ) {
420 mPendingUpdateBeforeRepaint = true; 420 mPendingUpdateBeforeRepaint = true;
421 } else { 421 } else {
422#ifdef DESKTOP_VERSION 422#ifdef DESKTOP_VERSION
423 //mRepaintTimer->start( 100 ); 423 //mRepaintTimer->start( 100 );
424 //updateViewTimed(); 424 //updateViewTimed();
425 mUpdateTimer->start( 20 ); 425 mUpdateTimer->start( 20 );
426#else 426#else
427 mRepaintTimer->start( 350 ); 427 mRepaintTimer->start( 350 );
428 mUpdateTimer->start( 1200 ); 428 mUpdateTimer->start( 1200 );
429#endif 429#endif
430 } 430 }
431} 431}
432void KODayMatrix::updateEvents() 432void KODayMatrix::updateEvents()
433{ 433{
434 if ( !mCalendar ) return; 434 if ( !mCalendar ) return;
435 435
436 for( int i = 0; i < NUMDAYS; i++ ) { 436 for( int i = 0; i < NUMDAYS; i++ ) {
437 // if events are set for the day then remember to draw it bold 437 // if events are set for the day then remember to draw it bold
438 QPtrList<Event> eventlist = mCalendar->events( days[ i ] ); 438 QPtrList<Event> eventlist = mCalendar->events( days[ i ] );
439 int numEvents = eventlist.count(); 439 int numEvents = eventlist.count();
440 Event *event; 440 Event *event;
441 for( event = eventlist.first(); event != 0;event=eventlist.next()) { 441 for( event = eventlist.first(); event != 0;event=eventlist.next()) {
442 ushort recurType = event->doesRecur(); 442 ushort recurType = event->doesRecur();
443 443
444 if ( ( recurType == Recurrence::rDaily && 444 if ( ( recurType == Recurrence::rDaily &&
445 !KOPrefs::instance()->mDailyRecur ) || 445 !KOPrefs::instance()->mDailyRecur ) ||
446 ( recurType == Recurrence::rWeekly && 446 ( recurType == Recurrence::rWeekly &&
447 !KOPrefs::instance()->mWeeklyRecur ) ) { 447 !KOPrefs::instance()->mWeeklyRecur ) ) {
448 numEvents--; 448 numEvents--;
449 } 449 }
450 } 450 }
451 events[ i ] = numEvents; 451 events[ i ] = numEvents;
452 } 452 }
453} 453}
454 454
455const QDate& KODayMatrix::getDate(int offset) 455const QDate& KODayMatrix::getDate(int offset)
456{ 456{
457 if (offset < 0 || offset > NUMDAYS-1) { 457 if (offset < 0 || offset > NUMDAYS-1) {
458 qDebug("Wrong offset2 %d", offset); 458 qDebug("Wrong offset2 %d", offset);
459 return days[0]; 459 return days[0];
460 } 460 }
461 return days[offset]; 461 return days[offset];
462} 462}
463 463
464QString KODayMatrix::getHolidayLabel(int offset) 464QString KODayMatrix::getHolidayLabel(int offset)
465{ 465{
466 if (offset < 0 || offset > NUMDAYS-1) { 466 if (offset < 0 || offset > NUMDAYS-1) {
467 qDebug("Wrong offset1 %d", offset); 467 qDebug("Wrong offset1 %d", offset);
468 return QString(); 468 return QString();
469 } 469 }
470 return mHolidays[offset]; 470 return mHolidays[offset];
471} 471}
472 472
473int KODayMatrix::getDayIndexFrom(int x, int y) 473int KODayMatrix::getDayIndexFrom(int x, int y)
474{ 474{
475 int colModulo = (width()-2) % 7; 475 int colModulo = (width()-2) % 7;
476 int rowModulo = (height()-2) % 6; 476 int rowModulo = (height()-2) % 6;
477#if 0 477#if 0
478 return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ? 478 return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ?
479 6 - x/daysize.width() : x/daysize.width()); 479 6 - x/daysize.width() : x/daysize.width());
480#endif 480#endif
481 int xVal = (x-colModulo/2-2)/daysize.width(); 481 int xVal = (x-colModulo/2-2)/daysize.width();
482 int yVal = (y-rowModulo/2-2)/daysize.height(); 482 int yVal = (y-rowModulo/2-2)/daysize.height();
483 483
484 484
485 return 7*(yVal) + xVal; 485 return 7*(yVal) + xVal;
486 486
487} 487}
488 488
489// ---------------------------------------------------------------------------- 489// ----------------------------------------------------------------------------
490// M O U S E E V E N T H A N D L I N G 490// M O U S E E V E N T H A N D L I N G
491// ---------------------------------------------------------------------------- 491// ----------------------------------------------------------------------------
492 492
493void KODayMatrix::mousePressEvent (QMouseEvent* e) 493void KODayMatrix::mousePressEvent (QMouseEvent* e)
494{ 494{
495 495
496 if ( e->button() == LeftButton ) 496 if ( e->button() == LeftButton )
497 mouseDown = true; 497 mouseDown = true;
498 mSelStart = getDayIndexFrom(e->x(), e->y()); 498 mSelStart = getDayIndexFrom(e->x(), e->y());
499 if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1; 499 if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1;
500 mSelInit = mSelStart; 500 mSelInit = mSelStart;
501 mSelEnd = mSelStart; 501 mSelEnd = mSelStart;
502 repaint(false); 502 repaint(false);
503} 503}
504 504
505void KODayMatrix::mouseReleaseEvent (QMouseEvent* e) 505void KODayMatrix::mouseReleaseEvent (QMouseEvent* e)
506{ 506{
507 if ( e->button() == LeftButton ) 507 if ( e->button() == LeftButton )
508 if ( ! mouseDown ) { 508 if ( ! mouseDown ) {
509 return; 509 return;
510 } 510 }
511 else 511 else
512 mouseDown = false; 512 mouseDown = false;
513 int tmp = getDayIndexFrom(e->x(), e->y()); 513 int tmp = getDayIndexFrom(e->x(), e->y());
514 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; 514 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1;
515 515
516 if (mSelInit > tmp) { 516 if (mSelInit > tmp) {
517 mSelEnd = mSelInit; 517 mSelEnd = mSelInit;
518 if (tmp != mSelStart) { 518 if (tmp != mSelStart) {
519 mSelStart = tmp; 519 mSelStart = tmp;
520 repaint(false); 520 repaint(false);
521 } 521 }
522 } else { 522 } else {
523 mSelStart = mSelInit; 523 mSelStart = mSelInit;
524 524
525 //repaint only if selection has changed 525 //repaint only if selection has changed
526 if (tmp != mSelEnd) { 526 if (tmp != mSelEnd) {
527 mSelEnd = tmp; 527 mSelEnd = tmp;
528 repaint(false); 528 repaint(false);
529 } 529 }
530 } 530 }
531 531
532 DateList daylist; 532 DateList daylist;
533 if ( mSelStart < 0 ) 533 if ( mSelStart < 0 )
534 mSelStart = 0; 534 mSelStart = 0;
535 for (int i = mSelStart; i <= mSelEnd; i++) { 535 for (int i = mSelStart; i <= mSelEnd; i++) {
536 daylist.append(days[i]); 536 daylist.append(days[i]);
537 } 537 }
538 emit selected((const DateList)daylist); 538 emit selected((const DateList)daylist);
539 539
540} 540}
541 541
542void KODayMatrix::mouseMoveEvent (QMouseEvent* e) 542void KODayMatrix::mouseMoveEvent (QMouseEvent* e)
543{ 543{
544 if ( ! mouseDown ) { 544 if ( ! mouseDown ) {
545 return; 545 return;
546 } 546 }
547 int tmp = getDayIndexFrom(e->x(), e->y()); 547 int tmp = getDayIndexFrom(e->x(), e->y());
548 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; 548 if (tmp > NUMDAYS-1) tmp=NUMDAYS-1;
549 549
550 if (mSelInit > tmp) { 550 if (mSelInit > tmp) {
551 mSelEnd = mSelInit; 551 mSelEnd = mSelInit;
552 if (tmp != mSelStart) { 552 if (tmp != mSelStart) {
553 mSelStart = tmp; 553 mSelStart = tmp;
554 repaint(false); 554 repaint(false);
555 } 555 }
556 } else { 556 } else {
557 mSelStart = mSelInit; 557 mSelStart = mSelInit;
558 558
559 //repaint only if selection has changed 559 //repaint only if selection has changed
560 if (tmp != mSelEnd) { 560 if (tmp != mSelEnd) {
561 mSelEnd = tmp; 561 mSelEnd = tmp;
562 repaint(false); 562 repaint(false);
563 } 563 }
564 } 564 }
565} 565}
566 566
567// ---------------------------------------------------------------------------- 567// ----------------------------------------------------------------------------
568// D R A G ' N D R O P H A N D L I N G 568// D R A G ' N D R O P H A N D L I N G
569// ---------------------------------------------------------------------------- 569// ----------------------------------------------------------------------------
570 570
571void KODayMatrix::dragEnterEvent(QDragEnterEvent *e) 571void KODayMatrix::dragEnterEvent(QDragEnterEvent *e)
572{ 572{
573#ifndef KORG_NODND 573#ifndef KORG_NODND
574 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { 574 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
575 e->ignore(); 575 e->ignore();
576 return; 576 return;
577 } 577 }
578 578
579 // some visual feedback 579 // some visual feedback
580// oldPalette = palette(); 580// oldPalette = palette();
581// setPalette(my_HilitePalette); 581// setPalette(my_HilitePalette);
582// update(); 582// update();
583#endif 583#endif
584} 584}
585 585
586void KODayMatrix::dragMoveEvent(QDragMoveEvent *e) 586void KODayMatrix::dragMoveEvent(QDragMoveEvent *e)
587{ 587{
588#ifndef KORG_NODND 588#ifndef KORG_NODND
589 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { 589 if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
590 e->ignore(); 590 e->ignore();
591 return; 591 return;
592 } 592 }
593 593
594 e->accept(); 594 e->accept();
595#endif 595#endif
596} 596}
597 597
598void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/) 598void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/)
599{ 599{
600#ifndef KORG_NODND 600#ifndef KORG_NODND
601// setPalette(oldPalette); 601// setPalette(oldPalette);
602// update(); 602// update();
603#endif 603#endif
604} 604}
605 605
606void KODayMatrix::dropEvent(QDropEvent *e) 606void KODayMatrix::dropEvent(QDropEvent *e)
607{ 607{
608#ifndef KORG_NODND 608#ifndef KORG_NODND
609// kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl; 609// kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl;
610 610
611 if (!mCalendar || !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { 611 if (!mCalendar || !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) {
612 e->ignore(); 612 e->ignore();
613 return; 613 return;
614 } 614 }
615 615
616 DndFactory factory( mCalendar ); 616 DndFactory factory( mCalendar );
617 Event *event = factory.createDrop(e); 617 Event *event = factory.createDrop(e);
618 618
619 if (event) { 619 if (event) {
620 e->acceptAction(); 620 e->acceptAction();
621 621
622 Event *existingEvent = mCalendar->event(event->uid()); 622 Event *existingEvent = mCalendar->event(event->uid());
623 623
624 if(existingEvent) { 624 if(existingEvent) {
625 // uniquify event 625 // uniquify event
626 event->recreate(); 626 event->recreate();
627/* 627/*
628 KMessageBox::sorry(this, 628 KMessageBox::sorry(this,
629 i18n("Event already exists in this calendar."), 629 i18n("Event already exists in this calendar."),
630 i18n("Drop Event")); 630 i18n("Drop Event"));
631 delete event; 631 delete event;
632 return; 632 return;
633*/ 633*/
634 } 634 }
635// kdDebug() << "Drop new Event" << endl; 635// kdDebug() << "Drop new Event" << endl;
636 // Adjust date 636 // Adjust date
637 QDateTime start = event->dtStart(); 637 QDateTime start = event->dtStart();
638 QDateTime end = event->dtEnd(); 638 QDateTime end = event->dtEnd();
639 int duration = start.daysTo(end); 639 int duration = start.daysTo(end);
640 int idx = getDayIndexFrom(e->pos().x(), e->pos().y()); 640 int idx = getDayIndexFrom(e->pos().x(), e->pos().y());
641 641
642 start.setDate(days[idx]); 642 start.setDate(days[idx]);
643 end.setDate(days[idx].addDays(duration)); 643 end.setDate(days[idx].addDays(duration));
644 644
645 event->setDtStart(start); 645 event->setDtStart(start);
646 event->setDtEnd(end); 646 event->setDtEnd(end);
647 mCalendar->addEvent(event); 647 mCalendar->addEvent(event);
648 648
649 emit eventDropped(event); 649 emit eventDropped(event);
650 } else { 650 } else {
651// kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl; 651// kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl;
652 e->ignore(); 652 e->ignore();
653 } 653 }
654#endif 654#endif
655} 655}
656 656
657// ---------------------------------------------------------------------------- 657// ----------------------------------------------------------------------------
658// P A I N T E V E N T H A N D L I N G 658// P A I N T E V E N T H A N D L I N G
659// ---------------------------------------------------------------------------- 659// ----------------------------------------------------------------------------
660 660
661void KODayMatrix::paintEvent(QPaintEvent * pevent) 661void KODayMatrix::paintEvent(QPaintEvent * pevent)
662{ 662{
663 QRect sz = frameRect(); 663 QRect sz = frameRect();
664 if ( sz.width() <= 0 || sz.height() <= 0 ) 664 if ( sz.width() <= 0 || sz.height() <= 0 )
665 return; 665 return;
666 if ( mPendingUpdateBeforeRepaint ) { 666 if ( mPendingUpdateBeforeRepaint ) {
667 updateViewTimed(); 667 updateViewTimed();
668 mPendingUpdateBeforeRepaint = false; 668 mPendingUpdateBeforeRepaint = false;
669 } 669 }
670 if ( myPix.width() != sz.width() || myPix.height()!=sz.height() ) { 670 if ( myPix.width() != sz.width() || myPix.height()!=sz.height() ) {
671 myPix.resize(sz.size() ); 671 myPix.resize(sz.size() );
672 } 672 }
673 QPainter p(&myPix); 673 QPainter p(&myPix);
674 p.setFont(font()); 674 p.setFont(font());
675 675
676 676
677 int dheight = daysize.height(); 677 int dheight = daysize.height();
678 int dwidth = daysize.width(); 678 int dwidth = daysize.width();
679 int row,col; 679 int row,col;
680 int selw, selh; 680 int selw, selh;
681 int xyOff = frameWidth(); 681 int xyOff = frameWidth();
682 int colModulo = sz.width() % 7; 682 int colModulo = sz.width() % 7;
683 int rowModulo = sz.height() % 6; 683 int rowModulo = sz.height() % 6;
684 //qDebug("col %d row %d ",colModulo,rowModulo ); 684 //qDebug("col %d row %d ",colModulo,rowModulo );
685 685
686 bool isRTL = KOGlobals::self()->reverseLayout(); 686 bool isRTL = KOGlobals::self()->reverseLayout();
687 687
688 // draw background and topleft frame 688 // draw background and topleft frame
689 p.fillRect(pevent->rect(), mDefaultBackColor); 689 p.fillRect(pevent->rect(), mDefaultBackColor);
690 p.setPen(mDefaultTextColor); 690 p.setPen(mDefaultTextColor);
691 p.drawRect(0, 0, sz.width()+1, sz.height()+1); 691 p.drawRect(0, 0, sz.width()+1, sz.height()+1);
692 int mSelStartT = mSelStart; 692 int mSelStartT = mSelStart;
693 int mSelEndT = mSelEnd; 693 int mSelEndT = mSelEnd;
694 if ( mSelEndT >= NUMDAYS ) 694 if ( mSelEndT >= NUMDAYS )
695 mSelEndT = NUMDAYS-1; 695 mSelEndT = NUMDAYS-1;
696 // draw selected days with highlighted background color 696 // draw selected days with highlighted background color
697 if (mSelStart != NOSELECTION) { 697 if (mSelStart != NOSELECTION) {
698 bool skip = false; 698 bool skip = false;
699 if ( ! mouseDown ) { 699 if ( ! mouseDown ) {
700 int mo = days[20].month(); 700 int mo = days[20].month();
701 //qDebug("-- %d %d ", mSelStartT, mSelEndT); 701 //qDebug("-- %d %d ", mSelStartT, mSelEndT);
702 //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() ); 702 //qDebug("%d %d %d - d %d", mo, days[mSelStartT].month() , days[mSelEndT].month(), days[mSelEndT].day() );
703 int startMo = days[mSelStartT].month(); 703 int startMo = days[mSelStartT].month();
704 int endMo = days[mSelEndT].month(); 704 int endMo = days[mSelEndT].month();
705 if ( startMo == 12 && mo == 1 && endMo <= 2 ) 705 if ( startMo == 12 && mo == 1 && endMo <= 2 )
706 startMo = 1; 706 startMo = 1;
707 if ( endMo == 1 && mo == 12 ) 707 if ( endMo == 1 && mo == 12 )
708 endMo = 12; 708 endMo = 12;
709 if ( mo == 12 && startMo == 1 ) 709 if ( mo == 12 && startMo == 1 )
710 startMo = 13; 710 startMo = 13;
711 if ( (startMo > mo || endMo < mo) ) { 711 if ( (startMo > mo || endMo < mo) ) {
712 skip = true; 712 skip = true;
713 } else { 713 } else {
714 if ( days[mSelStartT].month() != mo ) { 714 if ( days[mSelStartT].month() != mo ) {
715 int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day(); 715 int add = days[mSelStartT].daysInMonth ()-days[mSelStartT].day();
716 mSelStartT += add +1; 716 mSelStartT += add +1;
717 } 717 }
718 if ( days[mSelEndT].month() != mo ) { 718 if ( days[mSelEndT].month() != mo ) {
719 int sub = days[mSelEndT].day(); 719 int sub = days[mSelEndT].day();
720 mSelEndT -= sub ; 720 mSelEndT -= sub ;
721 } 721 }
722 } 722 }
723 } 723 }
724 //qDebug("SKIP %d ", skip); 724 //qDebug("SKIP %d ", skip);
725 if ( ! skip ) { 725 if ( ! skip ) {
726 row = mSelStartT/7; 726 row = mSelStartT/7;
727 col = mSelStartT -row*7; 727 col = mSelStartT -row*7;
728 QColor selcol = KOPrefs::instance()->mHighlightColor; 728 QColor selcol = KOPrefs::instance()->mHighlightColor;
729 int addCol = 0; 729 int addCol = 0;
730 int addRow = 0; 730 int addRow = 0;
731 int addRow2 = 0; 731 int addRow2 = 0;
732 int addCol2 = 0; 732 int addCol2 = 0;
733 if (row == mSelEndT/7) { 733 if (row == mSelEndT/7) {
734 if ( rowModulo ) { 734 if ( rowModulo ) {
735 if ( row >= 6 - rowModulo ) 735 if ( row >= 6 - rowModulo )
736 addRow = row - 5 + rowModulo; 736 addRow = row - 5 + rowModulo;
737 } 737 }
738 if ( colModulo ) { 738 if ( colModulo ) {
739 int colt1 = mSelEndT%7; 739 int colt1 = mSelEndT%7;
740 //qDebug("colt1 %d ", colt1 ); 740 //qDebug("colt1 %d ", colt1 );
741 if ( colt1 >= 7 - colModulo ) 741 if ( colt1 >= 7 - colModulo )
742 addCol = colt1 - 7 + colModulo+1; 742 addCol = colt1 - 7 + colModulo+1;
743 int colt = mSelStartT%7; 743 int colt = mSelStartT%7;
744 if ( colt >= 7 - colModulo ) 744 if ( colt >= 7 - colModulo )
745 addCol2 = colt - 7 + colModulo; 745 addCol2 = colt - 7 + colModulo;
746 addCol -= addCol2; 746 addCol -= addCol2;
747 //qDebug("COL %d %d %d %d ",col , colt1 ,addCol ,addCol2 ); 747 //qDebug("COL %d %d %d %d ",col , colt1 ,addCol ,addCol2 );
748 } 748 }
749 // Single row selection 749 // Single row selection
750 if ( row == 0) 750 if ( row == 0)
751 addRow = 1; 751 addRow = 1;
752 p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth+1+addCol2, 752 p.fillRect(isRTL ? (7 - (mSelEndT-mSelStartT+1) - col)*dwidth : col*dwidth+1+addCol2,
753 row*dheight+addRow, (mSelEndT-mSelStartT+1)*dwidth+addCol, dheight+1, selcol); 753 row*dheight+addRow, (mSelEndT-mSelStartT+1)*dwidth+addCol, dheight+1, selcol);
754 } else { 754 } else {
755 // draw first row to the right 755 // draw first row to the right
756 if ( colModulo ) { 756 if ( colModulo ) {
757 if ( col >= 7 - colModulo ) 757 if ( col >= 7 - colModulo )
758 addCol2 = col - 7 + colModulo; 758 addCol2 = col - 7 + colModulo;
759 } 759 }
760 if ( rowModulo ) { 760 if ( rowModulo ) {
761 if ( row >= 6 - rowModulo ) 761 if ( row >= 6 - rowModulo )
762 addRow = row - 5 + rowModulo; 762 addRow = row - 5 + rowModulo;
763 } 763 }
764 if ( row == 0) 764 if ( row == 0)
765 addRow = 1; 765 addRow = 1;
766 p.fillRect(isRTL ? 0 : col*dwidth+1+addCol2, row*dheight+addRow, (7-col)*dwidth+colModulo, 766 p.fillRect(isRTL ? 0 : col*dwidth+1+addCol2, row*dheight+addRow, (7-col)*dwidth+colModulo,
767 dheight+1, selcol); 767 dheight+1, selcol);
768 // draw full block till last line 768 // draw full block till last line
769 selh = mSelEndT/7-row; 769 selh = mSelEndT/7-row;
770 addRow = 0; 770 addRow = 0;
771 if ( rowModulo ) { 771 if ( rowModulo ) {
772 if ( mSelEndT/7 >= 6 - rowModulo ) 772 if ( mSelEndT/7 >= 6 - rowModulo )
773 addRow = mSelEndT/7 - 5 + rowModulo; 773 addRow = mSelEndT/7 - 5 + rowModulo;
774 } 774 }
775 if (selh > 1) { 775 if (selh > 1) {
776 p.fillRect(1, (row+1)*dheight, 7*dwidth+colModulo, (selh-1)*dheight+addRow,selcol); 776 p.fillRect(1, (row+1)*dheight, 7*dwidth+colModulo, (selh-1)*dheight+addRow,selcol);
777 } 777 }
778 // draw last block from left to mSelEndT 778 // draw last block from left to mSelEndT
779 selw = mSelEndT-7*(mSelEndT/7)+1; 779 selw = mSelEndT-7*(mSelEndT/7)+1;
780 //qDebug("esl %d ",selw ); 780 //qDebug("esl %d ",selw );
781 int add = 0; 781 int add = 0;
782 if ( colModulo ) { 782 if ( colModulo ) {
783 add = 7 - colModulo; 783 add = 7 - colModulo;
784 if ( selw > add ) 784 if ( selw > add )
785 add = selw - add; 785 add = selw - add;
786 else 786 else
787 add = 0; 787 add = 0;
788 } 788 }
789 //qDebug("add %d ", add); 789 //qDebug("add %d ", add);
790 p.fillRect(isRTL ? (7-selw)*dwidth : 1, (row+selh)*dheight+addRow, 790 p.fillRect(isRTL ? (7-selw)*dwidth : 1, (row+selh)*dheight+addRow,
791 selw*dwidth+add, dheight+1, selcol); 791 selw*dwidth+add, dheight+1, selcol);
792 } 792 }
793 } 793 }
794 } 794 }
795 795
796 // iterate over all days in the matrix and draw the day label in appropriate colors 796 // iterate over all days in the matrix and draw the day label in appropriate colors
797 QColor actcol = mDefaultTextColorShaded; 797 QColor actcol = mDefaultTextColorShaded;
798 p.setPen(actcol); 798 p.setPen(actcol);
799 QPen tmppen; 799 QPen tmppen;
800 for(int i = 0; i < NUMDAYS; i++) { 800 for(int i = 0; i < NUMDAYS; i++) {
801 row = i/7; 801 row = i/7;
802 col = isRTL ? 6-(i-row*7) : i-row*7; 802 col = isRTL ? 6-(i-row*7) : i-row*7;
803 803
804 // if it is the first day of a month switch color from normal to shaded and vice versa 804 // if it is the first day of a month switch color from normal to shaded and vice versa
805 if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) { 805 if ( KOGlobals::self()->calendarSystem()->day( days[i] ) == 1) {
806 if (actcol == mDefaultTextColorShaded) { 806 if (actcol == mDefaultTextColorShaded) {
807 actcol = mDefaultTextColor; 807 actcol = mDefaultTextColor;
808 } else { 808 } else {
809 actcol = mDefaultTextColorShaded; 809 actcol = mDefaultTextColorShaded;
810 } 810 }
811 p.setPen(actcol); 811 p.setPen(actcol);
812 } 812 }
813 if (actcol == mDefaultTextColorShaded) { 813 if (actcol == mDefaultTextColorShaded) {
814 if ( ! mouseDown ) { 814 if ( ! mouseDown ) {
815 continue; 815 continue;
816 } 816 }
817 } 817 }
818 //Reset pen color after selected days block 818 //Reset pen color after selected days block
819 if (i == mSelEndT+1) { 819 if (i == mSelEndT+1) {
820 p.setPen(actcol); 820 p.setPen(actcol);
821 } 821 }
822 822
823 // if today then draw rectangle around day 823 // if today then draw rectangle around day
824 if (today == i) { 824 if (today == i) {
825 tmppen = p.pen(); 825 tmppen = p.pen();
826 QPen mTodayPen(p.pen()); 826 QPen mTodayPen(p.pen());
827 if ( daysize.width() < 20 ) 827 if ( daysize.width() < 20 )
828 mTodayPen.setWidth(1); 828 mTodayPen.setWidth(1);
829 else 829 else
830 mTodayPen.setWidth(mTodayMarginWidth); 830 mTodayPen.setWidth(mTodayMarginWidth);
831 //draw red rectangle for holidays 831 //draw red rectangle for holidays
832 if (!mHolidays[i].isNull()) { 832 if (!mHolidays[i].isNull()) {
833 if (actcol == mDefaultTextColor) { 833 if (actcol == mDefaultTextColor) {
834 mTodayPen.setColor(KOPrefs::instance()->mHolidayColor); 834 mTodayPen.setColor(KOPrefs::instance()->mHolidayColor);
835 } else { 835 } else {
836 mTodayPen.setColor(mHolidayColorShaded); 836 mTodayPen.setColor(mHolidayColorShaded);
837 } 837 }
838 } 838 }
839 //draw gray rectangle for today if in selection 839 //draw gray rectangle for today if in selection
840 if (i >= mSelStartT && i <= mSelEndT) { 840 if (i >= mSelStartT && i <= mSelEndT) {
841 QColor grey("grey"); 841 QColor grey("grey");
842 mTodayPen.setColor(grey); 842 mTodayPen.setColor(grey);
843 } 843 }
844 p.setPen(mTodayPen); 844 p.setPen(mTodayPen);
845 845
846 846
847 int addCol = 0; 847 int addCol = 0;
848 int addRow = 0; 848 int addRow = 0;
849 if (rowModulo) { 849 if (rowModulo) {
850 if ( row >= 6 - rowModulo ) 850 if ( row >= 6 - rowModulo )
851 addRow = row - 5 + rowModulo; 851 addRow = row - 5 + rowModulo;
852 } 852 }
853 if ( colModulo ) { 853 if ( colModulo ) {
854 if ( col >= 7 - colModulo ) 854 if ( col >= 7 - colModulo )
855 addCol = col - 6 + colModulo-1; 855 addCol = col - 6 + colModulo-1;
856 } 856 }
857 857
858 addCol += 1; 858 addCol += 1;
859 p.drawRect(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight+1); 859 p.drawRect(col*dwidth+addCol, row*dheight+addRow, dwidth, dheight+1);
860 p.setPen(tmppen); 860 p.setPen(tmppen);
861 } 861 }
862 862
863 // if any events are on that day then draw it using a bold font 863 // if any events are on that day then draw it using a bold font
864 if (events[i] > 0) { 864 if (events[i] > 0) {
865 QFont myFont = font(); 865 QFont myFont = font();
866 myFont.setBold(true); 866 myFont.setBold(true);
867 p.setFont(myFont); 867 p.setFont(myFont);
868 } 868 }
869 869
870 // if it is a holiday then use the default holiday color 870 // if it is a holiday then use the default holiday color
871 if (!mHolidays[i].isNull()) { 871 if (!mHolidays[i].isNull()) {
872 if ( bDays.testBit(i) ) { 872 if ( bDays.testBit(i) ) {
873 p.setPen(Qt::green); 873 p.setPen(Qt::green);
874 } else { 874 } else {