VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/include/QILabel_p.h@ 23588

Last change on this file since 23588 was 16955, checked in by vboxsync, 16 years ago

FE/Qt4: 1 - Update QILabel to support minimum width setter. 2 - Update QILabel to maintain custom minimum size hint policy. These updates are necessary for word-wrapping feature.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.6 KB
Line 
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
33class QAction;
34
35class QILabelPrivate: public QLabel
36{
37 Q_OBJECT;
38
39public:
40
41 QILabelPrivate (QWidget *aParent = NULL, Qt::WindowFlags aFlags = 0)
42 : QLabel (aParent, aFlags)
43 {
44 init();
45 }
46
47 QILabelPrivate (const QString &aText, QWidget *aParent = NULL, Qt::WindowFlags aFlags = 0)
48 : QLabel (aParent, aFlags)
49 {
50 init();
51 setFullText (aText);
52 }
53
54 void clearAll()
55 {
56 QLabel::clear();
57 setFullText ("");
58 }
59
60 QString fullText () const
61 {
62 return mText;
63 }
64
65 void setFullText (const QString &aText)
66 {
67 mText = aText;
68 updateText();
69 }
70
71 bool fullSizeSelection () const;
72 void setFullSizeSelection (bool bOn);
73
74 void updateSizeHint()
75 {
76 if (minimumWidth() > 0)
77 mOwnSizeHint = QSize (minimumWidth(),
78 heightForWidth (minimumWidth()));
79 }
80
81 QSize sizeHint() const
82 {
83 /* If there is an updated sizeHint() present - using it. */
84 return mOwnSizeHint.isValid() ? mOwnSizeHint : QLabel::sizeHint();
85 }
86
87 QSize minimumSizeHint() const
88 {
89 /* If there is an updated minimumSizeHint() present - using it. */
90 return mOwnSizeHint.isValid() ? mOwnSizeHint : QLabel::minimumSizeHint();
91 }
92
93protected:
94
95 void resizeEvent (QResizeEvent *aEvent);
96 void mousePressEvent (QMouseEvent *aEvent);
97 void mouseReleaseEvent (QMouseEvent *aEvent);
98 void mouseMoveEvent (QMouseEvent *aEvent);
99 void contextMenuEvent (QContextMenuEvent *aEvent);
100 void focusInEvent (QFocusEvent *aEvent);
101 void focusOutEvent (QFocusEvent *aEvent);
102 void paintEvent (QPaintEvent *aEvent);
103
104protected slots:
105
106 void copy();
107
108private:
109
110 void init();
111
112 void updateText();
113
114 QString removeHtmlTags (QString aText) const
115 {
116 /* Remove all HTML tags from the text and return it. */
117 return QString(aText).remove (mCopyRegExp);
118 }
119
120 Qt::TextElideMode toTextElideMode (const QString& aStr) const
121 {
122 /* Converts a string to a Qt elide mode */
123 Qt::TextElideMode mode = Qt::ElideNone;
124 if (aStr == "start")
125 mode = Qt::ElideLeft;
126 else
127 if (aStr == "middle")
128 mode = Qt::ElideMiddle;
129 else
130 if (aStr == "end")
131 mode = Qt::ElideRight;
132 return mode;
133 }
134
135
136 QString compressText (const QString &aText) const;
137
138 /* Private member vars */
139 QString mText;
140 bool mFullSizeSeclection;
141 static const QRegExp mCopyRegExp;
142 static QRegExp mElideRegExp;
143 QSize mOwnSizeHint;
144 bool mStartDragging;
145 QAction *mCopyAction;
146};
147
148#endif // __QILabel_p_h__
149
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette