forked from Public-Mirror/Textractor
add extra window to view text
This commit is contained in:
parent
7015ef0c53
commit
507e0bc1e6
@ -7,10 +7,12 @@ cmake_policy(SET CMP0037 OLD)
|
||||
add_library(Bing\ Translate SHARED bingtranslate.cpp extensionimpl.cpp)
|
||||
add_library(Copy\ to\ Clipboard SHARED copyclipboard.cpp extensionimpl.cpp)
|
||||
add_library(Extra\ Newlines SHARED extranewlines.cpp extensionimpl.cpp)
|
||||
add_library(Extra\ Window SHARED extrawindow.cpp extensionimpl.cpp)
|
||||
add_library(Google\ Translate SHARED googletranslate.cpp extensionimpl.cpp)
|
||||
add_library(Regex\ Filter SHARED regexfilter.cpp extensionimpl.cpp)
|
||||
add_library(Remove\ Repetition SHARED removerepeat.cpp extensionimpl.cpp)
|
||||
|
||||
target_link_libraries(Bing\ Translate winhttp Qt5::Widgets)
|
||||
target_link_libraries(Extra\ Window Qt5::Widgets)
|
||||
target_link_libraries(Google\ Translate winhttp Qt5::Widgets)
|
||||
target_link_libraries(Regex\ Filter Qt5::Widgets)
|
||||
|
66
extensions/extrawindow.cpp
Normal file
66
extensions/extrawindow.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
#include "extension.h"
|
||||
#include "text.h"
|
||||
#include <QMainWindow>
|
||||
#include <QLayout>
|
||||
#include <QLabel>
|
||||
#include <QCheckBox>
|
||||
#include <QTimer>
|
||||
|
||||
std::mutex m;
|
||||
|
||||
struct : QMainWindow
|
||||
{
|
||||
QLabel* display;
|
||||
void launch()
|
||||
{
|
||||
auto centralWidget = new QWidget(this);
|
||||
auto layout = new QVBoxLayout(centralWidget);
|
||||
auto options = new QHBoxLayout(centralWidget);
|
||||
layout->addItem(options);
|
||||
layout->addWidget(display = new QLabel(centralWidget));
|
||||
auto onTop = new QCheckBox(ALWAYS_ON_TOP, this);
|
||||
options->addWidget(onTop);
|
||||
connect(onTop, &QCheckBox::stateChanged, [this](int state)
|
||||
{
|
||||
SetWindowPos((HWND)winId(), state == Qt::Checked ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
|
||||
});
|
||||
resize(800, 600);
|
||||
setCentralWidget(centralWidget);
|
||||
show();
|
||||
}
|
||||
}*window = nullptr;
|
||||
|
||||
BOOL WINAPI DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
|
||||
{
|
||||
switch (ul_reason_for_call)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
{
|
||||
QTimer::singleShot(0, []
|
||||
{
|
||||
std::lock_guard l(m);
|
||||
(window = new std::remove_pointer_t<decltype(window)>)->launch();
|
||||
});
|
||||
}
|
||||
break;
|
||||
case DLL_PROCESS_DETACH:
|
||||
{
|
||||
if (lpReserved == NULL) // https://blogs.msdn.microsoft.com/oldnewthing/20120105-00/?p=8683
|
||||
{
|
||||
std::lock_guard l(m);
|
||||
delete window;
|
||||
window = nullptr;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
|
||||
{
|
||||
std::lock_guard l(m);
|
||||
if (window == nullptr || !sentenceInfo["current select"]) return false;
|
||||
window->display->setText(QString::fromStdWString(sentence));
|
||||
return false;
|
||||
}
|
@ -11,7 +11,7 @@ std::mutex m;
|
||||
|
||||
struct : QMainWindow
|
||||
{
|
||||
void Initialize()
|
||||
void launch()
|
||||
{
|
||||
auto centralWidget = new QWidget(this);
|
||||
auto layout = new QVBoxLayout(centralWidget);
|
||||
@ -43,7 +43,7 @@ BOOL WINAPI DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved
|
||||
QTimer::singleShot(0, []
|
||||
{
|
||||
std::lock_guard l(m);
|
||||
(window = new std::remove_pointer_t<decltype(window)>)->Initialize();
|
||||
(window = new std::remove_pointer_t<decltype(window)>)->launch();
|
||||
});
|
||||
}
|
||||
break;
|
||||
|
@ -58,6 +58,7 @@ constexpr auto BING_PROMPT = u8"What language should Bing translate to?";
|
||||
constexpr auto GOOGLE_PROMPT = u8"What language should Google translate to?";
|
||||
constexpr auto TOO_MANY_TRANS_REQUESTS = L"\r\nToo many translation requests: refuse to make more";
|
||||
constexpr auto TRANSLATION_ERROR = L"Error while translating";
|
||||
constexpr auto ALWAYS_ON_TOP = u8"Keep this window on top";
|
||||
constexpr auto REGEX_FILTER = u8"Regex Filter";
|
||||
constexpr auto INVALID_REGEX = u8"Invalid regex";
|
||||
constexpr auto CURRENT_FILTER = u8"Currently filtering: ";
|
||||
|
Loading…
x
Reference in New Issue
Block a user