-rw-r--r-- | library/datebookmonth.cpp | 5 |
1 files changed, 0 insertions, 5 deletions
diff --git a/library/datebookmonth.cpp b/library/datebookmonth.cpp index 728045f..76e022f 100644 --- a/library/datebookmonth.cpp +++ b/library/datebookmonth.cpp | |||
@@ -1,417 +1,412 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include "config.h" | 20 | #include "config.h" |
21 | #include "datebookmonth.h" | 21 | #include "datebookmonth.h" |
22 | #include "datebookdb.h" | 22 | #include "datebookdb.h" |
23 | #include <qtopia/private/event.h> | ||
24 | #include "resource.h" | 23 | #include "resource.h" |
25 | #include <qpe/qpeapplication.h> | 24 | #include <qpe/qpeapplication.h> |
26 | #include "timestring.h" | ||
27 | 25 | ||
28 | #include <qtoolbutton.h> | 26 | #include <qtoolbutton.h> |
29 | #include <qspinbox.h> | 27 | #include <qspinbox.h> |
30 | #include <qcombobox.h> | 28 | #include <qcombobox.h> |
31 | #include <qdatetime.h> | ||
32 | #include <qpainter.h> | ||
33 | #include <qpopupmenu.h> | ||
34 | #include <qvaluestack.h> | 29 | #include <qvaluestack.h> |
35 | #include <qwhatsthis.h> | 30 | #include <qwhatsthis.h> |
36 | 31 | ||
37 | 32 | ||
38 | DateBookMonthHeader::DateBookMonthHeader( QWidget *parent, const char *name ) | 33 | DateBookMonthHeader::DateBookMonthHeader( QWidget *parent, const char *name ) |
39 | : QHBox( parent, name ) | 34 | : QHBox( parent, name ) |
40 | { | 35 | { |
41 | setBackgroundMode( PaletteButton ); | 36 | setBackgroundMode( PaletteButton ); |
42 | 37 | ||
43 | begin = new QToolButton( this ); | 38 | begin = new QToolButton( this ); |
44 | begin->setFocusPolicy(NoFocus); | 39 | begin->setFocusPolicy(NoFocus); |
45 | begin->setPixmap( Resource::loadPixmap( "start" ) ); | 40 | begin->setPixmap( Resource::loadPixmap( "start" ) ); |
46 | begin->setAutoRaise( TRUE ); | 41 | begin->setAutoRaise( TRUE ); |
47 | begin->setFixedSize( begin->sizeHint() ); | 42 | begin->setFixedSize( begin->sizeHint() ); |
48 | QWhatsThis::add( begin, tr("Show January in the selected year") ); | 43 | QWhatsThis::add( begin, tr("Show January in the selected year") ); |
49 | 44 | ||
50 | back = new QToolButton( this ); | 45 | back = new QToolButton( this ); |
51 | back->setFocusPolicy(NoFocus); | 46 | back->setFocusPolicy(NoFocus); |
52 | back->setPixmap( Resource::loadPixmap( "back" ) ); | 47 | back->setPixmap( Resource::loadPixmap( "back" ) ); |
53 | back->setAutoRaise( TRUE ); | 48 | back->setAutoRaise( TRUE ); |
54 | back->setFixedSize( back->sizeHint() ); | 49 | back->setFixedSize( back->sizeHint() ); |
55 | QWhatsThis::add( back, tr("Show the previous month") ); | 50 | QWhatsThis::add( back, tr("Show the previous month") ); |
56 | 51 | ||
57 | month = new QComboBox( FALSE, this ); | 52 | month = new QComboBox( FALSE, this ); |
58 | for ( int i = 0; i < 12; ++i ) | 53 | for ( int i = 0; i < 12; ++i ) |
59 | month->insertItem( Calendar::nameOfMonth( i + 1 ) ); | 54 | month->insertItem( Calendar::nameOfMonth( i + 1 ) ); |
60 | 55 | ||
61 | year = new QSpinBox( 1752, 8000, 1, this ); | 56 | year = new QSpinBox( 1752, 8000, 1, this ); |
62 | 57 | ||
63 | next = new QToolButton( this ); | 58 | next = new QToolButton( this ); |
64 | next->setFocusPolicy(NoFocus); | 59 | next->setFocusPolicy(NoFocus); |
65 | next->setPixmap( Resource::loadPixmap( "forward" ) ); | 60 | next->setPixmap( Resource::loadPixmap( "forward" ) ); |
66 | next->setAutoRaise( TRUE ); | 61 | next->setAutoRaise( TRUE ); |
67 | next->setFixedSize( next->sizeHint() ); | 62 | next->setFixedSize( next->sizeHint() ); |
68 | QWhatsThis::add( next, tr("Show the next month") ); | 63 | QWhatsThis::add( next, tr("Show the next month") ); |
69 | 64 | ||
70 | end = new QToolButton( this ); | 65 | end = new QToolButton( this ); |
71 | end->setFocusPolicy(NoFocus); | 66 | end->setFocusPolicy(NoFocus); |
72 | end->setPixmap( Resource::loadPixmap( "finish" ) ); | 67 | end->setPixmap( Resource::loadPixmap( "finish" ) ); |
73 | end->setAutoRaise( TRUE ); | 68 | end->setAutoRaise( TRUE ); |
74 | end->setFixedSize( end->sizeHint() ); | 69 | end->setFixedSize( end->sizeHint() ); |
75 | QWhatsThis::add( end, tr("Show December in the selected year") ); | 70 | QWhatsThis::add( end, tr("Show December in the selected year") ); |
76 | 71 | ||
77 | connect( month, SIGNAL( activated( int ) ), | 72 | connect( month, SIGNAL( activated( int ) ), |
78 | this, SLOT( updateDate() ) ); | 73 | this, SLOT( updateDate() ) ); |
79 | connect( year, SIGNAL( valueChanged( int ) ), | 74 | connect( year, SIGNAL( valueChanged( int ) ), |
80 | this, SLOT( updateDate() ) ); | 75 | this, SLOT( updateDate() ) ); |
81 | connect( begin, SIGNAL( clicked() ), | 76 | connect( begin, SIGNAL( clicked() ), |
82 | this, SLOT( firstMonth() ) ); | 77 | this, SLOT( firstMonth() ) ); |
83 | connect( end, SIGNAL( clicked() ), | 78 | connect( end, SIGNAL( clicked() ), |
84 | this, SLOT( lastMonth() ) ); | 79 | this, SLOT( lastMonth() ) ); |
85 | connect( back, SIGNAL( clicked() ), | 80 | connect( back, SIGNAL( clicked() ), |
86 | this, SLOT( monthBack() ) ); | 81 | this, SLOT( monthBack() ) ); |
87 | connect( next, SIGNAL( clicked() ), | 82 | connect( next, SIGNAL( clicked() ), |
88 | this, SLOT( monthForward() ) ); | 83 | this, SLOT( monthForward() ) ); |
89 | back->setAutoRepeat( TRUE ); | 84 | back->setAutoRepeat( TRUE ); |
90 | next->setAutoRepeat( TRUE ); | 85 | next->setAutoRepeat( TRUE ); |
91 | } | 86 | } |
92 | 87 | ||
93 | 88 | ||
94 | DateBookMonthHeader::~DateBookMonthHeader() | 89 | DateBookMonthHeader::~DateBookMonthHeader() |
95 | { | 90 | { |
96 | 91 | ||
97 | } | 92 | } |
98 | 93 | ||
99 | void DateBookMonthHeader::updateDate() | 94 | void DateBookMonthHeader::updateDate() |
100 | { | 95 | { |
101 | emit dateChanged( year->value(), month->currentItem() + 1 ); | 96 | emit dateChanged( year->value(), month->currentItem() + 1 ); |
102 | } | 97 | } |
103 | 98 | ||
104 | void DateBookMonthHeader::firstMonth() | 99 | void DateBookMonthHeader::firstMonth() |
105 | { | 100 | { |
106 | emit dateChanged( year->value(), 1 ); | 101 | emit dateChanged( year->value(), 1 ); |
107 | month->setCurrentItem( 0 ); | 102 | month->setCurrentItem( 0 ); |
108 | } | 103 | } |
109 | 104 | ||
110 | void DateBookMonthHeader::lastMonth() | 105 | void DateBookMonthHeader::lastMonth() |
111 | { | 106 | { |
112 | emit dateChanged( year->value(), 12 ); | 107 | emit dateChanged( year->value(), 12 ); |
113 | month->setCurrentItem( 11 ); | 108 | month->setCurrentItem( 11 ); |
114 | } | 109 | } |
115 | 110 | ||
116 | void DateBookMonthHeader::monthBack() | 111 | void DateBookMonthHeader::monthBack() |
117 | { | 112 | { |
118 | if ( month->currentItem() > 0 ) { | 113 | if ( month->currentItem() > 0 ) { |
119 | emit dateChanged( year->value(), month->currentItem() ); | 114 | emit dateChanged( year->value(), month->currentItem() ); |
120 | month->setCurrentItem( month->currentItem() - 1 ); | 115 | month->setCurrentItem( month->currentItem() - 1 ); |
121 | } else { | 116 | } else { |
122 | emit dateChanged( year->value() - 1, 12 ); | 117 | emit dateChanged( year->value() - 1, 12 ); |
123 | // we have a signal set to a changed value in year so we only need to change | 118 | // we have a signal set to a changed value in year so we only need to change |
124 | // year to get the result... | 119 | // year to get the result... |
125 | month->setCurrentItem( 11 ); | 120 | month->setCurrentItem( 11 ); |
126 | year->setValue( year->value() - 1 ); | 121 | year->setValue( year->value() - 1 ); |
127 | } | 122 | } |
128 | } | 123 | } |
129 | 124 | ||
130 | void DateBookMonthHeader::monthForward() | 125 | void DateBookMonthHeader::monthForward() |
131 | { | 126 | { |
132 | if ( month->currentItem() < 11 ) { | 127 | if ( month->currentItem() < 11 ) { |
133 | emit dateChanged( year->value(), month->currentItem() + 2 ); | 128 | emit dateChanged( year->value(), month->currentItem() + 2 ); |
134 | month->setCurrentItem( month->currentItem() + 1 ); | 129 | month->setCurrentItem( month->currentItem() + 1 ); |
135 | } else { | 130 | } else { |
136 | // we have a signal set to a changed value in year so we only need to change | 131 | // we have a signal set to a changed value in year so we only need to change |
137 | // year to get the result... | 132 | // year to get the result... |
138 | month->setCurrentItem( 0 ); | 133 | month->setCurrentItem( 0 ); |
139 | year->setValue( year->value() + 1 ); | 134 | year->setValue( year->value() + 1 ); |
140 | } | 135 | } |
141 | } | 136 | } |
142 | 137 | ||
143 | void DateBookMonthHeader::setDate( int y, int m ) | 138 | void DateBookMonthHeader::setDate( int y, int m ) |
144 | { | 139 | { |
145 | year->setValue( y ); | 140 | year->setValue( y ); |
146 | month->setCurrentItem( m - 1 ); | 141 | month->setCurrentItem( m - 1 ); |
147 | } | 142 | } |
148 | 143 | ||
149 | //--------------------------------------------------------------------------- | 144 | //--------------------------------------------------------------------------- |
150 | 145 | ||
151 | class DateBookMonthTablePrivate | 146 | class DateBookMonthTablePrivate |
152 | { | 147 | { |
153 | public: | 148 | public: |
154 | DateBookMonthTablePrivate() {}; | 149 | DateBookMonthTablePrivate() {}; |
155 | ~DateBookMonthTablePrivate() { mMonthEvents.clear(); }; | 150 | ~DateBookMonthTablePrivate() { mMonthEvents.clear(); }; |
156 | 151 | ||
157 | QValueList<EffectiveEvent> mMonthEvents; | 152 | QValueList<EffectiveEvent> mMonthEvents; |
158 | bool onMonday; | 153 | bool onMonday; |
159 | }; | 154 | }; |
160 | 155 | ||
161 | DateBookMonthTable::DateBookMonthTable( QWidget *parent, const char *name, | 156 | DateBookMonthTable::DateBookMonthTable( QWidget *parent, const char *name, |
162 | DateBookDB *newDb ) | 157 | DateBookDB *newDb ) |
163 | : QTable( 6, 7, parent, name ), | 158 | : QTable( 6, 7, parent, name ), |
164 | db( newDb ) | 159 | db( newDb ) |
165 | { | 160 | { |
166 | d = new DateBookMonthTablePrivate(); | 161 | d = new DateBookMonthTablePrivate(); |
167 | selYear = -1; | 162 | selYear = -1; |
168 | selMonth = -1; | 163 | selMonth = -1; |
169 | selDay = -1; | 164 | selDay = -1; |
170 | 165 | ||
171 | /* init these as well make valgrind happy and be consistent with Qtopia1.6 -zecke */ | 166 | /* init these as well make valgrind happy and be consistent with Qtopia1.6 -zecke */ |
172 | year = -1; | 167 | year = -1; |
173 | month = -1; | 168 | month = -1; |
174 | day = -1; | 169 | day = -1; |
175 | 170 | ||
176 | Config cfg( "qpe" ); | 171 | Config cfg( "qpe" ); |
177 | cfg.setGroup( "Time" ); | 172 | cfg.setGroup( "Time" ); |
178 | d->onMonday = cfg.readBoolEntry( "MONDAY" ); | 173 | d->onMonday = cfg.readBoolEntry( "MONDAY" ); |
179 | 174 | ||
180 | horizontalHeader()->setResizeEnabled( FALSE ); | 175 | horizontalHeader()->setResizeEnabled( FALSE ); |
181 | // we have to do this here... or suffer the consequences later... | 176 | // we have to do this here... or suffer the consequences later... |
182 | for ( int i = 0; i < 7; i++ ){ | 177 | for ( int i = 0; i < 7; i++ ){ |
183 | horizontalHeader()->resizeSection( i, 30 ); | 178 | horizontalHeader()->resizeSection( i, 30 ); |
184 | setColumnStretchable( i, TRUE ); | 179 | setColumnStretchable( i, TRUE ); |
185 | } | 180 | } |
186 | setupLabels(); | 181 | setupLabels(); |
187 | 182 | ||
188 | verticalHeader()->hide(); | 183 | verticalHeader()->hide(); |
189 | setLeftMargin( 0 ); | 184 | setLeftMargin( 0 ); |
190 | for ( int i = 0; i < 6; ++i ) | 185 | for ( int i = 0; i < 6; ++i ) |
191 | setRowStretchable( i, TRUE ); | 186 | setRowStretchable( i, TRUE ); |
192 | 187 | ||
193 | setSelectionMode( NoSelection ); | 188 | setSelectionMode( NoSelection ); |
194 | 189 | ||
195 | connect( this, SIGNAL( clicked( int, int, int, const QPoint & ) ), | 190 | connect( this, SIGNAL( clicked( int, int, int, const QPoint & ) ), |
196 | this, SLOT( dayClicked( int, int ) ) ); | 191 | this, SLOT( dayClicked( int, int ) ) ); |
197 | connect( this, SIGNAL( currentChanged( int, int ) ), | 192 | connect( this, SIGNAL( currentChanged( int, int ) ), |
198 | this, SLOT( dragDay( int, int ) ) ); | 193 | this, SLOT( dragDay( int, int ) ) ); |
199 | setVScrollBarMode( AlwaysOff ); | 194 | setVScrollBarMode( AlwaysOff ); |
200 | setHScrollBarMode( AlwaysOff ); | 195 | setHScrollBarMode( AlwaysOff ); |
201 | } | 196 | } |
202 | 197 | ||
203 | DateBookMonthTable::~DateBookMonthTable() | 198 | DateBookMonthTable::~DateBookMonthTable() |
204 | { | 199 | { |
205 | monthsEvents.clear(); | 200 | monthsEvents.clear(); |
206 | delete d; | 201 | delete d; |
207 | } | 202 | } |
208 | 203 | ||
209 | void DateBookMonthTable::setDate(int y, int m, int d) | 204 | void DateBookMonthTable::setDate(int y, int m, int d) |
210 | { | 205 | { |
211 | if (month == m && year == y) { | 206 | if (month == m && year == y) { |
212 | if ( selYear == -1 ) | 207 | if ( selYear == -1 ) |
213 | year = selYear; | 208 | year = selYear; |
214 | if ( selMonth == -1 ) | 209 | if ( selMonth == -1 ) |
215 | month = selMonth; | 210 | month = selMonth; |
216 | int r1, c1, r2, c2; | 211 | int r1, c1, r2, c2; |
217 | findDay(selDay, r1, c1); | 212 | findDay(selDay, r1, c1); |
218 | selDay = day = d; | 213 | selDay = day = d; |
219 | findDay(selDay, r2, c2); | 214 | findDay(selDay, r2, c2); |
220 | setCurrentCell( r2, c2 ); | 215 | setCurrentCell( r2, c2 ); |
221 | //updateCell(r1,c1); | 216 | //updateCell(r1,c1); |
222 | //updateCell(r2,c2); | 217 | //updateCell(r2,c2); |
223 | } else { | 218 | } else { |
224 | selYear = year = y; | 219 | selYear = year = y; |
225 | selMonth = month = m; | 220 | selMonth = month = m; |
226 | selDay = day = d; | 221 | selDay = day = d; |
227 | setupTable(); | 222 | setupTable(); |
228 | } | 223 | } |
229 | } | 224 | } |
230 | 225 | ||
231 | void DateBookMonthTable::redraw() | 226 | void DateBookMonthTable::redraw() |
232 | { | 227 | { |
233 | setupLabels(); | 228 | setupLabels(); |
234 | setupTable(); | 229 | setupTable(); |
235 | } | 230 | } |
236 | 231 | ||
237 | void DateBookMonthTable::setWeekStart( bool onMonday ) | 232 | void DateBookMonthTable::setWeekStart( bool onMonday ) |
238 | { | 233 | { |
239 | d->onMonday = onMonday; | 234 | d->onMonday = onMonday; |
240 | setupLabels(); | 235 | setupLabels(); |
241 | setupTable(); | 236 | setupTable(); |
242 | } | 237 | } |
243 | 238 | ||
244 | void DateBookMonthTable::setupTable() | 239 | void DateBookMonthTable::setupTable() |
245 | { | 240 | { |
246 | QValueList<Calendar::Day> days = Calendar::daysOfMonth( year, month, d->onMonday ); | 241 | QValueList<Calendar::Day> days = Calendar::daysOfMonth( year, month, d->onMonday ); |
247 | QValueList<Calendar::Day>::Iterator it = days.begin(); | 242 | QValueList<Calendar::Day>::Iterator it = days.begin(); |
248 | int row = 0, col = 0; | 243 | int row = 0, col = 0; |
249 | int crow = 0; | 244 | int crow = 0; |
250 | int ccol = 0; | 245 | int ccol = 0; |
251 | for ( ; it != days.end(); ++it ) { | 246 | for ( ; it != days.end(); ++it ) { |
252 | DayItemMonth *i = (DayItemMonth *)item( row, col ); | 247 | DayItemMonth *i = (DayItemMonth *)item( row, col ); |
253 | if ( !i ) { | 248 | if ( !i ) { |
254 | i = new DayItemMonth( this, QTableItem::Never, "" ); | 249 | i = new DayItemMonth( this, QTableItem::Never, "" ); |
255 | setItem( row, col, i ); | 250 | setItem( row, col, i ); |
256 | } | 251 | } |
257 | Calendar::Day calDay = *it; | 252 | Calendar::Day calDay = *it; |
258 | i->clearEffEvents(); | 253 | i->clearEffEvents(); |
259 | i->setDay( calDay.date ); | 254 | i->setDay( calDay.date ); |
260 | i->setType( calDay.type ); | 255 | i->setType( calDay.type ); |
261 | if ( i->day() == day && calDay.type == Calendar::Day::ThisMonth ) { | 256 | if ( i->day() == day && calDay.type == Calendar::Day::ThisMonth ) { |
262 | crow = row; | 257 | crow = row; |
263 | ccol = col; | 258 | ccol = col; |
264 | } | 259 | } |
265 | 260 | ||
266 | updateCell( row, col ); | 261 | updateCell( row, col ); |
267 | 262 | ||
268 | if ( col == 6 ) { | 263 | if ( col == 6 ) { |
269 | ++row; | 264 | ++row; |
270 | col = 0; | 265 | col = 0; |
271 | } else { | 266 | } else { |
272 | ++col; | 267 | ++col; |
273 | } | 268 | } |
274 | } | 269 | } |
275 | setCurrentCell( crow, ccol ); | 270 | setCurrentCell( crow, ccol ); |
276 | getEvents(); | 271 | getEvents(); |
277 | } | 272 | } |
278 | 273 | ||
279 | void DateBookMonthTable::findDay( int day, int &row, int &col ) | 274 | void DateBookMonthTable::findDay( int day, int &row, int &col ) |
280 | { | 275 | { |
281 | QDate dtBegin( year, month, 1 ); | 276 | QDate dtBegin( year, month, 1 ); |
282 | int skips = dtBegin.dayOfWeek(); | 277 | int skips = dtBegin.dayOfWeek(); |
283 | int effective_day = day + skips - 1; // row/columns begin at 0 | 278 | int effective_day = day + skips - 1; // row/columns begin at 0 |
284 | // make an extra adjustment if we start on Mondays. | 279 | // make an extra adjustment if we start on Mondays. |
285 | if ( d->onMonday ) | 280 | if ( d->onMonday ) |
286 | effective_day--; | 281 | effective_day--; |
287 | row = effective_day / 7; | 282 | row = effective_day / 7; |
288 | col = effective_day % 7; | 283 | col = effective_day % 7; |
289 | } | 284 | } |
290 | 285 | ||
291 | void DateBookMonthTable::dayClicked( int row, int col ) | 286 | void DateBookMonthTable::dayClicked( int row, int col ) |
292 | { | 287 | { |
293 | changeDaySelection( row, col ); | 288 | changeDaySelection( row, col ); |
294 | emit dateClicked( selYear, selMonth, selDay ); | 289 | emit dateClicked( selYear, selMonth, selDay ); |
295 | } | 290 | } |
296 | 291 | ||
297 | void DateBookMonthTable::dragDay( int row, int col ) | 292 | void DateBookMonthTable::dragDay( int row, int col ) |
298 | { | 293 | { |
299 | changeDaySelection( row, col ); | 294 | changeDaySelection( row, col ); |
300 | } | 295 | } |
301 | 296 | ||
302 | void DateBookMonthTable::changeDaySelection( int row, int col ) | 297 | void DateBookMonthTable::changeDaySelection( int row, int col ) |
303 | { | 298 | { |
304 | DayItemMonth *i = (DayItemMonth*)item( row, col ); | 299 | DayItemMonth *i = (DayItemMonth*)item( row, col ); |
305 | if ( !i ) | 300 | if ( !i ) |
306 | return; | 301 | return; |
307 | switch ( i->type() ) { | 302 | switch ( i->type() ) { |
308 | case Calendar::Day::ThisMonth: | 303 | case Calendar::Day::ThisMonth: |
309 | selMonth = month; | 304 | selMonth = month; |
310 | break; | 305 | break; |
311 | case Calendar::Day::PrevMonth: | 306 | case Calendar::Day::PrevMonth: |
312 | selMonth = month-1; | 307 | selMonth = month-1; |
313 | break; | 308 | break; |
314 | default: | 309 | default: |
315 | selMonth = month+1; | 310 | selMonth = month+1; |
316 | } | 311 | } |
317 | 312 | ||
318 | selYear = year; | 313 | selYear = year; |
319 | if ( selMonth <= 0 ) { | 314 | if ( selMonth <= 0 ) { |
320 | selMonth = 12; | 315 | selMonth = 12; |
321 | selYear--; | 316 | selYear--; |
322 | } else if ( selMonth > 12 ) { | 317 | } else if ( selMonth > 12 ) { |
323 | selMonth = 1; | 318 | selMonth = 1; |
324 | selYear++; | 319 | selYear++; |
325 | } | 320 | } |
326 | selDay = i->day(); | 321 | selDay = i->day(); |
327 | } | 322 | } |
328 | 323 | ||
329 | 324 | ||
330 | void DateBookMonthTable::viewportMouseReleaseEvent( QMouseEvent * ) | 325 | void DateBookMonthTable::viewportMouseReleaseEvent( QMouseEvent * ) |
331 | { | 326 | { |
332 | dayClicked( currentRow(), currentColumn() ); | 327 | dayClicked( currentRow(), currentColumn() ); |
333 | } | 328 | } |
334 | 329 | ||
335 | void DateBookMonthTable::getEvents() | 330 | void DateBookMonthTable::getEvents() |
336 | { | 331 | { |
337 | if ( !db ) | 332 | if ( !db ) |
338 | return; | 333 | return; |
339 | 334 | ||
340 | QDate dtStart( year, month, 1 ); | 335 | QDate dtStart( year, month, 1 ); |
341 | d->mMonthEvents = db->getEffectiveEvents( dtStart, | 336 | d->mMonthEvents = db->getEffectiveEvents( dtStart, |
342 | QDate( year, month, | 337 | QDate( year, month, |
343 | dtStart.daysInMonth() ) ); | 338 | dtStart.daysInMonth() ) ); |
344 | QValueListIterator<EffectiveEvent> it = d->mMonthEvents.begin(); | 339 | QValueListIterator<EffectiveEvent> it = d->mMonthEvents.begin(); |
345 | // now that the events are sorted, basically go through the list, make | 340 | // now that the events are sorted, basically go through the list, make |
346 | // a small list for every day and set it for each item... | 341 | // a small list for every day and set it for each item... |
347 | // clear all the items... | 342 | // clear all the items... |
348 | while ( it != d->mMonthEvents.end() ) { | 343 | while ( it != d->mMonthEvents.end() ) { |
349 | QValueList<EffectiveEvent> dayEvent; | 344 | QValueList<EffectiveEvent> dayEvent; |
350 | EffectiveEvent e = *it; | 345 | EffectiveEvent e = *it; |
351 | ++it; | 346 | ++it; |
352 | dayEvent.append( e ); | 347 | dayEvent.append( e ); |
353 | while ( it != d->mMonthEvents.end() | 348 | while ( it != d->mMonthEvents.end() |
354 | && e.date() == (*it).date() ) { | 349 | && e.date() == (*it).date() ) { |
355 | dayEvent.append( *it ); | 350 | dayEvent.append( *it ); |
356 | ++it; | 351 | ++it; |
357 | } | 352 | } |
358 | int row, col; | 353 | int row, col; |
359 | findDay( e.date().day(), row, col ); | 354 | findDay( e.date().day(), row, col ); |
360 | DayItemMonth* w = static_cast<DayItemMonth*>( item( row, col ) ); | 355 | DayItemMonth* w = static_cast<DayItemMonth*>( item( row, col ) ); |
361 | w->setEvents( dayEvent ); | 356 | w->setEvents( dayEvent ); |
362 | updateCell( row, col ); | 357 | updateCell( row, col ); |
363 | dayEvent.clear(); | 358 | dayEvent.clear(); |
364 | } | 359 | } |
365 | } | 360 | } |
366 | 361 | ||
367 | 362 | ||
368 | void DateBookMonthTable::setupLabels() | 363 | void DateBookMonthTable::setupLabels() |
369 | { | 364 | { |
370 | for ( int i = 0; i < 7; ++i ) { | 365 | for ( int i = 0; i < 7; ++i ) { |
371 | // horizontalHeader()->resizeSection( i, 30 ); | 366 | // horizontalHeader()->resizeSection( i, 30 ); |
372 | // setColumnStretchable( i, TRUE ); | 367 | // setColumnStretchable( i, TRUE ); |
373 | if ( d->onMonday ) | 368 | if ( d->onMonday ) |
374 | horizontalHeader()->setLabel( i, Calendar::nameOfDay( i + 1 ) ); | 369 | horizontalHeader()->setLabel( i, Calendar::nameOfDay( i + 1 ) ); |
375 | else { | 370 | else { |
376 | if ( i == 0 ) | 371 | if ( i == 0 ) |
377 | horizontalHeader()->setLabel( i, Calendar::nameOfDay( 7 ) ); | 372 | horizontalHeader()->setLabel( i, Calendar::nameOfDay( 7 ) ); |
378 | else | 373 | else |
379 | horizontalHeader()->setLabel( i, Calendar::nameOfDay( i ) ); | 374 | horizontalHeader()->setLabel( i, Calendar::nameOfDay( i ) ); |
380 | } | 375 | } |
381 | } | 376 | } |
382 | } | 377 | } |
383 | 378 | ||
384 | 379 | ||
385 | //--------------------------------------------------------------------------- | 380 | //--------------------------------------------------------------------------- |
386 | 381 | ||
387 | DateBookMonth::DateBookMonth( QWidget *parent, const char *name, bool ac, | 382 | DateBookMonth::DateBookMonth( QWidget *parent, const char *name, bool ac, |
388 | DateBookDB *data ) | 383 | DateBookDB *data ) |
389 | : QVBox( parent, name ), | 384 | : QVBox( parent, name ), |
390 | autoClose( ac ) | 385 | autoClose( ac ) |
391 | { | 386 | { |
392 | setFocusPolicy(StrongFocus); | 387 | setFocusPolicy(StrongFocus); |
393 | year = QDate::currentDate().year(); | 388 | year = QDate::currentDate().year(); |
394 | month = QDate::currentDate().month(); | 389 | month = QDate::currentDate().month(); |
395 | day = QDate::currentDate().day(); | 390 | day = QDate::currentDate().day(); |
396 | header = new DateBookMonthHeader( this, "DateBookMonthHeader" ); | 391 | header = new DateBookMonthHeader( this, "DateBookMonthHeader" ); |
397 | table = new DateBookMonthTable( this, "DateBookMonthTable", data ); | 392 | table = new DateBookMonthTable( this, "DateBookMonthTable", data ); |
398 | header->setDate( year, month ); | 393 | header->setDate( year, month ); |
399 | table->setDate( year, month, QDate::currentDate().day() ); | 394 | table->setDate( year, month, QDate::currentDate().day() ); |
400 | header->setFocusPolicy(NoFocus); | 395 | header->setFocusPolicy(NoFocus); |
401 | table->setFocusPolicy(NoFocus); | 396 | table->setFocusPolicy(NoFocus); |
402 | connect( header, SIGNAL( dateChanged( int, int ) ), | 397 | connect( header, SIGNAL( dateChanged( int, int ) ), |
403 | this, SLOT( setDate( int, int ) ) ); | 398 | this, SLOT( setDate( int, int ) ) ); |
404 | connect( table, SIGNAL( dateClicked( int, int, int ) ), | 399 | connect( table, SIGNAL( dateClicked( int, int, int ) ), |
405 | this, SLOT( finalDate(int, int, int) ) ); | 400 | this, SLOT( finalDate(int, int, int) ) ); |
406 | connect( qApp, SIGNAL(weekChanged(bool)), this, | 401 | connect( qApp, SIGNAL(weekChanged(bool)), this, |
407 | SLOT(slotWeekChange(bool)) ); | 402 | SLOT(slotWeekChange(bool)) ); |
408 | table->setFocus(); | 403 | table->setFocus(); |
409 | } | 404 | } |
410 | 405 | ||
411 | DateBookMonth::~DateBookMonth() | 406 | DateBookMonth::~DateBookMonth() |
412 | { | 407 | { |
413 | 408 | ||
414 | } | 409 | } |
415 | 410 | ||
416 | void DateBookMonth::setDate( int y, int m ) | 411 | void DateBookMonth::setDate( int y, int m ) |
417 | { | 412 | { |