From ddcaab6f4d08408959eec1229430fcd17f42bfb2 Mon Sep 17 00:00:00 2001 From: uncor3 Date: Fri, 20 Mar 2026 02:40:42 +0000 Subject: [PATCH] add rotation and mirror controls to LiveScreenWidget --- src/livescreenwidget.cpp | 70 ++++++++++++++++++++++++++++++++++++++-- src/livescreenwidget.h | 13 ++++++++ 2 files changed, 80 insertions(+), 3 deletions(-) diff --git a/src/livescreenwidget.cpp b/src/livescreenwidget.cpp index d3b94fe..17e9c6b 100644 --- a/src/livescreenwidget.cpp +++ b/src/livescreenwidget.cpp @@ -23,11 +23,13 @@ #include "devdiskmanager.h" #include "iDescriptor.h" #include +#include #include #include #include #include #include +#include #include LiveScreenWidget::LiveScreenWidget(iDescriptorDevice *device, QWidget *parent) @@ -74,6 +76,38 @@ LiveScreenWidget::LiveScreenWidget(iDescriptorDevice *device, QWidget *parent) m_imageLabel->setAlignment(Qt::AlignCenter); mainLayout->addWidget(m_imageLabel, 1); + // Controls (rotate / mirror), initially hidden, shown when capturing starts + m_controlsWidget = new QWidget(this); + auto *controlsLayout = new QHBoxLayout(m_controlsWidget); + controlsLayout->setContentsMargins(0, 0, 0, 0); + controlsLayout->setSpacing(5); + + m_rotateCwButton = new QPushButton("Rotate ↻", m_controlsWidget); + m_rotateCcwButton = new QPushButton("Rotate ↺", m_controlsWidget); + m_mirrorButton = new QPushButton("Mirror", m_controlsWidget); + + controlsLayout->addWidget(m_rotateCwButton); + controlsLayout->addWidget(m_rotateCcwButton); + controlsLayout->addWidget(m_mirrorButton); + controlsLayout->addStretch(1); + + m_controlsWidget->setVisible(false); + mainLayout->addWidget(m_controlsWidget); + + // button actions + connect(m_rotateCwButton, &QPushButton::clicked, this, [this]() { + m_rotationDegrees = (m_rotationDegrees + 90) % 360; + applyTransformAndDisplay(); + }); + connect(m_rotateCcwButton, &QPushButton::clicked, this, [this]() { + m_rotationDegrees = (m_rotationDegrees + 270) % 360; // -90 mod 360 + applyTransformAndDisplay(); + }); + connect(m_mirrorButton, &QPushButton::clicked, this, [this]() { + m_mirrorHorizontal = !m_mirrorHorizontal; + applyTransformAndDisplay(); + }); + QTimer::singleShot(0, this, &LiveScreenWidget::startInitialization); } @@ -132,6 +166,8 @@ bool LiveScreenWidget::initializeScreenshotService(bool notify) } // Successfully initialized, start capturing m_statusLabel->setText("Capturing"); + if (m_controlsWidget) + m_controlsWidget->setVisible(true); // show rotation/mirror buttons startCapturing(); return true; } catch (const std::exception &e) { @@ -140,6 +176,7 @@ bool LiveScreenWidget::initializeScreenshotService(bool notify) QMessageBox::critical( this, "Exception", QString("Exception occurred: %1").arg(e.what())); + return false; } } @@ -154,9 +191,36 @@ void LiveScreenWidget::startCapturing() m_thread = new ScreenshotrThread(m_screenshotrClient, m_device, this); connect(m_thread, &ScreenshotrThread::screenshotCaptured, this, [this](const QPixmap &pixmap) { - m_imageLabel->setPixmap( - pixmap.scaled(m_imageLabel->size(), Qt::KeepAspectRatio, - Qt::SmoothTransformation)); + // store raw pixmap and render with current rotation/mirror + m_lastPixmap = pixmap; + applyTransformAndDisplay(); }); m_thread->start(); +} + +void LiveScreenWidget::applyTransformAndDisplay() +{ + if (m_lastPixmap.isNull() || !m_imageLabel) + return; + + QTransform transform; + transform.rotate(m_rotationDegrees); + + QPixmap transformed = + m_lastPixmap.transformed(transform, Qt::SmoothTransformation); + + if (m_mirrorHorizontal) { + QTransform mirrorTransform; + mirrorTransform.scale(-1, 1); + transformed = + transformed.transformed(mirrorTransform, Qt::SmoothTransformation); + } + + const QSize targetSize = m_imageLabel->size(); + if (!targetSize.isEmpty()) { + transformed = transformed.scaled(targetSize, Qt::KeepAspectRatio, + Qt::SmoothTransformation); + } + + m_imageLabel->setPixmap(transformed); } \ No newline at end of file diff --git a/src/livescreenwidget.h b/src/livescreenwidget.h index 95d12f9..aa488bc 100644 --- a/src/livescreenwidget.h +++ b/src/livescreenwidget.h @@ -24,6 +24,7 @@ #include "iDescriptor.h" #include "servicemanager.h" #include +#include #include #include #include @@ -85,6 +86,7 @@ private: bool initializeScreenshotService(bool notify); void updateScreenshot(); void startCapturing(); + void applyTransformAndDisplay(); iDescriptorDevice *m_device; QLabel *m_imageLabel; @@ -92,6 +94,17 @@ private: ScreenshotrClientHandle *m_screenshotrClient = nullptr; ScreenshotrThread *m_thread = nullptr; + // controls for rotation / mirroring + QWidget *m_controlsWidget = nullptr; + QPushButton *m_rotateCwButton = nullptr; + QPushButton *m_rotateCcwButton = nullptr; + QPushButton *m_mirrorButton = nullptr; + + // transformation state + QPixmap m_lastPixmap; + int m_rotationDegrees = 0; // 0, 90, 180, 270 + bool m_mirrorHorizontal = false; + private: void startInitialization(); };