Skip to content

Commit 006abde

Browse files
committed
fine tuning
1 parent 73de366 commit 006abde

File tree

10 files changed

+608
-192
lines changed

10 files changed

+608
-192
lines changed

app/CMakeLists.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
set(APP_NAME "PPUC-Serum-Colorizer")
22
add_executable(${APP_NAME})
33

4+
set(APP_ICON_PNG ${CMAKE_SOURCE_DIR}/icons/app-icon.png)
5+
set(APP_ICON_ICNS ${CMAKE_SOURCE_DIR}/icons/app-icon.icns)
6+
set(APP_ICON_ICO ${CMAKE_SOURCE_DIR}/icons/app-icon.ico)
7+
48
set(HANDBOOK_MD ${CMAKE_SOURCE_DIR}/handbook.md)
59
set(HANDBOOK_QRC ${CMAKE_CURRENT_BINARY_DIR}/handbook.qrc)
610

@@ -30,6 +34,26 @@ target_sources(${APP_NAME} PRIVATE
3034
${HANDBOOK_QRC}
3135
)
3236

37+
if (APPLE)
38+
set_target_properties(${APP_NAME} PROPERTIES
39+
MACOSX_BUNDLE TRUE
40+
MACOSX_BUNDLE_ICON_FILE "app-icon"
41+
)
42+
if (EXISTS ${APP_ICON_ICNS})
43+
set_source_files_properties(${APP_ICON_ICNS} PROPERTIES
44+
MACOSX_PACKAGE_LOCATION "Resources"
45+
)
46+
target_sources(${APP_NAME} PRIVATE ${APP_ICON_ICNS})
47+
endif ()
48+
endif ()
49+
50+
if (WIN32)
51+
set_target_properties(${APP_NAME} PROPERTIES WIN32_EXECUTABLE TRUE)
52+
if (EXISTS ${APP_ICON_ICO})
53+
target_sources(${APP_NAME} PRIVATE app_icon.rc)
54+
endif ()
55+
endif ()
56+
3357
option(COLORIZINGDMD_BUILD_WIN32_APP "Build the legacy Win32 UI sources" OFF)
3458

3559
if (WIN32 AND COLORIZINGDMD_BUILD_WIN32_APP)

app/CanvasWidget.cpp

Lines changed: 41 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,54 @@
11
#include "CanvasWidget.h"
22

33
#include <QLabel>
4-
#include <QResizeEvent>
54
#include <QSignalBlocker>
65
#include <QToolButton>
76
#include <QVBoxLayout>
7+
#include <QHBoxLayout>
88

99
#include "GLCanvasWidget.h"
1010

