SARibbon 2.5.2
SARibbon wiki
载入中...
搜索中...
未找到
SARibbonQt5Compat.hpp
1#ifndef SARIBBONQT5COMPAT_HPP
2#define SARIBBONQT5COMPAT_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 SA
12{
13
18namespace compat
19{
20
27template< typename EventType >
28inline QPoint eventGlobalPos(EventType* event)
29{
30#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
31 return event->globalPos();
32#else
33 return event->globalPosition().toPoint();
34#endif
35}
36
43template< typename EventType >
44inline QPoint eventPos(EventType* event)
45{
46#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
47 return event->pos();
48#else
49 return event->position().toPoint();
50#endif
51}
52
59template< typename EventType >
60inline int eventPosX(EventType* event)
61{
62#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
63 return event->pos().x();
64#else
65 return static_cast< int >(event->position().x());
66#endif
67}
68
75template< typename EventType >
76inline int eventPosY(EventType* event)
77{
78#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
79 return event->pos().y();
80#else
81 return static_cast< int >(event->position().y());
82#endif
83}
84
91template< typename strType >
92inline int horizontalAdvance(const QFontMetrics& fm, const strType& 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
107template< typename strType >
108inline qreal horizontalAdvanceF(const QFontMetricsF& fm, const strType& str)
109{
110#if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
111 return fm.width(str);
112#else
113 return fm.horizontalAdvance(str);
114#endif
115}
116
134inline int wheelEventDelta(QWheelEvent* e)
135{
136#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
137 return e->delta();
138#else
139 return e->angleDelta().y();
140#endif
141}
142} // namespace compat
143} // namespace qwt
144#endif // SARIBBONQT5COMPAT_HPP
int eventPosX(EventType *event)
获取事件的x坐标
Definition SARibbonQt5Compat.hpp:60
int horizontalAdvance(const QFontMetrics &fm, const strType &str)
计算字符串的水平宽度(整数版本)
Definition SARibbonQt5Compat.hpp:92
int wheelEventDelta(QWheelEvent *e)
Get vertical wheel delta value compatible with Qt5 and Qt6
Definition SARibbonQt5Compat.hpp:134
QPoint eventPos(EventType *event)
获取事件的位置(QPoint)
Definition SARibbonQt5Compat.hpp:44
QPoint eventGlobalPos(EventType *event)
获取事件的位置(QPoint)
Definition SARibbonQt5Compat.hpp:28
int eventPosY(EventType *event)
获取事件的y坐标
Definition SARibbonQt5Compat.hpp:76
qreal horizontalAdvanceF(const QFontMetricsF &fm, const strType &str)
计算字符串的水平宽度(浮点数版本)
Definition SARibbonQt5Compat.hpp:108