Skip to content

Commit

Permalink
Fixed #26: Added mouse move and mouse release events on output label
Browse files Browse the repository at this point in the history
  • Loading branch information
JairajJangle committed Sep 12, 2020
1 parent bf48ac6 commit 5ededf7
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 17 deletions.
25 changes: 20 additions & 5 deletions CustomWidgets/ClickableLabel/clickablelabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include "clickablelabel.h"

#include <QDebug>

ClickableLabel::ClickableLabel(QWidget* parent)
: QLabel(parent)
{
Expand All @@ -32,6 +34,7 @@ void ClickableLabel::mousePressEvent(QMouseEvent* event)
{
if(event->button() == Qt::LeftButton)
{
ismouseLBMoved = false;
emit LBclicked(QPoint(event->x(), event->y()));
}
if(event->button() == Qt::RightButton)
Expand All @@ -40,8 +43,20 @@ void ClickableLabel::mousePressEvent(QMouseEvent* event)
}
}

//void ClickableLabel::mouseMoveEvent(QMouseEvent *event)
//{
// ClickPos = cv::Point(event->x(), event->y());
// emit clicked();
//}
void ClickableLabel::mouseMoveEvent(QMouseEvent* event)
{
if(event->buttons() == Qt::LeftButton)
{
ismouseLBMoved = true;
emit LBMoved(event->pos());
}
}

void ClickableLabel::mouseReleaseEvent(QMouseEvent* event)
{
if(event->button() == Qt::LeftButton
&& ismouseLBMoved)
{
emit LBReleased(event->pos());
}
}
20 changes: 17 additions & 3 deletions CustomWidgets/ClickableLabel/clickablelabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,34 @@ class ClickableLabel : public QLabel

signals:
/**
* @brief LBclicked Signal fired when Left Mouse Button click is recorded on this widget
* @brief LBclicked Signal fired when Left Mouse Button clicked
*/
void LBclicked(QPoint);

/**
* @brief LBclicked Signal fired when Right Mouse Button click is recorded on this widget
* @brief LBclicked Signal fired when Right Mouse Button clicked
*/
void RBclicked(QPoint);

/**
* @brief LBMoved Signal fired when Left Mouse Button is dragged and moved
*/
void LBMoved(QPoint);

/**
* @brief LBReleased Signal fired when Left Mouse Button is released after a move
*/
void LBReleased(QPoint);

protected:
/**
* @brief mousePressEvent Overriden method from QLabel
* @param event See QLabel::mousePressEvent
*/
void mousePressEvent(QMouseEvent* event) override;
// void mouseMoveEvent(QMouseEvent* event);
void mouseMoveEvent(QMouseEvent* event) override;
void mouseReleaseEvent(QMouseEvent* event) override;

private:
bool ismouseLBMoved = false;
};
12 changes: 11 additions & 1 deletion CustomWidgets/baseconfigwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,22 @@
#include "CustomWidgets/baseconfigwidget.h"
#include "Utils/constants.h"

void BaseConfigWidget::beginPointChanged(QPoint point)
void BaseConfigWidget::mouseLBClicked(QPoint point)
{
if(chainMenuWidget->getRadioButton()->isChecked())
begin = cv::Point(point.x(), point.y());
}

void BaseConfigWidget::mouseLBMoved(QPoint point)
{
qInfo() << "Mouse LB moved at: " << point;
}

void BaseConfigWidget::mouseLBReleased(QPoint point)
{
qInfo() << "Mouse LB released at: " << point;
}

