8 changed files with 338 additions and 225 deletions
@ -0,0 +1,68 @@
@@ -0,0 +1,68 @@
|
||||
#include "QGCMessageView.h" |
||||
#include "ui_QGCMessageView.h" |
||||
|
||||
#include "UASManager.h" |
||||
#include "QGCUnconnectedInfoWidget.h" |
||||
#include <QMenu> |
||||
|
||||
QGCMessageView::QGCMessageView(QWidget *parent) : |
||||
QWidget(parent), |
||||
activeUAS(NULL), |
||||
clearAction(new QAction(tr("Clear Text"), this)), |
||||
ui(new Ui::QGCMessageView) |
||||
{ |
||||
setObjectName("QUICKVIEW_MESSAGE_CONSOLE"); |
||||
|
||||
ui->setupUi(this); |
||||
setStyleSheet("QScrollArea { border: 0px; } QPlainTextEdit { border: 0px }"); |
||||
|
||||
// Construct initial widget
|
||||
connectWidget = new QGCUnconnectedInfoWidget(this); |
||||
ui->horizontalLayout->addWidget(connectWidget); |
||||
ui->plainTextEdit->hide(); |
||||
|
||||
connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), this, SLOT(setActiveUAS(UASInterface*))); |
||||
} |
||||
|
||||
QGCMessageView::~QGCMessageView() |
||||
{ |
||||
delete ui; |
||||
} |
||||
|
||||
void QGCMessageView::setActiveUAS(UASInterface* uas) |
||||
{ |
||||
if (!uas) |
||||
return; |
||||
|
||||
if (activeUAS) { |
||||
disconnect(uas, SIGNAL(textMessageReceived(int,int,int,QString)), this, SLOT(handleTextMessage(int,int,int,QString))); |
||||
ui->plainTextEdit->clear(); |
||||
} else { |
||||
|
||||
// First time UI setup, clear layout
|
||||
ui->horizontalLayout->removeWidget(connectWidget); |
||||
connectWidget->deleteLater(); |
||||
ui->plainTextEdit->show(); |
||||
|
||||
connect(clearAction, SIGNAL(triggered()), ui->plainTextEdit, SLOT(clear())); |
||||
} |
||||
|
||||
connect(uas, SIGNAL(textMessageReceived(int,int,int,QString)), this, SLOT(handleTextMessage(int,int,int,QString))); |
||||
activeUAS = uas; |
||||
} |
||||
|
||||
void QGCMessageView::handleTextMessage(int uasid, int componentid, int severity, QString text) |
||||
{ |
||||
// XXX color messages according to severity
|
||||
|
||||
ui->plainTextEdit->appendHtml(QString("<font color=\"%1\">[%2:%3] %4</font>\n").arg(UASManager::instance()->getUASForId(uasid)->getColor().name()).arg(UASManager::instance()->getUASForId(uasid)->getUASName()).arg(componentid).arg(text)); |
||||
// Ensure text area scrolls correctly
|
||||
ui->plainTextEdit->ensureCursorVisible(); |
||||
} |
||||
|
||||
void QGCMessageView::contextMenuEvent(QContextMenuEvent* event) |
||||
{ |
||||
QMenu menu(this); |
||||
menu.addAction(clearAction); |
||||
menu.exec(event->globalPos()); |
||||
} |
@ -0,0 +1,53 @@
@@ -0,0 +1,53 @@
|
||||
#ifndef QGCMESSAGEVIEW_H |
||||
#define QGCMESSAGEVIEW_H |
||||
|
||||
#include <QWidget> |
||||
#include <UASInterface.h> |
||||
#include <QVBoxLayout> |
||||
#include <QAction> |
||||
#include "QGCUnconnectedInfoWidget.h" |
||||
|
||||
namespace Ui { |
||||
class QGCMessageView; |
||||
} |
||||
|
||||
class QGCMessageView : public QWidget |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
explicit QGCMessageView(QWidget *parent = 0); |
||||
~QGCMessageView(); |
||||
|
||||
public slots: |
||||
/**
|
||||
* @brief Set currently active UAS |
||||
* @param uas the current active UAS |
||||
*/ |
||||
void setActiveUAS(UASInterface* uas); |
||||
/**
|
||||
* @brief Handle text message from current active UAS |
||||
* @param uasid |
||||
* @param componentid |
||||
* @param severity |
||||
* @param text |
||||
*/ |
||||
void handleTextMessage(int uasid, int componentid, int severity, QString text); |
||||
|
||||
/**
|
||||
* @brief Hand context menu event |
||||
* @param event |
||||
*/ |
||||
virtual void contextMenuEvent(QContextMenuEvent* event); |
||||
|
||||
protected: |
||||
UASInterface* activeUAS; |
||||
QVBoxLayout* initialLayout; |
||||
QGCUnconnectedInfoWidget *connectWidget; |
||||
QAction* clearAction; |
||||
|
||||
private: |
||||
Ui::QGCMessageView *ui; |
||||
}; |
||||
|
||||
#endif // QGCMESSAGEVIEW_H
|
@ -0,0 +1,62 @@
@@ -0,0 +1,62 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<ui version="4.0"> |
||||
<class>QGCMessageView</class> |
||||
<widget class="QWidget" name="QGCMessageView"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>0</x> |
||||
<y>0</y> |
||||
<width>305</width> |
||||
<height>283</height> |
||||
</rect> |
||||
</property> |
||||
<property name="windowTitle"> |
||||
<string>Form</string> |
||||
</property> |
||||
<layout class="QHBoxLayout" name="horizontalLayout_2"> |
||||
<property name="leftMargin"> |
||||
<number>0</number> |
||||
</property> |
||||
<property name="topMargin"> |
||||
<number>8</number> |
||||
</property> |
||||
<property name="rightMargin"> |
||||
<number>0</number> |
||||
</property> |
||||
<property name="bottomMargin"> |
||||
<number>0</number> |
||||
</property> |
||||
<item> |
||||
<widget class="QScrollArea" name="scrollArea"> |
||||
<property name="widgetResizable"> |
||||
<bool>true</bool> |
||||
</property> |
||||
<widget class="QWidget" name="scrollAreaWidgetContents"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>0</x> |
||||
<y>0</y> |
||||
<width>303</width> |
||||
<height>273</height> |
||||
</rect> |
||||
</property> |
||||
<layout class="QHBoxLayout" name="horizontalLayout"> |
||||
<property name="margin"> |
||||
<number>0</number> |
||||
</property> |
||||
<item> |
||||
<widget class="QPlainTextEdit" name="plainTextEdit"> |
||||
<property name="readOnly"> |
||||
<bool>true</bool> |
||||
</property> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</widget> |
||||
</widget> |
||||
</item> |
||||
</layout> |
||||
</widget> |
||||
<resources/> |
||||
<connections/> |
||||
</ui> |
Loading…
Reference in new issue