comparison src/squeezedlabel.h @ 523:d869e6a18f63

Make the text labels in the work status area squeezable for small window sizes. Fixes #329
author Chris Cannam
date Tue, 15 Nov 2011 16:02:18 +0000
parents
children 533519ebc0cb
comparison
equal deleted inserted replaced
522:43ddfa5e9fd0 523:d869e6a18f63
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 EasyMercurial
5
6 Based on HgExplorer by Jari Korhonen
7 Copyright (c) 2010 Jari Korhonen
8 Copyright (c) 2011 Chris Cannam
9 Copyright (c) 2011 Queen Mary, University of London
10
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation; either version 2 of the
14 License, or (at your option) any later version. See the file
15 COPYING included with this distribution for more information.
16 */
17
18 /*
19 This file adapted from Rosegarden, a sequencer and musical
20 notation editor. Copyright 2000-2011 the Rosegarden development
21 team.
22
23 Adapted from KDE 4.2.0, this code originally Copyright (c) 2000
24 Ronny Standtke.
25 */
26
27 #ifndef _SQUEEZED_LABEL_H_
28 #define _SQUEEZED_LABEL_H_
29
30 #include <QLabel>
31
32 class SqueezedLabelPrivate;
33
34 /**
35 * @short A replacement for QLabel that squeezes its text
36 *
37 * A label class that squeezes its text into the label
38 *
39 * If the text is too long to fit into the label it is divided into
40 * remaining left and right parts which are separated by three dots.
41 */
42
43 class SqueezedLabel : public QLabel
44 {
45 Q_OBJECT
46 Q_PROPERTY(Qt::TextElideMode textElideMode READ textElideMode WRITE setTextElideMode)
47
48 public:
49 /**
50 * Default constructor.
51 */
52 explicit SqueezedLabel(QWidget *parent = 0);
53 explicit SqueezedLabel(const QString &text, QWidget *parent = 0);
54
55 virtual ~SqueezedLabel();
56
57 virtual QSize minimumSizeHint() const;
58 virtual QSize sizeHint() const;
59 /**
60 * Overridden for internal reasons; the API remains unaffected.
61 */
62 virtual void setAlignment(Qt::Alignment);
63
64 /**
65 * Returns the text elide mode.
66 */
67 Qt::TextElideMode textElideMode() const;
68
69 /**
70 * Sets the text elide mode.
71 * @param mode The text elide mode.
72 */
73 void setTextElideMode(Qt::TextElideMode mode);
74
75 public Q_SLOTS:
76 /**
77 * Sets the text. Note that this is not technically a reimplementation of QLabel::setText(),
78 * which is not virtual (in Qt 4.3). Therefore, you may need to cast the object to
79 * SqueezedLabel in some situations:
80 * \Example
81 * \code
82 * SqueezedLabel* squeezed = new SqueezedLabel("text", parent);
83 * QLabel* label = squeezed;
84 * label->setText("new text"); // this will not work
85 * squeezed->setText("new text"); // works as expected
86 * static_cast<SqueezedLabel*>(label)->setText("new text"); // works as expected
87 * \endcode
88 * @param mode The new text.
89 */
90 void setText(const QString &text);
91 /**
92 * Clears the text. Same remark as above.
93 *
94 */
95 void clear();
96
97 protected:
98 /**
99 * Called when widget is resized
100 */
101 void resizeEvent(QResizeEvent *);
102 /**
103 * \reimp
104 */
105 void contextMenuEvent(QContextMenuEvent*);
106 /**
107 * does the dirty work
108 */
109 void squeezeTextToLabel();
110
111 private slots:
112 void _k_copyFullText();
113
114 private:
115 QString fullText;
116 Qt::TextElideMode elideMode;
117 };
118
119
120 #endif