Added new qml module for drawing lines
This commit is contained in:
@ -20,7 +20,11 @@ find_package(Qt5QuickCompiler)
|
|||||||
|
|
||||||
set(CMAKE_AUTOMOC ON)
|
set(CMAKE_AUTOMOC ON)
|
||||||
set(QT_QML_GENERATE_QMLLS_INI ON)
|
set(QT_QML_GENERATE_QMLLS_INI ON)
|
||||||
qt_wrap_cpp(MOC_FILES include/rqt_demo_plugin/rqt_demo_plugin.hpp)
|
|
||||||
|
qt_wrap_cpp(
|
||||||
|
MOC_FILES
|
||||||
|
include/rqt_demo_plugin/rqt_demo_plugin.hpp
|
||||||
|
include/rqt_demo_plugin/lineItem.hpp)
|
||||||
qtquick_compiler_add_resources(RCC_SOURCES "resources/res.qrc")
|
qtquick_compiler_add_resources(RCC_SOURCES "resources/res.qrc")
|
||||||
|
|
||||||
|
|
||||||
@ -28,6 +32,7 @@ add_library(
|
|||||||
rqt_demo_plugin
|
rqt_demo_plugin
|
||||||
SHARED
|
SHARED
|
||||||
src/rqt_demo_plugin.cpp
|
src/rqt_demo_plugin.cpp
|
||||||
|
src/lineItem.cpp
|
||||||
${RCC_SOURCES}
|
${RCC_SOURCES}
|
||||||
${MOC_FILES}
|
${MOC_FILES}
|
||||||
)
|
)
|
||||||
|
|||||||
32
include/rqt_demo_plugin/lineItem.hpp
Normal file
32
include/rqt_demo_plugin/lineItem.hpp
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <QtQuick/QQuickItem>
|
||||||
|
#include <qchar.h>
|
||||||
|
#include <qglobal.h>
|
||||||
|
#include <qobjectdefs.h>
|
||||||
|
#include <qpoint.h>
|
||||||
|
#include <qquickitem.h>
|
||||||
|
#include <qsgnode.h>
|
||||||
|
|
||||||
|
class LineItem : public QQuickItem
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
Q_PROPERTY(QString stupid READ stupid WRITE setStupid)
|
||||||
|
QML_ELEMENT
|
||||||
|
public:
|
||||||
|
LineItem(QQuickItem *parent = nullptr);
|
||||||
|
~LineItem();
|
||||||
|
|
||||||
|
QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
|
||||||
|
|
||||||
|
QString stupid() const {return stupid_;}
|
||||||
|
|
||||||
|
void setStupid(const QString &str) {
|
||||||
|
stupid_ = str;
|
||||||
|
qDebug() << str;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString stupid_;
|
||||||
|
};
|
||||||
@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "rqt_gui_cpp/plugin.h"
|
#include "rqt_gui_cpp/plugin.h"
|
||||||
|
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
#include <QtQuick>
|
#include <QtQuick>
|
||||||
#include <QtWidgets>
|
#include <QtWidgets>
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
pluginlib:rclcpp:rqt:rqt_gui_cpp
|
pluginlib:rclcpp:rqt:rqt_gui_cpp:rqt_image_view
|
||||||
@ -1 +1 @@
|
|||||||
build_2025-03-08_17-19-32
|
build_2025-03-09_02-21-28
|
||||||
@ -1,11 +1,12 @@
|
|||||||
import QtQuick 2.3
|
import QtQuick 2.3
|
||||||
|
import LineItem 1.0
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
color: "gray"
|
color: "gray"
|
||||||
Flickable {
|
Flickable {
|
||||||
width: parent.width;
|
width: parent.width;
|
||||||
height: parent.height
|
height: parent.height
|
||||||
contentWidth: 2500; contentHeight: 1500
|
contentWidth: 2500*4; contentHeight: 1500*4
|
||||||
flickDeceleration: 10000
|
flickDeceleration: 10000
|
||||||
leftMargin: Math.max((width - contentWidth)/2,0)
|
leftMargin: Math.max((width - contentWidth)/2,0)
|
||||||
topMargin: Math.max((height - contentHeight)/2,0)
|
topMargin: Math.max((height - contentHeight)/2,0)
|
||||||
@ -16,10 +17,10 @@ Rectangle {
|
|||||||
id: contentRect
|
id: contentRect
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
width: parent.width
|
width: parent.width/4
|
||||||
height: parent.height
|
height: parent.height/4
|
||||||
|
|
||||||
transform: Scale {yScale: 1; xScale: 1}
|
transform: Scale {yScale: 4; xScale: 4}
|
||||||
transformOrigin: Item.TopLeft
|
transformOrigin: Item.TopLeft
|
||||||
|
|
||||||
Row {
|
Row {
|
||||||
@ -43,6 +44,10 @@ Rectangle {
|
|||||||
text: "Hello, World!"
|
text: "Hello, World!"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
LineItem {
|
||||||
|
height: 100
|
||||||
|
width: 100
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
44
src/lineItem.cpp
Normal file
44
src/lineItem.cpp
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#include "rqt_demo_plugin/lineItem.hpp"
|
||||||
|
#include <qquickitem.h>
|
||||||
|
#include <qsgflatcolormaterial.h>
|
||||||
|
#include <qsggeometry.h>
|
||||||
|
#include <qsgnode.h>
|
||||||
|
#include <qsize.h>
|
||||||
|
|
||||||
|
LineItem::LineItem(QQuickItem *parent)
|
||||||
|
: QQuickItem(parent)
|
||||||
|
, stupid_("")
|
||||||
|
{
|
||||||
|
setFlag(ItemHasContents, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
LineItem::~LineItem() = default;
|
||||||
|
|
||||||
|
|
||||||
|
QSGNode *LineItem::updatePaintNode(QSGNode *old, UpdatePaintNodeData *)
|
||||||
|
{
|
||||||
|
QSGGeometryNode *node = nullptr;
|
||||||
|
QSGGeometry *geometry = nullptr;
|
||||||
|
|
||||||
|
if(!old) {
|
||||||
|
node = new QSGGeometryNode;
|
||||||
|
geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 4);
|
||||||
|
geometry->setLineWidth(5);
|
||||||
|
geometry->setDrawingMode(QSGGeometry::DrawLines);
|
||||||
|
node->setGeometry(geometry);
|
||||||
|
node->setFlag(QSGNode::OwnsGeometry);
|
||||||
|
auto *material = new QSGFlatColorMaterial;
|
||||||
|
material->setColor(QColor(255,0,0));
|
||||||
|
node->setMaterial(material);
|
||||||
|
node->setFlag(QSGNode::OwnsMaterial);
|
||||||
|
|
||||||
|
QSGGeometry::Point2D *verticies = geometry->vertexDataAsPoint2D();
|
||||||
|
QSizeF s = size();
|
||||||
|
verticies[0].set(0.1 * s.width(), 0.1 * s.height());
|
||||||
|
verticies[1].set(0.75 * s.width(), 0.75 * s.height());
|
||||||
|
verticies[2].set(0.1 * s.width(), 0.9 * s.height());
|
||||||
|
verticies[3].set(0.9 * s.width(), 0.1 * s.height());
|
||||||
|
node->markDirty(QSGNode::DirtyGeometry);
|
||||||
|
}
|
||||||
|
return node;
|
||||||
|
}
|
||||||
@ -1,4 +1,5 @@
|
|||||||
#include "rqt_demo_plugin/rqt_demo_plugin.hpp"
|
#include "rqt_demo_plugin/rqt_demo_plugin.hpp"
|
||||||
|
#include "rqt_demo_plugin/lineItem.hpp"
|
||||||
|
|
||||||
#include "pluginlib/class_list_macros.hpp"
|
#include "pluginlib/class_list_macros.hpp"
|
||||||
#include <qnamespace.h>
|
#include <qnamespace.h>
|
||||||
@ -10,4 +11,9 @@ mg::DemoPluginMg::DemoPluginMg() : Plugin() {
|
|||||||
fmt.setSwapInterval(0);
|
fmt.setSwapInterval(0);
|
||||||
fmt.setRenderableType(QSurfaceFormat::OpenGLES);
|
fmt.setRenderableType(QSurfaceFormat::OpenGLES);
|
||||||
QSurfaceFormat::setDefaultFormat(fmt);
|
QSurfaceFormat::setDefaultFormat(fmt);
|
||||||
|
static bool typesRegistered = 0;
|
||||||
|
if(!typesRegistered) {
|
||||||
|
qmlRegisterType<LineItem>("LineItem", 1, 0, "LineItem");
|
||||||
|
typesRegistered = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user