ElidedButton.h

Go to the documentation of this file.
00001 /*
00002  * The information in this file is
00003  * Copyright(c) 2010 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 ELIDEDBUTTON_H
00011 #define ELIDEDBUTTON_H
00012 
00013 #include <QtGui/QPushButton>
00014 
00015 /**
00016  *  A specialized QPushButton that displays an ellipsis when its text is larger
00017  *  than the button width.
00018  *
00019  *  If the text string displayed in the button is longer than the width of the
00020  *  button, an ellipsis is drawn based on the elide mode returned by
00021  *  getElideMode().  To allow the button to resize smaller than the text string,
00022  *  a minimum size must be set (e.g. QWidget::setMimimumWidth()).
00023  *
00024  *  @see        ElidedLabel
00025  */
00026 class ElidedButton : public QPushButton
00027 {
00028    Q_OBJECT
00029 
00030 public:
00031    /**
00032     *  Creates a new elided push button with a default elide mode of
00033     *  Qt::ElideLeft.
00034     *
00035     *  @param   pParent
00036     *           The parent widget.
00037     *
00038     *  @see     setElideMode()
00039     */
00040    ElidedButton(QWidget* pParent = NULL);
00041 
00042    /**
00043     *  Creates a new elided push button with initial text and a default elide
00044     *  mode of Qt::ElideLeft.
00045     *
00046     *  @param   text
00047     *           The text string to display in the button.
00048     *  @param   pParent
00049     *           The parent widget.
00050     *
00051     *  @see     setElideMode()
00052     */
00053    ElidedButton(const QString& text, QWidget* pParent = NULL);
00054 
00055    /**
00056     *  Destroys the push button.
00057     */
00058    virtual ~ElidedButton();
00059 
00060    /**
00061     *  Sets the position in the text of the ellipsis that is drawn when the
00062     *  text is longer the button width.
00063     *
00064     *  @param   mode
00065     *           The new ellipsis position within the text.
00066     */
00067    void setElideMode(Qt::TextElideMode mode);
00068 
00069    /**
00070     *  Returns the position in the text of the ellipsis that is drawn when the
00071     *  text is longer the button width.
00072     *
00073     *  @return  The current ellipsis position within the text.
00074     */
00075    Qt::TextElideMode getElideMode() const;
00076 
00077 protected:
00078    /**
00079     *  Draws the push button and its text.
00080     *
00081     *  The default implementation draws an ellipsis based on the elide mode
00082     *  returned by getElideMode() if the text string is longer than the button
00083     *  width.  Otherwise, the QPushButton base class implementation is called.
00084     *
00085     *  @param   pEvent
00086     *           The paint event.
00087     */
00088    virtual void paintEvent(QPaintEvent* pEvent);
00089 
00090 private:
00091    ElidedButton(const ElidedButton& rhs);
00092    ElidedButton& operator=(const ElidedButton& rhs);
00093    Qt::TextElideMode mElideMode;
00094    QString mPreviousText;
00095    QRect mPreviousRect;
00096    QString mElidedText;
00097 };
00098 
00099 #endif

Software Development Kit - Opticks 4.9.0 Build 16218