| 189 | }; |
| 190 | |
| 191 | class ExtraWindow : public PrettyWindow, QAbstractNativeEventFilter |
| 192 | { |
| 193 | public: |
| 194 | ExtraWindow() : PrettyWindow("Extra Window") |
| 195 | { |
| 196 | ui.display->setTextFormat(Qt::PlainText); |
| 197 | if (settings.contains(WINDOW) && QApplication::screenAt(settings.value(WINDOW).toRect().bottomRight())) setGeometry(settings.value(WINDOW).toRect()); |
| 198 | |
| 199 | for (auto [name, default, slot] : Array<const char*, bool, void(ExtraWindow::*)(bool)>{ |
| 200 | { TOPMOST, false, &ExtraWindow::SetTopmost }, |
| 201 | { SIZE_LOCK, false, &ExtraWindow::SetSizeLock }, |
| 202 | { POSITION_LOCK, false, &ExtraWindow::SetPositionLock }, |
| 203 | { CENTERED_TEXT, false, &ExtraWindow::SetCenteredText }, |
| 204 | { AUTO_RESIZE_WINDOW_HEIGHT, false, &ExtraWindow::SetAutoResize }, |
| 205 | { SHOW_ORIGINAL, true, &ExtraWindow::SetShowOriginal }, |
| 206 | { ORIGINAL_AFTER_TRANSLATION, true, &ExtraWindow::SetShowOriginalAfterTranslation }, |
| 207 | { DICTIONARY, false, &ExtraWindow::SetUseDictionary }, |
| 208 | }) |
| 209 | { |
| 210 | // delay processing anything until Textractor has finished initializing |
| 211 | QMetaObject::invokeMethod(this, std::bind(slot, this, default = settings.value(name, default).toBool()), Qt::QueuedConnection); |
| 212 | auto action = menu.addAction(name, this, slot); |
| 213 | action->setCheckable(true); |
| 214 | action->setChecked(default); |
| 215 | } |
| 216 | |
| 217 | menu.addAction(CLICK_THROUGH, this, &ExtraWindow::ToggleClickThrough); |
| 218 | |
| 219 | ui.display->installEventFilter(this); |
| 220 | qApp->installNativeEventFilter(this); |
| 221 | |
| 222 | QMetaObject::invokeMethod(this, [this] |
| 223 | { |
| 224 | RegisterHotKey((HWND)winId(), CLICK_THROUGH_HOTKEY, MOD_ALT | MOD_NOREPEAT, 0x58); |
| 225 | show(); |
| 226 | AddSentence(EXTRA_WINDOW_INFO); |
| 227 | }, Qt::QueuedConnection); |
| 228 | } |
| 229 | |
| 230 | ~ExtraWindow() |
| 231 | { |
| 232 | settings.setValue(WINDOW, geometry()); |
| 233 | } |
| 234 | |
| 235 | void AddSentence(QString sentence) |
| 236 | { |
| 237 | sanitize(sentence); |
| 238 | sentence.chop(std::distance(std::remove(sentence.begin(), sentence.end(), QChar::Tabulation), sentence.end())); |
| 239 | sentenceHistory.push_back(sentence); |
| 240 | if (sentenceHistory.size() > 1000) sentenceHistory.erase(sentenceHistory.begin()); |
| 241 | historyIndex = sentenceHistory.size() - 1; |
| 242 | DisplaySentence(); |
| 243 | } |
| 244 | |
| 245 | private: |
| 246 | void DisplaySentence() |
| 247 | { |
| 248 | if (sentenceHistory.empty()) return; |
nothing calls this directly
no outgoing calls
no test coverage detected