Changeset View
Changeset View
Standalone View
Standalone View
libs/flake/KisGamutMaskViewConverter.cpp
- This file was added.
1 | #include "KisGamutMaskViewConverter.h" | ||||
---|---|---|---|---|---|
2 | | ||||
3 | #include <QPointF> | ||||
4 | #include <QRectF> | ||||
5 | #include <QSizeF> | ||||
6 | | ||||
7 | #include <FlakeDebug.h> | ||||
8 | | ||||
9 | //#define DEBUG_GAMUT_MASK_CONVERTER | ||||
10 | | ||||
11 | KisGamutMaskViewConverter::KisGamutMaskViewConverter() | ||||
12 | : m_viewSize(1.0) | ||||
13 | , m_maskSize(QSizeF(1,1)) | ||||
14 | , m_maskResolution(1) | ||||
15 | { | ||||
16 | computeAndSetZoom(); | ||||
17 | } | ||||
18 | | ||||
19 | KisGamutMaskViewConverter::~KisGamutMaskViewConverter() | ||||
20 | { | ||||
21 | } | ||||
22 | | ||||
23 | QPointF KisGamutMaskViewConverter::documentToView(const QPointF &documentPoint) const | ||||
24 | { | ||||
25 | return QPointF(documentToViewX(documentPoint.x()), documentToViewY(documentPoint.y())); | ||||
26 | } | ||||
27 | | ||||
28 | | ||||
29 | QPointF KisGamutMaskViewConverter::viewToDocument(const QPointF &viewPoint) const | ||||
30 | { | ||||
31 | return QPointF(viewToDocumentX(viewPoint.x()), viewToDocumentY(viewPoint.y())); | ||||
32 | } | ||||
33 | | ||||
34 | QRectF KisGamutMaskViewConverter::documentToView(const QRectF &documentRect) const | ||||
35 | { | ||||
36 | return QRectF(documentToView(documentRect.topLeft()), documentToView(documentRect.size())); | ||||
37 | } | ||||
38 | | ||||
39 | QRectF KisGamutMaskViewConverter::viewToDocument(const QRectF &viewRect) const | ||||
40 | { | ||||
41 | return QRectF(viewToDocument(viewRect.topLeft()), viewToDocument(viewRect.size())); | ||||
42 | } | ||||
43 | | ||||
44 | QSizeF KisGamutMaskViewConverter::documentToView(const QSizeF &documentSize) const | ||||
45 | { | ||||
46 | return QSizeF(documentToViewX(documentSize.width()), documentToViewY(documentSize.height())); | ||||
47 | } | ||||
48 | | ||||
49 | QSizeF KisGamutMaskViewConverter::viewToDocument(const QSizeF &viewSize) const | ||||
50 | { | ||||
51 | return QSizeF(viewToDocumentX(viewSize.width()), viewToDocumentY(viewSize.height())); | ||||
52 | } | ||||
53 | | ||||
54 | qreal KisGamutMaskViewConverter::documentToViewX(qreal documentX) const | ||||
55 | { | ||||
56 | qreal translated = documentX * m_zoomLevel; | ||||
57 | | ||||
58 | #ifdef DEBUG_GAMUT_MASK_CONVERTER | ||||
59 | debugFlake << "KisGamutMaskViewConverter::DocumentToViewX: " | ||||
60 | << "documentX: " << documentX | ||||
61 | << " -> translated: " << translated; | ||||
62 | #endif | ||||
63 | | ||||
64 | return translated; | ||||
65 | } | ||||
66 | | ||||
67 | qreal KisGamutMaskViewConverter::documentToViewY(qreal documentY) const | ||||
68 | { | ||||
69 | qreal translated = documentY * m_zoomLevel; | ||||
70 | | ||||
71 | #ifdef DEBUG_GAMUT_MASK_CONVERTER | ||||
72 | debugFlake << "KisGamutMaskViewConverter::DocumentToViewY: " | ||||
73 | << "documentY: " << documentY | ||||
74 | << " -> translated: " << translated; | ||||
75 | #endif | ||||
76 | | ||||
77 | return translated; | ||||
78 | } | ||||
79 | | ||||
80 | qreal KisGamutMaskViewConverter::viewToDocumentX(qreal viewX) const | ||||
81 | { | ||||
82 | qreal translated = viewX / m_zoomLevel; | ||||
83 | | ||||
84 | #ifdef DEBUG_GAMUT_MASK_CONVERTER | ||||
85 | debugFlake << "KisGamutMaskViewConverter::viewToDocumentX: " | ||||
86 | << "viewX: " << viewX | ||||
87 | << " -> translated: " << translated; | ||||
88 | #endif | ||||
89 | | ||||
90 | return translated; | ||||
91 | } | ||||
92 | | ||||
93 | qreal KisGamutMaskViewConverter::viewToDocumentY(qreal viewY) const | ||||
94 | { | ||||
95 | qreal translated = viewY / m_zoomLevel; | ||||
96 | | ||||
97 | #ifdef DEBUG_GAMUT_MASK_CONVERTER | ||||
98 | debugFlake << "KisGamutMaskViewConverter::viewToDocumentY: " | ||||
99 | << "viewY: " << viewY | ||||
100 | << " -> translated: " << translated; | ||||
101 | #endif | ||||
102 | | ||||
103 | return translated; | ||||
104 | } | ||||
105 | | ||||
106 | | ||||
107 | void KisGamutMaskViewConverter::setZoom(qreal zoom) | ||||
108 | { | ||||
109 | if (qFuzzyCompare(zoom, qreal(0.0)) || qFuzzyCompare(zoom, qreal(1.0))) { | ||||
110 | zoom = 1; | ||||
111 | } | ||||
112 | | ||||
113 | #ifdef DEBUG_GAMUT_MASK_CONVERTER | ||||
114 | debugFlake << "KisGamutMaskViewConverter::setZoom: setting to " << zoom; | ||||
115 | #endif | ||||
116 | | ||||
117 | m_zoomLevel = zoom; | ||||
118 | } | ||||
119 | | ||||
120 | void KisGamutMaskViewConverter::zoom(qreal *zoomX, qreal *zoomY) const | ||||
121 | { | ||||
122 | *zoomX = m_zoomLevel; | ||||
123 | *zoomY = m_zoomLevel; | ||||
124 | } | ||||
125 | | ||||
126 | void KisGamutMaskViewConverter::setViewSize(QSize viewSize) | ||||
127 | { | ||||
128 | m_viewSize = viewSize.width(); | ||||
129 | | ||||
130 | computeAndSetZoom(); | ||||
131 | } | ||||
132 | | ||||
133 | void KisGamutMaskViewConverter::setMaskSize(QSizeF maskSize) | ||||
134 | { | ||||
135 | m_maskSize = maskSize; | ||||
136 | m_maskResolution = maskSize.width(); | ||||
137 | | ||||
138 | computeAndSetZoom(); | ||||
139 | } | ||||
140 | | ||||
141 | void KisGamutMaskViewConverter::computeAndSetZoom() | ||||
142 | { | ||||
143 | qreal zoom = m_viewSize / m_maskResolution; | ||||
144 | | ||||
145 | #ifdef DEBUG_GAMUT_MASK_CONVERTER | ||||
146 | debugFlake << "KisGamutMaskViewConverter::computeAndSetZoom: " | ||||
147 | << "m_viewSize: " << m_viewSize | ||||
148 | << " m_maskSize: " << m_maskResolution; | ||||
149 | #endif | ||||
150 | | ||||
151 | setZoom(zoom); | ||||
152 | } |