refs #275, own info window component

* added to CVariant for value object
* signal in text message to indicate overlay messages
* info window component (currently not runtme aware, maybe changed in future)
* removed old window, adjusted GUI
This commit is contained in:
Klaus Basan
2014-06-17 17:59:14 +02:00
parent ab77f19544
commit 0547b2847e
13 changed files with 435 additions and 239 deletions

View File

@@ -0,0 +1,137 @@
#include "infowindowcomponent.h"
#include "ui_infowindowcomponent.h"
#include <QTimer>
#include <QDesktopWidget>
using namespace BlackMisc;
using namespace BlackMisc::Network;
namespace BlackGui
{
/*
* Constructor
*/
CInfoWindowComponent::CInfoWindowComponent(QWidget *parent) :
QWizardPage(parent), ui(new Ui::InfoWindow), m_hideTimer(nullptr)
{
ui->setupUi(this);
this->hide();
this->m_hideTimer = new QTimer(this);
this->m_hideTimer->setSingleShot(true);
connect(this->m_hideTimer, &QTimer::timeout, this, &CInfoWindowComponent::hide);
}
/*
* Destructor
*/
CInfoWindowComponent::~CInfoWindowComponent() { }
/*
* Info message for some time
*/
void CInfoWindowComponent::displayStringMessage(const QString &message, int displayTimeMs)
{
if (message.isEmpty())
{
this->hide();
return;
}
// message and display
this->ui->te_StringMessage->setText(message);
this->setCurrentPage(this->ui->pg_StringMessage);
this->showWindow(displayTimeMs);
}
/*
* Info message for some time
*/
void CInfoWindowComponent::displayTextMessage(const CTextMessage &textMessage, int displayTimeMs)
{
if (textMessage.isEmpty())
{
this->hide();
return;
}
// message and display
this->ui->le_TmFrom->setText(textMessage.getSenderCallsign().asString());
this->ui->le_TmTo->setText(textMessage.getRecipientCallsign().asString());
this->ui->le_TmReceived->setText(textMessage.receivedTime());
this->ui->te_TmText->setText(textMessage.getMessage());
this->setCurrentPage(this->ui->pg_TextMessage);
this->showWindow(displayTimeMs);
}
/*
* Display status message
*/
void CInfoWindowComponent::displayStatusMessage(const CStatusMessage &statusMessage, int displayTimeMs)
{
if (statusMessage.isEmpty())
{
this->hide();
return;
}
this->ui->le_SmSeverity->setText(statusMessage.getSeverityAsString());
this->ui->le_SmType->setText(statusMessage.getTypeAsString());
this->ui->te_SmStatusMessage->setText(statusMessage.getMessage());
this->ui->lbl_SmSeverity->setPixmap(statusMessage.toIcon());
this->setCurrentPage(this->ui->pg_StatusMessage);
this->showWindow(displayTimeMs);
}
/*
* Display
*/
void CInfoWindowComponent::display(const BlackMisc::CVariant &variant, int displayTimeMs)
{
if (variant.isNull()) return;
if (variant.canConvert<CTextMessage>())
this->displayTextMessage(variant.value<CTextMessage>(), displayTimeMs);
else if (variant.canConvert<CStatusMessage>())
this->displayStatusMessage(variant.value<CStatusMessage>(), displayTimeMs);
else
this->displayStringMessage(variant.toString(), displayTimeMs);
}
/*
* Init this window
*/
void CInfoWindowComponent::initWindow()
{
// center
const QRect parent = this->parentWidget()->geometry();
const QRect myself = this->rect();
int dx = (parent.width() - myself.width()) / 2;
int dy = (parent.height() - myself.height()) / 2;
dy -= 80; // some offset, in order to display further on top
this->move(dx, dy);
this->show();
}
/*
* Show window
*/
void CInfoWindowComponent::showWindow(int displayTimeMs)
{
this->initWindow();
// hide after some time
this->m_hideTimer->start(displayTimeMs);
}
/*
* Set current widget
*/
void CInfoWindowComponent::setCurrentPage(QWidget *widget)
{
this->ui->sw_DifferentModes->setCurrentWidget(widget);
}
} // namespace

View File

