diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui index 13605a8..12d45f3 100644 --- a/forms/mainwindow.ui +++ b/forms/mainwindow.ui @@ -76,16 +76,16 @@ - QFrame::StyledPanel + QFrame::NoFrame - QFrame::Sunken + QFrame::Plain - + 0 0 @@ -98,7 +98,7 @@ - 237 + 16777215 267 @@ -130,7 +130,7 @@ - + 0 0 @@ -143,7 +143,7 @@ - 235 + 16777215 265 @@ -288,14 +288,6 @@ - - - BottomToolBarArea - - - false - - diff --git a/images/eProsimaLogo.png b/images/eProsimaLogo.png index acc4dce..8d1d750 100644 Binary files a/images/eProsimaLogo.png and b/images/eProsimaLogo.png differ diff --git a/include/eprosimashapesdemo/qt/DrawArea.h b/include/eprosimashapesdemo/qt/DrawArea.h index c9108cf..9ce68a3 100644 --- a/include/eprosimashapesdemo/qt/DrawArea.h +++ b/include/eprosimashapesdemo/qt/DrawArea.h @@ -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. @@ -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 m_shapes; float firstA, lastA; diff --git a/include/eprosimashapesdemo/shapesdemo/ShapesDemo.h b/include/eprosimashapesdemo/shapesdemo/ShapesDemo.h index aaa31c9..d3ce592 100644 --- a/include/eprosimashapesdemo/shapesdemo/ShapesDemo.h +++ b/include/eprosimashapesdemo/shapesdemo/ShapesDemo.h @@ -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 m_publishers; diff --git a/src/qt/AxisArrowOverlay.cpp b/src/qt/AxisArrowOverlay.cpp index cfc0d0e..447d14c 100644 --- a/src/qt/AxisArrowOverlay.cpp +++ b/src/qt/AxisArrowOverlay.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -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. @@ -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), diff --git a/src/qt/DrawArea.cpp b/src/qt/DrawArea.cpp index 1548e55..dd18633 100644 --- a/src/qt/DrawArea.cpp +++ b/src/qt/DrawArea.cpp @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -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()); + } +} diff --git a/src/qt/mainwindow.cpp b/src/qt/mainwindow.cpp index 54b29f9..9681e29 100644 --- a/src/qt/mainwindow.cpp +++ b/src/qt/mainwindow.cpp @@ -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(); diff --git a/src/shapesdemo/ShapesDemo.cpp b/src/shapesdemo/ShapesDemo.cpp index 2be8aa2..b986ad7 100644 --- a/src/shapesdemo/ShapesDemo.cpp +++ b/src/shapesdemo/ShapesDemo.cpp @@ -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::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) {