LeechCraft Monocle
0.6.70-18450-gabe19ee3b0
Modular document viewer for LeechCraft
Toggle main menu visibility
Loading...
Searching...
No Matches
coordsbase.h
Go to the documentation of this file.
1
/**********************************************************************
2
* LeechCraft - modular cross-platform feature rich internet client.
3
* Copyright (C) 2006-2014 Georg Rudoy
4
*
5
* Distributed under the Boost Software License, Version 1.0.
6
* (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7
**********************************************************************/
8
9
#pragma once
10
11
#include <QPointF>
12
#include <QRectF>
13
14
namespace
LC::Monocle
15
{
16
enum class
Relativity
: std::uint8_t
17
{
18
PageRelative
,
19
PageAbsolute
,
20
SceneAbsolute
,
21
ViewAbsolute
,
22
};
23
24
template
<Relativity R>
25
struct
Pos
26
{
27
static
constexpr
auto
Relativity
= R;
28
29
using
Type
= QPointF;
30
31
Type
P_
{};
32
33
Pos
() =
default
;
34
35
explicit
Pos
(
Type
p)
36
:
P_
{ p }
37
{
38
}
39
40
explicit
Pos
(qreal x, qreal y)
41
:
P_
{ x, y }
42
{
43
}
44
45
auto
operator<=>
(
const
Pos
&)
const
=
default
;
46
47
template
<
typename
Self>
48
[[nodiscard]]
49
auto
ClearedX
(
this
const
Self& self)
50
{
51
return
Self { 0, self.P_.y () };
52
}
53
54
template
<
typename
Self>
55
[[nodiscard]]
56
auto
ClearedY
(
this
const
Self& self)
57
{
58
return
Self { self.P_.x (), 0 };
59
}
60
61
template
<
typename
Self>
62
[[nodiscard]]
63
Self
Shifted
(
this
const
Self& self, qreal dx, qreal dy)
64
{
65
return
Self { self.P_ +
Type
{ dx, dy } };
66
}
67
68
Type
ToPointF
()
const
69
{
70
return
P_
;
71
}
72
73
template
<
typename
Self>
74
Self
operator+
(
this
Self p1, Self p2)
75
{
76
return
Self { p1.P_ + p2.P_ };
77
}
78
79
template
<
typename
Self>
80
Self
operator-
(
this
Self p1, Self p2)
81
{
82
return
Self { p1.P_ - p2.P_ };
83
}
84
85
template
<
typename
Self>
86
Self
operator*
(
this
Self p, qreal factor)
87
{
88
return
Self { p.P_ * factor };
89
}
90
91
template
<
typename
Self>
92
Self
operator/
(
this
Self p, qreal factor)
93
{
94
return
Self { p.P_ / factor };
95
}
96
97
bool
BothGeqThan
(
Pos
p)
const
98
{
99
return
P_
.x () >= p.
P_
.x () &&
P_
.y () >= p.
P_
.y ();
100
}
101
102
bool
BothLeqThan
(
Pos
p)
const
103
{
104
return
P_
.x () <= p.
P_
.x () &&
P_
.y () <= p.
P_
.y ();
105
}
106
};
107
108
template
<Relativity R>
109
struct
Rect
110
{
111
static
constexpr
auto
Relativity
= R;
112
113
using
Type
= QRectF;
114
115
Type
R_
{};
116
117
Rect
() =
default
;
118
119
explicit
Rect
(
const
Type
& r)
120
:
R_
{ r }
121
{
122
}
123
124
explicit
Rect
(
Pos<R>
topLeft,
Pos<R>
bottomRight)
125
:
R_
{ topLeft.ToPointF (), bottomRight.ToPointF () }
126
{
127
}
128
129
auto
operator<=>
(
const
Rect
&)
const
=
default
;
130
131
template
<
typename
P>
132
requires
(P::Relativity == R)
133
P
TopLeft
()
const
134
{
135
return
P {
R_
.topLeft () };
136
}
137
138
template
<
typename
P>
139
requires
(P::Relativity == R)
140
P
BottomRight
()
const
141
{
142
return
P {
R_
.bottomRight () };
143
}
144
145
void
SetLeft
(qreal x)
146
{
147
R_
.setLeft (x);
148
}
149
150
void
SetRight
(qreal x)
151
{
152
R_
.setRight (x);
153
}
154
155
Type
ToRectF
()
const
156
{
157
return
R_
;
158
}
159
160
bool
IsEmpty
()
const
161
{
162
return
R_
.isEmpty ();
163
}
164
165
template
<
typename
Self>
166
Self
operator|
(
this
const
Self& r1,
const
Self& r2)
167
{
168
return
Self { r1.R_ | r2.R_ };
169
}
170
171
template
<
typename
Self>
172
Self
operator&
(
this
const
Self& r1,
const
Self& r2)
173
{
174
return
Self { r1.R_ & r2.R_ };
175
}
176
};
177
178
struct
PageRelativePosBase;
179
struct
PageAbsolutePosBase;
180
181
struct
PageRelativePosBase
:
Pos
<Relativity::PageRelative>
182
{
183
using
Pos::Pos
;
184
185
PageAbsolutePosBase
ToPageAbsolute
(QSizeF)
const
;
186
};
187
188
struct
PageAbsolutePosBase
:
Pos
<Relativity::PageAbsolute>
189
{
190
using
Pos::Pos
;
191
192
PageRelativePosBase
ToPageRelative
(QSizeF)
const
;
193
};
194
195
inline
PageAbsolutePosBase
PageRelativePosBase::ToPageAbsolute
(QSizeF size)
const
196
{
197
return
PageAbsolutePosBase
{
P_
.x () * size.width (),
P_
.y () * size.height () };
198
}
199
200
inline
PageRelativePosBase
PageAbsolutePosBase::ToPageRelative
(QSizeF size)
const
201
{
202
return
PageRelativePosBase
{
P_
.x () / size.width (),
P_
.y () / size.height () };
203
}
204
205
struct
PageRelativeRectBase
;
206
struct
PageAbsoluteRectBase
;
207
208
struct
PageRelativeRectBase
:
Rect
<Relativity::PageRelative>
209
{
210
using
Rect::Rect
;
211
212
PageAbsoluteRectBase
ToPageAbsolute
(QSizeF)
const
;
213
};
214
215
struct
PageAbsoluteRectBase
:
Rect
<Relativity::PageAbsolute>
216
{
217
using
Rect::Rect
;
218
219
PageRelativeRectBase
ToPageRelative
(QSizeF)
const
;
220
};
221
222
namespace
detail
223
{
224
template
<
typename
Target,
typename
SrcPos,
typename
TargetPos,
typename
Source,
typename
Ctx>
225
Target
Convert
(TargetPos (SrcPos::*posConvert) (Ctx)
const
,
const
Source& src,
const
auto
& context)
226
{
227
return
Target
228
{
229
(src.template TopLeft<SrcPos> ().*posConvert) (context),
230
(src.template BottomRight<SrcPos> ().*posConvert) (context)
231
};
232
}
233
}
234
235
inline
PageAbsoluteRectBase
PageRelativeRectBase::ToPageAbsolute
(QSizeF size)
const
236
{
237
return
detail::Convert<PageAbsoluteRectBase>
(&
PageRelativePosBase::ToPageAbsolute
, *
this
, size);
238
}
239
240
inline
PageRelativeRectBase
PageAbsoluteRectBase::ToPageRelative
(QSizeF size)
const
241
{
242
return
detail::Convert<PageRelativeRectBase>
(&
PageAbsolutePosBase::ToPageRelative
, *
this
, size);
243
}
244
}
245
246
template
<LC::Monocle::Relativity R>
247
class
QTypeInfo<
LC
::Monocle::Pos<R>> :
public
QTypeInfo<QPointF> {};
248
249
template
<LC::Monocle::Relativity R>
250
class
QTypeInfo<
LC
::Monocle::Rect<R>> :
public
QTypeInfo<QRectF> {};
251
252
template
<>
253
class
QTypeInfo<
LC
::Monocle::PageRelativePosBase> :
public
QTypeInfo<QPointF> {};
254
template
<>
255
class
QTypeInfo<
LC
::Monocle::PageAbsolutePosBase> :
public
QTypeInfo<QPointF> {};
256
257
template
<>
258
class
QTypeInfo<
LC
::Monocle::PageRelativeRectBase> :
public
QTypeInfo<QRectF> {};
259
template
<>
260
class
QTypeInfo<
LC
::Monocle::PageAbsoluteRectBase> :
public
QTypeInfo<QRectF> {};
LC::Monocle::detail
Definition
coordsbase.h:223
LC::Monocle::detail::Convert
Target Convert(TargetPos(SrcPos::*posConvert)(Ctx) const, const Source &src, const auto &context)
Definition
coordsbase.h:225
LC::Monocle
Definition
coordsbase.h:15
LC::Monocle::Relativity
Relativity
Definition
coordsbase.h:17
LC::Monocle::Relativity::PageRelative
@ PageRelative
Definition
coordsbase.h:18
LC::Monocle::Relativity::SceneAbsolute
@ SceneAbsolute
Definition
coordsbase.h:20
LC::Monocle::Relativity::ViewAbsolute
@ ViewAbsolute
Definition
coordsbase.h:21
LC::Monocle::Relativity::PageAbsolute
@ PageAbsolute
Definition
coordsbase.h:19
LC
Definition
coordsbase.h:15
LC::Monocle::PageAbsolutePosBase
Definition
coordsbase.h:189
LC::Monocle::PageAbsolutePosBase::Pos
Pos()=default
LC::Monocle::PageAbsolutePosBase::ToPageRelative
PageRelativePosBase ToPageRelative(QSizeF) const
Definition
coordsbase.h:200
LC::Monocle::PageAbsoluteRectBase
Definition
coordsbase.h:216
LC::Monocle::PageAbsoluteRectBase::Rect
Rect()=default
LC::Monocle::PageAbsoluteRectBase::ToPageRelative
PageRelativeRectBase ToPageRelative(QSizeF) const
Definition
coordsbase.h:240
LC::Monocle::PageRelativePosBase
Definition
coordsbase.h:182
LC::Monocle::PageRelativePosBase::Pos
Pos()=default
LC::Monocle::PageRelativePosBase::ToPageAbsolute
PageAbsolutePosBase ToPageAbsolute(QSizeF) const
Definition
coordsbase.h:195
LC::Monocle::PageRelativeRectBase
Definition
coordsbase.h:209
LC::Monocle::PageRelativeRectBase::ToPageAbsolute
PageAbsoluteRectBase ToPageAbsolute(QSizeF) const
Definition
coordsbase.h:235
LC::Monocle::PageRelativeRectBase::Rect
Rect()=default
LC::Monocle::Pos
Definition
coordsbase.h:26
LC::Monocle::Pos::BothGeqThan
bool BothGeqThan(Pos p) const
Definition
coordsbase.h:97
LC::Monocle::Pos::Pos
Pos()=default
LC::Monocle::Pos::BothLeqThan
bool BothLeqThan(Pos p) const
Definition
coordsbase.h:102
LC::Monocle::Pos::ClearedY
auto ClearedY(this const Self &self)
Definition
coordsbase.h:56
LC::Monocle::Pos::ToPointF
Type ToPointF() const
Definition
coordsbase.h:68
LC::Monocle::Pos::ClearedX
auto ClearedX(this const Self &self)
Definition
coordsbase.h:49
LC::Monocle::Pos::Pos
Pos(qreal x, qreal y)
Definition
coordsbase.h:40
LC::Monocle::Pos::operator/
Self operator/(this Self p, qreal factor)
Definition
coordsbase.h:92
LC::Monocle::Pos::operator-
Self operator-(this Self p1, Self p2)
Definition
coordsbase.h:80
LC::Monocle::Pos::operator+
Self operator+(this Self p1, Self p2)
Definition
coordsbase.h:74
LC::Monocle::Pos::operator*
Self operator*(this Self p, qreal factor)
Definition
coordsbase.h:86
LC::Monocle::Pos::operator<=>
auto operator<=>(const Pos &) const =default
LC::Monocle::Pos::P_
Type P_
Definition
coordsbase.h:31
LC::Monocle::Pos::Relativity
static constexpr auto Relativity
Definition
coordsbase.h:27
LC::Monocle::Pos::Shifted
Self Shifted(this const Self &self, qreal dx, qreal dy)
Definition
coordsbase.h:63
LC::Monocle::Pos::Pos
Pos(Type p)
Definition
coordsbase.h:35
LC::Monocle::Pos::Type
QPointF Type
Definition
coordsbase.h:29
LC::Monocle::Rect::BottomRight
P BottomRight() const
Definition
coordsbase.h:140
LC::Monocle::Rect::Relativity
static constexpr auto Relativity
Definition
coordsbase.h:111
LC::Monocle::Rect::SetRight
void SetRight(qreal x)
Definition
coordsbase.h:150
LC::Monocle::Rect::TopLeft
P TopLeft() const
Definition
coordsbase.h:133
LC::Monocle::Rect::Type
QRectF Type
Definition
coordsbase.h:113
LC::Monocle::Rect::IsEmpty
bool IsEmpty() const
Definition
coordsbase.h:160
LC::Monocle::Rect::Rect
Rect()=default
LC::Monocle::Rect::Rect
Rect(const Type &r)
Definition
coordsbase.h:119
LC::Monocle::Rect::R_
Type R_
Definition
coordsbase.h:115
LC::Monocle::Rect::Rect
Rect(Pos< R > topLeft, Pos< R > bottomRight)
Definition
coordsbase.h:124
LC::Monocle::Rect::operator<=>
auto operator<=>(const Rect &) const =default
LC::Monocle::Rect::ToRectF
Type ToRectF() const
Definition
coordsbase.h:155
LC::Monocle::Rect::operator|
Self operator|(this const Self &r1, const Self &r2)
Definition
coordsbase.h:166
LC::Monocle::Rect::operator&
Self operator&(this const Self &r1, const Self &r2)
Definition
coordsbase.h:172
LC::Monocle::Rect::SetLeft
void SetLeft(qreal x)
Definition
coordsbase.h:145
src
plugins
monocle
interfaces
monocle
coordsbase.h
Generated by
1.17.0