@@ -0,0 +1,66 @@
/* Copyright (C) 2013 VATSIM Community / authors
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef BLACKGUI_INFOWINDOW_H
#define BLACKGUI_INFOWINDOW_H
#include "blackmisc/nwtextmessage.h"
#include "blackmisc/statusmessage.h"
#include "blackmisc/variant.h"
#include <QWizardPage>
#include <QScopedPointer>
namespace Ui { class InfoWindow; }
namespace BlackGui
{
/*!
* Multi purpose info window (pop up window)
*/
class CInfoWindowComponent : public QWizardPage
{
Q_OBJECT
public:
const static int DefaultDisplayTimeMs = 4000; //!< Display n milliseconds
//! Constructor
explicit CInfoWindowComponent(QWidget *parent = nullptr);
//! Destructor
~CInfoWindowComponent();
public slots:
//! Info message, pure string
void displayStringMessage(const QString &message, int displayTimeMs = DefaultDisplayTimeMs);
//! Info message, based on text message
void displayTextMessage(const BlackMisc::Network::CTextMessage &textMessage, int displayTimeMs = DefaultDisplayTimeMs);
//! Info message, based on status message
void displayStatusMessage(const BlackMisc::CStatusMessage &statusMessage, int displayTimeMs = DefaultDisplayTimeMs);
//! Display any of the specialized types
void display(const BlackMisc::CVariant &variant, int displayTimeMs = DefaultDisplayTimeMs);
private:
QScopedPointer<Ui::InfoWindow> ui; //!< user interface
QTimer *m_hideTimer;
//! Init the window
void initWindow();
//! Show window, hide after some time
void showWindow(int displayTimeMs);
//! Current page
void setCurrentPage(QWidget *widget);
};
}
#endif // guard

View File

@@ -0,0 +1,206 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>InfoWindow</class>
<widget class="QWizardPage" name="InfoWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>278</width>
<height>143</height>
</rect>
</property>
<property name="windowTitle">
<string>WizardPage</string>
</property>
<property name="styleSheet">
<string notr="true">QWidget {
font-family: arial-rounded;
font: bold 10px;
color: black; /** font **/
}
QPushButton {
background-color: transparent;
border-style: solid;
border-width: 0px;
border-radius:3px;
border-color: green;
max-height:20px;
}
QTextEdit {
background-color: rgba(255, 255, 0, 240); /* transparent yellow */
border-style: solid;
border-width:1px;
border-radius:6px;
border-color: green;
opacity: 0.5;
}
</string>
</property>
<layout class="QHBoxLayout" name="hl_InfoWindow">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QStackedWidget" name="sw_DifferentModes">
<property name="currentIndex">
<number>2</number>
</property>
<widget class="QWidget" name="pg_StringMessage">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTextEdit" name="te_StringMessage">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="pg_TextMessage">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QGridLayout" name="gl_TextMessage">
<item row="0" column="2">
<widget class="QLabel" name="lbl_TmTo">
<property name="text">
<string>To</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Received</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="le_TmReceived"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lbl_TmFrom">
<property name="text">
<string>From</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLineEdit" name="le_TmTo">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="le_TmFrom">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="1" colspan="3">
<widget class="QTextEdit" name="te_TmText"/>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="pg_StatusMessage">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QGridLayout" name="gl_StatusMessage">
<item row="0" column="0">
<widget class="QLabel" name="lbl_SmSeverity">
<property name="text">
<string>Severity</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lbl_SmType">
<property name="text">
<string>Type</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="le_SmSeverity">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QTextEdit" name="te_SmStatusMessage"/>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="le_SmType"/>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
<item alignment="Qt::AlignTop">
<widget class="QPushButton" name="pb_Close">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="blackgui.qrc">
<normaloff>:/blackgui/icons/close.png</normaloff>:/blackgui/icons/close.png</iconset>
</property>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="blackgui.qrc"/>
</resources>
<connections>
<connection>
<sender>pb_Close</sender>
<signal>clicked()</signal>
<receiver>InfoWindow</receiver>
<slot>hide()</slot>
<hints>
<hint type="sourcelabel">
<x>272</x>
<y>52</y>
</hint>
<hint type="destinationlabel">
<x>302</x>
<y>67</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -81,7 +81,7 @@ namespace BlackGui
}
else
{
emit this->displayOverlayInfo(CStatusMessage::getInfoMessage("SELCAL received", CStatusMessage::TypeGui));
emit this->displayInInfoWindow(CStatusMessage::getInfoMessage("SELCAL received", CStatusMessage::TypeGui).toCVariant(), 3 * 1000);
}
}
continue; // not displayed
@@ -127,7 +127,7 @@ namespace BlackGui
{
// if the channel is selected, do nothing
if (!this->isCorrespondingTextMessageTabSelected(message))
emit this->displayOverlayInfo(message.asStatusMessage(true, true, "\t"));
emit this->displayInInfoWindow(message.toCVariant(), 5 * 1000);
}
}
}

