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.

kdirstatsettings.h 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  1. /*
  2. * File name: kdirstatsettings.h
  3. * Summary: Settings dialog for KDirStat
  4. * License: GPL - See file COPYING for details.
  5. * Author: Stefan Hundhammer <sh@suse.de>
  6. *
  7. * Updated: 2003-01-07
  8. */
  9. #ifndef KDirStatSettings_h
  10. #define KDirStatSettings_h
  11. #ifdef HAVE_CONFIG_H
  12. # include <config.h>
  13. #endif
  14. #include <tqlistbox.h>
  15. #include <kdialogbase.h>
  16. #include "kcleanup.h"
  17. #include "kcleanupcollection.h"
  18. #include "kdirstatapp.h"
  19. class TQCheckBox;
  20. class TQComboBox;
  21. class TQHGroupBox;
  22. class TQLabel;
  23. class TQLineEdit;
  24. class TQRadioButton;
  25. class TQSlider;
  26. class TQSpinBox;
  27. class TQVGroupBox;
  28. class TQWidget;
  29. class KColorButton;
  30. #define KDirStatSettingsMaxColorButton 12
  31. namespace KDirStat
  32. {
  33. class KCleanupListBox;
  34. class KCleanupPropertiesPage;
  35. class KDirTreeView;
  36. class KTreemapView;
  37. /**
  38. * Settings dialog for KDirStat
  39. *
  40. * @short Settings dialog for KDirStat
  41. **/
  42. class KSettingsDialog: public KDialogBase
  43. {
  44. Q_OBJECT
  45. public:
  46. /**
  47. * Constructor.
  48. *
  49. * Notice there is no parent widget passed but the application's main
  50. * window so its functions can be accessed. The parent of this widget
  51. * is always 0 since this is a dialog.
  52. **/
  53. KSettingsDialog( KDirStatApp * mainWin );
  54. /**
  55. * Destructor.
  56. **/
  57. virtual ~KSettingsDialog();
  58. /**
  59. * Overwritten from @ref TQDialog() to get any chance to set up the
  60. * dialog contents when the dialog gets shown - every time, not just at
  61. * program startup when the settings dialog is created (!).
  62. *
  63. * TQTabDialog used to have 'aboutToShow()' for a good reason, but the
  64. * creators of @ref KDialogBase in their infinite wisdom chose not to
  65. * include anything similar. How is that supposed to work, anyway?
  66. * Everything I saw in any other KDE sources looked to me like ugly
  67. * hacks to work around this. Am I really supposed to destroy my
  68. * settings dialog and create a new one every time it pops up? This can
  69. * certainly not be the way to go.
  70. *
  71. * This overwritten show() method sends that @ref aboutToShow() signal
  72. * before calling the parent class show() method.
  73. **/
  74. virtual void show();
  75. public slots:
  76. /**
  77. * Reimplemented from @ref KDialogBase to ask for confirmation.
  78. * Emits signal @ref defaultClicked() when the user confirms.
  79. **/
  80. virtual void slotDefault();
  81. /**
  82. * Reimplemented from @ref KDialogBase to set the appropriate help
  83. * topic prior to invoking online help.
  84. **/
  85. virtual void slotHelp();
  86. signals:
  87. /**
  88. * Emitted when (you might have guessed it) the dialog is about to be
  89. * shown. Connect this to slots that fill the individual dialog pages'
  90. * widgets contents (input fields etc.)
  91. **/
  92. void aboutToShow();
  93. protected:
  94. KDirStatApp * _mainWin;
  95. int _cleanupsPageIndex;
  96. int _treeColorsPageIndex;
  97. int _treemapPageIndex;
  98. int _generalSettingsPageIndex;
  99. }; // class KSettingsDialog
  100. /**
  101. * Abstract base class for all settings pages. Contains stubs for methods
  102. * that all settings pages have in common: setup(), apply(),
  103. * revertToDefaults().
  104. *
  105. * Note: This class contains pure virtuals - it cannot be
  106. * instantiated. Rather, derive your own classes from this one.
  107. **/
  108. class KSettingsPage: public TQWidget
  109. {
  110. Q_OBJECT
  111. public:
  112. /**
  113. * Constructor.
  114. *
  115. * Sets up standard connections to the methods defined in this class,
  116. * e.g., apply(), setup(), revertToDefaults().
  117. **/
  118. KSettingsPage( KSettingsDialog * dialog,
  119. TQWidget * parent );
  120. /**
  121. * Destructor.
  122. **/
  123. virtual ~KSettingsPage();
  124. public slots:
  125. /**
  126. * Apply the changes.
  127. *
  128. * Derived classes need to reimplement this method.
  129. **/
  130. virtual void apply() = 0;
  131. /**
  132. * Revert all values to their defaults.
  133. *
  134. * Derived classes need to reimplement this method.
  135. **/
  136. virtual void revertToDefaults() = 0;
  137. /**
  138. * Set up all fields prior to displaying the dialog.
  139. *
  140. * Derived classes need to reimplement this method.
  141. **/
  142. virtual void setup() = 0;
  143. public:
  144. /**
  145. * Returns the page index of this page.
  146. * This seems to be the only way to find out which settings page is in
  147. * the foreground for a @ref KDialogBase page.
  148. **/
  149. int pageIndex() { return _pageIndex; }
  150. protected:
  151. int _pageIndex;
  152. }; // class KSettingsPage
  153. /**
  154. * Settings tab page for the tree colors.
  155. *
  156. * Uses a vertical slider on the left side and a column of color
  157. * selection buttons on the right side. The slider enables/disables
  158. * the color buttons from top to bottom (at least one button is always
  159. * enabled). Each button represents the percentage fill color of one
  160. * directory level within the tree. When the tree widget runs out of
  161. * colors (i.e. there are more directory levels than different
  162. * colors), it will wrap around to the first color.
  163. *
  164. * @short settings page for tree colors
  165. * @author Stefan Hundhammer <sh@suse.de>
  166. **/
  167. class KTreeColorsPage: public KSettingsPage
  168. {
  169. Q_OBJECT
  170. public:
  171. /**
  172. * Constructor
  173. **/
  174. KTreeColorsPage( KSettingsDialog * dialog,
  175. TQWidget * parent,
  176. KDirStatApp * mainWin );
  177. /**
  178. * Destructor
  179. **/
  180. virtual ~KTreeColorsPage();
  181. public slots:
  182. /**
  183. * Apply the changes.
  184. *
  185. * Inherited from @ref KSettingsPage.
  186. **/
  187. virtual void apply();
  188. /**
  189. * Revert all values to their defaults.
  190. *
  191. * Inherited from @ref KSettingsPage.
  192. **/
  193. virtual void revertToDefaults();
  194. /**
  195. * Set up all fields prior to displaying the dialog.
  196. *
  197. * Inherited from @ref KSettingsPage.
  198. **/
  199. virtual void setup();
  200. protected slots:
  201. /**
  202. * Enable all colors up to color no. 'maxColors'.
  203. **/
  204. void enableColors( int maxColors );
  205. protected:
  206. KDirStatApp * _mainWin;
  207. KDirTreeView * _treeView;
  208. TQSlider * _slider;
  209. KColorButton * _colorButton [ KDirStatSettingsMaxColorButton ];
  210. TQLabel * _colorLabel [ KDirStatSettingsMaxColorButton ];
  211. int _maxButtons;
  212. }; // class KTreeColorsPage
  213. /**
  214. * Settings tab page for cleanup actions.
  215. *
  216. * Uses a KCleanupListBox for selection of one cleanup action and a
  217. * KCleanupPropertiesPage for editing this cleanup action's
  218. * properties. This class handles just the switching between the individual
  219. * cleanups. It copies the cleanup actions inserted and works with the
  220. * copies only until it is requested to save the changes or revert all
  221. * values to their defaults.
  222. *
  223. * @short settings page for cleanup actions
  224. **/
  225. class KCleanupPage: public KSettingsPage
  226. {
  227. Q_OBJECT
  228. public:
  229. /**
  230. * Constructor
  231. **/
  232. KCleanupPage( KSettingsDialog * dialog,
  233. TQWidget * parent,
  234. KDirStatApp * mainWin );
  235. /**
  236. * Destructor
  237. **/
  238. virtual ~KCleanupPage();
  239. /**
  240. * Insert an entry for a cleanup action. This is the original value
  241. * that will be changed only when receiving the apply() or
  242. * defaultValues() signals.
  243. **/
  244. void insert( KCleanup *cleanup );
  245. /**
  246. * Import all cleanup actions from the originals (from the main
  247. * window) to internal working copies.
  248. **/
  249. void importCleanups();
  250. /**
  251. * Copy the internal working copies of the cleanup actions back to
  252. * the main window's originals. Take care of pending changes within
  253. * the current properties page's fields prior to that.
  254. **/
  255. void exportCleanups();
  256. public slots:
  257. /**
  258. * Apply the changes.
  259. *
  260. * Inherited from @ref KSettingsPage.
  261. **/
  262. virtual void apply();
  263. /**
  264. * Revert all values to their defaults.
  265. *
  266. * Inherited from @ref KSettingsPage.
  267. **/
  268. virtual void revertToDefaults();
  269. /**
  270. * Set up all fields prior to displaying the dialog.
  271. *
  272. * Inherited from @ref KSettingsPage.
  273. **/
  274. virtual void setup();
  275. /**
  276. * Switch back and forth between all the cleanup actions very much
  277. * like in a tab dialog: Exchange field contents of the cleanup
  278. * properties page with the cleanup specified. Store the old
  279. * properties page contents in the working copies of the cleanups.
  280. **/
  281. void changeCleanup( KCleanup * cleanup );
  282. protected:
  283. /**
  284. * Retrieve any pending changes from the properties page and store
  285. * them in the cleanup specified.
  286. **/
  287. void storeProps( KCleanup * cleanup );
  288. //
  289. // Data members
  290. //
  291. KCleanupListBox * _listBox;
  292. KCleanupPropertiesPage * _props;
  293. KDirStatApp * _mainWin;
  294. KCleanupCollection _workCleanupCollection;
  295. KCleanup * _currentCleanup;
  296. }; // class KCleanupPage
  297. /**
  298. * List box for cleanup actions.
  299. *
  300. * This is meant as a substitute for a tabbed dialog inside the tabbed
  301. * dialog which would be much too wide and possibly confusing. Plus, this
  302. * list box is supposed to take care of its own geometry - the normal
  303. * dumbass list box obviously cannot do that. It just uses some random
  304. * geometry, relying on scroll bars for everything else. But in this
  305. * special case we want all items to be visible at all times without scroll
  306. * bars.
  307. *
  308. * @short cleanup list box
  309. **/
  310. class KCleanupListBox: public TQListBox
  311. {
  312. Q_OBJECT
  313. public:
  314. /**
  315. * Constructor.
  316. **/
  317. KCleanupListBox( TQWidget * parent = 0 );
  318. /**
  319. * Destructor.
  320. **/
  321. virtual ~KCleanupListBox() {};
  322. /**
  323. * Reimplemented so we can make sure all items are visible at all times
  324. * without scrolling. In fact, we never want to see a scroll bar with
  325. * this kind of list box.
  326. **/
  327. virtual TQSize sizeHint() const;
  328. /**
  329. * Insert an entry for a cleanup action into the list box. Uses the
  330. * cleanup action's internally stored title for display.
  331. **/
  332. void insert( KCleanup * cleanup );
  333. /**
  334. * Returns the currently selected cleanup of 0 if nothing is selected.
  335. **/
  336. KCleanup * selection() { return _selection; }
  337. /**
  338. * Update the list item's text that corresponds to 'cleanup' - the user
  339. * may have entered a new cleanup name. '0' means "check all items".
  340. **/
  341. void updateTitle( KCleanup * cleanup = 0 );
  342. signals:
  343. /**
  344. * Emitted when the user selects a list item, i.e. a cleanup action.
  345. **/
  346. void selectCleanup( KCleanup * cleanup );
  347. protected slots:
  348. /**
  349. * Select an item.
  350. **/
  351. void selectCleanup( TQListBoxItem * item );
  352. protected:
  353. KCleanup * _selection;
  354. }; // class KCleanupListBox
  355. /**
  356. * List box item for a KCleanupListBox.
  357. **/
  358. class KCleanupListBoxItem: public TQListBoxText
  359. {
  360. public:
  361. /**
  362. * Constructor.
  363. **/
  364. KCleanupListBoxItem( KCleanupListBox * listBox,
  365. KCleanup * cleanup );
  366. /**
  367. * Returns the corresponding cleanup.
  368. **/
  369. KCleanup * cleanup() { return _cleanup; }
  370. /**
  371. * Update the list box display with the cleanup's name which may have
  372. * changed - the user may have entered a new one.
  373. **/
  374. void updateTitle();
  375. protected:
  376. // Data members
  377. KCleanup * _cleanup;
  378. }; // class KCleanupListBoxItem
  379. /**
  380. * Properties page for one cleanup action.
  381. **/
  382. class KCleanupPropertiesPage: public TQWidget
  383. {
  384. Q_OBJECT
  385. public:
  386. /**
  387. * Constructor
  388. **/
  389. KCleanupPropertiesPage( TQWidget * parent,
  390. KDirStatApp * mainWin );
  391. /**
  392. * Retrieve the page's fields' values and store them in the cleanup
  393. * action.
  394. **/
  395. KCleanup fields( void ) const;
  396. public slots:
  397. /**
  398. * Set the page's fields' values with the cleanup action's
  399. * contents.
  400. **/
  401. void setFields( const KCleanup * cleanup );
  402. /**
  403. * Enable / disable all of the properties page's fields except the
  404. * 'enabled' check box.
  405. **/
  406. void enableFields( bool active );
  407. protected:
  408. TQString _id;
  409. TQCheckBox * _enabled;
  410. TQWidget * _fields;
  411. TQLineEdit * _title;
  412. TQLineEdit * _command;
  413. TQCheckBox * _recurse;
  414. TQCheckBox * _askForConfirmation;
  415. TQCheckBox * _worksForDir;
  416. TQCheckBox * _worksForFile;
  417. TQCheckBox * _worksForDotEntry;
  418. TQComboBox * _worksForProtocols;
  419. TQComboBox * _refreshPolicy;
  420. KDirStatApp * _mainWin;
  421. }; // class KCleanupPropertiesPage
  422. /**
  423. * Settings tab page for general/misc settings.
  424. **/
  425. class KGeneralSettingsPage: public KSettingsPage
  426. {
  427. Q_OBJECT
  428. public:
  429. /**
  430. * Constructor
  431. **/
  432. KGeneralSettingsPage( KSettingsDialog * dialog,
  433. TQWidget * parent,
  434. KDirStatApp * mainWin );
  435. /**
  436. * Destructor
  437. **/
  438. virtual ~KGeneralSettingsPage();
  439. public slots:
  440. /**
  441. * Apply the changes.
  442. *
  443. * Inherited from @ref KSettingsPage.
  444. **/
  445. virtual void apply();
  446. /**
  447. * Revert all values to their defaults.
  448. *
  449. * Inherited from @ref KSettingsPage.
  450. **/
  451. virtual void revertToDefaults();
  452. /**
  453. * Set up all fields prior to displaying the dialog.
  454. *
  455. * Inherited from @ref KSettingsPage.
  456. **/
  457. virtual void setup();
  458. /**
  459. * Check the enabled state of all widgets depending on the value of
  460. * other widgets.
  461. **/
  462. void checkEnabledState();
  463. protected:
  464. // Data members
  465. KDirStatApp * _mainWin;
  466. KDirTreeView * _treeView;
  467. TQCheckBox * _crossFileSystems;
  468. TQCheckBox * _enableLocalDirReader;
  469. TQCheckBox * _enableToolBarAnimation;
  470. TQCheckBox * _enableTreeViewAnimation;
  471. }; // class KGeneralSettingsPage
  472. /**
  473. * Settings tab page for treemap settings.
  474. **/
  475. class KTreemapPage: public KSettingsPage
  476. {
  477. Q_OBJECT
  478. public:
  479. /**
  480. * Constructor
  481. **/
  482. KTreemapPage( KSettingsDialog * dialog,
  483. TQWidget * parent,
  484. KDirStatApp * mainWin );
  485. /**
  486. * Destructor
  487. **/
  488. virtual ~KTreemapPage();
  489. public slots:
  490. /**
  491. * Apply the changes.
  492. *
  493. * Inherited from @ref KSettingsPage.
  494. **/
  495. virtual void apply();
  496. /**
  497. * Revert all values to their defaults.
  498. *
  499. * Inherited from @ref KSettingsPage.
  500. **/
  501. virtual void revertToDefaults();
  502. /**
  503. * Set up all fields prior to displaying the dialog.
  504. *
  505. * Inherited from @ref KSettingsPage.
  506. **/
  507. virtual void setup();
  508. /**
  509. * Check the enabled state of all widgets depending on the value of
  510. * other widgets.
  511. **/
  512. void checkEnabledState();
  513. protected:
  514. /**
  515. * Returns the main window's current treemap view or 0 if there is
  516. * none. Don't cache this value, it changes frequently!
  517. **/
  518. KTreemapView * treemapView() const { return _mainWin->treemapView(); }
  519. /**
  520. * Convenience method to read a color from 'config'.
  521. **/
  522. TQColor readColorEntry( TDEConfig * config,
  523. const char * entryName,
  524. TQColor defaultColor );
  525. // Data members
  526. KDirStatApp * _mainWin;
  527. // Widgets
  528. TQCheckBox * _squarify;
  529. TQCheckBox * _doCushionShading;
  530. TQVGroupBox * _cushionParams;
  531. TQSlider * _ambientLight;
  532. TQSpinBox * _ambientLightSB;
  533. TQSlider * _heightScalePercent;
  534. TQSpinBox * _heightScalePercentSB;
  535. TQCheckBox * _ensureContrast;
  536. TQCheckBox * _forceCushionGrid;
  537. KColorButton * _cushionGridColor;
  538. TQLabel * _cushionGridColorL;
  539. TQHGroupBox * _plainTileParams;
  540. KColorButton * _fileFillColor;
  541. KColorButton * _dirFillColor;
  542. KColorButton * _outlineColor;
  543. KColorButton * _highlightColor;
  544. TQSpinBox * _minTileSize;
  545. TQCheckBox * _autoResize;
  546. }; // class KTreemapPage
  547. } // namespace KDirStat
  548. /**
  549. * Add a horizontal stretch widget to take all excess space.
  550. **/
  551. void addHStretch( TQWidget * parent );
  552. /**
  553. * Add a vertical stretch widget to take all excess space.
  554. **/
  555. void addVStretch( TQWidget * parent );
  556. #endif // ifndef KDirStatSettings_h
  557. // EOF