From a2d1f001b0ad40e606c12ebcc2679ffceb66c387 Mon Sep 17 00:00:00 2001 From: Nick D'Ademo Date: Sun, 8 Dec 2013 19:03:55 +1100 Subject: [PATCH] Add menu item to toggle full screen on/off. Fix issues related to setting ROI which were introduced with the new dynamic window resizing feature. Fix cursor display: value in square brackets now displays cursor "pixel coordinates". --- src/CameraView.cpp | 68 +++++++++++++++++++++++++++++++++++++--------- src/MainWindow.cpp | 9 ++++++ src/MainWindow.h | 1 + src/MainWindow.ui | 23 +++++++++++++++- 4 files changed, 87 insertions(+), 14 deletions(-) diff --git a/src/CameraView.cpp b/src/CameraView.cpp index c1056e0..fb4d600 100644 --- a/src/CameraView.cpp +++ b/src/CameraView.cpp @@ -237,13 +237,31 @@ void CameraView::updateMouseCursorPosLabel() QString(",")+QString::number(ui->frameLabel->getMouseCursorPos().y())+ QString(")")); - // Show ROI-adjusted cursor position if camera is connected - if(isCameraConnected) - ui->mouseCursorPosLabel->setText(ui->mouseCursorPosLabel->text()+ - QString(" [")+QString::number(ui->frameLabel->getMouseCursorPos().x()-(ui->frameLabel->width()-processingThread->getCurrentROI().width())/2)+ - QString(",")+QString::number(ui->frameLabel->getMouseCursorPos().y()-(ui->frameLabel->height()-processingThread->getCurrentROI().height())/2)+ - QString("]")); + // Show pixel cursor position if camera is connected (image is being shown) + if(ui->frameLabel->pixmap()!=0) + { + // Scaling factor calculation depends on whether frame is scaled to fit label or not + if(!ui->frameLabel->hasScaledContents()) + { + double xScalingFactor=((double) ui->frameLabel->getMouseCursorPos().x() - ((ui->frameLabel->width() - ui->frameLabel->pixmap()->width()) / 2)) / (double) ui->frameLabel->pixmap()->width(); + double yScalingFactor=((double) ui->frameLabel->getMouseCursorPos().y() - ((ui->frameLabel->height() - ui->frameLabel->pixmap()->height()) / 2)) / (double) ui->frameLabel->pixmap()->height(); + ui->mouseCursorPosLabel->setText(ui->mouseCursorPosLabel->text()+ + QString(" [")+QString::number((int)(xScalingFactor*processingThread->getCurrentROI().width()))+ + QString(",")+QString::number((int)(yScalingFactor*processingThread->getCurrentROI().height()))+ + QString("]")); + } + else + { + double xScalingFactor=(double) ui->frameLabel->getMouseCursorPos().x() / (double) ui->frameLabel->width(); + double yScalingFactor=(double) ui->frameLabel->getMouseCursorPos().y() / (double) ui->frameLabel->height(); + + ui->mouseCursorPosLabel->setText(ui->mouseCursorPosLabel->text()+ + QString(" [")+QString::number((int)(xScalingFactor*processingThread->getCurrentROI().width()))+ + QString(",")+QString::number((int)(yScalingFactor*processingThread->getCurrentROI().height()))+ + QString("]")); + } + } } void CameraView::newMouseData(struct MouseData mouseData) @@ -255,11 +273,33 @@ void CameraView::newMouseData(struct MouseData mouseData) // Set ROI if(mouseData.leftButtonRelease) { - // Copy box dimensions from mouseData to taskData - selectionBox.setX(mouseData.selectionBox.x()-((ui->frameLabel->width()-captureThread->getInputSourceWidth()))/2); - selectionBox.setY(mouseData.selectionBox.y()-((ui->frameLabel->height()-captureThread->getInputSourceHeight()))/2); - selectionBox.setWidth(mouseData.selectionBox.width()); - selectionBox.setHeight(mouseData.selectionBox.height()); + double xScalingFactor; + double yScalingFactor; + double wScalingFactor; + double hScalingFactor; + + // Selection box calculation depends on whether frame is scaled to fit label or not + if(!ui->frameLabel->hasScaledContents()) + { + xScalingFactor=((double) mouseData.selectionBox.x() - ((ui->frameLabel->width() - ui->frameLabel->pixmap()->width()) / 2)) / (double) ui->frameLabel->pixmap()->width(); + yScalingFactor=((double) mouseData.selectionBox.y() - ((ui->frameLabel->height() - ui->frameLabel->pixmap()->height()) / 2)) / (double) ui->frameLabel->pixmap()->height(); + wScalingFactor=(double) processingThread->getCurrentROI().width() / (double) ui->frameLabel->pixmap()->width(); + hScalingFactor=(double) processingThread->getCurrentROI().height() / (double) ui->frameLabel->pixmap()->height(); + } + else + { + xScalingFactor=(double) mouseData.selectionBox.x() / (double) ui->frameLabel->width(); + yScalingFactor=(double) mouseData.selectionBox.y() / (double) ui->frameLabel->height(); + wScalingFactor=(double) processingThread->getCurrentROI().width() / (double) ui->frameLabel->width(); + hScalingFactor=(double) processingThread->getCurrentROI().height() / (double) ui->frameLabel->height(); + } + + // Set selection box properties (new ROI) + selectionBox.setX(xScalingFactor*processingThread->getCurrentROI().width() + processingThread->getCurrentROI().x()); + selectionBox.setY(yScalingFactor*processingThread->getCurrentROI().height() + processingThread->getCurrentROI().y()); + selectionBox.setWidth(wScalingFactor*mouseData.selectionBox.width()); + selectionBox.setHeight(hScalingFactor*mouseData.selectionBox.height()); + // Check if selection box has NON-ZERO dimensions if((selectionBox.width()!=0)&&((selectionBox.height())!=0)) { @@ -281,8 +321,10 @@ void CameraView::newMouseData(struct MouseData mouseData) // Check if selection box is not outside window if((selectionBox.x()<0)||(selectionBox.y()<0)|| - ((selectionBox.x()+selectionBox.width())>captureThread->getInputSourceWidth())|| - ((selectionBox.y()+selectionBox.height())>captureThread->getInputSourceHeight())) + ((selectionBox.x()+selectionBox.width())>(processingThread->getCurrentROI().x()+processingThread->getCurrentROI().width()))|| + ((selectionBox.y()+selectionBox.height())>(processingThread->getCurrentROI().y()+processingThread->getCurrentROI().height()))|| + (selectionBox.x()getCurrentROI().x())|| + (selectionBox.y()getCurrentROI().y())) { // Display error message QMessageBox::warning(this,"ERROR:","Selection box outside range. Please try again."); diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 11a9a0e..640d6a5 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -59,6 +59,7 @@ MainWindow::MainWindow(QWidget *parent) : // Connect other signals/slots connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(showAboutDialog())); connect(ui->actionQuit, SIGNAL(triggered()), this, SLOT(close())); + connect(ui->actionFullScreen, SIGNAL(toggled(bool)), this, SLOT(setFullScreen(bool))); // Create SharedImageBuffer object sharedImageBuffer = new SharedImageBuffer(); } @@ -261,3 +262,11 @@ void MainWindow::setTabCloseToolTips(QTabWidget *tabs, QString tooltip) item->setToolTip(tooltip); } } + +void MainWindow::setFullScreen(bool input) +{ + if(input) + this->showFullScreen(); + else + this->showNormal(); +} diff --git a/src/MainWindow.h b/src/MainWindow.h index 01192e6..b9cdc2f 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -68,6 +68,7 @@ class MainWindow : public QMainWindow void connectToCamera(); void disconnectCamera(int index); void showAboutDialog(); + void setFullScreen(bool); }; #endif // MAINWINDOW_H diff --git a/src/MainWindow.ui b/src/MainWindow.ui index 20b02d9..b30631a 100644 --- a/src/MainWindow.ui +++ b/src/MainWindow.ui @@ -16,8 +16,14 @@ 0 + + + 0 + 0 + + - qt-opencv-multithreaded + 8tree-core @@ -66,8 +72,15 @@ + + + View + + + + @@ -97,6 +110,14 @@ Scale to fit frame + + + true + + + Full Screen + +