QWT API (中文) 7.3.0
Qt绘图库 - 中文API文档
载入中...
搜索中...
未找到
qwt_qt5qt6_compat.hpp
1#ifndef QWT_QT5QT6_COMPAT_HPP
2#define QWT_QT5QT6_COMPAT_HPP
3#include <QtCore/QtGlobal>
4#include <QtCore/QObject>
5#include <QtCore/QTimeZone>
6#include <QtGui/QMouseEvent>
7#include <QtGui/QKeyEvent>
8#include <QtGui/QWheelEvent>
9#include <QtGui/QFontMetrics>
10#include <QtGui/QFontMetricsF>
11
12namespace qwt
13{
14
19namespace compat
20{
21
28template< typename EventType >
29inline QPoint eventPos(EventType* event)
30{
31#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
32 return event->pos();
33#else
34 return event->position().toPoint();
35#endif
36}
37
44template< typename EventType >
45inline int eventPosX(EventType* event)
46{
47#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
48 return event->pos().x();
49#else
50 return static_cast< int >(event->position().x());
51#endif
52}
53
60template< typename EventType >
61inline int eventPosY(EventType* event)
62{
63#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
64 return event->pos().y();
65#else
66 return static_cast< int >(event->position().y());
67#endif
68}
69
76inline int horizontalAdvance(const QFontMetrics& fm, const QString& str)
77{
78#if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
79 return fm.width(str);
80#else
81 return fm.horizontalAdvance(str);
82#endif
83}
84
91inline qreal horizontalAdvanceF(const QFontMetricsF& fm, const QString& str)
92{
93#if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
94 return fm.width(str);
95#else
96 return fm.horizontalAdvance(str);
97#endif
98}
99
117inline int wheelEventDelta(QWheelEvent* e)
118{
119#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
120 return e->delta();
121#else
122 return e->angleDelta().y();
123#endif
124}
131inline QTimeZone utcTimeZone()
132{
133#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
134 return QTimeZone::utc();
135#else
136 return QTimeZone("UTC");
137#endif
138}
139
144inline QTimeZone systemTimeZone()
145{
146 return QTimeZone::systemTimeZone();
147}
148
156inline QTimeZone offsetTimeZone(int seconds)
157{
158#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0)
159 return QTimeZone::fromSecondsAheadOfUtc(seconds);
160#else
161 return QTimeZone(seconds);
162#endif
163}
164
165} // namespace compat
166} // namespace qwt
167#endif // QWT_QT5QT6_COMPAT_HPP
int eventPosX(EventType *event)
Get the x coordinate of the event
Definition qwt_qt5qt6_compat.hpp:45
int horizontalAdvance(const QFontMetrics &fm, const QString &str)
Calculate the horizontal advance of a string (integer version)
Definition qwt_qt5qt6_compat.hpp:76
QTimeZone systemTimeZone()
Get the system time zone
Definition qwt_qt5qt6_compat.hpp:144
QTimeZone utcTimeZone()
Get the UTC time zone
Definition qwt_qt5qt6_compat.hpp:131
int wheelEventDelta(QWheelEvent *e)
Get vertical wheel delta value compatible with Qt5 and Qt6
Definition qwt_qt5qt6_compat.hpp:117
QPoint eventPos(EventType *event)
Get the event position (QPoint)
Definition qwt_qt5qt6_compat.hpp:29
QTimeZone offsetTimeZone(int seconds)
Create a time zone from an offset in seconds ahead of UTC
Definition qwt_qt5qt6_compat.hpp:156
qreal horizontalAdvanceF(const QFontMetricsF &fm, const QString &str)
Calculate the horizontal advance of a string (floating-point version)
Definition qwt_qt5qt6_compat.hpp:91
int eventPosY(EventType *event)
Get the y coordinate of the event
Definition qwt_qt5qt6_compat.hpp:61