OpenTwin 0.1
OpenTwin
 
Loading...
Searching...
No Matches
QtFactory.h
Go to the documentation of this file.
1
4// ###########################################################################################################################################################################################################################################################################################################################
5
6#pragma once
7
8// OpenTwin header
9#include "OTCore/Rect.h"
10#include "OTCore/Color.h"
11#include "OTCore/Size2D.h"
12#include "OTCore/Point2D.h"
14#include "OTGui/Font.h"
15#include "OTGui/Path2D.h"
16#include "OTGui/Outline.h"
17#include "OTGui/Margins.h"
18#include "OTGui/GuiTypes.h"
19#include "OTGui/Transform.h"
20#include "OTGui/TableRange.h"
22
23// Qt header
24#include <QtCore/qrect.h>
25#include <QtCore/qsize.h>
26#include <QtCore/qpoint.h>
27#include <QtCore/qmargins.h>
28#include <QtCore/qstringlist.h>
29#include <QtGui/qpen.h>
30#include <QtGui/qfont.h>
31#include <QtGui/qcolor.h>
32#include <QtGui/qbrush.h>
33#include <QtGui/qevent.h>
34#include <QtGui/qtransform.h>
35#include <QtGui/qpainterpath.h>
36#include <QtWidgets/qtablewidget.h>
37
38namespace ot {
39
40 class Painter2D;
41
46 public:
48 static inline QColor toQColor(const ot::Color& _color) noexcept { return QColor(_color.r(), _color.g(), _color.b(), _color.a()); };
49 static inline QColor toQColor(const ot::ColorF& _color) noexcept { return QColor((int)(_color.r() * 255.f), (int)(_color.g() * 255.f), (int)(_color.b() * 255.f), (int)(_color.a() * 255.f)); };
50
51 static inline ot::Color toColor(const QColor& _color) { return ot::Color(_color.red(), _color.green(), _color.blue(), _color.alpha()); };
52 static inline ot::ColorF toColorF(const QColor& _color) { return ot::Color(_color.red(), _color.green(), _color.blue(), _color.alpha()).toColorF(); };
53
54 static inline QPoint toQPoint(const Point2D& _pt) noexcept { return QPoint(_pt.x(), _pt.y()); };
55 static inline QPointF toQPoint(const Point2DF& _pt) noexcept { return QPointF((qreal)_pt.x(), (qreal)_pt.y()); };
56 static inline QPointF toQPoint(const Point2DD& _pt) noexcept { return QPointF((qreal)_pt.x(), (qreal)_pt.y()); };
57
58 static inline ot::Point2D toPoint2D(const QPoint& _pt) { return ot::Point2D(_pt.x(), _pt.y()); };
59 static inline ot::Point2DD toPoint2D(const QPointF& _pt) { return ot::Point2DD(_pt.x(), _pt.y()); };
60
61 static inline QSize toQSize(const Size2D& _s) noexcept { return QSize(_s.width(), _s.height()); };
62 static inline QSizeF toQSize(const Size2DF& _s) noexcept { return QSizeF((qreal)_s.width(), (qreal)_s.height()); };
63 static inline QSizeF toQSize(const Size2DD& _s) noexcept { return QSizeF((qreal)_s.width(), (qreal)_s.height()); };
64
65 static inline Size2D toSize2D(const QSize& _s) { return Size2D(_s.width(), _s.height()); };
66 static inline Size2DD toSize2D(const QSizeF& _s) { return Size2DD(_s.width(), _s.height()); };
67
68 static inline QRect toQRect(const Rect& _r) noexcept { return QRect(toQPoint(_r.getTopLeft()), toQPoint(_r.getBottomRight())); };
69 static inline QRectF toQRect(const RectF& _r) noexcept { return QRectF(toQPoint(_r.getTopLeft()), toQPoint(_r.getBottomRight())); };
70 static inline QRectF toQRect(const RectD& _r) noexcept { return QRectF(toQPoint(_r.getTopLeft()), toQPoint(_r.getBottomRight())); };
71
72 static inline Rect toRect(const QRect& _r) { return Rect(toPoint2D(_r.topLeft()), toPoint2D(_r.bottomRight())); };
73 static inline RectD toRect(const QRectF& _r) { return RectD(toPoint2D(_r.topLeft()), toPoint2D(_r.bottomRight())); };
74
75 static inline QMargins toQMargins(const Margins& _m) noexcept { return QMargins(_m.left(), _m.top(), _m.right(), _m.bottom()); };
76 static inline QMarginsF toQMargins(const MarginsF& _m) noexcept { return QMarginsF(_m.left(), _m.top(), _m.right(), _m.bottom()); };
77 static inline QMarginsF toQMargins(const MarginsD& _m) noexcept { return QMarginsF(_m.left(), _m.top(), _m.right(), _m.bottom()); };
78
79 static inline Margins toMargins(const QMargins& _m) { return Margins(_m.left(), _m.top(), _m.right(), _m.bottom()); };
80 static inline MarginsD toMargins(const QMarginsF& _m) { return MarginsD(_m.left(), _m.top(), _m.right(), _m.bottom()); };
81
82 static QFont toQFont(const Font& _f);
83 static Font toFont(const QFont& _font);
84
85 static QPen toQPen(const Outline& _outline);
86 static QPen toQPen(const OutlineF& _outline);
87
88 static Qt::Alignment toQAlignment(Alignment _alignment);
89
90 static QGradient::Spread toQGradientSpread(ot::GradientSpread _spread);
91
94 static QBrush toQBrush(const ot::Painter2D* _painter);
95
96 static Qt::PenStyle toQPenStyle(LineStyle _style);
97 static Qt::PenCapStyle toQPenCapStyle(LineCapStyle _style);
98 static Qt::PenJoinStyle toQPenJoinStyle(LineJoinStyle _style);
99
100 static QPainterPath toQPainterPath(const Path2DF& _path);
101
102 static QTransform toQTransform(const ot::Transform& _transform);
103 static QTransform toQTransformOnCenter(const ot::Transform& _transform, const QPointF& _centerPos);
104
105 static ot::TableRange toTableRange(const QTableWidgetSelectionRange& _range);
106 static QTableWidgetSelectionRange toQTableRange(const ot::TableRange& _range);
107
108 static QString toQString(QEvent::Type _type);
109 private:
110 QtFactory() {};
111 ~QtFactory() {};
112 };
113}
This file contains defines that may be used simplyfy class creation.
#define OT_DECL_NOCOPY(___class)
Removes the default copy constructor and assignment operator.
Definition OTClassHelper.h:14
#define OT_WIDGETS_API_EXPORT
Definition OTWidgetsAPIExport.h:12
The ColorF class is used to represent RGBA colors with float values.
Definition Color.h:157
The Color class is used to represent RGBA colors with integer values.
Definition Color.h:72
ColorF toColorF(void) const
Definition Color.cpp:344
Definition Font.h:20
Definition Margins.h:98
Definition Margins.h:58
Definition Margins.h:18
The OutlineF class is used to describe how a outline should look like.
Definition Outline.h:161
The Outline class is used to describe how a outline should look like.
Definition Outline.h:54
Definition Painter2D.h:17
The Path2DF class describes a path consisting of different types of lines.
Definition Path2D.h:116
2D Point with double values
Definition Point2D.h:144
2D Point with float values
Definition Point2D.h:82
2D Point with integer values
Definition Point2D.h:20
The QtFactory is used to convert OpenTwin configuration objects to Qt objects.
Definition QtFactory.h:44
static QRectF toQRect(const RectD &_r) noexcept
Definition QtFactory.h:70
static MarginsD toMargins(const QMarginsF &_m)
Definition QtFactory.h:80
static QSizeF toQSize(const Size2DF &_s) noexcept
Definition QtFactory.h:62
static Size2D toSize2D(const QSize &_s)
Definition QtFactory.h:65
static QMargins toQMargins(const Margins &_m) noexcept
Definition QtFactory.h:75
static QPointF toQPoint(const Point2DD &_pt) noexcept
Definition QtFactory.h:56
static QSize toQSize(const Size2D &_s) noexcept
Definition QtFactory.h:61
static QColor toQColor(const ot::ColorF &_color) noexcept
Definition QtFactory.h:49
static Size2DD toSize2D(const QSizeF &_s)
Definition QtFactory.h:66
static QMarginsF toQMargins(const MarginsF &_m) noexcept
Definition QtFactory.h:76
static QMarginsF toQMargins(const MarginsD &_m) noexcept
Definition QtFactory.h:77
static RectD toRect(const QRectF &_r)
Definition QtFactory.h:73
static Rect toRect(const QRect &_r)
Definition QtFactory.h:72
static QRectF toQRect(const RectF &_r) noexcept
Definition QtFactory.h:69
static QSizeF toQSize(const Size2DD &_s) noexcept
Definition QtFactory.h:63
static ot::ColorF toColorF(const QColor &_color)
Definition QtFactory.h:52
static QPointF toQPoint(const Point2DF &_pt) noexcept
Definition QtFactory.h:55
static ot::Point2DD toPoint2D(const QPointF &_pt)
Definition QtFactory.h:59
static ot::Color toColor(const QColor &_color)
Definition QtFactory.h:51
static ot::Point2D toPoint2D(const QPoint &_pt)
Definition QtFactory.h:58
static Margins toMargins(const QMargins &_m)
Definition QtFactory.h:79
static QRect toQRect(const Rect &_r) noexcept
Definition QtFactory.h:68
static QPoint toQPoint(const Point2D &_pt) noexcept
Definition QtFactory.h:54
static QColor toQColor(const ot::Color &_color) noexcept
Convert OpenTwin Color to Qt Color.
Definition QtFactory.h:48
Rectangle that holds the top left and bottom right corner in double values.
Definition Rect.h:234
Definition Rect.h:127
Rectangle that holds the top left and bottom right corner in int values.
Definition Rect.h:20
2D Size with double values
Definition Size2D.h:115
2D Size with float values
Definition Size2D.h:65
2D Size with integer values
Definition Size2D.h:15
Definition TableRange.h:16
General item transformation.
Definition Transform.h:16
Definition Connector.h:8
Alignment
Alignment.
Definition GuiTypes.h:21
GradientSpread
Describes how the painter will behave when painting outsite the gradient area.
Definition GuiTypes.h:76
LineCapStyle
Line cap style.
Definition Outline.h:29
LineJoinStyle
Line join style.
Definition Outline.h:36
LineStyle
Line style.
Definition Outline.h:19