Diffstat (limited to 'korganizer/datenavigatorcontainer.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | korganizer/datenavigatorcontainer.cpp | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/korganizer/datenavigatorcontainer.cpp b/korganizer/datenavigatorcontainer.cpp index ea510f1..53507d3 100644 --- a/korganizer/datenavigatorcontainer.cpp +++ b/korganizer/datenavigatorcontainer.cpp | |||
@@ -1,228 +1,230 @@ | |||
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 | //Added by qt3to4: | ||
38 | #include <QResizeEvent> | ||
37 | 39 | ||
38 | DateNavigatorContainer::DateNavigatorContainer( QWidget *parent, | 40 | DateNavigatorContainer::DateNavigatorContainer( QWidget *parent, |
39 | const char *name ) | 41 | const char *name ) |
40 | : QWidget( parent, name ), mCalendar( 0 ), | 42 | : QWidget( parent, name ), mCalendar( 0 ), |
41 | mHorizontalCount( 1 ), mVerticalCount( 1 ) | 43 | mHorizontalCount( 1 ), mVerticalCount( 1 ) |
42 | { | 44 | { |
43 | mResizeEnabled = false; | 45 | mResizeEnabled = false; |
44 | mExtraViews.setAutoDelete( true ); | 46 | mExtraViews.setAutoDelete( true ); |
45 | 47 | ||
46 | mNavigatorView = new KDateNavigator( this, name ); | 48 | mNavigatorView = new KDateNavigator( this, name ); |
47 | mNavigatorView->hide(); | 49 | mNavigatorView->hide(); |
48 | connectNavigatorView( mNavigatorView ); | 50 | connectNavigatorView( mNavigatorView ); |
49 | //setSizePolicy( QSizePolicy (QSizePolicy::Expanding,QSizePolicy::Expanding) ); | 51 | //setSizePolicy( QSizePolicy (QSizePolicy::Expanding,QSizePolicy::Expanding) ); |
50 | mLastDisplayedDN = 0; | 52 | mLastDisplayedDN = 0; |
51 | mUpdateTimer = new QTimer( this ); | 53 | mUpdateTimer = new QTimer( this ); |
52 | connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( checkUpdateDayMatrixDates() )); | 54 | connect (mUpdateTimer ,SIGNAL(timeout()), this, SLOT ( checkUpdateDayMatrixDates() )); |
53 | mFirstSelectedDate = QDate::currentDate(); | 55 | mFirstSelectedDate = QDate::currentDate(); |
54 | mSelectedDateCount = 1; | 56 | mSelectedDateCount = 1; |
55 | } | 57 | } |
56 | 58 | ||
57 | DateNavigatorContainer::~DateNavigatorContainer() | 59 | DateNavigatorContainer::~DateNavigatorContainer() |
58 | { | 60 | { |
59 | } | 61 | } |
60 | 62 | ||
61 | void DateNavigatorContainer::connectNavigatorView( KDateNavigator *v ) | 63 | void DateNavigatorContainer::connectNavigatorView( KDateNavigator *v ) |
62 | { | 64 | { |
63 | connect( v, SIGNAL( datesSelected( const KCal::DateList & ) ), | 65 | connect( v, SIGNAL( datesSelected( const KCal::DateList & ) ), |
64 | SIGNAL( datesSelected( const KCal::DateList & ) ) ); | 66 | SIGNAL( datesSelected( const KCal::DateList & ) ) ); |
65 | #if 0 | 67 | #if 0 |
66 | connect( v, SIGNAL( incidenceDropped( Incidence *, const QDate & ) ), | 68 | connect( v, SIGNAL( incidenceDropped( Incidence *, const QDate & ) ), |
67 | SIGNAL( incidenceDropped( Incidence *, const QDate & ) ) ); | 69 | SIGNAL( incidenceDropped( Incidence *, const QDate & ) ) ); |
68 | connect( v, SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ), | 70 | connect( v, SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ), |
69 | SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ) ); | 71 | SIGNAL( incidenceDroppedMove( Incidence *, const QDate & ) ) ); |
70 | #endif | 72 | #endif |
71 | connect( v, SIGNAL( weekClicked( const QDate & ) ), | 73 | connect( v, SIGNAL( weekClicked( const QDate & ) ), |
72 | SIGNAL( weekClicked( const QDate & ) ) ); | 74 | SIGNAL( weekClicked( const QDate & ) ) ); |
73 | connect( v, SIGNAL( showMonth( const QDate & ) ), | 75 | connect( v, SIGNAL( showMonth( const QDate & ) ), |
74 | SIGNAL( showMonth( const QDate & ) ) ); | 76 | SIGNAL( showMonth( const QDate & ) ) ); |
75 | 77 | ||
76 | connect( v, SIGNAL( goPrevious() ), SIGNAL( goPrevious() ) ); | 78 | connect( v, SIGNAL( goPrevious() ), SIGNAL( goPrevious() ) ); |
77 | connect( v, SIGNAL( goNext() ), SIGNAL( goNext() ) ); | 79 | connect( v, SIGNAL( goNext() ), SIGNAL( goNext() ) ); |
78 | 80 | ||
79 | connect( v, SIGNAL( goNextMonth() ), SLOT( slotgoNextMonth() ) ); | 81 | connect( v, SIGNAL( goNextMonth() ), SLOT( slotgoNextMonth() ) ); |
80 | connect( v, SIGNAL( goPrevMonth() ), SLOT( slotgoPrevMonth() ) ); | 82 | connect( v, SIGNAL( goPrevMonth() ), SLOT( slotgoPrevMonth() ) ); |
81 | connect( v, SIGNAL( goNextYear() ), SLOT( slotgoNextYear() ) ); | 83 | connect( v, SIGNAL( goNextYear() ), SLOT( slotgoNextYear() ) ); |
82 | connect( v, SIGNAL( goPrevYear() ), SLOT( slotgoPrevYear() ) ); | 84 | connect( v, SIGNAL( goPrevYear() ), SLOT( slotgoPrevYear() ) ); |
83 | 85 | ||
84 | connect( v, SIGNAL( monthSelected( int ) ), SLOT( slotMonthSelected( int ) ) ); | 86 | connect( v, SIGNAL( monthSelected( int ) ), SLOT( slotMonthSelected( int ) ) ); |
85 | } | 87 | } |
86 | void DateNavigatorContainer::slotgoNextYear() | 88 | void DateNavigatorContainer::slotgoNextYear() |
87 | { | 89 | { |
88 | jumpMonth( 12 ); | 90 | jumpMonth( 12 ); |
89 | emit goNextYear(); | 91 | emit goNextYear(); |
90 | 92 | ||
91 | } | 93 | } |
92 | void DateNavigatorContainer::slotgoPrevYear() | 94 | void DateNavigatorContainer::slotgoPrevYear() |
93 | { | 95 | { |
94 | jumpMonth( -12 ); | 96 | jumpMonth( -12 ); |
95 | emit goPrevYear(); | 97 | emit goPrevYear(); |
96 | 98 | ||
97 | } | 99 | } |
98 | void DateNavigatorContainer::slotgoPrevMonth() | 100 | void DateNavigatorContainer::slotgoPrevMonth() |
99 | { | 101 | { |
100 | jumpMonth( -1 ); | 102 | jumpMonth( -1 ); |
101 | emit goPrevMonth(); | 103 | emit goPrevMonth(); |
102 | 104 | ||
103 | } | 105 | } |
104 | void DateNavigatorContainer::slotgoNextMonth() | 106 | void DateNavigatorContainer::slotgoNextMonth() |
105 | { | 107 | { |
106 | jumpMonth( 1 ); | 108 | jumpMonth( 1 ); |
107 | emit goNextMonth(); | 109 | emit goNextMonth(); |
108 | } | 110 | } |
109 | void DateNavigatorContainer::jumpMonth( int month ) | 111 | void DateNavigatorContainer::jumpMonth( int month ) |
110 | { | 112 | { |
111 | 113 | ||
112 | QDate baseDate = mNavigatorView->baseDate(); | 114 | QDate baseDate = mNavigatorView->baseDate(); |
113 | computeMonthSelected( baseDate.month() + month, false ); | 115 | computeMonthSelected( baseDate.month() + month, false ); |
114 | } | 116 | } |
115 | void DateNavigatorContainer::slotMonthSelected( int month ) | 117 | void DateNavigatorContainer::slotMonthSelected( int month ) |
116 | { | 118 | { |
117 | computeMonthSelected( month, true ); | 119 | computeMonthSelected( month, true ); |
118 | } | 120 | } |
119 | void DateNavigatorContainer::computeMonthSelected( int month , bool forceEmit ) | 121 | void DateNavigatorContainer::computeMonthSelected( int month , bool forceEmit ) |
120 | { | 122 | { |
121 | //qDebug("slotMonthSelected %d ", month); | 123 | //qDebug("slotMonthSelected %d ", month); |
122 | QDate baseDate = mNavigatorView->baseDate(); | 124 | QDate baseDate = mNavigatorView->baseDate(); |
123 | if ( baseDate.month() == month ) | 125 | if ( baseDate.month() == month ) |
124 | return; | 126 | return; |
125 | //qDebug("month %d %d ",baseDate.month(),month); | 127 | //qDebug("month %d %d ",baseDate.month(),month); |
126 | QDate date = QDate ( baseDate.year(), baseDate.month() , 15 ); | 128 | QDate date = QDate ( baseDate.year(), baseDate.month() , 15 ); |
127 | date = date.addDays( -(baseDate.month()-month ) *30 ); | 129 | date = date.addDays( -(baseDate.month()-month ) *30 ); |
128 | QDate newBase = QDate ( date.year(), date.month() ,1 ); | 130 | QDate newBase = QDate ( date.year(), date.month() ,1 ); |
129 | 131 | ||
130 | //qDebug("NEW BASE %s", newBase.toString().latin1()); | 132 | //qDebug("NEW BASE %s", newBase.toString().latin1()); |
131 | mNavigatorView->setBaseDate( newBase ); | 133 | mNavigatorView->setBaseDate( newBase ); |
132 | QDate last = lastAvailableDate(); | 134 | QDate last = lastAvailableDate(); |
133 | QDate first = firstAvailableDate(); | 135 | QDate first = firstAvailableDate(); |
134 | QDate selFirst = mFirstSelectedDate; | 136 | QDate selFirst = mFirstSelectedDate; |
135 | QDate selLast = selFirst.addDays( mSelectedDateCount-1 ); | 137 | QDate selLast = selFirst.addDays( mSelectedDateCount-1 ); |
136 | if ( selFirst >= first && selLast <= last ) { | 138 | if ( selFirst >= first && selLast <= last ) { |
137 | setBaseDates(); | 139 | setBaseDates(); |
138 | if ( forceEmit ) | 140 | if ( forceEmit ) |
139 | updateDayMatrixDates(); | 141 | updateDayMatrixDates(); |
140 | } | 142 | } |
141 | else { | 143 | else { |
142 | setBaseDates(); | 144 | setBaseDates(); |
143 | if ( forceEmit ) | 145 | if ( forceEmit ) |
144 | updateDayMatrixDates(); | 146 | updateDayMatrixDates(); |
145 | if ( forceEmit ) | 147 | if ( forceEmit ) |
146 | emit monthSelected( month ); | 148 | emit monthSelected( month ); |
147 | } | 149 | } |
148 | } | 150 | } |
149 | void DateNavigatorContainer::setCalendar( Calendar *cal ) | 151 | void DateNavigatorContainer::setCalendar( Calendar *cal ) |
150 | { | 152 | { |
151 | mCalendar = cal; | 153 | mCalendar = cal; |
152 | mNavigatorView->setCalendar( cal ); | 154 | mNavigatorView->setCalendar( cal ); |
153 | for( int i = 0; i < mLastDisplayedDN; ++i ) { | 155 | for( int i = 0; i < mLastDisplayedDN; ++i ) { |
154 | KDateNavigator *n = mExtraViews.at( i ); | 156 | KDateNavigator *n = mExtraViews.at( i ); |
155 | n->setCalendar( cal ); | 157 | n->setCalendar( cal ); |
156 | } | 158 | } |
157 | } | 159 | } |
158 | void DateNavigatorContainer::checkUpdateDayMatrixDates() | 160 | void DateNavigatorContainer::checkUpdateDayMatrixDates() |
159 | { | 161 | { |
160 | //qDebug("KODNC: wid %d hei %d ", width(), height()); | 162 | //qDebug("KODNC: wid %d hei %d ", width(), height()); |
161 | mUpdateTimer->stop(); | 163 | mUpdateTimer->stop(); |
162 | //return; | 164 | //return; |
163 | if ( width() < 3 || height() < 3 ) | 165 | if ( width() < 3 || height() < 3 ) |
164 | return; | 166 | return; |
165 | static int lastWid = 0; | 167 | static int lastWid = 0; |
166 | static int lastHei = 0; | 168 | static int lastHei = 0; |
167 | if ( lastWid == width() && height() == lastHei ) { | 169 | if ( lastWid == width() && height() == lastHei ) { |
168 | qDebug("KODNC: No layout computing needed. "); | 170 | qDebug("KODNC: No layout computing needed. "); |
169 | } else { | 171 | } else { |
170 | lastWid = width(); | 172 | lastWid = width(); |
171 | lastHei = height(); | 173 | lastHei = height(); |
172 | 174 | ||
173 | QSize minSize = mNavigatorView->yourSizeHint(); | 175 | QSize minSize = mNavigatorView->yourSizeHint(); |
174 | 176 | ||
175 | int verticalCount = size().height() / minSize.height(); | 177 | int verticalCount = size().height() / minSize.height(); |
176 | int horizontalCount = size().width() / minSize.width(); | 178 | int horizontalCount = size().width() / minSize.width(); |
177 | //qDebug(" wattdatt %d new %d %d ", size().width() ,e->size().width() , minSize.width() ); | 179 | //qDebug(" wattdatt %d new %d %d ", size().width() ,e->size().width() , minSize.width() ); |
178 | //qDebug("COUNT %d %d %d %d ", verticalCount, horizontalCount , mVerticalCount, mHorizontalCount ); | 180 | //qDebug("COUNT %d %d %d %d ", verticalCount, horizontalCount , mVerticalCount, mHorizontalCount ); |
179 | bool fontchange = false; | 181 | bool fontchange = false; |
180 | if ( horizontalCount == 1) | 182 | if ( horizontalCount == 1) |
181 | horizontalCount = size().width() / mNavigatorView->yourFullSizeHint().width(); | 183 | horizontalCount = size().width() / mNavigatorView->yourFullSizeHint().width(); |
182 | QFont fo; | 184 | QFont fo; |
183 | if ( horizontalCount != mHorizontalCount || | 185 | if ( horizontalCount != mHorizontalCount || |
184 | verticalCount != mVerticalCount ) { | 186 | verticalCount != mVerticalCount ) { |
185 | uint count = horizontalCount * verticalCount; | 187 | uint count = horizontalCount * verticalCount; |
186 | if ( count == 0 ) { | 188 | if ( count == 0 ) { |
187 | bool ok; | 189 | bool ok; |
188 | fo = mNavigatorView->yourFontHint( size() , &ok ); | 190 | fo = mNavigatorView->yourFontHint( size() , &ok ); |
189 | //mNavigatorView->resize( size() ); | 191 | //mNavigatorView->resize( size() ); |
190 | //if ( ! ok ) | 192 | //if ( ! ok ) |
191 | // return; | 193 | // return; |
192 | horizontalCount = size().width() / mNavigatorView->sizeHintTwoButtons( ).width(); | 194 | horizontalCount = size().width() / mNavigatorView->sizeHintTwoButtons( ).width(); |
193 | if ( horizontalCount <= 1 ) | 195 | if ( horizontalCount <= 1 ) |
194 | minSize = mNavigatorView->sizeHintTwoButtons( 4 ); | 196 | minSize = mNavigatorView->sizeHintTwoButtons( 4 ); |
195 | else | 197 | else |
196 | minSize = mNavigatorView->sizeHintTwoButtons(); | 198 | minSize = mNavigatorView->sizeHintTwoButtons(); |
197 | verticalCount = size().height() / minSize.height(); | 199 | verticalCount = size().height() / minSize.height(); |
198 | horizontalCount = size().width() / minSize.width(); | 200 | horizontalCount = size().width() / minSize.width(); |
199 | if ( horizontalCount == 0 ) | 201 | if ( horizontalCount == 0 ) |
200 | horizontalCount = 1; | 202 | horizontalCount = 1; |
201 | if ( verticalCount == 0 ) | 203 | if ( verticalCount == 0 ) |
202 | verticalCount = 1; | 204 | verticalCount = 1; |
203 | fontchange = true; | 205 | fontchange = true; |
204 | count = horizontalCount * verticalCount; | 206 | count = horizontalCount * verticalCount; |
205 | } else { | 207 | } else { |
206 | if ( mNavigatorView->fontChanged() ) { | 208 | if ( mNavigatorView->fontChanged() ) { |
207 | fontchange = true; | 209 | fontchange = true; |
208 | fo = KOPrefs::instance()->mDateNavigatorFont; | 210 | fo = KOPrefs::instance()->mDateNavigatorFont; |
209 | mNavigatorView->changeFont( fo ); | 211 | mNavigatorView->changeFont( fo ); |
210 | mNavigatorView->unsetFontChanged(); | 212 | mNavigatorView->unsetFontChanged(); |
211 | } | 213 | } |
212 | } | 214 | } |
213 | mLastDisplayedDN = horizontalCount*verticalCount-1; | 215 | mLastDisplayedDN = horizontalCount*verticalCount-1; |
214 | while ( count > ( mExtraViews.count() + 1 ) ) { | 216 | while ( count > ( mExtraViews.count() + 1 ) ) { |
215 | KDateNavigator *n = new KDateNavigator( this ); | 217 | KDateNavigator *n = new KDateNavigator( this ); |
216 | n->setMonthSignalOffset ( mExtraViews.count()+1 ); | 218 | n->setMonthSignalOffset ( mExtraViews.count()+1 ); |
217 | mExtraViews.append( n ); | 219 | mExtraViews.append( n ); |
218 | n->setCalendar( mCalendar ); | 220 | n->setCalendar( mCalendar ); |
219 | connectNavigatorView( n ); | 221 | connectNavigatorView( n ); |
220 | // n->show(); | 222 | // n->show(); |
221 | } | 223 | } |
222 | 224 | ||
223 | setBaseDates(); | 225 | setBaseDates(); |
224 | if ( fontchange ) { | 226 | if ( fontchange ) { |
225 | //mNavigatorView->changeFont( fo ); | 227 | //mNavigatorView->changeFont( fo ); |
226 | uint i; | 228 | uint i; |
227 | for( i = 0; i < mExtraViews.count(); ++i ) { | 229 | for( i = 0; i < mExtraViews.count(); ++i ) { |
228 | KDateNavigator *view = mExtraViews.at( i ); | 230 | KDateNavigator *view = mExtraViews.at( i ); |