Added possibility to select image several times without closing SelectionDialog.

This commit is contained in:
Gres 2015-09-30 19:49:10 +03:00
parent 4c51e264b5
commit fb1d25f914
6 changed files with 23 additions and 9 deletions

View File

@ -34,7 +34,7 @@ Manager::Manager (QObject *parent) :
// Recognizer
Recognizer *recognizer = new Recognizer;
connect (this, SIGNAL (selected (ProcessingItem)),
connect (this, SIGNAL (requestRecognize (ProcessingItem)),
recognizer, SLOT (recognize (ProcessingItem)));
connect (recognizer, SIGNAL (recognized (ProcessingItem)),
SIGNAL (recognized (ProcessingItem)));
@ -188,8 +188,8 @@ void Manager::capture () {
selection->setWindowIcon (trayIcon_->icon ());
connect (this, SIGNAL (closeSelections ()), selection, SLOT (close ()));
connect (this, SIGNAL (settingsEdited ()), selection, SLOT (updateMenu ()));
connect (selection, SIGNAL (selected (ProcessingItem)), SIGNAL (selected (ProcessingItem)));
connect (selection, SIGNAL (selected (ProcessingItem)), SIGNAL (closeSelections ()));
connect (selection, SIGNAL (selected (ProcessingItem)),
SLOT (handleSelection (ProcessingItem)));
connect (selection, SIGNAL (rejected ()), SIGNAL (closeSelections ()));
selections_[name] = selection;
}
@ -199,6 +199,13 @@ void Manager::capture () {
updateActionsState ();
}
void Manager::handleSelection (ProcessingItem item) {
emit requestRecognize (item);
if (!(item.modifiers & Qt::ControlModifier)) {
emit closeSelections ();
}
}
void Manager::repeatCapture () {
if (selections_.isEmpty ()) {
return;

View File

@ -22,7 +22,7 @@ class Manager : public QObject {
~Manager ();
signals:
void selected (ProcessingItem item);
void requestRecognize (ProcessingItem item);
void recognized (ProcessingItem item);
void requestTranslate (ProcessingItem item);
void closeSelections ();
@ -41,6 +41,7 @@ class Manager : public QObject {
void processTrayAction (QSystemTrayIcon::ActivationReason reason);
void handleSelection (ProcessingItem item);
void showResult (ProcessingItem item);
void showError (QString text);

View File

@ -12,6 +12,8 @@ struct ProcessingItem {
QString ocrLanguage;
QString sourceLanguage;
Qt::KeyboardModifiers modifiers;
bool isValid () const;
};
Q_DECLARE_METATYPE (ProcessingItem)

View File

@ -10,7 +10,7 @@ ResultDialog::ResultDialog (QWidget *parent) :
isShowAtCapturePos_ (true) {
ui->setupUi (this);
setWindowFlags (Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint |
Qt::WindowStaysOnTopHint);
Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint);
installEventFilter (this);
}
@ -21,7 +21,8 @@ ResultDialog::~ResultDialog () {
bool ResultDialog::eventFilter (QObject *object, QEvent *event) {
Q_UNUSED (object);
if (event->type () == QEvent::MouseButtonRelease) {
if (event->type () == QEvent::MouseButtonRelease ||
event->type () == QEvent::WindowDeactivate) {
hide ();
}
return QDialog::eventFilter (object, event);

View File

@ -19,7 +19,7 @@ win32{
linux{
QT += x11extras
INCLUDEPATH += ../linux/include
LIBS += -L../linux/lib -lX11
LIBS += -L../linux/lib -lX11 -Wl,-rpath,.
}
LIBS += -ltesseract -llept
@ -70,4 +70,5 @@ OTHER_FILES += \
app.rc \
images/icon.ico \
README.md \
uncrustify.cfg
uncrustify.cfg\
TODO.md

View File

@ -14,7 +14,7 @@ SelectionDialog::SelectionDialog (const LanguageHelper &dictionary, QWidget *par
languageMenu_ (new QMenu) {
ui->setupUi (this);
setWindowFlags (Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint |
Qt::WindowStaysOnTopHint);
Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint);
ui->label->setAutoFillBackground (false);
ui->label->installEventFilter (this);
@ -101,6 +101,7 @@ bool SelectionDialog::eventFilter (QObject *object, QEvent *event) {
}
QPoint endPos = mouseEvent->pos ();
QRect selection = QRect (startSelectPos_, endPos).normalized ();
startSelectPos_ = currentSelectPos_ = QPoint ();
QPixmap selectedPixmap = currentPixmap_.copy (selection);
if (selectedPixmap.width () < 3 || selectedPixmap.height () < 3) {
reject ();
@ -109,6 +110,7 @@ bool SelectionDialog::eventFilter (QObject *object, QEvent *event) {
ProcessingItem item;
item.source = selectedPixmap;
item.screenPos = pos () + selection.topLeft ();
item.modifiers = mouseEvent->modifiers ();
if (mouseEvent->button () == Qt::RightButton &&
!languageMenu_->children ().isEmpty ()) {