DAWorkbench 0.0.1
DAWorkbench API
载入中...
搜索中...
未找到
da_qt5qt6_compat.hpp
1#ifndef DA_QT5QT6_COMPAT_HPP
2#define DA_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#include <QtGui/QColor>
11namespace DA
12{
13
18namespace compat
19{
20
21
28template< typename EventType >
29inline QPoint eventGlobalPos(EventType* event)
30{
31#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
32 return event->globalPos();
33#else
34 return event->globalPosition().toPoint();
35#endif
36}
37
44template< typename EventType >
45inline QPoint eventPos(EventType* event)
46{
47#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
48 return event->pos();
49#else
50 return event->position().toPoint();
51#endif
52}
53
60template< typename EventType >
61inline int eventPosX(EventType* event)
62{
63#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
64 return event->pos().x();
65#else
66 return static_cast< int >(event->position().x());
67#endif
68}
69
76template< typename EventType >
77inline int eventPosY(EventType* event)
78{
79#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
80 return event->pos().y();
81#else
82 return static_cast< int >(event->position().y());
83#endif
84}
85
92inline int horizontalAdvance(const QFontMetrics& fm, const QString& str)
93{
94#if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
95 return fm.width(str);
96#else
97 return fm.horizontalAdvance(str);
98#endif
99}
100
107inline qreal horizontalAdvanceF(const QFontMetricsF& fm, const QString& str)
108{
109#if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
110 return fm.width(str);
111#else
112 return fm.horizontalAdvance(str);
113#endif
114}
115
133inline int wheelEventDelta(QWheelEvent* e)
134{
135#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
136 return e->delta();
137#else
138 return e->angleDelta().y();
139#endif
140}
141
142inline void setNamedColor(QColor& c,const char* colorName){
143#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
144 c.setNamedColor(colorName);
145#else
146 c = QColor::fromString(colorName);
147#endif
148}
149inline void setNamedColor(QColor& c,const QString& colorName){
150#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
151 c.setNamedColor(colorName);
152#else
153 c = QColor::fromString(colorName);
154#endif
155}
156} // namespace DA
157} // namespace qwt
158#endif // QWT_QT5QT6_COMPAT_HPP
QPoint eventPos(EventType *event)
获取事件的位置(QPoint)
Definition da_qt5qt6_compat.hpp:45
int eventPosY(EventType *event)
获取事件的y坐标
Definition da_qt5qt6_compat.hpp:77
int horizontalAdvance(const QFontMetrics &fm, const QString &str)
计算字符串的水平宽度(整数版本)
Definition da_qt5qt6_compat.hpp:92
int wheelEventDelta(QWheelEvent *e)
Get vertical wheel delta value compatible with Qt5 and Qt6
Definition da_qt5qt6_compat.hpp:133
QPoint eventGlobalPos(EventType *event)
获取事件的位置(QPoint)
Definition da_qt5qt6_compat.hpp:29
qreal horizontalAdvanceF(const QFontMetricsF &fm, const QString &str)
计算字符串的水平宽度(浮点数版本)
Definition da_qt5qt6_compat.hpp:107
int eventPosX(EventType *event)
获取事件的x坐标
Definition da_qt5qt6_compat.hpp:61
序列化类都是带异常的,使用中需要处理异常
Definition AppMainWindow.cpp:44