1111
CanvasWidget::CanvasWidget(const QString& title, QWidget* parent)
1212
: QWidget(parent)
1313
, m_canvas(new GLCanvasWidget(this))
1414
, m_label(new QLabel(title, this))
15-
, m_fitButton(new QToolButton(m_canvas))
16-
, m_backButton(new QToolButton(m_canvas))
17-
, m_forwardButton(new QToolButton(m_canvas))
18-
, m_gridButton(new QToolButton(m_canvas))
19-
, m_originalButton(new QToolButton(m_canvas))
20-
, m_backgroundButton(new QToolButton(m_canvas))
21-
, m_maskButton(new QToolButton(m_canvas))
22-
, m_dynamicButton(new QToolButton(m_canvas))
23-
, m_backgroundMaskButton(new QToolButton(m_canvas))
24-
, m_zoneButton(new QToolButton(m_canvas))
25-
, m_hdButton(new QToolButton(m_canvas))
26-
, m_rotateButton(new QToolButton(m_canvas))
15+
, m_viewLabel(new QLabel(this))
16+
, m_fitButton(new QToolButton(this))
17+
, m_backButton(new QToolButton(this))
18+
, m_forwardButton(new QToolButton(this))
19+
, m_gridButton(new QToolButton(this))
20+
, m_originalButton(new QToolButton(this))
21+
, m_backgroundButton(new QToolButton(this))
22+
, m_maskButton(new QToolButton(this))
23+
, m_dynamicButton(new QToolButton(this))
24+
, m_backgroundMaskButton(new QToolButton(this))
25+
, m_zoneButton(new QToolButton(this))
26+
, m_hdButton(new QToolButton(this))
27+
, m_rotateButton(new QToolButton(this))
2728
{
2829
auto* layout = new QVBoxLayout(this);
30+
auto* toolbar = new QHBoxLayout();
31+
toolbar->setContentsMargins(0, 0, 0, 0);
32+
toolbar->setSpacing(6);
2933
m_canvas->setOverlayText(title);
3034
m_label->setAlignment(Qt::AlignCenter);
35+
m_viewLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
36+
m_viewLabel->setText("Zoom 1.00x Pan 0,0");
37+
toolbar->addWidget(m_backButton);
38+
toolbar->addWidget(m_forwardButton);
39+
toolbar->addWidget(m_fitButton);
40+
toolbar->addWidget(m_gridButton);
41+
toolbar->addWidget(m_originalButton);
42+
toolbar->addWidget(m_backgroundButton);
43+
toolbar->addWidget(m_maskButton);
44+
toolbar->addWidget(m_dynamicButton);
45+
toolbar->addWidget(m_backgroundMaskButton);
46+
toolbar->addWidget(m_zoneButton);
47+
toolbar->addWidget(m_hdButton);
48+
toolbar->addWidget(m_rotateButton);
49+
toolbar->addStretch(1);
50+
toolbar->addWidget(m_viewLabel);
51+
layout->addLayout(toolbar);
3152
layout->addWidget(m_canvas, 1);
3253
layout->addWidget(m_label, 0);
3354
setLayout(layout);
@@ -117,6 +138,13 @@ CanvasWidget::CanvasWidget(const QString& title, QWidget* parent)
117138
m_rotateButton->setToolTip("Preview color rotations");
118139
m_rotateButton->setCursor(Qt::PointingHandCursor);
119140
connect(m_rotateButton, &QToolButton::toggled, this, &CanvasWidget::rotateToggled);
141+
142+
connect(m_canvas, &GLCanvasWidget::zoomPanChanged, this, [this](double zoom, const QPointF& pan) {
143+
m_viewLabel->setText(QString("Zoom %1x Pan %2,%3")
144+
.arg(QString::number(zoom, 'f', 2))
145+
.arg(QString::number(pan.x(), 'f', 1))
146+
.arg(QString::number(pan.y(), 'f', 1)));
147+
});
120148
}
121149

122150
void CanvasWidget::setTitle(const QString& title)
@@ -334,74 +362,3 @@ void CanvasWidget::setHdButtonEnabled(bool enabled)
334362
}
335363
m_hdButton->setEnabled(enabled);
336364
}
337-
338-
void CanvasWidget::resizeEvent(QResizeEvent* event)
339-
{
340-
QWidget::resizeEvent(event);
341-
if (!m_fitButton || !m_backButton || !m_forwardButton || !m_gridButton || !m_originalButton || !m_backgroundButton ||
342-
!m_maskButton || !m_dynamicButton || !m_backgroundMaskButton || !m_zoneButton || !m_hdButton ||
343-
!m_rotateButton) {
344-
return;
345-
}
346-
const int margin = 8;
347-
const QSize forwardSize = m_forwardButton->sizeHint();
348-
const int x = m_canvas->width() - forwardSize.width() - margin;
349-
const int y = margin;
350-
m_forwardButton->move(x, y);
351-
m_forwardButton->raise();
352-
353-
const QSize backSize = m_backButton->sizeHint();
354-
const int backX = x - backSize.width() - 6;
355-
m_backButton->move(backX, y);
356-
m_backButton->raise();
357-
358-
const QSize fitSize = m_fitButton->sizeHint();
359-
const int fitX = backX - fitSize.width() - 6;
360-
m_fitButton->move(fitX, y);
361-
m_fitButton->raise();
362-
363-
const QSize gridSize = m_gridButton->sizeHint();
364-
const int gridX = fitX - gridSize.width() - 6;
365-
m_gridButton->move(gridX, y);
366-
m_gridButton->raise();
367-
368-
const QSize originalSize = m_originalButton->sizeHint();
369-
const int originalX = gridX - originalSize.width() - 6;
370-
m_originalButton->move(originalX, y);
371-
m_originalButton->raise();
372-
373-
const QSize backgroundSize = m_backgroundButton->sizeHint();
374-
const int backgroundX = originalX - backgroundSize.width() - 6;
375-
m_backgroundButton->move(backgroundX, y);
376-
m_backgroundButton->raise();
377-
378-
const QSize dynamicSize = m_dynamicButton->sizeHint();
379-
const int dynamicX = backgroundX - dynamicSize.width() - 6;
380-
m_dynamicButton->move(dynamicX, y);
381-
m_dynamicButton->raise();
382-
383-
const QSize maskSize = m_maskButton->sizeHint();
384-
const int maskX = dynamicX - maskSize.width() - 6;
385-
m_maskButton->move(maskX, y);
386-
m_maskButton->raise();
387-
388-
const QSize zoneSize = m_zoneButton->sizeHint();
389-
const int zoneX = maskX - zoneSize.width() - 6;
390-
m_zoneButton->move(zoneX, y);
391-
m_zoneButton->raise();
392-
393-
const QSize bgSize = m_backgroundMaskButton->sizeHint();
394-
const int bgX = zoneX - bgSize.width() - 6;
395-
m_backgroundMaskButton->move(bgX, y);
396-
m_backgroundMaskButton->raise();
397-
398-
const QSize hdSize = m_hdButton->sizeHint();
399-
const int hdX = bgX - hdSize.width() - 6;
400-
m_hdButton->move(hdX, y);
401-
m_hdButton->raise();
402-
403-
const QSize rotateSize = m_rotateButton->sizeHint();
404-
const int rotateX = hdX - rotateSize.width() - 6;
405-
m_rotateButton->move(rotateX, y);
406-
m_rotateButton->raise();
407-
}

