From 4814872bcffddcce9e92a7d5c1a4ffdcd518569f Mon Sep 17 00:00:00 2001 From: Albert S Date: Sat, 8 May 2021 20:49:35 +0200 Subject: [PATCH] window: use new TextoutputLabel --- window.cpp | 38 ++++++++++---------------------------- window.h | 6 ++++-- 2 files changed, 14 insertions(+), 30 deletions(-) diff --git a/window.cpp b/window.cpp index 568eb69..198ae79 100644 --- a/window.cpp +++ b/window.cpp @@ -38,13 +38,7 @@ Window::Window(EntryProvider &entryProvider, SettingsProvider &configProvider) initFromConfig(); this->lineEdit->installEventFilter(this); this->setAcceptDrops(true); - QFont font; - font.setPointSize(48); - font.setBold(true); - calculationResultLabel.setFont(font); - calculationResultLabel.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - calculationResultLabel.setAlignment(Qt::AlignCenter); - calculationResultLabel.setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu); + connect(&calculationResultLabel, &QLabel::customContextMenuRequested, this, &Window::showCalculationResultContextMenu); } @@ -287,35 +281,23 @@ void Window::clearGrid() buttonsInGrid.clear(); } -void Window::addCalcResult(const QString &expression) +void Window::showGrowingOutputText(QString text) { clearGrid(); - currentCalculationResult = calcEngine.evaluate(expression); - QString labelText = expression + ": " + currentCalculationResult; - calculationResultLabel.setText(labelText); + calculationResultLabel.setText(text); calculationResultLabel.setVisible(true); - QFont currentFont = calculationResultLabel.font(); - int calculatedPointSize = currentFont.pointSize(); - QFontMetrics fm(currentFont); - int contentWidth = calculationResultLabel.contentsRect().width() - calculationResultLabel.margin(); - while(calculatedPointSize < 48 && fm.boundingRect(labelText).width() < contentWidth) - { - calculatedPointSize += 1; - currentFont.setPointSize(calculatedPointSize); - fm = QFontMetrics(currentFont); - } - while(fm.boundingRect(labelText).width() >= contentWidth) - { - calculatedPointSize -= 1; - currentFont.setPointSize(calculatedPointSize); - fm = QFontMetrics(currentFont); - } - calculationResultLabel.setFont(currentFont); grid->addWidget(&calculationResultLabel, 0, 0); } +void Window::addCalcResult(const QString &expression) +{ + currentCalculationResult = calcEngine.evaluate(expression); + QString labelText = expression + ": " + currentCalculationResult; + showGrowingOutputText(labelText); + +} // main problem here there is no easy event compression (clearing emit queue and only processing the last one) void Window::lineEditTextChanged(QString text) diff --git a/window.h b/window.h index 17c0fe0..4a2ca28 100644 --- a/window.h +++ b/window.h @@ -36,6 +36,7 @@ #include "entrypushbutton.h" #include "calculationengine.h" #include "settingsprovider.h" +#include "textoutputlabel.h" class RankedButton { @@ -59,7 +60,7 @@ class Window : public QWidget QVector userEntryButtons; QVector systemEntryButtons; QVector buttonsInGrid; - QLabel calculationResultLabel; + TextoutputLabel calculationResultLabel; QString currentCalculationResult; QString queuedFileSearch; QString queuedContentSearch; @@ -85,7 +86,8 @@ class Window : public QWidget void closeWindow(); std::pair getNextFreeCell(); int rankConfig(const EntryConfig &config, QString filter) const; - private slots: + void showGrowingOutputText(QString text); +private slots: void lineEditReturnPressed(); void showCalculationResultContextMenu(const QPoint &point);