55 #include "private/qstylesheetstyle_p.h" 58 #ifndef QT_NO_ACCESSIBILITY 63 #include "private/qt_s60_p.h" 157 #ifndef QT_NO_PICTURE 268 QWidget *parent,
const char *
name, Qt::WindowFlags f)
275 #ifndef QT_NO_SHORTCUT 301 #ifndef QT_NO_SHORTCUT 307 #ifndef QT_NO_PICTURE 312 scaledcontents =
false;
313 textLayoutDirty =
false;
377 d->isTextLabel =
true;
382 d->control = oldControl;
384 if (
d->needTextControl()) {
385 d->ensureTextControl();
397 #ifndef QT_NO_SHORTCUT 404 #ifndef QT_NO_ACCESSIBILITY 442 if (!
d->pixmap ||
d->pixmap->cacheKey() != pixmap.
cacheKey()) {
447 if (
d->pixmap->depth() == 1 && !
d->pixmap->mask())
448 d->pixmap->setMask(*((
QBitmap *)
d->pixmap));
459 #ifndef QT_NO_PICTURE 477 #endif // QT_NO_PICTURE 657 if (
d->margin == margin)
670 if(q->minimumWidth() > 0)
671 w =
qMax(w, q->minimumWidth());
672 QSize contentsMargin(leftmargin + rightmargin, topmargin + bottommargin);
682 #ifndef QT_NO_PICTURE 690 else if (isTextLabel) {
705 ensureTextLayouted();
706 const qreal oldTextWidth = control->textWidth();
710 w =
qMax(w-hextra-contentsMargin.
width(), 0);
711 control->setTextWidth(w);
713 control->adjustSize();
716 control->setTextWidth(-1);
719 QSizeF controlSize = control->size();
723 control->setTextWidth(oldTextWidth);
739 w =
qMin(S60->clientRect().Width(), q->maximumSize().width());
745 w -= (hextra + contentsMargin.
width());
757 return (contentsSize + contentsMargin).
expandedTo(q->minimumSize());
769 return d->sizeForWidth(w).height();
794 return d->openExternalLinks;
800 d->openExternalLinks =
open;
802 d->control->setOpenExternalLinks(open);
823 if (
d->textInteractionFlags == flags)
825 d->textInteractionFlags = flags;
833 if (
d->needTextControl()) {
834 d->ensureTextControl();
841 d->control->setTextInteractionFlags(
d->textInteractionFlags);
847 return d->textInteractionFlags;
864 d->ensureTextPopulated();
868 d->control->setTextCursor(cursor);
895 return d->control->textCursor().hasSelection();
922 return d->control->textCursor().selectedText();
940 if (
d->control &&
d->control->textCursor().hasSelection())
941 return d->control->textCursor().selectionStart();
961 if (
d->valid_hints) {
967 d->valid_hints =
true;
968 d->sh =
d->sizeForWidth(-1);
971 if (!
d->isTextLabel) {
975 msh.
rwidth() =
d->sizeForWidth(0).width();
976 if (
d->sh.height() < msh.
height())
989 d->sendControlEvent(ev);
997 d->sendControlEvent(ev);
1005 d->sendControlEvent(ev);
1012 #ifdef QT_NO_CONTEXTMENU 1016 if (!
d->isTextLabel) {
1020 QMenu *menu =
d->createStandardContextMenu(ev->
pos());
1037 if (
d->isTextLabel) {
1038 d->ensureTextControl();
1039 d->sendControlEvent(ev);
1051 d->sendControlEvent(ev);
1058 d->control->setTextCursor(cursor);
1070 if (
d->control &&
d->control->setFocusToNextOrPreviousAnchor(next))
1080 d->sendControlEvent(ev);
1090 #ifndef QT_NO_SHORTCUT 1108 d->textLayoutDirty =
true;
1130 cr.
adjust(
d->margin,
d->margin, -
d->margin, -
d->margin);
1136 if (
d->scaledcontents)
1139 style->
drawItemPixmap(&painter, cr, align,
d->movie->currentPixmap());
1143 if (
d->isTextLabel) {
1144 QRectF lr =
d->layoutRect().toAlignedRect();
1147 #ifndef QT_NO_STYLE_STYLESHEET 1149 cssStyle->styleSheetPalette(
this, &opt, &opt.
palette);
1153 #ifndef QT_NO_SHORTCUT 1155 if (
d->shortcutId != 0
1156 && underline !=
d->shortcutCursor.charFormat().fontUnderline()) {
1159 d->shortcutCursor.mergeCharFormat(fmt);
1162 d->ensureTextLayouted();
1175 layout->
draw(&painter, context);
1188 d->control->setPalette(context.
palette);
1189 d->control->drawContents(&painter,
QRectF(),
this);
1194 if (
d->hasShortcut) {
1202 #ifndef QT_NO_PICTURE 1204 QRect br =
d->picture->boundingRect();
1205 int rw = br.
width();
1207 if (
d->scaledcontents) {
1223 xo = (cr.
width()-rw)/2;
1228 if (
d->pixmap && !
d->pixmap->isNull()) {
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;
1237 pix = *
d->scaledpixmap;
1256 valid_hints =
false;
1262 if (policy != q->sizePolicy())
1263 q->setSizePolicy(policy);
1264 textLayoutDirty =
true;
1266 q->updateGeometry();
1267 q->update(q->contentsRect());
1270 #ifndef QT_NO_SHORTCUT 1301 if (
d->isTextLabel) {
1305 d->textDirty =
true;
1307 d->updateShortcut();
1333 hasShortcut =
false;
1341 #endif // QT_NO_SHORTCUT 1349 if (scaledcontents) {
1350 QRect cr = q->contentsRect();
1352 if (pixmapRect.isEmpty())
1355 (rect.
width() * cr.
width()) / pixmapRect.width(),
1371 valid_hints =
false;
1373 q->updateGeometry();
1403 #endif // QT_NO_MOVIE 1418 isTextLabel =
false;
1419 hasShortcut =
false;
1421 #ifndef QT_NO_PICTURE 1425 delete scaledpixmap;
1434 #ifndef QT_NO_SHORTCUT 1436 q->releaseShortcut(shortcutId);
1446 #ifndef QT_NO_CURSOR 1453 validCursor =
false;
1474 #endif // QT_NO_MOVIE 1494 return d->textformat;
1500 if (format !=
d->textformat) {
1517 if (
d->isTextLabel) {
1519 d->control->document()->setDefaultFont(
font());
1546 return d->scaledcontents;
1552 if ((
bool)
d->scaledcontents == enable)
1554 d->scaledcontents = enable;
1556 delete d->scaledpixmap;
1557 d->scaledpixmap = 0;
1558 delete d->cachedimage;
1567 QTextOption opt = control->document()->defaultTextOption();
1590 Q_ASSERT_X(isTextLabel,
"documentRect",
"document rect called for label that is not a text label!");
1591 QRect cr = q->contentsRect();
1594 : q->layoutDirection(),
QFlag(this->align));
1618 #ifndef QT_NO_TEXTHTMLPARSER 1628 #ifndef QT_NO_SHORTCUT 1652 if (!textLayoutDirty)
1654 ensureTextPopulated();
1673 textLayoutDirty =
false;
1683 control->document()->setUndoRedoEnabled(
false);
1684 control->document()->setDefaultFont(q->font());
1687 control->setPalette(q->palette());
1688 control->setFocus(q->hasFocus());
1695 textLayoutDirty =
true;
1707 control->processEvent(e, -layoutRect().topLeft(), q);
1713 #ifndef QT_NO_CURSOR 1720 }
else if (!onAnchor) {
1729 emit q->linkHovered(anchor);
1737 QRectF cr = documentRect();
1740 ensureTextLayouted();
1742 qreal rh = control->document()->documentLayout()->documentSize().height();
1754 QRect lr = layoutRect().toRect();
1758 #ifndef QT_NO_CONTEXTMENU 1763 if (control && isRichText) {
1764 p = layoutPoint(pos);
1765 linkToCopy = control->document()->documentLayout()->anchorAt(p);
1768 if (linkToCopy.
isEmpty() && !control)
1771 return control->createStandardContextMenu(p, q_func());
1804 #include "moc_qlabel.cpp"
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
The QPainter class performs low-level painting on widgets and other paint devices.
QPoint layoutPoint(const QPoint &p) const
QLabel(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs an empty label.
Qt::TextFormat textFormat() const
static void updateAccessibility(QObject *, int who, Event reason)
Notifies accessibility clients about a change in object's accessibility information.
QSize sizeForWidth(int w) const
Returns the size that will be used if the width of the label is w.
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.
qreal y() const
Returns the y-coordinate of the rectangle's top edge.
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
The QKeyEvent class describes a key event.
void setHeight(int h)
Sets the height of the rectangle to the given height.
void _q_linkHovered(const QString &link)
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
void setBottom(int pos)
Sets the bottom edge of the rectangle to the given y coordinate.
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
The QFontMetrics class provides font metrics information.
#define QT_END_NAMESPACE
This macro expands to.
const QColor & color() const
Returns the brush color.
void setTextFormat(Qt::TextFormat)
void _q_movieResized(const QSize &)
void setWordWrap(bool on)
The QMovie class is a convenience class for playing movies with QImageReader.
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
QSize size() const
Returns the size of the pixmap.
Qt::TextInteractionFlags textInteractionFlags() const
void setPicture(const QPicture &)
Sets the label contents to picture.
The QFlag class is a helper data type for QFlags.
void setText(const QString &)
~QLabel()
Destroys the label.
qreal width() const
Returns the width.
bool focusNextPrevChild(bool next)
em>Reimplemented Function
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...
const QPixmap * pixmap() const
qreal height() const
Returns the height.
void restore()
Restores the current painter state (pops a saved state off the stack).
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...
QPointF topLeft() const
Returns the position of the rectangle's top-left corner.
QSize expandedTo(const QSize &) const
Returns a size holding the maximum width and height of this size and the given otherSize.
int left() const
Returns the x-coordinate of the rectangle's left edge.
int width() const
Returns the width of the rectangle.
QSize sizeHint() const
em>Reimplemented Function
void clearContents()
Clears any contents, without updating/repainting the label.
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.
bool isNull() const
Returns true if the picture contains no data; otherwise returns false.
QMenu * createStandardContextMenu(const QPoint &pos)
int height() const
Returns the height of the rectangle.
void setTextInteractionFlags(Qt::TextInteractionFlags flags)
int bottom() const
Returns the y-coordinate of the rectangle's bottom edge.
The QString class provides a Unicode character string.
T * qobject_cast(QObject *object)
void mouseMoveEvent(QMouseEvent *ev)
em>Reimplemented Function
QPalette palette
the default color that is used for the text, when no color is specified.
void ensureTextPopulated() const
void setOpenExternalLinks(bool open)
void focusOutEvent(QFocusEvent *ev)
Reimplemented Function
const QColor & color(ColorGroup cg, ColorRole cr) const
Returns the color in the specified color group, used for the given color role.
QString selectedText() const
Returns the current selection's text (which may be empty).
The QSizeF class defines the size of a two-dimensional object using floating point precision...
void setNum(int)
Sets the label contents to plain text containing the textual representation of integer num...
bool hasScaledContents() const
void save()
Saves the current painter state (pushes the state onto a stack).
bool hasSelectedText() const
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
void mousePressEvent(QMouseEvent *ev)
em>Reimplemented Function
void setDefaultTextOption(const QTextOption &option)
Sets the default text option.
void setPixmap(const QPixmap &)
void setObjectName(const QString &name)
QFrame(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a frame widget with frame style NoFrame and a 1-pixel frame width.
QTextFrame * rootFrame() const
Returns the document's root frame.
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...
QPixmap currentPixmap() const
Returns the current frame as a QPixmap.
void setHeightForWidth(bool b)
void setPlainText(const QString &text)
Replaces the entire contents of the document with the given plain text.
The QBitmap class provides monochrome (1-bit depth) pixmaps.
int width() const
Returns the width.
void setAlignment(Qt::Alignment alignment)
Sets the option's text alignment to the specified alignment.
Qt::Alignment alignment() const
QWidget * buddy() const
Returns this label's buddy, or 0 if no buddy is currently set.
int averageCharWidth() const
Returns the average width of glyphs in the font.
#define QT_BEGIN_NAMESPACE
This macro expands to.
The QRectF class defines a rectangle in the plane using floating point precision. ...
static bool isEmpty(const char *str)
Qt::LayoutDirection textDirection() const
const QBrush & light() const
Returns the light brush of the current color group.
QRect documentRect() const
void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
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.
The QStyleOption class stores the parameters used by QStyle functions.
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...
void setScaledContents(bool)
QString & setNum(short, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
The QTextCursor class offers an API to access and modify QTextDocuments.
void initFrom(const QWidget *w)
void setTop(int pos)
Sets the top edge of the rectangle to the given y coordinate.
QRect boundingRect() const
Returns the picture's bounding rectangle or an invalid rectangle if the picture contains no data...
qreal height() const
Returns the height of the rectangle.
bool isRightToLeft() const
Returns true if the string is read right to left.
QSize size() const
Returns the size of the rectangle.
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.
void setRight(int pos)
Sets the right edge of the rectangle to the given x coordinate.
The QImage class provides a hardware-independent image representation that allows direct access to th...
void ensureTextLayouted() const
const QPicture * picture() const
Returns the label's picture or 0 if the label doesn't have a picture.
qreal width() const
Returns the width of the rectangle.
void drawFrame(QPainter *)
em>Reimplemented Function
QRectF layoutRect() const
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.
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.
int heightForWidth(int) const
Reimplemented Function
void clearSelection()
Clears the current selection by setting the anchor to the cursor position.
void _q_movieUpdated(const QRect &)
The QMouseEvent class contains parameters that describe a mouse event.
void focusInEvent(QFocusEvent *ev)
Reimplemented Function
QMovie * movie() const
Returns a pointer to the label's movie, or 0 if no movie has been set.
QPalette palette
the palette that should be used when painting the control
bool isNull() const
Returns true if this string is null; otherwise returns false.
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.
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.
int shortcutId()
This is an overloaded member function, provided for convenience. It differs from the above function o...
void ensureTextControl() const
void keyPressEvent(QKeyEvent *ev)
em>Reimplemented Function
#define Q_ASSERT_X(cond, where, what)
int top() const
Returns the y-coordinate of the rectangle's top edge.
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...
void setBuddy(QWidget *)
Sets this label's buddy to buddy.
int right() const
Returns the x-coordinate of the rectangle's right edge.
void setTextWidth(qreal width)
Type
This enum type defines the valid event types in Qt.
void setLeft(int pos)
Sets the left edge of the rectangle to the given x coordinate.
void changeEvent(QEvent *)
Reimplemented Function
bool isValid() const
Returns true if the movie is valid (e.g., the image data is readable and the image format is supporte...
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's top edge.
void clear()
Clears the contents of the string and makes it empty.
qreal x() const
Returns the x-coordinate of the rectangle's left edge.
Qt::LayoutDirection textDirection() const
Returns the direction of the text layout defined by the option.
void sendControlEvent(QEvent *e)
void setFontUnderline(bool underline)
If underline is true, sets the text format's font to be underlined; otherwise it is displayed non-und...
int x() const
Returns the x-coordinate of the rectangle's left edge.
QObject * parent() const
Returns a pointer to the parent object.
void setRect(int x, int y, int w, int h)
Sets the coordinates of the rectangle's top-left corner to ({x}, {y}), and its size to the given widt...
void mouseReleaseEvent(QMouseEvent *ev)
em>Reimplemented Function
int selectionStart() const
selectionStart() returns the index of the first selected character in the label or -1 if no text is s...
The QPoint class defines a point in the plane using integer precision.
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...
bool event(QEvent *e)
Reimplemented Function
The QTextFrameFormat class provides formatting information for frames in a QTextDocument.
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...
void setWidth(int w)
Sets the width of the rectangle to the given width.
int & rheight()
Returns a reference to the height.
void setUndoRedoEnabled(bool enable)
int height() const
Returns the height.
The QRect class defines a rectangle in the plane using integer precision.
The QLabel widget provides a text or image display.
The QTextOption class provides a description of general rich text properties.
MovieState state() const
Returns the current state of QMovie.
qint64 cacheKey() const
Returns a number that identifies this QPixmap.
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's enclosing rectangle.
int lineSpacing() const
Returns the distance from one base line to the next.
The QPixmap class is an off-screen image representation that can be used as a paint device...
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...
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}).
void setSelection(int, int)
Selects text from position start and for length characters.
void setMargin(qreal margin)
Sets the frame's margin in pixels.
void setWrapMode(WrapMode wrap)
Sets the option's text wrap mode to the given mode.
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
The QSize class defines the size of a two-dimensional object using integer point precision.
void updateLabel()
Updates the label, but not the frame.
QString selectedText() const
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
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...
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.
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...
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.
The QEvent class is the base class of all event classes.
Type type() const
Returns the event type.
The QFrame class is the base class of widgets that can have a frame.
QSize minimumSizeHint() const
Reimplemented Function
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
void setFrameFormat(const QTextFrameFormat &format)
Sets the frame's format.
void setAlignment(Qt::Alignment)
Without this function, a call to e.
QTextFrameFormat frameFormat() const
Returns the frame's format.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
The QFocusEvent class contains event parameters for widget focus events.
static bool isNull(const QVariant::Private *d)
int open(const char *, int,...)
int & rwidth()
Returns a reference to the width.
virtual void draw(QPainter *painter, const PaintContext &context)=0
Draws the layout with the given painter using the given context.
QPoint topLeft() const
Returns the position of the rectangle's top-left corner.
The QAbstractTextDocumentLayout class is an abstract base class used to implement custom layouts for ...
void clear()
Clears any label contents.
void translate(const QPointF &offset)
Translates the coordinate system by the given offset; i.e.
void contextMenuEvent(QContextMenuEvent *ev)
This event handler, for event event, can be reimplemented in a subclass to receive widget context men...