home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / ktip.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-09-10  |  5.7 KB  |  193 lines

  1. /*****************************************************************
  2.  
  3. Copyright (c) 2000-2003 Matthias Hoelzer-Kluepfel <mhk@kde.org>
  4.                         Tobias Koenig <tokoe@kde.org>
  5.                         Daniel Molkentin <molkentin@kde.org>
  6.  
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13.  
  14. The above copyright notice and this permission notice shall be included in
  15. all copies or substantial portions of the Software.
  16.  
  17. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
  20. AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  21. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23.  
  24. ******************************************************************/
  25.  
  26. #ifndef __K_TIP_H__
  27. #define __K_TIP_H__
  28.  
  29. #include <qstringlist.h>
  30.  
  31. #include <kdialog.h>
  32.  
  33. class QCheckBox;
  34.  
  35. class KTextBrowser;
  36.  
  37. /**
  38.  * A database for tips-of-the-day.
  39.  *
  40.  * This class provides convenient access to a database containing
  41.  * tips of the day. The database is stored in a XML file and parsed
  42.  * when a KTipDatabase object is created.
  43.  *
  44.  * Once the file is read in, you can access the tips to display
  45.  * them in the tip of the day dialog.
  46.  *
  47.  * The state of the tipdialog is saved to the applications's config file
  48.  * in the group "TipOfDay" with a bool entry "RunOnStart". Check this value
  49.  * if you want to allow the user to enable/disable the tipdialog in the
  50.  * application's configuration dialog.
  51.  *
  52.  * @author Matthias Hoelzer-Kluepfel <mhk@kde.org>
  53.  *
  54.  */
  55. class KDEUI_EXPORT KTipDatabase
  56. {
  57. public:
  58.     /**
  59.      * This constructor reads in the tips from a file with the given name. If
  60.      * no name is given, a file called 'application-name/tips' will be loaded.
  61.      *
  62.      * @param tipFile The absolute path to the tips file.
  63.      */
  64.     KTipDatabase(const QString &tipFile = QString::null);
  65.  
  66.     /**
  67.      * This constructor takes a list of files that will be merged. This constructor
  68.      * essentially behaves like the one above. It returns when tipFiles is empty.
  69.      *
  70.      * @param tipFiles A list of absolute paths to the tips file
  71.      */ 
  72.     KTipDatabase(const QStringList &tipFiles);
  73.  
  74.     /**
  75.      * Returns the current tip.
  76.      */
  77.     QString tip() const;
  78.  
  79.     /**
  80.      * The next tip will become the current one.
  81.      */
  82.     void nextTip();
  83.  
  84.     /**
  85.      * The previous tip will become the current one.
  86.      */
  87.     void prevTip();
  88.  
  89. private:
  90.     void loadTips(const QString &tipFile);
  91.  
  92.     void addTips(const QString &tipFile);
  93.  
  94.     QStringList mTips;
  95.  
  96.     int mCurrent;
  97.     class KTipDatabasePrivate;
  98.     KTipDatabasePrivate *d;
  99. };
  100.  
  101. /**
  102.  * A Tip-of-the-Day dialog.
  103.  *
  104.  * This dialog class presents a tip-of-the-day.
  105.  *
  106.  * @author Matthias Hoelzer-Kluepfel <mhk@caldera.de>
  107.  */
  108. class KDEUI_EXPORT KTipDialog : public KDialog
  109. {
  110.     Q_OBJECT
  111. public:
  112.     /**
  113.      * Construct a tip dialog.
  114.      *
  115.      * @param db TipDatabase that should be used by the TipDialog.
  116.      * @param parent Parent widget of TipDialog.
  117.      * @param name The object name.
  118.      */
  119.     KTipDialog(KTipDatabase *db, QWidget *parent = 0, const char *name = 0);
  120.     ~KTipDialog();
  121.  
  122.     /**
  123.      * Shows a tip.
  124.      *
  125.      * This static method is all that is needed to add a tip-of-the-day
  126.      * dialog to an application. It will pop up the dialog, unless the
  127.      * user has asked that the dialog does not pop up on startup.
  128.      *
  129.      * Note that you probably want an item in the help menu calling
  130.      * this method with force=true.
  131.      *
  132.      * @param parent Parent widget of TipDialog.
  133.      * @param tipFile The name of the tip file. It has be relative to the "data"
  134.      *                resource of KStandardDirs
  135.      * @param force If true, the dialog is show, even when the users
  136.      *              disabled it.
  137.      */
  138.     static void showTip(QWidget *parent, const QString &tipFile = QString::null, bool force=false);
  139.  
  140.     /**
  141.      * Shows a tip
  142.      *
  143.      * This method behaves essentially as the one above, but expects a list of tips
  144.      *
  145.      * @param parent Parent widget of TipDialog.
  146.      * @param tipFiles A List of tip files. Each has be relative to the "data"
  147.      *                resource of KStandardDirs
  148.      * @param force If true, the dialog is show, even when the users
  149.      *              disabled it.
  150.      */
  151.     static void showMultiTip(QWidget *parent, const QStringList &tipFiles, bool force=false);
  152.  
  153.     /**
  154.      * Shows a tip.
  155.      *
  156.      * This methods calls showTip() with the applications main window as parent.
  157.      *
  158.      */
  159.     static void showTip(const QString &tipFile = QString::null, bool force = false);
  160.  
  161.     /**
  162.      * Toggles the start behavior.
  163.      *
  164.      * Normally, the user can disable the display of the tip in the dialog.
  165.      * This is just a way to change this setting from outside.
  166.      */
  167.     static void setShowOnStart(bool show);
  168.  
  169. protected:
  170.     bool eventFilter(QObject *, QEvent *);
  171.     virtual void virtual_hook( int id, void* data );
  172.  
  173. private slots:
  174.     void nextTip();
  175.     void prevTip();
  176.     void showOnStart(bool);
  177.  
  178. private:
  179.     KTipDatabase *mDatabase;
  180.  
  181.     QCheckBox *mTipOnStart;
  182.     KTextBrowser *mTipText;
  183.  
  184.     class KTipDialogPrivate;
  185.     KTipDialogPrivate *d;
  186.  
  187.     static KTipDialog *mInstance;
  188.  
  189.     QColor mBaseColor, mBlendedColor, mTextColor;
  190. };
  191.  
  192. #endif
  193.