Render widgets on framebuffer

This commit is contained in:
Alex Spataru 2021-11-29 05:35:40 -06:00
parent 40e4b94697
commit 00640a3f4e
4 changed files with 92 additions and 80 deletions

View File

@ -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
}
}

View File

@ -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") + "..."

View File

@ -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<QWheelEvent *>(event));
return true;
break;
case QEvent::MouseButtonPress:
case QEvent::MouseButtonRelease:
case QEvent::MouseButtonDblClick:
case QEvent::MouseMove:
processMouseEvents(static_cast<QMouseEvent *>(event));
return true;
break;
default:
break;
case QEvent::FocusIn:
forceActiveFocus();
return QQuickPaintedItem::event(event);
break;
case QEvent::Wheel:
processWheelEvents(static_cast<QWheelEvent *>(event));
return true;
break;
case QEvent::MouseButtonPress:
case QEvent::MouseButtonRelease:
case QEvent::MouseButtonDblClick:
case QEvent::MouseMove:
processMouseEvents(static_cast<QMouseEvent *>(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<Hack *>(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();

View File

@ -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()));
}
/**