summaryrefslogtreecommitdiff
path: root/core/pim/datebook/datebookweekheaderimpl.cpp
authorkergoth <kergoth>2002-01-25 22:14:26 (UTC)
committer kergoth <kergoth>2002-01-25 22:14:26 (UTC)
commit15318cad33835e4e2dc620d033e43cd930676cdd (patch) (unidiff)
treec2fa0399a2c47fda8e2cd0092c73a809d17f68eb /core/pim/datebook/datebookweekheaderimpl.cpp
downloadopie-15318cad33835e4e2dc620d033e43cd930676cdd.zip
opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.gz
opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.bz2
Initial revision
Diffstat (limited to 'core/pim/datebook/datebookweekheaderimpl.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/datebook/datebookweekheaderimpl.cpp126
1 files changed, 126 insertions, 0 deletions
diff --git a/core/pim/datebook/datebookweekheaderimpl.cpp b/core/pim/datebook/datebookweekheaderimpl.cpp
new file mode 100644
index 0000000..e7c7208
--- a/dev/null
+++ b/core/pim/datebook/datebookweekheaderimpl.cpp
@@ -0,0 +1,126 @@
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 "datebookweekheaderimpl.h"
21#include <qlabel.h>
22#include <qspinbox.h>
23#include <qdatetime.h>
24
25/*
26 * Constructs a DateBookWeekHeader which is a child of 'parent', with the
27 * name 'name' and widget flags set to 'f'
28 */
29DateBookWeekHeader::DateBookWeekHeader( bool startOnMonday, QWidget* parent,
30 const char* name, WFlags fl )
31 : DateBookWeekHeaderBase( parent, name, fl ),
32 bStartOnMonday( startOnMonday )
33{
34 setBackgroundMode( PaletteButton );
35 labelDate->setBackgroundMode( PaletteButton );
36}
37
38/*
39 * Destroys the object and frees any allocated resources
40 */
41DateBookWeekHeader::~DateBookWeekHeader()
42{
43 // no need to delete child widgets, Qt does it all for us
44}
45
46/*
47 * public slot
48 */
49void DateBookWeekHeader::yearChanged( int y )
50{
51 setDate( y, week );
52}
53/*
54 * public slot
55 */
56void DateBookWeekHeader::nextWeek()
57{
58 if ( week < 52 )
59 week++;
60 setDate( year, week );
61}
62/*
63 * public slot
64 */
65void DateBookWeekHeader::prevWeek()
66{
67 if ( week > 1 )
68 week--;
69 setDate( year, week );
70}
71/*
72 * public slot
73 */
74void DateBookWeekHeader::weekChanged( int w )
75{
76 setDate( year, w );
77}
78
79void DateBookWeekHeader::setDate( int y, int w )
80{
81 year = y;
82 week = w;
83 spinYear->setValue( y );
84 spinWeek->setValue( w );
85
86 QDate d = dateFromWeek( week, year, bStartOnMonday );
87
88 QString s = QString::number( d.day() ) + ". " + d.monthName( d.month() )
89 + "-";
90 d = d.addDays( 6 );
91 s += QString::number( d.day() ) + ". " + d.monthName( d.month() );
92 labelDate->setText( s );
93
94 emit dateChanged( y, w );
95}
96
97void DateBookWeekHeader::setStartOfWeek( bool onMonday )
98{
99 bStartOnMonday = onMonday;
100 setDate( year, week );
101}
102
103// dateFromWeek
104// compute the date from the week in the year
105
106QDate dateFromWeek( int week, int year, bool startOnMonday )
107{
108 QDate d;
109 d.setYMD( year, 1, 1 );
110 int dayOfWeek = d.dayOfWeek();
111 if ( startOnMonday ) {
112 if ( dayOfWeek <= 4 ) {
113 d = d.addDays( ( week - 1 ) * 7 - dayOfWeek + 1 );
114 } else {
115 d = d.addDays( (week) * 7 - dayOfWeek + 1 );
116 }
117 } else {
118 if ( dayOfWeek <= 4 || dayOfWeek == 7) {
119 d = d.addDays( ( week - 1 ) * 7 - dayOfWeek % 7 );
120 } else {
121 d = d.addDays( ( week ) * 7 - dayOfWeek % 7 );
122 }
123 }
124 return d;
125}
126