Added possibility to capture image from last used screenshot (SelectionDialog).
This commit is contained in:
parent
dd3d92edb6
commit
9e85af0eaf
65
Manager.cpp
65
Manager.cpp
@ -26,7 +26,8 @@ Manager::Manager (QObject *parent) :
|
||||
trayIcon_ (new QSystemTrayIcon (QIcon (":/images/icon.png"), this)),
|
||||
dictionary_ (new LanguageHelper),
|
||||
resultDialog_ (new ResultDialog),
|
||||
captureAction_ (NULL), repeatAction_ (NULL), clipboardAction_ (NULL),
|
||||
captureAction_ (NULL), repeatCaptureAction_ (NULL),
|
||||
repeatAction_ (NULL), clipboardAction_ (NULL),
|
||||
useResultDialog_ (true) {
|
||||
GlobalActionHelper::init ();
|
||||
qRegisterMetaType<ProcessingItem>();
|
||||
@ -72,6 +73,7 @@ Manager::Manager (QObject *parent) :
|
||||
SLOT (processTrayAction (QSystemTrayIcon::ActivationReason)));
|
||||
|
||||
trayIcon_->setContextMenu (trayContextMenu ());
|
||||
updateActionsState ();
|
||||
trayIcon_->show ();
|
||||
|
||||
applySettings ();
|
||||
@ -80,6 +82,8 @@ Manager::Manager (QObject *parent) :
|
||||
QMenu * Manager::trayContextMenu () {
|
||||
QMenu *menu = new QMenu ();
|
||||
captureAction_ = menu->addAction (tr ("Захват"), this, SLOT (capture ()));
|
||||
repeatCaptureAction_ = menu->addAction (tr ("Повторить захват"),
|
||||
this, SLOT (repeatCapture ()));
|
||||
QMenu *translateMenu = menu->addMenu (tr ("Результат"));
|
||||
repeatAction_ = translateMenu->addAction (tr ("Показать"), this,
|
||||
SLOT (showLast ()));
|
||||
@ -91,10 +95,29 @@ QMenu * Manager::trayContextMenu () {
|
||||
return menu;
|
||||
}
|
||||
|
||||
void Manager::setActionsEnabled (bool isEnabled) {
|
||||
void Manager::updateActionsState (bool isEnabled) {
|
||||
#ifdef Q_OS_LINUX
|
||||
// Avoid unneeded tray blinking (required to update context menu).
|
||||
QList<QAction *> actions;
|
||||
actions << captureAction_ << repeatCaptureAction_ << repeatAction_ << clipboardAction_;
|
||||
QList<bool> states;
|
||||
foreach (const QAction * action, actions) {
|
||||
states << action->isEnabled ();
|
||||
}
|
||||
#endif
|
||||
captureAction_->setEnabled (isEnabled);
|
||||
repeatAction_->setEnabled (isEnabled);
|
||||
clipboardAction_->setEnabled (isEnabled);
|
||||
repeatCaptureAction_->setEnabled (isEnabled && !selections_.isEmpty ());
|
||||
repeatAction_->setEnabled (isEnabled && lastItem_.isValid ());
|
||||
clipboardAction_->setEnabled (isEnabled && lastItem_.isValid ());
|
||||
#ifdef Q_OS_LINUX
|
||||
for (int i = 0, end = actions.size (); i < end; ++i) {
|
||||
if (states.at (i) != actions.at (i)->isEnabled ()) {
|
||||
trayIcon_->hide ();
|
||||
trayIcon_->show ();
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Manager::applySettings () {
|
||||
@ -107,6 +130,11 @@ void Manager::applySettings () {
|
||||
captureAction_->setShortcut (GET (captureHotkey).toString ());
|
||||
GlobalActionHelper::makeGlobal (captureAction_);
|
||||
|
||||
Q_CHECK_PTR (repeatCaptureAction_);
|
||||
GlobalActionHelper::removeGlobal (repeatCaptureAction_);
|
||||
repeatCaptureAction_->setShortcut (GET (repeatCaptureHotkey).toString ());
|
||||
GlobalActionHelper::makeGlobal (repeatCaptureAction_);
|
||||
|
||||
Q_CHECK_PTR (repeatAction_);
|
||||
GlobalActionHelper::removeGlobal (repeatAction_);
|
||||
repeatAction_->setShortcut (GET (repeatHotkey).toString ());
|
||||
@ -168,15 +196,32 @@ void Manager::capture () {
|
||||
SelectionDialog *selection = selections_[name];
|
||||
selection->setPixmap (pixmap, geometry);
|
||||
}
|
||||
updateActionsState ();
|
||||
}
|
||||
|
||||
void Manager::repeatCapture () {
|
||||
if (selections_.isEmpty ()) {
|
||||
return;
|
||||
}
|
||||
QList<QScreen *> screens = QApplication::screens ();
|
||||
foreach (QScreen * screen, screens) {
|
||||
QString name = screen->name ();
|
||||
if (!selections_.contains (name)) {
|
||||
continue;
|
||||
}
|
||||
SelectionDialog *selection = selections_[name];
|
||||
selection->show ();
|
||||
selection->activateWindow ();
|
||||
}
|
||||
}
|
||||
|
||||
void Manager::settings () {
|
||||
SettingsEditor editor (*dictionary_);
|
||||
editor.setWindowIcon (trayIcon_->icon ());
|
||||
connect (&editor, SIGNAL (settingsEdited ()), SIGNAL (settingsEdited ()));
|
||||
setActionsEnabled (false);
|
||||
updateActionsState (false);
|
||||
editor.exec ();
|
||||
setActionsEnabled (true);
|
||||
updateActionsState (true);
|
||||
}
|
||||
|
||||
void Manager::close () {
|
||||
@ -198,12 +243,15 @@ void Manager::about () {
|
||||
}
|
||||
|
||||
void Manager::processTrayAction (QSystemTrayIcon::ActivationReason reason) {
|
||||
if (reason == QSystemTrayIcon::Trigger) {
|
||||
if (reason == QSystemTrayIcon::Trigger && repeatAction_->isEnabled ()) {
|
||||
showLast ();
|
||||
}
|
||||
else if (reason == QSystemTrayIcon::MiddleClick) {
|
||||
else if (reason == QSystemTrayIcon::MiddleClick && clipboardAction_->isEnabled ()) {
|
||||
copyLastToClipboard ();
|
||||
}
|
||||
else if (reason == QSystemTrayIcon::DoubleClick && repeatCaptureAction_->isEnabled ()) {
|
||||
repeatCapture ();
|
||||
}
|
||||
}
|
||||
|
||||
void Manager::showLast () {
|
||||
@ -236,6 +284,7 @@ void Manager::showResult (ProcessingItem item) {
|
||||
QString message = item.recognized + " - " + item.translated;
|
||||
trayIcon_->showMessage (tr ("Результат"), message, QSystemTrayIcon::Information);
|
||||
}
|
||||
updateActionsState ();
|
||||
}
|
||||
|
||||
void Manager::showError (QString text) {
|
||||
|
@ -30,6 +30,7 @@ class Manager : public QObject {
|
||||
|
||||
private slots:
|
||||
void capture ();
|
||||
void repeatCapture ();
|
||||
void settings ();
|
||||
void close ();
|
||||
void about ();
|
||||
@ -45,7 +46,7 @@ class Manager : public QObject {
|
||||
|
||||
private:
|
||||
QMenu * trayContextMenu ();
|
||||
void setActionsEnabled (bool isEnabled);
|
||||
void updateActionsState (bool isEnabled = true);
|
||||
|
||||
private:
|
||||
QSystemTrayIcon *trayIcon_;
|
||||
@ -54,6 +55,7 @@ class Manager : public QObject {
|
||||
QMap<QString, SelectionDialog *> selections_;
|
||||
ResultDialog *resultDialog_;
|
||||
QAction *captureAction_;
|
||||
QAction *repeatCaptureAction_;
|
||||
QAction *repeatAction_;
|
||||
QAction *clipboardAction_;
|
||||
ProcessingItem lastItem_;
|
||||
|
@ -8,6 +8,7 @@ namespace settings_names {
|
||||
const QString guiGroup = "GUI";
|
||||
const QString geometry = "geometry";
|
||||
const QString captureHotkey = "captureHotkey";
|
||||
const QString repeatCaptureHotkey = "repeatCaptureHotkey";
|
||||
const QString repeatHotkey = "repeatHotkey";
|
||||
const QString clipboardHotkey = "clipboardHotkey";
|
||||
const QString resultShowType = "resultShowType";
|
||||
@ -32,6 +33,7 @@ namespace settings_values {
|
||||
|
||||
//! UI
|
||||
const QString captureHotkey = "Ctrl+Alt+Z";
|
||||
const QString repeatCaptureHotkey = "Ctrl+Alt+S";
|
||||
const QString repeatHotkey = "Ctrl+Alt+X";
|
||||
const QString clipboardHotkey = "Ctrl+Alt+C";
|
||||
const QString resultShowType = "1";//dialog
|
||||
|
@ -43,6 +43,7 @@ void SettingsEditor::saveSettings () const {
|
||||
QSettings settings;
|
||||
settings.beginGroup (guiGroup);
|
||||
settings.setValue (captureHotkey, ui->captureEdit->keySequence ().toString ());
|
||||
settings.setValue (repeatCaptureHotkey, ui->repeatCaptureEdit->keySequence ().toString ());
|
||||
settings.setValue (repeatHotkey, ui->repeatEdit->keySequence ().toString ());
|
||||
settings.setValue (clipboardHotkey, ui->clipboardEdit->keySequence ().toString ());
|
||||
settings.setValue (resultShowType, buttonGroup_->checkedId ());
|
||||
@ -84,6 +85,7 @@ void SettingsEditor::loadSettings () {
|
||||
|
||||
settings.beginGroup (settings_names::guiGroup);
|
||||
ui->captureEdit->setKeySequence (QKeySequence (GET (captureHotkey).toString ()));
|
||||
ui->repeatCaptureEdit->setKeySequence (QKeySequence (GET (repeatCaptureHotkey).toString ()));
|
||||
ui->repeatEdit->setKeySequence (QKeySequence (GET (repeatHotkey).toString ()));
|
||||
ui->clipboardEdit->setKeySequence (QKeySequence (GET (clipboardHotkey).toString ()));
|
||||
QAbstractButton *button = buttonGroup_->button (GET (resultShowType).toInt ());
|
||||
|
@ -6,61 +6,26 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>518</width>
|
||||
<height>274</height>
|
||||
<width>603</width>
|
||||
<height>269</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Настройки</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_5">
|
||||
<item row="0" column="0">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Горячие клавиши</string>
|
||||
<item row="4" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="toolTip">
|
||||
<string><html><head/><body><p>Сочетание клавиш для перехода в режим захвата.</p></body></html></string>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>1</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Захватить</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QKeySequenceEdit" name="captureEdit"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="toolTip">
|
||||
<string><html><head/><body><p>Сочетание клавиш для повторного отображения последнего результата.</p></body></html></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Показать</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QKeySequenceEdit" name="repeatEdit"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="toolTip">
|
||||
<string><html><head/><body><p>Сочетание клавиш для копирования последнего результата в буфер обмена.</p></body></html></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Скопировать</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QKeySequenceEdit" name="clipboardEdit"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
@ -126,20 +91,17 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<spacer name="horizontalSpacer">
|
||||
<item row="3" column="0" colspan="2">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</spacer>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<item row="2" column="0">
|
||||
<widget class="QGroupBox" name="resultGroup">
|
||||
<property name="title">
|
||||
<string>Вывод результата</string>
|
||||
@ -165,7 +127,68 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" rowspan="2">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Горячие клавиши</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="toolTip">
|
||||
<string><html><head/><body><p>Сочетание клавиш для перехода в режим захвата.</p></body></html></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Захватить</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QKeySequenceEdit" name="captureEdit"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_8">
|
||||
<property name="toolTip">
|
||||
<string><html><head/><body><p>Сочетание клавиш для перехода в режим захвата, но с использованием последнего использованного, а не текущего, изображения.</p></body></html></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Захватить повторно</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QKeySequenceEdit" name="repeatCaptureEdit"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="toolTip">
|
||||
<string><html><head/><body><p>Сочетание клавиш для повторного отображения последнего результата.</p></body></html></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Показать</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QKeySequenceEdit" name="repeatEdit"/>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="toolTip">
|
||||
<string><html><head/><body><p>Сочетание клавиш для копирования последнего результата в буфер обмена.</p></body></html></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Скопировать</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QKeySequenceEdit" name="clipboardEdit"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1" rowspan="2">
|
||||
<widget class="QGroupBox" name="groupBox_3">
|
||||
<property name="title">
|
||||
<string>Перевод</string>
|
||||
@ -200,29 +223,6 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>1</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
|
Loading…
Reference in New Issue
Block a user