虚拟示波器,要使用Qchart进行处理
This commit is contained in:
@@ -6,9 +6,31 @@ Scope::Scope(QWidget *parent) :
|
||||
ui(new Ui::Scope)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
|
||||
virtualscope = new VirtualScope(this);
|
||||
virtualscope->setGeometry(ui->frame->geometry());
|
||||
virtualscope->show();
|
||||
}
|
||||
|
||||
Scope::~Scope()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
void Scope::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
|
||||
virtualscope->setGeometry(ui->frame->geometry());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define SCOPE_H
|
||||
|
||||
#include <QWidget>
|
||||
#include "VirtualScope.h"
|
||||
|
||||
namespace Ui {
|
||||
class Scope;
|
||||
@@ -15,8 +16,16 @@ public:
|
||||
explicit Scope(QWidget *parent = nullptr);
|
||||
~Scope();
|
||||
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
|
||||
private:
|
||||
Ui::Scope *ui;
|
||||
|
||||
VirtualScope *virtualscope = nullptr;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // SCOPE_H
|
||||
|
||||
@@ -7,10 +7,12 @@ FORMS += \
|
||||
$$PWD/Scope.ui
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/Scope.h
|
||||
$$PWD/Scope.h \
|
||||
$$PWD/VirtualScope.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/Scope.cpp
|
||||
$$PWD/Scope.cpp \
|
||||
$$PWD/VirtualScope.cpp
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -6,13 +6,37 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>585</width>
|
||||
<height>313</height>
|
||||
<width>658</width>
|
||||
<height>409</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
#include "VirtualScope.h"
|
||||
|
||||
|
||||
|
||||
VirtualScope::VirtualScope(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
VirtualScope::~VirtualScope()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void VirtualScope::mouseReleaseEvent(QMouseEvent *e)
|
||||
{
|
||||
qDebug() << "VirtualScope release" << e;
|
||||
}
|
||||
|
||||
void VirtualScope::mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
qDebug() << "VirtualScope press" << e;
|
||||
}
|
||||
|
||||
void VirtualScope::mouseDoubleClickEvent(QMouseEvent *e)
|
||||
{
|
||||
qDebug() << "VirtualScope double clicked" << e;
|
||||
}
|
||||
|
||||
void VirtualScope::wheelEvent(QWheelEvent *e)
|
||||
{
|
||||
qDebug() << e;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void VirtualScope::paintEvent(QPaintEvent *)
|
||||
{
|
||||
//qreal scale = 4000.0;
|
||||
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing); /* 使用反锯齿(如果可用) */
|
||||
painter.setRenderHint(QPainter::TextAntialiasing);
|
||||
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||
|
||||
painter.translate(width() / 2, height() / 2); /* 坐标变换为窗体中心 */
|
||||
//int side = qMin(width(), height()); /* 这一句决定了这个模块只能是方形 */
|
||||
//painter.scale(side / scale, side / scale); /* 比例缩放 */
|
||||
painter.setPen(Qt::NoPen);
|
||||
|
||||
drawBackground(&painter);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void VirtualScope::drawBackground(QPainter *painter)
|
||||
{
|
||||
QPen pen;
|
||||
QFont font;
|
||||
|
||||
float w = width();
|
||||
float h = height();
|
||||
|
||||
//画大黑背景
|
||||
painter->save();
|
||||
painter->setBrush(Qt::black);
|
||||
painter->drawRect(-w/2,-h/2,w,h);
|
||||
painter->restore();
|
||||
|
||||
|
||||
//画坐标系
|
||||
painter->save();
|
||||
|
||||
//painter->translate(-200,0);
|
||||
|
||||
//水平,垂直虚线
|
||||
pen.setColor(QColor("#FFFFFF"));
|
||||
pen.setWidthF(1);
|
||||
painter->setPen(pen);
|
||||
|
||||
font.setPointSize(15);
|
||||
font.setFamily("Arial");//非衬线
|
||||
painter->setFont(font);
|
||||
|
||||
//水平分成8个格,竖直分成10个格
|
||||
float g_h = (h - 50)/8;
|
||||
float g_w = (w - 50)/10;
|
||||
|
||||
for(int i = -4;i <= 4;i++)
|
||||
{
|
||||
painter->drawLine(-(w - 50)/2,g_h * i,(w - 50)/2,g_h * i);
|
||||
}
|
||||
|
||||
//水平分成10条线
|
||||
for(int i = -5;i <= 5;i++)
|
||||
{
|
||||
painter->drawLine(g_w * i,-(h - 50)/2,g_w * i,(h - 50)/2);
|
||||
painter->drawText(QRect(g_w * i - 100,(h - 50)/2,200,20), Qt::AlignCenter,QString::number(i));
|
||||
}
|
||||
|
||||
painter->restore();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
#ifndef VIRTUALSCOPE_H
|
||||
#define VIRTUALSCOPE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include "QDebug"
|
||||
#include "QPicture"
|
||||
#include "QtMath"
|
||||
|
||||
class VirtualScope : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit VirtualScope(QWidget *parent = nullptr);
|
||||
~VirtualScope();
|
||||
|
||||
|
||||
signals:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
void mouseReleaseEvent(QMouseEvent *e);
|
||||
void mousePressEvent(QMouseEvent *e);
|
||||
void mouseDoubleClickEvent(QMouseEvent *e);
|
||||
void wheelEvent(QWheelEvent *e);
|
||||
void paintEvent(QPaintEvent *);
|
||||
|
||||
|
||||
private slots:
|
||||
void drawBackground(QPainter *painter);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // VIRTUALSCOPE_H
|
||||
@@ -24,7 +24,7 @@ INCLUDEPATH += $$PWD/../ComponentUI/CharInputter
|
||||
INCLUDEPATH += $$PWD/../ComponentUI/Inputter
|
||||
INCLUDEPATH += $$PWD/../ComponentUI/MultiSelector
|
||||
INCLUDEPATH += $$PWD/../ComponentUI/Selector
|
||||
|
||||
INCLUDEPATH += $$PWD/../ComponentUI/Scope
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/ToolsUI.h \
|
||||
|
||||
@@ -15,6 +15,10 @@ Tools_Index1::Tools_Index1(QWidget *parent) :
|
||||
this->setStyleSheet(stylesheet);
|
||||
file.close();
|
||||
|
||||
|
||||
scope = new Scope(this);
|
||||
scope->setGeometry(ui->frame->geometry());
|
||||
scope->show();
|
||||
}
|
||||
|
||||
Tools_Index1::~Tools_Index1()
|
||||
@@ -25,6 +29,7 @@ Tools_Index1::~Tools_Index1()
|
||||
void Tools_Index1::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
scope->setGeometry(ui->frame->geometry());
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
#include "QTextStream"
|
||||
#include "QDebug"
|
||||
|
||||
#include "Scope.h"
|
||||
|
||||
|
||||
namespace Ui {
|
||||
class Tools_Index1;
|
||||
}
|
||||
@@ -23,7 +26,7 @@ public:
|
||||
private:
|
||||
Ui::Tools_Index1 *ui;
|
||||
|
||||
|
||||
Scope *scope = nullptr;
|
||||
};
|
||||
|
||||
#endif // INDEX1_H
|
||||
|
||||
Reference in New Issue
Block a user