-rw-r--r-- | korganizer/koagendaview.cpp | 130 |
1 files changed, 26 insertions, 104 deletions
diff --git a/korganizer/koagendaview.cpp b/korganizer/koagendaview.cpp index 95388ef..880d399 100644 --- a/korganizer/koagendaview.cpp +++ b/korganizer/koagendaview.cpp | |||
@@ -59,298 +59,219 @@ | |||
59 | #include "kocore.h" | 59 | #include "kocore.h" |
60 | #endif | 60 | #endif |
61 | #include "koprefs.h" | 61 | #include "koprefs.h" |
62 | #include "koagenda.h" | 62 | #include "koagenda.h" |
63 | #include "koagendaitem.h" | 63 | #include "koagendaitem.h" |
64 | #ifndef KORG_NOPRINTER | 64 | #ifndef KORG_NOPRINTER |
65 | #include "calprinter.h" | 65 | #include "calprinter.h" |
66 | #endif | 66 | #endif |
67 | 67 | ||
68 | #include "koagendaview.h" | 68 | #include "koagendaview.h" |
69 | //#include "koagendaview.moc" | 69 | //#include "koagendaview.moc" |
70 | 70 | ||
71 | //extern bool globalFlagBlockPainting; | 71 | //extern bool globalFlagBlockPainting; |
72 | extern int globalFlagBlockAgenda; | 72 | extern int globalFlagBlockAgenda; |
73 | extern int globalFlagBlockStartup; | 73 | extern int globalFlagBlockStartup; |
74 | extern int globalFlagBlockAgendaItemPaint; | 74 | extern int globalFlagBlockAgendaItemPaint; |
75 | extern int globalFlagBlockAgendaItemUpdate; | 75 | extern int globalFlagBlockAgendaItemUpdate; |
76 | extern int globalFlagBlockLabel; | 76 | extern int globalFlagBlockLabel; |
77 | using namespace KOrg; | 77 | using namespace KOrg; |
78 | 78 | ||
79 | 79 | ||
80 | 80 | ||
81 | TimeLabels::TimeLabels(int rows,QWidget *parent,const char *name,WFlags f) : | 81 | TimeLabels::TimeLabels(int rows,QWidget *parent,const char *name,WFlags f) : |
82 | QScrollView(parent,name,f) | 82 | QScrollView(parent,name,f) |
83 | { | 83 | { |
84 | myPix.resize( 1, 1 ); | 84 | myPix.resize( 1, 1 ); |
85 | mRows = rows; | 85 | mRows = rows; |
86 | 86 | ||
87 | mRedrawNeeded = true; | 87 | mRedrawNeeded = true; |
88 | setMinimumHeight( 20 ); | 88 | setMinimumHeight( 20 ); |
89 | mCellHeight = KOPrefs::instance()->mHourSize*4; | 89 | mCellHeight = KOPrefs::instance()->mHourSize*4; |
90 | 90 | ||
91 | enableClipper(true); | 91 | enableClipper(true); |
92 | 92 | ||
93 | setHScrollBarMode(AlwaysOff); | 93 | setHScrollBarMode(AlwaysOff); |
94 | setVScrollBarMode(AlwaysOff); | 94 | setVScrollBarMode(AlwaysOff); |
95 | 95 | ||
96 | resizeContents(50,mRows * mCellHeight); | 96 | resizeContents(50,mRows * mCellHeight); |
97 | 97 | ||
98 | viewport()->setBackgroundMode( PaletteBackground ); | 98 | viewport()->setBackgroundMode( PaletteBackground ); |
99 | } | 99 | } |
100 | 100 | ||
101 | void TimeLabels::setCellHeight(int height) | 101 | void TimeLabels::setCellHeight(int height) |
102 | { | 102 | { |
103 | mCellHeight = height; | 103 | mCellHeight = height; |
104 | } | 104 | } |
105 | 105 | ||
106 | /* | 106 | /* |
107 | Optimization so that only the "dirty" portion of the scroll view | 107 | Optimization so that only the "dirty" portion of the scroll view |
108 | is redrawn. Unfortunately, this is not called by default paintEvent() method. | 108 | is redrawn. Unfortunately, this is not called by default paintEvent() method. |
109 | */ | 109 | */ |
110 | void TimeLabels::drawContents(QPainter *p,int cx, int cy, int cw, int ch) | 110 | void TimeLabels::drawContents(QPainter *p,int cx, int cy, int cw, int ch) |
111 | { | 111 | { |
112 | 112 | ||
113 | cx = contentsX() + frameWidth()*2; | 113 | cx = contentsX() + frameWidth()*2; |
114 | cw = contentsWidth() ; | 114 | cw = contentsWidth() ; |
115 | // end of workaround | 115 | // end of workaround |
116 | 116 | ||
117 | int cell = ((int)(cy/mCellHeight)); | 117 | int cell = ((int)(cy/mCellHeight)); |
118 | int y = cell * mCellHeight; | 118 | int y = cell * mCellHeight; |
119 | QFontMetrics fm = fontMetrics(); | 119 | QFontMetrics fm = fontMetrics(); |
120 | QString hour; | 120 | QString hour; |
121 | QString suffix = "am"; | 121 | QString suffix = "am"; |
122 | int timeHeight = fm.ascent(); | 122 | int timeHeight = fm.ascent(); |
123 | QFont nFont = p->font(); | 123 | QFont nFont = font(); |
124 | p->setFont( font()); | ||
124 | 125 | ||
125 | if (!KGlobal::locale()->use12Clock()) { | 126 | if (!KGlobal::locale()->use12Clock()) { |
126 | if ( QApplication::desktop()->width() <= 320 ) | ||
127 | suffix = "00"; | 127 | suffix = "00"; |
128 | else | 128 | } else |
129 | suffix = "00"; | 129 | if (cell > 11) suffix = "pm"; |
130 | } | ||
131 | 130 | ||
132 | if ( timeHeight > mCellHeight ) { | 131 | if ( timeHeight > mCellHeight ) { |
133 | timeHeight = mCellHeight-1; | 132 | timeHeight = mCellHeight-1; |
134 | int pointS = nFont.pointSize(); | 133 | int pointS = nFont.pointSize(); |
135 | while ( pointS > 4 ) { | 134 | while ( pointS > 4 ) { |
136 | nFont.setPointSize( pointS ); | 135 | nFont.setPointSize( pointS ); |
137 | fm = QFontMetrics( nFont ); | 136 | fm = QFontMetrics( nFont ); |
138 | if ( fm.ascent() < mCellHeight ) | 137 | if ( fm.ascent() < mCellHeight ) |
139 | break; | 138 | break; |
140 | -- pointS; | 139 | -- pointS; |
141 | } | 140 | } |
142 | fm = QFontMetrics( nFont ); | 141 | fm = QFontMetrics( nFont ); |
143 | timeHeight = fm.ascent(); | 142 | timeHeight = fm.ascent(); |
144 | } | 143 | } |
145 | //timeHeight -= (timeHeight/4-2); | 144 | //timeHeight -= (timeHeight/4-2); |
146 | QFont sFont = nFont; | 145 | QFont sFont = nFont; |
147 | sFont.setPointSize( sFont.pointSize()/2 ); | 146 | sFont.setPointSize( sFont.pointSize()/2 ); |
148 | QFontMetrics fmS( sFont ); | 147 | QFontMetrics fmS( sFont ); |
149 | int sHei = fmS.ascent() ; | 148 | int sHei = fmS.ascent() ; |
150 | //sHei -= (sHei/4-2); | 149 | //sHei -= (sHei/4-2); |
151 | int startW = this->width() - frameWidth()-2; | 150 | int startW = mMiniWidth - frameWidth()-2 ; |
152 | int tw2 = fmS.width(suffix); | 151 | int tw2 = fmS.width(suffix); |
153 | timeHeight = (timeHeight-1) /2 -1; | 152 | timeHeight = (timeHeight-1) /2 -1; |
153 | //testline | ||
154 | //p->drawLine(0,0,0,contentsHeight()); | ||
154 | while (y < cy + ch+mCellHeight) { | 155 | while (y < cy + ch+mCellHeight) { |
155 | p->drawLine(startW-tw2+1 ,y,cw,y); | 156 | p->drawLine(startW-tw2 ,y,cw+2,y); |
156 | hour.setNum(cell); | 157 | hour.setNum(cell); |
157 | // handle 24h and am/pm time formats | 158 | // handle 24h and am/pm time formats |
158 | if (KGlobal::locale()->use12Clock()) { | 159 | if (KGlobal::locale()->use12Clock()) { |
159 | if (cell > 11) suffix = "pm"; | 160 | if (cell == 12) suffix = "pm"; |
160 | else | ||
161 | suffix = "am"; | ||
162 | if (cell == 0) hour.setNum(12); | 161 | if (cell == 0) hour.setNum(12); |
163 | if (cell > 12) hour.setNum(cell - 12); | 162 | if (cell > 12) hour.setNum(cell - 12); |
164 | } | 163 | } |
165 | 164 | ||
166 | // center and draw the time label | 165 | // center and draw the time label |
167 | int timeWidth = fm.width(hour); | 166 | int timeWidth = fm.width(hour); |
168 | int offset = startW - timeWidth - tw2 ; | 167 | int offset = startW - timeWidth - tw2 -1 ; |
169 | p->setFont( nFont ); | 168 | p->setFont( nFont ); |
170 | p->drawText( offset, y+ timeHeight, hour); | 169 | p->drawText( offset, y+ timeHeight, hour); |
171 | p->setFont( sFont ); | 170 | p->setFont( sFont ); |
172 | offset = startW - tw2+1; | 171 | offset = startW - tw2; |
173 | p->drawText( offset, y -1, suffix); | 172 | p->drawText( offset, y -1, suffix); |
174 | 173 | ||
175 | // increment indices | 174 | // increment indices |
176 | y += mCellHeight; | 175 | y += mCellHeight; |
177 | cell++; | 176 | cell++; |
178 | } | 177 | } |
179 | 178 | ||
180 | 179 | ||
181 | 180 | ||
182 | 181 | ||
183 | #if 0 | ||
184 | mRedrawNeeded = true; | ||
185 | if ( mRedrawNeeded ) { | ||
186 | cx = contentsX() + frameWidth()*2; | ||
187 | cw = contentsWidth() ; | ||
188 | // end of workaround | ||
189 | |||
190 | int cell = ((int)(cy/mCellHeight)); | ||
191 | int y = cell * mCellHeight; | ||
192 | QFontMetrics fm = fontMetrics(); | ||
193 | QString hour; | ||
194 | QString suffix; | ||
195 | int timeHeight = fm.ascent(); | ||
196 | QFont nFont = p->font(); | ||
197 | |||
198 | if (!KGlobal::locale()->use12Clock()) { | ||
199 | if ( QApplication::desktop()->width() <= 320 ) | ||
200 | suffix = ""; | ||
201 | else | ||
202 | suffix = "00"; | ||
203 | } | ||
204 | |||
205 | if ( timeHeight > mCellHeight ) { | ||
206 | timeHeight = mCellHeight-1; | ||
207 | int pointS = nFont.pointSize(); | ||
208 | while ( pointS > 4 ) { | ||
209 | nFont.setPointSize( pointS ); | ||
210 | fm = QFontMetrics( nFont ); | ||
211 | if ( fm.ascent() < mCellHeight ) | ||
212 | break; | ||
213 | -- pointS; | ||
214 | } | ||
215 | fm = QFontMetrics( nFont ); | ||
216 | timeHeight = fm.ascent(); | ||
217 | } | ||
218 | //timeHeight -= (timeHeight/4-2); | ||
219 | QFont sFont = nFont; | ||
220 | sFont.setPointSize( sFont.pointSize()/2 ); | ||
221 | QFontMetrics fmS( sFont ); | ||
222 | int sHei = fmS.ascent() ; | ||
223 | //sHei -= (sHei/4-2); | ||
224 | int startW = this->width() - frameWidth()-2; | ||
225 | int tw2 = fmS.width(suffix); | ||
226 | while (y < cy + ch) { | ||
227 | p->drawLine(cx,y,cw,y); | ||
228 | hour.setNum(cell); | ||
229 | // handle 24h and am/pm time formats | ||
230 | if (KGlobal::locale()->use12Clock()) { | ||
231 | if (cell > 11) suffix = "pm"; | ||
232 | else | ||
233 | suffix = "am"; | ||
234 | if (cell == 0) hour.setNum(12); | ||
235 | if (cell > 12) hour.setNum(cell - 12); | ||
236 | tw2 = fmS.width(suffix); | ||
237 | } | ||
238 | |||
239 | // center and draw the time label | ||
240 | int timeWidth = fm.width(hour); | ||
241 | int offset = startW - timeWidth - tw2 ; | ||
242 | p->setFont( nFont ); | ||
243 | p->drawText( offset, y+ timeHeight, hour); | ||
244 | p->setFont( sFont ); | ||
245 | offset = startW - tw2+1; | ||
246 | p->drawText( offset, y+ sHei, suffix); | ||
247 | |||
248 | // increment indices | ||
249 | y += mCellHeight; | ||
250 | cell++; | ||
251 | } | ||
252 | } else { | ||
253 | //qDebug("NO redraw "); | ||
254 | } | ||
255 | // double buffer not yet implemented | ||
256 | //bitBlt (this, 0, 0, &myPix, 0 ,0,width(), height() ,CopyROP); | ||
257 | //mRedrawNeeded = false; | ||
258 | #endif | ||
259 | } | 182 | } |
260 | 183 | ||
261 | /** | 184 | /** |
262 | Calculates the minimum width. | 185 | Calculates the minimum width. |
263 | */ | 186 | */ |
264 | int TimeLabels::minimumWidth() const | 187 | int TimeLabels::minimumWidth() const |
265 | { | 188 | { |
266 | return mMiniWidth; | 189 | return mMiniWidth; |
267 | } | 190 | } |
268 | 191 | ||
269 | /** updates widget's internal state */ | 192 | /** updates widget's internal state */ |
270 | void TimeLabels::updateConfig() | 193 | void TimeLabels::updateConfig() |
271 | { | 194 | { |
272 | mRedrawNeeded = true; | 195 | mRedrawNeeded = true; |
273 | // set the font | 196 | // set the font |
274 | // config->setGroup("Fonts"); | 197 | // config->setGroup("Fonts"); |
275 | // QFont font = config->readFontEntry("TimeBar Font"); | 198 | // QFont font = config->readFontEntry("TimeBar Font"); |
276 | setFont(KOPrefs::instance()->mTimeBarFont); | 199 | setFont(KOPrefs::instance()->mTimeBarFont); |
277 | QString test = "20"; | 200 | QString test = "20"; |
278 | if (KGlobal::locale()->use12Clock()) | 201 | if (KGlobal::locale()->use12Clock()) |
279 | test = "12"; | 202 | test = "12"; |
280 | mMiniWidth = fontMetrics().width(test); | 203 | mMiniWidth = fontMetrics().width(test); |
281 | if (KGlobal::locale()->use12Clock()) | 204 | if (KGlobal::locale()->use12Clock()) |
282 | test = "pm"; | 205 | test = "pm"; |
283 | else { | 206 | else { |
284 | if ( QApplication::desktop()->width() <= 320 ) | 207 | test = "00"; |
285 | test = "00"; | ||
286 | else | ||
287 | test = "00"; | ||
288 | } | 208 | } |
289 | QFont sFont = font(); | 209 | QFont sFont = font(); |
290 | sFont.setPointSize( sFont.pointSize()/2 ); | 210 | sFont.setPointSize( sFont.pointSize()/2 ); |
291 | QFontMetrics fmS( sFont ); | 211 | QFontMetrics fmS( sFont ); |
292 | mMiniWidth += fmS.width( test ) + frameWidth()*2 +4 ; | 212 | mMiniWidth += fmS.width( test ) + frameWidth()*2+4 ; |
213 | qDebug("testwid %d %d", mMiniWidth ,fmS.width( test )); | ||
293 | // update geometry restrictions based on new settings | 214 | // update geometry restrictions based on new settings |
294 | setFixedWidth( mMiniWidth ); | 215 | setFixedWidth( mMiniWidth ); |
295 | 216 | ||
296 | // update HourSize | 217 | // update HourSize |
297 | mCellHeight = KOPrefs::instance()->mHourSize*4; | 218 | mCellHeight = KOPrefs::instance()->mHourSize*4; |
298 | resizeContents(50,mRows * mCellHeight); | 219 | resizeContents(50,mRows * mCellHeight); |
299 | } | 220 | } |
300 | 221 | ||
301 | /** update time label positions */ | 222 | /** update time label positions */ |
302 | void TimeLabels::positionChanged() | 223 | void TimeLabels::positionChanged() |
303 | { | 224 | { |
304 | int adjustment = mAgenda->contentsY(); | 225 | int adjustment = mAgenda->contentsY(); |
305 | setContentsPos(0, adjustment); | 226 | setContentsPos(0, adjustment); |
306 | } | 227 | } |
307 | 228 | ||
308 | /** */ | 229 | /** */ |
309 | void TimeLabels::setAgenda(KOAgenda* agenda) | 230 | void TimeLabels::setAgenda(KOAgenda* agenda) |
310 | { | 231 | { |
311 | mAgenda = agenda; | 232 | mAgenda = agenda; |
312 | } | 233 | } |
313 | 234 | ||
314 | void TimeLabels::contentsMousePressEvent ( QMouseEvent * e) | 235 | void TimeLabels::contentsMousePressEvent ( QMouseEvent * e) |
315 | { | 236 | { |
316 | mMouseDownY = e->pos().y(); | 237 | mMouseDownY = e->pos().y(); |
317 | mOrgCap = topLevelWidget()->caption(); | 238 | mOrgCap = topLevelWidget()->caption(); |
318 | } | 239 | } |
319 | 240 | ||
320 | void TimeLabels::contentsMouseMoveEvent ( QMouseEvent * e ) | 241 | void TimeLabels::contentsMouseMoveEvent ( QMouseEvent * e ) |
321 | { | 242 | { |
322 | int diff = mMouseDownY - e->pos().y(); | 243 | int diff = mMouseDownY - e->pos().y(); |
323 | if ( diff < 10 && diff > -10 ) | 244 | if ( diff < 10 && diff > -10 ) |
324 | return; | 245 | return; |
325 | int tSize = KOPrefs::instance()->mHourSize + (diff/10) ; | 246 | int tSize = KOPrefs::instance()->mHourSize + (diff/10) ; |
326 | if ( tSize < 4 ) | 247 | if ( tSize < 4 ) |
327 | tSize = 4; | 248 | tSize = 4; |
328 | if ( tSize > 22 ) | 249 | if ( tSize > 22 ) |
329 | tSize = 22; | 250 | tSize = 22; |
330 | tSize = (tSize-2)/2; | 251 | tSize = (tSize-2)/2; |
331 | topLevelWidget()->setCaption(i18n("New Agendasize: %1").arg(tSize)); | 252 | topLevelWidget()->setCaption(i18n("New Agendasize: %1").arg(tSize)); |
332 | 253 | ||
333 | } | 254 | } |
334 | void TimeLabels::contentsMouseReleaseEvent ( QMouseEvent * e ) | 255 | void TimeLabels::contentsMouseReleaseEvent ( QMouseEvent * e ) |
335 | { | 256 | { |
336 | topLevelWidget()->setCaption( mOrgCap ); | 257 | topLevelWidget()->setCaption( mOrgCap ); |
337 | int diff = mMouseDownY - e->pos().y(); | 258 | int diff = mMouseDownY - e->pos().y(); |
338 | if ( diff < 10 && diff > -10 ) | 259 | if ( diff < 10 && diff > -10 ) |
339 | return; | 260 | return; |
340 | int tSize = KOPrefs::instance()->mHourSize + (diff/10); | 261 | int tSize = KOPrefs::instance()->mHourSize + (diff/10); |
341 | if ( tSize < 4 ) | 262 | if ( tSize < 4 ) |
342 | tSize = 4; | 263 | tSize = 4; |
343 | if ( tSize > 22 ) | 264 | if ( tSize > 22 ) |
344 | tSize = 22; | 265 | tSize = 22; |
345 | tSize = (tSize/2)*2; | 266 | tSize = (tSize/2)*2; |
346 | if ( tSize == KOPrefs::instance()->mHourSize ) | 267 | if ( tSize == KOPrefs::instance()->mHourSize ) |
347 | return; | 268 | return; |
348 | KOPrefs::instance()->mHourSize = tSize; | 269 | KOPrefs::instance()->mHourSize = tSize; |
349 | emit scaleChanged(); | 270 | emit scaleChanged(); |
350 | } | 271 | } |
351 | 272 | ||
352 | /** This is called in response to repaint() */ | 273 | /** This is called in response to repaint() */ |
353 | void TimeLabels::paintEvent(QPaintEvent*) | 274 | void TimeLabels::paintEvent(QPaintEvent*) |
354 | { | 275 | { |
355 | 276 | ||
356 | // kdDebug() << "paintevent..." << endl; | 277 | // kdDebug() << "paintevent..." << endl; |
@@ -673,148 +594,152 @@ KOAgendaView::~KOAgendaView() | |||
673 | //delete mAllDayAgendaPopup; | 594 | //delete mAllDayAgendaPopup; |
674 | delete KOAgendaItem::paintPix(); | 595 | delete KOAgendaItem::paintPix(); |
675 | delete KOAgendaItem::paintPixSel(); | 596 | delete KOAgendaItem::paintPixSel(); |
676 | } | 597 | } |
677 | void KOAgendaView::resizeEvent( QResizeEvent* e ) | 598 | void KOAgendaView::resizeEvent( QResizeEvent* e ) |
678 | { | 599 | { |
679 | //qDebug("KOAgendaView::resizeEvent( QResizeEvent* e ) %d ", e->size().width()); | 600 | //qDebug("KOAgendaView::resizeEvent( QResizeEvent* e ) %d ", e->size().width()); |
680 | bool uc = false; | 601 | bool uc = false; |
681 | int ow = e->oldSize().width(); | 602 | int ow = e->oldSize().width(); |
682 | int oh = e->oldSize().height(); | 603 | int oh = e->oldSize().height(); |
683 | int w = e->size().width(); | 604 | int w = e->size().width(); |
684 | int h = e->size().height(); | 605 | int h = e->size().height(); |
685 | if ( (ow > oh && w< h ) || (ow < oh && w > h ) ) { | 606 | if ( (ow > oh && w< h ) || (ow < oh && w > h ) ) { |
686 | if ( ! mBlockUpdating && !globalFlagBlockStartup && !globalFlagBlockAgenda ) | 607 | if ( ! mBlockUpdating && !globalFlagBlockStartup && !globalFlagBlockAgenda ) |
687 | uc = true; | 608 | uc = true; |
688 | //qDebug("view changed %d %d %d %d ", ow, oh , w , h); | 609 | //qDebug("view changed %d %d %d %d ", ow, oh , w , h); |
689 | } | 610 | } |
690 | mUpcomingWidth = e->size().width() ; | 611 | mUpcomingWidth = e->size().width() ; |
691 | if ( mBlockUpdating || uc ) { | 612 | if ( mBlockUpdating || uc ) { |
692 | mBlockUpdating = false; | 613 | mBlockUpdating = false; |
693 | //mAgenda->setMinimumSize(800 , 600 ); | 614 | //mAgenda->setMinimumSize(800 , 600 ); |
694 | //qDebug("mAgenda->resize+++++++++++++++ "); | 615 | //qDebug("mAgenda->resize+++++++++++++++ "); |
695 | updateConfig(); | 616 | updateConfig(); |
696 | //qDebug("KOAgendaView::Updating now possible "); | 617 | //qDebug("KOAgendaView::Updating now possible "); |
697 | } else | 618 | } else |
698 | createDayLabels(); | 619 | createDayLabels(); |
699 | //qDebug("resizeEvent end "); | 620 | //qDebug("resizeEvent end "); |
700 | 621 | ||
701 | } | 622 | } |
702 | void KOAgendaView::slotDaylabelClicked( int num ) | 623 | void KOAgendaView::slotDaylabelClicked( int num ) |
703 | { | 624 | { |
704 | 625 | ||
705 | QDate firstDate = mSelectedDates.first(); | 626 | QDate firstDate = mSelectedDates.first(); |
706 | if ( num == -1 ) | 627 | if ( num == -1 ) |
707 | emit showDateView( 6, firstDate ); | 628 | emit showDateView( 6, firstDate ); |
708 | else if (num >= 0 ) { | 629 | else if (num >= 0 ) { |
709 | if ( mSelectedDates.count() == 1) | 630 | if ( mSelectedDates.count() == 1) |
710 | emit showDateView( 9, firstDate.addDays( num ) ); | 631 | emit showDateView( 9, firstDate.addDays( num ) ); |
711 | else | 632 | else |
712 | emit showDateView( 3, firstDate.addDays( num ) ); | 633 | emit showDateView( 3, firstDate.addDays( num ) ); |
713 | } | 634 | } |
714 | else | 635 | else |
715 | showDateView( 10, firstDate.addDays(1) ); | 636 | showDateView( 10, firstDate.addDays(1) ); |
716 | } | 637 | } |
717 | 638 | ||
718 | KOAgendaButton* KOAgendaView::getNewDaylabel() | 639 | KOAgendaButton* KOAgendaView::getNewDaylabel() |
719 | { | 640 | { |
720 | 641 | ||
721 | KOAgendaButton * dayLabel = new KOAgendaButton(mDayLabels); | 642 | KOAgendaButton * dayLabel = new KOAgendaButton(mDayLabels); |
722 | connect( dayLabel, SIGNAL( numClicked(int) ), this, SLOT ( slotDaylabelClicked(int) ) ); | 643 | connect( dayLabel, SIGNAL( numClicked(int) ), this, SLOT ( slotDaylabelClicked(int) ) ); |
723 | mDayLabelsList.append( dayLabel ); | 644 | mDayLabelsList.append( dayLabel ); |
724 | mLayoutDayLabels->addWidget(dayLabel); | 645 | mLayoutDayLabels->addWidget(dayLabel); |
725 | return dayLabel ; | 646 | return dayLabel ; |
726 | } | 647 | } |
727 | 648 | ||
728 | void KOAgendaView::createDayLabels() | 649 | void KOAgendaView::createDayLabels() |
729 | { | 650 | { |
730 | 651 | ||
731 | if ( mBlockUpdating || globalFlagBlockLabel == 1) { | 652 | if ( mBlockUpdating || globalFlagBlockLabel == 1) { |
732 | // qDebug(" KOAgendaView::createDayLabels() blocked "); | 653 | // qDebug(" KOAgendaView::createDayLabels() blocked "); |
733 | return; | 654 | return; |
734 | 655 | ||
735 | } | 656 | } |
736 | int newHight; | 657 | int newHight; |
658 | if ( !mSelectedDates.count()) | ||
659 | return; | ||
737 | 660 | ||
738 | // ### Before deleting and recreating we could check if mSelectedDates changed... | 661 | // ### Before deleting and recreating we could check if mSelectedDates changed... |
739 | // It would remove some flickering and gain speed (since this is called by | 662 | // It would remove some flickering and gain speed (since this is called by |
740 | // each updateView() call) | 663 | // each updateView() call) |
741 | 664 | ||
742 | int maxWid = mUpcomingWidth - mTimeLabels->width()- mAgenda->verticalScrollBar()->width() - mAgenda->frameWidth()*2; | 665 | int maxWid = mUpcomingWidth - mTimeLabels->width()- mAgenda->verticalScrollBar()->width() - mAgenda->frameWidth()*2; |
743 | if ( QApplication::desktop()->width() <= 320 ) | ||
744 | maxWid -= 10; | ||
745 | mDayLabelsFrame->setMaximumWidth( mUpcomingWidth ); | 666 | mDayLabelsFrame->setMaximumWidth( mUpcomingWidth ); |
746 | if ( maxWid < 0 ) | 667 | if ( maxWid < 20 ) |
747 | maxWid = 20; | 668 | maxWid = 20; |
748 | 669 | ||
749 | QFont dlf = KOPrefs::instance()->mTimeLabelsFont; | 670 | QFont dlf = KOPrefs::instance()->mTimeLabelsFont; |
750 | QFontMetrics fm ( dlf ); | 671 | QFontMetrics fm ( dlf ); |
751 | int selCount = mSelectedDates.count(); | 672 | int selCount = mSelectedDates.count(); |
673 | int widModulo = maxWid - (mAgenda->gridSpacingX() * selCount)+1; | ||
752 | QString dayTest = "Mon 20"; | 674 | QString dayTest = "Mon 20"; |
753 | //QString dayTest = "Mon 20"; | 675 | //QString dayTest = "Mon 20"; |
754 | int wid = fm.width( dayTest ); | 676 | int wid = fm.width( dayTest ); |
755 | //maxWid -= ( selCount * 3 ); //working for QLabels | 677 | //maxWid -= ( selCount * 3 ); //working for QLabels |
756 | maxWid -= ( selCount * 3 ); //working for QPushButton | 678 | if ( QApplication::desktop()->width() <= 320 ) |
679 | maxWid -= ( selCount * 3 ); //working for QPushButton | ||
680 | else | ||
681 | maxWid -= ( selCount * 3 ); //working for QPushButton | ||
757 | if ( maxWid < 0 ) | 682 | if ( maxWid < 0 ) |
758 | maxWid = 20; | 683 | maxWid = 20; |
759 | int needWid = wid * selCount; | 684 | int needWid = wid * selCount; |
760 | //qDebug("++++++++Needed : %d MaxWidth: %d", needWid, maxWid ); | 685 | //qDebug("++++++++Needed : %d MaxWidth: %d", needWid, maxWid ); |
761 | //if ( needWid > maxWid ) | 686 | //if ( needWid > maxWid ) |
762 | // qDebug("DAYLABELS TOOOOOOO BIG "); | 687 | // qDebug("DAYLABELS TOOOOOOO BIG "); |
763 | while ( needWid > maxWid ) { | 688 | while ( needWid > maxWid ) { |
764 | dayTest = dayTest.left( dayTest.length() - 1 ); | 689 | dayTest = dayTest.left( dayTest.length() - 1 ); |
765 | wid = fm.width( dayTest ); | 690 | wid = fm.width( dayTest ); |
766 | needWid = wid * selCount; | 691 | needWid = wid * selCount; |
767 | } | 692 | } |
768 | int maxLen = dayTest.length(); | 693 | int maxLen = dayTest.length(); |
769 | int fontPoint = dlf.pointSize(); | 694 | int fontPoint = dlf.pointSize(); |
770 | if ( maxLen < 2 ) { | 695 | if ( maxLen < 2 ) { |
771 | int fontPoint = dlf.pointSize(); | 696 | int fontPoint = dlf.pointSize(); |
772 | while ( fontPoint > 4 ) { | 697 | while ( fontPoint > 4 ) { |
773 | --fontPoint; | 698 | --fontPoint; |
774 | dlf.setPointSize( fontPoint ); | 699 | dlf.setPointSize( fontPoint ); |
775 | QFontMetrics f( dlf ); | 700 | QFontMetrics f( dlf ); |
776 | wid = f.width( "30" ); | 701 | wid = f.width( "30" ); |
777 | needWid = wid * selCount; | 702 | needWid = wid * selCount; |
778 | if ( needWid < maxWid ) | 703 | if ( needWid < maxWid ) |
779 | break; | 704 | break; |
780 | } | 705 | } |
781 | maxLen = 2; | 706 | maxLen = 2; |
782 | } | 707 | } |
783 | //qDebug("Max len %d ", dayTest.length() ); | 708 | //qDebug("Max len %d ", dayTest.length() ); |
784 | 709 | ||
785 | QFontMetrics tempF( dlf ); | 710 | QFontMetrics tempF( dlf ); |
786 | newHight = tempF.height(); | 711 | newHight = tempF.height(); |
787 | mDayLabels->setFont( dlf ); | 712 | mDayLabels->setFont( dlf ); |
788 | // mLayoutDayLabels = new QHBoxLayout(mDayLabels);; | 713 | // mLayoutDayLabels = new QHBoxLayout(mDayLabels);; |
789 | // mLayoutDayLabels->addSpacing(mTimeLabels->width()); | 714 | // mLayoutDayLabels->addSpacing(mTimeLabels->width()); |
790 | //mLayoutDayLabels->addSpacing( 2 ); | 715 | //mLayoutDayLabels->addSpacing( 2 ); |
791 | // QFont lFont = dlf; | 716 | // QFont lFont = dlf; |
792 | bool appendLabels = false; | 717 | bool appendLabels = false; |
793 | KOAgendaButton *dayLabel; | 718 | KOAgendaButton *dayLabel; |
794 | dayLabel = mDayLabelsList.first(); | 719 | dayLabel = mDayLabelsList.first(); |
795 | if ( !dayLabel ) { | 720 | if ( !dayLabel ) { |
796 | appendLabels = true; | 721 | appendLabels = true; |
797 | dayLabel = getNewDaylabel(); | 722 | dayLabel = getNewDaylabel(); |
798 | } | 723 | } |
799 | dayLabel->setFixedWidth( mTimeLabels->width()+mAgenda->frameWidth() ); | 724 | dayLabel->setFixedWidth( mTimeLabels->width()+mAgenda->frameWidth() ); |
800 | dayLabel->setFont( dlf ); | 725 | dayLabel->setFont( dlf ); |
801 | dayLabel->setNum( -1 ); | 726 | dayLabel->setNum( -1 ); |
802 | //dayLabel->setAlignment(QLabel::AlignHCenter); | 727 | //dayLabel->setAlignment(QLabel::AlignHCenter); |
803 | #if 0 | 728 | #if 0 |
804 | if ( QApplication::desktop()->width() <= 320 ) | 729 | if ( QApplication::desktop()->width() <= 320 ) |
805 | dayLabel->setText( KOGlobals::self()->calendarSystem()->monthName( mSelectedDates.first(), true ).left(2) ); | 730 | dayLabel->setText( KOGlobals::self()->calendarSystem()->monthName( mSelectedDates.first(), true ).left(2) ); |
806 | else | 731 | else |
807 | #endif | 732 | #endif |
808 | dayLabel->setText( KOGlobals::self()->calendarSystem()->monthName( mSelectedDates.first(), true ) ); | 733 | dayLabel->setText( KOGlobals::self()->calendarSystem()->monthName( mSelectedDates.first(), true ) ); |
809 | dayLabel->show(); | 734 | dayLabel->show(); |
810 | DateList::ConstIterator dit; | 735 | DateList::ConstIterator dit; |
811 | bool oneday = (mSelectedDates.first() == mSelectedDates.last() ); | 736 | bool oneday = (mSelectedDates.first() == mSelectedDates.last() ); |
812 | int counter = -1; | 737 | int counter = -1; |
813 | for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) { | 738 | for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) { |
814 | ++counter; | 739 | ++counter; |
815 | QDate date = *dit; | 740 | QDate date = *dit; |
816 | // QBoxLayout *dayLayout = new QVBoxLayout(mLayoutDayLabels); | 741 | // QBoxLayout *dayLayout = new QVBoxLayout(mLayoutDayLabels); |
817 | if ( ! appendLabels ) { | 742 | if ( ! appendLabels ) { |
818 | dayLabel = mDayLabelsList.next(); | 743 | dayLabel = mDayLabelsList.next(); |
819 | if ( !dayLabel ) | 744 | if ( !dayLabel ) |
820 | appendLabels = true; | 745 | appendLabels = true; |
@@ -851,139 +776,136 @@ void KOAgendaView::createDayLabels() | |||
851 | case 6: | 776 | case 6: |
852 | str = dayName.left( 3 ) + " " +QString::number( date.day()); | 777 | str = dayName.left( 3 ) + " " +QString::number( date.day()); |
853 | break; | 778 | break; |
854 | 779 | ||
855 | default: | 780 | default: |
856 | break; | 781 | break; |
857 | } | 782 | } |
858 | if ( oneday ) { | 783 | if ( oneday ) { |
859 | QString addString; | 784 | QString addString; |
860 | if ( mSelectedDates.first() == QDateTime::currentDateTime().date() ) | 785 | if ( mSelectedDates.first() == QDateTime::currentDateTime().date() ) |
861 | addString = i18n("Today"); | 786 | addString = i18n("Today"); |
862 | else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(1) ) | 787 | else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(1) ) |
863 | addString = i18n("Tomorrow"); | 788 | addString = i18n("Tomorrow"); |
864 | else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-1) ) | 789 | else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-1) ) |
865 | addString = i18n("Yesterday"); | 790 | addString = i18n("Yesterday"); |
866 | else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-2) ) | 791 | else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-2) ) |
867 | addString = i18n("Day before yesterday"); | 792 | addString = i18n("Day before yesterday"); |
868 | else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(2) ) | 793 | else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(2) ) |
869 | addString = i18n("Day after tomorrow"); | 794 | addString = i18n("Day after tomorrow"); |
870 | if ( !addString.isEmpty() ) { | 795 | if ( !addString.isEmpty() ) { |
871 | str = addString+", " + str; | 796 | str = addString+", " + str; |
872 | } else { | 797 | } else { |
873 | str = KGlobal::locale()->formatDate( date, KOPrefs::instance()->mShortDateInViewer); | 798 | str = KGlobal::locale()->formatDate( date, KOPrefs::instance()->mShortDateInViewer); |
874 | } | 799 | } |
875 | } | 800 | } |
876 | dayLabel->setText(str); | 801 | dayLabel->setText(str); |
877 | //dayLabel->setAlignment(QLabel::AlignHCenter); | 802 | //dayLabel->setAlignment(QLabel::AlignHCenter); |
878 | if (date == QDate::currentDate()) { | 803 | if (date == QDate::currentDate()) { |
879 | QFont bFont = dlf; | 804 | QFont bFont = dlf; |
880 | bFont.setBold( true ); | 805 | bFont.setBold( true ); |
881 | dayLabel->setFont(bFont); | 806 | dayLabel->setFont(bFont); |
882 | } | 807 | } |
883 | //dayLayout->addWidget(dayLabel); | 808 | //dayLayout->addWidget(dayLabel); |
884 | 809 | ||
885 | #ifndef KORG_NOPLUGINS | 810 | #ifndef KORG_NOPLUGINS |
886 | CalendarDecoration::List cds = KOCore::self()->calendarDecorations(); | 811 | CalendarDecoration::List cds = KOCore::self()->calendarDecorations(); |
887 | CalendarDecoration *it; | 812 | CalendarDecoration *it; |
888 | for(it = cds.first(); it; it = cds.next()) { | 813 | for(it = cds.first(); it; it = cds.next()) { |
889 | QString text = it->shortText( date ); | 814 | QString text = it->shortText( date ); |
890 | if ( !text.isEmpty() ) { | 815 | if ( !text.isEmpty() ) { |
891 | QLabel *label = new QLabel(text,mDayLabels); | 816 | QLabel *label = new QLabel(text,mDayLabels); |
892 | label->setAlignment(AlignCenter); | 817 | label->setAlignment(AlignCenter); |
893 | dayLayout->addWidget(label); | 818 | dayLayout->addWidget(label); |
894 | } | 819 | } |
895 | } | 820 | } |
896 | 821 | ||
897 | for(it = cds.first(); it; it = cds.next()) { | 822 | for(it = cds.first(); it; it = cds.next()) { |
898 | QWidget *wid = it->smallWidget(mDayLabels,date); | 823 | QWidget *wid = it->smallWidget(mDayLabels,date); |
899 | if ( wid ) { | 824 | if ( wid ) { |
900 | // wid->setHeight(20); | 825 | // wid->setHeight(20); |
901 | dayLayout->addWidget(wid); | 826 | dayLayout->addWidget(wid); |
902 | } | 827 | } |
903 | } | 828 | } |
904 | #endif | 829 | #endif |
905 | } | 830 | } |
906 | if ( ! appendLabels ) { | 831 | if ( ! appendLabels ) { |
907 | dayLabel = mDayLabelsList.next(); | 832 | dayLabel = mDayLabelsList.next(); |
908 | if ( !dayLabel ) | 833 | if ( !dayLabel ) |
909 | appendLabels = true; | 834 | appendLabels = true; |
910 | } | 835 | } |
911 | if ( appendLabels ) { | 836 | if ( appendLabels ) { |
912 | dayLabel = getNewDaylabel(); | 837 | dayLabel = getNewDaylabel(); |
913 | } | 838 | } |
914 | //dayLabel->hide();//test only | 839 | //dayLabel->hide();//test only |
915 | int offset = (mAgenda->width() - mAgenda->verticalScrollBar()->width()- (mAgenda->frameWidth()*2) ) % mSelectedDates.count() ; | 840 | |
916 | if ( offset < 0 ) offset = 0; | 841 | dayLabel->setText(">"); |
917 | //qDebug("mLayoutDayLabels->addSpacing %d ", mAgenda->verticalScrollBar()->width()+offset+2 ); | ||
918 | dayLabel->setText(">");//QString::number ( mSelectedDates.first().month() ) ); | ||
919 | dayLabel->setFont( dlf ); | 842 | dayLabel->setFont( dlf ); |
920 | dayLabel->setAutoRepeat( true ); | 843 | dayLabel->setAutoRepeat( true ); |
921 | dayLabel->show(); | 844 | dayLabel->show(); |
922 | dayLabel->setNum( -2 ); | 845 | dayLabel->setNum( -2 ); |
923 | dayLabel->setFixedWidth( mAgenda->verticalScrollBar()->width()+ offset ); | 846 | dayLabel->setFixedWidth( mAgenda->verticalScrollBar()->width()+ widModulo ); |
924 | 847 | ||
925 | //qDebug("setToFixed %d ", mAgenda->verticalScrollBar()->width()+ offset+2); | ||
926 | //mLayoutDayLabels->addSpacing(mAgenda->verticalScrollBar()->width()+ offset+2); | 848 | //mLayoutDayLabels->addSpacing(mAgenda->verticalScrollBar()->width()+ offset+2); |
927 | if ( !appendLabels ) { | 849 | if ( !appendLabels ) { |
928 | dayLabel = mDayLabelsList.next(); | 850 | dayLabel = mDayLabelsList.next(); |
929 | while ( dayLabel ) { | 851 | while ( dayLabel ) { |
930 | //qDebug("!dayLabel %d",dayLabel ); | 852 | //qDebug("!dayLabel %d",dayLabel ); |
931 | dayLabel->hide(); | 853 | dayLabel->hide(); |
932 | dayLabel = mDayLabelsList.next(); | 854 | dayLabel = mDayLabelsList.next(); |
933 | } | 855 | } |
934 | } | 856 | } |
935 | 857 | ||
936 | mDayLabelsFrame->setFixedHeight( newHight + 4 ); | 858 | mDayLabelsFrame->setFixedHeight( newHight + 4 ); |
937 | } | 859 | } |
938 | 860 | ||
939 | int KOAgendaView::maxDatesHint() | 861 | int KOAgendaView::maxDatesHint() |
940 | { | 862 | { |
941 | // Not sure about the max number of events, so return 0 for now. | 863 | // Not sure about the max number of events, so return 0 for now. |
942 | return 0; | 864 | return 0; |
943 | } | 865 | } |
944 | 866 | ||
945 | int KOAgendaView::currentDateCount() | 867 | int KOAgendaView::currentDateCount() |
946 | { | 868 | { |
947 | return mSelectedDates.count(); | 869 | return mSelectedDates.count(); |
948 | } | 870 | } |
949 | 871 | ||
950 | QPtrList<Incidence> KOAgendaView::selectedIncidences() | 872 | QPtrList<Incidence> KOAgendaView::selectedIncidences() |
951 | { | 873 | { |
952 | QPtrList<Incidence> selected; | 874 | QPtrList<Incidence> selected; |
953 | Incidence *incidence; | 875 | Incidence *incidence; |
954 | 876 | ||
955 | incidence = mAgenda->selectedIncidence(); | 877 | incidence = mAgenda->selectedIncidence(); |
956 | if (incidence) selected.append(incidence); | 878 | if (incidence) selected.append(incidence); |
957 | 879 | ||
958 | incidence = mAllDayAgenda->selectedIncidence(); | 880 | incidence = mAllDayAgenda->selectedIncidence(); |
959 | if (incidence) selected.append(incidence); | 881 | if (incidence) selected.append(incidence); |
960 | 882 | ||
961 | return selected; | 883 | return selected; |
962 | } | 884 | } |
963 | 885 | ||
964 | DateList KOAgendaView::selectedDates() | 886 | DateList KOAgendaView::selectedDates() |
965 | { | 887 | { |
966 | DateList selected; | 888 | DateList selected; |
967 | QDate qd; | 889 | QDate qd; |
968 | 890 | ||
969 | qd = mAgenda->selectedIncidenceDate(); | 891 | qd = mAgenda->selectedIncidenceDate(); |
970 | if (qd.isValid()) selected.append(qd); | 892 | if (qd.isValid()) selected.append(qd); |
971 | 893 | ||
972 | qd = mAllDayAgenda->selectedIncidenceDate(); | 894 | qd = mAllDayAgenda->selectedIncidenceDate(); |
973 | if (qd.isValid()) selected.append(qd); | 895 | if (qd.isValid()) selected.append(qd); |
974 | 896 | ||
975 | return selected; | 897 | return selected; |
976 | } | 898 | } |
977 | 899 | ||
978 | 900 | ||
979 | void KOAgendaView::updateView() | 901 | void KOAgendaView::updateView() |
980 | { | 902 | { |
981 | if ( mBlockUpdating ) | 903 | if ( mBlockUpdating ) |
982 | return; | 904 | return; |
983 | // kdDebug() << "KOAgendaView::updateView()" << endl; | 905 | // kdDebug() << "KOAgendaView::updateView()" << endl; |
984 | fillAgenda(); | 906 | fillAgenda(); |
985 | 907 | ||
986 | } | 908 | } |
987 | 909 | ||
988 | 910 | ||
989 | /* | 911 | /* |