Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 6 additions & 14 deletions forms/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@
<string notr="true"/>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
<enum>QFrame::Plain</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QFrame" name="frameDraw2">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
Expand All @@ -98,7 +98,7 @@
</property>
<property name="maximumSize">
<size>
<width>237</width>
<width>16777215</width>
<height>267</height>
</size>
</property>
Expand Down Expand Up @@ -130,7 +130,7 @@
<item>
<widget class="DrawArea" name="areaDraw" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
Expand All @@ -143,7 +143,7 @@
</property>
<property name="maximumSize">
<size>
<width>235</width>
<width>16777215</width>
<height>265</height>
</size>
</property>
Expand Down Expand Up @@ -288,14 +288,6 @@
</item>
</layout>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>BottomToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
Expand Down
Binary file modified images/eProsimaLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions include/eprosimashapesdemo/qt/DrawArea.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,25 @@ class DrawArea : public QWidget
void addContentFilter(
ShapeSubscriber* ssub);

/**
* @brief setDrawAreaResizeTarget Sets the ShapesDemo that should be notified
* of the draw area width whenever it changes, so the movement bounds track
* the window size.
* @param SD Pointer to the ShapesDemo object.
*/
void setDrawAreaResizeTarget(
ShapesDemo* SD);

protected:

/**
* @brief resizeEvent Reports the new width to the ShapesDemo so shapes can
* use the extra horizontal space (and be dragged back in when shrinking).
* @param event Pointer to the resize event.
*/
void resizeEvent(
QResizeEvent* event) override;

/**
* @brief paintEvent Paintevent method.
* @param event Pointer to the event.
Expand Down Expand Up @@ -135,6 +152,9 @@ class DrawArea : public QWidget
bool isHistory = false);

ShapesDemo* mp_SD;
// ShapesDemo notified of width changes (may differ from mp_SD lifetime-wise,
// kept separate so a resize before setShapesDemo() is still safe).
ShapesDemo* mp_resizeSD = nullptr;
bool m_isInitialized;
// std::vector<Shape*> m_shapes;
float firstA, lastA;
Expand Down
9 changes: 9 additions & 0 deletions include/eprosimashapesdemo/shapesdemo/ShapesDemo.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,15 @@ class ShapesDemo
Topic* getTopic(
std::string topic_name);

/**
* @brief setDrawAreaWidth Update the horizontal movement bound to match the
* current draw area width. When the area shrinks, already-published shapes
* are dragged back inside so they do not end up outside the visible window.
* @param width New draw area width in pixels.
*/
void setDrawAreaWidth(
uint32_t width);

private:

std::vector<ShapePublisher*> m_publishers;
Expand Down
10 changes: 8 additions & 2 deletions src/qt/AxisArrowOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <QFont>
#include <QFontMetrics>
#include <QPainter>
#include <QPalette>
#include <QPen>
#include <QPolygon>
#include <QResizeEvent>
Expand Down Expand Up @@ -99,9 +100,14 @@ void AxisArrowOverlay::paintEvent(
const int bottomY = fd2.bottom() - 1;
const int leftX = qMax(0, fd2.left() - yw - 3);

// Follow the theme foreground: black in a light theme, light grey in a dark
// theme. darker(140) tones the dark-theme near-white down to a grey; on the
// light-theme black it has no effect (black cannot be darkened further).
const QColor axisColor = palette().color(QPalette::WindowText).darker(140);

// Draw filled shapes (no outline)
p.setPen(Qt::NoPen);
p.setBrush(Qt::black);
p.setBrush(axisColor);

// Origin dot at the corner where both axes meet.
// Not inverted: top-left corner. Inverted: bottom-left corner.
Expand Down Expand Up @@ -143,7 +149,7 @@ void AxisArrowOverlay::paintEvent(
}

// Axis labels
p.setPen(Qt::black);
p.setPen(axisColor);
p.drawText(QRect(rightX, invertY ? bottomY : topY, xw, lh),
Qt::AlignLeft | Qt::AlignTop, "X");
p.drawText(QRect(leftX, invertY ? topY : bottomY, yw, lh),
Expand Down
22 changes: 22 additions & 0 deletions src/qt/DrawArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <eprosimashapesdemo/shapesdemo/ShapeSubscriber.h>

#include <QPainter>
#include <QResizeEvent>
#include <QStyleOption>
#include <QVBoxLayout>
#include <QSizeGrip>
Expand Down Expand Up @@ -250,3 +251,24 @@ void DrawArea::setShapesDemo(
m_isInitialized = true;
}
}

void DrawArea::setDrawAreaResizeTarget(
ShapesDemo* SD)
{
mp_resizeSD = SD;
// Report the initial width so the bounds are consistent from the start.
if (mp_resizeSD != NULL)
{
mp_resizeSD->setDrawAreaWidth(width());
}
}

void DrawArea::resizeEvent(
QResizeEvent* e)
{
QWidget::resizeEvent(e);
if (mp_resizeSD != NULL)
{
mp_resizeSD->setDrawAreaWidth(width());
}
}
3 changes: 3 additions & 0 deletions src/qt/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ MainWindow::MainWindow(

ui->setupUi(this);
ui->areaDraw->setShapesDemo(this->getShapesDemo());
// Let the draw area report its size back so the movement bounds (maxX) can
// grow/shrink together with the window width.
ui->areaDraw->setDrawAreaResizeTarget(this->getShapesDemo());

m_axisOverlay = new AxisArrowOverlay(ui->frameDraw, ui->frameDraw2, this->getShapesDemo());
m_axisOverlay->raise();
Expand Down
30 changes: 30 additions & 0 deletions src/shapesdemo/ShapesDemo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,36 @@ void ShapesDemo::moveShape(
sh->m_shape.y(ny);
}

void ShapesDemo::setDrawAreaWidth(
uint32_t width)
{
// Never shrink below the historical/default width, so the coordinate space
// stays consistent with other Shapes Demo implementations.
uint32_t new_max_x = width < MAX_DRAW_AREA_X ? MAX_DRAW_AREA_X : width;

QMutexLocker lock(&m_mutex);
bool shrinking = new_max_x < maxX;
maxX = new_max_x;

// When the area shrinks, drag any published shape that would now fall
// outside the window back inside its right edge.
if (shrinking)
{
for (std::vector<ShapePublisher*>::iterator it = m_publishers.begin();
it != m_publishers.end(); ++it)
{
QMutexLocker lock2(&(*it)->m_mutex);
Shape& sh = (*it)->m_shape;
int half = (int)sh.m_shape.shapesize() / 2;
int max_center = (int)maxX - half;
if ((int)sh.m_shape.x() > max_center)
{
sh.m_shape.x(max_center > half ? max_center : half);
}
}
}
}

void ShapesDemo::getNewDirection(
Shape* sh)
{
Expand Down