summaryrefslogtreecommitdiff
path: root/core/pim/datebook/datebookdayheaderimpl.cpp
Unidiff
Diffstat (limited to 'core/pim/datebook/datebookdayheaderimpl.cpp') (more/less context) (show whitespace changes)
-rw-r--r--core/pim/datebook/datebookdayheaderimpl.cpp181
1 files changed, 181 insertions, 0 deletions
diff --git a/core/pim/datebook/datebookdayheaderimpl.cpp b/core/pim/datebook/datebookdayheaderimpl.cpp
new file mode 100644
index 0000000..fbcb3d2
--- a/dev/null
+++ b/core/pim/datebook/datebookdayheaderimpl.cpp
@@ -0,0 +1,181 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
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
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
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.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "datebookdayheaderimpl.h"
21
22#include <qpe/datebookmonth.h>
23#include <qpe/timestring.h>
24
25#include <qbuttongroup.h>
26#include <qpopupmenu.h>
27#include <qstringlist.h>
28#include <qtimer.h>
29#include <qtoolbutton.h>
30
31/*
32 * Constructs a DateBookDayHeader which is a child of 'parent', with the
33 * name 'name' and widget flags set to 'f'
34 *
35 * The dialog will by default be modeless, unless you set 'modal' to
36 * TRUE to construct a modal dialog.
37 */
38DateBookDayHeader::DateBookDayHeader( bool useMonday,
39 QWidget* parent, const char* name )
40 : DateBookDayHeaderBase( parent, name ),
41 bUseMonday( useMonday )
42{
43 connect(date,SIGNAL(pressed()),this,SLOT(pickDate()));
44
45 setupNames();
46
47 setBackgroundMode( PaletteButton );
48 grpDays->setBackgroundMode( PaletteButton );
49}
50
51/*
52 * Destroys the object and frees any allocated resources
53 */
54DateBookDayHeader::~DateBookDayHeader()
55{
56 // no need to delete child widgets, Qt does it all for us
57}
58
59void DateBookDayHeader::setStartOfWeek( bool onMonday )
60{
61 bUseMonday = onMonday;
62 setupNames();
63 setDate( currDate.year(), currDate.month(), currDate.day() );
64}
65
66void DateBookDayHeader::setupNames()
67{
68 if ( bUseMonday ) {
69 cmdDay1->setText( DateBookDayHeaderBase::tr("Monday").left(1) );
70 cmdDay2->setText( DateBookDayHeaderBase::tr("Tuesday").left(1) );
71 cmdDay3->setText( DateBookDayHeaderBase::tr("Wednesday").left(1) );
72 cmdDay4->setText( DateBookDayHeaderBase::tr("Thursday").left(1) );
73 cmdDay5->setText( DateBookDayHeaderBase::tr("Friday").left(1) );
74 cmdDay6->setText( DateBookDayHeaderBase::tr("Saturday").left(1) );
75 cmdDay7->setText( DateBookDayHeaderBase::tr("Sunday").left(1) );
76 } else {
77 cmdDay1->setText( DateBookDayHeaderBase::tr("Sunday").left(1) );
78 cmdDay2->setText( DateBookDayHeaderBase::tr("Monday").left(1) );
79 cmdDay3->setText( DateBookDayHeaderBase::tr("Tuesday").left(1) );
80 cmdDay4->setText( DateBookDayHeaderBase::tr("Wednesday").left(1) );
81 cmdDay5->setText( DateBookDayHeaderBase::tr("Thursday").left(1) );
82 cmdDay6->setText( DateBookDayHeaderBase::tr("Friday").left(1) );
83 cmdDay7->setText( DateBookDayHeaderBase::tr("Saturday").left(1) );
84 }
85}
86
87
88void DateBookDayHeader::pickDate()
89{
90 static QPopupMenu *m1 = 0;
91 static DateBookMonth *picker = 0;
92 if ( !m1 ) {
93 m1 = new QPopupMenu( this );
94 picker = new DateBookMonth( m1, 0, TRUE );
95 m1->insertItem( picker );
96 connect( picker, SIGNAL( dateClicked( int, int, int ) ),
97 this, SLOT( setDate( int, int, int ) ) );
98 connect( m1, SIGNAL( aboutToHide() ),
99 this, SLOT( gotHide() ) );
100 }
101 picker->setDate( currDate.year(), currDate.month(), currDate.day() );
102 m1->popup(mapToGlobal(date->pos()+QPoint(0,date->height())));
103 picker->setFocus();
104}
105
106void DateBookDayHeader::gotHide()
107{
108 // we have to redo the button...
109 date->setDown( false );
110}
111
112/*
113 * public slot
114 */
115void DateBookDayHeader::goBack()
116{
117 currDate = currDate.addDays( -1 );
118 setDate( currDate.year(), currDate.month(), currDate.day() );
119}
120/*
121 * public slot
122 */
123void DateBookDayHeader::goForward()
124{
125 currDate = currDate.addDays( 1 );
126 setDate( currDate.year(), currDate.month(), currDate.day() );
127}
128
129
130/*
131 * public slot
132 */
133void DateBookDayHeader::setDate( int y, int m, int d )
134{
135 currDate.setYMD( y, m, d );
136 date->setText( TimeString::shortDate( currDate ) );
137
138 int iDayOfWeek = currDate.dayOfWeek();
139 // cleverly adjust the day depending on how we start the week
140 if ( bUseMonday )
141 iDayOfWeek--;
142 else {
143 if ( iDayOfWeek == 7 ) // Sunday
144 iDayOfWeek = 0;
145 }
146 grpDays->setButton( iDayOfWeek );
147 emit dateChanged( y, m, d );
148}
149
150/*
151 * public slot
152 */
153void DateBookDayHeader::setDay( int day )
154{
155 int realDay;
156 int dayOfWeek = currDate.dayOfWeek();
157
158 // a little adjustment is needed...
159 if ( bUseMonday )
160 realDay = day + 1 ;
161 else if ( !bUseMonday && day == 0 ) // sunday
162 realDay = 7;
163 else
164 realDay = day;
165 // special cases first...
166 if ( realDay == 7 && !bUseMonday ) {
167 while ( currDate.dayOfWeek() != realDay )
168 currDate = currDate.addDays( -1 );
169 } else if ( !bUseMonday && dayOfWeek == 7 && dayOfWeek > realDay ) {
170 while ( currDate.dayOfWeek() != realDay )
171 currDate = currDate.addDays( 1 );
172 } else if ( dayOfWeek < realDay ) {
173 while ( currDate.dayOfWeek() < realDay )
174 currDate = currDate.addDays( 1 );
175 } else if ( dayOfWeek > realDay ) {
176 while ( currDate.dayOfWeek() > realDay )
177 currDate = currDate.addDays( -1 );
178 }
179 // update the date...
180 setDate( currDate.year(), currDate.month(), currDate.day() );
181}