added Auto Resize and Click Through features
This commit is contained in:
parent
ad3f09d8ef
commit
2f08ab1e9b
@ -22,6 +22,8 @@ extern const char* OPACITY;
|
||||
extern const char* SHOW_ORIGINAL;
|
||||
extern const char* SHOW_ORIGINAL_INFO;
|
||||
extern const char* SIZE_LOCK;
|
||||
extern const char* AUTO_RESIZE_WINDOW_HEIGHT;
|
||||
extern const char* CLICK_THROUGH;
|
||||
extern const char* DICTIONARY;
|
||||
extern const char* DICTIONARY_INSTRUCTIONS;
|
||||
extern const char* BG_COLOR;
|
||||
@ -163,8 +165,10 @@ public:
|
||||
for (auto [name, default, slot] : Array<const char*, bool, void(ExtraWindow::*)(bool)>{
|
||||
{ TOPMOST, false, &ExtraWindow::SetTopmost },
|
||||
{ SIZE_LOCK, false, &ExtraWindow::SetLock },
|
||||
{ AUTO_RESIZE_WINDOW_HEIGHT, false, &ExtraWindow::SetAutoResizeHeight },
|
||||
{ SHOW_ORIGINAL, true, &ExtraWindow::SetShowOriginal },
|
||||
{ DICTIONARY, false, &ExtraWindow::SetUseDictionary },
|
||||
{ CLICK_THROUGH, false, &ExtraWindow::SetClickThrough },
|
||||
})
|
||||
{
|
||||
// delay processing anything until Textractor has finished initializing
|
||||
@ -172,6 +176,12 @@ public:
|
||||
auto action = menu.addAction(name, this, slot);
|
||||
action->setCheckable(true);
|
||||
action->setChecked(default);
|
||||
if (slot == &ExtraWindow::SetClickThrough)
|
||||
{
|
||||
action->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_T));
|
||||
action->setShortcutContext(Qt::ApplicationShortcut);
|
||||
addAction(action);
|
||||
}
|
||||
}
|
||||
menu.addAction(MAX_SENTENCE_SIZE, this, [this]
|
||||
{
|
||||
@ -201,6 +211,8 @@ public:
|
||||
sentenceHistory.push_back(sentence);
|
||||
historyIndex = sentenceHistory.size() - 1;
|
||||
ui.display->setText(sentence);
|
||||
|
||||
AutoResize(sentence);
|
||||
}
|
||||
|
||||
private:
|
||||
@ -217,6 +229,49 @@ private:
|
||||
settings.setValue(SIZE_LOCK, this->locked = locked);
|
||||
};
|
||||
|
||||
void SetAutoResizeHeight(bool autoResizeHeight)
|
||||
{
|
||||
settings.setValue(AUTO_RESIZE_WINDOW_HEIGHT, this->autoResizeHeight = autoResizeHeight);
|
||||
|
||||
// If we disable this then we need to reset window to a default height. For now we will just use value from settings
|
||||
if (!autoResizeHeight && settings.contains(WINDOW) && QApplication::screenAt(settings.value(WINDOW).toRect().bottomRight()))
|
||||
{
|
||||
setGeometry(settings.value(WINDOW).toRect());
|
||||
}
|
||||
};
|
||||
|
||||
void AutoResize(QString sentence)
|
||||
{
|
||||
if (!autoResizeHeight) return;
|
||||
|
||||
QFontMetrics fontMetrics(ui.display->font(), ui.display);
|
||||
auto boundingRect = fontMetrics.boundingRect(0, 0, width(), INT_MAX, Qt::TextWordWrap, sentence);
|
||||
int newHeight = boundingRect.height() + 30;
|
||||
int currHeight = height();
|
||||
|
||||
if (newHeight != currHeight) {
|
||||
QSize s = size();
|
||||
s.setWidth(width());
|
||||
s.setHeight(newHeight);
|
||||
resize(s);
|
||||
}
|
||||
}
|
||||
|
||||
void SetClickThrough(bool clickThrough)
|
||||
{
|
||||
if (clickThrough)
|
||||
{
|
||||
setAttribute(Qt::WA_TransparentForMouseEvents, true);
|
||||
setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
|
||||
} else {
|
||||
setAttribute(Qt::WA_TransparentForMouseEvents , false);
|
||||
//setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint); // doesn't work
|
||||
setWindowFlags(Qt::FramelessWindowHint);
|
||||
SetTopmost(settings.value(TOPMOST, false).toBool());
|
||||
}
|
||||
show();
|
||||
};
|
||||
|
||||
void SetShowOriginal(bool showOriginal)
|
||||
{
|
||||
if (!showOriginal && settings.value(SHOW_ORIGINAL, false).toBool()) QMessageBox::information(this, SHOW_ORIGINAL, SHOW_ORIGINAL_INFO);
|
||||
@ -298,9 +353,10 @@ private:
|
||||
int scroll = event->angleDelta().y();
|
||||
if (scroll > 0 && historyIndex > 0) ui.display->setText(sentenceHistory[--historyIndex]);
|
||||
if (scroll < 0 && historyIndex + 1 < sentenceHistory.size()) ui.display->setText(sentenceHistory[++historyIndex]);
|
||||
AutoResize(sentenceHistory[historyIndex]);
|
||||
}
|
||||
|
||||
bool locked, showOriginal, useDictionary;
|
||||
bool locked, autoResizeHeight, showOriginal, useDictionary, clickThrough;
|
||||
int maxSentenceSize = 1000;
|
||||
QPoint oldPos;
|
||||
|
||||
|
16
text.cpp
16
text.cpp
@ -179,6 +179,8 @@ const char* SHOW_ORIGINAL = u8"Original text";
|
||||
const char* SHOW_ORIGINAL_INFO = u8R"(Original text will not be shown
|
||||
Only works if this extension is used directly after a translation extension)";
|
||||
const char* SIZE_LOCK = u8"Size lock";
|
||||
const char* AUTO_RESIZE_WINDOW_HEIGHT = u8"Auto resize window height";
|
||||
const char* CLICK_THROUGH = u8"Click Through";
|
||||
const char* OPACITY = u8"Opacity";
|
||||
const char* BG_COLOR = u8"Background color";
|
||||
const char* TEXT_COLOR = u8"Text color";
|
||||
@ -435,6 +437,8 @@ Clic y arrastra los bordes de la ventana para moverla, o en la esquina inferior
|
||||
仅当此扩展置于翻译扩展之后使用时才有效)";
|
||||
OPACITY = u8"透明度";
|
||||
SIZE_LOCK = u8"锁定窗口大小";
|
||||
AUTO_RESIZE_WINDOW_HEIGHT = u8"Auto resize window height";
|
||||
CLICK_THROUGH = u8"Click Through";
|
||||
BG_COLOR = u8"背景颜色";
|
||||
TEXT_COLOR = u8"文本颜色";
|
||||
TEXT_OUTLINE = u8"文字边框";
|
||||
@ -624,6 +628,8 @@ Textractor отобразит конечный корневой термин, а
|
||||
SHOW_ORIGINAL_INFO = u8R"(Исходный текст будет скрыт
|
||||
Работает только если это расширение используется после расширения перевода)";
|
||||
SIZE_LOCK = u8"Фиксированный размер";
|
||||
AUTO_RESIZE_WINDOW_HEIGHT = u8"Auto resize window height";
|
||||
CLICK_THROUGH = u8"Click Through";
|
||||
OPACITY = u8"Прозрачность";
|
||||
BG_COLOR = u8"Цвет заднего фона";
|
||||
TEXT_COLOR = u8"Цвет текста";
|
||||
@ -884,6 +890,8 @@ Questo file deve essere codificato in UTF-8.)";
|
||||
SHOW_ORIGINAL_INFO = u8R"(Testo originale non sarà mostrato
|
||||
Funziona solo se questa estenzione è usata direttamente dopo un'estensione di traduzione)";
|
||||
SIZE_LOCK = u8"Lock delle dimensione";
|
||||
AUTO_RESIZE_WINDOW_HEIGHT = u8"Auto resize altezza finestra";
|
||||
CLICK_THROUGH = u8"Clicca attraverso";
|
||||
OPACITY = u8"Opacità";
|
||||
BG_COLOR = u8"Colore dello sfondo";
|
||||
TEXT_COLOR = u8"Colore del testo";
|
||||
@ -998,6 +1006,8 @@ Clique e arraste nas beiradas da janela para mover, ou no canto inferior direito
|
||||
SHOW_ORIGINAL_INFO = u8R"(Texto original não será mostrado
|
||||
Apenas funciona se essa extensão for usada diretamente após uma extensão de tradução)";
|
||||
SIZE_LOCK = u8"Travar o Tamanho";
|
||||
AUTO_RESIZE_WINDOW_HEIGHT = u8"Auto resize window height";
|
||||
CLICK_THROUGH = u8"Click Through";
|
||||
BG_COLOR = u8"Cor de fundo";
|
||||
TEXT_COLOR = u8"Cor do Texto";
|
||||
FONT = u8"Fonte";
|
||||
@ -1073,6 +1083,8 @@ Source code สามารถหาได้จากส่วนของ GPLv
|
||||
TOPMOST = u8"หน้าต่างอยู่บนโปรแกรมอื่น";
|
||||
SHOW_ORIGINAL = u8"ข้อความดังเดิมก่อนแปลภาษา";
|
||||
SIZE_LOCK = u8"ปรับให้ไม่สามารถเปลี่ยนขนาดได้";
|
||||
AUTO_RESIZE_WINDOW_HEIGHT = u8"Auto resize window height";
|
||||
CLICK_THROUGH = u8"Click Through";
|
||||
FONT = u8"ฟ้อนต์";
|
||||
#endif // THAI
|
||||
|
||||
@ -1138,6 +1150,8 @@ Source code สามารถหาได้จากส่วนของ GPLv
|
||||
SHOW_ORIGINAL_INFO = u8R"(원문이 출력되지 않음
|
||||
이 확장기능이 번역확장기능 이후에 사용될때만 동작함)";
|
||||
SIZE_LOCK = u8"사이즈 고정";
|
||||
AUTO_RESIZE_WINDOW_HEIGHT = u8"Auto resize window height";
|
||||
CLICK_THROUGH = u8"Click Through";
|
||||
BG_COLOR = u8"배경색";
|
||||
TEXT_COLOR = u8"글씨색";
|
||||
FONT = u8"폰트";
|
||||
@ -1303,6 +1317,8 @@ Ce fichier doit être encodé en UTF-8.)";
|
||||
SHOW_ORIGINAL_INFO = u8R"(Le texte d'origine ne sera pas affiché
|
||||
Fonctionne uniquement si cette extension est utilisée directement après une extension de traduction)";
|
||||
SIZE_LOCK = u8"Verouiller la taille";
|
||||
AUTO_RESIZE_WINDOW_HEIGHT = u8"Auto resize window height";
|
||||
CLICK_THROUGH = u8"Click Through";
|
||||
OPACITY = u8"Opacité";
|
||||
BG_COLOR = u8"Couleur d'arrière-plan";
|
||||
TEXT_COLOR = u8"Couleur du texte";
|
||||
|
Loading…
Reference in New Issue
Block a user