-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOutputGLCanvas.cpp
257 lines (227 loc) · 8.05 KB
/
OutputGLCanvas.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/*
* OutputGLCanvas.cpp
*
* (c) 2013 Sofian Audry -- info(@)sofianaudry(.)com
* (c) 2013 Alexandre Quessy -- alexandre(@)quessy(.)net
* (c) 2014 Dame Diongue -- baydamd(@)gmail(.)com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "OutputGLCanvas.h"
#include "MainWindow.h"
namespace mmp {
OutputGLCanvas::OutputGLCanvas(MainWindow* mainWindow, QWidget* parent, const QGLWidget* shareWidget, QGraphicsScene* scene)
: MapperGLCanvas(mainWindow, true, parent, shareWidget, scene),
_displayCrosshair(false),
_displayTestSignal(false)
{
// Disable scrollbars.
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setSceneRectToViewportGeometry();
}
void OutputGLCanvas::setSceneRectToViewportGeometry()
{
setSceneRect(viewport()->geometry());
}
void OutputGLCanvas::drawForeground(QPainter *painter , const QRectF &rect)
{
if (_displayTestSignal)
{
// Draw the preferred signal test card
QSettings settings;
int testCard = settings.value("signalTestCard", MM::DEFAULT_TEST_CARD).toInt();
glPushMatrix();
painter->translate(rect.x(), rect.y());
painter->setRenderHint(QPainter::Antialiasing);
painter->save();
switch (testCard) {
case MM::Classic:
_drawClassicTestSignal(painter);
break;
case MM::PAL:
_drawPALTestCard(painter);
break;
case MM::NTSC:
_drawNTSCTestCard(painter);
break;
default: // Do nothing;
break;
}
painter->restore();
glPopMatrix();
}
else
{
MapperGLCanvas::drawForeground(painter, rect);
// Display crosshair cursor.
if (_displayCrosshair)
{
#ifdef Q_OS_OSX
QPoint globalCursorPos = QCursor::pos();
int mouseScreen = QApplication::desktop()->screenNumber(globalCursorPos);
QRect mouseScreenGeometry = QApplication::desktop()->screen(mouseScreen)->geometry();
QPoint localCursorPos = globalCursorPos - mouseScreenGeometry.topLeft();
QPointF cursorPosition = mapToScene(localCursorPos);
// qDebug() << "Cursor pos " << globalCursorPos << " " << cursorPosition << " " << localCursorPos << mouseScreen << endl;
if (rect.contains(cursorPosition) && getMainWindow()->getPreferredScreen() == mouseScreen)
// qDebug() << "Cursor pos " << mapToScene(mapFromGlobal(QCursor::pos(QApplication::screens()[1])));
#else
QPointF cursorPosition = mapToScene(mapFromGlobal(cursor().pos()));// - rect.topLeft();//(QCursor::pos());///*this->mapFromGlobal(*/QCursor::pos()/*)*/;
if (rect.contains(cursorPosition))
#endif
{
// painter->setPen(MM::CONTROL_COLOR);
// painter->drawLine(cursorPosition.x(), rect.y(), cursorPosition.x(), rect.height());
// painter->drawLine(rect.x(), cursorPosition.y(), rect.width(), cursorPosition.y());
// Draw crosshair line
painter->setPen(MM::CROSSHAIR_STROKE);
painter->setBrush(MM::CONTROL_COLOR);
painter->drawRect(cursorPosition.x() - 2, rect.y(), 4, rect.height());
painter->drawRect(rect.x(), cursorPosition.y() - 2, rect.width(), 4);
// Draw crosshair pointer
painter->setPen(MM::CONTROL_COLOR);
painter->setBrush(MM::CROSSHAIR_STROKE);
painter->drawRect(cursorPosition.x() - 10, cursorPosition.y() - 10, 20, 20);
}
}
}
}
void OutputGLCanvas::_drawClassicTestSignal(QPainter* painter)
{
const QRect& geo = geometry();
int width = geo.width();
int height = geo.height();
int rectSize = 10;
QColor darkerGray(191, 191, 191);
QColor darkGray(Qt::darkGray);
painter->setPen(Qt::NoPen);
// Draw checkerboard pattern.
for (int x = geo.x(); x < width; x += rectSize)
{
for (int y = geo.y(); y < height; y += rectSize)
{
if (((x + y) % 20) == 0)
{
painter->setBrush(darkerGray);
} else {
painter->setBrush(darkGray);
}
painter->drawRect(x, y, rectSize, rectSize);
}
}
// Create responsive image
_classicTestCard = QImage(":/test-signal").scaled(height, height, Qt::KeepAspectRatio, Qt::SmoothTransformation);
int imageX = (width - _classicTestCard.width()) / 2;
int imageY = (height - _classicTestCard.height()) / 2;
// Draw the image.
painter->drawImage(imageX, imageY, _classicTestCard);
}
void OutputGLCanvas::_drawPALTestCard(QPainter* painter)
{
const QRect& geo = geometry();
int width = geo.width();
int height = geo.height();
int rectSize = 85;
int marginX = (rectSize - width % rectSize) / 2;
int marginY = (rectSize - height % rectSize) / 2;
QColor black(Qt::black);
QColor white(Qt::white);
QColor darkGray(Qt::darkGray);
// Draw checkerboard pattern.
for (int x = geo.x(); x < width; x += rectSize)
{
for (int y = geo.y(); y < height; y += rectSize)
{
painter->setPen(Qt::NoPen);
if (((x + y) % (rectSize * 2)) == 0)
{
painter->setBrush(QBrush(white));
} else {
painter->setBrush(QBrush(black));
}
if ((x > 0 && x <= (width - rectSize)) && (y > 0 && y <= (height - rectSize))) {
painter->setBrush(QBrush(darkGray));
painter->setPen(QPen(QBrush(white), 3));
}
painter->drawRect(x - marginX, y - marginY, rectSize, rectSize);
}
}
// Create responsive image
_palTestCard = QImage(":/pal-test-card").scaled(height - (rectSize * 2), height - (rectSize * 2),
Qt::KeepAspectRatio, Qt::SmoothTransformation);
// Draw image
int imageX = (width - _palTestCard.width()) / 2;
int imageY = (height - _palTestCard.height()) / 2;
int imageHeight = _palTestCard.height();
painter->drawImage(imageX, imageY, _palTestCard);
// Draw text for screen resolution
int fontSize = imageHeight / 18;
QRect textRect((width / 2) - (fontSize * 3), imageY + (imageHeight / 19), fontSize * 6, fontSize);
_drawResolutionText(painter, textRect, fontSize);
}
void OutputGLCanvas::_drawNTSCTestCard(QPainter* painter)
{
const QRect& geo = geometry();
int width = geo.width();
int height = geo.height();
// Create image
_ntscTestCard = QImage(":/ntsc-test-card").scaled(width, height);
// Draw backgroung image
painter->drawImage(geo.x(), geo.y(), _ntscTestCard);
// Draw logo
QImage mapmapLogo = QImage(":/mapmap-logo-with-border").scaled(width, height / 15, Qt::KeepAspectRatio, Qt::SmoothTransformation);
painter->drawImage((width - mapmapLogo.width()) / 2, height / 4, mapmapLogo);
// Draw text for screen resolution
int fontSize = height / 21;
QRect textRect((width / 2) - (fontSize * 3), height / 3, fontSize * 6, fontSize);
_drawResolutionText(painter, textRect, fontSize);
}
void OutputGLCanvas::_drawResolutionText(QPainter *painter, const QRect &rect, int fontSize)
{
QSettings settings;
if (settings.value("showResolution").toBool())
{
painter->fillRect(rect, Qt::black);
QFont font = painter->font();
font.setPixelSize(fontSize);
font.setBold(true);
painter->setFont(font);
painter->setPen(Qt::white);
painter->drawText(rect, Qt::AlignCenter,
QString::number(geometry().width()) +
" x " + QString::number(geometry().height()));
}
}
void OutputGLCanvas::resizeGL(int width, int height)
{
setSceneRectToViewportGeometry();
}
void OutputGLCanvas::wheelEvent(QWheelEvent *event)
{
event->ignore();
}
void OutputGLCanvas::mouseMoveEvent(QMouseEvent *event)
{
// Click-and-drag translate view.
if (event->buttons() & Qt::MiddleButton)
{
event->ignore();
}
else
{
MapperGLCanvas::mouseMoveEvent(event);
}
}
}