1 | /** @file
|
---|
2 | *
|
---|
3 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
4 | * VirtualBox Qt extensions: QILabelPrivate class declaration
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2008 Sun Microsystems, Inc.
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | *
|
---|
18 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
19 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
20 | * additional information or have any questions.
|
---|
21 | */
|
---|
22 |
|
---|
23 | /*
|
---|
24 | * This class is based on the original QLabel implementation.
|
---|
25 | */
|
---|
26 |
|
---|
27 | #ifndef __QILabel_p_h__
|
---|
28 | #define __QILabel_p_h__
|
---|
29 |
|
---|
30 | /* Qt includes */
|
---|
31 | #include <QLabel>
|
---|
32 |
|
---|
33 | class QILabelPrivate: public QLabel
|
---|
34 | {
|
---|
35 | Q_OBJECT;
|
---|
36 |
|
---|
37 | public:
|
---|
38 |
|
---|
39 | QILabelPrivate (QWidget *aParent = NULL, Qt::WindowFlags aFlags = 0)
|
---|
40 | : QLabel (aParent, aFlags)
|
---|
41 | {
|
---|
42 | init();
|
---|
43 | }
|
---|
44 |
|
---|
45 | QILabelPrivate (const QString &aText, QWidget *aParent = NULL, Qt::WindowFlags aFlags = 0)
|
---|
46 | : QLabel (aParent, aFlags)
|
---|
47 | {
|
---|
48 | init();
|
---|
49 | setFullText (aText);
|
---|
50 | }
|
---|
51 |
|
---|
52 | void clearAll()
|
---|
53 | {
|
---|
54 | QLabel::clear();
|
---|
55 | setFullText ("");
|
---|
56 | }
|
---|
57 |
|
---|
58 | QString fullText () const
|
---|
59 | {
|
---|
60 | return mText;
|
---|
61 | }
|
---|
62 |
|
---|
63 | void setFullText (const QString &aText)
|
---|
64 | {
|
---|
65 | mText = aText;
|
---|
66 | updateText();
|
---|
67 | }
|
---|
68 |
|
---|
69 | bool fullSizeSelection () const;
|
---|
70 | void setFullSizeSelection (bool bOn);
|
---|
71 |
|
---|
72 | void updateSizeHint()
|
---|
73 | {
|
---|
74 | if (minimumWidth() > 0)
|
---|
75 | mOwnSizeHint = QSize (minimumWidth(),
|
---|
76 | heightForWidth (minimumWidth()));
|
---|
77 | }
|
---|
78 |
|
---|
79 | QSize sizeHint() const
|
---|
80 | {
|
---|
81 | /* If there is an updated sizeHint() present - using it. */
|
---|
82 | return mOwnSizeHint.isValid() ? mOwnSizeHint : QLabel::sizeHint();
|
---|
83 | }
|
---|
84 |
|
---|
85 | protected:
|
---|
86 |
|
---|
87 | void resizeEvent (QResizeEvent *aEvent);
|
---|
88 | void mousePressEvent (QMouseEvent *aEvent);
|
---|
89 | void contextMenuEvent (QContextMenuEvent *aEvent);
|
---|
90 |
|
---|
91 | protected slots:
|
---|
92 |
|
---|
93 | void copy();
|
---|
94 |
|
---|
95 | private:
|
---|
96 |
|
---|
97 | void init();
|
---|
98 |
|
---|
99 | void updateText();
|
---|
100 |
|
---|
101 | QString removeHtmlTags (QString aText) const
|
---|
102 | {
|
---|
103 | /* Remove all HTML tags from the text and return it. */
|
---|
104 | return QString(aText).remove (mCopyRegExp);
|
---|
105 | }
|
---|
106 |
|
---|
107 | Qt::TextElideMode toTextElideMode (const QString& aStr) const
|
---|
108 | {
|
---|
109 | /* Converts a string to a Qt elide mode */
|
---|
110 | Qt::TextElideMode mode = Qt::ElideNone;
|
---|
111 | if (aStr == "start")
|
---|
112 | mode = Qt::ElideLeft;
|
---|
113 | else
|
---|
114 | if (aStr == "middle")
|
---|
115 | mode = Qt::ElideMiddle;
|
---|
116 | else
|
---|
117 | if (aStr == "end")
|
---|
118 | mode = Qt::ElideRight;
|
---|
119 | return mode;
|
---|
120 | }
|
---|
121 |
|
---|
122 |
|
---|
123 | QString compressText (const QString &aText) const;
|
---|
124 |
|
---|
125 | /* Private member vars */
|
---|
126 | QString mText;
|
---|
127 | bool mFullSizeSeclection;
|
---|
128 | static const QRegExp mCopyRegExp;
|
---|
129 | static QRegExp mElideRegExp;
|
---|
130 | QSize mOwnSizeHint;
|
---|
131 | };
|
---|
132 |
|
---|
133 | #endif // __QILabel_p_h__
|
---|
134 |
|
---|