Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qframe.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qframe.h"
5#include "qbitmap.h"
6#include "qdrawutil.h"
7#include "qevent.h"
8#include "qpainter.h"
9#include "qstyle.h"
10#include "qstyleoption.h"
11#include "qstylepainter.h"
12#include "qapplication.h"
13
14#include "qframe_p.h"
15
17
19 : frect(0, 0, 0, 0),
20 frameStyle(QFrame::NoFrame | QFrame::Plain),
21 lineWidth(1),
22 midLineWidth(0),
23 frameWidth(0),
24 leftFrameWidth(0), rightFrameWidth(0),
25 topFrameWidth(0), bottomFrameWidth(0)
26{
27}
28
32
37
165QFrame::QFrame(QWidget* parent, Qt::WindowFlags f)
166 : QWidget(*new QFramePrivate, parent, f)
167{
168 Q_D(QFrame);
169 d->init();
170}
171
173QFrame::QFrame(QFramePrivate &dd, QWidget* parent, Qt::WindowFlags f)
174 : QWidget(dd, parent, f)
175{
176 Q_D(QFrame);
177 d->init();
178}
179
190{
191 if (!option)
192 return;
193
194 Q_D(const QFrame);
195 option->initFrom(this);
196
197 int frameShape = d->frameStyle & QFrame::Shape_Mask;
198 int frameShadow = d->frameStyle & QFrame::Shadow_Mask;
199 option->frameShape = Shape(int(option->frameShape) | frameShape);
200 option->rect = frameRect();
201 switch (frameShape) {
202 case QFrame::Box:
203 case QFrame::HLine:
204 case QFrame::VLine:
206 case QFrame::Panel:
207 option->lineWidth = d->lineWidth;
208 option->midLineWidth = d->midLineWidth;
209 break;
210 default:
211 // most frame styles do not handle customized line and midline widths
212 // (see updateFrameWidth()).
213 option->lineWidth = d->frameWidth;
214 break;
215 }
216
217 if (frameShadow == Sunken)
219 else if (frameShadow == Raised)
221}
222
223
228{
229}
230
239{
240 Q_D(const QFrame);
241 return d->frameStyle;
242}
243
252{
253 Q_D(const QFrame);
254 return (Shape) (d->frameStyle & Shape_Mask);
255}
256
258{
259 Q_D(QFrame);
260 setFrameStyle((d->frameStyle & Shadow_Mask) | s);
261}
262
263
271{
272 Q_D(const QFrame);
273 return (Shadow) (d->frameStyle & Shadow_Mask);
274}
275
277{
278 Q_D(QFrame);
279 setFrameStyle((d->frameStyle & Shape_Mask) | s);
280}
281
301{
302 Q_D(QFrame);
305
306 switch (style & Shape_Mask) {
307 case HLine:
309 break;
310 case VLine:
312 break;
313 default:
315 }
318 }
319 d->frameStyle = (short)style;
320 update();
321 d->updateFrameWidth();
322}
323
337{
338 Q_D(QFrame);
339 if (short(w) == d->lineWidth)
340 return;
341 d->lineWidth = short(w);
342 d->updateFrameWidth();
343}
344
346{
347 Q_D(const QFrame);
348 return d->lineWidth;
349}
350
361{
362 Q_D(QFrame);
363 if (short(w) == d->midLineWidth)
364 return;
365 d->midLineWidth = short(w);
366 d->updateFrameWidth();
367}
368
370{
371 Q_D(const QFrame);
372 return d->midLineWidth;
373}
374
380{
381 Q_Q(const QFrame);
383 q->initStyleOption(&opt);
384
385 QRect cr = q->style()->subElementRect(QStyle::SE_ShapedFrameContents, &opt, q);
386 leftFrameWidth = cr.left() - opt.rect.left();
387 topFrameWidth = cr.top() - opt.rect.top();
392}
393
400{
401 Q_Q(QFrame);
402 QRect fr = q->frameRect();
404 q->setFrameRect(fr);
406}
407
420{
421 Q_D(const QFrame);
422 return d->frameWidth;
423}
424
425
441{
442 Q_D(const QFrame);
443 QRect fr = contentsRect();
444 fr.adjust(-d->leftFrameWidth, -d->topFrameWidth, d->rightFrameWidth, d->bottomFrameWidth);
445 return fr;
446}
447
449{
450 Q_D(QFrame);
451 QRect cr = r.isValid() ? r : rect();
452 cr.adjust(d->leftFrameWidth, d->topFrameWidth, -d->rightFrameWidth, -d->bottomFrameWidth);
453 setContentsMargins(cr.left(), cr.top(), rect().right() - cr.right(), rect().bottom() - cr.bottom());
454}
455
459{
460 Q_D(const QFrame);
461 // Returns a size hint for the frame - for HLine and VLine
462 // shapes, this is stretchable one way and 3 pixels wide the
463 // other. For other shapes, QWidget::sizeHint() is used.
464 switch (d->frameStyle & Shape_Mask) {
465 case HLine:
466 return QSize(-1,3);
467 case VLine:
468 return QSize(3,-1);
469 default:
470 return QWidget::sizeHint();
471 }
472}
473
478{
479 QStylePainter p(this);
480 drawFrame(&p);
481}
482
494
495
499{
500 Q_D(QFrame);
501 if (ev->type() == QEvent::StyleChange
502#ifdef Q_OS_MAC
503 || ev->type() == QEvent::MacSizeChange
504#endif
505 )
506 d->updateFrameWidth();
508}
509
512{
513 if (e->type() == QEvent::ParentChange)
514 d_func()->updateFrameWidth();
515 bool result = QWidget::event(e);
516 //this has to be done after the widget has been polished
517 if (e->type() == QEvent::Polish)
518 d_func()->updateFrameWidth();
519 return result;
520}
521
523
524#include "moc_qframe.cpp"
\inmodule QtCore
Definition qcoreevent.h:45
@ ParentChange
Definition qcoreevent.h:80
@ StyleChange
Definition qcoreevent.h:136
@ MacSizeChange
Definition qcoreevent.h:217
Type type() const
Returns the event type.
Definition qcoreevent.h:304
short frameWidth
Definition qframe_p.h:38
short topFrameWidth
Definition qframe_p.h:40
void updateStyledFrameWidths()
Definition qframe.cpp:379
short bottomFrameWidth
Definition qframe_p.h:40
void updateFrameWidth()
Definition qframe.cpp:399
void init()
Definition qframe.cpp:33
short rightFrameWidth
Definition qframe_p.h:39
short leftFrameWidth
Definition qframe_p.h:39
The QFrame class is the base class of widgets that can have a frame.
Definition qframe.h:17
~QFrame()
Destroys the frame.
Definition qframe.cpp:227
Shadow
This enum type defines the types of shadow that are used to give a 3D effect to frames.
Definition qframe.h:48
@ Raised
Definition qframe.h:50
@ Sunken
Definition qframe.h:51
QSize sizeHint() const override
\reimp
Definition qframe.cpp:458
Shadow frameShadow
the frame shadow value from the frame style
Definition qframe.h:21
QRect frameRect
the frame's rectangle
Definition qframe.h:25
int midLineWidth
the width of the mid-line
Definition qframe.h:23
int frameWidth
the width of the frame that is drawn.
Definition qframe.h:24
@ Shadow_Mask
Definition qframe.h:56
@ Shape_Mask
Definition qframe.h:57
bool event(QEvent *e) override
\reimp
Definition qframe.cpp:511
void drawFrame(QPainter *)
Definition qframe.cpp:488
void setFrameShape(Shape)
Definition qframe.cpp:257
void setFrameStyle(int)
Sets the frame style to style.
Definition qframe.cpp:300
virtual void initStyleOption(QStyleOptionFrame *option) const
Definition qframe.cpp:189
int frameStyle() const
Returns the frame style.
Definition qframe.cpp:238
void paintEvent(QPaintEvent *) override
\reimp
Definition qframe.cpp:477
void setLineWidth(int)
Definition qframe.cpp:336
QFrame(QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags())
Constructs a frame widget with frame style \l NoFrame and a 1-pixel frame width.
Definition qframe.cpp:165
Shape
This enum type defines the shapes of frame available.
Definition qframe.h:38
@ Panel
Definition qframe.h:41
@ HLine
Definition qframe.h:43
@ StyledPanel
Definition qframe.h:45
@ Box
Definition qframe.h:40
@ VLine
Definition qframe.h:44
int lineWidth
the line width
Definition qframe.h:22
void changeEvent(QEvent *) override
\reimp
Definition qframe.cpp:498
void setFrameShadow(Shadow)
Definition qframe.cpp:276
void setFrameRect(const QRect &)
Definition qframe.cpp:448
void setMidLineWidth(int)
Definition qframe.cpp:360
Shape frameShape
the frame shape value from the frame style
Definition qframe.h:20
The QPaintEvent class contains event parameters for paint events.
Definition qevent.h:486
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr void adjust(int x1, int y1, int x2, int y2) noexcept
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
Definition qrect.h:373
constexpr bool isValid() const noexcept
Returns true if the rectangle is valid, otherwise returns false.
Definition qrect.h:170
constexpr int bottom() const noexcept
Returns the y-coordinate of the rectangle's bottom edge.
Definition qrect.h:182
constexpr int top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:176
constexpr int left() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:173
constexpr int right() const noexcept
Returns the x-coordinate of the rectangle's right edge.
Definition qrect.h:179
The QSizePolicy class is a layout attribute describing horizontal and vertical resizing policy.
Definition qsizepolicy.h:18
\inmodule QtCore
Definition qsize.h:25
\variable QStyleOptionFocusRect::backgroundColor
The QStylePainter class is a convenience class for drawing QStyle elements inside a widget.
@ State_Sunken
Definition qstyle.h:69
@ State_Raised
Definition qstyle.h:68
@ CE_ShapedFrame
Definition qstyle.h:232
virtual void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w=nullptr) const =0
Draws the given element with the provided painter with the style options specified by option.
@ SE_ShapedFrameContents
Definition qstyle.h:312
@ SE_FrameLayoutItem
Definition qstyle.h:300
void setLayoutItemMargins(int left, int top, int right, int bottom)
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
void setContentsMargins(int left, int top, int right, int bottom)
Sets the margins around the contents of the widget to have the sizes left, top, right,...
Definition qwidget.cpp:7590
void setSizePolicy(QSizePolicy)
QRect contentsRect() const
Returns the area inside the widget's margins.
Definition qwidget.cpp:7667
QRect rect
the internal geometry of the widget excluding any window frame
Definition qwidget.h:116
void update()
Updates the widget unless updates are disabled or the widget is hidden.
virtual void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition qwidget.cpp:9382
QSize sizeHint
the recommended size for the widget
Definition qwidget.h:148
bool event(QEvent *event) override
This is the main event handler; it handles event event.
Definition qwidget.cpp:8866
QStyle * style() const
Definition qwidget.cpp:2600
bool testAttribute(Qt::WidgetAttribute) const
Returns true if attribute attribute is set on this widget; otherwise returns false.
Definition qwidget.h:910
QStyleOptionButton opt
Combined button and popup list for selecting options.
@ WA_WState_OwnSizePolicy
Definition qnamespace.h:334
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
GLfloat GLfloat GLfloat w
[0]
GLboolean r
[2]
GLdouble GLdouble right
GLfloat GLfloat f
GLint GLint bottom
GLdouble s
[6]
Definition qopenglext.h:235
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLuint64EXT * result
[6]
GLfloat GLfloat p
[1]
GLuint GLenum option
#define sp