From 426ac96f3e87c7eeb0914bfa021ca6c79928f44d Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Thu, 28 Dec 2017 18:27:58 +0100 Subject: [PATCH] Ref T172, combo box for ecosystems --- src/blackgui/ecosystemcombobox.cpp | 56 ++++++++++++++++++++++++++++++ src/blackgui/ecosystemcombobox.h | 49 ++++++++++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 src/blackgui/ecosystemcombobox.cpp create mode 100644 src/blackgui/ecosystemcombobox.h diff --git a/src/blackgui/ecosystemcombobox.cpp b/src/blackgui/ecosystemcombobox.cpp new file mode 100644 index 000000000..a7ac586c2 --- /dev/null +++ b/src/blackgui/ecosystemcombobox.cpp @@ -0,0 +1,56 @@ +/* Copyright (C) 2017 + * 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 "ecosystemcombobox.h" +#include "blackmisc/network/ecosystemlist.h" + +using namespace BlackMisc::Network; + +namespace BlackGui +{ + CEcosystemComboBox::CEcosystemComboBox(QWidget *parent) : QComboBox(parent) + { + this->initAllItems(); + } + + CEcosystemComboBox::CEcosystemComboBox(const CEcosystemList &systems, QWidget *parent) : + QComboBox(parent), m_systems(systems) + { + this->initAllItems(); + } + + CEcosystem CEcosystemComboBox::getSelectedEcosystem() const + { + if (this->currentIndex() < 0 || this->currentIndex() >= m_systems.size()) { return CEcosystem(); } + return m_systems[this->currentIndex()]; + } + + void CEcosystemComboBox::setCurrentEcosystem(const CEcosystem &ecosystem) + { + if (m_systems.contains(ecosystem)) + { + this->setCurrentText(ecosystem.getSystemString()); + } + } + + void CEcosystemComboBox::setEcosystems(const CEcosystemList &systems) + { + m_systems = systems; + this->initAllItems(); + } + + void CEcosystemComboBox::initAllItems() + { + this->clear(); + for (const CEcosystem &e : m_systems) + { + this->addItem(e.toIcon().toPixmap(), e.getSystemString()); + } + } +} // ns diff --git a/src/blackgui/ecosystemcombobox.h b/src/blackgui/ecosystemcombobox.h new file mode 100644 index 000000000..54354eb7d --- /dev/null +++ b/src/blackgui/ecosystemcombobox.h @@ -0,0 +1,49 @@ +/* Copyright (C) 2017 + * 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_ECOSYSTEMCOMBOBOX_H +#define BLACKGUI_ECOSYSTEMCOMBOBOX_H + +#include "blackmisc/network/ecosystemlist.h" +#include + +namespace BlackGui +{ + //! Combo box widget for ecosystems + class CEcosystemComboBox : public QComboBox + { + public: + //! Constructor + CEcosystemComboBox(QWidget *parent = nullptr); + + //! Constructor + CEcosystemComboBox(const BlackMisc::Network::CEcosystemList &systems, QWidget *parent = nullptr); + + //! Destructor + virtual ~CEcosystemComboBox() {} + + //! The selected ecosystem + BlackMisc::Network::CEcosystem getSelectedEcosystem() const; + + //! Set current system + void setCurrentEcosystem(const BlackMisc::Network::CEcosystem &ecosystem); + + //! Set the supported systems + void setEcosystems(const BlackMisc::Network::CEcosystemList &systems); + + private: + //! Init all items + void initAllItems(); + + BlackMisc::Network::CEcosystemList m_systems { BlackMisc::Network::CEcosystemList::allKnownSystems() }; + }; +} // ns +#endif // guard