| 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 | #ifndef QGRAPHICSLAYOUT_P_H |
| 5 | #define QGRAPHICSLAYOUT_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists for the convenience |
| 12 | // of other Qt classes. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtWidgets/private/qtwidgetsglobal_p.h> |
| 19 | |
| 20 | #include "qgraphicslayout.h" |
| 21 | #include "qgraphicslayoutitem_p.h" |
| 22 | #include <QtWidgets/qstyle.h> |
| 23 | #include <QtWidgets/qwidget.h> |
| 24 | #include <QtWidgets/qstyleoption.h> |
| 25 | |
| 26 | QT_REQUIRE_CONFIG(graphicsview); |
| 27 | |
| 28 | QT_BEGIN_NAMESPACE |
| 29 | |
| 30 | class QGraphicsLayoutItem; |
| 31 | class QGraphicsWidget; |
| 32 | |
| 33 | #ifdef QT_DEBUG |
| 34 | inline bool qt_graphicsLayoutDebug() |
| 35 | { |
| 36 | static int checked_env = -1; |
| 37 | if (checked_env == -1) |
| 38 | checked_env = !!qEnvironmentVariableIntValue(varName: "QT_GRAPHICSLAYOUT_DEBUG" ); |
| 39 | return checked_env; |
| 40 | } |
| 41 | #endif |
| 42 | |
| 43 | |
| 44 | class QLayoutStyleInfo |
| 45 | { |
| 46 | public: |
| 47 | inline QLayoutStyleInfo() { invalidate(); } |
| 48 | inline QLayoutStyleInfo(QStyle *style, QWidget *widget) |
| 49 | : m_valid(true), m_style(style), m_widget(widget) |
| 50 | { |
| 51 | Q_ASSERT(style); |
| 52 | if (widget) //### |
| 53 | m_styleOption.initFrom(w: widget); |
| 54 | m_defaultSpacing[0] = style->pixelMetric(metric: QStyle::PM_LayoutHorizontalSpacing, option: &m_styleOption, widget); |
| 55 | m_defaultSpacing[1] = style->pixelMetric(metric: QStyle::PM_LayoutVerticalSpacing, option: &m_styleOption, widget); |
| 56 | } |
| 57 | |
| 58 | inline void invalidate() { m_valid = false; m_style = nullptr; m_widget = nullptr; } |
| 59 | |
| 60 | inline QStyle *style() const { return m_style; } |
| 61 | inline QWidget *widget() const { return m_widget; } |
| 62 | |
| 63 | inline bool operator==(const QLayoutStyleInfo &other) const |
| 64 | { return m_style == other.m_style && m_widget == other.m_widget; } |
| 65 | inline bool operator!=(const QLayoutStyleInfo &other) const |
| 66 | { return !(*this == other); } |
| 67 | |
| 68 | inline void setDefaultSpacing(Qt::Orientation o, qreal spacing){ |
| 69 | if (spacing >= 0) |
| 70 | m_defaultSpacing[int(o) - 1] = spacing; |
| 71 | } |
| 72 | |
| 73 | inline qreal defaultSpacing(Qt::Orientation o) const { |
| 74 | return m_defaultSpacing[int(o) - 1]; |
| 75 | } |
| 76 | |
| 77 | inline qreal perItemSpacing(QSizePolicy::ControlType control1, |
| 78 | QSizePolicy::ControlType control2, |
| 79 | Qt::Orientation orientation) const |
| 80 | { |
| 81 | Q_ASSERT(style()); |
| 82 | return style()->layoutSpacing(control1, control2, orientation, option: &m_styleOption, widget: widget()); |
| 83 | } |
| 84 | private: |
| 85 | bool m_valid; |
| 86 | QStyle *m_style; |
| 87 | QWidget *m_widget; |
| 88 | QStyleOption m_styleOption; |
| 89 | qreal m_defaultSpacing[2]; |
| 90 | }; |
| 91 | |
| 92 | class Q_AUTOTEST_EXPORT QGraphicsLayoutPrivate : public QGraphicsLayoutItemPrivate |
| 93 | { |
| 94 | Q_DECLARE_PUBLIC(QGraphicsLayout) |
| 95 | |
| 96 | public: |
| 97 | QGraphicsLayoutPrivate() : QGraphicsLayoutItemPrivate(nullptr, true), left(-1.0), top(-1.0), right(-1.0), bottom(-1.0), |
| 98 | activated(true) { } |
| 99 | |
| 100 | void reparentChildItems(QGraphicsItem *newParent); |
| 101 | void getMargin(qreal *result, qreal userMargin, QStyle::PixelMetric pm) const; |
| 102 | Qt::LayoutDirection visualDirection() const; |
| 103 | |
| 104 | void addChildLayoutItem(QGraphicsLayoutItem *item); |
| 105 | void activateRecursive(QGraphicsLayoutItem *item); |
| 106 | |
| 107 | qreal left, top, right, bottom; |
| 108 | bool activated; |
| 109 | }; |
| 110 | |
| 111 | QT_END_NAMESPACE |
| 112 | |
| 113 | #endif |
| 114 | |