界面绘制完成

This commit is contained in:
hm
2022-04-01 21:37:32 +08:00
parent 98a02885ce
commit 7492424716
8 changed files with 571 additions and 506 deletions
+6 -2
View File
@@ -48,7 +48,9 @@ SOURCES += $$PWD/mapgraphicitem.cpp \
$$PWD/traillineitem.cpp \
$$PWD/waypointline.cpp \
$$PWD/waypointcircle.cpp \
$$PWD/AltitudeItem.cpp
$$PWD/AltitudeItem.cpp \
waypointbutton.cpp \
waypointsetting.cpp
HEADERS += $$PWD/mapgraphicitem.h \
$$PWD/opmapwidget.h \
@@ -66,7 +68,9 @@ HEADERS += $$PWD/mapgraphicitem.h \
$$PWD/waypointline.h \
$$PWD/waypointcircle.h \
$$PWD/mapwidgetglobal.h \
$$PWD/AltitudeItem.h
$$PWD/AltitudeItem.h \
waypointbutton.h \
waypointsetting.h
RESOURCES += mapresources.qrc
+3 -1
View File
@@ -105,6 +105,9 @@ OPMapWidget::OPMapWidget(QWidget *parent, Configuration *config) : QGraphicsView
altitudeitem->hide();
waypointsetting = new WayPointSetting(map,QColor("#a39d9c"));
waypointsetting->setParentItem(map);
NoOperationTimer = new QTimer(this);
connect(NoOperationTimer,SIGNAL(timeout()),
@@ -1234,7 +1237,6 @@ void OPMapWidget::setWPCreate(bool const & value)
}
if(altitudeitem)
{
if(value)
+9
View File
@@ -53,6 +53,11 @@
#include <QTranslator>
#include "waypointbutton.h"
#include "waypointsetting.h"
namespace mapcontrol {
#ifdef QtopmapWidget
@@ -379,6 +384,10 @@ public:
AltitudeItem *altitudeitem;
WayPointSetting *waypointsetting;
void SetShowUAV(bool const & value);
bool ShowUAV() const
{
+197
View File
@@ -0,0 +1,197 @@
#include "waypointbutton.h"
namespace mapcontrol {
WayPointButton::WayPointButton(MapGraphicItem *parent) : myMap(parent)
{
this->setAcceptHoverEvents(true);
this->setFlag(QGraphicsItem::ItemIsMovable, true);
this->setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
this->setFlag(QGraphicsItem::ItemIsSelectable, false);
this->setAcceptedMouseButtons(Qt::LeftButton);
connect(parent, SIGNAL(childRefreshPosition()), this, SLOT(RefreshPos()));
connect(parent, SIGNAL(childSetOpacity(qreal)), this, SLOT(setOpacitySlot(qreal)));
this->setZValue(8);//在幕布上面
position.setX(0);
position.setY(0);
position.setWidth(100);
position.setHeight(100);
}
QRectF WayPointButton::boundingRect() const //鼠标可以操作的大小
{
return QRectF(0,0,position.width(),position.height());
}
void WayPointButton::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
painter->setRenderHint(QPainter::Antialiasing, true);
QPen ePen;
ePen.setWidth(1);
QFont font;
font.setPixelSize(15);//不随着屏幕分辨率改变而改变
font.setFamily("Arial");//非衬线
painter->setFont(font);
//画底部
painter->save();
ePen.setColor(QColor("#2EFE64"));
painter->setPen(ePen);
painter->setBrush(QColor("#2EFE64"));
painter->setOpacity(opacity);
painter->drawRoundedRect(0,0,this->boundingRect().width(),this->boundingRect().height(),10,10);
painter->restore();
painter->save();
ePen.setColor(QColor("#000000"));
painter->setPen(ePen);
painter->drawText(0,0,this->boundingRect().width(),this->boundingRect().height(),Qt::AlignCenter,text);
painter->restore();
}
void WayPointButton::RefreshPos()
{
this->setPos(position.x(),
position.y());
}
void WayPointButton::setOpacitySlot(qreal opacity)
{
setOpacity(opacity);
}
void WayPointButton::setPosition(int x,int y)
{
position.setX(x);
position.setY(y);
RefreshPos();
update();
}
void WayPointButton::resize(int width,int height)
{
position.setWidth(width);
position.setHeight(height);
RefreshPos();
update();
}
void WayPointButton::setGeometry(QRect rect)
{
position.setX(rect.x());
position.setY(rect.y());
position.setWidth(rect.width());
position.setHeight(rect.height());
update();
}
void WayPointButton::setGeometry(int x,int y,int w,int h)
{
position.setX(x);
position.setY(y);
position.setWidth(w);
position.setHeight(h);
update();
}
void WayPointButton::setText(QString t)
{
text = t;
update();
}
QString WayPointButton::Text(void)
{
return text;
}
void WayPointButton::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
event->accept();
qDebug() << "press";
if (event->button() == Qt::LeftButton) {
isDragging = true;
}
}
void WayPointButton::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
event->accept();
qDebug() << "release";
if (event->button() == Qt::LeftButton) {
isDragging = false;
}
}
void WayPointButton::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
event->accept();
qDebug() << "double clicked";
if (event->button() == Qt::LeftButton) {
}
}
void WayPointButton::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
event->accept();
if (isDragging) {
}
}
void WayPointButton::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
event->accept();
qDebug() << "enter";
opacity = 0.8;
update();
}
void WayPointButton::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
event->accept();
qDebug() << "leave";
opacity = 0.5;
update();
}
void WayPointButton::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{
event->accept();
qDebug() << "move";
}
}
+80
View File
@@ -0,0 +1,80 @@
#ifndef WAYPOINTBUTTON_H
#define WAYPOINTBUTTON_H
#include <QGraphicsItem>
#include <QPainter>
#include <QLabel>
#include "pointlatlng.h"
#include "mapgraphicitem.h"
#include "waypointitem.h"
#include <QObject>
#include <QPoint>
#include <QGraphicsSceneMouseEvent>
namespace mapcontrol {
//class OPMapWidget;
#ifdef QtopmapWidget
#include <mapwidgetglobal.h>
class OPMAPWIDGETSHARED_EXPORT WayPointButton : public QObject, public QGraphicsItem {
#else
class WayPointButton : public QObject, public QGraphicsItem {
#endif
Q_OBJECT Q_INTERFACES(QGraphicsItem)
public:
WayPointButton(MapGraphicItem *parent);
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
private:
MapGraphicItem *myMap;
QColor myColor;
bool isDragging;
qreal opacity = 0.5;
QRect position;
QString text;
protected:
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
public slots:
void setPosition(int x,int y);
void resize(int width,int height);
void setGeometry(QRect rect);
void setGeometry(int x,int y,int w,int h);
void RefreshPos();
void setOpacitySlot(qreal opacity);
void setText(QString t);
QString Text(void);
};
} //NAME SPACE
#endif // WAYPOINTBUTTON_H
+192
View File
@@ -0,0 +1,192 @@
#include "waypointsetting.h"
namespace mapcontrol {
WayPointSetting::WayPointSetting(MapGraphicItem *map, QColor background) : myMap(map), myColor(background)
{
this->setAcceptHoverEvents(true);
this->setFlag(QGraphicsItem::ItemIsMovable, true);
this->setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
this->setFlag(QGraphicsItem::ItemIsSelectable, false);
this->setFlag(QGraphicsItem::ItemIsFocusable,false);
connect(map, SIGNAL(childRefreshPosition()), this, SLOT(RefreshPos()));
connect(map, SIGNAL(childSetOpacity(qreal)), this, SLOT(setOpacitySlot(qreal)));
this->setZValue(7);
btn_load = new WayPointButton(map);
btn_load->setParentItem(this);
btn_load->setGeometry(10,10,80,80);
btn_load->setText(tr("Load"));
btn_save = new WayPointButton(map);
btn_save->setParentItem(this);
btn_save->setGeometry(110,10,80,80);
btn_save->setText(tr("Save"));
btn_upload = new WayPointButton(map);
btn_upload->setParentItem(this);
btn_upload->setGeometry(10,100,80,80);
btn_upload->setText(tr("Upload"));
btn_download = new WayPointButton(map);
btn_download->setParentItem(this);
btn_download->setGeometry(110,100,80,80);
btn_download->setText(tr("Download"));
btn_insert = new WayPointButton(map);
btn_insert->setParentItem(this);
btn_insert->setGeometry(10,190,80,80);
btn_insert->setText(tr("insert"));
btn_delete = new WayPointButton(map);
btn_delete->setParentItem(this);
btn_delete->setGeometry(110,190,80,80);
btn_delete->setText(tr("delete"));
btn_last = new WayPointButton(map);
btn_last->setParentItem(this);
btn_last->setGeometry(10,280,80,80);
btn_last->setText(tr("last"));
btn_next = new WayPointButton(map);
btn_next->setParentItem(this);
btn_next->setGeometry(110,280,80,80);
btn_next->setText(tr("next"));
btn_ruler = new WayPointButton(map);
btn_ruler->setParentItem(this);
btn_ruler->setGeometry(10,370,80,80);
btn_ruler->setText(tr("ruler"));
btn_table = new WayPointButton(map);
btn_table->setParentItem(this);
btn_table->setGeometry(110,370,80,80);
btn_table->setText(tr("table"));
}
QRectF WayPointSetting::boundingRect() const //鼠标可以操作的大小
{
return QRectF(0,0,200,460);
}
void WayPointSetting::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
painter->setRenderHint(QPainter::Antialiasing, true);
QPen ePen;
ePen.setWidth(1);
QFont font;
font.setPixelSize(15);//不随着屏幕分辨率改变而改变
font.setFamily("Arial");//非衬线
painter->setFont(font);
//画底部
painter->save();
ePen.setColor(myColor);
painter->setPen(ePen);
painter->setBrush(myColor);//QColor("#a39d9c"));
painter->setOpacity(opacity);
painter->drawRect(0,0,this->boundingRect().width(),this->boundingRect().height());
painter->restore();
}
void WayPointSetting::RefreshPos()
{
this->setPos(0,
0);
}
void WayPointSetting::setOpacitySlot(qreal opacity)
{
setOpacity(opacity);
}
void WayPointSetting::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
event->accept();
if (event->button() == Qt::LeftButton) {
isDragging = true;
}
}
void WayPointSetting::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
event->accept();
if (event->button() == Qt::LeftButton) {
isDragging = false;
}
}
void WayPointSetting::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
event->accept();
if (event->button() == Qt::LeftButton) {
}
}
void WayPointSetting::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
event->accept();
if (isDragging) {
}
}
void WayPointSetting::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
event->accept();
opacity = 0.6;
update();
}
void WayPointSetting::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
event->accept();
opacity = 0.2;
update();
}
void WayPointSetting::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{
event->accept();
}
}
+84
View File
@@ -0,0 +1,84 @@
#ifndef WAYPOINTSETTING_H
#define WAYPOINTSETTING_H
#include <QGraphicsItem>
#include <QPainter>
#include <QLabel>
#include "pointlatlng.h"
#include "mapgraphicitem.h"
#include "waypointitem.h"
#include <QObject>
#include <QPoint>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsSceneHoverEvent>
#include "waypointbutton.h"
namespace mapcontrol {
//class OPMapWidget;
#ifdef QtopmapWidget
#include <mapwidgetglobal.h>
class OPMAPWIDGETSHARED_EXPORT WayPointSetting : public QObject, public QGraphicsItem {
#else
class WayPointSetting : public QObject, public QGraphicsItem {
#endif
Q_OBJECT Q_INTERFACES(QGraphicsItem)
public:
WayPointSetting(MapGraphicItem *map, QColor background = Qt::green);
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
private:
MapGraphicItem *myMap;
QColor myColor;
bool isDragging;
qreal opacity = 0.2;
WayPointButton *btn_load;
WayPointButton *btn_save;
WayPointButton *btn_upload;
WayPointButton *btn_download;
WayPointButton *btn_insert;
WayPointButton *btn_delete;
WayPointButton *btn_last;
WayPointButton *btn_next;
WayPointButton *btn_ruler;
WayPointButton *btn_table;
protected:
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
public slots:
void RefreshPos();
void setOpacitySlot(qreal opacity);
};
} //NAME SPACE
#endif // WAYPOINTSETTING_H
-503
View File
@@ -1,503 +0,0 @@
import QtQuick 2.6
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.3
import QtQuick.Templates 2.5
import QtQuick.Dialogs 1.2
import QtGraphicalEffects 1.0
import Qt.labs.calendar 1.0
import QtQuick.Dialogs.qml 1.0
import QtQuick.Window 2.10
import "MissionManager"
Rectangle {
id:root
visible: true
x:0
y:0
width: 280
height: 320
color: "#fbfdca"
antialiasing: true
property int number : 1
property bool isSettingCategory: false
property bool isFirst: true
property var json: {
"comment": "",
"id": 0,
"rawName": "",
"friendlyName": "null",
"description": "",
"specifiesCoordinate": true,
"friendlyEdit": true,
"category": "",
"param1": {
"label": "",
"units": "",
"default": 0,
"decimalPlaces": 0
},
"param2": {
"label": "",
"units": "",
"default": 3,
"decimalPlaces": 2
},
"param3": {
"label": "",
"units": "",
"default": 0,
"decimalPlaces": 0
},
"param4": {
"label": "",
"units": "",
"nanUnchanged": true,
"default": 0,
"decimalPlaces": 0
},
"param5": {
"label": "",
"default": 0,
"decimalPlaces": 0
},
"param6": {
"label": "",
"default": 0,
"decimalPlaces": 0
},
"param7": {
"label": "",
"default": 0,
"decimalPlaces": 0
}
}
onJsonChanged: {
if(isFirst == true)
{
//jsonModel.remove(0)
jsonModel.clear()
jsonModel.set(0,json)
isFirst = false
}
else
{
jsonModel.append(json)
//console.log(json)
}
}
property ListModel model : ListModel { id: jsonModel }//总的模型
property var paraJson: {
"label": "",
"units": "",
"defaultValue": 3,
"decimalPlaces": 2
}
onParaJsonChanged: {
paramModel.append(paraJson)
}
property ListModel _paramModel : ListModel { id: paramModel }//参数的模型
Rectangle {
id: last
x: 8
y: 8
width: 32
height: 27
color: "#bbf4b6"
radius: 5
clip: true
antialiasing: true
MouseArea {
clip: true
hoverEnabled: true
anchors.fill: parent
onEntered: {
parent.color = "#22fd0e"
}
onExited: {
parent.color = "#bbf4b6"
}
//请求读取上一个航点的属性
}
Triangle {
x: 5
y: 4
width: 20
height: 20
direction: "reverse"
color: "#b344fb"
clip: true
border: 0
}
}
Rectangle {
id: next
x: 238
y: 8
width: 32
height: 27
color: "#bbf4b6"
radius: 5
clip: true
antialiasing: true
MouseArea {
clip: true
hoverEnabled: true
anchors.fill: parent
onEntered: {
parent.color = "#22fd0e"
}
onExited: {
parent.color = "#bbf4b6"
}
//请求读取下一个航点的属性
}
Triangle {
id: triangle
x: 7
y: 4
width: 20
height: 20
color: "#b344fb"
clip: true
}
}
Rectangle {
id: seq
x: 46
y: 8
width: 54
height: 27
color: "#b7f3f0"
radius: 5
clip: true
antialiasing: true
Text {
id: seq_text
text: number
font.family: "Arial"
clip: true
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
anchors.fill: parent
font.pixelSize: 12
}
MouseArea {
id: mouseArea
clip: true
hoverEnabled: true
anchors.fill: parent
onEntered: {
parent.color = "#48fcf2"
}
onExited: {
parent.color = "#b7f3f0"
}
}
}
Rectangle {
id: mav_cmd
x: 106
y: 8
width: 126
height: 27
color: "#bae5b4"
radius: 5
clip: true
antialiasing: true
Text {
id: mav_cmd_text
text: ""
clip: true
anchors.rightMargin: 0
anchors.bottomMargin: 0
anchors.leftMargin: 0
anchors.topMargin: 0
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
anchors.fill: parent
font.pixelSize: 12
onTextChanged: {
//console.log(text)
//console.log(jsonModel.get(0).friendlyName)
}
}
MouseArea {
clip: true
hoverEnabled: true
anchors.fill: parent
onEntered: {
cursorShape = Qt.PointingHandCursor
parent.color = "#e0fb88"
}
onExited: {
cursorShape = Qt.ArrowCursor
parent.color = "#bae5b4"
}
onClicked: {
//请求所有CMD,并显示
isSettingCategory = true
//console.log(json.toString())
}
}
}
Rectangle {
x: 106
y: 41
width: 167
height: 147
color: "#ffffff"
radius: 9
clip: true
Rectangle {
id: rectangle
color: "#eedbfe"
radius: 10
anchors.bottomMargin: 8
anchors.topMargin: 8
anchors.rightMargin: 8
anchors.leftMargin: 8
anchors.fill: parent
visible: isSettingCategory?(false):(true)
ListView {
id : param_listView
anchors.bottomMargin: 8
anchors.topMargin: 8
anchors.rightMargin: 8
anchors.leftMargin: 8
anchors.fill: parent
model: paramModel
delegate: paramDelegate
spacing: 5
clip: true
focus: true
RadioButton {
id: radioButton
x: 0
y: 15
width: 172
height: 61
text: qsTr("Radio Button")
}
}
Component {
id: paramDelegate
Rectangle {
id: rect_param1
x: 8
y: 8
width: 233
height: 34
color: "#ffffff"
radius: 6
Label {
x: 3
y: 7
width: 47
height: 21
text: label
font.pointSize: 12
font.family: "Arial"
}
Label {
x: 180
y: 8
text: units
font.pointSize: 12
font.family: "Arial"
}
TextEdit {
id: textEdit
x: 56
y: 7
width: 129
height: 21
text: defaultValue
visible: true
clip: false
cursorVisible: false
overwriteMode: false
persistentSelection: true
selectByMouse: true
antialiasing: true
font.family: "Arial"
font.bold: true
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
font.pixelSize: 13
}
}
}
}
ListView {
id : m_listView
anchors.bottomMargin: 8
anchors.topMargin: 8
anchors.rightMargin: 8
anchors.leftMargin: 8
anchors.fill: parent
model: jsonModel
delegate: numberDelegate
spacing: 5
clip: true
focus: true
visible: isSettingCategory
}
Component {
id: numberDelegate
Rectangle {
width: ListView.view.width
height: ListView.isCurrentItem?100:40
color: ListView.isCurrentItem?"#157efb":"#53d769"
border.color: Qt.lighter(color, 1.1)
radius: 10
Text {
id:friendlyNameText
anchors.top: parent.top
anchors.horizontalCenter: parent.horizontalCenter
anchors.topMargin: 10
font.pixelSize: 10
text: (friendlyName == null)?(rawName):(friendlyName)
}
TextArea {
id:descriptionText
anchors.top:friendlyNameText.bottom
anchors.horizontalCenter: parent.horizontalCenter
anchors.left: parent.left
anchors.topMargin: 10
anchors.leftMargin: 10
anchors.rightMargin: 10
width: parent.width
height: parent.height - friendlyNameText.height
visible: (parent.height == 100)?true:false
font.pixelSize: 10
text: (description == null)?(""):(description)
}
MouseArea {
anchors.rightMargin: -50
hoverEnabled: true
anchors.fill: parent
onClicked:{
m_listView.currentIndex = index //实现item切换
isSettingCategory = false
mav_cmd_text.text = friendlyNameText.text
paraJson = jsonModel.get(index)
}
onEntered: {
descriptionText.visible = true
m_listView.currentIndex = index //实现item切换
mav_cmd_text.text = friendlyNameText.text
}
onExited: {
descriptionText.visible = false
mav_cmd_text.text = friendlyNameText.text
}
}
}
}
}
RadioButton {
id: radioButton1
x: 32
y: 223
width: 51
height: 42
text: qsTr("Radio Button")
}
}