window: use new TextoutputLabel

This commit is contained in:
Albert S. 2021-05-08 20:49:35 +02:00
parent 6d78dbe92e
commit 4814872bcf
2 changed files with 14 additions and 30 deletions

View File

@ -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)

View File

@ -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<EntryPushButton *> userEntryButtons;
QVector<EntryPushButton *> systemEntryButtons;
QVector<EntryPushButton *> buttonsInGrid;
QLabel calculationResultLabel;
TextoutputLabel calculationResultLabel;
QString currentCalculationResult;
QString queuedFileSearch;
QString queuedContentSearch;
@ -85,7 +86,8 @@ class Window : public QWidget
void closeWindow();
std::pair<int, int> getNextFreeCell();
int rankConfig(const EntryConfig &config, QString filter) const;
private slots:
void showGrowingOutputText(QString text);
private slots:
void lineEditReturnPressed();
void showCalculationResultContextMenu(const QPoint &point);