1/* This file is part of the KDE libraries
2 Copyright (C) 2000 Ronny Standtke <Ronny.Standtke@gmx.de>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
17*/
18
19#ifndef KSQUEEZEDTEXTLABEL_H
20#define KSQUEEZEDTEXTLABEL_H
21
22#include <kdeui_export.h>
23#include <QtGui/QLabel>
24
25class KSqueezedTextLabelPrivate;
26
27/**
28 * @short A replacement for QLabel that squeezes its text
29 *
30 * A label class that squeezes its text into the label
31 *
32 * If the text is too long to fit into the label it is divided into
33 * remaining left and right parts which are separated by three dots.
34 *
35 * Example:
36 * http://www.kde.org/documentation/index.html could be squeezed to
37 * http://www.kde...ion/index.html
38 *
39 * \image html ksqueezedtextlabel.png "KSqueezedTextLabel Widget"
40 *
41 * @author Ronny Standtke <Ronny.Standtke@gmx.de>
42 */
43
44/*
45 * QLabel
46 */
47class KDEUI_EXPORT KSqueezedTextLabel : public QLabel {
48 Q_OBJECT
49 Q_PROPERTY( Qt::TextElideMode textElideMode READ textElideMode WRITE setTextElideMode )
50
51public:
52 /**
53 * Default constructor.
54 */
55 explicit KSqueezedTextLabel( QWidget *parent = 0 );
56 explicit KSqueezedTextLabel( const QString &text, QWidget *parent = 0 );
57
58 virtual ~KSqueezedTextLabel();
59
60 virtual QSize minimumSizeHint() const;
61 virtual QSize sizeHint() const;
62 /**
63 * Overridden for internal reasons; the API remains unaffected.
64 */
65 virtual void setAlignment( Qt::Alignment );
66
67 /**
68 * Returns the text elide mode.
69 */
70 Qt::TextElideMode textElideMode() const;
71
72 /**
73 * Sets the text elide mode.
74 * @param mode The text elide mode.
75 */
76 void setTextElideMode( Qt::TextElideMode mode );
77
78 /**
79 * Get the full text set via setText.
80 *
81 * @since 4.4
82 */
83 QString fullText() const;
84
85public Q_SLOTS:
86 /**
87 * Sets the text. Note that this is not technically a reimplementation of QLabel::setText(),
88 * which is not virtual (in Qt 4.3). Therefore, you may need to cast the object to
89 * KSqueezedTextLabel in some situations:
90 * \Example
91 * \code
92 * KSqueezedTextLabel* squeezed = new KSqueezedTextLabel("text", parent);
93 * QLabel* label = squeezed;
94 * label->setText("new text"); // this will not work
95 * squeezed->setText("new text"); // works as expected
96 * static_cast<KSqueezedTextLabel*>(label)->setText("new text"); // works as expected
97 * \endcode
98 * @param mode The new text.
99 */
100 void setText( const QString &text );
101 /**
102 * Clears the text. Same remark as above.
103 *
104 */
105 void clear();
106
107protected:
108 /**
109 * \reimp
110 */
111 void mouseReleaseEvent(QMouseEvent*);
112
113 /**
114 * Called when widget is resized
115 */
116 void resizeEvent( QResizeEvent * );
117 /**
118 * \reimp
119 */
120 void contextMenuEvent(QContextMenuEvent* );
121 /**
122 * does the dirty work
123 */
124 void squeezeTextToLabel();
125
126private:
127 Q_PRIVATE_SLOT(d, void _k_copyFullText())
128 KSqueezedTextLabelPrivate * const d;
129};
130
131#endif // KSQUEEZEDTEXTLABEL_H
132