From e114051625d6f9d4b19747ecf3fc18dad7110076 Mon Sep 17 00:00:00 2001 From: huangziyi Date: Thu, 23 May 2024 14:21:38 +0800 Subject: [PATCH] add rotate Signed-off-by: huangziyi --- src/plugins/openmv/openmvplugin.cpp | 13 ++++++++++--- src/plugins/openmv/openmvplugin.h | 2 ++ src/plugins/openmv/openmvpluginfb.cpp | 10 ++++++++-- src/plugins/openmv/openmvpluginfb.h | 3 +++ 4 files changed, 23 insertions(+), 5 deletions(-) mode change 100644 => 100755 src/plugins/openmv/openmvpluginfb.cpp mode change 100644 => 100755 src/plugins/openmv/openmvpluginfb.h diff --git a/src/plugins/openmv/openmvplugin.cpp b/src/plugins/openmv/openmvplugin.cpp index 3a7aeff2999..68748eb0233 100755 --- a/src/plugins/openmv/openmvplugin.cpp +++ b/src/plugins/openmv/openmvplugin.cpp @@ -2059,6 +2059,11 @@ void OpenMVPlugin::extensionsInitialized() } }); + m_rotate = new QToolButton; + m_rotate->setText(Tr::tr("Rotate")); + m_rotate->setToolTip(Tr::tr("Rotate the frame buffer")); + styledBar0Layout->addWidget(m_rotate); + Utils::ElidingLabel *disableLabel = new Utils::ElidingLabel(Tr::tr("Frame Buffer Disabled - click the disable button again to enable (top right)")); disableLabel->setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Preferred, QSizePolicy::Label)); disableLabel->setStyleSheet(QString(QStringLiteral("background-color:%1;color:%2;padding:4px;")). @@ -2089,6 +2094,7 @@ void OpenMVPlugin::extensionsInitialized() tempWidget0->setLayout(tempLayout0); connect(zoomButton, &QToolButton::toggled, m_frameBuffer, &OpenMVPluginFB::enableFitInView); + connect(m_rotate, &QToolButton::clicked, m_frameBuffer, &OpenMVPluginFB::rotate); connect(m_iodevice, &OpenMVPluginIO::frameBufferData, this, [this] (const QPixmap &data) { if(!m_disableFrameBuffer->isChecked()) m_frameBuffer->frameBufferData(data); }); connect(m_frameBuffer, &OpenMVPluginFB::saveImage, this, &OpenMVPlugin::saveImage); connect(m_frameBuffer, &OpenMVPluginFB::saveTemplate, this, &OpenMVPlugin::saveTemplate); @@ -2674,6 +2680,7 @@ void OpenMVPlugin::extensionsInitialized() bool OpenMVPlugin::delayedInitialize() { +#if USE_WIFI_CONNECT QUdpSocket *socket = new QUdpSocket(this); connect(socket, &QUdpSocket::readyRead, this, [this, socket] { @@ -2714,7 +2721,7 @@ bool OpenMVPlugin::delayedInitialize() } } }); - +#endif // Scan Serial Ports { QThread *thread = new QThread; @@ -2775,7 +2782,7 @@ bool OpenMVPlugin::delayedInitialize() timer->start(1000); QTimer::singleShot(0, scanSerialPortsThread, &ScanSerialPortsThread::scanSerialPortsSlot); } - +#if USE_WIFI_CONNECT if(!socket->bind(OPENMVCAM_BROADCAST_PORT)) { delete socket; @@ -2785,7 +2792,7 @@ bool OpenMVPlugin::delayedInitialize() Tr::tr("Another application is using the OpenMV Cam broadcast discovery port. " "Please close that application and restart OpenMV IDE to enable WiFi programming.")); } - +#endif if(!QDir().mkpath(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + QStringLiteral("/OpenMV"))) { QMessageBox::warning(Core::ICore::dialogParent(), diff --git a/src/plugins/openmv/openmvplugin.h b/src/plugins/openmv/openmvplugin.h index 1c54c5712ce..b733ba87f7c 100755 --- a/src/plugins/openmv/openmvplugin.h +++ b/src/plugins/openmv/openmvplugin.h @@ -413,6 +413,8 @@ public slots: // private QToolButton *m_jpgCompress; QToolButton *m_disableFrameBuffer; + QToolButton *m_rotate; + OpenMVDatasetEditor *m_datasetEditor; OpenMVPluginFB *m_frameBuffer; OpenMVPluginHistogram *m_histogram; diff --git a/src/plugins/openmv/openmvpluginfb.cpp b/src/plugins/openmv/openmvpluginfb.cpp old mode 100644 new mode 100755 index eec2035b892..490a4b5fb17 --- a/src/plugins/openmv/openmvpluginfb.cpp +++ b/src/plugins/openmv/openmvpluginfb.cpp @@ -11,7 +11,7 @@ namespace OpenMV { namespace Internal { -OpenMVPluginFB::OpenMVPluginFB(QWidget *parent) : QGraphicsView(parent), m_enableSaveTemplate(false), m_enableSaveDescriptor(false), m_enableInteraction(true) +OpenMVPluginFB::OpenMVPluginFB(QWidget *parent) : QGraphicsView(parent), m_enableSaveTemplate(false), m_enableSaveDescriptor(false), m_enableInteraction(true), rotation(0) { setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); @@ -103,6 +103,11 @@ void OpenMVPluginFB::endImageWriter() m_tempFile = Q_NULLPTR; } +void OpenMVPluginFB::rotate() { + rotation += 90; + myFitInView(m_pixmap); +} + void OpenMVPluginFB::enableFitInView(bool enable) { m_enableFitInView = enable; @@ -145,6 +150,7 @@ void OpenMVPluginFB::frameBufferData(const QPixmap &data) } myFitInView(m_pixmap); + // setTransform(transform); // Broadcast the new pixmap emit pixmapUpdate(getPixmap()); @@ -397,7 +403,7 @@ void OpenMVPluginFB::myFitInView(QGraphicsPixmapItem *item) { matrix.scale(scale, scale); } - + matrix.rotate(rotation); setTransform(matrix); if(item) centerOn(item); diff --git a/src/plugins/openmv/openmvpluginfb.h b/src/plugins/openmv/openmvpluginfb.h old mode 100644 new mode 100755 index 7068a19e3db..c198ce47f4d --- a/src/plugins/openmv/openmvpluginfb.h +++ b/src/plugins/openmv/openmvpluginfb.h @@ -28,6 +28,7 @@ public slots: void enableSaveTemplate(bool enable) { m_enableSaveTemplate = enable; } void enableSaveDescriptor(bool enable) { m_enableSaveDescriptor = enable; } void private_timerCallBack(); + void rotate(); signals: @@ -67,6 +68,8 @@ public slots: QTemporaryFile *m_tempFile; QElapsedTimer m_elaspedTimer; QQueue m_previousElaspedTimers; + + qreal rotation; }; } // namespace Internal