Skip to content

Commit

Permalink
Added ability to copy selected image to clipboard.
Browse files Browse the repository at this point in the history
  • Loading branch information
OneMoreGres committed Oct 9, 2015
1 parent 350fa4c commit a7977a1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ Manager::Manager (QObject *parent) :
connect (resultDialog_, SIGNAL (requestTranslate (ProcessingItem)),
this, SIGNAL (requestTranslate (ProcessingItem)));
connect (resultDialog_, SIGNAL (requestClipboard ()), SLOT (copyLastToClipboard ()));
connect (resultDialog_, SIGNAL (requestImageClipboard ()),
SLOT (copyLastImageToClipboard ()));
connect (resultDialog_, SIGNAL (requestEdition (ProcessingItem)),
this, SLOT (editRecognized (ProcessingItem)));

Expand Down Expand Up @@ -293,6 +295,14 @@ void Manager::copyLastToClipboard () {
}
}

void Manager::copyLastImageToClipboard () {
const ProcessingItem &item = resultDialog_->item ();
if (item.isValid ()) {
QClipboard *clipboard = QApplication::clipboard ();
clipboard->setPixmap (item.source);
}
}

void Manager::showResult (ProcessingItem item) {
ST_ASSERT (item.isValid ());
if (useResultDialog_) {
Expand Down
1 change: 1 addition & 0 deletions Manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Manager : public QObject {
void about ();
void showLast ();
void copyLastToClipboard ();
void copyLastImageToClipboard ();

void applySettings ();

Expand Down
6 changes: 5 additions & 1 deletion ResultDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ResultDialog::ResultDialog (const LanguageHelper &dictionary, QWidget *parent) :
ui (new Ui::ResultDialog),
dictionary_ (dictionary),
contextMenu_ (NULL), recognizeSubMenu_ (NULL), translateSubMenu_ (NULL),
clipboardAction_ (NULL), correctAction_ (NULL) {
clipboardAction_ (NULL), imageClipboardAction_ (NULL), correctAction_ (NULL) {
ui->setupUi (this);
setWindowFlags (Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint |
Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint);
Expand Down Expand Up @@ -41,6 +41,7 @@ void ResultDialog::createContextMenu () {
recognizeSubMenu_ = contextMenu_->addMenu (tr ("Распознать другой язык"));
translateSubMenu_ = contextMenu_->addMenu (tr ("Перевести на другой язык"));
clipboardAction_ = contextMenu_->addAction (tr ("Скопировать в буфер"));
imageClipboardAction_ = contextMenu_->addAction (tr ("Скопировать рисунок в буфер"));
correctAction_ = contextMenu_->addAction (tr ("Исправить распознанный текст"));
}

Expand All @@ -65,6 +66,9 @@ bool ResultDialog::eventFilter (QObject *object, QEvent *event) {
else if (action == clipboardAction_) {
emit requestClipboard ();
}
else if (action == imageClipboardAction_) {
emit requestImageClipboard ();
}
else if (action == correctAction_) {
emit requestEdition (item_);
// Return because Manager calls showResult() before hide() otherwise.
Expand Down
2 changes: 2 additions & 0 deletions ResultDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ResultDialog : public QDialog {
void requestRecognize (ProcessingItem item);
void requestTranslate (ProcessingItem item);
void requestClipboard (); // Assume that slot will be called immediately.
void requestImageClipboard (); // Assume that slot will be called immediately.
void requestEdition (ProcessingItem item);

public:
Expand All @@ -42,6 +43,7 @@ class ResultDialog : public QDialog {
QMenu *recognizeSubMenu_;
QMenu *translateSubMenu_;
QAction *clipboardAction_;
QAction *imageClipboardAction_;
QAction *correctAction_;
ProcessingItem item_;
};
Expand Down

0 comments on commit a7977a1

Please sign in to comment.