About added
This commit is contained in:
		
							parent
							
								
									ff43ab624b
								
							
						
					
					
						commit
						46e13d5141
					
				
							
								
								
									
										34
									
								
								Manager.cpp
									
									
									
									
									
								
							
							
						
						
									
										34
									
								
								Manager.cpp
									
									
									
									
									
								
							@ -1,13 +1,13 @@
 | 
				
			|||||||
#include "Manager.h"
 | 
					#include "Manager.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <QDebug>
 | 
					#include <QDebug>
 | 
				
			||||||
#include <QSystemTrayIcon>
 | 
					 | 
				
			||||||
#include <QMenu>
 | 
					#include <QMenu>
 | 
				
			||||||
#include <QApplication>
 | 
					#include <QApplication>
 | 
				
			||||||
#include <QDesktopWidget>
 | 
					#include <QDesktopWidget>
 | 
				
			||||||
#include <QScreen>
 | 
					#include <QScreen>
 | 
				
			||||||
#include <QThread>
 | 
					#include <QThread>
 | 
				
			||||||
#include <QSettings>
 | 
					#include <QSettings>
 | 
				
			||||||
 | 
					#include <QMessageBox>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "Settings.h"
 | 
					#include "Settings.h"
 | 
				
			||||||
#include "SettingsEditor.h"
 | 
					#include "SettingsEditor.h"
 | 
				
			||||||
@ -54,6 +54,9 @@ Manager::Manager(QObject *parent) :
 | 
				
			|||||||
  connect (this, SIGNAL (settingsEdited ()), recognizer, SLOT (applySettings ()));
 | 
					  connect (this, SIGNAL (settingsEdited ()), recognizer, SLOT (applySettings ()));
 | 
				
			||||||
  connect (this, SIGNAL (settingsEdited ()), translator, SLOT (applySettings ()));
 | 
					  connect (this, SIGNAL (settingsEdited ()), translator, SLOT (applySettings ()));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  connect (trayIcon_, SIGNAL (activated (QSystemTrayIcon::ActivationReason)),
 | 
				
			||||||
 | 
					           SLOT (processTrayAction (QSystemTrayIcon::ActivationReason)));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  trayIcon_->setContextMenu (trayContextMenu ());
 | 
					  trayIcon_->setContextMenu (trayContextMenu ());
 | 
				
			||||||
  trayIcon_->show ();
 | 
					  trayIcon_->show ();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -65,6 +68,7 @@ QMenu*Manager::trayContextMenu()
 | 
				
			|||||||
  QMenu* menu = new QMenu ();
 | 
					  QMenu* menu = new QMenu ();
 | 
				
			||||||
  captureAction_ = menu->addAction (tr ("Захват"), this, SLOT (capture ()));
 | 
					  captureAction_ = menu->addAction (tr ("Захват"), this, SLOT (capture ()));
 | 
				
			||||||
  menu->addAction (tr ("Настройки"), this, SLOT (settings ()));
 | 
					  menu->addAction (tr ("Настройки"), this, SLOT (settings ()));
 | 
				
			||||||
 | 
					  menu->addAction (tr ("О программе"), this, SLOT (about ()));
 | 
				
			||||||
  menu->addAction (tr ("Выход"), this, SLOT (close ()));
 | 
					  menu->addAction (tr ("Выход"), this, SLOT (close ()));
 | 
				
			||||||
  return menu;
 | 
					  return menu;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -82,6 +86,18 @@ void Manager::applySettings()
 | 
				
			|||||||
  GlobalActionHelper::makeGlobal (captureAction_);
 | 
					  GlobalActionHelper::makeGlobal (captureAction_);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void Manager::processTrayAction(QSystemTrayIcon::ActivationReason reason)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  if (reason == QSystemTrayIcon::Trigger)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    if (!lastMessage_.isEmpty ())
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      trayIcon_->showMessage (tr ("Последний перевод"), lastMessage_,
 | 
				
			||||||
 | 
					                              QSystemTrayIcon::Information);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Manager::~Manager()
 | 
					Manager::~Manager()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -111,11 +127,23 @@ void Manager::close()
 | 
				
			|||||||
  QApplication::quit ();
 | 
					  QApplication::quit ();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void Manager::about()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  QString text = tr ("Программа для распознавания текста на экране.\n"\
 | 
				
			||||||
 | 
					                     "Создана с использованием Qt, tesseract-ocr, Google Translate.\n"
 | 
				
			||||||
 | 
					                     "Автор: Gres (dariusiii@qip.ru)");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  QMessageBox message (QMessageBox::Information, tr ("О программе"), text,
 | 
				
			||||||
 | 
					                       QMessageBox::Ok);
 | 
				
			||||||
 | 
					  message.setIconPixmap (trayIcon_->icon ().pixmap (QSize (64, 64)));
 | 
				
			||||||
 | 
					  message.exec ();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Manager::showTranslation(QString sourceText, QString translatedText)
 | 
					void Manager::showTranslation(QString sourceText, QString translatedText)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  QString message = sourceText + " - " + translatedText;
 | 
					  lastMessage_ = sourceText + " - " + translatedText;
 | 
				
			||||||
  qDebug () << sourceText << translatedText;
 | 
					  qDebug () << sourceText << translatedText;
 | 
				
			||||||
  trayIcon_->showMessage (tr ("Перевод"), message, QSystemTrayIcon::Information);
 | 
					  trayIcon_->showMessage (tr ("Перевод"), lastMessage_, QSystemTrayIcon::Information);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Manager::showError(QString text)
 | 
					void Manager::showError(QString text)
 | 
				
			||||||
 | 
				
			|||||||
