SILICON
Toggle main menu visibility
Loading...
Searching...
No Matches
grid.hpp
Go to the documentation of this file.
1
/*
2
Copyright (c) 2026. Giulio Cocconi
3
4
This program is free software: you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation, either version 3 of the License, or
7
(at your option) any later version.
8
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
13
14
You should have received a copy of the GNU General Public License
15
along with this program. If not, see <http://www.gnu.org/licenses/>.
16
*/
17
18
#pragma once
19
20
#include <cmath>
21
22
#include <QPoint>
23
#include <QPointF>
24
#include <QSize>
25
26
namespace
SILICON::ui
{
27
inline
constexpr
int
GRID_SIZE
= 10;
28
29
[[nodiscard]]
inline
int
gridToPixels
(
int
value)
30
{
31
return
value *
GRID_SIZE
;
32
}
33
[[nodiscard]]
inline
int
pixelsToGrid
(
int
value)
34
{
35
return
value /
GRID_SIZE
;
36
}
37
[[nodiscard]]
inline
QPoint
gridToPixels
(
const
QPoint& point)
38
{
39
return
{
gridToPixels
(point.x()),
gridToPixels
(point.y())};
40
}
41
[[nodiscard]]
inline
QPoint
pixelsToGrid
(
const
QPoint& point)
42
{
43
return
{
pixelsToGrid
(point.x()),
pixelsToGrid
(point.y())};
44
}
45
[[nodiscard]]
inline
QSize
pixelsToGrid
(
const
QSize& size)
46
{
47
return
{
pixelsToGrid
(size.width()),
pixelsToGrid
(size.height())};
48
}
49
[[nodiscard]]
inline
int
pixelsToNearestGrid
(qreal value)
50
{
51
return
static_cast<
int
>
(std::lround(value /
GRID_SIZE
));
52
}
53
[[nodiscard]]
inline
QPoint
pixelsToNearestGrid
(
const
QPointF& point)
54
{
55
return
{
pixelsToNearestGrid
(point.x()),
pixelsToNearestGrid
(point.y())};
56
}
57
}
// namespace SILICON::ui
SILICON::ui
Definition
actionGroups.hpp:14
SILICON::ui::GRID_SIZE
constexpr int GRID_SIZE
Definition
grid.hpp:27
SILICON::ui::pixelsToNearestGrid
int pixelsToNearestGrid(qreal value)
Definition
grid.hpp:49
SILICON::ui::pixelsToGrid
int pixelsToGrid(int value)
Definition
grid.hpp:33
SILICON::ui::gridToPixels
int gridToPixels(int value)
Definition
grid.hpp:29
src
ui
circuit
diagram
grid.hpp
Generated by
1.17.0