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 <QtWidgets/private/qtwidgetsglobal_p.h>
5#include <QtCore/qpoint.h>
6#include <QtCore/qstring.h>
7#include <QtGui/qpaintdevice.h>
8#include <QtGui/qpolygon.h>
9#include <QtCore/qstringbuilder.h>
10#include <QtGui/qaccessible.h>
11#include <QtGui/qpainter.h>
12#include <QtGui/qguiapplication.h>
13#include <QtWidgets/qwidget.h>
14
15#ifndef QSTYLEHELPER_P_H
16#define QSTYLEHELPER_P_H
17
18//
19// W A R N I N G
20// -------------
21//
22// This file is not part of the Qt API. It exists purely as an
23// implementation detail. This header file may change from version to
24// version without notice, or even be removed.
25//
26// We mean it.
27//
28
29#include <private/qhexstring_p.h>
30
31QT_BEGIN_NAMESPACE
32
33class QColor;
34class QObject;
35class QPalette;
36class QPixmap;
37class QStyleOptionSlider;
38class QStyleOption;
39class QWindow;
40
41namespace QStyleHelper
42{
43 Q_WIDGETS_EXPORT QString uniqueName(const QString &key, const QStyleOption *option, const QSize &size, qreal dpr);
44
45 Q_WIDGETS_EXPORT qreal dpi(const QStyleOption *option);
46
47 Q_WIDGETS_EXPORT qreal dpiScaled(qreal value, qreal dpi);
48 Q_WIDGETS_EXPORT qreal dpiScaled(qreal value, const QPaintDevice *device);
49 Q_WIDGETS_EXPORT qreal dpiScaled(qreal value, const QStyleOption *option);
50
51#if QT_CONFIG(dial)
52 qreal angle(const QPointF &p1, const QPointF &p2);
53 QPolygonF calcLines(const QStyleOptionSlider *dial);
54 int calcBigLineSize(int radius);
55 Q_WIDGETS_EXPORT void drawDial(const QStyleOptionSlider *dial, QPainter *painter);
56#endif //QT_CONFIG(dial)
57 Q_WIDGETS_EXPORT void drawBorderPixmap(const QPixmap &pixmap, QPainter *painter, const QRect &rect,
58 int left = 0, int top = 0, int right = 0,
59 int bottom = 0);
60#if QT_CONFIG(accessibility)
61 Q_WIDGETS_EXPORT bool isInstanceOf(QObject *obj, QAccessible::Role role);
62 Q_WIDGETS_EXPORT bool hasAncestor(QObject *obj, QAccessible::Role role);
63#endif
64 Q_WIDGETS_EXPORT QColor backgroundColor(const QPalette &pal, const QWidget* widget = nullptr);
65
66 enum WidgetSizePolicy { SizeLarge = 0, SizeSmall = 1, SizeMini = 2, SizeDefault = -1 };
67
68 Q_WIDGETS_EXPORT WidgetSizePolicy widgetSizePolicy(const QWidget *w, const QStyleOption *opt = nullptr);
69
70 // returns the device pixel ratio of the widget or the global one
71 // if widget is a nullptr
72 static inline qreal getDpr(const QWidget *widget)
73 {
74 return widget ? widget->devicePixelRatio()
75 : qApp->devicePixelRatio();
76 }
77
78 // returns the device pixel ratio of the painters underlying paint device
79 static inline qreal getDpr(const QPainter *painter)
80 {
81 Q_ASSERT(painter && painter->device());
82 return painter->device()->devicePixelRatio();
83 }
84}
85
86
87QT_END_NAMESPACE
88
89#endif // QSTYLEHELPER_P_H
90

source code of qtbase/src/widgets/styles/qstylehelper_p.h