From 00640a3f4e71ce4c7f210172426c4f670c5e9aad Mon Sep 17 00:00:00 2001 From: Alex Spataru Date: Mon, 29 Nov 2021 05:35:40 -0600 Subject: [PATCH] Render widgets on framebuffer --- assets/qml/Dashboard/WidgetDelegate.qml | 2 + assets/qml/Widgets/Terminal.qml | 1 + src/UI/WidgetLoader.cpp | 156 ++++++++++++------------ src/Widgets/Terminal.cpp | 13 +- 4 files changed, 92 insertions(+), 80 deletions(-) diff --git a/assets/qml/Dashboard/WidgetDelegate.qml b/assets/qml/Dashboard/WidgetDelegate.qml index 7f87df82..8c5369cf 100644 --- a/assets/qml/Dashboard/WidgetDelegate.qml +++ b/assets/qml/Dashboard/WidgetDelegate.qml @@ -51,6 +51,7 @@ Item { WidgetLoader { id: loader widgetIndex: root.widgetIndex + renderTarget: PaintedItem.FramebufferObject anchors { fill: parent leftMargin: window.borderWidth @@ -113,6 +114,7 @@ Item { widgetIndex: root.widgetIndex widgetVisible: _window.visible anchors.margins: _window.radius + renderTarget: PaintedItem.FramebufferObject } } diff --git a/assets/qml/Widgets/Terminal.qml b/assets/qml/Widgets/Terminal.qml index b73ea1a1..1fcb928b 100644 --- a/assets/qml/Widgets/Terminal.qml +++ b/assets/qml/Widgets/Terminal.qml @@ -145,6 +145,7 @@ Item { maximumBlockCount: 12000 font.family: app.monoFont autoscroll: Cpp_IO_Console.autoscroll + renderTarget: PaintedItem.FramebufferObject wordWrapMode: Text.WrapAtWordBoundaryOrAnywhere placeholderText: qsTr("No data received so far") + "..." diff --git a/src/UI/WidgetLoader.cpp b/src/UI/WidgetLoader.cpp index 71d7f53d..ab445850 100644 --- a/src/UI/WidgetLoader.cpp +++ b/src/UI/WidgetLoader.cpp @@ -51,10 +51,11 @@ WidgetLoader::WidgetLoader(QQuickItem *parent) , m_widgetVisible(false) , m_isExternalWindow(false) { - // Set item flags - setFlag(ItemHasContents, true); - setFlag(ItemIsFocusScope, true); - setFlag(ItemAcceptsInputMethod, true); + // Set render flags + setOpaquePainting(true); + setAcceptHoverEvents(true); + setRenderTarget(FramebufferObject); + setPerformanceHints(FastFBOResizing); setAcceptedMouseButtons(Qt::AllButtons); // Resize widget to fit QML item size @@ -66,6 +67,9 @@ WidgetLoader::WidgetLoader(QQuickItem *parent) // Automatically update the widget's visibility connect(Dashboard::getInstance(), &Dashboard::widgetVisibilityChanged, this, &WidgetLoader::updateWidgetVisible); + + // Draw widget + QTimer::singleShot(0, this, SLOT(update())); } /** @@ -89,23 +93,23 @@ bool WidgetLoader::event(QEvent *event) // Process focus, wheel & mouse click/release events switch (event->type()) { - case QEvent::FocusIn: - forceActiveFocus(); - return QQuickPaintedItem::event(event); - break; - case QEvent::Wheel: - processWheelEvents(static_cast(event)); - return true; - break; - case QEvent::MouseButtonPress: - case QEvent::MouseButtonRelease: - case QEvent::MouseButtonDblClick: - case QEvent::MouseMove: - processMouseEvents(static_cast(event)); - return true; - break; - default: - break; + case QEvent::FocusIn: + forceActiveFocus(); + return QQuickPaintedItem::event(event); + break; + case QEvent::Wheel: + processWheelEvents(static_cast(event)); + return true; + break; + case QEvent::MouseButtonPress: + case QEvent::MouseButtonRelease: + case QEvent::MouseButtonDblClick: + case QEvent::MouseMove: + processMouseEvents(static_cast(event)); + return true; + break; + default: + break; } // @@ -136,12 +140,12 @@ bool WidgetLoader::eventFilter(QObject *watched, QEvent *event) { switch (event->type()) { - case QEvent::Paint: - case QEvent::UpdateRequest: - update(); - break; - default: - break; + case QEvent::Paint: + case QEvent::UpdateRequest: + update(); + break; + default: + break; } } @@ -246,41 +250,41 @@ void WidgetLoader::setWidgetIndex(const int index) // Construct new widget switch (widgetType()) { - case UI::Dashboard::WidgetType::Group: - m_widget = new Widgets::DataGroup(relativeIndex()); - break; - case UI::Dashboard::WidgetType::MultiPlot: - m_widget = new Widgets::MultiPlot(relativeIndex()); - break; - case UI::Dashboard::WidgetType::FFT: - m_widget = new Widgets::FFTPlot(relativeIndex()); - break; - case UI::Dashboard::WidgetType::Plot: - m_widget = new Widgets::Plot(relativeIndex()); - break; - case UI::Dashboard::WidgetType::Bar: - m_widget = new Widgets::Bar(relativeIndex()); - break; - case UI::Dashboard::WidgetType::Gauge: - m_widget = new Widgets::Gauge(relativeIndex()); - break; - case UI::Dashboard::WidgetType::Compass: - m_widget = new Widgets::Compass(relativeIndex()); - break; - case UI::Dashboard::WidgetType::Gyroscope: - m_widget = new Widgets::Gyroscope(relativeIndex()); - break; - case UI::Dashboard::WidgetType::Accelerometer: - m_widget = new Widgets::Accelerometer(relativeIndex()); - break; - case UI::Dashboard::WidgetType::GPS: - m_widget = new Widgets::GPS(relativeIndex()); - break; - case UI::Dashboard::WidgetType::LED: - m_widget = new Widgets::LEDPanel(relativeIndex()); - break; - default: - break; + case UI::Dashboard::WidgetType::Group: + m_widget = new Widgets::DataGroup(relativeIndex()); + break; + case UI::Dashboard::WidgetType::MultiPlot: + m_widget = new Widgets::MultiPlot(relativeIndex()); + break; + case UI::Dashboard::WidgetType::FFT: + m_widget = new Widgets::FFTPlot(relativeIndex()); + break; + case UI::Dashboard::WidgetType::Plot: + m_widget = new Widgets::Plot(relativeIndex()); + break; + case UI::Dashboard::WidgetType::Bar: + m_widget = new Widgets::Bar(relativeIndex()); + break; + case UI::Dashboard::WidgetType::Gauge: + m_widget = new Widgets::Gauge(relativeIndex()); + break; + case UI::Dashboard::WidgetType::Compass: + m_widget = new Widgets::Compass(relativeIndex()); + break; + case UI::Dashboard::WidgetType::Gyroscope: + m_widget = new Widgets::Gyroscope(relativeIndex()); + break; + case UI::Dashboard::WidgetType::Accelerometer: + m_widget = new Widgets::Accelerometer(relativeIndex()); + break; + case UI::Dashboard::WidgetType::GPS: + m_widget = new Widgets::GPS(relativeIndex()); + break; + case UI::Dashboard::WidgetType::LED: + m_widget = new Widgets::LEDPanel(relativeIndex()); + break; + default: + break; } // Allow widget to receive events from the QML interface @@ -418,20 +422,20 @@ void WidgetLoader::processMouseEvents(QMouseEvent *event) auto hack = static_cast(m_widget); switch (event->type()) { - case QEvent::MouseButtonPress: - hack->mousePressEvent(event); - break; - case QEvent::MouseMove: - hack->mouseMoveEvent(event); - break; - case QEvent::MouseButtonRelease: - hack->mouseReleaseEvent(event); - break; - case QEvent::MouseButtonDblClick: - hack->mouseDoubleClickEvent(event); - break; - default: - break; + case QEvent::MouseButtonPress: + hack->mousePressEvent(event); + break; + case QEvent::MouseMove: + hack->mouseMoveEvent(event); + break; + case QEvent::MouseButtonRelease: + hack->mouseReleaseEvent(event); + break; + case QEvent::MouseButtonDblClick: + hack->mouseDoubleClickEvent(event); + break; + default: + break; } update(); diff --git a/src/Widgets/Terminal.cpp b/src/Widgets/Terminal.cpp index bfd7c6a7..2dd1bc75 100644 --- a/src/Widgets/Terminal.cpp +++ b/src/Widgets/Terminal.cpp @@ -57,10 +57,12 @@ Terminal::Terminal(QQuickItem *parent) , m_copyAvailable(false) , m_textEdit(new QPlainTextEdit) { - // Set item flags - setFlag(ItemHasContents, true); - setFlag(ItemAcceptsInputMethod, true); - setFlag(ItemIsFocusScope, true); + // Set render flags + setAntialiasing(true); + setOpaquePainting(true); + setAcceptHoverEvents(true); + setRenderTarget(FramebufferObject); + setPerformanceHints(FastFBOResizing); setAcceptedMouseButtons(Qt::AllButtons); m_escapeCodeHandler.setTextEdit(textEdit()); @@ -100,6 +102,9 @@ Terminal::Terminal(QQuickItem *parent) // React to widget events connect(textEdit(), SIGNAL(copyAvailable(bool)), this, SLOT(setCopyAvailable(bool))); + + // Draw widget + QTimer::singleShot(0, this, SLOT(update())); } /**