From 953a537cb85f48921555bd16f96ae77eea1ab927 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Sat, 1 Jan 2022 21:27:42 -0700 Subject: [PATCH] squashing final bugs with resizing --- extensions/extrawindow.cpp | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/extensions/extrawindow.cpp b/extensions/extrawindow.cpp index a7398d5..5f1cdf6 100644 --- a/extensions/extrawindow.cpp +++ b/extensions/extrawindow.cpp @@ -117,10 +117,7 @@ protected: private: void RequestFont() { - QFont font; - // Forced reading of the font from settings otherwise the font window does not have the size set - if (!font.fromString(settings.value(FONT, font.toString()).toString())) font = ui.display->font(); - if (font = QFontDialog::getFont(&ok, font, this, FONT); ok) + if (QFont font = QFontDialog::getFont(&ok, ui.display->font(), this, FONT); ok) { settings.setValue(FONT, font.toString()); ui.display->setFont(font); @@ -254,32 +251,28 @@ private: if (!showOriginal) sentence = sentence.split(u8"\x200b \n")[1]; else if (showOriginalAfterTranslation) sentence = sentence.split(u8"\x200b \n")[1] + "\n" + sentence.split(u8"\x200b \n")[0]; - if (autoResize) - { - ui.display->resize( - ui.display->width(), - QFontMetrics(ui.display->font(), ui.display).boundingRect(0, 0, ui.display->width(), INT_MAX, Qt::TextWordWrap, sentence).height() - ); - //resize(width(), QFontMetrics(ui.display->font(), ui.display).boundingRect(0, 0, ui.display->width(), INT_MAX, Qt::TextWordWrap, sentence).height() + 22); - } - else if (sizeLock) + if (sizeLock && !autoResize) { QFontMetrics fontMetrics(ui.display->font(), ui.display); int low = 0, high = sentence.size(), last = 0; - while (low < high) + while (low <= high) { int mid = (low + high) / 2; - if (fontMetrics.boundingRect(0, 0, ui.display->width(), INT_MAX, Qt::TextWordWrap, sentence.left(mid)).height() < ui.display->height()) + if (fontMetrics.boundingRect(0, 0, ui.display->width(), INT_MAX, Qt::TextWordWrap, sentence.left(mid)).height() <= ui.display->height()) { last = mid; low = mid + 1; } - else high = mid; + else high = mid - 1; } sentence = sentence.left(last); } ui.display->setText(sentence); + if (autoResize) + resize(width(), height() - ui.display->height() + + QFontMetrics(ui.display->font(), ui.display).boundingRect(0, 0, ui.display->width(), INT_MAX, Qt::TextWordWrap, sentence).height() + ); } void SetTopmost(bool topmost)