1 | //////////////////////////////////////////////////////////////////////////// |
2 | // // |
3 | // Copyright (C) 2008 Mathias Soeken <msoeken@informatik.uni-bremen.de> // |
4 | // // |
5 | // This program is free software; you can redistribute it and/or // |
6 | // modify it under the terms of the GNU General Public License // |
7 | // as published by the Free Software Foundation; either version 2 // |
8 | // of the License, or (at your option) any later version. // |
9 | // // |
10 | // This program is distributed in the hope that it will be useful, // |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
13 | // GNU General Public License for more details. // |
14 | // // |
15 | // You should have received a copy of the GNU General Public License // |
16 | // along with this program; if not, write to the Free Software // |
17 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA // |
18 | // 02110-1301, USA. // |
19 | //////////////////////////////////////////////////////////////////////////// |
20 | |
21 | #include "qautosizelabel.h" |
22 | |
23 | #include <QFontMetrics> |
24 | |
25 | QAutoSizeLabel::QAutoSizeLabel( QWidget *parent, Qt::WindowFlags f ) |
26 | : QLabel( parent, f ) |
27 | { |
28 | resize(); |
29 | } |
30 | |
31 | QAutoSizeLabel::QAutoSizeLabel( const QString &text, QWidget *parent, Qt::WindowFlags f ) |
32 | : QLabel( text, parent, f ) |
33 | { |
34 | resize(); |
35 | } |
36 | |
37 | QAutoSizeLabel::~QAutoSizeLabel() |
38 | { |
39 | } |
40 | |
41 | void QAutoSizeLabel::setText( const QString &text ) |
42 | { |
43 | QLabel::setText( text ); |
44 | resize(); |
45 | } |
46 | |
47 | void QAutoSizeLabel::resize() |
48 | { |
49 | QFontMetrics fm( font(), this ); |
50 | QLabel::resize( fm.size( Qt::TextSingleLine, text() ) ); |
51 | } |
52 | |
53 | #include "qautosizelabel.moc" |
54 | |