calc result: remove wordwrap, instead decrea^C/increase font size as necessary
Este commit está contenido en:
padre
8484e88a27
commit
45abb2bf27
25
window.cpp
25
window.cpp
@ -38,7 +38,6 @@ Window::Window(const QVector<EntryConfig> &configs)
|
||||
calculationResultLabel.setFont(font);
|
||||
calculationResultLabel.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
calculationResultLabel.setAlignment(Qt::AlignCenter);
|
||||
calculationResultLabel.setWordWrap(true);
|
||||
calculationResultLabel.setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu);
|
||||
connect(&calculationResultLabel, &QLabel::customContextMenuRequested, this, &Window::showCalculationResultContextMenu);
|
||||
|
||||
@ -164,8 +163,30 @@ void Window::addCalcResult(const QString &expression)
|
||||
{
|
||||
clearGrid();
|
||||
currentCalculationResult = calcEngine.evaluate(expression);
|
||||
calculationResultLabel.setText(expression + ": " + currentCalculationResult);
|
||||
QString labelText = expression + ": " + currentCalculationResult;
|
||||
calculationResultLabel.setText(labelText);
|
||||
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);
|
||||
}
|
||||
|
||||
|
Cargando…
Referencia en una nueva incidencia
Block a user