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 QCOMMONSTYLE_P_H
5#define QCOMMONSTYLE_P_H
6
7#include <QtWidgets/private/qtwidgetsglobal_p.h>
8#include <QtGui/private/qguiapplication_p.h>
9#include "qhash.h"
10#include "qcommonstyle.h"
11#include "qstyle_p.h"
12#if QT_CONFIG(animation)
13#include "qstyleanimation_p.h"
14#endif
15#include "qstyleoption.h"
16
17QT_BEGIN_NAMESPACE
18
19//
20// W A R N I N G
21// -------------
22//
23// This file is not part of the Qt API. It exists for the convenience
24// of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp. This header
25// file may change from version to version without notice, or even be removed.
26//
27// We mean it.
28//
29
30class QTextOption;
31
32// Private class
33class Q_WIDGETS_EXPORT QCommonStylePrivate : public QStylePrivate
34{
35 Q_DECLARE_PUBLIC(QCommonStyle)
36public:
37 inline QCommonStylePrivate() :
38#if QT_CONFIG(itemviews)
39 cachedOption(nullptr),
40#endif
41 animationFps(30)
42 { }
43
44 ~QCommonStylePrivate()
45 {
46#if QT_CONFIG(animation)
47 qDeleteAll(c: animations);
48#endif
49#if QT_CONFIG(itemviews)
50 delete cachedOption;
51#endif
52 }
53
54 QString calculateElidedText(const QString &text, const QTextOption &textOption,
55 const QFont &font, const QRect &textRect, const Qt::Alignment valign,
56 Qt::TextElideMode textElideMode, int flags,
57 bool lastVisibleLineShouldBeElided, QPointF *paintStartPosition) const;
58#if QT_CONFIG(itemviews)
59 void viewItemDrawText(QPainter *p, const QStyleOptionViewItem *option, const QRect &rect) const;
60 void viewItemLayout(const QStyleOptionViewItem *opt, QRect *checkRect,
61 QRect *pixmapRect, QRect *textRect, bool sizehint) const;
62 QSize viewItemSize(const QStyleOptionViewItem *option, int role) const;
63
64 mutable QRect decorationRect, displayRect, checkRect;
65 mutable QStyleOptionViewItem *cachedOption;
66 bool isViewItemCached(const QStyleOptionViewItem &option) const {
67 return cachedOption && (option.widget == cachedOption->widget
68 && option.index == cachedOption->index
69 && option.state == cachedOption->state
70 && option.rect == cachedOption->rect
71 && option.text == cachedOption->text
72 && option.direction == cachedOption->direction
73 && option.displayAlignment == cachedOption->displayAlignment
74 && option.decorationAlignment == cachedOption->decorationAlignment
75 && option.decorationPosition == cachedOption->decorationPosition
76 && option.decorationSize == cachedOption->decorationSize
77 && option.features == cachedOption->features
78 && option.icon.isNull() == cachedOption->icon.isNull()
79 && option.font == cachedOption->font
80 && option.viewItemPosition == cachedOption->viewItemPosition
81 && option.showDecorationSelected == cachedOption->showDecorationSelected);
82 }
83#endif
84#if QT_CONFIG(toolbutton)
85 QString toolButtonElideText(const QStyleOptionToolButton *toolbutton,
86 const QRect &textRect, int flags) const;
87#endif
88
89 mutable QIcon tabBarcloseButtonIcon;
90#if QT_CONFIG(tabbar)
91 virtual void tabLayout(const QStyleOptionTab *opt, const QWidget *widget, QRect *textRect, QRect *pixmapRect) const;
92#endif
93
94 int animationFps;
95#if QT_CONFIG(animation)
96 QStyleAnimation* animation(const QObject *target) const;
97 void startAnimation(QStyleAnimation *animation) const;
98 void stopAnimation(const QObject *target) const;
99 void removeAnimation(const QObject *target) const;
100#endif
101
102 QIcon iconFromWindowsTheme(QCommonStyle::StandardPixmap standardIcon,
103 const QStyleOption *option,
104 const QWidget *widget) const;
105 QIcon iconFromMacTheme(QCommonStyle::StandardPixmap standardIcon,
106 const QStyleOption *option,
107 const QWidget *widget) const;
108 QIcon iconFromApplicationTheme(QCommonStyle::StandardPixmap standardIcon,
109 const QStyleOption *option,
110 const QWidget *widget) const;
111 QIcon iconFromResourceTheme(QCommonStyle::StandardPixmap standardIcon,
112 const QStyleOption *option,
113 const QWidget *widget) const;
114 static bool inline rtl(const QStyleOption *option) {
115 return (option && option->direction == Qt::RightToLeft) ||
116 (!option && QGuiApplication::isRightToLeft());
117 }
118#if QT_CONFIG(animation)
119private:
120 mutable QHash<const QObject*, QStyleAnimation*> animations;
121#endif // animation
122};
123
124QT_END_NAMESPACE
125
126#endif //QCOMMONSTYLE_P_H
127

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