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

Software Development Kit - Opticks 4.9.0 Build 16218