Skip to content

Commit

Permalink
Add menu item to toggle full screen on/off.
Browse files Browse the repository at this point in the history
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".
  • Loading branch information
nickdademo committed Dec 8, 2013
1 parent 0c1973a commit a2d1f00
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 14 deletions.
68 changes: 55 additions & 13 deletions src/CameraView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))
{
Expand All @@ -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()<processingThread->getCurrentROI().x())||
(selectionBox.y()<processingThread->getCurrentROI().y()))
{
// Display error message
QMessageBox::warning(this,"ERROR:","Selection box outside range. Please try again.");
Expand Down
9 changes: 9 additions & 0 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
1 change: 1 addition & 0 deletions src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class MainWindow : public QMainWindow
void connectToCamera();
void disconnectCamera(int index);
void showAboutDialog();
void setFullScreen(bool);
};

#endif // MAINWINDOW_H
23 changes: 22 additions & 1 deletion src/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="windowTitle">
<string>qt-opencv-multithreaded</string>
<string>8tree-core</string>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QVBoxLayout" name="verticalLayout">
Expand Down Expand Up @@ -66,8 +72,15 @@
</property>
<addaction name="actionSynchronizeStreams"/>
</widget>
<widget class="QMenu" name="menuView">
<property name="title">
<string>View</string>
</property>
<addaction name="actionFullScreen"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuOptions"/>
<addaction name="menuView"/>
<addaction name="menuHelp"/>
</widget>
<widget class="QStatusBar" name="statusBar"/>
Expand Down Expand Up @@ -97,6 +110,14 @@
<string>Scale to fit frame</string>
</property>
</action>
<action name="actionFullScreen">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Full Screen</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
Expand Down

0 comments on commit a2d1f00

Please sign in to comment.