Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qlabel.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||
2 | ** | - | ||||||||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||
5 | ** | - | ||||||||||||||||||
6 | ** This file is part of the QtWidgets module of the Qt Toolkit. | - | ||||||||||||||||||
7 | ** | - | ||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||
16 | ** | - | ||||||||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||
25 | ** | - | ||||||||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||
29 | ** | - | ||||||||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
31 | ** | - | ||||||||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||||||||
33 | - | |||||||||||||||||||
34 | #include "qpainter.h" | - | ||||||||||||||||||
35 | #include "qevent.h" | - | ||||||||||||||||||
36 | #include "qdrawutil.h" | - | ||||||||||||||||||
37 | #include "qapplication.h" | - | ||||||||||||||||||
38 | #include "qabstractbutton.h" | - | ||||||||||||||||||
39 | #include "qstyle.h" | - | ||||||||||||||||||
40 | #include "qstyleoption.h" | - | ||||||||||||||||||
41 | #include <limits.h> | - | ||||||||||||||||||
42 | #include "qaction.h" | - | ||||||||||||||||||
43 | #include "qclipboard.h" | - | ||||||||||||||||||
44 | #include <qdebug.h> | - | ||||||||||||||||||
45 | #include <qurl.h> | - | ||||||||||||||||||
46 | #include "qlabel_p.h" | - | ||||||||||||||||||
47 | #include "private/qstylesheetstyle_p.h" | - | ||||||||||||||||||
48 | #include <qmath.h> | - | ||||||||||||||||||
49 | - | |||||||||||||||||||
50 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||
51 | #include <qaccessible.h> | - | ||||||||||||||||||
52 | #endif | - | ||||||||||||||||||
53 | - | |||||||||||||||||||
54 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
55 | - | |||||||||||||||||||
56 | QLabelPrivate::QLabelPrivate() | - | ||||||||||||||||||
57 | : QFramePrivate(), | - | ||||||||||||||||||
58 | sh(), | - | ||||||||||||||||||
59 | msh(), | - | ||||||||||||||||||
60 | text(), | - | ||||||||||||||||||
61 | pixmap(Q_NULLPTR), | - | ||||||||||||||||||
62 | scaledpixmap(Q_NULLPTR), | - | ||||||||||||||||||
63 | cachedimage(Q_NULLPTR), | - | ||||||||||||||||||
64 | #ifndef QT_NO_PICTURE | - | ||||||||||||||||||
65 | picture(Q_NULLPTR), | - | ||||||||||||||||||
66 | #endif | - | ||||||||||||||||||
67 | #ifndef QT_NO_MOVIE | - | ||||||||||||||||||
68 | movie(), | - | ||||||||||||||||||
69 | #endif | - | ||||||||||||||||||
70 | control(Q_NULLPTR), | - | ||||||||||||||||||
71 | shortcutCursor(), | - | ||||||||||||||||||
72 | #ifndef QT_NO_CURSOR | - | ||||||||||||||||||
73 | cursor(), | - | ||||||||||||||||||
74 | #endif | - | ||||||||||||||||||
75 | #ifndef QT_NO_SHORTCUT | - | ||||||||||||||||||
76 | buddy(), | - | ||||||||||||||||||
77 | shortcutId(0), | - | ||||||||||||||||||
78 | #endif | - | ||||||||||||||||||
79 | textformat(Qt::AutoText), | - | ||||||||||||||||||
80 | textInteractionFlags(Qt::LinksAccessibleByMouse), | - | ||||||||||||||||||
81 | sizePolicy(), | - | ||||||||||||||||||
82 | margin(0), | - | ||||||||||||||||||
83 | align(Qt::AlignLeft | Qt::AlignVCenter | Qt::TextExpandTabs), | - | ||||||||||||||||||
84 | indent(-1), | - | ||||||||||||||||||
85 | valid_hints(false), | - | ||||||||||||||||||
86 | scaledcontents(false), | - | ||||||||||||||||||
87 | textLayoutDirty(false), | - | ||||||||||||||||||
88 | textDirty(false), | - | ||||||||||||||||||
89 | isRichText(false), | - | ||||||||||||||||||
90 | isTextLabel(false), | - | ||||||||||||||||||
91 | hasShortcut(/*???*/), | - | ||||||||||||||||||
92 | #ifndef QT_NO_CURSOR | - | ||||||||||||||||||
93 | validCursor(false), | - | ||||||||||||||||||
94 | onAnchor(false), | - | ||||||||||||||||||
95 | #endif | - | ||||||||||||||||||
96 | openExternalLinks(false) | - | ||||||||||||||||||
97 | { | - | ||||||||||||||||||
98 | } never executed: end of block | 0 | ||||||||||||||||||
99 | - | |||||||||||||||||||
100 | QLabelPrivate::~QLabelPrivate() | - | ||||||||||||||||||
101 | { | - | ||||||||||||||||||
102 | } | - | ||||||||||||||||||
103 | - | |||||||||||||||||||
104 | /*! | - | ||||||||||||||||||
105 | \class QLabel | - | ||||||||||||||||||
106 | \brief The QLabel widget provides a text or image display. | - | ||||||||||||||||||
107 | - | |||||||||||||||||||
108 | \ingroup basicwidgets | - | ||||||||||||||||||
109 | \inmodule QtWidgets | - | ||||||||||||||||||
110 | - | |||||||||||||||||||
111 | QLabel is used for displaying text or an image. No user | - | ||||||||||||||||||
112 | interaction functionality is provided. The visual appearance of | - | ||||||||||||||||||
113 | the label can be configured in various ways, and it can be used | - | ||||||||||||||||||
114 | for specifying a focus mnemonic key for another widget. | - | ||||||||||||||||||
115 | - | |||||||||||||||||||
116 | A QLabel can contain any of the following content types: | - | ||||||||||||||||||
117 | - | |||||||||||||||||||
118 | \table | - | ||||||||||||||||||
119 | \header \li Content \li Setting | - | ||||||||||||||||||
120 | \row \li Plain text | - | ||||||||||||||||||
121 | \li Pass a QString to setText(). | - | ||||||||||||||||||
122 | \row \li Rich text | - | ||||||||||||||||||
123 | \li Pass a QString that contains rich text to setText(). | - | ||||||||||||||||||
124 | \row \li A pixmap | - | ||||||||||||||||||
125 | \li Pass a QPixmap to setPixmap(). | - | ||||||||||||||||||
126 | \row \li A movie | - | ||||||||||||||||||
127 | \li Pass a QMovie to setMovie(). | - | ||||||||||||||||||
128 | \row \li A number | - | ||||||||||||||||||
129 | \li Pass an \e int or a \e double to setNum(), which converts | - | ||||||||||||||||||
130 | the number to plain text. | - | ||||||||||||||||||
131 | \row \li Nothing | - | ||||||||||||||||||
132 | \li The same as an empty plain text. This is the default. Set | - | ||||||||||||||||||
133 | by clear(). | - | ||||||||||||||||||
134 | \endtable | - | ||||||||||||||||||
135 | - | |||||||||||||||||||
136 | \warning When passing a QString to the constructor or calling setText(), | - | ||||||||||||||||||
137 | make sure to sanitize your input, as QLabel tries to guess whether it | - | ||||||||||||||||||
138 | displays the text as plain text or as rich text, a subset of HTML 4 | - | ||||||||||||||||||
139 | markup. You may want to call | - | ||||||||||||||||||
140 | setTextFormat() explicitly, e.g. in case you expect the text to be in | - | ||||||||||||||||||
141 | plain format but cannot control the text source (for instance when | - | ||||||||||||||||||
142 | displaying data loaded from the Web). | - | ||||||||||||||||||
143 | - | |||||||||||||||||||
144 | When the content is changed using any of these functions, any | - | ||||||||||||||||||
145 | previous content is cleared. | - | ||||||||||||||||||
146 | - | |||||||||||||||||||
147 | By default, labels display \l{alignment}{left-aligned, vertically-centered} | - | ||||||||||||||||||
148 | text and images, where any tabs in the text to be displayed are | - | ||||||||||||||||||
149 | \l{Qt::TextExpandTabs}{automatically expanded}. However, the look | - | ||||||||||||||||||
150 | of a QLabel can be adjusted and fine-tuned in several ways. | - | ||||||||||||||||||
151 | - | |||||||||||||||||||
152 | The positioning of the content within the QLabel widget area can | - | ||||||||||||||||||
153 | be tuned with setAlignment() and setIndent(). Text content can | - | ||||||||||||||||||
154 | also wrap lines along word boundaries with setWordWrap(). For | - | ||||||||||||||||||
155 | example, this code sets up a sunken panel with a two-line text in | - | ||||||||||||||||||
156 | the bottom right corner (both lines being flush with the right | - | ||||||||||||||||||
157 | side of the label): | - | ||||||||||||||||||
158 | - | |||||||||||||||||||
159 | \snippet code/src_gui_widgets_qlabel.cpp 0 | - | ||||||||||||||||||
160 | - | |||||||||||||||||||
161 | The properties and functions QLabel inherits from QFrame can also | - | ||||||||||||||||||
162 | be used to specify the widget frame to be used for any given label. | - | ||||||||||||||||||
163 | - | |||||||||||||||||||
164 | A QLabel is often used as a label for an interactive widget. For | - | ||||||||||||||||||
165 | this use QLabel provides a useful mechanism for adding an | - | ||||||||||||||||||
166 | mnemonic (see QKeySequence) that will set the keyboard focus to | - | ||||||||||||||||||
167 | the other widget (called the QLabel's "buddy"). For example: | - | ||||||||||||||||||
168 | - | |||||||||||||||||||
169 | \snippet code/src_gui_widgets_qlabel.cpp 1 | - | ||||||||||||||||||
170 | - | |||||||||||||||||||
171 | In this example, keyboard focus is transferred to the label's | - | ||||||||||||||||||
172 | buddy (the QLineEdit) when the user presses Alt+P. If the buddy | - | ||||||||||||||||||
173 | was a button (inheriting from QAbstractButton), triggering the | - | ||||||||||||||||||
174 | mnemonic would emulate a button click. | - | ||||||||||||||||||
175 | - | |||||||||||||||||||
176 | \table 100% | - | ||||||||||||||||||
177 | \row | - | ||||||||||||||||||
178 | \li \inlineimage macintosh-label.png Screenshot of a Macintosh style label | - | ||||||||||||||||||
179 | \li A label shown in the \l{Macintosh Style Widget Gallery}{Macintosh widget style}. | - | ||||||||||||||||||
180 | \row | - | ||||||||||||||||||
181 | \li \inlineimage fusion-label.png Screenshot of a Fusion style label | - | ||||||||||||||||||
182 | \li A label shown in the \l{Fusion Style Widget Gallery}{Fusion widget style}. | - | ||||||||||||||||||
183 | \row | - | ||||||||||||||||||
184 | \li \inlineimage windowsvista-label.png Screenshot of a Windows Vista style label | - | ||||||||||||||||||
185 | \li A label shown in the \l{Windows Vista Style Widget Gallery}{Windows Vista widget style}. | - | ||||||||||||||||||
186 | \endtable | - | ||||||||||||||||||
187 | - | |||||||||||||||||||
188 | \sa QLineEdit, QTextEdit, QPixmap, QMovie, | - | ||||||||||||||||||
189 | {fowler}{GUI Design Handbook: Label} | - | ||||||||||||||||||
190 | */ | - | ||||||||||||||||||
191 | - | |||||||||||||||||||
192 | #ifndef QT_NO_PICTURE | - | ||||||||||||||||||
193 | /*! | - | ||||||||||||||||||
194 | Returns the label's picture or 0 if the label doesn't have a | - | ||||||||||||||||||
195 | picture. | - | ||||||||||||||||||
196 | */ | - | ||||||||||||||||||
197 | - | |||||||||||||||||||
198 | const QPicture *QLabel::picture() const | - | ||||||||||||||||||
199 | { | - | ||||||||||||||||||
200 | Q_D(const QLabel); | - | ||||||||||||||||||
201 | return d->picture; never executed: return d->picture; | 0 | ||||||||||||||||||
202 | } | - | ||||||||||||||||||
203 | #endif | - | ||||||||||||||||||
204 | - | |||||||||||||||||||
205 | - | |||||||||||||||||||
206 | /*! | - | ||||||||||||||||||
207 | Constructs an empty label. | - | ||||||||||||||||||
208 | - | |||||||||||||||||||
209 | The \a parent and widget flag \a f, arguments are passed | - | ||||||||||||||||||
210 | to the QFrame constructor. | - | ||||||||||||||||||
211 | - | |||||||||||||||||||
212 | \sa setAlignment(), setFrameStyle(), setIndent() | - | ||||||||||||||||||
213 | */ | - | ||||||||||||||||||
214 | QLabel::QLabel(QWidget *parent, Qt::WindowFlags f) | - | ||||||||||||||||||
215 | : QFrame(*new QLabelPrivate(), parent, f) | - | ||||||||||||||||||
216 | { | - | ||||||||||||||||||
217 | Q_D(QLabel); | - | ||||||||||||||||||
218 | d->init(); | - | ||||||||||||||||||
219 | } never executed: end of block | 0 | ||||||||||||||||||
220 | - | |||||||||||||||||||
221 | /*! | - | ||||||||||||||||||
222 | Constructs a label that displays the text, \a text. | - | ||||||||||||||||||
223 | - | |||||||||||||||||||
224 | The \a parent and widget flag \a f, arguments are passed | - | ||||||||||||||||||
225 | to the QFrame constructor. | - | ||||||||||||||||||
226 | - | |||||||||||||||||||
227 | \sa setText(), setAlignment(), setFrameStyle(), setIndent() | - | ||||||||||||||||||
228 | */ | - | ||||||||||||||||||
229 | QLabel::QLabel(const QString &text, QWidget *parent, Qt::WindowFlags f) | - | ||||||||||||||||||
230 | : QFrame(*new QLabelPrivate(), parent, f) | - | ||||||||||||||||||
231 | { | - | ||||||||||||||||||
232 | Q_D(QLabel); | - | ||||||||||||||||||
233 | d->init(); | - | ||||||||||||||||||
234 | setText(text); | - | ||||||||||||||||||
235 | } never executed: end of block | 0 | ||||||||||||||||||
236 | - | |||||||||||||||||||
237 | - | |||||||||||||||||||
238 | - | |||||||||||||||||||
239 | /*! | - | ||||||||||||||||||
240 | Destroys the label. | - | ||||||||||||||||||
241 | */ | - | ||||||||||||||||||
242 | - | |||||||||||||||||||
243 | QLabel::~QLabel() | - | ||||||||||||||||||
244 | { | - | ||||||||||||||||||
245 | Q_D(QLabel); | - | ||||||||||||||||||
246 | d->clearContents(); | - | ||||||||||||||||||
247 | } never executed: end of block | 0 | ||||||||||||||||||
248 | - | |||||||||||||||||||
249 | void QLabelPrivate::init() | - | ||||||||||||||||||
250 | { | - | ||||||||||||||||||
251 | Q_Q(QLabel); | - | ||||||||||||||||||
252 | - | |||||||||||||||||||
253 | q->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred, | - | ||||||||||||||||||
254 | QSizePolicy::Label)); | - | ||||||||||||||||||
255 | setLayoutItemMargins(QStyle::SE_LabelLayoutItem); | - | ||||||||||||||||||
256 | } never executed: end of block | 0 | ||||||||||||||||||
257 | - | |||||||||||||||||||
258 | - | |||||||||||||||||||
259 | /*! | - | ||||||||||||||||||
260 | \property QLabel::text | - | ||||||||||||||||||
261 | \brief the label's text | - | ||||||||||||||||||
262 | - | |||||||||||||||||||
263 | If no text has been set this will return an empty string. Setting | - | ||||||||||||||||||
264 | the text clears any previous content. | - | ||||||||||||||||||
265 | - | |||||||||||||||||||
266 | The text will be interpreted either as plain text or as rich | - | ||||||||||||||||||
267 | text, depending on the text format setting; see setTextFormat(). | - | ||||||||||||||||||
268 | The default setting is Qt::AutoText; i.e. QLabel will try to | - | ||||||||||||||||||
269 | auto-detect the format of the text set. | - | ||||||||||||||||||
270 | See \l {Supported HTML Subset} for the definition of rich text. | - | ||||||||||||||||||
271 | - | |||||||||||||||||||
272 | If a buddy has been set, the buddy mnemonic key is updated | - | ||||||||||||||||||
273 | from the new text. | - | ||||||||||||||||||
274 | - | |||||||||||||||||||
275 | Note that QLabel is well-suited to display small rich text | - | ||||||||||||||||||
276 | documents, such as small documents that get their document | - | ||||||||||||||||||
277 | specific settings (font, text color, link color) from the label's | - | ||||||||||||||||||
278 | palette and font properties. For large documents, use QTextEdit | - | ||||||||||||||||||
279 | in read-only mode instead. QTextEdit can also provide a scroll bar | - | ||||||||||||||||||
280 | when necessary. | - | ||||||||||||||||||
281 | - | |||||||||||||||||||
282 | \note This function enables mouse tracking if \a text contains rich | - | ||||||||||||||||||
283 | text. | - | ||||||||||||||||||
284 | - | |||||||||||||||||||
285 | \sa setTextFormat(), setBuddy(), alignment | - | ||||||||||||||||||
286 | */ | - | ||||||||||||||||||
287 | - | |||||||||||||||||||
288 | void QLabel::setText(const QString &text) | - | ||||||||||||||||||
289 | { | - | ||||||||||||||||||
290 | Q_D(QLabel); | - | ||||||||||||||||||
291 | if (d->text == text)
| 0 | ||||||||||||||||||
292 | return; never executed: return; | 0 | ||||||||||||||||||
293 | - | |||||||||||||||||||
294 | QWidgetTextControl *oldControl = d->control; | - | ||||||||||||||||||
295 | d->control = 0; | - | ||||||||||||||||||
296 | - | |||||||||||||||||||
297 | d->clearContents(); | - | ||||||||||||||||||
298 | d->text = text; | - | ||||||||||||||||||
299 | d->isTextLabel = true; | - | ||||||||||||||||||
300 | d->textDirty = true; | - | ||||||||||||||||||
301 | d->isRichText = d->textformat == Qt::RichText
| 0 | ||||||||||||||||||
302 | || (d->textformat == Qt::AutoText && Qt::mightBeRichText(d->text));
| 0 | ||||||||||||||||||
303 | - | |||||||||||||||||||
304 | d->control = oldControl; | - | ||||||||||||||||||
305 | - | |||||||||||||||||||
306 | if (d->needTextControl()) {
| 0 | ||||||||||||||||||
307 | d->ensureTextControl(); | - | ||||||||||||||||||
308 | } else { never executed: end of block | 0 | ||||||||||||||||||
309 | delete d->control; | - | ||||||||||||||||||
310 | d->control = 0; | - | ||||||||||||||||||
311 | } never executed: end of block | 0 | ||||||||||||||||||
312 | - | |||||||||||||||||||
313 | if (d->isRichText) {
| 0 | ||||||||||||||||||
314 | setMouseTracking(true); | - | ||||||||||||||||||
315 | } else { never executed: end of block | 0 | ||||||||||||||||||
316 | // Note: mouse tracking not disabled intentionally | - | ||||||||||||||||||
317 | } never executed: end of block | 0 | ||||||||||||||||||
318 | - | |||||||||||||||||||
319 | #ifndef QT_NO_SHORTCUT | - | ||||||||||||||||||
320 | if (d->buddy)
| 0 | ||||||||||||||||||
321 | d->updateShortcut(); never executed: d->updateShortcut(); | 0 | ||||||||||||||||||
322 | #endif | - | ||||||||||||||||||
323 | - | |||||||||||||||||||
324 | d->updateLabel(); | - | ||||||||||||||||||
325 | - | |||||||||||||||||||
326 | #ifndef QT_NO_ACCESSIBILITY | - | ||||||||||||||||||
327 | if (accessibleName().isEmpty()) {
| 0 | ||||||||||||||||||
328 | QAccessibleEvent event(this, QAccessible::NameChanged); | - | ||||||||||||||||||
329 | QAccessible::updateAccessibility(&event); | - | ||||||||||||||||||
330 | } never executed: end of block | 0 | ||||||||||||||||||
331 | #endif | - | ||||||||||||||||||
332 | } never executed: end of block | 0 | ||||||||||||||||||
333 | - | |||||||||||||||||||
334 | QString QLabel::text() const | - | ||||||||||||||||||
335 | { | - | ||||||||||||||||||
336 | Q_D(const QLabel); | - | ||||||||||||||||||
337 | return d->text; never executed: return d->text; | 0 | ||||||||||||||||||
338 | } | - | ||||||||||||||||||
339 | - | |||||||||||||||||||
340 | /*! | - | ||||||||||||||||||
341 | Clears any label contents. | - | ||||||||||||||||||
342 | */ | - | ||||||||||||||||||
343 | - | |||||||||||||||||||
344 | void QLabel::clear() | - | ||||||||||||||||||
345 | { | - | ||||||||||||||||||
346 | Q_D(QLabel); | - | ||||||||||||||||||
347 | d->clearContents(); | - | ||||||||||||||||||
348 | d->updateLabel(); | - | ||||||||||||||||||
349 | } never executed: end of block | 0 | ||||||||||||||||||
350 | - | |||||||||||||||||||
351 | /*! | - | ||||||||||||||||||
352 | \property QLabel::pixmap | - | ||||||||||||||||||
353 | \brief the label's pixmap | - | ||||||||||||||||||
354 | - | |||||||||||||||||||
355 | If no pixmap has been set this will return 0. | - | ||||||||||||||||||
356 | - | |||||||||||||||||||
357 | Setting the pixmap clears any previous content. The buddy | - | ||||||||||||||||||
358 | shortcut, if any, is disabled. | - | ||||||||||||||||||
359 | */ | - | ||||||||||||||||||
360 | void QLabel::setPixmap(const QPixmap &pixmap) | - | ||||||||||||||||||
361 | { | - | ||||||||||||||||||
362 | Q_D(QLabel); | - | ||||||||||||||||||
363 | if (!d->pixmap || d->pixmap->cacheKey() != pixmap.cacheKey()) {
| 0 | ||||||||||||||||||
364 | d->clearContents(); | - | ||||||||||||||||||
365 | d->pixmap = new QPixmap(pixmap); | - | ||||||||||||||||||
366 | } never executed: end of block | 0 | ||||||||||||||||||
367 | - | |||||||||||||||||||
368 | if (d->pixmap->depth() == 1 && !d->pixmap->mask())
| 0 | ||||||||||||||||||
369 | d->pixmap->setMask(*((QBitmap *)d->pixmap)); never executed: d->pixmap->setMask(*((QBitmap *)d->pixmap)); | 0 | ||||||||||||||||||
370 | - | |||||||||||||||||||
371 | d->updateLabel(); | - | ||||||||||||||||||
372 | } never executed: end of block | 0 | ||||||||||||||||||
373 | - | |||||||||||||||||||
374 | const QPixmap *QLabel::pixmap() const | - | ||||||||||||||||||
375 | { | - | ||||||||||||||||||
376 | Q_D(const QLabel); | - | ||||||||||||||||||
377 | return d->pixmap; never executed: return d->pixmap; | 0 | ||||||||||||||||||
378 | } | - | ||||||||||||||||||
379 | - | |||||||||||||||||||
380 | #ifndef QT_NO_PICTURE | - | ||||||||||||||||||
381 | /*! | - | ||||||||||||||||||
382 | Sets the label contents to \a picture. Any previous content is | - | ||||||||||||||||||
383 | cleared. | - | ||||||||||||||||||
384 | - | |||||||||||||||||||
385 | The buddy shortcut, if any, is disabled. | - | ||||||||||||||||||
386 | - | |||||||||||||||||||
387 | \sa picture(), setBuddy() | - | ||||||||||||||||||
388 | */ | - | ||||||||||||||||||
389 | - | |||||||||||||||||||
390 | void QLabel::setPicture(const QPicture &picture) | - | ||||||||||||||||||
391 | { | - | ||||||||||||||||||
392 | Q_D(QLabel); | - | ||||||||||||||||||
393 | d->clearContents(); | - | ||||||||||||||||||
394 | d->picture = new QPicture(picture); | - | ||||||||||||||||||
395 | - | |||||||||||||||||||
396 | d->updateLabel(); | - | ||||||||||||||||||
397 | } never executed: end of block | 0 | ||||||||||||||||||
398 | #endif // QT_NO_PICTURE | - | ||||||||||||||||||
399 | - | |||||||||||||||||||
400 | /*! | - | ||||||||||||||||||
401 | Sets the label contents to plain text containing the textual | - | ||||||||||||||||||
402 | representation of integer \a num. Any previous content is cleared. | - | ||||||||||||||||||
403 | Does nothing if the integer's string representation is the same as | - | ||||||||||||||||||
404 | the current contents of the label. | - | ||||||||||||||||||
405 | - | |||||||||||||||||||
406 | The buddy shortcut, if any, is disabled. | - | ||||||||||||||||||
407 | - | |||||||||||||||||||
408 | \sa setText(), QString::setNum(), setBuddy() | - | ||||||||||||||||||
409 | */ | - | ||||||||||||||||||
410 | - | |||||||||||||||||||
411 | void QLabel::setNum(int num) | - | ||||||||||||||||||
412 | { | - | ||||||||||||||||||
413 | QString str; | - | ||||||||||||||||||
414 | str.setNum(num); | - | ||||||||||||||||||
415 | setText(str); | - | ||||||||||||||||||
416 | } never executed: end of block | 0 | ||||||||||||||||||
417 | - | |||||||||||||||||||
418 | /*! | - | ||||||||||||||||||
419 | \overload | - | ||||||||||||||||||
420 | - | |||||||||||||||||||
421 | Sets the label contents to plain text containing the textual | - | ||||||||||||||||||
422 | representation of double \a num. Any previous content is cleared. | - | ||||||||||||||||||
423 | Does nothing if the double's string representation is the same as | - | ||||||||||||||||||
424 | the current contents of the label. | - | ||||||||||||||||||
425 | - | |||||||||||||||||||
426 | The buddy shortcut, if any, is disabled. | - | ||||||||||||||||||
427 | - | |||||||||||||||||||
428 | \sa setText(), QString::setNum(), setBuddy() | - | ||||||||||||||||||
429 | */ | - | ||||||||||||||||||
430 | - | |||||||||||||||||||
431 | void QLabel::setNum(double num) | - | ||||||||||||||||||
432 | { | - | ||||||||||||||||||
433 | QString str; | - | ||||||||||||||||||
434 | str.setNum(num); | - | ||||||||||||||||||
435 | setText(str); | - | ||||||||||||||||||
436 | } never executed: end of block | 0 | ||||||||||||||||||
437 | - | |||||||||||||||||||
438 | /*! | - | ||||||||||||||||||
439 | \property QLabel::alignment | - | ||||||||||||||||||
440 | \brief the alignment of the label's contents | - | ||||||||||||||||||
441 | - | |||||||||||||||||||
442 | By default, the contents of the label are left-aligned and vertically-centered. | - | ||||||||||||||||||
443 | - | |||||||||||||||||||
444 | \sa text | - | ||||||||||||||||||
445 | */ | - | ||||||||||||||||||
446 | - | |||||||||||||||||||
447 | void QLabel::setAlignment(Qt::Alignment alignment) | - | ||||||||||||||||||
448 | { | - | ||||||||||||||||||
449 | Q_D(QLabel); | - | ||||||||||||||||||
450 | if (alignment == (d->align & (Qt::AlignVertical_Mask|Qt::AlignHorizontal_Mask)))
| 0 | ||||||||||||||||||
451 | return; never executed: return; | 0 | ||||||||||||||||||
452 | d->align = (d->align & ~(Qt::AlignVertical_Mask|Qt::AlignHorizontal_Mask)) | - | ||||||||||||||||||
453 | | (alignment & (Qt::AlignVertical_Mask|Qt::AlignHorizontal_Mask)); | - | ||||||||||||||||||
454 | - | |||||||||||||||||||
455 | d->updateLabel(); | - | ||||||||||||||||||
456 | } never executed: end of block | 0 | ||||||||||||||||||
457 | - | |||||||||||||||||||
458 | - | |||||||||||||||||||
459 | Qt::Alignment QLabel::alignment() const | - | ||||||||||||||||||
460 | { | - | ||||||||||||||||||
461 | Q_D(const QLabel); | - | ||||||||||||||||||
462 | return QFlag(d->align & (Qt::AlignVertical_Mask|Qt::AlignHorizontal_Mask)); never executed: return QFlag(d->align & (Qt::AlignVertical_Mask|Qt::AlignHorizontal_Mask)); | 0 | ||||||||||||||||||
463 | } | - | ||||||||||||||||||
464 | - | |||||||||||||||||||
465 | - | |||||||||||||||||||
466 | /*! | - | ||||||||||||||||||
467 | \property QLabel::wordWrap | - | ||||||||||||||||||
468 | \brief the label's word-wrapping policy | - | ||||||||||||||||||
469 | - | |||||||||||||||||||
470 | If this property is \c true then label text is wrapped where | - | ||||||||||||||||||
471 | necessary at word-breaks; otherwise it is not wrapped at all. | - | ||||||||||||||||||
472 | - | |||||||||||||||||||
473 | By default, word wrap is disabled. | - | ||||||||||||||||||
474 | - | |||||||||||||||||||
475 | \sa text | - | ||||||||||||||||||
476 | */ | - | ||||||||||||||||||
477 | void QLabel::setWordWrap(bool on) | - | ||||||||||||||||||
478 | { | - | ||||||||||||||||||
479 | Q_D(QLabel); | - | ||||||||||||||||||
480 | if (on)
| 0 | ||||||||||||||||||
481 | d->align |= Qt::TextWordWrap; never executed: d->align |= Qt::TextWordWrap; | 0 | ||||||||||||||||||
482 | else | - | ||||||||||||||||||
483 | d->align &= ~Qt::TextWordWrap; never executed: d->align &= ~Qt::TextWordWrap; | 0 | ||||||||||||||||||
484 | - | |||||||||||||||||||
485 | d->updateLabel(); | - | ||||||||||||||||||
486 | } never executed: end of block | 0 | ||||||||||||||||||
487 | - | |||||||||||||||||||
488 | bool QLabel::wordWrap() const | - | ||||||||||||||||||
489 | { | - | ||||||||||||||||||
490 | Q_D(const QLabel); | - | ||||||||||||||||||
491 | return d->align & Qt::TextWordWrap; never executed: return d->align & Qt::TextWordWrap; | 0 | ||||||||||||||||||
492 | } | - | ||||||||||||||||||
493 | - | |||||||||||||||||||
494 | /*! | - | ||||||||||||||||||
495 | \property QLabel::indent | - | ||||||||||||||||||
496 | \brief the label's text indent in pixels | - | ||||||||||||||||||
497 | - | |||||||||||||||||||
498 | If a label displays text, the indent applies to the left edge if | - | ||||||||||||||||||
499 | alignment() is Qt::AlignLeft, to the right edge if alignment() is | - | ||||||||||||||||||
500 | Qt::AlignRight, to the top edge if alignment() is Qt::AlignTop, and | - | ||||||||||||||||||
501 | to the bottom edge if alignment() is Qt::AlignBottom. | - | ||||||||||||||||||
502 | - | |||||||||||||||||||
503 | If indent is negative, or if no indent has been set, the label | - | ||||||||||||||||||
504 | computes the effective indent as follows: If frameWidth() is 0, | - | ||||||||||||||||||
505 | the effective indent becomes 0. If frameWidth() is greater than 0, | - | ||||||||||||||||||
506 | the effective indent becomes half the width of the "x" character | - | ||||||||||||||||||
507 | of the widget's current font(). | - | ||||||||||||||||||
508 | - | |||||||||||||||||||
509 | By default, the indent is -1, meaning that an effective indent is | - | ||||||||||||||||||
510 | calculating in the manner described above. | - | ||||||||||||||||||
511 | - | |||||||||||||||||||
512 | \sa alignment, margin, frameWidth(), font() | - | ||||||||||||||||||
513 | */ | - | ||||||||||||||||||
514 | - | |||||||||||||||||||
515 | void QLabel::setIndent(int indent) | - | ||||||||||||||||||
516 | { | - | ||||||||||||||||||
517 | Q_D(QLabel); | - | ||||||||||||||||||
518 | d->indent = indent; | - | ||||||||||||||||||
519 | d->updateLabel(); | - | ||||||||||||||||||
520 | } never executed: end of block | 0 | ||||||||||||||||||
521 | - | |||||||||||||||||||
522 | int QLabel::indent() const | - | ||||||||||||||||||
523 | { | - | ||||||||||||||||||
524 | Q_D(const QLabel); | - | ||||||||||||||||||
525 | return d->indent; never executed: return d->indent; | 0 | ||||||||||||||||||
526 | } | - | ||||||||||||||||||
527 | - | |||||||||||||||||||
528 | - | |||||||||||||||||||
529 | /*! | - | ||||||||||||||||||
530 | \property QLabel::margin | - | ||||||||||||||||||
531 | \brief the width of the margin | - | ||||||||||||||||||
532 | - | |||||||||||||||||||
533 | The margin is the distance between the innermost pixel of the | - | ||||||||||||||||||
534 | frame and the outermost pixel of contents. | - | ||||||||||||||||||
535 | - | |||||||||||||||||||
536 | The default margin is 0. | - | ||||||||||||||||||
537 | - | |||||||||||||||||||
538 | \sa indent | - | ||||||||||||||||||
539 | */ | - | ||||||||||||||||||
540 | int QLabel::margin() const | - | ||||||||||||||||||
541 | { | - | ||||||||||||||||||
542 | Q_D(const QLabel); | - | ||||||||||||||||||
543 | return d->margin; never executed: return d->margin; | 0 | ||||||||||||||||||
544 | } | - | ||||||||||||||||||
545 | - | |||||||||||||||||||
546 | void QLabel::setMargin(int margin) | - | ||||||||||||||||||
547 | { | - | ||||||||||||||||||
548 | Q_D(QLabel); | - | ||||||||||||||||||
549 | if (d->margin == margin)
| 0 | ||||||||||||||||||
550 | return; never executed: return; | 0 | ||||||||||||||||||
551 | d->margin = margin; | - | ||||||||||||||||||
552 | d->updateLabel(); | - | ||||||||||||||||||
553 | } never executed: end of block | 0 | ||||||||||||||||||
554 | - | |||||||||||||||||||
555 | /*! | - | ||||||||||||||||||
556 | Returns the size that will be used if the width of the label is \a | - | ||||||||||||||||||
557 | w. If \a w is -1, the sizeHint() is returned. If \a w is 0 minimumSizeHint() is returned | - | ||||||||||||||||||
558 | */ | - | ||||||||||||||||||
559 | QSize QLabelPrivate::sizeForWidth(int w) const | - | ||||||||||||||||||
560 | { | - | ||||||||||||||||||
561 | Q_Q(const QLabel); | - | ||||||||||||||||||
562 | if(q->minimumWidth() > 0)
| 0 | ||||||||||||||||||
563 | w = qMax(w, q->minimumWidth()); never executed: w = qMax(w, q->minimumWidth()); | 0 | ||||||||||||||||||
564 | QSize contentsMargin(leftmargin + rightmargin, topmargin + bottommargin); | - | ||||||||||||||||||
565 | - | |||||||||||||||||||
566 | QRect br; | - | ||||||||||||||||||
567 | - | |||||||||||||||||||
568 | int hextra = 2 * margin; | - | ||||||||||||||||||
569 | int vextra = hextra; | - | ||||||||||||||||||
570 | QFontMetrics fm = q->fontMetrics(); | - | ||||||||||||||||||
571 | - | |||||||||||||||||||
572 | if (pixmap && !pixmap->isNull()) {
| 0 | ||||||||||||||||||
573 | br = pixmap->rect(); | - | ||||||||||||||||||
574 | br.setSize(br.size() / pixmap->devicePixelRatio()); | - | ||||||||||||||||||
575 | #ifndef QT_NO_PICTURE | - | ||||||||||||||||||
576 | } else if (picture && !picture->isNull()) { never executed: end of block
| 0 | ||||||||||||||||||
577 | br = picture->boundingRect(); | - | ||||||||||||||||||
578 | #endif | - | ||||||||||||||||||
579 | #ifndef QT_NO_MOVIE | - | ||||||||||||||||||
580 | } else if (movie && !movie->currentPixmap().isNull()) { never executed: end of block
| 0 | ||||||||||||||||||
581 | br = movie->currentPixmap().rect(); | - | ||||||||||||||||||
582 | br.setSize(br.size() / movie->currentPixmap().devicePixelRatio()); | - | ||||||||||||||||||
583 | #endif | - | ||||||||||||||||||
584 | } else if (isTextLabel) { never executed: end of block
| 0 | ||||||||||||||||||
585 | int align = QStyle::visualAlignment(textDirection(), QFlag(this->align)); | - | ||||||||||||||||||
586 | // Add indentation | - | ||||||||||||||||||
587 | int m = indent; | - | ||||||||||||||||||
588 | - | |||||||||||||||||||
589 | if (m < 0 && q->frameWidth()) // no indent, but we do have a frame
| 0 | ||||||||||||||||||
590 | m = fm.width(QLatin1Char('x')) - margin*2; never executed: m = fm.width(QLatin1Char('x')) - margin*2; | 0 | ||||||||||||||||||
591 | if (m > 0) {
| 0 | ||||||||||||||||||
592 | if ((align & Qt::AlignLeft) || (align & Qt::AlignRight))
| 0 | ||||||||||||||||||
593 | hextra += m; never executed: hextra += m; | 0 | ||||||||||||||||||
594 | if ((align & Qt::AlignTop) || (align & Qt::AlignBottom))
| 0 | ||||||||||||||||||
595 | vextra += m; never executed: vextra += m; | 0 | ||||||||||||||||||
596 | } never executed: end of block | 0 | ||||||||||||||||||
597 | - | |||||||||||||||||||
598 | if (control) {
| 0 | ||||||||||||||||||
599 | ensureTextLayouted(); | - | ||||||||||||||||||
600 | const qreal oldTextWidth = control->textWidth(); | - | ||||||||||||||||||
601 | // Calculate the length of document if w is the width | - | ||||||||||||||||||
602 | if (align & Qt::TextWordWrap) {
| 0 | ||||||||||||||||||
603 | if (w >= 0) {
| 0 | ||||||||||||||||||
604 | w = qMax(w-hextra-contentsMargin.width(), 0); // strip margin and indent | - | ||||||||||||||||||
605 | control->setTextWidth(w); | - | ||||||||||||||||||
606 | } else { never executed: end of block | 0 | ||||||||||||||||||
607 | control->adjustSize(); | - | ||||||||||||||||||
608 | } never executed: end of block | 0 | ||||||||||||||||||
609 | } else { | - | ||||||||||||||||||
610 | control->setTextWidth(-1); | - | ||||||||||||||||||
611 | } never executed: end of block | 0 | ||||||||||||||||||
612 | - | |||||||||||||||||||
613 | QSizeF controlSize = control->size(); | - | ||||||||||||||||||
614 | br = QRect(QPoint(0, 0), QSize(qCeil(controlSize.width()), qCeil(controlSize.height()))); | - | ||||||||||||||||||
615 | - | |||||||||||||||||||
616 | // restore state | - | ||||||||||||||||||
617 | control->setTextWidth(oldTextWidth); | - | ||||||||||||||||||
618 | } else { never executed: end of block | 0 | ||||||||||||||||||
619 | // Turn off center alignment in order to avoid rounding errors for centering, | - | ||||||||||||||||||
620 | // since centering involves a division by 2. At the end, all we want is the size. | - | ||||||||||||||||||
621 | int flags = align & ~(Qt::AlignVCenter | Qt::AlignHCenter); | - | ||||||||||||||||||
622 | if (hasShortcut) {
| 0 | ||||||||||||||||||
623 | flags |= Qt::TextShowMnemonic; | - | ||||||||||||||||||
624 | QStyleOption opt; | - | ||||||||||||||||||
625 | opt.initFrom(q); | - | ||||||||||||||||||
626 | if (!q->style()->styleHint(QStyle::SH_UnderlineShortcut, &opt, q))
| 0 | ||||||||||||||||||
627 | flags |= Qt::TextHideMnemonic; never executed: flags |= Qt::TextHideMnemonic; | 0 | ||||||||||||||||||
628 | } never executed: end of block | 0 | ||||||||||||||||||
629 | - | |||||||||||||||||||
630 | bool tryWidth = (w < 0) && (align & Qt::TextWordWrap);
| 0 | ||||||||||||||||||
631 | if (tryWidth)
| 0 | ||||||||||||||||||
632 | w = qMin(fm.averageCharWidth() * 80, q->maximumSize().width()); never executed: w = qMin(fm.averageCharWidth() * 80, q->maximumSize().width()); | 0 | ||||||||||||||||||
633 | else if (w < 0)
| 0 | ||||||||||||||||||
634 | w = 2000; never executed: w = 2000; | 0 | ||||||||||||||||||
635 | w -= (hextra + contentsMargin.width()); | - | ||||||||||||||||||
636 | br = fm.boundingRect(0, 0, w ,2000, flags, text); | - | ||||||||||||||||||
637 | if (tryWidth && br.height() < 4*fm.lineSpacing() && br.width() > w/2)
| 0 | ||||||||||||||||||
638 | br = fm.boundingRect(0, 0, w/2, 2000, flags, text); never executed: br = fm.boundingRect(0, 0, w/2, 2000, flags, text); | 0 | ||||||||||||||||||
639 | if (tryWidth && br.height() < 2*fm.lineSpacing() && br.width() > w/4)
| 0 | ||||||||||||||||||
640 | br = fm.boundingRect(0, 0, w/4, 2000, flags, text); never executed: br = fm.boundingRect(0, 0, w/4, 2000, flags, text); | 0 | ||||||||||||||||||
641 | } never executed: end of block | 0 | ||||||||||||||||||
642 | } else { | - | ||||||||||||||||||
643 | br = QRect(QPoint(0, 0), QSize(fm.averageCharWidth(), fm.lineSpacing())); | - | ||||||||||||||||||
644 | } never executed: end of block | 0 | ||||||||||||||||||
645 | - | |||||||||||||||||||
646 | const QSize contentsSize(br.width() + hextra, br.height() + vextra); | - | ||||||||||||||||||
647 | return (contentsSize + contentsMargin).expandedTo(q->minimumSize()); never executed: return (contentsSize + contentsMargin).expandedTo(q->minimumSize()); | 0 | ||||||||||||||||||
648 | } | - | ||||||||||||||||||
649 | - | |||||||||||||||||||
650 | - | |||||||||||||||||||
651 | /*! | - | ||||||||||||||||||
652 | \reimp | - | ||||||||||||||||||
653 | */ | - | ||||||||||||||||||
654 | - | |||||||||||||||||||
655 | int QLabel::heightForWidth(int w) const | - | ||||||||||||||||||
656 | { | - | ||||||||||||||||||
657 | Q_D(const QLabel); | - | ||||||||||||||||||
658 | if (d->isTextLabel)
| 0 | ||||||||||||||||||
659 | return d->sizeForWidth(w).height(); never executed: return d->sizeForWidth(w).height(); | 0 | ||||||||||||||||||
660 | return QWidget::heightForWidth(w); never executed: return QWidget::heightForWidth(w); | 0 | ||||||||||||||||||
661 | } | - | ||||||||||||||||||
662 | - | |||||||||||||||||||
663 | /*! | - | ||||||||||||||||||
664 | \property QLabel::openExternalLinks | - | ||||||||||||||||||
665 | \since 4.2 | - | ||||||||||||||||||
666 | - | |||||||||||||||||||
667 | Specifies whether QLabel should automatically open links using | - | ||||||||||||||||||
668 | QDesktopServices::openUrl() instead of emitting the | - | ||||||||||||||||||
669 | linkActivated() signal. | - | ||||||||||||||||||
670 | - | |||||||||||||||||||
671 | \b{Note:} The textInteractionFlags set on the label need to include | - | ||||||||||||||||||
672 | either LinksAccessibleByMouse or LinksAccessibleByKeyboard. | - | ||||||||||||||||||
673 | - | |||||||||||||||||||
674 | The default value is false. | - | ||||||||||||||||||
675 | - | |||||||||||||||||||
676 | \sa textInteractionFlags() | - | ||||||||||||||||||
677 | */ | - | ||||||||||||||||||
678 | bool QLabel::openExternalLinks() const | - | ||||||||||||||||||
679 | { | - | ||||||||||||||||||
680 | Q_D(const QLabel); | - | ||||||||||||||||||
681 | return d->openExternalLinks; never executed: return d->openExternalLinks; | 0 | ||||||||||||||||||
682 | } | - | ||||||||||||||||||
683 | - | |||||||||||||||||||
684 | void QLabel::setOpenExternalLinks(bool open) | - | ||||||||||||||||||
685 | { | - | ||||||||||||||||||
686 | Q_D(QLabel); | - | ||||||||||||||||||
687 | d->openExternalLinks = open; | - | ||||||||||||||||||
688 | if (d->control)
| 0 | ||||||||||||||||||
689 | d->control->setOpenExternalLinks(open); never executed: d->control->setOpenExternalLinks(open); | 0 | ||||||||||||||||||
690 | } never executed: end of block | 0 | ||||||||||||||||||
691 | - | |||||||||||||||||||
692 | /*! | - | ||||||||||||||||||
693 | \property QLabel::textInteractionFlags | - | ||||||||||||||||||
694 | \since 4.2 | - | ||||||||||||||||||
695 | - | |||||||||||||||||||
696 | Specifies how the label should interact with user input if it displays text. | - | ||||||||||||||||||
697 | - | |||||||||||||||||||
698 | If the flags contain Qt::LinksAccessibleByKeyboard the focus policy is also | - | ||||||||||||||||||
699 | automatically set to Qt::StrongFocus. If Qt::TextSelectableByKeyboard is set | - | ||||||||||||||||||
700 | then the focus policy is set to Qt::ClickFocus. | - | ||||||||||||||||||
701 | - | |||||||||||||||||||
702 | The default value is Qt::LinksAccessibleByMouse. | - | ||||||||||||||||||
703 | */ | - | ||||||||||||||||||
704 | void QLabel::setTextInteractionFlags(Qt::TextInteractionFlags flags) | - | ||||||||||||||||||
705 | { | - | ||||||||||||||||||
706 | Q_D(QLabel); | - | ||||||||||||||||||
707 | if (d->textInteractionFlags == flags)
| 0 | ||||||||||||||||||
708 | return; never executed: return; | 0 | ||||||||||||||||||
709 | d->textInteractionFlags = flags; | - | ||||||||||||||||||
710 | if (flags & Qt::LinksAccessibleByKeyboard)
| 0 | ||||||||||||||||||
711 | setFocusPolicy(Qt::StrongFocus); never executed: setFocusPolicy(Qt::StrongFocus); | 0 | ||||||||||||||||||
712 | else if (flags & (Qt::TextSelectableByKeyboard | Qt::TextSelectableByMouse))
| 0 | ||||||||||||||||||
713 | setFocusPolicy(Qt::ClickFocus); never executed: setFocusPolicy(Qt::ClickFocus); | 0 | ||||||||||||||||||
714 | else | - | ||||||||||||||||||
715 | setFocusPolicy(Qt::NoFocus); never executed: setFocusPolicy(Qt::NoFocus); | 0 | ||||||||||||||||||
716 | - | |||||||||||||||||||
717 | if (d->needTextControl()) {
| 0 | ||||||||||||||||||
718 | d->ensureTextControl(); | - | ||||||||||||||||||
719 | } else { never executed: end of block | 0 | ||||||||||||||||||
720 | delete d->control; | - | ||||||||||||||||||
721 | d->control = 0; | - | ||||||||||||||||||
722 | } never executed: end of block | 0 | ||||||||||||||||||
723 | - | |||||||||||||||||||
724 | if (d->control)
| 0 | ||||||||||||||||||
725 | d->control->setTextInteractionFlags(d->textInteractionFlags); never executed: d->control->setTextInteractionFlags(d->textInteractionFlags); | 0 | ||||||||||||||||||
726 | } never executed: end of block | 0 | ||||||||||||||||||
727 | - | |||||||||||||||||||
728 | Qt::TextInteractionFlags QLabel::textInteractionFlags() const | - | ||||||||||||||||||
729 | { | - | ||||||||||||||||||
730 | Q_D(const QLabel); | - | ||||||||||||||||||
731 | return d->textInteractionFlags; never executed: return d->textInteractionFlags; | 0 | ||||||||||||||||||
732 | } | - | ||||||||||||||||||
733 | - | |||||||||||||||||||
734 | /*! | - | ||||||||||||||||||
735 | Selects text from position \a start and for \a length characters. | - | ||||||||||||||||||
736 | - | |||||||||||||||||||
737 | \sa selectedText() | - | ||||||||||||||||||
738 | - | |||||||||||||||||||
739 | \b{Note:} The textInteractionFlags set on the label need to include | - | ||||||||||||||||||
740 | either TextSelectableByMouse or TextSelectableByKeyboard. | - | ||||||||||||||||||
741 | - | |||||||||||||||||||
742 | \since 4.7 | - | ||||||||||||||||||
743 | */ | - | ||||||||||||||||||
744 | void QLabel::setSelection(int start, int length) | - | ||||||||||||||||||
745 | { | - | ||||||||||||||||||
746 | Q_D(QLabel); | - | ||||||||||||||||||
747 | if (d->control) {
| 0 | ||||||||||||||||||
748 | d->ensureTextPopulated(); | - | ||||||||||||||||||
749 | QTextCursor cursor = d->control->textCursor(); | - | ||||||||||||||||||
750 | cursor.setPosition(start); | - | ||||||||||||||||||
751 | cursor.setPosition(start + length, QTextCursor::KeepAnchor); | - | ||||||||||||||||||
752 | d->control->setTextCursor(cursor); | - | ||||||||||||||||||
753 | } never executed: end of block | 0 | ||||||||||||||||||
754 | } never executed: end of block | 0 | ||||||||||||||||||
755 | - | |||||||||||||||||||
756 | /*! | - | ||||||||||||||||||
757 | \property QLabel::hasSelectedText | - | ||||||||||||||||||
758 | \brief whether there is any text selected | - | ||||||||||||||||||
759 | - | |||||||||||||||||||
760 | hasSelectedText() returns \c true if some or all of the text has been | - | ||||||||||||||||||
761 | selected by the user; otherwise returns \c false. | - | ||||||||||||||||||
762 | - | |||||||||||||||||||
763 | By default, this property is \c false. | - | ||||||||||||||||||
764 | - | |||||||||||||||||||
765 | \sa selectedText() | - | ||||||||||||||||||
766 | - | |||||||||||||||||||
767 | \b{Note:} The textInteractionFlags set on the label need to include | - | ||||||||||||||||||
768 | either TextSelectableByMouse or TextSelectableByKeyboard. | - | ||||||||||||||||||
769 | - | |||||||||||||||||||
770 | \since 4.7 | - | ||||||||||||||||||
771 | */ | - | ||||||||||||||||||
772 | bool QLabel::hasSelectedText() const | - | ||||||||||||||||||
773 | { | - | ||||||||||||||||||
774 | Q_D(const QLabel); | - | ||||||||||||||||||
775 | if (d->control)
| 0 | ||||||||||||||||||
776 | return d->control->textCursor().hasSelection(); never executed: return d->control->textCursor().hasSelection(); | 0 | ||||||||||||||||||
777 | return false; never executed: return false; | 0 | ||||||||||||||||||
778 | } | - | ||||||||||||||||||
779 | - | |||||||||||||||||||
780 | /*! | - | ||||||||||||||||||
781 | \property QLabel::selectedText | - | ||||||||||||||||||
782 | \brief the selected text | - | ||||||||||||||||||
783 | - | |||||||||||||||||||
784 | If there is no selected text this property's value is | - | ||||||||||||||||||
785 | an empty string. | - | ||||||||||||||||||
786 | - | |||||||||||||||||||
787 | By default, this property contains an empty string. | - | ||||||||||||||||||
788 | - | |||||||||||||||||||
789 | \sa hasSelectedText() | - | ||||||||||||||||||
790 | - | |||||||||||||||||||
791 | \b{Note:} The textInteractionFlags set on the label need to include | - | ||||||||||||||||||
792 | either TextSelectableByMouse or TextSelectableByKeyboard. | - | ||||||||||||||||||
793 | - | |||||||||||||||||||
794 | \since 4.7 | - | ||||||||||||||||||
795 | */ | - | ||||||||||||||||||
796 | QString QLabel::selectedText() const | - | ||||||||||||||||||
797 | { | - | ||||||||||||||||||
798 | Q_D(const QLabel); | - | ||||||||||||||||||
799 | if (d->control)
| 0 | ||||||||||||||||||
800 | return d->control->textCursor().selectedText(); never executed: return d->control->textCursor().selectedText(); | 0 | ||||||||||||||||||
801 | return QString(); never executed: return QString(); | 0 | ||||||||||||||||||
802 | } | - | ||||||||||||||||||
803 | - | |||||||||||||||||||
804 | /*! | - | ||||||||||||||||||
805 | selectionStart() returns the index of the first selected character in the | - | ||||||||||||||||||
806 | label or -1 if no text is selected. | - | ||||||||||||||||||
807 | - | |||||||||||||||||||
808 | \sa selectedText() | - | ||||||||||||||||||
809 | - | |||||||||||||||||||
810 | \b{Note:} The textInteractionFlags set on the label need to include | - | ||||||||||||||||||
811 | either TextSelectableByMouse or TextSelectableByKeyboard. | - | ||||||||||||||||||
812 | - | |||||||||||||||||||
813 | \since 4.7 | - | ||||||||||||||||||
814 | */ | - | ||||||||||||||||||
815 | int QLabel::selectionStart() const | - | ||||||||||||||||||
816 | { | - | ||||||||||||||||||
817 | Q_D(const QLabel); | - | ||||||||||||||||||
818 | if (d->control && d->control->textCursor().hasSelection())
| 0 | ||||||||||||||||||
819 | return d->control->textCursor().selectionStart(); never executed: return d->control->textCursor().selectionStart(); | 0 | ||||||||||||||||||
820 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
821 | } | - | ||||||||||||||||||
822 | - | |||||||||||||||||||
823 | /*!\reimp | - | ||||||||||||||||||
824 | */ | - | ||||||||||||||||||
825 | QSize QLabel::sizeHint() const | - | ||||||||||||||||||
826 | { | - | ||||||||||||||||||
827 | Q_D(const QLabel); | - | ||||||||||||||||||
828 | if (!d->valid_hints)
| 0 | ||||||||||||||||||
829 | (void) QLabel::minimumSizeHint(); never executed: (void) QLabel::minimumSizeHint(); | 0 | ||||||||||||||||||
830 | return d->sh; never executed: return d->sh; | 0 | ||||||||||||||||||
831 | } | - | ||||||||||||||||||
832 | - | |||||||||||||||||||
833 | /*! | - | ||||||||||||||||||
834 | \reimp | - | ||||||||||||||||||
835 | */ | - | ||||||||||||||||||
836 | QSize QLabel::minimumSizeHint() const | - | ||||||||||||||||||
837 | { | - | ||||||||||||||||||
838 | Q_D(const QLabel); | - | ||||||||||||||||||
839 | if (d->valid_hints) {
| 0 | ||||||||||||||||||
840 | if (d->sizePolicy == sizePolicy())
| 0 | ||||||||||||||||||
841 | return d->msh; never executed: return d->msh; | 0 | ||||||||||||||||||
842 | } never executed: end of block | 0 | ||||||||||||||||||
843 | - | |||||||||||||||||||
844 | ensurePolished(); | - | ||||||||||||||||||
845 | d->valid_hints = true; | - | ||||||||||||||||||
846 | d->sh = d->sizeForWidth(-1); // wrap ? golden ratio : min doc size | - | ||||||||||||||||||
847 | QSize msh(-1, -1); | - | ||||||||||||||||||
848 | - | |||||||||||||||||||
849 | if (!d->isTextLabel) {
| 0 | ||||||||||||||||||
850 | msh = d->sh; | - | ||||||||||||||||||
851 | } else { never executed: end of block | 0 | ||||||||||||||||||
852 | msh.rheight() = d->sizeForWidth(QWIDGETSIZE_MAX).height(); // height for one line | - | ||||||||||||||||||
853 | msh.rwidth() = d->sizeForWidth(0).width(); // wrap ? size of biggest word : min doc size | - | ||||||||||||||||||
854 | if (d->sh.height() < msh.height())
| 0 | ||||||||||||||||||
855 | msh.rheight() = d->sh.height(); never executed: msh.rheight() = d->sh.height(); | 0 | ||||||||||||||||||
856 | } never executed: end of block | 0 | ||||||||||||||||||
857 | d->msh = msh; | - | ||||||||||||||||||
858 | d->sizePolicy = sizePolicy(); | - | ||||||||||||||||||
859 | return msh; never executed: return msh; | 0 | ||||||||||||||||||
860 | } | - | ||||||||||||||||||
861 | - | |||||||||||||||||||
862 | /*!\reimp | - | ||||||||||||||||||
863 | */ | - | ||||||||||||||||||
864 | void QLabel::mousePressEvent(QMouseEvent *ev) | - | ||||||||||||||||||
865 | { | - | ||||||||||||||||||
866 | Q_D(QLabel); | - | ||||||||||||||||||
867 | d->sendControlEvent(ev); | - | ||||||||||||||||||
868 | } never executed: end of block | 0 | ||||||||||||||||||
869 | - | |||||||||||||||||||
870 | /*!\reimp | - | ||||||||||||||||||
871 | */ | - | ||||||||||||||||||
872 | void QLabel::mouseMoveEvent(QMouseEvent *ev) | - | ||||||||||||||||||
873 | { | - | ||||||||||||||||||
874 | Q_D(QLabel); | - | ||||||||||||||||||
875 | d->sendControlEvent(ev); | - | ||||||||||||||||||
876 | } never executed: end of block | 0 | ||||||||||||||||||
877 | - | |||||||||||||||||||
878 | /*!\reimp | - | ||||||||||||||||||
879 | */ | - | ||||||||||||||||||
880 | void QLabel::mouseReleaseEvent(QMouseEvent *ev) | - | ||||||||||||||||||
881 | { | - | ||||||||||||||||||
882 | Q_D(QLabel); | - | ||||||||||||||||||
883 | d->sendControlEvent(ev); | - | ||||||||||||||||||
884 | } never executed: end of block | 0 | ||||||||||||||||||
885 | - | |||||||||||||||||||
886 | /*!\reimp | - | ||||||||||||||||||
887 | */ | - | ||||||||||||||||||
888 | void QLabel::contextMenuEvent(QContextMenuEvent *ev) | - | ||||||||||||||||||
889 | { | - | ||||||||||||||||||
890 | #ifdef QT_NO_CONTEXTMENU | - | ||||||||||||||||||
891 | Q_UNUSED(ev); | - | ||||||||||||||||||
892 | #else | - | ||||||||||||||||||
893 | Q_D(QLabel); | - | ||||||||||||||||||
894 | if (!d->isTextLabel) {
| 0 | ||||||||||||||||||
895 | ev->ignore(); | - | ||||||||||||||||||
896 | return; never executed: return; | 0 | ||||||||||||||||||
897 | } | - | ||||||||||||||||||
898 | QMenu *menu = d->createStandardContextMenu(ev->pos()); | - | ||||||||||||||||||
899 | if (!menu) {
| 0 | ||||||||||||||||||
900 | ev->ignore(); | - | ||||||||||||||||||
901 | return; never executed: return; | 0 | ||||||||||||||||||
902 | } | - | ||||||||||||||||||
903 | ev->accept(); | - | ||||||||||||||||||
904 | menu->setAttribute(Qt::WA_DeleteOnClose); | - | ||||||||||||||||||
905 | menu->popup(ev->globalPos()); | - | ||||||||||||||||||
906 | #endif | - | ||||||||||||||||||
907 | } never executed: end of block | 0 | ||||||||||||||||||
908 | - | |||||||||||||||||||
909 | /*! | - | ||||||||||||||||||
910 | \reimp | - | ||||||||||||||||||
911 | */ | - | ||||||||||||||||||
912 | void QLabel::focusInEvent(QFocusEvent *ev) | - | ||||||||||||||||||
913 | { | - | ||||||||||||||||||
914 | Q_D(QLabel); | - | ||||||||||||||||||
915 | if (d->isTextLabel) {
| 0 | ||||||||||||||||||
916 | d->ensureTextControl(); | - | ||||||||||||||||||
917 | d->sendControlEvent(ev); | - | ||||||||||||||||||
918 | } never executed: end of block | 0 | ||||||||||||||||||
919 | QFrame::focusInEvent(ev); | - | ||||||||||||||||||
920 | } never executed: end of block | 0 | ||||||||||||||||||
921 | - | |||||||||||||||||||
922 | /*! | - | ||||||||||||||||||
923 | \reimp | - | ||||||||||||||||||
924 | */ | - | ||||||||||||||||||
925 | void QLabel::focusOutEvent(QFocusEvent *ev) | - | ||||||||||||||||||
926 | { | - | ||||||||||||||||||
927 | Q_D(QLabel); | - | ||||||||||||||||||
928 | if (d->control) {
| 0 | ||||||||||||||||||
929 | d->sendControlEvent(ev); | - | ||||||||||||||||||
930 | QTextCursor cursor = d->control->textCursor(); | - | ||||||||||||||||||
931 | Qt::FocusReason reason = ev->reason(); | - | ||||||||||||||||||
932 | if (reason != Qt::ActiveWindowFocusReason
| 0 | ||||||||||||||||||
933 | && reason != Qt::PopupFocusReason
| 0 | ||||||||||||||||||
934 | && cursor.hasSelection()) {
| 0 | ||||||||||||||||||
935 | cursor.clearSelection(); | - | ||||||||||||||||||
936 | d->control->setTextCursor(cursor); | - | ||||||||||||||||||
937 | } never executed: end of block | 0 | ||||||||||||||||||
938 | } never executed: end of block | 0 | ||||||||||||||||||
939 | - | |||||||||||||||||||
940 | QFrame::focusOutEvent(ev); | - | ||||||||||||||||||
941 | } never executed: end of block | 0 | ||||||||||||||||||
942 | - | |||||||||||||||||||
943 | /*!\reimp | - | ||||||||||||||||||
944 | */ | - | ||||||||||||||||||
945 | bool QLabel::focusNextPrevChild(bool next) | - | ||||||||||||||||||
946 | { | - | ||||||||||||||||||
947 | Q_D(QLabel); | - | ||||||||||||||||||
948 | if (d->control && d->control->setFocusToNextOrPreviousAnchor(next))
| 0 | ||||||||||||||||||
949 | return true; never executed: return true; | 0 | ||||||||||||||||||
950 | return QFrame::focusNextPrevChild(next); never executed: return QFrame::focusNextPrevChild(next); | 0 | ||||||||||||||||||
951 | } | - | ||||||||||||||||||
952 | - | |||||||||||||||||||
953 | /*!\reimp | - | ||||||||||||||||||
954 | */ | - | ||||||||||||||||||
955 | void QLabel::keyPressEvent(QKeyEvent *ev) | - | ||||||||||||||||||
956 | { | - | ||||||||||||||||||
957 | Q_D(QLabel); | - | ||||||||||||||||||
958 | d->sendControlEvent(ev); | - | ||||||||||||||||||
959 | } never executed: end of block | 0 | ||||||||||||||||||
960 | - | |||||||||||||||||||
961 | /*!\reimp | - | ||||||||||||||||||
962 | */ | - | ||||||||||||||||||
963 | bool QLabel::event(QEvent *e) | - | ||||||||||||||||||
964 | { | - | ||||||||||||||||||
965 | Q_D(QLabel); | - | ||||||||||||||||||
966 | QEvent::Type type = e->type(); | - | ||||||||||||||||||
967 | - | |||||||||||||||||||
968 | #ifndef QT_NO_SHORTCUT | - | ||||||||||||||||||
969 | if (type == QEvent::Shortcut) {
| 0 | ||||||||||||||||||
970 | QShortcutEvent *se = static_cast<QShortcutEvent *>(e); | - | ||||||||||||||||||
971 | if (se->shortcutId() == d->shortcutId) {
| 0 | ||||||||||||||||||
972 | QWidget * w = d->buddy; | - | ||||||||||||||||||
973 | QAbstractButton *button = qobject_cast<QAbstractButton *>(w); | - | ||||||||||||||||||
974 | if (w->focusPolicy() != Qt::NoFocus)
| 0 | ||||||||||||||||||
975 | w->setFocus(Qt::ShortcutFocusReason); never executed: w->setFocus(Qt::ShortcutFocusReason); | 0 | ||||||||||||||||||
976 | if (button && !se->isAmbiguous())
| 0 | ||||||||||||||||||
977 | button->animateClick(); never executed: button->animateClick(); | 0 | ||||||||||||||||||
978 | else | - | ||||||||||||||||||
979 | window()->setAttribute(Qt::WA_KeyboardFocusChange); never executed: window()->setAttribute(Qt::WA_KeyboardFocusChange); | 0 | ||||||||||||||||||
980 | return true; never executed: return true; | 0 | ||||||||||||||||||
981 | } | - | ||||||||||||||||||
982 | } else never executed: end of block | 0 | ||||||||||||||||||
983 | #endif | - | ||||||||||||||||||
984 | if (type == QEvent::Resize) {
| 0 | ||||||||||||||||||
985 | if (d->control)
| 0 | ||||||||||||||||||
986 | d->textLayoutDirty = true; never executed: d->textLayoutDirty = true; | 0 | ||||||||||||||||||
987 | } else if (e->type() == QEvent::StyleChange never executed: end of block
| 0 | ||||||||||||||||||
988 | #ifdef Q_OS_MAC | - | ||||||||||||||||||
989 | || e->type() == QEvent::MacSizeChange | - | ||||||||||||||||||
990 | #endif | - | ||||||||||||||||||
991 | ) { | - | ||||||||||||||||||
992 | d->setLayoutItemMargins(QStyle::SE_LabelLayoutItem); | - | ||||||||||||||||||
993 | d->updateLabel(); | - | ||||||||||||||||||
994 | } never executed: end of block | 0 | ||||||||||||||||||
995 | - | |||||||||||||||||||
996 | return QFrame::event(e); never executed: return QFrame::event(e); | 0 | ||||||||||||||||||
997 | } | - | ||||||||||||||||||
998 | - | |||||||||||||||||||
999 | /*!\reimp | - | ||||||||||||||||||
1000 | */ | - | ||||||||||||||||||
1001 | void QLabel::paintEvent(QPaintEvent *) | - | ||||||||||||||||||
1002 | { | - | ||||||||||||||||||
1003 | Q_D(QLabel); | - | ||||||||||||||||||
1004 | QStyle *style = QWidget::style(); | - | ||||||||||||||||||
1005 | QPainter painter(this); | - | ||||||||||||||||||
1006 | drawFrame(&painter); | - | ||||||||||||||||||
1007 | QRect cr = contentsRect(); | - | ||||||||||||||||||
1008 | cr.adjust(d->margin, d->margin, -d->margin, -d->margin); | - | ||||||||||||||||||
1009 | int align = QStyle::visualAlignment(d->isTextLabel ? d->textDirection() | - | ||||||||||||||||||
1010 | : layoutDirection(), QFlag(d->align)); | - | ||||||||||||||||||
1011 | - | |||||||||||||||||||
1012 | #ifndef QT_NO_MOVIE | - | ||||||||||||||||||
1013 | if (d->movie) {
| 0 | ||||||||||||||||||
1014 | if (d->scaledcontents)
| 0 | ||||||||||||||||||
1015 | style->drawItemPixmap(&painter, cr, align, d->movie->currentPixmap().scaled(cr.size())); never executed: style->drawItemPixmap(&painter, cr, align, d->movie->currentPixmap().scaled(cr.size())); | 0 | ||||||||||||||||||
1016 | else | - | ||||||||||||||||||
1017 | style->drawItemPixmap(&painter, cr, align, d->movie->currentPixmap()); never executed: style->drawItemPixmap(&painter, cr, align, d->movie->currentPixmap()); | 0 | ||||||||||||||||||
1018 | } | - | ||||||||||||||||||
1019 | else | - | ||||||||||||||||||
1020 | #endif | - | ||||||||||||||||||
1021 | if (d->isTextLabel) {
| 0 | ||||||||||||||||||
1022 | QRectF lr = d->layoutRect().toAlignedRect(); | - | ||||||||||||||||||
1023 | QStyleOption opt; | - | ||||||||||||||||||
1024 | opt.initFrom(this); | - | ||||||||||||||||||
1025 | #ifndef QT_NO_STYLE_STYLESHEET | - | ||||||||||||||||||
1026 | if (QStyleSheetStyle* cssStyle = qobject_cast<QStyleSheetStyle*>(style)) {
| 0 | ||||||||||||||||||
1027 | cssStyle->styleSheetPalette(this, &opt, &opt.palette); | - | ||||||||||||||||||
1028 | } never executed: end of block | 0 | ||||||||||||||||||
1029 | #endif | - | ||||||||||||||||||
1030 | if (d->control) {
| 0 | ||||||||||||||||||
1031 | #ifndef QT_NO_SHORTCUT | - | ||||||||||||||||||
1032 | const bool underline = (bool)style->styleHint(QStyle::SH_UnderlineShortcut, 0, this, 0); | - | ||||||||||||||||||
1033 | if (d->shortcutId != 0
| 0 | ||||||||||||||||||
1034 | && underline != d->shortcutCursor.charFormat().fontUnderline()) {
| 0 | ||||||||||||||||||
1035 | QTextCharFormat fmt; | - | ||||||||||||||||||
1036 | fmt.setFontUnderline(underline); | - | ||||||||||||||||||
1037 | d->shortcutCursor.mergeCharFormat(fmt); | - | ||||||||||||||||||
1038 | } never executed: end of block | 0 | ||||||||||||||||||
1039 | #endif | - | ||||||||||||||||||
1040 | d->ensureTextLayouted(); | - | ||||||||||||||||||
1041 | - | |||||||||||||||||||
1042 | QAbstractTextDocumentLayout::PaintContext context; | - | ||||||||||||||||||
1043 | // Adjust the palette | - | ||||||||||||||||||
1044 | context.palette = opt.palette; | - | ||||||||||||||||||
1045 | - | |||||||||||||||||||
1046 | if (foregroundRole() != QPalette::Text && isEnabled())
| 0 | ||||||||||||||||||
1047 | context.palette.setColor(QPalette::Text, context.palette.color(foregroundRole())); never executed: context.palette.setColor(QPalette::Text, context.palette.color(foregroundRole())); | 0 | ||||||||||||||||||
1048 | - | |||||||||||||||||||
1049 | painter.save(); | - | ||||||||||||||||||
1050 | painter.translate(lr.topLeft()); | - | ||||||||||||||||||
1051 | painter.setClipRect(lr.translated(-lr.x(), -lr.y())); | - | ||||||||||||||||||
1052 | d->control->setPalette(context.palette); | - | ||||||||||||||||||
1053 | d->control->drawContents(&painter, QRectF(), this); | - | ||||||||||||||||||
1054 | painter.restore(); | - | ||||||||||||||||||
1055 | } else { never executed: end of block | 0 | ||||||||||||||||||
1056 | int flags = align | (d->textDirection() == Qt::LeftToRight ? Qt::TextForceLeftToRight | - | ||||||||||||||||||
1057 | : Qt::TextForceRightToLeft); | - | ||||||||||||||||||
1058 | if (d->hasShortcut) {
| 0 | ||||||||||||||||||
1059 | flags |= Qt::TextShowMnemonic; | - | ||||||||||||||||||
1060 | if (!style->styleHint(QStyle::SH_UnderlineShortcut, &opt, this))
| 0 | ||||||||||||||||||
1061 | flags |= Qt::TextHideMnemonic; never executed: flags |= Qt::TextHideMnemonic; | 0 | ||||||||||||||||||
1062 | } never executed: end of block | 0 | ||||||||||||||||||
1063 | style->drawItemText(&painter, lr.toRect(), flags, opt.palette, isEnabled(), d->text, foregroundRole()); | - | ||||||||||||||||||
1064 | } never executed: end of block | 0 | ||||||||||||||||||
1065 | } else | - | ||||||||||||||||||
1066 | #ifndef QT_NO_PICTURE | - | ||||||||||||||||||
1067 | if (d->picture) {
| 0 | ||||||||||||||||||
1068 | QRect br = d->picture->boundingRect(); | - | ||||||||||||||||||
1069 | int rw = br.width(); | - | ||||||||||||||||||
1070 | int rh = br.height(); | - | ||||||||||||||||||
1071 | if (d->scaledcontents) {
| 0 | ||||||||||||||||||
1072 | painter.save(); | - | ||||||||||||||||||
1073 | painter.translate(cr.x(), cr.y()); | - | ||||||||||||||||||
1074 | painter.scale((double)cr.width()/rw, (double)cr.height()/rh); | - | ||||||||||||||||||
1075 | painter.drawPicture(-br.x(), -br.y(), *d->picture); | - | ||||||||||||||||||
1076 | painter.restore(); | - | ||||||||||||||||||
1077 | } else { never executed: end of block | 0 | ||||||||||||||||||
1078 | int xo = 0; | - | ||||||||||||||||||
1079 | int yo = 0; | - | ||||||||||||||||||
1080 | if (align & Qt::AlignVCenter)
| 0 | ||||||||||||||||||
1081 | yo = (cr.height()-rh)/2; never executed: yo = (cr.height()-rh)/2; | 0 | ||||||||||||||||||
1082 | else if (align & Qt::AlignBottom)
| 0 | ||||||||||||||||||
1083 | yo = cr.height()-rh; never executed: yo = cr.height()-rh; | 0 | ||||||||||||||||||
1084 | if (align & Qt::AlignRight)
| 0 | ||||||||||||||||||
1085 | xo = cr.width()-rw; never executed: xo = cr.width()-rw; | 0 | ||||||||||||||||||
1086 | else if (align & Qt::AlignHCenter)
| 0 | ||||||||||||||||||
1087 | xo = (cr.width()-rw)/2; never executed: xo = (cr.width()-rw)/2; | 0 | ||||||||||||||||||
1088 | painter.drawPicture(cr.x()+xo-br.x(), cr.y()+yo-br.y(), *d->picture); | - | ||||||||||||||||||
1089 | } never executed: end of block | 0 | ||||||||||||||||||
1090 | } else | - | ||||||||||||||||||
1091 | #endif | - | ||||||||||||||||||
1092 | if (d->pixmap && !d->pixmap->isNull()) {
| 0 | ||||||||||||||||||
1093 | QPixmap pix; | - | ||||||||||||||||||
1094 | if (d->scaledcontents) {
| 0 | ||||||||||||||||||
1095 | QSize scaledSize = cr.size() * devicePixelRatioF(); | - | ||||||||||||||||||
1096 | if (!d->scaledpixmap || d->scaledpixmap->size() != scaledSize) {
| 0 | ||||||||||||||||||
1097 | if (!d->cachedimage)
| 0 | ||||||||||||||||||
1098 | d->cachedimage = new QImage(d->pixmap->toImage()); never executed: d->cachedimage = new QImage(d->pixmap->toImage()); | 0 | ||||||||||||||||||
1099 | delete d->scaledpixmap; | - | ||||||||||||||||||
1100 | QImage scaledImage = | - | ||||||||||||||||||
1101 | d->cachedimage->scaled(scaledSize, | - | ||||||||||||||||||
1102 | Qt::IgnoreAspectRatio, Qt::SmoothTransformation); | - | ||||||||||||||||||
1103 | d->scaledpixmap = new QPixmap(QPixmap::fromImage(scaledImage)); | - | ||||||||||||||||||
1104 | d->scaledpixmap->setDevicePixelRatio(devicePixelRatioF()); | - | ||||||||||||||||||
1105 | } never executed: end of block | 0 | ||||||||||||||||||
1106 | pix = *d->scaledpixmap; | - | ||||||||||||||||||
1107 | } else never executed: end of block | 0 | ||||||||||||||||||
1108 | pix = *d->pixmap; never executed: pix = *d->pixmap; | 0 | ||||||||||||||||||
1109 | QStyleOption opt; | - | ||||||||||||||||||
1110 | opt.initFrom(this); | - | ||||||||||||||||||
1111 | if (!isEnabled())
| 0 | ||||||||||||||||||
1112 | pix = style->generatedIconPixmap(QIcon::Disabled, pix, &opt); never executed: pix = style->generatedIconPixmap(QIcon::Disabled, pix, &opt); | 0 | ||||||||||||||||||
1113 | style->drawItemPixmap(&painter, cr, align, pix); | - | ||||||||||||||||||
1114 | } never executed: end of block | 0 | ||||||||||||||||||
1115 | } never executed: end of block | 0 | ||||||||||||||||||
1116 | - | |||||||||||||||||||
1117 | - | |||||||||||||||||||
1118 | /*! | - | ||||||||||||||||||
1119 | Updates the label, but not the frame. | - | ||||||||||||||||||
1120 | */ | - | ||||||||||||||||||
1121 | - | |||||||||||||||||||
1122 | void QLabelPrivate::updateLabel() | - | ||||||||||||||||||
1123 | { | - | ||||||||||||||||||
1124 | Q_Q(QLabel); | - | ||||||||||||||||||
1125 | valid_hints = false; | - | ||||||||||||||||||
1126 | - | |||||||||||||||||||
1127 | if (isTextLabel) {
| 0 | ||||||||||||||||||
1128 | QSizePolicy policy = q->sizePolicy(); | - | ||||||||||||||||||
1129 | const bool wrap = align & Qt::TextWordWrap; | - | ||||||||||||||||||
1130 | policy.setHeightForWidth(wrap); | - | ||||||||||||||||||
1131 | if (policy != q->sizePolicy()) // ### should be replaced by WA_WState_OwnSizePolicy idiom
| 0 | ||||||||||||||||||
1132 | q->setSizePolicy(policy); never executed: q->setSizePolicy(policy); | 0 | ||||||||||||||||||
1133 | textLayoutDirty = true; | - | ||||||||||||||||||
1134 | } never executed: end of block | 0 | ||||||||||||||||||
1135 | q->updateGeometry(); | - | ||||||||||||||||||
1136 | q->update(q->contentsRect()); | - | ||||||||||||||||||
1137 | } never executed: end of block | 0 | ||||||||||||||||||
1138 | - | |||||||||||||||||||
1139 | #ifndef QT_NO_SHORTCUT | - | ||||||||||||||||||
1140 | /*! | - | ||||||||||||||||||
1141 | Sets this label's buddy to \a buddy. | - | ||||||||||||||||||
1142 | - | |||||||||||||||||||
1143 | When the user presses the shortcut key indicated by this label, | - | ||||||||||||||||||
1144 | the keyboard focus is transferred to the label's buddy widget. | - | ||||||||||||||||||
1145 | - | |||||||||||||||||||
1146 | The buddy mechanism is only available for QLabels that contain | - | ||||||||||||||||||
1147 | text in which one character is prefixed with an ampersand, '&'. | - | ||||||||||||||||||
1148 | This character is set as the shortcut key. See the \l | - | ||||||||||||||||||
1149 | QKeySequence::mnemonic() documentation for details (to display an | - | ||||||||||||||||||
1150 | actual ampersand, use '&&'). | - | ||||||||||||||||||
1151 | - | |||||||||||||||||||
1152 | In a dialog, you might create two data entry widgets and a label | - | ||||||||||||||||||
1153 | for each, and set up the geometry layout so each label is just to | - | ||||||||||||||||||
1154 | the left of its data entry widget (its "buddy"), for example: | - | ||||||||||||||||||
1155 | \snippet code/src_gui_widgets_qlabel.cpp 2 | - | ||||||||||||||||||
1156 | - | |||||||||||||||||||
1157 | With the code above, the focus jumps to the Name field when the | - | ||||||||||||||||||
1158 | user presses Alt+N, and to the Phone field when the user presses | - | ||||||||||||||||||
1159 | Alt+P. | - | ||||||||||||||||||
1160 | - | |||||||||||||||||||
1161 | To unset a previously set buddy, call this function with \a buddy | - | ||||||||||||||||||
1162 | set to 0. | - | ||||||||||||||||||
1163 | - | |||||||||||||||||||
1164 | \sa buddy(), setText(), QShortcut, setAlignment() | - | ||||||||||||||||||
1165 | */ | - | ||||||||||||||||||
1166 | - | |||||||||||||||||||
1167 | void QLabel::setBuddy(QWidget *buddy) | - | ||||||||||||||||||
1168 | { | - | ||||||||||||||||||
1169 | Q_D(QLabel); | - | ||||||||||||||||||
1170 | d->buddy = buddy; | - | ||||||||||||||||||
1171 | if (d->isTextLabel) {
| 0 | ||||||||||||||||||
1172 | if (d->shortcutId)
| 0 | ||||||||||||||||||
1173 | releaseShortcut(d->shortcutId); never executed: releaseShortcut(d->shortcutId); | 0 | ||||||||||||||||||
1174 | d->shortcutId = 0; | - | ||||||||||||||||||
1175 | d->textDirty = true; | - | ||||||||||||||||||
1176 | if (buddy)
| 0 | ||||||||||||||||||
1177 | d->updateShortcut(); // grab new shortcut never executed: d->updateShortcut(); | 0 | ||||||||||||||||||
1178 | d->updateLabel(); | - | ||||||||||||||||||
1179 | } never executed: end of block | 0 | ||||||||||||||||||
1180 | } never executed: end of block | 0 | ||||||||||||||||||
1181 | - | |||||||||||||||||||
1182 | - | |||||||||||||||||||
1183 | /*! | - | ||||||||||||||||||
1184 | Returns this label's buddy, or 0 if no buddy is currently set. | - | ||||||||||||||||||
1185 | - | |||||||||||||||||||
1186 | \sa setBuddy() | - | ||||||||||||||||||
1187 | */ | - | ||||||||||||||||||
1188 | - | |||||||||||||||||||
1189 | QWidget * QLabel::buddy() const | - | ||||||||||||||||||
1190 | { | - | ||||||||||||||||||
1191 | Q_D(const QLabel); | - | ||||||||||||||||||
1192 | return d->buddy; never executed: return d->buddy; | 0 | ||||||||||||||||||
1193 | } | - | ||||||||||||||||||
1194 | - | |||||||||||||||||||
1195 | void QLabelPrivate::updateShortcut() | - | ||||||||||||||||||
1196 | { | - | ||||||||||||||||||
1197 | Q_Q(QLabel); | - | ||||||||||||||||||
1198 | Q_ASSERT(shortcutId == 0); | - | ||||||||||||||||||
1199 | // Introduce an extra boolean to indicate the presence of a shortcut in the | - | ||||||||||||||||||
1200 | // text. We cannot use the shortcutId itself because on the mac mnemonics are | - | ||||||||||||||||||
1201 | // off by default, so QKeySequence::mnemonic always returns an empty sequence. | - | ||||||||||||||||||
1202 | // But then we do want to hide the ampersands, so we can't use shortcutId. | - | ||||||||||||||||||
1203 | hasShortcut = false; | - | ||||||||||||||||||
1204 | - | |||||||||||||||||||
1205 | if (!text.contains(QLatin1Char('&')))
| 0 | ||||||||||||||||||
1206 | return; never executed: return; | 0 | ||||||||||||||||||
1207 | hasShortcut = true; | - | ||||||||||||||||||
1208 | shortcutId = q->grabShortcut(QKeySequence::mnemonic(text)); | - | ||||||||||||||||||
1209 | } never executed: end of block | 0 | ||||||||||||||||||
1210 | - | |||||||||||||||||||
1211 | #endif // QT_NO_SHORTCUT | - | ||||||||||||||||||
1212 | - | |||||||||||||||||||
1213 | #ifndef QT_NO_MOVIE | - | ||||||||||||||||||
1214 | void QLabelPrivate::_q_movieUpdated(const QRect& rect) | - | ||||||||||||||||||
1215 | { | - | ||||||||||||||||||
1216 | Q_Q(QLabel); | - | ||||||||||||||||||
1217 | if (movie && movie->isValid()) {
| 0 | ||||||||||||||||||
1218 | QRect r; | - | ||||||||||||||||||
1219 | if (scaledcontents) {
| 0 | ||||||||||||||||||
1220 | QRect cr = q->contentsRect(); | - | ||||||||||||||||||
1221 | QRect pixmapRect(cr.topLeft(), movie->currentPixmap().size()); | - | ||||||||||||||||||
1222 | if (pixmapRect.isEmpty())
| 0 | ||||||||||||||||||
1223 | return; never executed: return; | 0 | ||||||||||||||||||
1224 | r.setRect(cr.left(), cr.top(), | - | ||||||||||||||||||
1225 | (rect.width() * cr.width()) / pixmapRect.width(), | - | ||||||||||||||||||
1226 | (rect.height() * cr.height()) / pixmapRect.height()); | - | ||||||||||||||||||
1227 | } else { never executed: end of block | 0 | ||||||||||||||||||
1228 | r = q->style()->itemPixmapRect(q->contentsRect(), align, movie->currentPixmap()); | - | ||||||||||||||||||
1229 | r.translate(rect.x(), rect.y()); | - | ||||||||||||||||||
1230 | r.setWidth(qMin(r.width(), rect.width())); | - | ||||||||||||||||||
1231 | r.setHeight(qMin(r.height(), rect.height())); | - | ||||||||||||||||||
1232 | } never executed: end of block | 0 | ||||||||||||||||||
1233 | q->update(r); | - | ||||||||||||||||||
1234 | } never executed: end of block | 0 | ||||||||||||||||||
1235 | } never executed: end of block | 0 | ||||||||||||||||||
1236 | - | |||||||||||||||||||
1237 | void QLabelPrivate::_q_movieResized(const QSize& size) | - | ||||||||||||||||||
1238 | { | - | ||||||||||||||||||
1239 | Q_Q(QLabel); | - | ||||||||||||||||||
1240 | q->update(); //we need to refresh the whole background in case the new size is smaler | - | ||||||||||||||||||
1241 | valid_hints = false; | - | ||||||||||||||||||
1242 | _q_movieUpdated(QRect(QPoint(0,0), size)); | - | ||||||||||||||||||
1243 | q->updateGeometry(); | - | ||||||||||||||||||
1244 | } never executed: end of block | 0 | ||||||||||||||||||
1245 | - | |||||||||||||||||||
1246 | /*! | - | ||||||||||||||||||
1247 | Sets the label contents to \a movie. Any previous content is | - | ||||||||||||||||||
1248 | cleared. The label does NOT take ownership of the movie. | - | ||||||||||||||||||
1249 | - | |||||||||||||||||||
1250 | The buddy shortcut, if any, is disabled. | - | ||||||||||||||||||
1251 | - | |||||||||||||||||||
1252 | \sa movie(), setBuddy() | - | ||||||||||||||||||
1253 | */ | - | ||||||||||||||||||
1254 | - | |||||||||||||||||||
1255 | void QLabel::setMovie(QMovie *movie) | - | ||||||||||||||||||
1256 | { | - | ||||||||||||||||||
1257 | Q_D(QLabel); | - | ||||||||||||||||||
1258 | d->clearContents(); | - | ||||||||||||||||||
1259 | - | |||||||||||||||||||
1260 | if (!movie)
| 0 | ||||||||||||||||||
1261 | return; never executed: return; | 0 | ||||||||||||||||||
1262 | - | |||||||||||||||||||
1263 | d->movie = movie; | - | ||||||||||||||||||
1264 | connect(movie, SIGNAL(resized(QSize)), this, SLOT(_q_movieResized(QSize))); | - | ||||||||||||||||||
1265 | connect(movie, SIGNAL(updated(QRect)), this, SLOT(_q_movieUpdated(QRect))); | - | ||||||||||||||||||
1266 | - | |||||||||||||||||||
1267 | // Assume that if the movie is running, | - | ||||||||||||||||||
1268 | // resize/update signals will come soon enough | - | ||||||||||||||||||
1269 | if (movie->state() != QMovie::Running)
| 0 | ||||||||||||||||||
1270 | d->updateLabel(); never executed: d->updateLabel(); | 0 | ||||||||||||||||||
1271 | } never executed: end of block | 0 | ||||||||||||||||||
1272 | - | |||||||||||||||||||
1273 | #endif // QT_NO_MOVIE | - | ||||||||||||||||||
1274 | - | |||||||||||||||||||
1275 | /*! | - | ||||||||||||||||||
1276 | \internal | - | ||||||||||||||||||
1277 | - | |||||||||||||||||||
1278 | Clears any contents, without updating/repainting the label. | - | ||||||||||||||||||
1279 | */ | - | ||||||||||||||||||
1280 | - | |||||||||||||||||||
1281 | void QLabelPrivate::clearContents() | - | ||||||||||||||||||
1282 | { | - | ||||||||||||||||||
1283 | delete control; | - | ||||||||||||||||||
1284 | control = 0; | - | ||||||||||||||||||
1285 | isTextLabel = false; | - | ||||||||||||||||||
1286 | hasShortcut = false; | - | ||||||||||||||||||
1287 | - | |||||||||||||||||||
1288 | #ifndef QT_NO_PICTURE | - | ||||||||||||||||||
1289 | delete picture; | - | ||||||||||||||||||
1290 | picture = 0; | - | ||||||||||||||||||
1291 | #endif | - | ||||||||||||||||||
1292 | delete scaledpixmap; | - | ||||||||||||||||||
1293 | scaledpixmap = 0; | - | ||||||||||||||||||
1294 | delete cachedimage; | - | ||||||||||||||||||
1295 | cachedimage = 0; | - | ||||||||||||||||||
1296 | delete pixmap; | - | ||||||||||||||||||
1297 | pixmap = 0; | - | ||||||||||||||||||
1298 | - | |||||||||||||||||||
1299 | text.clear(); | - | ||||||||||||||||||
1300 | Q_Q(QLabel); | - | ||||||||||||||||||
1301 | #ifndef QT_NO_SHORTCUT | - | ||||||||||||||||||
1302 | if (shortcutId)
| 0 | ||||||||||||||||||
1303 | q->releaseShortcut(shortcutId); never executed: q->releaseShortcut(shortcutId); | 0 | ||||||||||||||||||
1304 | shortcutId = 0; | - | ||||||||||||||||||
1305 | #endif | - | ||||||||||||||||||
1306 | #ifndef QT_NO_MOVIE | - | ||||||||||||||||||
1307 | if (movie) {
| 0 | ||||||||||||||||||
1308 | QObject::disconnect(movie, SIGNAL(resized(QSize)), q, SLOT(_q_movieResized(QSize))); | - | ||||||||||||||||||
1309 | QObject::disconnect(movie, SIGNAL(updated(QRect)), q, SLOT(_q_movieUpdated(QRect))); | - | ||||||||||||||||||
1310 | } never executed: end of block | 0 | ||||||||||||||||||
1311 | movie = 0; | - | ||||||||||||||||||
1312 | #endif | - | ||||||||||||||||||
1313 | #ifndef QT_NO_CURSOR | - | ||||||||||||||||||
1314 | if (onAnchor) {
| 0 | ||||||||||||||||||
1315 | if (validCursor)
| 0 | ||||||||||||||||||
1316 | q->setCursor(cursor); never executed: q->setCursor(cursor); | 0 | ||||||||||||||||||
1317 | else | - | ||||||||||||||||||
1318 | q->unsetCursor(); never executed: q->unsetCursor(); | 0 | ||||||||||||||||||
1319 | } | - | ||||||||||||||||||
1320 | validCursor = false; | - | ||||||||||||||||||
1321 | onAnchor = false; | - | ||||||||||||||||||
1322 | #endif | - | ||||||||||||||||||
1323 | } never executed: end of block | 0 | ||||||||||||||||||
1324 | - | |||||||||||||||||||
1325 | - | |||||||||||||||||||
1326 | #ifndef QT_NO_MOVIE | - | ||||||||||||||||||
1327 | - | |||||||||||||||||||
1328 | /*! | - | ||||||||||||||||||
1329 | Returns a pointer to the label's movie, or 0 if no movie has been | - | ||||||||||||||||||
1330 | set. | - | ||||||||||||||||||
1331 | - | |||||||||||||||||||
1332 | \sa setMovie() | - | ||||||||||||||||||
1333 | */ | - | ||||||||||||||||||
1334 | - | |||||||||||||||||||
1335 | QMovie *QLabel::movie() const | - | ||||||||||||||||||
1336 | { | - | ||||||||||||||||||
1337 | Q_D(const QLabel); | - | ||||||||||||||||||
1338 | return d->movie; never executed: return d->movie; | 0 | ||||||||||||||||||
1339 | } | - | ||||||||||||||||||
1340 | - | |||||||||||||||||||
1341 | #endif // QT_NO_MOVIE | - | ||||||||||||||||||
1342 | - | |||||||||||||||||||
1343 | /*! | - | ||||||||||||||||||
1344 | \property QLabel::textFormat | - | ||||||||||||||||||
1345 | \brief the label's text format | - | ||||||||||||||||||
1346 | - | |||||||||||||||||||
1347 | See the Qt::TextFormat enum for an explanation of the possible | - | ||||||||||||||||||
1348 | options. | - | ||||||||||||||||||
1349 | - | |||||||||||||||||||
1350 | The default format is Qt::AutoText. | - | ||||||||||||||||||
1351 | - | |||||||||||||||||||
1352 | \sa text() | - | ||||||||||||||||||
1353 | */ | - | ||||||||||||||||||
1354 | - | |||||||||||||||||||
1355 | Qt::TextFormat QLabel::textFormat() const | - | ||||||||||||||||||
1356 | { | - | ||||||||||||||||||
1357 | Q_D(const QLabel); | - | ||||||||||||||||||
1358 | return d->textformat; never executed: return d->textformat; | 0 | ||||||||||||||||||
1359 | } | - | ||||||||||||||||||
1360 | - | |||||||||||||||||||
1361 | void QLabel::setTextFormat(Qt::TextFormat format) | - | ||||||||||||||||||
1362 | { | - | ||||||||||||||||||
1363 | Q_D(QLabel); | - | ||||||||||||||||||
1364 | if (format != d->textformat) {
| 0 | ||||||||||||||||||
1365 | d->textformat = format; | - | ||||||||||||||||||
1366 | QString t = d->text; | - | ||||||||||||||||||
1367 | if (!t.isNull()) {
| 0 | ||||||||||||||||||
1368 | d->text.clear(); | - | ||||||||||||||||||
1369 | setText(t); | - | ||||||||||||||||||
1370 | } never executed: end of block | 0 | ||||||||||||||||||
1371 | } never executed: end of block | 0 | ||||||||||||||||||
1372 | } never executed: end of block | 0 | ||||||||||||||||||
1373 | - | |||||||||||||||||||
1374 | /*! | - | ||||||||||||||||||
1375 | \reimp | - | ||||||||||||||||||
1376 | */ | - | ||||||||||||||||||
1377 | void QLabel::changeEvent(QEvent *ev) | - | ||||||||||||||||||
1378 | { | - | ||||||||||||||||||
1379 | Q_D(QLabel); | - | ||||||||||||||||||
1380 | if(ev->type() == QEvent::FontChange || ev->type() == QEvent::ApplicationFontChange) {
| 0 | ||||||||||||||||||
1381 | if (d->isTextLabel) {
| 0 | ||||||||||||||||||
1382 | if (d->control)
| 0 | ||||||||||||||||||
1383 | d->control->document()->setDefaultFont(font()); never executed: d->control->document()->setDefaultFont(font()); | 0 | ||||||||||||||||||
1384 | d->updateLabel(); | - | ||||||||||||||||||
1385 | } never executed: end of block | 0 | ||||||||||||||||||
1386 | } else if (ev->type() == QEvent::PaletteChange && d->control) { never executed: end of block
| 0 | ||||||||||||||||||
1387 | d->control->setPalette(palette()); | - | ||||||||||||||||||
1388 | } else if (ev->type() == QEvent::ContentsRectChange) { never executed: end of block
| 0 | ||||||||||||||||||
1389 | d->updateLabel(); | - | ||||||||||||||||||
1390 | } never executed: end of block | 0 | ||||||||||||||||||
1391 | QFrame::changeEvent(ev); | - | ||||||||||||||||||
1392 | } never executed: end of block | 0 | ||||||||||||||||||
1393 | - | |||||||||||||||||||
1394 | /*! | - | ||||||||||||||||||
1395 | \property QLabel::scaledContents | - | ||||||||||||||||||
1396 | \brief whether the label will scale its contents to fill all | - | ||||||||||||||||||
1397 | available space. | - | ||||||||||||||||||
1398 | - | |||||||||||||||||||
1399 | When enabled and the label shows a pixmap, it will scale the | - | ||||||||||||||||||
1400 | pixmap to fill the available space. | - | ||||||||||||||||||
1401 | - | |||||||||||||||||||
1402 | This property's default is false. | - | ||||||||||||||||||
1403 | */ | - | ||||||||||||||||||
1404 | bool QLabel::hasScaledContents() const | - | ||||||||||||||||||
1405 | { | - | ||||||||||||||||||
1406 | Q_D(const QLabel); | - | ||||||||||||||||||
1407 | return d->scaledcontents; never executed: return d->scaledcontents; | 0 | ||||||||||||||||||
1408 | } | - | ||||||||||||||||||
1409 | - | |||||||||||||||||||
1410 | void QLabel::setScaledContents(bool enable) | - | ||||||||||||||||||
1411 | { | - | ||||||||||||||||||
1412 | Q_D(QLabel); | - | ||||||||||||||||||
1413 | if ((bool)d->scaledcontents == enable)
| 0 | ||||||||||||||||||
1414 | return; never executed: return; | 0 | ||||||||||||||||||
1415 | d->scaledcontents = enable; | - | ||||||||||||||||||
1416 | if (!enable) {
| 0 | ||||||||||||||||||
1417 | delete d->scaledpixmap; | - | ||||||||||||||||||
1418 | d->scaledpixmap = 0; | - | ||||||||||||||||||
1419 | delete d->cachedimage; | - | ||||||||||||||||||
1420 | d->cachedimage = 0; | - | ||||||||||||||||||
1421 | } never executed: end of block | 0 | ||||||||||||||||||
1422 | update(contentsRect()); | - | ||||||||||||||||||
1423 | } never executed: end of block | 0 | ||||||||||||||||||
1424 | - | |||||||||||||||||||
1425 | Qt::LayoutDirection QLabelPrivate::textDirection() const | - | ||||||||||||||||||
1426 | { | - | ||||||||||||||||||
1427 | if (control) {
| 0 | ||||||||||||||||||
1428 | QTextOption opt = control->document()->defaultTextOption(); | - | ||||||||||||||||||
1429 | return opt.textDirection(); never executed: return opt.textDirection(); | 0 | ||||||||||||||||||
1430 | } | - | ||||||||||||||||||
1431 | - | |||||||||||||||||||
1432 | return text.isRightToLeft() ? Qt::RightToLeft : Qt::LeftToRight; never executed: return text.isRightToLeft() ? Qt::RightToLeft : Qt::LeftToRight;
| 0 | ||||||||||||||||||
1433 | } | - | ||||||||||||||||||
1434 | - | |||||||||||||||||||
1435 | - | |||||||||||||||||||
1436 | // Returns the rect that is available for us to draw the document | - | ||||||||||||||||||
1437 | QRect QLabelPrivate::documentRect() const | - | ||||||||||||||||||
1438 | { | - | ||||||||||||||||||
1439 | Q_Q(const QLabel); | - | ||||||||||||||||||
1440 | Q_ASSERT_X(isTextLabel, "documentRect", "document rect called for label that is not a text label!"); | - | ||||||||||||||||||
1441 | QRect cr = q->contentsRect(); | - | ||||||||||||||||||
1442 | cr.adjust(margin, margin, -margin, -margin); | - | ||||||||||||||||||
1443 | const int align = QStyle::visualAlignment(isTextLabel ? textDirection() | - | ||||||||||||||||||
1444 | : q->layoutDirection(), QFlag(this->align)); | - | ||||||||||||||||||
1445 | int m = indent; | - | ||||||||||||||||||
1446 | if (m < 0 && q->frameWidth()) // no indent, but we do have a frame
| 0 | ||||||||||||||||||
1447 | m = q->fontMetrics().width(QLatin1Char('x')) / 2 - margin; never executed: m = q->fontMetrics().width(QLatin1Char('x')) / 2 - margin; | 0 | ||||||||||||||||||
1448 | if (m > 0) {
| 0 | ||||||||||||||||||
1449 | if (align & Qt::AlignLeft)
| 0 | ||||||||||||||||||
1450 | cr.setLeft(cr.left() + m); never executed: cr.setLeft(cr.left() + m); | 0 | ||||||||||||||||||
1451 | if (align & Qt::AlignRight)
| 0 | ||||||||||||||||||
1452 | cr.setRight(cr.right() - m); never executed: cr.setRight(cr.right() - m); | 0 | ||||||||||||||||||
1453 | if (align & Qt::AlignTop)
| 0 | ||||||||||||||||||
1454 | cr.setTop(cr.top() + m); never executed: cr.setTop(cr.top() + m); | 0 | ||||||||||||||||||
1455 | if (align & Qt::AlignBottom)
| 0 | ||||||||||||||||||
1456 | cr.setBottom(cr.bottom() - m); never executed: cr.setBottom(cr.bottom() - m); | 0 | ||||||||||||||||||
1457 | } never executed: end of block | 0 | ||||||||||||||||||
1458 | return cr; never executed: return cr; | 0 | ||||||||||||||||||
1459 | } | - | ||||||||||||||||||
1460 | - | |||||||||||||||||||
1461 | void QLabelPrivate::ensureTextPopulated() const | - | ||||||||||||||||||
1462 | { | - | ||||||||||||||||||
1463 | if (!textDirty)
| 0 | ||||||||||||||||||
1464 | return; never executed: return; | 0 | ||||||||||||||||||
1465 | if (control) {
| 0 | ||||||||||||||||||
1466 | QTextDocument *doc = control->document(); | - | ||||||||||||||||||
1467 | if (textDirty) {
| 0 | ||||||||||||||||||
1468 | #ifndef QT_NO_TEXTHTMLPARSER | - | ||||||||||||||||||
1469 | if (isRichText)
| 0 | ||||||||||||||||||
1470 | doc->setHtml(text); never executed: doc->setHtml(text); | 0 | ||||||||||||||||||
1471 | else | - | ||||||||||||||||||
1472 | doc->setPlainText(text); never executed: doc->setPlainText(text); | 0 | ||||||||||||||||||
1473 | #else | - | ||||||||||||||||||
1474 | doc->setPlainText(text); | - | ||||||||||||||||||
1475 | #endif | - | ||||||||||||||||||
1476 | doc->setUndoRedoEnabled(false); | - | ||||||||||||||||||
1477 | - | |||||||||||||||||||
1478 | #ifndef QT_NO_SHORTCUT | - | ||||||||||||||||||
1479 | if (hasShortcut) {
| 0 | ||||||||||||||||||
1480 | // Underline the first character that follows an ampersand (and remove the others ampersands) | - | ||||||||||||||||||
1481 | int from = 0; | - | ||||||||||||||||||
1482 | bool found = false; | - | ||||||||||||||||||
1483 | QTextCursor cursor; | - | ||||||||||||||||||
1484 | while (!(cursor = control->document()->find((QLatin1String("&")), from)).isNull()) {
| 0 | ||||||||||||||||||
1485 | cursor.deleteChar(); // remove the ampersand | - | ||||||||||||||||||
1486 | cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor); | - | ||||||||||||||||||
1487 | from = cursor.position(); | - | ||||||||||||||||||
1488 | if (!found && cursor.selectedText() != QLatin1String("&")) { //not a second &
| 0 | ||||||||||||||||||
1489 | found = true; | - | ||||||||||||||||||
1490 | shortcutCursor = cursor; | - | ||||||||||||||||||
1491 | } never executed: end of block | 0 | ||||||||||||||||||
1492 | } never executed: end of block | 0 | ||||||||||||||||||
1493 | } never executed: end of block | 0 | ||||||||||||||||||
1494 | #endif | - | ||||||||||||||||||
1495 | } never executed: end of block | 0 | ||||||||||||||||||
1496 | } never executed: end of block | 0 | ||||||||||||||||||
1497 | textDirty = false; | - | ||||||||||||||||||
1498 | } never executed: end of block | 0 | ||||||||||||||||||
1499 | - | |||||||||||||||||||
1500 | void QLabelPrivate::ensureTextLayouted() const | - | ||||||||||||||||||
1501 | { | - | ||||||||||||||||||
1502 | if (!textLayoutDirty)
| 0 | ||||||||||||||||||
1503 | return; never executed: return; | 0 | ||||||||||||||||||
1504 | ensureTextPopulated(); | - | ||||||||||||||||||
1505 | if (control) {
| 0 | ||||||||||||||||||
1506 | QTextDocument *doc = control->document(); | - | ||||||||||||||||||
1507 | QTextOption opt = doc->defaultTextOption(); | - | ||||||||||||||||||
1508 | - | |||||||||||||||||||
1509 | opt.setAlignment(QFlag(this->align)); | - | ||||||||||||||||||
1510 | - | |||||||||||||||||||
1511 | if (this->align & Qt::TextWordWrap)
| 0 | ||||||||||||||||||
1512 | opt.setWrapMode(QTextOption::WordWrap); never executed: opt.setWrapMode(QTextOption::WordWrap); | 0 | ||||||||||||||||||
1513 | else | - | ||||||||||||||||||
1514 | opt.setWrapMode(QTextOption::ManualWrap); never executed: opt.setWrapMode(QTextOption::ManualWrap); | 0 | ||||||||||||||||||
1515 | - | |||||||||||||||||||
1516 | doc->setDefaultTextOption(opt); | - | ||||||||||||||||||
1517 | - | |||||||||||||||||||
1518 | QTextFrameFormat fmt = doc->rootFrame()->frameFormat(); | - | ||||||||||||||||||
1519 | fmt.setMargin(0); | - | ||||||||||||||||||
1520 | doc->rootFrame()->setFrameFormat(fmt); | - | ||||||||||||||||||
1521 | doc->setTextWidth(documentRect().width()); | - | ||||||||||||||||||
1522 | } never executed: end of block | 0 | ||||||||||||||||||
1523 | textLayoutDirty = false; | - | ||||||||||||||||||
1524 | } never executed: end of block | 0 | ||||||||||||||||||
1525 | - | |||||||||||||||||||
1526 | void QLabelPrivate::ensureTextControl() const | - | ||||||||||||||||||
1527 | { | - | ||||||||||||||||||
1528 | Q_Q(const QLabel); | - | ||||||||||||||||||
1529 | if (!isTextLabel)
| 0 | ||||||||||||||||||
1530 | return; never executed: return; | 0 | ||||||||||||||||||
1531 | if (!control) {
| 0 | ||||||||||||||||||
1532 | control = new QWidgetTextControl(const_cast<QLabel *>(q)); | - | ||||||||||||||||||
1533 | control->document()->setUndoRedoEnabled(false); | - | ||||||||||||||||||
1534 | control->document()->setDefaultFont(q->font()); | - | ||||||||||||||||||
1535 | control->setTextInteractionFlags(textInteractionFlags); | - | ||||||||||||||||||
1536 | control->setOpenExternalLinks(openExternalLinks); | - | ||||||||||||||||||
1537 | control->setPalette(q->palette()); | - | ||||||||||||||||||
1538 | control->setFocus(q->hasFocus()); | - | ||||||||||||||||||
1539 | QObject::connect(control, SIGNAL(updateRequest(QRectF)), | - | ||||||||||||||||||
1540 | q, SLOT(update())); | - | ||||||||||||||||||
1541 | QObject::connect(control, SIGNAL(linkHovered(QString)), | - | ||||||||||||||||||
1542 | q, SLOT(_q_linkHovered(QString))); | - | ||||||||||||||||||
1543 | QObject::connect(control, SIGNAL(linkActivated(QString)), | - | ||||||||||||||||||
1544 | q, SIGNAL(linkActivated(QString))); | - | ||||||||||||||||||
1545 | textLayoutDirty = true; | - | ||||||||||||||||||
1546 | textDirty = true; | - | ||||||||||||||||||
1547 | } never executed: end of block | 0 | ||||||||||||||||||
1548 | } never executed: end of block | 0 | ||||||||||||||||||
1549 | - | |||||||||||||||||||
1550 | void QLabelPrivate::sendControlEvent(QEvent *e) | - | ||||||||||||||||||
1551 | { | - | ||||||||||||||||||
1552 | Q_Q(QLabel); | - | ||||||||||||||||||
1553 | if (!isTextLabel || !control || textInteractionFlags == Qt::NoTextInteraction) {
| 0 | ||||||||||||||||||
1554 | e->ignore(); | - | ||||||||||||||||||
1555 | return; never executed: return; | 0 | ||||||||||||||||||
1556 | } | - | ||||||||||||||||||
1557 | control->processEvent(e, -layoutRect().topLeft(), q); | - | ||||||||||||||||||
1558 | } never executed: end of block | 0 | ||||||||||||||||||
1559 | - | |||||||||||||||||||
1560 | void QLabelPrivate::_q_linkHovered(const QString &anchor) | - | ||||||||||||||||||
1561 | { | - | ||||||||||||||||||
1562 | Q_Q(QLabel); | - | ||||||||||||||||||
1563 | #ifndef QT_NO_CURSOR | - | ||||||||||||||||||
1564 | if (anchor.isEmpty()) { // restore cursor
| 0 | ||||||||||||||||||
1565 | if (validCursor)
| 0 | ||||||||||||||||||
1566 | q->setCursor(cursor); never executed: q->setCursor(cursor); | 0 | ||||||||||||||||||
1567 | else | - | ||||||||||||||||||
1568 | q->unsetCursor(); never executed: q->unsetCursor(); | 0 | ||||||||||||||||||
1569 | onAnchor = false; | - | ||||||||||||||||||
1570 | } else if (!onAnchor) { never executed: end of block
| 0 | ||||||||||||||||||
1571 | validCursor = q->testAttribute(Qt::WA_SetCursor); | - | ||||||||||||||||||
1572 | if (validCursor) {
| 0 | ||||||||||||||||||
1573 | cursor = q->cursor(); | - | ||||||||||||||||||
1574 | } never executed: end of block | 0 | ||||||||||||||||||
1575 | q->setCursor(Qt::PointingHandCursor); | - | ||||||||||||||||||
1576 | onAnchor = true; | - | ||||||||||||||||||
1577 | } never executed: end of block | 0 | ||||||||||||||||||
1578 | #endif | - | ||||||||||||||||||
1579 | emit q->linkHovered(anchor); | - | ||||||||||||||||||
1580 | } never executed: end of block | 0 | ||||||||||||||||||
1581 | - | |||||||||||||||||||
1582 | // Return the layout rect - this is the rect that is given to the layout painting code | - | ||||||||||||||||||
1583 | // This may be different from the document rect since vertical alignment is not | - | ||||||||||||||||||
1584 | // done by the text layout code | - | ||||||||||||||||||
1585 | QRectF QLabelPrivate::layoutRect() const | - | ||||||||||||||||||
1586 | { | - | ||||||||||||||||||
1587 | QRectF cr = documentRect(); | - | ||||||||||||||||||
1588 | if (!control)
| 0 | ||||||||||||||||||
1589 | return cr; never executed: return cr; | 0 | ||||||||||||||||||
1590 | ensureTextLayouted(); | - | ||||||||||||||||||
1591 | // Caculate y position manually | - | ||||||||||||||||||
1592 | qreal rh = control->document()->documentLayout()->documentSize().height(); | - | ||||||||||||||||||
1593 | qreal yo = 0; | - | ||||||||||||||||||
1594 | if (align & Qt::AlignVCenter)
| 0 | ||||||||||||||||||
1595 | yo = qMax((cr.height()-rh)/2, qreal(0)); never executed: yo = qMax((cr.height()-rh)/2, qreal(0)); | 0 | ||||||||||||||||||
1596 | else if (align & Qt::AlignBottom)
| 0 | ||||||||||||||||||
1597 | yo = qMax(cr.height()-rh, qreal(0)); never executed: yo = qMax(cr.height()-rh, qreal(0)); | 0 | ||||||||||||||||||
1598 | return QRectF(cr.x(), yo + cr.y(), cr.width(), cr.height()); never executed: return QRectF(cr.x(), yo + cr.y(), cr.width(), cr.height()); | 0 | ||||||||||||||||||
1599 | } | - | ||||||||||||||||||
1600 | - | |||||||||||||||||||
1601 | // Returns the point in the document rect adjusted with p | - | ||||||||||||||||||
1602 | QPoint QLabelPrivate::layoutPoint(const QPoint& p) const | - | ||||||||||||||||||
1603 | { | - | ||||||||||||||||||
1604 | QRect lr = layoutRect().toRect(); | - | ||||||||||||||||||
1605 | return p - lr.topLeft(); never executed: return p - lr.topLeft(); | 0 | ||||||||||||||||||
1606 | } | - | ||||||||||||||||||
1607 | - | |||||||||||||||||||
1608 | #ifndef QT_NO_CONTEXTMENU | - | ||||||||||||||||||
1609 | QMenu *QLabelPrivate::createStandardContextMenu(const QPoint &pos) | - | ||||||||||||||||||
1610 | { | - | ||||||||||||||||||
1611 | QString linkToCopy; | - | ||||||||||||||||||
1612 | QPoint p; | - | ||||||||||||||||||
1613 | if (control && isRichText) {
| 0 | ||||||||||||||||||
1614 | p = layoutPoint(pos); | - | ||||||||||||||||||
1615 | linkToCopy = control->document()->documentLayout()->anchorAt(p); | - | ||||||||||||||||||
1616 | } never executed: end of block | 0 | ||||||||||||||||||
1617 | - | |||||||||||||||||||
1618 | if (linkToCopy.isEmpty() && !control)
| 0 | ||||||||||||||||||
1619 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
1620 | - | |||||||||||||||||||
1621 | return control->createStandardContextMenu(p, q_func()); never executed: return control->createStandardContextMenu(p, q_func()); | 0 | ||||||||||||||||||
1622 | } | - | ||||||||||||||||||
1623 | #endif | - | ||||||||||||||||||
1624 | - | |||||||||||||||||||
1625 | /*! | - | ||||||||||||||||||
1626 | \fn void QLabel::linkHovered(const QString &link) | - | ||||||||||||||||||
1627 | \since 4.2 | - | ||||||||||||||||||
1628 | - | |||||||||||||||||||
1629 | This signal is emitted when the user hovers over a link. The URL | - | ||||||||||||||||||
1630 | referred to by the anchor is passed in \a link. | - | ||||||||||||||||||
1631 | - | |||||||||||||||||||
1632 | \sa linkActivated() | - | ||||||||||||||||||
1633 | */ | - | ||||||||||||||||||
1634 | - | |||||||||||||||||||
1635 | - | |||||||||||||||||||
1636 | /*! | - | ||||||||||||||||||
1637 | \fn void QLabel::linkActivated(const QString &link) | - | ||||||||||||||||||
1638 | \since 4.2 | - | ||||||||||||||||||
1639 | - | |||||||||||||||||||
1640 | This signal is emitted when the user clicks a link. The URL | - | ||||||||||||||||||
1641 | referred to by the anchor is passed in \a link. | - | ||||||||||||||||||
1642 | - | |||||||||||||||||||
1643 | \sa linkHovered() | - | ||||||||||||||||||
1644 | */ | - | ||||||||||||||||||
1645 | - | |||||||||||||||||||
1646 | QT_END_NAMESPACE | - | ||||||||||||||||||
1647 | - | |||||||||||||||||||
1648 | #include "moc_qlabel.cpp" | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |