Skip to content

Commit

Permalink
add rotate
Browse files Browse the repository at this point in the history
Signed-off-by: huangziyi <[email protected]>
  • Loading branch information
MrThanlon committed May 23, 2024
1 parent 6e37c5d commit e114051
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
13 changes: 10 additions & 3 deletions src/plugins/openmv/openmvplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;")).
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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] {
Expand Down Expand Up @@ -2714,7 +2721,7 @@ bool OpenMVPlugin::delayedInitialize()
}
}
});

#endif
// Scan Serial Ports
{
QThread *thread = new QThread;
Expand Down Expand Up @@ -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;
Expand All @@ -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(),
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/openmv/openmvplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 8 additions & 2 deletions src/plugins/openmv/openmvpluginfb.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -145,6 +150,7 @@ void OpenMVPluginFB::frameBufferData(const QPixmap &data)
}

myFitInView(m_pixmap);
// setTransform(transform);

// Broadcast the new pixmap
emit pixmapUpdate(getPixmap());
Expand Down Expand Up @@ -397,7 +403,7 @@ void OpenMVPluginFB::myFitInView(QGraphicsPixmapItem *item)
{
matrix.scale(scale, scale);
}

matrix.rotate(rotation);
setTransform(matrix);

if(item) centerOn(item);
Expand Down
3 changes: 3 additions & 0 deletions src/plugins/openmv/openmvpluginfb.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -67,6 +68,8 @@ public slots:
QTemporaryFile *m_tempFile;
QElapsedTimer m_elaspedTimer;
QQueue<qint64> m_previousElaspedTimers;

qreal rotation;
};

} // namespace Internal
Expand Down

0 comments on commit e114051

Please sign in to comment.