@ -1,12 +1,11 @@
 | 
				
			|||||||
#ifndef MANAGER_H
 | 
					#ifndef MANAGER_H
 | 
				
			||||||
#define MANAGER_H
 | 
					#define MANAGER_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <QObject>
 | 
					 | 
				
			||||||
#include <QPixmap>
 | 
					#include <QPixmap>
 | 
				
			||||||
 | 
					#include <QSystemTrayIcon>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class QAction;
 | 
					class QAction;
 | 
				
			||||||
class QMenu;
 | 
					class QMenu;
 | 
				
			||||||
class QSystemTrayIcon;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
class SelectionDialog;
 | 
					class SelectionDialog;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -26,9 +25,12 @@ class Manager : public QObject
 | 
				
			|||||||
    void capture ();
 | 
					    void capture ();
 | 
				
			||||||
    void settings ();
 | 
					    void settings ();
 | 
				
			||||||
    void close ();
 | 
					    void close ();
 | 
				
			||||||
 | 
					    void about ();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void applySettings ();
 | 
					    void applySettings ();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    void processTrayAction (QSystemTrayIcon::ActivationReason reason);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void showTranslation (QString sourceText, QString translatedText);
 | 
					    void showTranslation (QString sourceText, QString translatedText);
 | 
				
			||||||
    void showError (QString text);
 | 
					    void showError (QString text);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -39,7 +41,7 @@ class Manager : public QObject
 | 
				
			|||||||
    QSystemTrayIcon* trayIcon_;
 | 
					    QSystemTrayIcon* trayIcon_;
 | 
				
			||||||
    SelectionDialog* selection_;
 | 
					    SelectionDialog* selection_;
 | 
				
			||||||
    QAction* captureAction_;
 | 
					    QAction* captureAction_;
 | 
				
			||||||
 | 
					    QString lastMessage_;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif // MANAGER_H
 | 
					#endif // MANAGER_H
 | 
				
			||||||
 | 
				
			|||||||
