Port to qt6
This commit is contained in:
parent
12997389ff
commit
6eb5a6d9f1
@ -14,7 +14,7 @@ win32{
|
|||||||
LIBS += -lUser32
|
LIBS += -lUser32
|
||||||
}
|
}
|
||||||
linux{
|
linux{
|
||||||
QT += x11extras
|
# QT += x11extras
|
||||||
LIBS += -lX11
|
LIBS += -lX11
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QTextCodec>
|
#include <QStringConverter>
|
||||||
|
|
||||||
static int levenshteinDistance(const QString &source, const QString &target)
|
static int levenshteinDistance(const QString &source, const QString &target)
|
||||||
{
|
{
|
||||||
@ -106,19 +106,21 @@ QString HunspellCorrector::correct(const QString &original)
|
|||||||
{
|
{
|
||||||
SOFT_ASSERT(engine_, return original);
|
SOFT_ASSERT(engine_, return original);
|
||||||
|
|
||||||
const auto codec =
|
const auto encoding =
|
||||||
QTextCodec::codecForName(engine_->get_dict_encoding().c_str());
|
QStringConverter::encodingForName(engine_->get_dict_encoding().c_str());
|
||||||
SOFT_ASSERT(codec, return original);
|
SOFT_ASSERT(encoding, return original);
|
||||||
|
auto codec = QStringEncoder(*encoding);
|
||||||
|
|
||||||
QString result;
|
QString result;
|
||||||
|
|
||||||
QString word;
|
QString word;
|
||||||
QString separator;
|
QString separator;
|
||||||
for (auto i = 0, end = original.size(); i < end; ++i) {
|
|
||||||
|
for (auto i = 0ll, end = original.size(); i < end; ++i) {
|
||||||
const auto ch = original[i];
|
const auto ch = original[i];
|
||||||
if (ch.isPunct() || ch.isSpace()) {
|
if (ch.isPunct() || ch.isSpace()) {
|
||||||
if (!word.isEmpty()) {
|
if (!word.isEmpty()) {
|
||||||
correctWord(word, *codec);
|
correctWord(word, codec);
|
||||||
result += word;
|
result += word;
|
||||||
word.clear();
|
word.clear();
|
||||||
}
|
}
|
||||||
@ -139,7 +141,7 @@ QString HunspellCorrector::correct(const QString &original)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!word.isEmpty()) {
|
if (!word.isEmpty()) {
|
||||||
correctWord(word, *codec);
|
correctWord(word, codec);
|
||||||
result += word;
|
result += word;
|
||||||
}
|
}
|
||||||
result += separator;
|
result += separator;
|
||||||
@ -147,12 +149,12 @@ QString HunspellCorrector::correct(const QString &original)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HunspellCorrector::correctWord(QString &word, QTextCodec &codec) const
|
void HunspellCorrector::correctWord(QString &word, QStringEncoder &codec) const
|
||||||
{
|
{
|
||||||
if (word.isEmpty())
|
if (word.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const auto stdWord = codec.fromUnicode(word).toStdString();
|
const auto stdWord = codec(word).data.toStdString();
|
||||||
if (engine_->spell(stdWord))
|
if (engine_->spell(stdWord))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
class Hunspell;
|
class Hunspell;
|
||||||
|
class QStringEncoder;
|
||||||
|
|
||||||
class HunspellCorrector
|
class HunspellCorrector
|
||||||
{
|
{
|
||||||
@ -19,7 +20,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void init(const QString& path);
|
void init(const QString& path);
|
||||||
void correctWord(QString& word, QTextCodec& codec) const;
|
void correctWord(QString& word, QStringEncoder& codec) const;
|
||||||
|
|
||||||
std::unique_ptr<Hunspell> engine_;
|
std::unique_ptr<Hunspell> engine_;
|
||||||
QString error_;
|
QString error_;
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QNetworkProxy>
|
#include <QNetworkProxy>
|
||||||
|
#include <QStandardPaths>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
@ -187,7 +188,8 @@ bool Manager::setupTrace(bool isOn)
|
|||||||
const auto traceFile =
|
const auto traceFile =
|
||||||
QStandardPaths::writableLocation(QStandardPaths::TempLocation) +
|
QStandardPaths::writableLocation(QStandardPaths::TempLocation) +
|
||||||
QLatin1String("/screen-translator-") +
|
QLatin1String("/screen-translator-") +
|
||||||
QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss");
|
QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss") +
|
||||||
|
QLatin1String(".txt");
|
||||||
|
|
||||||
if (!debug::setTraceFileName(traceFile)) {
|
if (!debug::setTraceFileName(traceFile)) {
|
||||||
QMessageBox::warning(
|
QMessageBox::warning(
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
Q_MOC_INCLUDE("tesseract.h")
|
||||||
|
|
||||||
class Tesseract;
|
class Tesseract;
|
||||||
|
|
||||||
class RecognizeWorker : public QObject
|
class RecognizeWorker : public QObject
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QBoxLayout>
|
#include <QBoxLayout>
|
||||||
#include <QDesktopWidget>
|
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
@ -70,7 +69,7 @@ ResultWidget::ResultWidget(Manager &manager, Representer &representer,
|
|||||||
layout->addWidget(separator_);
|
layout->addWidget(separator_);
|
||||||
layout->addWidget(translated_);
|
layout->addWidget(translated_);
|
||||||
|
|
||||||
layout->setMargin(0);
|
layout->setContentsMargins(0, 0, 0, 0);
|
||||||
layout->setSpacing(0);
|
layout->setSpacing(0);
|
||||||
|
|
||||||
updateSettings();
|
updateSettings();
|
||||||
|
@ -77,7 +77,7 @@ void GlobalAction::triggerHotKey(quint32 nativeKey, quint32 nativeMods)
|
|||||||
#ifdef Q_OS_LINUX
|
#ifdef Q_OS_LINUX
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <xcb/xcb_event.h>
|
#include <xcb/xcb_event.h>
|
||||||
#include <QX11Info>
|
#include <QWindow>
|
||||||
|
|
||||||
namespace service
|
namespace service
|
||||||
{
|
{
|
||||||
@ -101,18 +101,22 @@ static int customHandler(Display *display, XErrorEvent *event)
|
|||||||
|
|
||||||
bool GlobalAction::registerHotKey(quint32 nativeKey, quint32 nativeMods)
|
bool GlobalAction::registerHotKey(quint32 nativeKey, quint32 nativeMods)
|
||||||
{
|
{
|
||||||
Display *display = QX11Info::display();
|
auto nativeInterface =
|
||||||
Window window = QX11Info::appRootWindow();
|
qApp->nativeInterface<QNativeInterface::QX11Application>();
|
||||||
|
SOFT_ASSERT(nativeInterface, return false);
|
||||||
|
Display *display = nativeInterface->display();
|
||||||
|
SOFT_ASSERT(display, return false);
|
||||||
Bool owner = True;
|
Bool owner = True;
|
||||||
int pointer = GrabModeAsync;
|
int pointer = GrabModeAsync;
|
||||||
int keyboard = GrabModeAsync;
|
int keyboard = GrabModeAsync;
|
||||||
error = false;
|
error = false;
|
||||||
int (*handler)(Display * display, XErrorEvent * event) =
|
int (*handler)(Display * display, XErrorEvent * event) =
|
||||||
XSetErrorHandler(customHandler);
|
XSetErrorHandler(customHandler);
|
||||||
XGrabKey(display, nativeKey, nativeMods, window, owner, pointer, keyboard);
|
XGrabKey(display, nativeKey, nativeMods, DefaultRootWindow(display), owner,
|
||||||
|
pointer, keyboard);
|
||||||
// allow numlock
|
// allow numlock
|
||||||
XGrabKey(display, nativeKey, nativeMods | Mod2Mask, window, owner, pointer,
|
XGrabKey(display, nativeKey, nativeMods | Mod2Mask,
|
||||||
keyboard);
|
DefaultRootWindow(display), owner, pointer, keyboard);
|
||||||
XSync(display, False);
|
XSync(display, False);
|
||||||
XSetErrorHandler(handler);
|
XSetErrorHandler(handler);
|
||||||
return !error;
|
return !error;
|
||||||
@ -120,21 +124,25 @@ bool GlobalAction::registerHotKey(quint32 nativeKey, quint32 nativeMods)
|
|||||||
|
|
||||||
bool GlobalAction::unregisterHotKey(quint32 nativeKey, quint32 nativeMods)
|
bool GlobalAction::unregisterHotKey(quint32 nativeKey, quint32 nativeMods)
|
||||||
{
|
{
|
||||||
Display *display = QX11Info::display();
|
auto nativeInterface =
|
||||||
Window window = QX11Info::appRootWindow();
|
qApp->nativeInterface<QNativeInterface::QX11Application>();
|
||||||
|
SOFT_ASSERT(nativeInterface, return false);
|
||||||
|
Display *display = nativeInterface->display();
|
||||||
|
SOFT_ASSERT(display, return false);
|
||||||
error = false;
|
error = false;
|
||||||
int (*handler)(Display * display, XErrorEvent * event) =
|
int (*handler)(Display * display, XErrorEvent * event) =
|
||||||
XSetErrorHandler(customHandler);
|
XSetErrorHandler(customHandler);
|
||||||
XUngrabKey(display, nativeKey, nativeMods, window);
|
XUngrabKey(display, nativeKey, nativeMods, DefaultRootWindow(display));
|
||||||
// allow numlock
|
// allow numlock
|
||||||
XUngrabKey(display, nativeKey, nativeMods | Mod2Mask, window);
|
XUngrabKey(display, nativeKey, nativeMods | Mod2Mask,
|
||||||
|
DefaultRootWindow(display));
|
||||||
XSync(display, False);
|
XSync(display, False);
|
||||||
XSetErrorHandler(handler);
|
XSetErrorHandler(handler);
|
||||||
return !error;
|
return !error;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GlobalAction::nativeEventFilter(const QByteArray &eventType, void *message,
|
bool GlobalAction::nativeEventFilter(const QByteArray &eventType, void *message,
|
||||||
long *result)
|
qintptr *result)
|
||||||
{
|
{
|
||||||
Q_UNUSED(eventType);
|
Q_UNUSED(eventType);
|
||||||
Q_UNUSED(result);
|
Q_UNUSED(result);
|
||||||
@ -151,7 +159,9 @@ bool GlobalAction::nativeEventFilter(const QByteArray &eventType, void *message,
|
|||||||
|
|
||||||
quint32 GlobalAction::nativeKeycode(Qt::Key key)
|
quint32 GlobalAction::nativeKeycode(Qt::Key key)
|
||||||
{
|
{
|
||||||
Display *display = QX11Info::display();
|
auto nativeInterface =
|
||||||
|
qApp->nativeInterface<QNativeInterface::QX11Application>();
|
||||||
|
Display *display = nativeInterface->display();
|
||||||
KeySym keySym = XStringToKeysym(qPrintable(QKeySequence(key).toString()));
|
KeySym keySym = XStringToKeysym(qPrintable(QKeySequence(key).toString()));
|
||||||
if (XKeysymToString(keySym) == nullptr) {
|
if (XKeysymToString(keySym) == nullptr) {
|
||||||
keySym = QChar(key).unicode();
|
keySym = QChar(key).unicode();
|
||||||
@ -191,7 +201,7 @@ bool GlobalAction::unregisterHotKey(quint32 nativeKey, quint32 nativeMods)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool GlobalAction::nativeEventFilter(const QByteArray &eventType, void *message,
|
bool GlobalAction::nativeEventFilter(const QByteArray &eventType, void *message,
|
||||||
long *result)
|
qintptr *result)
|
||||||
{
|
{
|
||||||
Q_UNUSED(eventType);
|
Q_UNUSED(eventType);
|
||||||
Q_UNUSED(result);
|
Q_UNUSED(result);
|
||||||
@ -407,8 +417,8 @@ bool GlobalAction::unregisterHotKey(quint32 nativeKey, quint32 nativeMods)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GlobalAction::nativeEventFilter(const QByteArray & /*eventType*/,
|
bool GlobalAction::nativeEventFilter(const QByteArray &eventType, void *message,
|
||||||
void * /*message*/, long * /*result*/)
|
qintptr *result)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ class GlobalAction : public QAbstractNativeEventFilter
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
bool nativeEventFilter(const QByteArray &eventType, void *message,
|
bool nativeEventFilter(const QByteArray &eventType, void *message,
|
||||||
long *result);
|
qintptr *result) override;
|
||||||
|
|
||||||
static void init();
|
static void init();
|
||||||
static bool makeGlobal(QAction *action);
|
static bool makeGlobal(QAction *action);
|
||||||
|
@ -63,7 +63,7 @@ void KeySequenceEdit::keyPressEvent(QKeyEvent *event)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QKeySequence seq = event->modifiers() + event->key();
|
QKeySequence seq(QKeyCombination(event->modifiers(), Qt::Key(event->key())));
|
||||||
setKeySequence(seq, false);
|
setKeySequence(seq, false);
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ Substitutions unpackSubstitutions(const QStringList& raw)
|
|||||||
return {};
|
return {};
|
||||||
|
|
||||||
Substitutions result;
|
Substitutions result;
|
||||||
for (auto i = 0, end = raw.size(); i < end; i += 3) {
|
for (auto i = 0ll, end = raw.size(); i < end; i += 3) {
|
||||||
result.emplace(raw[i], Substitution{raw[i + 1], raw[i + 2]});
|
result.emplace(raw[i], Substitution{raw[i + 1], raw[i + 2]});
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include "widgetstate.h"
|
#include "widgetstate.h"
|
||||||
|
|
||||||
#include <QColorDialog>
|
#include <QColorDialog>
|
||||||
|
#include <QRegularExpression>
|
||||||
#include <QStandardItemModel>
|
#include <QStandardItemModel>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
@ -112,10 +113,10 @@ SettingsEditor::SettingsEditor(Manager &manager, update::Updater &updater)
|
|||||||
proxyTypes.insert(ProxyType::Http, tr("HTTP"));
|
proxyTypes.insert(ProxyType::Http, tr("HTTP"));
|
||||||
ui->proxyTypeCombo->addItems(proxyTypes.values());
|
ui->proxyTypeCombo->addItems(proxyTypes.values());
|
||||||
|
|
||||||
QRegExp urlRegexp(
|
QRegularExpression urlRegexp(
|
||||||
R"(^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$)");
|
R"(^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$)");
|
||||||
ui->proxyHostEdit->setValidator(
|
ui->proxyHostEdit->setValidator(
|
||||||
new QRegExpValidator(urlRegexp, ui->proxyHostEdit));
|
new QRegularExpressionValidator(urlRegexp, ui->proxyHostEdit));
|
||||||
|
|
||||||
ui->proxyPassEdit->setEchoMode(QLineEdit::PasswordEchoOnEdit);
|
ui->proxyPassEdit->setEchoMode(QLineEdit::PasswordEchoOnEdit);
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,9 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
class QString;
|
class QString;
|
||||||
class QStringList;
|
template <class T>
|
||||||
|
class QList;
|
||||||
|
using QStringList = QList<QString>;
|
||||||
|
|
||||||
class Manager;
|
class Manager;
|
||||||
class Settings;
|
class Settings;
|
||||||
|
@ -55,7 +55,7 @@ public:
|
|||||||
{"\\\\", "\\"},
|
{"\\\\", "\\"},
|
||||||
{"\\n", "\n"},
|
{"\\n", "\n"},
|
||||||
};
|
};
|
||||||
for (auto i = 0, end = text.size() - 1; i < end; ++i) {
|
for (auto i = 0ll, end = text.size() - 1; i < end; ++i) {
|
||||||
const auto pair = text.mid(i, 2);
|
const auto pair = text.mid(i, 2);
|
||||||
const auto replaced = replacements.value(pair);
|
const auto replaced = replacements.value(pair);
|
||||||
if (replaced.isEmpty())
|
if (replaced.isEmpty())
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QSplitter>
|
#include <QSplitter>
|
||||||
#include <QTabWidget>
|
#include <QTabWidget>
|
||||||
|
#include <QTcpSocket>
|
||||||
#include <QTextEdit>
|
#include <QTextEdit>
|
||||||
#include <QToolBar>
|
#include <QToolBar>
|
||||||
|
|
||||||
|
@ -33,6 +33,9 @@ WebPage::WebPage(Translator &translator, const QString &script,
|
|||||||
channel->registerObject("proxy", proxy_.get());
|
channel->registerObject("proxy", proxy_.get());
|
||||||
setWebChannel(channel, QWebEngineScript::ScriptWorldId::UserWorld);
|
setWebChannel(channel, QWebEngineScript::ScriptWorldId::UserWorld);
|
||||||
|
|
||||||
|
connect(this, &QWebEnginePage::certificateError, //
|
||||||
|
this, &WebPage::handleCertificateError);
|
||||||
|
|
||||||
// to load scripts
|
// to load scripts
|
||||||
setUrl(QUrl::fromUserInput("about:blank"));
|
setUrl(QUrl::fromUserInput("about:blank"));
|
||||||
}
|
}
|
||||||
@ -186,11 +189,15 @@ void WebPage::javaScriptConsoleMessage(
|
|||||||
emit log(QString("%1: %2 %3").arg(sourceID).arg(lineNumber).arg(message));
|
emit log(QString("%1: %2 %3").arg(sourceID).arg(lineNumber).arg(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WebPage::certificateError(const QWebEngineCertificateError &error)
|
void WebPage::handleCertificateError(const QWebEngineCertificateError &error)
|
||||||
{
|
{
|
||||||
qDebug() << "certificateError" << error.url() << error.error()
|
qDebug() << "certificateError" << error.url() << error.type()
|
||||||
<< error.errorDescription();
|
<< error.description();
|
||||||
return ignoreSslErrors_;
|
if (ignoreSslErrors_) {
|
||||||
|
const_cast<QWebEngineCertificateError &>(error).acceptCertificate();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const_cast<QWebEngineCertificateError &>(error).rejectCertificate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebPage::authenticateProxy(const QUrl & /*requestUrl*/,
|
void WebPage::authenticateProxy(const QUrl & /*requestUrl*/,
|
||||||
|
@ -34,7 +34,7 @@ protected:
|
|||||||
void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level,
|
void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level,
|
||||||
const QString &message, int lineNumber,
|
const QString &message, int lineNumber,
|
||||||
const QString &sourceID) override;
|
const QString &sourceID) override;
|
||||||
bool certificateError(const QWebEngineCertificateError &error) override;
|
void handleCertificateError(const QWebEngineCertificateError &error);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void authenticateProxy(const QUrl &requestUrl, QAuthenticator *authenticator,
|
void authenticateProxy(const QUrl &requestUrl, QAuthenticator *authenticator,
|
||||||
|
Loading…
Reference in New Issue
Block a user