diff --git a/src/blackgui/components/interpolationlogdisplay.cpp b/src/blackgui/components/interpolationlogdisplay.cpp new file mode 100644 index 000000000..27fa31505 --- /dev/null +++ b/src/blackgui/components/interpolationlogdisplay.cpp @@ -0,0 +1,133 @@ +/* Copyright (C) 2018 + * 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 "interpolationlogdisplay.h" +#include "ui_interpolationlogdisplay.h" +#include "blackmisc/simulation/interpolationlogger.h" + +using namespace BlackCore; +using namespace BlackMisc::Aviation; +using namespace BlackMisc::Simulation; + +namespace BlackGui +{ + namespace Components + { + CInterpolationLogDisplay::CInterpolationLogDisplay(QWidget *parent) : + QFrame(parent), + ui(new Ui::CInterpolationLogDisplay) + { + ui->setupUi(this); + constexpr int timeSecs = 5; + ui->hs_UpdateTime->setValue(timeSecs); + this->onSliderChanged(timeSecs); + connect(&m_updateTimer, &QTimer::timeout, this, &CInterpolationLogDisplay::updateLog); + connect(ui->hs_UpdateTime, &QSlider::valueChanged, this, &CInterpolationLogDisplay::onSliderChanged); + connect(ui->pb_StartStop, &QPushButton::released, this, &CInterpolationLogDisplay::toggleStartStop); + connect(ui->comp_CallsignCompleter, &CCallsignCompleter::validCallsignEntered, this, &CInterpolationLogDisplay::onCallsignEntered); + + m_callsign = ui->comp_CallsignCompleter->getCallsign(); + } + + CInterpolationLogDisplay::~CInterpolationLogDisplay() + { } + + void CInterpolationLogDisplay::setSimulator(CSimulatorCommon *simulatorCommon) + { + m_simulatorCommon = simulatorCommon; + } + + void CInterpolationLogDisplay::updateLog() + { + const bool hasLogger = m_simulatorCommon; + if (hasLogger && !m_callsign.isEmpty()) + { + const QString log = m_simulatorCommon->latestLoggedDataFormatted(m_callsign); + ui->te_Log->setText(log); + } + else + { + ui->te_Log->setText("No logger attached or no callsign"); + this->stop(); + } + } + + void CInterpolationLogDisplay::onSliderChanged(int timeSecs) + { + static const QString time("%1 secs"); + m_updateTimer.setInterval(timeSecs * 1000); + ui->le_UpdateTime->setText(time.arg(timeSecs)); + } + + void CInterpolationLogDisplay::onCallsignEntered() + { + const CCallsign cs = ui->comp_CallsignCompleter->getCallsign(); + if (!m_simulatorCommon) + { + this->stop(); + return; + } + + // clear last callsign + if (!m_callsign.isEmpty()) + { + m_simulatorCommon->setLogInterpolation(false, m_callsign); // stop logging "old" callsign + m_callsign = CCallsign(); // clear callsign + } + + // set new callsign or stop + if (cs.isEmpty()) + { + this->stop(); + return; + } + + m_callsign = cs; + m_simulatorCommon->setLogInterpolation(true, cs); + } + + void CInterpolationLogDisplay::toggleStartStop() + { + const bool running = m_updateTimer.isActive(); + if (running) + { + this->stop(); + } + else + { + this->start(); + } + } + + void CInterpolationLogDisplay::start() + { + const int interval = ui->hs_UpdateTime->value() * 1000; + m_updateTimer.start(interval); + ui->pb_StartStop->setText(stopText()); + } + + void CInterpolationLogDisplay::stop() + { + m_updateTimer.stop(); + ui->pb_StartStop->setText(startText()); + } + + const QString &CInterpolationLogDisplay::startText() + { + static const QString start("start"); + return start; + } + + const QString &CInterpolationLogDisplay::stopText() + { + static const QString stop("stop"); + return stop; + } + } // ns +} // ns diff --git a/src/blackgui/components/interpolationlogdisplay.h b/src/blackgui/components/interpolationlogdisplay.h new file mode 100644 index 000000000..11aa700d1 --- /dev/null +++ b/src/blackgui/components/interpolationlogdisplay.h @@ -0,0 +1,75 @@ +/* Copyright (C) 2018 + * 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_INTERPOLATIONLOGDISPLAY_H +#define BLACKGUI_COMPONENTS_INTERPOLATIONLOGDISPLAY_H + +#include "blackgui/blackguiexport.h" +#include "blackcore/simulatorcommon.h" +#include "blackmisc/aviation/callsign.h" +#include +#include +#include +#include + +namespace Ui { class CInterpolationLogDisplay; } +namespace BlackGui +{ + namespace Components + { + /** + * Display live data of interpolation + */ + class BLACKGUI_EXPORT CInterpolationLogDisplay : public QFrame + { + Q_OBJECT + + public: + //! Constructor + explicit CInterpolationLogDisplay(QWidget *parent = nullptr); + + //! Destructor + virtual ~CInterpolationLogDisplay(); + + //! Set simulator + void setSimulator(BlackCore::CSimulatorCommon *simulatorCommon); + + private: + //! Update log. + void updateLog(); + + //! Slider interval + void onSliderChanged(int timeSecs); + + //! Callsign has been changed + void onCallsignEntered(); + + //! Toggle start/stop + void toggleStartStop(); + + //! Start displaying + void start(); + + //! Stop displaying + void stop(); + + QScopedPointer ui; + QTimer m_updateTimer; + QPointer m_simulatorCommon = nullptr; //!< related simulator + BlackMisc::Aviation::CCallsign m_callsign; //!< current callsign + + static const QString &startText(); + static const QString &stopText(); + }; + } // ns +} // ns + +#endif // guard diff --git a/src/blackgui/components/interpolationlogdisplay.ui b/src/blackgui/components/interpolationlogdisplay.ui new file mode 100644 index 000000000..0fbf8e5b4 --- /dev/null +++ b/src/blackgui/components/interpolationlogdisplay.ui @@ -0,0 +1,78 @@ + + + CInterpolationLogDisplay + + + + 0 + 0 + 640 + 480 + + + + Interpolation log. display + + + + + + + + + + + + 1 + + + 10 + + + Qt::Horizontal + + + QSlider::TicksBelow + + + 1 + + + + + + + true + + + + + + + Start + + + + + + + + + + true + + + + + + + + BlackGui::Components::CCallsignCompleter + QFrame +
blackgui/components/callsigncompleter.h
+ 1 +
+
+ + +
diff --git a/src/blackgui/components/interpolationlogdisplaydialog.cpp b/src/blackgui/components/interpolationlogdisplaydialog.cpp new file mode 100644 index 000000000..4d7ebf071 --- /dev/null +++ b/src/blackgui/components/interpolationlogdisplaydialog.cpp @@ -0,0 +1,37 @@ +/* Copyright (C) 2018 + * 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 "interpolationlogdisplaydialog.h" +#include "ui_interpolationlogdisplaydialog.h" +#include "blackcore/simulatorcommon.h" + +using namespace BlackCore; + +namespace BlackGui +{ + namespace Components + { + CInterpolationLogDisplayDialog::CInterpolationLogDisplayDialog(CSimulatorCommon *simulatorCommon, QWidget *parent) : + QDialog(parent), + ui(new Ui::CInterpolationLogDisplayDialog) + { + ui->setupUi(this); + this->setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint); + this->setSimulator(simulatorCommon); + } + + CInterpolationLogDisplayDialog::~CInterpolationLogDisplayDialog() + { } + + void CInterpolationLogDisplayDialog::setSimulator(CSimulatorCommon *simulatorCommon) + { + ui->comp_InterpolationLogDisplay->setSimulator(simulatorCommon); + } + } // ns +} // ns diff --git a/src/blackgui/components/interpolationlogdisplaydialog.h b/src/blackgui/components/interpolationlogdisplaydialog.h new file mode 100644 index 000000000..06e0b466d --- /dev/null +++ b/src/blackgui/components/interpolationlogdisplaydialog.h @@ -0,0 +1,48 @@ +/* Copyright (C) 2018 + * 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_INTERPOLATIONLOGDISPLAYDIALOG_H +#define BLACKGUI_COMPONENTS_INTERPOLATIONLOGDISPLAYDIALOG_H + +#include "blackgui/blackguiexport.h" +#include +#include + +namespace Ui { class CInterpolationLogDisplayDialog; } +namespace BlackCore { class CSimulatorCommon; } +namespace BlackGui +{ + namespace Components + { + /** + * CInterpolationLogDisplay as dialog + */ + class BLACKGUI_EXPORT CInterpolationLogDisplayDialog : public QDialog + { + Q_OBJECT + + public: + //! Constructor + explicit CInterpolationLogDisplayDialog(BlackCore::CSimulatorCommon *simulatorCommon, QWidget *parent = nullptr); + + //! Destructor + virtual ~CInterpolationLogDisplayDialog(); + + //! Set simulator + void setSimulator(BlackCore::CSimulatorCommon *simulatorCommon); + + private: + QScopedPointer ui; + }; + } // ns +} // ns + +#endif // guard diff --git a/src/blackgui/components/interpolationlogdisplaydialog.ui b/src/blackgui/components/interpolationlogdisplaydialog.ui new file mode 100644 index 000000000..a1b42ab68 --- /dev/null +++ b/src/blackgui/components/interpolationlogdisplaydialog.ui @@ -0,0 +1,82 @@ + + + CInterpolationLogDisplayDialog + + + + 0 + 0 + 640 + 480 + + + + Interpolation log. display + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Close + + + + + + + + BlackGui::Components::CInterpolationLogDisplay + QFrame +
blackgui/components/interpolationlogdisplay.h
+ 1 +
+
+ + + + bb_InterpolationLogDisplay + accepted() + CInterpolationLogDisplayDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + bb_InterpolationLogDisplay + rejected() + CInterpolationLogDisplayDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + +