Special Commands Handling #41
38
window.cpp
38
window.cpp
@ -38,13 +38,7 @@ Window::Window(EntryProvider &entryProvider, SettingsProvider &configProvider)
|
|||||||
initFromConfig();
|
initFromConfig();
|
||||||
this->lineEdit->installEventFilter(this);
|
this->lineEdit->installEventFilter(this);
|
||||||
this->setAcceptDrops(true);
|
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,
|
connect(&calculationResultLabel, &QLabel::customContextMenuRequested, this,
|
||||||
&Window::showCalculationResultContextMenu);
|
&Window::showCalculationResultContextMenu);
|
||||||
}
|
}
|
||||||
@ -287,35 +281,23 @@ void Window::clearGrid()
|
|||||||
buttonsInGrid.clear();
|
buttonsInGrid.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::addCalcResult(const QString &expression)
|
void Window::showGrowingOutputText(QString text)
|
||||||
{
|
{
|
||||||
clearGrid();
|
clearGrid();
|
||||||
currentCalculationResult = calcEngine.evaluate(expression);
|
calculationResultLabel.setText(text);
|
||||||
QString labelText = expression + ": " + currentCalculationResult;
|
|
||||||
calculationResultLabel.setText(labelText);
|
|
||||||
calculationResultLabel.setVisible(true);
|
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);
|
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)
|
// main problem here there is no easy event compression (clearing emit queue and only processing the last one)
|
||||||
void Window::lineEditTextChanged(QString text)
|
void Window::lineEditTextChanged(QString text)
|
||||||
|
6
window.h
6
window.h
@ -36,6 +36,7 @@
|
|||||||
#include "entrypushbutton.h"
|
#include "entrypushbutton.h"
|
||||||
#include "calculationengine.h"
|
#include "calculationengine.h"
|
||||||
#include "settingsprovider.h"
|
#include "settingsprovider.h"
|
||||||
|
#include "textoutputlabel.h"
|
||||||
|
|
||||||
class RankedButton
|
class RankedButton
|
||||||
{
|
{
|
||||||
@ -59,7 +60,7 @@ class Window : public QWidget
|
|||||||
QVector<EntryPushButton *> userEntryButtons;
|
QVector<EntryPushButton *> userEntryButtons;
|
||||||
QVector<EntryPushButton *> systemEntryButtons;
|
QVector<EntryPushButton *> systemEntryButtons;
|
||||||
QVector<EntryPushButton *> buttonsInGrid;
|
QVector<EntryPushButton *> buttonsInGrid;
|
||||||
QLabel calculationResultLabel;
|
TextoutputLabel calculationResultLabel;
|
||||||
QString currentCalculationResult;
|
QString currentCalculationResult;
|
||||||
QString queuedFileSearch;
|
QString queuedFileSearch;
|
||||||
QString queuedContentSearch;
|
QString queuedContentSearch;
|
||||||
@ -85,7 +86,8 @@ class Window : public QWidget
|
|||||||
void closeWindow();
|
void closeWindow();
|
||||||
std::pair<int, int> getNextFreeCell();
|
std::pair<int, int> getNextFreeCell();
|
||||||
int rankConfig(const EntryConfig &config, QString filter) const;
|
int rankConfig(const EntryConfig &config, QString filter) const;
|
||||||
private slots:
|
void showGrowingOutputText(QString text);
|
||||||
|
private slots:
|
||||||
void lineEditReturnPressed();
|
void lineEditReturnPressed();
|
||||||
void showCalculationResultContextMenu(const QPoint &point);
|
void showCalculationResultContextMenu(const QPoint &point);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user