LabeledSection.h

Go to the documentation of this file.
00001 /*
00002  * The information in this file is
00003  * Copyright(c) 2007 Ball Aerospace & Technologies Corporation
00004  * and is subject to the terms and conditions of the
00005  * GNU Lesser General Public License Version 2.1
00006  * The license text is available from   
00007  * http://www.gnu.org/licenses/lgpl.html
00008  */
00009 
00010 #ifndef LABELEDSECTION_H
00011 #define LABELEDSECTION_H
00012 
00013 #include <QtGui/QWidget>
00014 #include <QtCore/QString>
00015 
00016 class QLabel;
00017 
00018 /**
00019  *  Used to organize complex widgets into smaller sections.
00020  *
00021  *  This widget should be used within complex layouts which have logical
00022  *  sections which can be split up.  By placing each section within a labeled
00023  *  section, a these complex widgets can have a consistent appearance
00024  *  throughout the application.
00025  *
00026  *  When a section widget is added, an expand/collapse indicator appears in the
00027  *  header next to the text label.  When the user clicks on the indicator the
00028  *  section widget is shown or hidden, giving the appearance of expanding or
00029  *  collapsing the labeled section.  This is especially useful when multiple
00030  *  labeled sections are contained in a LabeledSectionGroup, which provides a
00031  *  common layout in a scroll area.
00032  *
00033  *  @see        setSectionWidget()
00034  */
00035 class LabeledSection : public QWidget
00036 {
00037    Q_OBJECT
00038 
00039 public:
00040    /**
00041     *  Creates a labeled section with no header text and no section widget.
00042     *
00043     *  @param   pParent
00044     *           The parent widget.
00045     */
00046    LabeledSection(QWidget* pParent = NULL);
00047 
00048    /**
00049     *  Creates a labeled section with header text but no section widget.
00050     *
00051     *  This constructor may be used to create a simple separator between other
00052     *  widgets.  With no section widget, the expand/collapse indicator is not
00053     *  shown.
00054     *
00055     *  @param   text
00056     *           The text to dispay in the header.
00057     *  @param   pParent
00058     *           The parent widget.
00059     */
00060    LabeledSection(const QString& text, QWidget* pParent = NULL);
00061 
00062    /**
00063     *  Creates a labeled section with header text and a section widget.
00064     *
00065     *  @param   pSectionWidget
00066     *           The widget to display below the header.  When a valid section
00067     *           widget is given, the widget is shown and the labeled section
00068     *           assumes ownership of the new section widget.  The labeled
00069     *           section will delete the section widget when the labeled section
00070     *           itself is deleted.
00071     *  @param   text
00072     *           The text to dispay in the header.
00073     *  @param   pParent
00074     *           The parent widget.
00075     */
00076    LabeledSection(QWidget* pSectionWidget, const QString& text, QWidget* pParent = NULL);
00077 
00078    /**
00079     *  Destroys the labeled section and the section widget.
00080     */
00081    ~LabeledSection();
00082 
00083    /**
00084     *  Returns the header text.
00085     *
00086     *  @return  The header text.
00087     *
00088     *  @see     setText()
00089     */
00090    QString getText() const;
00091 
00092    /**
00093     *  Sets the text in the header.
00094     *
00095     *  @param   newText
00096     *           The new text to use in the header.
00097     *
00098     *  @see     getText()
00099     */
00100    void setText(const QString &newText);
00101 
00102    /**
00103     *  Returns the contained section widget.
00104     *
00105     *  @return  The contained section widget, which may be \c NULL.
00106     *
00107     *  @see     setSectionWidget()
00108     */
00109    QWidget* getSectionWidget() const;
00110 
00111    /**
00112     *  Sets the contained section widget.
00113     *
00114     *  If the widget already contains a section widget, the parent of the old
00115     *  section widget is set to \c NULL and the widget is not deleted.  The
00116     *  caller of this function then assumes ownership of the old section
00117     *  widget and is responsible for deleting it.
00118     *
00119     *  When a valid section widget is given, an expand/collapse indicator
00120     *  appears in the header next to the text label.  When the user clicks on
00121     *  the indicator the section widget is shown or hidden, giving the
00122     *  appearance of expanding or collapsing the labeled section.
00123     *
00124     *  @param   pNewSectionWidget
00125     *           The new section widget to display.  The labeled section assumes
00126     *           ownership of the new section widget and will delete the section
00127     *           widget when the labeled section itself is deleted.
00128     *
00129     *  @see     getSectionWidget()
00130     */
00131    void setSectionWidget(QWidget* pNewSectionWidget);
00132 
00133 public slots:
00134    /**
00135     *  Collapses the section widget to show just the header.
00136     *
00137     *  If the widget does not have a section widget, this method does nothing.
00138     */
00139    void collapse();
00140 
00141    /**
00142     *  Expands the section widget to show both the header and the section
00143     *  widget.
00144     *
00145     *  If the widget does not have a section widget, this method does nothing.
00146     */
00147    void expand();
00148 
00149 signals:
00150    /**
00151     *  Emitted when the section widget is hidden.
00152     *
00153     *  This signal is emitted when the section widget is hidden either
00154     *  programmatically by calling collapse() or when the user clicks the
00155     *  collapse indicator (-) next to the header text.
00156     */
00157    void collapsed();
00158 
00159    /**
00160     *  Emitted when the section widget is shown.
00161     *
00162     *  This signal is emitted when the section widget is shown either
00163     *  programmatically by calling expand() or when the user clicks the expand
00164     *  indicator (+) next to the header text.
00165     */
00166    void expanded();
00167 
00168 protected:
00169    /**
00170     *  Emits the collapsed() and expanded() signals when the section widget is
00171     *  hidden or shown.
00172     *
00173     *  By default, when the labeled section contains a section widget, an event
00174     *  filter is installed on the section widget to emit either the collapsed()
00175     *  or expanded() signal.  If another event filter is installed on the
00176     *  labeled section and the given object is not the section widget, this
00177     *  method is just a pass-through to the default QWidget implementation.
00178     *
00179     *  @param   pObject
00180     *           The object prompting the event.
00181     *  @param   pEvent
00182     *           The event invoked by the object.
00183     *
00184     *  @return  Returns the value returned by the default QWidget
00185     *           implementation.
00186     */
00187    bool eventFilter(QObject* pObject, QEvent* pEvent);
00188 
00189    /**
00190     *  Expands or collapses the section widget.
00191     *
00192     *  This method is called by Qt when the user clicks inside the section
00193     *  widget.  If the user clicked on the expand/collapse indicator in the
00194     *  header, the section is shown or hidden and the expanded() or collapsed()
00195     *  signal is emitted accordingly.
00196     *
00197     *  @param   pEvent
00198     *           The mouse event associated with the mouse press.
00199     */
00200    void mousePressEvent(QMouseEvent* pEvent);
00201 
00202    /**
00203     *  Expands or collapses the section widget.
00204     *
00205     *  This method is called by Qt when the user double clicks inside the
00206     *  section widget.  If the user clicked on the header text or the
00207     *  horizontal line, the section is shown or hidden and the expanded() or
00208     *  collapsed() signal is emitted accordingly.
00209     *
00210     *  @param   pEvent
00211     *           The mouse event associated with the mouse double click.
00212     */
00213    void mouseDoubleClickEvent(QMouseEvent* pEvent);
00214 
00215 private:
00216    LabeledSection(const LabeledSection& rhs);
00217    LabeledSection& operator=(const LabeledSection& rhs);
00218    void initialize(const QString& text = QString(), QWidget* pSectionWidget = NULL);
00219    void updateIndicator();
00220 
00221    QLabel* mpExpandLabel;
00222    QLabel* mpTextLabel;
00223    QWidget* mpSectionWidget;
00224 };
00225 
00226 #endif

Software Development Kit - Opticks 4.9.0 Build 16218