kdirstat
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.

ktreemapview.h 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. /*
  2. * File name: ktreemapview.h
  3. * Summary: High level classes for KDirStat
  4. * License: LGPL - See file COPYING.LIB for details.
  5. * Author: Stefan Hundhammer <sh@suse.de>
  6. *
  7. * Updated: 2003-02-02
  8. */
  9. #ifndef KTreemapView_h
  10. #define KTreemapView_h
  11. #include <tqcanvas.h>
  12. #ifdef HAVE_CONFIG_H
  13. # include <config.h>
  14. #endif
  15. #define MinAmbientLight 0
  16. #define MaxAmbientLight 200
  17. #define DefaultAmbientLight 40
  18. #define MinHeightScalePercent 10
  19. #define MaxHeightScalePercent 200
  20. #define DefaultHeightScalePercent 100
  21. #define DefaultHeightScaleFactor ( DefaultHeightScalePercent / 100.0 )
  22. #define DefaultMinTileSize 3
  23. #define CushionHeight 1.0
  24. class TQMouseEvent;
  25. class TDEConfig;
  26. namespace KDirStat
  27. {
  28. class KTreemapTile;
  29. class KTreemapSelectionRect;
  30. class KDirTree;
  31. class KFileInfo;
  32. class KTreemapView: public TQCanvasView
  33. {
  34. Q_OBJECT
  35. public:
  36. /**
  37. * Constructor.
  38. **/
  39. KTreemapView( KDirTree * tree,
  40. TQWidget * parent = 0,
  41. const TQSize & initialSize = TQSize() );
  42. /**
  43. * Destructor.
  44. **/
  45. virtual ~KTreemapView();
  46. /**
  47. * Returns the (topmost) treemap tile at the specified position
  48. * or 0 if there is none.
  49. **/
  50. KTreemapTile * tileAt( TQPoint pos );
  51. /**
  52. * Returns the minimum recommended size for this widget.
  53. * Reimplemented from TQWidget.
  54. **/
  55. virtual TQSize minimumSizeHint() const { return TQSize( 0, 0 ); }
  56. /**
  57. * Returns this treemap view's currently selected treemap tile or 0 if
  58. * there is none.
  59. **/
  60. KTreemapTile * selectedTile() const { return _selectedTile; }
  61. /**
  62. * Returns this treemap view's root treemap tile or 0 if there is none.
  63. **/
  64. KTreemapTile * rootTile() const { return _rootTile; }
  65. /**
  66. * Returns this treemap view's @ref KDirTree.
  67. **/
  68. KDirTree * tree() const { return _tree; }
  69. /**
  70. * Search the treemap for a tile that corresponds to the specified
  71. * KFileInfo node. Returns 0 if there is none.
  72. *
  73. * Notice: This is an expensive operation since all treemap tiles need
  74. * to be searched.
  75. **/
  76. KTreemapTile * findTile( KFileInfo * node );
  77. /**
  78. * Returns a suitable color for 'file' based on a set of internal rules
  79. * (according to filename extension, MIME type or permissions).
  80. **/
  81. TQColor tileColor( KFileInfo * file );
  82. public slots:
  83. /**
  84. * Make a treemap tile this treemap's selected tile.
  85. * 'tile' may be 0. In this case, only the previous selection is
  86. * deselected.
  87. **/
  88. void selectTile( KTreemapTile * tile );
  89. /**
  90. * Search the treemap for a tile with the specified KFileInfo node and
  91. * select that tile if it is found. If nothing is found or if 'node' is
  92. * 0, the previously selected tile is deselected.
  93. **/
  94. void selectTile( KFileInfo * node );
  95. /**
  96. * Zoom in one level towards the currently selected treemap tile:
  97. * The entire treemap will be rebuilt with the near-topmost ancestor of
  98. * the selected tile as the new root.
  99. **/
  100. void zoomIn();
  101. /**
  102. * Zoom out one level: The parent (if there is any) KFileInfo node of
  103. * the current treemap root becomes the new root. This usually works
  104. * only after zoomIn().
  105. **/
  106. void zoomOut();
  107. /**
  108. * Select the parent of the currently selected tile (if possible).
  109. *
  110. * This is very much the same as clicking with the middle mouse button,
  111. * but not quite: The middle mouse button cycles back to the tile
  112. * clicked at if there is no more parent. This method does not (because
  113. * there is no known mouse position).
  114. **/
  115. void selectParent();
  116. /**
  117. * Completely rebuild the entire treemap from the internal tree's root
  118. * on.
  119. **/
  120. void rebuildTreemap();
  121. /**
  122. * Clear the treemap contents.
  123. **/
  124. void clear();
  125. /**
  126. * Delete all items of a TQCanvas.
  127. *
  128. * Strangely enough, TQCanvas itself does not provide such a function.
  129. **/
  130. static void deleteAllItems( TQCanvas * canvas );
  131. /**
  132. * Notification that a dir tree node has been deleted.
  133. **/
  134. void deleteNotify( KFileInfo * node );
  135. /**
  136. * Read some parameters from the global @ref TDEConfig object.
  137. **/
  138. void readConfig();
  139. public:
  140. /**
  141. * Rebuild the treemap with 'newRoot' as the new root and the specified
  142. * size. If 'newSize' is (0, 0), visibleSize() is used.
  143. **/
  144. void rebuildTreemap( KFileInfo * newRoot,
  145. const TQSize & newSize = TQSize() );
  146. /**
  147. * Returns the visible size of the viewport presuming no scrollbars are
  148. * needed - which makes a lot more sense than fiddling with scrollbars
  149. * since treemaps can be scaled to make scrollbars unnecessary.
  150. **/
  151. TQSize visibleSize();
  152. /**
  153. * Returns the visible width of the viewport presuming no scrollbars
  154. * are needed.
  155. *
  156. * This uses visibleSize() which is a somewhat expensive operation, so
  157. * if you need both visibleWidth() and visibleHeight(), better call
  158. * visibleSize() once and access its width() and height() methods.
  159. **/
  160. int visibleWidth() { return visibleSize().width(); }
  161. /**
  162. * Returns the visible height of the viewport presuming no scrollbars
  163. * are needed.
  164. *
  165. * This uses visibleSize() which is a somewhat expensive operation, so
  166. * if you need both visibleWidth() and visibleHeight(), better call
  167. * visibleSize() once and access its width() and height() methods.
  168. **/
  169. int visibleHeight() { return visibleSize().height(); }
  170. /**
  171. * Returns true if it is possible to zoom in with the currently
  172. * selected tile, false if not.
  173. **/
  174. bool canZoomIn() const;
  175. /**
  176. * Returns true if it is possible to zoom out with the currently
  177. * selected tile, false if not.
  178. **/
  179. bool canZoomOut() const;
  180. /**
  181. * Returns true if it is possible to select the parent of the currently
  182. * selected tile, false if not.
  183. **/
  184. bool canSelectParent() const;
  185. /**
  186. * Returns 'true' if the treemap is automatically resized to fit into
  187. * the available space, 'false' if not.
  188. **/
  189. bool autoResize() const { return _autoResize; }
  190. /**
  191. * Returns 'true' if treemap tiles are to be squarified upon creation,
  192. * 'false' if not.
  193. **/
  194. bool squarify() const { return _squarify; }
  195. /**
  196. * Returns 'true' if cushion shading is to be used, 'false' if not.
  197. **/
  198. bool doCushionShading() const { return _doCushionShading; }
  199. /**
  200. * Returns 'true' if cushion shaded treemap tiles are to be separated
  201. * by a grid, 'false' if not.
  202. **/
  203. bool forceCushionGrid() const { return _forceCushionGrid; }
  204. /**
  205. * Returns 'true' if tile boundary lines should be drawn for cushion
  206. * treemaps, 'false' if not.
  207. **/
  208. bool ensureContrast() const { return _ensureContrast; }
  209. /**
  210. * Returns the minimum tile size in pixels. No treemap tiles less than
  211. * this in width or height are desired.
  212. **/
  213. int minTileSize() const { return _minTileSize; }
  214. /**
  215. * Returns the cushion grid color.
  216. **/
  217. const TQColor & cushionGridColor() const { return _cushionGridColor; }
  218. /**
  219. * Returns the outline color to use if cushion shading is not used.
  220. **/
  221. const TQColor & outlineColor() const { return _outlineColor; }
  222. /**
  223. * Returns the fill color for non-directory treemap tiles when cushion
  224. * shading is not used.
  225. **/
  226. const TQColor & fileFillColor() const { return _fileFillColor; }
  227. /**
  228. * Returns the fill color for directory (or "dotentry") treemap tiles
  229. * when cushion shading is not used.
  230. **/
  231. const TQColor & dirFillColor() const { return _dirFillColor; }
  232. /**
  233. * Returns the intensity of ambient light for cushion shading
  234. * [0..255]
  235. **/
  236. int ambientLight() const { return _ambientLight; }
  237. /**
  238. * Returns the X coordinate of a directed light source for cushion
  239. * shading.
  240. **/
  241. double lightX() const { return _lightX; }
  242. /**
  243. * Returns the Y coordinate of a directed light source for cushion
  244. * shading.
  245. **/
  246. double lightY() const { return _lightY; }
  247. /**
  248. * Returns the Z coordinate of a directed light source for cushion
  249. * shading.
  250. **/
  251. double lightZ() const { return _lightZ; }
  252. /**
  253. * Returns cushion ridge height degradation factor (0 .. 1.0) for each
  254. * level of subdivision.
  255. **/
  256. double heightScaleFactor() const { return _heightScaleFactor; }
  257. signals:
  258. /**
  259. * Emitted when the currently selected item changes.
  260. * Caution: 'item' may be 0 when the selection is cleared.
  261. **/
  262. void selectionChanged( KFileInfo * item );
  263. /**
  264. * Emitted when the treemap changes, e.g. is rebuilt, zoomed in, or
  265. * zoomed out.
  266. **/
  267. void treemapChanged();
  268. /**
  269. * Emitted when a context menu for this tile should be opened.
  270. * (usually on right click). 'pos' contains the click's mouse
  271. * coordinates.
  272. **/
  273. void contextMenu( KTreemapTile * tile, const TQPoint & pos );
  274. /**
  275. * Emitted at user activity. Some interactive actions are assigned an
  276. * amount of "activity points" that can be used to judge whether or not
  277. * the user is actually using this program or if it's just idly sitting
  278. * around on the desktop. This is intended for use together with a @ref
  279. * KActivityTracker.
  280. **/
  281. void userActivity( int points );
  282. protected:
  283. /**
  284. * Catch mouse click - emits a selectionChanged() signal.
  285. **/
  286. virtual void contentsMousePressEvent( TQMouseEvent * event );
  287. /**
  288. * Catch mouse double click:
  289. * Left button double-click zooms in,
  290. * right button double-click zooms out,
  291. * middle button double-click rebuilds treemap.
  292. **/
  293. virtual void contentsMouseDoubleClickEvent( TQMouseEvent * event );
  294. /**
  295. * Resize the treemap view. Suppress the treemap contents if the size
  296. * falls below a minimum size, redisplay it if it grows above that
  297. * minimum size.
  298. *
  299. * Reimplemented from TQFrame.
  300. **/
  301. virtual void resizeEvent( TQResizeEvent * event );
  302. /**
  303. * Convenience method to read a color from 'config'.
  304. **/
  305. TQColor readColorEntry( TDEConfig * config,
  306. const char * entryName,
  307. TQColor defaultColor );
  308. // Data members
  309. KDirTree * _tree;
  310. KTreemapTile * _rootTile;
  311. KTreemapTile * _selectedTile;
  312. KTreemapSelectionRect * _selectionRect;
  313. TQString _savedRootUrl;
  314. bool _autoResize;
  315. bool _squarify;
  316. bool _doCushionShading;
  317. bool _forceCushionGrid;
  318. bool _ensureContrast;
  319. int _minTileSize;
  320. TQColor _highlightColor;
  321. TQColor _cushionGridColor;
  322. TQColor _outlineColor;
  323. TQColor _fileFillColor;
  324. TQColor _dirFillColor;
  325. int _ambientLight;
  326. double _lightX;
  327. double _lightY;
  328. double _lightZ;
  329. double _heightScaleFactor;
  330. }; // class KTreemapView
  331. /**
  332. * Transparent rectangle to make a treemap tile clearly visible as
  333. * "selected". Leaf tiles could do that on their own, but higher-level
  334. * tiles (corresponding to directories) are obscured for the most part, so
  335. * only a small portion (if any) of their highlighted outline could be
  336. * visible. This selection rectangle simply draws a two-pixel red outline
  337. * on top (i.e., great z-height) of everything else. The rectangle is
  338. * transparent, so the treemap tile contents remain visible.
  339. **/
  340. class KTreemapSelectionRect: public TQCanvasRectangle
  341. {
  342. public:
  343. /**
  344. * Constructor.
  345. **/
  346. KTreemapSelectionRect( TQCanvas * canvas, const TQColor & color );
  347. /**
  348. * Highlight the specified treemap tile: Resize this selection
  349. * rectangle to match this tile and move it to this tile's
  350. * position. Show the selection rectangle if it is currently
  351. * invisible.
  352. **/
  353. void highlight( KTreemapTile * tile );
  354. }; // class KTreemapSelectionRect
  355. } // namespace KDirStat
  356. #endif // ifndef KTreemapView_h
  357. // EOF