summaryrefslogtreecommitdiffabout
path: root/korganizer/koagendaview.cpp
Unidiff
Diffstat (limited to 'korganizer/koagendaview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/koagendaview.cpp134
1 files changed, 72 insertions, 62 deletions
diff --git a/korganizer/koagendaview.cpp b/korganizer/koagendaview.cpp
index 2996acb..218396d 100644
--- a/korganizer/koagendaview.cpp
+++ b/korganizer/koagendaview.cpp
@@ -1,294 +1,304 @@
1/* 1/*
2 This file is part of KOrganizer. 2 This file is part of KOrganizer.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#include <qhbox.h> 24#include <qhbox.h>
25#include <qvbox.h> 25#include <qvbox.h>
26#include <qlabel.h> 26#include <qlabel.h>
27#include <qframe.h> 27#include <qframe.h>
28#include <qlayout.h> 28#include <qlayout.h>
29#ifndef KORG_NOSPLITTER 29#ifndef KORG_NOSPLITTER
30#include <qsplitter.h> 30#include <qsplitter.h>
31#endif 31#endif
32#include <qfont.h> 32#include <qfont.h>
33#include <qfontmetrics.h> 33#include <qfontmetrics.h>
34#include <qpopupmenu.h> 34#include <qpopupmenu.h>
35#include <qtooltip.h> 35#include <qtooltip.h>
36#include <qpainter.h> 36#include <qpainter.h>
37#include <qpushbutton.h> 37#include <qpushbutton.h>
38#include <qapplication.h> 38#include <qapplication.h>
39 39
40#include <kapplication.h> 40#include <kapplication.h>
41#include <KDGanttMinimizeSplitter.h> 41#include <KDGanttMinimizeSplitter.h>
42#include <kdebug.h> 42#include <kdebug.h>
43#include <kstandarddirs.h> 43#include <kstandarddirs.h>
44#include <kiconloader.h> 44#include <kiconloader.h>
45#include <klocale.h> 45#include <klocale.h>
46#include <kconfig.h> 46#include <kconfig.h>
47#include <kglobal.h> 47#include <kglobal.h>
48#include "calendarview.h" 48#include "calendarview.h"
49#include "koviewmanager.h" 49#include "koviewmanager.h"
50 50
51#include <libkcal/calendar.h> 51#include <libkcal/calendar.h>
52#include <libkcal/icaldrag.h> 52#include <libkcal/icaldrag.h>
53#include <libkcal/dndfactory.h> 53#include <libkcal/dndfactory.h>
54 54
55#include <kcalendarsystem.h> 55#include <kcalendarsystem.h>
56 56
57#include "koglobals.h" 57#include "koglobals.h"
58#ifndef KORG_NOPLUGINS 58#ifndef KORG_NOPLUGINS
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;
72extern int globalFlagBlockAgenda; 72extern int globalFlagBlockAgenda;
73extern int globalFlagBlockStartup; 73extern int globalFlagBlockStartup;
74extern int globalFlagBlockAgendaItemPaint; 74extern int globalFlagBlockAgendaItemPaint;
75extern int globalFlagBlockAgendaItemUpdate; 75extern int globalFlagBlockAgendaItemUpdate;
76extern int globalFlagBlockLabel; 76extern int globalFlagBlockLabel;
77using namespace KOrg; 77using namespace KOrg;
78 78
79 79
80 80
81TimeLabels::TimeLabels(int rows,QWidget *parent,const char *name,WFlags f) : 81TimeLabels::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 mRows = rows; 85 mRows = rows;
85 86
87 mRedrawNeeded = true;
86 setMinimumHeight( 20 ); 88 setMinimumHeight( 20 );
87 mCellHeight = KOPrefs::instance()->mHourSize*4; 89 mCellHeight = KOPrefs::instance()->mHourSize*4;
88 90
89 enableClipper(true); 91 enableClipper(true);
90 92
91 setHScrollBarMode(AlwaysOff); 93 setHScrollBarMode(AlwaysOff);
92 setVScrollBarMode(AlwaysOff); 94 setVScrollBarMode(AlwaysOff);
93 95
94 resizeContents(50,mRows * mCellHeight); 96 resizeContents(50,mRows * mCellHeight);
95 97
96 viewport()->setBackgroundMode( PaletteBackground ); 98 viewport()->setBackgroundMode( PaletteBackground );
97} 99}
98 100
99void TimeLabels::setCellHeight(int height) 101void TimeLabels::setCellHeight(int height)
100{ 102{
101 mCellHeight = height; 103 mCellHeight = height;
102} 104}
103 105
104/* 106/*
105 Optimization so that only the "dirty" portion of the scroll view 107 Optimization so that only the "dirty" portion of the scroll view
106 is redrawn. Unfortunately, this is not called by default paintEvent() method. 108 is redrawn. Unfortunately, this is not called by default paintEvent() method.
107*/ 109*/
108void TimeLabels::drawContents(QPainter *p,int cx, int cy, int cw, int ch) 110void TimeLabels::drawContents(QPainter *p,int cx, int cy, int cw, int ch)
109{ 111{
110 112
111 // if ( globalFlagBlockAgenda ) 113 // if ( globalFlagBlockAgenda )
112 // return; 114 // return;
113 // bug: the parameters cx, cy, cw, ch are the areas that need to be 115 // bug: the parameters cx, cy, cw, ch are the areas that need to be
114 // redrawn, not the area of the widget. unfortunately, this 116 // redrawn, not the area of the widget. unfortunately, this
115 // code assumes the latter... 117 // code assumes the latter...
116 118
117 // now, for a workaround... 119 // now, for a workaround...
118 // these two assignments fix the weird redraw bug 120 // these two assignments fix the weird redraw bug
119 cx = contentsX() + 2; 121 if ( mRedrawNeeded ) {
120 cw = contentsWidth() - 2; 122 cx = contentsX() + 2;
121 // end of workaround 123 cw = contentsWidth() - 2;
122 124 // end of workaround
123 int cell = ((int)(cy/mCellHeight)); 125
124 int y = cell * mCellHeight; 126 int cell = ((int)(cy/mCellHeight));
125 QFontMetrics fm = fontMetrics(); 127 int y = cell * mCellHeight;
126 QString hour; 128 QFontMetrics fm = fontMetrics();
127 QString suffix; 129 QString hour;
128 int tW = fm.width("24:00i"); 130 QString suffix;
129 int timeHeight = fm.height(); 131 int tW = fm.width("24:00i");
130 //timeHeight -= (timeHeight/4-2); 132 int timeHeight = fm.height();
131 int borderWidth = 0; 133 //timeHeight -= (timeHeight/4-2);
132 QFont nFont = p->font(); 134 int borderWidth = 0;
135 QFont nFont = p->font();
133 136
134 if (!KGlobal::locale()->use12Clock()) 137 if (!KGlobal::locale()->use12Clock())
135 suffix = "00"; 138 suffix = "00";
136 else 139 else
137 borderWidth = 0; 140 borderWidth = 0;
138 if ( timeHeight > mCellHeight ) { 141 if ( timeHeight > mCellHeight ) {
139 timeHeight = mCellHeight-1; 142 timeHeight = mCellHeight-1;
140 int pointS = nFont.pointSize(); 143 int pointS = nFont.pointSize();
141 while ( pointS > 4 ) { 144 while ( pointS > 4 ) {
142 nFont.setPointSize( pointS ); 145 nFont.setPointSize( pointS );
146 fm = QFontMetrics( nFont );
147 if ( fm.height() < mCellHeight )
148 break;
149 -- pointS;
150 }
143 fm = QFontMetrics( nFont ); 151 fm = QFontMetrics( nFont );
144 if ( fm.height() < mCellHeight ) 152 borderWidth = 4;
145 break; 153 timeHeight = fm.height();
146 -- pointS;
147 }
148 fm = QFontMetrics( nFont );
149 borderWidth = 4;
150 timeHeight = fm.height();
151 }
152 timeHeight -= (timeHeight/4-2);
153 QFont sFont = nFont;
154 sFont.setPointSize( sFont.pointSize()/2+2 );
155 QFontMetrics fmS( sFont );
156 int sHei = fmS.height();
157 sHei -= (sHei/4-2);
158 int startW = this->width() - frameWidth();
159 while (y < cy + ch) {
160 p->drawLine(cx,y,cx+tW,y);
161 hour.setNum(cell);
162
163 // handle 24h and am/pm time formats
164 if (KGlobal::locale()->use12Clock()) {
165 if (cell > 11) suffix = "pm";
166 else
167 suffix = "am";
168 if (cell == 0) hour.setNum(12);
169 if (cell > 12) hour.setNum(cell - 12);
170 } 154 }
155 timeHeight -= (timeHeight/4-2);
156 QFont sFont = nFont;
157 sFont.setPointSize( sFont.pointSize()/2+2 );
158 QFontMetrics fmS( sFont );
159 int sHei = fmS.height();
160 sHei -= (sHei/4-2);
161 int startW = this->width() - frameWidth();
162 while (y < cy + ch) {
163 p->drawLine(cx,y,cx+tW,y);
164 hour.setNum(cell);
165
166 // handle 24h and am/pm time formats
167 if (KGlobal::locale()->use12Clock()) {
168 if (cell > 11) suffix = "pm";
169 else
170 suffix = "am";
171 if (cell == 0) hour.setNum(12);
172 if (cell > 12) hour.setNum(cell - 12);
173 }
171 174
172 // center and draw the time label 175 // center and draw the time label
173 int timeWidth = fm.width(hour+"i"); 176 int timeWidth = fm.width(hour+"i");
174 int tw2 = fm.width(suffix); 177 int tw2 = fm.width(suffix);
175 int offset = startW - timeWidth - tw2 ; 178 int offset = startW - timeWidth - tw2 ;
176 p->setFont( nFont ); 179 p->setFont( nFont );
177 p->drawText(cx - borderWidth + offset, y+ timeHeight, hour); 180 p->drawText(cx - borderWidth + offset, y+ timeHeight, hour);
178 p->setFont( sFont ); 181 p->setFont( sFont );
179 offset = startW - tw2-1; 182 offset = startW - tw2-1;
180 p->drawText(cx - borderWidth + offset, y+ sHei, suffix); 183 p->drawText(cx - borderWidth + offset, y+ sHei, suffix);
181 184
182 // increment indices 185 // increment indices
183 y += mCellHeight; 186 y += mCellHeight;
184 cell++; 187 cell++;
188 }
189 } else {
190 //qDebug("NO redraw ");
185 } 191 }
192 // double buffer not yet implemented
193 //bitBlt (this, 0, 0, &myPix, 0 ,0,width(), height() ,CopyROP);
194 //mRedrawNeeded = false;
186} 195}
187 196
188/** 197/**
189 Calculates the minimum width. 198 Calculates the minimum width.
190*/ 199*/
191int TimeLabels::minimumWidth() const 200int TimeLabels::minimumWidth() const
192{ 201{
193 return mMiniWidth; 202 return mMiniWidth;
194} 203}
195 204
196/** updates widget's internal state */ 205/** updates widget's internal state */
197void TimeLabels::updateConfig() 206void TimeLabels::updateConfig()
198{ 207{
208 mRedrawNeeded = true;
199 // set the font 209 // set the font
200 // config->setGroup("Fonts"); 210 // config->setGroup("Fonts");
201 // QFont font = config->readFontEntry("TimeBar Font"); 211 // QFont font = config->readFontEntry("TimeBar Font");
202 setFont(KOPrefs::instance()->mTimeBarFont); 212 setFont(KOPrefs::instance()->mTimeBarFont);
203 QString test = "88:88"; 213 QString test = "88:88";
204 if (KGlobal::locale()->use12Clock()) 214 if (KGlobal::locale()->use12Clock())
205 test += "i"; 215 test += "i";
206 mMiniWidth = fontMetrics().width(test) + frameWidth()*2 +1 ; 216 mMiniWidth = fontMetrics().width(test) + frameWidth()*2 +1 ;
207 // update geometry restrictions based on new settings 217 // update geometry restrictions based on new settings
208 setFixedWidth(minimumWidth()); 218 setFixedWidth(minimumWidth());
209 219
210 // update HourSize 220 // update HourSize
211 mCellHeight = KOPrefs::instance()->mHourSize*4; 221 mCellHeight = KOPrefs::instance()->mHourSize*4;
212 resizeContents(50,mRows * mCellHeight); 222 resizeContents(50,mRows * mCellHeight);
213} 223}
214 224
215/** update time label positions */ 225/** update time label positions */
216void TimeLabels::positionChanged() 226void TimeLabels::positionChanged()
217{ 227{
218 int adjustment = mAgenda->contentsY(); 228 int adjustment = mAgenda->contentsY();
219 setContentsPos(0, adjustment); 229 setContentsPos(0, adjustment);
220} 230}
221 231
222/** */ 232/** */
223void TimeLabels::setAgenda(KOAgenda* agenda) 233void TimeLabels::setAgenda(KOAgenda* agenda)
224{ 234{
225 mAgenda = agenda; 235 mAgenda = agenda;
226} 236}
227 237
228void TimeLabels::contentsMousePressEvent ( QMouseEvent * e) 238void TimeLabels::contentsMousePressEvent ( QMouseEvent * e)
229{ 239{
230 mMouseDownY = e->pos().y(); 240 mMouseDownY = e->pos().y();
231 mOrgCap = topLevelWidget()->caption(); 241 mOrgCap = topLevelWidget()->caption();
232} 242}
233 243
234void TimeLabels::contentsMouseMoveEvent ( QMouseEvent * e ) 244void TimeLabels::contentsMouseMoveEvent ( QMouseEvent * e )
235{ 245{
236 int diff = mMouseDownY - e->pos().y(); 246 int diff = mMouseDownY - e->pos().y();
237 if ( diff < 10 && diff > -10 ) 247 if ( diff < 10 && diff > -10 )
238 return; 248 return;
239 int tSize = KOPrefs::instance()->mHourSize + (diff/10) ; 249 int tSize = KOPrefs::instance()->mHourSize + (diff/10) ;
240 if ( tSize < 4 ) 250 if ( tSize < 4 )
241 tSize = 4; 251 tSize = 4;
242 if ( tSize > 22 ) 252 if ( tSize > 22 )
243 tSize = 22; 253 tSize = 22;
244 tSize = (tSize-2)/2; 254 tSize = (tSize-2)/2;
245 topLevelWidget()->setCaption(i18n("New Agendasize: %1").arg(tSize)); 255 topLevelWidget()->setCaption(i18n("New Agendasize: %1").arg(tSize));
246 256
247} 257}
248void TimeLabels::contentsMouseReleaseEvent ( QMouseEvent * e ) 258void TimeLabels::contentsMouseReleaseEvent ( QMouseEvent * e )
249{ 259{
250 topLevelWidget()->setCaption( mOrgCap ); 260 topLevelWidget()->setCaption( mOrgCap );
251 int diff = mMouseDownY - e->pos().y(); 261 int diff = mMouseDownY - e->pos().y();
252 if ( diff < 10 && diff > -10 ) 262 if ( diff < 10 && diff > -10 )
253 return; 263 return;
254 int tSize = KOPrefs::instance()->mHourSize + (diff/10); 264 int tSize = KOPrefs::instance()->mHourSize + (diff/10);
255 if ( tSize < 4 ) 265 if ( tSize < 4 )
256 tSize = 4; 266 tSize = 4;
257 if ( tSize > 22 ) 267 if ( tSize > 22 )
258 tSize = 22; 268 tSize = 22;
259 tSize = (tSize/2)*2; 269 tSize = (tSize/2)*2;
260 if ( tSize == KOPrefs::instance()->mHourSize ) 270 if ( tSize == KOPrefs::instance()->mHourSize )
261 return; 271 return;
262 KOPrefs::instance()->mHourSize = tSize; 272 KOPrefs::instance()->mHourSize = tSize;
263 emit scaleChanged(); 273 emit scaleChanged();
264} 274}
265 275
266/** This is called in response to repaint() */ 276/** This is called in response to repaint() */
267void TimeLabels::paintEvent(QPaintEvent*) 277void TimeLabels::paintEvent(QPaintEvent*)
268{ 278{
269 279
270 // kdDebug() << "paintevent..." << endl; 280 // kdDebug() << "paintevent..." << endl;
271 // this is another hack! 281 // this is another hack!
272 // QPainter painter(this); 282 // QPainter painter(this);
273 //QString c 283 //QString c
274 repaintContents(contentsX(), contentsY(), visibleWidth(), visibleHeight()); 284 repaintContents(contentsX(), contentsY(), visibleWidth(), visibleHeight());
275} 285}
276 286
277//////////////////////////////////////////////////////////////////////////// 287////////////////////////////////////////////////////////////////////////////
278 288
279EventIndicator::EventIndicator(Location loc,QWidget *parent,const char *name) 289EventIndicator::EventIndicator(Location loc,QWidget *parent,const char *name)
280 : QFrame(parent,name) 290 : QFrame(parent,name)
281{ 291{
282 mColumns = 1; 292 mColumns = 1;
283 mTopBox = 0; 293 mTopBox = 0;
284 mLocation = loc; 294 mLocation = loc;
285 mTopLayout = 0; 295 mTopLayout = 0;
286 mPaintWidget = 0; 296 mPaintWidget = 0;
287 mXOffset = 0; 297 mXOffset = 0;
288 if (mLocation == Top) mPixmap = SmallIcon("1uparrow"); 298 if (mLocation == Top) mPixmap = SmallIcon("1uparrow");
289 else mPixmap = SmallIcon("1downarrow"); 299 else mPixmap = SmallIcon("1downarrow");
290 mEnabled.resize(mColumns); 300 mEnabled.resize(mColumns);
291 mEnabled.fill( false ); 301 mEnabled.fill( false );
292 setMinimumHeight(mPixmap.height()); 302 setMinimumHeight(mPixmap.height());
293} 303}
294 304