Skip to content

Commit

Permalink
#39 and #47 resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrussmill committed May 29, 2019
1 parent ea1cf7d commit 9264878
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 12 deletions.
6 changes: 6 additions & 0 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <QImage>
#include <QMutex>
#include <QRect>
#include <QAction>
#include <QStackedWidget>
#include <opencv2/imgproc.hpp>
#include <opencv2/imgcodecs.hpp>
Expand Down Expand Up @@ -60,12 +61,17 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
connect(ui->actionZoom_Actual, SIGNAL(triggered()), ui->imageWidget, SLOT(zoomActual()));
connect(ui->actionOpen, SIGNAL(triggered()), this, SLOT(getImagePath()));
connect(ui->actionHistogram, SIGNAL(triggered()), this, SLOT(loadHistogramTool()));
//connect(ui->action)

//right side tool menu - mainwindow/ui slots
connect(ui->quickMenu, SIGNAL(menuItemClicked(int)), ui->toolMenu, SLOT(setCurrentIndex(int)));
connect(ui->toolMenu, SIGNAL(currentChanged(int)), this, SLOT(cancelPreview()));
connect(ui->pushButtonCancel, SIGNAL(released()), this, SLOT(cancelPreview()));
connect(ui->pushButtonApply, SIGNAL(released()), this, SLOT(applyPreviewToMaster()));
connect(ui->actionAdjust, &QAction::triggered, [=](){ui->toolMenu->setCurrentIndex(0);}); //lambda
connect(ui->actionFilter, &QAction::triggered, [=](){ui->toolMenu->setCurrentIndex(1);}); //lambda
connect(ui->actionTemperature, &QAction::triggered, [=](){ui->toolMenu->setCurrentIndex(2);}); //lambda
connect(ui->actionTransform, &QAction::triggered, [=](){ui->toolMenu->setCurrentIndex(3);}); //lambda

//image widget / area - mainwindow/ui slots
connect(ui->imageWidget, SIGNAL(imageNull()), this, SLOT(imageOpenOperationFailed()));
Expand Down
34 changes: 29 additions & 5 deletions mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,10 @@
<property name="title">
<string>Edit</string>
</property>
<addaction name="actionZoom_In"/>
<addaction name="actionZoom_Out"/>
<addaction name="actionZoom_Fit"/>
<addaction name="actionZoom_Actual"/>
<addaction name="separator"/>
<addaction name="actionAdjust"/>
<addaction name="actionFilter"/>
<addaction name="actionTemperature"/>
<addaction name="actionTransform"/>
</widget>
<widget class="QMenu" name="menuHelp">
<property name="title">
Expand All @@ -342,6 +341,11 @@
<property name="title">
<string>Tools</string>
</property>
<addaction name="actionZoom_Fit"/>
<addaction name="actionZoom_In"/>
<addaction name="actionZoom_Out"/>
<addaction name="actionZoom_Actual"/>
<addaction name="separator"/>
<addaction name="actionHistogram"/>
</widget>
<addaction name="menuFile"/>
Expand Down Expand Up @@ -432,6 +436,26 @@
<string>OpenCV...</string>
</property>
</action>
<action name="actionAdjust">
<property name="text">
<string>Adjust...</string>
</property>
</action>
<action name="actionFilter">
<property name="text">
<string>Filter...</string>
</property>
</action>
<action name="actionTemperature">
<property name="text">
<string>Temperature...</string>
</property>
</action>
<action name="actionTransform">
<property name="text">
<string>Transform...</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
Expand Down
21 changes: 15 additions & 6 deletions transformmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ void TransformMenu::initializeSliders()
{
//crop
ui->lineEdit_CropRoiStart->setText("(0, 0)");
ui->lineEdit_CropRoiEnd->setText("("+ QString::number(imageSize_m.width()) +", "
+ QString::number(imageSize_m.height()) +")");
ui->lineEdit_CropRoiEnd->setText("("+ QString::number(imageSize_m.bottomRight().x()) +", "
+ QString::number(imageSize_m.bottomRight().y()) +")");

//scale
ui->spinBox_ScaleHeight->setValue(imageSize_m.height());
Expand Down Expand Up @@ -234,7 +234,7 @@ void TransformMenu::initializeSliders()
}

// setImageResolution sets the default image resolution for initializing menu items
void TransformMenu::setImageResolution(QRect imageSize)
void TransformMenu::setImageResolution(const QRect &imageSize)
{
imageSize_m = imageSize;
initializeSliders();
Expand All @@ -247,15 +247,23 @@ bool TransformMenu::boundCheck(const QRect &ROI)
ROI.getCoords(&x1, &y1, &x2, &y2);
if(x1 >= x2 || y1 >= y2)
return false;
else if(x1 < 0 || y1 < 0 || x2 >= imageSize_m.width() || y2 >= imageSize_m.height())
else if(x1 < 0 || y1 < 0 || x2 > imageSize_m.bottomRight().x() || y2 > imageSize_m.bottomRight().y())
return false;
return true;
}

/* setImageROI is a public slot that when signaled, sets the menu line edits and stored ROI values
* from an external source. It is assumed the ROI is correct on arrival and no further checks are made*/
* from an external source.*/
void TransformMenu::setImageROI(QRect ROI)
{
//if out of bounds, fix bounds
if(ROI.topLeft().y() < 0) ROI.setTopLeft(QPoint(ROI.topLeft().x(), 0));
if(ROI.topLeft().x() < 0) ROI.setTopLeft(QPoint(0, ROI.topLeft().y()));
if(ROI.bottomRight().y() > imageSize_m.bottomRight().y()) ROI.setBottomRight(
QPoint(ROI.bottomRight().x(), imageSize_m.bottomRight().y()));
if(ROI.bottomRight().x() > imageSize_m.bottomRight().x()) ROI.setBottomRight(
QPoint(imageSize_m.bottomRight().x(), ROI.bottomRight().y()));

ui->lineEdit_CropRoiStart->setText("("+ QString::number(ROI.topLeft().x()) +", "
+ QString::number(ROI.topLeft().y()) +")");

Expand All @@ -264,6 +272,7 @@ void TransformMenu::setImageROI(QRect ROI)
+ QString::number(ROI.bottomRight().y()) +")");

ui->label_CropInstruction->setText("Select ROI");

croppedROI_m = ROI;
emit performImageCrop(ROI);
}
Expand All @@ -282,7 +291,7 @@ void TransformMenu::setImageInternalROI()
{
//extract values from match
QRect ROI(QPoint(rectTopLeft.captured(1).toInt(), rectTopLeft.captured(2).toInt()),
QPoint(rectBottomRight.captured(1).toInt() - 1, rectBottomRight.captured(2).toInt() - 1));
QPoint(rectBottomRight.captured(1).toInt(), rectBottomRight.captured(2).toInt()));

if(boundCheck(ROI) && boundCheck(ROI))
{
Expand Down
2 changes: 1 addition & 1 deletion transformmenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public slots:
void initializeSliders();
void receiveImageAddresses(const cv::Mat *masterImage, cv::Mat *previewImage);
void setMenuTracking(bool enable);
void setImageResolution(QRect imageSize);
void setImageResolution(const QRect &imageSize);
void setImageROI(QRect ROI);
void setVisible(bool visible) override;
void showEvent(QShowEvent *event) override;
Expand Down

0 comments on commit 9264878

Please sign in to comment.