1
0
Fork 0

Replace broken line breaking in goto dialog with tooltip

This commit is contained in:
Duncan Ogilvie 2024-01-06 01:31:19 +01:00
parent a6e448b598
commit 9c07d82dc8
1 changed files with 7 additions and 20 deletions

View File

@ -46,7 +46,9 @@ GotoDialog::GotoDialog(QWidget* parent, bool allowInvalidExpression, bool allowI
connect(this, SIGNAL(finished(int)), this, SLOT(finishedSlot(int))); connect(this, SIGNAL(finished(int)), this, SLOT(finishedSlot(int)));
connect(Config(), SIGNAL(disableAutoCompleteUpdated()), this, SLOT(disableAutoCompleteUpdated())); connect(Config(), SIGNAL(disableAutoCompleteUpdated()), this, SLOT(disableAutoCompleteUpdated()));
auto prevSize = size();
Config()->loadWindowGeometry(this); Config()->loadWindowGeometry(this);
this->resize(prevSize);
} }
GotoDialog::~GotoDialog() GotoDialog::~GotoDialog()
@ -61,6 +63,9 @@ void GotoDialog::showEvent(QShowEvent* event)
{ {
Q_UNUSED(event); Q_UNUSED(event);
mValidateThread->start(); mValidateThread->start();
// Fix the label width
ui->labelError->setMaximumWidth(ui->labelError->width());
} }
void GotoDialog::hideEvent(QHideEvent* event) void GotoDialog::hideEvent(QHideEvent* event)
@ -85,24 +90,6 @@ void GotoDialog::setInitialExpression(const QString & expression)
emit ui->editExpression->textEdited(expression); emit ui->editExpression->textEdited(expression);
} }
static QString breakWithLines(const unsigned int numberCharsPerLine, const QString & txt, const bool condBreakBefore)
{
const QString BRStr = QString("<br>");
const unsigned int breakCount = txt.size() / numberCharsPerLine;
QString result = txt;
for(unsigned int i = 1 ; i <= breakCount; i++)
{
unsigned int charactersToSkip = (numberCharsPerLine + BRStr.size()) * i - BRStr.size();
result = result.left(charactersToSkip) + BRStr + result.right(result.size() - charactersToSkip);
}
if(condBreakBefore && breakCount >= 1)
result = BRStr + result;
return result;
}
void GotoDialog::expressionChanged(bool validExpression, bool validPointer, dsint value) void GotoDialog::expressionChanged(bool validExpression, bool validPointer, dsint value)
{ {
QString expression = ui->editExpression->text(); QString expression = ui->editExpression->text();
@ -186,8 +173,8 @@ void GotoDialog::expressionChanged(bool validExpression, bool validPointer, dsin
else else
addrText = ToPtrString(addr); addrText = ToPtrString(addr);
addrText = breakWithLines(ui->editExpression->size().width() / 11, addrText, true); // 11 is a good value for WWWWWWWs ui->labelError->setToolTip(QString("<qt>%1</qt>").arg(addrText.toHtmlEscaped()));
ui->labelError->setText(tr("<font color='#00DD00'><b>Correct expression! -&gt; </b></font>") + addrText); ui->labelError->setText(tr("<font color='#00DD00'><b>Correct expression! -&gt; </b></font>") + addrText.toHtmlEscaped());
setOkEnabled(true); setOkEnabled(true);
expressionText = expression; expressionText = expression;
} }