mirror of
https://github.com/jankae/LibreVNA.git
synced 2026-04-04 22:17:31 +00:00
Font-dependent width in toolbar
This commit is contained in:
parent
bcb47717b5
commit
b636274b3b
9 changed files with 470 additions and 23 deletions
|
|
@ -87,13 +87,7 @@ bool SIUnitEdit::eventFilter(QObject *, QEvent *event)
|
|||
} else if(event->type() == QEvent::FocusIn) {
|
||||
// online found clumsy way to select all text when clicked!?!
|
||||
// just selectAll() alone does _not_ work!
|
||||
QTimer::singleShot(0, this, &QLineEdit::selectAll);
|
||||
/*
|
||||
* However, this widget does not loose focus when clicking on a smith chart from here
|
||||
* At the same time, clicking on x-y plot does loose focus as expected
|
||||
* This behaviour existed before this mod, but it was not obvious due to properties of placeholdertext
|
||||
*/
|
||||
|
||||
QTimer::singleShot(0, this, &SIUnitEdit::continueEditing);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
@ -102,8 +96,7 @@ void SIUnitEdit::setValueQuiet(double value)
|
|||
{
|
||||
_value = value;
|
||||
clear();
|
||||
setPlaceholderText(Unit::ToString(value, unit, prefixes, precision)); // didn't remove it because maybe needed elsewhere
|
||||
setText(Unit::ToString(value, unit, prefixes, precision)); // because selectAll() only affects setText() (placeholder text is igonred)
|
||||
setPlaceholderText(Unit::ToString(value, unit, prefixes, precision));
|
||||
}
|
||||
|
||||
void SIUnitEdit::parseNewValue(double factor)
|
||||
|
|
@ -130,7 +123,7 @@ void SIUnitEdit::parseNewValue(double factor)
|
|||
} else {
|
||||
qWarning() << "SIUnit conversion failure:" << input;
|
||||
}
|
||||
// clear(); // removed due to funny behaviour when clicking repeatedly between start, center, span, stop, but without editing anything
|
||||
clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,9 +24,10 @@ signals:
|
|||
void focusLost();
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||
private slots:
|
||||
void continueEditing();
|
||||
private:
|
||||
void parseNewValue(double factor);
|
||||
void continueEditing();
|
||||
QString unit, prefixes;
|
||||
int precision;
|
||||
double _value;
|
||||
|
|
|
|||
|
|
@ -73,7 +73,9 @@ SpectrumAnalyzer::SpectrumAnalyzer(AppWindow *window)
|
|||
// Sweep toolbar
|
||||
auto tb_sweep = new QToolBar("Sweep");
|
||||
auto eStart = new SIUnitEdit("Hz", " kMG", 6);
|
||||
eStart->setFixedWidth(100);
|
||||
// calculate width required with expected string length
|
||||
auto width = QFontMetrics(eStart->font()).width("3.00000GHz") + 15;
|
||||
eStart->setFixedWidth(width);
|
||||
eStart->setToolTip("Start frequency");
|
||||
connect(eStart, &SIUnitEdit::valueChanged, this, &SpectrumAnalyzer::SetStartFreq);
|
||||
connect(this, &SpectrumAnalyzer::startFreqChanged, eStart, &SIUnitEdit::setValueQuiet);
|
||||
|
|
@ -81,7 +83,7 @@ SpectrumAnalyzer::SpectrumAnalyzer(AppWindow *window)
|
|||
tb_sweep->addWidget(eStart);
|
||||
|
||||
auto eCenter = new SIUnitEdit("Hz", " kMG", 6);
|
||||
eCenter->setFixedWidth(100);
|
||||
eCenter->setFixedWidth(width);
|
||||
eCenter->setToolTip("Center frequency");
|
||||
connect(eCenter, &SIUnitEdit::valueChanged, this, &SpectrumAnalyzer::SetCenterFreq);
|
||||
connect(this, &SpectrumAnalyzer::centerFreqChanged, eCenter, &SIUnitEdit::setValueQuiet);
|
||||
|
|
@ -89,7 +91,7 @@ SpectrumAnalyzer::SpectrumAnalyzer(AppWindow *window)
|
|||
tb_sweep->addWidget(eCenter);
|
||||
|
||||
auto eStop = new SIUnitEdit("Hz", " kMG", 6);
|
||||
eStop->setFixedWidth(100);
|
||||
eStop->setFixedWidth(width);
|
||||
eStop->setToolTip("Stop frequency");
|
||||
connect(eStop, &SIUnitEdit::valueChanged, this, &SpectrumAnalyzer::SetStopFreq);
|
||||
connect(this, &SpectrumAnalyzer::stopFreqChanged, eStop, &SIUnitEdit::setValueQuiet);
|
||||
|
|
@ -97,7 +99,7 @@ SpectrumAnalyzer::SpectrumAnalyzer(AppWindow *window)
|
|||
tb_sweep->addWidget(eStop);
|
||||
|
||||
auto eSpan = new SIUnitEdit("Hz", " kMG", 6);
|
||||
eSpan->setFixedWidth(100);
|
||||
eSpan->setFixedWidth(width);
|
||||
eSpan->setToolTip("Span");
|
||||
connect(eSpan, &SIUnitEdit::valueChanged, this, &SpectrumAnalyzer::SetSpan);
|
||||
connect(this, &SpectrumAnalyzer::spanChanged, eSpan, &SIUnitEdit::setValueQuiet);
|
||||
|
|
@ -212,7 +214,7 @@ SpectrumAnalyzer::SpectrumAnalyzer(AppWindow *window)
|
|||
tb_trackgen->addWidget(dbm);
|
||||
|
||||
auto tgOffset = new SIUnitEdit("Hz", " kMG", 6);
|
||||
tgOffset->setFixedWidth(100);
|
||||
tgOffset->setFixedWidth(width);
|
||||
tgOffset->setToolTip("Tracking generator offset");
|
||||
connect(tgOffset, &SIUnitEdit::valueChanged, this, &SpectrumAnalyzer::SetTGOffset);
|
||||
connect(this, &SpectrumAnalyzer::TGOffsetChanged, tgOffset, &SIUnitEdit::setValueQuiet);
|
||||
|
|
@ -223,7 +225,7 @@ SpectrumAnalyzer::SpectrumAnalyzer(AppWindow *window)
|
|||
tb_trackgen->addWidget(normalize.enable);
|
||||
connect(normalize.enable, &QCheckBox::toggled, this, &SpectrumAnalyzer::EnableNormalization);
|
||||
normalize.Level = new SIUnitEdit("dBm", " ", 3);
|
||||
normalize.Level->setFixedWidth(100);
|
||||
normalize.Level->setFixedWidth(width);
|
||||
normalize.Level->setValue(0);
|
||||
normalize.Level->setToolTip("Level to normalize to");
|
||||
tb_trackgen->addWidget(new QLabel("To:"));
|
||||
|
|
|
|||
|
|
@ -171,10 +171,11 @@ VNA::VNA(AppWindow *window)
|
|||
|
||||
|
||||
// Sweep toolbar
|
||||
int wid = 80; // propose slight reduction, to fit more widgets comfortably
|
||||
auto tb_sweep = new QToolBar("Sweep");
|
||||
auto eStart = new SIUnitEdit("Hz", " kMG", 6);
|
||||
eStart->setFixedWidth(wid);
|
||||
// calculate width required with expected string length
|
||||
auto width = QFontMetrics(eStart->font()).width("3.00000GHz") + 15;
|
||||
eStart->setFixedWidth(width);
|
||||
eStart->setToolTip("Start frequency");
|
||||
connect(eStart, &SIUnitEdit::valueChanged, this, &VNA::SetStartFreq);
|
||||
connect(this, &VNA::startFreqChanged, eStart, &SIUnitEdit::setValueQuiet);
|
||||
|
|
@ -182,7 +183,7 @@ VNA::VNA(AppWindow *window)
|
|||
tb_sweep->addWidget(eStart);
|
||||
|
||||
auto eCenter = new SIUnitEdit("Hz", " kMG", 6);
|
||||
eCenter->setFixedWidth(wid);
|
||||
eCenter->setFixedWidth(width);
|
||||
eCenter->setToolTip("Center frequency");
|
||||
connect(eCenter, &SIUnitEdit::valueChanged, this, &VNA::SetCenterFreq);
|
||||
connect(this, &VNA::centerFreqChanged, eCenter, &SIUnitEdit::setValueQuiet);
|
||||
|
|
@ -190,7 +191,7 @@ VNA::VNA(AppWindow *window)
|
|||
tb_sweep->addWidget(eCenter);
|
||||
|
||||
auto eStop = new SIUnitEdit("Hz", " kMG", 6);
|
||||
eStop->setFixedWidth(wid);
|
||||
eStop->setFixedWidth(width);
|
||||
eStop->setToolTip("Stop frequency");
|
||||
connect(eStop, &SIUnitEdit::valueChanged, this, &VNA::SetStopFreq);
|
||||
connect(this, &VNA::stopFreqChanged, eStop, &SIUnitEdit::setValueQuiet);
|
||||
|
|
@ -198,7 +199,7 @@ VNA::VNA(AppWindow *window)
|
|||
tb_sweep->addWidget(eStop);
|
||||
|
||||
auto eSpan = new SIUnitEdit("Hz", " kMG", 6);
|
||||
eSpan->setFixedWidth(wid);
|
||||
eSpan->setFixedWidth(width);
|
||||
eSpan->setToolTip("Span");
|
||||
connect(eSpan, &SIUnitEdit::valueChanged, this, &VNA::SetSpan);
|
||||
connect(this, &VNA::spanChanged, eSpan, &SIUnitEdit::setValueQuiet);
|
||||
|
|
@ -226,7 +227,8 @@ VNA::VNA(AppWindow *window)
|
|||
// Acquisition toolbar
|
||||
auto tb_acq = new QToolBar("Acquisition");
|
||||
auto dbm = new QDoubleSpinBox();
|
||||
dbm->setFixedWidth(80); // propose slight reduction, to fit more widgets when App not maximized
|
||||
width = QFontMetrics(dbm->font()).width("-30.00dBm") + 20;
|
||||
dbm->setFixedWidth(width);
|
||||
dbm->setRange(-100.0, 100.0);
|
||||
dbm->setSingleStep(0.25);
|
||||
dbm->setSuffix("dbm");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue