From 57ede8b04cbf99cc10f3853d85d0aa733de5b869 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 7 Mar 2017 04:54:40 +0100 Subject: [PATCH] refs #901, utility class for single UI widgets (disables widget when >1 swift application runs) --- src/blackgui/singleapplicationui.cpp | 33 ++++++++++++++++++++++ src/blackgui/singleapplicationui.h | 42 ++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 src/blackgui/singleapplicationui.cpp create mode 100644 src/blackgui/singleapplicationui.h diff --git a/src/blackgui/singleapplicationui.cpp b/src/blackgui/singleapplicationui.cpp new file mode 100644 index 000000000..e91ec65f2 --- /dev/null +++ b/src/blackgui/singleapplicationui.cpp @@ -0,0 +1,33 @@ +/* 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 "singleapplicationui.h" +#include "guiapplication.h" +#include + +using namespace BlackMisc; + +namespace BlackGui +{ + CSingleApplicationUi::CSingleApplicationUi(QWidget *ui) : m_ui(ui) + { + QObject::connect(&m_timer, &QTimer::timeout, [ = ] { this->evaluate(); }); + m_timer.setInterval(5000); + m_timer.start(); + } + + void CSingleApplicationUi::evaluate() + { + if (!sGui) { return; } + if (!m_ui) { return; } + const CApplicationInfoList apps = sGui->getRunningApplications(); + const bool enable = apps.size() < 2; + m_ui->setEnabled(enable); + } +} // ns diff --git a/src/blackgui/singleapplicationui.h b/src/blackgui/singleapplicationui.h new file mode 100644 index 000000000..a8363de22 --- /dev/null +++ b/src/blackgui/singleapplicationui.h @@ -0,0 +1,42 @@ +/* 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_SINGLEAPPLICATIONUI_H +#define BLACKGUI_SINGLEAPPLICATIONUI_H + +#include + +class QWidget; + +namespace BlackGui +{ + /** + * Enable / disable UI depending on how many swift applications are running + */ + class CSingleApplicationUi + { + public: + //! Constructor + CSingleApplicationUi(QWidget *ui); + + //! Set UI widget + void setWidget(QWidget *ui) { m_ui = ui; } + + private: + //! Evaluate if + void evaluate(); + + QTimer m_timer; + QWidget *m_ui = nullptr; //!< enabled/disabled UI + }; +} // ns + +#endif // guard