[Simulator] UI tweaks for last major update. (#4414)

* [Simulator] Debug output: Adjust exclusion filter, help text <kbd> background color, fix help text typos & mark as translatable.

* [Simulator] Radio Outputs: Fix wrong FM highlighted (closes #4408) and current FM not highlighted until switched once; Change highlight color role of active LS/FM so it is always shown (fixes #4393); Active LSs now much more obvious (bold font & sunken frame).

* [Simulator] Rework some SimulatorMainWindow functionality:
    * Fix floating dock widgets appearing behind other applications on Linux (https://github.com/opentx/opentx/issues/4403#issuecomment-277510273);
    * Fix previously-unused floating dock widgets appearing in top-left corner upon subsequent launches of application (https://github.com/opentx/opentx/pull/4385#issuecomment-277315158);
    * Fix various anomalies due to not using a "central widget" in QMainWindow (extra separators appearing, vertical resize not working in some cases), radio widget is now central by default;
    * Add (keep) option to float the radio widget separate from main window, though this may cause the minor visual anomalies mentioned above;
    * Add options to disable radio widget size constraints while docked.
This commit is contained in:
Max Paperno
2017-02-06 18:27:03 +01:00
committed by Bertrand Songis
parent b0eeeb4dbc
commit ded843b989
7 changed files with 280 additions and 124 deletions
+7 -7
View File
@@ -67,7 +67,7 @@ DebugOutput::DebugOutput(QWidget * parent, SimulatorInterface *simulator):
QStringList stockFilters;
stockFilters << "^lua[A-Z].*";
stockFilters << "/(error|warning|-(E|W)-)/i";
stockFilters << "!^(GC Use|(play|load|write|find(True)?)File|convert(To|From)Simu|\\tfound( in map)?:|eeprom |f_[a-z]+\\(|(push|(p|P)op(up)?|chain)? ?Menu( .+ display)?|RamBackup).+$";
stockFilters << "!^(GC Use|(play|load|write|find(True)?)File|convert(To|From)Simu|\\t(not )?found( in map)?:?|eeprom |f_[a-z]+\\(|(push|(p|P)op(up)?|chain)? ?Menu( .+ display)?|RamBackup).+$";
foreach (const QString & fltr, stockFilters)
ui->filterText->addItem(fltr, "no_delete");
@@ -267,9 +267,9 @@ void DebugOutput::on_actionClearScr_triggered()
void DebugOutput::on_actionShowFilterHelp_triggered()
{
// TODO : find some place better for this.
QString help = \
"<html><head><style>kbd {background-color: ghostwhite; font-size: large; white-space: nowrap;}</style></head><body>"
"<p>The filter supports two syntax types: basic matching with common wildcards and well as full Perl-style (<code>pcre</code>) Regular Expressions.</p>"
QString help = tr( \
"<html><head><style>kbd {background-color: palette(alternate-base); font-size: large; white-space: nowrap;}</style></head><body>"
"<p>The filter supports two syntax types: basic matching with common wildcards as well as full Perl-style (<code>pcre</code>) Regular Expressions.</p>"
"<p>By default a filter will only show lines which match (<b>inclusive</b>). To make an <b>exclusive</b> filter which removes matching lines, "
"prefix the filter expression with a <kbd>!</kbd> (exclamation mark).</p>"
"<p>To use <b>Regular Expressions</b> (RegEx), prefix the filter text with a <kbd>/</kbd> (slash) or <kbd>^</kbd> (up caret). "
@@ -280,8 +280,9 @@ void DebugOutput::on_actionShowFilterHelp_triggered()
"<li>If the RegEx is invalid, the filter edit field should show a red border and you will not be able to enable the filter.</li>"
"<li>A useful resource for testing REs (with a full reference) can be found at <a href=\"http://www.regexr.com/\">http://www.regexr.com/</a></li>"
"</ul></p>"
"<p>To use <b>basic matching</b> just type any text. Wildcards <kbd>*</kbd> (asterisk) matches any text and <kbd>?</kbd> (question mark) matches any single character."
"<p>To use <b>basic matching</b> just type any text."
"<ul>"
"<li>Wildcards: <kbd>*</kbd> (asterisk) matches zero or more of any character(s), and <kbd>?</kbd> (question mark) matches any single character.</li>"
"<li>The match is always case-insensitive.</li>"
"<li>The match always starts from the beginning of a log line. To ignore characters at the start, use a leading <kbd>*</kbd> wildcard.</li>"
"<li>A trailing <kbd>*</kbd> is always implied (that is, matches anything to the end of the log line). To avoid this, use a RegEx.</li>"
@@ -291,7 +292,7 @@ void DebugOutput::on_actionShowFilterHelp_triggered()
"<p>To <b>remove an entry</b> from the filter selector list, first choose it, and while in the line editor press <kbd>Shift-Delete</kbd> (or <kbd>Shift-Backspace</kbd>) key combination. "
"The default filters cannot be removed. Up to 50 filters are stored.</p>"
"</body></html>"
;
);
QMessageBox * msgbox = new QMessageBox(QMessageBox::NoIcon, tr("Debug Console Filter Help"), help, QMessageBox::Ok, this);
msgbox->exec();
}
@@ -341,7 +342,6 @@ QRegularExpression DebugOutput::makeRegEx(const QString & input, bool * isExlusi
reFlags |= QRegularExpression::CaseInsensitiveOption;
re.setPattern(output);
}
// TODO : user option?
re.setPatternOptions(reFlags);
return re;
}
+36 -36
View File
@@ -234,8 +234,8 @@ void RadioOutputsWidget::setupGVarsDisplay()
gvarsLayout->addWidget(label, gv+1, 0);
for (int fm=0; fm < fmodes; fm++) {
QLabel * value = new QLabel(gvarsWidget);
value->setAutoFillBackground(true);
value->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
value->setAutoFillBackground(true);
value->setBackgroundRole(bgrole);
value->setText("0");
value->setStyleSheet("padding-right: .06em;");
@@ -272,43 +272,38 @@ void RadioOutputsWidget::setupLsDisplay()
// populate logical switches
int rows = switches / (switches > 16 ? 4 : 2);
for (int i=0; i < switches; i++) {
QLabel * lsLbl = new QLabel;
logicalSwitchesLayout->addWidget(createLogicalSwitch(logicalSwitches, i, lsLbl), i / rows, i % rows, 1, 1);
m_logicSwitchMap.insert(i, lsLbl);
logicalSwitchesLayout->addWidget(createLogicalSwitch(logicalSwitches, i), i / rows, i % rows, 1, 1);
}
}
QWidget * RadioOutputsWidget::createLogicalSwitch(QWidget * parent, int switchNo, QLabel * label)
QWidget * RadioOutputsWidget::createLogicalSwitch(QWidget * parent, int switchNo)
{
QFrame * swtch = new QFrame(parent);
QLabel * swtch = new QLabel(parent);
swtch->setAutoFillBackground(true);
swtch->setFrameShape(QFrame::Panel);
swtch->setFrameShadow(QFrame::Raised);
swtch->setFrameStyle(QFrame::Panel | QFrame::Raised);
swtch->setLineWidth(2);
swtch->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
swtch->setMaximumHeight(18);
QVBoxLayout * layout = new QVBoxLayout(swtch);
layout->setContentsMargins(2, 0, 2, 0);
if (label) {
QFont font;
font.setPointSize(8);
label->setParent(swtch);
label->setFont(font);
label->setText(RawSwitch(SWITCH_TYPE_VIRTUAL, switchNo+1).toString());
label->setAlignment(Qt::AlignCenter);
label->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
label->setAutoFillBackground(true);
layout->addWidget(label);
}
QFont font = swtch->font();
font.setBold(true);
swtch->setFont(font);
swtch->setMinimumWidth(swtch->fontMetrics().width("99") + 10);
font.setBold(false);
swtch->setFont(font);
swtch->setText(QString("%1").arg(RawSwitch(SWITCH_TYPE_VIRTUAL, switchNo+1).toString().remove("L"), 2, QLatin1Char('0')));
swtch->setAlignment(Qt::AlignCenter);
m_logicSwitchMap.insert(switchNo, swtch);
return swtch;
}
// Read various values from firmware simulator and populate values in this UI
void RadioOutputsWidget::setValues()
{
static int lastPhase = 0;
static int lastPhase = -1;
static TxOutputs prevOutputs = TxOutputs();
static bool firstGvarsRun = true;
int currentPhase;
TxOutputs outputs;
QFont font;
m_simulator->getValues(outputs);
currentPhase = m_simulator->getPhase();
@@ -328,13 +323,17 @@ void RadioOutputsWidget::setValues()
for (ls = m_logicSwitchMap.constBegin(); ls != m_logicSwitchMap.constEnd(); ++ls) {
if (ls.key() >= CPN_MAX_CSW || prevOutputs.vsw[ls.key()] == outputs.vsw[ls.key()])
continue;
ls.value()->setBackgroundRole(outputs.vsw[ls.key()] ? QPalette::Highlight : QPalette::Background);
ls.value()->setBackgroundRole(outputs.vsw[ls.key()] ? QPalette::Dark : QPalette::Background);
ls.value()->setForegroundRole(outputs.vsw[ls.key()] ? QPalette::BrightText : QPalette::WindowText);
ls.value()->setFrameShadow(outputs.vsw[ls.key()] ? QFrame::Sunken : QFrame::Raised);
font = ls.value()->font();
font.setBold(outputs.vsw[ls.key()]);
ls.value()->setFont(font);
prevOutputs.vsw[ls.key()] = outputs.vsw[ls.key()];
}
}
if (ui->globalVarsWidget->isVisible()) {
QFont font;
QPalette::ColorRole bgrole;
QHash<int, QHash<int, QLabel *> >::const_iterator gv;
QHash<int, QLabel *>::const_iterator fm;
@@ -344,22 +343,23 @@ void RadioOutputsWidget::setValues()
for (fm = gv.value().constBegin(); fm != gv.value().constEnd(); ++fm) {
if (fm.key() >= CPN_MAX_FLIGHT_MODES)
continue;
if (currentPhase != lastPhase || prevOutputs.gvars[fm.key()][gv.key()] != outputs.gvars[fm.key()][gv.key()]) {
font = fm.value()->font();
bgrole = ((gv.key() % 2) ? QPalette::Background : QPalette::AlternateBase);
if (fm.key() == lastPhase) {
font.setBold(true);
bgrole = QPalette::Highlight;
}
fm.value()->setText(QString::number(outputs.gvars[fm.key()][gv.key()]));
fm.value()->setFont(font);
if (currentPhase != lastPhase || prevOutputs.gvars[fm.key()][gv.key()] != outputs.gvars[fm.key()][gv.key()] || firstGvarsRun) {
if (fm.key() == currentPhase)
bgrole = QPalette::Dark;
else
bgrole = ((gv.key() % 2) ? QPalette::Background : QPalette::AlternateBase);
fm.value()->setBackgroundRole(bgrole);
fm.value()->setForegroundRole(fm.key() == currentPhase ? QPalette::BrightText : QPalette::WindowText);
font = fm.value()->font();
font.setBold(fm.key() == currentPhase);
fm.value()->setFont(font);
fm.value()->setText(QString::number(outputs.gvars[fm.key()][gv.key()]));
prevOutputs.gvars[fm.key()][gv.key()] = outputs.gvars[fm.key()][gv.key()];
firstGvarsRun = false;
}
}
}
}
if (currentPhase != lastPhase)
lastPhase = currentPhase;
lastPhase = currentPhase;
}
@@ -63,7 +63,7 @@ class RadioOutputsWidget : public QWidget
void setupChannelsDisplay();
void setupLsDisplay();
void setupGVarsDisplay();
QWidget * createLogicalSwitch(QWidget * parent, int switchNo, QLabel * label);
QWidget * createLogicalSwitch(QWidget * parent, int switchNo);
SimulatorInterface * m_simulator;
Firmware * m_firmware;
+3 -5
View File
@@ -11,7 +11,7 @@
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@@ -20,7 +20,7 @@
<string>Companion Simulator</string>
</property>
<property name="windowIcon">
<iconset resource="../companion.qrc">
<iconset>
<normaloff>:/icon.png</normaloff>:/icon.png</iconset>
</property>
<property name="styleSheet">
@@ -307,8 +307,6 @@
</item>
</layout>
</widget>
<resources>
<include location="../companion.qrc"/>
</resources>
<resources/>
<connections/>
</ui>
+170 -61
View File
@@ -36,7 +36,7 @@
extern AppData g; // ensure what "g" means
const quint16 SimulatorMainWindow::m_savedUiStateVersion = 1;
const quint16 SimulatorMainWindow::m_savedUiStateVersion = 2;
SimulatorMainWindow::SimulatorMainWindow(QWidget *parent, SimulatorInterface * simulator, quint8 flags, Qt::WindowFlags wflags) :
QMainWindow(parent, wflags),
@@ -51,28 +51,21 @@ SimulatorMainWindow::SimulatorMainWindow(QWidget *parent, SimulatorInterface * s
m_trainerDockWidget(NULL),
m_outputsDockWidget(NULL),
m_radioProfileId(g.sessionId()),
m_radioSizeConstraint(Qt::Horizontal | Qt::Vertical),
m_firstShow(true),
m_showRadioTitlebar(true),
m_showRadioDocked(true),
m_showMenubar(true)
{
ui->setupUi(this);
ui->centralwidget->hide();
//#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
// setDockOptions(dockOptions() | QMainWindow::GroupedDragging);
//#endif
setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
m_simulatorWidget = new SimulatorDialog(this, m_simulator, flags);
m_simulatorDockWidget = new QDockWidget(m_simulatorWidget->windowTitle(), this);
m_simulatorDockWidget->setObjectName("RADIO_SIMULATOR");
m_simulatorDockWidget->setWidget(m_simulatorWidget);
m_simulatorDockWidget->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);
addDockWidget(Qt::BottomDockWidgetArea, m_simulatorDockWidget);
// setCentralWidget(m_simulatorWidget);
toggleRadioDocked(true);
createDockWidgets();
ui->actionReloadLua->setIcon(SimulatorIcon("reload_script"));
@@ -80,8 +73,10 @@ SimulatorMainWindow::SimulatorMainWindow(QWidget *parent, SimulatorInterface * s
ui->actionJoystickSettings->setIcon(SimulatorIcon("joystick_settings"));
ui->actionScreenshot->setIcon(SimulatorIcon("camera"));
ui->actionShowKeymap->setIcon(SimulatorIcon("info"));
ui->actionToggleRadioTitle->setIcon(ui->toolBar->toggleViewAction()->icon());
ui->actionToggleMenuBar->setIcon(ui->toolBar->toggleViewAction()->icon());
ui->actionFixedRadioWidth->setIcon(ui->toolBar->toggleViewAction()->icon());
ui->actionFixedRadioHeight->setIcon(ui->toolBar->toggleViewAction()->icon());
ui->actionDockRadio->setIcon(ui->toolBar->toggleViewAction()->icon());
ui->toolBar->toggleViewAction()->setShortcut(tr("Alt+T"));
ui->toolBar->setIconSize(SimulatorIcon::toolbarIconSize(g.iconSize()));
@@ -91,10 +86,8 @@ SimulatorMainWindow::SimulatorMainWindow(QWidget *parent, SimulatorInterface * s
addAction(ui->toolBar->toggleViewAction());
addAction(ui->actionToggleMenuBar);
ui->menuView->addSeparator();
ui->menuView->addAction(ui->toolBar->toggleViewAction());
ui->menuView->addAction(ui->actionToggleMenuBar);
ui->menuView->addAction(ui->actionToggleRadioTitle);
ui->menuView->insertSeparator(ui->actionToggleMenuBar);
ui->menuView->insertAction(ui->actionToggleMenuBar, ui->toolBar->toggleViewAction());
// Hide some actions based on board capabilities.
Firmware * firmware = getCurrentFirmware();
@@ -117,23 +110,16 @@ SimulatorMainWindow::SimulatorMainWindow(QWidget *parent, SimulatorInterface * s
connect(ui->actionShowKeymap, &QAction::triggered, this, &SimulatorMainWindow::showHelp);
connect(ui->actionJoystickSettings, &QAction::triggered, this, &SimulatorMainWindow::openJoystickDialog);
connect(ui->actionReloadLua, &QAction::triggered, this, &SimulatorMainWindow::luaReload);
connect(ui->actionToggleRadioTitle, &QAction::toggled, this, &SimulatorMainWindow::showRadioTitlebar);
connect(ui->actionToggleMenuBar, &QAction::toggled, this, &SimulatorMainWindow::toggleMenuBar);
connect(ui->actionToggleMenuBar, &QAction::toggled, this, &SimulatorMainWindow::showMenuBar);
connect(ui->actionFixedRadioWidth, &QAction::toggled, this, &SimulatorMainWindow::showRadioFixedWidth);
connect(ui->actionFixedRadioHeight, &QAction::toggled, this, &SimulatorMainWindow::showRadioFixedHeight);
connect(ui->actionDockRadio, &QAction::toggled, this, &SimulatorMainWindow::showRadioDocked);
if (m_simulatorWidget) {
connect(ui->actionScreenshot, &QAction::triggered, m_simulatorWidget, &SimulatorDialog::captureScreenshot);
connect(ui->actionReloadRadioData, &QAction::triggered, m_simulatorWidget, &SimulatorDialog::restart);
}
if (m_outputsWidget)
connect(ui->actionReloadRadioData, &QAction::triggered, m_outputsWidget, &RadioOutputsWidget::restart);
// this sets the radio widget to a fixed width while docked, freeform while floating
connect(m_simulatorDockWidget, &QDockWidget::topLevelChanged, [this](bool top) {
if (top)
m_simulatorWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
else
m_simulatorWidget->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
});
}
SimulatorMainWindow::~SimulatorMainWindow()
@@ -155,6 +141,20 @@ void SimulatorMainWindow::closeEvent(QCloseEvent *)
delete m_outputsDockWidget;
if (m_simulatorDockWidget)
delete m_simulatorDockWidget;
else if (m_simulatorWidget)
delete m_simulatorWidget;
}
void SimulatorMainWindow::show()
{
QMainWindow::show();
#ifdef Q_OS_LINUX
// for whatever reason, w/out this workaround any floating docks may appear and get "stuck" behind other windows, eg. Terminal or Companion.
if (m_firstShow) {
restoreUiState();
m_firstShow = false;
}
#endif
}
void SimulatorMainWindow::changeEvent(QEvent *e)
@@ -169,10 +169,10 @@ void SimulatorMainWindow::changeEvent(QEvent *e)
}
}
QMenu* SimulatorMainWindow::createPopupMenu(){
QMenu * SimulatorMainWindow::createPopupMenu(){
QMenu * menu = QMainWindow::createPopupMenu();
menu->addAction(ui->actionToggleMenuBar);
menu->addAction(ui->actionToggleRadioTitle);
menu->clear();
menu->addActions(ui->menuView->actions());
return menu;
}
@@ -180,7 +180,8 @@ void SimulatorMainWindow::saveUiState()
{
QByteArray state;
QDataStream stream(&state, QIODevice::WriteOnly);
stream << m_savedUiStateVersion << saveState() << m_showMenubar << m_showRadioTitlebar;
stream << m_savedUiStateVersion << saveState(m_savedUiStateVersion)
<< m_showMenubar << m_showRadioDocked << m_radioSizeConstraint;
SimulatorOptions opts = g.profile[m_radioProfileId].simulatorOptions();
opts.windowState = state;
@@ -196,13 +197,17 @@ void SimulatorMainWindow::restoreUiState()
QDataStream stream(state);
stream >> ver;
if (ver && ver <= m_savedUiStateVersion)
stream >> windowState >> m_showMenubar >> m_showRadioTitlebar;
if (ver && ver <= m_savedUiStateVersion) {
stream >> windowState >> m_showMenubar >> m_showRadioDocked;
if (ver >= 2)
stream >> m_radioSizeConstraint;
}
restoreState(windowState);
restoreGeometry(g.profile[m_radioProfileId].simulatorOptions().windowGeometry);
showRadioTitlebar(m_showRadioTitlebar);
toggleRadioDocked(m_showRadioDocked);
setRadioSizePolicy(m_radioSizeConstraint);
toggleMenuBar(m_showMenubar);
restoreGeometry(g.profile[m_radioProfileId].simulatorOptions().windowGeometry);
restoreState(windowState, m_savedUiStateVersion);
}
bool SimulatorMainWindow::setRadioData(RadioData * radioData)
@@ -236,17 +241,15 @@ void SimulatorMainWindow::createDockWidgets()
SimulatorIcon icon("radio_outputs");
m_outputsDockWidget = new QDockWidget(tr("Radio Outputs"), this);
m_outputsWidget = new RadioOutputsWidget(m_simulator, getCurrentFirmware(), this);
m_outputsWidget->setWindowIcon(icon);
m_outputsDockWidget->setWidget(m_outputsWidget);
m_outputsDockWidget->setObjectName("OUTPUTS");
addTool(m_outputsDockWidget, Qt::BottomDockWidgetArea, icon, QKeySequence(tr("F2")));
addTool(m_outputsDockWidget, Qt::RightDockWidgetArea, icon, QKeySequence(tr("F2")));
}
if (!m_telemetryDockWidget) {
SimulatorIcon icon("telemetry");
m_telemetryDockWidget = new QDockWidget(tr("Telemetry Simulator"), this);
TelemetrySimulator * telem = new TelemetrySimulator(this, m_simulator);
telem->setWindowIcon(icon);
m_telemetryDockWidget->setWidget(telem);
m_telemetryDockWidget->setObjectName("TELEMETRY_SIMULATOR");
addTool(m_telemetryDockWidget, Qt::LeftDockWidgetArea, icon, QKeySequence(tr("F4")));
@@ -256,7 +259,6 @@ void SimulatorMainWindow::createDockWidgets()
SimulatorIcon icon("trainer");
m_trainerDockWidget = new QDockWidget(tr("Trainer Simulator"), this);
TrainerSimulator * trainer = new TrainerSimulator(this, m_simulator);
trainer->setWindowIcon(icon);
m_trainerDockWidget->setWidget(trainer);
m_trainerDockWidget->setObjectName("TRAINER_SIMULATOR");
addTool(m_trainerDockWidget, Qt::TopDockWidgetArea, icon, QKeySequence(tr("F5")));
@@ -266,7 +268,6 @@ void SimulatorMainWindow::createDockWidgets()
SimulatorIcon icon("console");
m_consoleDockWidget = new QDockWidget(tr("Debug Output"), this);
m_consoleWidget = new DebugOutput(this, m_simulator);
m_consoleWidget->setWindowIcon(icon);
m_consoleDockWidget->setWidget(m_consoleWidget);
m_consoleDockWidget->setObjectName("CONSOLE");
addTool(m_consoleDockWidget, Qt::RightDockWidgetArea, icon, QKeySequence(tr("F6")));
@@ -278,40 +279,148 @@ void SimulatorMainWindow::addTool(QDockWidget * widget, Qt::DockWidgetArea area,
QAction* tempAction = widget->toggleViewAction();
tempAction->setIcon(icon);
tempAction->setShortcut(shortcut);
ui->menuView->addAction(tempAction);
ui->menuView->insertAction(ui->actionToggleMenuBar, tempAction);
ui->toolBar->insertAction(ui->actionReloadLua, tempAction);
widget->setAllowedAreas(Qt::AllDockWidgetAreas);
widget->setWindowIcon(icon);
widget->widget()->setWindowIcon(icon);
addDockWidget(area, widget);
widget->hide();
widget->setFloating(true);
// Upon subsequent launches of application, any previously un-shown floating widgets get
// positioned at screen location (0,0 - frameGeometry.topLeft) which is awkward at best.
// This ensures newly shown floating widgets don't get stuck in top left corner.
connect(widget, &QDockWidget::visibilityChanged, [this, widget](bool visible) {
if (visible && widget->isFloating() && widget->geometry().topLeft() == QPoint(0,0)) {
// position top left corner in middle of this parent window.
QPoint newPos(pos() + (geometry().bottomRight() - geometry().topLeft()) / 2);
widget->move(newPos);
}
});
}
void SimulatorMainWindow::showRadioTitlebar(bool show)
void SimulatorMainWindow::showMenuBar(bool show)
{
m_showRadioTitlebar = show;
if (show) {
QWidget * w = m_simulatorDockWidget->titleBarWidget();
if (w)
w->deleteLater();
m_simulatorDockWidget->setTitleBarWidget(0);
}
else {
m_simulatorDockWidget->setTitleBarWidget(new QWidget());
}
if (ui->actionToggleRadioTitle->isChecked() != show)
ui->actionToggleRadioTitle->setChecked(show);
if (m_showMenubar != show)
toggleMenuBar(show);
}
void SimulatorMainWindow::toggleMenuBar(bool show)
{
m_showMenubar = show;
ui->menubar->setVisible(show);
m_showMenubar = show;
if (ui->actionToggleMenuBar->isChecked() != show)
ui->actionToggleMenuBar->setChecked(show);
}
void SimulatorMainWindow::showRadioFixedSize(Qt::Orientation orientation, bool fixed)
{
int fix = m_radioSizeConstraint;
if (fixed)
fix |= orientation;
else
fix &= ~(orientation);
if (m_radioSizeConstraint != fix)
setRadioSizePolicy(fix);
}
void SimulatorMainWindow::showRadioFixedWidth(bool fixed)
{
showRadioFixedSize(Qt::Horizontal, fixed);
}
void SimulatorMainWindow::showRadioFixedHeight(bool fixed)
{
showRadioFixedSize(Qt::Vertical, fixed);
}
void SimulatorMainWindow::setRadioSizePolicy(int fixType)
{
QSizePolicy sp;
sp.setHorizontalPolicy((fixType & Qt::Horizontal) ? QSizePolicy::Maximum : QSizePolicy::Preferred);
sp.setVerticalPolicy((fixType & Qt::Vertical) ? QSizePolicy::Maximum : QSizePolicy::Preferred);
m_simulatorWidget->setSizePolicy(sp);
m_radioSizeConstraint = fixType;
if (ui->actionFixedRadioWidth->isChecked() != (fixType & Qt::Horizontal))
ui->actionFixedRadioWidth->setChecked((fixType & Qt::Horizontal));
if (ui->actionFixedRadioHeight->isChecked() != (fixType & Qt::Vertical))
ui->actionFixedRadioHeight->setChecked((fixType & Qt::Vertical));
}
void SimulatorMainWindow::showRadioDocked(bool dock)
{
if (m_showRadioDocked != dock)
toggleRadioDocked(dock);
}
void SimulatorMainWindow::toggleRadioDocked(bool dock)
{
if (!m_simulatorWidget)
return;
if (dock) {
if (m_simulatorDockWidget) {
m_simulatorDockWidget->setWidget(0);
m_simulatorDockWidget->deleteLater();
m_simulatorDockWidget = NULL;
}
QWidget * w = takeCentralWidget();
if (w && w != m_simulatorWidget)
w->deleteLater();
setCentralWidget(m_simulatorWidget);
setRadioSizePolicy(m_radioSizeConstraint);
ui->actionFixedRadioWidth->setEnabled(true);
ui->actionFixedRadioHeight->setEnabled(true);
m_simulatorWidget->show();
}
else {
if (m_simulatorDockWidget) {
m_simulatorDockWidget->deleteLater();
m_simulatorDockWidget = NULL;
}
takeCentralWidget();
QLabel * dummy = new QLabel("");
dummy->setFixedSize(0, 0);
dummy->setEnabled(false);
setCentralWidget(dummy);
m_simulatorDockWidget = new QDockWidget(m_simulatorWidget->windowTitle(), this);
m_simulatorDockWidget->setObjectName("RADIO_SIMULATOR");
m_simulatorDockWidget->setWidget(m_simulatorWidget);
m_simulatorDockWidget->setFeatures(QDockWidget::DockWidgetFloatable);
m_simulatorDockWidget->setAllowedAreas(Qt::BottomDockWidgetArea);
addDockWidget(Qt::BottomDockWidgetArea, m_simulatorDockWidget);
m_simulatorDockWidget->setFloating(true);
m_simulatorWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
ui->actionFixedRadioWidth->setDisabled(true);
ui->actionFixedRadioHeight->setDisabled(true);
restoreDockWidget(m_simulatorDockWidget);
if (!m_simulatorDockWidget->isVisible())
m_simulatorDockWidget->show();
if (m_simulatorDockWidget->geometry().topLeft() == QPoint(0,0) && this->isVisible()) {
// default position top left corner in middle of this parent window.
QPoint newPos(pos() + (geometry().bottomRight() - geometry().topLeft()) / 2);
m_simulatorDockWidget->move(newPos);
}
connect(m_simulatorDockWidget, &QDockWidget::topLevelChanged, [this](bool top) {
showRadioDocked(!top);
});
}
m_showRadioDocked = dock;
if (ui->actionDockRadio->isChecked() != dock)
ui->actionDockRadio->setChecked(dock);
}
void SimulatorMainWindow::luaReload(bool)
{
// force a reload of the lua environment
+11 -3
View File
@@ -57,15 +57,22 @@ class SimulatorMainWindow : public QMainWindow
QMenu * createPopupMenu();
public slots:
virtual void show();
void start();
void showRadioTitlebar(bool show);
void toggleMenuBar(bool show);
void showMenuBar(bool show);
void showRadioFixedSize(Qt::Orientation orientation, bool fixed);
void showRadioFixedWidth(bool fixed);
void showRadioFixedHeight(bool fixed);
void showRadioDocked(bool dock);
protected slots:
virtual void closeEvent(QCloseEvent *);
virtual void changeEvent(QEvent *e);
void restoreUiState();
void saveUiState();
void toggleMenuBar(bool show);
void setRadioSizePolicy(int fixType);
void toggleRadioDocked(bool dock);
void luaReload(bool);
void openJoystickDialog(bool);
void showHelp(bool show);
@@ -89,8 +96,9 @@ class SimulatorMainWindow : public QMainWindow
QVector<keymapHelp_t> m_keymapHelp;
int m_radioProfileId;
int m_radioSizeConstraint;
bool m_firstShow;
bool m_showRadioTitlebar;
bool m_showRadioDocked;
bool m_showMenubar;
const static quint16 m_savedUiStateVersion;
+52 -11
View File
@@ -14,7 +14,7 @@
<string>OpenTx Simulator</string>
</property>
<property name="windowIcon">
<iconset>
<iconset resource="../companion.qrc">
<normaloff>:/icon.png</normaloff>:/icon.png</iconset>
</property>
<property name="dockNestingEnabled">
@@ -23,7 +23,14 @@
<property name="dockOptions">
<set>QMainWindow::AllowNestedDocks|QMainWindow::AllowTabbedDocks|QMainWindow::AnimatedDocks</set>
</property>
<widget class="QWidget" name="centralwidget"/>
<widget class="QWidget" name="centralwidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Ignored">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
@@ -40,6 +47,16 @@
<property name="title">
<string>View</string>
</property>
<widget class="QMenu" name="menuRadio_Window">
<property name="title">
<string>Radio Window</string>
</property>
<addaction name="actionFixedRadioWidth"/>
<addaction name="actionFixedRadioHeight"/>
<addaction name="actionDockRadio"/>
</widget>
<addaction name="actionToggleMenuBar"/>
<addaction name="menuRadio_Window"/>
</widget>
<widget class="QMenu" name="menuReload">
<property name="title">
@@ -79,7 +96,7 @@
</widget>
<action name="actionReloadLua">
<property name="icon">
<iconset>
<iconset resource="../companion.qrc">
<normaloff>:/images/simulator/icons/svg/reload_script.svg</normaloff>:/images/simulator/icons/svg/reload_script.svg</iconset>
</property>
<property name="text">
@@ -94,7 +111,7 @@
</action>
<action name="actionReloadRadioData">
<property name="icon">
<iconset>
<iconset resource="../companion.qrc">
<normaloff>:/images/simulator/icons/svg/restart.svg</normaloff>:/images/simulator/icons/svg/restart.svg</iconset>
</property>
<property name="text">
@@ -109,7 +126,7 @@
</action>
<action name="actionShowKeymap">
<property name="icon">
<iconset>
<iconset resource="../companion.qrc">
<normaloff>:/images/simulator/icons/svg/info.svg</normaloff>:/images/simulator/icons/svg/info.svg</iconset>
</property>
<property name="text">
@@ -124,7 +141,7 @@
</action>
<action name="actionJoystickSettings">
<property name="icon">
<iconset>
<iconset resource="../companion.qrc">
<normaloff>:/images/simulator/icons/svg/joystick_settings.svg</normaloff>:/images/simulator/icons/svg/joystick_settings.svg</iconset>
</property>
<property name="text">
@@ -139,7 +156,7 @@
</action>
<action name="actionScreenshot">
<property name="icon">
<iconset>
<iconset resource="../companion.qrc">
<normaloff>:/images/simulator/icons/svg/camera.svg</normaloff>:/images/simulator/icons/svg/camera.svg</iconset>
</property>
<property name="text">
@@ -152,15 +169,15 @@
<string>F8</string>
</property>
</action>
<action name="actionToggleRadioTitle">
<action name="actionDockRadio">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Radio Titlebar</string>
<string>Dock In Main Window</string>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The title bar on the main radio window allows you to undock it or move it around separately from the other windows. Hiding the title makes a more compact and streamlined appearance.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>Show the radio in the main window or as a separate &quot;floating&quot; window.</string>
</property>
</action>
<action name="actionToggleMenuBar">
@@ -177,7 +194,31 @@
<string>Alt+M</string>
</property>
</action>
<action name="actionFixedRadioWidth">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Constrain Width</string>
</property>
<property name="toolTip">
<string>Set radio widget width to be a fixed size.</string>
</property>
</action>
<action name="actionFixedRadioHeight">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Constrain Height</string>
</property>
<property name="toolTip">
<string>Set radio widget height to be a fixed size.</string>
</property>
</action>
</widget>
<resources/>
<resources>
<include location="../companion.qrc"/>
</resources>
<connections/>
</ui>