app/CanvasWidget.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
class GLCanvasWidget;
66
class QLabel;
77
class QToolButton;
8+
class QHBoxLayout;
89
namespace cv {
910
class Mat;
1011
}
@@ -57,11 +58,10 @@ class CanvasWidget : public QWidget
5758
void rotateToggled(bool enabled);
5859

5960
protected:
60-
void resizeEvent(QResizeEvent* event) override;
61-
6261
private:
6362
GLCanvasWidget* m_canvas;
6463
QLabel* m_label;
64+
QLabel* m_viewLabel;
6565
QToolButton* m_fitButton;
6666
QToolButton* m_backButton;
6767
QToolButton* m_forwardButton;

app/GLCanvasWidget.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ void GLCanvasWidget::fitToImage()
8989
const double scaleY = height() > 0 ? static_cast<double>(height()) / m_image.rows : 1.0;
9090
m_zoom = std::max(0.1, std::min(scaleX, scaleY));
9191
m_pan = QPointF(0.0, 0.0);
92+
emit zoomPanChanged(m_zoom, m_pan);
9293
update();
9394
}
9495

@@ -212,6 +213,7 @@ void GLCanvasWidget::scaleZoom(double factor)
212213
}
213214
m_zoom = std::max(0.1, m_zoom * factor);
214215
m_fitOnResize = false;
216+
emit zoomPanChanged(m_zoom, m_pan);
215217
update();
216218
}
217219

@@ -467,12 +469,6 @@ void GLCanvasWidget::paintGL()
467469
}
468470

469471
painter.setPen(QColor(150, 150, 150));
470-
painter.drawText(QRect(10, 10, width() - 20, 20),
471-
Qt::AlignLeft,
472-
QString("Zoom %1x Pan %2,%3")
473-
.arg(QString::number(m_zoom, 'f', 2))
474-
.arg(QString::number(m_pan.x(), 'f', 1))
475-
.arg(QString::number(m_pan.y(), 'f', 1)));
476472
}
477473

478474
namespace {
@@ -528,6 +524,7 @@ void GLCanvasWidget::wheelEvent(QWheelEvent* event)
528524
const double delta = event->angleDelta().y() / 120.0;
529525
m_zoom = std::max(0.1, m_zoom + delta * 0.1);
530526
m_fitOnResize = false;
527+
emit zoomPanChanged(m_zoom, m_pan);
531528
update();
532529
}
533530

@@ -566,6 +563,7 @@ void GLCanvasWidget::mouseMoveEvent(QMouseEvent* event)
566563
m_pan += QPointF(delta.x(), delta.y());
567564
m_lastPos = event->pos();
568565
m_fitOnResize = false;
566+
emit zoomPanChanged(m_zoom, m_pan);
569567
update();
570568
}
571569
if (!m_panning && (event->buttons() & (Qt::LeftButton | Qt::RightButton))) {

app/GLCanvasWidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class GLCanvasWidget : public QOpenGLWidget, protected QOpenGLFunctions
3636
void imageReleased(int x, int y, Qt::MouseButton button, Qt::KeyboardModifiers modifiers);
3737
void maskDropped(const QString& kind, int index);
3838
void imageHovered(int x, int y, bool onImage);
39+
void zoomPanChanged(double zoom, const QPointF& pan);
3940

4041
protected:
4142
void initializeGL() override;

0 commit comments

Comments
 (0)