-rw-r--r-- | korganizer/datenavigatorcontainer.cpp | 3 | ||||
-rw-r--r-- | korganizer/kdatenavigator.cpp | 2 | ||||
-rw-r--r-- | korganizer/kodaymatrix.cpp | 6 |
3 files changed, 6 insertions, 5 deletions
diff --git a/korganizer/datenavigatorcontainer.cpp b/korganizer/datenavigatorcontainer.cpp index 5941337..d4173e8 100644 --- a/korganizer/datenavigatorcontainer.cpp +++ b/korganizer/datenavigatorcontainer.cpp | |||
@@ -1,261 +1,262 @@ | |||
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 | ||
38 | DateNavigatorContainer::DateNavigatorContainer( QWidget *parent, | 38 | DateNavigatorContainer::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 | } | 48 | } |
49 | 49 | ||
50 | DateNavigatorContainer::~DateNavigatorContainer() | 50 | DateNavigatorContainer::~DateNavigatorContainer() |
51 | { | 51 | { |
52 | } | 52 | } |
53 | 53 | ||
54 | void DateNavigatorContainer::connectNavigatorView( KDateNavigator *v ) | 54 | void DateNavigatorContainer::connectNavigatorView( KDateNavigator *v ) |
55 | { | 55 | { |
56 | connect( v, SIGNAL( datesSelected( const KCal::DateList & ) ), | 56 | connect( v, SIGNAL( datesSelected( const KCal::DateList & ) ), |
57 | SIGNAL( datesSelected( const KCal::DateList & ) ) ); | 57 | SIGNAL( datesSelected( const KCal::DateList & ) ) ); |
58 | #if 0 | 58 | #if 0 |
59 | connect( v, SIGNAL( incidenceDropped( Incidence *, const QDate & ) ), | 59 | connect( v, SIGNAL( incidenceDropped( Incidence *, const QDate & ) ), |
60 | SIGNAL( incidenceDropped( Incidence *, const QDate & ) ) ); | 60 | SIGNAL( incidenceDropped( Incidence *, const QDate & ) ) ); |
61 | connect( v, SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ), | 61 | connect( v, SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ), |
62 | SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ) ); | 62 | SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ) ); |
63 | #endif | 63 | #endif |
64 | connect( v, SIGNAL( weekClicked( const QDate & ) ), | 64 | connect( v, SIGNAL( weekClicked( const QDate & ) ), |
65 | SIGNAL( weekClicked( const QDate & ) ) ); | 65 | SIGNAL( weekClicked( const QDate & ) ) ); |
66 | 66 | ||
67 | connect( v, SIGNAL( goPrevious() ), SIGNAL( goPrevious() ) ); | 67 | connect( v, SIGNAL( goPrevious() ), SIGNAL( goPrevious() ) ); |
68 | connect( v, SIGNAL( goNext() ), SIGNAL( goNext() ) ); | 68 | connect( v, SIGNAL( goNext() ), SIGNAL( goNext() ) ); |
69 | 69 | ||
70 | connect( v, SIGNAL( goNextMonth() ), SIGNAL( goNextMonth() ) ); | 70 | connect( v, SIGNAL( goNextMonth() ), SIGNAL( goNextMonth() ) ); |
71 | connect( v, SIGNAL( goPrevMonth() ), SIGNAL( goPrevMonth() ) ); | 71 | connect( v, SIGNAL( goPrevMonth() ), SIGNAL( goPrevMonth() ) ); |
72 | connect( v, SIGNAL( goNextYear() ), SIGNAL( goNextYear() ) ); | 72 | connect( v, SIGNAL( goNextYear() ), SIGNAL( goNextYear() ) ); |
73 | connect( v, SIGNAL( goPrevYear() ), SIGNAL( goPrevYear() ) ); | 73 | connect( v, SIGNAL( goPrevYear() ), SIGNAL( goPrevYear() ) ); |
74 | 74 | ||
75 | connect( v, SIGNAL( monthSelected( int ) ), SIGNAL( monthSelected( int ) ) ); | 75 | connect( v, SIGNAL( monthSelected( int ) ), SIGNAL( monthSelected( int ) ) ); |
76 | } | 76 | } |
77 | 77 | ||
78 | void DateNavigatorContainer::setCalendar( Calendar *cal ) | 78 | void DateNavigatorContainer::setCalendar( Calendar *cal ) |
79 | { | 79 | { |
80 | mCalendar = cal; | 80 | mCalendar = cal; |
81 | mNavigatorView->setCalendar( cal ); | 81 | mNavigatorView->setCalendar( cal ); |
82 | KDateNavigator *n; | 82 | KDateNavigator *n; |
83 | for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { | 83 | for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { |
84 | n->setCalendar( cal ); | 84 | n->setCalendar( cal ); |
85 | } | 85 | } |
86 | } | 86 | } |
87 | 87 | ||
88 | void DateNavigatorContainer::updateDayMatrix() | 88 | void DateNavigatorContainer::updateDayMatrix() |
89 | { | 89 | { |
90 | mNavigatorView->updateDayMatrix(); | 90 | mNavigatorView->updateDayMatrix(); |
91 | KDateNavigator *n; | 91 | KDateNavigator *n; |
92 | for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { | 92 | for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { |
93 | n->updateDayMatrix(); | 93 | n->updateDayMatrix(); |
94 | } | 94 | } |
95 | } | 95 | } |
96 | 96 | ||
97 | void DateNavigatorContainer::updateToday() | 97 | void DateNavigatorContainer::updateToday() |
98 | { | 98 | { |
99 | qDebug("DateNavigatorContainer::updateToday() NOT IMPL "); | 99 | qDebug("DateNavigatorContainer::updateToday() NOT IMPL "); |
100 | #if 0 | 100 | #if 0 |
101 | mNavigatorView->updateToday(); | 101 | mNavigatorView->updateToday(); |
102 | KDateNavigator *n; | 102 | KDateNavigator *n; |
103 | for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { | 103 | for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { |
104 | n->updateToday(); | 104 | n->updateToday(); |
105 | } | 105 | } |
106 | #endif | 106 | #endif |
107 | } | 107 | } |
108 | 108 | ||
109 | void DateNavigatorContainer::updateView() | 109 | void DateNavigatorContainer::updateView() |
110 | { | 110 | { |
111 | mNavigatorView->updateView(); | 111 | mNavigatorView->updateView(); |
112 | KDateNavigator *n; | 112 | KDateNavigator *n; |
113 | for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { | 113 | for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { |
114 | n->updateView(); | 114 | n->updateView(); |
115 | } | 115 | } |
116 | } | 116 | } |
117 | 117 | ||
118 | void DateNavigatorContainer::updateConfig() | 118 | void DateNavigatorContainer::updateConfig() |
119 | { | 119 | { |
120 | mNavigatorView->updateConfig(); | 120 | mNavigatorView->updateConfig(); |
121 | KDateNavigator *n; | 121 | KDateNavigator *n; |
122 | for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { | 122 | for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { |
123 | n->updateConfig(); | 123 | n->updateConfig(); |
124 | } | 124 | } |
125 | } | 125 | } |
126 | 126 | ||
127 | void DateNavigatorContainer::selectDates( const DateList &dateList ) | 127 | void DateNavigatorContainer::selectDates( const DateList &dateList ) |
128 | { | 128 | { |
129 | mNavigatorView->selectDates( dateList ); | 129 | mNavigatorView->selectDates( dateList ); |
130 | setBaseDates(); | 130 | setBaseDates(); |
131 | if ( mExtraViews.count() ) { | 131 | if ( mExtraViews.count() ) { |
132 | KDateNavigator *view = mExtraViews.at( 0 ); | 132 | KDateNavigator *view = mExtraViews.at( 0 ); |
133 | view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end())); | 133 | view->dayMatrix()->setSelectedDaysFrom(*(dateList.begin()), *(--dateList.end())); |
134 | view->dayMatrix()->repaint(); | 134 | view->dayMatrix()->repaint(); |
135 | } | 135 | } |
136 | } | 136 | } |
137 | 137 | ||
138 | void DateNavigatorContainer::setBaseDates() | 138 | void DateNavigatorContainer::setBaseDates() |
139 | { | 139 | { |
140 | KCal::DateList dateList = mNavigatorView->selectedDates(); | 140 | KCal::DateList dateList = mNavigatorView->selectedDates(); |
141 | if ( dateList.isEmpty() ) { | 141 | if ( dateList.isEmpty() ) { |
142 | kdError() << "DateNavigatorContainer::selectDates() empty list." << endl; | 142 | kdError() << "DateNavigatorContainer::selectDates() empty list." << endl; |
143 | } | 143 | } |
144 | QDate baseDate = dateList.first(); | 144 | QDate baseDate = dateList.first(); |
145 | KDateNavigator *n; | 145 | KDateNavigator *n; |
146 | bool doRepaint = false; // skip first repaint | 146 | bool doRepaint = false; // skip first repaint |
147 | for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { | 147 | for( n = mExtraViews.first(); n; n = mExtraViews.next() ) { |
148 | baseDate = baseDate.addDays( baseDate.daysInMonth () - baseDate.day() +1 ); | 148 | baseDate = baseDate.addDays( baseDate.daysInMonth () - baseDate.day() +1 ); |
149 | n->setBaseDate( baseDate, doRepaint ); | 149 | n->setBaseDate( baseDate, doRepaint ); |
150 | doRepaint = true; | 150 | doRepaint = true; |
151 | } | 151 | } |
152 | } | 152 | } |
153 | 153 | ||
154 | void DateNavigatorContainer::resizeEvent( QResizeEvent * e ) | 154 | void DateNavigatorContainer::resizeEvent( QResizeEvent * e ) |
155 | { | 155 | { |
156 | #if 0 | 156 | #if 0 |
157 | kdDebug(5850) << "DateNavigatorContainer::resizeEvent()" << endl; | 157 | kdDebug(5850) << "DateNavigatorContainer::resizeEvent()" << endl; |
158 | kdDebug(5850) << " CURRENT SIZE: " << size() << endl; | 158 | kdDebug(5850) << " CURRENT SIZE: " << size() << endl; |
159 | kdDebug(5850) << " MINIMUM SIZEHINT: " << minimumSizeHint() << endl; | 159 | kdDebug(5850) << " MINIMUM SIZEHINT: " << minimumSizeHint() << endl; |
160 | kdDebug(5850) << " SIZEHINT: " << sizeHint() << endl; | 160 | kdDebug(5850) << " SIZEHINT: " << sizeHint() << endl; |
161 | kdDebug(5850) << " MINIMUM SIZE: " << minimumSize() << endl; | 161 | kdDebug(5850) << " MINIMUM SIZE: " << minimumSize() << endl; |
162 | #endif | 162 | #endif |
163 | QSize minSize = mNavigatorView->sizeHintTwoButtons(); | 163 | //QSize minSize = mNavigatorView->sizeHintTwoButtons(); |
164 | QSize minSize = mNavigatorView->yourSizeHint(); | ||
164 | 165 | ||
165 | // kdDebug(5850) << " NAVIGATORVIEW minimumSizeHint: " << minSize << endl; | 166 | // kdDebug(5850) << " NAVIGATORVIEW minimumSizeHint: " << minSize << endl; |
166 | 167 | ||
167 | int verticalCount = size().height() / minSize.height(); | 168 | int verticalCount = size().height() / minSize.height(); |
168 | int horizontalCount = size().width() / minSize.width(); | 169 | int horizontalCount = size().width() / minSize.width(); |
169 | //qDebug(" wattdatt %d new %d %d ", size().width() ,e->size().width() , minSize.width() ); | 170 | //qDebug(" wattdatt %d new %d %d ", size().width() ,e->size().width() , minSize.width() ); |
170 | //qDebug("COUNT %d %d %d %d ", verticalCount, horizontalCount , mVerticalCount, mHorizontalCount ); | 171 | //qDebug("COUNT %d %d %d %d ", verticalCount, horizontalCount , mVerticalCount, mHorizontalCount ); |
171 | bool fontchange = false; | 172 | bool fontchange = false; |
172 | QFont fo; | 173 | QFont fo; |
173 | if ( horizontalCount != mHorizontalCount || | 174 | if ( horizontalCount != mHorizontalCount || |
174 | verticalCount != mVerticalCount ) { | 175 | verticalCount != mVerticalCount ) { |
175 | uint count = horizontalCount * verticalCount; | 176 | uint count = horizontalCount * verticalCount; |
176 | if ( count == 0 ) { | 177 | if ( count == 0 ) { |
177 | bool ok; | 178 | bool ok; |
178 | fo = mNavigatorView->yourFontHint( size() , &ok); | 179 | fo = mNavigatorView->yourFontHint( size() , &ok); |
179 | //mNavigatorView->resize( size() ); | 180 | //mNavigatorView->resize( size() ); |
180 | //if ( ! ok ) | 181 | //if ( ! ok ) |
181 | // return; | 182 | // return; |
182 | minSize = mNavigatorView->sizeHintTwoButtons(); | 183 | minSize = mNavigatorView->sizeHintTwoButtons(); |
183 | verticalCount = size().height() / minSize.height(); | 184 | verticalCount = size().height() / minSize.height(); |
184 | horizontalCount = size().width() / minSize.width(); | 185 | horizontalCount = size().width() / minSize.width(); |
185 | if ( horizontalCount == 0 ) | 186 | if ( horizontalCount == 0 ) |
186 | horizontalCount = 1; | 187 | horizontalCount = 1; |
187 | if ( verticalCount == 0 ) | 188 | if ( verticalCount == 0 ) |
188 | verticalCount = 1; | 189 | verticalCount = 1; |
189 | fontchange = true; | 190 | fontchange = true; |
190 | count = horizontalCount * verticalCount; | 191 | count = horizontalCount * verticalCount; |
191 | } else { | 192 | } else { |
192 | if ( mNavigatorView->fontChanged() ) { | 193 | if ( mNavigatorView->fontChanged() ) { |
193 | fontchange = true; | 194 | fontchange = true; |
194 | fo = KOPrefs::instance()->mDateNavigatorFont; | 195 | fo = KOPrefs::instance()->mDateNavigatorFont; |
195 | mNavigatorView->changeFont( fo ); | 196 | mNavigatorView->changeFont( fo ); |
196 | mNavigatorView->unsetFontChanged(); | 197 | mNavigatorView->unsetFontChanged(); |
197 | } | 198 | } |
198 | } | 199 | } |
199 | 200 | ||
200 | while ( count > ( mExtraViews.count() + 1 ) ) { | 201 | while ( count > ( mExtraViews.count() + 1 ) ) { |
201 | KDateNavigator *n = new KDateNavigator( this ); | 202 | KDateNavigator *n = new KDateNavigator( this ); |
202 | n->setMonthSignalOffset ( mExtraViews.count()+1 ); | 203 | n->setMonthSignalOffset ( mExtraViews.count()+1 ); |
203 | mExtraViews.append( n ); | 204 | mExtraViews.append( n ); |
204 | n->setCalendar( mCalendar ); | 205 | n->setCalendar( mCalendar ); |
205 | setBaseDates(); | 206 | setBaseDates(); |
206 | connectNavigatorView( n ); | 207 | connectNavigatorView( n ); |
207 | n->show(); | 208 | n->show(); |
208 | } | 209 | } |
209 | int iii = 0; | 210 | int iii = 0; |
210 | while ( iii < ( mExtraViews.count() ) ) { | 211 | while ( iii < ( mExtraViews.count() ) ) { |
211 | if ( iii < count-1 ) | 212 | if ( iii < count-1 ) |
212 | mExtraViews.at( iii )->show(); | 213 | mExtraViews.at( iii )->show(); |
213 | else | 214 | else |
214 | mExtraViews.at( iii )->hide(); | 215 | mExtraViews.at( iii )->hide(); |
215 | ++iii; | 216 | ++iii; |
216 | } | 217 | } |
217 | if ( fontchange ) { | 218 | if ( fontchange ) { |
218 | //mNavigatorView->changeFont( fo ); | 219 | //mNavigatorView->changeFont( fo ); |
219 | uint i; | 220 | uint i; |
220 | for( i = 0; i < mExtraViews.count(); ++i ) { | 221 | for( i = 0; i < mExtraViews.count(); ++i ) { |
221 | KDateNavigator *view = mExtraViews.at( i ); | 222 | KDateNavigator *view = mExtraViews.at( i ); |
222 | view->changeFont( fo ); | 223 | view->changeFont( fo ); |
223 | } | 224 | } |
224 | } | 225 | } |
225 | mHorizontalCount = horizontalCount; | 226 | mHorizontalCount = horizontalCount; |
226 | mVerticalCount = verticalCount; | 227 | mVerticalCount = verticalCount; |
227 | } | 228 | } |
228 | int height = size().height() / verticalCount; | 229 | int height = size().height() / verticalCount; |
229 | int width = size().width() / horizontalCount; | 230 | int width = size().width() / horizontalCount; |
230 | 231 | ||
231 | NavigatorBar *bar = mNavigatorView->navigatorBar(); | 232 | NavigatorBar *bar = mNavigatorView->navigatorBar(); |
232 | if ( horizontalCount > 1 ) bar->showButtons( true, false ); | 233 | if ( horizontalCount > 1 ) bar->showButtons( true, false ); |
233 | else bar->showButtons( true, true ); | 234 | else bar->showButtons( true, true ); |
234 | 235 | ||
235 | mNavigatorView->setGeometry(0, | 236 | mNavigatorView->setGeometry(0, |
236 | 0, width, height ); | 237 | 0, width, height ); |
237 | for( uint i = 0; i < mExtraViews.count(); ++i ) { | 238 | for( uint i = 0; i < mExtraViews.count(); ++i ) { |
238 | int x = ( i + 1 ) % horizontalCount; | 239 | int x = ( i + 1 ) % horizontalCount; |
239 | int y = ( i + 1 ) / horizontalCount; | 240 | int y = ( i + 1 ) / horizontalCount; |
240 | 241 | ||
241 | KDateNavigator *view = mExtraViews.at( i ); | 242 | KDateNavigator *view = mExtraViews.at( i ); |
242 | bar = view->navigatorBar(); | 243 | bar = view->navigatorBar(); |
243 | if ( y > 0 ) bar->showButtons( false, false ); | 244 | if ( y > 0 ) bar->showButtons( false, false ); |
244 | else { | 245 | else { |
245 | if ( x + 1 == horizontalCount ) bar->showButtons( false, true ); | 246 | if ( x + 1 == horizontalCount ) bar->showButtons( false, true ); |
246 | else bar->showButtons( false, false ); | 247 | else bar->showButtons( false, false ); |
247 | } | 248 | } |
248 | view->setGeometry( x * width, | 249 | view->setGeometry( x * width, |
249 | y * height, width, height ); | 250 | y * height, width, height ); |
250 | } | 251 | } |
251 | } | 252 | } |
252 | 253 | ||
253 | QSize DateNavigatorContainer::minimumSizeHint() const | 254 | QSize DateNavigatorContainer::minimumSizeHint() const |
254 | { | 255 | { |
255 | return mNavigatorView->minimumSizeHint(); | 256 | return mNavigatorView->minimumSizeHint(); |
256 | } | 257 | } |
257 | 258 | ||
258 | QSize DateNavigatorContainer::sizeHint() const | 259 | QSize DateNavigatorContainer::sizeHint() const |
259 | { | 260 | { |
260 | return mNavigatorView->sizeHint(); | 261 | return mNavigatorView->sizeHint(); |
261 | } | 262 | } |
diff --git a/korganizer/kdatenavigator.cpp b/korganizer/kdatenavigator.cpp index a5dbc5d..4b50b5a 100644 --- a/korganizer/kdatenavigator.cpp +++ b/korganizer/kdatenavigator.cpp | |||
@@ -1,310 +1,310 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KOrganizer. | 2 | This file is part of KOrganizer. |
3 | Copyright (c) 2001,2002 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001,2002 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or | 7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. | 8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software | 16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | 18 | ||
19 | As a special exception, permission is given to link this program | 19 | As a special exception, permission is given to link this program |
20 | with any edition of Qt, and distribute the resulting executable, | 20 | with any edition of Qt, and distribute the resulting executable, |
21 | without including the source code for Qt in the source distribution. | 21 | without including the source code for Qt in the source distribution. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | #include <qkeycode.h> | 25 | #include <qkeycode.h> |
26 | #include <qlayout.h> | 26 | #include <qlayout.h> |
27 | #include <qtimer.h> | 27 | #include <qtimer.h> |
28 | #include <qframe.h> | 28 | #include <qframe.h> |
29 | #include <qlabel.h> | 29 | #include <qlabel.h> |
30 | #include <qapplication.h> | 30 | #include <qapplication.h> |
31 | 31 | ||
32 | #include <kdebug.h> | 32 | #include <kdebug.h> |
33 | #include <klocale.h> | 33 | #include <klocale.h> |
34 | #include <kglobal.h> | 34 | #include <kglobal.h> |
35 | 35 | ||
36 | #include "koglobals.h" | 36 | #include "koglobals.h" |
37 | #include "koprefs.h" | 37 | #include "koprefs.h" |
38 | #ifndef KORG_NOPLUGINS | 38 | #ifndef KORG_NOPLUGINS |
39 | #include "kocore.h" | 39 | #include "kocore.h" |
40 | #endif | 40 | #endif |
41 | 41 | ||
42 | #include <kcalendarsystem.h> | 42 | #include <kcalendarsystem.h> |
43 | 43 | ||
44 | #include "navigatorbar.h" | 44 | #include "navigatorbar.h" |
45 | 45 | ||
46 | #include "kdatenavigator.h" | 46 | #include "kdatenavigator.h" |
47 | 47 | ||
48 | KDateNavigator::KDateNavigator( QWidget *parent, const char *name ) | 48 | KDateNavigator::KDateNavigator( QWidget *parent, const char *name ) |
49 | : QFrame(parent, name), | 49 | : QFrame(parent, name), |
50 | updateTimer(0L) | 50 | updateTimer(0L) |
51 | { | 51 | { |
52 | setFrameStyle(QFrame::NoFrame); | 52 | setFrameStyle(QFrame::NoFrame); |
53 | QDate startDate = QDate::currentDate(); | 53 | QDate startDate = QDate::currentDate(); |
54 | QGridLayout *topLayout = new QGridLayout(this,8,8); | 54 | QGridLayout *topLayout = new QGridLayout(this,8,8); |
55 | 55 | ||
56 | if (! startDate.isValid()) { | 56 | if (! startDate.isValid()) { |
57 | qDebug("KDateNavigator::invalid startdate "); | 57 | qDebug("KDateNavigator::invalid startdate "); |
58 | startDate = QDate::currentDate(); | 58 | startDate = QDate::currentDate(); |
59 | } | 59 | } |
60 | mMonthSignalOffset = 0; | 60 | mMonthSignalOffset = 0; |
61 | mSelectedDates.append(startDate); | 61 | mSelectedDates.append(startDate); |
62 | m_MthYr = startDate; | 62 | m_MthYr = startDate; |
63 | m_bShowWeekNums = true; | 63 | m_bShowWeekNums = true; |
64 | 64 | ||
65 | setFont( KOPrefs::instance()->mDateNavigatorFont ); | 65 | setFont( KOPrefs::instance()->mDateNavigatorFont ); |
66 | mNavigatorBar = new NavigatorBar( startDate, this ); | 66 | mNavigatorBar = new NavigatorBar( startDate, this ); |
67 | topLayout->addMultiCellWidget( mNavigatorBar, 0, 0, 0, 7 ); | 67 | topLayout->addMultiCellWidget( mNavigatorBar, 0, 0, 0, 7 ); |
68 | //mNavigatorBar->resize( 1,1); | 68 | //mNavigatorBar->resize( 1,1); |
69 | connect( mNavigatorBar, SIGNAL( goPrevYear() ), SIGNAL( goPrevYear() ) ); | 69 | connect( mNavigatorBar, SIGNAL( goPrevYear() ), SIGNAL( goPrevYear() ) ); |
70 | connect( mNavigatorBar, SIGNAL( goPrevMonth() ), SIGNAL( goPrevMonth() ) ); | 70 | connect( mNavigatorBar, SIGNAL( goPrevMonth() ), SIGNAL( goPrevMonth() ) ); |
71 | connect( mNavigatorBar, SIGNAL( goNextMonth() ), SIGNAL( goNextMonth() ) ); | 71 | connect( mNavigatorBar, SIGNAL( goNextMonth() ), SIGNAL( goNextMonth() ) ); |
72 | connect( mNavigatorBar, SIGNAL( goNextYear() ), SIGNAL( goNextYear() ) ); | 72 | connect( mNavigatorBar, SIGNAL( goNextYear() ), SIGNAL( goNextYear() ) ); |
73 | connect( mNavigatorBar, SIGNAL( monthSelected( int ) ), SLOT( slotMonthSelected( int ) ) ); | 73 | connect( mNavigatorBar, SIGNAL( monthSelected( int ) ), SLOT( slotMonthSelected( int ) ) ); |
74 | 74 | ||
75 | // get the day of the week on the first day | 75 | // get the day of the week on the first day |
76 | QDate dayone(m_MthYr.year(), m_MthYr.month(), 1); | 76 | QDate dayone(m_MthYr.year(), m_MthYr.month(), 1); |
77 | m_fstDayOfWk = dayone.dayOfWeek(); | 77 | m_fstDayOfWk = dayone.dayOfWeek(); |
78 | 78 | ||
79 | int i; | 79 | int i; |
80 | 80 | ||
81 | // Set up the heading fields. | 81 | // Set up the heading fields. |
82 | for( i = 0; i < 7; i++ ) { | 82 | for( i = 0; i < 7; i++ ) { |
83 | headings[i] = new QLabel("",this); | 83 | headings[i] = new QLabel("",this); |
84 | //headings[i]->setFont(QFont("Arial", 10, QFont::Bold)); | 84 | //headings[i]->setFont(QFont("Arial", 10, QFont::Bold)); |
85 | headings[i]->setAlignment(AlignCenter); | 85 | headings[i]->setAlignment(AlignCenter); |
86 | 86 | ||
87 | topLayout->addWidget(headings[i],1,i+1); | 87 | topLayout->addWidget(headings[i],1,i+1); |
88 | } | 88 | } |
89 | 89 | ||
90 | // Create the weeknumber labels | 90 | // Create the weeknumber labels |
91 | for( i = 0; i < 6; i++ ) { | 91 | for( i = 0; i < 6; i++ ) { |
92 | weeknos[i] = new QLabel(this); | 92 | weeknos[i] = new QLabel(this); |
93 | weeknos[i]->setAlignment(AlignCenter); | 93 | weeknos[i]->setAlignment(AlignCenter); |
94 | //weeknos[i]->setFont(QFont("Arial", 10)); | 94 | //weeknos[i]->setFont(QFont("Arial", 10)); |
95 | if(!m_bShowWeekNums) { | 95 | if(!m_bShowWeekNums) { |
96 | weeknos[i]->hide(); | 96 | weeknos[i]->hide(); |
97 | } | 97 | } |
98 | weeknos[i]->installEventFilter(this); | 98 | weeknos[i]->installEventFilter(this); |
99 | 99 | ||
100 | topLayout->addWidget(weeknos[i],i+2,0); | 100 | topLayout->addWidget(weeknos[i],i+2,0); |
101 | } | 101 | } |
102 | 102 | ||
103 | daymatrix = new KODayMatrix( this, "KDateNavigator::DayMatrix"); | 103 | daymatrix = new KODayMatrix( this, "KDateNavigator::DayMatrix"); |
104 | daymatrix->setFrameStyle(QFrame::Panel|QFrame::Sunken); | 104 | daymatrix->setFrameStyle(QFrame::Panel|QFrame::Sunken); |
105 | daymatrix->setLineWidth(1); | 105 | daymatrix->setLineWidth(1); |
106 | 106 | ||
107 | connect( daymatrix, SIGNAL( selected( const KCal::DateList & ) ), | 107 | connect( daymatrix, SIGNAL( selected( const KCal::DateList & ) ), |
108 | SIGNAL( datesSelected( const KCal::DateList & ) ) ); | 108 | SIGNAL( datesSelected( const KCal::DateList & ) ) ); |
109 | 109 | ||
110 | connect( daymatrix, SIGNAL( eventDropped( Event * ) ), | 110 | connect( daymatrix, SIGNAL( eventDropped( Event * ) ), |
111 | SIGNAL( eventDropped( Event * ) ) ); | 111 | SIGNAL( eventDropped( Event * ) ) ); |
112 | 112 | ||
113 | topLayout->addMultiCellWidget(daymatrix,2,7,1,7); | 113 | topLayout->addMultiCellWidget(daymatrix,2,7,1,7); |
114 | 114 | ||
115 | // read settings from configuration file. | 115 | // read settings from configuration file. |
116 | updateConfig(); | 116 | updateConfig(); |
117 | enableRollover(FollowMonth); | 117 | enableRollover(FollowMonth); |
118 | mySizeHint = sizeHint(); | 118 | mySizeHint = sizeHintTwoButtons(); |
119 | mFontChanged = false; | 119 | mFontChanged = false; |
120 | } | 120 | } |
121 | void KDateNavigator::changeFont ( QFont fo ) | 121 | void KDateNavigator::changeFont ( QFont fo ) |
122 | { | 122 | { |
123 | setFont( fo ); | 123 | setFont( fo ); |
124 | mNavigatorBar->resetFont( fo ); | 124 | mNavigatorBar->resetFont( fo ); |
125 | } | 125 | } |
126 | QFont KDateNavigator::yourFontHint( QSize si , bool *b) | 126 | QFont KDateNavigator::yourFontHint( QSize si , bool *b) |
127 | { | 127 | { |
128 | QFont fo = KOPrefs::instance()->mDateNavigatorFont; | 128 | QFont fo = KOPrefs::instance()->mDateNavigatorFont; |
129 | *b = false; | 129 | *b = false; |
130 | int fontPoint = fo.pointSize(); | 130 | int fontPoint = fo.pointSize(); |
131 | while ( fontPoint > 5 ) { | 131 | while ( fontPoint > 5 ) { |
132 | --fontPoint; | 132 | --fontPoint; |
133 | fo.setPointSize( fontPoint ); | 133 | fo.setPointSize( fontPoint ); |
134 | setFont( fo ); | 134 | setFont( fo ); |
135 | mFontChanged = true; | 135 | mFontChanged = true; |
136 | mNavigatorBar->resetFont( fo ); | 136 | mNavigatorBar->resetFont( fo ); |
137 | QSize sh = sizeHintTwoButtons(); | 137 | QSize sh = sizeHintTwoButtons(); |
138 | //qDebug("fp %d %d %d %d %d", fontPoint, si.width() , sh.width() , si.height() , sh.height() ); | 138 | //qDebug("fp %d %d %d %d %d", fontPoint, si.width() , sh.width() , si.height() , sh.height() ); |
139 | if ( si.width() > sh.width() && si.height() > sh.height()) { | 139 | if ( si.width() > sh.width() && si.height() > sh.height()) { |
140 | *b = true; | 140 | *b = true; |
141 | //qDebug("fooooooooooooooooooooooouuuuund "); | 141 | //qDebug("fooooooooooooooooooooooouuuuund "); |
142 | break; | 142 | break; |
143 | } | 143 | } |
144 | } | 144 | } |
145 | //qDebug("returnnnnnnnnnnnnnnnnnnn %d", fo.pointSize() ); | 145 | //qDebug("returnnnnnnnnnnnnnnnnnnn %d", fo.pointSize() ); |
146 | return fo; | 146 | return fo; |
147 | } | 147 | } |
148 | QSize KDateNavigator::sizeHint() const | 148 | QSize KDateNavigator::sizeHint() const |
149 | { | 149 | { |
150 | QFontMetrics fm ( font() ); | 150 | QFontMetrics fm ( font() ); |
151 | QSize day = daymatrix->sizeHint(); | 151 | QSize day = daymatrix->sizeHint(); |
152 | QSize nav = mNavigatorBar->sizeHint(); | 152 | QSize nav = mNavigatorBar->sizeHint(); |
153 | int wid = fm.width( "30") + day.width()+3; | 153 | int wid = fm.width( "30") + day.width()+3; |
154 | int hei = fm.height() +day.height()+nav.height()+2; | 154 | int hei = fm.height() +day.height()+nav.height()+2; |
155 | if ( wid < nav.width() ) | 155 | if ( wid < nav.width() ) |
156 | wid = nav.width() ; | 156 | wid = nav.width() ; |
157 | //qDebug("KDateNavigator+++++++++++++ %d %d", wid , hei); | 157 | //qDebug("KDateNavigator+++++++++++++ %d %d", wid , hei); |
158 | return QSize ( wid, hei ); | 158 | return QSize ( wid, hei ); |
159 | } | 159 | } |
160 | QSize KDateNavigator::sizeHintTwoButtons() const | 160 | QSize KDateNavigator::sizeHintTwoButtons() const |
161 | { | 161 | { |
162 | QFontMetrics fm ( font() ); | 162 | QFontMetrics fm ( font() ); |
163 | QSize day = daymatrix->sizeHint(); | 163 | QSize day = daymatrix->sizeHint(); |
164 | QSize nav = mNavigatorBar->sizeHintTwoButtons(); | 164 | QSize nav = mNavigatorBar->sizeHintTwoButtons(); |
165 | int wid = fm.width( "30") + day.width()+3; | 165 | int wid = fm.width( "30") + day.width()+3; |
166 | int hei = fm.height() +day.height()+nav.height()+2; | 166 | int hei = fm.height() +day.height()+nav.height()+2; |
167 | if ( wid < nav.width() ) | 167 | if ( wid < nav.width() ) |
168 | wid = nav.width() ; | 168 | wid = nav.width() ; |
169 | //qDebug("KDateNavigator+++++++++++++ %d %d", wid , hei); | 169 | //qDebug("KDateNavigator+++++++++++++ %d %d", wid , hei); |
170 | return QSize ( wid, hei ); | 170 | return QSize ( wid, hei ); |
171 | } | 171 | } |
172 | void KDateNavigator::slotMonthSelected( int m ) | 172 | void KDateNavigator::slotMonthSelected( int m ) |
173 | { | 173 | { |
174 | if ( m_MthYr.month() <= mMonthSignalOffset) | 174 | if ( m_MthYr.month() <= mMonthSignalOffset) |
175 | m += 12; | 175 | m += 12; |
176 | int mo = m - mMonthSignalOffset; | 176 | int mo = m - mMonthSignalOffset; |
177 | emit monthSelected( m - mMonthSignalOffset ); | 177 | emit monthSelected( m - mMonthSignalOffset ); |
178 | 178 | ||
179 | } | 179 | } |
180 | void KDateNavigator::setCalendar( Calendar *cal ) | 180 | void KDateNavigator::setCalendar( Calendar *cal ) |
181 | { | 181 | { |
182 | daymatrix->setCalendar( cal ); | 182 | daymatrix->setCalendar( cal ); |
183 | } | 183 | } |
184 | 184 | ||
185 | void KDateNavigator::setBaseDate( const QDate &date , bool doRepaint ) // = true | 185 | void KDateNavigator::setBaseDate( const QDate &date , bool doRepaint ) // = true |
186 | { | 186 | { |
187 | m_MthYr = date; | 187 | m_MthYr = date; |
188 | 188 | ||
189 | updateDates(); | 189 | updateDates(); |
190 | updateView(); | 190 | updateView(); |
191 | 191 | ||
192 | KCal::DateList dates; | 192 | KCal::DateList dates; |
193 | dates.append( date ); | 193 | dates.append( date ); |
194 | mNavigatorBar->selectDates( dates ); | 194 | mNavigatorBar->selectDates( dates ); |
195 | 195 | ||
196 | daymatrix->clearSelection(); | 196 | daymatrix->clearSelection(); |
197 | if ( doRepaint ) | 197 | if ( doRepaint ) |
198 | daymatrix->repaint(); | 198 | daymatrix->repaint(); |
199 | } | 199 | } |
200 | 200 | ||
201 | void KDateNavigator::enableRollover(RolloverType r) | 201 | void KDateNavigator::enableRollover(RolloverType r) |
202 | { | 202 | { |
203 | switch(r) | 203 | switch(r) |
204 | { | 204 | { |
205 | case None : | 205 | case None : |
206 | if (updateTimer) | 206 | if (updateTimer) |
207 | { | 207 | { |
208 | updateTimer->stop(); | 208 | updateTimer->stop(); |
209 | delete updateTimer; | 209 | delete updateTimer; |
210 | updateTimer=0L; | 210 | updateTimer=0L; |
211 | } | 211 | } |
212 | break; | 212 | break; |
213 | case FollowDay : | 213 | case FollowDay : |
214 | case FollowMonth : | 214 | case FollowMonth : |
215 | if (!updateTimer) | 215 | if (!updateTimer) |
216 | { | 216 | { |
217 | updateTimer = new QTimer(this); | 217 | updateTimer = new QTimer(this); |
218 | QObject::connect(updateTimer,SIGNAL(timeout()), | 218 | QObject::connect(updateTimer,SIGNAL(timeout()), |
219 | this,SLOT(possiblyPastMidnight())); | 219 | this,SLOT(possiblyPastMidnight())); |
220 | } | 220 | } |
221 | updateTimer->start(0,true); | 221 | updateTimer->start(0,true); |
222 | lastDayChecked = QDate::currentDate(); | 222 | lastDayChecked = QDate::currentDate(); |
223 | } | 223 | } |
224 | updateRollover=r; | 224 | updateRollover=r; |
225 | } | 225 | } |
226 | 226 | ||
227 | 227 | ||
228 | KDateNavigator::~KDateNavigator() | 228 | KDateNavigator::~KDateNavigator() |
229 | { | 229 | { |
230 | } | 230 | } |
231 | 231 | ||
232 | 232 | ||
233 | void KDateNavigator::passedMidnight() | 233 | void KDateNavigator::passedMidnight() |
234 | { | 234 | { |
235 | QDate today = QDate::currentDate(); | 235 | QDate today = QDate::currentDate(); |
236 | bool emitMonth = false; | 236 | bool emitMonth = false; |
237 | 237 | ||
238 | if (today.month() != lastDayChecked.month()) | 238 | if (today.month() != lastDayChecked.month()) |
239 | { | 239 | { |
240 | if (updateRollover==FollowMonth && | 240 | if (updateRollover==FollowMonth && |
241 | daymatrix->isEndOfMonth()) { | 241 | daymatrix->isEndOfMonth()) { |
242 | goNextMonth(); | 242 | goNextMonth(); |
243 | emitMonth=true; | 243 | emitMonth=true; |
244 | } | 244 | } |
245 | } | 245 | } |
246 | daymatrix->recalculateToday(); | 246 | daymatrix->recalculateToday(); |
247 | daymatrix->repaint(); | 247 | daymatrix->repaint(); |
248 | emit dayPassed(today); | 248 | emit dayPassed(today); |
249 | if (emitMonth) { emit monthPassed(today); } | 249 | if (emitMonth) { emit monthPassed(today); } |
250 | } | 250 | } |
251 | 251 | ||
252 | /* slot */ void KDateNavigator::possiblyPastMidnight() | 252 | /* slot */ void KDateNavigator::possiblyPastMidnight() |
253 | { | 253 | { |
254 | if (lastDayChecked!=QDate::currentDate()) | 254 | if (lastDayChecked!=QDate::currentDate()) |
255 | { | 255 | { |
256 | passedMidnight(); | 256 | passedMidnight(); |
257 | lastDayChecked=QDate::currentDate(); | 257 | lastDayChecked=QDate::currentDate(); |
258 | } | 258 | } |
259 | // Set the timer to go off 1 second after midnight | 259 | // Set the timer to go off 1 second after midnight |
260 | // or after 8 minutes, whichever comes first. | 260 | // or after 8 minutes, whichever comes first. |
261 | if (updateTimer) | 261 | if (updateTimer) |
262 | { | 262 | { |
263 | QTime now = QTime::currentTime(); | 263 | QTime now = QTime::currentTime(); |
264 | QTime midnight = QTime(23,59,59); | 264 | QTime midnight = QTime(23,59,59); |
265 | int msecsWait = QMIN(480000,now.msecsTo(midnight)+2000); | 265 | int msecsWait = QMIN(480000,now.msecsTo(midnight)+2000); |
266 | 266 | ||
267 | // qDebug(QString("Waiting %1 msec from %2 to %3.").arg(msecsWait)) | 267 | // qDebug(QString("Waiting %1 msec from %2 to %3.").arg(msecsWait)) |
268 | //.arg(now.toString()).arg(midnight.toString())); | 268 | //.arg(now.toString()).arg(midnight.toString())); |
269 | 269 | ||
270 | updateTimer->stop(); | 270 | updateTimer->stop(); |
271 | updateTimer->start(msecsWait,true); | 271 | updateTimer->start(msecsWait,true); |
272 | } | 272 | } |
273 | } | 273 | } |
274 | 274 | ||
275 | void KDateNavigator::updateDates() | 275 | void KDateNavigator::updateDates() |
276 | { | 276 | { |
277 | // Find the first day of the week of the current month. | 277 | // Find the first day of the week of the current month. |
278 | //int d1 = KOGlobals::self()->calendarSystem()->day( m_MthYr ); | 278 | //int d1 = KOGlobals::self()->calendarSystem()->day( m_MthYr ); |
279 | QDate dayone( m_MthYr.year(), m_MthYr.month(), m_MthYr.day() ); | 279 | QDate dayone( m_MthYr.year(), m_MthYr.month(), m_MthYr.day() ); |
280 | int d2 = KOGlobals::self()->calendarSystem()->day( dayone ); | 280 | int d2 = KOGlobals::self()->calendarSystem()->day( dayone ); |
281 | //int di = d1 - d2 + 1; | 281 | //int di = d1 - d2 + 1; |
282 | dayone = dayone.addDays( -d2 + 1 ); | 282 | dayone = dayone.addDays( -d2 + 1 ); |
283 | 283 | ||
284 | int m_fstDayOfWkCalsys = KOGlobals::self()->calendarSystem()->dayOfWeek( dayone ); | 284 | int m_fstDayOfWkCalsys = KOGlobals::self()->calendarSystem()->dayOfWeek( dayone ); |
285 | 285 | ||
286 | // If month begins on Monday and Monday is first day of week, | 286 | // If month begins on Monday and Monday is first day of week, |
287 | // month should begin on second line. Sunday doesn't have this problem. | 287 | // month should begin on second line. Sunday doesn't have this problem. |
288 | int nextLine = ( ( m_fstDayOfWkCalsys == 1) && | 288 | int nextLine = ( ( m_fstDayOfWkCalsys == 1) && |
289 | ( KGlobal::locale()->weekStartsMonday() == 1 ) ) ? 7 : 0; | 289 | ( KGlobal::locale()->weekStartsMonday() == 1 ) ) ? 7 : 0; |
290 | 290 | ||
291 | // update the matrix dates | 291 | // update the matrix dates |
292 | int index = (KGlobal::locale()->weekStartsMonday() ? 1 : 0) - m_fstDayOfWkCalsys - nextLine; | 292 | int index = (KGlobal::locale()->weekStartsMonday() ? 1 : 0) - m_fstDayOfWkCalsys - nextLine; |
293 | 293 | ||
294 | 294 | ||
295 | daymatrix->updateView(dayone.addDays(index)); | 295 | daymatrix->updateView(dayone.addDays(index)); |
296 | //each updateDates is followed by an updateView -> repaint is issued there ! | 296 | //each updateDates is followed by an updateView -> repaint is issued there ! |
297 | // daymatrix->repaint(); | 297 | // daymatrix->repaint(); |
298 | } | 298 | } |
299 | 299 | ||
300 | void KDateNavigator::updateDayMatrix() | 300 | void KDateNavigator::updateDayMatrix() |
301 | { | 301 | { |
302 | daymatrix->updateView(); | 302 | daymatrix->updateView(); |
303 | //daymatrix->repaint(); | 303 | //daymatrix->repaint(); |
304 | } | 304 | } |
305 | 305 | ||
306 | 306 | ||
307 | void KDateNavigator::updateView() | 307 | void KDateNavigator::updateView() |
308 | { | 308 | { |
309 | 309 | ||
310 | setUpdatesEnabled( false ); | 310 | setUpdatesEnabled( false ); |
diff --git a/korganizer/kodaymatrix.cpp b/korganizer/kodaymatrix.cpp index 582b2ef..9baff20 100644 --- a/korganizer/kodaymatrix.cpp +++ b/korganizer/kodaymatrix.cpp | |||
@@ -256,395 +256,395 @@ void KODayMatrix::addSelectedDaysTo(DateList& selDays) | |||
256 | if (mSelStart == NOSELECTION) { | 256 | if (mSelStart == NOSELECTION) { |
257 | return; | 257 | return; |
258 | } | 258 | } |
259 | 259 | ||
260 | //cope with selection being out of matrix limits at top (< 0) | 260 | //cope with selection being out of matrix limits at top (< 0) |
261 | int i0 = mSelStart; | 261 | int i0 = mSelStart; |
262 | if (i0 < 0) { | 262 | if (i0 < 0) { |
263 | for (int i = i0; i < 0; i++) { | 263 | for (int i = i0; i < 0; i++) { |
264 | selDays.append(days[0].addDays(i)); | 264 | selDays.append(days[0].addDays(i)); |
265 | } | 265 | } |
266 | i0 = 0; | 266 | i0 = 0; |
267 | } | 267 | } |
268 | 268 | ||
269 | //cope with selection being out of matrix limits at bottom (> NUMDAYS-1) | 269 | //cope with selection being out of matrix limits at bottom (> NUMDAYS-1) |
270 | if (mSelEnd > NUMDAYS-1) { | 270 | if (mSelEnd > NUMDAYS-1) { |
271 | for (int i = i0; i <= NUMDAYS-1; i++) { | 271 | for (int i = i0; i <= NUMDAYS-1; i++) { |
272 | selDays.append(days[i]); | 272 | selDays.append(days[i]); |
273 | } | 273 | } |
274 | for (int i = NUMDAYS; i < mSelEnd; i++) { | 274 | for (int i = NUMDAYS; i < mSelEnd; i++) { |
275 | selDays.append(days[0].addDays(i)); | 275 | selDays.append(days[0].addDays(i)); |
276 | } | 276 | } |
277 | 277 | ||
278 | // apply normal routine to selection being entirely within matrix limits | 278 | // apply normal routine to selection being entirely within matrix limits |
279 | } else { | 279 | } else { |
280 | for (int i = i0; i <= mSelEnd; i++) { | 280 | for (int i = i0; i <= mSelEnd; i++) { |
281 | selDays.append(days[i]); | 281 | selDays.append(days[i]); |
282 | } | 282 | } |
283 | } | 283 | } |
284 | } | 284 | } |
285 | 285 | ||
286 | void KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end) | 286 | void KODayMatrix::setSelectedDaysFrom(const QDate& start, const QDate& end) |
287 | { | 287 | { |
288 | mSelStart = startdate.daysTo(start); | 288 | mSelStart = startdate.daysTo(start); |
289 | if ( mSelStart < 0 ) | 289 | if ( mSelStart < 0 ) |
290 | mSelStart = 0; | 290 | mSelStart = 0; |
291 | mSelEnd = startdate.daysTo(end); | 291 | mSelEnd = startdate.daysTo(end); |
292 | if ( mSelEnd < 0 ) | 292 | if ( mSelEnd < 0 ) |
293 | clearSelection(); | 293 | clearSelection(); |
294 | } | 294 | } |
295 | void KODayMatrix::clearSelection() | 295 | void KODayMatrix::clearSelection() |
296 | { | 296 | { |
297 | mSelEnd = mSelStart = NOSELECTION; | 297 | mSelEnd = mSelStart = NOSELECTION; |
298 | } | 298 | } |
299 | 299 | ||
300 | 300 | ||
301 | void KODayMatrix::recalculateToday() | 301 | void KODayMatrix::recalculateToday() |
302 | { | 302 | { |
303 | today = -1; | 303 | today = -1; |
304 | for (int i=0; i<NUMDAYS; i++) { | 304 | for (int i=0; i<NUMDAYS; i++) { |
305 | events[i] = 0; | 305 | events[i] = 0; |
306 | days[i] = startdate.addDays(i); | 306 | days[i] = startdate.addDays(i); |
307 | daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] )); | 307 | daylbls[i] = QString::number( KOGlobals::self()->calendarSystem()->day( days[i] )); |
308 | 308 | ||
309 | // if today is in the currently displayed month, hilight today | 309 | // if today is in the currently displayed month, hilight today |
310 | if (days[i].year() == QDate::currentDate().year() && | 310 | if (days[i].year() == QDate::currentDate().year() && |
311 | days[i].month() == QDate::currentDate().month() && | 311 | days[i].month() == QDate::currentDate().month() && |
312 | days[i].day() == QDate::currentDate().day()) { | 312 | days[i].day() == QDate::currentDate().day()) { |
313 | today = i; | 313 | today = i; |
314 | } | 314 | } |
315 | } | 315 | } |
316 | // qDebug(QString("Today is visible at %1.").arg(today)); | 316 | // qDebug(QString("Today is visible at %1.").arg(today)); |
317 | } | 317 | } |
318 | 318 | ||
319 | void KODayMatrix::updateView() | 319 | void KODayMatrix::updateView() |
320 | { | 320 | { |
321 | updateView(startdate); | 321 | updateView(startdate); |
322 | } | 322 | } |
323 | void KODayMatrix::repaintViewTimed() | 323 | void KODayMatrix::repaintViewTimed() |
324 | { | 324 | { |
325 | mRepaintTimer->stop(); | 325 | mRepaintTimer->stop(); |
326 | repaint(false); | 326 | repaint(false); |
327 | } | 327 | } |
328 | void KODayMatrix::updateViewTimed() | 328 | void KODayMatrix::updateViewTimed() |
329 | { | 329 | { |
330 | mUpdateTimer->stop(); | 330 | mUpdateTimer->stop(); |
331 | if ( !mCalendar ) { | 331 | if ( !mCalendar ) { |
332 | qDebug("NOT CAL "); | 332 | qDebug("NOT CAL "); |
333 | return; | 333 | return; |
334 | } | 334 | } |
335 | //qDebug("KODayMatrix::updateViewTimed "); | 335 | //qDebug("KODayMatrix::updateViewTimed "); |
336 | for(int i = 0; i < NUMDAYS; i++) { | 336 | for(int i = 0; i < NUMDAYS; i++) { |
337 | // if events are set for the day then remember to draw it bold | 337 | // if events are set for the day then remember to draw it bold |
338 | QPtrList<Event> eventlist = mCalendar->events(days[i]); | 338 | QPtrList<Event> eventlist = mCalendar->events(days[i]); |
339 | Event *event; | 339 | Event *event; |
340 | int numEvents = eventlist.count(); | 340 | int numEvents = eventlist.count(); |
341 | QString holiStr = ""; | 341 | QString holiStr = ""; |
342 | bDays.clearBit(i); | 342 | bDays.clearBit(i); |
343 | for(event=eventlist.first();event != 0;event=eventlist.next()) { | 343 | for(event=eventlist.first();event != 0;event=eventlist.next()) { |
344 | ushort recurType = event->recurrence()->doesRecur(); | 344 | ushort recurType = event->recurrence()->doesRecur(); |
345 | if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || | 345 | if ((recurType == Recurrence::rDaily && !KOPrefs::instance()->mDailyRecur) || |
346 | (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { | 346 | (recurType == Recurrence::rWeekly && !KOPrefs::instance()->mWeeklyRecur)) { |
347 | numEvents--; | 347 | numEvents--; |
348 | } | 348 | } |
349 | if ( event->categories().contains( i18n("Holiday") ) || event->categories().contains( "Holiday" )) { | 349 | if ( event->categories().contains( i18n("Holiday") ) || event->categories().contains( "Holiday" )) { |
350 | if ( !holiStr.isEmpty() ) | 350 | if ( !holiStr.isEmpty() ) |
351 | holiStr += "\n"; | 351 | holiStr += "\n"; |
352 | holiStr += event->summary(); | 352 | holiStr += event->summary(); |
353 | if ( !event->location().isEmpty() ) | 353 | if ( !event->location().isEmpty() ) |
354 | holiStr += " (" + event->location() + ")"; | 354 | holiStr += " (" + event->location() + ")"; |
355 | } | 355 | } |
356 | if ( event->categories().contains( i18n("Birthday") ) || event->categories().contains( "Birthday" )) { | 356 | if ( event->categories().contains( i18n("Birthday") ) || event->categories().contains( "Birthday" )) { |
357 | if ( !holiStr.isEmpty() ) | 357 | if ( !holiStr.isEmpty() ) |
358 | holiStr += "\n"; | 358 | holiStr += "\n"; |
359 | holiStr += i18n("Birthday") + ": "+event->summary(); | 359 | holiStr += i18n("Birthday") + ": "+event->summary(); |
360 | if ( !event->location().isEmpty() ) | 360 | if ( !event->location().isEmpty() ) |
361 | holiStr += " (" + event->location() + ")"; | 361 | holiStr += " (" + event->location() + ")"; |
362 | bDays.setBit(i); | 362 | bDays.setBit(i); |
363 | } | 363 | } |
364 | } | 364 | } |
365 | events[i] = numEvents; | 365 | events[i] = numEvents; |
366 | //if it is a holy day then draw it red. Sundays are consider holidays, too | 366 | //if it is a holy day then draw it red. Sundays are consider holidays, too |
367 | if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) || | 367 | if ( (KOGlobals::self()->calendarSystem()->dayOfWeek(days[i]) == KOGlobals::self()->calendarSystem()->weekDayOfPray()) || |
368 | !holiStr.isEmpty()) { | 368 | !holiStr.isEmpty()) { |
369 | mHolidays[i] = holiStr; | 369 | mHolidays[i] = holiStr; |
370 | } else { | 370 | } else { |
371 | mHolidays[i] = QString::null; | 371 | mHolidays[i] = QString::null; |
372 | } | 372 | } |
373 | } | 373 | } |
374 | if ( ! mPendingUpdateBeforeRepaint ) | 374 | if ( ! mPendingUpdateBeforeRepaint ) |
375 | repaint(false); | 375 | repaint(false); |
376 | } | 376 | } |
377 | void KODayMatrix::updateView(QDate actdate) | 377 | void KODayMatrix::updateView(QDate actdate) |
378 | { | 378 | { |
379 | 379 | ||
380 | if ( ! actdate.isValid() ) { | 380 | if ( ! actdate.isValid() ) { |
381 | //qDebug("date not valid "); | 381 | //qDebug("date not valid "); |
382 | return; | 382 | return; |
383 | } | 383 | } |
384 | mDayChanged = false; | 384 | mDayChanged = false; |
385 | //flag to indicate if the starting day of the matrix has changed by this call | 385 | //flag to indicate if the starting day of the matrix has changed by this call |
386 | //mDayChanged = false; | 386 | //mDayChanged = false; |
387 | // if a new startdate is to be set then apply Cornelius's calculation | 387 | // if a new startdate is to be set then apply Cornelius's calculation |
388 | // of the first day to be shown | 388 | // of the first day to be shown |
389 | if (actdate != startdate) { | 389 | if (actdate != startdate) { |
390 | // reset index of selection according to shift of starting date from startdate to actdate | 390 | // reset index of selection according to shift of starting date from startdate to actdate |
391 | if (mSelStart != NOSELECTION) { | 391 | if (mSelStart != NOSELECTION) { |
392 | int tmp = actdate.daysTo(startdate); | 392 | int tmp = actdate.daysTo(startdate); |
393 | //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl; | 393 | //kdDebug() << "Shift of Selection1: " << mSelStart << " - " << mSelEnd << " -> " << tmp << "(" << offset << ")" << endl; |
394 | // shift selection if new one would be visible at least partly ! | 394 | // shift selection if new one would be visible at least partly ! |
395 | 395 | ||
396 | if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) { | 396 | if (mSelStart+tmp < NUMDAYS && mSelEnd+tmp >= 0) { |
397 | // nested if is required for next X display pushed from a different month - correction required | 397 | // nested if is required for next X display pushed from a different month - correction required |
398 | // otherwise, for month forward and backward, it must be avoided | 398 | // otherwise, for month forward and backward, it must be avoided |
399 | if( mSelStart > NUMDAYS || mSelStart < 0 ) | 399 | if( mSelStart > NUMDAYS || mSelStart < 0 ) |
400 | mSelStart = mSelStart + tmp; | 400 | mSelStart = mSelStart + tmp; |
401 | if( mSelEnd > NUMDAYS || mSelEnd < 0 ) | 401 | if( mSelEnd > NUMDAYS || mSelEnd < 0 ) |
402 | mSelEnd = mSelEnd + tmp; | 402 | mSelEnd = mSelEnd + tmp; |
403 | } | 403 | } |
404 | } | 404 | } |
405 | startdate = actdate; | 405 | startdate = actdate; |
406 | mDayChanged = true; | 406 | mDayChanged = true; |
407 | recalculateToday(); | 407 | recalculateToday(); |
408 | } | 408 | } |
409 | //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() ); | 409 | //qDebug("restart Timer %d vis: %d", mDayChanged, isVisible() ); |
410 | if ( !isVisible() ) { | 410 | if ( !isVisible() ) { |
411 | mPendingUpdateBeforeRepaint = true; | 411 | mPendingUpdateBeforeRepaint = true; |
412 | } else { | 412 | } else { |
413 | #ifdef DESKTOP_VERSION | 413 | #ifdef DESKTOP_VERSION |
414 | //mRepaintTimer->start( 150 ); | 414 | //mRepaintTimer->start( 150 ); |
415 | mUpdateTimer->start( 150 ); | 415 | mUpdateTimer->start( 150 ); |
416 | #else | 416 | #else |
417 | mRepaintTimer->start( 350 ); | 417 | mRepaintTimer->start( 350 ); |
418 | mUpdateTimer->start( 1200 ); | 418 | mUpdateTimer->start( 1200 ); |
419 | #endif | 419 | #endif |
420 | } | 420 | } |
421 | } | 421 | } |
422 | void KODayMatrix::updateEvents() | 422 | void KODayMatrix::updateEvents() |
423 | { | 423 | { |
424 | if ( !mCalendar ) return; | 424 | if ( !mCalendar ) return; |
425 | 425 | ||
426 | for( int i = 0; i < NUMDAYS; i++ ) { | 426 | for( int i = 0; i < NUMDAYS; i++ ) { |
427 | // if events are set for the day then remember to draw it bold | 427 | // if events are set for the day then remember to draw it bold |
428 | QPtrList<Event> eventlist = mCalendar->events( days[ i ] ); | 428 | QPtrList<Event> eventlist = mCalendar->events( days[ i ] ); |
429 | int numEvents = eventlist.count(); | 429 | int numEvents = eventlist.count(); |
430 | Event *event; | 430 | Event *event; |
431 | for( event = eventlist.first(); event != 0;event=eventlist.next()) { | 431 | for( event = eventlist.first(); event != 0;event=eventlist.next()) { |
432 | ushort recurType = event->doesRecur(); | 432 | ushort recurType = event->doesRecur(); |
433 | 433 | ||
434 | if ( ( recurType == Recurrence::rDaily && | 434 | if ( ( recurType == Recurrence::rDaily && |
435 | !KOPrefs::instance()->mDailyRecur ) || | 435 | !KOPrefs::instance()->mDailyRecur ) || |
436 | ( recurType == Recurrence::rWeekly && | 436 | ( recurType == Recurrence::rWeekly && |
437 | !KOPrefs::instance()->mWeeklyRecur ) ) { | 437 | !KOPrefs::instance()->mWeeklyRecur ) ) { |
438 | numEvents--; | 438 | numEvents--; |
439 | } | 439 | } |
440 | } | 440 | } |
441 | events[ i ] = numEvents; | 441 | events[ i ] = numEvents; |
442 | } | 442 | } |
443 | } | 443 | } |
444 | 444 | ||
445 | const QDate& KODayMatrix::getDate(int offset) | 445 | const QDate& KODayMatrix::getDate(int offset) |
446 | { | 446 | { |
447 | if (offset < 0 || offset > NUMDAYS-1) { | 447 | if (offset < 0 || offset > NUMDAYS-1) { |
448 | qDebug("Wrong offset2 "); | 448 | qDebug("Wrong offset2 %d", offset); |
449 | return days[0]; | 449 | return days[0]; |
450 | } | 450 | } |
451 | return days[offset]; | 451 | return days[offset]; |
452 | } | 452 | } |
453 | 453 | ||
454 | QString KODayMatrix::getHolidayLabel(int offset) | 454 | QString KODayMatrix::getHolidayLabel(int offset) |
455 | { | 455 | { |
456 | if (offset < 0 || offset > NUMDAYS-1) { | 456 | if (offset < 0 || offset > NUMDAYS-1) { |
457 | qDebug("Wrong offset1 "); | 457 | qDebug("Wrong offset1 %d", offset); |
458 | return 0; | 458 | return QString(); |
459 | } | 459 | } |
460 | return mHolidays[offset]; | 460 | return mHolidays[offset]; |
461 | } | 461 | } |
462 | 462 | ||
463 | int KODayMatrix::getDayIndexFrom(int x, int y) | 463 | int KODayMatrix::getDayIndexFrom(int x, int y) |
464 | { | 464 | { |
465 | int colModulo = (width()-2) % 7; | 465 | int colModulo = (width()-2) % 7; |
466 | int rowModulo = (height()-2) % 6; | 466 | int rowModulo = (height()-2) % 6; |
467 | #if 0 | 467 | #if 0 |
468 | return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ? | 468 | return 7*(y/daysize.height()) + (KOGlobals::self()->reverseLayout() ? |
469 | 6 - x/daysize.width() : x/daysize.width()); | 469 | 6 - x/daysize.width() : x/daysize.width()); |
470 | #endif | 470 | #endif |
471 | int xVal = (x-colModulo/2-2)/daysize.width(); | 471 | int xVal = (x-colModulo/2-2)/daysize.width(); |
472 | int yVal = (y-rowModulo/2-2)/daysize.height(); | 472 | int yVal = (y-rowModulo/2-2)/daysize.height(); |
473 | 473 | ||
474 | 474 | ||
475 | return 7*(yVal) + xVal; | 475 | return 7*(yVal) + xVal; |
476 | 476 | ||
477 | } | 477 | } |
478 | 478 | ||
479 | // ---------------------------------------------------------------------------- | 479 | // ---------------------------------------------------------------------------- |
480 | // M O U S E E V E N T H A N D L I N G | 480 | // M O U S E E V E N T H A N D L I N G |
481 | // ---------------------------------------------------------------------------- | 481 | // ---------------------------------------------------------------------------- |
482 | 482 | ||
483 | void KODayMatrix::mousePressEvent (QMouseEvent* e) | 483 | void KODayMatrix::mousePressEvent (QMouseEvent* e) |
484 | { | 484 | { |
485 | 485 | ||
486 | if ( e->button() == LeftButton ) | 486 | if ( e->button() == LeftButton ) |
487 | mouseDown = true; | 487 | mouseDown = true; |
488 | mSelStart = getDayIndexFrom(e->x(), e->y()); | 488 | mSelStart = getDayIndexFrom(e->x(), e->y()); |
489 | if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1; | 489 | if (mSelStart > NUMDAYS-1) mSelStart=NUMDAYS-1; |
490 | mSelInit = mSelStart; | 490 | mSelInit = mSelStart; |
491 | mSelEnd = mSelStart; | 491 | mSelEnd = mSelStart; |
492 | repaint(false); | 492 | repaint(false); |
493 | } | 493 | } |
494 | 494 | ||
495 | void KODayMatrix::mouseReleaseEvent (QMouseEvent* e) | 495 | void KODayMatrix::mouseReleaseEvent (QMouseEvent* e) |
496 | { | 496 | { |
497 | if ( e->button() == LeftButton ) | 497 | if ( e->button() == LeftButton ) |
498 | if ( ! mouseDown ) { | 498 | if ( ! mouseDown ) { |
499 | return; | 499 | return; |
500 | } | 500 | } |
501 | else | 501 | else |
502 | mouseDown = false; | 502 | mouseDown = false; |
503 | int tmp = getDayIndexFrom(e->x(), e->y()); | 503 | int tmp = getDayIndexFrom(e->x(), e->y()); |
504 | if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; | 504 | if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; |
505 | 505 | ||
506 | if (mSelInit > tmp) { | 506 | if (mSelInit > tmp) { |
507 | mSelEnd = mSelInit; | 507 | mSelEnd = mSelInit; |
508 | if (tmp != mSelStart) { | 508 | if (tmp != mSelStart) { |
509 | mSelStart = tmp; | 509 | mSelStart = tmp; |
510 | repaint(false); | 510 | repaint(false); |
511 | } | 511 | } |
512 | } else { | 512 | } else { |
513 | mSelStart = mSelInit; | 513 | mSelStart = mSelInit; |
514 | 514 | ||
515 | //repaint only if selection has changed | 515 | //repaint only if selection has changed |
516 | if (tmp != mSelEnd) { | 516 | if (tmp != mSelEnd) { |
517 | mSelEnd = tmp; | 517 | mSelEnd = tmp; |
518 | repaint(false); | 518 | repaint(false); |
519 | } | 519 | } |
520 | } | 520 | } |
521 | 521 | ||
522 | DateList daylist; | 522 | DateList daylist; |
523 | if ( mSelStart < 0 ) | 523 | if ( mSelStart < 0 ) |
524 | mSelStart = 0; | 524 | mSelStart = 0; |
525 | for (int i = mSelStart; i <= mSelEnd; i++) { | 525 | for (int i = mSelStart; i <= mSelEnd; i++) { |
526 | daylist.append(days[i]); | 526 | daylist.append(days[i]); |
527 | } | 527 | } |
528 | emit selected((const DateList)daylist); | 528 | emit selected((const DateList)daylist); |
529 | 529 | ||
530 | } | 530 | } |
531 | 531 | ||
532 | void KODayMatrix::mouseMoveEvent (QMouseEvent* e) | 532 | void KODayMatrix::mouseMoveEvent (QMouseEvent* e) |
533 | { | 533 | { |
534 | if ( ! mouseDown ) { | 534 | if ( ! mouseDown ) { |
535 | return; | 535 | return; |
536 | } | 536 | } |
537 | int tmp = getDayIndexFrom(e->x(), e->y()); | 537 | int tmp = getDayIndexFrom(e->x(), e->y()); |
538 | if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; | 538 | if (tmp > NUMDAYS-1) tmp=NUMDAYS-1; |
539 | 539 | ||
540 | if (mSelInit > tmp) { | 540 | if (mSelInit > tmp) { |
541 | mSelEnd = mSelInit; | 541 | mSelEnd = mSelInit; |
542 | if (tmp != mSelStart) { | 542 | if (tmp != mSelStart) { |
543 | mSelStart = tmp; | 543 | mSelStart = tmp; |
544 | repaint(false); | 544 | repaint(false); |
545 | } | 545 | } |
546 | } else { | 546 | } else { |
547 | mSelStart = mSelInit; | 547 | mSelStart = mSelInit; |
548 | 548 | ||
549 | //repaint only if selection has changed | 549 | //repaint only if selection has changed |
550 | if (tmp != mSelEnd) { | 550 | if (tmp != mSelEnd) { |
551 | mSelEnd = tmp; | 551 | mSelEnd = tmp; |
552 | repaint(false); | 552 | repaint(false); |
553 | } | 553 | } |
554 | } | 554 | } |
555 | } | 555 | } |
556 | 556 | ||
557 | // ---------------------------------------------------------------------------- | 557 | // ---------------------------------------------------------------------------- |
558 | // D R A G ' N D R O P H A N D L I N G | 558 | // D R A G ' N D R O P H A N D L I N G |
559 | // ---------------------------------------------------------------------------- | 559 | // ---------------------------------------------------------------------------- |
560 | 560 | ||
561 | void KODayMatrix::dragEnterEvent(QDragEnterEvent *e) | 561 | void KODayMatrix::dragEnterEvent(QDragEnterEvent *e) |
562 | { | 562 | { |
563 | #ifndef KORG_NODND | 563 | #ifndef KORG_NODND |
564 | if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { | 564 | if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { |
565 | e->ignore(); | 565 | e->ignore(); |
566 | return; | 566 | return; |
567 | } | 567 | } |
568 | 568 | ||
569 | // some visual feedback | 569 | // some visual feedback |
570 | // oldPalette = palette(); | 570 | // oldPalette = palette(); |
571 | // setPalette(my_HilitePalette); | 571 | // setPalette(my_HilitePalette); |
572 | // update(); | 572 | // update(); |
573 | #endif | 573 | #endif |
574 | } | 574 | } |
575 | 575 | ||
576 | void KODayMatrix::dragMoveEvent(QDragMoveEvent *e) | 576 | void KODayMatrix::dragMoveEvent(QDragMoveEvent *e) |
577 | { | 577 | { |
578 | #ifndef KORG_NODND | 578 | #ifndef KORG_NODND |
579 | if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { | 579 | if ( !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { |
580 | e->ignore(); | 580 | e->ignore(); |
581 | return; | 581 | return; |
582 | } | 582 | } |
583 | 583 | ||
584 | e->accept(); | 584 | e->accept(); |
585 | #endif | 585 | #endif |
586 | } | 586 | } |
587 | 587 | ||
588 | void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/) | 588 | void KODayMatrix::dragLeaveEvent(QDragLeaveEvent */*dl*/) |
589 | { | 589 | { |
590 | #ifndef KORG_NODND | 590 | #ifndef KORG_NODND |
591 | // setPalette(oldPalette); | 591 | // setPalette(oldPalette); |
592 | // update(); | 592 | // update(); |
593 | #endif | 593 | #endif |
594 | } | 594 | } |
595 | 595 | ||
596 | void KODayMatrix::dropEvent(QDropEvent *e) | 596 | void KODayMatrix::dropEvent(QDropEvent *e) |
597 | { | 597 | { |
598 | #ifndef KORG_NODND | 598 | #ifndef KORG_NODND |
599 | // kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl; | 599 | // kdDebug() << "KODayMatrix::dropEvent(e) begin" << endl; |
600 | 600 | ||
601 | if (!mCalendar || !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { | 601 | if (!mCalendar || !ICalDrag::canDecode( e ) && !VCalDrag::canDecode( e ) ) { |
602 | e->ignore(); | 602 | e->ignore(); |
603 | return; | 603 | return; |
604 | } | 604 | } |
605 | 605 | ||
606 | DndFactory factory( mCalendar ); | 606 | DndFactory factory( mCalendar ); |
607 | Event *event = factory.createDrop(e); | 607 | Event *event = factory.createDrop(e); |
608 | 608 | ||
609 | if (event) { | 609 | if (event) { |
610 | e->acceptAction(); | 610 | e->acceptAction(); |
611 | 611 | ||
612 | Event *existingEvent = mCalendar->event(event->uid()); | 612 | Event *existingEvent = mCalendar->event(event->uid()); |
613 | 613 | ||
614 | if(existingEvent) { | 614 | if(existingEvent) { |
615 | // uniquify event | 615 | // uniquify event |
616 | event->recreate(); | 616 | event->recreate(); |
617 | /* | 617 | /* |
618 | KMessageBox::sorry(this, | 618 | KMessageBox::sorry(this, |
619 | i18n("Event already exists in this calendar."), | 619 | i18n("Event already exists in this calendar."), |
620 | i18n("Drop Event")); | 620 | i18n("Drop Event")); |
621 | delete event; | 621 | delete event; |
622 | return; | 622 | return; |
623 | */ | 623 | */ |
624 | } | 624 | } |
625 | // kdDebug() << "Drop new Event" << endl; | 625 | // kdDebug() << "Drop new Event" << endl; |
626 | // Adjust date | 626 | // Adjust date |
627 | QDateTime start = event->dtStart(); | 627 | QDateTime start = event->dtStart(); |
628 | QDateTime end = event->dtEnd(); | 628 | QDateTime end = event->dtEnd(); |
629 | int duration = start.daysTo(end); | 629 | int duration = start.daysTo(end); |
630 | int idx = getDayIndexFrom(e->pos().x(), e->pos().y()); | 630 | int idx = getDayIndexFrom(e->pos().x(), e->pos().y()); |
631 | 631 | ||
632 | start.setDate(days[idx]); | 632 | start.setDate(days[idx]); |
633 | end.setDate(days[idx].addDays(duration)); | 633 | end.setDate(days[idx].addDays(duration)); |
634 | 634 | ||
635 | event->setDtStart(start); | 635 | event->setDtStart(start); |
636 | event->setDtEnd(end); | 636 | event->setDtEnd(end); |
637 | mCalendar->addEvent(event); | 637 | mCalendar->addEvent(event); |
638 | 638 | ||
639 | emit eventDropped(event); | 639 | emit eventDropped(event); |
640 | } else { | 640 | } else { |
641 | // kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl; | 641 | // kdDebug() << "KODayMatrix::dropEvent(): Event from drop not decodable" << endl; |
642 | e->ignore(); | 642 | e->ignore(); |
643 | } | 643 | } |
644 | #endif | 644 | #endif |
645 | } | 645 | } |
646 | 646 | ||
647 | // ---------------------------------------------------------------------------- | 647 | // ---------------------------------------------------------------------------- |
648 | // P A I N T E V E N T H A N D L I N G | 648 | // P A I N T E V E N T H A N D L I N G |
649 | // ---------------------------------------------------------------------------- | 649 | // ---------------------------------------------------------------------------- |
650 | 650 | ||