QWT 7.0.1
Loading...
Searching...
No Matches
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 <QtGui/QMouseEvent>
6#include <QtGui/QKeyEvent>
7#include <QtGui/QWheelEvent>
8#include <QtGui/QFontMetrics>
9#include <QtGui/QFontMetricsF>
10
11namespace qwt
12{
13
18namespace compat
19{
20
27template< typename EventType >
28inline QPoint eventPos(EventType* event)
29{
30#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
31 return event->pos();
32#else
33 return event->position().toPoint();
34#endif
35}
36
43template< typename EventType >
44inline int eventPosX(EventType* event)
45{
46#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
47 return event->pos().x();
48#else
49 return static_cast< int >(event->position().x());
50#endif
51}
52
59template< typename EventType >
60inline int eventPosY(EventType* event)
61{
62#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
63 return event->pos().y();
64#else
65 return static_cast< int >(event->position().y());
66#endif
67}
68
75inline int horizontalAdvance(const QFontMetrics& fm, const QString& str)
76{
77#if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
78 return fm.width(str);
79#else
80 return fm.horizontalAdvance(str);
81#endif
82}
83
90inline qreal horizontalAdvanceF(const QFontMetricsF& fm, const QString& str)
91{
92#if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
93 return fm.width(str);
94#else
95 return fm.horizontalAdvance(str);
96#endif
97}
98
116inline int wheelEventDelta(QWheelEvent* e)
117{
118#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
119 return e->delta();
120#else
121 return e->angleDelta().y();
122#endif
123}
124} // namespace compat
125} // namespace qwt
126#endif // QWT_QT5QT6_COMPAT_HPP
int eventPosX(EventType *event)
获取事件的x坐标
Definition qwt_qt5qt6_compat.hpp:44
int horizontalAdvance(const QFontMetrics &fm, const QString &str)
计算字符串的水平宽度(整数版本)
Definition qwt_qt5qt6_compat.hpp:75
int wheelEventDelta(QWheelEvent *e)
Get vertical wheel delta value compatible with Qt5 and Qt6.
Definition qwt_qt5qt6_compat.hpp:116
QPoint eventPos(EventType *event)
获取事件的位置(QPoint)
Definition qwt_qt5qt6_compat.hpp:28
qreal horizontalAdvanceF(const QFontMetricsF &fm, const QString &str)
计算字符串的水平宽度(浮点数版本)
Definition qwt_qt5qt6_compat.hpp:90
int eventPosY(EventType *event)
获取事件的y坐标
Definition qwt_qt5qt6_compat.hpp:60