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

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