use kDebug
[kdegraphics.git] / kolourpaint / mainWindow / kpMainWindow_StatusBar.cpp
blobd5f44f896cd5cc99b2f2946f1ff6b11c9c106e0d
2 /*
3 Copyright (c) 2003-2007 Clarence Dang <dang@kde.org>
4 All rights reserved.
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
10 1. Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #define DEBUG_STATUS_BAR (DEBUG_KP_MAIN_WINDOW && 0)
31 #include <kpMainWindow.h>
32 #include <kpMainWindowPrivate.h>
34 #include <qlabel.h>
35 #include <qstring.h>
37 #include <kdebug.h>
38 #include <klocale.h>
39 #include <kstatusbar.h>
41 #include <kpDefs.h>
42 #include <kpDocument.h>
43 #include <kpSqueezedTextLabel.h>
44 #include <kpTool.h>
45 #include <kpViewManager.h>
46 #include <kpViewScrollableContainer.h>
47 #include <kpZoomedView.h>
50 // private
51 void kpMainWindow::addPermanentStatusBarItem (int id, int maxTextLen)
53 KStatusBar *sb = statusBar ();
55 QString textWithMaxLen;
56 textWithMaxLen.fill (QString::number (8/*big fat*/).at (0),
57 maxTextLen); //+ 2/*spaces on either side*/);
59 // Permanent --> place on the right
60 sb->insertPermanentFixedItem (textWithMaxLen, id);
61 sb->changeItem (QString(), id);
64 // private
65 void kpMainWindow::createStatusBar ()
67 KStatusBar *sb = statusBar ();
69 // 9999 pixels "ought to be enough for anybody"
70 const int maxDimenLength = 4;
72 //sb->insertItem (QString(), StatusBarItemMessage, 1/*stretch*/);
73 //sb->setItemAlignment (StatusBarItemMessage, Qt::AlignLeft | Qt::AlignVCenter);
75 d->statusBarMessageLabel = new kpSqueezedTextLabel (sb);
76 //d->statusBarMessageLabel->setShowEllipsis (false);
77 sb->addWidget (d->statusBarMessageLabel, 1/*stretch*/);
79 addPermanentStatusBarItem (StatusBarItemShapePoints,
80 (maxDimenLength + 1/*,*/ + maxDimenLength) * 2 + 3/* - */);
81 addPermanentStatusBarItem (StatusBarItemShapeSize,
82 (1/*+/-*/ + maxDimenLength) * 2 + 1/*x*/);
84 // TODO: This doesn't seem to fit "5000x5000".
85 addPermanentStatusBarItem (StatusBarItemDocSize,
86 maxDimenLength + 1/*x*/ + maxDimenLength);
87 addPermanentStatusBarItem (StatusBarItemDocDepth,
88 5/*XXbpp*/);
90 addPermanentStatusBarItem (StatusBarItemZoom,
91 5/*1600%*/);
93 d->statusBarShapeLastPointsInitialised = false;
94 d->statusBarShapeLastSizeInitialised = false;
95 d->statusBarCreated = true;
99 // private slot
100 void kpMainWindow::setStatusBarMessage (const QString &message)
102 #if DEBUG_STATUS_BAR && 1
103 kDebug () << "kpMainWindow::setStatusBarMessage("
104 << message
105 << ") ok=" << d->statusBarCreated
106 << endl;
107 #endif
109 if (!d->statusBarCreated)
110 return;
112 //statusBar ()->changeItem (message, StatusBarItemMessage);
113 d->statusBarMessageLabel->setText (message);
116 // private slot
117 void kpMainWindow::setStatusBarShapePoints (const QPoint &startPoint,
118 const QPoint &endPoint)
120 #if DEBUG_STATUS_BAR && 0
121 kDebug () << "kpMainWindow::setStatusBarShapePoints("
122 << startPoint << "," << endPoint
123 << ") ok=" << d->statusBarCreated
124 << endl;
125 #endif
127 if (!d->statusBarCreated)
128 return;
130 if (d->statusBarShapeLastPointsInitialised &&
131 startPoint == d->statusBarShapeLastStartPoint &&
132 endPoint == d->statusBarShapeLastEndPoint)
134 #if DEBUG_STATUS_BAR && 0
135 kDebug () << "\tNOP";
136 #endif
137 return;
140 if (startPoint == KP_INVALID_POINT)
142 statusBar ()->changeItem (QString(), StatusBarItemShapePoints);
144 else if (endPoint == KP_INVALID_POINT)
146 statusBar ()->changeItem (i18n ("%1,%2",
147 startPoint.x (),
148 startPoint.y ()),
149 StatusBarItemShapePoints);
151 else
153 statusBar ()->changeItem (i18n ("%1,%2 - %3,%4",
154 startPoint.x (),
155 startPoint.y (),
156 endPoint.x (),
157 endPoint.y ()),
158 StatusBarItemShapePoints);
161 d->statusBarShapeLastStartPoint = startPoint;
162 d->statusBarShapeLastEndPoint = endPoint;
163 d->statusBarShapeLastPointsInitialised = true;
166 // private slot
167 void kpMainWindow::setStatusBarShapeSize (const QSize &size)
169 #if DEBUG_STATUS_BAR && 0
170 kDebug () << "kpMainWindow::setStatusBarShapeSize("
171 << size
172 << ") ok=" << d->statusBarCreated
173 << endl;
174 #endif
176 if (!d->statusBarCreated)
177 return;
179 if (d->statusBarShapeLastSizeInitialised &&
180 size == d->statusBarShapeLastSize)
182 #if DEBUG_STATUS_BAR && 0
183 kDebug () << "\tNOP";
184 #endif
185 return;
188 if (size == KP_INVALID_SIZE)
190 statusBar ()->changeItem (QString(), StatusBarItemShapeSize);
192 else
194 statusBar ()->changeItem (i18n ("%1x%2",
195 size.width (),
196 size.height ()),
197 StatusBarItemShapeSize);
200 d->statusBarShapeLastSize = size;
201 d->statusBarShapeLastSizeInitialised = true;
204 // private slot
205 void kpMainWindow::setStatusBarDocSize (const QSize &size)
207 #if DEBUG_STATUS_BAR && 0
208 kDebug () << "kpMainWindow::setStatusBarDocSize("
209 << size
210 << ") ok=" << d->statusBarCreated
211 << endl;
212 #endif
214 if (!d->statusBarCreated)
215 return;
217 if (size == KP_INVALID_SIZE)
219 statusBar ()->changeItem (QString(), StatusBarItemDocSize);
221 else
223 statusBar ()->changeItem (i18n ("%1x%2",
224 size.width (),
225 size.height ()),
226 StatusBarItemDocSize);
230 // private slot
231 void kpMainWindow::setStatusBarDocDepth (int depth)
233 #if DEBUG_STATUS_BAR && 0
234 kDebug () << "kpMainWindow::setStatusBarDocDepth("
235 << depth
236 << ") ok=" << d->statusBarCreated
237 << endl;
238 #endif
240 if (!d->statusBarCreated)
241 return;
243 if (depth <= 0)
245 statusBar ()->changeItem (QString(), StatusBarItemDocDepth);
247 else
249 statusBar ()->changeItem (i18n ("%1bpp", depth),
250 StatusBarItemDocDepth);
254 // private slot
255 void kpMainWindow::setStatusBarZoom (int zoom)
257 #if DEBUG_STATUS_BAR && 0
258 kDebug () << "kpMainWindow::setStatusBarZoom("
259 << zoom
260 << ") ok=" << d->statusBarCreated
261 << endl;
262 #endif
264 if (!d->statusBarCreated)
265 return;
267 if (zoom <= 0)
269 statusBar ()->changeItem (QString(), StatusBarItemZoom);
271 else
273 statusBar ()->changeItem (i18n ("%1%", zoom),
274 StatusBarItemZoom);
278 void kpMainWindow::recalculateStatusBarMessage ()
280 #if DEBUG_STATUS_BAR && 1
281 kDebug () << "kpMainWindow::recalculateStatusBarMessage()";
282 #endif
283 QString scrollViewMessage = d->scrollView->statusMessage ();
284 #if DEBUG_STATUS_BAR && 1
285 kDebug () << "\tscrollViewMessage=" << scrollViewMessage;
286 kDebug () << "\tresizing doc? " << !d->scrollView->newDocSize ().isEmpty ()
287 << endl;
288 kDebug () << "\tviewUnderCursor? "
289 << (d->viewManager && d->viewManager->viewUnderCursor ())
290 << endl;
291 #endif
293 // HACK: To work around kpViewScrollableContainer's unreliable
294 // status messages (which in turn is due to Qt not updating
295 // QWidget::underMouse() on drags and we needing to hack around it)
296 if (!scrollViewMessage.isEmpty () &&
297 d->scrollView->newDocSize ().isEmpty () &&
298 d->viewManager && d->viewManager->viewUnderCursor ())
300 #if DEBUG_STATUS_BAR && 1
301 kDebug () << "\t\tnot resizing & viewUnderCursor - message is wrong - clearing"
302 << endl;
303 #endif
304 d->scrollView->blockSignals (true);
305 d->scrollView->clearStatusMessage ();
306 d->scrollView->blockSignals (false);
308 scrollViewMessage.clear ();
309 #if DEBUG_STATUS_BAR && 1
310 kDebug () << "\t\t\tdone";
311 #endif
314 if (!scrollViewMessage.isEmpty ())
316 setStatusBarMessage (scrollViewMessage);
318 else
320 const kpTool *t = tool ();
321 if (t)
323 setStatusBarMessage (t->userMessage ());
325 else
327 setStatusBarMessage ();
332 // private slot
333 void kpMainWindow::recalculateStatusBarShape ()
335 #if DEBUG_STATUS_BAR && 0
336 kDebug () << "kpMainWindow::recalculateStatusBarShape()";
337 #endif
339 QSize docResizeTo = d->scrollView->newDocSize ();
340 #if DEBUG_STATUS_BAR && 0
341 kDebug () << "\tdocResizeTo=" << docResizeTo;
342 #endif
343 if (docResizeTo.isValid ())
345 const QPoint startPoint (d->document->width (), d->document->height ());
346 #if DEBUG_STATUS_BAR && 0
347 kDebug () << "\thavedMovedFromOrgSize="
348 << d->scrollView->haveMovedFromOriginalDocSize () << endl;
349 #endif
350 if (!d->scrollView->haveMovedFromOriginalDocSize ())
352 setStatusBarShapePoints (startPoint);
353 setStatusBarShapeSize ();
355 else
357 const int newWidth = docResizeTo.width ();
358 const int newHeight = docResizeTo.height ();
360 setStatusBarShapePoints (startPoint, QPoint (newWidth, newHeight));
361 const QPoint sizeAsPoint (QPoint (newWidth, newHeight) - startPoint);
362 setStatusBarShapeSize (QSize (sizeAsPoint.x (), sizeAsPoint.y ()));
365 else
367 const kpTool *t = tool ();
368 #if DEBUG_STATUS_BAR && 0
369 kDebug () << "\ttool=" << t;
370 #endif
371 if (t)
373 setStatusBarShapePoints (t->userShapeStartPoint (),
374 t->userShapeEndPoint ());
375 setStatusBarShapeSize (t->userShapeSize ());
377 else
379 setStatusBarShapePoints ();
380 setStatusBarShapeSize ();
385 // private slot
386 void kpMainWindow::recalculateStatusBar ()
388 #if DEBUG_STATUS_BAR && 1
389 kDebug () << "kpMainWindow::recalculateStatusBar() ok="
390 << d->statusBarCreated
391 << endl;
392 #endif
394 if (!d->statusBarCreated)
395 return;
397 recalculateStatusBarMessage ();
398 recalculateStatusBarShape ();
400 if (d->document)
402 setStatusBarDocSize (QSize (d->document->width (), d->document->height ()));
403 setStatusBarDocDepth (d->document->image ().depth ());
405 else
407 setStatusBarDocSize ();
408 setStatusBarDocDepth ();
411 if (d->mainView)
413 setStatusBarZoom (d->mainView->zoomLevelX ());
415 else
417 setStatusBarZoom ();