Diffstat (limited to 'korganizer/kdatenavigator.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | korganizer/kdatenavigator.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/korganizer/kdatenavigator.cpp b/korganizer/kdatenavigator.cpp index b097dc1..92a0ac2 100644 --- a/korganizer/kdatenavigator.cpp +++ b/korganizer/kdatenavigator.cpp | |||
@@ -23,192 +23,232 @@ | |||
23 | 23 | ||
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | #include <qkeycode.h> | 25 | #include <qkeycode.h> |
26 | #include <qlayout.h> | 26 | #include <qlayout.h> |
27 | #include <qtimer.h> | 27 | #include <qtimer.h> |
28 | #include <qframe.h> | 28 | #include <qframe.h> |
29 | #include <qlabel.h> | 29 | #include <qlabel.h> |
30 | #include <qapplication.h> | 30 | #include <qapplication.h> |
31 | 31 | ||
32 | #include <kdebug.h> | 32 | #include <kdebug.h> |
33 | #include <klocale.h> | 33 | #include <klocale.h> |
34 | #include <kglobal.h> | 34 | #include <kglobal.h> |
35 | 35 | ||
36 | #include "koglobals.h" | 36 | #include "koglobals.h" |
37 | #include "koprefs.h" | 37 | #include "koprefs.h" |
38 | #ifndef KORG_NOPLUGINS | 38 | #ifndef KORG_NOPLUGINS |
39 | #include "kocore.h" | 39 | #include "kocore.h" |
40 | #endif | 40 | #endif |
41 | 41 | ||
42 | #include <kcalendarsystem.h> | 42 | #include <kcalendarsystem.h> |
43 | 43 | ||
44 | #include "navigatorbar.h" | 44 | #include "navigatorbar.h" |
45 | 45 | ||
46 | #include "kdatenavigator.h" | 46 | #include "kdatenavigator.h" |
47 | 47 | ||
48 | KDateNavigator::KDateNavigator( QWidget *parent, const char *name ) | 48 | KDateNavigator::KDateNavigator( QWidget *parent, const char *name ) |
49 | : QFrame(parent, name), | 49 | : QFrame(parent, name), |
50 | updateTimer(0L) | 50 | updateTimer(0L) |
51 | { | 51 | { |
52 | setFrameStyle(QFrame::NoFrame); | 52 | setFrameStyle(QFrame::NoFrame); |
53 | QDate startDate = QDate::currentDate(); | 53 | QDate startDate = QDate::currentDate(); |
54 | QGridLayout *topLayout = new QGridLayout(this,8,8); | 54 | QGridLayout *topLayout = new QGridLayout(this,8,8); |
55 | 55 | ||
56 | if (! startDate.isValid()) { | 56 | if (! startDate.isValid()) { |
57 | qDebug("KDateNavigator::invalid startdate "); | 57 | qDebug("KDateNavigator::invalid startdate "); |
58 | startDate = QDate::currentDate(); | 58 | startDate = QDate::currentDate(); |
59 | } | 59 | } |
60 | mMonthSignalOffset = 0; | 60 | mMonthSignalOffset = 0; |
61 | mSelectedDates.append(startDate); | 61 | mSelectedDates.append(startDate); |
62 | m_MthYr = startDate; | 62 | m_MthYr = startDate; |
63 | m_bShowWeekNums = true; | 63 | m_bShowWeekNums = true; |
64 | 64 | ||
65 | setFont( KOPrefs::instance()->mDateNavigatorFont ); | 65 | setFont( KOPrefs::instance()->mDateNavigatorFont ); |
66 | mNavigatorBar = new NavigatorBar( startDate, this ); | 66 | mNavigatorBar = new NavigatorBar( startDate, this ); |
67 | topLayout->addMultiCellWidget( mNavigatorBar, 0, 0, 0, 7 ); | 67 | topLayout->addMultiCellWidget( mNavigatorBar, 0, 0, 0, 7 ); |
68 | //mNavigatorBar->resize( 1,1); | 68 | //mNavigatorBar->resize( 1,1); |
69 | connect( mNavigatorBar, SIGNAL( goPrevYear() ), SIGNAL( goPrevYear() ) ); | 69 | connect( mNavigatorBar, SIGNAL( goPrevYear() ), SIGNAL( goPrevYear() ) ); |
70 | connect( mNavigatorBar, SIGNAL( goPrevMonth() ), SIGNAL( goPrevMonth() ) ); | 70 | connect( mNavigatorBar, SIGNAL( goPrevMonth() ), SIGNAL( goPrevMonth() ) ); |
71 | connect( mNavigatorBar, SIGNAL( goNextMonth() ), SIGNAL( goNextMonth() ) ); | 71 | connect( mNavigatorBar, SIGNAL( goNextMonth() ), SIGNAL( goNextMonth() ) ); |
72 | connect( mNavigatorBar, SIGNAL( goNextYear() ), SIGNAL( goNextYear() ) ); | 72 | connect( mNavigatorBar, SIGNAL( goNextYear() ), SIGNAL( goNextYear() ) ); |
73 | connect( mNavigatorBar, SIGNAL( monthSelected( int ) ), SLOT( slotMonthSelected( int ) ) ); | 73 | connect( mNavigatorBar, SIGNAL( monthSelected( int ) ), SLOT( slotMonthSelected( int ) ) ); |
74 | 74 | ||
75 | // get the day of the week on the first day | 75 | // get the day of the week on the first day |
76 | QDate dayone(m_MthYr.year(), m_MthYr.month(), 1); | 76 | QDate dayone(m_MthYr.year(), m_MthYr.month(), 1); |
77 | m_fstDayOfWk = dayone.dayOfWeek(); | 77 | m_fstDayOfWk = dayone.dayOfWeek(); |
78 | 78 | ||
79 | int i; | 79 | int i; |
80 | 80 | ||
81 | // Set up the heading fields. | 81 | // Set up the heading fields. |
82 | for( i = 0; i < 7; i++ ) { | 82 | for( i = 0; i < 7; i++ ) { |
83 | headings[i] = new QLabel("",this); | 83 | headings[i] = new QLabel("",this); |
84 | //headings[i]->setFont(QFont("Arial", 10, QFont::Bold)); | 84 | //headings[i]->setFont(QFont("Arial", 10, QFont::Bold)); |
85 | headings[i]->setAlignment(AlignCenter); | 85 | headings[i]->setAlignment(AlignCenter); |
86 | 86 | ||
87 | topLayout->addWidget(headings[i],1,i+1); | 87 | topLayout->addWidget(headings[i],1,i+1); |
88 | } | 88 | } |
89 | 89 | ||
90 | // Create the weeknumber labels | 90 | // Create the weeknumber labels |
91 | for( i = 0; i < 6; i++ ) { | 91 | for( i = 0; i < 6; i++ ) { |
92 | weeknos[i] = new QLabel(this); | 92 | weeknos[i] = new QLabel(this); |
93 | weeknos[i]->setAlignment(AlignCenter); | 93 | weeknos[i]->setAlignment(AlignCenter); |
94 | //weeknos[i]->setFont(QFont("Arial", 10)); | 94 | //weeknos[i]->setFont(QFont("Arial", 10)); |
95 | if(!m_bShowWeekNums) { | 95 | if(!m_bShowWeekNums) { |
96 | weeknos[i]->hide(); | 96 | weeknos[i]->hide(); |
97 | } | 97 | } |
98 | weeknos[i]->installEventFilter(this); | 98 | weeknos[i]->installEventFilter(this); |
99 | 99 | ||
100 | topLayout->addWidget(weeknos[i],i+2,0); | 100 | topLayout->addWidget(weeknos[i],i+2,0); |
101 | } | 101 | } |
102 | 102 | ||
103 | daymatrix = new KODayMatrix( this, "KDateNavigator::DayMatrix"); | 103 | daymatrix = new KODayMatrix( this, "KDateNavigator::DayMatrix"); |
104 | daymatrix->setFrameStyle(QFrame::Panel|QFrame::Sunken); | 104 | daymatrix->setFrameStyle(QFrame::Panel|QFrame::Sunken); |
105 | daymatrix->setLineWidth(1); | 105 | daymatrix->setLineWidth(1); |
106 | 106 | ||
107 | connect( daymatrix, SIGNAL( selected( const KCal::DateList & ) ), | 107 | connect( daymatrix, SIGNAL( selected( const KCal::DateList & ) ), |
108 | SIGNAL( datesSelected( const KCal::DateList & ) ) ); | 108 | SIGNAL( datesSelected( const KCal::DateList & ) ) ); |
109 | 109 | ||
110 | connect( daymatrix, SIGNAL( eventDropped( Event * ) ), | 110 | connect( daymatrix, SIGNAL( eventDropped( Event * ) ), |
111 | SIGNAL( eventDropped( Event * ) ) ); | 111 | SIGNAL( eventDropped( Event * ) ) ); |
112 | 112 | ||
113 | topLayout->addMultiCellWidget(daymatrix,2,7,1,7); | 113 | topLayout->addMultiCellWidget(daymatrix,2,7,1,7); |
114 | 114 | ||
115 | // read settings from configuration file. | 115 | // read settings from configuration file. |
116 | updateConfig(); | 116 | updateConfig(); |
117 | enableRollover(FollowMonth); | 117 | enableRollover(FollowMonth); |
118 | mySizeHint = sizeHint(); | 118 | mySizeHint = sizeHint(); |
119 | mFontChanged = false; | ||
120 | } | ||
121 | void KDateNavigator::changeFont ( QFont fo ) | ||
122 | { | ||
123 | setFont( fo ); | ||
124 | mNavigatorBar->resetFont( fo ); | ||
125 | } | ||
126 | QFont KDateNavigator::yourFontHint( QSize si , bool *b) | ||
127 | { | ||
128 | QFont fo = KOPrefs::instance()->mDateNavigatorFont; | ||
129 | *b = false; | ||
130 | int fontPoint = fo.pointSize(); | ||
131 | while ( fontPoint > 5 ) { | ||
132 | --fontPoint; | ||
133 | fo.setPointSize( fontPoint ); | ||
134 | setFont( fo ); | ||
135 | mFontChanged = true; | ||
136 | mNavigatorBar->resetFont( fo ); | ||
137 | QSize sh = sizeHint(); | ||
138 | //qDebug("fp %d %d %d %d %d", fontPoint, si.width() , sh.width() , si.height() , sh.height() ); | ||
139 | if ( si.width() > sh.width() && si.height() > sh.height()) { | ||
140 | *b = true; | ||
141 | //qDebug("fooooooooooooooooooooooouuuuund "); | ||
142 | break; | ||
143 | } | ||
144 | } | ||
145 | //qDebug("returnnnnnnnnnnnnnnnnnnn %d", fo.pointSize() ); | ||
146 | return fo; | ||
147 | } | ||
148 | QSize KDateNavigator::sizeHint() const | ||
149 | { | ||
150 | QFontMetrics fm ( font() ); | ||
151 | QSize day = daymatrix->sizeHint(); | ||
152 | QSize nav = mNavigatorBar->sizeHint(); | ||
153 | int wid = fm.width( "30") + day.width()+3; | ||
154 | int hei = fm.height() +day.height()+nav.height()+2; | ||
155 | if ( wid < nav.width() ) | ||
156 | wid = nav.width() ; | ||
157 | //qDebug("KDateNavigator+++++++++++++ %d %d", wid , hei); | ||
158 | return QSize ( wid, hei ); | ||
119 | } | 159 | } |
120 | void KDateNavigator::slotMonthSelected( int m ) | 160 | void KDateNavigator::slotMonthSelected( int m ) |
121 | { | 161 | { |
122 | if ( m_MthYr.month() <= mMonthSignalOffset) | 162 | if ( m_MthYr.month() <= mMonthSignalOffset) |
123 | m += 12; | 163 | m += 12; |
124 | int mo = m - mMonthSignalOffset; | 164 | int mo = m - mMonthSignalOffset; |
125 | emit monthSelected( m - mMonthSignalOffset ); | 165 | emit monthSelected( m - mMonthSignalOffset ); |
126 | 166 | ||
127 | } | 167 | } |
128 | void KDateNavigator::setCalendar( Calendar *cal ) | 168 | void KDateNavigator::setCalendar( Calendar *cal ) |
129 | { | 169 | { |
130 | daymatrix->setCalendar( cal ); | 170 | daymatrix->setCalendar( cal ); |
131 | } | 171 | } |
132 | 172 | ||
133 | void KDateNavigator::setBaseDate( const QDate &date , bool doRepaint ) // = true | 173 | void KDateNavigator::setBaseDate( const QDate &date , bool doRepaint ) // = true |
134 | { | 174 | { |
135 | m_MthYr = date; | 175 | m_MthYr = date; |
136 | 176 | ||
137 | updateDates(); | 177 | updateDates(); |
138 | updateView(); | 178 | updateView(); |
139 | 179 | ||
140 | KCal::DateList dates; | 180 | KCal::DateList dates; |
141 | dates.append( date ); | 181 | dates.append( date ); |
142 | mNavigatorBar->selectDates( dates ); | 182 | mNavigatorBar->selectDates( dates ); |
143 | 183 | ||
144 | daymatrix->clearSelection(); | 184 | daymatrix->clearSelection(); |
145 | if ( doRepaint ) | 185 | if ( doRepaint ) |
146 | daymatrix->repaint(); | 186 | daymatrix->repaint(); |
147 | } | 187 | } |
148 | 188 | ||
149 | void KDateNavigator::enableRollover(RolloverType r) | 189 | void KDateNavigator::enableRollover(RolloverType r) |
150 | { | 190 | { |
151 | switch(r) | 191 | switch(r) |
152 | { | 192 | { |
153 | case None : | 193 | case None : |
154 | if (updateTimer) | 194 | if (updateTimer) |
155 | { | 195 | { |
156 | updateTimer->stop(); | 196 | updateTimer->stop(); |
157 | delete updateTimer; | 197 | delete updateTimer; |
158 | updateTimer=0L; | 198 | updateTimer=0L; |
159 | } | 199 | } |
160 | break; | 200 | break; |
161 | case FollowDay : | 201 | case FollowDay : |
162 | case FollowMonth : | 202 | case FollowMonth : |
163 | if (!updateTimer) | 203 | if (!updateTimer) |
164 | { | 204 | { |
165 | updateTimer = new QTimer(this); | 205 | updateTimer = new QTimer(this); |
166 | QObject::connect(updateTimer,SIGNAL(timeout()), | 206 | QObject::connect(updateTimer,SIGNAL(timeout()), |
167 | this,SLOT(possiblyPastMidnight())); | 207 | this,SLOT(possiblyPastMidnight())); |
168 | } | 208 | } |
169 | updateTimer->start(0,true); | 209 | updateTimer->start(0,true); |
170 | lastDayChecked = QDate::currentDate(); | 210 | lastDayChecked = QDate::currentDate(); |
171 | } | 211 | } |
172 | updateRollover=r; | 212 | updateRollover=r; |
173 | } | 213 | } |
174 | 214 | ||
175 | 215 | ||
176 | KDateNavigator::~KDateNavigator() | 216 | KDateNavigator::~KDateNavigator() |
177 | { | 217 | { |
178 | } | 218 | } |
179 | 219 | ||
180 | 220 | ||
181 | void KDateNavigator::passedMidnight() | 221 | void KDateNavigator::passedMidnight() |
182 | { | 222 | { |
183 | QDate today = QDate::currentDate(); | 223 | QDate today = QDate::currentDate(); |
184 | bool emitMonth = false; | 224 | bool emitMonth = false; |
185 | 225 | ||
186 | if (today.month() != lastDayChecked.month()) | 226 | if (today.month() != lastDayChecked.month()) |
187 | { | 227 | { |
188 | if (updateRollover==FollowMonth && | 228 | if (updateRollover==FollowMonth && |
189 | daymatrix->isEndOfMonth()) { | 229 | daymatrix->isEndOfMonth()) { |
190 | goNextMonth(); | 230 | goNextMonth(); |
191 | emitMonth=true; | 231 | emitMonth=true; |
192 | } | 232 | } |
193 | } | 233 | } |
194 | daymatrix->recalculateToday(); | 234 | daymatrix->recalculateToday(); |
195 | daymatrix->repaint(); | 235 | daymatrix->repaint(); |
196 | emit dayPassed(today); | 236 | emit dayPassed(today); |
197 | if (emitMonth) { emit monthPassed(today); } | 237 | if (emitMonth) { emit monthPassed(today); } |
198 | } | 238 | } |
199 | 239 | ||
200 | /* slot */ void KDateNavigator::possiblyPastMidnight() | 240 | /* slot */ void KDateNavigator::possiblyPastMidnight() |
201 | { | 241 | { |
202 | if (lastDayChecked!=QDate::currentDate()) | 242 | if (lastDayChecked!=QDate::currentDate()) |
203 | { | 243 | { |
204 | passedMidnight(); | 244 | passedMidnight(); |
205 | lastDayChecked=QDate::currentDate(); | 245 | lastDayChecked=QDate::currentDate(); |
206 | } | 246 | } |
207 | // Set the timer to go off 1 second after midnight | 247 | // Set the timer to go off 1 second after midnight |
208 | // or after 8 minutes, whichever comes first. | 248 | // or after 8 minutes, whichever comes first. |
209 | if (updateTimer) | 249 | if (updateTimer) |
210 | { | 250 | { |
211 | QTime now = QTime::currentTime(); | 251 | QTime now = QTime::currentTime(); |
212 | QTime midnight = QTime(23,59,59); | 252 | QTime midnight = QTime(23,59,59); |
213 | int msecsWait = QMIN(480000,now.msecsTo(midnight)+2000); | 253 | int msecsWait = QMIN(480000,now.msecsTo(midnight)+2000); |
214 | 254 | ||