Show translated/recognized text on top if there is no space below
This commit is contained in:
parent
4b5fb132f7
commit
872b047d70
@ -76,15 +76,27 @@ void ResultWidget::show(const TaskPtr &task)
|
|||||||
|
|
||||||
QDesktopWidget *desktop = QApplication::desktop();
|
QDesktopWidget *desktop = QApplication::desktop();
|
||||||
Q_CHECK_PTR(desktop);
|
Q_CHECK_PTR(desktop);
|
||||||
auto correction = QPoint((width() - task->captured.width()) / 2, lineWidth());
|
const auto correction =
|
||||||
move(task->capturePoint - correction);
|
QPoint((width() - task->captured.width()) / 2, lineWidth());
|
||||||
|
auto rect = QRect(task->capturePoint - correction, size());
|
||||||
|
|
||||||
auto screenRect = desktop->screenGeometry(this);
|
const auto screenRect = desktop->screenGeometry(this);
|
||||||
auto minY = screenRect.bottom() - height();
|
const auto shouldTextOnTop = rect.bottom() > screenRect.bottom();
|
||||||
if (y() > minY) {
|
if (shouldTextOnTop)
|
||||||
move(x(), minY);
|
rect.moveBottom(rect.top() + task->captured.height() + lineWidth());
|
||||||
|
|
||||||
|
auto layout = static_cast<QBoxLayout *>(this->layout());
|
||||||
|
SOFT_ASSERT(layout, return );
|
||||||
|
const auto isTextOnTop = layout->indexOf(recognized_) == 0;
|
||||||
|
if (isTextOnTop != shouldTextOnTop) {
|
||||||
|
layout->removeWidget(recognized_);
|
||||||
|
layout->removeWidget(translated_);
|
||||||
|
layout->insertWidget(shouldTextOnTop ? 0 : 1, recognized_);
|
||||||
|
layout->insertWidget(shouldTextOnTop ? 1 : 2, translated_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
move(rect.topLeft());
|
||||||
|
|
||||||
activateWindow();
|
activateWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user