summaryrefslogtreecommitdiff
path: root/library/datebookmonth.cpp
Unidiff
Diffstat (limited to 'library/datebookmonth.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/datebookmonth.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/library/datebookmonth.cpp b/library/datebookmonth.cpp
index b2074e6..f4b3e6b 100644
--- a/library/datebookmonth.cpp
+++ b/library/datebookmonth.cpp
@@ -1,249 +1,249 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of 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 <qpe/event.h> 23#include <qpe/event.h>
24#include "resource.h" 24#include "resource.h"
25#include "qpeapplication.h" 25#include "qpeapplication.h"
26#include "timestring.h" 26#include "timestring.h"
27 27
28#include <qtoolbutton.h> 28#include <qtoolbutton.h>
29#include <qspinbox.h> 29#include <qspinbox.h>
30#include <qcombobox.h> 30#include <qcombobox.h>
31#include <qdatetime.h> 31#include <qdatetime.h>
32#include <qpainter.h> 32#include <qpainter.h>
33#include <qpopupmenu.h> 33#include <qpopupmenu.h>
34 34
35 35
36DateBookMonthHeader::DateBookMonthHeader( QWidget *parent, const char *name ) 36DateBookMonthHeader::DateBookMonthHeader( QWidget *parent, const char *name )
37 : QHBox( parent, name ) 37 : QHBox( parent, name )
38{ 38{
39 setBackgroundMode( PaletteButton ); 39 setBackgroundMode( PaletteButton );
40 40
41 begin = new QToolButton( this ); 41 begin = new QToolButton( this );
42 begin->setFocusPolicy(NoFocus); 42 begin->setFocusPolicy(NoFocus);
43 begin->setPixmap( Resource::loadPixmap( "start" ) ); 43 begin->setPixmap( Resource::loadPixmap( "start" ) );
44 begin->setAutoRaise( TRUE ); 44 begin->setAutoRaise( TRUE );
45 begin->setFixedSize( begin->sizeHint() ); 45 begin->setFixedSize( begin->sizeHint() );
46 46
47 back = new QToolButton( this ); 47 back = new QToolButton( this );
48 back->setFocusPolicy(NoFocus); 48 back->setFocusPolicy(NoFocus);
49 back->setPixmap( Resource::loadPixmap( "back" ) ); 49 back->setPixmap( Resource::loadPixmap( "back" ) );
50 back->setAutoRaise( TRUE ); 50 back->setAutoRaise( TRUE );
51 back->setFixedSize( back->sizeHint() ); 51 back->setFixedSize( back->sizeHint() );
52 52
53 month = new QComboBox( FALSE, this ); 53 month = new QComboBox( FALSE, this );
54 for ( int i = 0; i < 12; ++i ) 54 for ( int i = 0; i < 12; ++i )
55 month->insertItem( Calendar::nameOfMonth( i + 1 ) ); 55 month->insertItem( Calendar::nameOfMonth( i + 1 ) );
56 56
57 year = new QSpinBox( 1970, 2037, 1, this ); 57 year = new QSpinBox( 1752, 8000, 1, this );
58 58
59 next = new QToolButton( this ); 59 next = new QToolButton( this );
60 next->setFocusPolicy(NoFocus); 60 next->setFocusPolicy(NoFocus);
61 next->setPixmap( Resource::loadPixmap( "forward" ) ); 61 next->setPixmap( Resource::loadPixmap( "forward" ) );
62 next->setAutoRaise( TRUE ); 62 next->setAutoRaise( TRUE );
63 next->setFixedSize( next->sizeHint() ); 63 next->setFixedSize( next->sizeHint() );
64 64
65 end = new QToolButton( this ); 65 end = new QToolButton( this );
66 end->setFocusPolicy(NoFocus); 66 end->setFocusPolicy(NoFocus);
67 end->setPixmap( Resource::loadPixmap( "finish" ) ); 67 end->setPixmap( Resource::loadPixmap( "finish" ) );
68 end->setAutoRaise( TRUE ); 68 end->setAutoRaise( TRUE );
69 end->setFixedSize( end->sizeHint() ); 69 end->setFixedSize( end->sizeHint() );
70 70
71 connect( month, SIGNAL( activated( int ) ), 71 connect( month, SIGNAL( activated( int ) ),
72 this, SLOT( updateDate() ) ); 72 this, SLOT( updateDate() ) );
73 connect( year, SIGNAL( valueChanged( int ) ), 73 connect( year, SIGNAL( valueChanged( int ) ),
74 this, SLOT( updateDate() ) ); 74 this, SLOT( updateDate() ) );
75 connect( begin, SIGNAL( clicked() ), 75 connect( begin, SIGNAL( clicked() ),
76 this, SLOT( firstMonth() ) ); 76 this, SLOT( firstMonth() ) );
77 connect( end, SIGNAL( clicked() ), 77 connect( end, SIGNAL( clicked() ),
78 this, SLOT( lastMonth() ) ); 78 this, SLOT( lastMonth() ) );
79 connect( back, SIGNAL( clicked() ), 79 connect( back, SIGNAL( clicked() ),
80 this, SLOT( monthBack() ) ); 80 this, SLOT( monthBack() ) );
81 connect( next, SIGNAL( clicked() ), 81 connect( next, SIGNAL( clicked() ),
82 this, SLOT( monthForward() ) ); 82 this, SLOT( monthForward() ) );
83 back->setAutoRepeat( TRUE ); 83 back->setAutoRepeat( TRUE );
84 next->setAutoRepeat( TRUE ); 84 next->setAutoRepeat( TRUE );
85} 85}
86 86
87 87
88DateBookMonthHeader::~DateBookMonthHeader() 88DateBookMonthHeader::~DateBookMonthHeader()
89{ 89{
90 90
91} 91}
92 92
93void DateBookMonthHeader::updateDate() 93void DateBookMonthHeader::updateDate()
94{ 94{
95 emit dateChanged( year->value(), month->currentItem() + 1 ); 95 emit dateChanged( year->value(), month->currentItem() + 1 );
96} 96}
97 97
98void DateBookMonthHeader::firstMonth() 98void DateBookMonthHeader::firstMonth()
99{ 99{
100 emit dateChanged( year->value(), 1 ); 100 emit dateChanged( year->value(), 1 );
101 month->setCurrentItem( 0 ); 101 month->setCurrentItem( 0 );
102} 102}
103 103
104void DateBookMonthHeader::lastMonth() 104void DateBookMonthHeader::lastMonth()
105{ 105{
106 emit dateChanged( year->value(), 12 ); 106 emit dateChanged( year->value(), 12 );
107 month->setCurrentItem( 11 ); 107 month->setCurrentItem( 11 );
108} 108}
109 109
110void DateBookMonthHeader::monthBack() 110void DateBookMonthHeader::monthBack()
111{ 111{
112 if ( month->currentItem() > 0 ) { 112 if ( month->currentItem() > 0 ) {
113 emit dateChanged( year->value(), month->currentItem() ); 113 emit dateChanged( year->value(), month->currentItem() );
114 month->setCurrentItem( month->currentItem() - 1 ); 114 month->setCurrentItem( month->currentItem() - 1 );
115 } else { 115 } else {
116 emit dateChanged( year->value() - 1, 12 ); 116 emit dateChanged( year->value() - 1, 12 );
117 // we have a signal set to a changed value in year so we only need to change 117 // we have a signal set to a changed value in year so we only need to change
118 // year to get the result... 118 // year to get the result...
119 month->setCurrentItem( 11 ); 119 month->setCurrentItem( 11 );
120 year->setValue( year->value() - 1 ); 120 year->setValue( year->value() - 1 );
121 } 121 }
122} 122}
123 123
124void DateBookMonthHeader::monthForward() 124void DateBookMonthHeader::monthForward()
125{ 125{
126 if ( month->currentItem() < 11 ) { 126 if ( month->currentItem() < 11 ) {
127 emit dateChanged( year->value(), month->currentItem() + 2 ); 127 emit dateChanged( year->value(), month->currentItem() + 2 );
128 month->setCurrentItem( month->currentItem() + 1 ); 128 month->setCurrentItem( month->currentItem() + 1 );
129 } else { 129 } else {
130 // we have a signal set to a changed value in year so we only need to change 130 // we have a signal set to a changed value in year so we only need to change
131 // year to get the result... 131 // year to get the result...
132 month->setCurrentItem( 0 ); 132 month->setCurrentItem( 0 );
133 year->setValue( year->value() + 1 ); 133 year->setValue( year->value() + 1 );
134 } 134 }
135} 135}
136 136
137void DateBookMonthHeader::setDate( int y, int m ) 137void DateBookMonthHeader::setDate( int y, int m )
138{ 138{
139 year->setValue( y ); 139 year->setValue( y );
140 month->setCurrentItem( m - 1 ); 140 month->setCurrentItem( m - 1 );
141} 141}
142 142
143//--------------------------------------------------------------------------- 143//---------------------------------------------------------------------------
144 144
145class DateBookMonthTablePrivate 145class DateBookMonthTablePrivate
146{ 146{
147public: 147public:
148 DateBookMonthTablePrivate() {}; 148 DateBookMonthTablePrivate() {};
149 ~DateBookMonthTablePrivate() { mMonthEvents.clear(); }; 149 ~DateBookMonthTablePrivate() { mMonthEvents.clear(); };
150 150
151 QValueList<EffectiveEvent> mMonthEvents; 151 QValueList<EffectiveEvent> mMonthEvents;
152 bool onMonday; 152 bool onMonday;
153}; 153};
154 154
155DateBookMonthTable::DateBookMonthTable( QWidget *parent, const char *name, 155DateBookMonthTable::DateBookMonthTable( QWidget *parent, const char *name,
156 DateBookDB *newDb ) 156 DateBookDB *newDb )
157 : QTable( 6, 7, parent, name ), 157 : QTable( 6, 7, parent, name ),
158 db( newDb ) 158 db( newDb )
159{ 159{
160 d = new DateBookMonthTablePrivate(); 160 d = new DateBookMonthTablePrivate();
161 selYear = -1; 161 selYear = -1;
162 selMonth = -1; 162 selMonth = -1;
163 selDay = -1; 163 selDay = -1;
164 164
165 Config cfg( "qpe" ); 165 Config cfg( "qpe" );
166 cfg.setGroup( "Time" ); 166 cfg.setGroup( "Time" );
167 d->onMonday = cfg.readBoolEntry( "MONDAY" ); 167 d->onMonday = cfg.readBoolEntry( "MONDAY" );
168 168
169 horizontalHeader()->setResizeEnabled( FALSE ); 169 horizontalHeader()->setResizeEnabled( FALSE );
170 // we have to do this here... or suffer the consequences later... 170 // we have to do this here... or suffer the consequences later...
171 for ( int i = 0; i < 7; i++ ){ 171 for ( int i = 0; i < 7; i++ ){
172 horizontalHeader()->resizeSection( i, 30 ); 172 horizontalHeader()->resizeSection( i, 30 );
173 setColumnStretchable( i, TRUE ); 173 setColumnStretchable( i, TRUE );
174 } 174 }
175 setupLabels(); 175 setupLabels();
176 176
177 verticalHeader()->hide(); 177 verticalHeader()->hide();
178 setLeftMargin( 0 ); 178 setLeftMargin( 0 );
179 for ( int i = 0; i < 6; ++i ) 179 for ( int i = 0; i < 6; ++i )
180 setRowStretchable( i, TRUE ); 180 setRowStretchable( i, TRUE );
181 181
182 setSelectionMode( NoSelection ); 182 setSelectionMode( NoSelection );
183 183
184 connect( this, SIGNAL( clicked( int, int, int, const QPoint & ) ), 184 connect( this, SIGNAL( clicked( int, int, int, const QPoint & ) ),
185 this, SLOT( dayClicked( int, int ) ) ); 185 this, SLOT( dayClicked( int, int ) ) );
186 connect( this, SIGNAL( currentChanged( int, int ) ), 186 connect( this, SIGNAL( currentChanged( int, int ) ),
187 this, SLOT( dragDay( int, int ) ) ); 187 this, SLOT( dragDay( int, int ) ) );
188 setVScrollBarMode( AlwaysOff ); 188 setVScrollBarMode( AlwaysOff );
189 setHScrollBarMode( AlwaysOff ); 189 setHScrollBarMode( AlwaysOff );
190} 190}
191 191
192DateBookMonthTable::~DateBookMonthTable() 192DateBookMonthTable::~DateBookMonthTable()
193{ 193{
194 monthsEvents.clear(); 194 monthsEvents.clear();
195 delete d; 195 delete d;
196} 196}
197 197
198void DateBookMonthTable::setDate(int y, int m, int d) 198void DateBookMonthTable::setDate(int y, int m, int d)
199{ 199{
200 if (month == m && year == y) { 200 if (month == m && year == y) {
201 if ( selYear == -1 ) 201 if ( selYear == -1 )
202 year = selYear; 202 year = selYear;
203 if ( selMonth == -1 ) 203 if ( selMonth == -1 )
204 month = selMonth; 204 month = selMonth;
205 int r1, c1, r2, c2; 205 int r1, c1, r2, c2;
206 findDay(selDay, r1, c1); 206 findDay(selDay, r1, c1);
207 selDay = day = d; 207 selDay = day = d;
208 findDay(selDay, r2, c2); 208 findDay(selDay, r2, c2);
209 setCurrentCell( r2, c2 ); 209 setCurrentCell( r2, c2 );
210 //updateCell(r1,c1); 210 //updateCell(r1,c1);
211 //updateCell(r2,c2); 211 //updateCell(r2,c2);
212 } else { 212 } else {
213 selYear = year = y; 213 selYear = year = y;
214 selMonth = month = m; 214 selMonth = month = m;
215 selDay = day = d; 215 selDay = day = d;
216 setupTable(); 216 setupTable();
217 } 217 }
218} 218}
219 219
220void DateBookMonthTable::redraw() 220void DateBookMonthTable::redraw()
221{ 221{
222 setupLabels(); 222 setupLabels();
223 setupTable(); 223 setupTable();
224} 224}
225 225
226void DateBookMonthTable::setWeekStart( bool onMonday ) 226void DateBookMonthTable::setWeekStart( bool onMonday )
227{ 227{
228 d->onMonday = onMonday; 228 d->onMonday = onMonday;
229 setupLabels(); 229 setupLabels();
230 setupTable(); 230 setupTable();
231} 231}
232 232
233void DateBookMonthTable::setupTable() 233void DateBookMonthTable::setupTable()
234{ 234{
235 QValueList<Calendar::Day> days = Calendar::daysOfMonth( year, month, d->onMonday ); 235 QValueList<Calendar::Day> days = Calendar::daysOfMonth( year, month, d->onMonday );
236 QValueList<Calendar::Day>::Iterator it = days.begin(); 236 QValueList<Calendar::Day>::Iterator it = days.begin();
237 int row = 0, col = 0; 237 int row = 0, col = 0;
238 int crow = 0; 238 int crow = 0;
239 int ccol = 0; 239 int ccol = 0;
240 for ( ; it != days.end(); ++it ) { 240 for ( ; it != days.end(); ++it ) {
241 DayItemMonth *i = (DayItemMonth *)item( row, col ); 241 DayItemMonth *i = (DayItemMonth *)item( row, col );
242 if ( !i ) { 242 if ( !i ) {
243 i = new DayItemMonth( this, QTableItem::Never, "" ); 243 i = new DayItemMonth( this, QTableItem::Never, "" );
244 setItem( row, col, i ); 244 setItem( row, col, i );
245 } 245 }
246 Calendar::Day calDay = *it; 246 Calendar::Day calDay = *it;
247 i->clearEffEvents(); 247 i->clearEffEvents();
248 i->setDay( calDay.date ); 248 i->setDay( calDay.date );
249 i->setType( calDay.type ); 249 i->setType( calDay.type );