20 changed files with 2 additions and 1192 deletions
@ -1,23 +0,0 @@ |
|||||||
#include "QGCTabbedInfoView.h" |
|
||||||
#include "QGCApplication.h" |
|
||||||
|
|
||||||
QGCTabbedInfoView::QGCTabbedInfoView(const QString& title, QAction* action, QWidget *parent) |
|
||||||
: QGCDockWidget(title, action, parent) |
|
||||||
{ |
|
||||||
ui.setupUi(this); |
|
||||||
messageView = new UASMessageViewWidget(qgcApp()->toolbox()->uasMessageHandler(), this); |
|
||||||
quickView = new UASQuickView(this); |
|
||||||
ui.tabWidget->addTab(quickView,"Quick"); |
|
||||||
ui.tabWidget->addTab(messageView,"Messages"); |
|
||||||
|
|
||||||
loadSettings(); |
|
||||||
} |
|
||||||
void QGCTabbedInfoView::addSource(MAVLinkDecoder *decoder) |
|
||||||
{ |
|
||||||
m_decoder = decoder; |
|
||||||
quickView->addSource(decoder); |
|
||||||
} |
|
||||||
|
|
||||||
QGCTabbedInfoView::~QGCTabbedInfoView() |
|
||||||
{ |
|
||||||
} |
|
@ -1,26 +0,0 @@ |
|||||||
#ifndef QGCTABBEDINFOVIEW_H |
|
||||||
#define QGCTABBEDINFOVIEW_H |
|
||||||
|
|
||||||
#include "QGCDockWidget.h" |
|
||||||
#include "MAVLinkDecoder.h" |
|
||||||
#include "UASMessageView.h" |
|
||||||
#include "UASQuickView.h" |
|
||||||
|
|
||||||
#include "ui_QGCTabbedInfoView.h" |
|
||||||
|
|
||||||
class QGCTabbedInfoView : public QGCDockWidget |
|
||||||
{ |
|
||||||
Q_OBJECT |
|
||||||
|
|
||||||
public: |
|
||||||
explicit QGCTabbedInfoView(const QString& title, QAction* action, QWidget *parent = 0); |
|
||||||
~QGCTabbedInfoView(); |
|
||||||
void addSource(MAVLinkDecoder *decoder); |
|
||||||
private: |
|
||||||
MAVLinkDecoder *m_decoder; |
|
||||||
Ui::QGCTabbedInfoView ui; |
|
||||||
UASMessageViewWidget *messageView; |
|
||||||
UASQuickView *quickView; |
|
||||||
}; |
|
||||||
|
|
||||||
#endif // QGCTABBEDINFOVIEW_H
|
|
@ -1,28 +0,0 @@ |
|||||||
<?xml version="1.0" encoding="UTF-8"?> |
|
||||||
<ui version="4.0"> |
|
||||||
<class>QGCTabbedInfoView</class> |
|
||||||
<widget class="QWidget" name="QGCTabbedInfoView"> |
|
||||||
<property name="geometry"> |
|
||||||
<rect> |
|
||||||
<x>0</x> |
|
||||||
<y>0</y> |
|
||||||
<width>571</width> |
|
||||||
<height>457</height> |
|
||||||
</rect> |
|
||||||
</property> |
|
||||||
<property name="windowTitle"> |
|
||||||
<string>Info View</string> |
|
||||||
</property> |
|
||||||
<layout class="QVBoxLayout" name="verticalLayout"> |
|
||||||
<item> |
|
||||||
<widget class="QTabWidget" name="tabWidget"> |
|
||||||
<property name="currentIndex"> |
|
||||||
<number>-1</number> |
|
||||||
</property> |
|
||||||
</widget> |
|
||||||
</item> |
|
||||||
</layout> |
|
||||||
</widget> |
|
||||||
<resources/> |
|
||||||
<connections/> |
|
||||||
</ui> |
|
@ -1,86 +0,0 @@ |
|||||||
/****************************************************************************
|
|
||||||
* |
|
||||||
* (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
|
|
||||||
* |
|
||||||
* QGroundControl is licensed according to the terms in the file |
|
||||||
* COPYING.md in the root of the source code directory. |
|
||||||
* |
|
||||||
****************************************************************************/ |
|
||||||
|
|
||||||
|
|
||||||
#include <QMenu> |
|
||||||
#include <QScrollBar> |
|
||||||
|
|
||||||
#include "UASMessageView.h" |
|
||||||
#include "QGCUnconnectedInfoWidget.h" |
|
||||||
#include "ui_UASMessageView.h" |
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------------------
|
|
||||||
UASMessageView |
|
||||||
-------------------------------------------------------------------------------------*/ |
|
||||||
|
|
||||||
UASMessageView::UASMessageView(QWidget *parent) : |
|
||||||
QWidget(parent), |
|
||||||
_ui(new Ui::UASMessageView) |
|
||||||
{ |
|
||||||
_ui->setupUi(this); |
|
||||||
} |
|
||||||
|
|
||||||
UASMessageView::~UASMessageView() |
|
||||||
{ |
|
||||||
delete _ui; |
|
||||||
} |
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------------------
|
|
||||||
UASMessageViewWidget |
|
||||||
-------------------------------------------------------------------------------------*/ |
|
||||||
|
|
||||||
UASMessageViewWidget::UASMessageViewWidget(UASMessageHandler* uasMessageHandler, QWidget *parent) |
|
||||||
: UASMessageView(parent) |
|
||||||
, _unconnectedWidget(NULL) |
|
||||||
, _uasMessageHandler(uasMessageHandler) |
|
||||||
{ |
|
||||||
setStyleSheet("QPlainTextEdit { border: 0px }"); |
|
||||||
|
|
||||||
// Enable the right-click menu for the text editor. This works because the plainTextEdit
|
|
||||||
// widget has its context menu policy set to its actions list. So any actions we add
|
|
||||||
// to this widget's action list will be automatically displayed.
|
|
||||||
// We only have the clear action right now.
|
|
||||||
QAction* clearAction = new QAction(tr("Clear Messages"), this); |
|
||||||
connect(clearAction, &QAction::triggered, this, &UASMessageViewWidget::clearMessages); |
|
||||||
ui()->plainTextEdit->addAction(clearAction); |
|
||||||
// Connect message handler
|
|
||||||
connect(_uasMessageHandler, &UASMessageHandler::textMessageReceived, this, &UASMessageViewWidget::handleTextMessage); |
|
||||||
} |
|
||||||
|
|
||||||
UASMessageViewWidget::~UASMessageViewWidget() |
|
||||||
{ |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
void UASMessageViewWidget::clearMessages() |
|
||||||
{ |
|
||||||
ui()->plainTextEdit->clear(); |
|
||||||
_uasMessageHandler->clearMessages(); |
|
||||||
} |
|
||||||
|
|
||||||
void UASMessageViewWidget::handleTextMessage(UASMessage *message) |
|
||||||
{ |
|
||||||
// Reset
|
|
||||||
if(!message) { |
|
||||||
ui()->plainTextEdit->clear(); |
|
||||||
} else { |
|
||||||
QPlainTextEdit *msgWidget = ui()->plainTextEdit; |
|
||||||
// Turn off updates while we're appending content to avoid breaking the autoscroll behavior
|
|
||||||
msgWidget->setUpdatesEnabled(false); |
|
||||||
QScrollBar *scroller = msgWidget->verticalScrollBar(); |
|
||||||
QString messages = message->getFormatedText(); |
|
||||||
messages = messages.replace("<#E>", "color: #f95e5e; font: monospace;"); |
|
||||||
messages = messages.replace("<#I>", "color: #f9b55e; font: monospace;"); |
|
||||||
messages = messages.replace("<#N>", "color: #ffffff; font: monospace;"); |
|
||||||
msgWidget->appendHtml(messages); |
|
||||||
// Ensure text area scrolls correctly
|
|
||||||
scroller->setValue(scroller->maximum()); |
|
||||||
msgWidget->setUpdatesEnabled(true); |
|
||||||
} |
|
||||||
} |
|
@ -1,60 +0,0 @@ |
|||||||
/****************************************************************************
|
|
||||||
* |
|
||||||
* (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
|
|
||||||
* |
|
||||||
* QGroundControl is licensed according to the terms in the file |
|
||||||
* COPYING.md in the root of the source code directory. |
|
||||||
* |
|
||||||
****************************************************************************/ |
|
||||||
|
|
||||||
|
|
||||||
#ifndef QGCMESSAGEVIEW_H |
|
||||||
#define QGCMESSAGEVIEW_H |
|
||||||
|
|
||||||
#include <QWidget> |
|
||||||
#include <UASInterface.h> |
|
||||||
#include <QVBoxLayout> |
|
||||||
#include <QAction> |
|
||||||
|
|
||||||
#include "QGCUnconnectedInfoWidget.h" |
|
||||||
#include "UASMessageHandler.h" |
|
||||||
|
|
||||||
class UASMessage; |
|
||||||
|
|
||||||
namespace Ui { |
|
||||||
class UASMessageView; |
|
||||||
} |
|
||||||
|
|
||||||
// Message View base class
|
|
||||||
class UASMessageView : public QWidget |
|
||||||
{ |
|
||||||
Q_OBJECT |
|
||||||
|
|
||||||
public: |
|
||||||
explicit UASMessageView(QWidget *parent = 0); |
|
||||||
virtual ~UASMessageView(); |
|
||||||
Ui::UASMessageView* ui() { return _ui; } |
|
||||||
|
|
||||||
private: |
|
||||||
Ui::UASMessageView* _ui; |
|
||||||
}; |
|
||||||
|
|
||||||
// Message View Widget (used in the Info View tabbed Widget)
|
|
||||||
class UASMessageViewWidget : public UASMessageView |
|
||||||
{ |
|
||||||
Q_OBJECT |
|
||||||
|
|
||||||
public: |
|
||||||
explicit UASMessageViewWidget(UASMessageHandler* uasMessageHandler, QWidget *parent = 0); |
|
||||||
~UASMessageViewWidget(); |
|
||||||
|
|
||||||
public slots: |
|
||||||
void handleTextMessage(UASMessage* message); |
|
||||||
void clearMessages(); |
|
||||||
|
|
||||||
private: |
|
||||||
QGCUnconnectedInfoWidget* _unconnectedWidget; |
|
||||||
UASMessageHandler* _uasMessageHandler; |
|
||||||
}; |
|
||||||
|
|
||||||
#endif // QGCMESSAGEVIEW_H
|
|
@ -1,67 +0,0 @@ |
|||||||
<?xml version="1.0" encoding="UTF-8"?> |
|
||||||
<ui version="4.0"> |
|
||||||
<class>UASMessageView</class> |
|
||||||
<widget class="QWidget" name="UASMessageView"> |
|
||||||
<property name="geometry"> |
|
||||||
<rect> |
|
||||||
<x>0</x> |
|
||||||
<y>0</y> |
|
||||||
<width>248</width> |
|
||||||
<height>249</height> |
|
||||||
</rect> |
|
||||||
</property> |
|
||||||
<property name="sizePolicy"> |
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding"> |
|
||||||
<horstretch>0</horstretch> |
|
||||||
<verstretch>0</verstretch> |
|
||||||
</sizepolicy> |
|
||||||
</property> |
|
||||||
<property name="contextMenuPolicy"> |
|
||||||
<enum>Qt::NoContextMenu</enum> |
|
||||||
</property> |
|
||||||
<property name="windowTitle"> |
|
||||||
<string>Form</string> |
|
||||||
</property> |
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout"> |
|
||||||
<property name="leftMargin"> |
|
||||||
<number>4</number> |
|
||||||
</property> |
|
||||||
<property name="topMargin"> |
|
||||||
<number>8</number> |
|
||||||
</property> |
|
||||||
<property name="rightMargin"> |
|
||||||
<number>4</number> |
|
||||||
</property> |
|
||||||
<property name="bottomMargin"> |
|
||||||
<number>4</number> |
|
||||||
</property> |
|
||||||
<item> |
|
||||||
<widget class="QPlainTextEdit" name="plainTextEdit"> |
|
||||||
<property name="minimumSize"> |
|
||||||
<size> |
|
||||||
<width>0</width> |
|
||||||
<height>0</height> |
|
||||||
</size> |
|
||||||
</property> |
|
||||||
<property name="contextMenuPolicy"> |
|
||||||
<enum>Qt::ActionsContextMenu</enum> |
|
||||||
</property> |
|
||||||
<property name="acceptDrops"> |
|
||||||
<bool>false</bool> |
|
||||||
</property> |
|
||||||
<property name="undoRedoEnabled"> |
|
||||||
<bool>false</bool> |
|
||||||
</property> |
|
||||||
<property name="readOnly"> |
|
||||||
<bool>true</bool> |
|
||||||
</property> |
|
||||||
<property name="plainText"> |
|
||||||
<string notr="true"/> |
|
||||||
</property> |
|
||||||
</widget> |
|
||||||
</item> |
|
||||||
</layout> |
|
||||||
</widget> |
|
||||||
<resources/> |
|
||||||
<connections/> |
|
||||||
</ui> |
|
@ -1,320 +0,0 @@ |
|||||||
#include "UASQuickView.h" |
|
||||||
#include "UASQuickViewItemSelect.h" |
|
||||||
#include "UASQuickViewTextItem.h" |
|
||||||
#include "MultiVehicleManager.h" |
|
||||||
#include "UAS.h" |
|
||||||
#include "QGCApplication.h" |
|
||||||
|
|
||||||
#include <QMetaMethod> |
|
||||||
#include <QDebug> |
|
||||||
#include <QSettings> |
|
||||||
#include <QInputDialog> |
|
||||||
|
|
||||||
UASQuickView::UASQuickView(QWidget *parent) : QWidget(parent), |
|
||||||
uas(NULL) |
|
||||||
{ |
|
||||||
quickViewSelectDialog=0; |
|
||||||
m_columnCount=2; |
|
||||||
m_currentColumn=0; |
|
||||||
ui.setupUi(this); |
|
||||||
|
|
||||||
ui.horizontalLayout->setMargin(0); |
|
||||||
m_verticalLayoutList.append(new QVBoxLayout()); |
|
||||||
ui.horizontalLayout->addItem(m_verticalLayoutList[0]); |
|
||||||
|
|
||||||
connect(qgcApp()->toolbox()->multiVehicleManager(), &MultiVehicleManager::activeVehicleChanged, this, &UASQuickView::_activeVehicleChanged); |
|
||||||
_activeVehicleChanged(qgcApp()->toolbox()->multiVehicleManager()->activeVehicle()); |
|
||||||
this->setContextMenuPolicy(Qt::ActionsContextMenu); |
|
||||||
|
|
||||||
loadSettings(); |
|
||||||
|
|
||||||
//If we don't have any predefined settings, set some defaults.
|
|
||||||
if (uasPropertyValueMap.size() == 0) |
|
||||||
{ |
|
||||||
valueEnabled("altitudeAMSL"); |
|
||||||
valueEnabled("altitudeAMSLFT"); |
|
||||||
valueEnabled("altitudeRelative"); |
|
||||||
valueEnabled("groundSpeed"); |
|
||||||
valueEnabled("distToWaypoint"); |
|
||||||
} |
|
||||||
|
|
||||||
QAction *action = new QAction("Add/Remove Items",this); |
|
||||||
action->setCheckable(false); |
|
||||||
connect(action,&QAction::triggered,this, &UASQuickView::addActionTriggered); |
|
||||||
this->addAction(action); |
|
||||||
|
|
||||||
QAction *columnaction = new QAction("Set Column Count",this); |
|
||||||
columnaction->setCheckable(false); |
|
||||||
connect(columnaction,&QAction::triggered,this,&UASQuickView::columnActionTriggered); |
|
||||||
this->addAction(columnaction); |
|
||||||
|
|
||||||
updateTimer = new QTimer(this); |
|
||||||
connect(updateTimer,&QTimer::timeout,this,&UASQuickView::updateTimerTick); |
|
||||||
updateTimer->start(1000); |
|
||||||
|
|
||||||
} |
|
||||||
UASQuickView::~UASQuickView() |
|
||||||
{ |
|
||||||
if (quickViewSelectDialog) |
|
||||||
{ |
|
||||||
delete quickViewSelectDialog; |
|
||||||
} |
|
||||||
} |
|
||||||
void UASQuickView::columnActionTriggered() |
|
||||||
{ |
|
||||||
bool ok = false; |
|
||||||
int newcolumns = QInputDialog::getInt( |
|
||||||
this,"Columns","Enter number of columns", m_columnCount, 1, 10, 1, &ok); |
|
||||||
if (!ok) |
|
||||||
{ |
|
||||||
return; |
|
||||||
} |
|
||||||
m_columnCount = newcolumns; |
|
||||||
sortItems(newcolumns); |
|
||||||
saveSettings(); |
|
||||||
} |
|
||||||
|
|
||||||
void UASQuickView::addActionTriggered() |
|
||||||
{ |
|
||||||
if (quickViewSelectDialog) |
|
||||||
{ |
|
||||||
quickViewSelectDialog->show(); |
|
||||||
return; |
|
||||||
} |
|
||||||
quickViewSelectDialog = new UASQuickViewItemSelect(); |
|
||||||
connect(quickViewSelectDialog,&UASQuickViewItemSelect::destroyed,this,&UASQuickView::selectDialogClosed); |
|
||||||
connect(quickViewSelectDialog,&UASQuickViewItemSelect::valueDisabled,this,&UASQuickView::valueDisabled); |
|
||||||
connect(quickViewSelectDialog,&UASQuickViewItemSelect::valueEnabled,this,&UASQuickView::valueEnabled); |
|
||||||
|
|
||||||
quickViewSelectDialog->setAttribute(Qt::WA_DeleteOnClose,true); |
|
||||||
for (QMap<QString,double>::const_iterator i = uasPropertyValueMap.constBegin();i!=uasPropertyValueMap.constEnd();i++) |
|
||||||
{ |
|
||||||
quickViewSelectDialog->addItem(i.key(),uasEnabledPropertyList.contains(i.key())); |
|
||||||
} |
|
||||||
quickViewSelectDialog->show(); |
|
||||||
} |
|
||||||
void UASQuickView::saveSettings() |
|
||||||
{ |
|
||||||
QSettings settings; |
|
||||||
settings.beginWriteArray("UAS_QUICK_VIEW_ITEMS"); |
|
||||||
int count = 0; |
|
||||||
for (QMap<QString,UASQuickViewItem*>::const_iterator i = uasPropertyToLabelMap.constBegin();i!=uasPropertyToLabelMap.constEnd();i++) |
|
||||||
{ |
|
||||||
settings.setArrayIndex(count++); |
|
||||||
settings.setValue("name",i.key()); |
|
||||||
settings.setValue("type","text"); |
|
||||||
} |
|
||||||
settings.endArray(); |
|
||||||
settings.setValue("UAS_QUICK_VIEW_COLUMNS",m_columnCount); |
|
||||||
} |
|
||||||
void UASQuickView::loadSettings() |
|
||||||
{ |
|
||||||
QSettings settings; |
|
||||||
m_columnCount = settings.value("UAS_QUICK_VIEW_COLUMNS",1).toInt(); |
|
||||||
int size = settings.beginReadArray("UAS_QUICK_VIEW_ITEMS"); |
|
||||||
for (int i = 0; i < size; i++) |
|
||||||
{ |
|
||||||
settings.setArrayIndex(i); |
|
||||||
QString nameval = settings.value("name").toString(); |
|
||||||
QString typeval = settings.value("type").toString(); |
|
||||||
if (typeval == "text" && !uasPropertyToLabelMap.contains(nameval)) |
|
||||||
{ |
|
||||||
valueEnabled(nameval); |
|
||||||
} |
|
||||||
} |
|
||||||
settings.endArray(); |
|
||||||
sortItems(m_columnCount); |
|
||||||
} |
|
||||||
|
|
||||||
void UASQuickView::valueEnabled(QString value) |
|
||||||
{ |
|
||||||
UASQuickViewItem *item = new UASQuickViewTextItem(this); |
|
||||||
item->setTitle(value); |
|
||||||
//ui.verticalLayout->addWidget(item);
|
|
||||||
//m_currentColumn
|
|
||||||
m_verticalLayoutList[m_currentColumn]->addWidget(item); |
|
||||||
m_PropertyToLayoutIndexMap[value] = m_currentColumn; |
|
||||||
m_currentColumn++; |
|
||||||
if (m_currentColumn >= m_columnCount-1) |
|
||||||
{ |
|
||||||
m_currentColumn = 0; |
|
||||||
} |
|
||||||
uasPropertyToLabelMap[value] = item; |
|
||||||
uasEnabledPropertyList.append(value); |
|
||||||
|
|
||||||
if (!uasPropertyValueMap.contains(value)) |
|
||||||
{ |
|
||||||
uasPropertyValueMap[value] = 0; |
|
||||||
} |
|
||||||
saveSettings(); |
|
||||||
item->show(); |
|
||||||
sortItems(m_columnCount); |
|
||||||
|
|
||||||
} |
|
||||||
void UASQuickView::sortItems(int columncount) |
|
||||||
{ |
|
||||||
QList<QWidget*> itemlist; |
|
||||||
for (QMap<QString,UASQuickViewItem*>::const_iterator i = uasPropertyToLabelMap.constBegin();i!=uasPropertyToLabelMap.constEnd();i++) |
|
||||||
{ |
|
||||||
m_verticalLayoutList[m_PropertyToLayoutIndexMap[i.key()]]->removeWidget(i.value()); |
|
||||||
m_PropertyToLayoutIndexMap.remove(i.key()); |
|
||||||
itemlist.append(i.value()); |
|
||||||
} |
|
||||||
// Item list has all the widgets available, now re-add them to the layouts.
|
|
||||||
for (int i = 0; i < m_verticalLayoutList.size(); i++) |
|
||||||
{ |
|
||||||
ui.horizontalLayout->removeItem(m_verticalLayoutList[i]); |
|
||||||
m_verticalLayoutList[i]->deleteLater(); //removeItem de-parents the item.
|
|
||||||
} |
|
||||||
m_verticalLayoutList.clear(); |
|
||||||
|
|
||||||
// Create a vertical layout for every intended column
|
|
||||||
for (int i = 0; i < columncount; i++) |
|
||||||
{ |
|
||||||
QVBoxLayout *layout = new QVBoxLayout(); |
|
||||||
ui.horizontalLayout->addItem(layout); |
|
||||||
m_verticalLayoutList.append(layout); |
|
||||||
layout->setMargin(0); |
|
||||||
} |
|
||||||
|
|
||||||
//Cycle through all items and add them to the layout
|
|
||||||
int currcol = 0; |
|
||||||
for (int i = 0; i < itemlist.size(); i++) |
|
||||||
{ |
|
||||||
m_verticalLayoutList[currcol]->addWidget(itemlist[i]); |
|
||||||
currcol++; |
|
||||||
if (currcol >= columncount) |
|
||||||
{ |
|
||||||
currcol = 0; |
|
||||||
} |
|
||||||
} |
|
||||||
m_currentColumn = currcol; |
|
||||||
QApplication::processEvents(); |
|
||||||
recalculateItemTextSizing(); |
|
||||||
} |
|
||||||
void UASQuickView::resizeEvent(QResizeEvent *evt) |
|
||||||
{ |
|
||||||
Q_UNUSED(evt); |
|
||||||
recalculateItemTextSizing(); |
|
||||||
} |
|
||||||
void UASQuickView::recalculateItemTextSizing() |
|
||||||
{ |
|
||||||
return; |
|
||||||
int minpixelsize = 65535; |
|
||||||
for (QMap<QString,UASQuickViewItem*>::const_iterator i = uasPropertyToLabelMap.constBegin();i!=uasPropertyToLabelMap.constEnd();i++) |
|
||||||
{ |
|
||||||
int tempmin = i.value()->minValuePixelSize(); |
|
||||||
if (tempmin < minpixelsize) |
|
||||||
{ |
|
||||||
minpixelsize = tempmin; |
|
||||||
} |
|
||||||
} |
|
||||||
if(minpixelsize < 6) |
|
||||||
minpixelsize = 6; |
|
||||||
for (QMap<QString,UASQuickViewItem*>::const_iterator i = uasPropertyToLabelMap.constBegin();i!=uasPropertyToLabelMap.constEnd();i++) |
|
||||||
{ |
|
||||||
i.value()->setValuePixelSize(minpixelsize); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void UASQuickView::valueDisabled(QString value) |
|
||||||
{ |
|
||||||
if (uasPropertyToLabelMap.contains(value)) |
|
||||||
{ |
|
||||||
UASQuickViewItem *item = uasPropertyToLabelMap[value]; |
|
||||||
uasPropertyToLabelMap.remove(value); |
|
||||||
item->hide(); |
|
||||||
//ui.verticalLayout->removeWidget(item);
|
|
||||||
//layout->removeWidget(item);
|
|
||||||
m_verticalLayoutList[m_PropertyToLayoutIndexMap[value]]->removeWidget(item); |
|
||||||
sortItems(m_columnCount); |
|
||||||
item->deleteLater(); |
|
||||||
uasEnabledPropertyList.removeOne(value); |
|
||||||
saveSettings(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void UASQuickView::selectDialogClosed() |
|
||||||
{ |
|
||||||
quickViewSelectDialog = 0; |
|
||||||
} |
|
||||||
|
|
||||||
void UASQuickView::updateTimerTick() |
|
||||||
{ |
|
||||||
//uasPropertyValueMap
|
|
||||||
for (QMap<QString,UASQuickViewItem*>::const_iterator i = uasPropertyToLabelMap.constBegin(); i != uasPropertyToLabelMap.constEnd();i++) |
|
||||||
{ |
|
||||||
if (uasPropertyValueMap.contains(i.key())) |
|
||||||
{ |
|
||||||
i.value()->setValue(uasPropertyValueMap[i.key()]); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void UASQuickView::_activeVehicleChanged(Vehicle* vehicle) |
|
||||||
{ |
|
||||||
if (uas || !vehicle) { |
|
||||||
return; |
|
||||||
} |
|
||||||
this->uas = vehicle->uas(); |
|
||||||
connect(uas, SIGNAL(valueChanged(int,QString,QString,QVariant,quint64)),this,SLOT(valueChanged(int,QString,QString,QVariant,quint64))); |
|
||||||
} |
|
||||||
void UASQuickView::addSource(MAVLinkDecoder *decoder) |
|
||||||
{ |
|
||||||
connect(decoder,SIGNAL(valueChanged(int,QString,QString,QVariant,quint64)),this,SLOT(valueChanged(int,QString,QString,QVariant,quint64))); |
|
||||||
} |
|
||||||
|
|
||||||
void UASQuickView::valueChanged(const int uasId, const QString& name, const QString& unit, const QVariant &variant, const quint64 msec) |
|
||||||
{ |
|
||||||
Q_UNUSED(uasId); |
|
||||||
Q_UNUSED(unit); |
|
||||||
Q_UNUSED(msec); |
|
||||||
|
|
||||||
bool ok; |
|
||||||
double value = variant.toDouble(&ok); |
|
||||||
QMetaType::Type metaType = static_cast<QMetaType::Type>(variant.type()); |
|
||||||
if(!ok || metaType == QMetaType::QString || metaType == QMetaType::QByteArray) |
|
||||||
return; |
|
||||||
|
|
||||||
if (!uasPropertyValueMap.contains(name)) |
|
||||||
{ |
|
||||||
if (quickViewSelectDialog) |
|
||||||
{ |
|
||||||
quickViewSelectDialog->addItem(name); |
|
||||||
} |
|
||||||
} |
|
||||||
uasPropertyValueMap[name] = value; |
|
||||||
} |
|
||||||
|
|
||||||
void UASQuickView::actionTriggered(bool checked) |
|
||||||
{ |
|
||||||
QAction *senderlabel = qobject_cast<QAction*>(sender()); |
|
||||||
if (!senderlabel) |
|
||||||
{ |
|
||||||
return; |
|
||||||
} |
|
||||||
if (checked) |
|
||||||
{ |
|
||||||
valueEnabled(senderlabel->text()); |
|
||||||
/*UASQuickViewItem *item = new UASQuickViewTextItem(this);
|
|
||||||
item->setTitle(senderlabel->text()); |
|
||||||
layout->addWidget(item); |
|
||||||
//ui.verticalLayout->addWidget(item);
|
|
||||||
m_currentColumn++; |
|
||||||
if (m_currentColumn >= m_verticalLayoutList.size()) |
|
||||||
{ |
|
||||||
m_currentColumn = 0; |
|
||||||
} |
|
||||||
uasPropertyToLabelMap[senderlabel->text()] = item;*/ |
|
||||||
|
|
||||||
|
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
valueDisabled(senderlabel->text()); |
|
||||||
/*layout->removeWidget(uasPropertyToLabelMap[senderlabel->text()]);
|
|
||||||
uasPropertyToLabelMap[senderlabel->text()]->deleteLater(); |
|
||||||
uasPropertyToLabelMap.remove(senderlabel->text());*/ |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
@ -1,75 +0,0 @@ |
|||||||
#ifndef UASQUICKVIEW_H |
|
||||||
#define UASQUICKVIEW_H |
|
||||||
|
|
||||||
#include <QWidget> |
|
||||||
#include <QTimer> |
|
||||||
#include <QLabel> |
|
||||||
#include "uas/UASInterface.h" |
|
||||||
#include "ui_UASQuickView.h" |
|
||||||
#include "UASQuickViewItem.h" |
|
||||||
#include "MAVLinkDecoder.h" |
|
||||||
#include "UASQuickViewItemSelect.h" |
|
||||||
#include "Vehicle.h" |
|
||||||
class UASQuickView : public QWidget |
|
||||||
{ |
|
||||||
Q_OBJECT |
|
||||||
public: |
|
||||||
UASQuickView(QWidget *parent = 0); |
|
||||||
~UASQuickView(); |
|
||||||
void addSource(MAVLinkDecoder *decoder); |
|
||||||
private: |
|
||||||
UASInterface *uas; |
|
||||||
|
|
||||||
/** List of enabled properties */ |
|
||||||
QList<QString> uasEnabledPropertyList; |
|
||||||
|
|
||||||
/** Maps from the property name to the current value */ |
|
||||||
QMap<QString,double> uasPropertyValueMap; |
|
||||||
|
|
||||||
/** Maps from property name to the display item */ |
|
||||||
QMap<QString,UASQuickViewItem*> uasPropertyToLabelMap; |
|
||||||
|
|
||||||
/** Timer for updating the UI */ |
|
||||||
QTimer *updateTimer; |
|
||||||
|
|
||||||
/** Selection dialog for selectin/deselecting gauge items */ |
|
||||||
UASQuickViewItemSelect *quickViewSelectDialog; |
|
||||||
|
|
||||||
/** Saves gauge layout to settings file */ |
|
||||||
void saveSettings(); |
|
||||||
|
|
||||||
/** Loads gauge layout from settings file */ |
|
||||||
void loadSettings(); |
|
||||||
|
|
||||||
void recalculateItemTextSizing(); |
|
||||||
|
|
||||||
/** Column Count */ |
|
||||||
int m_columnCount; |
|
||||||
|
|
||||||
QList<QVBoxLayout*> m_verticalLayoutList; |
|
||||||
void sortItems(int columncount); |
|
||||||
QList<int> m_verticalLayoutItemCount; |
|
||||||
int m_currentColumn; |
|
||||||
QMap<QString,int> m_PropertyToLayoutIndexMap; |
|
||||||
|
|
||||||
//FlowLayout *layout;
|
|
||||||
protected: |
|
||||||
Ui::Form ui; |
|
||||||
void resizeEvent(QResizeEvent *evt); |
|
||||||
signals: |
|
||||||
|
|
||||||
public slots: |
|
||||||
void valueChanged(const int uasid, const QString& name, const QString& unit, const QVariant& value,const quint64 msecs); |
|
||||||
void actionTriggered(bool checked); |
|
||||||
void addActionTriggered(); |
|
||||||
void updateTimerTick(); |
|
||||||
void selectDialogClosed(); |
|
||||||
void valueEnabled(QString value); |
|
||||||
void valueDisabled(QString value); |
|
||||||
void columnActionTriggered(); |
|
||||||
|
|
||||||
private slots: |
|
||||||
void _activeVehicleChanged(Vehicle* vehicle); |
|
||||||
}; |
|
||||||
|
|
||||||
#endif // UASQUICKVIEW_H
|
|
@ -1,30 +0,0 @@ |
|||||||
<?xml version="1.0" encoding="UTF-8"?> |
|
||||||
<ui version="4.0"> |
|
||||||
<class>Form</class> |
|
||||||
<widget class="QWidget" name="Form"> |
|
||||||
<property name="geometry"> |
|
||||||
<rect> |
|
||||||
<x>0</x> |
|
||||||
<y>0</y> |
|
||||||
<width>400</width> |
|
||||||
<height>300</height> |
|
||||||
</rect> |
|
||||||
</property> |
|
||||||
<property name="minimumSize"> |
|
||||||
<size> |
|
||||||
<width>100</width> |
|
||||||
<height>100</height> |
|
||||||
</size> |
|
||||||
</property> |
|
||||||
<property name="windowTitle"> |
|
||||||
<string>Form</string> |
|
||||||
</property> |
|
||||||
<layout class="QVBoxLayout" name="verticalLayout"> |
|
||||||
<item> |
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout"/> |
|
||||||
</item> |
|
||||||
</layout> |
|
||||||
</widget> |
|
||||||
<resources/> |
|
||||||
<connections/> |
|
||||||
</ui> |
|
@ -1,27 +0,0 @@ |
|||||||
#include "UASQuickViewGaugeItem.h" |
|
||||||
#include <QVBoxLayout> |
|
||||||
UASQuickViewGaugeItem::UASQuickViewGaugeItem(QWidget *parent) : UASQuickViewItem(parent) |
|
||||||
{ |
|
||||||
|
|
||||||
} |
|
||||||
void UASQuickViewGaugeItem::setValue(double value) |
|
||||||
{ |
|
||||||
valueLabel->setText(QString::number(value,'f',4)); |
|
||||||
} |
|
||||||
|
|
||||||
void UASQuickViewGaugeItem::setTitle(QString title) |
|
||||||
{ |
|
||||||
titleLabel->setText(title); |
|
||||||
} |
|
||||||
void UASQuickViewGaugeItem::resizeEvent(QResizeEvent *event) |
|
||||||
{ |
|
||||||
Q_UNUSED(event); |
|
||||||
|
|
||||||
QFont valuefont = valueLabel->font(); |
|
||||||
QFont titlefont = titleLabel->font(); |
|
||||||
valuefont.setPixelSize(this->height() / 2.0); |
|
||||||
titlefont.setPixelSize(this->height() / 4.0); |
|
||||||
valueLabel->setFont(valuefont); |
|
||||||
titleLabel->setFont(titlefont); |
|
||||||
update(); |
|
||||||
} |
|
@ -1,19 +0,0 @@ |
|||||||
#ifndef UASQuickViewGaugeItem_H |
|
||||||
#define UASQuickViewGaugeItem_H |
|
||||||
|
|
||||||
#include "UASQuickViewItem.h" |
|
||||||
#include <QLabel> |
|
||||||
class UASQuickViewGaugeItem : public UASQuickViewItem |
|
||||||
{ |
|
||||||
public: |
|
||||||
UASQuickViewGaugeItem(QWidget *parent=0); |
|
||||||
void setValue(double value); |
|
||||||
void setTitle(QString title); |
|
||||||
protected: |
|
||||||
void resizeEvent(QResizeEvent *event); |
|
||||||
private: |
|
||||||
QLabel *titleLabel; |
|
||||||
QLabel *valueLabel; |
|
||||||
}; |
|
||||||
|
|
||||||
#endif // UASQuickViewGaugeItem_H
|
|
@ -1,6 +0,0 @@ |
|||||||
#include "UASQuickViewItem.h" |
|
||||||
|
|
||||||
UASQuickViewItem::UASQuickViewItem(QWidget *parent) : |
|
||||||
QWidget(parent) |
|
||||||
{ |
|
||||||
} |
|
@ -1,16 +0,0 @@ |
|||||||
#ifndef UASQUICKVIEWITEM_H |
|
||||||
#define UASQUICKVIEWITEM_H |
|
||||||
|
|
||||||
#include <QWidget> |
|
||||||
class UASQuickViewItem : public QWidget |
|
||||||
{ |
|
||||||
Q_OBJECT |
|
||||||
public: |
|
||||||
explicit UASQuickViewItem(QWidget *parent = 0); |
|
||||||
virtual void setValue(double value)=0; |
|
||||||
virtual void setTitle(QString title)=0; |
|
||||||
virtual int minValuePixelSize()=0; |
|
||||||
virtual void setValuePixelSize(int size)=0; |
|
||||||
}; |
|
||||||
|
|
||||||
#endif // UASQUICKVIEWITEM_H
|
|
@ -1,106 +0,0 @@ |
|||||||
#include "UASQuickViewItemSelect.h" |
|
||||||
#include <QLabel> |
|
||||||
#include <QCheckBox> |
|
||||||
UASQuickViewItemSelect::UASQuickViewItemSelect(QWidget *parent) : QWidget(parent) |
|
||||||
{ |
|
||||||
ui.setupUi(this); |
|
||||||
currcol = 0; |
|
||||||
currrow = 0; |
|
||||||
ui.gridLayout->setSpacing(5); |
|
||||||
ui.gridLayout->setMargin(0); |
|
||||||
} |
|
||||||
void UASQuickViewItemSelect::addItem(QString item,bool enabled) |
|
||||||
{ |
|
||||||
QString category = "."; |
|
||||||
QString name = item; |
|
||||||
if (item.indexOf(":") != -1 && item.indexOf(".") != -1) |
|
||||||
{ |
|
||||||
//Item has a subcateogry
|
|
||||||
category = item.mid(item.indexOf(":")+1,item.indexOf(".") - item.indexOf(":")-1); |
|
||||||
name = item.mid(item.indexOf(".")+1); |
|
||||||
} |
|
||||||
int col = -1; |
|
||||||
if (m_categoryToIndexMap.contains(category)) |
|
||||||
{ |
|
||||||
col = m_categoryToIndexMap[category]; |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
m_categoryToIndexMap[category] = currcol++; |
|
||||||
col = m_categoryToIndexMap[category]; |
|
||||||
//New column.
|
|
||||||
QLabel *titlelabel = new QLabel(this); |
|
||||||
titlelabel->setText(category); |
|
||||||
titlelabel->show(); |
|
||||||
ui.gridLayout->addWidget(titlelabel,0,col); |
|
||||||
} |
|
||||||
QCheckBox *label = new QCheckBox(this); |
|
||||||
m_checkboxToValueMap[label] = item; |
|
||||||
m_checkBoxList.append(label); |
|
||||||
if (enabled) |
|
||||||
{ |
|
||||||
label->setChecked(true); |
|
||||||
} |
|
||||||
connect(label,SIGNAL(clicked(bool)),this,SLOT(checkBoxClicked(bool))); |
|
||||||
label->setText(name); |
|
||||||
label->show(); |
|
||||||
//ui.gridLayout->addWidget(label,currrow,currcol++);
|
|
||||||
bool breakout = false; |
|
||||||
int row = -1; |
|
||||||
while (!breakout) |
|
||||||
{ |
|
||||||
if (!ui.gridLayout->itemAtPosition(++row,col) || row > 100) |
|
||||||
{ |
|
||||||
breakout = true; |
|
||||||
} |
|
||||||
} |
|
||||||
//Row is the next invalid object, and col is the proper column.
|
|
||||||
ui.gridLayout->addWidget(label,row,col); |
|
||||||
} |
|
||||||
void UASQuickViewItemSelect::resizeEvent(QResizeEvent *event) |
|
||||||
{ |
|
||||||
Q_UNUSED(event); |
|
||||||
|
|
||||||
/*for (int i=0;i<m_checkBoxList.size();i++)
|
|
||||||
{ |
|
||||||
ui.gridLayout->removeWidget(m_checkBoxList[i]); |
|
||||||
} |
|
||||||
int row = 0; |
|
||||||
int col = 0; |
|
||||||
for (int i=0;i<m_checkBoxList.size();i++) |
|
||||||
{ |
|
||||||
ui.gridLayout->addWidget(m_checkBoxList[i],row,col); |
|
||||||
col++; |
|
||||||
ui.gridLayout->widget()->width() > this->width(); |
|
||||||
//need to reduce column number.
|
|
||||||
|
|
||||||
}*/ |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
void UASQuickViewItemSelect::checkBoxClicked(bool checked) |
|
||||||
{ |
|
||||||
QCheckBox *check = qobject_cast<QCheckBox*>(sender()); |
|
||||||
if (!check) |
|
||||||
{ |
|
||||||
return; |
|
||||||
} |
|
||||||
QString checkval = check->text(); |
|
||||||
if (m_checkboxToValueMap.contains(check)) |
|
||||||
{ |
|
||||||
checkval = m_checkboxToValueMap[check]; |
|
||||||
} |
|
||||||
if (checked) |
|
||||||
{ |
|
||||||
|
|
||||||
emit valueEnabled(checkval); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
emit valueDisabled(checkval); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
UASQuickViewItemSelect::~UASQuickViewItemSelect() |
|
||||||
{ |
|
||||||
} |
|
@ -1,32 +0,0 @@ |
|||||||
#ifndef UASQUICKVIEWITEMSELECT_H |
|
||||||
#define UASQUICKVIEWITEMSELECT_H |
|
||||||
|
|
||||||
#include <QWidget> |
|
||||||
#include <QCheckBox> |
|
||||||
#include "ui_UASQuickViewItemSelect.h" |
|
||||||
|
|
||||||
class UASQuickViewItemSelect : public QWidget |
|
||||||
{ |
|
||||||
Q_OBJECT |
|
||||||
|
|
||||||
public: |
|
||||||
explicit UASQuickViewItemSelect(QWidget *parent = 0); |
|
||||||
~UASQuickViewItemSelect(); |
|
||||||
void addItem(QString item,bool enabled = false); |
|
||||||
int currrow; |
|
||||||
int currcol; |
|
||||||
protected: |
|
||||||
void resizeEvent(QResizeEvent *event); |
|
||||||
private: |
|
||||||
QMap<QString,int> m_categoryToIndexMap; |
|
||||||
QMap<QCheckBox*,QString> m_checkboxToValueMap; |
|
||||||
QList<QCheckBox*> m_checkBoxList; |
|
||||||
Ui::UASQuickViewItemSelect ui; |
|
||||||
private slots: |
|
||||||
void checkBoxClicked(bool checked); |
|
||||||
signals: |
|
||||||
void valueEnabled(QString value); |
|
||||||
void valueDisabled(QString value); |
|
||||||
}; |
|
||||||
|
|
||||||
#endif // UASQUICKVIEWITEMSELECT_H
|
|
@ -1,56 +0,0 @@ |
|||||||
<?xml version="1.0" encoding="UTF-8"?> |
|
||||||
<ui version="4.0"> |
|
||||||
<class>UASQuickViewItemSelect</class> |
|
||||||
<widget class="QWidget" name="UASQuickViewItemSelect"> |
|
||||||
<property name="geometry"> |
|
||||||
<rect> |
|
||||||
<x>0</x> |
|
||||||
<y>0</y> |
|
||||||
<width>947</width> |
|
||||||
<height>248</height> |
|
||||||
</rect> |
|
||||||
</property> |
|
||||||
<property name="windowTitle"> |
|
||||||
<string>Select Item</string> |
|
||||||
</property> |
|
||||||
<layout class="QVBoxLayout" name="verticalLayout"> |
|
||||||
<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>927</width> |
|
||||||
<height>228</height> |
|
||||||
</rect> |
|
||||||
</property> |
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2"> |
|
||||||
<item> |
|
||||||
<layout class="QGridLayout" name="gridLayout"/> |
|
||||||
</item> |
|
||||||
<item> |
|
||||||
<spacer name="verticalSpacer"> |
|
||||||
<property name="orientation"> |
|
||||||
<enum>Qt::Vertical</enum> |
|
||||||
</property> |
|
||||||
<property name="sizeHint" stdset="0"> |
|
||||||
<size> |
|
||||||
<width>20</width> |
|
||||||
<height>40</height> |
|
||||||
</size> |
|
||||||
</property> |
|
||||||
</spacer> |
|
||||||
</item> |
|
||||||
</layout> |
|
||||||
</widget> |
|
||||||
</widget> |
|
||||||
</item> |
|
||||||
</layout> |
|
||||||
</widget> |
|
||||||
<resources/> |
|
||||||
<connections/> |
|
||||||
</ui> |
|
@ -1,165 +0,0 @@ |
|||||||
#include "UASQuickViewTextItem.h" |
|
||||||
#include <QVBoxLayout> |
|
||||||
#include <QDebug> |
|
||||||
UASQuickViewTextItem::UASQuickViewTextItem(QWidget *parent) : UASQuickViewItem(parent) |
|
||||||
{ |
|
||||||
// Set a standard vertical layout.
|
|
||||||
QVBoxLayout* layout = new QVBoxLayout(); |
|
||||||
layout->setMargin(0); |
|
||||||
layout->setSizeConstraint(QLayout::SetMinimumSize); |
|
||||||
|
|
||||||
// Create the title label. Scale the font based on available size.
|
|
||||||
titleLabel = new QLabel(this); |
|
||||||
titleLabel->setAlignment(Qt::AlignHCenter); |
|
||||||
titleLabel->setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Minimum); |
|
||||||
titleLabel->setObjectName(QString::fromUtf8("title")); |
|
||||||
QFont titlefont = titleLabel->font(); |
|
||||||
//titlefont.setPixelSize(this->height() / 4.0);
|
|
||||||
titleLabel->setFont(titlefont); |
|
||||||
layout->addWidget(titleLabel); |
|
||||||
|
|
||||||
// Create the value label. Scale the font based on available size.
|
|
||||||
valueLabel = new QLabel(this); |
|
||||||
valueLabel->setAlignment(Qt::AlignHCenter); |
|
||||||
valueLabel->setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Minimum); |
|
||||||
valueLabel->setObjectName(QString::fromUtf8("value")); |
|
||||||
valueLabel->setText("0.00"); |
|
||||||
QFont valuefont = valueLabel->font(); |
|
||||||
//valuefont.setPixelSize(this->height() / 2.0);
|
|
||||||
valueLabel->setFont(valuefont); |
|
||||||
layout->addWidget(valueLabel); |
|
||||||
|
|
||||||
// And make sure the items are evenly spaced in the UASQuickView.
|
|
||||||
layout->addSpacerItem(new QSpacerItem(10, 0, QSizePolicy::Minimum, QSizePolicy::Expanding)); |
|
||||||
this->setLayout(layout); |
|
||||||
} |
|
||||||
void UASQuickViewTextItem::setValue(double value) |
|
||||||
{ |
|
||||||
if (value < 10 && value > -10) |
|
||||||
{ |
|
||||||
valueLabel->setText(QString::number(value,'f',4)); |
|
||||||
} |
|
||||||
else if (value < 100 && value > -100) |
|
||||||
{ |
|
||||||
valueLabel->setText(QString::number(value,'f',3)); |
|
||||||
} |
|
||||||
else if (value < 1000 && value > -1000) |
|
||||||
{ |
|
||||||
valueLabel->setText(QString::number(value,'f',2)); |
|
||||||
} |
|
||||||
else if (value < 10000 && value > -10000) |
|
||||||
{ |
|
||||||
valueLabel->setText(QString::number(value,'f',1)); |
|
||||||
} |
|
||||||
else
|
|
||||||
{ |
|
||||||
valueLabel->setText(QString::number(value,'f',0)); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void UASQuickViewTextItem::setTitle(QString title) |
|
||||||
{ |
|
||||||
if (title.indexOf(".") != -1 && title.indexOf(":") != -1) |
|
||||||
{ |
|
||||||
titleLabel->setText(title.mid(title.indexOf(".") + 1)); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
titleLabel->setText(title); |
|
||||||
} |
|
||||||
} |
|
||||||
int UASQuickViewTextItem::minValuePixelSize() |
|
||||||
{ |
|
||||||
QFont valuefont = valueLabel->font(); |
|
||||||
QFont titlefont = titleLabel->font(); |
|
||||||
valuefont.setPixelSize(this->height()); |
|
||||||
titlefont.setPixelSize(valuefont.pointSize() * 0.75); |
|
||||||
//spacerItem->setGeometry(QRect(0,0,20,this->height()/10.0));
|
|
||||||
|
|
||||||
QFontMetrics metrics(valuefont); |
|
||||||
//valuefont.setPixelSize(this->height() / 2.0);
|
|
||||||
bool fit = false; |
|
||||||
while (!fit) |
|
||||||
{ |
|
||||||
|
|
||||||
QFontMetrics valfm( valuefont ); |
|
||||||
QRect valbound = valfm.boundingRect(0,0, valueLabel->width(), valueLabel->height(), Qt::TextWordWrap | Qt::AlignLeft, "12345678.00"/*valueLabel->text()*/); |
|
||||||
//QFontMetrics titlefm( titlefont );
|
|
||||||
//QRect titlebound = titlefm.boundingRect(0,0, titleLabel->width(), titleLabel->height(), Qt::TextWordWrap | Qt::AlignLeft, titleLabel->text());
|
|
||||||
|
|
||||||
if ((valbound.width() <= valueLabel->width() && valbound.height() <= valueLabel->height())) // && (titlebound.width() <= titleLabel->width() && titlebound.height() <= titleLabel->height()))
|
|
||||||
fit = true; |
|
||||||
else |
|
||||||
{ |
|
||||||
if (valuefont.pointSize() - 1 <= 6) |
|
||||||
{ |
|
||||||
fit = true; |
|
||||||
valuefont.setPixelSize(6); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
valuefont.setPixelSize(valuefont.pointSize() - 1); |
|
||||||
} |
|
||||||
//titlefont.setPixelSize(valuefont.pointSize() / 2.0);
|
|
||||||
//qDebug() << "Point size:" << valuefont.pointSize() << valueLabel->width() << valueLabel->height();
|
|
||||||
} |
|
||||||
} |
|
||||||
return valuefont.pointSize(); |
|
||||||
} |
|
||||||
void UASQuickViewTextItem::setValuePixelSize(int size) |
|
||||||
{ |
|
||||||
QFont valuefont = valueLabel->font(); |
|
||||||
QFont titlefont = titleLabel->font(); |
|
||||||
valuefont.setPixelSize(size); |
|
||||||
titlefont.setPixelSize(valuefont.pointSize() * 0.75); |
|
||||||
valueLabel->setFont(valuefont); |
|
||||||
titleLabel->setFont(titlefont); |
|
||||||
update(); |
|
||||||
} |
|
||||||
|
|
||||||
void UASQuickViewTextItem::resizeEvent(QResizeEvent *event) |
|
||||||
{ |
|
||||||
Q_UNUSED(event); |
|
||||||
return; |
|
||||||
#if 0 |
|
||||||
// code ifdef'ed out to silence warnings
|
|
||||||
QFont valuefont = valueLabel->font(); |
|
||||||
QFont titlefont = titleLabel->font(); |
|
||||||
valuefont.setPixelSize(this->height()); |
|
||||||
titlefont.setPixelSize(valuefont.pointSize() / 2.0); |
|
||||||
//spacerItem->setGeometry(QRect(0,0,20,this->height()/10.0));
|
|
||||||
|
|
||||||
QFontMetrics metrics(valuefont); |
|
||||||
//valuefont.setPixelSize(this->height() / 2.0);
|
|
||||||
bool fit = false; |
|
||||||
while (!fit) |
|
||||||
{ |
|
||||||
|
|
||||||
QFontMetrics valfm( valuefont ); |
|
||||||
QRect valbound = valfm.boundingRect(0,0, valueLabel->width(), valueLabel->height(), Qt::TextWordWrap | Qt::AlignLeft, valueLabel->text()); |
|
||||||
//QFontMetrics titlefm( titlefont );
|
|
||||||
//QRect titlebound = titlefm.boundingRect(0,0, titleLabel->width(), titleLabel->height(), Qt::TextWordWrap | Qt::AlignLeft, titleLabel->text());
|
|
||||||
|
|
||||||
if ((valbound.width() <= valueLabel->width() && valbound.height() <= valueLabel->height()))// && (titlebound.width() <= titleLabel->width() && titlebound.height() <= titleLabel->height()))
|
|
||||||
fit = true; |
|
||||||
else |
|
||||||
{ |
|
||||||
if (valuefont.pointSize()-5 <= 0) |
|
||||||
{ |
|
||||||
fit = true; |
|
||||||
valuefont.setPixelSize(5); |
|
||||||
} |
|
||||||
else |
|
||||||
{ |
|
||||||
valuefont.setPixelSize(valuefont.pointSize() - 5); |
|
||||||
} |
|
||||||
//titlefont.setPixelSize(valuefont.pointSize() / 2.0);
|
|
||||||
//qDebug() << "Point size:" << valuefont.pointSize() << valueLabel->width() << valueLabel->height();
|
|
||||||
} |
|
||||||
} |
|
||||||
titlefont.setPixelSize(valuefont.pointSize() / 2.0); |
|
||||||
valueLabel->setFont(valuefont); |
|
||||||
titleLabel->setFont(titlefont); |
|
||||||
update(); |
|
||||||
#endif |
|
||||||
} |
|
@ -1,22 +0,0 @@ |
|||||||
#ifndef UASQUICKVIEWTEXTITEM_H |
|
||||||
#define UASQUICKVIEWTEXTITEM_H |
|
||||||
|
|
||||||
#include "UASQuickViewItem.h" |
|
||||||
#include <QLabel> |
|
||||||
#include <QSpacerItem> |
|
||||||
class UASQuickViewTextItem : public UASQuickViewItem |
|
||||||
{ |
|
||||||
public: |
|
||||||
UASQuickViewTextItem(QWidget *parent=0); |
|
||||||
void setValue(double value); |
|
||||||
void setTitle(QString title); |
|
||||||
int minValuePixelSize(); |
|
||||||
void setValuePixelSize(int size); |
|
||||||
protected: |
|
||||||
void resizeEvent(QResizeEvent *event); |
|
||||||
private: |
|
||||||
QLabel *titleLabel; |
|
||||||
QLabel *valueLabel; |
|
||||||
}; |
|
||||||
|
|
||||||
#endif // UASQUICKVIEWTEXTITEM_H
|
|
Loading…
Reference in new issue