View File

@@ -38,8 +38,8 @@ namespace BlackGui
void setSelcalCallback(const std::function<const QString(void)> &selcalCallback) { this->m_selcalCallback = selcalCallback; }
signals:
//! Invisible text message
void displayOverlayInfo(const BlackMisc::CStatusMessage &message) const;
//! Message to be displayed in info window
void displayInInfoWindow(const BlackMisc::CVariant &message, int displayDurationMs) const;
public slots:
//! Command entered
@@ -110,7 +110,6 @@ namespace BlackGui
//! Clear text edit
void clearTextEdit();
};
}

View File

@@ -4,6 +4,7 @@
#include "dbus.h"
#include "tuple.h"
#include "json.h"
#include "variant.h"
#include <QtDBus/QDBusMetaType>
#include <QString>
#include <QtGlobal>
@@ -36,7 +37,7 @@ namespace BlackMisc
public:
//! True if and only if T is derived from CPhysicalQuantity.
static const bool value = sizeof(test(*(T*)0)) == sizeof(yes);
static const bool value = sizeof(test(*(T *)0)) == sizeof(yes);
};
}
@@ -101,7 +102,7 @@ namespace BlackMisc
friend bool operator!=(const CValueObject &valueObject, const CIndexVariantMap &valueMap);
//! Comparison operator to allow valueobjects be used as keys in QMap and std::set.
template <class T> friend typename std::enable_if<std::is_base_of<CValueObject, T>::value && ! PhysicalQuantities::IsQuantity<T>::value, bool>::type
template <class T> friend typename std::enable_if < std::is_base_of<CValueObject, T>::value &&! PhysicalQuantities::IsQuantity<T>::value, bool >::type
operator<(const T &lhs, const T &rhs)
{
const auto &lhsBase = static_cast<const CValueObject &>(lhs);
@@ -110,7 +111,7 @@ namespace BlackMisc
}
//! Comparison for symmetry with operator<.
template <class T> friend typename std::enable_if<std::is_base_of<CValueObject, T>::value && ! PhysicalQuantities::IsQuantity<T>::value, bool>::type
template <class T> friend typename std::enable_if < std::is_base_of<CValueObject, T>::value &&! PhysicalQuantities::IsQuantity<T>::value, bool >::type
operator>(const T &lhs, const T &rhs)
{
const auto &lhsBase = static_cast<const CValueObject &>(lhs);
@@ -119,7 +120,7 @@ namespace BlackMisc
}
//! Comparison for symmetry with operator<.
template <class T> friend typename std::enable_if<std::is_base_of<CValueObject, T>::value && ! PhysicalQuantities::IsQuantity<T>::value, bool>::type
template <class T> friend typename std::enable_if < std::is_base_of<CValueObject, T>::value &&! PhysicalQuantities::IsQuantity<T>::value, bool >::type
operator<=(const T &lhs, const T &rhs)
{
const auto &lhsBase = static_cast<const CValueObject &>(lhs);
@@ -128,7 +129,7 @@ namespace BlackMisc
}
//! Comparison for symmetry with operator<.
template <class T> friend typename std::enable_if<std::is_base_of<CValueObject, T>::value && ! PhysicalQuantities::IsQuantity<T>::value, bool>::type
template <class T> friend typename std::enable_if < std::is_base_of<CValueObject, T>::value &&! PhysicalQuantities::IsQuantity<T>::value, bool >::type
operator>=(const T &lhs, const T &rhs)
{
const auto &lhsBase = static_cast<const CValueObject &>(lhs);
@@ -167,6 +168,9 @@ namespace BlackMisc
//! Virtual method to return QVariant, used with DBus QVariant lists
virtual QVariant toQVariant() const = 0;
//! Virtual method to return CVariant
virtual CVariant toCVariant() const { return CVariant(this->toQVariant()); }
//! Contribute to JSON object
virtual QJsonObject toJson() const { QJsonObject json; return json;}