6#include <QtCore/qscopedvaluerollback.h>
7#include <QtCore/qdir.h>
9#include <QtQuick/qsgninepatchnode.h>
10#include <QtQuick/private/qquickwindow_p.h>
11#include <QtQuick/qquickwindow.h>
12#include <QtQuick/qquickrendercontrol.h>
14#include <QtQuickTemplates2/private/qquickcontrol_p.h>
15#include <QtQuickTemplates2/private/qquickbutton_p.h>
17#include <QtQml/qqml.h>
28 debug <<
"StyleMargins(";
41 debug <<
"StyleItemGeometry(";
51int QQuickStyleItem::dprAlignedSize(
const int size)
const
55 static int multiplier = [&]() {
57 for (
int m = 1;
m <= 10; ++
m) {
63 qWarning() <<
"The current dpr (" <<
dpr <<
") is not supported"
64 <<
"by the style and might result in drawing artifacts";
88 m_connectedWindow =
win;
110 node =
window()->createNinePatchNode();
112 if (m_paintedImage.
isNull()) {
119 const auto texture =
window()->createTextureFromImage(m_paintedImage, QQuickWindow::TextureCanUseAtlas);
129 if (bounds.
width() < unscaledImageSize.
width())
135 if (m_debugFlags.testFlag(Unscaled)) {
136 bounds.
setSize(unscaledImageSize);
137 qqc2Info() <<
"Setting qsg node size to the unscaled size of m_paintedImage:" << bounds;
141 if (m_useNinePatchImage) {
143 if (padding.
right() == -1) {
149 if (padding.
bottom() == -1) {
167 if (
item->metaObject()->indexOfProperty(
"qqc2_style_small") != -1)
169 if (
item->metaObject()->indexOfProperty(
"qqc2_style_mini") != -1)
177 return renderWindow ? renderWindow :
window;
197 if (styleOption.
window->isActive())
244 if (m_connectedWindow)
248 m_connectedWindow =
win;
266void QQuickStyleItem::updateGeometry()
279 qmlWarning(
this) <<
"(StyleItem) minimumSize is empty!";
286 qqc2Info() <<
"implicitSize is empty, using minimumSize instead";
291 qmlWarning(
this) <<
"(StyleItem) implicit width is smaller than minimum width!";
293 qmlWarning(
this) <<
"(StyleItem) implicit height is smaller than minimum height!";
309 <<
"input content size:" << m_contentSize;
312void QQuickStyleItem::paintControlToImage()
333 const int alignedW = int(dprAlignedSize(imgSize.
width()) *
dpr);
334 const int alignedH = int(dprAlignedSize(imgSize.
height()) *
dpr);
335 const QSize alignedSize =
QSize(alignedW, alignedH);
337 if (m_paintedImage.
size() != alignedSize) {
340 qqc2Info() <<
"created image with dpr aligned size:" << alignedSize;
349 if (m_debugFlags != NoDebug) {
351 if (m_debugFlags.testFlag(ImageRect))
353 if (m_debugFlags.testFlag(LayoutRect)) {
356 rect.adjust(
m.left(),
m.top(), -
m.right(), -
m.bottom());
359 if (m_debugFlags.testFlag(ContentRect)) {
362 rect.adjust(
p.left(),
p.top(), -
p.right(), -
p.bottom());
365 if (m_debugFlags.testFlag(InputContentSize)) {
371 if (m_debugFlags.testFlag(NinePatchMargins)) {
373 if (
m.right() != -1) {
377 if (
m.bottom() != -1) {
382 if (m_debugFlags.testFlag(SaveImage)) {
407 paintControlToImage();
411void QQuickStyleItem::addDebugInfo()
419 static const auto matchAll = debugString.startsWith(
QLatin1String(
"All "));
421 if (debugString.isEmpty())
427 const bool matchType = debugString.startsWith(
typeName);
429 if (!(matchAll || matchName || matchType))
432#define QQC2_DEBUG_FLAG(FLAG) \
433 if (debugString.contains(QLatin1String(#FLAG), Qt::CaseInsensitive)) m_debugFlags |= FLAG
435 QQC2_DEBUG_FLAG(
Info);
436 QQC2_DEBUG_FLAG(ImageRect);
437 QQC2_DEBUG_FLAG(ContentRect);
438 QQC2_DEBUG_FLAG(LayoutRect);
439 QQC2_DEBUG_FLAG(InputContentSize);
440 QQC2_DEBUG_FLAG(DontUseNinePatchImage);
441 QQC2_DEBUG_FLAG(NinePatchMargins);
442 QQC2_DEBUG_FLAG(Unscaled);
443 QQC2_DEBUG_FLAG(Debug);
444 QQC2_DEBUG_FLAG(SaveImage);
446 if (m_debugFlags & (DontUseNinePatchImage
450 | NinePatchMargins)) {
453 m_debugFlags |= DontUseNinePatchImage;
454 m_useNinePatchImage =
false;
457 if (m_debugFlags != NoDebug)
460 qDebug() <<
"available debug options:" << DebugFlags(0xFFFF);
478 return m_contentSize.
width();
492 return m_contentSize.
height();
563#include "moc_qquickstyleitem.cpp"
The QColor class provides colors based on RGB, HSV or CMYK values.
static QDir current()
Returns the application's current directory.
QString absoluteFilePath(const QString &fileName) const
Returns the absolute path name of a file in the directory.
@ ApplicationPaletteChange
static QFont font()
Returns the default application font.
QSize size() const
Returns the size of the image, i.e.
bool save(const QString &fileName, const char *format=nullptr, int quality=-1) const
Saves the image to the file with the given fileName, using the given image file format and quality fa...
bool isNull() const
Returns true if it is a null image, otherwise returns false.
@ Format_ARGB32_Premultiplied
void fill(uint pixel)
Fills the entire image with the given pixelValue.
void setDevicePixelRatio(qreal scaleFactor)
Sets the device pixel ratio for the image.
constexpr void setTop(int top) noexcept
Sets the Top margin to Top.
constexpr int bottom() const noexcept
Returns the bottom margin.
constexpr void setBottom(int bottom) noexcept
Sets the bottom margin to bottom.
constexpr void setLeft(int left) noexcept
Sets the left margin to left.
constexpr int left() const noexcept
Returns the left margin.
constexpr int right() const noexcept
Returns the right margin.
constexpr int top() const noexcept
Returns the top margin.
constexpr void setRight(int right) noexcept
Sets the right margin to right.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
QString objectName
the name of this object
The QPainter class performs low-level painting on widgets and other paint devices.
void drawRect(const QRectF &rect)
Draws the current rectangle with the current pen and brush.
void setPen(const QColor &color)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void drawLine(const QLineF &line)
Draws a line defined by line.
\inmodule QtCore\reentrant
Qt::LayoutDirection direction
static QQuickItemPrivate * get(QQuickItem *item)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
bool event(QEvent *) override
\reimp
void activeFocusChanged(bool)
void setFlag(Flag flag, bool enabled=true)
Enables the specified flag for this item if enabled is true; if enabled is false, the flag is disable...
virtual void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
void componentComplete() override
\reimp Derived classes should call the base class method before adding their own actions to perform a...
bool hasActiveFocus() const
virtual QRectF boundingRect() const
Returns the extents of the item in its own coordinate system: a rectangle from {0,...
QQuickWindow * window() const
Returns the window in which this item is rendered.
virtual void itemChange(ItemChange, const ItemChangeData &)
Called when change occurs for this item.
bool isComponentComplete() const
Returns true if construction of the QML component is complete; otherwise returns false.
ItemChange
Used in conjunction with QQuickItem::itemChange() to notify the item about certain types of changes.
bool isUnderMouse() const
void update()
Schedules a call to updatePaintNode() for this item.
void polish()
Schedules a polish event for this item.
void setImplicitSize(qreal, qreal)
virtual QQuickPalette * palette() const
QPalette toQPalette() const
static QWindow * renderWindowFor(QQuickWindow *win, QPoint *offset=nullptr)
Returns the real window that win is being rendered to, if any.
virtual void connectToControl() const
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
void layoutMarginsChanged()
QQuickStyleMargins contentPadding
qreal focusFrameRadius() const
virtual StyleItemGeometry calculateGeometry()=0
OverrideState m_overrideState
virtual void paintEvent(QPainter *painter) const =0
void itemChange(ItemChange change, const ItemChangeData &data) override
Called when change occurs for this item.
void minimumSizeChanged()
virtual Q_INVOKABLE QFont styleFont(QQuickItem *control) const
layoutMarginsChangedQSize minimumSize
void updatePolish() override
This function should perform any layout as required for this item.
void setContentHeight(qreal contentHeight)
~QQuickStyleItem() override
void contentPaddingChanged()
static QStyle::State controlSize(QQuickItem *item)
contentPaddingChangedQQuickStyleMargins layoutMargins
void setContentWidth(qreal contentWidth)
void initStyleOptionBase(QStyleOption &styleOption) const
QQuickStyleItem(QQuickItem *parent=nullptr)
QSGNode * updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *updatePaintNodeData) override
Called on the render thread when it is time to sync the state of the item with the scene graph.
void componentComplete() override
\reimp Derived classes should call the base class method before adding their own actions to perform a...
bool event(QEvent *event) override
\reimp
\qmltype Window \instantiates QQuickWindow \inqmlmodule QtQuick
\inmodule QtCore\reentrant
constexpr qreal height() const noexcept
Returns the height of the rectangle.
constexpr qreal width() const noexcept
Returns the width of the rectangle.
constexpr void setWidth(qreal w) noexcept
Sets the width of the rectangle to the given finite width.
constexpr void setSize(const QSizeF &s) noexcept
Sets the size of the rectangle to the given finite size.
constexpr void setHeight(qreal h) noexcept
Sets the height of the rectangle to the given finite height.
\inmodule QtCore\reentrant
constexpr bool isValid() const noexcept
Returns true if the rectangle is valid, otherwise returns false.
constexpr QPoint topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
virtual void setDevicePixelRatio(qreal ratio)=0
virtual void setPadding(qreal left, qreal top, qreal right, qreal bottom)=0
virtual void setBounds(const QRectF &bounds)=0
virtual void setTexture(QSGTexture *texture)=0
\group qtquick-scenegraph-nodes \title Qt Quick Scene Graph Node classes
constexpr void setHeight(qreal h) noexcept
Sets the height to the given finite height.
constexpr QSize toSize() const noexcept
Returns an integer based copy of this size.
constexpr void setWidth(qreal w) noexcept
Sets the width to the given finite width.
constexpr qreal width() const noexcept
Returns the width.
constexpr qreal height() const noexcept
Returns the height.
constexpr int height() const noexcept
Returns the height.
constexpr int width() const noexcept
Returns the width.
constexpr bool isEmpty() const noexcept
Returns true if either of the width and height is less than or equal to 0; otherwise returns false.
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString fromUtf8(QByteArrayView utf8)
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.
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QString & remove(qsizetype i, qsizetype len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
@ State_KeyboardFocusChange
Combined button and popup list for selecting options.
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
GLsizei const GLfloat * v
[13]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint GLintptr offset
GLsizei const GLchar *const * path
Q_QML_EXPORT QQmlInfo qmlWarning(const QObject *me)
static QT_BEGIN_NAMESPACE qreal dpr(const QWindow *w)
static QWindow * effectiveWindow(QQuickWindow *window)
QT_BEGIN_NAMESPACE QDebug operator<<(QDebug debug, const QQuickStyleMargins &padding)
#define qqc2InfoHeading(HEADING)
#define Q_ASSERT_X(cond, x, msg)
QLatin1StringView QLatin1String
#define QStringLiteral(str)
QString qEnvironmentVariable(const char *varName, const QString &defaultValue)
const char className[16]
[1]
obj metaObject() -> className()
myObject disconnect()
[26]
QMargins ninePatchMargins
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent