From 4c51e264b5251c89500e89787a5eb671f36a4187 Mon Sep 17 00:00:00 2001 From: Gres Date: Wed, 30 Sep 2015 19:48:21 +0300 Subject: [PATCH] Ignore small selection (less 3x3). --- SelectionDialog.cpp | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/SelectionDialog.cpp b/SelectionDialog.cpp index 96e1d4b..f2b04ad 100644 --- a/SelectionDialog.cpp +++ b/SelectionDialog.cpp @@ -102,25 +102,27 @@ bool SelectionDialog::eventFilter (QObject *object, QEvent *event) { QPoint endPos = mouseEvent->pos (); QRect selection = QRect (startSelectPos_, endPos).normalized (); QPixmap selectedPixmap = currentPixmap_.copy (selection); - if (!selectedPixmap.isNull ()) { - ProcessingItem item; - item.source = selectedPixmap; - item.screenPos = pos () + selection.topLeft (); - - if (mouseEvent->button () == Qt::RightButton && - !languageMenu_->children ().isEmpty ()) { - QAction *action = languageMenu_->exec (QCursor::pos ()); - if (action == NULL) { - reject (); - return QDialog::eventFilter (object, event); - } - item.ocrLanguage = dictionary_.ocrUiToCode (action->text ()); - ST_ASSERT (!item.ocrLanguage.isEmpty ()); - item.sourceLanguage = dictionary_.translateForOcrCode (item.ocrLanguage); - ST_ASSERT (!item.sourceLanguage.isEmpty ()); - } - emit selected (item); + if (selectedPixmap.width () < 3 || selectedPixmap.height () < 3) { + reject (); + return QDialog::eventFilter (object, event); } + ProcessingItem item; + item.source = selectedPixmap; + item.screenPos = pos () + selection.topLeft (); + + if (mouseEvent->button () == Qt::RightButton && + !languageMenu_->children ().isEmpty ()) { + QAction *action = languageMenu_->exec (QCursor::pos ()); + if (action == NULL) { + reject (); + return QDialog::eventFilter (object, event); + } + item.ocrLanguage = dictionary_.ocrUiToCode (action->text ()); + ST_ASSERT (!item.ocrLanguage.isEmpty ()); + item.sourceLanguage = dictionary_.translateForOcrCode (item.ocrLanguage); + ST_ASSERT (!item.sourceLanguage.isEmpty ()); + } + emit selected (item); } } return QDialog::eventFilter (object, event);