Qt 4.8
qlabel.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qpainter.h"
43 #include "qevent.h"
44 #include "qdrawutil.h"
45 #include "qapplication.h"
46 #include "qabstractbutton.h"
47 #include "qstyle.h"
48 #include "qstyleoption.h"
49 #include <limits.h>
50 #include "qaction.h"
51 #include "qclipboard.h"
52 #include <qdebug.h>
53 #include <qurl.h>
54 #include "qlabel_p.h"
55 #include "private/qstylesheetstyle_p.h"
56 #include <qmath.h>
57 
58 #ifndef QT_NO_ACCESSIBILITY
59 #include <qaccessible.h>
60 #endif
61 
62 #ifdef Q_OS_SYMBIAN
63 #include "private/qt_s60_p.h"
64 #endif
65 
67 
157 #ifndef QT_NO_PICTURE
158 
163 const QPicture *QLabel::picture() const
164 {
165  Q_D(const QLabel);
166  return d->picture;
167 }
168 #endif
169 
170 
179 QLabel::QLabel(QWidget *parent, Qt::WindowFlags f)
180  : QFrame(*new QLabelPrivate(), parent, f)
181 {
182  Q_D(QLabel);
183  d->init();
184 }
185 
194 QLabel::QLabel(const QString &text, QWidget *parent, Qt::WindowFlags f)
195  : QFrame(*new QLabelPrivate(), parent, f)
196 {
197  Q_D(QLabel);
198  d->init();
199  setText(text);
200 }
201 
202 
203 #ifdef QT3_SUPPORT
204 
216 QLabel::QLabel(QWidget *parent, const char *name, Qt::WindowFlags f)
217  : QFrame(*new QLabelPrivate(), parent, f)
218 {
219  Q_D(QLabel);
220  if (name)
222  d->init();
223 }
224 
225 
238 QLabel::QLabel(const QString &text, QWidget *parent, const char *name,
239  Qt::WindowFlags f)
240  : QFrame(*new QLabelPrivate(), parent, f)
241 {
242  Q_D(QLabel);
243  if (name)
245  d->init();
246  setText(text);
247 }
248 
249 
267 QLabel::QLabel(QWidget *buddy, const QString &text,
268  QWidget *parent, const char *name, Qt::WindowFlags f)
269  : QFrame(*new QLabelPrivate(), parent, f)
270 {
271  Q_D(QLabel);
272  if (name)
274  d->init();
275 #ifndef QT_NO_SHORTCUT
276  setBuddy(buddy);
277 #endif
278  setText(text);
279 }
280 #endif //QT3_SUPPORT
281 
287 {
288  Q_D(QLabel);
289  d->clearContents();
290 }
291 
293 {
294  Q_Q(QLabel);
295 
296  valid_hints = false;
297  margin = 0;
298 #ifndef QT_NO_MOVIE
299  movie = 0;
300 #endif
301 #ifndef QT_NO_SHORTCUT
302  shortcutId = 0;
303 #endif
304  pixmap = 0;
305  scaledpixmap = 0;
306  cachedimage = 0;
307 #ifndef QT_NO_PICTURE
308  picture = 0;
309 #endif
311  indent = -1;
312  scaledcontents = false;
313  textLayoutDirty = false;
314  textDirty = false;
315  textformat = Qt::AutoText;
316  control = 0;
318  isRichText = false;
319  isTextLabel = false;
320 
323 
324 #ifndef QT_NO_CURSOR
325  validCursor = false;
326  onAnchor = false;
327 #endif
328 
329  openExternalLinks = false;
330 
332 }
333 
334 
366 void QLabel::setText(const QString &text)
367 {
368  Q_D(QLabel);
369  if (d->text == text)
370  return;
371 
372  QTextControl *oldControl = d->control;
373  d->control = 0;
374 
375  d->clearContents();
376  d->text = text;
377  d->isTextLabel = true;
378  d->textDirty = true;
379  d->isRichText = d->textformat == Qt::RichText
380  || (d->textformat == Qt::AutoText && Qt::mightBeRichText(d->text));
381 
382  d->control = oldControl;
383 
384  if (d->needTextControl()) {
385  d->ensureTextControl();
386  } else {
387  delete d->control;
388  d->control = 0;
389  }
390 
391  if (d->isRichText) {
392  setMouseTracking(true);
393  } else {
394  // Note: mouse tracking not disabled intentionally
395  }
396 
397 #ifndef QT_NO_SHORTCUT
398  if (d->buddy)
399  d->updateShortcut();
400 #endif
401 
402  d->updateLabel();
403 
404 #ifndef QT_NO_ACCESSIBILITY
405  if (accessibleName().isEmpty())
407 #endif
408 }
409 
410 QString QLabel::text() const
411 {
412  Q_D(const QLabel);
413  return d->text;
414 }
415 
421 {
422  Q_D(QLabel);
423  d->clearContents();
424  d->updateLabel();
425 }
426 
440 {
441  Q_D(QLabel);
442  if (!d->pixmap || d->pixmap->cacheKey() != pixmap.cacheKey()) {
443  d->clearContents();
444  d->pixmap = new QPixmap(pixmap);
445  }
446 
447  if (d->pixmap->depth() == 1 && !d->pixmap->mask())
448  d->pixmap->setMask(*((QBitmap *)d->pixmap));
449 
450  d->updateLabel();
451 }
452 
453 const QPixmap *QLabel::pixmap() const
454 {
455  Q_D(const QLabel);
456  return d->pixmap;
457 }
458 
459 #ifndef QT_NO_PICTURE
460 
470 {
471  Q_D(QLabel);
472  d->clearContents();
473  d->picture = new QPicture(picture);
474 
475  d->updateLabel();
476 }
477 #endif // QT_NO_PICTURE
478 
490 void QLabel::setNum(int num)
491 {
492  QString str;
493  str.setNum(num);
494  setText(str);
495 }
496 
513 void QLabel::setNum(double num)
514 {
515  QString str;
516  str.setNum(num);
517  setText(str);
518 }
519 
532 void QLabel::setAlignment(Qt::Alignment alignment)
533 {
534  Q_D(QLabel);
535  if (alignment == (d->align & (Qt::AlignVertical_Mask|Qt::AlignHorizontal_Mask)))
536  return;
537  d->align = (d->align & ~(Qt::AlignVertical_Mask|Qt::AlignHorizontal_Mask))
539 
540  d->updateLabel();
541 }
542 
543 #ifdef QT3_SUPPORT
544 
551 {
552  Q_D(QLabel);
554  setAlignment(Qt::Alignment(QFlag(alignment)));
555 }
556 #endif
557 
558 Qt::Alignment QLabel::alignment() const
559 {
560  Q_D(const QLabel);
562 }
563 
564 
579 void QLabel::setWordWrap(bool on)
580 {
581  Q_D(QLabel);
582  if (on)
583  d->align |= Qt::TextWordWrap;
584  else
585  d->align &= ~Qt::TextWordWrap;
586 
587  d->updateLabel();
588 }
589 
590 bool QLabel::wordWrap() const
591 {
592  Q_D(const QLabel);
593  return d->align & Qt::TextWordWrap;
594 }
595 
621 {
622  Q_D(QLabel);
623  d->indent = indent;
624  d->updateLabel();
625 }
626 
627 int QLabel::indent() const
628 {
629  Q_D(const QLabel);
630  return d->indent;
631 }
632 
633 
648 int QLabel::margin() const
649 {
650  Q_D(const QLabel);
651  return d->margin;
652 }
653 
655 {
656  Q_D(QLabel);
657  if (d->margin == margin)
658  return;
659  d->margin = margin;
660  d->updateLabel();
661 }
662 
668 {
669  Q_Q(const QLabel);
670  if(q->minimumWidth() > 0)
671  w = qMax(w, q->minimumWidth());
672  QSize contentsMargin(leftmargin + rightmargin, topmargin + bottommargin);
673 
674  QRect br;
675 
676  int hextra = 2 * margin;
677  int vextra = hextra;
678  QFontMetrics fm = q->fontMetrics();
679 
680  if (pixmap && !pixmap->isNull())
681  br = pixmap->rect();
682 #ifndef QT_NO_PICTURE
683  else if (picture && !picture->isNull())
684  br = picture->boundingRect();
685 #endif
686 #ifndef QT_NO_MOVIE
687  else if (movie && !movie->currentPixmap().isNull())
688  br = movie->currentPixmap().rect();
689 #endif
690  else if (isTextLabel) {
691  int align = QStyle::visualAlignment(textDirection(), QFlag(this->align));
692  // Add indentation
693  int m = indent;
694 
695  if (m < 0 && q->frameWidth()) // no indent, but we do have a frame
696  m = fm.width(QLatin1Char('x')) - margin*2;
697  if (m > 0) {
698  if ((align & Qt::AlignLeft) || (align & Qt::AlignRight))
699  hextra += m;
700  if ((align & Qt::AlignTop) || (align & Qt::AlignBottom))
701  vextra += m;
702  }
703 
704  if (control) {
705  ensureTextLayouted();
706  const qreal oldTextWidth = control->textWidth();
707  // Calculate the length of document if w is the width
708  if (align & Qt::TextWordWrap) {
709  if (w >= 0) {
710  w = qMax(w-hextra-contentsMargin.width(), 0); // strip margin and indent
711  control->setTextWidth(w);
712  } else {
713  control->adjustSize();
714  }
715  } else {
716  control->setTextWidth(-1);
717  }
718 
719  QSizeF controlSize = control->size();
720  br = QRect(QPoint(0, 0), QSize(qCeil(controlSize.width()), qCeil(controlSize.height())));
721 
722  // restore state
723  control->setTextWidth(oldTextWidth);
724  } else {
725  // Turn off center alignment in order to avoid rounding errors for centering,
726  // since centering involves a division by 2. At the end, all we want is the size.
727  int flags = align & ~(Qt::AlignVCenter | Qt::AlignHCenter);
728  if (hasShortcut) {
729  flags |= Qt::TextShowMnemonic;
730  QStyleOption opt;
731  opt.initFrom(q);
732  if (!q->style()->styleHint(QStyle::SH_UnderlineShortcut, &opt, q))
733  flags |= Qt::TextHideMnemonic;
734  }
735 
736  bool tryWidth = (w < 0) && (align & Qt::TextWordWrap);
737  if (tryWidth)
738 #ifdef Q_OS_SYMBIAN
739  w = qMin(S60->clientRect().Width(), q->maximumSize().width());
740 #else
741  w = qMin(fm.averageCharWidth() * 80, q->maximumSize().width());
742 #endif
743  else if (w < 0)
744  w = 2000;
745  w -= (hextra + contentsMargin.width());
746  br = fm.boundingRect(0, 0, w ,2000, flags, text);
747  if (tryWidth && br.height() < 4*fm.lineSpacing() && br.width() > w/2)
748  br = fm.boundingRect(0, 0, w/2, 2000, flags, text);
749  if (tryWidth && br.height() < 2*fm.lineSpacing() && br.width() > w/4)
750  br = fm.boundingRect(0, 0, w/4, 2000, flags, text);
751  }
752  } else {
753  br = QRect(QPoint(0, 0), QSize(fm.averageCharWidth(), fm.lineSpacing()));
754  }
755 
756  const QSize contentsSize(br.width() + hextra, br.height() + vextra);
757  return (contentsSize + contentsMargin).expandedTo(q->minimumSize());
758 }
759 
760 
765 int QLabel::heightForWidth(int w) const
766 {
767  Q_D(const QLabel);
768  if (d->isTextLabel)
769  return d->sizeForWidth(w).height();
770  return QWidget::heightForWidth(w);
771 }
772 
791 bool QLabel::openExternalLinks() const
792 {
793  Q_D(const QLabel);
794  return d->openExternalLinks;
795 }
796 
798 {
799  Q_D(QLabel);
800  d->openExternalLinks = open;
801  if (d->control)
802  d->control->setOpenExternalLinks(open);
803 }
804 
820 void QLabel::setTextInteractionFlags(Qt::TextInteractionFlags flags)
821 {
822  Q_D(QLabel);
823  if (d->textInteractionFlags == flags)
824  return;
825  d->textInteractionFlags = flags;
826  if (flags & Qt::LinksAccessibleByKeyboard)
830  else
832 
833  if (d->needTextControl()) {
834  d->ensureTextControl();
835  } else {
836  delete d->control;
837  d->control = 0;
838  }
839 
840  if (d->control)
841  d->control->setTextInteractionFlags(d->textInteractionFlags);
842 }
843 
844 Qt::TextInteractionFlags QLabel::textInteractionFlags() const
845 {
846  Q_D(const QLabel);
847  return d->textInteractionFlags;
848 }
849 
860 void QLabel::setSelection(int start, int length)
861 {
862  Q_D(QLabel);
863  if (d->control) {
864  d->ensureTextPopulated();
865  QTextCursor cursor = d->control->textCursor();
866  cursor.setPosition(start);
867  cursor.setPosition(start + length, QTextCursor::KeepAnchor);
868  d->control->setTextCursor(cursor);
869  }
870 }
871 
891 bool QLabel::hasSelectedText() const
892 {
893  Q_D(const QLabel);
894  if (d->control)
895  return d->control->textCursor().hasSelection();
896  return false;
897 }
898 
919 {
920  Q_D(const QLabel);
921  if (d->control)
922  return d->control->textCursor().selectedText();
923  return QString();
924 }
925 
938 {
939  Q_D(const QLabel);
940  if (d->control && d->control->textCursor().hasSelection())
941  return d->control->textCursor().selectionStart();
942  return -1;
943 }
944 
948 {
949  Q_D(const QLabel);
950  if (!d->valid_hints)
951  (void) QLabel::minimumSizeHint();
952  return d->sh;
953 }
954 
959 {
960  Q_D(const QLabel);
961  if (d->valid_hints) {
962  if (d->sizePolicy == sizePolicy())
963  return d->msh;
964  }
965 
966  ensurePolished();
967  d->valid_hints = true;
968  d->sh = d->sizeForWidth(-1); // wrap ? golden ratio : min doc size
969  QSize msh(-1, -1);
970 
971  if (!d->isTextLabel) {
972  msh = d->sh;
973  } else {
974  msh.rheight() = d->sizeForWidth(QWIDGETSIZE_MAX).height(); // height for one line
975  msh.rwidth() = d->sizeForWidth(0).width(); // wrap ? size of biggest word : min doc size
976  if (d->sh.height() < msh.height())
977  msh.rheight() = d->sh.height();
978  }
979  d->msh = msh;
980  d->sizePolicy = sizePolicy();
981  return msh;
982 }
983 
987 {
988  Q_D(QLabel);
989  d->sendControlEvent(ev);
990 }
991 
995 {
996  Q_D(QLabel);
997  d->sendControlEvent(ev);
998 }
999 
1003 {
1004  Q_D(QLabel);
1005  d->sendControlEvent(ev);
1006 }
1007 
1011 {
1012 #ifdef QT_NO_CONTEXTMENU
1013  Q_UNUSED(ev);
1014 #else
1015  Q_D(QLabel);
1016  if (!d->isTextLabel) {
1017  ev->ignore();
1018  return;
1019  }
1020  QMenu *menu = d->createStandardContextMenu(ev->pos());
1021  if (!menu) {
1022  ev->ignore();
1023  return;
1024  }
1025  ev->accept();
1027  menu->popup(ev->globalPos());
1028 #endif
1029 }
1030 
1035 {
1036  Q_D(QLabel);
1037  if (d->isTextLabel) {
1038  d->ensureTextControl();
1039  d->sendControlEvent(ev);
1040  }
1042 }
1043 
1048 {
1049  Q_D(QLabel);
1050  if (d->control) {
1051  d->sendControlEvent(ev);
1052  QTextCursor cursor = d->control->textCursor();
1053  Qt::FocusReason reason = ev->reason();
1054  if (reason != Qt::ActiveWindowFocusReason
1055  && reason != Qt::PopupFocusReason
1056  && cursor.hasSelection()) {
1057  cursor.clearSelection();
1058  d->control->setTextCursor(cursor);
1059  }
1060  }
1061 
1063 }
1064 
1068 {
1069  Q_D(QLabel);
1070  if (d->control && d->control->setFocusToNextOrPreviousAnchor(next))
1071  return true;
1072  return QFrame::focusNextPrevChild(next);
1073 }
1074 
1078 {
1079  Q_D(QLabel);
1080  d->sendControlEvent(ev);
1081 }
1082 
1086 {
1087  Q_D(QLabel);
1088  QEvent::Type type = e->type();
1089 
1090 #ifndef QT_NO_SHORTCUT
1091  if (type == QEvent::Shortcut) {
1092  QShortcutEvent *se = static_cast<QShortcutEvent *>(e);
1093  if (se->shortcutId() == d->shortcutId) {
1094  QWidget * w = d->buddy;
1096  if (w->focusPolicy() != Qt::NoFocus)
1098  if (button && !se->isAmbiguous())
1099  button->animateClick();
1100  else
1102  return true;
1103  }
1104  } else
1105 #endif
1106  if (type == QEvent::Resize) {
1107  if (d->control)
1108  d->textLayoutDirty = true;
1109  } else if (e->type() == QEvent::StyleChange
1110 #ifdef Q_WS_MAC
1111  || e->type() == QEvent::MacSizeChange
1112 #endif
1113  ) {
1114  d->setLayoutItemMargins(QStyle::SE_LabelLayoutItem);
1115  d->updateLabel();
1116  }
1117 
1118  return QFrame::event(e);
1119 }
1120 
1124 {
1125  Q_D(QLabel);
1127  QPainter painter(this);
1128  drawFrame(&painter);
1129  QRect cr = contentsRect();
1130  cr.adjust(d->margin, d->margin, -d->margin, -d->margin);
1131  int align = QStyle::visualAlignment(d->isTextLabel ? d->textDirection()
1132  : layoutDirection(), QFlag(d->align));
1133 
1134 #ifndef QT_NO_MOVIE
1135  if (d->movie) {
1136  if (d->scaledcontents)
1137  style->drawItemPixmap(&painter, cr, align, d->movie->currentPixmap().scaled(cr.size()));
1138  else
1139  style->drawItemPixmap(&painter, cr, align, d->movie->currentPixmap());
1140  }
1141  else
1142 #endif
1143  if (d->isTextLabel) {
1144  QRectF lr = d->layoutRect().toAlignedRect();
1145  QStyleOption opt;
1146  opt.initFrom(this);
1147 #ifndef QT_NO_STYLE_STYLESHEET
1148  if (QStyleSheetStyle* cssStyle = qobject_cast<QStyleSheetStyle*>(style)) {
1149  cssStyle->styleSheetPalette(this, &opt, &opt.palette);
1150  }
1151 #endif
1152  if (d->control) {
1153 #ifndef QT_NO_SHORTCUT
1154  const bool underline = (bool)style->styleHint(QStyle::SH_UnderlineShortcut, 0, this, 0);
1155  if (d->shortcutId != 0
1156  && underline != d->shortcutCursor.charFormat().fontUnderline()) {
1157  QTextCharFormat fmt;
1158  fmt.setFontUnderline(underline);
1159  d->shortcutCursor.mergeCharFormat(fmt);
1160  }
1161 #endif
1162  d->ensureTextLayouted();
1163 
1165  if (!isEnabled() && !d->control &&
1166  // We cannot support etched for rich text controls because custom
1167  // colors and links will override the light palette
1168  style->styleHint(QStyle::SH_EtchDisabledText, &opt, this)) {
1169  context.palette = opt.palette;
1170  context.palette.setColor(QPalette::Text, context.palette.light().color());
1171  painter.save();
1172  painter.translate(lr.x() + 1, lr.y() + 1);
1173  painter.setClipRect(lr.translated(-lr.x() - 1, -lr.y() - 1));
1174  QAbstractTextDocumentLayout *layout = d->control->document()->documentLayout();
1175  layout->draw(&painter, context);
1176  painter.restore();
1177  }
1178 
1179  // Adjust the palette
1180  context.palette = opt.palette;
1181 
1182  if (foregroundRole() != QPalette::Text && isEnabled())
1184 
1185  painter.save();
1186  painter.translate(lr.topLeft());
1187  painter.setClipRect(lr.translated(-lr.x(), -lr.y()));
1188  d->control->setPalette(context.palette);
1189  d->control->drawContents(&painter, QRectF(), this);
1190  painter.restore();
1191  } else {
1192  int flags = align | (d->textDirection() == Qt::LeftToRight ? Qt::TextForceLeftToRight
1194  if (d->hasShortcut) {
1195  flags |= Qt::TextShowMnemonic;
1196  if (!style->styleHint(QStyle::SH_UnderlineShortcut, &opt, this))
1197  flags |= Qt::TextHideMnemonic;
1198  }
1199  style->drawItemText(&painter, lr.toRect(), flags, opt.palette, isEnabled(), d->text, foregroundRole());
1200  }
1201  } else
1202 #ifndef QT_NO_PICTURE
1203  if (d->picture) {
1204  QRect br = d->picture->boundingRect();
1205  int rw = br.width();
1206  int rh = br.height();
1207  if (d->scaledcontents) {
1208  painter.save();
1209  painter.translate(cr.x(), cr.y());
1210  painter.scale((double)cr.width()/rw, (double)cr.height()/rh);
1211  painter.drawPicture(-br.x(), -br.y(), *d->picture);
1212  painter.restore();
1213  } else {
1214  int xo = 0;
1215  int yo = 0;
1216  if (align & Qt::AlignVCenter)
1217  yo = (cr.height()-rh)/2;
1218  else if (align & Qt::AlignBottom)
1219  yo = cr.height()-rh;
1220  if (align & Qt::AlignRight)
1221  xo = cr.width()-rw;
1222  else if (align & Qt::AlignHCenter)
1223  xo = (cr.width()-rw)/2;
1224  painter.drawPicture(cr.x()+xo-br.x(), cr.y()+yo-br.y(), *d->picture);
1225  }
1226  } else
1227 #endif
1228  if (d->pixmap && !d->pixmap->isNull()) {
1229  QPixmap pix;
1230  if (d->scaledcontents) {
1231  if (!d->scaledpixmap || d->scaledpixmap->size() != cr.size()) {
1232  if (!d->cachedimage)
1233  d->cachedimage = new QImage(d->pixmap->toImage());
1234  delete d->scaledpixmap;
1235  d->scaledpixmap = new QPixmap(QPixmap::fromImage(d->cachedimage->scaled(cr.size(),Qt::IgnoreAspectRatio,Qt::SmoothTransformation)));
1236  }
1237  pix = *d->scaledpixmap;
1238  } else
1239  pix = *d->pixmap;
1240  QStyleOption opt;
1241  opt.initFrom(this);
1242  if (!isEnabled())
1243  pix = style->generatedIconPixmap(QIcon::Disabled, pix, &opt);
1244  style->drawItemPixmap(&painter, cr, align, pix);
1245  }
1246 }
1247 
1248 
1254 {
1255  Q_Q(QLabel);
1256  valid_hints = false;
1257 
1258  if (isTextLabel) {
1259  QSizePolicy policy = q->sizePolicy();
1260  const bool wrap = align & Qt::TextWordWrap;
1261  policy.setHeightForWidth(wrap);
1262  if (policy != q->sizePolicy()) // ### should be replaced by WA_WState_OwnSizePolicy idiom
1263  q->setSizePolicy(policy);
1264  textLayoutDirty = true;
1265  }
1266  q->updateGeometry();
1267  q->update(q->contentsRect());
1268 }
1269 
1270 #ifndef QT_NO_SHORTCUT
1271 
1298 {
1299  Q_D(QLabel);
1300  d->buddy = buddy;
1301  if (d->isTextLabel) {
1302  if (d->shortcutId)
1303  releaseShortcut(d->shortcutId);
1304  d->shortcutId = 0;
1305  d->textDirty = true;
1306  if (buddy)
1307  d->updateShortcut(); // grab new shortcut
1308  d->updateLabel();
1309  }
1310 }
1311 
1312 
1320 {
1321  Q_D(const QLabel);
1322  return d->buddy;
1323 }
1324 
1326 {
1327  Q_Q(QLabel);
1328  Q_ASSERT(shortcutId == 0);
1329  // Introduce an extra boolean to indicate the presence of a shortcut in the
1330  // text. We cannot use the shortcutId itself because on the mac mnemonics are
1331  // off by default, so QKeySequence::mnemonic always returns an empty sequence.
1332  // But then we do want to hide the ampersands, so we can't use shortcutId.
1333  hasShortcut = false;
1334 
1335  if (!text.contains(QLatin1Char('&')))
1336  return;
1337  hasShortcut = true;
1338  shortcutId = q->grabShortcut(QKeySequence::mnemonic(text));
1339 }
1340 
1341 #endif // QT_NO_SHORTCUT
1342 
1343 #ifndef QT_NO_MOVIE
1345 {
1346  Q_Q(QLabel);
1347  if (movie && movie->isValid()) {
1348  QRect r;
1349  if (scaledcontents) {
1350  QRect cr = q->contentsRect();
1351  QRect pixmapRect(cr.topLeft(), movie->currentPixmap().size());
1352  if (pixmapRect.isEmpty())
1353  return;
1354  r.setRect(cr.left(), cr.top(),
1355  (rect.width() * cr.width()) / pixmapRect.width(),
1356  (rect.height() * cr.height()) / pixmapRect.height());
1357  } else {
1358  r = q->style()->itemPixmapRect(q->contentsRect(), align, movie->currentPixmap());
1359  r.translate(rect.x(), rect.y());
1360  r.setWidth(qMin(r.width(), rect.width()));
1361  r.setHeight(qMin(r.height(), rect.height()));
1362  }
1363  q->update(r);
1364  }
1365 }
1366 
1368 {
1369  Q_Q(QLabel);
1370  q->update(); //we need to refresh the whole background in case the new size is smaler
1371  valid_hints = false;
1372  _q_movieUpdated(QRect(QPoint(0,0), size));
1373  q->updateGeometry();
1374 }
1375 
1386 {
1387  Q_D(QLabel);
1388  d->clearContents();
1389 
1390  if (!movie)
1391  return;
1392 
1393  d->movie = movie;
1394  connect(movie, SIGNAL(resized(QSize)), this, SLOT(_q_movieResized(QSize)));
1395  connect(movie, SIGNAL(updated(QRect)), this, SLOT(_q_movieUpdated(QRect)));
1396 
1397  // Assume that if the movie is running,
1398  // resize/update signals will come soon enough
1399  if (movie->state() != QMovie::Running)
1400  d->updateLabel();
1401 }
1402 
1403 #endif // QT_NO_MOVIE
1404 
1415 {
1416  delete control;
1417  control = 0;
1418  isTextLabel = false;
1419  hasShortcut = false;
1420 
1421 #ifndef QT_NO_PICTURE
1422  delete picture;
1423  picture = 0;
1424 #endif
1425  delete scaledpixmap;
1426  scaledpixmap = 0;
1427  delete cachedimage;
1428  cachedimage = 0;
1429  delete pixmap;
1430  pixmap = 0;
1431 
1432  text.clear();
1433  Q_Q(QLabel);
1434 #ifndef QT_NO_SHORTCUT
1435  if (shortcutId)
1436  q->releaseShortcut(shortcutId);
1437  shortcutId = 0;
1438 #endif
1439 #ifndef QT_NO_MOVIE
1440  if (movie) {
1441  QObject::disconnect(movie, SIGNAL(resized(QSize)), q, SLOT(_q_movieResized(QSize)));
1442  QObject::disconnect(movie, SIGNAL(updated(QRect)), q, SLOT(_q_movieUpdated(QRect)));
1443  }
1444  movie = 0;
1445 #endif
1446 #ifndef QT_NO_CURSOR
1447  if (onAnchor) {
1448  if (validCursor)
1449  q->setCursor(cursor);
1450  else
1451  q->unsetCursor();
1452  }
1453  validCursor = false;
1454  onAnchor = false;
1455 #endif
1456 }
1457 
1458 
1459 #ifndef QT_NO_MOVIE
1460 
1469 {
1470  Q_D(const QLabel);
1471  return d->movie;
1472 }
1473 
1474 #endif // QT_NO_MOVIE
1475 
1492 {
1493  Q_D(const QLabel);
1494  return d->textformat;
1495 }
1496 
1498 {
1499  Q_D(QLabel);
1500  if (format != d->textformat) {
1501  d->textformat = format;
1502  QString t = d->text;
1503  if (!t.isNull()) {
1504  d->text.clear();
1505  setText(t);
1506  }
1507  }
1508 }
1509 
1514 {
1515  Q_D(QLabel);
1516  if(ev->type() == QEvent::FontChange || ev->type() == QEvent::ApplicationFontChange) {
1517  if (d->isTextLabel) {
1518  if (d->control)
1519  d->control->document()->setDefaultFont(font());
1520  d->updateLabel();
1521  }
1522  } else if (ev->type() == QEvent::PaletteChange && d->control) {
1523  d->control->setPalette(palette());
1524  } else if (ev->type() == QEvent::ContentsRectChange) {
1525  d->updateLabel();
1526  }
1527  QFrame::changeEvent(ev);
1528 }
1529 
1544 {
1545  Q_D(const QLabel);
1546  return d->scaledcontents;
1547 }
1548 
1549 void QLabel::setScaledContents(bool enable)
1550 {
1551  Q_D(QLabel);
1552  if ((bool)d->scaledcontents == enable)
1553  return;
1554  d->scaledcontents = enable;
1555  if (!enable) {
1556  delete d->scaledpixmap;
1557  d->scaledpixmap = 0;
1558  delete d->cachedimage;
1559  d->cachedimage = 0;
1560  }
1561  update(contentsRect());
1562 }
1563 
1565 {
1566  if (control) {
1567  QTextOption opt = control->document()->defaultTextOption();
1568  return opt.textDirection();
1569  }
1570 
1571  return text.isRightToLeft() ? Qt::RightToLeft : Qt::LeftToRight;
1572 }
1573 
1586 // Returns the rect that is available for us to draw the document
1588 {
1589  Q_Q(const QLabel);
1590  Q_ASSERT_X(isTextLabel, "documentRect", "document rect called for label that is not a text label!");
1591  QRect cr = q->contentsRect();
1592  cr.adjust(margin, margin, -margin, -margin);
1593  const int align = QStyle::visualAlignment(isTextLabel ? textDirection()
1594  : q->layoutDirection(), QFlag(this->align));
1595  int m = indent;
1596  if (m < 0 && q->frameWidth()) // no indent, but we do have a frame
1597  m = q->fontMetrics().width(QLatin1Char('x')) / 2 - margin;
1598  if (m > 0) {
1599  if (align & Qt::AlignLeft)
1600  cr.setLeft(cr.left() + m);
1601  if (align & Qt::AlignRight)
1602  cr.setRight(cr.right() - m);
1603  if (align & Qt::AlignTop)
1604  cr.setTop(cr.top() + m);
1605  if (align & Qt::AlignBottom)
1606  cr.setBottom(cr.bottom() - m);
1607  }
1608  return cr;
1609 }
1610 
1612 {
1613  if (!textDirty)
1614  return;
1615  if (control) {
1616  QTextDocument *doc = control->document();
1617  if (textDirty) {
1618 #ifndef QT_NO_TEXTHTMLPARSER
1619  if (isRichText)
1620  doc->setHtml(text);
1621  else
1622  doc->setPlainText(text);
1623 #else
1624  doc->setPlainText(text);
1625 #endif
1626  doc->setUndoRedoEnabled(false);
1627 
1628 #ifndef QT_NO_SHORTCUT
1629  if (hasShortcut) {
1630  // Underline the first character that follows an ampersand (and remove the others ampersands)
1631  int from = 0;
1632  bool found = false;
1634  while (!(cursor = control->document()->find((QLatin1String("&")), from)).isNull()) {
1635  cursor.deleteChar(); // remove the ampersand
1637  from = cursor.position();
1638  if (!found && cursor.selectedText() != QLatin1String("&")) { //not a second &
1639  found = true;
1640  shortcutCursor = cursor;
1641  }
1642  }
1643  }
1644 #endif
1645  }
1646  }
1647  textDirty = false;
1648 }
1649 
1651 {
1652  if (!textLayoutDirty)
1653  return;
1654  ensureTextPopulated();
1655  if (control) {
1656  QTextDocument *doc = control->document();
1657  QTextOption opt = doc->defaultTextOption();
1658 
1659  opt.setAlignment(QFlag(this->align));
1660 
1661  if (this->align & Qt::TextWordWrap)
1663  else
1665 
1666  doc->setDefaultTextOption(opt);
1667 
1668  QTextFrameFormat fmt = doc->rootFrame()->frameFormat();
1669  fmt.setMargin(0);
1670  doc->rootFrame()->setFrameFormat(fmt);
1671  doc->setTextWidth(documentRect().width());
1672  }
1673  textLayoutDirty = false;
1674 }
1675 
1677 {
1678  Q_Q(const QLabel);
1679  if (!isTextLabel)
1680  return;
1681  if (!control) {
1682  control = new QTextControl(const_cast<QLabel *>(q));
1683  control->document()->setUndoRedoEnabled(false);
1684  control->document()->setDefaultFont(q->font());
1685  control->setTextInteractionFlags(textInteractionFlags);
1686  control->setOpenExternalLinks(openExternalLinks);
1687  control->setPalette(q->palette());
1688  control->setFocus(q->hasFocus());
1689  QObject::connect(control, SIGNAL(updateRequest(QRectF)),
1690  q, SLOT(update()));
1692  q, SLOT(_q_linkHovered(QString)));
1695  textLayoutDirty = true;
1696  textDirty = true;
1697  }
1698 }
1699 
1701 {
1702  Q_Q(QLabel);
1703  if (!isTextLabel || !control || textInteractionFlags == Qt::NoTextInteraction) {
1704  e->ignore();
1705  return;
1706  }
1707  control->processEvent(e, -layoutRect().topLeft(), q);
1708 }
1709 
1711 {
1712  Q_Q(QLabel);
1713 #ifndef QT_NO_CURSOR
1714  if (anchor.isEmpty()) { // restore cursor
1715  if (validCursor)
1716  q->setCursor(cursor);
1717  else
1718  q->unsetCursor();
1719  onAnchor = false;
1720  } else if (!onAnchor) {
1721  validCursor = q->testAttribute(Qt::WA_SetCursor);
1722  if (validCursor) {
1723  cursor = q->cursor();
1724  }
1725  q->setCursor(Qt::PointingHandCursor);
1726  onAnchor = true;
1727  }
1728 #endif
1729  emit q->linkHovered(anchor);
1730 }
1731 
1732 // Return the layout rect - this is the rect that is given to the layout painting code
1733 // This may be different from the document rect since vertical alignment is not
1734 // done by the text layout code
1736 {
1737  QRectF cr = documentRect();
1738  if (!control)
1739  return cr;
1740  ensureTextLayouted();
1741  // Caculate y position manually
1742  qreal rh = control->document()->documentLayout()->documentSize().height();
1743  qreal yo = 0;
1744  if (align & Qt::AlignVCenter)
1745  yo = qMax((cr.height()-rh)/2, qreal(0));
1746  else if (align & Qt::AlignBottom)
1747  yo = qMax(cr.height()-rh, qreal(0));
1748  return QRectF(cr.x(), yo + cr.y(), cr.width(), cr.height());
1749 }
1750 
1751 // Returns the point in the document rect adjusted with p
1753 {
1754  QRect lr = layoutRect().toRect();
1755  return p - lr.topLeft();
1756 }
1757 
1758 #ifndef QT_NO_CONTEXTMENU
1760 {
1761  QString linkToCopy;
1762  QPoint p;
1763  if (control && isRichText) {
1764  p = layoutPoint(pos);
1765  linkToCopy = control->document()->documentLayout()->anchorAt(p);
1766  }
1767 
1768  if (linkToCopy.isEmpty() && !control)
1769  return 0;
1770 
1771  return control->createStandardContextMenu(p, q_func());
1772 }
1773 #endif
1774 
1803 
1804 #include "moc_qlabel.cpp"
bool wordWrap() const
The QAbstractButton class is the abstract base class of button widgets, providing functionality commo...
QPoint pos() const
virtual QPixmap generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *opt) const =0
Returns a copy of the given pixmap, styled to conform to the specified iconMode and taking into accou...
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
QPoint layoutPoint(const QPoint &p) const
Definition: qlabel.cpp:1752
QLabel(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs an empty label.
Definition: qlabel.cpp:179
Qt::TextFormat textFormat() const
static void updateAccessibility(QObject *, int who, Event reason)
Notifies accessibility clients about a change in object&#39;s accessibility information.
QSize sizeForWidth(int w) const
Returns the size that will be used if the width of the label is w.
Definition: qlabel.cpp:667
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
Definition: qpixmap.cpp:2197
qreal y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:667
int width(const QString &, int len=-1) const
Returns the width in pixels of the first len characters of text.
bool event(QEvent *e)
em>Reimplemented Function
Definition: qlabel.cpp:1085
The QKeyEvent class describes a key event.
Definition: qevent.h:224
void setHeight(int h)
Sets the height of the rectangle to the given height.
Definition: qrect.h:445
int type
Definition: qmetatype.cpp:239
void _q_linkHovered(const QString &link)
Definition: qlabel.cpp:1710
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
Definition: qtextformat.h:372
double qreal
Definition: qglobal.h:1193
virtual int heightForWidth(int) const
Returns the preferred height for this widget, given the width w.
Definition: qwidget.cpp:10241
void setBottom(int pos)
Sets the bottom edge of the rectangle to the given y coordinate.
Definition: qrect.h:267
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
void setTextFormat(Qt::TextFormat)
Definition: qlabel.cpp:1497
void _q_movieResized(const QSize &)
Definition: qlabel.cpp:1367
void setWordWrap(bool on)
Definition: qlabel.cpp:579
The QMovie class is a convenience class for playing movies with QImageReader.
Definition: qmovie.h:74
QSize size() const
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
QSize size() const
Returns the size of the pixmap.
Definition: qpixmap.cpp:661
QCursor cursor() const
int qCeil(qreal v)
Definition: qmath.h:63
Qt::TextInteractionFlags textInteractionFlags() const
void setPicture(const QPicture &)
Sets the label contents to picture.
Definition: qlabel.cpp:469
void ensurePolished() const
Ensures that the widget has been polished by QStyle (i.e., has a proper font and palette).
Definition: qwidget.cpp:10024
The QFlag class is a helper data type for QFlags.
Definition: qglobal.h:2289
QRect contentsRect() const
Returns the area inside the widget&#39;s margins.
Definition: qwidget.cpp:7544
void setText(const QString &)
Definition: qlabel.cpp:366
void popup(const QPoint &pos, QAction *at=0)
Displays the menu so that the action atAction will be at the specified global position p...
Definition: qmenu.cpp:1847
The QContextMenuEvent class contains parameters that describe a context menu event.
Definition: qevent.h:396
~QLabel()
Destroys the label.
Definition: qlabel.cpp:286
const QPoint & pos() const
Returns the position of the mouse pointer relative to the widget that received the event...
Definition: qevent.h:412
int indent() const
qreal width() const
Returns the width.
Definition: qsize.h:284
bool focusNextPrevChild(bool next)
em>Reimplemented Function
Definition: qlabel.cpp:1067
static QKeySequence mnemonic(const QString &text)
Returns the shortcut key sequence for the mnemonic in text, or an empty key sequence if no mnemonics ...
void setClipRect(const QRectF &, Qt::ClipOperation op=Qt::ReplaceClip)
Enables clipping, and sets the clip region to the given rectangle using the given clip operation...
Definition: qpainter.cpp:2801
const QPixmap * pixmap() const
#define SLOT(a)
Definition: qobjectdefs.h:226
qreal height() const
Returns the height.
Definition: qsize.h:287
#define QWIDGETSIZE_MAX
Defines the maximum size for a QWidget object.
Definition: qwidget.h:1087
Qt::FocusPolicy focusPolicy
the way the widget accepts keyboard focus
Definition: qwidget.h:187
void restore()
Restores the current painter state (pops a saved state off the stack).
Definition: qpainter.cpp:1620
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=0, const QWidget *widget=0, QStyleHintReturn *returnData=0) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
Q_GUI_EXPORT bool mightBeRichText(const QString &)
Returns true if the string text is likely to be rich text; otherwise returns false.
The QShortcutEvent class provides an event which is generated when the user presses a key combination...
Definition: qevent.h:675
QPointF topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:539
QSize expandedTo(const QSize &) const
Returns a size holding the maximum width and height of this size and the given otherSize.
Definition: qsize.h:187
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
QSize sizeHint() const
em>Reimplemented Function
Definition: qlabel.cpp:947
void clearContents()
Clears any contents, without updating/repainting the label.
Definition: qlabel.cpp:1414
QTextDocument * document() const
Returns the document this cursor is associated with.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
virtual void drawItemText(QPainter *painter, const QRect &rect, int flags, const QPalette &pal, bool enabled, const QString &text, QPalette::ColorRole textRole=QPalette::NoRole) const
Draws the given text in the specified rectangle using the provided painter and palette.
Definition: qstyle.cpp:532
bool isNull() const
Returns true if the picture contains no data; otherwise returns false.
Definition: qpicture.cpp:215
int frameWidth() const
QMenu * createStandardContextMenu(const QPoint &pos)
Definition: qlabel.cpp:1759
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
void setTextInteractionFlags(Qt::TextInteractionFlags flags)
Definition: qlabel.cpp:820
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
The QString class provides a Unicode character string.
Definition: qstring.h:83
T * qobject_cast(QObject *object)
Definition: qobject.h:375
void mouseMoveEvent(QMouseEvent *ev)
em>Reimplemented Function
Definition: qlabel.cpp:994
QPalette palette
the default color that is used for the text, when no color is specified.
void ensureTextPopulated() const
Definition: qlabel.cpp:1611
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void setOpenExternalLinks(bool open)
Definition: qlabel.cpp:797
#define Q_D(Class)
Definition: qglobal.h:2482
void focusOutEvent(QFocusEvent *ev)
Reimplemented Function
Definition: qlabel.cpp:1047
const QColor & color(ColorGroup cg, ColorRole cr) const
Returns the color in the specified color group, used for the given color role.
Definition: qpalette.h:107
QString selectedText() const
Returns the current selection&#39;s text (which may be empty).
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
void setNum(int)
Sets the label contents to plain text containing the textual representation of integer num...
Definition: qlabel.cpp:490
bool hasScaledContents() const
Definition: qlabel.cpp:1543
void releaseShortcut(int id)
Removes the shortcut with the given id from Qt&#39;s shortcut system.
Definition: qwidget.cpp:11771
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
virtual void focusOutEvent(QFocusEvent *)
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus lost) f...
Definition: qwidget.cpp:9457
bool hasSelectedText() const
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
void mousePressEvent(QMouseEvent *ev)
em>Reimplemented Function
Definition: qlabel.cpp:986
void setDefaultTextOption(const QTextOption &option)
Sets the default text option.
void setPixmap(const QPixmap &)
Definition: qlabel.cpp:439
QStyle * style() const
Definition: qwidget.cpp:2742
void setObjectName(const QString &name)
Definition: qobject.cpp:1112
#define Q_Q(Class)
Definition: qglobal.h:2483
void updateShortcut()
Definition: qlabel.cpp:1325
QFrame(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a frame widget with frame style NoFrame and a 1-pixel frame width.
Definition: qframe.cpp:219
QTextFrame * rootFrame() const
Returns the document&#39;s root frame.
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
QRect boundingRect(QChar) const
Returns the rectangle that is covered by ink if character ch were to be drawn at the origin of the co...
QSizePolicy sizePolicy() const
QPixmap currentPixmap() const
Returns the current frame as a QPixmap.
Definition: qmovie.cpp:825
void setHeightForWidth(bool b)
Definition: qsizepolicy.h:135
void setPlainText(const QString &text)
Replaces the entire contents of the document with the given plain text.
#define SIGNAL(a)
Definition: qobjectdefs.h:227
The QBitmap class provides monochrome (1-bit depth) pixmaps.
Definition: qbitmap.h:55
int width() const
Returns the width.
Definition: qsize.h:126
void setAlignment(Qt::Alignment alignment)
Sets the option&#39;s text alignment to the specified alignment.
Definition: qtextoption.h:148
Qt::Alignment alignment() const
QWidget * buddy() const
Returns this label&#39;s buddy, or 0 if no buddy is currently set.
Definition: qlabel.cpp:1319
int averageCharWidth() const
Returns the average width of glyphs in the font.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
static bool isEmpty(const char *str)
Qt::LayoutDirection textDirection() const
Definition: qlabel.cpp:1564
const QBrush & light() const
Returns the light brush of the current color group.
Definition: qpalette.h:126
QRect documentRect() const
Definition: qlabel.cpp:1587
friend class QPixmap
Definition: qwidget.h:748
void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition: qframe.cpp:574
bool hasSelection() const
Returns true if the cursor contains a selection; otherwise returns false.
void drawPicture(const QPointF &p, const QPicture &picture)
Replays the given picture at the given point.
Definition: qpainter.cpp:7282
The QStyleOption class stores the parameters used by QStyle functions.
Definition: qstyleoption.h:67
QPalette::ColorRole foregroundRole() const
Returns the foreground role.
Definition: qwidget.cpp:4728
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
void setScaledContents(bool)
Definition: qlabel.cpp:1549
QString & setNum(short, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.h:729
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
The QTextCursor class offers an API to access and modify QTextDocuments.
Definition: qtextcursor.h:70
int margin() const
int width() const
QString text() const
void initFrom(const QWidget *w)
Definition: qstyleoption.h:99
void setTop(int pos)
Sets the top edge of the rectangle to the given y coordinate.
Definition: qrect.h:261
QRect boundingRect() const
Returns the picture&#39;s bounding rectangle or an invalid rectangle if the picture contains no data...
Definition: qpicture.cpp:385
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
const char * name
bool isRightToLeft() const
Returns true if the string is read right to left.
Definition: qstring.cpp:7528
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
#define emit
Definition: qobjectdefs.h:76
void linkActivated(const QString &link)
This signal is emitted when the user clicks a link.
void adjust(int x1, int y1, int x2, int y2)
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
Definition: qrect.h:434
void setRight(int pos)
Sets the right edge of the rectangle to the given x coordinate.
Definition: qrect.h:264
const QPalette & palette() const
LayoutDirection
Definition: qnamespace.h:1580
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
void ensureTextLayouted() const
Definition: qlabel.cpp:1650
const QPicture * picture() const
Returns the label&#39;s picture or 0 if the label doesn&#39;t have a picture.
Definition: qlabel.cpp:163
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
QString accessibleName() const
void drawFrame(QPainter *)
em>Reimplemented Function
Definition: qframe.cpp:538
QRectF layoutRect() const
Definition: qlabel.cpp:1735
void setHtml(const QString &html)
Replaces the entire contents of the document with the given HTML-formatted text in the html string...
void setMovie(QMovie *movie)
Sets the label contents to movie.
Definition: qlabel.cpp:1385
int position() const
Returns the absolute position of the cursor within the document.
void linkHovered(const QString &link)
This signal is emitted when the user hovers over a link.
QRect toRect() const
Returns a QRect based on the values of this rectangle.
Definition: qrect.h:845
QRect rect() const
int heightForWidth(int) const
Reimplemented Function
Definition: qlabel.cpp:765
bool isEnabled() const
Definition: qwidget.h:948
void clearSelection()
Clears the current selection by setting the anchor to the cursor position.
void _q_movieUpdated(const QRect &)
Definition: qlabel.cpp:1344
TextFormat
Definition: qnamespace.h:1310
void setMouseTracking(bool enable)
Definition: qwidget.h:990
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
void focusInEvent(QFocusEvent *ev)
Reimplemented Function
Definition: qlabel.cpp:1034
QMovie * movie() const
Returns a pointer to the label&#39;s movie, or 0 if no movie has been set.
Definition: qlabel.cpp:1468
QPalette palette
the palette that should be used when painting the control
Definition: qstyleoption.h:92
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition: qstring.h:505
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
virtual void drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, const QPixmap &pixmap) const
Draws the given pixmap in the specified rectangle, according to the specified alignment, using the provided painter.
Definition: qstyle.cpp:570
void setFocus()
Gives the keyboard input focus to this widget (or its focus proxy) if this widget or one of its paren...
Definition: qwidget.h:432
int shortcutId()
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qevent.h:683
void ensureTextControl() const
Definition: qlabel.cpp:1676
void keyPressEvent(QKeyEvent *ev)
em>Reimplemented Function
Definition: qlabel.cpp:1077
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
void init()
Definition: qlabel.cpp:292
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
static Qt::Alignment visualAlignment(Qt::LayoutDirection direction, Qt::Alignment alignment)
Transforms an alignment of Qt::AlignLeft or Qt::AlignRight without Qt::AlignAbsolute into Qt::AlignLe...
Definition: qstyle.cpp:2149
void setBuddy(QWidget *)
Sets this label&#39;s buddy to buddy.
Definition: qlabel.cpp:1297
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus...
Definition: qmenu.h:72
Qt::LayoutDirection layoutDirection() const
void setTextWidth(qreal width)
FocusReason
Definition: qnamespace.h:1521
Type
This enum type defines the valid event types in Qt.
Definition: qcoreevent.h:62
void setLeft(int pos)
Sets the left edge of the rectangle to the given x coordinate.
Definition: qrect.h:258
void changeEvent(QEvent *)
Reimplemented Function
Definition: qlabel.cpp:1513
bool isValid() const
Returns true if the movie is valid (e.g., the image data is readable and the image format is supporte...
Definition: qmovie.cpp:854
void setMargin(int)
Definition: qlabel.cpp:654
QTextCursor find(const QString &subString, int from=0, FindFlags options=0) const
Finds the next occurrence of the string, subString, in the document.
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
qreal x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:664
Qt::LayoutDirection textDirection() const
Returns the direction of the text layout defined by the option.
Definition: qtextoption.h:100
void sendControlEvent(QEvent *e)
Definition: qlabel.cpp:1700
void setFontUnderline(bool underline)
If underline is true, sets the text format&#39;s font to be underlined; otherwise it is displayed non-und...
Definition: qtextformat.h:432
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
void setRect(int x, int y, int w, int h)
Sets the coordinates of the rectangle&#39;s top-left corner to ({x}, {y}), and its size to the given widt...
Definition: qrect.h:400
void mouseReleaseEvent(QMouseEvent *ev)
em>Reimplemented Function
Definition: qlabel.cpp:1002
int selectionStart() const
selectionStart() returns the index of the first selected character in the label or -1 if no text is s...
Definition: qlabel.cpp:937
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
bool openExternalLinks() const
void setColor(ColorGroup cg, ColorRole cr, const QColor &color)
Sets the color in the specified color group, used for the given color role, to the specified solid co...
Definition: qpalette.h:201
bool event(QEvent *e)
Reimplemented Function
Definition: qframe.cpp:587
virtual bool focusNextPrevChild(bool next)
Finds a new widget to give the keyboard focus to, as appropriate for Tab and Shift+Tab, and returns true if it can find a new widget, or false if it can&#39;t.
Definition: qwidget.cpp:6836
The QTextFrameFormat class provides formatting information for frames in a QTextDocument.
Definition: qtextformat.h:727
The QAbstractTextDocumentLayout::PaintContext class is a convenience class defining the parameters us...
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
void setWidth(int w)
Sets the width of the rectangle to the given width.
Definition: qrect.h:442
int & rheight()
Returns a reference to the height.
Definition: qsize.h:144
void setUndoRedoEnabled(bool enable)
int height() const
Returns the height.
Definition: qsize.h:129
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
Definition: qnamespace.h:54
The QLabel widget provides a text or image display.
Definition: qlabel.h:55
Qt::FocusReason reason()
Definition: qevent.cpp:1197
The QTextOption class provides a description of general rich text properties.
Definition: qtextoption.h:59
MovieState state() const
Returns the current state of QMovie.
Definition: qmovie.cpp:778
qint64 cacheKey() const
Returns a number that identifies this QPixmap.
Definition: qpixmap.cpp:1136
bool movePosition(MoveOperation op, MoveMode=MoveAnchor, int n=1)
Moves the cursor by performing the given operation n times, using the specified mode, and returns true if all operations were completed successfully; otherwise returns false.
QRect rect() const
Returns the pixmap&#39;s enclosing rectangle.
Definition: qpixmap.cpp:676
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
Definition: qwidget.cpp:11087
int lineSpacing() const
Returns the distance from one base line to the next.
QWidget * window() const
Returns the window for this widget, i.e.
Definition: qwidget.cpp:4492
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
void setPosition(int pos, MoveMode mode=MoveAnchor)
Moves the cursor to the absolute position in the document specified by pos using a MoveMode specified...
void paintEvent(QPaintEvent *)
This event handler can be reimplemented in a subclass to receive paint events passed in event...
Definition: qlabel.cpp:1123
The QTextDocument class holds formatted text that can be viewed and edited using a QTextEdit...
void scale(qreal sx, qreal sy)
Scales the coordinate system by ({sx}, {sy}).
Definition: qpainter.cpp:3234
void setSelection(int, int)
Selects text from position start and for length characters.
Definition: qlabel.cpp:860
void setMargin(qreal margin)
Sets the frame&#39;s margin in pixels.
void setWrapMode(WrapMode wrap)
Sets the option&#39;s text wrap mode to the given mode.
Definition: qtextoption.h:109
QLayout * layout() const
Returns the layout manager that is installed on this widget, or 0 if no layout manager is installed...
Definition: qwidget.cpp:10073
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Definition: qcoreevent.h:310
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
Definition: qcoreevent.h:309
const QFont & font() const
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
bool isAmbiguous()
Definition: qevent.h:685
void updateLabel()
Updates the label, but not the frame.
Definition: qlabel.cpp:1253
const QPoint & globalPos() const
Returns the global position of the mouse pointer at the time of the event.
Definition: qevent.h:413
QString selectedText() const
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
QRectF translated(qreal dx, qreal dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
Definition: qrect.h:740
void deleteChar()
If there is no selected text, deletes the character at the current cursor position; otherwise deletes...
The QPaintEvent class contains event parameters for paint events.
Definition: qevent.h:298
void translate(int dx, int dy)
Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position...
Definition: qrect.h:312
QTextOption defaultTextOption() const
the default text option will be set on all QTextLayout in the document.
static void setLayoutItemMargins(int left, int top, int right, int bottom, QRect *rect, Qt::LayoutDirection dir)
The QPicture class is a paint device that records and replays QPainter commands.
Definition: qpicture.h:58
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
The QFrame class is the base class of widgets that can have a frame.
Definition: qframe.h:55
QSize minimumSizeHint() const
Reimplemented Function
Definition: qlabel.cpp:958
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
void setFrameFormat(const QTextFrameFormat &format)
Sets the frame&#39;s format.
Definition: qtextobject.h:191
void setAlignment(Qt::Alignment)
Without this function, a call to e.
Definition: qlabel.cpp:532
QTextFrameFormat frameFormat() const
Returns the frame&#39;s format.
Definition: qtextobject.h:131
virtual void focusInEvent(QFocusEvent *)
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus receive...
Definition: qwidget.cpp:9431
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
The QFocusEvent class contains event parameters for widget focus events.
Definition: qevent.h:275
static bool isNull(const QVariant::Private *d)
Definition: qvariant.cpp:300
int open(const char *, int,...)
int & rwidth()
Returns a reference to the width.
Definition: qsize.h:141
virtual void draw(QPainter *painter, const PaintContext &context)=0
Draws the layout with the given painter using the given context.
void setFocusPolicy(Qt::FocusPolicy policy)
Definition: qwidget.cpp:7631
void setIndent(int)
Definition: qlabel.cpp:620
void animateClick(int msec=100)
Performs an animated click: the button is pressed immediately, and released msec milliseconds later (...
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288
The QAbstractTextDocumentLayout class is an abstract base class used to implement custom layouts for ...
void clear()
Clears any label contents.
Definition: qlabel.cpp:420
void translate(const QPointF &offset)
Translates the coordinate system by the given offset; i.e.
Definition: qpainter.cpp:3311
void contextMenuEvent(QContextMenuEvent *ev)
This event handler, for event event, can be reimplemented in a subclass to receive widget context men...
Definition: qlabel.cpp:1010