CustomTreeWidget.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 CUSTOMTREEWIDGET_H
00011 #define CUSTOMTREEWIDGET_H
00012 
00013 #include <QtCore/QMap>
00014 #include <QtGui/QComboBox>
00015 #include <QtGui/QDoubleSpinBox>
00016 #include <QtGui/QLineEdit>
00017 #include <QtGui/QPushButton>
00018 #include <QtGui/QSpinBox>
00019 #include <QtGui/QStyledItemDelegate>
00020 #include <QtGui/QTreeWidget>
00021 #include <QtGui/QTreeWidgetItem>
00022 
00023 #include "ColorType.h"
00024 #include "EnumWrapper.h"
00025 
00026 class FileBrowser;
00027 
00028 /**
00029  *  A tree view widget with in-cell editing capbilities.
00030  *
00031  *  The CustomTreeWidget extends the QTreeWidget class to provide in-cell
00032  *  editing to allow the user to change the value of a particular cell.  The
00033  *  following edit capabilities are provided:
00034  *
00035  *  <pre>
00036  *  Edit Capability     Description
00037  *  ==================  =======================================================
00038  *  None                The cell cannot be edited by the user.
00039  *  Check Box           The cell contains a check box that the user can toggle
00040  *                      on and off.  %Text can optionally be displayed next to
00041  *                      the check box.
00042  *  Color               The cell contains a colored pixmap indicating the
00043  *                      selected color for the cell.  %Text can optionally be
00044  *                      displayed next to the colored pixmap.
00045  *  Line Edit           A single-line edit is invoked for the user to enter
00046  *                      text when the user activates the cell.
00047  *  Custom Line Edit    A single-line edit is invoked for the user to enter
00048  *                      text when the user activates the cell.  Enhancements
00049  *                      or restrictions may be placed on the line edit such as
00050  *                      a custom alignment or echo mode, or a validator or
00051  *                      completer by creating a QLineEdit independently from
00052  *                      the tree widget and calling the setCustomLineEdit()
00053  *                      method.
00054  *  File Browser        A single-line edit box with a browse button is invoked
00055  *                      when the user activates the cell.  When the user clicks
00056  *                      the browse button, a file selection dialog is invoked
00057  *                      for the user to select a single file.
00058  *  Directory Browser   A single-line edit box with a browse button is invoked
00059  *                      when the user activates the cell.  When the user clicks
00060  *                      the browse button, a file selection dialog is invoked
00061  *                      for the user to select a directory.
00062  *  Shortcut Edit       A single-line edit box is invoked when the user
00063  *                      activates the cell.  As the user types, the keystrokes
00064  *                      are converted into key combinations that displayed in
00065  *                      the edit box.  Examples of key combinations include
00066  *                      "Ctrl+S", and "Shift+F5".
00067  *  Combo Box           A drop-down combo box is invoked when the user
00068  *                      activates the cell.  The combo box items are populated
00069  *                      by creating a QComboBox indepentently from the tree
00070  *                      widget and calling the setComboBox() method.
00071  *  Spin Box            A spin box is invoked when the user activates the cell.
00072  *                      The step size and range of values in the spin box are
00073  *                      set by creating a QSpinBox independently from the tree
00074  *                      widget and calling the setSpinBox() method.
00075  *  Double Spin Box     A double precision floating-point spin box is invoked when
00076  *                      the user activates the cell.  The step size and range of values
00077  *                      in the spin box are set by creating a QDoubleSpinBox independently
00078  *                      from the tree widget and calling the setDoubleSpinBox() method.
00079  *  </pre>
00080  *
00081  *  The default row height of tree widget items that are added to a custom tree
00082  *  widget is 20 pixels to provide additional room for an edit widget.
00083  *
00084  *  Each item can be drawn with horizontal gridlines, vertical gridlines, or
00085  *  both.
00086  */
00087 class CustomTreeWidget : public QTreeWidget
00088 {
00089    Q_OBJECT
00090 
00091 public:
00092    /**
00093     *  Creates a new, empty custom tree widget.
00094     *
00095     *  @param   parent
00096     *           The parent widget.
00097     */
00098    CustomTreeWidget(QWidget* parent = 0);
00099 
00100    /**
00101     *  Destroys the custom tree widget and all child tree widget items.
00102     */
00103    virtual ~CustomTreeWidget();
00104 
00105    /**
00106     *  Specifies the edit widget used in a cell of the tree widget.
00107     *
00108     *  @see        setCellWidgetType()
00109     */
00110    enum WidgetTypeEnum
00111    {
00112       NO_WIDGET = 0,     /**< A read-only cell that contains no edit widget. */
00113       LINE_EDIT,         /**< A single-line edit box is invoked when the user
00114                               activates the cell.\  The line edit is
00115                               automatically created and managed by the custom
00116                               tree widget. */
00117       CUSTOM_LINE_EDIT,  /**< A single-line edit box is invoked when the user
00118                               activates the cell.\  The line edit is created
00119                               externally to the tree widget, and any
00120                               enhancements or restrictions are added by the
00121                               object creating the line edit.\  It is set into
00122                               the tree widget with the setCustomLineEdit()
00123                               method. */
00124       BROWSE_FILE_EDIT,  /**< A single-line edit box with a browse button is
00125                               invoked when the user activates the cell.\  When
00126                               the user clicks the browse button, a file
00127                               selection dialog is invoked to select a single
00128                               file. */
00129       BROWSE_DIR_EDIT,   /**< A single-line edit box with a browse button is
00130                               invoked when the user activates the cell.\  When
00131                               the user clicks the browse button, a file
00132                               selection dialog is invoked to select a
00133                               directory. */
00134       SHORTCUT_EDIT,     /**< A single-line edit box is invoked when the user
00135                               activates the cell.\  As the user types in the
00136                               edit box, the keystrokes are converted to
00137                               keyboard shortcut combinations. */
00138       COMBO_BOX,         /**< A drop-down combo box is invoked when the user
00139                               activates the cell.\  The combo box is created
00140                               and populated by the object creating the tree
00141                               widget.\  It is set into the tree widget with the
00142                               setComboBox() method. */
00143       SPIN_BOX,          /**< A spin box for integer values is invoked when the user
00144                               activates the cell.\  The spin box is created and its
00145                               step size and range of values are determined by the
00146                               object creating the tree widget.\  It is set into the
00147                               tree widget with the setSpinBox() method. */
00148       DOUBLE_SPIN_BOX    /**< A spin box for double precision floating-point values is
00149                               invoked when the user activates the cell.\  The spin box
00150                               is created and its step size and range of values are determined
00151                               by the object creating the tree widget.\  It is set into the
00152                               tree widget with the setDoubleSpinBox() method. */
00153    };
00154 
00155    /**
00156     * @EnumWrapper CustomTreeWidget::WidgetTypeEnum.
00157     */
00158    typedef EnumWrapper<WidgetTypeEnum> WidgetType;
00159 
00160    /**
00161     *  Specifies the state of the edit check box in a cell of the tree widget.
00162     *
00163     *  @see        setCellCheckState()
00164     */
00165    enum CheckStateEnum
00166    {
00167       UNCHECKED = 0,  /**< The check box is not checked. */
00168       CHECKED,        /**< The check box is checked. */
00169       SEMI_CHECKED    /**< The check box is partially checked, indicating that
00170                            the check box represents multiple values, some of
00171                            which are selected and some are not selected. */
00172    };
00173 
00174    /**
00175     * @EnumWrapper CustomTreeWidget::CheckStateEnum.
00176     */
00177    typedef EnumWrapper<CheckStateEnum> CheckState;
00178 
00179    /**
00180     *  Deletes all tree widget items.
00181     *
00182     *  This method clears the tree widget by destroying all tree widget items,
00183     *  but the columns and their names and sizes are not changed.
00184     */
00185    virtual void clear();
00186 
00187    /**
00188     *  Displays a check box in a given cell and sets its check state.
00189     *
00190     *  @param   pItem
00191     *           The item for which to display the check box and set its value.
00192     *  @param   iColumn
00193     *           The item column in which to display the check box and set its
00194     *           value.
00195     *  @param   eState
00196     *           The check state to set as the cell value.
00197     *
00198     *  @return  Returns \c true if the check box was successfully displayed and
00199     *           the value set; otherwise returns \c false.
00200     */
00201    bool setCellCheckState(QTreeWidgetItem* pItem, int iColumn, CheckState eState);
00202 
00203    /**
00204     *  Returns the current state of the check box in the given cell.
00205     *
00206     *  @param   pItem
00207     *           The item for which to query a cell check state.
00208     *  @param   iColumn
00209     *           The item column to query its check state.
00210     *
00211     *  @return  The check state of the given cell.  CustomTreeWidget::UNCHECKED
00212     *           is returned if the cell is not displaying a check box.
00213     */
00214    CheckState getCellCheckState(QTreeWidgetItem* pItem, int iColumn) const;
00215 
00216    /**
00217     *  Displays a pixmap of a given color in a cell.
00218     *
00219     *  @param   pItem
00220     *           The item for which to display the color pixmap and set its
00221     *           value.
00222     *  @param   iColumn
00223     *           The item column in which to display the color pixmap and set
00224     *           its value.
00225     *  @param   clrCell
00226     *           The color to set as the cell value.  If an invalid color is
00227     *           given, the pixmap is removed from the cell.
00228     *
00229     *  @return  Returns \c true if the color pixmap is successfully displayed;
00230     *           otherwise returns \c false.
00231     */
00232    bool setCellColor(QTreeWidgetItem* pItem, int iColumn, QColor clrCell);
00233 
00234    /**
00235     *  Returns the current color of a given cell.
00236     *
00237     *  @param   pItem
00238     *           The item for which to query a cell color.
00239     *  @param   iColumn
00240     *           The item column to query its color.
00241     *
00242     *  @return  The current cell color.  An invalid color is returned if the
00243     *           cell is not currently displaying a color.
00244     */
00245    QColor getCellColor(QTreeWidgetItem* pItem, int iColumn) const;
00246 
00247    /**
00248     *  Toggles whether the size of a color pixmap adjusts to the column width.
00249     *
00250     *  If a cell in an item is displaying a color pixmap, this method toggles
00251     *  the format for the pixmap width.  The pixmap can either adjust to the
00252     *  column size, which automatically updates as the column is resized, or
00253     *  the pixmap can have a fixed width to allow text to be displayed next to
00254     *  the pixmap.
00255     *
00256     *  Calling this method affects all cells displaying a color pixmap and it
00257     *  has no effect if no cells currently display a color pixmap.
00258     *
00259     *  @param   bFullCell
00260     *           Set this value to true to automatically adjust the pixmap size
00261     *           to the column width.  Set this value to false to use a fixed
00262     *           size for the color pixmap.
00263     *
00264     *  @see     setCellColor(), setColorWidth()
00265     */
00266    void setFullCellColor(bool bFullCell);
00267 
00268    /**
00269     *  Queries whether the size of a color pixmap adjusts to the column width.
00270     *
00271     *  @return  Returns \c true if the width of color pixmaps adjust to the
00272     *           column width.  Returns \c false if the color pixmaps use a
00273     *           fixed width.
00274     */
00275    bool getFullCellColor() const;
00276 
00277    /**
00278     *  Sets a fixed width for cell color pixmaps.
00279     *
00280     *  This method sets a fixed width for all cells displaying a color pixmap.
00281     *  The default fixed width is 50 screen pixels.  Calling this method has no
00282     *  effect if no cells currently display a color pixmap, or if the pixmap is
00283     *  set to adjust to the column width.
00284     *
00285     *  @param   iWidth
00286     *           The width of the color pixmap.
00287     *
00288     *  @see     setFullCellColor()
00289     */
00290    void setColorWidth(int iWidth);
00291 
00292    /**
00293     *  Returns the fixed width for cell color pixmaps.
00294     *
00295     *  @return  The fixed width of the color pixmaps.  A valid value is
00296     *           returned regardless of whether any cells are currently
00297     *           displaying color pixmaps or whether the pixmap width adjusts to
00298     *           the column width.
00299     */
00300    int getColorWidth() const;
00301 
00302    /**
00303     *  Returns the current edit widget type of a given cell.
00304     *
00305     *  @param   pItem
00306     *           The item to get a cell edit widget type.
00307     *  @param   iColumn
00308     *           The item column to get its edit widget type.
00309     *
00310     *  @return  The cell edit widget type.
00311     */
00312    WidgetType getCellWidgetType(QTreeWidgetItem* pItem, int iColumn) const;
00313 
00314    /**
00315     *  Sets the current edit widget type of a given cell.
00316     *
00317     *  This method sets the current edit widget type for a cell.  The edit
00318     *  widget can be used in conjunction with a cell color and a cell check
00319     *  box.
00320     *
00321     *  @param   pItem
00322     *           The item to set a cell edit widget type. This item can either be present
00323     *           in the tree at the time this method is called or added at a later time.
00324     *  @param   iColumn
00325     *           The item column to set its edit widget type.
00326     *  @param   eType
00327     *           The edit widget type for the cell.
00328     */
00329    bool setCellWidgetType(QTreeWidgetItem* pItem, int iColumn, WidgetType eType);
00330 
00331    /**
00332     *  Toggles whether the cell edit widget covers the entire cell.
00333     *
00334     *  If a cell in an item contains an edit widget, this method toggles the
00335     *  format for the widget width.  The widget can either cover the entire
00336     *  cell or just the portion of the cell not covered by the cell icon.
00337     *
00338     *  The default behavior is for the edit widget to cover the entire cell
00339     *  area.
00340     *
00341     *  Calling this method has no effect if the cell is read-only.
00342     *
00343     *  @param   pItem
00344     *           The item to set a cell's edit widget width format.
00345     *  @param   iColumn
00346     *           The item column to set its edit widget width format.
00347     *  @param   bFullCell
00348     *           Set this value to \c true to automatically adjust the edit
00349     *           widget size to the column width.  Set this value to \c false
00350     *           for the edit widget to not cover the cell icon.
00351     */
00352    void setFullCellEdit(QTreeWidgetItem* pItem, int iColumn, bool bFullCell);
00353 
00354    /**
00355     *  Queries whether a cell edit widget covers the entire cell.
00356     *
00357     *  @param   pItem
00358     *           The item to query for a cell's edit widget width format.
00359     *  @param   iColumn
00360     *           The item column to query its edit widget width format.
00361     *
00362     *  @return  Returns \c true if the edit widget of the given cell covers
00363     *           the entire cell.  Returns \c false if the edit widget does not
00364     *           cover the cell icon..
00365     */
00366    bool getFullCellEdit(QTreeWidgetItem* pItem, int iColumn) const;
00367 
00368    /**
00369     *  Sets a custom line edit to use as the edit widget for a given cell.
00370     *
00371     *  This method sets a custom line edit as the edit widget for the given
00372     *  cell.  The cell edit widget type must be set to
00373     *  CustomTreeWidget::CUSTOM_LINE_EDIT before this method is called.
00374     *
00375     *  @param   pItem
00376     *           The item in which to set the custom line edit as a cell edit
00377     *           widget.
00378     *  @param   iColumn
00379     *           The item column in which to set the custom line edit as its edit
00380     *           widget.
00381     *  @param   pLineEdit
00382     *           The line edit to use as the edit widget.  The line edit is
00383     *           reparented to the viewport widget, so it will automatically be
00384     *           deleted when the tree widget is deleted.
00385     *
00386     *  @return  Returns \c true if the line edit was successfully set as the
00387     *           edit widget; otherwise returns \c false.
00388     *
00389     *  @see     setCellWidgetType()
00390     */
00391    bool setCustomLineEdit(QTreeWidgetItem* pItem, int iColumn, QLineEdit* pLineEdit);
00392 
00393    /**
00394     *  Returns the custom line edit used as the edit widget for a given cell.
00395     *
00396     *  @param   pItem
00397     *           The item in which to get a cell custom line edit widget.
00398     *  @param   iColumn
00399     *           The item column in which to get the custom line edit widget.
00400     *
00401     *  @return  The custom line edit widget.  A valid line edit pointer is
00402     *           returned regardless of the current edit widget if a line edit
00403     *           has been previously set as the edit widget but not reset to
00404     *           \c NULL.
00405     */
00406    QLineEdit* getCustomLineEdit(QTreeWidgetItem* pItem, int iColumn) const;
00407 
00408    /**
00409     *  Sets the file browser to use as the edit widget for a given cell.
00410     *
00411     *  This method sets a file browser as the edit widget for the given cell.
00412     *  The cell edit widget type must be set to
00413     *  CustomTreeWidget::BROWSE_FILE_EDIT before this method is called.
00414     *
00415     *  @param   pItem
00416     *           The item in which to set the file browser as a cell edit widget.
00417     *  @param   iColumn
00418     *           The item column in which to set the file browser as its edit
00419     *           widget.
00420     *  @param   pFileBrowser
00421     *           The file browser to use as the edit widget.  The file browser
00422     *           is reparented to the viewport widget, so it will automatically
00423     *           be deleted when the tree widget is deleted.
00424     *
00425     *  @return  Returns \c true if the file browser was successfully set as the
00426     *           edit widget; otherwise returns \c false.
00427     *
00428     *  @see     setCellWidgetType()
00429     */
00430    bool setFileBrowser(QTreeWidgetItem* pItem, int iColumn, FileBrowser* pFileBrowser);
00431 
00432    /**
00433     *  Returns the file browser used as the edit widget for a given cell.
00434     *
00435     *  @param   pItem
00436     *           The item in which to get a cell file browser edit widget.
00437     *  @param   iColumn
00438     *           The item column in which to get the file browser edit widget.
00439     *
00440     *  @return  The file browser edit widget.  A valid item is returned
00441     *           regardless of the current edit widget if a file browser has
00442     *           been previously set as the edit widget but not reset to \c NULL.
00443     */
00444    FileBrowser* getFileBrowser(QTreeWidgetItem* pItem, int iColumn) const;
00445 
00446    /**
00447     *  Sets the combo box to use as the edit widget for a given cell.
00448     *
00449     *  This method sets a combo box as the edit widget for the given cell.  The
00450     *  cell edit widget type must be set to CustomTreeWidget::COMBO_BOX before
00451     *  this method is called.
00452     *
00453     *  @param   pItem
00454     *           The item in which to set the combo box as a cell edit widget.
00455     *  @param   iColumn
00456     *           The item column in which to set the combo box as its edit
00457     *           widget.
00458     *  @param   pCombo
00459     *           The populated combo box to use as the edit widget.  The combo
00460     *           box is reparented to the viewport widget, so it will
00461     *           automatically be deleted when the tree widget is deleted.
00462     *
00463     *  @return  Returns \c true if the combo box was successfully set as the
00464     *           edit widget; otherwise returns \c false.
00465     *
00466     *  @see     setCellWidgetType()
00467     */
00468    bool setComboBox(QTreeWidgetItem* pItem, int iColumn, QComboBox* pCombo);
00469 
00470    /**
00471     *  Returns the combo box used as the edit widget for a given cell.
00472     *
00473     *  @param   pItem
00474     *           The item in which to get a cell combo box edit widget.
00475     *  @param   iColumn
00476     *           The item column in which to get the combo box edit widget.
00477     *
00478     *  @return  The combo box edit widget.  A valid item is returned regardless
00479     *           of the current edit widget if a combo box has been previously
00480     *           set as the edit widget but not reset to \c NULL.
00481     */
00482    QComboBox* getComboBox(QTreeWidgetItem* pItem, int iColumn) const;
00483 
00484    /**
00485     *  Sets the spin box to use as the edit widget for a given cell.
00486     *
00487     *  This method sets a spin box as the edit widget for the given cell.  The
00488     *  cell edit widget type must be set to CustomTreeWidget::SPIN_BOX before this method is
00489     *  called.
00490     *
00491     *  @param   pItem
00492     *           The item in which to set the spin box as a cell edit widget.
00493     *  @param   iColumn
00494     *           The item column in which to set the spin box as its edit
00495     *           widget.
00496     *  @param   pSpin
00497     *           The spin box to use as the edit widget.  The spin box is
00498     *           reparented to the viewport widget, so it will automatically be
00499     *           deleted when the tree widget is deleted.
00500     *
00501     *  @return  Returns \c true if the spin box was successfully set as the
00502     *           edit widget; otherwise returns \c false.
00503     *
00504     *  @see     setDoubleSpinBox(), setCellWidgetType()
00505     */
00506    bool setSpinBox(QTreeWidgetItem* pItem, int iColumn, QSpinBox* pSpin);
00507 
00508    /**
00509     *  Returns the spin box used as the edit widget for a given cell.
00510     *
00511     *  @param   pItem
00512     *           The item in which to get a cell spin box edit widget.
00513     *  @param   iColumn
00514     *           The item column in which to get its spin box edit widget.
00515     *
00516     *  @return  The spin box edit widget.  A valid item is returned regardless
00517     *           of the current edit widget if a spin box has been previously
00518     *           set as the edit widget but not reset to \c NULL.
00519     *
00520     *  @see     getDoubleSpinBox()
00521     */
00522    QSpinBox* getSpinBox(QTreeWidgetItem* pItem, int iColumn) const;
00523 
00524    /**
00525     *  Sets the double spin box to use as the edit widget for a given cell.
00526     *
00527     *  This method sets a double spin box as the edit widget for the given cell.  The
00528     *  cell edit widget type must be set to CustomTreeWidget::DOUBLE_SPIN_BOX before this method is
00529     *  called.
00530     *
00531     *  @param   pItem
00532     *           The item in which to set the double spin box as a cell edit widget.
00533     *  @param   iColumn
00534     *           The item column in which to set the double spin box as its edit
00535     *           widget.
00536     *  @param   pSpin
00537     *           The double spin box to use as the edit widget.  The double spin box is
00538     *           reparented to the viewport widget, so it will automatically be
00539     *           deleted when the tree widget is deleted.
00540     *
00541     *  @return  Returns \c true if the double spin box was successfully set as the
00542     *           edit widget; otherwise returns \c false.
00543     *
00544     *  @see     setSpinBox(), setCellWidgetType()
00545     */
00546    bool setDoubleSpinBox(QTreeWidgetItem* pItem, int iColumn, QDoubleSpinBox* pSpin);
00547 
00548    /**
00549     *  Returns the double spin box used as the edit widget for a given cell.
00550     *
00551     *  @param   pItem
00552     *           The item in which to get a cell double spin box edit widget.
00553     *  @param   iColumn
00554     *           The item column in which to get its double spin box edit widget.
00555     *
00556     *  @return  The double spin box edit widget.  A valid item is returned regardless
00557     *           of the current edit widget if a double spin box has been previously
00558     *           set as the edit widget but not reset to \c NULL.
00559     *
00560     *  @see     getSpinBox()
00561     */
00562    QDoubleSpinBox* getDoubleSpinBox(QTreeWidgetItem* pItem, int iColumn) const;
00563 
00564    /**
00565     *  Invokes the edit widget for a given cell.
00566     *
00567     *  This method invokes the edit widget for a given cell.  It does nothing
00568     *  if the cell edit widget type is CustomTreeWidget::NO_WIDGET.
00569     *
00570     *  @param   pItem
00571     *           The item in which to invoke a cell edit widget.
00572     *  @param   iColumn
00573     *           The item column in which to invoke its edit widget.
00574     *
00575     *  @see     CellType
00576     */
00577    void activateCellWidget(QTreeWidgetItem* pItem, int iColumn);
00578 
00579    /**
00580     *  Tests if a given point is contained within a given item cell.
00581     *
00582     *  @param   ptCoord
00583     *           The screen pixel coordinate to test.
00584     *  @param   pItem
00585     *           The item to test for the coordinate.
00586     *  @param   iColumn
00587     *           The item column to test for the coordinate.
00588     *
00589     *  @return  Returns \c true if the given coordinate is contained within the
00590     *           given item cell, otherwise returns \c false.
00591     */
00592    bool hitTest(QPoint ptCoord, QTreeWidgetItem* pItem, int iColumn);
00593 
00594    /**
00595     *  Toggles the display of horizontal or vertical gridlines.
00596     *
00597     *  @param   orientations
00598     *           Indicates whether to show or hide horizontal or vertical
00599     *           gridlines, or both.
00600     *  @param   bShow
00601     *           Set this value to \c true to display the gridlines, or to
00602     *           \c false to hide the gridlines.
00603     */
00604    void setGridlinesShown(Qt::Orientations orientations, bool bShow);
00605 
00606    /**
00607     *  Queries whether gridlines are currently displayed.
00608     *
00609     *  @param   orientation
00610     *           Indicates whether to show or hide either horizontal or vertical
00611     *           gridlines.
00612     *
00613     *  @return  Returns \c true if gridlines are displayed for the given
00614     *           orientation; otherwise returns \c false.
00615     */
00616    bool areGridlinesShown(Qt::Orientation orientation) const;
00617 
00618    /**
00619     *  Performs the keyboard shortcut conversion for the
00620     *  CustomTreeWidget::SHORTCUT_EDIT edit widget type.
00621     *
00622     *  @param   pObject
00623     *           The object prompting the event.
00624     *  @param   pEvent
00625     *           The event invoked by the object.
00626     *
00627     *  @return  Returns \c true if a keyboard shortcut conversion was
00628     *           successfully performed; otherwise returns \c false.
00629     */
00630    bool eventFilter(QObject* pObject, QEvent* pEvent);
00631 
00632 public slots:
00633    /**
00634     *  Closes the active edit widget.
00635     *
00636     *  This method closes the active edit widget if it is currently invoked.
00637     *  It is often useful to call this method if the list view is contained
00638     *  inside a dialog and the user has clicked on the OK or Cancel buttons.
00639     *
00640     *  @param   bAcceptEdit
00641     *           Set this value to \c true to accept any changes the user made
00642     *           in the edit widget before closing.  Set this value to \c false
00643     *           to ignore any user changes.
00644     */
00645    void closeActiveCellWidget(bool bAcceptEdit);
00646 
00647    /**
00648     *  Sets the initial browse directory.
00649     *
00650     *  This method pertains to the initial browse directory when the user
00651     *  clicks on the browse button for the CustomTreeWidget::BROWSE_DIR_EDIT
00652     *  edit widget type.
00653     *
00654     *  @param   strDirectory
00655     *           The directory to set as the initial browse directory.  Set this
00656     *           value to an empty string to use the current working directory.
00657     *
00658     *  @see     setCellWidgetType()
00659     */
00660    void setBrowseDir(const QString& strDirectory);
00661 
00662 signals:
00663    /**
00664     *  This signal is emitted when the text of a cell is changed.
00665     *
00666     *  @param   pItem
00667     *           The item with modified text.
00668     *  @param   iColumn
00669     *           The item column containing the text that has changed.
00670     */
00671    void cellTextChanged(QTreeWidgetItem* pItem, int iColumn);
00672 
00673    /**
00674     *  This signal is emitted when the pixmap of a cell is changed.
00675     *
00676     *  @param   pItem
00677     *           The item with a modified pixmap.
00678     *  @param   iColumn
00679     *           The item column containing the pixmap that has changed.
00680     */
00681    void cellIconChanged(QTreeWidgetItem* pItem, int iColumn);
00682 
00683    /**
00684     *  This signal is emitted when the color of a cell is changed.
00685     *
00686     *  @param   pItem
00687     *           The item with a modified color.
00688     *  @param   iColumn
00689     *           The item column containing the color that has changed.
00690     */
00691    void cellColorChanged(QTreeWidgetItem* pItem, int iColumn);
00692 
00693    /**
00694     *  This signal is emitted when the check box state of a cell is changed.
00695     *
00696     *  @param   pItem
00697     *           The item with a modified check box state.
00698     *  @param   iColumn
00699     *           The item column containing the check box whose state has
00700     *           changed.
00701     */
00702    void cellCheckChanged(QTreeWidgetItem* pItem, int iColumn);
00703 
00704    /**
00705     *  This signal is emitted when the delete key is pressed.
00706     */
00707    void deleteKeyPressed();
00708 
00709 protected:
00710    /**
00711     *  Invokes the cell edit widget.
00712     *
00713     *  This method is called by Qt when the user clicks inside the tree widget
00714     *  area.  If an item cell is clicked and the item is selected, the edit
00715     *  widget is invoked.  If the user clicked on a color pixmap, a common
00716     *  color selected dialog is invoked instead.  If the user clicked on the
00717     *  check box, the check state is toggled.
00718     *
00719     *  @param   e
00720     *           The mouse event associated with the mouse press.
00721     */
00722    void mousePressEvent(QMouseEvent* e);
00723 
00724    /**
00725     *  Invokes the cell edit widget.
00726     *
00727     *  This method is called by Qt when the user double clicks inside the tree
00728     *  widget area.  If the item that is double clicked is not selected, it is
00729     *  selected and the edit widget is invoked by calling mousePressEvent().
00730     *
00731     *  @param   e
00732     *           The mouse event associated with the mouse double click.
00733     */
00734    void mouseDoubleClickEvent(QMouseEvent* e);
00735 
00736    /**
00737     *  Performs common operation in response to key presses.
00738     *
00739     *  This method is called by Qt when the user presses a key on the keyboard.
00740     *  The default behavior is as follows:
00741     *
00742     *  <pre>
00743     *  Key            Behavior
00744     *  =============  =========================================================
00745     *  Delete         Emits the deleteKeyPressed() signal.
00746     *  Esc            Closes the active edit widget and ignores any changes.
00747     *  Return/Enter   Closes the active edit widget and accepts any changes.
00748     *  Down %Arrow     Closes the active edit widget and accepts any changes.
00749     *                 Selects the item below the currently selected item and
00750     *                 activates the edit widget in the same column as the edit
00751     *                 widget that was closed.
00752     *  Up %Arrow       Closes the active edit widget and accepts any changes.
00753     *                 Selects the item above the currently selected item and
00754     *                 activates the edit widget in the same column as the edit
00755     *                 widget that was closed.
00756     *  Page Down      Closes the active edit widget and accepts any changes.
00757     *                 Scrolls the list view to display items below the
00758     *                 previously displayed items.
00759     *  Page Up        Closes the active edit widget and accepts any changes.
00760     *                 Scrolls the list view to display items above the
00761     *                 previously displayed items.
00762     *  </pre>
00763     *
00764     *  @param   e
00765     *           The key event associated with the key press.
00766     *
00767     *  @see     closeActiveCellWidget()
00768     */
00769    void keyPressEvent(QKeyEvent* e);
00770 
00771    /**
00772     *  Returns the index of the column at a given screen x-coordinate.
00773     *
00774     *  @param   iItemX
00775     *           The screen x-coordinate value for which to get the column
00776     *           index.
00777     *
00778     *  @return  The index of the column at the given screen x-coordinate.
00779     */
00780    int getColumnIndex(int iItemX) const;
00781 
00782    /**
00783     *  Returns the bounding rectangle of the given item cell.
00784     *
00785     *  The cell bounding rectangle is a combination of the pixmap rectangle
00786     *  and the edit widget rectangle.
00787     *
00788     *  @param   pItem
00789     *           The item containing the cell for which to get its rectangle.
00790     *  @param   iColumn
00791     *           The item column identifying the cell for which to get its
00792     *           rectangle.
00793     *
00794     *  @return  The cell bounding rectangle.
00795     */
00796    QRect getCellRect(QTreeWidgetItem* pItem, int iColumn) const;
00797 
00798    /**
00799     *  Returns the rectangle of the pixmap in a given item cell.
00800     *
00801     *  @param   pItem
00802     *           The item containing the cell for which to get the pixmap
00803     *           rectangle.
00804     *  @param   iColumn
00805     *           The item column identifying the cell for which to get its
00806     *           pixmap rectangle.
00807     *
00808     *  @return  The pixmap rectangle of the given cell.
00809     */
00810    QRect getCellPixmapRect(QTreeWidgetItem* pItem, int iColumn) const;
00811 
00812    /**
00813     *  Returns the rectangle of the edit widget in a given item cell.
00814     *
00815     *  @param   pItem
00816     *           The item containing the cell for which to get the edit widget
00817     *           rectangle.
00818     *  @param   iColumn
00819     *           The item column identifying the cell for which to get its edit
00820     *           widget rectangle.
00821     *
00822     *  @return  The pixmap rectangle of the given cell.
00823     */
00824    QRect getCellWidgetRect(QTreeWidgetItem* pItem, int iColumn) const;
00825 
00826    /**
00827     *  Draws the gridlines for the row if necessary.
00828     *
00829     *  This method overrides the QTreeWidget base class implementation to draw
00830     *  the gridlines on each cell in the row if necessary.
00831     *
00832     *  @param   pPainter
00833     *           The painter object in which to draw the cell in the row.
00834     *  @param   option
00835     *           The style in which the cell should be drawn.
00836     *  @param   index
00837     *           The index of the cell to draw.
00838     *
00839     *  @see     setGridlinesShown()
00840     */
00841    void drawRow(QPainter* pPainter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
00842 
00843 protected slots:
00844    /**
00845     *  Resizes the edit widget and/or the color pixmap.
00846     *
00847     *  This method is called when the user resizes a column.  The color pixmap
00848     *  is resized if fixed widths are not used.  %Any active edit widget is
00849     *  also resized to fit within the bounding rectangle of the cell.
00850     *
00851     *  @param   iColumn
00852     *           The item column whose width has changed.
00853     *  @param   iOldWidth
00854     *           The previous width of the item column.
00855     *  @param   iNewWidth
00856     *           The new width of the item column.
00857     */
00858    void columnWidthChanged(int iColumn, int iOldWidth, int iNewWidth);
00859 
00860    /**
00861     *  Sets the text of the current cell.
00862     *
00863     *  This method is called when the user accepts changes in the active edit
00864     *  widget.
00865     *
00866     *  @param   strText
00867     *           The new text for the cell.
00868     */
00869    void setCurrentCellText(const QString& strText);
00870 
00871    /**
00872     *  Invokes a directory selection dialog to select a directory.
00873     *
00874     *  This method is called when the user clicks on the browse button from
00875     *  the active edit widget to select a directory.
00876     */
00877    void browse();
00878 
00879    /**
00880     *  Accepts the changes in the active line edit widget.
00881     *
00882     *  This method sets the cell text to the current text in the active line
00883     *  edit widget.
00884     */
00885    void acceptEditText();
00886 
00887    /**
00888     *  Hides the active line edit widget.
00889     *
00890     *  @see     closeActiveCellWidget()
00891     */
00892    void closeEdit();
00893 
00894    /**
00895     *  Accepts the changes in the active custom line edit widget.
00896     *
00897     *  This method sets the cell text to the current text in the active custom
00898     *  line edit widget.
00899     */
00900    void acceptCustomEditText();
00901 
00902    /**
00903     *  Hides the active custom line edit widget.
00904     *
00905     *  @see     closeActiveCellWidget()
00906     */
00907    void closeCustomEdit();
00908 
00909    /**
00910     *  Accepts the changes in the active file browser edit widget.
00911     *
00912     *  This method sets the cell text to the current text in the active file
00913     *  browser edit widget.
00914     */
00915    void acceptFileBrowserText();
00916 
00917    /**
00918     *  Hides the active file browser edit widget.
00919     *
00920     *  @see     closeActiveCellWidget()
00921     */
00922    void closeFileBrowser();
00923 
00924    /**
00925     *  Accepts the changes in the active combo box edit widget.
00926     *
00927     *  This method sets the cell text to the current text in the active combo
00928     *  box edit widget.
00929     */
00930    void acceptComboText();
00931 
00932    /**
00933     *  Hides the active combo box edit widget.
00934     *
00935     *  @see     closeActiveCellWidget()
00936     */
00937    void closeCombo();
00938 
00939    /**
00940     *  Accepts the changes in the active spin box edit widget.
00941     *
00942     *  This method sets the cell text to the current value in the active spin
00943     *  box edit widget.
00944     */
00945    void acceptSpinText();
00946 
00947    /**
00948     *  Hides the active spin box edit widget.
00949     *
00950     *  @see     closeActiveCellWidget()
00951     */
00952    void closeSpin();
00953 
00954    /**
00955     *  Accepts the changes in the active double spin box edit widget.
00956     *
00957     *  This method sets the cell text to the current value in the active double spin
00958     *  box edit widget.
00959     */
00960    void acceptDoubleSpinText();
00961 
00962    /**
00963     *  Hides the active double spin box edit widget.
00964     *
00965     *  @see     closeActiveCellWidget()
00966     */
00967    void closeDoubleSpin();
00968 
00969 private:
00970    CustomTreeWidget(const CustomTreeWidget& rhs);
00971    CustomTreeWidget& operator=(const CustomTreeWidget& rhs);
00972 
00973    class CellLocation
00974    {
00975    public:
00976       CellLocation() :
00977          pItem(NULL),
00978          iColumn(-1)
00979       {
00980       }
00981 
00982       bool operator<(const CellLocation& cell) const
00983       {
00984          if (cell.pItem < pItem)
00985          {
00986             return true;
00987          }
00988          else if (cell.pItem > pItem)
00989          {
00990             return false;
00991          }
00992          else if (cell.iColumn < iColumn)
00993          {
00994             return true;
00995          }
00996 
00997          return false;
00998       };
00999 
01000       QTreeWidgetItem* pItem;
01001       int iColumn;
01002    };
01003 
01004    class CustomTreeWidgetItemDelegate : public QStyledItemDelegate
01005    {
01006    public:
01007       CustomTreeWidgetItemDelegate()
01008       {}
01009 
01010       QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
01011       {
01012          QSize itemSize = QStyledItemDelegate::sizeHint(option, index);
01013          itemSize.setHeight(20);
01014 
01015          return itemSize;
01016       }
01017    private:
01018       CustomTreeWidgetItemDelegate(const CustomTreeWidgetItemDelegate& rhs);
01019       CustomTreeWidgetItemDelegate& operator=(const CustomTreeWidgetItemDelegate& rhs);
01020    };
01021 
01022    bool mbFullColor;
01023    int miColorWidth;
01024    bool mHorizontalGridlines;
01025    bool mVerticalGridlines;
01026 
01027    QLineEdit* mpEdit;
01028    QLineEdit* mpCustomEdit;
01029    FileBrowser* mpFileBrowser;
01030    QPushButton* mpBrowse;
01031    QString mBrowseDir;
01032    QComboBox* mpCombo;
01033    QSpinBox* mpSpin;
01034    QDoubleSpinBox* mpDoubleSpin;
01035    QKeySequence mShortcut;
01036 
01037    QMap<CellLocation, WidgetType> mCellWidgets;
01038    QMap<CellLocation, QLineEdit*> mCustomLineEdits;
01039    QMap<CellLocation, FileBrowser*> mFileBrowsers;
01040    QMap<CellLocation, QComboBox*> mComboBoxes;
01041    QMap<CellLocation, QSpinBox*> mSpinBoxes;
01042    QMap<CellLocation, QDoubleSpinBox*> mDoubleSpinBoxes;
01043    QMap<CellLocation, CheckState> mChecks;
01044    QMap<CellLocation, ColorType> mColors;
01045    QMap<CellLocation, bool> mFullCellEdit;
01046 };
01047 
01048 #endif

Software Development Kit - Opticks 4.9.0 Build 16218