| 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 | |
| 16 | QT_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 | |
| 29 | class QTextOption; |
| 30 | |
| 31 | // Private class |
| 32 | class Q_WIDGETS_EXPORT QCommonStylePrivate : public QStylePrivate |
| 33 | { |
| 34 | Q_DECLARE_PUBLIC(QCommonStyle) |
| 35 | public: |
| 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 | QStyleAnimation* animation(const QObject *target) const; |
| 96 | void startAnimation(QStyleAnimation *animation) const; |
| 97 | void stopAnimation(const QObject *target) const; |
| 98 | void removeAnimation(const QObject *target) const; |
| 99 | #endif |
| 100 | |
| 101 | QIcon iconFromWindowsTheme(QCommonStyle::StandardPixmap standardIcon, |
| 102 | const QStyleOption *option, |
| 103 | const QWidget *widget) const; |
| 104 | QIcon iconFromMacTheme(QCommonStyle::StandardPixmap standardIcon, |
| 105 | const QStyleOption *option, |
| 106 | const QWidget *widget) const; |
| 107 | QIcon iconFromApplicationTheme(QCommonStyle::StandardPixmap standardIcon, |
| 108 | const QStyleOption *option, |
| 109 | const QWidget *widget) const; |
| 110 | QIcon iconFromResourceTheme(QCommonStyle::StandardPixmap standardIcon, |
| 111 | const QStyleOption *option, |
| 112 | const QWidget *widget) const; |
| 113 | static bool inline rtl(const QStyleOption *option) { |
| 114 | return (option && option->direction == Qt::RightToLeft) || |
| 115 | (!option && QGuiApplication::isRightToLeft()); |
| 116 | } |
| 117 | #if QT_CONFIG(animation) |
| 118 | private: |
| 119 | mutable QHash<const QObject*, QStyleAnimation*> animations; |
| 120 | #endif // animation |
| 121 | }; |
| 122 | |
| 123 | QT_END_NAMESPACE |
| 124 | |
| 125 | #endif //QCOMMONSTYLE_P_H |
| 126 | |