forked from GSam/Capture2Text
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Settings.cpp
180 lines (149 loc) · 6.75 KB
/
Settings.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
Copyright (C) 2010-2017 Christopher Brochtrup
This file is part of Capture2Text.
Capture2Text is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Capture2Text is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Capture2Text. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QTextToSpeech>
#include "Settings.h"
#include "PostProcess.h"
const QColor Settings::defaultCaptureBoxBackgroundColor(0, 128, 255, 60);
const QColor Settings::defaultCaptureBoxBorderColor(0, 128, 255, 255);
const QString Settings::defaultHotkeyCaptureBox("Win+Q");
const QString Settings::defaultHotkeyReCaptureLast("Win+R");
const QString Settings::defaultHotkeyTextLineCapture("Win+E");
const QString Settings::defaultHotkeyForwardTextLineCapture("Win+W");
const QString Settings::defaultHotkeyBubbleCapture("Win+S");
const QString Settings::defaultHotkeyLang1("Win+1");
const QString Settings::defaultHotkeyLang2("Win+2");
const QString Settings::defaultHotkeyLang3("Win+3");
const QString Settings::defaultHotkeyTextOrientation("Win+O");
const QString Settings::defaultHotkeyWhitelist("Win+<Unmapped>");
const QString Settings::defaultHotkeyBlacklist("Win+<Unmapped>");
const QString Settings::defaultOcrLang("English");
const QString Settings::defaultOcrQuickAccessLang1("English");
const QString Settings::defaultOcrQuickAccessLang2("Japanese");
const QString Settings::defaultOcrQuickAccessLang3("German");
const QString Settings::defaultOcrTextOrientation("Auto");
const QString Settings::defaultOcrTesseractConfigFile("");
const QString Settings::defaultOcrWhitelist("");
const QString Settings::defaultOcrBlacklist("");
const double Settings::defaultOcrScaleFactor(3.5);
const QString Settings::defaultOutputLogFile("");
const QString Settings::defaultOutputLogFormat("${capture}${linebreak}");
const QFont Settings::defaultOutputPopupFont("Arial", 12);
const QString Settings::defaultOutputCallExe("");
const QColor Settings::defaultPreviewBackgroundColor(10, 10, 10, 255);
const QColor Settings::defaultPreviewBorderColor(128, 128, 128, 255);
const QString Settings::defaultPreviewPosition("Fixed - Top Left");
const QColor Settings::defaultPreviewTextColor(200, 200, 200, 255);
const QFont Settings::defaultPreviewTextFont("Arial", 16);
QList<Replacement> Settings::getOcrReplacementList(QString lang)
{
static QList<Replacement> defaultJapaneseList = QList<Replacement>()
<< Replacement("カゝ", "か")
<< Replacement("ヵ", "カ")
<< Replacement("〈", "く")
<< Replacement("<", "く")
<< Replacement("<", "く")
<< Replacement("︿", "く")
<< Replacement("\\|二", "に")
<< Replacement("_", "一")
<< Replacement("I", "ー")
<< Replacement("1", "ー")
<< Replacement("ムロ", "合")
<< Replacement("ぁ", "あ")
<< Replacement("ぃ", "い")
<< Replacement("ぅ", "う")
<< Replacement("ぇ", "え")
<< Replacement("ぉ", "お")
<< Replacement("ゎ", "わ")
<< Replacement("ァ", "ア")
<< Replacement("ィ", "イ")
<< Replacement("ゥ", "ウ")
<< Replacement("ェ", "エ")
<< Replacement("ォ", "オ")
<< Replacement("ヶ", "ケ")
<< Replacement("ヮ", "ワ")
;
QString defaultValue = "";
if(lang == "Japanese")
{
defaultValue = PostProcess::replacementListToStr(defaultJapaneseList);
}
return PostProcess::strToReplacementList(QSettings().value("Replacement/" + lang, defaultValue).toString());
}
void Settings::setOcrReplacementList(QString lang, QList<Replacement> value)
{
QSettings().setValue("Replacement/" + lang, PostProcess::replacementListToStr(value));
}
QString Settings::getTranslateLang(QString ocrLang)
{
QString defaultValue = "English";
if(ocrLang == "English")
{
defaultValue = "German";
}
return QSettings().value("Translate/" + ocrLang, defaultValue).toString();
}
void Settings::setTranslateLang(QString ocrLang, QString translateLang)
{
QSettings().setValue("Translate/" + ocrLang, translateLang);
}
void Settings::getSpeechInfo(QString ocrLang, QString &locale, QString &voice, int &rate, int &pitch)
{
locale = QSettings().value("Speech/" + ocrLang + "/Locale", "<Init>").toString();
voice = QSettings().value("Speech/" + ocrLang + "/Voice", "<Init>").toString();
rate = QSettings().value("Speech/" + ocrLang + "/Rate", defaultSpeechRate).toInt();
pitch = QSettings().value("Speech/" + ocrLang + "/Pitch", defaultSpeechPitch).toInt();
if(voice == "<Init>")
{
// Default voice to disabled
locale = "<Disabled>";
voice = "<Disabled>";
QTextToSpeech speech;
QVector<QLocale> locales = speech.availableLocales();
// Try to match up voice based on OCR langauge
foreach (const QLocale &localeItem, locales)
{
speech.setLocale(localeItem);
QString localLangName = QLocale::languageToString(localeItem.language());
if(localLangName.startsWith(ocrLang))
{
auto voiceList = speech.availableVoices();
foreach (const QVoice &voiceItem, voiceList)
{
locale = localeItem.name();
voice = voiceItem.name();
break;
}
}
}
setSpeechInfo(ocrLang, locale, voice, rate, pitch);
}
}
void Settings::setSpeechInfo(QString ocrLang, QString locale, QString voice, int rate, int pitch)
{
QSettings().setValue("Speech/" + ocrLang + "/Locale", locale);
QSettings().setValue("Speech/" + ocrLang + "/Voice", voice);
QSettings().setValue("Speech/" + ocrLang + "/Rate", rate);
QSettings().setValue("Speech/" + ocrLang + "/Pitch", pitch);
}
QString Settings::separatorToStr(QString separator)
{
if(separator == "Space") return " ";
else if(separator == "Tab") return "\t";
else if(separator == "Line Break") return "\r\n";
else if(separator == "Comma") return ",";
else if(separator == "Semicolon") return ";";
else if(separator == "Pipe") return "|";
else return " ";
}