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