tdegraphics
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

kpmainwindow_statusbar.cpp 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. /*
  2. Copyright (c) 2003,2004,2005 Clarence Dang <dang@kde.org>
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions
  6. are met:
  7. 1. Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. 2. Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in the
  11. documentation and/or other materials provided with the distribution.
  12. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  13. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  14. OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  15. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  16. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  17. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  18. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  19. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  20. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  21. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22. */
  23. #define DEBUG_STATUS_BAR (DEBUG_KP_MAIN_WINDOW && 0)
  24. #include <kpmainwindow.h>
  25. #include <tqlabel.h>
  26. #include <tqstring.h>
  27. #include <kdebug.h>
  28. #include <tdelocale.h>
  29. #include <kstatusbar.h>
  30. #include <kpdefs.h>
  31. #include <kpdocument.h>
  32. #include <kpsqueezedtextlabel.h>
  33. #include <kptool.h>
  34. #include <kpviewmanager.h>
  35. #include <kpviewscrollablecontainer.h>
  36. #include <kpzoomedview.h>
  37. // private
  38. void kpMainWindow::addPermanentStatusBarItem (int id, int maxTextLen)
  39. {
  40. KStatusBar *sb = statusBar ();
  41. TQString textWithMaxLen;
  42. textWithMaxLen.fill (TQString::number (8/*big fat*/).at (0),
  43. maxTextLen); //+ 2/*spaces on either side*/);
  44. sb->insertFixedItem (textWithMaxLen, id, true/*permanent, place on the right*/);
  45. sb->changeItem (TQString(), id);
  46. }
  47. // private
  48. void kpMainWindow::createStatusBar ()
  49. {
  50. KStatusBar *sb = statusBar ();
  51. // 9999 pixels "ought to be enough for anybody"
  52. const int maxDimenLength = 4;
  53. //sb->insertItem (TQString(), StatusBarItemMessage, 1/*stretch*/);
  54. //sb->setItemAlignment (StatusBarItemMessage, TQt::AlignLeft | TQt::AlignVCenter);
  55. m_statusBarMessageLabel = new kpSqueezedTextLabel (sb);
  56. //m_statusBarMessageLabel->setShowEllipsis (false);
  57. sb->addWidget (m_statusBarMessageLabel, 1/*stretch*/);
  58. addPermanentStatusBarItem (StatusBarItemShapePoints,
  59. (maxDimenLength + 1/*,*/ + maxDimenLength) * 2 + 3/* - */);
  60. addPermanentStatusBarItem (StatusBarItemShapeSize,
  61. (1/*+/-*/ + maxDimenLength) * 2 + 1/*x*/);
  62. addPermanentStatusBarItem (StatusBarItemDocSize,
  63. maxDimenLength + 1/*x*/ + maxDimenLength);
  64. addPermanentStatusBarItem (StatusBarItemDocDepth,
  65. 5/*XXbpp*/);
  66. addPermanentStatusBarItem (StatusBarItemZoom,
  67. 5/*1600%*/);
  68. m_statusBarShapeLastPointsInitialised = false;
  69. m_statusBarShapeLastSizeInitialised = false;
  70. m_statusBarCreated = true;
  71. }
  72. // private slot
  73. void kpMainWindow::setStatusBarMessage (const TQString &message)
  74. {
  75. #if DEBUG_STATUS_BAR && 1
  76. kdDebug () << "kpMainWindow::setStatusBarMessage("
  77. << message
  78. << ") ok=" << m_statusBarCreated
  79. << endl;
  80. #endif
  81. if (!m_statusBarCreated)
  82. return;
  83. //statusBar ()->changeItem (message, StatusBarItemMessage);
  84. m_statusBarMessageLabel->setText (message);
  85. }
  86. // private slot
  87. void kpMainWindow::setStatusBarShapePoints (const TQPoint &startPoint,
  88. const TQPoint &endPoint)
  89. {
  90. #if DEBUG_STATUS_BAR && 0
  91. kdDebug () << "kpMainWindow::setStatusBarShapePoints("
  92. << startPoint << "," << endPoint
  93. << ") ok=" << m_statusBarCreated
  94. << endl;
  95. #endif
  96. if (!m_statusBarCreated)
  97. return;
  98. if (m_statusBarShapeLastPointsInitialised &&
  99. startPoint == m_statusBarShapeLastStartPoint &&
  100. endPoint == m_statusBarShapeLastEndPoint)
  101. {
  102. #if DEBUG_STATUS_BAR && 0
  103. kdDebug () << "\tNOP" << endl;
  104. #endif
  105. return;
  106. }
  107. if (startPoint == KP_INVALID_POINT)
  108. {
  109. statusBar ()->changeItem (TQString(), StatusBarItemShapePoints);
  110. }
  111. else if (endPoint == KP_INVALID_POINT)
  112. {
  113. statusBar ()->changeItem (i18n ("%1,%2")
  114. .arg (startPoint.x ())
  115. .arg (startPoint.y ()),
  116. StatusBarItemShapePoints);
  117. }
  118. else
  119. {
  120. statusBar ()->changeItem (i18n ("%1,%2 - %3,%4")
  121. .arg (startPoint.x ())
  122. .arg (startPoint.y ())
  123. .arg (endPoint.x ())
  124. .arg (endPoint.y ()),
  125. StatusBarItemShapePoints);
  126. }
  127. m_statusBarShapeLastStartPoint = startPoint;
  128. m_statusBarShapeLastEndPoint = endPoint;
  129. m_statusBarShapeLastPointsInitialised = true;
  130. }
  131. // private slot
  132. void kpMainWindow::setStatusBarShapeSize (const TQSize &size)
  133. {
  134. #if DEBUG_STATUS_BAR && 0
  135. kdDebug () << "kpMainWindow::setStatusBarShapeSize("
  136. << size
  137. << ") ok=" << m_statusBarCreated
  138. << endl;
  139. #endif
  140. if (!m_statusBarCreated)
  141. return;
  142. if (m_statusBarShapeLastSizeInitialised &&
  143. size == m_statusBarShapeLastSize)
  144. {
  145. #if DEBUG_STATUS_BAR && 0
  146. kdDebug () << "\tNOP" << endl;
  147. #endif
  148. return;
  149. }
  150. if (size == KP_INVALID_SIZE)
  151. {
  152. statusBar ()->changeItem (TQString(), StatusBarItemShapeSize);
  153. }
  154. else
  155. {
  156. statusBar ()->changeItem (i18n ("%1x%2")
  157. .arg (size.width ())
  158. .arg (size.height ()),
  159. StatusBarItemShapeSize);
  160. }
  161. m_statusBarShapeLastSize = size;
  162. m_statusBarShapeLastSizeInitialised = true;
  163. }
  164. // private slot
  165. void kpMainWindow::setStatusBarDocSize (const TQSize &size)
  166. {
  167. #if DEBUG_STATUS_BAR && 0
  168. kdDebug () << "kpMainWindow::setStatusBarDocSize("
  169. << size
  170. << ") ok=" << m_statusBarCreated
  171. << endl;
  172. #endif
  173. if (!m_statusBarCreated)
  174. return;
  175. if (size == KP_INVALID_SIZE)
  176. {
  177. statusBar ()->changeItem (TQString(), StatusBarItemDocSize);
  178. }
  179. else
  180. {
  181. statusBar ()->changeItem (i18n ("%1x%2")
  182. .arg (size.width ())
  183. .arg (size.height ()),
  184. StatusBarItemDocSize);
  185. }
  186. }
  187. // private slot
  188. void kpMainWindow::setStatusBarDocDepth (int depth)
  189. {
  190. #if DEBUG_STATUS_BAR && 0
  191. kdDebug () << "kpMainWindow::setStatusBarDocDepth("
  192. << depth
  193. << ") ok=" << m_statusBarCreated
  194. << endl;
  195. #endif
  196. if (!m_statusBarCreated)
  197. return;
  198. if (depth <= 0)
  199. {
  200. statusBar ()->changeItem (TQString(), StatusBarItemDocDepth);
  201. }
  202. else
  203. {
  204. statusBar ()->changeItem (i18n ("%1bpp").arg (depth),
  205. StatusBarItemDocDepth);
  206. }
  207. }
  208. // private slot
  209. void kpMainWindow::setStatusBarZoom (int zoom)
  210. {
  211. #if DEBUG_STATUS_BAR && 0
  212. kdDebug () << "kpMainWindow::setStatusBarZoom("
  213. << zoom
  214. << ") ok=" << m_statusBarCreated
  215. << endl;
  216. #endif
  217. if (!m_statusBarCreated)
  218. return;
  219. if (zoom <= 0)
  220. {
  221. statusBar ()->changeItem (TQString(), StatusBarItemZoom);
  222. }
  223. else
  224. {
  225. statusBar ()->changeItem (i18n ("%1%").arg (zoom),
  226. StatusBarItemZoom);
  227. }
  228. }
  229. void kpMainWindow::recalculateStatusBarMessage ()
  230. {
  231. #if DEBUG_STATUS_BAR && 1
  232. kdDebug () << "kpMainWindow::recalculateStatusBarMessage()" << endl;
  233. #endif
  234. TQString scrollViewMessage = m_scrollView->statusMessage ();
  235. #if DEBUG_STATUS_BAR && 1
  236. kdDebug () << "\tscrollViewMessage=" << scrollViewMessage << endl;
  237. kdDebug () << "\tresizing doc? " << !m_scrollView->newDocSize ().isEmpty ()
  238. << endl;
  239. kdDebug () << "\tviewUnderCursor? "
  240. << (m_viewManager && m_viewManager->viewUnderCursor ())
  241. << endl;
  242. #endif
  243. // HACK: To work around kpViewScrollableContainer's unreliable
  244. // status messages (which in turn is due to TQt not updating
  245. // TQWidget::hasMouse() on drags and we needing to hack around it)
  246. if (!scrollViewMessage.isEmpty () &&
  247. m_scrollView->newDocSize ().isEmpty () &&
  248. m_viewManager && m_viewManager->viewUnderCursor ())
  249. {
  250. #if DEBUG_STATUS_BAR && 1
  251. kdDebug () << "\t\tnot resizing & viewUnderCursor - message is wrong - clearing"
  252. << endl;
  253. #endif
  254. m_scrollView->blockSignals (true);
  255. m_scrollView->clearStatusMessage ();
  256. m_scrollView->blockSignals (false);
  257. scrollViewMessage = TQString();
  258. #if DEBUG_STATUS_BAR && 1
  259. kdDebug () << "\t\t\tdone" << endl;
  260. #endif
  261. }
  262. if (!scrollViewMessage.isEmpty ())
  263. {
  264. setStatusBarMessage (scrollViewMessage);
  265. }
  266. else
  267. {
  268. const kpTool *t = tool ();
  269. if (t)
  270. {
  271. setStatusBarMessage (t->userMessage ());
  272. }
  273. else
  274. {
  275. setStatusBarMessage ();
  276. }
  277. }
  278. }
  279. // private slot
  280. void kpMainWindow::recalculateStatusBarShape ()
  281. {
  282. #if DEBUG_STATUS_BAR && 0
  283. kdDebug () << "kpMainWindow::recalculateStatusBarShape()" << endl;
  284. #endif
  285. TQSize docResizeTo = m_scrollView->newDocSize ();
  286. #if DEBUG_STATUS_BAR && 0
  287. kdDebug () << "\tdocResizeTo=" << docResizeTo << endl;
  288. #endif
  289. if (docResizeTo.isValid ())
  290. {
  291. const TQPoint startPoint (m_document->width (), m_document->height ());
  292. #if DEBUG_STATUS_BAR && 0
  293. kdDebug () << "\thavedMovedFromOrgSize="
  294. << m_scrollView->haveMovedFromOriginalDocSize () << endl;
  295. #endif
  296. if (!m_scrollView->haveMovedFromOriginalDocSize ())
  297. {
  298. setStatusBarShapePoints (startPoint);
  299. setStatusBarShapeSize ();
  300. }
  301. else
  302. {
  303. const int newWidth = docResizeTo.width ();
  304. const int newHeight = docResizeTo.height ();
  305. setStatusBarShapePoints (startPoint, TQPoint (newWidth, newHeight));
  306. const TQPoint sizeAsPoint (TQPoint (newWidth, newHeight) - startPoint);
  307. setStatusBarShapeSize (TQSize (sizeAsPoint.x (), sizeAsPoint.y ()));
  308. }
  309. }
  310. else
  311. {
  312. const kpTool *t = tool ();
  313. #if DEBUG_STATUS_BAR && 0
  314. kdDebug () << "\ttool=" << t << endl;
  315. #endif
  316. if (t)
  317. {
  318. setStatusBarShapePoints (t->userShapeStartPoint (),
  319. t->userShapeEndPoint ());
  320. setStatusBarShapeSize (t->userShapeSize ());
  321. }
  322. else
  323. {
  324. setStatusBarShapePoints ();
  325. setStatusBarShapeSize ();
  326. }
  327. }
  328. }
  329. // private slot
  330. void kpMainWindow::recalculateStatusBar ()
  331. {
  332. #if DEBUG_STATUS_BAR && 1
  333. kdDebug () << "kpMainWindow::recalculateStatusBar() ok="
  334. << m_statusBarCreated
  335. << endl;
  336. #endif
  337. if (!m_statusBarCreated)
  338. return;
  339. recalculateStatusBarMessage ();
  340. recalculateStatusBarShape ();
  341. if (m_document)
  342. {
  343. setStatusBarDocSize (TQSize (m_document->width (), m_document->height ()));
  344. setStatusBarDocDepth (m_document->pixmap ()->depth ());
  345. }
  346. else
  347. {
  348. setStatusBarDocSize ();
  349. setStatusBarDocDepth ();
  350. }
  351. if (m_mainView)
  352. {
  353. setStatusBarZoom (m_mainView->zoomLevelX ());
  354. }
  355. else
  356. {
  357. setStatusBarZoom ();
  358. }
  359. }