BaseConfigWidget::BaseConfigWidget(){
begin =cv::Point(-1, -1);
end =cv::Point(-1, -1);
Expand Down
4 changes: 3 additions & 1 deletion CustomWidgets/baseconfigwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ class BaseConfigWidget : public QWidget
void operationSelected(ParamAdjustWidget*);

public slots:
void beginPointChanged(QPoint point);
virtual void mouseLBClicked(QPoint point);
virtual void mouseLBMoved(QPoint point);
virtual void mouseLBReleased(QPoint point);

public:
cv::Point begin;
Expand Down
30 changes: 29 additions & 1 deletion Window/MainWindow/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ void MainWindow::connectSignals()

connect(ui->labelOutput, SIGNAL(LBclicked(QPoint)),
this, SLOT(outputLabelLBClicked(QPoint)));
connect(ui->labelOutput, SIGNAL(LBMoved(QPoint)),
this, SLOT(outputLabelLBMoved(QPoint)));
connect(ui->labelOutput, SIGNAL(LBReleased(QPoint)),
this, SLOT(outputLabelLBReleased(QPoint)));

connect(this, SIGNAL(removeOperationWidgetSignal()),
this, SLOT(removeOperationWidget()));
Expand Down Expand Up @@ -170,6 +174,16 @@ void MainWindow::connectSignals()
ui->labelInputFPS->setText(
QString(Strings::fps).arg(fps));
});

// Not yet implemented features
connect(ui->actionSave_Chain, &QAction::triggered,
this, [=](){
setUserMessage("Save Chain feature is not yet implemented", WARNING);
});
connect(ui->actionLoad_Chain, &QAction::triggered,
this, [=](){
setUserMessage("Load Chain feature is not yet implemented", WARNING);
});
}

void MainWindow::addOperation(OPCodes opCode)
Expand Down Expand Up @@ -319,7 +333,11 @@ void MainWindow::addOperationWidget()
});

connect(ui->labelOutput, SIGNAL(LBclicked(QPoint)),
baseConfigWidgetChain.last(), SLOT(beginPointChanged(QPoint)));
baseConfigWidgetChain.last(), SLOT(mouseLBClicked(QPoint)));
connect(ui->labelOutput, SIGNAL(LBMoved(QPoint)),
baseConfigWidgetChain.last(), SLOT(mouseLBMoved(QPoint)));
connect(ui->labelOutput, SIGNAL(LBReleased(QPoint)),
baseConfigWidgetChain.last(), SLOT(mouseLBReleased(QPoint)));

connect(baseConfigWidgetChain.last(), SIGNAL(operationSelected(ParamAdjustWidget*)),
this, SLOT(operationSelectedToDisplay(ParamAdjustWidget*)));
Expand Down Expand Up @@ -911,6 +929,16 @@ void MainWindow::outputLabelLBClicked(QPoint point)
qDebug() << "Output label Mouse LB button click pos = " << point;
}

void MainWindow::outputLabelLBMoved(QPoint point)
{
qDebug() << "Output label Mouse LB button move pos = " << point;
}

void MainWindow::outputLabelLBReleased(QPoint point)
{
qDebug() << "Output label Mouse LB button release pos = " << point;
}

void MainWindow::toggleFlipSource(bool isChecked)
{
isSourceFlipped = isChecked;
Expand Down
14 changes: 8 additions & 6 deletions Window/MainWindow/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ class MainWindow : public QMainWindow
HISTOGRAM_CALCULATION, HARRIS_CORNER, ERODE, DILATE, BITWISE_OPS,
CONTOURS, RESIZE,

/*
* Add all other Enum values before this
*
* To connect OpenCV operation Base Config widget to
* the added OpCodes enum, see MainWindow::addOperation(...)
*/
/*
* Add all other Enum values before this
*
* To connect OpenCV operation Base Config widget to
* the added OpCodes enum, see MainWindow::addOperation(...)
*/
NONE /* Corresponds to OPCodes::NO_OPERATION */ };

private slots:
Expand All @@ -110,6 +110,8 @@ private slots:
void lastOperationChanged(MainWindow::OPCodes opCode);
void showAboutDialog();
void outputLabelLBClicked(QPoint);
void outputLabelLBMoved(QPoint);
void outputLabelLBReleased(QPoint);
void showHideExplodedView(int);
void refreshOutputImage(const cv::Mat img);
void addOperationWidget();
Expand Down

0 comments on commit 5ededf7

Please sign in to comment.