-rw-r--r-- | korganizer/koagendaview.cpp | 16 | ||||
-rw-r--r-- | microkde/KDGanttMinimizeSplitter.cpp | 7 |
2 files changed, 16 insertions, 7 deletions
diff --git a/korganizer/koagendaview.cpp b/korganizer/koagendaview.cpp index 99f547a..667ff2a 100644 --- a/korganizer/koagendaview.cpp +++ b/korganizer/koagendaview.cpp | |||
@@ -1,1614 +1,1622 @@ | |||
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; |
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 | // if ( globalFlagBlockAgenda ) | 113 | // if ( globalFlagBlockAgenda ) |
114 | // return; | 114 | // return; |
115 | // 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 |
116 | // redrawn, not the area of the widget. unfortunately, this | 116 | // redrawn, not the area of the widget. unfortunately, this |
117 | // code assumes the latter... | 117 | // code assumes the latter... |
118 | 118 | ||
119 | // now, for a workaround... | 119 | // now, for a workaround... |
120 | // these two assignments fix the weird redraw bug | 120 | // these two assignments fix the weird redraw bug |
121 | mRedrawNeeded = true; | 121 | mRedrawNeeded = true; |
122 | if ( mRedrawNeeded ) { | 122 | if ( mRedrawNeeded ) { |
123 | cx = contentsX() + frameWidth()*2; | 123 | cx = contentsX() + frameWidth()*2; |
124 | cw = contentsWidth() ; | 124 | cw = contentsWidth() ; |
125 | // end of workaround | 125 | // end of workaround |
126 | 126 | ||
127 | int cell = ((int)(cy/mCellHeight)); | 127 | int cell = ((int)(cy/mCellHeight)); |
128 | int y = cell * mCellHeight; | 128 | int y = cell * mCellHeight; |
129 | QFontMetrics fm = fontMetrics(); | 129 | QFontMetrics fm = fontMetrics(); |
130 | QString hour; | 130 | QString hour; |
131 | QString suffix; | 131 | QString suffix; |
132 | int timeHeight = fm.ascent(); | 132 | int timeHeight = fm.ascent(); |
133 | QFont nFont = p->font(); | 133 | QFont nFont = p->font(); |
134 | 134 | ||
135 | if (!KGlobal::locale()->use12Clock()) | 135 | if (!KGlobal::locale()->use12Clock()) |
136 | suffix = "00"; | 136 | suffix = "00"; |
137 | 137 | ||
138 | if ( timeHeight > mCellHeight ) { | 138 | if ( timeHeight > mCellHeight ) { |
139 | timeHeight = mCellHeight-1; | 139 | timeHeight = mCellHeight-1; |
140 | int pointS = nFont.pointSize(); | 140 | int pointS = nFont.pointSize(); |
141 | while ( pointS > 4 ) { | 141 | while ( pointS > 4 ) { |
142 | nFont.setPointSize( pointS ); | 142 | nFont.setPointSize( pointS ); |
143 | fm = QFontMetrics( nFont ); | 143 | fm = QFontMetrics( nFont ); |
144 | if ( fm.ascent() < mCellHeight ) | 144 | if ( fm.ascent() < mCellHeight ) |
145 | break; | 145 | break; |
146 | -- pointS; | 146 | -- pointS; |
147 | } | 147 | } |
148 | fm = QFontMetrics( nFont ); | 148 | fm = QFontMetrics( nFont ); |
149 | timeHeight = fm.ascent(); | 149 | timeHeight = fm.ascent(); |
150 | } | 150 | } |
151 | //timeHeight -= (timeHeight/4-2); | 151 | //timeHeight -= (timeHeight/4-2); |
152 | QFont sFont = nFont; | 152 | QFont sFont = nFont; |
153 | sFont.setPointSize( sFont.pointSize()/2 ); | 153 | sFont.setPointSize( sFont.pointSize()/2 ); |
154 | QFontMetrics fmS( sFont ); | 154 | QFontMetrics fmS( sFont ); |
155 | int sHei = fmS.ascent() ; | 155 | int sHei = fmS.ascent() ; |
156 | //sHei -= (sHei/4-2); | 156 | //sHei -= (sHei/4-2); |
157 | int startW = this->width() - 2*frameWidth()-1; | 157 | int startW = this->width() - frameWidth()-2; |
158 | int tw2 = fmS.width(suffix); | 158 | int tw2 = fmS.width(suffix); |
159 | while (y < cy + ch) { | 159 | while (y < cy + ch) { |
160 | p->drawLine(cx,y,cw,y); | 160 | p->drawLine(cx,y,cw,y); |
161 | hour.setNum(cell); | 161 | hour.setNum(cell); |
162 | 162 | ||
163 | // handle 24h and am/pm time formats | 163 | // handle 24h and am/pm time formats |
164 | if (KGlobal::locale()->use12Clock()) { | 164 | if (KGlobal::locale()->use12Clock()) { |
165 | if (cell > 11) suffix = "pm"; | 165 | if (cell > 11) suffix = "pm"; |
166 | else | 166 | else |
167 | suffix = "am"; | 167 | suffix = "am"; |
168 | if (cell == 0) hour.setNum(12); | 168 | if (cell == 0) hour.setNum(12); |
169 | if (cell > 12) hour.setNum(cell - 12); | 169 | if (cell > 12) hour.setNum(cell - 12); |
170 | tw2 = fmS.width(suffix); | 170 | tw2 = fmS.width(suffix); |
171 | } | 171 | } |
172 | 172 | ||
173 | // center and draw the time label | 173 | // center and draw the time label |
174 | int timeWidth = fm.width(hour); | 174 | int timeWidth = fm.width(hour); |
175 | int offset = startW - timeWidth - tw2 ; | 175 | int offset = startW - timeWidth - tw2 ; |
176 | p->setFont( nFont ); | 176 | p->setFont( nFont ); |
177 | p->drawText( offset, y+ timeHeight, hour); | 177 | p->drawText( offset, y+ timeHeight, hour); |
178 | p->setFont( sFont ); | 178 | p->setFont( sFont ); |
179 | offset = startW - tw2+1; | 179 | offset = startW - tw2+1; |
180 | p->drawText( offset, y+ sHei, suffix); | 180 | p->drawText( offset, y+ sHei, suffix); |
181 | 181 | ||
182 | // increment indices | 182 | // increment indices |
183 | y += mCellHeight; | 183 | y += mCellHeight; |
184 | cell++; | 184 | cell++; |
185 | } | 185 | } |
186 | } else { | 186 | } else { |
187 | //qDebug("NO redraw "); | 187 | //qDebug("NO redraw "); |
188 | } | 188 | } |
189 | // double buffer not yet implemented | 189 | // double buffer not yet implemented |
190 | //bitBlt (this, 0, 0, &myPix, 0 ,0,width(), height() ,CopyROP); | 190 | //bitBlt (this, 0, 0, &myPix, 0 ,0,width(), height() ,CopyROP); |
191 | //mRedrawNeeded = false; | 191 | //mRedrawNeeded = false; |
192 | } | 192 | } |
193 | 193 | ||
194 | /** | 194 | /** |
195 | Calculates the minimum width. | 195 | Calculates the minimum width. |
196 | */ | 196 | */ |
197 | int TimeLabels::minimumWidth() const | 197 | int TimeLabels::minimumWidth() const |
198 | { | 198 | { |
199 | return mMiniWidth; | 199 | return mMiniWidth; |
200 | } | 200 | } |
201 | 201 | ||
202 | /** updates widget's internal state */ | 202 | /** updates widget's internal state */ |
203 | void TimeLabels::updateConfig() | 203 | void TimeLabels::updateConfig() |
204 | { | 204 | { |
205 | mRedrawNeeded = true; | 205 | mRedrawNeeded = true; |
206 | // set the font | 206 | // set the font |
207 | // config->setGroup("Fonts"); | 207 | // config->setGroup("Fonts"); |
208 | // QFont font = config->readFontEntry("TimeBar Font"); | 208 | // QFont font = config->readFontEntry("TimeBar Font"); |
209 | setFont(KOPrefs::instance()->mTimeBarFont); | 209 | setFont(KOPrefs::instance()->mTimeBarFont); |
210 | QString test = "20oo"; | 210 | QString test = "20"; |
211 | if (KGlobal::locale()->use12Clock()) | 211 | if (KGlobal::locale()->use12Clock()) |
212 | test = "12mi"; | 212 | test = "12"; |
213 | mMiniWidth = fontMetrics().width(test) + frameWidth()*2 +1 ; | 213 | mMiniWidth = fontMetrics().width(test); |
214 | if (KGlobal::locale()->use12Clock()) | ||
215 | test = "pm"; | ||
216 | else | ||
217 | test = "00"; | ||
218 | QFont sFont = font(); | ||
219 | sFont.setPointSize( sFont.pointSize()/2 ); | ||
220 | QFontMetrics fmS( sFont ); | ||
221 | mMiniWidth += fmS.width( test ) + frameWidth()*2 +4 ; | ||
214 | // update geometry restrictions based on new settings | 222 | // update geometry restrictions based on new settings |
215 | setFixedWidth( mMiniWidth ); | 223 | setFixedWidth( mMiniWidth ); |
216 | 224 | ||
217 | // update HourSize | 225 | // update HourSize |
218 | mCellHeight = KOPrefs::instance()->mHourSize*4; | 226 | mCellHeight = KOPrefs::instance()->mHourSize*4; |
219 | resizeContents(50,mRows * mCellHeight); | 227 | resizeContents(50,mRows * mCellHeight); |
220 | } | 228 | } |
221 | 229 | ||
222 | /** update time label positions */ | 230 | /** update time label positions */ |
223 | void TimeLabels::positionChanged() | 231 | void TimeLabels::positionChanged() |
224 | { | 232 | { |
225 | int adjustment = mAgenda->contentsY(); | 233 | int adjustment = mAgenda->contentsY(); |
226 | setContentsPos(0, adjustment); | 234 | setContentsPos(0, adjustment); |
227 | } | 235 | } |
228 | 236 | ||
229 | /** */ | 237 | /** */ |
230 | void TimeLabels::setAgenda(KOAgenda* agenda) | 238 | void TimeLabels::setAgenda(KOAgenda* agenda) |
231 | { | 239 | { |
232 | mAgenda = agenda; | 240 | mAgenda = agenda; |
233 | } | 241 | } |
234 | 242 | ||
235 | void TimeLabels::contentsMousePressEvent ( QMouseEvent * e) | 243 | void TimeLabels::contentsMousePressEvent ( QMouseEvent * e) |
236 | { | 244 | { |
237 | mMouseDownY = e->pos().y(); | 245 | mMouseDownY = e->pos().y(); |
238 | mOrgCap = topLevelWidget()->caption(); | 246 | mOrgCap = topLevelWidget()->caption(); |
239 | } | 247 | } |
240 | 248 | ||
241 | void TimeLabels::contentsMouseMoveEvent ( QMouseEvent * e ) | 249 | void TimeLabels::contentsMouseMoveEvent ( QMouseEvent * e ) |
242 | { | 250 | { |
243 | int diff = mMouseDownY - e->pos().y(); | 251 | int diff = mMouseDownY - e->pos().y(); |
244 | if ( diff < 10 && diff > -10 ) | 252 | if ( diff < 10 && diff > -10 ) |
245 | return; | 253 | return; |
246 | int tSize = KOPrefs::instance()->mHourSize + (diff/10) ; | 254 | int tSize = KOPrefs::instance()->mHourSize + (diff/10) ; |
247 | if ( tSize < 4 ) | 255 | if ( tSize < 4 ) |
248 | tSize = 4; | 256 | tSize = 4; |
249 | if ( tSize > 22 ) | 257 | if ( tSize > 22 ) |
250 | tSize = 22; | 258 | tSize = 22; |
251 | tSize = (tSize-2)/2; | 259 | tSize = (tSize-2)/2; |
252 | topLevelWidget()->setCaption(i18n("New Agendasize: %1").arg(tSize)); | 260 | topLevelWidget()->setCaption(i18n("New Agendasize: %1").arg(tSize)); |
253 | 261 | ||
254 | } | 262 | } |
255 | void TimeLabels::contentsMouseReleaseEvent ( QMouseEvent * e ) | 263 | void TimeLabels::contentsMouseReleaseEvent ( QMouseEvent * e ) |
256 | { | 264 | { |
257 | topLevelWidget()->setCaption( mOrgCap ); | 265 | topLevelWidget()->setCaption( mOrgCap ); |
258 | int diff = mMouseDownY - e->pos().y(); | 266 | int diff = mMouseDownY - e->pos().y(); |
259 | if ( diff < 10 && diff > -10 ) | 267 | if ( diff < 10 && diff > -10 ) |
260 | return; | 268 | return; |
261 | int tSize = KOPrefs::instance()->mHourSize + (diff/10); | 269 | int tSize = KOPrefs::instance()->mHourSize + (diff/10); |
262 | if ( tSize < 4 ) | 270 | if ( tSize < 4 ) |
263 | tSize = 4; | 271 | tSize = 4; |
264 | if ( tSize > 22 ) | 272 | if ( tSize > 22 ) |
265 | tSize = 22; | 273 | tSize = 22; |
266 | tSize = (tSize/2)*2; | 274 | tSize = (tSize/2)*2; |
267 | if ( tSize == KOPrefs::instance()->mHourSize ) | 275 | if ( tSize == KOPrefs::instance()->mHourSize ) |
268 | return; | 276 | return; |
269 | KOPrefs::instance()->mHourSize = tSize; | 277 | KOPrefs::instance()->mHourSize = tSize; |
270 | emit scaleChanged(); | 278 | emit scaleChanged(); |
271 | } | 279 | } |
272 | 280 | ||
273 | /** This is called in response to repaint() */ | 281 | /** This is called in response to repaint() */ |
274 | void TimeLabels::paintEvent(QPaintEvent*) | 282 | void TimeLabels::paintEvent(QPaintEvent*) |
275 | { | 283 | { |
276 | 284 | ||
277 | // kdDebug() << "paintevent..." << endl; | 285 | // kdDebug() << "paintevent..." << endl; |
278 | // this is another hack! | 286 | // this is another hack! |
279 | // QPainter painter(this); | 287 | // QPainter painter(this); |
280 | //QString c | 288 | //QString c |
281 | repaintContents(contentsX(), contentsY(), visibleWidth(), visibleHeight()); | 289 | repaintContents(contentsX(), contentsY(), visibleWidth(), visibleHeight()); |
282 | } | 290 | } |
283 | 291 | ||
284 | //////////////////////////////////////////////////////////////////////////// | 292 | //////////////////////////////////////////////////////////////////////////// |
285 | 293 | ||
286 | EventIndicator::EventIndicator(Location loc,QWidget *parent,const char *name) | 294 | EventIndicator::EventIndicator(Location loc,QWidget *parent,const char *name) |
287 | : QFrame(parent,name) | 295 | : QFrame(parent,name) |
288 | { | 296 | { |
289 | mColumns = 1; | 297 | mColumns = 1; |
290 | mTopBox = 0; | 298 | mTopBox = 0; |
291 | mLocation = loc; | 299 | mLocation = loc; |
292 | mTopLayout = 0; | 300 | mTopLayout = 0; |
293 | mPaintWidget = 0; | 301 | mPaintWidget = 0; |
294 | mXOffset = 0; | 302 | mXOffset = 0; |
295 | if (mLocation == Top) mPixmap = SmallIcon("1uparrow"); | 303 | if (mLocation == Top) mPixmap = SmallIcon("1uparrow"); |
296 | else mPixmap = SmallIcon("1downarrow"); | 304 | else mPixmap = SmallIcon("1downarrow"); |
297 | mEnabled.resize(mColumns); | 305 | mEnabled.resize(mColumns); |
298 | mEnabled.fill( false ); | 306 | mEnabled.fill( false ); |
299 | setMinimumHeight(mPixmap.height()); | 307 | setMinimumHeight(mPixmap.height()); |
300 | } | 308 | } |
301 | 309 | ||
302 | EventIndicator::~EventIndicator() | 310 | EventIndicator::~EventIndicator() |
303 | { | 311 | { |
304 | } | 312 | } |
305 | 313 | ||
306 | void EventIndicator::drawContents(QPainter *p) | 314 | void EventIndicator::drawContents(QPainter *p) |
307 | { | 315 | { |
308 | 316 | ||
309 | // kdDebug() << "======== top: " << contentsRect().top() << " bottom " << // contentsRect().bottom() << " left " << contentsRect().left() << " right " << contentsRect().right() << endl; | 317 | // kdDebug() << "======== top: " << contentsRect().top() << " bottom " << // contentsRect().bottom() << " left " << contentsRect().left() << " right " << contentsRect().right() << endl; |
310 | KDGanttSplitterHandle* han = 0; | 318 | KDGanttSplitterHandle* han = 0; |
311 | if ( mPaintWidget ) | 319 | if ( mPaintWidget ) |
312 | han = mPaintWidget->firstHandle(); | 320 | han = mPaintWidget->firstHandle(); |
313 | if ( ! han ) { | 321 | if ( ! han ) { |
314 | int i; | 322 | int i; |
315 | for(i=0;i<mColumns;++i) { | 323 | for(i=0;i<mColumns;++i) { |
316 | if (mEnabled[i]) { | 324 | if (mEnabled[i]) { |
317 | int cellWidth = contentsRect().right()/mColumns; | 325 | int cellWidth = contentsRect().right()/mColumns; |
318 | int xOffset = KOGlobals::self()->reverseLayout() ? | 326 | int xOffset = KOGlobals::self()->reverseLayout() ? |
319 | (mColumns - 1 - i)*cellWidth + (cellWidth -mPixmap.width())/2 : | 327 | (mColumns - 1 - i)*cellWidth + (cellWidth -mPixmap.width())/2 : |
320 | i*cellWidth + (cellWidth -mPixmap.width()) /2; | 328 | i*cellWidth + (cellWidth -mPixmap.width()) /2; |
321 | p->drawPixmap(QPoint(1+xOffset,0),mPixmap); | 329 | p->drawPixmap(QPoint(1+xOffset,0),mPixmap); |
322 | } | 330 | } |
323 | } | 331 | } |
324 | } else { | 332 | } else { |
325 | han->repaint(); | 333 | han->repaint(); |
326 | //mPaintWidget->setBackgroundColor( red ); | 334 | //mPaintWidget->setBackgroundColor( red ); |
327 | 335 | ||
328 | QPainter pa( han ); | 336 | QPainter pa( han ); |
329 | int i; | 337 | int i; |
330 | bool setColor = false; | 338 | bool setColor = false; |
331 | for(i=0;i<mColumns;++i) { | 339 | for(i=0;i<mColumns;++i) { |
332 | if (mEnabled[i]) { | 340 | if (mEnabled[i]) { |
333 | setColor = true; | 341 | setColor = true; |
334 | 342 | ||
335 | int cellWidth = contentsRect().right()/mColumns; | 343 | int cellWidth = contentsRect().right()/mColumns; |
336 | int xOffset = KOGlobals::self()->reverseLayout() ? | 344 | int xOffset = KOGlobals::self()->reverseLayout() ? |
337 | (mColumns - 1 - i)*cellWidth + cellWidth/2 -mPixmap.width()/2 : | 345 | (mColumns - 1 - i)*cellWidth + cellWidth/2 -mPixmap.width()/2 : |
338 | i*cellWidth + cellWidth/2 -mPixmap.width()/2; | 346 | i*cellWidth + cellWidth/2 -mPixmap.width()/2; |
339 | pa.drawPixmap(QPoint(mXOffset + xOffset,0),mPixmap); | 347 | pa.drawPixmap(QPoint(mXOffset + xOffset,0),mPixmap); |
340 | //qDebug("222draw pix %d ",xOffset ); | 348 | //qDebug("222draw pix %d ",xOffset ); |
341 | 349 | ||
342 | } | 350 | } |
343 | 351 | ||
344 | } | 352 | } |
345 | pa.end(); | 353 | pa.end(); |
346 | 354 | ||
347 | } | 355 | } |
348 | } | 356 | } |
349 | 357 | ||
350 | void EventIndicator::setXOffset( int x ) | 358 | void EventIndicator::setXOffset( int x ) |
351 | { | 359 | { |
352 | mXOffset = x; | 360 | mXOffset = x; |
353 | } | 361 | } |
354 | void EventIndicator::setPaintWidget( KDGanttMinimizeSplitter * w ) | 362 | void EventIndicator::setPaintWidget( KDGanttMinimizeSplitter * w ) |
355 | { | 363 | { |
356 | mPaintWidget = w; | 364 | mPaintWidget = w; |
357 | setMaximumHeight(0); | 365 | setMaximumHeight(0); |
358 | setMinimumHeight(0); | 366 | setMinimumHeight(0); |
359 | } | 367 | } |
360 | void EventIndicator::changeColumns(int columns) | 368 | void EventIndicator::changeColumns(int columns) |
361 | { | 369 | { |
362 | mColumns = columns; | 370 | mColumns = columns; |
363 | mEnabled.resize(mColumns); | 371 | mEnabled.resize(mColumns); |
364 | 372 | ||
365 | update(); | 373 | update(); |
366 | } | 374 | } |
367 | 375 | ||
368 | void EventIndicator::enableColumn(int column, bool enable) | 376 | void EventIndicator::enableColumn(int column, bool enable) |
369 | { | 377 | { |
370 | mEnabled[column] = enable; | 378 | mEnabled[column] = enable; |
371 | } | 379 | } |
372 | 380 | ||
373 | 381 | ||
374 | //////////////////////////////////////////////////////////////////////////// | 382 | //////////////////////////////////////////////////////////////////////////// |
375 | //////////////////////////////////////////////////////////////////////////// | 383 | //////////////////////////////////////////////////////////////////////////// |
376 | //////////////////////////////////////////////////////////////////////////// | 384 | //////////////////////////////////////////////////////////////////////////// |
377 | 385 | ||
378 | KOAgendaView::KOAgendaView(Calendar *cal,QWidget *parent,const char *name) : | 386 | KOAgendaView::KOAgendaView(Calendar *cal,QWidget *parent,const char *name) : |
379 | KOEventView (cal,parent,name) | 387 | KOEventView (cal,parent,name) |
380 | { | 388 | { |
381 | mBlockUpdating = true; | 389 | mBlockUpdating = true; |
382 | mStartHour = 8; | 390 | mStartHour = 8; |
383 | mSelectedDates.append(QDate::currentDate()); | 391 | mSelectedDates.append(QDate::currentDate()); |
384 | 392 | ||
385 | mLayoutDayLabels = 0; | 393 | mLayoutDayLabels = 0; |
386 | mDayLabelsFrame = 0; | 394 | mDayLabelsFrame = 0; |
387 | mDayLabels = 0; | 395 | mDayLabels = 0; |
388 | bool isRTL = KOGlobals::self()->reverseLayout(); | 396 | bool isRTL = KOGlobals::self()->reverseLayout(); |
389 | QPixmap expandPix; | 397 | QPixmap expandPix; |
390 | if ( KOPrefs::instance()->mVerticalScreen ) { | 398 | if ( KOPrefs::instance()->mVerticalScreen ) { |
391 | expandPix = SmallIcon( "1updownarrow" ); | 399 | expandPix = SmallIcon( "1updownarrow" ); |
392 | } else { | 400 | } else { |
393 | expandPix = SmallIcon("1leftrightarrow" ); | 401 | expandPix = SmallIcon("1leftrightarrow" ); |
394 | } | 402 | } |
395 | 403 | ||
396 | QBoxLayout *topLayout = new QVBoxLayout(this); | 404 | QBoxLayout *topLayout = new QVBoxLayout(this); |
397 | 405 | ||
398 | // Create day name labels for agenda columns | 406 | // Create day name labels for agenda columns |
399 | // Create agenda splitter | 407 | // Create agenda splitter |
400 | 408 | ||
401 | mSplitterAgenda = new KDGanttMinimizeSplitter( Qt::Vertical, this); | 409 | mSplitterAgenda = new KDGanttMinimizeSplitter( Qt::Vertical, this); |
402 | mSplitterAgenda->setMinimizeDirection ( KDGanttMinimizeSplitter::Up ); | 410 | mSplitterAgenda->setMinimizeDirection ( KDGanttMinimizeSplitter::Up ); |
403 | topLayout->addWidget( mSplitterAgenda ); | 411 | topLayout->addWidget( mSplitterAgenda ); |
404 | mAllDayFrame = new QHBox(mSplitterAgenda); | 412 | mAllDayFrame = new QHBox(mSplitterAgenda); |
405 | mAllDayFrame->setFocusPolicy(NoFocus); | 413 | mAllDayFrame->setFocusPolicy(NoFocus); |
406 | QWidget *agendaFrame = new QWidget(mSplitterAgenda); | 414 | QWidget *agendaFrame = new QWidget(mSplitterAgenda); |
407 | agendaFrame->setFocusPolicy(NoFocus); | 415 | agendaFrame->setFocusPolicy(NoFocus); |
408 | 416 | ||
409 | // Create all-day agenda widget | 417 | // Create all-day agenda widget |
410 | mDummyAllDayLeft = new QVBox( mAllDayFrame ); | 418 | mDummyAllDayLeft = new QVBox( mAllDayFrame ); |
411 | 419 | ||
412 | mExpandButton = new QPushButton(mDummyAllDayLeft); | 420 | mExpandButton = new QPushButton(mDummyAllDayLeft); |
413 | mExpandButton->setPixmap( expandPix ); | 421 | mExpandButton->setPixmap( expandPix ); |
414 | int widebut = mExpandButton->sizeHint().width()+4; | 422 | int widebut = mExpandButton->sizeHint().width()+4; |
415 | int heibut = mExpandButton->sizeHint().height()+4; | 423 | int heibut = mExpandButton->sizeHint().height()+4; |
416 | if ( heibut > widebut ) | 424 | if ( heibut > widebut ) |
417 | widebut = heibut ; | 425 | widebut = heibut ; |
418 | 426 | ||
419 | //mExpandButton->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, | 427 | //mExpandButton->setSizePolicy( QSizePolicy( QSizePolicy::Fixed, |
420 | // QSizePolicy::Fixed ) ); | 428 | // QSizePolicy::Fixed ) ); |
421 | mExpandButton->setFixedSize( widebut, widebut); | 429 | mExpandButton->setFixedSize( widebut, widebut); |
422 | connect( mExpandButton, SIGNAL( clicked() ), SIGNAL( toggleExpand() ) ); | 430 | connect( mExpandButton, SIGNAL( clicked() ), SIGNAL( toggleExpand() ) ); |
423 | mExpandButton->setFocusPolicy(NoFocus); | 431 | mExpandButton->setFocusPolicy(NoFocus); |
424 | mAllDayAgenda = new KOAgenda(1,mAllDayFrame); | 432 | mAllDayAgenda = new KOAgenda(1,mAllDayFrame); |
425 | mAllDayAgenda->setFocusPolicy(NoFocus); | 433 | mAllDayAgenda->setFocusPolicy(NoFocus); |
426 | QLabel *dummyAllDayRight = new QLabel (mAllDayFrame); | 434 | QLabel *dummyAllDayRight = new QLabel (mAllDayFrame); |
427 | 435 | ||
428 | // Create event context menu for all day agenda | 436 | // Create event context menu for all day agenda |
429 | mAllDayAgendaPopup = eventPopup(); | 437 | mAllDayAgendaPopup = eventPopup(); |
430 | connect(mAllDayAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)), | 438 | connect(mAllDayAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)), |
431 | mAllDayAgendaPopup,SLOT(showIncidencePopup(Incidence *))); | 439 | mAllDayAgendaPopup,SLOT(showIncidencePopup(Incidence *))); |
432 | 440 | ||
433 | // Create agenda frame | 441 | // Create agenda frame |
434 | QGridLayout *agendaLayout = new QGridLayout(agendaFrame,4,3); | 442 | QGridLayout *agendaLayout = new QGridLayout(agendaFrame,4,3); |
435 | // QHBox *agendaFrame = new QHBox(splitterAgenda); | 443 | // QHBox *agendaFrame = new QHBox(splitterAgenda); |
436 | 444 | ||
437 | // create event indicator bars | 445 | // create event indicator bars |
438 | mEventIndicatorTop = new EventIndicator(EventIndicator::Top,agendaFrame); | 446 | mEventIndicatorTop = new EventIndicator(EventIndicator::Top,agendaFrame); |
439 | #ifndef DESKTOP_VERSION | 447 | #ifndef DESKTOP_VERSION |
440 | // FIX | 448 | // FIX |
441 | mEventIndicatorTop->setPaintWidget( mSplitterAgenda ); | 449 | mEventIndicatorTop->setPaintWidget( mSplitterAgenda ); |
442 | #endif | 450 | #endif |
443 | mDayLabelsFrame = new QHBox(agendaFrame); | 451 | mDayLabelsFrame = new QHBox(agendaFrame); |
444 | //topLayout->addWidget(mDayLabelsFrame); | 452 | //topLayout->addWidget(mDayLabelsFrame); |
445 | mDayLabels = new QFrame (mDayLabelsFrame); | 453 | mDayLabels = new QFrame (mDayLabelsFrame); |
446 | mLayoutDayLabels = new QHBoxLayout(mDayLabels); | 454 | mLayoutDayLabels = new QHBoxLayout(mDayLabels); |
447 | agendaLayout->addMultiCellWidget(mDayLabelsFrame ,0,0,0,2); | 455 | agendaLayout->addMultiCellWidget(mDayLabelsFrame ,0,0,0,2); |
448 | agendaLayout->addWidget(mEventIndicatorTop,1,1); | 456 | agendaLayout->addWidget(mEventIndicatorTop,1,1); |
449 | 457 | ||
450 | mEventIndicatorBottom = new EventIndicator(EventIndicator::Bottom, | 458 | mEventIndicatorBottom = new EventIndicator(EventIndicator::Bottom, |
451 | agendaFrame); | 459 | agendaFrame); |
452 | agendaLayout->addWidget(mEventIndicatorBottom,3,1); | 460 | agendaLayout->addWidget(mEventIndicatorBottom,3,1); |
453 | QWidget *dummyAgendaRight = new QWidget(agendaFrame); | 461 | QWidget *dummyAgendaRight = new QWidget(agendaFrame); |
454 | agendaLayout->addWidget(dummyAgendaRight,1,2); | 462 | agendaLayout->addWidget(dummyAgendaRight,1,2); |
455 | 463 | ||
456 | // Create time labels | 464 | // Create time labels |
457 | mTimeLabels = new TimeLabels(24,agendaFrame); | 465 | mTimeLabels = new TimeLabels(24,agendaFrame); |
458 | agendaLayout->addWidget(mTimeLabels,2,0); | 466 | agendaLayout->addWidget(mTimeLabels,2,0); |
459 | connect(mTimeLabels,SIGNAL( scaleChanged()), | 467 | connect(mTimeLabels,SIGNAL( scaleChanged()), |
460 | this,SLOT(updateConfig())); | 468 | this,SLOT(updateConfig())); |
461 | 469 | ||
462 | // Create agenda | 470 | // Create agenda |
463 | mAgenda = new KOAgenda(1,96,KOPrefs::instance()->mHourSize,agendaFrame); | 471 | mAgenda = new KOAgenda(1,96,KOPrefs::instance()->mHourSize,agendaFrame); |
464 | agendaLayout->addMultiCellWidget(mAgenda,2,2,1,2); | 472 | agendaLayout->addMultiCellWidget(mAgenda,2,2,1,2); |
465 | agendaLayout->setColStretch(1,1); | 473 | agendaLayout->setColStretch(1,1); |
466 | mAgenda->setFocusPolicy(NoFocus); | 474 | mAgenda->setFocusPolicy(NoFocus); |
467 | // Create event context menu for agenda | 475 | // Create event context menu for agenda |
468 | mAgendaPopup = eventPopup(); | 476 | mAgendaPopup = eventPopup(); |
469 | 477 | ||
470 | mAgendaPopup->addAdditionalItem(QIconSet(SmallIcon("bell")), | 478 | mAgendaPopup->addAdditionalItem(QIconSet(SmallIcon("bell")), |
471 | i18n("Toggle Alarm"),mAgenda, | 479 | i18n("Toggle Alarm"),mAgenda, |
472 | SLOT(popupAlarm()),true); | 480 | SLOT(popupAlarm()),true); |
473 | 481 | ||
474 | 482 | ||
475 | connect(mAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)), | 483 | connect(mAgenda,SIGNAL(showIncidencePopupSignal(Incidence *)), |
476 | mAgendaPopup,SLOT(showIncidencePopup(Incidence *))); | 484 | mAgendaPopup,SLOT(showIncidencePopup(Incidence *))); |
477 | 485 | ||
478 | // make connections between dependent widgets | 486 | // make connections between dependent widgets |
479 | mTimeLabels->setAgenda(mAgenda); | 487 | mTimeLabels->setAgenda(mAgenda); |
480 | 488 | ||
481 | // Update widgets to reflect user preferences | 489 | // Update widgets to reflect user preferences |
482 | // updateConfig(); | 490 | // updateConfig(); |
483 | 491 | ||
484 | // createDayLabels(); | 492 | // createDayLabels(); |
485 | 493 | ||
486 | // these blank widgets make the All Day Event box line up with the agenda | 494 | // these blank widgets make the All Day Event box line up with the agenda |
487 | dummyAllDayRight->setFixedWidth(mAgenda->verticalScrollBar()->width()); | 495 | dummyAllDayRight->setFixedWidth(mAgenda->verticalScrollBar()->width()); |
488 | dummyAgendaRight->setFixedWidth(mAgenda->verticalScrollBar()->width()); | 496 | dummyAgendaRight->setFixedWidth(mAgenda->verticalScrollBar()->width()); |
489 | mDummyAllDayLeft->setFixedWidth(mTimeLabels->width()); | 497 | mDummyAllDayLeft->setFixedWidth(mTimeLabels->width()); |
490 | 498 | ||
491 | // Scrolling | 499 | // Scrolling |
492 | connect(mAgenda->verticalScrollBar(),SIGNAL(valueChanged(int)), | 500 | connect(mAgenda->verticalScrollBar(),SIGNAL(valueChanged(int)), |
493 | mTimeLabels, SLOT(positionChanged())); | 501 | mTimeLabels, SLOT(positionChanged())); |
494 | connect(mTimeLabels->verticalScrollBar(),SIGNAL(valueChanged(int)), | 502 | connect(mTimeLabels->verticalScrollBar(),SIGNAL(valueChanged(int)), |
495 | SLOT(setContentsPos(int))); | 503 | SLOT(setContentsPos(int))); |
496 | 504 | ||
497 | connect(mAgenda,SIGNAL(showDateView( int, int)),SLOT(slotShowDateView( int, int ))); | 505 | connect(mAgenda,SIGNAL(showDateView( int, int)),SLOT(slotShowDateView( int, int ))); |
498 | connect(mAllDayAgenda,SIGNAL(showDateView( int, int )), SLOT(slotShowDateView( int, int ) )); | 506 | connect(mAllDayAgenda,SIGNAL(showDateView( int, int )), SLOT(slotShowDateView( int, int ) )); |
499 | 507 | ||
500 | // Create/Show/Edit/Delete Event | 508 | // Create/Show/Edit/Delete Event |
501 | connect(mAgenda,SIGNAL(newEventSignal(int,int)), | 509 | connect(mAgenda,SIGNAL(newEventSignal(int,int)), |
502 | SLOT(newEvent(int,int))); | 510 | SLOT(newEvent(int,int))); |
503 | connect(mAgenda,SIGNAL(newTodoSignal(int,int)), | 511 | connect(mAgenda,SIGNAL(newTodoSignal(int,int)), |
504 | SLOT(newTodo(int,int))); | 512 | SLOT(newTodo(int,int))); |
505 | connect(mAgenda,SIGNAL(newEventSignal(int,int,int,int)), | 513 | connect(mAgenda,SIGNAL(newEventSignal(int,int,int,int)), |
506 | SLOT(newEvent(int,int,int,int))); | 514 | SLOT(newEvent(int,int,int,int))); |
507 | connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int)), | 515 | connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int)), |
508 | SLOT(newEventAllDay(int,int))); | 516 | SLOT(newEventAllDay(int,int))); |
509 | connect(mAllDayAgenda,SIGNAL(newTodoSignal(int,int)), | 517 | connect(mAllDayAgenda,SIGNAL(newTodoSignal(int,int)), |
510 | SLOT(newTodoAllDay(int,int))); | 518 | SLOT(newTodoAllDay(int,int))); |
511 | connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int,int,int)), | 519 | connect(mAllDayAgenda,SIGNAL(newEventSignal(int,int,int,int)), |
512 | SLOT(newEventAllDay(int,int))); | 520 | SLOT(newEventAllDay(int,int))); |
513 | connect(mAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)), | 521 | connect(mAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)), |
514 | SLOT(newTimeSpanSelected(int,int,int,int))); | 522 | SLOT(newTimeSpanSelected(int,int,int,int))); |
515 | connect(mAllDayAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)), | 523 | connect(mAllDayAgenda,SIGNAL(newTimeSpanSignal(int,int,int,int)), |
516 | SLOT(newTimeSpanSelectedAllDay(int,int,int,int))); | 524 | SLOT(newTimeSpanSelectedAllDay(int,int,int,int))); |
517 | connect(mAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView())); | 525 | connect(mAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView())); |
518 | connect(mAllDayAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView())); | 526 | connect(mAllDayAgenda,SIGNAL(newStartSelectSignal()),SLOT(updateView())); |
519 | 527 | ||
520 | connect(mAgenda,SIGNAL(editIncidenceSignal(Incidence *)), | 528 | connect(mAgenda,SIGNAL(editIncidenceSignal(Incidence *)), |
521 | SIGNAL(editIncidenceSignal(Incidence *))); | 529 | SIGNAL(editIncidenceSignal(Incidence *))); |
522 | connect(mAllDayAgenda,SIGNAL(editIncidenceSignal(Incidence *)), | 530 | connect(mAllDayAgenda,SIGNAL(editIncidenceSignal(Incidence *)), |
523 | SIGNAL(editIncidenceSignal(Incidence *))); | 531 | SIGNAL(editIncidenceSignal(Incidence *))); |
524 | connect(mAgenda,SIGNAL(showIncidenceSignal(Incidence *)), | 532 | connect(mAgenda,SIGNAL(showIncidenceSignal(Incidence *)), |
525 | SIGNAL(showIncidenceSignal(Incidence *))); | 533 | SIGNAL(showIncidenceSignal(Incidence *))); |
526 | connect(mAllDayAgenda,SIGNAL(showIncidenceSignal(Incidence *)), | 534 | connect(mAllDayAgenda,SIGNAL(showIncidenceSignal(Incidence *)), |
527 | SIGNAL(showIncidenceSignal(Incidence *))); | 535 | SIGNAL(showIncidenceSignal(Incidence *))); |
528 | connect(mAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)), | 536 | connect(mAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)), |
529 | SIGNAL(deleteIncidenceSignal(Incidence *))); | 537 | SIGNAL(deleteIncidenceSignal(Incidence *))); |
530 | connect(mAllDayAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)), | 538 | connect(mAllDayAgenda,SIGNAL(deleteIncidenceSignal(Incidence *)), |
531 | SIGNAL(deleteIncidenceSignal(Incidence *))); | 539 | SIGNAL(deleteIncidenceSignal(Incidence *))); |
532 | 540 | ||
533 | connect(mAgenda,SIGNAL(itemModified(KOAgendaItem *, int )), | 541 | connect(mAgenda,SIGNAL(itemModified(KOAgendaItem *, int )), |
534 | SLOT(updateEventDates(KOAgendaItem *, int ))); | 542 | SLOT(updateEventDates(KOAgendaItem *, int ))); |
535 | connect(mAllDayAgenda,SIGNAL(itemModified(KOAgendaItem *, int )), | 543 | connect(mAllDayAgenda,SIGNAL(itemModified(KOAgendaItem *, int )), |
536 | SLOT(updateEventDates(KOAgendaItem *, int))); | 544 | SLOT(updateEventDates(KOAgendaItem *, int))); |
537 | 545 | ||
538 | // event indicator update | 546 | // event indicator update |
539 | connect(mAgenda,SIGNAL(lowerYChanged(int)), | 547 | connect(mAgenda,SIGNAL(lowerYChanged(int)), |
540 | SLOT(updateEventIndicatorTop(int))); | 548 | SLOT(updateEventIndicatorTop(int))); |
541 | connect(mAgenda,SIGNAL(upperYChanged(int)), | 549 | connect(mAgenda,SIGNAL(upperYChanged(int)), |
542 | SLOT(updateEventIndicatorBottom(int))); | 550 | SLOT(updateEventIndicatorBottom(int))); |
543 | // drag signals | 551 | // drag signals |
544 | /* | 552 | /* |
545 | connect(mAgenda,SIGNAL(startDragSignal(Event *)), | 553 | connect(mAgenda,SIGNAL(startDragSignal(Event *)), |
546 | SLOT(startDrag(Event *))); | 554 | SLOT(startDrag(Event *))); |
547 | connect(mAllDayAgenda,SIGNAL(startDragSignal(Event *)), | 555 | connect(mAllDayAgenda,SIGNAL(startDragSignal(Event *)), |
548 | SLOT(startDrag(Event *))); | 556 | SLOT(startDrag(Event *))); |
549 | */ | 557 | */ |
550 | // synchronize selections | 558 | // synchronize selections |
551 | connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ), | 559 | connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ), |
552 | mAllDayAgenda, SLOT( deselectItem() ) ); | 560 | mAllDayAgenda, SLOT( deselectItem() ) ); |
553 | connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ), | 561 | connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ), |
554 | mAgenda, SLOT( deselectItem() ) ); | 562 | mAgenda, SLOT( deselectItem() ) ); |
555 | connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ), | 563 | connect( mAgenda, SIGNAL( incidenceSelected( Incidence * ) ), |
556 | SIGNAL( incidenceSelected( Incidence * ) ) ); | 564 | SIGNAL( incidenceSelected( Incidence * ) ) ); |
557 | connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ), | 565 | connect( mAllDayAgenda, SIGNAL( incidenceSelected( Incidence * ) ), |
558 | SIGNAL( incidenceSelected( Incidence * ) ) ); | 566 | SIGNAL( incidenceSelected( Incidence * ) ) ); |
559 | connect( mAgenda, SIGNAL( resizedSignal() ), | 567 | connect( mAgenda, SIGNAL( resizedSignal() ), |
560 | SLOT( updateConfig( ) ) ); | 568 | SLOT( updateConfig( ) ) ); |
561 | connect( mAgenda, SIGNAL( addToCalSignal(Incidence *, Incidence *) ), | 569 | connect( mAgenda, SIGNAL( addToCalSignal(Incidence *, Incidence *) ), |
562 | SLOT( addToCalSlot(Incidence *, Incidence * ) ) ); | 570 | SLOT( addToCalSlot(Incidence *, Incidence * ) ) ); |
563 | connect( mAllDayAgenda, SIGNAL( addToCalSignal(Incidence * ,Incidence *) ), | 571 | connect( mAllDayAgenda, SIGNAL( addToCalSignal(Incidence * ,Incidence *) ), |
564 | SLOT( addToCalSlot(Incidence * , Incidence *) ) ); | 572 | SLOT( addToCalSlot(Incidence * , Incidence *) ) ); |
565 | // connect( mAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) ); | 573 | // connect( mAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) ); |
566 | //connect( mAllDayAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) ); | 574 | //connect( mAllDayAgenda, SIGNAL( cloneIncidenceSignal(Incidence *) ), SIGNAL( cloneIncidenceSignal(Incidence *) ) ); |
567 | 575 | ||
568 | 576 | ||
569 | } | 577 | } |
570 | 578 | ||
571 | void KOAgendaView::toggleAllDay() | 579 | void KOAgendaView::toggleAllDay() |
572 | { | 580 | { |
573 | if ( mSplitterAgenda->firstHandle() ) | 581 | if ( mSplitterAgenda->firstHandle() ) |
574 | mSplitterAgenda->firstHandle()->toggle(); | 582 | mSplitterAgenda->firstHandle()->toggle(); |
575 | } | 583 | } |
576 | void KOAgendaView::addToCalSlot(Incidence * inc, Incidence * incOld ) | 584 | void KOAgendaView::addToCalSlot(Incidence * inc, Incidence * incOld ) |
577 | { | 585 | { |
578 | calendar()->addIncidence( inc ); | 586 | calendar()->addIncidence( inc ); |
579 | 587 | ||
580 | if ( incOld ) { | 588 | if ( incOld ) { |
581 | if ( incOld->type() == "Todo" ) | 589 | if ( incOld->type() == "Todo" ) |
582 | emit todoMoved((Todo*)incOld, KOGlobals::EVENTEDITED ); | 590 | emit todoMoved((Todo*)incOld, KOGlobals::EVENTEDITED ); |
583 | else | 591 | else |
584 | emit incidenceChanged(incOld, KOGlobals::EVENTEDITED); | 592 | emit incidenceChanged(incOld, KOGlobals::EVENTEDITED); |
585 | } | 593 | } |
586 | 594 | ||
587 | } | 595 | } |
588 | 596 | ||
589 | KOAgendaView::~KOAgendaView() | 597 | KOAgendaView::~KOAgendaView() |
590 | { | 598 | { |
591 | delete mAgendaPopup; | 599 | delete mAgendaPopup; |
592 | delete mAllDayAgendaPopup; | 600 | delete mAllDayAgendaPopup; |
593 | delete KOAgendaItem::paintPix(); | 601 | delete KOAgendaItem::paintPix(); |
594 | delete KOAgendaItem::paintPixSel(); | 602 | delete KOAgendaItem::paintPixSel(); |
595 | } | 603 | } |
596 | void KOAgendaView::resizeEvent( QResizeEvent* e ) | 604 | void KOAgendaView::resizeEvent( QResizeEvent* e ) |
597 | { | 605 | { |
598 | //qDebug("KOAgendaView::resizeEvent( QResizeEvent* e ) %d ", e->size().width()); | 606 | //qDebug("KOAgendaView::resizeEvent( QResizeEvent* e ) %d ", e->size().width()); |
599 | bool uc = false; | 607 | bool uc = false; |
600 | int ow = e->oldSize().width(); | 608 | int ow = e->oldSize().width(); |
601 | int oh = e->oldSize().height(); | 609 | int oh = e->oldSize().height(); |
602 | int w = e->size().width(); | 610 | int w = e->size().width(); |
603 | int h = e->size().height(); | 611 | int h = e->size().height(); |
604 | if ( (ow > oh && w< h ) || (ow < oh && w > h ) ) { | 612 | if ( (ow > oh && w< h ) || (ow < oh && w > h ) ) { |
605 | if ( ! mBlockUpdating && !globalFlagBlockStartup && !globalFlagBlockAgenda ) | 613 | if ( ! mBlockUpdating && !globalFlagBlockStartup && !globalFlagBlockAgenda ) |
606 | uc = true; | 614 | uc = true; |
607 | //qDebug("view changed %d %d %d %d ", ow, oh , w , h); | 615 | //qDebug("view changed %d %d %d %d ", ow, oh , w , h); |
608 | } | 616 | } |
609 | mUpcomingWidth = e->size().width() ; | 617 | mUpcomingWidth = e->size().width() ; |
610 | if ( mBlockUpdating || uc ) { | 618 | if ( mBlockUpdating || uc ) { |
611 | mBlockUpdating = false; | 619 | mBlockUpdating = false; |
612 | //mAgenda->setMinimumSize(800 , 600 ); | 620 | //mAgenda->setMinimumSize(800 , 600 ); |
613 | //qDebug("mAgenda->resize+++++++++++++++ "); | 621 | //qDebug("mAgenda->resize+++++++++++++++ "); |
614 | updateConfig(); | 622 | updateConfig(); |
615 | //qDebug("KOAgendaView::Updating now possible "); | 623 | //qDebug("KOAgendaView::Updating now possible "); |
616 | } else | 624 | } else |
617 | createDayLabels(); | 625 | createDayLabels(); |
618 | //qDebug("resizeEvent end "); | 626 | //qDebug("resizeEvent end "); |
619 | 627 | ||
620 | } | 628 | } |
621 | void KOAgendaView::slotDaylabelClicked( int num ) | 629 | void KOAgendaView::slotDaylabelClicked( int num ) |
622 | { | 630 | { |
623 | 631 | ||
624 | QDate firstDate = mSelectedDates.first(); | 632 | QDate firstDate = mSelectedDates.first(); |
625 | if ( num == -1 ) | 633 | if ( num == -1 ) |
626 | emit showDateView( 6, firstDate ); | 634 | emit showDateView( 6, firstDate ); |
627 | else if (num >= 0 ) { | 635 | else if (num >= 0 ) { |
628 | if ( mSelectedDates.count() == 1) | 636 | if ( mSelectedDates.count() == 1) |
629 | emit showDateView( 9, firstDate.addDays( num ) ); | 637 | emit showDateView( 9, firstDate.addDays( num ) ); |
630 | else | 638 | else |
631 | emit showDateView( 3, firstDate.addDays( num ) ); | 639 | emit showDateView( 3, firstDate.addDays( num ) ); |
632 | } | 640 | } |
633 | else | 641 | else |
634 | showDateView( 10, firstDate.addDays(1) ); | 642 | showDateView( 10, firstDate.addDays(1) ); |
635 | } | 643 | } |
636 | 644 | ||
637 | KOAgendaButton* KOAgendaView::getNewDaylabel() | 645 | KOAgendaButton* KOAgendaView::getNewDaylabel() |
638 | { | 646 | { |
639 | 647 | ||
640 | KOAgendaButton * dayLabel = new KOAgendaButton(mDayLabels); | 648 | KOAgendaButton * dayLabel = new KOAgendaButton(mDayLabels); |
641 | connect( dayLabel, SIGNAL( numClicked(int) ), this, SLOT ( slotDaylabelClicked(int) ) ); | 649 | connect( dayLabel, SIGNAL( numClicked(int) ), this, SLOT ( slotDaylabelClicked(int) ) ); |
642 | mDayLabelsList.append( dayLabel ); | 650 | mDayLabelsList.append( dayLabel ); |
643 | mLayoutDayLabels->addWidget(dayLabel); | 651 | mLayoutDayLabels->addWidget(dayLabel); |
644 | return dayLabel ; | 652 | return dayLabel ; |
645 | } | 653 | } |
646 | 654 | ||
647 | void KOAgendaView::createDayLabels() | 655 | void KOAgendaView::createDayLabels() |
648 | { | 656 | { |
649 | 657 | ||
650 | if ( mBlockUpdating || globalFlagBlockLabel == 1) { | 658 | if ( mBlockUpdating || globalFlagBlockLabel == 1) { |
651 | // qDebug(" KOAgendaView::createDayLabels() blocked "); | 659 | // qDebug(" KOAgendaView::createDayLabels() blocked "); |
652 | return; | 660 | return; |
653 | 661 | ||
654 | } | 662 | } |
655 | int newHight; | 663 | int newHight; |
656 | 664 | ||
657 | // ### Before deleting and recreating we could check if mSelectedDates changed... | 665 | // ### Before deleting and recreating we could check if mSelectedDates changed... |
658 | // It would remove some flickering and gain speed (since this is called by | 666 | // It would remove some flickering and gain speed (since this is called by |
659 | // each updateView() call) | 667 | // each updateView() call) |
660 | 668 | ||
661 | int maxWid = mUpcomingWidth - mTimeLabels->width()- mAgenda->verticalScrollBar()->width() - 2; | 669 | int maxWid = mUpcomingWidth - mTimeLabels->width()- mAgenda->verticalScrollBar()->width() - 2; |
662 | mDayLabelsFrame->setMaximumWidth( mUpcomingWidth ); | 670 | mDayLabelsFrame->setMaximumWidth( mUpcomingWidth ); |
663 | if ( maxWid < 0 ) | 671 | if ( maxWid < 0 ) |
664 | maxWid = 20; | 672 | maxWid = 20; |
665 | 673 | ||
666 | QFont dlf = KOPrefs::instance()->mTimeLabelsFont; | 674 | QFont dlf = KOPrefs::instance()->mTimeLabelsFont; |
667 | QFontMetrics fm ( dlf ); | 675 | QFontMetrics fm ( dlf ); |
668 | int selCount = mSelectedDates.count(); | 676 | int selCount = mSelectedDates.count(); |
669 | QString dayTest = "Mon 20"; | 677 | QString dayTest = "Mon 20"; |
670 | //QString dayTest = "Mon 20"; | 678 | //QString dayTest = "Mon 20"; |
671 | int wid = fm.width( dayTest ); | 679 | int wid = fm.width( dayTest ); |
672 | //maxWid -= ( selCount * 3 ); //working for QLabels | 680 | //maxWid -= ( selCount * 3 ); //working for QLabels |
673 | maxWid -= ( selCount * 3 ); //working for QPushButton | 681 | maxWid -= ( selCount * 3 ); //working for QPushButton |
674 | if ( maxWid < 0 ) | 682 | if ( maxWid < 0 ) |
675 | maxWid = 20; | 683 | maxWid = 20; |
676 | int needWid = wid * selCount; | 684 | int needWid = wid * selCount; |
677 | //qDebug("++++++++Needed : %d MaxWidth: %d", needWid, maxWid ); | 685 | //qDebug("++++++++Needed : %d MaxWidth: %d", needWid, maxWid ); |
678 | //if ( needWid > maxWid ) | 686 | //if ( needWid > maxWid ) |
679 | // qDebug("DAYLABELS TOOOOOOO BIG "); | 687 | // qDebug("DAYLABELS TOOOOOOO BIG "); |
680 | while ( needWid > maxWid ) { | 688 | while ( needWid > maxWid ) { |
681 | dayTest = dayTest.left( dayTest.length() - 1 ); | 689 | dayTest = dayTest.left( dayTest.length() - 1 ); |
682 | wid = fm.width( dayTest ); | 690 | wid = fm.width( dayTest ); |
683 | needWid = wid * selCount; | 691 | needWid = wid * selCount; |
684 | } | 692 | } |
685 | int maxLen = dayTest.length(); | 693 | int maxLen = dayTest.length(); |
686 | int fontPoint = dlf.pointSize(); | 694 | int fontPoint = dlf.pointSize(); |
687 | if ( maxLen < 2 ) { | 695 | if ( maxLen < 2 ) { |
688 | int fontPoint = dlf.pointSize(); | 696 | int fontPoint = dlf.pointSize(); |
689 | while ( fontPoint > 4 ) { | 697 | while ( fontPoint > 4 ) { |
690 | --fontPoint; | 698 | --fontPoint; |
691 | dlf.setPointSize( fontPoint ); | 699 | dlf.setPointSize( fontPoint ); |
692 | QFontMetrics f( dlf ); | 700 | QFontMetrics f( dlf ); |
693 | wid = f.width( "30" ); | 701 | wid = f.width( "30" ); |
694 | needWid = wid * selCount; | 702 | needWid = wid * selCount; |
695 | if ( needWid < maxWid ) | 703 | if ( needWid < maxWid ) |
696 | break; | 704 | break; |
697 | } | 705 | } |
698 | maxLen = 2; | 706 | maxLen = 2; |
699 | } | 707 | } |
700 | //qDebug("Max len %d ", dayTest.length() ); | 708 | //qDebug("Max len %d ", dayTest.length() ); |
701 | 709 | ||
702 | QFontMetrics tempF( dlf ); | 710 | QFontMetrics tempF( dlf ); |
703 | newHight = tempF.height(); | 711 | newHight = tempF.height(); |
704 | mDayLabels->setFont( dlf ); | 712 | mDayLabels->setFont( dlf ); |
705 | // mLayoutDayLabels = new QHBoxLayout(mDayLabels);; | 713 | // mLayoutDayLabels = new QHBoxLayout(mDayLabels);; |
706 | // mLayoutDayLabels->addSpacing(mTimeLabels->width()); | 714 | // mLayoutDayLabels->addSpacing(mTimeLabels->width()); |
707 | //mLayoutDayLabels->addSpacing( 2 ); | 715 | //mLayoutDayLabels->addSpacing( 2 ); |
708 | // QFont lFont = dlf; | 716 | // QFont lFont = dlf; |
709 | bool appendLabels = false; | 717 | bool appendLabels = false; |
710 | KOAgendaButton *dayLabel; | 718 | KOAgendaButton *dayLabel; |
711 | dayLabel = mDayLabelsList.first(); | 719 | dayLabel = mDayLabelsList.first(); |
712 | if ( !dayLabel ) { | 720 | if ( !dayLabel ) { |
713 | appendLabels = true; | 721 | appendLabels = true; |
714 | dayLabel = getNewDaylabel(); | 722 | dayLabel = getNewDaylabel(); |
715 | } | 723 | } |
716 | dayLabel->setFixedWidth( mTimeLabels->width()+mAgenda->frameWidth() ); | 724 | dayLabel->setFixedWidth( mTimeLabels->width()+mAgenda->frameWidth() ); |
717 | dayLabel->setFont( dlf ); | 725 | dayLabel->setFont( dlf ); |
718 | dayLabel->setNum( -1 ); | 726 | dayLabel->setNum( -1 ); |
719 | //dayLabel->setAlignment(QLabel::AlignHCenter); | 727 | //dayLabel->setAlignment(QLabel::AlignHCenter); |
720 | dayLabel->setText( KOGlobals::self()->calendarSystem()->monthName( mSelectedDates.first(), true ) ); | 728 | dayLabel->setText( KOGlobals::self()->calendarSystem()->monthName( mSelectedDates.first(), true ) ); |
721 | dayLabel->show(); | 729 | dayLabel->show(); |
722 | DateList::ConstIterator dit; | 730 | DateList::ConstIterator dit; |
723 | bool oneday = (mSelectedDates.first() == mSelectedDates.last() ); | 731 | bool oneday = (mSelectedDates.first() == mSelectedDates.last() ); |
724 | int counter = -1; | 732 | int counter = -1; |
725 | for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) { | 733 | for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) { |
726 | ++counter; | 734 | ++counter; |
727 | QDate date = *dit; | 735 | QDate date = *dit; |
728 | // QBoxLayout *dayLayout = new QVBoxLayout(mLayoutDayLabels); | 736 | // QBoxLayout *dayLayout = new QVBoxLayout(mLayoutDayLabels); |
729 | if ( ! appendLabels ) { | 737 | if ( ! appendLabels ) { |
730 | dayLabel = mDayLabelsList.next(); | 738 | dayLabel = mDayLabelsList.next(); |
731 | if ( !dayLabel ) | 739 | if ( !dayLabel ) |
732 | appendLabels = true; | 740 | appendLabels = true; |
733 | } | 741 | } |
734 | if ( appendLabels ) { | 742 | if ( appendLabels ) { |
735 | dayLabel = getNewDaylabel(); | 743 | dayLabel = getNewDaylabel(); |
736 | } | 744 | } |
737 | dayLabel->setMinimumWidth( 1 ); | 745 | dayLabel->setMinimumWidth( 1 ); |
738 | dayLabel->setMaximumWidth( 10240 ); | 746 | dayLabel->setMaximumWidth( 10240 ); |
739 | dayLabel->setFont( dlf ); | 747 | dayLabel->setFont( dlf ); |
740 | dayLabel->show(); | 748 | dayLabel->show(); |
741 | dayLabel->setAutoRepeat( false ); | 749 | dayLabel->setAutoRepeat( false ); |
742 | dayLabel->setNum( counter ); | 750 | dayLabel->setNum( counter ); |
743 | QString str; | 751 | QString str; |
744 | int dW = KOGlobals::self()->calendarSystem()->dayOfWeek(date); | 752 | int dW = KOGlobals::self()->calendarSystem()->dayOfWeek(date); |
745 | QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( dW, true ); | 753 | QString dayName = KOGlobals::self()->calendarSystem()->weekDayName( dW, true ); |
746 | switch ( maxLen ) { | 754 | switch ( maxLen ) { |
747 | case 2: | 755 | case 2: |
748 | str = QString::number( date.day() ); | 756 | str = QString::number( date.day() ); |
749 | break; | 757 | break; |
750 | 758 | ||
751 | case 3: | 759 | case 3: |
752 | str = dayName.left( 1 ) +QString::number( date.day()); | 760 | str = dayName.left( 1 ) +QString::number( date.day()); |
753 | 761 | ||
754 | break; | 762 | break; |
755 | case 4: | 763 | case 4: |
756 | str = dayName.left( 1 ) + " " +QString::number( date.day()); | 764 | str = dayName.left( 1 ) + " " +QString::number( date.day()); |
757 | 765 | ||
758 | break; | 766 | break; |
759 | case 5: | 767 | case 5: |
760 | str = dayName.left( 2 ) + " " +QString::number( date.day()); | 768 | str = dayName.left( 2 ) + " " +QString::number( date.day()); |
761 | 769 | ||
762 | break; | 770 | break; |
763 | case 6: | 771 | case 6: |
764 | str = dayName.left( 3 ) + " " +QString::number( date.day()); | 772 | str = dayName.left( 3 ) + " " +QString::number( date.day()); |
765 | break; | 773 | break; |
766 | 774 | ||
767 | default: | 775 | default: |
768 | break; | 776 | break; |
769 | } | 777 | } |
770 | if ( oneday ) { | 778 | if ( oneday ) { |
771 | QString addString; | 779 | QString addString; |
772 | if ( mSelectedDates.first() == QDateTime::currentDateTime().date() ) | 780 | if ( mSelectedDates.first() == QDateTime::currentDateTime().date() ) |
773 | addString = i18n("Today"); | 781 | addString = i18n("Today"); |
774 | else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(1) ) | 782 | else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(1) ) |
775 | addString = i18n("Tomorrow"); | 783 | addString = i18n("Tomorrow"); |
776 | else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-1) ) | 784 | else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-1) ) |
777 | addString = i18n("Yesterday"); | 785 | addString = i18n("Yesterday"); |
778 | else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-2) ) | 786 | else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(-2) ) |
779 | addString = i18n("Day before yesterday"); | 787 | addString = i18n("Day before yesterday"); |
780 | else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(2) ) | 788 | else if ( mSelectedDates.first() == QDateTime::currentDateTime().date().addDays(2) ) |
781 | addString = i18n("Day after tomorrow"); | 789 | addString = i18n("Day after tomorrow"); |
782 | if ( !addString.isEmpty() ) { | 790 | if ( !addString.isEmpty() ) { |
783 | str = addString+", " + str; | 791 | str = addString+", " + str; |
784 | } else { | 792 | } else { |
785 | str = KGlobal::locale()->formatDate( date, KOPrefs::instance()->mShortDateInViewer); | 793 | str = KGlobal::locale()->formatDate( date, KOPrefs::instance()->mShortDateInViewer); |
786 | } | 794 | } |
787 | } | 795 | } |
788 | dayLabel->setText(str); | 796 | dayLabel->setText(str); |
789 | //dayLabel->setAlignment(QLabel::AlignHCenter); | 797 | //dayLabel->setAlignment(QLabel::AlignHCenter); |
790 | if (date == QDate::currentDate()) { | 798 | if (date == QDate::currentDate()) { |
791 | QFont bFont = dlf; | 799 | QFont bFont = dlf; |
792 | bFont.setBold( true ); | 800 | bFont.setBold( true ); |
793 | dayLabel->setFont(bFont); | 801 | dayLabel->setFont(bFont); |
794 | } | 802 | } |
795 | //dayLayout->addWidget(dayLabel); | 803 | //dayLayout->addWidget(dayLabel); |
796 | 804 | ||
797 | #ifndef KORG_NOPLUGINS | 805 | #ifndef KORG_NOPLUGINS |
798 | CalendarDecoration::List cds = KOCore::self()->calendarDecorations(); | 806 | CalendarDecoration::List cds = KOCore::self()->calendarDecorations(); |
799 | CalendarDecoration *it; | 807 | CalendarDecoration *it; |
800 | for(it = cds.first(); it; it = cds.next()) { | 808 | for(it = cds.first(); it; it = cds.next()) { |
801 | QString text = it->shortText( date ); | 809 | QString text = it->shortText( date ); |
802 | if ( !text.isEmpty() ) { | 810 | if ( !text.isEmpty() ) { |
803 | QLabel *label = new QLabel(text,mDayLabels); | 811 | QLabel *label = new QLabel(text,mDayLabels); |
804 | label->setAlignment(AlignCenter); | 812 | label->setAlignment(AlignCenter); |
805 | dayLayout->addWidget(label); | 813 | dayLayout->addWidget(label); |
806 | } | 814 | } |
807 | } | 815 | } |
808 | 816 | ||
809 | for(it = cds.first(); it; it = cds.next()) { | 817 | for(it = cds.first(); it; it = cds.next()) { |
810 | QWidget *wid = it->smallWidget(mDayLabels,date); | 818 | QWidget *wid = it->smallWidget(mDayLabels,date); |
811 | if ( wid ) { | 819 | if ( wid ) { |
812 | // wid->setHeight(20); | 820 | // wid->setHeight(20); |
813 | dayLayout->addWidget(wid); | 821 | dayLayout->addWidget(wid); |
814 | } | 822 | } |
815 | } | 823 | } |
816 | #endif | 824 | #endif |
817 | } | 825 | } |
818 | if ( ! appendLabels ) { | 826 | if ( ! appendLabels ) { |
819 | dayLabel = mDayLabelsList.next(); | 827 | dayLabel = mDayLabelsList.next(); |
820 | if ( !dayLabel ) | 828 | if ( !dayLabel ) |
821 | appendLabels = true; | 829 | appendLabels = true; |
822 | } | 830 | } |
823 | if ( appendLabels ) { | 831 | if ( appendLabels ) { |
824 | dayLabel = getNewDaylabel(); | 832 | dayLabel = getNewDaylabel(); |
825 | } | 833 | } |
826 | //dayLabel->hide();//test only | 834 | //dayLabel->hide();//test only |
827 | qDebug("fremwidd %d ", mAgenda->frameWidth()); | 835 | qDebug("fremwidd %d ", mAgenda->frameWidth()); |
828 | int offset = (mAgenda->width() - mAgenda->verticalScrollBar()->width()- (mAgenda->frameWidth()*2) ) % mSelectedDates.count() ; | 836 | int offset = (mAgenda->width() - mAgenda->verticalScrollBar()->width()- (mAgenda->frameWidth()*2) ) % mSelectedDates.count() ; |
829 | if ( offset < 0 ) offset = 0; | 837 | if ( offset < 0 ) offset = 0; |
830 | //qDebug("mLayoutDayLabels->addSpacing %d ", mAgenda->verticalScrollBar()->width()+offset+2 ); | 838 | //qDebug("mLayoutDayLabels->addSpacing %d ", mAgenda->verticalScrollBar()->width()+offset+2 ); |
831 | dayLabel->setText(">");//QString::number ( mSelectedDates.first().month() ) ); | 839 | dayLabel->setText(">");//QString::number ( mSelectedDates.first().month() ) ); |
832 | dayLabel->setFont( dlf ); | 840 | dayLabel->setFont( dlf ); |
833 | dayLabel->setAutoRepeat( true ); | 841 | dayLabel->setAutoRepeat( true ); |
834 | dayLabel->show(); | 842 | dayLabel->show(); |
835 | dayLabel->setNum( -2 ); | 843 | dayLabel->setNum( -2 ); |
836 | dayLabel->setFixedWidth( mAgenda->verticalScrollBar()->width()+ offset ); | 844 | dayLabel->setFixedWidth( mAgenda->verticalScrollBar()->width()+ offset ); |
837 | //qDebug("setToFixed %d ", mAgenda->verticalScrollBar()->width()+ offset+2); | 845 | //qDebug("setToFixed %d ", mAgenda->verticalScrollBar()->width()+ offset+2); |
838 | //mLayoutDayLabels->addSpacing(mAgenda->verticalScrollBar()->width()+ offset+2); | 846 | //mLayoutDayLabels->addSpacing(mAgenda->verticalScrollBar()->width()+ offset+2); |
839 | if ( !appendLabels ) { | 847 | if ( !appendLabels ) { |
840 | dayLabel = mDayLabelsList.next(); | 848 | dayLabel = mDayLabelsList.next(); |
841 | while ( dayLabel ) { | 849 | while ( dayLabel ) { |
842 | //qDebug("!dayLabel %d",dayLabel ); | 850 | //qDebug("!dayLabel %d",dayLabel ); |
843 | dayLabel->hide(); | 851 | dayLabel->hide(); |
844 | dayLabel = mDayLabelsList.next(); | 852 | dayLabel = mDayLabelsList.next(); |
845 | } | 853 | } |
846 | } | 854 | } |
847 | 855 | ||
848 | mDayLabelsFrame->setFixedHeight( newHight + 4 ); | 856 | mDayLabelsFrame->setFixedHeight( newHight + 4 ); |
849 | } | 857 | } |
850 | 858 | ||
851 | int KOAgendaView::maxDatesHint() | 859 | int KOAgendaView::maxDatesHint() |
852 | { | 860 | { |
853 | // Not sure about the max number of events, so return 0 for now. | 861 | // Not sure about the max number of events, so return 0 for now. |
854 | return 0; | 862 | return 0; |
855 | } | 863 | } |
856 | 864 | ||
857 | int KOAgendaView::currentDateCount() | 865 | int KOAgendaView::currentDateCount() |
858 | { | 866 | { |
859 | return mSelectedDates.count(); | 867 | return mSelectedDates.count(); |
860 | } | 868 | } |
861 | 869 | ||
862 | QPtrList<Incidence> KOAgendaView::selectedIncidences() | 870 | QPtrList<Incidence> KOAgendaView::selectedIncidences() |
863 | { | 871 | { |
864 | QPtrList<Incidence> selected; | 872 | QPtrList<Incidence> selected; |
865 | Incidence *incidence; | 873 | Incidence *incidence; |
866 | 874 | ||
867 | incidence = mAgenda->selectedIncidence(); | 875 | incidence = mAgenda->selectedIncidence(); |
868 | if (incidence) selected.append(incidence); | 876 | if (incidence) selected.append(incidence); |
869 | 877 | ||
870 | incidence = mAllDayAgenda->selectedIncidence(); | 878 | incidence = mAllDayAgenda->selectedIncidence(); |
871 | if (incidence) selected.append(incidence); | 879 | if (incidence) selected.append(incidence); |
872 | 880 | ||
873 | return selected; | 881 | return selected; |
874 | } | 882 | } |
875 | 883 | ||
876 | DateList KOAgendaView::selectedDates() | 884 | DateList KOAgendaView::selectedDates() |
877 | { | 885 | { |
878 | DateList selected; | 886 | DateList selected; |
879 | QDate qd; | 887 | QDate qd; |
880 | 888 | ||
881 | qd = mAgenda->selectedIncidenceDate(); | 889 | qd = mAgenda->selectedIncidenceDate(); |
882 | if (qd.isValid()) selected.append(qd); | 890 | if (qd.isValid()) selected.append(qd); |
883 | 891 | ||
884 | qd = mAllDayAgenda->selectedIncidenceDate(); | 892 | qd = mAllDayAgenda->selectedIncidenceDate(); |
885 | if (qd.isValid()) selected.append(qd); | 893 | if (qd.isValid()) selected.append(qd); |
886 | 894 | ||
887 | return selected; | 895 | return selected; |
888 | } | 896 | } |
889 | 897 | ||
890 | 898 | ||
891 | void KOAgendaView::updateView() | 899 | void KOAgendaView::updateView() |
892 | { | 900 | { |
893 | if ( mBlockUpdating ) | 901 | if ( mBlockUpdating ) |
894 | return; | 902 | return; |
895 | // kdDebug() << "KOAgendaView::updateView()" << endl; | 903 | // kdDebug() << "KOAgendaView::updateView()" << endl; |
896 | fillAgenda(); | 904 | fillAgenda(); |
897 | 905 | ||
898 | } | 906 | } |
899 | 907 | ||
900 | 908 | ||
901 | /* | 909 | /* |
902 | Update configuration settings for the agenda view. This method is not | 910 | Update configuration settings for the agenda view. This method is not |
903 | complete. | 911 | complete. |
904 | */ | 912 | */ |
905 | void KOAgendaView::updateConfig() | 913 | void KOAgendaView::updateConfig() |
906 | { | 914 | { |
907 | if ( mBlockUpdating ) | 915 | if ( mBlockUpdating ) |
908 | return; | 916 | return; |
909 | if ( mAgenda->height() > 96 * KOPrefs::instance()->mHourSize ) { | 917 | if ( mAgenda->height() > 96 * KOPrefs::instance()->mHourSize ) { |
910 | int old = KOPrefs::instance()->mHourSize; | 918 | int old = KOPrefs::instance()->mHourSize; |
911 | KOPrefs::instance()->mHourSize = mAgenda->height()/96 +1; | 919 | KOPrefs::instance()->mHourSize = mAgenda->height()/96 +1; |
912 | qDebug("KOPrefs::instance()->mHourSize adjusted %d to %d ", old,KOPrefs::instance()->mHourSize ); | 920 | qDebug("KOPrefs::instance()->mHourSize adjusted %d to %d ", old,KOPrefs::instance()->mHourSize ); |
913 | } | 921 | } |
914 | 922 | ||
915 | 923 | ||
916 | // update config for children | 924 | // update config for children |
917 | mTimeLabels->updateConfig(); | 925 | mTimeLabels->updateConfig(); |
918 | mAgenda->storePosition(); | 926 | mAgenda->storePosition(); |
919 | mAgenda->updateConfig(); | 927 | mAgenda->updateConfig(); |
920 | mAllDayAgenda->updateConfig(); | 928 | mAllDayAgenda->updateConfig(); |
921 | // widget synchronization | 929 | // widget synchronization |
922 | //TODO: find a better way, maybe signal/slot | 930 | //TODO: find a better way, maybe signal/slot |
923 | mTimeLabels->positionChanged(); | 931 | mTimeLabels->positionChanged(); |
924 | 932 | ||
925 | // for some reason, this needs to be called explicitly | 933 | // for some reason, this needs to be called explicitly |
926 | mTimeLabels->repaint(); | 934 | mTimeLabels->repaint(); |
927 | 935 | ||
928 | mDummyAllDayLeft->setFixedWidth(mTimeLabels->width()); | 936 | mDummyAllDayLeft->setFixedWidth(mTimeLabels->width()); |
929 | 937 | ||
930 | // ToolTips displaying summary of events | 938 | // ToolTips displaying summary of events |
931 | KOAgendaItem::toolTipGroup()->setEnabled(KOPrefs::instance() | 939 | KOAgendaItem::toolTipGroup()->setEnabled(KOPrefs::instance() |
932 | ->mEnableToolTips); | 940 | ->mEnableToolTips); |
933 | 941 | ||
934 | //setHolidayMasks(); | 942 | //setHolidayMasks(); |
935 | 943 | ||
936 | //createDayLabels(); called by via updateView(); | 944 | //createDayLabels(); called by via updateView(); |
937 | mEventIndicatorTop->setXOffset(mTimeLabels->width() + mAgenda->frameWidth()); | 945 | mEventIndicatorTop->setXOffset(mTimeLabels->width() + mAgenda->frameWidth()); |
938 | updateView(); | 946 | updateView(); |
939 | mAgenda->restorePosition(); | 947 | mAgenda->restorePosition(); |
940 | } | 948 | } |
941 | 949 | ||
942 | 950 | ||
943 | void KOAgendaView::updateEventDates(KOAgendaItem *item, int type) | 951 | void KOAgendaView::updateEventDates(KOAgendaItem *item, int type) |
944 | { | 952 | { |
945 | // kdDebug() << "KOAgendaView::updateEventDates(): " << item->text() << endl; | 953 | // kdDebug() << "KOAgendaView::updateEventDates(): " << item->text() << endl; |
946 | //qDebug("KOAgendaView::updateEventDates "); | 954 | //qDebug("KOAgendaView::updateEventDates "); |
947 | QDateTime startDt,endDt; | 955 | QDateTime startDt,endDt; |
948 | QDate startDate; | 956 | QDate startDate; |
949 | int lenInSecs; | 957 | int lenInSecs; |
950 | // if ( type == KOAgenda::RESIZETOP ) | 958 | // if ( type == KOAgenda::RESIZETOP ) |
951 | // qDebug("RESIZETOP "); | 959 | // qDebug("RESIZETOP "); |
952 | // if ( type == KOAgenda::RESIZEBOTTOM ) | 960 | // if ( type == KOAgenda::RESIZEBOTTOM ) |
953 | // qDebug("RESIZEBOTTOM "); | 961 | // qDebug("RESIZEBOTTOM "); |
954 | // if ( type == KOAgenda::MOVE ) | 962 | // if ( type == KOAgenda::MOVE ) |
955 | // qDebug("MOVE "); | 963 | // qDebug("MOVE "); |
956 | if ( item->incidence()->type() == "Event" ) { | 964 | if ( item->incidence()->type() == "Event" ) { |
957 | startDt =item->incidence()->dtStart(); | 965 | startDt =item->incidence()->dtStart(); |
958 | endDt = item->incidence()->dtEnd(); | 966 | endDt = item->incidence()->dtEnd(); |
959 | lenInSecs = startDt.secsTo( endDt ); | 967 | lenInSecs = startDt.secsTo( endDt ); |
960 | } | 968 | } |
961 | 969 | ||
962 | // emit incidenceItemChanged( item->incidence(), KOGlobals::EVENTEDITED ); | 970 | // emit incidenceItemChanged( item->incidence(), KOGlobals::EVENTEDITED ); |
963 | 971 | ||
964 | if ( item->incidence()->type()=="Todo" && item->mLastMoveXPos > 0 ) { | 972 | if ( item->incidence()->type()=="Todo" && item->mLastMoveXPos > 0 ) { |
965 | startDate = mSelectedDates[item->mLastMoveXPos]; | 973 | startDate = mSelectedDates[item->mLastMoveXPos]; |
966 | } else { | 974 | } else { |
967 | if (item->cellX() < 0) { | 975 | if (item->cellX() < 0) { |
968 | startDate = (mSelectedDates.first()).addDays(item->cellX()); | 976 | startDate = (mSelectedDates.first()).addDays(item->cellX()); |
969 | } else { | 977 | } else { |
970 | startDate = mSelectedDates[item->cellX()]; | 978 | startDate = mSelectedDates[item->cellX()]; |
971 | } | 979 | } |
972 | } | 980 | } |
973 | startDt.setDate(startDate); | 981 | startDt.setDate(startDate); |
974 | 982 | ||
975 | if (item->incidence()->doesFloat()) { | 983 | if (item->incidence()->doesFloat()) { |
976 | endDt.setDate(startDate.addDays(item->cellWidth() - 1)); | 984 | endDt.setDate(startDate.addDays(item->cellWidth() - 1)); |
977 | } else { | 985 | } else { |
978 | if ( type == KOAgenda::RESIZETOP || type == KOAgenda::MOVE ) | 986 | if ( type == KOAgenda::RESIZETOP || type == KOAgenda::MOVE ) |
979 | startDt.setTime(mAgenda->gyToTime(item->cellYTop())); | 987 | startDt.setTime(mAgenda->gyToTime(item->cellYTop())); |
980 | if ( item->incidence()->type() == "Event" ) { | 988 | if ( item->incidence()->type() == "Event" ) { |
981 | if ( type == KOAgenda::MOVE ) { | 989 | if ( type == KOAgenda::MOVE ) { |
982 | endDt = startDt.addSecs(lenInSecs); | 990 | endDt = startDt.addSecs(lenInSecs); |
983 | 991 | ||
984 | } else if ( type == KOAgenda::RESIZEBOTTOM ) { | 992 | } else if ( type == KOAgenda::RESIZEBOTTOM ) { |
985 | if (item->lastMultiItem()) { | 993 | if (item->lastMultiItem()) { |
986 | endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1)); | 994 | endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1)); |
987 | endDt.setDate(startDate. | 995 | endDt.setDate(startDate. |
988 | addDays(item->lastMultiItem()->cellX() - item->cellX())); | 996 | addDays(item->lastMultiItem()->cellX() - item->cellX())); |
989 | } else { | 997 | } else { |
990 | endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1)); | 998 | endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1)); |
991 | endDt.setDate(startDate); | 999 | endDt.setDate(startDate); |
992 | } | 1000 | } |
993 | } | 1001 | } |
994 | } else { | 1002 | } else { |
995 | // todo | 1003 | // todo |
996 | if (item->lastMultiItem()) { | 1004 | if (item->lastMultiItem()) { |
997 | endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1)); | 1005 | endDt.setTime(mAgenda->gyToTime(item->lastMultiItem()->cellYBottom()+1)); |
998 | endDt.setDate(startDate. | 1006 | endDt.setDate(startDate. |
999 | addDays(item->lastMultiItem()->cellX() - item->cellX())); | 1007 | addDays(item->lastMultiItem()->cellX() - item->cellX())); |
1000 | } else { | 1008 | } else { |
1001 | //qDebug("tem->cellYBottom() %d",item->cellYBottom() ); | 1009 | //qDebug("tem->cellYBottom() %d",item->cellYBottom() ); |
1002 | if ( item->cellYBottom() > 0 ) | 1010 | if ( item->cellYBottom() > 0 ) |
1003 | endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1)); | 1011 | endDt.setTime(mAgenda->gyToTime(item->cellYBottom()+1)); |
1004 | else | 1012 | else |
1005 | endDt.setTime((static_cast<Todo*>(item->incidence()))->dtDue().time()); | 1013 | endDt.setTime((static_cast<Todo*>(item->incidence()))->dtDue().time()); |
1006 | endDt.setDate(startDate); | 1014 | endDt.setDate(startDate); |
1007 | } | 1015 | } |
1008 | } | 1016 | } |
1009 | } | 1017 | } |
1010 | if ( item->incidence()->type() == "Event" ) { | 1018 | if ( item->incidence()->type() == "Event" ) { |
1011 | item->incidence()->setDtStart(startDt); | 1019 | item->incidence()->setDtStart(startDt); |
1012 | (static_cast<Event*>(item->incidence()))->setDtEnd(endDt); | 1020 | (static_cast<Event*>(item->incidence()))->setDtEnd(endDt); |
1013 | } else if ( item->incidence()->type() == "Todo" ) { | 1021 | } else if ( item->incidence()->type() == "Todo" ) { |
1014 | Todo* to = static_cast<Todo*>(item->incidence()); | 1022 | Todo* to = static_cast<Todo*>(item->incidence()); |
1015 | 1023 | ||
1016 | to->setDtDue(endDt); | 1024 | to->setDtDue(endDt); |
1017 | if ( to->hasStartDate() ) { | 1025 | if ( to->hasStartDate() ) { |
1018 | if (to->dtStart() >= to->dtDue() ) | 1026 | if (to->dtStart() >= to->dtDue() ) |
1019 | to->setDtStart(to->dtDue().addDays( -2 )); | 1027 | to->setDtStart(to->dtDue().addDays( -2 )); |
1020 | } | 1028 | } |
1021 | 1029 | ||
1022 | } | 1030 | } |
1023 | //qDebug("KOAgendaView::updateEventDates stsart %s end %s ", startDt.toString().latin1(), endDt.toString().latin1() ); | 1031 | //qDebug("KOAgendaView::updateEventDates stsart %s end %s ", startDt.toString().latin1(), endDt.toString().latin1() ); |
1024 | item->incidence()->setRevision(item->incidence()->revision()+1); | 1032 | item->incidence()->setRevision(item->incidence()->revision()+1); |
1025 | item->setItemDate(startDt.date()); | 1033 | item->setItemDate(startDt.date()); |
1026 | //item->updateItem(); | 1034 | //item->updateItem(); |
1027 | if ( item->incidence()->type() == "Todo" ) { | 1035 | if ( item->incidence()->type() == "Todo" ) { |
1028 | emit todoMoved((Todo*)item->incidence(), KOGlobals::EVENTEDITED ); | 1036 | emit todoMoved((Todo*)item->incidence(), KOGlobals::EVENTEDITED ); |
1029 | 1037 | ||
1030 | } | 1038 | } |
1031 | else | 1039 | else |
1032 | emit incidenceChanged(item->incidence(), KOGlobals::EVENTEDITED); | 1040 | emit incidenceChanged(item->incidence(), KOGlobals::EVENTEDITED); |
1033 | item->updateItem(); | 1041 | item->updateItem(); |
1034 | } | 1042 | } |
1035 | 1043 | ||
1036 | void KOAgendaView::showDates( const QDate &start, const QDate &end ) | 1044 | void KOAgendaView::showDates( const QDate &start, const QDate &end ) |
1037 | { | 1045 | { |
1038 | // kdDebug() << "KOAgendaView::selectDates" << endl; | 1046 | // kdDebug() << "KOAgendaView::selectDates" << endl; |
1039 | 1047 | ||
1040 | mSelectedDates.clear(); | 1048 | mSelectedDates.clear(); |
1041 | // qDebug("KOAgendaView::showDates "); | 1049 | // qDebug("KOAgendaView::showDates "); |
1042 | QDate d = start; | 1050 | QDate d = start; |
1043 | while (d <= end) { | 1051 | while (d <= end) { |
1044 | mSelectedDates.append(d); | 1052 | mSelectedDates.append(d); |
1045 | d = d.addDays( 1 ); | 1053 | d = d.addDays( 1 ); |
1046 | } | 1054 | } |
1047 | 1055 | ||
1048 | // and update the view | 1056 | // and update the view |
1049 | fillAgenda(); | 1057 | fillAgenda(); |
1050 | } | 1058 | } |
1051 | 1059 | ||
1052 | 1060 | ||
1053 | void KOAgendaView::showEvents(QPtrList<Event>) | 1061 | void KOAgendaView::showEvents(QPtrList<Event>) |
1054 | { | 1062 | { |
1055 | kdDebug() << "KOAgendaView::showEvents() is not yet implemented" << endl; | 1063 | kdDebug() << "KOAgendaView::showEvents() is not yet implemented" << endl; |
1056 | } | 1064 | } |
1057 | 1065 | ||
1058 | void KOAgendaView::changeEventDisplay(Event *, int) | 1066 | void KOAgendaView::changeEventDisplay(Event *, int) |
1059 | { | 1067 | { |
1060 | // qDebug("KOAgendaView::changeEventDisplay "); | 1068 | // qDebug("KOAgendaView::changeEventDisplay "); |
1061 | // kdDebug() << "KOAgendaView::changeEventDisplay" << endl; | 1069 | // kdDebug() << "KOAgendaView::changeEventDisplay" << endl; |
1062 | // this should be re-written to be MUCH smarter. Right now we | 1070 | // this should be re-written to be MUCH smarter. Right now we |
1063 | // are just playing dumb. | 1071 | // are just playing dumb. |
1064 | fillAgenda(); | 1072 | fillAgenda(); |
1065 | } | 1073 | } |
1066 | 1074 | ||
1067 | void KOAgendaView::fillAgenda(const QDate &) | 1075 | void KOAgendaView::fillAgenda(const QDate &) |
1068 | { | 1076 | { |
1069 | // qDebug("KOAgendaView::fillAgenda "); | 1077 | // qDebug("KOAgendaView::fillAgenda "); |
1070 | fillAgenda(); | 1078 | fillAgenda(); |
1071 | } | 1079 | } |
1072 | 1080 | ||
1073 | void KOAgendaView::fillAgenda() | 1081 | void KOAgendaView::fillAgenda() |
1074 | { | 1082 | { |
1075 | if ( globalFlagBlockStartup ) | 1083 | if ( globalFlagBlockStartup ) |
1076 | return; | 1084 | return; |
1077 | if ( globalFlagBlockAgenda == 1 ) | 1085 | if ( globalFlagBlockAgenda == 1 ) |
1078 | return; | 1086 | return; |
1079 | static bool onlyOne = false; | 1087 | static bool onlyOne = false; |
1080 | if ( onlyOne ) | 1088 | if ( onlyOne ) |
1081 | return; | 1089 | return; |
1082 | onlyOne = true; | 1090 | onlyOne = true; |
1083 | //if ( globalFlagBlockAgenda == 2 ) | 1091 | //if ( globalFlagBlockAgenda == 2 ) |
1084 | //globalFlagBlockAgenda = 0; | 1092 | //globalFlagBlockAgenda = 0; |
1085 | // globalFlagBlockPainting = false; | 1093 | // globalFlagBlockPainting = false; |
1086 | if ( globalFlagBlockAgenda == 0 ) | 1094 | if ( globalFlagBlockAgenda == 0 ) |
1087 | globalFlagBlockAgenda = 1; | 1095 | globalFlagBlockAgenda = 1; |
1088 | // clearView(); | 1096 | // clearView(); |
1089 | //qDebug("fillAgenda()++++ "); | 1097 | //qDebug("fillAgenda()++++ "); |
1090 | globalFlagBlockAgendaItemPaint = 1; | 1098 | globalFlagBlockAgendaItemPaint = 1; |
1091 | 1099 | ||
1092 | mAllDayAgenda->changeColumns(mSelectedDates.count()); | 1100 | mAllDayAgenda->changeColumns(mSelectedDates.count()); |
1093 | mAgenda->changeColumns(mSelectedDates.count()); | 1101 | mAgenda->changeColumns(mSelectedDates.count()); |
1094 | qApp->processEvents(); | 1102 | qApp->processEvents(); |
1095 | mEventIndicatorTop->changeColumns(mSelectedDates.count()); | 1103 | mEventIndicatorTop->changeColumns(mSelectedDates.count()); |
1096 | mEventIndicatorBottom->changeColumns(mSelectedDates.count()); | 1104 | mEventIndicatorBottom->changeColumns(mSelectedDates.count()); |
1097 | setHolidayMasks(); | 1105 | setHolidayMasks(); |
1098 | 1106 | ||
1099 | //mAgenda->hideUnused(); | 1107 | //mAgenda->hideUnused(); |
1100 | //mAllDayAgenda->hideUnused(); | 1108 | //mAllDayAgenda->hideUnused(); |
1101 | 1109 | ||
1102 | // mAgenda->blockNextRepaint( false ); | 1110 | // mAgenda->blockNextRepaint( false ); |
1103 | // mAgenda->viewport()->repaint(); | 1111 | // mAgenda->viewport()->repaint(); |
1104 | // mAgenda->blockNextRepaint( true ); | 1112 | // mAgenda->blockNextRepaint( true ); |
1105 | mMinY.resize(mSelectedDates.count()); | 1113 | mMinY.resize(mSelectedDates.count()); |
1106 | mMaxY.resize(mSelectedDates.count()); | 1114 | mMaxY.resize(mSelectedDates.count()); |
1107 | 1115 | ||
1108 | QPtrList<Event> dayEvents; | 1116 | QPtrList<Event> dayEvents; |
1109 | 1117 | ||
1110 | // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue. | 1118 | // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue. |
1111 | // Therefore, gtodoset all of them. | 1119 | // Therefore, gtodoset all of them. |
1112 | QPtrList<Todo> todos = calendar()->todos(); | 1120 | QPtrList<Todo> todos = calendar()->todos(); |
1113 | 1121 | ||
1114 | mAgenda->setDateList(mSelectedDates); | 1122 | mAgenda->setDateList(mSelectedDates); |
1115 | 1123 | ||
1116 | QDate today = QDate::currentDate(); | 1124 | QDate today = QDate::currentDate(); |
1117 | 1125 | ||
1118 | DateList::ConstIterator dit; | 1126 | DateList::ConstIterator dit; |
1119 | int curCol = 0; | 1127 | int curCol = 0; |
1120 | for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) { | 1128 | for( dit = mSelectedDates.begin(); dit != mSelectedDates.end(); ++dit ) { |
1121 | QDate currentDate = *dit; | 1129 | QDate currentDate = *dit; |
1122 | // kdDebug() << "KOAgendaView::fillAgenda(): " << currentDate.toString() | 1130 | // kdDebug() << "KOAgendaView::fillAgenda(): " << currentDate.toString() |
1123 | // << endl; | 1131 | // << endl; |
1124 | 1132 | ||
1125 | dayEvents = calendar()->events(currentDate,true); | 1133 | dayEvents = calendar()->events(currentDate,true); |
1126 | 1134 | ||
1127 | // Default values, which can never be reached | 1135 | // Default values, which can never be reached |
1128 | mMinY[curCol] = mAgenda->timeToY(QTime(23,59)) + 1; | 1136 | mMinY[curCol] = mAgenda->timeToY(QTime(23,59)) + 1; |
1129 | mMaxY[curCol] = mAgenda->timeToY(QTime(0,0)) - 1; | 1137 | mMaxY[curCol] = mAgenda->timeToY(QTime(0,0)) - 1; |
1130 | 1138 | ||
1131 | unsigned int numEvent; | 1139 | unsigned int numEvent; |
1132 | for(numEvent=0;numEvent<dayEvents.count();++numEvent) { | 1140 | for(numEvent=0;numEvent<dayEvents.count();++numEvent) { |
1133 | Event *event = dayEvents.at(numEvent); | 1141 | Event *event = dayEvents.at(numEvent); |
1134 | if ( !KOPrefs::instance()->mShowSyncEvents && event->uid().left(2) == QString("la") ) | 1142 | if ( !KOPrefs::instance()->mShowSyncEvents && event->uid().left(2) == QString("la") ) |
1135 | if ( event->uid().left(15) == QString("last-syncEvent-") ) | 1143 | if ( event->uid().left(15) == QString("last-syncEvent-") ) |
1136 | continue; | 1144 | continue; |
1137 | // kdDebug() << " Event: " << event->summary() << endl; | 1145 | // kdDebug() << " Event: " << event->summary() << endl; |
1138 | 1146 | ||
1139 | int beginX = currentDate.daysTo(event->dtStart().date()) + curCol; | 1147 | int beginX = currentDate.daysTo(event->dtStart().date()) + curCol; |
1140 | int endX = currentDate.daysTo(event->dtEnd().date()) + curCol; | 1148 | int endX = currentDate.daysTo(event->dtEnd().date()) + curCol; |
1141 | 1149 | ||
1142 | // kdDebug() << " beginX: " << beginX << " endX: " << endX << endl; | 1150 | // kdDebug() << " beginX: " << beginX << " endX: " << endX << endl; |
1143 | 1151 | ||
1144 | if (event->doesFloat()) { | 1152 | if (event->doesFloat()) { |
1145 | if (event->recurrence()->doesRecur()) { | 1153 | if (event->recurrence()->doesRecur()) { |
1146 | mAllDayAgenda->insertAllDayItem(event,currentDate,curCol,curCol); | 1154 | mAllDayAgenda->insertAllDayItem(event,currentDate,curCol,curCol); |
1147 | } else { | 1155 | } else { |
1148 | if (beginX <= 0 && curCol == 0) { | 1156 | if (beginX <= 0 && curCol == 0) { |
1149 | mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX); | 1157 | mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX); |
1150 | } else if (beginX == curCol) { | 1158 | } else if (beginX == curCol) { |
1151 | mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX); | 1159 | mAllDayAgenda->insertAllDayItem(event,currentDate,beginX,endX); |
1152 | } | 1160 | } |
1153 | } | 1161 | } |
1154 | } else if (event->isMultiDay()) { | 1162 | } else if (event->isMultiDay()) { |
1155 | if ( event->doesRecur () ) { | 1163 | if ( event->doesRecur () ) { |
1156 | QDate dateit = currentDate; | 1164 | QDate dateit = currentDate; |
1157 | int count = 0; | 1165 | int count = 0; |
1158 | int max = event->dtStart().daysTo( event->dtEnd() ) +2; | 1166 | int max = event->dtStart().daysTo( event->dtEnd() ) +2; |
1159 | while (! event->recursOn( dateit ) && count <= max ) { | 1167 | while (! event->recursOn( dateit ) && count <= max ) { |
1160 | ++count; | 1168 | ++count; |
1161 | dateit = dateit.addDays( -1 ); | 1169 | dateit = dateit.addDays( -1 ); |
1162 | } | 1170 | } |
1163 | bool ok; | 1171 | bool ok; |
1164 | QDateTime nextOcstart = event->getNextOccurence( QDateTime(dateit) ,&ok ); | 1172 | QDateTime nextOcstart = event->getNextOccurence( QDateTime(dateit) ,&ok ); |
1165 | if ( ok ) | 1173 | if ( ok ) |
1166 | { | 1174 | { |
1167 | int secs = event->dtStart().secsTo( event->dtEnd() ); | 1175 | int secs = event->dtStart().secsTo( event->dtEnd() ); |
1168 | QDateTime nextOcend =nextOcstart.addSecs( secs ); ; | 1176 | QDateTime nextOcend =nextOcstart.addSecs( secs ); ; |
1169 | beginX = currentDate.daysTo(nextOcstart.date()) + curCol; | 1177 | beginX = currentDate.daysTo(nextOcstart.date()) + curCol; |
1170 | endX = currentDate.daysTo(nextOcend.date()) + curCol; | 1178 | endX = currentDate.daysTo(nextOcend.date()) + curCol; |
1171 | 1179 | ||
1172 | } | 1180 | } |
1173 | } | 1181 | } |
1174 | int startY = mAgenda->timeToY(event->dtStart().time()); | 1182 | int startY = mAgenda->timeToY(event->dtStart().time()); |
1175 | int endY = mAgenda->timeToY(event->dtEnd().time()) - 1; | 1183 | int endY = mAgenda->timeToY(event->dtEnd().time()) - 1; |
1176 | //qDebug("insert %d %d %d %d %d ",beginX,endX,startY,endY , curCol ); | 1184 | //qDebug("insert %d %d %d %d %d ",beginX,endX,startY,endY , curCol ); |
1177 | if ((beginX <= 0 && curCol == 0) || beginX == curCol) { | 1185 | if ((beginX <= 0 && curCol == 0) || beginX == curCol) { |
1178 | //qDebug("insert!!! "); | 1186 | //qDebug("insert!!! "); |
1179 | mAgenda->insertMultiItem(event,currentDate,beginX,endX,startY,endY); | 1187 | mAgenda->insertMultiItem(event,currentDate,beginX,endX,startY,endY); |
1180 | } | 1188 | } |
1181 | if (beginX == curCol) { | 1189 | if (beginX == curCol) { |
1182 | mMaxY[curCol] = mAgenda->timeToY(QTime(23,59)); | 1190 | mMaxY[curCol] = mAgenda->timeToY(QTime(23,59)); |
1183 | if (startY < mMinY[curCol]) mMinY[curCol] = startY; | 1191 | if (startY < mMinY[curCol]) mMinY[curCol] = startY; |
1184 | } else if (endX == curCol) { | 1192 | } else if (endX == curCol) { |
1185 | mMinY[curCol] = mAgenda->timeToY(QTime(0,0)); | 1193 | mMinY[curCol] = mAgenda->timeToY(QTime(0,0)); |
1186 | if (endY > mMaxY[curCol]) mMaxY[curCol] = endY; | 1194 | if (endY > mMaxY[curCol]) mMaxY[curCol] = endY; |
1187 | } else { | 1195 | } else { |
1188 | mMinY[curCol] = mAgenda->timeToY(QTime(0,0)); | 1196 | mMinY[curCol] = mAgenda->timeToY(QTime(0,0)); |
1189 | mMaxY[curCol] = mAgenda->timeToY(QTime(23,59)); | 1197 | mMaxY[curCol] = mAgenda->timeToY(QTime(23,59)); |
1190 | } | 1198 | } |
1191 | } else { | 1199 | } else { |
1192 | int startY = mAgenda->timeToY(event->dtStart().time()); | 1200 | int startY = mAgenda->timeToY(event->dtStart().time()); |
1193 | int endY = mAgenda->timeToY(event->dtEnd().time()) - 1; | 1201 | int endY = mAgenda->timeToY(event->dtEnd().time()) - 1; |
1194 | if (endY < startY) endY = startY; | 1202 | if (endY < startY) endY = startY; |
1195 | mAgenda->insertItem(event,currentDate,curCol,startY,endY); | 1203 | mAgenda->insertItem(event,currentDate,curCol,startY,endY); |
1196 | if (startY < mMinY[curCol]) mMinY[curCol] = startY; | 1204 | if (startY < mMinY[curCol]) mMinY[curCol] = startY; |
1197 | if (endY > mMaxY[curCol]) mMaxY[curCol] = endY; | 1205 | if (endY > mMaxY[curCol]) mMaxY[curCol] = endY; |
1198 | } | 1206 | } |
1199 | } | 1207 | } |
1200 | // ---------- [display Todos -------------- | 1208 | // ---------- [display Todos -------------- |
1201 | unsigned int numTodo; | 1209 | unsigned int numTodo; |
1202 | for (numTodo = 0; numTodo < todos.count(); ++numTodo) { | 1210 | for (numTodo = 0; numTodo < todos.count(); ++numTodo) { |
1203 | Todo *todo = todos.at(numTodo); | 1211 | Todo *todo = todos.at(numTodo); |
1204 | 1212 | ||
1205 | if ( ! todo->hasDueDate() && !todo->hasCompletedDate()) continue; // todo shall not be displayed if it has no date | 1213 | if ( ! todo->hasDueDate() && !todo->hasCompletedDate()) continue; // todo shall not be displayed if it has no date |
1206 | 1214 | ||
1207 | // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue. | 1215 | // ToDo items shall be displayed for the day they are due, but only showed today if they are already overdue. |
1208 | // Already completed items can be displayed on their original due date | 1216 | // Already completed items can be displayed on their original due date |
1209 | //if not KOPrefs::instance()->mShowTodoInAgenda, show overdue in agenda | 1217 | //if not KOPrefs::instance()->mShowTodoInAgenda, show overdue in agenda |
1210 | bool overdue = (!todo->isCompleted()) && (todo->dtDue() < today) && KOPrefs::instance()->mShowTodoInAgenda; | 1218 | bool overdue = (!todo->isCompleted()) && (todo->dtDue() < today) && KOPrefs::instance()->mShowTodoInAgenda; |
1211 | bool fillIn = false; | 1219 | bool fillIn = false; |
1212 | if ( todo->hasCompletedDate() && todo->completed().date() == currentDate ) | 1220 | if ( todo->hasCompletedDate() && todo->completed().date() == currentDate ) |
1213 | fillIn = true; | 1221 | fillIn = true; |
1214 | if ( ! fillIn && !todo->hasCompletedDate() ) | 1222 | if ( ! fillIn && !todo->hasCompletedDate() ) |
1215 | fillIn = ((todo->dtDue().date() == currentDate) && !overdue) || ((currentDate == today) && overdue); | 1223 | fillIn = ((todo->dtDue().date() == currentDate) && !overdue) || ((currentDate == today) && overdue); |
1216 | if ( fillIn ) { | 1224 | if ( fillIn ) { |
1217 | if ( (todo->doesFloat() || overdue ) && !todo->hasCompletedDate() ) { // Todo has no due-time set or is already overdue | 1225 | if ( (todo->doesFloat() || overdue ) && !todo->hasCompletedDate() ) { // Todo has no due-time set or is already overdue |
1218 | if ( KOPrefs::instance()->mShowTodoInAgenda ) | 1226 | if ( KOPrefs::instance()->mShowTodoInAgenda ) |
1219 | mAllDayAgenda->insertAllDayItem(todo, currentDate, curCol, curCol); | 1227 | mAllDayAgenda->insertAllDayItem(todo, currentDate, curCol, curCol); |
1220 | } | 1228 | } |
1221 | else { | 1229 | else { |
1222 | QDateTime dt; | 1230 | QDateTime dt; |
1223 | if ( todo->hasCompletedDate() ) | 1231 | if ( todo->hasCompletedDate() ) |
1224 | dt = todo->completed(); | 1232 | dt = todo->completed(); |
1225 | else | 1233 | else |
1226 | dt = todo->dtDue();; | 1234 | dt = todo->dtDue();; |
1227 | 1235 | ||
1228 | 1236 | ||
1229 | int endY = mAgenda->timeToY(dt.time()) - 1; | 1237 | int endY = mAgenda->timeToY(dt.time()) - 1; |
1230 | int hi = (18/KOPrefs::instance()->mHourSize); | 1238 | int hi = (18/KOPrefs::instance()->mHourSize); |
1231 | //qDebug("hei %d ",KOPrefs::instance()->mHourSize); | 1239 | //qDebug("hei %d ",KOPrefs::instance()->mHourSize); |
1232 | int startY = endY -hi; | 1240 | int startY = endY -hi; |
1233 | 1241 | ||
1234 | mAgenda->insertItem(todo,currentDate,curCol,startY,endY); | 1242 | mAgenda->insertItem(todo,currentDate,curCol,startY,endY); |
1235 | 1243 | ||
1236 | if (startY < mMinY[curCol]) mMinY[curCol] = startY; | 1244 | if (startY < mMinY[curCol]) mMinY[curCol] = startY; |
1237 | if (endY > mMaxY[curCol]) mMaxY[curCol] = endY; | 1245 | if (endY > mMaxY[curCol]) mMaxY[curCol] = endY; |
1238 | } | 1246 | } |
1239 | } | 1247 | } |
1240 | } | 1248 | } |
1241 | // ---------- display Todos] -------------- | 1249 | // ---------- display Todos] -------------- |
1242 | 1250 | ||
1243 | ++curCol; | 1251 | ++curCol; |
1244 | } | 1252 | } |
1245 | mAgenda->hideUnused(); | 1253 | mAgenda->hideUnused(); |
1246 | mAllDayAgenda->hideUnused(); | 1254 | mAllDayAgenda->hideUnused(); |
1247 | mAgenda->checkScrollBoundaries(); | 1255 | mAgenda->checkScrollBoundaries(); |
1248 | 1256 | ||
1249 | deleteSelectedDateTime(); | 1257 | deleteSelectedDateTime(); |
1250 | 1258 | ||
1251 | createDayLabels(); | 1259 | createDayLabels(); |
1252 | emit incidenceSelected( 0 ); | 1260 | emit incidenceSelected( 0 ); |
1253 | 1261 | ||
1254 | if ( globalFlagBlockAgenda == 2 ) { | 1262 | if ( globalFlagBlockAgenda == 2 ) { |
1255 | if ( KOPrefs::instance()->mSetTimeToDayStartAt ) | 1263 | if ( KOPrefs::instance()->mSetTimeToDayStartAt ) |
1256 | setStartHour( KOPrefs::instance()->mDayBegins ); | 1264 | setStartHour( KOPrefs::instance()->mDayBegins ); |
1257 | else if ( KOPrefs::instance()->mCenterOnCurrentTime ) | 1265 | else if ( KOPrefs::instance()->mCenterOnCurrentTime ) |
1258 | setStartHour( QTime::currentTime ().hour() ); | 1266 | setStartHour( QTime::currentTime ().hour() ); |
1259 | // qApp->processEvents(); | 1267 | // qApp->processEvents(); |
1260 | } | 1268 | } |
1261 | qApp->processEvents(); | 1269 | qApp->processEvents(); |
1262 | //qDebug("qApp->processEvents(); END "); | 1270 | //qDebug("qApp->processEvents(); END "); |
1263 | globalFlagBlockAgenda = 0; | 1271 | globalFlagBlockAgenda = 0; |
1264 | 1272 | ||
1265 | // mAgenda->hideUnused(); | 1273 | // mAgenda->hideUnused(); |
1266 | //mAllDayAgenda->hideUnused(); | 1274 | //mAllDayAgenda->hideUnused(); |
1267 | mAllDayAgenda->drawContentsToPainter(); | 1275 | mAllDayAgenda->drawContentsToPainter(); |
1268 | mAgenda->drawContentsToPainter(); | 1276 | mAgenda->drawContentsToPainter(); |
1269 | repaintAgenda(); | 1277 | repaintAgenda(); |
1270 | onlyOne = false; | 1278 | onlyOne = false; |
1271 | // mAgenda->finishUpdate(); | 1279 | // mAgenda->finishUpdate(); |
1272 | //mAllDayAgenda->finishUpdate(); | 1280 | //mAllDayAgenda->finishUpdate(); |
1273 | 1281 | ||
1274 | // repaintAgenda(); | 1282 | // repaintAgenda(); |
1275 | //qApp->processEvents(); | 1283 | //qApp->processEvents(); |
1276 | // globalFlagBlockAgenda = 0; | 1284 | // globalFlagBlockAgenda = 0; |
1277 | } | 1285 | } |
1278 | void KOAgendaView::repaintAgenda() | 1286 | void KOAgendaView::repaintAgenda() |
1279 | { | 1287 | { |
1280 | // mAllDayAgenda->drawContentsToPainter(); | 1288 | // mAllDayAgenda->drawContentsToPainter(); |
1281 | // mAllDayAgenda->viewport()->repaint( false ); | 1289 | // mAllDayAgenda->viewport()->repaint( false ); |
1282 | // mAgenda->drawContentsToPainter(); | 1290 | // mAgenda->drawContentsToPainter(); |
1283 | // mAgenda->viewport()->repaint( false ); | 1291 | // mAgenda->viewport()->repaint( false ); |
1284 | // qApp->processEvents(); | 1292 | // qApp->processEvents(); |
1285 | 1293 | ||
1286 | //qDebug("KOAgendaView::repaintAgenda() "); | 1294 | //qDebug("KOAgendaView::repaintAgenda() "); |
1287 | //qApp->processEvents(); | 1295 | //qApp->processEvents(); |
1288 | mAgenda->viewport()->repaint( false ); | 1296 | mAgenda->viewport()->repaint( false ); |
1289 | mAllDayAgenda->viewport()->repaint( false ); | 1297 | mAllDayAgenda->viewport()->repaint( false ); |
1290 | mAgenda->finishUpdate(); | 1298 | mAgenda->finishUpdate(); |
1291 | mAllDayAgenda->finishUpdate(); | 1299 | mAllDayAgenda->finishUpdate(); |
1292 | } | 1300 | } |
1293 | 1301 | ||
1294 | 1302 | ||
1295 | void KOAgendaView::clearView() | 1303 | void KOAgendaView::clearView() |
1296 | { | 1304 | { |
1297 | // kdDebug() << "ClearView" << endl; | 1305 | // kdDebug() << "ClearView" << endl; |
1298 | mAllDayAgenda->clear(); | 1306 | mAllDayAgenda->clear(); |
1299 | mAgenda->clear(); | 1307 | mAgenda->clear(); |
1300 | } | 1308 | } |
1301 | 1309 | ||
1302 | void KOAgendaView::printPreview(CalPrinter *calPrinter, const QDate &fd, | 1310 | void KOAgendaView::printPreview(CalPrinter *calPrinter, const QDate &fd, |
1303 | const QDate &td) | 1311 | const QDate &td) |
1304 | { | 1312 | { |
1305 | #ifndef KORG_NOPRINTER | 1313 | #ifndef KORG_NOPRINTER |
1306 | if (fd == td) | 1314 | if (fd == td) |
1307 | calPrinter->preview(CalPrinter::Day, fd, td); | 1315 | calPrinter->preview(CalPrinter::Day, fd, td); |
1308 | else | 1316 | else |
1309 | calPrinter->preview(CalPrinter::Week, fd, td); | 1317 | calPrinter->preview(CalPrinter::Week, fd, td); |
1310 | #endif | 1318 | #endif |
1311 | } | 1319 | } |
1312 | 1320 | ||
1313 | // void KOAgendaView::updateMovedTodo() | 1321 | // void KOAgendaView::updateMovedTodo() |
1314 | // { | 1322 | // { |
1315 | // // updateConfig(); | 1323 | // // updateConfig(); |
1316 | // // emit updateTodoViews(); | 1324 | // // emit updateTodoViews(); |
1317 | // } | 1325 | // } |
1318 | 1326 | ||
1319 | void KOAgendaView::slotShowDateView( int mode , int d ) | 1327 | void KOAgendaView::slotShowDateView( int mode , int d ) |
1320 | { | 1328 | { |
1321 | if ( d >= mSelectedDates.count() ) { | 1329 | if ( d >= mSelectedDates.count() ) { |
1322 | qDebug("KOAgendaView::slotShowDateView datecounterror %d d ", d, mSelectedDates.count() ); | 1330 | qDebug("KOAgendaView::slotShowDateView datecounterror %d d ", d, mSelectedDates.count() ); |
1323 | 1331 | ||
1324 | } else { | 1332 | } else { |
1325 | QDate day = mSelectedDates[d]; | 1333 | QDate day = mSelectedDates[d]; |
1326 | emit showDateView(mode , day ); | 1334 | emit showDateView(mode , day ); |
1327 | } | 1335 | } |
1328 | 1336 | ||
1329 | } | 1337 | } |
1330 | void KOAgendaView::newEvent(int gx, int gy) | 1338 | void KOAgendaView::newEvent(int gx, int gy) |
1331 | { | 1339 | { |
1332 | if (!mSelectedDates.count()) return; | 1340 | if (!mSelectedDates.count()) return; |
1333 | 1341 | ||
1334 | QDate day = mSelectedDates[gx]; | 1342 | QDate day = mSelectedDates[gx]; |
1335 | 1343 | ||
1336 | QTime time = mAgenda->gyToTime(gy); | 1344 | QTime time = mAgenda->gyToTime(gy); |
1337 | QDateTime dt(day,time); | 1345 | QDateTime dt(day,time); |
1338 | // if ( dt < QDateTime::currentDateTime () ) | 1346 | // if ( dt < QDateTime::currentDateTime () ) |
1339 | // dt = QDateTime::currentDateTime ().addSecs( 3600 ); | 1347 | // dt = QDateTime::currentDateTime ().addSecs( 3600 ); |
1340 | emit newEventSignal(dt); | 1348 | emit newEventSignal(dt); |
1341 | } | 1349 | } |
1342 | 1350 | ||
1343 | void KOAgendaView::newEvent(int gxStart, int gyStart, int gxEnd, int gyEnd) | 1351 | void KOAgendaView::newEvent(int gxStart, int gyStart, int gxEnd, int gyEnd) |
1344 | { | 1352 | { |
1345 | if (!mSelectedDates.count()) return; | 1353 | if (!mSelectedDates.count()) return; |
1346 | 1354 | ||
1347 | QDate dayStart = mSelectedDates[gxStart]; | 1355 | QDate dayStart = mSelectedDates[gxStart]; |
1348 | QDate dayEnd = mSelectedDates[gxEnd]; | 1356 | QDate dayEnd = mSelectedDates[gxEnd]; |
1349 | 1357 | ||
1350 | QTime timeStart = mAgenda->gyToTime(gyStart); | 1358 | QTime timeStart = mAgenda->gyToTime(gyStart); |
1351 | QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 ); | 1359 | QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 ); |
1352 | 1360 | ||
1353 | QDateTime dtStart(dayStart,timeStart); | 1361 | QDateTime dtStart(dayStart,timeStart); |
1354 | QDateTime dtEnd(dayEnd,timeEnd); | 1362 | QDateTime dtEnd(dayEnd,timeEnd); |
1355 | 1363 | ||
1356 | emit newEventSignal(dtStart,dtEnd); | 1364 | emit newEventSignal(dtStart,dtEnd); |
1357 | } | 1365 | } |
1358 | 1366 | ||
1359 | void KOAgendaView::newEventAllDay(int gx, int ) | 1367 | void KOAgendaView::newEventAllDay(int gx, int ) |
1360 | { | 1368 | { |
1361 | if (!mSelectedDates.count()) return; | 1369 | if (!mSelectedDates.count()) return; |
1362 | 1370 | ||
1363 | QDate day = mSelectedDates[gx]; | 1371 | QDate day = mSelectedDates[gx]; |
1364 | 1372 | ||
1365 | emit newEventSignal(day); | 1373 | emit newEventSignal(day); |
1366 | } | 1374 | } |
1367 | void KOAgendaView::newTodoAllDay(int gx, int ) | 1375 | void KOAgendaView::newTodoAllDay(int gx, int ) |
1368 | { | 1376 | { |
1369 | if (!mSelectedDates.count()) return; | 1377 | if (!mSelectedDates.count()) return; |
1370 | 1378 | ||
1371 | QDateTime day (mSelectedDates[gx] ); | 1379 | QDateTime day (mSelectedDates[gx] ); |
1372 | emit newTodoSignal(day, true); | 1380 | emit newTodoSignal(day, true); |
1373 | } | 1381 | } |
1374 | void KOAgendaView::newTodo(int gx, int gy ) | 1382 | void KOAgendaView::newTodo(int gx, int gy ) |
1375 | { | 1383 | { |
1376 | if (!mSelectedDates.count()) return; | 1384 | if (!mSelectedDates.count()) return; |
1377 | QDate dayStart = mSelectedDates[gx]; | 1385 | QDate dayStart = mSelectedDates[gx]; |
1378 | QTime timeStart = mAgenda->gyToTime(gy); | 1386 | QTime timeStart = mAgenda->gyToTime(gy); |
1379 | QDateTime dt (dayStart,timeStart); | 1387 | QDateTime dt (dayStart,timeStart); |
1380 | emit newTodoSignal( dt, false ); | 1388 | emit newTodoSignal( dt, false ); |
1381 | } | 1389 | } |
1382 | 1390 | ||
1383 | void KOAgendaView::updateEventIndicatorTop(int newY) | 1391 | void KOAgendaView::updateEventIndicatorTop(int newY) |
1384 | { | 1392 | { |
1385 | uint i; | 1393 | uint i; |
1386 | for(i=0;i<mMinY.size();++i) { | 1394 | for(i=0;i<mMinY.size();++i) { |
1387 | if (newY >= mMinY.at(i)) mEventIndicatorTop->enableColumn(i,true); | 1395 | if (newY >= mMinY.at(i)) mEventIndicatorTop->enableColumn(i,true); |
1388 | else mEventIndicatorTop->enableColumn(i,false); | 1396 | else mEventIndicatorTop->enableColumn(i,false); |
1389 | } | 1397 | } |
1390 | 1398 | ||
1391 | mEventIndicatorTop->update(); | 1399 | mEventIndicatorTop->update(); |
1392 | } | 1400 | } |
1393 | 1401 | ||
1394 | void KOAgendaView::updateEventIndicatorBottom(int newY) | 1402 | void KOAgendaView::updateEventIndicatorBottom(int newY) |
1395 | { | 1403 | { |
1396 | uint i; | 1404 | uint i; |
1397 | for(i=0;i<mMaxY.size();++i) { | 1405 | for(i=0;i<mMaxY.size();++i) { |
1398 | if (newY <= mMaxY.at(i)) mEventIndicatorBottom->enableColumn(i,true); | 1406 | if (newY <= mMaxY.at(i)) mEventIndicatorBottom->enableColumn(i,true); |
1399 | else mEventIndicatorBottom->enableColumn(i,false); | 1407 | else mEventIndicatorBottom->enableColumn(i,false); |
1400 | } | 1408 | } |
1401 | 1409 | ||
1402 | mEventIndicatorBottom->update(); | 1410 | mEventIndicatorBottom->update(); |
1403 | } | 1411 | } |
1404 | 1412 | ||
1405 | void KOAgendaView::startDrag(Event *event) | 1413 | void KOAgendaView::startDrag(Event *event) |
1406 | { | 1414 | { |
1407 | #ifndef KORG_NODND | 1415 | #ifndef KORG_NODND |
1408 | DndFactory factory( calendar() ); | 1416 | DndFactory factory( calendar() ); |
1409 | ICalDrag *vd = factory.createDrag(event,this); | 1417 | ICalDrag *vd = factory.createDrag(event,this); |
1410 | if (vd->drag()) { | 1418 | if (vd->drag()) { |
1411 | kdDebug() << "KOAgendaView::startDrag(): Delete drag source" << endl; | 1419 | kdDebug() << "KOAgendaView::startDrag(): Delete drag source" << endl; |
1412 | } | 1420 | } |
1413 | #endif | 1421 | #endif |
1414 | } | 1422 | } |
1415 | 1423 | ||
1416 | void KOAgendaView::readSettings() | 1424 | void KOAgendaView::readSettings() |
1417 | { | 1425 | { |
1418 | readSettings(KOGlobals::config()); | 1426 | readSettings(KOGlobals::config()); |
1419 | } | 1427 | } |
1420 | 1428 | ||
1421 | void KOAgendaView::readSettings(KConfig *config) | 1429 | void KOAgendaView::readSettings(KConfig *config) |
1422 | { | 1430 | { |
1423 | // kdDebug() << "KOAgendaView::readSettings()" << endl; | 1431 | // kdDebug() << "KOAgendaView::readSettings()" << endl; |
1424 | 1432 | ||
1425 | config->setGroup("Views"); | 1433 | config->setGroup("Views"); |
1426 | 1434 | ||
1427 | //#ifndef KORG_NOSPLITTER | 1435 | //#ifndef KORG_NOSPLITTER |
1428 | QValueList<int> sizes = config->readIntListEntry("Separator AgendaView"); | 1436 | QValueList<int> sizes = config->readIntListEntry("Separator AgendaView"); |
1429 | if (sizes.count() == 2) { | 1437 | if (sizes.count() == 2) { |
1430 | if ( sizes[0] < 20 ) { | 1438 | if ( sizes[0] < 20 ) { |
1431 | sizes[1] = sizes[1] +20 - sizes[0]; | 1439 | sizes[1] = sizes[1] +20 - sizes[0]; |
1432 | sizes[0] = 20; | 1440 | sizes[0] = 20; |
1433 | } | 1441 | } |
1434 | mSplitterAgenda->setSizes(sizes); | 1442 | mSplitterAgenda->setSizes(sizes); |
1435 | // qDebug("read %d %d ",sizes[0],sizes[1] ); | 1443 | // qDebug("read %d %d ",sizes[0],sizes[1] ); |
1436 | } | 1444 | } |
1437 | //#endif | 1445 | //#endif |
1438 | 1446 | ||
1439 | // updateConfig(); | 1447 | // updateConfig(); |
1440 | } | 1448 | } |
1441 | 1449 | ||
1442 | void KOAgendaView::writeSettings(KConfig *config) | 1450 | void KOAgendaView::writeSettings(KConfig *config) |
1443 | { | 1451 | { |
1444 | // kdDebug() << "KOAgendaView::writeSettings()" << endl; | 1452 | // kdDebug() << "KOAgendaView::writeSettings()" << endl; |
1445 | 1453 | ||
1446 | config->setGroup("Views"); | 1454 | config->setGroup("Views"); |
1447 | 1455 | ||
1448 | //#ifndef KORG_NOSPLITTER | 1456 | //#ifndef KORG_NOSPLITTER |
1449 | QValueList<int> list = mSplitterAgenda->sizes(); | 1457 | QValueList<int> list = mSplitterAgenda->sizes(); |
1450 | config->writeEntry("Separator AgendaView",list); | 1458 | config->writeEntry("Separator AgendaView",list); |
1451 | //qDebug("write %d %d ", list[0],list[1] ); | 1459 | //qDebug("write %d %d ", list[0],list[1] ); |
1452 | //#endif | 1460 | //#endif |
1453 | } | 1461 | } |
1454 | 1462 | ||
1455 | void KOAgendaView::setHolidayMasks() | 1463 | void KOAgendaView::setHolidayMasks() |
1456 | { | 1464 | { |
1457 | mHolidayMask.resize(mSelectedDates.count()); | 1465 | mHolidayMask.resize(mSelectedDates.count()); |
1458 | 1466 | ||
1459 | uint i; | 1467 | uint i; |
1460 | for(i=0;i<mSelectedDates.count();++i) { | 1468 | for(i=0;i<mSelectedDates.count();++i) { |
1461 | QDate date = mSelectedDates[i]; | 1469 | QDate date = mSelectedDates[i]; |
1462 | bool showSaturday = KOPrefs::instance()->mExcludeSaturdays && (date.dayOfWeek() == 6); | 1470 | bool showSaturday = KOPrefs::instance()->mExcludeSaturdays && (date.dayOfWeek() == 6); |
1463 | bool showSunday = KOPrefs::instance()->mExcludeHolidays && (date.dayOfWeek() == 7); | 1471 | bool showSunday = KOPrefs::instance()->mExcludeHolidays && (date.dayOfWeek() == 7); |
1464 | bool showHoliday = false; | 1472 | bool showHoliday = false; |
1465 | if ( KOPrefs::instance()->mExcludeHolidays ) { | 1473 | if ( KOPrefs::instance()->mExcludeHolidays ) { |
1466 | QPtrList<Event> events = calendar()->events( date, true ); | 1474 | QPtrList<Event> events = calendar()->events( date, true ); |
1467 | Event *event; | 1475 | Event *event; |
1468 | for( event = events.first(); event; event = events.next() ) { | 1476 | for( event = events.first(); event; event = events.next() ) { |
1469 | if ( event->isHoliday()) { | 1477 | if ( event->isHoliday()) { |
1470 | showHoliday = true; | 1478 | showHoliday = true; |
1471 | break; | 1479 | break; |
1472 | } | 1480 | } |
1473 | } | 1481 | } |
1474 | 1482 | ||
1475 | } | 1483 | } |
1476 | 1484 | ||
1477 | #ifndef KORG_NOPLUGINS | 1485 | #ifndef KORG_NOPLUGINS |
1478 | bool showHoliday = KOPrefs::instance()->mExcludeHolidays && | 1486 | bool showHoliday = KOPrefs::instance()->mExcludeHolidays && |
1479 | !KOCore::self()->holiday(date).isEmpty(); | 1487 | !KOCore::self()->holiday(date).isEmpty(); |
1480 | #endif | 1488 | #endif |
1481 | bool showDay = showSaturday || showSunday || showHoliday; | 1489 | bool showDay = showSaturday || showSunday || showHoliday; |
1482 | 1490 | ||
1483 | if (showDay) { | 1491 | if (showDay) { |
1484 | mHolidayMask.at(i) = true; | 1492 | mHolidayMask.at(i) = true; |
1485 | } else { | 1493 | } else { |
1486 | mHolidayMask.at(i) = false; | 1494 | mHolidayMask.at(i) = false; |
1487 | } | 1495 | } |
1488 | } | 1496 | } |
1489 | 1497 | ||
1490 | mAgenda->setHolidayMask(&mHolidayMask); | 1498 | mAgenda->setHolidayMask(&mHolidayMask); |
1491 | mAllDayAgenda->setHolidayMask(&mHolidayMask); | 1499 | mAllDayAgenda->setHolidayMask(&mHolidayMask); |
1492 | } | 1500 | } |
1493 | 1501 | ||
1494 | void KOAgendaView::setContentsPos(int y) | 1502 | void KOAgendaView::setContentsPos(int y) |
1495 | { | 1503 | { |
1496 | mAgenda->setContentsPos(0,y); | 1504 | mAgenda->setContentsPos(0,y); |
1497 | } | 1505 | } |
1498 | 1506 | ||
1499 | void KOAgendaView::clearSelection() | 1507 | void KOAgendaView::clearSelection() |
1500 | { | 1508 | { |
1501 | mAgenda->deselectItem(); | 1509 | mAgenda->deselectItem(); |
1502 | mAllDayAgenda->deselectItem(); | 1510 | mAllDayAgenda->deselectItem(); |
1503 | } | 1511 | } |
1504 | 1512 | ||
1505 | void KOAgendaView::newTimeSpanSelectedAllDay(int gxStart, int gyStart, | 1513 | void KOAgendaView::newTimeSpanSelectedAllDay(int gxStart, int gyStart, |
1506 | int gxEnd, int gyEnd) | 1514 | int gxEnd, int gyEnd) |
1507 | { | 1515 | { |
1508 | mTimeSpanInAllDay = true; | 1516 | mTimeSpanInAllDay = true; |
1509 | newTimeSpanSelected(gxStart,gyStart,gxEnd,gyEnd); | 1517 | newTimeSpanSelected(gxStart,gyStart,gxEnd,gyEnd); |
1510 | } | 1518 | } |
1511 | 1519 | ||
1512 | 1520 | ||
1513 | 1521 | ||
1514 | 1522 | ||
1515 | void KOAgendaView::newTimeSpanSelected(int gxStart, int gyStart, | 1523 | void KOAgendaView::newTimeSpanSelected(int gxStart, int gyStart, |
1516 | int gxEnd, int gyEnd) | 1524 | int gxEnd, int gyEnd) |
1517 | { | 1525 | { |
1518 | if (!mSelectedDates.count()) return; | 1526 | if (!mSelectedDates.count()) return; |
1519 | 1527 | ||
1520 | QDate dayStart = mSelectedDates[gxStart]; | 1528 | QDate dayStart = mSelectedDates[gxStart]; |
1521 | QDate dayEnd = mSelectedDates[gxEnd]; | 1529 | QDate dayEnd = mSelectedDates[gxEnd]; |
1522 | 1530 | ||
1523 | QTime timeStart = mAgenda->gyToTime(gyStart); | 1531 | QTime timeStart = mAgenda->gyToTime(gyStart); |
1524 | QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 ); | 1532 | QTime timeEnd = mAgenda->gyToTime( gyEnd + 1 ); |
1525 | 1533 | ||
1526 | QDateTime dtStart(dayStart,timeStart); | 1534 | QDateTime dtStart(dayStart,timeStart); |
1527 | QDateTime dtEnd(dayEnd,timeEnd); | 1535 | QDateTime dtEnd(dayEnd,timeEnd); |
1528 | 1536 | ||
1529 | mTimeSpanBegin = dtStart; | 1537 | mTimeSpanBegin = dtStart; |
1530 | mTimeSpanEnd = dtEnd; | 1538 | mTimeSpanEnd = dtEnd; |
1531 | 1539 | ||
1532 | } | 1540 | } |
1533 | 1541 | ||
1534 | void KOAgendaView::deleteSelectedDateTime() | 1542 | void KOAgendaView::deleteSelectedDateTime() |
1535 | { | 1543 | { |
1536 | mTimeSpanBegin.setDate(QDate()); | 1544 | mTimeSpanBegin.setDate(QDate()); |
1537 | mTimeSpanEnd.setDate(QDate()); | 1545 | mTimeSpanEnd.setDate(QDate()); |
1538 | mTimeSpanInAllDay = false; | 1546 | mTimeSpanInAllDay = false; |
1539 | } | 1547 | } |
1540 | 1548 | ||
1541 | void KOAgendaView::keyPressEvent ( QKeyEvent * e ) | 1549 | void KOAgendaView::keyPressEvent ( QKeyEvent * e ) |
1542 | { | 1550 | { |
1543 | e->ignore(); | 1551 | e->ignore(); |
1544 | } | 1552 | } |
1545 | 1553 | ||
1546 | void KOAgendaView::scrollOneHourUp() | 1554 | void KOAgendaView::scrollOneHourUp() |
1547 | { | 1555 | { |
1548 | 1556 | ||
1549 | mAgenda->scrollBy ( 0, -mAgenda->contentsHeight () / 24 ); | 1557 | mAgenda->scrollBy ( 0, -mAgenda->contentsHeight () / 24 ); |
1550 | } | 1558 | } |
1551 | void KOAgendaView::scrollOneHourDown() | 1559 | void KOAgendaView::scrollOneHourDown() |
1552 | { | 1560 | { |
1553 | mAgenda->scrollBy ( 0, mAgenda->contentsHeight () / 24 ); | 1561 | mAgenda->scrollBy ( 0, mAgenda->contentsHeight () / 24 ); |
1554 | } | 1562 | } |
1555 | 1563 | ||
1556 | void KOAgendaView::setStartHour( int h ) | 1564 | void KOAgendaView::setStartHour( int h ) |
1557 | { | 1565 | { |
1558 | mAgenda->setStartHour( h ); | 1566 | mAgenda->setStartHour( h ); |
1559 | 1567 | ||
1560 | } | 1568 | } |
1561 | void KOAgendaView::setInitStartHour() | 1569 | void KOAgendaView::setInitStartHour() |
1562 | { | 1570 | { |
1563 | 1571 | ||
1564 | if ( KOPrefs::instance()->mCenterOnCurrentTime ) | 1572 | if ( KOPrefs::instance()->mCenterOnCurrentTime ) |
1565 | setStartHour( QTime::currentTime ().hour() ); | 1573 | setStartHour( QTime::currentTime ().hour() ); |
1566 | else | 1574 | else |
1567 | setStartHour( KOPrefs::instance()->mDayBegins ); | 1575 | setStartHour( KOPrefs::instance()->mDayBegins ); |
1568 | 1576 | ||
1569 | } | 1577 | } |
1570 | 1578 | ||
1571 | 1579 | ||
1572 | void KOAgendaView::updateTodo( Todo * t, int ) | 1580 | void KOAgendaView::updateTodo( Todo * t, int ) |
1573 | { | 1581 | { |
1574 | if ( !isVisible() ) | 1582 | if ( !isVisible() ) |
1575 | return; | 1583 | return; |
1576 | bool remove = false; | 1584 | bool remove = false; |
1577 | bool removeAD = false; | 1585 | bool removeAD = false; |
1578 | QDate da; | 1586 | QDate da; |
1579 | if ( t->hasCompletedDate() ) | 1587 | if ( t->hasCompletedDate() ) |
1580 | da = t->completed().date(); | 1588 | da = t->completed().date(); |
1581 | else | 1589 | else |
1582 | da = t->dtDue().date(); | 1590 | da = t->dtDue().date(); |
1583 | if ( ! t->hasDueDate() && !t->hasCompletedDate() ) { | 1591 | if ( ! t->hasDueDate() && !t->hasCompletedDate() ) { |
1584 | remove = true; | 1592 | remove = true; |
1585 | removeAD = true; | 1593 | removeAD = true; |
1586 | } | 1594 | } |
1587 | else { | 1595 | else { |
1588 | bool overdue = (!t->isCompleted()) && (t->dtDue() < QDate::currentDate()) && KOPrefs::instance()->mShowTodoInAgenda ; | 1596 | bool overdue = (!t->isCompleted()) && (t->dtDue() < QDate::currentDate()) && KOPrefs::instance()->mShowTodoInAgenda ; |
1589 | if ( overdue && | 1597 | if ( overdue && |
1590 | QDate::currentDate() >= mSelectedDates.first() && | 1598 | QDate::currentDate() >= mSelectedDates.first() && |
1591 | QDate::currentDate() <= mSelectedDates.last()) { | 1599 | QDate::currentDate() <= mSelectedDates.last()) { |
1592 | removeAD = false; | 1600 | removeAD = false; |
1593 | remove = true; | 1601 | remove = true; |
1594 | } | 1602 | } |
1595 | else { | 1603 | else { |
1596 | 1604 | ||
1597 | if ( da < mSelectedDates.first() || | 1605 | if ( da < mSelectedDates.first() || |
1598 | da > mSelectedDates.last() ) { | 1606 | da > mSelectedDates.last() ) { |
1599 | remove = true; | 1607 | remove = true; |
1600 | removeAD = true; | 1608 | removeAD = true; |
1601 | } else { | 1609 | } else { |
1602 | remove = t->doesFloat() && !t->hasCompletedDate(); | 1610 | remove = t->doesFloat() && !t->hasCompletedDate(); |
1603 | removeAD = !remove; | 1611 | removeAD = !remove; |
1604 | } | 1612 | } |
1605 | } | 1613 | } |
1606 | } | 1614 | } |
1607 | int days = mSelectedDates.first().daysTo( da ); | 1615 | int days = mSelectedDates.first().daysTo( da ); |
1608 | //qDebug("daysto %d %d %d", days, remove,removeAD ); | 1616 | //qDebug("daysto %d %d %d", days, remove,removeAD ); |
1609 | mAgenda->updateTodo( t , days, remove); | 1617 | mAgenda->updateTodo( t , days, remove); |
1610 | if ( KOPrefs::instance()->mShowTodoInAgenda ) | 1618 | if ( KOPrefs::instance()->mShowTodoInAgenda ) |
1611 | mAllDayAgenda->updateTodo( t , days, removeAD); | 1619 | mAllDayAgenda->updateTodo( t , days, removeAD); |
1612 | //qDebug("KOAgendaView::updateTodo( Todo *, int ) "); | 1620 | //qDebug("KOAgendaView::updateTodo( Todo *, int ) "); |
1613 | 1621 | ||
1614 | } | 1622 | } |
diff --git a/microkde/KDGanttMinimizeSplitter.cpp b/microkde/KDGanttMinimizeSplitter.cpp index d675517..6cb1f31 100644 --- a/microkde/KDGanttMinimizeSplitter.cpp +++ b/microkde/KDGanttMinimizeSplitter.cpp | |||
@@ -1,1695 +1,1696 @@ | |||
1 | /* -*- Mode: C++ -*- | 1 | /* -*- Mode: C++ -*- |
2 | $Id$ | 2 | $Id$ |
3 | */ | 3 | */ |
4 | 4 | ||
5 | /**************************************************************************** | 5 | /**************************************************************************** |
6 | ** Copyright (C) 2002-2004 Klarälvdalens Datakonsult AB. All rights reserved. | 6 | ** Copyright (C) 2002-2004 Klarälvdalens Datakonsult AB. All rights reserved. |
7 | ** | 7 | ** |
8 | ** This file is part of the KDGantt library. | 8 | ** This file is part of the KDGantt library. |
9 | ** | 9 | ** |
10 | ** This file may be distributed and/or modified under the terms of the | 10 | ** This file may be distributed and/or modified under the terms of the |
11 | ** GNU General Public License version 2 as published by the Free Software | 11 | ** GNU General Public License version 2 as published by the Free Software |
12 | ** Foundation and appearing in the file LICENSE.GPL included in the | 12 | ** Foundation and appearing in the file LICENSE.GPL included in the |
13 | ** packaging of this file. | 13 | ** packaging of this file. |
14 | ** | 14 | ** |
15 | ** Licensees holding valid commercial KDGantt licenses may use this file in | 15 | ** Licensees holding valid commercial KDGantt licenses may use this file in |
16 | ** accordance with the KDGantt Commercial License Agreement provided with | 16 | ** accordance with the KDGantt Commercial License Agreement provided with |
17 | ** the Software. | 17 | ** the Software. |
18 | ** | 18 | ** |
19 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 19 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
20 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 20 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
21 | ** | 21 | ** |
22 | ** See http://www.klaralvdalens-datakonsult.se/Public/products/ for | 22 | ** See http://www.klaralvdalens-datakonsult.se/Public/products/ for |
23 | ** information about KDGantt Commercial License Agreements. | 23 | ** information about KDGantt Commercial License Agreements. |
24 | ** | 24 | ** |
25 | ** Contact info@klaralvdalens-datakonsult.se if any conditions of this | 25 | ** Contact info@klaralvdalens-datakonsult.se if any conditions of this |
26 | ** licensing are not clear to you. | 26 | ** licensing are not clear to you. |
27 | ** | 27 | ** |
28 | ** As a special exception, permission is given to link this program | 28 | ** As a special exception, permission is given to link this program |
29 | ** with any edition of Qt, and distribute the resulting executable, | 29 | ** with any edition of Qt, and distribute the resulting executable, |
30 | ** without including the source code for Qt in the source distribution. | 30 | ** without including the source code for Qt in the source distribution. |
31 | ** | 31 | ** |
32 | **********************************************************************/ | 32 | **********************************************************************/ |
33 | 33 | ||
34 | #include "KDGanttMinimizeSplitter.h" | 34 | #include "KDGanttMinimizeSplitter.h" |
35 | #ifndef QT_NO_SPLITTER___ | 35 | #ifndef QT_NO_SPLITTER___ |
36 | 36 | ||
37 | #include "qpainter.h" | 37 | #include "qpainter.h" |
38 | #include "qdrawutil.h" | 38 | #include "qdrawutil.h" |
39 | #include "qbitmap.h" | 39 | #include "qbitmap.h" |
40 | #if QT_VERSION >= 0x030000 | 40 | #if QT_VERSION >= 0x030000 |
41 | #include "qptrlist.h" | 41 | #include "qptrlist.h" |
42 | #include "qmemarray.h" | 42 | #include "qmemarray.h" |
43 | #else | 43 | #else |
44 | #include <qlist.h> | 44 | #include <qlist.h> |
45 | #include <qarray.h> | 45 | #include <qarray.h> |
46 | #define QPtrList QList | 46 | #define QPtrList QList |
47 | #define QMemArray QArray | 47 | #define QMemArray QArray |
48 | #endif | 48 | #endif |
49 | #include "qlayoutengine_p.h" | 49 | #include "qlayoutengine_p.h" |
50 | #include "qobjectlist.h" | 50 | #include "qobjectlist.h" |
51 | #include "qstyle.h" | 51 | #include "qstyle.h" |
52 | #include "qapplication.h" //sendPostedEvents | 52 | #include "qapplication.h" //sendPostedEvents |
53 | #include <qvaluelist.h> | 53 | #include <qvaluelist.h> |
54 | #include <qcursor.h> | 54 | #include <qcursor.h> |
55 | #ifndef KDGANTT_MASTER_CVS | 55 | #ifndef KDGANTT_MASTER_CVS |
56 | //#include "KDGanttMinimizeSplitter.moc" | 56 | //#include "KDGanttMinimizeSplitter.moc" |
57 | #endif | 57 | #endif |
58 | 58 | ||
59 | 59 | ||
60 | 60 | ||
61 | #ifndef DOXYGEN_SKIP_INTERNAL | 61 | #ifndef DOXYGEN_SKIP_INTERNAL |
62 | 62 | ||
63 | #if QT_VERSION >= 232 | 63 | #if QT_VERSION >= 232 |
64 | static int mouseOffset; | 64 | static int mouseOffset; |
65 | static int opaqueOldPos = -1; //### there's only one mouse, but this is a bit risky | 65 | static int opaqueOldPos = -1; //### there's only one mouse, but this is a bit risky |
66 | 66 | ||
67 | 67 | ||
68 | KDGanttSplitterHandle::KDGanttSplitterHandle( Qt::Orientation o, | 68 | KDGanttSplitterHandle::KDGanttSplitterHandle( Qt::Orientation o, |
69 | KDGanttMinimizeSplitter *parent, const char * name ) | 69 | KDGanttMinimizeSplitter *parent, const char * name ) |
70 | : QWidget( parent, name ), _activeButton( 0 ), _collapsed( false ) | 70 | : QWidget( parent, name ), _activeButton( 0 ), _collapsed( false ) |
71 | { | 71 | { |
72 | 72 | ||
73 | if ( QApplication::desktop()->width() > 320 && QApplication::desktop()->width() < 650 ) { | 73 | if ( QApplication::desktop()->width() > 320 && QApplication::desktop()->width() < 650 ) { |
74 | mSizeHint = QSize(7,7); | 74 | mSizeHint = QSize(7,7); |
75 | mUseOffset = true; | 75 | mUseOffset = true; |
76 | } else { | 76 | } else { |
77 | mSizeHint = QSize(6,6); | 77 | mSizeHint = QSize(6,6); |
78 | mUseOffset = false; | 78 | mUseOffset = false; |
79 | } | 79 | } |
80 | s = parent; | 80 | s = parent; |
81 | setOrientation(o); | 81 | setOrientation(o); |
82 | setMouseTracking( true ); | 82 | setMouseTracking( true ); |
83 | mMouseDown = false; | 83 | mMouseDown = false; |
84 | //setMaximumHeight( 5 ); // test only | 84 | //setMaximumHeight( 5 ); // test only |
85 | } | 85 | } |
86 | 86 | ||
87 | QSize KDGanttSplitterHandle::sizeHint() const | 87 | QSize KDGanttSplitterHandle::sizeHint() const |
88 | { | 88 | { |
89 | return mSizeHint; | 89 | return mSizeHint; |
90 | } | 90 | } |
91 | 91 | ||
92 | void KDGanttSplitterHandle::setOrientation( Qt::Orientation o ) | 92 | void KDGanttSplitterHandle::setOrientation( Qt::Orientation o ) |
93 | { | 93 | { |
94 | orient = o; | 94 | orient = o; |
95 | #ifndef QT_NO_CURSOR | 95 | #ifndef QT_NO_CURSOR |
96 | if ( o == KDGanttMinimizeSplitter::Horizontal ) | 96 | if ( o == KDGanttMinimizeSplitter::Horizontal ) |
97 | setCursor( splitHCursor ); | 97 | setCursor( splitHCursor ); |
98 | else | 98 | else |
99 | setCursor( splitVCursor ); | 99 | setCursor( splitVCursor ); |
100 | #endif | 100 | #endif |
101 | } | 101 | } |
102 | 102 | ||
103 | 103 | ||
104 | void KDGanttSplitterHandle::mouseMoveEvent( QMouseEvent *e ) | 104 | void KDGanttSplitterHandle::mouseMoveEvent( QMouseEvent *e ) |
105 | { | 105 | { |
106 | updateCursor( e->pos() ); | 106 | updateCursor( e->pos() ); |
107 | if ( !(e->state()&LeftButton) ) | 107 | if ( !(e->state()&LeftButton) ) |
108 | return; | 108 | return; |
109 | 109 | ||
110 | if ( _activeButton != 0) | 110 | if ( _activeButton != 0) |
111 | return; | 111 | return; |
112 | 112 | ||
113 | QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos())) | 113 | QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos())) |
114 | - mouseOffset; | 114 | - mouseOffset; |
115 | if ( opaque() ) { | 115 | if ( opaque() ) { |
116 | s->moveSplitter( pos, id() ); | 116 | s->moveSplitter( pos, id() ); |
117 | } else { | 117 | } else { |
118 | int min = pos; int max = pos; | 118 | int min = pos; int max = pos; |
119 | s->getRange( id(), &min, &max ); | 119 | s->getRange( id(), &min, &max ); |
120 | s->setRubberband( QMAX( min, QMIN(max, pos ))); | 120 | s->setRubberband( QMAX( min, QMIN(max, pos ))); |
121 | } | 121 | } |
122 | _collapsed = false; | 122 | _collapsed = false; |
123 | } | 123 | } |
124 | 124 | ||
125 | void KDGanttSplitterHandle::mousePressEvent( QMouseEvent *e ) | 125 | void KDGanttSplitterHandle::mousePressEvent( QMouseEvent *e ) |
126 | { | 126 | { |
127 | if ( e->button() == LeftButton ) { | 127 | if ( e->button() == LeftButton ) { |
128 | _activeButton = onButton( e->pos() ); | 128 | _activeButton = onButton( e->pos() ); |
129 | mouseOffset = s->pick(e->pos()); | 129 | mouseOffset = s->pick(e->pos()); |
130 | mMouseDown = true; | 130 | mMouseDown = true; |
131 | repaint(); | 131 | repaint(); |
132 | updateCursor( e->pos() ); | 132 | updateCursor( e->pos() ); |
133 | } | 133 | } |
134 | } | 134 | } |
135 | 135 | ||
136 | void KDGanttSplitterHandle::updateCursor( const QPoint& p) | 136 | void KDGanttSplitterHandle::updateCursor( const QPoint& p) |
137 | { | 137 | { |
138 | if ( onButton( p ) != 0 ) { | 138 | if ( onButton( p ) != 0 ) { |
139 | setCursor( arrowCursor ); | 139 | setCursor( arrowCursor ); |
140 | } | 140 | } |
141 | else { | 141 | else { |
142 | if ( orient == KDGanttMinimizeSplitter::Horizontal ) | 142 | if ( orient == KDGanttMinimizeSplitter::Horizontal ) |
143 | setCursor( splitHCursor ); | 143 | setCursor( splitHCursor ); |
144 | else | 144 | else |
145 | setCursor( splitVCursor ); | 145 | setCursor( splitVCursor ); |
146 | } | 146 | } |
147 | } | 147 | } |
148 | void KDGanttSplitterHandle::toggle() | 148 | void KDGanttSplitterHandle::toggle() |
149 | { | 149 | { |
150 | int pos; | 150 | int pos; |
151 | int min, max; | 151 | int min, max; |
152 | if ( !_collapsed ) { | 152 | if ( !_collapsed ) { |
153 | s->expandPos( id(), &min, &max ); | 153 | s->expandPos( id(), &min, &max ); |
154 | if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Left | 154 | if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Left |
155 | || s->minimizeDirection() == KDGanttMinimizeSplitter::Up ) { | 155 | || s->minimizeDirection() == KDGanttMinimizeSplitter::Up ) { |
156 | pos = min; | 156 | pos = min; |
157 | } | 157 | } |
158 | else { | 158 | else { |
159 | pos = max; | 159 | pos = max; |
160 | } | 160 | } |
161 | 161 | ||
162 | _origPos = s->pick(mapToParent( QPoint( 0,0 ) )); | 162 | _origPos = s->pick(mapToParent( QPoint( 0,0 ) )); |
163 | s->moveSplitter( pos, id() ); | 163 | s->moveSplitter( pos, id() ); |
164 | _collapsed = true; | 164 | _collapsed = true; |
165 | } | 165 | } |
166 | else { | 166 | else { |
167 | s->moveSplitter( _origPos, id() ); | 167 | s->moveSplitter( _origPos, id() ); |
168 | _collapsed = false; | 168 | _collapsed = false; |
169 | } | 169 | } |
170 | repaint(); | 170 | repaint(); |
171 | } | 171 | } |
172 | 172 | ||
173 | void KDGanttSplitterHandle::mouseReleaseEvent( QMouseEvent *e ) | 173 | void KDGanttSplitterHandle::mouseReleaseEvent( QMouseEvent *e ) |
174 | { | 174 | { |
175 | mMouseDown = false; | 175 | mMouseDown = false; |
176 | if ( _activeButton != 0 ) { | 176 | if ( _activeButton != 0 ) { |
177 | if ( onButton( e->pos() ) == _activeButton ) | 177 | if ( onButton( e->pos() ) == _activeButton ) |
178 | { | 178 | { |
179 | toggle(); | 179 | toggle(); |
180 | } | 180 | } |
181 | _activeButton = 0; | 181 | _activeButton = 0; |
182 | updateCursor( e->pos() ); | 182 | updateCursor( e->pos() ); |
183 | } | 183 | } |
184 | else { | 184 | else { |
185 | if ( !opaque() && e->button() == LeftButton ) { | 185 | if ( !opaque() && e->button() == LeftButton ) { |
186 | QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos())) | 186 | QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos())) |
187 | - mouseOffset; | 187 | - mouseOffset; |
188 | s->setRubberband( -1 ); | 188 | s->setRubberband( -1 ); |
189 | s->moveSplitter( pos, id() ); | 189 | s->moveSplitter( pos, id() ); |
190 | } | 190 | } |
191 | } | 191 | } |
192 | if ( s->rubberBand() ) | 192 | if ( s->rubberBand() ) |
193 | s->rubberBand()->hide(); | 193 | s->rubberBand()->hide(); |
194 | repaint(); | 194 | repaint(); |
195 | } | 195 | } |
196 | 196 | ||
197 | int KDGanttSplitterHandle::onButton( const QPoint& p ) | 197 | int KDGanttSplitterHandle::onButton( const QPoint& p ) |
198 | { | 198 | { |
199 | QValueList<QPointArray> list = buttonRegions(); | 199 | QValueList<QPointArray> list = buttonRegions(); |
200 | int index = 1; | 200 | int index = 1; |
201 | int add = 12; | 201 | int add = 12; |
202 | for( QValueList<QPointArray>::Iterator it = list.begin(); it != list.end(); ++it ) { | 202 | for( QValueList<QPointArray>::Iterator it = list.begin(); it != list.end(); ++it ) { |
203 | QRect rect = (*it).boundingRect(); | 203 | QRect rect = (*it).boundingRect(); |
204 | rect.setLeft( rect.left()- add ); | 204 | rect.setLeft( rect.left()- add ); |
205 | rect.setRight( rect.right() + add); | 205 | rect.setRight( rect.right() + add); |
206 | rect.setTop( rect.top()- add ); | 206 | rect.setTop( rect.top()- add ); |
207 | rect.setBottom( rect.bottom() + add); | 207 | rect.setBottom( rect.bottom() + add); |
208 | if ( rect.contains( p ) ) { | 208 | if ( rect.contains( p ) ) { |
209 | return index; | 209 | return index; |
210 | } | 210 | } |
211 | index++; | 211 | index++; |
212 | } | 212 | } |
213 | return 0; | 213 | return 0; |
214 | } | 214 | } |
215 | 215 | ||
216 | 216 | ||
217 | QValueList<QPointArray> KDGanttSplitterHandle::buttonRegions() | 217 | QValueList<QPointArray> KDGanttSplitterHandle::buttonRegions() |
218 | { | 218 | { |
219 | QValueList<QPointArray> list; | 219 | QValueList<QPointArray> list; |
220 | 220 | ||
221 | int sw = 8; | 221 | int sw = 8; |
222 | int yyy = 1; | 222 | int yyy = 1; |
223 | int xxx = 1; | 223 | int xxx = 1; |
224 | int voffset[] = { (int) -sw*3, (int) sw*3 }; | 224 | int voffset[] = { (int) -sw*3, (int) sw*3 }; |
225 | for ( int i = 0; i < 2; i++ ) { | 225 | for ( int i = 0; i < 2; i++ ) { |
226 | QPointArray arr; | 226 | QPointArray arr; |
227 | if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Right || | 227 | if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Right || |
228 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Left) { | 228 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Left) { |
229 | int mid = height()/2 + voffset[i]; | 229 | int mid = height()/2 + voffset[i]; |
230 | arr.setPoints( 3, | 230 | arr.setPoints( 3, |
231 | 1-xxx, mid - sw + 4, | 231 | 1-xxx, mid - sw + 4, |
232 | sw-3-xxx, mid, | 232 | sw-3-xxx, mid, |
233 | 1-xxx, mid + sw -4); | 233 | 1-xxx, mid + sw -4); |
234 | } | 234 | } |
235 | else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Left || | 235 | else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Left || |
236 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Right ) { | 236 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Right ) { |
237 | int mid = height()/2 + voffset[i]; | 237 | int mid = height()/2 + voffset[i]; |
238 | arr.setPoints( 3, | 238 | arr.setPoints( 3, |
239 | sw-4, mid - sw + 4, | 239 | sw-4, mid - sw + 4, |
240 | 0, mid, | 240 | 0, mid, |
241 | sw-4, mid + sw - 4); | 241 | sw-4, mid + sw - 4); |
242 | } | 242 | } |
243 | else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Up || | 243 | else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Up || |
244 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Down) { | 244 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Down) { |
245 | int mid = width()/2 + voffset[i]; | 245 | int mid = width()/2 + voffset[i]; |
246 | arr.setPoints( 3, | 246 | arr.setPoints( 3, |
247 | mid - sw + 4, sw-4, | 247 | mid - sw + 4, sw-4, |
248 | mid, 0, | 248 | mid, 0, |
249 | mid + sw - 4, sw-4 ); | 249 | mid + sw - 4, sw-4 ); |
250 | } | 250 | } |
251 | else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Down || | 251 | else if ( !_collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Down || |
252 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Up ) { | 252 | _collapsed && s->minimizeDirection() == KDGanttMinimizeSplitter::Up ) { |
253 | int mid = width()/2 + voffset[i]; | 253 | int mid = width()/2 + voffset[i]; |
254 | arr.setPoints( 3, | 254 | arr.setPoints( 3, |
255 | mid - sw + 4, 1-yyy, | 255 | mid - sw + 4, 1-yyy, |
256 | mid, sw-3-yyy, | 256 | mid, sw-3-yyy, |
257 | mid + sw -4, 1-yyy); | 257 | mid + sw -4, 1-yyy); |
258 | } | 258 | } |
259 | list.append( arr ); | 259 | list.append( arr ); |
260 | } | 260 | } |
261 | return list; | 261 | return list; |
262 | } | 262 | } |
263 | 263 | ||
264 | void KDGanttSplitterHandle::paintEvent( QPaintEvent * ) | 264 | void KDGanttSplitterHandle::paintEvent( QPaintEvent * ) |
265 | { | 265 | { |
266 | QPixmap buffer( size() ); | 266 | QPixmap buffer( size() ); |
267 | QPainter p( &buffer ); | 267 | QPainter p( &buffer ); |
268 | 268 | ||
269 | //LR | 269 | //LR |
270 | // Draw the splitter rectangle | 270 | // Draw the splitter rectangle |
271 | p.setBrush( colorGroup().background() ); | 271 | p.setBrush( colorGroup().background() ); |
272 | p.setPen( colorGroup().foreground() ); | 272 | p.setPen( colorGroup().foreground() ); |
273 | //p.drawRect( rect() ); | 273 | //p.drawRect( rect() ); |
274 | buffer.fill( colorGroup().background() ); | 274 | buffer.fill( colorGroup().background() ); |
275 | //buffer.fill( backgroundColor() ); | 275 | //buffer.fill( backgroundColor() ); |
276 | // parentWidget()->style().drawPrimitive( QStyle::PE_Panel, &p, rect(), parentWidget()->colorGroup()); | 276 | // parentWidget()->style().drawPrimitive( QStyle::PE_Panel, &p, rect(), parentWidget()->colorGroup()); |
277 | 277 | ||
278 | int sw = 8; // Hardcoded, given I didn't use styles anymore, I didn't like to use their size | 278 | int sw = 8; // Hardcoded, given I didn't use styles anymore, I didn't like to use their size |
279 | 279 | ||
280 | // arrow color | 280 | // arrow color |
281 | QColor col; | 281 | QColor col; |
282 | if ( _activeButton ) | 282 | if ( _activeButton ) |
283 | col = colorGroup().background().dark( 250 ); | 283 | col = colorGroup().background().dark( 250 ); |
284 | else { | 284 | else { |
285 | if ( mMouseDown ) | 285 | if ( mMouseDown ) |
286 | col = Qt::white; | 286 | col = Qt::white; |
287 | else | 287 | else |
288 | col = colorGroup().background().dark( 150 ); | 288 | col = colorGroup().background().dark( 150 ); |
289 | } | 289 | } |
290 | //QColor col = backgroundColor().dark( 130 ); | 290 | //QColor col = backgroundColor().dark( 130 ); |
291 | p.setBrush( col ); | 291 | p.setBrush( col ); |
292 | p.setPen( col ); | 292 | p.setPen( col ); |
293 | 293 | ||
294 | QValueList<QPointArray> list = buttonRegions(); | 294 | QValueList<QPointArray> list = buttonRegions(); |
295 | int index = 1; | 295 | int index = 1; |
296 | if ( mUseOffset ) | 296 | if ( mUseOffset ) |
297 | p.translate( 0, 1 ); | 297 | p.translate( 0, 1 ); |
298 | for ( QValueList<QPointArray>::Iterator it = list.begin(); it != list.end(); ++it ) { | 298 | for ( QValueList<QPointArray>::Iterator it = list.begin(); it != list.end(); ++it ) { |
299 | if ( index == _activeButton ) { | 299 | if ( index == _activeButton ) { |
300 | 300 | ||
301 | /* | 301 | /* |
302 | if ( ! _collapsed ) { | 302 | if ( ! _collapsed ) { |
303 | p.save(); | 303 | p.save(); |
304 | // p.translate( parentWidget()->style().pixelMetric( QStyle::PM_ButtonShiftHorizontal ), | 304 | // p.translate( parentWidget()->style().pixelMetric( QStyle::PM_ButtonShiftHorizontal ), |
305 | // parentWidget()->style().pixelMetric( QStyle::PM_ButtonShiftVertical ) ); | 305 | // parentWidget()->style().pixelMetric( QStyle::PM_ButtonShiftVertical ) ); |
306 | p.translate( -1, 0 ); | 306 | p.translate( -1, 0 ); |
307 | p.drawPolygon( *it, true ); | 307 | p.drawPolygon( *it, true ); |
308 | p.restore(); } else | 308 | p.restore(); } else |
309 | */ | 309 | */ |
310 | p.drawPolygon( *it, true ); | 310 | p.drawPolygon( *it, true ); |
311 | 311 | ||
312 | } | 312 | } |
313 | else { | 313 | else { |
314 | /* | 314 | /* |
315 | if ( ! _collapsed ) { | 315 | if ( ! _collapsed ) { |
316 | p.save(); | 316 | p.save(); |
317 | p.translate( -1, 0 ); | 317 | p.translate( -1, 0 ); |
318 | p.drawPolygon( *it, true ); | 318 | p.drawPolygon( *it, true ); |
319 | p.restore(); | 319 | p.restore(); |
320 | } else | 320 | } else |
321 | */ | 321 | */ |
322 | p.drawPolygon( *it, true ); | 322 | p.drawPolygon( *it, true ); |
323 | 323 | ||
324 | } | 324 | } |
325 | index++; | 325 | index++; |
326 | } | 326 | } |
327 | 327 | ||
328 | // Draw the lines between the arrows | 328 | // Draw the lines between the arrows |
329 | if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Left || | 329 | if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Left || |
330 | s->minimizeDirection() == KDGanttMinimizeSplitter::Right ) { | 330 | s->minimizeDirection() == KDGanttMinimizeSplitter::Right ) { |
331 | int mid = height()/2; | 331 | int mid = height()/2; |
332 | p.drawLine ( 1, mid - sw, 1, mid + sw ); | 332 | p.drawLine ( 1, mid - sw, 1, mid + sw ); |
333 | p.drawLine ( 3, mid - sw, 3, mid + sw ); | 333 | p.drawLine ( 3, mid - sw, 3, mid + sw ); |
334 | } | 334 | } |
335 | else if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Up || | 335 | else if ( s->minimizeDirection() == KDGanttMinimizeSplitter::Up || |
336 | s->minimizeDirection() == KDGanttMinimizeSplitter::Down ) { | 336 | s->minimizeDirection() == KDGanttMinimizeSplitter::Down ) { |
337 | int mid = width()/2; | 337 | int mid = width()/2; |
338 | p.drawLine( mid -sw, 1, mid +sw, 1 ); | 338 | p.drawLine( mid -sw, 1, mid +sw, 1 ); |
339 | p.drawLine( mid -sw, 3, mid +sw, 3 ); | 339 | p.drawLine( mid -sw, 3, mid +sw, 3 ); |
340 | } | 340 | } |
341 | bitBlt( this, 0, 0, &buffer ); | 341 | bitBlt( this, 0, 0, &buffer ); |
342 | 342 | ||
343 | } | 343 | } |
344 | #endif | 344 | #endif |
345 | 345 | ||
346 | class QSplitterLayoutStruct | 346 | class QSplitterLayoutStruct |
347 | { | 347 | { |
348 | public: | 348 | public: |
349 | KDGanttMinimizeSplitter::ResizeMode mode; | 349 | KDGanttMinimizeSplitter::ResizeMode mode; |
350 | QCOORD sizer; | 350 | QCOORD sizer; |
351 | bool isSplitter; | 351 | bool isSplitter; |
352 | QWidget *wid; | 352 | QWidget *wid; |
353 | }; | 353 | }; |
354 | 354 | ||
355 | class QSplitterData | 355 | class QSplitterData |
356 | { | 356 | { |
357 | public: | 357 | public: |
358 | QSplitterData() : opaque( FALSE ), firstShow( TRUE ) {} | 358 | QSplitterData() : opaque( FALSE ), firstShow( TRUE ) {} |
359 | 359 | ||
360 | QPtrList<QSplitterLayoutStruct> list; | 360 | QPtrList<QSplitterLayoutStruct> list; |
361 | bool opaque; | 361 | bool opaque; |
362 | bool firstShow; | 362 | bool firstShow; |
363 | }; | 363 | }; |
364 | 364 | ||
365 | void kdganttGeomCalc( QMemArray<QLayoutStruct> &chain, int start, int count, int pos, | 365 | void kdganttGeomCalc( QMemArray<QLayoutStruct> &chain, int start, int count, int pos, |
366 | int space, int spacer ); | 366 | int space, int spacer ); |
367 | #endif // DOXYGEN_SKIP_INTERNAL | 367 | #endif // DOXYGEN_SKIP_INTERNAL |
368 | 368 | ||
369 | 369 | ||
370 | /*! | 370 | /*! |
371 | \class KDGanttMinimizeSplitter KDGanttMinimizeSplitter.h | 371 | \class KDGanttMinimizeSplitter KDGanttMinimizeSplitter.h |
372 | \brief The KDGanttMinimizeSplitter class implements a splitter | 372 | \brief The KDGanttMinimizeSplitter class implements a splitter |
373 | widget with minimize buttons. | 373 | widget with minimize buttons. |
374 | 374 | ||
375 | This class (and its documentation) is largely a copy of Qt's | 375 | This class (and its documentation) is largely a copy of Qt's |
376 | QSplitter; the copying was necessary because QSplitter is not | 376 | QSplitter; the copying was necessary because QSplitter is not |
377 | extensible at all. QSplitter and its documentation are licensed | 377 | extensible at all. QSplitter and its documentation are licensed |
378 | according to the GPL and the Qt Professional License (if you hold | 378 | according to the GPL and the Qt Professional License (if you hold |
379 | such a license) and are (C) Trolltech AS. | 379 | such a license) and are (C) Trolltech AS. |
380 | 380 | ||
381 | A splitter lets the user control the size of child widgets by | 381 | A splitter lets the user control the size of child widgets by |
382 | dragging the boundary between the children. Any number of widgets | 382 | dragging the boundary between the children. Any number of widgets |
383 | may be controlled. | 383 | may be controlled. |
384 | 384 | ||
385 | To show a QListBox, a QListView and a QTextEdit side by side: | 385 | To show a QListBox, a QListView and a QTextEdit side by side: |
386 | 386 | ||
387 | \code | 387 | \code |
388 | KDGanttMinimizeSplitter *split = new KDGanttMinimizeSplitter( parent ); | 388 | KDGanttMinimizeSplitter *split = new KDGanttMinimizeSplitter( parent ); |
389 | QListBox *lb = new QListBox( split ); | 389 | QListBox *lb = new QListBox( split ); |
390 | QListView *lv = new QListView( split ); | 390 | QListView *lv = new QListView( split ); |
391 | QTextEdit *ed = new QTextEdit( split ); | 391 | QTextEdit *ed = new QTextEdit( split ); |
392 | \endcode | 392 | \endcode |
393 | 393 | ||
394 | In KDGanttMinimizeSplitter, the boundary can be either horizontal or | 394 | In KDGanttMinimizeSplitter, the boundary can be either horizontal or |
395 | vertical. The default is horizontal (the children are side by side) | 395 | vertical. The default is horizontal (the children are side by side) |
396 | but you can use setOrientation( QSplitter::Vertical ) to set it to | 396 | but you can use setOrientation( QSplitter::Vertical ) to set it to |
397 | vertical. | 397 | vertical. |
398 | 398 | ||
399 | Use setResizeMode() to specify | 399 | Use setResizeMode() to specify |
400 | that a widget should keep its size when the splitter is resized. | 400 | that a widget should keep its size when the splitter is resized. |
401 | 401 | ||
402 | Although KDGanttMinimizeSplitter normally resizes the children only | 402 | Although KDGanttMinimizeSplitter normally resizes the children only |
403 | at the end of a resize operation, if you call setOpaqueResize( TRUE | 403 | at the end of a resize operation, if you call setOpaqueResize( TRUE |
404 | ) the widgets are resized as often as possible. | 404 | ) the widgets are resized as often as possible. |
405 | 405 | ||
406 | The initial distribution of size between the widgets is determined | 406 | The initial distribution of size between the widgets is determined |
407 | by the initial size of each widget. You can also use setSizes() to | 407 | by the initial size of each widget. You can also use setSizes() to |
408 | set the sizes of all the widgets. The function sizes() returns the | 408 | set the sizes of all the widgets. The function sizes() returns the |
409 | sizes set by the user. | 409 | sizes set by the user. |
410 | 410 | ||
411 | If you hide() a child, its space will be distributed among the other | 411 | If you hide() a child, its space will be distributed among the other |
412 | children. It will be reinstated when you show() it again. It is also | 412 | children. It will be reinstated when you show() it again. It is also |
413 | possible to reorder the widgets within the splitter using | 413 | possible to reorder the widgets within the splitter using |
414 | moveToFirst() and moveToLast(). | 414 | moveToFirst() and moveToLast(). |
415 | */ | 415 | */ |
416 | 416 | ||
417 | 417 | ||
418 | 418 | ||
419 | static QSize minSize( const QWidget* /*w*/ ) | 419 | static QSize minSize( const QWidget* /*w*/ ) |
420 | { | 420 | { |
421 | return QSize(0,0); | 421 | return QSize(0,0); |
422 | } | 422 | } |
423 | 423 | ||
424 | // This is the original version of minSize | 424 | // This is the original version of minSize |
425 | static QSize minSizeHint( const QWidget* w ) | 425 | static QSize minSizeHint( const QWidget* w ) |
426 | { | 426 | { |
427 | QSize min = w->minimumSize(); | 427 | QSize min = w->minimumSize(); |
428 | QSize s; | 428 | QSize s; |
429 | if ( min.height() <= 0 || min.width() <= 0 ) | 429 | if ( min.height() <= 0 || min.width() <= 0 ) |
430 | s = w->minimumSizeHint(); | 430 | s = w->minimumSizeHint(); |
431 | if ( min.height() > 0 ) | 431 | if ( min.height() > 0 ) |
432 | s.setHeight( min.height() ); | 432 | s.setHeight( min.height() ); |
433 | if ( min.width() > 0 ) | 433 | if ( min.width() > 0 ) |
434 | s.setWidth( min.width() ); | 434 | s.setWidth( min.width() ); |
435 | return s.expandedTo(QSize(0,0)); | 435 | return s.expandedTo(QSize(0,0)); |
436 | } | 436 | } |
437 | 437 | ||
438 | 438 | ||
439 | /*! | 439 | /*! |
440 | Constructs a horizontal splitter with the \a parent and \a | 440 | Constructs a horizontal splitter with the \a parent and \a |
441 | name arguments being passed on to the QFrame constructor. | 441 | name arguments being passed on to the QFrame constructor. |
442 | */ | 442 | */ |
443 | KDGanttMinimizeSplitter::KDGanttMinimizeSplitter( QWidget *parent, const char *name ) | 443 | KDGanttMinimizeSplitter::KDGanttMinimizeSplitter( QWidget *parent, const char *name ) |
444 | :QFrame(parent,name,WPaintUnclipped) | 444 | :QFrame(parent,name,WPaintUnclipped) |
445 | { | 445 | { |
446 | mRubberBand = 0; | 446 | mRubberBand = 0; |
447 | mFirstHandle = 0; | 447 | mFirstHandle = 0; |
448 | #if QT_VERSION >= 232 | 448 | #if QT_VERSION >= 232 |
449 | orient = Horizontal; | 449 | orient = Horizontal; |
450 | init(); | 450 | init(); |
451 | #endif | 451 | #endif |
452 | } | 452 | } |
453 | 453 | ||
454 | /*! | 454 | /*! |
455 | Constructs a splitter with orientation \a o with the \a parent | 455 | Constructs a splitter with orientation \a o with the \a parent |
456 | and \a name arguments being passed on to the QFrame constructor. | 456 | and \a name arguments being passed on to the QFrame constructor. |
457 | */ | 457 | */ |
458 | KDGanttMinimizeSplitter::KDGanttMinimizeSplitter( Orientation o, QWidget *parent, const char *name ) | 458 | KDGanttMinimizeSplitter::KDGanttMinimizeSplitter( Orientation o, QWidget *parent, const char *name ) |
459 | :QFrame(parent,name,WPaintUnclipped) | 459 | :QFrame(parent,name,WPaintUnclipped) |
460 | { | 460 | { |
461 | 461 | ||
462 | mRubberBand = 0; | 462 | mRubberBand = 0; |
463 | mFirstHandle = 0; | 463 | mFirstHandle = 0; |
464 | #if QT_VERSION >= 232 | 464 | #if QT_VERSION >= 232 |
465 | orient = o; | 465 | orient = o; |
466 | init(); | 466 | init(); |
467 | #endif | 467 | #endif |
468 | } | 468 | } |
469 | 469 | ||
470 | /*! | 470 | /*! |
471 | Destroys the splitter and any children. | 471 | Destroys the splitter and any children. |
472 | */ | 472 | */ |
473 | KDGanttMinimizeSplitter::~KDGanttMinimizeSplitter() | 473 | KDGanttMinimizeSplitter::~KDGanttMinimizeSplitter() |
474 | { | 474 | { |
475 | #if QT_VERSION >= 232 | 475 | #if QT_VERSION >= 232 |
476 | data->list.setAutoDelete( TRUE ); | 476 | data->list.setAutoDelete( TRUE ); |
477 | delete data; | 477 | delete data; |
478 | #endif | 478 | #endif |
479 | if ( mRubberBand ) | 479 | if ( mRubberBand ) |
480 | delete mRubberBand; | 480 | delete mRubberBand; |
481 | } | 481 | } |
482 | 482 | ||
483 | 483 | ||
484 | #if QT_VERSION >= 232 | 484 | #if QT_VERSION >= 232 |
485 | void KDGanttMinimizeSplitter::init() | 485 | void KDGanttMinimizeSplitter::init() |
486 | { | 486 | { |
487 | data = new QSplitterData; | 487 | data = new QSplitterData; |
488 | if ( orient == Horizontal ) | 488 | if ( orient == Horizontal ) |
489 | setSizePolicy( QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum) ); | 489 | setSizePolicy( QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum) ); |
490 | else | 490 | else |
491 | setSizePolicy( QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Expanding) ); | 491 | setSizePolicy( QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Expanding) ); |
492 | #ifndef DESKTOP_VERSION | 492 | #ifndef DESKTOP_VERSION |
493 | setOpaqueResize( false ); | 493 | setOpaqueResize( false ); |
494 | #else | 494 | #else |
495 | setOpaqueResize( true ); | 495 | setOpaqueResize( true ); |
496 | #endif | 496 | #endif |
497 | } | 497 | } |
498 | #endif | 498 | #endif |
499 | 499 | ||
500 | 500 | ||
501 | void KDGanttMinimizeSplitter::toggle() | 501 | void KDGanttMinimizeSplitter::toggle() |
502 | { | 502 | { |
503 | if ( mFirstHandle ) | 503 | if ( mFirstHandle ) |
504 | mFirstHandle->toggle(); | 504 | mFirstHandle->toggle(); |
505 | else | 505 | else |
506 | qDebug("KDGanttMinimizeSplitter::toggle::sorry, handle not available "); | 506 | qDebug("KDGanttMinimizeSplitter::toggle::sorry, handle not available "); |
507 | 507 | ||
508 | } | 508 | } |
509 | 509 | ||
510 | 510 | ||
511 | /*! | 511 | /*! |
512 | \brief the orientation of the splitter | 512 | \brief the orientation of the splitter |
513 | 513 | ||
514 | By default the orientation is horizontal (the widgets are side by side). | 514 | By default the orientation is horizontal (the widgets are side by side). |
515 | The possible orientations are Qt:Vertical and Qt::Horizontal (the default). | 515 | The possible orientations are Qt:Vertical and Qt::Horizontal (the default). |
516 | */ | 516 | */ |
517 | void KDGanttMinimizeSplitter::setOrientation( Orientation o ) | 517 | void KDGanttMinimizeSplitter::setOrientation( Orientation o ) |
518 | { | 518 | { |
519 | #if QT_VERSION >= 232 | 519 | #if QT_VERSION >= 232 |
520 | if ( orient == o ) | 520 | if ( orient == o ) |
521 | return; | 521 | return; |
522 | orient = o; | 522 | orient = o; |
523 | 523 | ||
524 | if ( orient == Horizontal ) | 524 | if ( orient == Horizontal ) |
525 | setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); | 525 | setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); |
526 | else | 526 | else |
527 | setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) ); | 527 | setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) ); |
528 | 528 | ||
529 | QSplitterLayoutStruct *s = data->list.first(); | 529 | QSplitterLayoutStruct *s = data->list.first(); |
530 | while ( s ) { | 530 | while ( s ) { |
531 | if ( s->isSplitter ) | 531 | if ( s->isSplitter ) |
532 | ((KDGanttSplitterHandle*)s->wid)->setOrientation( o ); | 532 | ((KDGanttSplitterHandle*)s->wid)->setOrientation( o ); |
533 | s = data->list.next(); // ### next at end of loop, no iterator | 533 | s = data->list.next(); // ### next at end of loop, no iterator |
534 | } | 534 | } |
535 | recalc( isVisible() ); | 535 | recalc( isVisible() ); |
536 | #endif | 536 | #endif |
537 | } | 537 | } |
538 | 538 | ||
539 | 539 | ||
540 | #if QT_VERSION >= 232 | 540 | #if QT_VERSION >= 232 |
541 | /*! | 541 | /*! |
542 | \reimp | 542 | \reimp |
543 | */ | 543 | */ |
544 | void KDGanttMinimizeSplitter::resizeEvent( QResizeEvent * ) | 544 | void KDGanttMinimizeSplitter::resizeEvent( QResizeEvent * ) |
545 | { | 545 | { |
546 | doResize(); | 546 | doResize(); |
547 | } | 547 | } |
548 | 548 | ||
549 | 549 | ||
550 | /* | 550 | /* |
551 | Inserts the widget \a w at the end (or at the beginning if \a first | 551 | Inserts the widget \a w at the end (or at the beginning if \a first |
552 | is TRUE) of the splitter's list of widgets. | 552 | is TRUE) of the splitter's list of widgets. |
553 | 553 | ||
554 | It is the responsibility of the caller of this function to make sure | 554 | It is the responsibility of the caller of this function to make sure |
555 | that \a w is not already in the splitter and to call recalcId if | 555 | that \a w is not already in the splitter and to call recalcId if |
556 | needed. (If \a first is TRUE, then recalcId is very probably | 556 | needed. (If \a first is TRUE, then recalcId is very probably |
557 | needed.) | 557 | needed.) |
558 | */ | 558 | */ |
559 | QSplitterLayoutStruct *KDGanttMinimizeSplitter::addWidget( QWidget *w, bool first ) | 559 | QSplitterLayoutStruct *KDGanttMinimizeSplitter::addWidget( QWidget *w, bool first ) |
560 | { | 560 | { |
561 | QSplitterLayoutStruct *s; | 561 | QSplitterLayoutStruct *s; |
562 | KDGanttSplitterHandle *newHandle = 0; | 562 | KDGanttSplitterHandle *newHandle = 0; |
563 | if ( data->list.count() > 0 ) { | 563 | if ( data->list.count() > 0 ) { |
564 | s = new QSplitterLayoutStruct; | 564 | s = new QSplitterLayoutStruct; |
565 | s->mode = KeepSize; | 565 | s->mode = KeepSize; |
566 | QString tmp = "qt_splithandle_"; | 566 | QString tmp = "qt_splithandle_"; |
567 | tmp += w->name(); | 567 | tmp += w->name(); |
568 | newHandle = new KDGanttSplitterHandle( orientation(), this, tmp.latin1() ); | 568 | newHandle = new KDGanttSplitterHandle( orientation(), this, tmp.latin1() ); |
569 | if ( ! mFirstHandle ) | 569 | if ( ! mFirstHandle ) |
570 | mFirstHandle = newHandle; | 570 | mFirstHandle = newHandle; |
571 | s->wid = newHandle; | 571 | s->wid = newHandle; |
572 | newHandle->setId(data->list.count()); | 572 | newHandle->setId(data->list.count()); |
573 | s->isSplitter = TRUE; | 573 | s->isSplitter = TRUE; |
574 | s->sizer = pick( newHandle->sizeHint() ); | 574 | s->sizer = pick( newHandle->sizeHint() ); |
575 | if ( first ) | 575 | if ( first ) |
576 | data->list.insert( 0, s ); | 576 | data->list.insert( 0, s ); |
577 | else | 577 | else |
578 | data->list.append( s ); | 578 | data->list.append( s ); |
579 | } | 579 | } |
580 | s = new QSplitterLayoutStruct; | 580 | s = new QSplitterLayoutStruct; |
581 | s->mode = Stretch; | 581 | s->mode = Stretch; |
582 | s->wid = w; | 582 | s->wid = w; |
583 | if ( !testWState( WState_Resized ) && w->sizeHint().isValid() ) | 583 | if ( !testWState( WState_Resized ) && w->sizeHint().isValid() ) |
584 | s->sizer = pick( w->sizeHint() ); | 584 | s->sizer = pick( w->sizeHint() ); |
585 | else | 585 | else |
586 | s->sizer = pick( w->size() ); | 586 | s->sizer = pick( w->size() ); |
587 | s->isSplitter = FALSE; | 587 | s->isSplitter = FALSE; |
588 | if ( first ) | 588 | if ( first ) |
589 | data->list.insert( 0, s ); | 589 | data->list.insert( 0, s ); |
590 | else | 590 | else |
591 | data->list.append( s ); | 591 | data->list.append( s ); |
592 | if ( newHandle && isVisible() ) | 592 | if ( newHandle && isVisible() ) |
593 | newHandle->show(); //will trigger sending of post events | 593 | newHandle->show(); //will trigger sending of post events |
594 | return s; | 594 | return s; |
595 | } | 595 | } |
596 | 596 | ||
597 | 597 | ||
598 | /*! | 598 | /*! |
599 | Tells the splitter that a child widget has been inserted or removed. | 599 | Tells the splitter that a child widget has been inserted or removed. |
600 | The event is passed in \a c. | 600 | The event is passed in \a c. |
601 | */ | 601 | */ |
602 | void KDGanttMinimizeSplitter::childEvent( QChildEvent *c ) | 602 | void KDGanttMinimizeSplitter::childEvent( QChildEvent *c ) |
603 | { | 603 | { |
604 | if ( c->type() == QEvent::ChildInserted ) { | 604 | if ( c->type() == QEvent::ChildInserted ) { |
605 | if ( !c->child()->isWidgetType() ) | 605 | if ( !c->child()->isWidgetType() ) |
606 | return; | 606 | return; |
607 | 607 | ||
608 | if ( ((QWidget*)c->child())->testWFlags( WType_TopLevel ) ) | 608 | if ( ((QWidget*)c->child())->testWFlags( WType_TopLevel ) ) |
609 | return; | 609 | return; |
610 | 610 | ||
611 | QSplitterLayoutStruct *s = data->list.first(); | 611 | QSplitterLayoutStruct *s = data->list.first(); |
612 | while ( s ) { | 612 | while ( s ) { |
613 | if ( s->wid == c->child() ) | 613 | if ( s->wid == c->child() ) |
614 | return; | 614 | return; |
615 | s = data->list.next(); | 615 | s = data->list.next(); |
616 | } | 616 | } |
617 | addWidget( (QWidget*)c->child() ); | 617 | addWidget( (QWidget*)c->child() ); |
618 | recalc( isVisible() ); | 618 | recalc( isVisible() ); |
619 | 619 | ||
620 | } else if ( c->type() == QEvent::ChildRemoved ) { | 620 | } else if ( c->type() == QEvent::ChildRemoved ) { |
621 | QSplitterLayoutStruct *p = 0; | 621 | QSplitterLayoutStruct *p = 0; |
622 | if ( data->list.count() > 1 ) | 622 | if ( data->list.count() > 1 ) |
623 | p = data->list.at(1); //remove handle _after_ first widget. | 623 | p = data->list.at(1); //remove handle _after_ first widget. |
624 | QSplitterLayoutStruct *s = data->list.first(); | 624 | QSplitterLayoutStruct *s = data->list.first(); |
625 | while ( s ) { | 625 | while ( s ) { |
626 | if ( s->wid == c->child() ) { | 626 | if ( s->wid == c->child() ) { |
627 | data->list.removeRef( s ); | 627 | data->list.removeRef( s ); |
628 | delete s; | 628 | delete s; |
629 | if ( p && p->isSplitter ) { | 629 | if ( p && p->isSplitter ) { |
630 | data->list.removeRef( p ); | 630 | data->list.removeRef( p ); |
631 | delete p->wid; //will call childEvent | 631 | delete p->wid; //will call childEvent |
632 | delete p; | 632 | delete p; |
633 | } | 633 | } |
634 | recalcId(); | 634 | recalcId(); |
635 | doResize(); | 635 | doResize(); |
636 | return; | 636 | return; |
637 | } | 637 | } |
638 | p = s; | 638 | p = s; |
639 | s = data->list.next(); | 639 | s = data->list.next(); |
640 | } | 640 | } |
641 | } | 641 | } |
642 | } | 642 | } |
643 | 643 | ||
644 | 644 | ||
645 | /*! | 645 | /*! |
646 | Shows a rubber band at position \a p. If \a p is negative, the | 646 | Shows a rubber band at position \a p. If \a p is negative, the |
647 | rubber band is removed. | 647 | rubber band is removed. |
648 | */ | 648 | */ |
649 | void KDGanttMinimizeSplitter::setRubberband( int p ) | 649 | void KDGanttMinimizeSplitter::setRubberband( int p ) |
650 | { | 650 | { |
651 | #ifdef DESKTOP_VERSION | 651 | #ifdef DESKTOP_VERSION |
652 | QPainter paint( this ); | 652 | QPainter paint( this ); |
653 | paint.setPen( gray ); | 653 | paint.setPen( gray ); |
654 | paint.setBrush( gray ); | 654 | paint.setBrush( gray ); |
655 | paint.setRasterOp( XorROP ); | 655 | paint.setRasterOp( XorROP ); |
656 | QRect r = contentsRect(); | 656 | QRect r = contentsRect(); |
657 | const int rBord = 3; //Themable???? | 657 | const int rBord = 3; //Themable???? |
658 | #if QT_VERSION >= 0x030000 | 658 | #if QT_VERSION >= 0x030000 |
659 | int sw = style().pixelMetric(QStyle::PM_SplitterWidth, this); | 659 | int sw = style().pixelMetric(QStyle::PM_SplitterWidth, this); |
660 | #else | 660 | #else |
661 | int sw = style().splitterWidth(); | 661 | int sw = style().splitterWidth(); |
662 | #endif | 662 | #endif |
663 | if ( orient == Horizontal ) { | 663 | if ( orient == Horizontal ) { |
664 | if ( opaqueOldPos >= 0 ) | 664 | if ( opaqueOldPos >= 0 ) |
665 | paint.drawRect( opaqueOldPos + sw/2 - rBord , r.y(), | 665 | paint.drawRect( opaqueOldPos + sw/2 - rBord , r.y(), |
666 | 2*rBord, r.height() ); | 666 | 2*rBord, r.height() ); |
667 | if ( p >= 0 ) | 667 | if ( p >= 0 ) |
668 | paint.drawRect( p + sw/2 - rBord, r.y(), 2*rBord, r.height() ); | 668 | paint.drawRect( p + sw/2 - rBord, r.y(), 2*rBord, r.height() ); |
669 | } else { | 669 | } else { |
670 | if ( opaqueOldPos >= 0 ) | 670 | if ( opaqueOldPos >= 0 ) |
671 | paint.drawRect( r.x(), opaqueOldPos + sw/2 - rBord, | 671 | paint.drawRect( r.x(), opaqueOldPos + sw/2 - rBord, |
672 | r.width(), 2*rBord ); | 672 | r.width(), 2*rBord ); |
673 | if ( p >= 0 ) | 673 | if ( p >= 0 ) |
674 | paint.drawRect( r.x(), p + sw/2 - rBord, r.width(), 2*rBord ); | 674 | paint.drawRect( r.x(), p + sw/2 - rBord, r.width(), 2*rBord ); |
675 | } | 675 | } |
676 | opaqueOldPos = p; | 676 | opaqueOldPos = p; |
677 | #else | 677 | #else |
678 | if ( !mRubberBand ) { | 678 | if ( !mRubberBand ) { |
679 | mRubberBand = new QFrame( 0, "rubber", WStyle_NoBorder | WStyle_Customize | WStyle_StaysOnTop); | 679 | mRubberBand = new QFrame( 0, "rubber", WStyle_NoBorder | WStyle_Customize | WStyle_StaysOnTop); |
680 | mRubberBand->setFrameStyle( Box | Raised ); | 680 | mRubberBand->setFrameStyle( Box | Raised ); |
681 | mRubberBand->setPalette( QPalette ( Qt::red.light(),Qt::red.dark() ) ); | 681 | //mRubberBand->setPalette( QPalette ( Qt::red.light(),Qt::red.dark() ) ); |
682 | mRubberBand->setPalette( QPalette ( QColor( 178,18,188), QColor( 242,27,255 ) )); | ||
682 | } | 683 | } |
683 | QRect r = contentsRect(); | 684 | QRect r = contentsRect(); |
684 | static int rBord = 0; //Themable???? | 685 | static int rBord = 0; //Themable???? |
685 | if ( !rBord ) { | 686 | if ( !rBord ) { |
686 | if (QApplication::desktop()->width() <= 320 ) | 687 | if (QApplication::desktop()->width() <= 320 ) |
687 | rBord = 4; | 688 | rBord = 3; |
688 | else | 689 | else |
689 | rBord = 5; | 690 | rBord = 4; |
690 | } | 691 | } |
691 | int sw = style().splitterWidth(); | 692 | int sw = style().splitterWidth(); |
692 | if ( orient == Horizontal ) { | 693 | if ( orient == Horizontal ) { |
693 | if ( p >= 0 ) { | 694 | if ( p >= 0 ) { |
694 | QPoint geo = mapToGlobal (QPoint ( p + sw/2 - rBord, r.y())); | 695 | QPoint geo = mapToGlobal (QPoint ( p + sw/2 - rBord, r.y())); |
695 | mRubberBand->setGeometry( geo.x(), geo.y(), 2*rBord, r.height() ); | 696 | mRubberBand->setGeometry( geo.x(), geo.y(), 2*rBord, r.height() ); |
696 | } | 697 | } |
697 | } else { | 698 | } else { |
698 | if ( p >= 0 ) { | 699 | if ( p >= 0 ) { |
699 | QPoint geo = mapToGlobal (QPoint ( r.x(), p + sw/2 - rBord)); | 700 | QPoint geo = mapToGlobal (QPoint ( r.x(), p + sw/2 - rBord)); |
700 | mRubberBand->setGeometry( geo.x(), geo.y(), r.width(), 2*rBord); | 701 | mRubberBand->setGeometry( geo.x(), geo.y(), r.width(), 2*rBord); |
701 | } | 702 | } |
702 | } | 703 | } |
703 | opaqueOldPos = p; | 704 | opaqueOldPos = p; |
704 | if ( ! mRubberBand->isVisible() ) { | 705 | if ( ! mRubberBand->isVisible() ) { |
705 | mRubberBand->show(); | 706 | mRubberBand->show(); |
706 | } | 707 | } |
707 | #endif | 708 | #endif |
708 | } | 709 | } |
709 | 710 | ||
710 | 711 | ||
711 | /*! \reimp */ | 712 | /*! \reimp */ |
712 | bool KDGanttMinimizeSplitter::event( QEvent *e ) | 713 | bool KDGanttMinimizeSplitter::event( QEvent *e ) |
713 | { | 714 | { |
714 | if ( e->type() == QEvent::LayoutHint || ( e->type() == QEvent::Show && data->firstShow ) ) { | 715 | if ( e->type() == QEvent::LayoutHint || ( e->type() == QEvent::Show && data->firstShow ) ) { |
715 | recalc( isVisible() ); | 716 | recalc( isVisible() ); |
716 | if ( e->type() == QEvent::Show ) | 717 | if ( e->type() == QEvent::Show ) |
717 | data->firstShow = FALSE; | 718 | data->firstShow = FALSE; |
718 | } | 719 | } |
719 | return QWidget::event( e ); | 720 | return QWidget::event( e ); |
720 | } | 721 | } |
721 | 722 | ||
722 | 723 | ||
723 | /*! | 724 | /*! |
724 | \obsolete | 725 | \obsolete |
725 | 726 | ||
726 | Draws the splitter handle in the rectangle described by \a x, \a y, | 727 | Draws the splitter handle in the rectangle described by \a x, \a y, |
727 | \a w, \a h using painter \a p. | 728 | \a w, \a h using painter \a p. |
728 | \sa QStyle::drawPrimitive() | 729 | \sa QStyle::drawPrimitive() |
729 | */ | 730 | */ |
730 | void KDGanttMinimizeSplitter::drawSplitter( QPainter *p, | 731 | void KDGanttMinimizeSplitter::drawSplitter( QPainter *p, |
731 | QCOORD x, QCOORD y, QCOORD w, QCOORD h ) | 732 | QCOORD x, QCOORD y, QCOORD w, QCOORD h ) |
732 | { | 733 | { |
733 | #if 0 | 734 | #if 0 |
734 | // LR | 735 | // LR |
735 | style().drawPrimitive(QStyle::PE_Splitter, p, QRect(x, y, w, h), colorGroup(), | 736 | style().drawPrimitive(QStyle::PE_Splitter, p, QRect(x, y, w, h), colorGroup(), |
736 | (orientation() == Qt::Horizontal ? | 737 | (orientation() == Qt::Horizontal ? |
737 | QStyle::Style_Horizontal : 0)); | 738 | QStyle::Style_Horizontal : 0)); |
738 | #endif | 739 | #endif |
739 | } | 740 | } |
740 | 741 | ||
741 | 742 | ||
742 | /*! | 743 | /*! |
743 | Returns the id of the splitter to the right of or below the widget \a w, | 744 | Returns the id of the splitter to the right of or below the widget \a w, |
744 | or 0 if there is no such splitter | 745 | or 0 if there is no such splitter |
745 | (i.e. it is either not in this KDGanttMinimizeSplitter or it is at the end). | 746 | (i.e. it is either not in this KDGanttMinimizeSplitter or it is at the end). |
746 | */ | 747 | */ |
747 | int KDGanttMinimizeSplitter::idAfter( QWidget* w ) const | 748 | int KDGanttMinimizeSplitter::idAfter( QWidget* w ) const |
748 | { | 749 | { |
749 | QSplitterLayoutStruct *s = data->list.first(); | 750 | QSplitterLayoutStruct *s = data->list.first(); |
750 | bool seen_w = FALSE; | 751 | bool seen_w = FALSE; |
751 | while ( s ) { | 752 | while ( s ) { |
752 | if ( s->isSplitter && seen_w ) | 753 | if ( s->isSplitter && seen_w ) |
753 | return data->list.at(); | 754 | return data->list.at(); |
754 | if ( !s->isSplitter && s->wid == w ) | 755 | if ( !s->isSplitter && s->wid == w ) |
755 | seen_w = TRUE; | 756 | seen_w = TRUE; |
756 | s = data->list.next(); | 757 | s = data->list.next(); |
757 | } | 758 | } |
758 | return 0; | 759 | return 0; |
759 | } | 760 | } |
760 | 761 | ||
761 | 762 | ||
762 | /*! | 763 | /*! |
763 | Moves the left/top edge of the splitter handle with id \a id as | 764 | Moves the left/top edge of the splitter handle with id \a id as |
764 | close as possible to position \a p, which is the distance from the | 765 | close as possible to position \a p, which is the distance from the |
765 | left (or top) edge of the widget. | 766 | left (or top) edge of the widget. |
766 | 767 | ||
767 | For Arabic and Hebrew the layout is reversed, and using this | 768 | For Arabic and Hebrew the layout is reversed, and using this |
768 | function to set the position of the splitter might lead to | 769 | function to set the position of the splitter might lead to |
769 | unexpected results, since in Arabic and Hebrew the position of | 770 | unexpected results, since in Arabic and Hebrew the position of |
770 | splitter one is to the left of the position of splitter zero. | 771 | splitter one is to the left of the position of splitter zero. |
771 | 772 | ||
772 | \sa idAfter() | 773 | \sa idAfter() |
773 | */ | 774 | */ |
774 | void KDGanttMinimizeSplitter::moveSplitter( QCOORD p, int id ) | 775 | void KDGanttMinimizeSplitter::moveSplitter( QCOORD p, int id ) |
775 | { | 776 | { |
776 | p = adjustPos( p, id ); | 777 | p = adjustPos( p, id ); |
777 | QSplitterLayoutStruct *s = data->list.at(id); | 778 | QSplitterLayoutStruct *s = data->list.at(id); |
778 | int oldP = orient == Horizontal ? s->wid->x() : s->wid->y(); | 779 | int oldP = orient == Horizontal ? s->wid->x() : s->wid->y(); |
779 | bool upLeft; | 780 | bool upLeft; |
780 | if ( false && orient == Horizontal ) { | 781 | if ( false && orient == Horizontal ) { |
781 | p += s->wid->width(); | 782 | p += s->wid->width(); |
782 | upLeft = p > oldP; | 783 | upLeft = p > oldP; |
783 | } else | 784 | } else |
784 | upLeft = p < oldP; | 785 | upLeft = p < oldP; |
785 | 786 | ||
786 | moveAfter( p, id, upLeft ); | 787 | moveAfter( p, id, upLeft ); |
787 | moveBefore( p-1, id-1, upLeft ); | 788 | moveBefore( p-1, id-1, upLeft ); |
788 | 789 | ||
789 | storeSizes(); | 790 | storeSizes(); |
790 | } | 791 | } |
791 | 792 | ||
792 | 793 | ||
793 | void KDGanttMinimizeSplitter::setG( QWidget *w, int p, int s, bool isSplitter ) | 794 | void KDGanttMinimizeSplitter::setG( QWidget *w, int p, int s, bool isSplitter ) |
794 | { | 795 | { |
795 | if ( orient == Horizontal ) { | 796 | if ( orient == Horizontal ) { |
796 | if ( false && orient == Horizontal && !isSplitter ) | 797 | if ( false && orient == Horizontal && !isSplitter ) |
797 | p = contentsRect().width() - p - s; | 798 | p = contentsRect().width() - p - s; |
798 | w->setGeometry( p, contentsRect().y(), s, contentsRect().height() ); | 799 | w->setGeometry( p, contentsRect().y(), s, contentsRect().height() ); |
799 | } else | 800 | } else |
800 | w->setGeometry( contentsRect().x(), p, contentsRect().width(), s ); | 801 | w->setGeometry( contentsRect().x(), p, contentsRect().width(), s ); |
801 | } | 802 | } |
802 | 803 | ||
803 | 804 | ||
804 | /* | 805 | /* |
805 | Places the right/bottom edge of the widget at \a id at position \a pos. | 806 | Places the right/bottom edge of the widget at \a id at position \a pos. |
806 | 807 | ||
807 | \sa idAfter() | 808 | \sa idAfter() |
808 | */ | 809 | */ |
809 | void KDGanttMinimizeSplitter::moveBefore( int pos, int id, bool upLeft ) | 810 | void KDGanttMinimizeSplitter::moveBefore( int pos, int id, bool upLeft ) |
810 | { | 811 | { |
811 | if( id < 0 ) | 812 | if( id < 0 ) |
812 | return; | 813 | return; |
813 | QSplitterLayoutStruct *s = data->list.at(id); | 814 | QSplitterLayoutStruct *s = data->list.at(id); |
814 | if ( !s ) | 815 | if ( !s ) |
815 | return; | 816 | return; |
816 | QWidget *w = s->wid; | 817 | QWidget *w = s->wid; |
817 | if ( w->isHidden() ) { | 818 | if ( w->isHidden() ) { |
818 | moveBefore( pos, id-1, upLeft ); | 819 | moveBefore( pos, id-1, upLeft ); |
819 | } else if ( s->isSplitter ) { | 820 | } else if ( s->isSplitter ) { |
820 | int pos1, pos2; | 821 | int pos1, pos2; |
821 | int dd = s->sizer; | 822 | int dd = s->sizer; |
822 | if( false && orient == Horizontal ) { | 823 | if( false && orient == Horizontal ) { |
823 | pos1 = pos; | 824 | pos1 = pos; |
824 | pos2 = pos + dd; | 825 | pos2 = pos + dd; |
825 | } else { | 826 | } else { |
826 | pos2 = pos - dd; | 827 | pos2 = pos - dd; |
827 | pos1 = pos2 + 1; | 828 | pos1 = pos2 + 1; |
828 | } | 829 | } |
829 | if ( upLeft ) { | 830 | if ( upLeft ) { |
830 | setG( w, pos1, dd, TRUE ); | 831 | setG( w, pos1, dd, TRUE ); |
831 | moveBefore( pos2, id-1, upLeft ); | 832 | moveBefore( pos2, id-1, upLeft ); |
832 | } else { | 833 | } else { |
833 | moveBefore( pos2, id-1, upLeft ); | 834 | moveBefore( pos2, id-1, upLeft ); |
834 | setG( w, pos1, dd, TRUE ); | 835 | setG( w, pos1, dd, TRUE ); |
835 | } | 836 | } |
836 | } else { | 837 | } else { |
837 | int dd, newLeft, nextPos; | 838 | int dd, newLeft, nextPos; |
838 | if( false && orient == Horizontal ) { | 839 | if( false && orient == Horizontal ) { |
839 | dd = w->geometry().right() - pos; | 840 | dd = w->geometry().right() - pos; |
840 | dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); | 841 | dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); |
841 | newLeft = pos+1; | 842 | newLeft = pos+1; |
842 | nextPos = newLeft + dd; | 843 | nextPos = newLeft + dd; |
843 | } else { | 844 | } else { |
844 | dd = pos - pick( w->pos() ) + 1; | 845 | dd = pos - pick( w->pos() ) + 1; |
845 | dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); | 846 | dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); |
846 | newLeft = pos-dd+1; | 847 | newLeft = pos-dd+1; |
847 | nextPos = newLeft - 1; | 848 | nextPos = newLeft - 1; |
848 | } | 849 | } |
849 | setG( w, newLeft, dd, TRUE ); | 850 | setG( w, newLeft, dd, TRUE ); |
850 | moveBefore( nextPos, id-1, upLeft ); | 851 | moveBefore( nextPos, id-1, upLeft ); |
851 | } | 852 | } |
852 | } | 853 | } |
853 | 854 | ||
854 | 855 | ||
855 | /* | 856 | /* |
856 | Places the left/top edge of the widget at \a id at position \a pos. | 857 | Places the left/top edge of the widget at \a id at position \a pos. |
857 | 858 | ||
858 | \sa idAfter() | 859 | \sa idAfter() |
859 | */ | 860 | */ |
860 | void KDGanttMinimizeSplitter::moveAfter( int pos, int id, bool upLeft ) | 861 | void KDGanttMinimizeSplitter::moveAfter( int pos, int id, bool upLeft ) |
861 | { | 862 | { |
862 | QSplitterLayoutStruct *s = id < int(data->list.count()) ? | 863 | QSplitterLayoutStruct *s = id < int(data->list.count()) ? |
863 | data->list.at(id) : 0; | 864 | data->list.at(id) : 0; |
864 | if ( !s ) | 865 | if ( !s ) |
865 | return; | 866 | return; |
866 | QWidget *w = s->wid; | 867 | QWidget *w = s->wid; |
867 | if ( w->isHidden() ) { | 868 | if ( w->isHidden() ) { |
868 | moveAfter( pos, id+1, upLeft ); | 869 | moveAfter( pos, id+1, upLeft ); |
869 | } else if ( pick( w->pos() ) == pos ) { | 870 | } else if ( pick( w->pos() ) == pos ) { |
870 | //No need to do anything if it's already there. | 871 | //No need to do anything if it's already there. |
871 | return; | 872 | return; |
872 | } else if ( s->isSplitter ) { | 873 | } else if ( s->isSplitter ) { |
873 | int dd = s->sizer; | 874 | int dd = s->sizer; |
874 | int pos1, pos2; | 875 | int pos1, pos2; |
875 | if( false && orient == Horizontal ) { | 876 | if( false && orient == Horizontal ) { |
876 | pos2 = pos - dd; | 877 | pos2 = pos - dd; |
877 | pos1 = pos2 + 1; | 878 | pos1 = pos2 + 1; |
878 | } else { | 879 | } else { |
879 | pos1 = pos; | 880 | pos1 = pos; |
880 | pos2 = pos + dd; | 881 | pos2 = pos + dd; |
881 | } | 882 | } |
882 | if ( upLeft ) { | 883 | if ( upLeft ) { |
883 | setG( w, pos1, dd, TRUE ); | 884 | setG( w, pos1, dd, TRUE ); |
884 | moveAfter( pos2, id+1, upLeft ); | 885 | moveAfter( pos2, id+1, upLeft ); |
885 | } else { | 886 | } else { |
886 | moveAfter( pos2, id+1, upLeft ); | 887 | moveAfter( pos2, id+1, upLeft ); |
887 | setG( w, pos1, dd, TRUE ); | 888 | setG( w, pos1, dd, TRUE ); |
888 | } | 889 | } |
889 | } else { | 890 | } else { |
890 | int left = pick( w->pos() ); | 891 | int left = pick( w->pos() ); |
891 | int right, dd,/* newRight,*/ newLeft, nextPos; | 892 | int right, dd,/* newRight,*/ newLeft, nextPos; |
892 | if ( false && orient == Horizontal ) { | 893 | if ( false && orient == Horizontal ) { |
893 | dd = pos - left + 1; | 894 | dd = pos - left + 1; |
894 | dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); | 895 | dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); |
895 | newLeft = pos-dd+1; | 896 | newLeft = pos-dd+1; |
896 | nextPos = newLeft - 1; | 897 | nextPos = newLeft - 1; |
897 | } else { | 898 | } else { |
898 | right = pick( w->geometry().bottomRight() ); | 899 | right = pick( w->geometry().bottomRight() ); |
899 | dd = right - pos + 1; | 900 | dd = right - pos + 1; |
900 | dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); | 901 | dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize()))); |
901 | /*newRight = pos+dd-1;*/ | 902 | /*newRight = pos+dd-1;*/ |
902 | newLeft = pos; | 903 | newLeft = pos; |
903 | nextPos = newLeft + dd; | 904 | nextPos = newLeft + dd; |
904 | } | 905 | } |
905 | setG( w, newLeft, dd, TRUE ); | 906 | setG( w, newLeft, dd, TRUE ); |
906 | /*if( right != newRight )*/ | 907 | /*if( right != newRight )*/ |
907 | moveAfter( nextPos, id+1, upLeft ); | 908 | moveAfter( nextPos, id+1, upLeft ); |
908 | } | 909 | } |
909 | } | 910 | } |
910 | 911 | ||
911 | 912 | ||
912 | void KDGanttMinimizeSplitter::expandPos( int id, int* min, int* max ) | 913 | void KDGanttMinimizeSplitter::expandPos( int id, int* min, int* max ) |
913 | { | 914 | { |
914 | QSplitterLayoutStruct *s = data->list.at(id-1); | 915 | QSplitterLayoutStruct *s = data->list.at(id-1); |
915 | QWidget* w = s->wid; | 916 | QWidget* w = s->wid; |
916 | *min = pick( w->mapToParent( QPoint(0,0) ) ); | 917 | *min = pick( w->mapToParent( QPoint(0,0) ) ); |
917 | 918 | ||
918 | if ( (uint) id == data->list.count() ) { | 919 | if ( (uint) id == data->list.count() ) { |
919 | pick( size() ); | 920 | pick( size() ); |
920 | } | 921 | } |
921 | else { | 922 | else { |
922 | QSplitterLayoutStruct *s = data->list.at(id+1); | 923 | QSplitterLayoutStruct *s = data->list.at(id+1); |
923 | QWidget* w = s->wid; | 924 | QWidget* w = s->wid; |
924 | *max = pick( w->mapToParent( QPoint( w->width(), w->height() ) ) ) -8; | 925 | *max = pick( w->mapToParent( QPoint( w->width(), w->height() ) ) ) -8; |
925 | } | 926 | } |
926 | } | 927 | } |
927 | 928 | ||
928 | 929 | ||
929 | /*! | 930 | /*! |
930 | Returns the valid range of the splitter with id \a id in \a *min and \a *max. | 931 | Returns the valid range of the splitter with id \a id in \a *min and \a *max. |
931 | 932 | ||
932 | \sa idAfter() | 933 | \sa idAfter() |
933 | */ | 934 | */ |
934 | 935 | ||
935 | void KDGanttMinimizeSplitter::getRange( int id, int *min, int *max ) | 936 | void KDGanttMinimizeSplitter::getRange( int id, int *min, int *max ) |
936 | { | 937 | { |
937 | int minB = 0;//before | 938 | int minB = 0;//before |
938 | int maxB = 0; | 939 | int maxB = 0; |
939 | int minA = 0; | 940 | int minA = 0; |
940 | int maxA = 0;//after | 941 | int maxA = 0;//after |
941 | int n = data->list.count(); | 942 | int n = data->list.count(); |
942 | if ( id < 0 || id >= n ) | 943 | if ( id < 0 || id >= n ) |
943 | return; | 944 | return; |
944 | int i; | 945 | int i; |
945 | for ( i = 0; i < id; i++ ) { | 946 | for ( i = 0; i < id; i++ ) { |
946 | QSplitterLayoutStruct *s = data->list.at(i); | 947 | QSplitterLayoutStruct *s = data->list.at(i); |
947 | if ( s->wid->isHidden() ) { | 948 | if ( s->wid->isHidden() ) { |
948 | //ignore | 949 | //ignore |
949 | } else if ( s->isSplitter ) { | 950 | } else if ( s->isSplitter ) { |
950 | minB += s->sizer; | 951 | minB += s->sizer; |
951 | maxB += s->sizer; | 952 | maxB += s->sizer; |
952 | } else { | 953 | } else { |
953 | minB += pick( minSize(s->wid) ); | 954 | minB += pick( minSize(s->wid) ); |
954 | maxB += pick( s->wid->maximumSize() ); | 955 | maxB += pick( s->wid->maximumSize() ); |
955 | } | 956 | } |
956 | } | 957 | } |
957 | for ( i = id; i < n; i++ ) { | 958 | for ( i = id; i < n; i++ ) { |
958 | QSplitterLayoutStruct *s = data->list.at(i); | 959 | QSplitterLayoutStruct *s = data->list.at(i); |
959 | if ( s->wid->isHidden() ) { | 960 | if ( s->wid->isHidden() ) { |
960 | //ignore | 961 | //ignore |
961 | } else if ( s->isSplitter ) { | 962 | } else if ( s->isSplitter ) { |
962 | minA += s->sizer; | 963 | minA += s->sizer; |
963 | maxA += s->sizer; | 964 | maxA += s->sizer; |
964 | } else { | 965 | } else { |
965 | minA += pick( minSize(s->wid) ); | 966 | minA += pick( minSize(s->wid) ); |
966 | maxA += pick( s->wid->maximumSize() ); | 967 | maxA += pick( s->wid->maximumSize() ); |
967 | } | 968 | } |
968 | } | 969 | } |
969 | QRect r = contentsRect(); | 970 | QRect r = contentsRect(); |
970 | if ( orient == Horizontal && false ) { | 971 | if ( orient == Horizontal && false ) { |
971 | #if QT_VERSION >= 0x030000 | 972 | #if QT_VERSION >= 0x030000 |
972 | int splitterWidth = style().pixelMetric(QStyle::PM_SplitterWidth, this); | 973 | int splitterWidth = style().pixelMetric(QStyle::PM_SplitterWidth, this); |
973 | #else | 974 | #else |
974 | int splitterWidth = style().splitterWidth(); | 975 | int splitterWidth = style().splitterWidth(); |
975 | #endif | 976 | #endif |
976 | 977 | ||
977 | if ( min ) | 978 | if ( min ) |
978 | *min = pick(r.topRight()) - QMIN( maxB, pick(r.size())-minA ) - splitterWidth; | 979 | *min = pick(r.topRight()) - QMIN( maxB, pick(r.size())-minA ) - splitterWidth; |
979 | if ( max ) | 980 | if ( max ) |
980 | *max = pick(r.topRight()) - QMAX( minB, pick(r.size())-maxA ) - splitterWidth; | 981 | *max = pick(r.topRight()) - QMAX( minB, pick(r.size())-maxA ) - splitterWidth; |
981 | } else { | 982 | } else { |
982 | if ( min ) | 983 | if ( min ) |
983 | *min = pick(r.topLeft()) + QMAX( minB, pick(r.size())-maxA ); | 984 | *min = pick(r.topLeft()) + QMAX( minB, pick(r.size())-maxA ); |
984 | if ( max ) | 985 | if ( max ) |
985 | *max = pick(r.topLeft()) + QMIN( maxB, pick(r.size())-minA ); | 986 | *max = pick(r.topLeft()) + QMIN( maxB, pick(r.size())-minA ); |
986 | } | 987 | } |
987 | } | 988 | } |
988 | 989 | ||
989 | 990 | ||
990 | /*! | 991 | /*! |
991 | Returns the closest legal position to \a p of the splitter with id \a id. | 992 | Returns the closest legal position to \a p of the splitter with id \a id. |
992 | 993 | ||
993 | \sa idAfter() | 994 | \sa idAfter() |
994 | */ | 995 | */ |
995 | 996 | ||
996 | int KDGanttMinimizeSplitter::adjustPos( int p, int id ) | 997 | int KDGanttMinimizeSplitter::adjustPos( int p, int id ) |
997 | { | 998 | { |
998 | int min = 0; | 999 | int min = 0; |
999 | int max = 0; | 1000 | int max = 0; |
1000 | getRange( id, &min, &max ); | 1001 | getRange( id, &min, &max ); |
1001 | p = QMAX( min, QMIN( p, max ) ); | 1002 | p = QMAX( min, QMIN( p, max ) ); |
1002 | 1003 | ||
1003 | return p; | 1004 | return p; |
1004 | } | 1005 | } |
1005 | 1006 | ||
1006 | 1007 | ||
1007 | void KDGanttMinimizeSplitter::doResize() | 1008 | void KDGanttMinimizeSplitter::doResize() |
1008 | { | 1009 | { |
1009 | QRect r = contentsRect(); | 1010 | QRect r = contentsRect(); |
1010 | int i; | 1011 | int i; |
1011 | int n = data->list.count(); | 1012 | int n = data->list.count(); |
1012 | QMemArray<QLayoutStruct> a( n ); | 1013 | QMemArray<QLayoutStruct> a( n ); |
1013 | for ( i = 0; i< n; i++ ) { | 1014 | for ( i = 0; i< n; i++ ) { |
1014 | a[i].init(); | 1015 | a[i].init(); |
1015 | QSplitterLayoutStruct *s = data->list.at(i); | 1016 | QSplitterLayoutStruct *s = data->list.at(i); |
1016 | if ( s->wid->isHidden() ) { | 1017 | if ( s->wid->isHidden() ) { |
1017 | a[i].stretch = 0; | 1018 | a[i].stretch = 0; |
1018 | a[i].sizeHint = a[i].minimumSize = 0; | 1019 | a[i].sizeHint = a[i].minimumSize = 0; |
1019 | a[i].maximumSize = 0; | 1020 | a[i].maximumSize = 0; |
1020 | } else if ( s->isSplitter ) { | 1021 | } else if ( s->isSplitter ) { |
1021 | a[i].stretch = 0; | 1022 | a[i].stretch = 0; |
1022 | a[i].sizeHint = a[i].minimumSize = a[i].maximumSize = s->sizer; | 1023 | a[i].sizeHint = a[i].minimumSize = a[i].maximumSize = s->sizer; |
1023 | a[i].empty = FALSE; | 1024 | a[i].empty = FALSE; |
1024 | } else if ( s->mode == KeepSize ) { | 1025 | } else if ( s->mode == KeepSize ) { |
1025 | a[i].stretch = 0; | 1026 | a[i].stretch = 0; |
1026 | a[i].minimumSize = pick( minSize(s->wid) ); | 1027 | a[i].minimumSize = pick( minSize(s->wid) ); |
1027 | a[i].sizeHint = s->sizer; | 1028 | a[i].sizeHint = s->sizer; |
1028 | a[i].maximumSize = pick( s->wid->maximumSize() ); | 1029 | a[i].maximumSize = pick( s->wid->maximumSize() ); |
1029 | a[i].empty = FALSE; | 1030 | a[i].empty = FALSE; |
1030 | } else if ( s->mode == FollowSizeHint ) { | 1031 | } else if ( s->mode == FollowSizeHint ) { |
1031 | a[i].stretch = 0; | 1032 | a[i].stretch = 0; |
1032 | a[i].minimumSize = a[i].sizeHint = pick( s->wid->sizeHint() ); | 1033 | a[i].minimumSize = a[i].sizeHint = pick( s->wid->sizeHint() ); |
1033 | a[i].maximumSize = pick( s->wid->maximumSize() ); | 1034 | a[i].maximumSize = pick( s->wid->maximumSize() ); |
1034 | a[i].empty = FALSE; | 1035 | a[i].empty = FALSE; |
1035 | } else { //proportional | 1036 | } else { //proportional |
1036 | a[i].stretch = s->sizer; | 1037 | a[i].stretch = s->sizer; |
1037 | a[i].maximumSize = pick( s->wid->maximumSize() ); | 1038 | a[i].maximumSize = pick( s->wid->maximumSize() ); |
1038 | a[i].sizeHint = a[i].minimumSize = pick( minSize(s->wid) ); | 1039 | a[i].sizeHint = a[i].minimumSize = pick( minSize(s->wid) ); |
1039 | a[i].empty = FALSE; | 1040 | a[i].empty = FALSE; |
1040 | } | 1041 | } |
1041 | } | 1042 | } |
1042 | 1043 | ||
1043 | kdganttGeomCalc( a, 0, n, pick( r.topLeft() ), pick( r.size() ), 0 ); | 1044 | kdganttGeomCalc( a, 0, n, pick( r.topLeft() ), pick( r.size() ), 0 ); |
1044 | 1045 | ||
1045 | for ( i = 0; i< n; i++ ) { | 1046 | for ( i = 0; i< n; i++ ) { |
1046 | QSplitterLayoutStruct *s = data->list.at(i); | 1047 | QSplitterLayoutStruct *s = data->list.at(i); |
1047 | setG( s->wid, a[i].pos, a[i].size ); | 1048 | setG( s->wid, a[i].pos, a[i].size ); |
1048 | } | 1049 | } |
1049 | 1050 | ||
1050 | } | 1051 | } |
1051 | 1052 | ||
1052 | 1053 | ||
1053 | void KDGanttMinimizeSplitter::recalc( bool update ) | 1054 | void KDGanttMinimizeSplitter::recalc( bool update ) |
1054 | { | 1055 | { |
1055 | int fi = 2*frameWidth(); | 1056 | int fi = 2*frameWidth(); |
1056 | int maxl = fi; | 1057 | int maxl = fi; |
1057 | int minl = fi; | 1058 | int minl = fi; |
1058 | int maxt = QWIDGETSIZE_MAX; | 1059 | int maxt = QWIDGETSIZE_MAX; |
1059 | int mint = fi; | 1060 | int mint = fi; |
1060 | int n = data->list.count(); | 1061 | int n = data->list.count(); |
1061 | bool first = TRUE; | 1062 | bool first = TRUE; |
1062 | /* | 1063 | /* |
1063 | The splitter before a hidden widget is always hidden. | 1064 | The splitter before a hidden widget is always hidden. |
1064 | The splitter before the first visible widget is hidden. | 1065 | The splitter before the first visible widget is hidden. |
1065 | The splitter before any other visible widget is visible. | 1066 | The splitter before any other visible widget is visible. |
1066 | */ | 1067 | */ |
1067 | for ( int i = 0; i< n; i++ ) { | 1068 | for ( int i = 0; i< n; i++ ) { |
1068 | QSplitterLayoutStruct *s = data->list.at(i); | 1069 | QSplitterLayoutStruct *s = data->list.at(i); |
1069 | if ( !s->isSplitter ) { | 1070 | if ( !s->isSplitter ) { |
1070 | QSplitterLayoutStruct *p = (i > 0) ? p = data->list.at( i-1 ) : 0; | 1071 | QSplitterLayoutStruct *p = (i > 0) ? p = data->list.at( i-1 ) : 0; |
1071 | if ( p && p->isSplitter ) | 1072 | if ( p && p->isSplitter ) |
1072 | if ( first || s->wid->isHidden() ) | 1073 | if ( first || s->wid->isHidden() ) |
1073 | p->wid->hide(); //may trigger new recalc | 1074 | p->wid->hide(); //may trigger new recalc |
1074 | else | 1075 | else |
1075 | p->wid->show(); //may trigger new recalc | 1076 | p->wid->show(); //may trigger new recalc |
1076 | if ( !s->wid->isHidden() ) | 1077 | if ( !s->wid->isHidden() ) |
1077 | first = FALSE; | 1078 | first = FALSE; |
1078 | } | 1079 | } |
1079 | } | 1080 | } |
1080 | 1081 | ||
1081 | bool empty=TRUE; | 1082 | bool empty=TRUE; |
1082 | for ( int j = 0; j< n; j++ ) { | 1083 | for ( int j = 0; j< n; j++ ) { |
1083 | QSplitterLayoutStruct *s = data->list.at(j); | 1084 | QSplitterLayoutStruct *s = data->list.at(j); |
1084 | if ( !s->wid->isHidden() ) { | 1085 | if ( !s->wid->isHidden() ) { |
1085 | empty = FALSE; | 1086 | empty = FALSE; |
1086 | if ( s->isSplitter ) { | 1087 | if ( s->isSplitter ) { |
1087 | minl += s->sizer; | 1088 | minl += s->sizer; |
1088 | maxl += s->sizer; | 1089 | maxl += s->sizer; |
1089 | } else { | 1090 | } else { |
1090 | QSize minS = minSize(s->wid); | 1091 | QSize minS = minSize(s->wid); |
1091 | minl += pick( minS ); | 1092 | minl += pick( minS ); |
1092 | maxl += pick( s->wid->maximumSize() ); | 1093 | maxl += pick( s->wid->maximumSize() ); |
1093 | mint = QMAX( mint, trans( minS )); | 1094 | mint = QMAX( mint, trans( minS )); |
1094 | int tm = trans( s->wid->maximumSize() ); | 1095 | int tm = trans( s->wid->maximumSize() ); |
1095 | if ( tm > 0 ) | 1096 | if ( tm > 0 ) |
1096 | maxt = QMIN( maxt, tm ); | 1097 | maxt = QMIN( maxt, tm ); |
1097 | } | 1098 | } |
1098 | } | 1099 | } |
1099 | } | 1100 | } |
1100 | if ( empty ) { | 1101 | if ( empty ) { |
1101 | if ( parentWidget() != 0 && parentWidget()->inherits("KDGanttMinimizeSplitter") ) { | 1102 | if ( parentWidget() != 0 && parentWidget()->inherits("KDGanttMinimizeSplitter") ) { |
1102 | // nested splitters; be nice | 1103 | // nested splitters; be nice |
1103 | maxl = maxt = 0; | 1104 | maxl = maxt = 0; |
1104 | } else { | 1105 | } else { |
1105 | // KDGanttMinimizeSplitter with no children yet | 1106 | // KDGanttMinimizeSplitter with no children yet |
1106 | maxl = QWIDGETSIZE_MAX; | 1107 | maxl = QWIDGETSIZE_MAX; |
1107 | } | 1108 | } |
1108 | } else { | 1109 | } else { |
1109 | maxl = QMIN( maxl, QWIDGETSIZE_MAX ); | 1110 | maxl = QMIN( maxl, QWIDGETSIZE_MAX ); |
1110 | } | 1111 | } |
1111 | if ( maxt < mint ) | 1112 | if ( maxt < mint ) |
1112 | maxt = mint; | 1113 | maxt = mint; |
1113 | 1114 | ||
1114 | if ( orient == Horizontal ) { | 1115 | if ( orient == Horizontal ) { |
1115 | setMaximumSize( maxl, maxt ); | 1116 | setMaximumSize( maxl, maxt ); |
1116 | setMinimumSize( minl, mint ); | 1117 | setMinimumSize( minl, mint ); |
1117 | } else { | 1118 | } else { |
1118 | setMaximumSize( maxt, maxl ); | 1119 | setMaximumSize( maxt, maxl ); |
1119 | setMinimumSize( mint, minl ); | 1120 | setMinimumSize( mint, minl ); |
1120 | } | 1121 | } |
1121 | if ( update ) | 1122 | if ( update ) |
1122 | doResize(); | 1123 | doResize(); |
1123 | } | 1124 | } |
1124 | 1125 | ||
1125 | /*! | 1126 | /*! |
1126 | Sets resize mode of \a w to \a mode. | 1127 | Sets resize mode of \a w to \a mode. |
1127 | 1128 | ||
1128 | \sa ResizeMode | 1129 | \sa ResizeMode |
1129 | */ | 1130 | */ |
1130 | 1131 | ||
1131 | void KDGanttMinimizeSplitter::setResizeMode( QWidget *w, ResizeMode mode ) | 1132 | void KDGanttMinimizeSplitter::setResizeMode( QWidget *w, ResizeMode mode ) |
1132 | { | 1133 | { |
1133 | processChildEvents(); | 1134 | processChildEvents(); |
1134 | QSplitterLayoutStruct *s = data->list.first(); | 1135 | QSplitterLayoutStruct *s = data->list.first(); |
1135 | while ( s ) { | 1136 | while ( s ) { |
1136 | if ( s->wid == w ) { | 1137 | if ( s->wid == w ) { |
1137 | s->mode = mode; | 1138 | s->mode = mode; |
1138 | return; | 1139 | return; |
1139 | } | 1140 | } |
1140 | s = data->list.next(); | 1141 | s = data->list.next(); |
1141 | } | 1142 | } |
1142 | s = addWidget( w, TRUE ); | 1143 | s = addWidget( w, TRUE ); |
1143 | s->mode = mode; | 1144 | s->mode = mode; |
1144 | } | 1145 | } |
1145 | 1146 | ||
1146 | 1147 | ||
1147 | /*! | 1148 | /*! |
1148 | Returns TRUE if opaque resize is on; otherwise returns FALSE. | 1149 | Returns TRUE if opaque resize is on; otherwise returns FALSE. |
1149 | 1150 | ||
1150 | \sa setOpaqueResize() | 1151 | \sa setOpaqueResize() |
1151 | */ | 1152 | */ |
1152 | 1153 | ||
1153 | bool KDGanttMinimizeSplitter::opaqueResize() const | 1154 | bool KDGanttMinimizeSplitter::opaqueResize() const |
1154 | { | 1155 | { |
1155 | return data->opaque; | 1156 | return data->opaque; |
1156 | } | 1157 | } |
1157 | 1158 | ||
1158 | 1159 | ||
1159 | /*! | 1160 | /*! |
1160 | If \a on is TRUE then opaque resizing is turned on; otherwise | 1161 | If \a on is TRUE then opaque resizing is turned on; otherwise |
1161 | opaque resizing is turned off. | 1162 | opaque resizing is turned off. |
1162 | Opaque resizing is initially turned off. | 1163 | Opaque resizing is initially turned off. |
1163 | 1164 | ||
1164 | \sa opaqueResize() | 1165 | \sa opaqueResize() |
1165 | */ | 1166 | */ |
1166 | 1167 | ||
1167 | void KDGanttMinimizeSplitter::setOpaqueResize( bool on ) | 1168 | void KDGanttMinimizeSplitter::setOpaqueResize( bool on ) |
1168 | { | 1169 | { |
1169 | data->opaque = on; | 1170 | data->opaque = on; |
1170 | } | 1171 | } |
1171 | 1172 | ||
1172 | 1173 | ||
1173 | /*! | 1174 | /*! |
1174 | Moves widget \a w to the leftmost/top position. | 1175 | Moves widget \a w to the leftmost/top position. |
1175 | */ | 1176 | */ |
1176 | 1177 | ||
1177 | void KDGanttMinimizeSplitter::moveToFirst( QWidget *w ) | 1178 | void KDGanttMinimizeSplitter::moveToFirst( QWidget *w ) |
1178 | { | 1179 | { |
1179 | processChildEvents(); | 1180 | processChildEvents(); |
1180 | bool found = FALSE; | 1181 | bool found = FALSE; |
1181 | QSplitterLayoutStruct *s = data->list.first(); | 1182 | QSplitterLayoutStruct *s = data->list.first(); |
1182 | while ( s ) { | 1183 | while ( s ) { |
1183 | if ( s->wid == w ) { | 1184 | if ( s->wid == w ) { |
1184 | found = TRUE; | 1185 | found = TRUE; |
1185 | QSplitterLayoutStruct *p = data->list.prev(); | 1186 | QSplitterLayoutStruct *p = data->list.prev(); |
1186 | if ( p ) { // not already at first place | 1187 | if ( p ) { // not already at first place |
1187 | data->list.take(); //take p | 1188 | data->list.take(); //take p |
1188 | data->list.take(); // take s | 1189 | data->list.take(); // take s |
1189 | data->list.insert( 0, p ); | 1190 | data->list.insert( 0, p ); |
1190 | data->list.insert( 0, s ); | 1191 | data->list.insert( 0, s ); |
1191 | } | 1192 | } |
1192 | break; | 1193 | break; |
1193 | } | 1194 | } |
1194 | s = data->list.next(); | 1195 | s = data->list.next(); |
1195 | } | 1196 | } |
1196 | if ( !found ) | 1197 | if ( !found ) |
1197 | addWidget( w, TRUE ); | 1198 | addWidget( w, TRUE ); |
1198 | recalcId(); | 1199 | recalcId(); |
1199 | } | 1200 | } |
1200 | 1201 | ||
1201 | 1202 | ||
1202 | /*! | 1203 | /*! |
1203 | Moves widget \a w to the rightmost/bottom position. | 1204 | Moves widget \a w to the rightmost/bottom position. |
1204 | */ | 1205 | */ |
1205 | 1206 | ||
1206 | void KDGanttMinimizeSplitter::moveToLast( QWidget *w ) | 1207 | void KDGanttMinimizeSplitter::moveToLast( QWidget *w ) |
1207 | { | 1208 | { |
1208 | processChildEvents(); | 1209 | processChildEvents(); |
1209 | bool found = FALSE; | 1210 | bool found = FALSE; |
1210 | QSplitterLayoutStruct *s = data->list.first(); | 1211 | QSplitterLayoutStruct *s = data->list.first(); |
1211 | while ( s ) { | 1212 | while ( s ) { |
1212 | if ( s->wid == w ) { | 1213 | if ( s->wid == w ) { |
1213 | found = TRUE; | 1214 | found = TRUE; |
1214 | data->list.take(); // take s | 1215 | data->list.take(); // take s |
1215 | QSplitterLayoutStruct *p = data->list.current(); | 1216 | QSplitterLayoutStruct *p = data->list.current(); |
1216 | if ( p ) { // the splitter handle after s | 1217 | if ( p ) { // the splitter handle after s |
1217 | data->list.take(); //take p | 1218 | data->list.take(); //take p |
1218 | data->list.append( p ); | 1219 | data->list.append( p ); |
1219 | } | 1220 | } |
1220 | data->list.append( s ); | 1221 | data->list.append( s ); |
1221 | break; | 1222 | break; |
1222 | } | 1223 | } |
1223 | s = data->list.next(); | 1224 | s = data->list.next(); |
1224 | } | 1225 | } |
1225 | if ( !found ) | 1226 | if ( !found ) |
1226 | addWidget( w); | 1227 | addWidget( w); |
1227 | recalcId(); | 1228 | recalcId(); |
1228 | } | 1229 | } |
1229 | 1230 | ||
1230 | 1231 | ||
1231 | void KDGanttMinimizeSplitter::recalcId() | 1232 | void KDGanttMinimizeSplitter::recalcId() |
1232 | { | 1233 | { |
1233 | int n = data->list.count(); | 1234 | int n = data->list.count(); |
1234 | for ( int i = 0; i < n; i++ ) { | 1235 | for ( int i = 0; i < n; i++ ) { |
1235 | QSplitterLayoutStruct *s = data->list.at(i); | 1236 | QSplitterLayoutStruct *s = data->list.at(i); |
1236 | if ( s->isSplitter ) | 1237 | if ( s->isSplitter ) |
1237 | ((KDGanttSplitterHandle*)s->wid)->setId(i); | 1238 | ((KDGanttSplitterHandle*)s->wid)->setId(i); |
1238 | } | 1239 | } |
1239 | } | 1240 | } |
1240 | 1241 | ||
1241 | 1242 | ||
1242 | /*!\reimp | 1243 | /*!\reimp |
1243 | */ | 1244 | */ |
1244 | QSize KDGanttMinimizeSplitter::sizeHint() const | 1245 | QSize KDGanttMinimizeSplitter::sizeHint() const |
1245 | { | 1246 | { |
1246 | constPolish(); | 1247 | constPolish(); |
1247 | int l = 0; | 1248 | int l = 0; |
1248 | int t = 0; | 1249 | int t = 0; |
1249 | if ( children() ) { | 1250 | if ( children() ) { |
1250 | const QObjectList * c = children(); | 1251 | const QObjectList * c = children(); |
1251 | QObjectListIt it( *c ); | 1252 | QObjectListIt it( *c ); |
1252 | QObject * o; | 1253 | QObject * o; |
1253 | 1254 | ||
1254 | while( (o=it.current()) != 0 ) { | 1255 | while( (o=it.current()) != 0 ) { |
1255 | ++it; | 1256 | ++it; |
1256 | if ( o->isWidgetType() && | 1257 | if ( o->isWidgetType() && |
1257 | !((QWidget*)o)->isHidden() ) { | 1258 | !((QWidget*)o)->isHidden() ) { |
1258 | QSize s = ((QWidget*)o)->sizeHint(); | 1259 | QSize s = ((QWidget*)o)->sizeHint(); |
1259 | if ( s.isValid() ) { | 1260 | if ( s.isValid() ) { |
1260 | l += pick( s ); | 1261 | l += pick( s ); |
1261 | t = QMAX( t, trans( s ) ); | 1262 | t = QMAX( t, trans( s ) ); |
1262 | } | 1263 | } |
1263 | } | 1264 | } |
1264 | } | 1265 | } |
1265 | } | 1266 | } |
1266 | return orientation() == Horizontal ? QSize( l, t ) : QSize( t, l ); | 1267 | return orientation() == Horizontal ? QSize( l, t ) : QSize( t, l ); |
1267 | } | 1268 | } |
1268 | 1269 | ||
1269 | 1270 | ||
1270 | /*! | 1271 | /*! |
1271 | \reimp | 1272 | \reimp |
1272 | */ | 1273 | */ |
1273 | 1274 | ||
1274 | QSize KDGanttMinimizeSplitter::minimumSizeHint() const | 1275 | QSize KDGanttMinimizeSplitter::minimumSizeHint() const |
1275 | { | 1276 | { |
1276 | constPolish(); | 1277 | constPolish(); |
1277 | int l = 0; | 1278 | int l = 0; |
1278 | int t = 0; | 1279 | int t = 0; |
1279 | if ( children() ) { | 1280 | if ( children() ) { |
1280 | const QObjectList * c = children(); | 1281 | const QObjectList * c = children(); |
1281 | QObjectListIt it( *c ); | 1282 | QObjectListIt it( *c ); |
1282 | QObject * o; | 1283 | QObject * o; |
1283 | 1284 | ||
1284 | while( (o=it.current()) != 0 ) { | 1285 | while( (o=it.current()) != 0 ) { |
1285 | ++it; | 1286 | ++it; |
1286 | if ( o->isWidgetType() && | 1287 | if ( o->isWidgetType() && |
1287 | !((QWidget*)o)->isHidden() ) { | 1288 | !((QWidget*)o)->isHidden() ) { |
1288 | QSize s = minSizeHint((QWidget*)o); | 1289 | QSize s = minSizeHint((QWidget*)o); |
1289 | if ( s.isValid() ) { | 1290 | if ( s.isValid() ) { |
1290 | l += pick( s ); | 1291 | l += pick( s ); |
1291 | t = QMAX( t, trans( s ) ); | 1292 | t = QMAX( t, trans( s ) ); |
1292 | } | 1293 | } |
1293 | } | 1294 | } |
1294 | } | 1295 | } |
1295 | } | 1296 | } |
1296 | return orientation() == Horizontal ? QSize( l, t ) : QSize( t, l ); | 1297 | return orientation() == Horizontal ? QSize( l, t ) : QSize( t, l ); |
1297 | } | 1298 | } |
1298 | 1299 | ||
1299 | 1300 | ||
1300 | /* | 1301 | /* |
1301 | Calculates stretch parameters from current sizes | 1302 | Calculates stretch parameters from current sizes |
1302 | */ | 1303 | */ |
1303 | 1304 | ||
1304 | void KDGanttMinimizeSplitter::storeSizes() | 1305 | void KDGanttMinimizeSplitter::storeSizes() |
1305 | { | 1306 | { |
1306 | QSplitterLayoutStruct *s = data->list.first(); | 1307 | QSplitterLayoutStruct *s = data->list.first(); |
1307 | while ( s ) { | 1308 | while ( s ) { |
1308 | if ( !s->isSplitter ) | 1309 | if ( !s->isSplitter ) |
1309 | s->sizer = pick( s->wid->size() ); | 1310 | s->sizer = pick( s->wid->size() ); |
1310 | s = data->list.next(); | 1311 | s = data->list.next(); |
1311 | } | 1312 | } |
1312 | } | 1313 | } |
1313 | 1314 | ||
1314 | 1315 | ||
1315 | #if 0 // ### remove this code ASAP | 1316 | #if 0 // ### remove this code ASAP |
1316 | 1317 | ||
1317 | /*! | 1318 | /*! |
1318 | Hides \a w if \a hide is TRUE and updates the splitter. | 1319 | Hides \a w if \a hide is TRUE and updates the splitter. |
1319 | 1320 | ||
1320 | \warning Due to a limitation in the current implementation, | 1321 | \warning Due to a limitation in the current implementation, |
1321 | calling QWidget::hide() will not work. | 1322 | calling QWidget::hide() will not work. |
1322 | */ | 1323 | */ |
1323 | 1324 | ||
1324 | void KDGanttMinimizeSplitter::setHidden( QWidget *w, bool hide ) | 1325 | void KDGanttMinimizeSplitter::setHidden( QWidget *w, bool hide ) |
1325 | { | 1326 | { |
1326 | if ( w == w1 ) { | 1327 | if ( w == w1 ) { |
1327 | w1show = !hide; | 1328 | w1show = !hide; |
1328 | } else if ( w == w2 ) { | 1329 | } else if ( w == w2 ) { |
1329 | w2show = !hide; | 1330 | w2show = !hide; |
1330 | } else { | 1331 | } else { |
1331 | #ifdef QT_CHECK_RANGE | 1332 | #ifdef QT_CHECK_RANGE |
1332 | qWarning( "KDGanttMinimizeSplitter::setHidden(), unknown widget" ); | 1333 | qWarning( "KDGanttMinimizeSplitter::setHidden(), unknown widget" ); |
1333 | #endif | 1334 | #endif |
1334 | return; | 1335 | return; |
1335 | } | 1336 | } |
1336 | if ( hide ) | 1337 | if ( hide ) |
1337 | w->hide(); | 1338 | w->hide(); |
1338 | else | 1339 | else |
1339 | w->show(); | 1340 | w->show(); |
1340 | recalc( TRUE ); | 1341 | recalc( TRUE ); |
1341 | } | 1342 | } |
1342 | 1343 | ||
1343 | 1344 | ||
1344 | /*! | 1345 | /*! |
1345 | Returns the hidden status of \a w | 1346 | Returns the hidden status of \a w |
1346 | */ | 1347 | */ |
1347 | 1348 | ||
1348 | bool KDGanttMinimizeSplitter::isHidden( QWidget *w ) const | 1349 | bool KDGanttMinimizeSplitter::isHidden( QWidget *w ) const |
1349 | { | 1350 | { |
1350 | if ( w == w1 ) | 1351 | if ( w == w1 ) |
1351 | return !w1show; | 1352 | return !w1show; |
1352 | else if ( w == w2 ) | 1353 | else if ( w == w2 ) |
1353 | return !w2show; | 1354 | return !w2show; |
1354 | #ifdef QT_CHECK_RANGE | 1355 | #ifdef QT_CHECK_RANGE |
1355 | else | 1356 | else |
1356 | qWarning( "KDGanttMinimizeSplitter::isHidden(), unknown widget" ); | 1357 | qWarning( "KDGanttMinimizeSplitter::isHidden(), unknown widget" ); |
1357 | #endif | 1358 | #endif |
1358 | return FALSE; | 1359 | return FALSE; |
1359 | } | 1360 | } |
1360 | #endif | 1361 | #endif |
1361 | 1362 | ||
1362 | 1363 | ||
1363 | /*! | 1364 | /*! |
1364 | Returns a list of the size parameters of all the widgets in this | 1365 | Returns a list of the size parameters of all the widgets in this |
1365 | splitter. | 1366 | splitter. |
1366 | 1367 | ||
1367 | Giving the values to another splitter's setSizes() function will | 1368 | Giving the values to another splitter's setSizes() function will |
1368 | produce a splitter with the same layout as this one. | 1369 | produce a splitter with the same layout as this one. |
1369 | 1370 | ||
1370 | Note that if you want to iterate over the list, you should | 1371 | Note that if you want to iterate over the list, you should |
1371 | iterate over a copy, e.g. | 1372 | iterate over a copy, e.g. |
1372 | \code | 1373 | \code |
1373 | QValueList<int> list = mySplitter.sizes(); | 1374 | QValueList<int> list = mySplitter.sizes(); |
1374 | QValueList<int>::Iterator it = list.begin(); | 1375 | QValueList<int>::Iterator it = list.begin(); |
1375 | while( it != list.end() ) { | 1376 | while( it != list.end() ) { |
1376 | myProcessing( *it ); | 1377 | myProcessing( *it ); |
1377 | ++it; | 1378 | ++it; |
1378 | } | 1379 | } |
1379 | \endcode | 1380 | \endcode |
1380 | 1381 | ||
1381 | \sa setSizes() | 1382 | \sa setSizes() |
1382 | */ | 1383 | */ |
1383 | 1384 | ||
1384 | QValueList<int> KDGanttMinimizeSplitter::sizes() const | 1385 | QValueList<int> KDGanttMinimizeSplitter::sizes() const |
1385 | { | 1386 | { |
1386 | if ( !testWState(WState_Polished) ) { | 1387 | if ( !testWState(WState_Polished) ) { |
1387 | QWidget* that = (QWidget*) this; | 1388 | QWidget* that = (QWidget*) this; |
1388 | that->polish(); | 1389 | that->polish(); |
1389 | } | 1390 | } |
1390 | QValueList<int> list; | 1391 | QValueList<int> list; |
1391 | QSplitterLayoutStruct *s = data->list.first(); | 1392 | QSplitterLayoutStruct *s = data->list.first(); |
1392 | while ( s ) { | 1393 | while ( s ) { |
1393 | if ( !s->isSplitter ) | 1394 | if ( !s->isSplitter ) |
1394 | list.append( s->sizer ); | 1395 | list.append( s->sizer ); |
1395 | s = data->list.next(); | 1396 | s = data->list.next(); |
1396 | } | 1397 | } |
1397 | return list; | 1398 | return list; |
1398 | } | 1399 | } |
1399 | 1400 | ||
1400 | 1401 | ||
1401 | 1402 | ||
1402 | /*! | 1403 | /*! |
1403 | Sets the size parameters to the values given in \a list. | 1404 | Sets the size parameters to the values given in \a list. |
1404 | If the splitter is horizontal, the values set the sizes from | 1405 | If the splitter is horizontal, the values set the sizes from |
1405 | left to right. If it is vertical, the sizes are applied from | 1406 | left to right. If it is vertical, the sizes are applied from |
1406 | top to bottom. | 1407 | top to bottom. |
1407 | Extra values in \a list are ignored. | 1408 | Extra values in \a list are ignored. |
1408 | 1409 | ||
1409 | If \a list contains too few values, the result is undefined | 1410 | If \a list contains too few values, the result is undefined |
1410 | but the program will still be well-behaved. | 1411 | but the program will still be well-behaved. |
1411 | 1412 | ||
1412 | \sa sizes() | 1413 | \sa sizes() |
1413 | */ | 1414 | */ |
1414 | 1415 | ||
1415 | void KDGanttMinimizeSplitter::setSizes( QValueList<int> list ) | 1416 | void KDGanttMinimizeSplitter::setSizes( QValueList<int> list ) |
1416 | { | 1417 | { |
1417 | processChildEvents(); | 1418 | processChildEvents(); |
1418 | QValueList<int>::Iterator it = list.begin(); | 1419 | QValueList<int>::Iterator it = list.begin(); |
1419 | QSplitterLayoutStruct *s = data->list.first(); | 1420 | QSplitterLayoutStruct *s = data->list.first(); |
1420 | while ( s && it != list.end() ) { | 1421 | while ( s && it != list.end() ) { |
1421 | if ( !s->isSplitter ) { | 1422 | if ( !s->isSplitter ) { |
1422 | s->sizer = *it; | 1423 | s->sizer = *it; |
1423 | ++it; | 1424 | ++it; |
1424 | } | 1425 | } |
1425 | s = data->list.next(); | 1426 | s = data->list.next(); |
1426 | } | 1427 | } |
1427 | doResize(); | 1428 | doResize(); |
1428 | } | 1429 | } |
1429 | 1430 | ||
1430 | 1431 | ||
1431 | /*! | 1432 | /*! |
1432 | Gets all posted child events, ensuring that the internal state of | 1433 | Gets all posted child events, ensuring that the internal state of |
1433 | the splitter is consistent. | 1434 | the splitter is consistent. |
1434 | */ | 1435 | */ |
1435 | 1436 | ||
1436 | void KDGanttMinimizeSplitter::processChildEvents() | 1437 | void KDGanttMinimizeSplitter::processChildEvents() |
1437 | { | 1438 | { |
1438 | QApplication::sendPostedEvents( this, QEvent::ChildInserted ); | 1439 | QApplication::sendPostedEvents( this, QEvent::ChildInserted ); |
1439 | } | 1440 | } |
1440 | 1441 | ||
1441 | 1442 | ||
1442 | /*! | 1443 | /*! |
1443 | \reimp | 1444 | \reimp |
1444 | */ | 1445 | */ |
1445 | 1446 | ||
1446 | void KDGanttMinimizeSplitter::styleChange( QStyle& old ) | 1447 | void KDGanttMinimizeSplitter::styleChange( QStyle& old ) |
1447 | { | 1448 | { |
1448 | 1449 | ||
1449 | #if QT_VERSION >= 0x030000 | 1450 | #if QT_VERSION >= 0x030000 |
1450 | int sw = style().pixelMetric(QStyle::PM_SplitterWidth, this); | 1451 | int sw = style().pixelMetric(QStyle::PM_SplitterWidth, this); |
1451 | #else | 1452 | #else |
1452 | int sw = style().splitterWidth(); | 1453 | int sw = style().splitterWidth(); |
1453 | #endif | 1454 | #endif |
1454 | QSplitterLayoutStruct *s = data->list.first(); | 1455 | QSplitterLayoutStruct *s = data->list.first(); |
1455 | while ( s ) { | 1456 | while ( s ) { |
1456 | if ( s->isSplitter ) | 1457 | if ( s->isSplitter ) |
1457 | s->sizer = sw; | 1458 | s->sizer = sw; |
1458 | s = data->list.next(); | 1459 | s = data->list.next(); |
1459 | } | 1460 | } |
1460 | doResize(); | 1461 | doResize(); |
1461 | QFrame::styleChange( old ); | 1462 | QFrame::styleChange( old ); |
1462 | } | 1463 | } |
1463 | 1464 | ||
1464 | #endif | 1465 | #endif |
1465 | 1466 | ||
1466 | /*! | 1467 | /*! |
1467 | Specifies the direction of the minimize buttons. | 1468 | Specifies the direction of the minimize buttons. |
1468 | If the orientation of the splitter is horizontal then with | 1469 | If the orientation of the splitter is horizontal then with |
1469 | KDGanttMinimizeSplitter::Left or KDGanttMinimizeSplitter::Right should be used, | 1470 | KDGanttMinimizeSplitter::Left or KDGanttMinimizeSplitter::Right should be used, |
1470 | otherwise either KDGanttMinimizeSplitter::Up or KDGanttMinimizeSplitter::Down | 1471 | otherwise either KDGanttMinimizeSplitter::Up or KDGanttMinimizeSplitter::Down |
1471 | should be used. | 1472 | should be used. |
1472 | */ | 1473 | */ |
1473 | void KDGanttMinimizeSplitter::setMinimizeDirection( Direction direction ) | 1474 | void KDGanttMinimizeSplitter::setMinimizeDirection( Direction direction ) |
1474 | { | 1475 | { |
1475 | _direction = direction; | 1476 | _direction = direction; |
1476 | } | 1477 | } |
1477 | 1478 | ||
1478 | /*! | 1479 | /*! |
1479 | Returns the direction of the minimize buttons. | 1480 | Returns the direction of the minimize buttons. |
1480 | */ | 1481 | */ |
1481 | KDGanttMinimizeSplitter::Direction KDGanttMinimizeSplitter::minimizeDirection() const | 1482 | KDGanttMinimizeSplitter::Direction KDGanttMinimizeSplitter::minimizeDirection() const |
1482 | { | 1483 | { |
1483 | return _direction; | 1484 | return _direction; |
1484 | } | 1485 | } |
1485 | 1486 | ||
1486 | /* | 1487 | /* |
1487 | This is a copy of qGeomCalc() in qlayoutengine.cpp which | 1488 | This is a copy of qGeomCalc() in qlayoutengine.cpp which |
1488 | unfortunately isn't exported. | 1489 | unfortunately isn't exported. |
1489 | */ | 1490 | */ |
1490 | static inline int toFixed( int i ) { return i * 256; } | 1491 | static inline int toFixed( int i ) { return i * 256; } |
1491 | static inline int fRound( int i ) { | 1492 | static inline int fRound( int i ) { |
1492 | return ( i % 256 < 128 ) ? i / 256 : 1 + i / 256; | 1493 | return ( i % 256 < 128 ) ? i / 256 : 1 + i / 256; |
1493 | } | 1494 | } |
1494 | void kdganttGeomCalc( QMemArray<QLayoutStruct> &chain, int start, int count, int pos, | 1495 | void kdganttGeomCalc( QMemArray<QLayoutStruct> &chain, int start, int count, int pos, |
1495 | int space, int spacer ) | 1496 | int space, int spacer ) |
1496 | { | 1497 | { |
1497 | typedef int fixed; | 1498 | typedef int fixed; |
1498 | int cHint = 0; | 1499 | int cHint = 0; |
1499 | int cMin = 0; | 1500 | int cMin = 0; |
1500 | int cMax = 0; | 1501 | int cMax = 0; |
1501 | int sumStretch = 0; | 1502 | int sumStretch = 0; |
1502 | int spacerCount = 0; | 1503 | int spacerCount = 0; |
1503 | 1504 | ||
1504 | bool wannaGrow = FALSE; // anyone who really wants to grow? | 1505 | bool wannaGrow = FALSE; // anyone who really wants to grow? |
1505 | // bool canShrink = FALSE; // anyone who could be persuaded to shrink? | 1506 | // bool canShrink = FALSE; // anyone who could be persuaded to shrink? |
1506 | 1507 | ||
1507 | int i; | 1508 | int i; |
1508 | for ( i = start; i < start + count; i++ ) { | 1509 | for ( i = start; i < start + count; i++ ) { |
1509 | chain[i].done = FALSE; | 1510 | chain[i].done = FALSE; |
1510 | cHint += chain[i].sizeHint; | 1511 | cHint += chain[i].sizeHint; |
1511 | cMin += chain[i].minimumSize; | 1512 | cMin += chain[i].minimumSize; |
1512 | cMax += chain[i].maximumSize; | 1513 | cMax += chain[i].maximumSize; |
1513 | sumStretch += chain[i].stretch; | 1514 | sumStretch += chain[i].stretch; |
1514 | if ( !chain[i].empty ) | 1515 | if ( !chain[i].empty ) |
1515 | spacerCount++; | 1516 | spacerCount++; |
1516 | wannaGrow = wannaGrow || chain[i].expansive; | 1517 | wannaGrow = wannaGrow || chain[i].expansive; |
1517 | } | 1518 | } |
1518 | 1519 | ||
1519 | int extraspace = 0; | 1520 | int extraspace = 0; |
1520 | if ( spacerCount ) | 1521 | if ( spacerCount ) |
1521 | spacerCount--; // only spacers between things | 1522 | spacerCount--; // only spacers between things |
1522 | if ( space < cMin + spacerCount * spacer ) { | 1523 | if ( space < cMin + spacerCount * spacer ) { |
1523 | //qDebug("not enough space"); | 1524 | //qDebug("not enough space"); |
1524 | for ( i = start; i < start+count; i++ ) { | 1525 | for ( i = start; i < start+count; i++ ) { |
1525 | chain[i].size = chain[i].minimumSize; | 1526 | chain[i].size = chain[i].minimumSize; |
1526 | chain[i].done = TRUE; | 1527 | chain[i].done = TRUE; |
1527 | } | 1528 | } |
1528 | } else if ( space < cHint + spacerCount*spacer ) { | 1529 | } else if ( space < cHint + spacerCount*spacer ) { |
1529 | // Less space than sizeHint, but more than minimum. | 1530 | // Less space than sizeHint, but more than minimum. |
1530 | // Currently take space equally from each, like in Qt 2.x. | 1531 | // Currently take space equally from each, like in Qt 2.x. |
1531 | // Commented-out lines will give more space to stretchier items. | 1532 | // Commented-out lines will give more space to stretchier items. |
1532 | int n = count; | 1533 | int n = count; |
1533 | int space_left = space - spacerCount*spacer; | 1534 | int space_left = space - spacerCount*spacer; |
1534 | int overdraft = cHint - space_left; | 1535 | int overdraft = cHint - space_left; |
1535 | //first give to the fixed ones: | 1536 | //first give to the fixed ones: |
1536 | for ( i = start; i < start+count; i++ ) { | 1537 | for ( i = start; i < start+count; i++ ) { |
1537 | if ( !chain[i].done && chain[i].minimumSize >= chain[i].sizeHint) { | 1538 | if ( !chain[i].done && chain[i].minimumSize >= chain[i].sizeHint) { |
1538 | chain[i].size = chain[i].sizeHint; | 1539 | chain[i].size = chain[i].sizeHint; |
1539 | chain[i].done = TRUE; | 1540 | chain[i].done = TRUE; |
1540 | space_left -= chain[i].sizeHint; | 1541 | space_left -= chain[i].sizeHint; |
1541 | // sumStretch -= chain[i].stretch; | 1542 | // sumStretch -= chain[i].stretch; |
1542 | n--; | 1543 | n--; |
1543 | } | 1544 | } |
1544 | } | 1545 | } |
1545 | bool finished = n == 0; | 1546 | bool finished = n == 0; |
1546 | while ( !finished ) { | 1547 | while ( !finished ) { |
1547 | finished = TRUE; | 1548 | finished = TRUE; |
1548 | fixed fp_over = toFixed( overdraft ); | 1549 | fixed fp_over = toFixed( overdraft ); |
1549 | fixed fp_w = 0; | 1550 | fixed fp_w = 0; |
1550 | 1551 | ||
1551 | for ( i = start; i < start+count; i++ ) { | 1552 | for ( i = start; i < start+count; i++ ) { |
1552 | if ( chain[i].done ) | 1553 | if ( chain[i].done ) |
1553 | continue; | 1554 | continue; |
1554 | // if ( sumStretch <= 0 ) | 1555 | // if ( sumStretch <= 0 ) |
1555 | fp_w += fp_over / n; | 1556 | fp_w += fp_over / n; |
1556 | // else | 1557 | // else |
1557 | // fp_w += (fp_over * chain[i].stretch) / sumStretch; | 1558 | // fp_w += (fp_over * chain[i].stretch) / sumStretch; |
1558 | int w = fRound( fp_w ); | 1559 | int w = fRound( fp_w ); |
1559 | chain[i].size = chain[i].sizeHint - w; | 1560 | chain[i].size = chain[i].sizeHint - w; |
1560 | fp_w -= toFixed( w ); //give the difference to the next | 1561 | fp_w -= toFixed( w ); //give the difference to the next |
1561 | if ( chain[i].size < chain[i].minimumSize ) { | 1562 | if ( chain[i].size < chain[i].minimumSize ) { |
1562 | chain[i].done = TRUE; | 1563 | chain[i].done = TRUE; |
1563 | chain[i].size = chain[i].minimumSize; | 1564 | chain[i].size = chain[i].minimumSize; |
1564 | finished = FALSE; | 1565 | finished = FALSE; |
1565 | overdraft -= chain[i].sizeHint - chain[i].minimumSize; | 1566 | overdraft -= chain[i].sizeHint - chain[i].minimumSize; |
1566 | // sumStretch -= chain[i].stretch; | 1567 | // sumStretch -= chain[i].stretch; |
1567 | n--; | 1568 | n--; |
1568 | break; | 1569 | break; |
1569 | } | 1570 | } |
1570 | } | 1571 | } |
1571 | } | 1572 | } |
1572 | } else { //extra space | 1573 | } else { //extra space |
1573 | int n = count; | 1574 | int n = count; |
1574 | int space_left = space - spacerCount*spacer; | 1575 | int space_left = space - spacerCount*spacer; |
1575 | // first give to the fixed ones, and handle non-expansiveness | 1576 | // first give to the fixed ones, and handle non-expansiveness |
1576 | for ( i = start; i < start + count; i++ ) { | 1577 | for ( i = start; i < start + count; i++ ) { |
1577 | if ( !chain[i].done && (chain[i].maximumSize <= chain[i].sizeHint | 1578 | if ( !chain[i].done && (chain[i].maximumSize <= chain[i].sizeHint |
1578 | || wannaGrow && !chain[i].expansive) ) { | 1579 | || wannaGrow && !chain[i].expansive) ) { |
1579 | chain[i].size = chain[i].sizeHint; | 1580 | chain[i].size = chain[i].sizeHint; |
1580 | chain[i].done = TRUE; | 1581 | chain[i].done = TRUE; |
1581 | space_left -= chain[i].sizeHint; | 1582 | space_left -= chain[i].sizeHint; |
1582 | sumStretch -= chain[i].stretch; | 1583 | sumStretch -= chain[i].stretch; |
1583 | n--; | 1584 | n--; |
1584 | } | 1585 | } |
1585 | } | 1586 | } |
1586 | extraspace = space_left; | 1587 | extraspace = space_left; |
1587 | /* | 1588 | /* |
1588 | Do a trial distribution and calculate how much it is off. | 1589 | Do a trial distribution and calculate how much it is off. |
1589 | If there are more deficit pixels than surplus pixels, give | 1590 | If there are more deficit pixels than surplus pixels, give |
1590 | the minimum size items what they need, and repeat. | 1591 | the minimum size items what they need, and repeat. |
1591 | Otherwise give to the maximum size items, and repeat. | 1592 | Otherwise give to the maximum size items, and repeat. |
1592 | 1593 | ||
1593 | I have a wonderful mathematical proof for the correctness | 1594 | I have a wonderful mathematical proof for the correctness |
1594 | of this principle, but unfortunately this comment is too | 1595 | of this principle, but unfortunately this comment is too |
1595 | small to contain it. | 1596 | small to contain it. |
1596 | */ | 1597 | */ |
1597 | int surplus, deficit; | 1598 | int surplus, deficit; |
1598 | do { | 1599 | do { |
1599 | surplus = deficit = 0; | 1600 | surplus = deficit = 0; |
1600 | fixed fp_space = toFixed( space_left ); | 1601 | fixed fp_space = toFixed( space_left ); |
1601 | fixed fp_w = 0; | 1602 | fixed fp_w = 0; |
1602 | for ( i = start; i < start+count; i++ ) { | 1603 | for ( i = start; i < start+count; i++ ) { |
1603 | if ( chain[i].done ) | 1604 | if ( chain[i].done ) |
1604 | continue; | 1605 | continue; |
1605 | extraspace = 0; | 1606 | extraspace = 0; |
1606 | if ( sumStretch <= 0 ) | 1607 | if ( sumStretch <= 0 ) |
1607 | fp_w += fp_space / n; | 1608 | fp_w += fp_space / n; |
1608 | else | 1609 | else |
1609 | fp_w += (fp_space * chain[i].stretch) / sumStretch; | 1610 | fp_w += (fp_space * chain[i].stretch) / sumStretch; |
1610 | int w = fRound( fp_w ); | 1611 | int w = fRound( fp_w ); |
1611 | chain[i].size = w; | 1612 | chain[i].size = w; |
1612 | fp_w -= toFixed( w ); // give the difference to the next | 1613 | fp_w -= toFixed( w ); // give the difference to the next |
1613 | if ( w < chain[i].sizeHint ) { | 1614 | if ( w < chain[i].sizeHint ) { |
1614 | deficit += chain[i].sizeHint - w; | 1615 | deficit += chain[i].sizeHint - w; |
1615 | } else if ( w > chain[i].maximumSize ) { | 1616 | } else if ( w > chain[i].maximumSize ) { |
1616 | surplus += w - chain[i].maximumSize; | 1617 | surplus += w - chain[i].maximumSize; |
1617 | } | 1618 | } |
1618 | } | 1619 | } |
1619 | if ( deficit > 0 && surplus <= deficit ) { | 1620 | if ( deficit > 0 && surplus <= deficit ) { |
1620 | // give to the ones that have too little | 1621 | // give to the ones that have too little |
1621 | for ( i = start; i < start+count; i++ ) { | 1622 | for ( i = start; i < start+count; i++ ) { |
1622 | if ( !chain[i].done && | 1623 | if ( !chain[i].done && |
1623 | chain[i].size < chain[i].sizeHint ) { | 1624 | chain[i].size < chain[i].sizeHint ) { |
1624 | chain[i].size = chain[i].sizeHint; | 1625 | chain[i].size = chain[i].sizeHint; |
1625 | chain[i].done = TRUE; | 1626 | chain[i].done = TRUE; |
1626 | space_left -= chain[i].sizeHint; | 1627 | space_left -= chain[i].sizeHint; |
1627 | sumStretch -= chain[i].stretch; | 1628 | sumStretch -= chain[i].stretch; |
1628 | n--; | 1629 | n--; |
1629 | } | 1630 | } |
1630 | } | 1631 | } |
1631 | } | 1632 | } |
1632 | if ( surplus > 0 && surplus >= deficit ) { | 1633 | if ( surplus > 0 && surplus >= deficit ) { |
1633 | // take from the ones that have too much | 1634 | // take from the ones that have too much |
1634 | for ( i = start; i < start+count; i++ ) { | 1635 | for ( i = start; i < start+count; i++ ) { |
1635 | if ( !chain[i].done && | 1636 | if ( !chain[i].done && |
1636 | chain[i].size > chain[i].maximumSize ) { | 1637 | chain[i].size > chain[i].maximumSize ) { |
1637 | chain[i].size = chain[i].maximumSize; | 1638 | chain[i].size = chain[i].maximumSize; |
1638 | chain[i].done = TRUE; | 1639 | chain[i].done = TRUE; |
1639 | space_left -= chain[i].maximumSize; | 1640 | space_left -= chain[i].maximumSize; |
1640 | sumStretch -= chain[i].stretch; | 1641 | sumStretch -= chain[i].stretch; |
1641 | n--; | 1642 | n--; |
1642 | } | 1643 | } |
1643 | } | 1644 | } |
1644 | } | 1645 | } |
1645 | } while ( n > 0 && surplus != deficit ); | 1646 | } while ( n > 0 && surplus != deficit ); |
1646 | if ( n == 0 ) | 1647 | if ( n == 0 ) |
1647 | extraspace = space_left; | 1648 | extraspace = space_left; |
1648 | } | 1649 | } |
1649 | 1650 | ||
1650 | // as a last resort, we distribute the unwanted space equally | 1651 | // as a last resort, we distribute the unwanted space equally |
1651 | // among the spacers (counting the start and end of the chain). | 1652 | // among the spacers (counting the start and end of the chain). |
1652 | 1653 | ||
1653 | //### should do a sub-pixel allocation of extra space | 1654 | //### should do a sub-pixel allocation of extra space |
1654 | int extra = extraspace / ( spacerCount + 2 ); | 1655 | int extra = extraspace / ( spacerCount + 2 ); |
1655 | int p = pos + extra; | 1656 | int p = pos + extra; |
1656 | for ( i = start; i < start+count; i++ ) { | 1657 | for ( i = start; i < start+count; i++ ) { |
1657 | chain[i].pos = p; | 1658 | chain[i].pos = p; |
1658 | p = p + chain[i].size; | 1659 | p = p + chain[i].size; |
1659 | if ( !chain[i].empty ) | 1660 | if ( !chain[i].empty ) |
1660 | p += spacer+extra; | 1661 | p += spacer+extra; |
1661 | } | 1662 | } |
1662 | } | 1663 | } |
1663 | 1664 | ||
1664 | #endif | 1665 | #endif |
1665 | 1666 | ||
1666 | /*! | 1667 | /*! |
1667 | \enum KDGanttMinimizeSplitter::Direction | 1668 | \enum KDGanttMinimizeSplitter::Direction |
1668 | 1669 | ||
1669 | The values of this enumeration describe into which direction the | 1670 | The values of this enumeration describe into which direction the |
1670 | splitter will collapse its child widgets. By extension, it also | 1671 | splitter will collapse its child widgets. By extension, it also |
1671 | specifies the orientation of the splitter; collapsing to the left or | 1672 | specifies the orientation of the splitter; collapsing to the left or |
1672 | to the right results in a horizontal splitter, collapsing to the top | 1673 | to the right results in a horizontal splitter, collapsing to the top |
1673 | or bottom in a vertical splitter. | 1674 | or bottom in a vertical splitter. |
1674 | */ | 1675 | */ |
1675 | 1676 | ||
1676 | /*! | 1677 | /*! |
1677 | \fn Orientation KDGanttMinimizeSplitter::orientation() const | 1678 | \fn Orientation KDGanttMinimizeSplitter::orientation() const |
1678 | 1679 | ||
1679 | Returns the orientation of the splitter. | 1680 | Returns the orientation of the splitter. |
1680 | */ | 1681 | */ |
1681 | 1682 | ||
1682 | /*! \enum KDGanttMinimizeSplitter::ResizeMode | 1683 | /*! \enum KDGanttMinimizeSplitter::ResizeMode |
1683 | 1684 | ||
1684 | This enum type describes how KDGanttMinimizeSplitter will resize each of its child widgets. The currently defined values are: | 1685 | This enum type describes how KDGanttMinimizeSplitter will resize each of its child widgets. The currently defined values are: |
1685 | 1686 | ||
1686 | Stretch: the widget will be resized when the splitter | 1687 | Stretch: the widget will be resized when the splitter |
1687 | itself is resized. | 1688 | itself is resized. |
1688 | 1689 | ||
1689 | KeepSize: KDGanttMinimizeSplitter will try to keep this widget's size | 1690 | KeepSize: KDGanttMinimizeSplitter will try to keep this widget's size |
1690 | unchanged. | 1691 | unchanged. |
1691 | 1692 | ||
1692 | FollowSizeHint: KDGanttMinimizeSplitter will resize the widget when the | 1693 | FollowSizeHint: KDGanttMinimizeSplitter will resize the widget when the |
1693 | widget's size hint changes. | 1694 | widget's size hint changes. |
1694 | */ | 1695 | */ |
1695 | 1696 | ||