add size locking option
This commit is contained in:
parent
08cd3959fa
commit
7b82aa62aa
@ -25,11 +25,11 @@ public:
|
|||||||
display->setTextInteractionFlags(Qt::TextSelectableByMouse);
|
display->setTextInteractionFlags(Qt::TextSelectableByMouse);
|
||||||
display->setAlignment(Qt::AlignTop);
|
display->setAlignment(Qt::AlignTop);
|
||||||
display->setWordWrap(true);
|
display->setWordWrap(true);
|
||||||
display->setMaximumHeight(600);
|
display->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
|
||||||
setWindowFlags(Qt::FramelessWindowHint);
|
setWindowFlags(Qt::FramelessWindowHint);
|
||||||
setAttribute(Qt::WA_TranslucentBackground);
|
setAttribute(Qt::WA_TranslucentBackground);
|
||||||
setSizeGripEnabled(true);
|
setSizeGripEnabled(true);
|
||||||
resize(400, 1);
|
resize(400, 300);
|
||||||
show();
|
show();
|
||||||
|
|
||||||
auto setBackgroundColor = [=](QColor color)
|
auto setBackgroundColor = [=](QColor color)
|
||||||
@ -60,7 +60,14 @@ public:
|
|||||||
SetWindowPos((HWND)winId(), topmost ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
|
SetWindowPos((HWND)winId(), topmost ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
|
||||||
settings->setValue(TOPMOST, topmost);
|
settings->setValue(TOPMOST, topmost);
|
||||||
};
|
};
|
||||||
|
auto setLock = [=](bool lock)
|
||||||
|
{
|
||||||
|
locked = lock;
|
||||||
|
setSizeGripEnabled(!lock);
|
||||||
|
settings->setValue(SIZE_LOCK, lock);
|
||||||
|
};
|
||||||
setGeometry(settings->value(WINDOW, geometry()).toRect());
|
setGeometry(settings->value(WINDOW, geometry()).toRect());
|
||||||
|
setLock(settings->value(SIZE_LOCK, false).toBool());
|
||||||
setTopmost(settings->value(TOPMOST, false).toBool());
|
setTopmost(settings->value(TOPMOST, false).toBool());
|
||||||
setFontSize(settings->value(FONT_SIZE, 16).toInt());
|
setFontSize(settings->value(FONT_SIZE, 16).toInt());
|
||||||
setBackgroundColor(settings->value(BG_COLOR, palette().window().color()).value<QColor>());
|
setBackgroundColor(settings->value(BG_COLOR, palette().window().color()).value<QColor>());
|
||||||
@ -70,6 +77,9 @@ public:
|
|||||||
auto topmost = menu->addAction(TOPMOST, setTopmost);
|
auto topmost = menu->addAction(TOPMOST, setTopmost);
|
||||||
topmost->setCheckable(true);
|
topmost->setCheckable(true);
|
||||||
topmost->setChecked(settings->value(TOPMOST, false).toBool());
|
topmost->setChecked(settings->value(TOPMOST, false).toBool());
|
||||||
|
auto lock = menu->addAction(SIZE_LOCK, setLock);
|
||||||
|
lock->setCheckable(true);
|
||||||
|
lock->setChecked(settings->value(SIZE_LOCK, false).toBool());
|
||||||
menu->addAction(BG_COLOR, [=] { setBackgroundColor(QColorDialog::getColor(bgColor, this, BG_COLOR, QColorDialog::ShowAlphaChannel)); });
|
menu->addAction(BG_COLOR, [=] { setBackgroundColor(QColorDialog::getColor(bgColor, this, BG_COLOR, QColorDialog::ShowAlphaChannel)); });
|
||||||
menu->addAction(TEXT_COLOR, [=] { setTextColor(QColorDialog::getColor(display->palette().windowText().color(), this, TEXT_COLOR, QColorDialog::ShowAlphaChannel)); });
|
menu->addAction(TEXT_COLOR, [=] { setTextColor(QColorDialog::getColor(display->palette().windowText().color(), this, TEXT_COLOR, QColorDialog::ShowAlphaChannel)); });
|
||||||
menu->addAction(FONT_SIZE, [=] { setFontSize(QInputDialog::getInt(this, FONT_SIZE, "", display->font().pointSize(), 0, INT_MAX, 1, nullptr, Qt::WindowCloseButtonHint)); });
|
menu->addAction(FONT_SIZE, [=] { setFontSize(QInputDialog::getInt(this, FONT_SIZE, "", display->font().pointSize(), 0, INT_MAX, 1, nullptr, Qt::WindowCloseButtonHint)); });
|
||||||
@ -87,24 +97,19 @@ private:
|
|||||||
QPainter(this).fillRect(rect(), bgColor);
|
QPainter(this).fillRect(rect(), bgColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void resizeEvent(QResizeEvent* event) override
|
void mousePressEvent(QMouseEvent* event) override
|
||||||
{
|
|
||||||
display->setMaximumWidth(event->size().width());
|
|
||||||
QDialog::resizeEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
void mousePressEvent(QMouseEvent* event)
|
|
||||||
{
|
{
|
||||||
oldPos = event->globalPos();
|
oldPos = event->globalPos();
|
||||||
}
|
}
|
||||||
|
|
||||||
void mouseMoveEvent(QMouseEvent* event)
|
void mouseMoveEvent(QMouseEvent* event) override
|
||||||
{
|
{
|
||||||
const QPoint delta = event->globalPos() - oldPos;
|
const QPoint delta = event->globalPos() - oldPos;
|
||||||
move(x() + delta.x(), y() + delta.y());
|
if (!locked) move(x() + delta.x(), y() + delta.y());
|
||||||
oldPos = event->globalPos();
|
oldPos = event->globalPos();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool locked;
|
||||||
QColor bgColor;
|
QColor bgColor;
|
||||||
QPoint oldPos;
|
QPoint oldPos;
|
||||||
}*window = nullptr;
|
}*window = nullptr;
|
||||||
|
@ -52,10 +52,11 @@ extern const char* GOOGLE_PROMPT;
|
|||||||
extern const wchar_t* TOO_MANY_TRANS_REQUESTS;
|
extern const wchar_t* TOO_MANY_TRANS_REQUESTS;
|
||||||
extern const wchar_t* TRANSLATION_ERROR;
|
extern const wchar_t* TRANSLATION_ERROR;
|
||||||
extern const char* EXTRA_WINDOW_INFO;
|
extern const char* EXTRA_WINDOW_INFO;
|
||||||
|
extern const char* TOPMOST;
|
||||||
|
extern const char* SIZE_LOCK;
|
||||||
extern const char* BG_COLOR;
|
extern const char* BG_COLOR;
|
||||||
extern const char* TEXT_COLOR;
|
extern const char* TEXT_COLOR;
|
||||||
extern const char* FONT_SIZE;
|
extern const char* FONT_SIZE;
|
||||||
extern const char* TOPMOST;
|
|
||||||
extern const char* LUA_INTRO;
|
extern const char* LUA_INTRO;
|
||||||
extern const char* LOAD_LUA_SCRIPT;
|
extern const char* LOAD_LUA_SCRIPT;
|
||||||
extern const wchar_t* LUA_ERROR;
|
extern const wchar_t* LUA_ERROR;
|
||||||
|
3
text.cpp
3
text.cpp
@ -81,10 +81,11 @@ const wchar_t* TOO_MANY_TRANS_REQUESTS = L"Too many translation requests: refuse
|
|||||||
const wchar_t* TRANSLATION_ERROR = L"Error while translating";
|
const wchar_t* TRANSLATION_ERROR = L"Error while translating";
|
||||||
const char* EXTRA_WINDOW_INFO = u8R"(Right click to change settings
|
const char* EXTRA_WINDOW_INFO = u8R"(Right click to change settings
|
||||||
Click and drag on window edges to move, or the bottom right corner to resize)";
|
Click and drag on window edges to move, or the bottom right corner to resize)";
|
||||||
|
const char* TOPMOST = u8"Always on Top";
|
||||||
|
const char* SIZE_LOCK = u8"Size Locked";
|
||||||
const char* BG_COLOR = u8"Background Color";
|
const char* BG_COLOR = u8"Background Color";
|
||||||
const char* TEXT_COLOR = u8"Text Color";
|
const char* TEXT_COLOR = u8"Text Color";
|
||||||
const char* FONT_SIZE = u8"Font Size";
|
const char* FONT_SIZE = u8"Font Size";
|
||||||
const char* TOPMOST = u8"Always on Top";
|
|
||||||
const char* LUA_INTRO = u8R"(--[[
|
const char* LUA_INTRO = u8R"(--[[
|
||||||
ProcessSentence is called each time Textractor receives a sentence of text.
|
ProcessSentence is called each time Textractor receives a sentence of text.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user