Add shadow margin to fcitx5-qt client side input panel
This commit is contained in:
parent
a53ab5b656
commit
c4b9f72e71
|
@ -358,8 +358,7 @@ void FcitxCandidateWindow::updateClientSideUI(
|
|||
bool visible =
|
||||
preeditVisble || auxUpVisbile || auxDownVisible || candidatesVisible;
|
||||
auto window = QGuiApplication::focusWindow();
|
||||
if (!theme_ || !visible || !QGuiApplication::focusWindow() ||
|
||||
window != parent_) {
|
||||
if (!theme_ || !visible || !window || window != parent_) {
|
||||
hide();
|
||||
hoverIndex_ = -1;
|
||||
return;
|
||||
|
@ -396,6 +395,13 @@ void FcitxCandidateWindow::updateClientSideUI(
|
|||
|
||||
actualSize_ = sizeHint();
|
||||
|
||||
QSize sizeWithoutShadow = actualSize_.shrunkBy(theme_->shadowMargin());
|
||||
if (sizeWithoutShadow.width() < 0) {
|
||||
sizeWithoutShadow.setWidth(0);
|
||||
}
|
||||
if (sizeWithoutShadow.height() < 0) {
|
||||
sizeWithoutShadow.setHeight(0);
|
||||
}
|
||||
QRect cursorRect =
|
||||
QGuiApplication::inputMethod()->cursorRectangle().toRect();
|
||||
QRect screenGeometry;
|
||||
|
@ -414,19 +420,20 @@ void FcitxCandidateWindow::updateClientSideUI(
|
|||
}
|
||||
|
||||
int x = cursorRect.left(), y = cursorRect.bottom();
|
||||
if (cursorRect.left() + actualSize_.width() > screenGeometry.right()) {
|
||||
x = screenGeometry.right() - actualSize_.width() + 1;
|
||||
if (cursorRect.left() + sizeWithoutShadow.width() >
|
||||
screenGeometry.right()) {
|
||||
x = screenGeometry.right() - sizeWithoutShadow.width() + 1;
|
||||
}
|
||||
|
||||
if (x < screenGeometry.left()) {
|
||||
x = screenGeometry.left();
|
||||
}
|
||||
|
||||
if (y + actualSize_.height() > screenGeometry.bottom()) {
|
||||
if (y + sizeWithoutShadow.height() > screenGeometry.bottom()) {
|
||||
if (y > screenGeometry.bottom()) {
|
||||
y = screenGeometry.bottom() - actualSize_.height() - 40;
|
||||
y = screenGeometry.bottom() - sizeWithoutShadow.height() - 40;
|
||||
} else { /* better position the window */
|
||||
y = y - actualSize_.height() -
|
||||
y = y - sizeWithoutShadow.height() -
|
||||
((cursorRect.height() == 0) ? 40 : cursorRect.height());
|
||||
}
|
||||
}
|
||||
|
@ -439,6 +446,8 @@ void FcitxCandidateWindow::updateClientSideUI(
|
|||
resize(actualSize_);
|
||||
// hide();
|
||||
QPoint newPosition(x, y);
|
||||
newPosition -=
|
||||
QPoint(theme_->shadowMargin().left(), theme_->shadowMargin().top());
|
||||
if (newPosition != position()) {
|
||||
if (isVisible()) {
|
||||
hide();
|
||||
|
|
|
@ -210,6 +210,7 @@ void FcitxTheme::themeChanged() {
|
|||
contentMargin_ = QMargins{2, 2, 2, 2};
|
||||
textMargin_ = QMargins{5, 5, 5, 5};
|
||||
highlightClickMargin_ = QMargins{0, 0, 0, 0};
|
||||
shadowMargin_ = QMargins{0, 0, 0, 0};
|
||||
background_.loadFromValue(highlightBackgroundColor_, highlightColor_,
|
||||
contentMargin_, 2);
|
||||
highlight_.loadFromValue(highlightBackgroundColor_,
|
||||
|
@ -236,6 +237,9 @@ void FcitxTheme::themeChanged() {
|
|||
settings.beginGroup("TextMargin");
|
||||
textMargin_ = readMargin(settings);
|
||||
settings.endGroup();
|
||||
settings.beginGroup("ShadowMargin");
|
||||
shadowMargin_ = readMargin(settings);
|
||||
settings.endGroup();
|
||||
|
||||
settings.beginGroup("Background");
|
||||
background_.load(theme_, settings);
|
||||
|
|
|
@ -81,6 +81,7 @@ public:
|
|||
auto textMargin() const { return textMargin_; }
|
||||
auto highlightClickMargin() const { return highlightClickMargin_; }
|
||||
QMargins highlightMargin() const;
|
||||
auto shadowMargin() const { return shadowMargin_; }
|
||||
auto normalColor() const { return normalColor_; }
|
||||
auto highlightCandidateColor() const { return highlightCandidateColor_; }
|
||||
auto vertical() const { return vertical_; }
|
||||
|
@ -113,6 +114,7 @@ private:
|
|||
QMargins highlightClickMargin_;
|
||||
QMargins contentMargin_;
|
||||
QMargins textMargin_;
|
||||
QMargins shadowMargin_;
|
||||
};
|
||||
|
||||
} // namespace fcitx
|
||||
|
|
Loading…
Reference in New Issue