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 / kaboutdialog.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  18.7 KB  |  634 lines

  1. /*
  2.  * This file is part of the KDE Libraries
  3.  * Copyright (C) 1999-2001 Mirko Boehm (mirko@kde.org) and
  4.  * Espen Sand (espen@kde.org)
  5.  *
  6.  * This library is free software; you can redistribute it and/or
  7.  * modify it under the terms of the GNU Library General Public
  8.  * License as published by the Free Software Foundation; either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * This library is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.  * Library General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU Library General Public License
  17.  * along with this library; see the file COPYING.LIB.  If not, write to
  18.  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  19.  * Boston, MA 02110-1301, USA.
  20.  *
  21.  */
  22.  
  23. /*
  24.  * This file declares a class for creating "About ..." dialogs
  25.  * in a general way. It provides geometry management and some
  26.  * options to connect for, like emailing the author or maintainer.
  27.  */
  28.  
  29.  
  30. #ifndef _KABOUTDIALOG_H_
  31. #define _KABOUTDIALOG_H_
  32.  
  33. #include <kdialogbase.h>
  34. #include <qstring.h>
  35.  
  36. class QFrame;
  37. class QLabel;
  38. class QVBoxLayout;
  39. class QTabWidget;
  40. class KURLLabel;
  41. class KAboutContainer;
  42. class KAboutContainerBase;
  43.  
  44. class KAboutWidgetPrivate;
  45.  
  46. class KAboutContainerPrivate;
  47. /**
  48.  *  KAboutContainer can be used to make a application specific AboutDialog.
  49.  */
  50. class KDEUI_EXPORT KAboutContainer : public QFrame
  51. {
  52.   Q_OBJECT
  53.  
  54.   public:
  55.     KAboutContainer( QWidget *parent=0, const char *name=0,
  56.              int margin=0, int spacing=0,
  57.              int childAlignment = AlignCenter,
  58.              int innerAlignment = AlignCenter );
  59.  
  60.     void addWidget( QWidget *widget );
  61.     void addPerson( const QString &name, const QString &email,
  62.             const QString &url, const QString &task,
  63.             bool showHeader = false, bool showframe = false,
  64.             bool showBold = false );
  65.     void addTitle(  const QString &title, int alignment=AlignLeft,
  66.             bool showframe = false, bool showBold = false );
  67.     void addImage( const QString &fileName, int alignment=AlignLeft );
  68.  
  69.     virtual QSize sizeHint( void ) const;
  70.     virtual QSize minimumSizeHint( void ) const;
  71.  
  72.   protected:
  73.     virtual void childEvent( QChildEvent *e );
  74.  
  75.   signals:
  76.     void urlClick( const QString &url );
  77.     void mailClick( const QString &name, const QString &address );
  78.  
  79.  
  80.   private:
  81.     QVBoxLayout *mVbox;
  82.     int mAlignment;
  83.     KAboutContainerPrivate* const d;
  84. };
  85.  
  86. class KAboutContributorPrivate;
  87.  
  88. /**
  89.  * Used internally by KAboutWidget
  90.  * @internal
  91.  */
  92. class KDEUI_EXPORT KAboutContributor : public QFrame
  93. {
  94.   Q_OBJECT
  95.  
  96.   public:
  97.     KAboutContributor( QWidget *parent=0, const char *name=0,
  98.                const QString &username=QString::null,
  99.                const QString &email=QString::null,
  100.                const QString &url=QString::null,
  101.                const QString &work=QString::null,
  102.                bool showHeader=false, bool showFrame=true,
  103.                bool showBold=false );
  104.  
  105.     void setName( const QString &text, const QString &header=QString::null,
  106.           bool update = true );
  107.     void setEmail( const QString &text, const QString &header=QString::null,
  108.            bool update = true );
  109.     void setURL( const QString &text, const QString &header=QString::null,
  110.          bool update = true );
  111.     void setWork( const QString &text, const QString &header=QString::null,
  112.           bool update = true );
  113.     QString getName( void ) const;
  114.     QString getEmail( void ) const;
  115.     QString getURL( void ) const;
  116.     QString getWork( void ) const;
  117.  
  118.     virtual QSize sizeHint( void ) const;
  119.  
  120.   protected:
  121.     virtual void fontChange( const QFont &oldFont );
  122.  
  123.   protected slots:
  124.     void urlClickedSlot( const QString& );
  125.     void emailClickedSlot( const QString& emailaddress );
  126.  
  127.   private:
  128.     void updateLayout( void );
  129.  
  130.   signals:
  131.     void sendEmail(const QString& name, const QString& email);
  132.     void openURL(const QString& url);
  133.  
  134.   private:
  135.     QLabel *mLabel[4];
  136.     QLabel *mText[4];
  137.     bool mShowHeader;
  138.     bool mShowBold;
  139.  
  140.     KAboutContributorPrivate* const d;
  141.  
  142.     virtual void setName(const char *_name) { QFrame::setName(_name); }
  143. };
  144.  
  145. /**
  146.  * KAboutWidget is the main widget for KAboutDialog.
  147.  *
  148.  * It has a minimum size set.
  149.  */
  150. class KDEUI_EXPORT KAboutWidget : public QWidget
  151. {
  152.   Q_OBJECT
  153.  
  154. public:
  155.  
  156.   /**
  157.    * The Qt constructor.
  158.    */
  159.   KAboutWidget(QWidget* parent=0, const char* name=0 );
  160.  
  161.   /**
  162.    * Adjust the minimum size (after setting the properties of the image and
  163.    * the labels.
  164.    */
  165.   void adjust();
  166.  
  167.   /**
  168.    * Sets the image as the application logo.
  169.    */
  170.   void setLogo(const QPixmap&);
  171.   /**
  172.    * Sets the author's name and email address.
  173.    */
  174.   void setAuthor(const QString& name, const QString& email,
  175.          const QString& url, const QString& work);
  176.   /**
  177.    * Sets the maintainers name and email address.
  178.    */
  179.   void setMaintainer(const QString& name, const QString& email,
  180.              const QString& url, const QString& work);
  181.   /**
  182.    * Shows this person as one of the major contributors.
  183.    */
  184.   void addContributor(const QString& name, const QString& email,
  185.               const QString& url, const QString& work);
  186.   /**
  187.    * Sets the text describing the version.
  188.    */
  189.   void setVersion(const QString& name);
  190.   // -------------------------------------------------------------------------
  191. protected slots:
  192.   /**
  193.    * Catches the signals from the contributors elements.
  194.    */
  195.   void sendEmailSlot(const QString& name, const QString& email);
  196.   /**
  197.    * Catches the clicked URLs.
  198.    */
  199.   void openURLSlot(const QString& url);
  200.   // -------------------------------------------------------------------------
  201. signals:
  202.   /**
  203.    * An email address has been selected by the user.
  204.    */
  205.   void sendEmail(const QString& name, const QString& email);
  206.   /**
  207.    * An URL has been clicked.
  208.    */
  209.   void openURL(const QString& url);
  210.   // -------------------------------------------------------------------------
  211. protected:
  212.   // events:
  213.   /**
  214.    * The resize event.
  215.    */
  216.   void resizeEvent(QResizeEvent*);
  217.   /**
  218.    * The label showing the program version.
  219.    */
  220.   QLabel *version;
  221.   /**
  222.    * The label showing the text "Other contributors:".
  223.    */
  224.   QLabel *cont;
  225.   /**
  226.    * The frame showing the logo.
  227.    */
  228.   QLabel *logo;
  229.   /**
  230.    * The application developer.
  231.    */
  232.   KAboutContributor *author;
  233.   /**
  234.    * The application maintainer.
  235.    */
  236.   KAboutContributor *maintainer;
  237.   /**
  238.    * Show the maintainer?
  239.    */
  240.   bool showMaintainer;
  241.   /**
  242.    * A set of people who contributed to the application.
  243.    */
  244.   QPtrList<KAboutContributor> contributors;
  245.   // #########################################################################
  246.   //
  247. private:
  248.   KAboutWidgetPrivate* const d;
  249. };
  250.  
  251. class KAboutDialogPrivate;
  252. /**
  253.  * A KDialogBase with predefined main widget.
  254.  *
  255.  * As a KDialogBase it uses your application wide settings
  256.  * for KDialogBase
  257.  * objects (base frame tiles, main frame tiles etc).
  258.  * To use it, simply create a KAboutDialog object, set all (or some) of its
  259.  * properties and show it. Do not derive it to create your own about dialog
  260.  * until you need some cool features that are unsupported and you have
  261.  * contacted me to add them.
  262.  *
  263.  * The dialog can be created using two different constructors. The
  264.  * difference between these constructors is the available components that
  265.  * can be used to build the contents of the dialog. The first (Constructor I)
  266.  * provides a number of easy to use methods. Basically it allows you
  267.  * to add the components of choice, and the components are placed in a
  268.  * predefined layout. You do not have to plan the layout. Everything is
  269.  * taken care of.
  270.  *
  271.  * The second constructor (Constructor II) works in quite the same manner
  272.  * as the first, but you have better control on where the components
  273.  * are postioned in the layout and you have access to an extended number
  274.  * of components you can install such as titles, product information,
  275.  * a tabbed pages (where you can display rich text with url links) and
  276.  * a person (developer) information field. The "About KDE" dialog box is
  277.  * created with Constructor II.
  278.  *
  279.  * For the derived features, see the basic class KDialogBase.
  280.  * @author Mirko Boehm (mirko@kde.org) and Espen Sand (espensa@online.no)
  281.  * @see KDialogBase
  282.  */
  283. class KDEUI_EXPORT KAboutDialog : public KDialogBase
  284. {
  285.   Q_OBJECT
  286.  
  287.   public:
  288.   /**
  289.    * Layout formats.
  290.    **/
  291.     enum LayoutType
  292.     {
  293.       AbtPlain         = 0x0001,
  294.       AbtTabbed        = 0x0002,
  295.       AbtTitle         = 0x0004,
  296.       AbtImageLeft     = 0x0008,
  297.       AbtImageRight    = 0x0010,
  298.       AbtImageOnly     = 0x0020,
  299.       AbtProduct       = 0x0040,
  300.       AbtKDEStandard   = AbtTabbed|AbtTitle|AbtImageLeft,
  301.       AbtAppStandard   = AbtTabbed|AbtTitle|AbtProduct,
  302.       AbtImageAndTitle = AbtPlain|AbtTitle|AbtImageOnly
  303.     };
  304.  
  305.   public:
  306.     /**
  307.      * The standard Qt constructor (Constructor I).
  308.      *
  309.      * Add components with the following methods:
  310.      * setLogo(), setAuthor(), setMaintainer(),
  311.      * addContributor(), or setVersion().
  312.      * The dialog will be laid out automatically.
  313.      */
  314.     KAboutDialog( QWidget *parent=0, const char *name=0, bool modal=true );
  315.  
  316.    /**
  317.     * The extended constructor. (Constructor II).
  318.     *
  319.     * Add components with the methods:
  320.     * setTitle(), setImage(), setImageBackgroundColor(),
  321.     * setImageFrame(), setProduct(), addTextPage(),
  322.     * addContainerPage(), addContainer(), or addPage().
  323.     *
  324.     * @param dialogLayout Use a mask of LayoutType flags.
  325.     * @param caption The dialog caption. The text you specify is prepended
  326.     *        by i18n("About").
  327.     * @param buttonMask Specifies what buttons will be visible.
  328.     * @param defaultButton Specifies what button will be marked as the default.
  329.     * @param parent Parent of the dialog.
  330.     * @param name Dialog name (for internal use only)
  331.     * @param modal Sets dialog modality. If false, the rest of the
  332.     *        program interface (other dialogs, for example) is accessible while
  333.     *        the dialog is open.
  334.     * @param separator If true, a separator line is drawn between the action
  335.     *        buttons an the main widget.
  336.     * @param user1 User button1 text.
  337.     * @param user2 User button2 text.
  338.     * @param user3 User button3 text.
  339.     *
  340.     */
  341.     KAboutDialog( int dialogLayout, const QString &caption, int buttonMask,
  342.           ButtonCode defaultButton, QWidget *parent=0,
  343.           const char *name=0, bool modal=false, bool separator = false,
  344.           const QString &user1 = QString::null,
  345.           const QString &user2 = QString::null,
  346.           const QString &user3 = QString::null );
  347.  
  348.   /**
  349.    * Adjusts the dialog.
  350.    *
  351.    * You can call this method after you have set up all
  352.    * the contents but it is not required. It is done automatically when
  353.    * show() is executed.
  354.    */
  355.   void adjust();
  356.  
  357.   /**
  358.    * Makes a modeless (modal = false in constructor) dialog visible.
  359.    *
  360.    * If you reimplement this method make sure you run it
  361.    * in the new method (e.g., show()). Reimplemented
  362.    * from KDialogBase.
  363.    */
  364.   virtual void show( void );
  365.  
  366.   /**
  367.    * Makes a modeless (modal = false in constructor) dialog visible.
  368.    *
  369.    * If you reimplmement this method make sure you run it
  370.    * in the new method (i.e., show( parent )).
  371.    *
  372.    * @param centerParent Center the dialog with respect to this widget.
  373.    */
  374.   virtual void show( QWidget *centerParent );
  375.  
  376.   /**
  377.    * (Constructor II only)
  378.    * Sets a title (not caption) in the uppermost area of the dialog.
  379.    *
  380.    * @param title Title string.
  381.    */
  382.   void setTitle( const QString &title );
  383.  
  384.   /**
  385.    * (Constructor II only)
  386.    * Define an image to be shown in the dialog. The position is dependent
  387.    * on the @p dialogLayout in the constructor
  388.    *
  389.    * @param fileName Path to image file.
  390.    */
  391.   void setImage( const QString &fileName );
  392.  
  393.   /**
  394.    * (Constructor II only)
  395.    * Define the program logo to be shown in the dialog.  Use this to override the
  396.    * default program logo.  For example, use this function if the 
  397.    * KAboutDialog is for a panel applet and you want to override the
  398.    * appletproxy logo with your own pixmap.
  399.    *
  400.    * @param fileName Path to file containing logo data in a format that 
  401.    *        can be loaded by QPixmap.
  402.    *
  403.    * @since 3.3
  404.    */
  405.   void setIcon( const QString &fileName ) KDE_DEPRECATED; // KDE4: remove
  406.  
  407.   /**
  408.    * Overloaded version of setProgramLogo(const QPixmap& pixmap).
  409.    *
  410.    * @since 3.4
  411.    */
  412.   void setProgramLogo( const QString &fileName );
  413.  
  414.   /**
  415.    * (Constructor II only)
  416.    * Define the program logo to be shown in the dialog.  Use this to override the
  417.    * default program logo. For example, use this function if the 
  418.    * KAboutDialog is for a panel applet and you want to override the
  419.    * appletproxy logo with your own pixmap.
  420.    *
  421.    * @param pixmap The logo pixmap.
  422.    *
  423.    * @since 3.4
  424.    */
  425.   void setProgramLogo( const QPixmap &pixmap );
  426.  
  427.   /**
  428.    * (Constructor II only)
  429.    * The image has a minimum size, but is centered within an area if the
  430.    * dialog box is enlarged by the user. You set the background color
  431.    * of the area with this method.
  432.    *
  433.    * @param color Background color.
  434.    */
  435.   void setImageBackgroundColor( const QColor &color );
  436.  
  437.   /**
  438.    * (Constructor II only)
  439.    * Enables or disables a frame around the image. The frame is, by default,
  440.    * enabled in the constructor
  441.    *
  442.    * @param state A value of @p true enables the frame
  443.    */
  444.   void setImageFrame( bool state );
  445.  
  446.   /**
  447.    * (Constructor II only)
  448.    * Prints the application name, KDE version, author, a copyright sign
  449.    * and a year string. To the left of the text the standard application
  450.    * icon is displayed.
  451.    *
  452.    * @param appName The application name.
  453.    * @param version Application version.
  454.    * @param author One or more authors.
  455.    * @param year A string telling when the application was made.
  456.    */
  457.   void setProduct( const QString &appName, const QString &version,
  458.            const QString &author, const QString &year );
  459.  
  460.   /**
  461.    * (Constructor II only)
  462.    * Adds a text page to a tab box. The text can be regular text or
  463.    * rich text. The rich text can contain URLs and mail links.
  464.    *
  465.    * @param title Tab name.
  466.    * @param text The text to display.
  467.    * @param richText Set this to @p true if 'text' is rich text.
  468.    * @param numLines The text area height will be adjusted so that this
  469.    *        is the minimum number of lines of text that are visible.
  470.    * @return The frame that contains the page.
  471.    */
  472.   QFrame *addTextPage( const QString &title, const QString &text,
  473.                        bool richText=false, int numLines=10 );
  474.  
  475.   /**
  476.    * (Constructor II only)
  477.    * Adds a license page to a tab box.
  478.    *
  479.    * @param title Tab name.
  480.    * @param text The text to display.
  481.    * @param numLines The text area height will be adjusted so that this
  482.    *        is the minimum number of lines of text that are visible.
  483.    * @return The frame that contains the page.
  484.    */
  485.   QFrame *addLicensePage( const QString &title, const QString &text,
  486.                           int numLines=10 );
  487.  
  488.   /**
  489.    * (Constructor II only)
  490.    * Adds a container to a tab box. You can add text and images to a
  491.    * container.
  492.    *
  493.    * @param title Tab name.
  494.    * @param childAlignment Specifies how the children of the container are
  495.    *        aligned with respect to the container.
  496.    * @param innerAlignment Specifies how the children are aligned with
  497.    *        respect to each other.
  498.    * @return The new container.
  499.    */
  500.   KAboutContainer *addContainerPage( const QString &title,
  501.     int childAlignment = AlignCenter, int innerAlignment = AlignCenter );
  502.  
  503.   /**
  504.    * (Constructor II only)
  505.    * Adds a container inside a QScrollView to a tab box. You can add text
  506.    * and images to a container.
  507.    *
  508.    * @param title Tab name.
  509.    * @param childAlignment Specifies how the children of the container are
  510.    *        aligned with respect to the container.
  511.    * @param innerAlignment Specifies how the children are aligned with
  512.    *        respect to each other.
  513.    * @return The new container.
  514.    */
  515.   KAboutContainer *addScrolledContainerPage( const QString &title,
  516.     int childAlignment = AlignCenter, int innerAlignment = AlignCenter );
  517.  
  518.   /**
  519.    * (Constructor II only)
  520.    * Adds a container. You can add text and images to a container.
  521.    *
  522.    * @param childAlignment Specifies how the children of the container are
  523.    *        aligned with respect to the container.
  524.    * @param innerAlignment Specifies how the children are aligned with
  525.    *        respect to each other.
  526.    * @return The new container.
  527.    */
  528.   KAboutContainer *addContainer( int childAlignment, int innerAlignment );
  529.  
  530.   /**
  531.    * (Constructor II only)
  532.    * Adds an empty page to a tab box.
  533.    *
  534.    * @param title Tab name
  535.    * @return The new page.
  536.    */
  537.   QFrame *addPage( const QString &title );
  538.  
  539.  
  540.   /**
  541.    * (Constructor I only)
  542.    * Sets the image as the application logo.
  543.    */
  544.   void setLogo(const QPixmap&);
  545.  
  546.   /**
  547.    * (Constructor I only)
  548.    * Sets the author's name and email address.
  549.    */
  550.   void setAuthor(const QString& name, const QString& email,
  551.          const QString& url, const QString& work);
  552.  
  553.   /**
  554.    * (Constructor I only)
  555.    * Sets the maintainer's name and email address.
  556.    */
  557.   void setMaintainer(const QString& name, const QString& email,
  558.              const QString& url, const QString& work);
  559.  
  560.   /**
  561.    * (Constructor I only)
  562.    * Show this person as one of the major contributors.
  563.    */
  564.   void addContributor(const QString& name, const QString& email,
  565.               const QString& url, const QString& work);
  566.  
  567.   /**
  568.    * (Constructor I only)
  569.    * Sets the text describing the version.
  570.    */
  571.   void setVersion(const QString& name);
  572.  
  573.   /**
  574.    * Create a modal dialog with an image in the upper area with a
  575.    * URL link below.
  576.    */
  577.   static void imageURL( QWidget *parent, const QString &caption,
  578.               const QString &path, const QColor &imageColor,
  579.               const QString &url );
  580.  
  581. signals:
  582.   /**
  583.    * Send an email to this person.
  584.    *
  585.    * The application must provide the
  586.    *  functionality.
  587.    */
  588.   void sendEmail(const QString& name, const QString& email);
  589.  
  590.   /**
  591.    * Open the selected URL.
  592.    */
  593.   void openURL(const QString& url);
  594.   // ----------------------------------------------------------------------------
  595. protected:
  596.   /**
  597.    * The main widget (Constructor I)
  598.    */
  599.   KAboutWidget * about;
  600.  
  601.   /**
  602.    * The main widget (Constructor II)
  603.    */
  604.   KAboutContainerBase *mContainerBase;
  605.  
  606.   // -------------------------------------------------------------------------
  607. protected slots:
  608.  
  609.   /**
  610.    * Connected to widget->sendEmail.
  611.    */
  612.   void sendEmailSlot(const QString& name, const QString& email);
  613.  
  614.   /**
  615.    * Open this URL.
  616.    */
  617.   void openURLSlot(const QString& url);
  618.  
  619.   /**
  620.    * (Constructor II only)
  621.    * Tells the position of the mouse cursor when the left mouse button
  622.    * is pressed above an image
  623.    */
  624.   virtual void mouseTrackSlot( int mode, const QMouseEvent *e );
  625.  
  626.   // #########################################################################
  627. protected:
  628.   virtual void virtual_hook( int id, void* data );
  629. private:
  630.   KAboutDialogPrivate* const d;
  631. };
  632.  
  633. #endif // defined KABOUTDIALOG_H
  634.