CustomColorButton.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 CUSTOMCOLORBUTTON_H
00011 #define CUSTOMCOLORBUTTON_H
00012 
00013 #include "ColorType.h"
00014 
00015 #include <QtGui/QColor>
00016 #include <QtGui/QToolButton>
00017 
00018 class ColorMenu;
00019 
00020 /**
00021  *  A push button to get a selected color from the user.
00022  *
00023  *  The custom color button allows users to select a color and displays a
00024  *  pixmap of the currently selected color.  Optional text can be displayed
00025  *  next to the color using the QPushButton::setText() method.
00026  *
00027  *  When the user clicks the button, a common color dialog is invoked in which
00028  *  the user can select a new color.  By calling usePopupGrid(), this behavior
00029  *  can change to invoke a popup color grid and a Custom menu command.  The
00030  *  user can then select a color from the grid or select the Custom command to
00031  *  invoke the common color dialog.  When a popup color grid is used, a down
00032  *  arrow appears on the right side of the button.
00033  *
00034  *  Regardless of the behavior when the button is clicked, the pixmap
00035  *  automatically updates when a new color is selected.
00036  */
00037 class CustomColorButton : public QToolButton
00038 {
00039    Q_OBJECT
00040 
00041 public:
00042    /**
00043     *  Creates a new color button with no text and a default color of Qt::black.
00044     *
00045     *  @param   parent
00046     *           The parent widget.
00047     */
00048    CustomColorButton(QWidget* parent = 0);
00049 
00050    /**
00051     *  Creates a new color button with text \e strText and a default color of
00052     *  Qt::black.
00053     *
00054     *  @param   strText
00055     *           The text to appear on the button.
00056     *  @param   parent
00057     *           The parent widget.
00058     */
00059    CustomColorButton(const QString& strText, QWidget* parent = 0);
00060 
00061    /**
00062     *  Creates a new color button with text \e strText and color \e color.
00063     *
00064     *  @param   strText
00065     *           The text to appear on the button.
00066     *  @param   color
00067     *           The initial color for the button.
00068     *  @param   parent
00069     *           The parent widget.
00070     */
00071    CustomColorButton(const QString& strText, const QColor& color, QWidget* parent = 0);
00072 
00073    /**
00074     *  Destroys the color button.
00075     */
00076    ~CustomColorButton();
00077 
00078    /**
00079     *  Returns the current button color.
00080     *
00081     *  @return  The button color.
00082     */
00083    QColor getColor() const;
00084 
00085    /**
00086     *  Returns the current button color.
00087     *  Convenience method that converts
00088     *  the QColor back into a ColorType.
00089     *
00090     *  @return  The button color.
00091     */
00092    ColorType getColorType() const;
00093 
00094    /**
00095     *  Queries whether clicking the button invokes a popup color grid.
00096     *
00097     *  @return  Returns \b true if clicking the button invokes a popup color
00098     *           grid. Returns \b false if clicking the button invokes a common
00099     *           color dialog.
00100     */
00101    bool isPopupGridUsed() const;
00102 
00103 public slots:
00104    /**
00105     *  Sets the button color.
00106     *
00107     *  @param   clrNew
00108     *           The new button color.  Must be a valid color.
00109     */
00110    void setColor(const QColor& clrNew);
00111 
00112    /**
00113     *  Sets the button color.  Convenience method
00114     *  that converts the ColorType into a QColor.
00115     *
00116     *  @param   clrNew
00117     *           The new button color.  Must be a valid color.
00118     */
00119    void setColor(const ColorType& clrNew);
00120 
00121    /**
00122     *  Toggles the behavior when the button is clicked.
00123     *
00124     *  @param   bGrid
00125     *           Pass in a value of \b true to invoke a popup color grid when
00126     *           the button is clicked.  Pass in a value of \b false to invoke
00127     *           a common color dialog when the button is clicked.
00128     */
00129    void usePopupGrid(bool bGrid);
00130 
00131 signals:
00132    /**
00133     *  This signal is emitted when the button color changes.
00134     *
00135     *  The color changes when the user selects a new color or when the color is set
00136     *  programmatically.
00137     *
00138     *  @param   clrNew
00139     *           The new button color.
00140     */
00141    void colorChanged(const QColor& clrNew);
00142 
00143 private:
00144    CustomColorButton(const CustomColorButton& rhs);
00145    CustomColorButton& operator=(const CustomColorButton& rhs);
00146    QColor mColor;
00147    ColorMenu* mpMenu;
00148 
00149 private:
00150    void initialize();
00151 
00152 private slots:
00153    void initializeColorMenu();
00154 };
00155 
00156 #endif

Software Development Kit - Opticks 4.9.0 Build 16218