@ -21,6 +21,10 @@ void Recognizer::applySettings()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  tessDataDir_ = settings.value (settings_names::tessDataPlace,
 | 
					  tessDataDir_ = settings.value (settings_names::tessDataPlace,
 | 
				
			||||||
                                 settings_values::tessDataPlace).toString ();
 | 
					                                 settings_values::tessDataPlace).toString ();
 | 
				
			||||||
 | 
					  if (tessDataDir_.right (1) != "/")
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    tessDataDir_ += "/";
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
  ocrLanguage_ = settings.value (settings_names::ocrLanguage,
 | 
					  ocrLanguage_ = settings.value (settings_names::ocrLanguage,
 | 
				
			||||||
                                 settings_values::ocrLanguage).toString ();
 | 
					                                 settings_values::ocrLanguage).toString ();
 | 
				
			||||||
  imageScale_ = settings.value (settings_names::imageScale,
 | 
					  imageScale_ = settings.value (settings_names::imageScale,
 | 
				
			||||||
 | 
				
			|||||||
@ -7,7 +7,7 @@
 | 
				
			|||||||
    <x>0</x>
 | 
					    <x>0</x>
 | 
				
			||||||
    <y>0</y>
 | 
					    <y>0</y>
 | 
				
			||||||
    <width>456</width>
 | 
					    <width>456</width>
 | 
				
			||||||
    <height>165</height>
 | 
					    <height>166</height>
 | 
				
			||||||
   </rect>
 | 
					   </rect>
 | 
				
			||||||
  </property>
 | 
					  </property>
 | 
				
			||||||
  <property name="windowTitle">
 | 
					  <property name="windowTitle">
 | 
				
			||||||
@ -22,9 +22,15 @@
 | 
				
			|||||||
     <layout class="QGridLayout" name="gridLayout">
 | 
					     <layout class="QGridLayout" name="gridLayout">
 | 
				
			||||||
      <item row="0" column="0">
 | 
					      <item row="0" column="0">
 | 
				
			||||||
       <widget class="QLabel" name="label">
 | 
					       <widget class="QLabel" name="label">
 | 
				
			||||||
 | 
					        <property name="toolTip">
 | 
				
			||||||
 | 
					         <string><html><head/><body><p>Сочетание клавиш для перехода в режим захвата.</p></body></html></string>
 | 
				
			||||||
 | 
					        </property>
 | 
				
			||||||
        <property name="text">
 | 
					        <property name="text">
 | 
				
			||||||
         <string>Захват</string>
 | 
					         <string>Захват</string>
 | 
				
			||||||
        </property>
 | 
					        </property>
 | 
				
			||||||
 | 
					        <property name="buddy">
 | 
				
			||||||
 | 
					         <cstring>captureEdit</cstring>
 | 
				
			||||||
 | 
					        </property>
 | 
				
			||||||
       </widget>
 | 
					       </widget>
 | 
				
			||||||
      </item>
 | 
					      </item>
 | 
				
			||||||
      <item row="0" column="1">
 | 
					      <item row="0" column="1">
 | 
				
			||||||
@ -41,9 +47,15 @@
 | 
				
			|||||||
     <layout class="QGridLayout" name="gridLayout_3">
 | 
					     <layout class="QGridLayout" name="gridLayout_3">
 | 
				
			||||||
      <item row="0" column="0">
 | 
					      <item row="0" column="0">
 | 
				
			||||||
       <widget class="QLabel" name="label_2">
 | 
					       <widget class="QLabel" name="label_2">
 | 
				
			||||||
 | 
					        <property name="toolTip">
 | 
				
			||||||
 | 
					         <string><html><head/><body><p>Необходимо для распознавания.</p><p>Скачивается отсюда: <a href="https://code.google.com/p/tesseract-ocr/downloads/list"><span style=" text-decoration: underline; color:#0000ff;">https://code.google.com/p/tesseract-ocr/downloads/list</span></a></p></body></html></string>
 | 
				
			||||||
 | 
					        </property>
 | 
				
			||||||
        <property name="text">
 | 
					        <property name="text">
 | 
				
			||||||
         <string>Путь к tessdata</string>
 | 
					         <string>Путь к tessdata</string>
 | 
				
			||||||
        </property>
 | 
					        </property>
 | 
				
			||||||
 | 
					        <property name="buddy">
 | 
				
			||||||
 | 
					         <cstring>tessdataEdit</cstring>
 | 
				
			||||||
 | 
					        </property>
 | 
				
			||||||
       </widget>
 | 
					       </widget>
 | 
				
			||||||
      </item>
 | 
					      </item>
 | 
				
			||||||
      <item row="0" column="1">
 | 
					      <item row="0" column="1">
 | 
				
			||||||
@ -58,16 +70,28 @@
 | 
				
			|||||||
      </item>
 | 
					      </item>
 | 
				
			||||||
      <item row="1" column="0">
 | 
					      <item row="1" column="0">
 | 
				
			||||||
       <widget class="QLabel" name="label_4">
 | 
					       <widget class="QLabel" name="label_4">
 | 
				
			||||||
 | 
					        <property name="toolTip">
 | 
				
			||||||
 | 
					         <string><html><head/><body><p>Заполняется на основании содержания tessdata</p></body></html></string>
 | 
				
			||||||
 | 
					        </property>
 | 
				
			||||||
        <property name="text">
 | 
					        <property name="text">
 | 
				
			||||||
         <string>Язык распознавания</string>
 | 
					         <string>Язык распознавания</string>
 | 
				
			||||||
        </property>
 | 
					        </property>
 | 
				
			||||||
 | 
					        <property name="buddy">
 | 
				
			||||||
 | 
					         <cstring>ocrLangCombo</cstring>
 | 
				
			||||||
 | 
					        </property>
 | 
				
			||||||
       </widget>
 | 
					       </widget>
 | 
				
			||||||
      </item>
 | 
					      </item>
 | 
				
			||||||
      <item row="2" column="0">
 | 
					      <item row="2" column="0">
 | 
				
			||||||
       <widget class="QLabel" name="label_5">
 | 
					       <widget class="QLabel" name="label_5">
 | 
				
			||||||
 | 
					        <property name="toolTip">
 | 
				
			||||||
 | 
					         <string><html><head/><body><p>Масштабирование изображения для улучшения распознания. Больше - лучше (до определенных пределов), но медленнее.</p></body></html></string>
 | 
				
			||||||
 | 
					        </property>
 | 
				
			||||||
        <property name="text">
 | 
					        <property name="text">
 | 
				
			||||||
         <string>Увеличение масштаба</string>
 | 
					         <string>Увеличение масштаба</string>
 | 
				
			||||||
        </property>
 | 
					        </property>
 | 
				
			||||||
 | 
					        <property name="buddy">
 | 
				
			||||||
 | 
					         <cstring>imageScaleSpin</cstring>
 | 
				
			||||||
 | 
					        </property>
 | 
				
			||||||
       </widget>
 | 
					       </widget>
 | 
				
			||||||
      </item>
 | 
					      </item>
 | 
				
			||||||
      <item row="1" column="1" colspan="2">
 | 
					      <item row="1" column="1" colspan="2">
 | 
				
			||||||
@ -87,9 +111,15 @@
 | 
				
			|||||||
     <layout class="QGridLayout" name="gridLayout_2">
 | 
					     <layout class="QGridLayout" name="gridLayout_2">
 | 
				
			||||||
      <item row="0" column="0">
 | 
					      <item row="0" column="0">
 | 
				
			||||||
       <widget class="QLabel" name="label_6">
 | 
					       <widget class="QLabel" name="label_6">
 | 
				
			||||||
 | 
					        <property name="toolTip">
 | 
				
			||||||
 | 
					         <string><html><head/><body><p>Язык, на который осуществляется перевод.</p></body></html></string>
 | 
				
			||||||
 | 
					        </property>
 | 
				
			||||||
        <property name="text">
 | 
					        <property name="text">
 | 
				
			||||||
         <string>Язык результата</string>
 | 
					         <string>Язык результата</string>
 | 
				
			||||||
        </property>
 | 
					        </property>
 | 
				
			||||||
 | 
					        <property name="buddy">
 | 
				
			||||||
 | 
					         <cstring>translateLangCombo</cstring>
 | 
				
			||||||
 | 
					        </property>
 | 
				
			||||||
       </widget>
 | 
					       </widget>
 | 
				
			||||||
      </item>
 | 
					      </item>
 | 
				
			||||||
      <item row="0" column="1">
 | 
					      <item row="0" column="1">
 | 
				
			||||||
@ -136,6 +166,15 @@
 | 
				
			|||||||
   </item>
 | 
					   </item>
 | 
				
			||||||
  </layout>
 | 
					  </layout>
 | 
				
			||||||
 </widget>
 | 
					 </widget>
 | 
				
			||||||
 | 
					 <tabstops>
 | 
				
			||||||
 | 
					  <tabstop>captureEdit</tabstop>
 | 
				
			||||||
 | 
					  <tabstop>translateLangCombo</tabstop>
 | 
				
			||||||
 | 
					  <tabstop>tessdataEdit</tabstop>
 | 
				
			||||||
 | 
					  <tabstop>tessdataButton</tabstop>
 | 
				
			||||||
 | 
					  <tabstop>ocrLangCombo</tabstop>
 | 
				
			||||||
 | 
					  <tabstop>imageScaleSpin</tabstop>
 | 
				
			||||||
 | 
					  <tabstop>buttonBox</tabstop>
 | 
				
			||||||
 | 
					 </tabstops>
 | 
				
			||||||
 <resources/>
 | 
					 <resources/>
 | 
				
			||||||
 <connections>
 | 
					 <connections>
 | 
				
			||||||
  <connection>
 | 
					  <connection>
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user