航线传输完成

This commit is contained in:
hm
2020-03-18 23:31:54 +08:00
parent 082ed2d316
commit b50977f923
6 changed files with 553 additions and 506 deletions
+114 -117
View File
@@ -1,117 +1,114 @@
#include "mainwindow.h"
//#include "splashscreen.h"
//#include "unit.h"
#include "skin.h"
//#include "appconfig.h"
#include <QApplication>
#include <QTextCodec>
#include <QDesktopWidget>
#include <QScreen>
#include <QDir>
#include <QTranslator>
#include <QDebug>
#include <QTextCodec>
//#include <windows.h>
//#include <winver.h>
//#pragma comment(lib, "Version")
QSize GetDesktopSize() {
#ifdef __arm__
int fb_fd = open("/dev/fb0", O_RDWR);
int lcd_width, lcd_height;
static struct fb_var_screeninfo var;
if(-1 == fb_fd)
{
printf("cat't open /dev/fb0 \n");
return QSize(0, 0);
}
//获取屏幕参数
if(-1 == ioctl(fb_fd, FBIOGET_VSCREENINFO, &var))
{
close(fb_fd);
printf("cat't ioctl /dev/fb0 \n");
return QSize(0, 0);
}
// 计算参数
lcd_width = var.xres;
lcd_height = var.yres;
printf("fb width:%d height:%d \n", lcd_width, lcd_height);
close(fb_fd);
return QSize(lcd_width, lcd_height);
#endif
//return QSize(800, 480);
return QSize(800, 480);
}
void CheckDir(const QString &path) {
QDir dir(path);
if (!dir.exists()) {
dir.mkpath(path);
}
}
void CheckDirs(const QString &path, const QStringList &dirs) {
for (int i = 0; i < dirs.size(); i++) {
CheckDir(path + dirs.at(i));
}
}
#define SoftWareVersion "V1.0.0"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF8"));
//QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF8"));
//QTextCodec::se(QTextCodec::codecForName("UTF8"));
QTranslator * qtTranslator = new QTranslator{};
QString lang = "qt_" + QLocale::system().name();
if (qtTranslator->load(lang, QLibraryInfo::location(QLibraryInfo::TranslationsPath))
&& a.installTranslator(qtTranslator))
{
qDebug() << "Success to load translator " <<lang << " from " << QLibraryInfo::location(QLibraryInfo::TranslationsPath);
}
else
{
qWarning() << "Fail to load translator " <<lang << " from " << QLibraryInfo::location(QLibraryInfo::TranslationsPath);
}
QTranslator * myappTranslator = new QTranslator{};
lang = "SimpleGroundStation_" + QLocale::system().name();
if (myappTranslator->load(lang, QCoreApplication::applicationDirPath())
&& a.installTranslator(myappTranslator))
{
qDebug() << "Success to load translator " <<lang << " from " << QCoreApplication::applicationDirPath();
}
else
{
qWarning() << "Fail to load translator " <<lang << " from " << QCoreApplication::applicationDirPath();
}
w.setWindowTitle(QStringLiteral("GCS New Frame @ %1"));//with version
// 主要是控制HDMI输出,如果是LCD显示,此行无关紧要
w.resize(GetDesktopSize());
w.show();
return a.exec();
}
#include "mainwindow.h"
//#include "splashscreen.h"
//#include "unit.h"
#include "skin.h"
//#include "appconfig.h"
#include <QApplication>
#include <QTextCodec>
#include <QDesktopWidget>
#include <QScreen>
#include <QDir>
#include <QTranslator>
#include <QDebug>
#include <QTextCodec>
//#include <windows.h>
//#include <winver.h>
//#pragma comment(lib, "Version")
QSize GetDesktopSize() {
#ifdef __arm__
int fb_fd = open("/dev/fb0", O_RDWR);
int lcd_width, lcd_height;
static struct fb_var_screeninfo var;
if(-1 == fb_fd)
{
printf("cat't open /dev/fb0 \n");
return QSize(0, 0);
}
//获取屏幕参数
if(-1 == ioctl(fb_fd, FBIOGET_VSCREENINFO, &var))
{
close(fb_fd);
printf("cat't ioctl /dev/fb0 \n");
return QSize(0, 0);
}
// 计算参数
lcd_width = var.xres;
lcd_height = var.yres;
printf("fb width:%d height:%d \n", lcd_width, lcd_height);
close(fb_fd);
return QSize(lcd_width, lcd_height);
#endif
//return QSize(800, 480);
return QSize(800, 480);
}
void CheckDir(const QString &path) {
QDir dir(path);
if (!dir.exists()) {
dir.mkpath(path);
}
}
void CheckDirs(const QString &path, const QStringList &dirs) {
for (int i = 0; i < dirs.size(); i++) {
CheckDir(path + dirs.at(i));
}
}
#define SoftWareVersion "V1.0.0"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF8"));
QTranslator * qtTranslator = new QTranslator{};
QString lang = "qt_" + QLocale::system().name();
if (qtTranslator->load(lang, QLibraryInfo::location(QLibraryInfo::TranslationsPath))
&& a.installTranslator(qtTranslator))
{
qDebug() << "Success to load translator " <<lang << " from " << QLibraryInfo::location(QLibraryInfo::TranslationsPath);
}
else
{
qWarning() << "Fail to load translator " <<lang << " from " << QLibraryInfo::location(QLibraryInfo::TranslationsPath);
}
QTranslator * myappTranslator = new QTranslator{};
lang = "SimpleGroundStation_" + QLocale::system().name();
if (myappTranslator->load(lang, QCoreApplication::applicationDirPath())
&& a.installTranslator(myappTranslator))
{
qDebug() << "Success to load translator " <<lang << " from " << QCoreApplication::applicationDirPath();
}
else
{
qWarning() << "Fail to load translator " <<lang << " from " << QCoreApplication::applicationDirPath();
}
w.setWindowTitle(QStringLiteral("GCS New Frame @ %1"));//with version
// 主要是控制HDMI输出,如果是LCD显示,此行无关紧要
w.resize(GetDesktopSize());
w.show();
return a.exec();
}
+14 -9
View File
@@ -36,18 +36,20 @@ MainWindow::MainWindow(QWidget *parent)
this->height());
QIcon icon;
nav = new QNavigationWidget(this);
nav->setGeometry(0,0,50,this->height());
nav->setRowHeight(50);
nav->addItem(tr("DRV"));
nav->addItem(tr("MAP"));
nav->addItem(tr("CMD"));
nav->addItem(tr("CHK"));
nav->addItem(tr("WAY"));
nav->addItem(tr("MIS"));
nav->addItem(tr("DAT"));
nav->addItem(tr("REP"));
nav->addItem(tr("COM"));
nav->addItem(tr("Flight"),icon);
nav->addItem(tr("Mission"),icon);
nav->addItem(tr("Parameter"),icon);
nav->addItem(tr("Communication"),icon);
nav->addItem(tr("Inspector"),icon);
nav->addItem(tr("Command"),icon);
nav->addItem(tr("Data"),icon);
nav->addItem(tr("Console"),icon);
nav->addItem(tr("SoftSetting"),icon);
connect(nav,SIGNAL(ItemChanged(int)),
this,SLOT(onTabIndexChanged(int)));
@@ -225,6 +227,9 @@ void MainWindow::onTabIndexChanged(const int &index)
}
else if (index == 3)
{
QAction* action;
MAVLinkInspector *inspector = new MAVLinkInspector("mavlink inspector",action,this);
+67 -24
View File
@@ -111,7 +111,7 @@ void MissionProcess::MissionParse(mavlink_message_t msg)
}break;
case MAVLINK_MSG_ID_MISSION_COUNT: {
mavlink_msg_mission_count_decode(&msg,&mission_count);
//qDebug() << "mission_count" << mission_count.count;
qDebug() << "mission_count" << mission_count.count;
mission_status.recieve.isWaitingforCount = false;
}break;
case MAVLINK_MSG_ID_MISSION_REQUEST_INT: {
@@ -124,6 +124,7 @@ void MissionProcess::MissionParse(mavlink_message_t msg)
}break;
case MAVLINK_MSG_ID_MISSION_ITEM_INT: {
mavlink_msg_mission_item_int_decode(&msg,&mission_item_int);
qDebug() << "recieve mission " << mission_item_int.seq;
mission_status.recieve.isWaitingforItem = false;//已经收到航点,不用再等待
}break;
case MAVLINK_MSG_ID_MISSION_ITEM: {
@@ -176,7 +177,7 @@ void MissionProcess::ReadStateMachine(void)
//如果超时,那么重新发一次指令
if((QTime::currentTime().msecsSinceStartOfDay() - time) > 1000)
{
step = 0;
step = 0;//如果超时没有收到就返回上一个步骤
timeout_count ++;
qDebug() << "mission count time out " << timeout_count << "times, retry again";
if(timeout_count > 5)//如果指令发5次还没发出去,那么结束读取,并报错
@@ -191,22 +192,51 @@ void MissionProcess::ReadStateMachine(void)
{
if(mission_status.recieve.isWaitingforCount == false)//收到count
{
qDebug() << "mission count reccieved";
timeout_count = 0;
mission_status.recieve.isWaitingforItem = true;
request_int(0);//读取0点
time = QTime::currentTime().msecsSinceStartOfDay();
mission_status.recieve.isWaitingforItem = true;
step ++;
}
}
}
else if(step ==2)//请求航点
else if(step ==2)//请求航点第0个航点
{
//超过时间
if((QTime::currentTime().msecsSinceStartOfDay() - time) > 1000)
{
timeout_count ++;
qDebug() << "mission request time out " << timeout_count << "times, retry again";
qDebug() << "mission request 0 time out " << timeout_count << "times, retry again";
if(timeout_count > 5)//如果指令发5次还没发出去,那么结束读取,并报错
{
step = 0;
mission_status.m_Mode= Nop_Mode;//切换到什么都不做
timeout_count = 0;
qDebug() << "mission read fail";
}
step = 1;//返回上一个步骤重新请求一次
}
else
{
if(mission_status.recieve.isWaitingforItem == false)
{
timeout_count = 0;
time = QTime::currentTime().msecsSinceStartOfDay();
mission_status.recieve.isWaitingforItem = false;
step ++;
}
}
}
else if(step ==3)//请求航点
{
//超过时间
if((QTime::currentTime().msecsSinceStartOfDay() - time) > 1000)
{
timeout_count ++;
qDebug() << "mission request " << (mission_item_int.seq+1) << " time out " << timeout_count << "times, retry again";
if(timeout_count > 5)//如果指令发5次还没发出去,那么结束读取,并报错
{
step = 0;
@@ -223,10 +253,11 @@ void MissionProcess::ReadStateMachine(void)
//分成两类,int和不带int
if((mission_item_int.seq+1) < mission_count.count)
{
qDebug() << "mission_item_int.seq+1" << (mission_item_int.seq+1);
qDebug() << "request mission_item_int.seq+1" << (mission_item_int.seq+1);
mission_status.recieve.isWaitingforItem = true;
request_int(mission_item_int.seq+1);
timeout_count = 0;
time = QTime::currentTime().msecsSinceStartOfDay();
}
@@ -239,7 +270,7 @@ void MissionProcess::ReadStateMachine(void)
}
}
else if(step == 3)//航线传输结束,发送ack
else if(step == 4)//航线传输结束,发送ack
{
qDebug() << "step" << step << "transmit ok";
@@ -263,6 +294,7 @@ void MissionProcess::WriteStateMachine(void)
{
//向其他线程或者自己读取航点的数量
count(mission_status.transmit.count);//发送count
mission_status.transmit.isWaiteforRequest = true;
time = QTime::currentTime().msecsSinceStartOfDay();
step++;//下一个阶段
}
@@ -294,7 +326,6 @@ void MissionProcess::WriteStateMachine(void)
{
if((QTime::currentTime().msecsSinceStartOfDay() - time) > 1000)
{
step = 3;//返回上一个阶段
timeout_count ++;
if(timeout_count > 5)//如果指令发5次还没发出去,那么结束读取,并报错
{
@@ -302,43 +333,55 @@ void MissionProcess::WriteStateMachine(void)
mission_status.m_Mode = Nop_Mode;
timeout_count = 0;
}
//如果超时了,重新发一次当前航点
mission_status.transmit.isWaiteforRequest = false;
}
else
{
if(mission_status.transmit.isWaiteforRequest == true)//收到Request
if(mission_status.transmit.isWaiteforRequest == false)//收到Request
{
//分成两类,int和不带int
if(mission_item_int.seq < mission_count.count)
{
//item_int(mission_item_int.seq+1);//发送航点
mission_status.transmit.isWaiteforRequest = false;
mission_status.transmit.isWaiteforRequest = true;
time = QTime::currentTime().msecsSinceStartOfDay();
}
else
{
step++;
mission_status.transmit.isWaiteforACK == true;
time = QTime::currentTime().msecsSinceStartOfDay();
}
}
}
}
else if(step == 4)//航线传输结束,等待ack,如果没接收到就算了,超时也结束
else if(step == 3)//航线传输结束,等待ack,如果没接收到就算了,超时也结束
{
//ack();//wait for ack
if((QTime::currentTime().msecsSinceStartOfDay() - time) > 1000)
{
timeout_count ++;
if(timeout_count > 5)//如果指令发5次还没发出去,那么结束读取
{
step = 0;
mission_status.m_Mode = Nop_Mode;
mission_status.transmit.isWaiteforACK = false;
timeout_count = 0;
}
if(mission_status.transmit.isWaiteforACK == true)
{
}
else
{
step = 0;
mission_status.m_Mode = Nop_Mode;
mission_status.transmit.isWaiteforRequest = false;
}
}
else
{
//收到ACK
if(mission_status.transmit.isWaiteforACK == false)
{
step = 0;
mission_status.m_Mode = Nop_Mode;
mission_status.transmit.isWaiteforRequest = false;
}
}
}
}
+2 -2
View File
@@ -18,11 +18,11 @@ class MissionProcess : public QObject
#endif
Q_OBJECT
enum {
enum _modetype {
Nop_Mode = 0,
RecieveMode,
TransmitMode
}_modetype;
};
typedef struct {
+289 -287
View File
@@ -1,287 +1,289 @@
#include "qnavigationwidget.h"
#include <QPainter>
#include <QDebug>
QNavigationWidget::QNavigationWidget(QWidget *parent) : QWidget(parent)
{
backgroundColor = "#E4E4E4";
selectedColor = "#2CA7F8";
rowHeight = 40;
currentIndex = 0;
MouseColor = "#87CEFF";
MouseIndex = -1;
controlBarColor = "#CAE1FF";
controlSlideColor = "#1E90FF";
controlBarWidth = 10;
setMouseTracking(true);
setFixedWidth(150);
}
QNavigationWidget::~QNavigationWidget()
{
}
void QNavigationWidget::addItem(const QString &title)
{
listItems << title;
update();
}
void QNavigationWidget::setWidth(const int &width)
{
setFixedWidth(width);
}
void QNavigationWidget::setBackgroundColor(const QString &color)
{
backgroundColor = color;
update();
}
void QNavigationWidget::setSelectColor(const QString &color)
{
selectedColor = color;
update();
}
void QNavigationWidget::setRowHeight(const int &height)
{
rowHeight = height;
update();
}
void QNavigationWidget::setCurrentIndex(const int &index)
{
currentIndex = index;
update();
}
int QNavigationWidget::Index(void)
{
return currentIndex;
}
void QNavigationWidget::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
// Draw background color.
painter.setPen(Qt::NoPen);
painter.setBrush(QColor(backgroundColor));
painter.drawRect(rect());
if(!isHidden)
{
QPainterPath MenuPath;
MenuPath.addRect(QRect(width() - controlBarWidth,0,controlBarWidth, height()));
painter.setPen("#202020");
painter.fillPath(MenuPath, QColor(controlBarColor));
int h = height()/2;
QPolygon polygon1,polygon2,polygon3,polygon4;
polygon1.setPoints(4,
width() - controlBarWidth,h ,
width(), h - controlBarWidth,
width(), h - 3 * controlBarWidth / 2,
width() - controlBarWidth,h - controlBarWidth / 2);
polygon2.setPoints(4,
width() - controlBarWidth,h ,
width(), h + controlBarWidth,
width(), h + 3 * controlBarWidth / 2,
width() - controlBarWidth,h + controlBarWidth / 2);
polygon3.setPoints(4,
width() - controlBarWidth,h - controlBarWidth ,
width(), h - 2 * controlBarWidth,
width(), h - 5 * controlBarWidth /2,
width() - controlBarWidth,h - 3 * controlBarWidth /2);
polygon4.setPoints(4,
width() - controlBarWidth,h + controlBarWidth ,
width(), h + 2 * controlBarWidth,
width(), h + 5 * controlBarWidth /2,
width() - controlBarWidth,h + 3 * controlBarWidth /2);
QPainterPath SlidePath;
SlidePath.addRegion(polygon1);
SlidePath.addRegion(polygon2);
SlidePath.addRegion(polygon3);
SlidePath.addRegion(polygon4);
painter.fillPath(SlidePath, QColor(controlSlideColor));
// Draw Items
int count = 0;
for (const QString &str : listItems) {
QPainterPath itemPath;
itemPath.addRect(QRect(0, count * rowHeight, width() - controlBarWidth, rowHeight));
if (currentIndex == count) {
painter.setPen("#FFFFFF");
painter.fillPath(itemPath, QColor(selectedColor));
}else {
painter.setPen("#202020");
if(MouseIndex == count)
{
painter.fillPath(itemPath, QColor(MouseColor));
}
else
{
painter.fillPath(itemPath, QColor(backgroundColor));
}
}
painter.drawText(QRect(0, count * rowHeight, width(), rowHeight), Qt::AlignVCenter | Qt::AlignHCenter, str);
++count;
}
//DrawHandle
}
else//隐藏状态
{
QPainterPath MenuPath;
MenuPath.addRect(QRect(0,0,controlBarWidth, height()));
painter.setPen("#202020");
painter.fillPath(MenuPath, QColor(controlBarColor));
int h = height()/2;
QPolygon polygon1,polygon2,polygon3,polygon4;
polygon1.setPoints(4,
controlBarWidth,h ,
0, h - controlBarWidth,
0, h - 3 * controlBarWidth / 2,
controlBarWidth,h - controlBarWidth / 2);
polygon2.setPoints(4,
controlBarWidth,h ,
0, h + controlBarWidth,
0, h + 3 * controlBarWidth / 2,
controlBarWidth,h + controlBarWidth / 2);
polygon3.setPoints(4,
controlBarWidth,h - controlBarWidth ,
0, h - 2 * controlBarWidth,
0, h - 5 * controlBarWidth /2,
controlBarWidth,h - 3 * controlBarWidth /2);
polygon4.setPoints(4,
controlBarWidth,h + controlBarWidth ,
0, h + 2 * controlBarWidth,
0, h + 5 * controlBarWidth /2,
controlBarWidth,h + 3 * controlBarWidth /2);
QPainterPath SlidePath;
SlidePath.addRegion(polygon1);
SlidePath.addRegion(polygon2);
SlidePath.addRegion(polygon3);
SlidePath.addRegion(polygon4);
painter.fillPath(SlidePath, QColor(controlSlideColor));
}
}
void QNavigationWidget::mouseMoveEvent(QMouseEvent *e)
{
if ((e->y() / rowHeight < listItems.count())&&
(e->x() < (width() - controlBarWidth)))
{
MouseIndex = e->y() / rowHeight;
update();
}
else
{
MouseIndex = -1;
update();
}
}
void QNavigationWidget::enterEvent(QEvent *e)
{
qDebug() << e;
}
void QNavigationWidget::leaveEvent(QEvent *e)
{
Q_UNUSED(e);
MouseIndex = -1;
update();
}
void QNavigationWidget::mousePressEvent(QMouseEvent *e)
{
if ((e->y() / rowHeight < listItems.count())&&
(e->x() < (width() - controlBarWidth)))
{
currentIndex = e->y() / rowHeight;
emit ItemChanged(currentIndex);
update();
}
else if((e->x() > (width() - controlBarWidth)) &&
(e->x() < width()) )
{
isHidden = isHidden?false:true;
//qDebug() << isHidden;
if(isHidden){
setWidth(controlBarWidth);
}
else {
setWidth(150);
}
update();
}
}
void QNavigationWidget::mouseReleaseEvent(QMouseEvent *e)
{
}
#include "qnavigationwidget.h"
#include <QPainter>
#include <QDebug>
QNavigationWidget::QNavigationWidget(QWidget *parent) : QWidget(parent)
{
backgroundColor = "#E4E4E4";
selectedColor = "#2CA7F8";
rowHeight = 40;
currentIndex = 0;
MouseColor = "#87CEFF";
MouseIndex = -1;
controlBarColor = "#CAE1FF";
controlSlideColor = "#1E90FF";
controlBarWidth = 10;
setMouseTracking(true);
setFixedWidth(150);
}
QNavigationWidget::~QNavigationWidget()
{
}
void QNavigationWidget::addItem(const QString &title, QIcon &icon)
{
Q_UNUSED(icon);
listItems << title;
update();
}
void QNavigationWidget::setWidth(const int &width)
{
setFixedWidth(width);
}
void QNavigationWidget::setBackgroundColor(const QString &color)
{
backgroundColor = color;
update();
}
void QNavigationWidget::setSelectColor(const QString &color)
{
selectedColor = color;
update();
}
void QNavigationWidget::setRowHeight(const int &height)
{
rowHeight = height;
update();
}
void QNavigationWidget::setCurrentIndex(const int &index)
{
currentIndex = index;
update();
}
int QNavigationWidget::Index(void)
{
return currentIndex;
}
void QNavigationWidget::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
// Draw background color.
painter.setPen(Qt::NoPen);
painter.setBrush(QColor(backgroundColor));
painter.drawRect(rect());
if(!isHidden)
{
QPainterPath MenuPath;
MenuPath.addRect(QRect(width() - controlBarWidth,0,controlBarWidth, height()));
painter.setPen("#202020");
painter.fillPath(MenuPath, QColor(controlBarColor));
int h = height()/2;
QPolygon polygon1,polygon2,polygon3,polygon4;
polygon1.setPoints(4,
width() - controlBarWidth,h ,
width(), h - controlBarWidth,
width(), h - 3 * controlBarWidth / 2,
width() - controlBarWidth,h - controlBarWidth / 2);
polygon2.setPoints(4,
width() - controlBarWidth,h ,
width(), h + controlBarWidth,
width(), h + 3 * controlBarWidth / 2,
width() - controlBarWidth,h + controlBarWidth / 2);
polygon3.setPoints(4,
width() - controlBarWidth,h - controlBarWidth ,
width(), h - 2 * controlBarWidth,
width(), h - 5 * controlBarWidth /2,
width() - controlBarWidth,h - 3 * controlBarWidth /2);
polygon4.setPoints(4,
width() - controlBarWidth,h + controlBarWidth ,
width(), h + 2 * controlBarWidth,
width(), h + 5 * controlBarWidth /2,
width() - controlBarWidth,h + 3 * controlBarWidth /2);
QPainterPath SlidePath;
SlidePath.addRegion(polygon1);
SlidePath.addRegion(polygon2);
SlidePath.addRegion(polygon3);
SlidePath.addRegion(polygon4);
painter.fillPath(SlidePath, QColor(controlSlideColor));
// Draw Items
int count = 0;
for (const QString &str : listItems) {
QPainterPath itemPath;
itemPath.addRect(QRect(0, count * rowHeight, width() - controlBarWidth, rowHeight));
if (currentIndex == count) {
painter.setPen("#FFFFFF");
painter.fillPath(itemPath, QColor(selectedColor));
}else {
painter.setPen("#202020");
if(MouseIndex == count)
{
painter.fillPath(itemPath, QColor(MouseColor));
}
else
{
painter.fillPath(itemPath, QColor(backgroundColor));
}
}
painter.drawText(QRect(0, count * rowHeight, width(), rowHeight), Qt::AlignVCenter | Qt::AlignHCenter, str);
++count;
}
//DrawHandle
}
else//隐藏状态
{
QPainterPath MenuPath;
MenuPath.addRect(QRect(0,0,controlBarWidth, height()));
painter.setPen("#202020");
painter.fillPath(MenuPath, QColor(controlBarColor));
int h = height()/2;
QPolygon polygon1,polygon2,polygon3,polygon4;
polygon1.setPoints(4,
controlBarWidth,h ,
0, h - controlBarWidth,
0, h - 3 * controlBarWidth / 2,
controlBarWidth,h - controlBarWidth / 2);
polygon2.setPoints(4,
controlBarWidth,h ,
0, h + controlBarWidth,
0, h + 3 * controlBarWidth / 2,
controlBarWidth,h + controlBarWidth / 2);
polygon3.setPoints(4,
controlBarWidth,h - controlBarWidth ,
0, h - 2 * controlBarWidth,
0, h - 5 * controlBarWidth /2,
controlBarWidth,h - 3 * controlBarWidth /2);
polygon4.setPoints(4,
controlBarWidth,h + controlBarWidth ,
0, h + 2 * controlBarWidth,
0, h + 5 * controlBarWidth /2,
controlBarWidth,h + 3 * controlBarWidth /2);
QPainterPath SlidePath;
SlidePath.addRegion(polygon1);
SlidePath.addRegion(polygon2);
SlidePath.addRegion(polygon3);
SlidePath.addRegion(polygon4);
painter.fillPath(SlidePath, QColor(controlSlideColor));
}
}
void QNavigationWidget::mouseMoveEvent(QMouseEvent *e)
{
if ((e->y() / rowHeight < listItems.count())&&
(e->x() < (width() - controlBarWidth)))
{
MouseIndex = e->y() / rowHeight;
update();
}
else
{
MouseIndex = -1;
update();
}
}
void QNavigationWidget::enterEvent(QEvent *e)
{
qDebug() << e;
}
void QNavigationWidget::leaveEvent(QEvent *e)
{
Q_UNUSED(e);
MouseIndex = -1;
update();
}
void QNavigationWidget::mousePressEvent(QMouseEvent *e)
{
if ((e->y() / rowHeight < listItems.count())&&
(e->x() < (width() - controlBarWidth)))
{
currentIndex = e->y() / rowHeight;
emit ItemChanged(currentIndex);
update();
}
else if((e->x() > (width() - controlBarWidth)) &&
(e->x() < width()) )
{
isHidden = isHidden?false:true;
//qDebug() << isHidden;
if(isHidden){
setWidth(controlBarWidth);
}
else {
setWidth(150);
}
update();
}
}
void QNavigationWidget::mouseReleaseEvent(QMouseEvent *e)
{
}
+67 -67
View File
@@ -1,67 +1,67 @@
#ifndef QNAVIGATIONWIDGET_H
#define QNAVIGATIONWIDGET_H
#include <QWidget>
#include <QMouseEvent>
#pragma execution_character_set("utf-8")
#ifdef QNavigation
#include <qnavigantionglobal.h>
class QNAVGATIONSHARED_EXPORT QNavigationWidget : public QWidget {
#else
class QNavigationWidget : public QWidget
{
#endif
Q_OBJECT
public:
QNavigationWidget(QWidget *parent=nullptr);
~QNavigationWidget();
void addItem(const QString &title);
void setWidth(const int &width);
void setBackgroundColor(const QString &color);
void setSelectColor(const QString &color);
void setRowHeight(const int &height);
void setCurrentIndex(const int &index);
int Index(void);
signals:
void ItemChanged(const int &index);
protected:
void paintEvent(QPaintEvent *);
void mouseMoveEvent(QMouseEvent *);
void mousePressEvent(QMouseEvent *);
void mouseReleaseEvent(QMouseEvent *);
void enterEvent(QEvent *);
void leaveEvent(QEvent *);
private:
QList<QString> listItems;
QString backgroundColor;
QString selectedColor;
QString MouseColor;
QString controlBarColor;
QString controlSlideColor;
int controlBarWidth = 10;
int rowHeight;
int currentIndex;
int MouseIndex;
bool isHidden = false;
};
#endif
#ifndef QNAVIGATIONWIDGET_H
#define QNAVIGATIONWIDGET_H
#include <QWidget>
#include <QMouseEvent>
#pragma execution_character_set("utf-8")
#ifdef QNavigation
#include <qnavigantionglobal.h>
class QNAVGATIONSHARED_EXPORT QNavigationWidget : public QWidget {
#else
class QNavigationWidget : public QWidget
{
#endif
Q_OBJECT
public:
QNavigationWidget(QWidget *parent=nullptr);
~QNavigationWidget();
void addItem(const QString &title, QIcon &icon);
void setWidth(const int &width);
void setBackgroundColor(const QString &color);
void setSelectColor(const QString &color);
void setRowHeight(const int &height);
void setCurrentIndex(const int &index);
int Index(void);
signals:
void ItemChanged(const int &index);
protected:
void paintEvent(QPaintEvent *);
void mouseMoveEvent(QMouseEvent *);
void mousePressEvent(QMouseEvent *);
void mouseReleaseEvent(QMouseEvent *);
void enterEvent(QEvent *);
void leaveEvent(QEvent *);
private:
QList<QString> listItems;
QString backgroundColor;
QString selectedColor;
QString MouseColor;
QString controlBarColor;
QString controlSlideColor;
int controlBarWidth = 10;
int rowHeight;
int currentIndex;
int MouseIndex;
bool isHidden = false;
};
#endif