TDE graphics utilities
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.

kpviewmanager.cpp 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  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_KP_VIEW_MANAGER 0
  24. #include <kpviewmanager.h>
  25. #include <tqapplication.h>
  26. #include <tqtimer.h>
  27. #include <kdebug.h>
  28. #include <kpdefs.h>
  29. #include <kpdocument.h>
  30. #include <kpmainwindow.h>
  31. #include <kpselection.h>
  32. #include <kptemppixmap.h>
  33. #include <kptool.h>
  34. #include <kpview.h>
  35. kpViewManager::kpViewManager (kpMainWindow *mainWindow)
  36. : m_textCursorBlinkTimer (0),
  37. m_textCursorRow (-1),
  38. m_textCursorCol (-1),
  39. m_textCursorBlinkState (true),
  40. m_mainWindow (mainWindow),
  41. m_tempPixmap (0),
  42. m_viewUnderCursor (0),
  43. m_selectionBorderVisible (false),
  44. m_selectionBorderFinished (false)
  45. {
  46. m_queueUpdatesCounter = m_fastUpdatesCounter = 0;
  47. }
  48. // private
  49. kpDocument *kpViewManager::document () const
  50. {
  51. return m_mainWindow ? m_mainWindow->document () : 0;
  52. }
  53. kpViewManager::~kpViewManager ()
  54. {
  55. unregisterAllViews ();
  56. delete m_tempPixmap; m_tempPixmap = 0;
  57. }
  58. void kpViewManager::registerView (kpView *view)
  59. {
  60. #if DEBUG_KP_VIEW_MANAGER && 1
  61. kdDebug () << "kpViewManager::registerView (" << view << ")" << endl;
  62. #endif
  63. if (view && m_views.findRef (view) < 0)
  64. {
  65. #if DEBUG_KP_VIEW_MANAGER && 1
  66. kdDebug () << "\tadded view" << endl;
  67. #endif
  68. view->setCursor (m_cursor);
  69. m_views.append (view);
  70. }
  71. else
  72. {
  73. #if DEBUG_KP_VIEW_MANAGER && 1
  74. kdDebug () << "\tignored register view attempt" << endl;
  75. #endif
  76. }
  77. }
  78. void kpViewManager::unregisterView (kpView *view)
  79. {
  80. if (view)
  81. {
  82. if (view == m_viewUnderCursor)
  83. m_viewUnderCursor = 0;
  84. view->unsetCursor ();
  85. m_views.removeRef (view);
  86. }
  87. }
  88. void kpViewManager::unregisterAllViews ()
  89. {
  90. // no autoDelete
  91. m_views.clear ();
  92. }
  93. // public
  94. const kpTempPixmap *kpViewManager::tempPixmap () const
  95. {
  96. return m_tempPixmap;
  97. }
  98. // public
  99. void kpViewManager::setTempPixmap (const kpTempPixmap &tempPixmap)
  100. {
  101. #if DEBUG_KP_VIEW_MANAGER
  102. kdDebug () << "kpViewManager::setTempPixmap(isBrush="
  103. << tempPixmap.isBrush ()
  104. << ",topLeft=" << tempPixmap.topLeft ()
  105. << ",pixmap.rect=" << tempPixmap.pixmap ().rect ()
  106. << ")" << endl;
  107. #endif
  108. TQRect oldRect;
  109. if (m_tempPixmap)
  110. {
  111. oldRect = m_tempPixmap->rect ();
  112. delete m_tempPixmap;
  113. m_tempPixmap = 0;
  114. }
  115. m_tempPixmap = new kpTempPixmap (tempPixmap);
  116. setQueueUpdates ();
  117. if (oldRect.isValid ())
  118. updateViews (oldRect);
  119. updateViews (m_tempPixmap->rect ());
  120. restoreQueueUpdates ();
  121. }
  122. // public
  123. void kpViewManager::invalidateTempPixmap ()
  124. {
  125. if (!m_tempPixmap)
  126. return;
  127. TQRect oldRect = m_tempPixmap->rect ();
  128. delete m_tempPixmap;
  129. m_tempPixmap = 0;
  130. updateViews (oldRect);
  131. }
  132. // public
  133. bool kpViewManager::selectionBorderVisible () const
  134. {
  135. return m_selectionBorderVisible;
  136. }
  137. // public
  138. void kpViewManager::setSelectionBorderVisible (bool yes)
  139. {
  140. if (m_selectionBorderVisible == yes)
  141. return;
  142. m_selectionBorderVisible = yes;
  143. if (document () && document ()->selection ())
  144. updateViews (document ()->selection ()->boundingRect ());
  145. }
  146. // public
  147. bool kpViewManager::selectionBorderFinished () const
  148. {
  149. return m_selectionBorderFinished;
  150. }
  151. // public
  152. void kpViewManager::setSelectionBorderFinished (bool yes)
  153. {
  154. if (m_selectionBorderFinished == yes)
  155. return;
  156. m_selectionBorderFinished = yes;
  157. if (document () && document ()->selection ())
  158. updateViews (document ()->selection ()->boundingRect ());
  159. }
  160. bool kpViewManager::textCursorEnabled () const
  161. {
  162. return (bool) m_textCursorBlinkTimer;
  163. }
  164. void kpViewManager::setTextCursorEnabled (bool yes)
  165. {
  166. #if DEBUG_KP_VIEW_MANAGER && 1
  167. kdDebug () << "kpViewManager::setTextCursorEnabled(" << yes << ")" << endl;
  168. #endif
  169. if (yes == textCursorEnabled ())
  170. return;
  171. delete m_textCursorBlinkTimer;
  172. m_textCursorBlinkTimer = 0;
  173. setFastUpdates ();
  174. setQueueUpdates ();
  175. m_textCursorBlinkState = true;
  176. if (yes)
  177. {
  178. m_textCursorBlinkTimer = new TQTimer (this);
  179. connect (m_textCursorBlinkTimer, TQT_SIGNAL (timeout ()),
  180. this, TQT_SLOT (slotTextCursorBlink ()));
  181. slotTextCursorBlink ();
  182. }
  183. // TODO: What if !yes - shouldn't it clear the cursor?
  184. restoreQueueUpdates ();
  185. restoreFastUpdates ();
  186. }
  187. int kpViewManager::textCursorRow () const
  188. {
  189. bool handledErrors = false;
  190. if (m_mainWindow)
  191. {
  192. kpDocument *doc = m_mainWindow->document ();
  193. if (doc)
  194. {
  195. kpSelection *sel = doc->selection ();
  196. if (sel && sel->isText ())
  197. {
  198. if (m_textCursorRow >= (int) sel->textLines ().size ())
  199. {
  200. #if DEBUG_KP_VIEW_MANAGER && 1
  201. kdDebug () << "kpViewManager::textCursorRow() row="
  202. << m_textCursorRow
  203. << endl;
  204. #endif
  205. (const_cast <kpViewManager *> (this))->m_textCursorRow =
  206. sel->textLines ().size () - 1;
  207. }
  208. handledErrors = true;
  209. }
  210. }
  211. }
  212. if (!handledErrors)
  213. {
  214. #if DEBUG_KP_VIEW_MANAGER && 1
  215. kdDebug () << "kpViewManager::textCursorRow() no mw, doc or text sel" << endl;
  216. #endif
  217. (const_cast <kpViewManager *> (this))->m_textCursorRow = -1;
  218. }
  219. return m_textCursorRow;
  220. }
  221. int kpViewManager::textCursorCol () const
  222. {
  223. int row = textCursorRow ();
  224. if (row < 0)
  225. return -1;
  226. bool handledErrors = false;
  227. if (m_mainWindow)
  228. {
  229. kpDocument *doc = m_mainWindow->document ();
  230. if (doc)
  231. {
  232. kpSelection *sel = doc->selection ();
  233. if (sel && sel->isText ())
  234. {
  235. if (m_textCursorCol > (int) sel->textLines () [row].length ())
  236. {
  237. #if DEBUG_KP_VIEW_MANAGER && 1
  238. kdDebug () << "kpViewManager::textCursorRow() col="
  239. << m_textCursorCol
  240. << endl;
  241. #endif
  242. (const_cast <kpViewManager *> (this))->m_textCursorCol =
  243. sel->textLines () [row].length ();
  244. }
  245. handledErrors = true;
  246. }
  247. }
  248. }
  249. if (!handledErrors)
  250. {
  251. #if DEBUG_KP_VIEW_MANAGER && 1
  252. kdDebug () << "kpViewManager::textCursorCol() no mw, doc or text sel" << endl;
  253. #endif
  254. (const_cast <kpViewManager *> (this))->m_textCursorCol = -1;
  255. }
  256. return m_textCursorCol;
  257. }
  258. void kpViewManager::setTextCursorPosition (int row, int col, bool isUpdateMicroFocusHint)
  259. {
  260. if (row == m_textCursorRow && col == m_textCursorCol)
  261. return;
  262. setFastUpdates ();
  263. setQueueUpdates ();
  264. m_textCursorBlinkState = false;
  265. updateTextCursor ();
  266. m_textCursorRow = row;
  267. m_textCursorCol = col;
  268. m_textCursorBlinkState = true;
  269. updateTextCursor ();
  270. restoreQueueUpdates ();
  271. restoreFastUpdates ();
  272. if (isUpdateMicroFocusHint)
  273. {
  274. kpDocument *doc = m_mainWindow->document ();
  275. if (!doc)
  276. return;
  277. kpSelection *sel = doc->selection ();
  278. if (!sel || !sel->isText ())
  279. return;
  280. if (m_viewUnderCursor)
  281. {
  282. // TODO: Fix code duplication: kpViewManager::{setTextCursorPosition,updateTextCursor}() & kpView::paintEventDrawSelection()
  283. TQPoint topLeft = sel->pointForTextRowCol (m_textCursorRow, m_textCursorCol);
  284. if (topLeft != KP_INVALID_POINT)
  285. {
  286. // TODO: I think you need to consider zooming e.g. try editing
  287. // text at 800% or with focus set to the thumbnail.
  288. // kpSelection/kpDocument works fully in unzoomed
  289. // coordinates unlike the view (which is zoomed and can
  290. // change size).
  291. //
  292. // To fix it here, I think you should call
  293. // m_viewUnderCursor->transformDocToView(TQRect). However,
  294. // the rest of the InputMethod support still needs to
  295. // audited for this.
  296. //
  297. // [Bug #27]
  298. m_viewUnderCursor->updateMicroFocusHint(TQRect (topLeft.x (), topLeft.y (), 1, sel->textStyle ().fontMetrics ().height ()));
  299. }
  300. }
  301. }
  302. }
  303. bool kpViewManager::textCursorBlinkState () const
  304. {
  305. return m_textCursorBlinkState;
  306. }
  307. void kpViewManager::setTextCursorBlinkState (bool on)
  308. {
  309. if (on == m_textCursorBlinkState)
  310. return;
  311. m_textCursorBlinkState = on;
  312. updateTextCursor ();
  313. }
  314. // protected
  315. void kpViewManager::updateTextCursor ()
  316. {
  317. #if DEBUG_KP_VIEW_MANAGER && 0
  318. kdDebug () << "kpViewManager::updateTextCursor()" << endl;
  319. #endif
  320. if (!m_mainWindow)
  321. return;
  322. kpDocument *doc = m_mainWindow->document ();
  323. if (!doc)
  324. return;
  325. kpSelection *sel = doc->selection ();
  326. if (!sel || !sel->isText ())
  327. return;
  328. // TODO: Fix code duplication: kpViewManager::{setTextCursorPosition,updateTextCursor}() & kpView::paintEventDrawSelection()
  329. TQPoint topLeft = sel->pointForTextRowCol (m_textCursorRow, m_textCursorCol);
  330. if (topLeft != KP_INVALID_POINT)
  331. {
  332. setFastUpdates ();
  333. updateViews (TQRect (topLeft.x (), topLeft.y (), 1, sel->textStyle ().fontMetrics ().height ()));
  334. restoreFastUpdates ();
  335. }
  336. }
  337. // protected slot
  338. void kpViewManager::slotTextCursorBlink ()
  339. {
  340. #if DEBUG_KP_VIEW_MANAGER && 0
  341. kdDebug () << "kpViewManager::slotTextCursorBlink() cursorBlinkState="
  342. << m_textCursorBlinkState << endl;
  343. #endif
  344. if (m_textCursorBlinkTimer)
  345. {
  346. m_textCursorBlinkTimer->start (TQApplication::cursorFlashTime () / 2,
  347. true/*single shot*/);
  348. }
  349. updateTextCursor ();
  350. m_textCursorBlinkState = !m_textCursorBlinkState;
  351. }
  352. void kpViewManager::setCursor (const TQCursor &cursor)
  353. {
  354. for (TQPtrList <kpView>::const_iterator it = m_views.begin ();
  355. it != m_views.end ();
  356. it++)
  357. {
  358. (*it)->setCursor (cursor);
  359. }
  360. m_cursor = cursor;
  361. }
  362. void kpViewManager::unsetCursor ()
  363. {
  364. for (TQPtrList <kpView>::const_iterator it = m_views.begin ();
  365. it != m_views.end ();
  366. it++)
  367. {
  368. (*it)->unsetCursor ();
  369. }
  370. m_cursor = TQCursor ();
  371. }
  372. kpView *kpViewManager::viewUnderCursor (bool usingTQt) const
  373. {
  374. if (!usingTQt)
  375. {
  376. kpViewManager *nonConstThis = const_cast <kpViewManager *> (this);
  377. if (m_viewUnderCursor && nonConstThis->m_views.findRef (m_viewUnderCursor) < 0)
  378. {
  379. kdError () << "kpViewManager::viewUnderCursor(): invalid view" << endl;
  380. nonConstThis->m_viewUnderCursor = 0;
  381. }
  382. return m_viewUnderCursor;
  383. }
  384. else
  385. {
  386. for (TQPtrList <kpView>::const_iterator it = m_views.begin ();
  387. it != m_views.end ();
  388. it++)
  389. {
  390. if ((*it)->hasMouse ())
  391. return (*it);
  392. }
  393. return 0;
  394. }
  395. }
  396. void kpViewManager::setViewUnderCursor (kpView *view)
  397. {
  398. #if DEBUG_KP_VIEW_MANAGER && 1
  399. kdDebug () << "kpViewManager::setViewUnderCursor ("
  400. << (view ? view->name () : "(none)") << ")"
  401. << " old=" << (m_viewUnderCursor ? m_viewUnderCursor->name () : "(none)")
  402. << endl;
  403. #endif
  404. if (view == m_viewUnderCursor)
  405. return;
  406. m_viewUnderCursor = view;
  407. if (!m_viewUnderCursor)
  408. {
  409. // Hide the brush if the mouse cursor just left the view
  410. if (m_tempPixmap && m_tempPixmap->isBrush ())
  411. {
  412. #if DEBUG_KP_VIEW_MANAGER && 1
  413. kdDebug () << "\thiding brush pixmap since cursor left view" << endl;
  414. #endif
  415. updateViews (m_tempPixmap->rect ());
  416. }
  417. }
  418. else
  419. {
  420. if (m_mainWindow && m_mainWindow->tool ())
  421. {
  422. #if DEBUG_KP_VIEW_MANAGER && 1
  423. kdDebug () << "\tnotify tool that something changed below cursor" << endl;
  424. #endif
  425. m_mainWindow->tool ()->somethingBelowTheCursorChanged ();
  426. }
  427. }
  428. }
  429. // public
  430. kpView *kpViewManager::activeView () const
  431. {
  432. for (TQPtrList <kpView>::const_iterator it = m_views.begin ();
  433. it != m_views.end ();
  434. it++)
  435. {
  436. if ((*it)->isActiveWindow ())
  437. return (*it);
  438. }
  439. return 0;
  440. }
  441. // public
  442. bool kpViewManager::queueUpdates () const
  443. {
  444. return (m_queueUpdatesCounter > 0);
  445. }
  446. // public
  447. void kpViewManager::setQueueUpdates ()
  448. {
  449. m_queueUpdatesCounter++;
  450. #if DEBUG_KP_VIEW_MANAGER && 1
  451. kdDebug () << "kpViewManager::setQueueUpdates() counter="
  452. << m_queueUpdatesCounter << endl;
  453. #endif
  454. }
  455. // public
  456. void kpViewManager::restoreQueueUpdates ()
  457. {
  458. m_queueUpdatesCounter--;
  459. #if DEBUG_KP_VIEW_MANAGER && 1
  460. kdDebug () << "kpViewManager::restoreQueueUpdates() counter="
  461. << m_queueUpdatesCounter << endl;
  462. #endif
  463. if (m_queueUpdatesCounter < 0)
  464. {
  465. kdError () << "kpViewManager::restoreQueueUpdates() counter="
  466. << m_queueUpdatesCounter;
  467. }
  468. if (m_queueUpdatesCounter <= 0)
  469. {
  470. for (TQPtrList <kpView>::const_iterator it = m_views.begin ();
  471. it != m_views.end ();
  472. it++)
  473. {
  474. (*it)->updateQueuedArea ();
  475. }
  476. }
  477. }
  478. // public
  479. bool kpViewManager::fastUpdates () const
  480. {
  481. return (m_fastUpdatesCounter > 0);
  482. }
  483. // public
  484. void kpViewManager::setFastUpdates ()
  485. {
  486. m_fastUpdatesCounter++;
  487. #if DEBUG_KP_VIEW_MANAGER && 0
  488. kdDebug () << "kpViewManager::setFastUpdates() counter="
  489. << m_fastUpdatesCounter << endl;
  490. #endif
  491. }
  492. // public
  493. void kpViewManager::restoreFastUpdates ()
  494. {
  495. m_fastUpdatesCounter--;
  496. #if DEBUG_KP_VIEW_MANAGER && 0
  497. kdDebug () << "kpViewManager::restoreFastUpdates() counter="
  498. << m_fastUpdatesCounter << endl;
  499. #endif
  500. if (m_fastUpdatesCounter < 0)
  501. {
  502. kdError () << "kpViewManager::restoreFastUpdates() counter="
  503. << m_fastUpdatesCounter;
  504. }
  505. }
  506. void kpViewManager::updateView (kpView *v)
  507. {
  508. updateView (v, TQRect (0, 0, v->width (), v->height ()));
  509. }
  510. void kpViewManager::updateView (kpView *v, const TQRect &viewRect)
  511. {
  512. if (!queueUpdates ())
  513. {
  514. if (fastUpdates ())
  515. v->repaint (viewRect, false/*no erase*/);
  516. else
  517. v->update (viewRect);
  518. }
  519. else
  520. v->addToQueuedArea (viewRect);
  521. }
  522. void kpViewManager::updateView (kpView *v, int x, int y, int w, int h)
  523. {
  524. updateView (v, TQRect (x, y, w, h));
  525. }
  526. void kpViewManager::updateView (kpView *v, const TQRegion &viewRegion)
  527. {
  528. if (!queueUpdates ())
  529. {
  530. if (fastUpdates ())
  531. v->repaint (viewRegion, false/*no erase*/);
  532. else
  533. v->update (viewRegion.boundingRect ());
  534. }
  535. else
  536. v->addToQueuedArea (viewRegion);
  537. }
  538. void kpViewManager::updateViewRectangleEdges (kpView *v, const TQRect &viewRect)
  539. {
  540. if (viewRect.height () <= 0 || viewRect.width () <= 0)
  541. return;
  542. // Top line
  543. updateView (v, TQRect (viewRect.x (), viewRect.y (),
  544. viewRect.width (), 1));
  545. if (viewRect.height () >= 2)
  546. {
  547. // Bottom line
  548. updateView (v, TQRect (viewRect.x (), viewRect.bottom (),
  549. viewRect.width (), 1));
  550. if (viewRect.height () > 2)
  551. {
  552. // Left line
  553. updateView (v, TQRect (viewRect.x (), viewRect.y () + 1,
  554. 1, viewRect.height () - 2));
  555. if (viewRect.width () >= 2)
  556. {
  557. // Right line
  558. updateView (v, TQRect (viewRect.right (), viewRect.y () + 1,
  559. 1, viewRect.height () - 2));
  560. }
  561. }
  562. }
  563. }
  564. void kpViewManager::updateViews ()
  565. {
  566. kpDocument *doc = document ();
  567. if (doc)
  568. updateViews (TQRect (0, 0, doc->width (), doc->height ()));
  569. }
  570. void kpViewManager::updateViews (const TQRect &docRect)
  571. {
  572. #if DEBUG_KP_VIEW_MANAGER && 0
  573. kdDebug () << "kpViewManager::updateViews (" << docRect << ")" << endl;
  574. #endif
  575. for (TQPtrList <kpView>::const_iterator it = m_views.begin ();
  576. it != m_views.end ();
  577. it++)
  578. {
  579. kpView *view = *it;
  580. #if DEBUG_KP_VIEW_MANAGER && 0
  581. kdDebug () << "\tupdating view " << view->name () << endl;
  582. #endif
  583. if (view->zoomLevelX () % 100 == 0 && view->zoomLevelY () % 100 == 0)
  584. {
  585. #if DEBUG_KP_VIEW_MANAGER && 0
  586. kdDebug () << "\t\tviewRect=" << view->transformDocToView (docRect) << endl;
  587. #endif
  588. updateView (view, view->transformDocToView (docRect));
  589. }
  590. else
  591. {
  592. TQRect viewRect = view->transformDocToView (docRect);
  593. int diff = tqRound (double (TQMAX (view->zoomLevelX (), view->zoomLevelY ())) / 100.0) + 1;
  594. TQRect newRect = TQRect (viewRect.x () - diff,
  595. viewRect.y () - diff,
  596. viewRect.width () + 2 * diff,
  597. viewRect.height () + 2 * diff)
  598. .intersect (TQRect (0, 0, view->width (), view->height ()));
  599. #if DEBUG_KP_VIEW_MANAGER && 0
  600. kdDebug () << "\t\tviewRect (+compensate)=" << newRect << endl;
  601. #endif
  602. updateView (view, newRect);
  603. }
  604. }
  605. }
  606. void kpViewManager::updateViews (int x, int y, int w, int h)
  607. {
  608. updateViews (TQRect (x, y, w, h));
  609. }
  610. void kpViewManager::adjustViewsToEnvironment ()
  611. {
  612. #if DEBUG_KP_VIEW_MANAGER && 1
  613. kdDebug () << "kpViewManager::adjustViewsToEnvironment()"
  614. << " numViews=" << m_views.count ()
  615. << endl;
  616. #endif
  617. for (TQPtrList <kpView>::const_iterator it = m_views.begin ();
  618. it != m_views.end ();
  619. it++)
  620. {
  621. kpView *view = *it;
  622. #if DEBUG_KP_VIEW_MANAGER && 1
  623. kdDebug () << "\tview: " << view->name ()
  624. << endl;
  625. #endif
  626. view->adjustToEnvironment ();
  627. }
  628. }
  629. #include <kpviewmanager.moc>