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.

kpviewscrollablecontainer.cpp 37KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390
  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_SCROLLABLE_CONTAINER 0
  24. #include <kpviewscrollablecontainer.h>
  25. #include <tqcursor.h>
  26. #include <tqpainter.h>
  27. #include <tqpen.h>
  28. #include <tqpixmap.h>
  29. #include <tqtimer.h>
  30. #include <kdebug.h>
  31. #include <tdelocale.h>
  32. #include <kpdefs.h>
  33. #include <kppixmapfx.h>
  34. #include <kpview.h>
  35. #include <kpwidgetmapper.h>
  36. // (Pulled from out of Thurston's hat)
  37. static const int DragScrollLeftTopMargin = 0;
  38. static const int DragScrollRightBottomMargin = 16; // scrollbarish
  39. static const int DragScrollInterval = 1000 / 10;
  40. static const int DragScrollInitialInterval = DragScrollInterval * 2;
  41. static const int DragScrollNumPixels = 5;
  42. static const int DragDistanceFromRectMaxFor1stMultiplier = 50;
  43. static const int DragDistanceFromRectMaxFor2ndMultiplier = 100;
  44. static const int GripSize = 7;
  45. static const int GripHandleSize = 7;
  46. kpGrip::kpGrip (GripType type,
  47. TQWidget *parent, const char *name)
  48. : TQWidget (parent, name),
  49. m_type (type),
  50. m_startPoint (KP_INVALID_POINT),
  51. m_currentPoint (KP_INVALID_POINT),
  52. m_shouldReleaseMouseButtons (false)
  53. {
  54. setCursor (cursorForType (m_type));
  55. setMouseTracking (true); // mouseMoveEvent's even when no mousebtn down
  56. updatePixmap ();
  57. }
  58. kpGrip::~kpGrip ()
  59. {
  60. }
  61. // public
  62. kpGrip::GripType kpGrip::type () const
  63. {
  64. return m_type;
  65. }
  66. // public static
  67. const TQCursor &kpGrip::cursorForType (GripType type)
  68. {
  69. switch (type)
  70. {
  71. case Bottom:
  72. return TQt::sizeVerCursor;
  73. break; // one day you'll forget
  74. case Right:
  75. return TQt::sizeHorCursor;
  76. break; // one day you'll forget
  77. case BottomRight:
  78. return TQt::sizeFDiagCursor;
  79. break; // one day you'll forget
  80. }
  81. return TQt::arrowCursor;
  82. }
  83. // public
  84. TQRect kpGrip::hotRect (bool toGlobal) const
  85. {
  86. TQRect ret;
  87. switch (m_type)
  88. {
  89. case Bottom:
  90. {
  91. const int handleX = (width () - GripHandleSize) / 2;
  92. ret = TQRect (handleX, 0,
  93. GripHandleSize, height ());
  94. break;
  95. }
  96. case Right:
  97. {
  98. const int handleY = (height () - GripHandleSize) / 2;
  99. ret = TQRect (0, handleY,
  100. width (), GripHandleSize);
  101. break;
  102. }
  103. case BottomRight:
  104. // pixmap all opaque
  105. ret = rect ();
  106. break;
  107. default:
  108. return TQRect ();
  109. }
  110. return (toGlobal ? TQRect (mapToGlobal (ret.topLeft ()),
  111. mapToGlobal (ret.bottomRight ()))
  112. : ret);
  113. }
  114. // public
  115. bool kpGrip::isDrawing () const
  116. {
  117. return (m_startPoint != KP_INVALID_POINT);
  118. }
  119. // public
  120. TQString kpGrip::haventBegunDrawUserMessage () const
  121. {
  122. return i18n ("Left drag the handle to resize the image.");
  123. }
  124. // public
  125. TQString kpGrip::userMessage () const
  126. {
  127. return m_userMessage;
  128. }
  129. // public
  130. void kpGrip::setUserMessage (const TQString &message)
  131. {
  132. // Don't do NOP checking here since another grip might have changed
  133. // the message so an apparent NOP for this grip is not a NOP in the
  134. // global sense (kpViewScrollableContainer::slotGripStatusMessageChanged()).
  135. m_userMessage = message;
  136. emit statusMessageChanged (message);
  137. }
  138. // protected
  139. void kpGrip::updatePixmap ()
  140. {
  141. #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER
  142. kdDebug () << "kpGrip::updatePixmap() rect=" << rect () << endl;
  143. #endif
  144. if (width () <= 0 || height () <= 0)
  145. return;
  146. TQPixmap pixmap (width (), height ());
  147. pixmap.fill (colorGroup ().highlight ());
  148. kpPixmapFX::ensureTransparentAt (&pixmap, pixmap.rect ());
  149. const TQRect hr = hotRect ();
  150. #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER
  151. kdDebug () << "\thotRect=" << hr << endl;
  152. #endif
  153. if (hr.isValid ())
  154. kpPixmapFX::ensureOpaqueAt (&pixmap, hr);
  155. setBackgroundPixmap (pixmap);
  156. if (pixmap.mask ())
  157. setMask (*pixmap.mask ());
  158. }
  159. // protected
  160. void kpGrip::cancel ()
  161. {
  162. #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER
  163. kdDebug () << "kpGrip::cancel()" << endl;
  164. #endif
  165. if (m_currentPoint == KP_INVALID_POINT)
  166. return;
  167. m_startPoint = KP_INVALID_POINT;
  168. m_currentPoint = KP_INVALID_POINT;
  169. setUserMessage (i18n ("Resize Image: Let go of all the mouse buttons."));
  170. setCursor (TQt::arrowCursor);
  171. m_shouldReleaseMouseButtons = true;
  172. releaseKeyboard ();
  173. emit cancelledDraw ();
  174. }
  175. // protected virtual [base TQWidget]
  176. void kpGrip::keyReleaseEvent (TQKeyEvent *e)
  177. {
  178. if (m_startPoint != KP_INVALID_POINT &&
  179. e->key () == TQt::Key_Escape)
  180. {
  181. cancel ();
  182. }
  183. }
  184. // protected virtual [base TQWidget]
  185. void kpGrip::mousePressEvent (TQMouseEvent *e)
  186. {
  187. if (m_startPoint == KP_INVALID_POINT &&
  188. (e->stateAfter () & Qt::MouseButtonMask) == Qt::LeftButton)
  189. {
  190. m_startPoint = e->pos ();
  191. m_currentPoint = e->pos ();
  192. emit beganDraw ();
  193. grabKeyboard ();
  194. setUserMessage (i18n ("Resize Image: Right click to cancel."));
  195. setCursor (cursorForType (m_type));
  196. }
  197. else
  198. {
  199. if (m_startPoint != KP_INVALID_POINT)
  200. cancel ();
  201. }
  202. }
  203. // public
  204. TQPoint kpGrip::viewDeltaPoint () const
  205. {
  206. if (m_startPoint == KP_INVALID_POINT)
  207. return KP_INVALID_POINT;
  208. const TQPoint point = mapFromGlobal (TQCursor::pos ());
  209. // TODO: this is getting out of sync with m_currentPoint
  210. return TQPoint (((m_type & Right) ? point.x () - m_startPoint.x () : 0),
  211. ((m_type & Bottom) ? point.y () - m_startPoint.y () : 0));
  212. }
  213. // public
  214. void kpGrip::mouseMovedTo (const TQPoint &point, bool dueToDragScroll)
  215. {
  216. if (m_startPoint == KP_INVALID_POINT)
  217. return;
  218. m_currentPoint = point;
  219. emit continuedDraw (((m_type & Right) ? point.x () - m_startPoint.x () : 0),
  220. ((m_type & Bottom) ? point.y () - m_startPoint.y () : 0),
  221. dueToDragScroll);
  222. }
  223. // protected virtual [base TQWidget]
  224. void kpGrip::mouseMoveEvent (TQMouseEvent *e)
  225. {
  226. #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER
  227. kdDebug () << "kpGrip::mouseMoveEvent() m_startPoint=" << m_startPoint
  228. << " stateAfter=" << e->stateAfter ()
  229. << endl;
  230. #endif
  231. if (m_startPoint == KP_INVALID_POINT)
  232. {
  233. if ((e->stateAfter () & Qt::MouseButtonMask) == 0)
  234. setUserMessage (haventBegunDrawUserMessage ());
  235. return;
  236. }
  237. mouseMovedTo (e->pos (), false/*not due to drag scroll*/);
  238. }
  239. // protected virtual [base TQWidget]
  240. void kpGrip::mouseReleaseEvent (TQMouseEvent *e)
  241. {
  242. #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER
  243. kdDebug () << "kpGrip::mouseReleaseEvent() m_startPoint=" << m_startPoint
  244. << " stateAfter=" << e->stateAfter ()
  245. << endl;
  246. #endif
  247. if (m_startPoint != KP_INVALID_POINT)
  248. {
  249. const int dx = m_currentPoint.x () - m_startPoint.x (),
  250. dy = m_currentPoint.y () - m_startPoint.y ();
  251. m_currentPoint = KP_INVALID_POINT;
  252. m_startPoint = KP_INVALID_POINT;
  253. releaseKeyboard ();
  254. emit endedDraw ((m_type & Right) ? dx : 0,
  255. (m_type & Bottom) ? dy : 0);
  256. }
  257. if ((e->stateAfter () & Qt::MouseButtonMask) == 0)
  258. {
  259. m_shouldReleaseMouseButtons = false;
  260. setUserMessage (TQString());
  261. setCursor (cursorForType (m_type));
  262. releaseKeyboard ();
  263. emit releasedAllButtons ();
  264. }
  265. }
  266. // protected virtual [base TQWidget]
  267. void kpGrip::resizeEvent (TQResizeEvent *)
  268. {
  269. #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER
  270. kdDebug () << "kpGrip::resizeEvent()" << endl;
  271. #endif
  272. updatePixmap ();
  273. }
  274. // protected virtual [base TQWidget]
  275. void kpGrip::enterEvent (TQEvent * /*e*/)
  276. {
  277. #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER
  278. kdDebug () << "kpGrip::enterEvent()"
  279. << " m_startPoint=" << m_startPoint
  280. << " shouldReleaseMouseButtons="
  281. << m_shouldReleaseMouseButtons << endl;
  282. #endif
  283. if (m_startPoint == KP_INVALID_POINT &&
  284. !m_shouldReleaseMouseButtons)
  285. {
  286. #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER
  287. kdDebug () << "\tsending message" << endl;
  288. #endif
  289. setUserMessage (haventBegunDrawUserMessage ());
  290. }
  291. }
  292. // protected virtual [base TQWidget]
  293. void kpGrip::leaveEvent (TQEvent * /*e*/)
  294. {
  295. #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER
  296. kdDebug () << "kpGrip::leaveEvent()"
  297. << " m_startPoint=" << m_startPoint
  298. << " shouldReleaseMouseButtons="
  299. << m_shouldReleaseMouseButtons << endl;
  300. #endif
  301. if (m_startPoint == KP_INVALID_POINT &&
  302. !m_shouldReleaseMouseButtons)
  303. {
  304. setUserMessage (TQString());
  305. }
  306. }
  307. // protected virtual [base TQWidget]
  308. void kpGrip::paintEvent (TQPaintEvent *e)
  309. {
  310. #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER && 0
  311. kdDebug () << "kpGrip::paintEvent(" << e->rect () << ")" << endl;
  312. #endif
  313. TQWidget::paintEvent (e);
  314. }
  315. // TODO: Are we checking for m_view == 0 often enough?
  316. kpViewScrollableContainer::kpViewScrollableContainer (kpMainWindow *parent,
  317. const char *name)
  318. : TQScrollView ((TQWidget *) parent, name, TQt::WStaticContents | TQt::WNoAutoErase),
  319. m_mainWindow (parent),
  320. m_contentsXSoon (-1), m_contentsYSoon (-1),
  321. m_view (0),
  322. m_bottomGrip (new kpGrip (kpGrip::Bottom, viewport (), "Bottom Grip")),
  323. m_rightGrip (new kpGrip (kpGrip::Right, viewport (), "Right Grip")),
  324. m_bottomRightGrip (new kpGrip (kpGrip::BottomRight, viewport (), "BottomRight Grip")),
  325. m_docResizingGrip (0),
  326. m_dragScrollTimer (new TQTimer (this)),
  327. m_zoomLevel (100),
  328. m_scrollTimerRunOnce (false),
  329. m_resizeRoundedLastViewX (-1), m_resizeRoundedLastViewY (-1),
  330. m_resizeRoundedLastViewDX (0), m_resizeRoundedLastViewDY (0),
  331. m_haveMovedFromOriginalDocSize (false)
  332. {
  333. m_bottomGrip->setFixedHeight (GripSize);
  334. m_bottomGrip->hide ();
  335. addChild (m_bottomGrip);
  336. connectGripSignals (m_bottomGrip);
  337. m_rightGrip->setFixedWidth (GripSize);
  338. m_rightGrip->hide ();
  339. addChild (m_rightGrip);
  340. connectGripSignals (m_rightGrip);
  341. m_bottomRightGrip->setFixedSize (GripSize, GripSize);
  342. m_bottomRightGrip->hide ();
  343. addChild (m_bottomRightGrip);
  344. connectGripSignals (m_bottomRightGrip);
  345. connect (this, TQT_SIGNAL (contentsMoving (int, int)),
  346. this, TQT_SLOT (slotContentsMoving (int, int)));
  347. connect (m_dragScrollTimer, TQT_SIGNAL (timeout ()),
  348. this, TQT_SLOT (slotDragScroll ()));
  349. }
  350. kpViewScrollableContainer::~kpViewScrollableContainer ()
  351. {
  352. }
  353. // public
  354. int kpViewScrollableContainer::contentsXSoon ()
  355. {
  356. if (m_contentsXSoon < 0)
  357. return contentsX ();
  358. else
  359. return m_contentsXSoon;
  360. }
  361. // public
  362. int kpViewScrollableContainer::contentsYSoon ()
  363. {
  364. if (m_contentsYSoon < 0)
  365. return contentsY ();
  366. else
  367. return m_contentsYSoon;
  368. }
  369. // protected
  370. void kpViewScrollableContainer::connectGripSignals (kpGrip *grip)
  371. {
  372. connect (grip, TQT_SIGNAL (beganDraw ()),
  373. this, TQT_SLOT (slotGripBeganDraw ()));
  374. connect (grip, TQT_SIGNAL (continuedDraw (int, int, bool)),
  375. this, TQT_SLOT (slotGripContinuedDraw (int, int, bool)));
  376. connect (grip, TQT_SIGNAL (cancelledDraw ()),
  377. this, TQT_SLOT (slotGripCancelledDraw ()));
  378. connect (grip, TQT_SIGNAL (endedDraw (int, int)),
  379. this, TQT_SLOT (slotGripEndedDraw (int, int)));
  380. connect (grip, TQT_SIGNAL (statusMessageChanged (const TQString &)),
  381. this, TQT_SLOT (slotGripStatusMessageChanged (const TQString &)));
  382. connect (grip, TQT_SIGNAL (releasedAllButtons ()),
  383. this, TQT_SLOT (recalculateStatusMessage ()));
  384. }
  385. // public
  386. TQSize kpViewScrollableContainer::newDocSize () const
  387. {
  388. return newDocSize (m_resizeRoundedLastViewDX,
  389. m_resizeRoundedLastViewDY);
  390. }
  391. // public
  392. bool kpViewScrollableContainer::haveMovedFromOriginalDocSize () const
  393. {
  394. return m_haveMovedFromOriginalDocSize;
  395. }
  396. // public
  397. TQString kpViewScrollableContainer::statusMessage () const
  398. {
  399. return m_gripStatusMessage;
  400. }
  401. // public
  402. void kpViewScrollableContainer::clearStatusMessage ()
  403. {
  404. #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER && 1
  405. kdDebug () << "kpViewScrollableContainer::clearStatusMessage()" << endl;
  406. #endif
  407. m_bottomRightGrip->setUserMessage (TQString());
  408. m_bottomGrip->setUserMessage (TQString());
  409. m_rightGrip->setUserMessage (TQString());
  410. }
  411. // protected
  412. TQSize kpViewScrollableContainer::newDocSize (int viewDX, int viewDY) const
  413. {
  414. if (!m_view)
  415. return TQSize ();
  416. if (!docResizingGrip ())
  417. return TQSize ();
  418. const int docX = (int) m_view->transformViewToDocX (m_view->width () + viewDX);
  419. const int docY = (int) m_view->transformViewToDocY (m_view->height () + viewDY);
  420. return TQSize (TQMAX (1, docX), TQMAX (1, docY));
  421. }
  422. // protected
  423. void kpViewScrollableContainer::calculateDocResizingGrip ()
  424. {
  425. if (m_bottomRightGrip->isDrawing ())
  426. m_docResizingGrip = m_bottomRightGrip;
  427. else if (m_bottomGrip->isDrawing ())
  428. m_docResizingGrip = m_bottomGrip;
  429. else if (m_rightGrip->isDrawing ())
  430. m_docResizingGrip = m_rightGrip;
  431. else
  432. m_docResizingGrip = 0;
  433. }
  434. // protected
  435. kpGrip *kpViewScrollableContainer::docResizingGrip () const
  436. {
  437. return m_docResizingGrip;
  438. }
  439. // protected
  440. int kpViewScrollableContainer::bottomResizeLineWidth () const
  441. {
  442. if (!docResizingGrip ())
  443. return -1;
  444. if (!m_view)
  445. return -1;
  446. if (docResizingGrip ()->type () & kpGrip::Bottom)
  447. return TQMAX (m_view->zoomLevelY () / 100, 1);
  448. else
  449. return 1;
  450. }
  451. // protected
  452. int kpViewScrollableContainer::rightResizeLineWidth () const
  453. {
  454. if (!docResizingGrip ())
  455. return -1;
  456. if (!m_view)
  457. return -1;
  458. if (docResizingGrip ()->type () & kpGrip::Right)
  459. return TQMAX (m_view->zoomLevelX () / 100, 1);
  460. else
  461. return 1;
  462. }
  463. // protected
  464. TQRect kpViewScrollableContainer::bottomResizeLineRect () const
  465. {
  466. if (m_resizeRoundedLastViewX < 0 || m_resizeRoundedLastViewY < 0)
  467. return TQRect ();
  468. return TQRect (TQPoint (0,
  469. m_resizeRoundedLastViewY),
  470. TQPoint (m_resizeRoundedLastViewX - 1,
  471. m_resizeRoundedLastViewY + bottomResizeLineWidth () - 1));
  472. }
  473. // protected
  474. TQRect kpViewScrollableContainer::rightResizeLineRect () const
  475. {
  476. if (m_resizeRoundedLastViewX < 0 || m_resizeRoundedLastViewY < 0)
  477. return TQRect ();
  478. return TQRect (TQPoint (m_resizeRoundedLastViewX,
  479. 0),
  480. TQPoint (m_resizeRoundedLastViewX + rightResizeLineWidth () - 1,
  481. m_resizeRoundedLastViewY - 1));
  482. }
  483. // protected
  484. TQRect kpViewScrollableContainer::bottomRightResizeLineRect () const
  485. {
  486. if (m_resizeRoundedLastViewX < 0 || m_resizeRoundedLastViewY < 0)
  487. return TQRect ();
  488. return TQRect (TQPoint (m_resizeRoundedLastViewX,
  489. m_resizeRoundedLastViewY),
  490. TQPoint (m_resizeRoundedLastViewX + rightResizeLineWidth () - 1,
  491. m_resizeRoundedLastViewY + bottomResizeLineWidth () - 1));
  492. }
  493. // TODO: are these 2 correct? Remember that viewport()->x() == 1, viewport()->y() == 1
  494. // protected
  495. TQPoint kpViewScrollableContainer::mapViewToViewport (const TQPoint &viewPoint)
  496. {
  497. return viewPoint - TQPoint (contentsX (), contentsY ());
  498. }
  499. // protected
  500. TQRect kpViewScrollableContainer::mapViewToViewport (const TQRect &viewRect)
  501. {
  502. if (!viewRect.isValid ())
  503. return TQRect ();
  504. TQRect ret = viewRect;
  505. ret.moveBy (-contentsX (), -contentsY ());
  506. return ret;
  507. }
  508. // protected
  509. TQRect kpViewScrollableContainer::mapViewportToGlobal (const TQRect &viewportRect)
  510. {
  511. return kpWidgetMapper::toGlobal (viewport (), viewportRect);
  512. }
  513. // protected
  514. TQRect kpViewScrollableContainer::mapViewToGlobal (const TQRect &viewRect)
  515. {
  516. return mapViewportToGlobal (mapViewToViewport (viewRect));
  517. }
  518. // protected
  519. void kpViewScrollableContainer::repaintWidgetAtResizeLineViewRect (
  520. TQWidget *widget, const TQRect &resizeLineViewRect)
  521. {
  522. const TQRect resizeLineGlobalRect = mapViewToGlobal (resizeLineViewRect);
  523. const TQRect widgetGlobalRect = kpWidgetMapper::toGlobal (widget,
  524. widget->rect ());
  525. const TQRect redrawGlobalRect =
  526. resizeLineGlobalRect.intersect (widgetGlobalRect);
  527. const TQRect redrawWidgetRect =
  528. kpWidgetMapper::fromGlobal (widget, redrawGlobalRect);
  529. if (redrawWidgetRect.isValid ())
  530. {
  531. // TODO: should be "!widget->testWFlags (TQt::WRepaintNoErase)"
  532. // but for some reason, doesn't work for viewport().
  533. const bool erase = !dynamic_cast <kpView *> (widget);
  534. widget->repaint (redrawWidgetRect, erase);
  535. }
  536. }
  537. // protected
  538. void kpViewScrollableContainer::repaintWidgetAtResizeLines (TQWidget *widget)
  539. {
  540. repaintWidgetAtResizeLineViewRect (widget, rightResizeLineRect ());
  541. repaintWidgetAtResizeLineViewRect (widget, bottomResizeLineRect ());
  542. repaintWidgetAtResizeLineViewRect (widget, bottomRightResizeLineRect ());
  543. }
  544. // protected
  545. void kpViewScrollableContainer::eraseResizeLines ()
  546. {
  547. if (m_resizeRoundedLastViewX >= 0 && m_resizeRoundedLastViewY >= 0)
  548. {
  549. repaintWidgetAtResizeLines (viewport ());
  550. repaintWidgetAtResizeLines (m_view);
  551. repaintWidgetAtResizeLines (m_bottomGrip);
  552. repaintWidgetAtResizeLines (m_rightGrip);
  553. repaintWidgetAtResizeLines (m_bottomRightGrip);
  554. }
  555. }
  556. // protected
  557. void kpViewScrollableContainer::drawResizeLines ()
  558. {
  559. #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER && 0
  560. kdDebug () << "kpViewScrollableContainer::drawResizeLines()"
  561. << " lastViewX=" << m_resizeRoundedLastViewX
  562. << " lastViewY=" << m_resizeRoundedLastViewY
  563. << endl;
  564. #endif
  565. TQPainter p (viewport (), true/*unclipped*/);
  566. p.setRasterOp (TQt::NotROP);
  567. const TQRect rightRect = rightResizeLineRect ();
  568. if (rightRect.isValid ())
  569. p.fillRect (mapViewToViewport (rightRect), TQt::white);
  570. const TQRect bottomRect = bottomResizeLineRect ();
  571. if (bottomRect.isValid ())
  572. p.fillRect (mapViewToViewport (bottomRect), TQt::white);
  573. const TQRect bottomRightRect = bottomRightResizeLineRect ();
  574. if (bottomRightRect.isValid ())
  575. p.fillRect (mapViewToViewport (bottomRightRect), TQt::white);
  576. p.end ();
  577. }
  578. // protected
  579. void kpViewScrollableContainer::updateResizeLines (int viewX, int viewY,
  580. int viewDX, int viewDY)
  581. {
  582. #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER && 0
  583. kdDebug () << "kpViewScrollableContainer::updateResizeLines("
  584. << viewX << "," << viewY << ")"
  585. << " oldViewX=" << m_resizeRoundedLastViewX
  586. << " oldViewY=" << m_resizeRoundedLastViewY
  587. << " viewDX=" << viewDX
  588. << " viewDY=" << viewDY
  589. << endl;
  590. #endif
  591. eraseResizeLines ();
  592. if (viewX >= 0 && viewY >= 0)
  593. {
  594. m_resizeRoundedLastViewX = (int) m_view->transformDocToViewX ((int) m_view->transformViewToDocX (viewX));
  595. m_resizeRoundedLastViewY = (int) m_view->transformDocToViewY ((int) m_view->transformViewToDocY (viewY));
  596. m_resizeRoundedLastViewDX = viewDX;
  597. m_resizeRoundedLastViewDY = viewDY;
  598. }
  599. else
  600. {
  601. m_resizeRoundedLastViewX = -1;
  602. m_resizeRoundedLastViewY = -1;
  603. m_resizeRoundedLastViewDX = 0;
  604. m_resizeRoundedLastViewDY = 0;
  605. }
  606. // TODO: This is suboptimal since if another window pops up on top of
  607. // KolourPaint then disappears, the lines are not redrawn
  608. // (although this doesn't happen very frequently since we grab the
  609. // keyboard and mouse when resizing):
  610. //
  611. // e.g. sleep 5 && gedit & sleep 10 && killall gedit
  612. //
  613. // Should be done in the paintEvent's of every child of the
  614. // scrollview.
  615. drawResizeLines ();
  616. }
  617. // protected slot
  618. void kpViewScrollableContainer::slotGripBeganDraw ()
  619. {
  620. if (!m_view)
  621. return;
  622. calculateDocResizingGrip ();
  623. m_haveMovedFromOriginalDocSize = false;
  624. updateResizeLines (m_view->width (), m_view->height (),
  625. 0/*viewDX*/, 0/*viewDY*/);
  626. emit beganDocResize ();
  627. }
  628. // protected slot
  629. void kpViewScrollableContainer::slotGripContinuedDraw (int inViewDX, int inViewDY,
  630. bool dueToDragScroll)
  631. {
  632. int viewDX = inViewDX,
  633. viewDY = inViewDY;
  634. #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER
  635. kdDebug () << "kpViewScrollableContainer::slotGripContinuedDraw("
  636. << viewDX << "," << viewDY << ") size="
  637. << newDocSize (viewDX, viewDY)
  638. << " dueToDragScroll=" << dueToDragScroll
  639. << endl;
  640. #endif
  641. if (!m_view)
  642. return;
  643. if (!dueToDragScroll &&
  644. beginDragScroll (TQPoint (), TQPoint (), m_view->zoomLevelX ()))
  645. {
  646. const TQPoint newViewDeltaPoint = docResizingGrip ()->viewDeltaPoint ();
  647. viewDX = newViewDeltaPoint.x ();
  648. viewDY = newViewDeltaPoint.y ();
  649. #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER
  650. kdDebug () << "\tdrag scrolled - new view delta point="
  651. << newViewDeltaPoint
  652. << endl;
  653. #endif
  654. }
  655. m_haveMovedFromOriginalDocSize = true;
  656. updateResizeLines (TQMAX (1, TQMAX (m_view->width () + viewDX, (int) m_view->transformDocToViewX (1))),
  657. TQMAX (1, TQMAX (m_view->height () + viewDY, (int) m_view->transformDocToViewY (1))),
  658. viewDX, viewDY);
  659. emit continuedDocResize (newDocSize ());
  660. }
  661. // protected slot
  662. void kpViewScrollableContainer::slotGripCancelledDraw ()
  663. {
  664. m_haveMovedFromOriginalDocSize = false;
  665. updateResizeLines (-1, -1, 0, 0);
  666. calculateDocResizingGrip ();
  667. emit cancelledDocResize ();
  668. endDragScroll ();
  669. }
  670. // protected slot
  671. void kpViewScrollableContainer::slotGripEndedDraw (int viewDX, int viewDY)
  672. {
  673. #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER
  674. kdDebug () << "kpViewScrollableContainer::slotGripEndedDraw("
  675. << viewDX << "," << viewDY << ") size="
  676. << newDocSize (viewDX, viewDY)
  677. << endl;
  678. #endif
  679. if (!m_view)
  680. return;
  681. const TQSize newSize = newDocSize (viewDX, viewDY);
  682. m_haveMovedFromOriginalDocSize = false;
  683. // must erase lines before view size changes
  684. updateResizeLines (-1, -1, 0, 0);
  685. calculateDocResizingGrip ();
  686. emit endedDocResize (newSize);
  687. endDragScroll ();
  688. }
  689. // protected slot
  690. void kpViewScrollableContainer::slotGripStatusMessageChanged (const TQString &string)
  691. {
  692. if (string == m_gripStatusMessage)
  693. return;
  694. m_gripStatusMessage = string;
  695. emit statusMessageChanged (string);
  696. }
  697. // public slot
  698. void kpViewScrollableContainer::recalculateStatusMessage ()
  699. {
  700. #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER
  701. kdDebug () << "kpViewScrollabelContainer::recalculateStatusMessage()" << endl;
  702. kdDebug () << "\tTQCursor::pos=" << TQCursor::pos ()
  703. << " global visibleRect="
  704. << kpWidgetMapper::toGlobal (this,
  705. TQRect (0, 0, visibleWidth (), visibleHeight ()))
  706. << " brGrip.hotRect=" << m_bottomRightGrip->hotRect (true)
  707. << " bGrip.hotRect=" << m_bottomGrip->hotRect (true)
  708. << " rGrip.hotRect=" << m_rightGrip->hotRect (true)
  709. << endl;
  710. #endif
  711. // HACK: After dragging to a new size, handles move so that they are now
  712. // under the mouse pointer but no mouseMoveEvent() is generated for
  713. // any grip. This also handles the case of cancelling over any
  714. // grip.
  715. //
  716. if (kpWidgetMapper::toGlobal (this,
  717. TQRect (0, 0, visibleWidth (), visibleHeight ()))
  718. .contains (TQCursor::pos ()))
  719. {
  720. if (m_bottomRightGrip->isShown () &&
  721. m_bottomRightGrip->hotRect (true/*to global*/)
  722. .contains (TQCursor::pos ()))
  723. {
  724. m_bottomRightGrip->setUserMessage (i18n ("Left drag the handle to resize the image."));
  725. }
  726. else if (m_bottomGrip->isShown () &&
  727. m_bottomGrip->hotRect (true/*to global*/)
  728. .contains (TQCursor::pos ()))
  729. {
  730. m_bottomGrip->setUserMessage (i18n ("Left drag the handle to resize the image."));
  731. }
  732. else if (m_rightGrip->isShown () &&
  733. m_rightGrip->hotRect (true/*to global*/)
  734. .contains (TQCursor::pos ()))
  735. {
  736. m_rightGrip->setUserMessage (i18n ("Left drag the handle to resize the image."));
  737. }
  738. else
  739. {
  740. clearStatusMessage ();
  741. }
  742. }
  743. else
  744. {
  745. clearStatusMessage ();
  746. }
  747. }
  748. // protected slot
  749. void kpViewScrollableContainer::slotContentsMoving (int x, int y)
  750. {
  751. #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER
  752. kdDebug () << "kpViewScrollableContainer::slotContentsMoving("
  753. << x << "," << y << ")"
  754. << " contentsX=" << contentsX ()
  755. << " contentsY=" << contentsY () << endl;
  756. #endif
  757. m_contentsXSoon = x, m_contentsYSoon = y;
  758. emit contentsMovingSoon (m_contentsXSoon, m_contentsYSoon);
  759. // Reduce flicker - don't let TQScrollView scroll to-be-erased lines
  760. eraseResizeLines ();
  761. TQTimer::singleShot (0, this, TQT_SLOT (slotContentsMoved ()));
  762. }
  763. // protected slot
  764. void kpViewScrollableContainer::slotContentsMoved ()
  765. {
  766. m_contentsXSoon = m_contentsYSoon = -1;
  767. kpGrip *grip = docResizingGrip ();
  768. #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER
  769. kdDebug () << "kpViewScrollableContainer::slotContentsMoved()"
  770. << " grip=" << grip
  771. << " contentsX=" << contentsX ()
  772. << " contentsY=" << contentsY () << endl;
  773. #endif
  774. if (!grip)
  775. return;
  776. grip->mouseMovedTo (grip->mapFromGlobal (TQCursor::pos ()),
  777. true/*moved due to drag scroll*/);
  778. }
  779. // protected
  780. void kpViewScrollableContainer::disconnectViewSignals ()
  781. {
  782. disconnect (m_view, TQT_SIGNAL (sizeChanged (const TQSize &)),
  783. this, TQT_SLOT (updateGrips ()));
  784. disconnect (m_view, TQT_SIGNAL (destroyed ()),
  785. this, TQT_SLOT (slotViewDestroyed ()));
  786. }
  787. // protected
  788. void kpViewScrollableContainer::connectViewSignals ()
  789. {
  790. connect (m_view, TQT_SIGNAL (sizeChanged (const TQSize &)),
  791. this, TQT_SLOT (updateGrips ()));
  792. connect (m_view, TQT_SIGNAL (destroyed ()),
  793. this, TQT_SLOT (slotViewDestroyed ()));
  794. }
  795. // public virtual [base TQScrollView]
  796. void kpViewScrollableContainer::addChild (TQWidget *widget, int x, int y)
  797. {
  798. #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER
  799. kdDebug () << "kpViewScrollableContainer::addChild(" << widget
  800. << "," << x << "," << y << endl;
  801. #endif
  802. TQScrollView::addChild (widget, x, y);
  803. kpView *view = dynamic_cast <kpView *> (widget);
  804. #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER
  805. kdDebug () << "\tcast to kpView: " << view << endl;
  806. #endif
  807. if (view)
  808. {
  809. setView (view);
  810. }
  811. }
  812. // public
  813. kpView *kpViewScrollableContainer::view () const
  814. {
  815. return m_view;
  816. }
  817. // public
  818. void kpViewScrollableContainer::setView (kpView *view)
  819. {
  820. #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER
  821. kdDebug () << "kpViewScrollableContainer::setView(" << view << ")" << endl;
  822. #endif
  823. if (m_view == view)
  824. return;
  825. if (m_view)
  826. {
  827. disconnectViewSignals ();
  828. }
  829. m_view = view;
  830. updateGrips ();
  831. if (m_view)
  832. {
  833. connectViewSignals ();
  834. }
  835. }
  836. // public slot
  837. void kpViewScrollableContainer::updateGrips ()
  838. {
  839. #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER
  840. kdDebug () << "kpViewScrollableContainer::updateGrips() m_view="
  841. << m_view << endl;
  842. #endif
  843. if (m_view)
  844. {
  845. m_bottomGrip->setFixedWidth (m_view->width ());
  846. moveChild (m_bottomGrip, 0, m_view->height ());
  847. m_rightGrip->setFixedHeight (m_view->height ());
  848. moveChild (m_rightGrip, m_view->width (), 0);
  849. moveChild (m_bottomRightGrip, m_view->width (), m_view->height ());
  850. }
  851. m_bottomGrip->setShown (bool (m_view));
  852. m_rightGrip->setShown (bool (m_view));
  853. m_bottomRightGrip->setShown (bool (m_view));
  854. #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER
  855. kdDebug () << "\tcontentsRect=" << contentsRect ()
  856. << " visibleRect=" << visibleRect ()
  857. << " viewportRect=" << viewport ()->rect ()
  858. << endl;
  859. #endif
  860. if (m_view)
  861. {
  862. resizeContents (m_view->width () + m_rightGrip->width (),
  863. m_view->height () + m_bottomGrip->height ());
  864. }
  865. else
  866. {
  867. resizeContents (0, 0);
  868. }
  869. recalculateStatusMessage ();
  870. }
  871. // protected slot
  872. void kpViewScrollableContainer::slotViewDestroyed ()
  873. {
  874. #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER
  875. kdDebug () << "kpViewScrollableContainer::slotViewDestroyed() m_view="
  876. << m_view << endl;
  877. #endif
  878. m_view = 0;
  879. updateGrips ();
  880. }
  881. // public slot
  882. bool kpViewScrollableContainer::beginDragScroll (const TQPoint &/*docPoint*/,
  883. const TQPoint &/*lastDocPoint*/,
  884. int zoomLevel,
  885. bool *didSomething)
  886. {
  887. if (didSomething)
  888. *didSomething = false;
  889. m_zoomLevel = zoomLevel;
  890. const TQPoint p = mapFromGlobal (TQCursor::pos ());
  891. #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER
  892. kdDebug () << "kpViewScrollableContainer::beginDragScroll() p=" << p
  893. << " dragScrollTimerRunOnce=" << m_scrollTimerRunOnce
  894. << endl;
  895. #endif
  896. bool stopDragScroll = true;
  897. bool scrolled = false;
  898. if (!noDragScrollRect ().contains (p))
  899. {
  900. if (m_dragScrollTimer->isActive ())
  901. {
  902. if (m_scrollTimerRunOnce)
  903. {
  904. scrolled = slotDragScroll ();
  905. }
  906. }
  907. else
  908. {
  909. m_scrollTimerRunOnce = false;
  910. m_dragScrollTimer->start (DragScrollInitialInterval);
  911. }
  912. stopDragScroll = false;
  913. }
  914. if (stopDragScroll)
  915. m_dragScrollTimer->stop ();
  916. if (didSomething)
  917. *didSomething = scrolled;
  918. return scrolled;
  919. }
  920. // public slot
  921. bool kpViewScrollableContainer::beginDragScroll (const TQPoint &docPoint,
  922. const TQPoint &lastDocPoint,
  923. int zoomLevel)
  924. {
  925. return beginDragScroll (docPoint, lastDocPoint, zoomLevel,
  926. 0/*don't want scrolled notification*/);
  927. }
  928. // public slot
  929. bool kpViewScrollableContainer::endDragScroll ()
  930. {
  931. #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER
  932. kdDebug () << "kpViewScrollableContainer::endDragScroll()" << endl;
  933. #endif
  934. if (m_dragScrollTimer->isActive ())
  935. {
  936. m_dragScrollTimer->stop ();
  937. return true;
  938. }
  939. else
  940. {
  941. return false;
  942. }
  943. }
  944. static const int distanceFromRectToMultiplier (int dist)
  945. {
  946. if (dist < 0)
  947. return 0;
  948. else if (dist < DragDistanceFromRectMaxFor1stMultiplier)
  949. return 1;
  950. else if (dist < DragDistanceFromRectMaxFor2ndMultiplier)
  951. return 2;
  952. else
  953. return 4;
  954. }
  955. // protected slot
  956. bool kpViewScrollableContainer::slotDragScroll (bool *didSomething)
  957. {
  958. bool scrolled = false;
  959. if (didSomething)
  960. *didSomething = false;
  961. const TQRect rect = noDragScrollRect ();
  962. const TQPoint pos = mapFromGlobal (TQCursor::pos ());
  963. #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER
  964. kdDebug () << "kpViewScrollableContainer::slotDragScroll()"
  965. << " noDragScrollRect=" << rect
  966. << " pos=" << pos
  967. << " contentsX=" << contentsX ()
  968. << " contentsY=" << contentsY () << endl;
  969. #endif
  970. int dx = 0, dy = 0;
  971. int dxMultiplier = 0, dyMultiplier = 0;
  972. if (pos.x () < rect.left ())
  973. {
  974. dx = -DragScrollNumPixels;
  975. dxMultiplier = distanceFromRectToMultiplier (rect.left () - pos.x ());
  976. }
  977. else if (pos.x () > rect.right ())
  978. {
  979. dx = +DragScrollNumPixels;
  980. dxMultiplier = distanceFromRectToMultiplier (pos.x () - rect.right ());
  981. }
  982. if (pos.y () < rect.top ())
  983. {
  984. dy = -DragScrollNumPixels;
  985. dyMultiplier = distanceFromRectToMultiplier (rect.top () - pos.y ());
  986. }
  987. else if (pos.y () > rect.bottom ())
  988. {
  989. dy = +DragScrollNumPixels;
  990. dyMultiplier = distanceFromRectToMultiplier (pos.y () - rect.bottom ());
  991. }
  992. #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER && 0
  993. kdDebug () << "kpViewScrollableContainer::slotDragScroll()"
  994. << " dx=" << dx << " * " << dxMultiplier
  995. << " dy=" << dy << " * " << dyMultiplier
  996. << " zoomLevel=" << m_zoomLevel
  997. << endl;
  998. #endif
  999. dx *= dxMultiplier;// * TQMAX (1, m_zoomLevel / 100);
  1000. dy *= dyMultiplier;// * TQMAX (1, m_zoomLevel / 100);
  1001. if (dx || dy)
  1002. {
  1003. const int oldContentsX = contentsX (),
  1004. oldContentsY = contentsY ();
  1005. scrollBy (dx, dy);
  1006. #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER && 1
  1007. kdDebug () << "\tafter scrollBy():"
  1008. << " contentsX=" << contentsX ()
  1009. << " contentsY=" << contentsY () << endl;
  1010. #endif
  1011. scrolled = (oldContentsX != contentsX () ||
  1012. oldContentsY != contentsY ());
  1013. if (scrolled)
  1014. {
  1015. TQRegion region = TQRect (contentsX (), contentsY (),
  1016. visibleWidth (), visibleHeight ());
  1017. region -= TQRect (oldContentsX, oldContentsY,
  1018. visibleWidth (), visibleHeight ());
  1019. // Repaint newly exposed region immediately to reduce tearing
  1020. // of scrollView.
  1021. m_view->repaint (region, false/*no erase*/);
  1022. }
  1023. }
  1024. m_dragScrollTimer->changeInterval (DragScrollInterval);
  1025. m_scrollTimerRunOnce = true;
  1026. if (didSomething)
  1027. *didSomething = scrolled;
  1028. return scrolled;
  1029. }
  1030. // protected virtual [base TQScrollView]
  1031. void kpViewScrollableContainer::contentsDragMoveEvent (TQDragMoveEvent *e)
  1032. {
  1033. #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER
  1034. kdDebug () << "kpViewScrollableContainer::contentsDragMoveEvent"
  1035. << e->pos ()
  1036. << endl;
  1037. #endif
  1038. TQScrollView::contentsDragMoveEvent (e);
  1039. }
  1040. // protected slot
  1041. bool kpViewScrollableContainer::slotDragScroll ()
  1042. {
  1043. return slotDragScroll (0/*don't want scrolled notification*/);
  1044. }
  1045. // protected virtual [base TQScrollView]
  1046. void kpViewScrollableContainer::contentsMouseMoveEvent (TQMouseEvent *e)
  1047. {
  1048. #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER
  1049. kdDebug () << "kpViewScrollableContainer::contentsMouseMoveEvent"
  1050. << e->pos ()
  1051. << endl;
  1052. #endif
  1053. TQScrollView::contentsMouseMoveEvent (e);
  1054. }
  1055. // protected virtual [base TQScrollView]
  1056. void kpViewScrollableContainer::mouseMoveEvent (TQMouseEvent *e)
  1057. {
  1058. #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER
  1059. kdDebug () << "kpViewScrollableContainer::mouseMoveEvent"
  1060. << e->pos ()
  1061. << endl;
  1062. #endif
  1063. TQScrollView::mouseMoveEvent (e);
  1064. }
  1065. // protected virtual [base TQScrollView]
  1066. void kpViewScrollableContainer::contentsWheelEvent (TQWheelEvent *e)
  1067. {
  1068. e->ignore ();
  1069. if (m_view)
  1070. m_view->wheelEvent (e);
  1071. if (!e->isAccepted ())
  1072. TQScrollView::contentsWheelEvent (e);
  1073. }
  1074. TQRect kpViewScrollableContainer::noDragScrollRect () const
  1075. {
  1076. return TQRect (DragScrollLeftTopMargin, DragScrollLeftTopMargin,
  1077. width () - DragScrollLeftTopMargin - DragScrollRightBottomMargin,
  1078. height () - DragScrollLeftTopMargin - DragScrollRightBottomMargin);
  1079. }
  1080. // protected virtual [base TQScrollView]
  1081. bool kpViewScrollableContainer::eventFilter (TQObject *watchedObject, TQEvent *event)
  1082. {
  1083. return TQScrollView::eventFilter (watchedObject, event);
  1084. }
  1085. // protected virtual [base TQScrollView]
  1086. void kpViewScrollableContainer::viewportPaintEvent (TQPaintEvent *e)
  1087. {
  1088. #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER
  1089. kdDebug () << "kpViewScrollableContainer::viewportPaintEvent("
  1090. << e->rect ()
  1091. << ")" << endl;
  1092. #endif
  1093. TQScrollView::viewportPaintEvent (e);
  1094. }
  1095. // protected virtual [base TQFrame]
  1096. void kpViewScrollableContainer::paintEvent (TQPaintEvent *e)
  1097. {
  1098. #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER && 0
  1099. kdDebug () << "kpViewScrollableContainer::paintEvent("
  1100. << e->rect ()
  1101. << ")" << endl;
  1102. #endif
  1103. TQScrollView::paintEvent (e);
  1104. }
  1105. // protected virtual [base TQScrollView]
  1106. void kpViewScrollableContainer::resizeEvent (TQResizeEvent *e)
  1107. {
  1108. TQScrollView::resizeEvent (e);
  1109. emit resized ();
  1110. }
  1111. #include <kpviewscrollablecontainer.moc>