Commit 08abea5b authored by DonLakeFlyer's avatar DonLakeFlyer

Remove InfoView widget

parent 60cec130
......@@ -353,13 +353,9 @@ FORMS += \
src/ui/QGCMAVLinkInspector.ui \
src/ui/QGCMAVLinkLogPlayer.ui \
src/ui/QGCMapRCToParamDialog.ui \
src/ui/QGCTabbedInfoView.ui \
src/ui/QGCUASFileView.ui \
src/ui/QGCUASFileViewMulti.ui \
src/ui/uas/QGCUnconnectedInfoWidget.ui \
src/ui/uas/UASMessageView.ui \
src/ui/uas/UASQuickView.ui \
src/ui/uas/UASQuickViewItemSelect.ui \
}
#
......@@ -618,7 +614,6 @@ HEADERS += \
src/ui/QGCMAVLinkInspector.h \
src/ui/QGCMAVLinkLogPlayer.h \
src/ui/QGCMapRCToParamDialog.h \
src/ui/QGCTabbedInfoView.h \
src/ui/QGCUASFileView.h \
src/ui/QGCUASFileViewMulti.h \
src/ui/linechart/ChartPlot.h \
......@@ -629,12 +624,6 @@ HEADERS += \
src/ui/linechart/ScrollZoomer.h \
src/ui/linechart/Scrollbar.h \
src/ui/uas/QGCUnconnectedInfoWidget.h \
src/ui/uas/UASMessageView.h \
src/ui/uas/UASQuickView.h \
src/ui/uas/UASQuickViewGaugeItem.h \
src/ui/uas/UASQuickViewItem.h \
src/ui/uas/UASQuickViewItemSelect.h \
src/ui/uas/UASQuickViewTextItem.h \
}
iOSBuild {
......@@ -782,7 +771,6 @@ SOURCES += \
src/ui/QGCMAVLinkInspector.cc \
src/ui/QGCMAVLinkLogPlayer.cc \
src/ui/QGCMapRCToParamDialog.cpp \
src/ui/QGCTabbedInfoView.cpp \
src/ui/QGCUASFileView.cc \
src/ui/QGCUASFileViewMulti.cc \
src/ui/linechart/ChartPlot.cc \
......@@ -793,12 +781,6 @@ SOURCES += \
src/ui/linechart/ScrollZoomer.cc \
src/ui/linechart/Scrollbar.cc \
src/ui/uas/QGCUnconnectedInfoWidget.cc \
src/ui/uas/UASMessageView.cc \
src/ui/uas/UASQuickView.cc \
src/ui/uas/UASQuickViewGaugeItem.cc \
src/ui/uas/UASQuickViewItem.cc \
src/ui/uas/UASQuickViewItemSelect.cc \
src/ui/uas/UASQuickViewTextItem.cc \
}
# Palette test widget in debug builds
......
......@@ -45,8 +45,6 @@
#ifndef __mobile__
#include "Linecharts.h"
#include "QGCUASFileViewMulti.h"
#include "UASQuickView.h"
#include "QGCTabbedInfoView.h"
#include "CustomCommandWidget.h"
#include "QGCDockWidget.h"
#include "HILDockWidget.h"
......@@ -69,7 +67,7 @@ enum DockWidgetTypes {
MAVLINK_INSPECTOR,
CUSTOM_COMMAND,
ONBOARD_FILES,
INFO_VIEW,
DEPRECATED_WIDGET,
HIL_CONFIG,
ANALYZE
};
......@@ -78,7 +76,7 @@ static const char *rgDockWidgetNames[] = {
"MAVLink Inspector",
"Custom Command",
"Onboard Files",
"Info View",
"Deprecated Widget",
"HIL Config",
"Analyze"
};
......@@ -367,12 +365,6 @@ bool MainWindow::_createInnerDockWidget(const QString& widgetName)
case ANALYZE:
widget = new Linecharts(widgetName, action, mavlinkDecoder, this);
break;
case INFO_VIEW:
widget= new QGCTabbedInfoView(widgetName, action, this);
break;
}
if(action->data().toInt() == INFO_VIEW) {
qobject_cast<QGCTabbedInfoView*>(widget)->addSource(mavlinkDecoder);
}
if(widget) {
_mapName2DockWidget[widgetName] = widget;
......
#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()
{
}
#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
<?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>
/****************************************************************************
*
* (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);
}
}
/****************************************************************************
*
* (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
<?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>
This diff is collapsed.
#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
<?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>
#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();
}
#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
#include "UASQuickViewItem.h"
UASQuickViewItem::UASQuickViewItem(QWidget *parent) :
QWidget(parent)
{
}
#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
#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()
{
}
#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
<?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>
#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
}
#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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment