From 6119c22c78def9084e700e14cb7c042831146526 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Fri, 8 May 2015 20:34:10 +0200 Subject: [PATCH] some fixes noticed during today's discussion around refs #302 * move hotkey settings in own GUI component -> easier adjustments * some fixes for dock widgets when tab widget is shown without names (unrelated but found + fixed in same step) --- src/blackgui/components/settingscomponent.cpp | 34 +---- src/blackgui/components/settingscomponent.h | 8 +- src/blackgui/components/settingscomponent.ui | 82 ++++------- .../components/settingshotkeycomponent.cpp | 73 +++++++++ .../components/settingshotkeycomponent.h | 65 ++++++++ .../components/settingshotkeycomponent.ui | 104 +++++++++++++ .../settingsnetworkserverscomponent.cpp | 2 +- .../settingsnetworkserverscomponent.ui | 12 +- src/blackgui/dockwidget.cpp | 7 + src/blackgui/dockwidget.h | 3 + src/blackgui/infoarea.cpp | 41 ++++-- src/blackgui/serverform.ui | 139 ++++++++++-------- 12 files changed, 391 insertions(+), 179 deletions(-) create mode 100644 src/blackgui/components/settingshotkeycomponent.cpp create mode 100644 src/blackgui/components/settingshotkeycomponent.h create mode 100644 src/blackgui/components/settingshotkeycomponent.ui diff --git a/src/blackgui/components/settingscomponent.cpp b/src/blackgui/components/settingscomponent.cpp index d2e34cd4b..a46dabdd6 100644 --- a/src/blackgui/components/settingscomponent.cpp +++ b/src/blackgui/components/settingscomponent.cpp @@ -77,11 +77,10 @@ namespace BlackGui void CSettingsComponent::reloadSettings() { // reload components + //! \todo Settings are loaded twice, this here is for init but each component also consumes the signal changed slot this->ui->comp_AudioSetup->reloadSettings(); this->ui->comp_SettingsServersComponent->reloadSettings(); - - // update hot keys - this->ui->tvp_SettingsMiscHotkeys->updateContainer(this->getIContextSettings()->getHotkeys()); + this->ui->comp_SettingsHotkeysComponent->reloadSettings(); } /* @@ -97,7 +96,7 @@ namespace BlackGui */ void CSettingsComponent::runtimeHasBeenSet() { - Q_ASSERT_X(this->getIContextSettings(), "runtimeHasBeenSet", "Missing settings"); + Q_ASSERT_X(this->getIContextSettings(), Q_FUNC_INFO, "Missing settings"); this->connect(this->getIContextSettings(), &IContextSettings::changedSettings, this, &CSettingsComponent::ps_changedSettings); // Opacity, intervals @@ -106,11 +105,6 @@ namespace BlackGui this->connect(this->ui->hs_SettingsGuiAtcRefreshTime, &QSlider::valueChanged, this, &CSettingsComponent::changedAtcStationsUpdateInterval); this->connect(this->ui->hs_SettingsGuiUserRefreshTime, &QSlider::valueChanged, this, &CSettingsComponent::changedUsersUpdateInterval); - // Settings hotkeys - this->connect(this->ui->pb_SettingsMiscCancel, &QPushButton::clicked, this, &CSettingsComponent::reloadSettings); - this->connect(this->ui->pb_SettingsMiscSave, &QPushButton::clicked, this, &CSettingsComponent::ps_saveHotkeys); - this->connect(this->ui->pb_SettingsMiscRemove, &QPushButton::clicked, this, &CSettingsComponent::ps_clearHotkey); - // Font const QFont font = this->font(); this->ui->cb_SettingsGuiFontStyle->setCurrentText(CStyleSheetUtility::fontAsCombinedWeightStyle(font)); @@ -138,28 +132,6 @@ namespace BlackGui Q_UNUSED(type); } - /* - * Save the hotkeys - */ - void CSettingsComponent::ps_saveHotkeys() - { - const QString path = CSettingUtilities::appendPaths(IContextSettings::PathRoot(), IContextSettings::PathHotkeys()); - this->getIContextSettings()->value(path, CSettingUtilities::CmdUpdate(), this->ui->tvp_SettingsMiscHotkeys->derivedModel()->getContainer().toCVariant()); - } - - /* - * Clear particular hotkey - */ - void CSettingsComponent::ps_clearHotkey() - { - QModelIndex i = this->ui->tvp_SettingsMiscHotkeys->currentIndex(); - if (i.row() < 0 || i.row() >= this->ui->tvp_SettingsMiscHotkeys->rowCount()) return; - CSettingKeyboardHotkey hotkey = this->ui->tvp_SettingsMiscHotkeys->at(i); - CSettingKeyboardHotkey defaultHotkey; - defaultHotkey.setFunction(hotkey.getFunction()); - this->ui->tvp_SettingsMiscHotkeys->derivedModel()->update(i, defaultHotkey); - } - /* * Font has been changed */ diff --git a/src/blackgui/components/settingscomponent.h b/src/blackgui/components/settingscomponent.h index f2dc986d0..34e6e8f2c 100644 --- a/src/blackgui/components/settingscomponent.h +++ b/src/blackgui/components/settingscomponent.h @@ -45,7 +45,7 @@ namespace BlackGui SettingTabAircraftAudio, SettingTabSimulator, SettingTabGui, - SettingTabMisc + SettingTabHotkeys }; //! Constructor @@ -98,12 +98,6 @@ namespace BlackGui //! Settings have been changed void ps_changedSettings(uint typeValue); - //! Save the Hotkeys - void ps_saveHotkeys(); - - //! Clear single hotkey - void ps_clearHotkey(); - //! Font has been changed void ps_fontChanged(); diff --git a/src/blackgui/components/settingscomponent.ui b/src/blackgui/components/settingscomponent.ui index 166574cb9..bcfce6880 100644 --- a/src/blackgui/components/settingscomponent.ui +++ b/src/blackgui/components/settingscomponent.ui @@ -480,79 +480,46 @@ - + + + + 0 + 0 + + - Misc + Hotkeys - 3 + 2 - 2 + 1 - 2 + 1 - 2 + 1 - 2 + 1 - - - true + + + + 0 + 0 + - - false - - - - - QFrame::StyledPanel QFrame::Raised - - - - - Save - - - - - - - - 0 - 0 - - - - Remove - - - - - - - - 0 - 0 - - - - Cancel - - - - @@ -565,11 +532,6 @@
blackgui/components/audiosetupcomponent.h
1 - - BlackGui::Views::CKeyboardKeyView - QTableView -
blackgui/views/keyboardkeyview.h
-
BlackGui::Components::CSettingsSimulatorComponent QFrame @@ -588,6 +550,12 @@
blackgui/components/settingsnetworkcomponent.h
1
+ + BlackGui::Components::CSettingsHotkeyComponent + QFrame +
blackgui/components/settingshotkeycomponent.h
+ 1 +
diff --git a/src/blackgui/components/settingshotkeycomponent.cpp b/src/blackgui/components/settingshotkeycomponent.cpp new file mode 100644 index 000000000..dea10d53b --- /dev/null +++ b/src/blackgui/components/settingshotkeycomponent.cpp @@ -0,0 +1,73 @@ +/* Copyright (C) 2015 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "settingshotkeycomponent.h" +#include "ui_settingshotkeycomponent.h" +#include "blackcore/context_settings.h" +#include "blackmisc/settingutilities.h" + +using namespace BlackCore; +using namespace BlackMisc::Settings; + +namespace BlackGui +{ + namespace Components + { + + CSettingsHotkeyComponent::CSettingsHotkeyComponent(QWidget *parent) : + QFrame(parent), + ui(new Ui::CSettingsHotkeyComponent) + { + ui->setupUi(this); + } + + CSettingsHotkeyComponent::~CSettingsHotkeyComponent() { } + + void CSettingsHotkeyComponent::runtimeHasBeenSet() + { + Q_ASSERT_X(this->getIContextSettings(), Q_FUNC_INFO, "Missing settings"); + this->connect(this->getIContextSettings(), &IContextSettings::changedSettings, this, &CSettingsHotkeyComponent::ps_changedSettings); + + // Settings hotkeys + this->connect(this->ui->pb_SettingsCancel, &QPushButton::clicked, this, &CSettingsHotkeyComponent::reloadSettings); + this->connect(this->ui->pb_SettingsSave, &QPushButton::clicked, this, &CSettingsHotkeyComponent::ps_saveHotkeys); + this->connect(this->ui->pb_SettingsRemove, &QPushButton::clicked, this, &CSettingsHotkeyComponent::ps_clearHotkey); + } + + void CSettingsHotkeyComponent::reloadSettings() + { + // update hot keys + this->ui->tvp_SettingsMiscHotkeys->updateContainer(this->getIContextSettings()->getHotkeys()); + } + + void CSettingsHotkeyComponent::ps_changedSettings(uint typeValue) + { + IContextSettings::SettingsType type = static_cast(typeValue); + this->reloadSettings(); + Q_UNUSED(type); + } + + void CSettingsHotkeyComponent::ps_saveHotkeys() + { + const QString path = CSettingUtilities::appendPaths(IContextSettings::PathRoot(), IContextSettings::PathHotkeys()); + this->getIContextSettings()->value(path, CSettingUtilities::CmdUpdate(), this->ui->tvp_SettingsMiscHotkeys->derivedModel()->getContainer().toCVariant()); + } + + void CSettingsHotkeyComponent::ps_clearHotkey() + { + QModelIndex i = this->ui->tvp_SettingsMiscHotkeys->currentIndex(); + if (i.row() < 0 || i.row() >= this->ui->tvp_SettingsMiscHotkeys->rowCount()) return; + CSettingKeyboardHotkey hotkey = this->ui->tvp_SettingsMiscHotkeys->at(i); + CSettingKeyboardHotkey defaultHotkey; + defaultHotkey.setFunction(hotkey.getFunction()); + this->ui->tvp_SettingsMiscHotkeys->derivedModel()->update(i, defaultHotkey); + } + + } // ns +} // ns diff --git a/src/blackgui/components/settingshotkeycomponent.h b/src/blackgui/components/settingshotkeycomponent.h new file mode 100644 index 000000000..343be69ae --- /dev/null +++ b/src/blackgui/components/settingshotkeycomponent.h @@ -0,0 +1,65 @@ +/* Copyright (C) 2015 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKGUI_COMPONENTS_SETTINGSHOTKEYCOMPONENT_H +#define BLACKGUI_COMPONENTS_SETTINGSHOTKEYCOMPONENT_H + +#include "blackgui/blackguiexport.h" +#include "blackgui/components/enableforruntime.h" +#include + +namespace Ui { class CSettingsHotkeyComponent; } + +namespace BlackGui +{ + namespace Components + { + + //! Define hotkeys + class BLACKGUI_EXPORT CSettingsHotkeyComponent : + public QFrame, + public CEnableForRuntime + { + Q_OBJECT + + public: + //! Constructor + explicit CSettingsHotkeyComponent(QWidget *parent = nullptr); + + //! Destructor + ~CSettingsHotkeyComponent(); + + //! Reload settings + void reloadSettings(); + + protected: + //! \copydoc CRuntimeBasedComponent::runtimeHasBeenSet + virtual void runtimeHasBeenSet() override; + + private slots: + + //! Settings have been changed + void ps_changedSettings(uint typeValue); + + //! Save the Hotkeys + void ps_saveHotkeys(); + + //! Clear single hotkey + void ps_clearHotkey(); + + private: + QScopedPointer ui; + }; + + } // ns +} // ns + +#endif // guard diff --git a/src/blackgui/components/settingshotkeycomponent.ui b/src/blackgui/components/settingshotkeycomponent.ui new file mode 100644 index 000000000..9c018d967 --- /dev/null +++ b/src/blackgui/components/settingshotkeycomponent.ui @@ -0,0 +1,104 @@ + + + CSettingsHotkeyComponent + + + + 0 + 0 + 400 + 300 + + + + Frame + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 3 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + true + + + false + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + Save + + + + + + + + 0 + 0 + + + + Remove + + + + + + + + 0 + 0 + + + + Cancel + + + + + + + + + + + BlackGui::Views::CKeyboardKeyView + QTableView +
blackgui/views/keyboardkeyview.h
+
+
+ + +
diff --git a/src/blackgui/components/settingsnetworkserverscomponent.cpp b/src/blackgui/components/settingsnetworkserverscomponent.cpp index 482fdc47c..14455418d 100644 --- a/src/blackgui/components/settingsnetworkserverscomponent.cpp +++ b/src/blackgui/components/settingsnetworkserverscomponent.cpp @@ -44,7 +44,7 @@ namespace BlackGui void CSettingsNetworkServersComponent::runtimeHasBeenSet() { - Q_ASSERT_X(this->getIContextSettings(), "runtimeHasBeenSet", "Missing settings"); + Q_ASSERT_X(this->getIContextSettings(), Q_FUNC_INFO, "Missing settings"); this->connect(this->getIContextSettings(), &IContextSettings::changedSettings, this, &CSettingsNetworkServersComponent::ps_changedSettings); } diff --git a/src/blackgui/components/settingsnetworkserverscomponent.ui b/src/blackgui/components/settingsnetworkserverscomponent.ui index 653526230..c91f97f48 100644 --- a/src/blackgui/components/settingsnetworkserverscomponent.ui +++ b/src/blackgui/components/settingsnetworkserverscomponent.ui @@ -6,8 +6,8 @@ 0 0 - 400 - 300 + 260 + 141 @@ -38,7 +38,7 @@ - + 0 0 @@ -82,7 +82,7 @@ - + 0 0 @@ -95,10 +95,10 @@ - 3 + 2 - 3 + 2 diff --git a/src/blackgui/dockwidget.cpp b/src/blackgui/dockwidget.cpp index 5bf48cf20..6e97f0efb 100644 --- a/src/blackgui/dockwidget.cpp +++ b/src/blackgui/dockwidget.cpp @@ -326,6 +326,13 @@ namespace BlackGui return ok; } + QString CDockWidget::windowTitleOrBackup() const + { + QString t(windowTitle()); + if (t.isEmpty()) { return windowTitleBackup(); } + return t; + } + void CDockWidget::ps_onTopLevelChanged(bool topLevel) { if (topLevel) diff --git a/src/blackgui/dockwidget.h b/src/blackgui/dockwidget.h index 56319fa7f..64e9d4307 100644 --- a/src/blackgui/dockwidget.h +++ b/src/blackgui/dockwidget.h @@ -73,6 +73,9 @@ namespace BlackGui //! Window title backup const QString &windowTitleBackup() const { return this->m_windowTitleBackup; } + //! If current window title is empty, use backup + QString windowTitleOrBackup() const; + //! Window title when window is docked bool showTitleWhenDocked() const { return this->m_windowTitleWhenDocked; } diff --git a/src/blackgui/infoarea.cpp b/src/blackgui/infoarea.cpp index 44a424ece..97c0a1538 100644 --- a/src/blackgui/infoarea.cpp +++ b/src/blackgui/infoarea.cpp @@ -626,47 +626,62 @@ namespace BlackGui { if (tabBarIndex >= this->m_dockWidgetInfoAreas.count() || tabBarIndex < 0) { return nullptr; } if (!this->m_tabBar) { return nullptr; } - return getDockWidgetInfoAreaByWindowTitle(this->m_tabBar->tabText(tabBarIndex)); + const QString t(this->m_tabBar->tabText(tabBarIndex)); + + // we have a title and search by that (best option, as order does not matter) + if (!t.isEmpty()) { return getDockWidgetInfoAreaByWindowTitle(t); } + + // no title, we assume the n-th not floating tab is correct + // this will work if the order in m_dockWidgetInfoAreas matches + int c = 0; + for (CDockWidgetInfoArea *dw : this->m_dockWidgetInfoAreas) + { + if (dw->isFloating()) { continue; } + if (c == tabBarIndex) { return dw; } + c++; + } + Q_ASSERT_X(false, Q_FUNC_INFO, "no dock widgte found"); + return nullptr; } CDockWidgetInfoArea *CInfoArea::getDockWidgetInfoAreaByWindowTitle(const QString &title) const { - Q_ASSERT(!title.isEmpty()); + Q_ASSERT_X(!title.isEmpty(), Q_FUNC_INFO, "No title"); for (CDockWidgetInfoArea *dw : this->m_dockWidgetInfoAreas) { - if (dw->windowTitle() == title) { return dw; } + if (dw->windowTitleOrBackup() == title) { return dw; } } return nullptr; } int CInfoArea::getAreaIndexByWindowTitle(const QString &title) const { - Q_ASSERT(!title.isEmpty()); + Q_ASSERT_X(!title.isEmpty(), Q_FUNC_INFO, "No title"); for (int i = 0; i < m_dockWidgetInfoAreas.size(); i++) { - const QString t(m_dockWidgetInfoAreas.at(i)->windowTitle()); - if (t == title) { return i; } + if (title == m_dockWidgetInfoAreas.at(i)->windowTitleOrBackup()) { return i; } } - Q_ASSERT(false); + Q_ASSERT_X(false, Q_FUNC_INFO, "No area for title"); return -1; } int CInfoArea::getTabBarIndexByTitle(const QString &title) const { - Q_ASSERT(!title.isEmpty()); + Q_ASSERT_X(!title.isEmpty(), Q_FUNC_INFO, "No title"); if (m_tabBar->count() < 1) { return -1;} for (int i = 0; i < m_tabBar->count(); i++) { if (m_tabBar->tabText(i) == title) { return i; } } + Q_ASSERT_X(!title.isEmpty(), Q_FUNC_INFO, "Wrong title"); return -1; } int CInfoArea::dockWidgetInfoAreaToTabBarIndex(const CDockWidgetInfoArea *dockWidgetInfoArea) const { - if (!dockWidgetInfoArea) return -1; - if (dockWidgetInfoArea->isFloating()) return -1; - return getTabBarIndexByTitle(dockWidgetInfoArea->windowTitle()); + if (!dockWidgetInfoArea) { return -1; } + if (dockWidgetInfoArea->isFloating()) { return -1; } + return getTabBarIndexByTitle(dockWidgetInfoArea->windowTitleOrBackup()); } void CInfoArea::selectArea(const CDockWidgetInfoArea *dockWidgetInfoArea) @@ -693,7 +708,7 @@ namespace BlackGui for (int i = 0; i < this->m_tabBar->count(); i++) { const QString t(this->m_tabBar->tabText(i)); - int areaIndex = this->getAreaIndexByWindowTitle(t); + int areaIndex = t.isEmpty() ? i : this->getAreaIndexByWindowTitle(t); const QPixmap p = indexToPixmap(areaIndex); this->m_tabBar->setTabIcon(i, p); } @@ -754,7 +769,7 @@ namespace BlackGui void CInfoArea::ps_showTabTexts(bool show) { - if (show == this->m_showTabTexts) return; + if (show == this->m_showTabTexts) { return; } this->m_showTabTexts = show; for (CDockWidgetInfoArea *dw : this->m_dockWidgetInfoAreas) { diff --git a/src/blackgui/serverform.ui b/src/blackgui/serverform.ui index 31c27a643..189e69446 100644 --- a/src/blackgui/serverform.ui +++ b/src/blackgui/serverform.ui @@ -6,10 +6,16 @@ 0 0 - 206 - 190 + 313 + 164 + + + 0 + 0 + + Frame @@ -36,16 +42,7 @@ 0 - - - QFormLayout::AllNonFixedFieldsGrow - - - 6 - - - 6 - + 6 @@ -58,6 +55,9 @@ 6 + + 6 + @@ -65,10 +65,35 @@ - - + + - + Addr./ port + + + + + + + + 0 + 0 + + + + + 75 + 0 + + + + + 75 + 16777215 + + + + 5 @@ -79,69 +104,38 @@ - - - - - - - Address - - - - - - - - - Port - - - - - - - 5 - - - - Real name - - - - - - - - - - Id: - - - - - - - - - - - Password - + + + + Id: + + + + + + + + + + + + + + @@ -154,6 +148,23 @@ + + + + + + + + + + + + + + + + +