From b188560ae57304676fb10d8015dc2e3985e44c42 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 3 Jan 2021 12:46:56 +0100 Subject: ui: create a RoundRectItem class Factor out code from ProfileWidget's ToolTipItem, but make the radius of the corners dynamic. Move into backend-shared, though a new ui-shared might be preferred. Signed-off-by: Berthold Stoeger --- backend-shared/CMakeLists.txt | 2 ++ backend-shared/roundrectitem.cpp | 18 ++++++++++++++++++ backend-shared/roundrectitem.h | 15 +++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 backend-shared/roundrectitem.cpp create mode 100644 backend-shared/roundrectitem.h (limited to 'backend-shared') diff --git a/backend-shared/CMakeLists.txt b/backend-shared/CMakeLists.txt index fdfdb1e05..736b03279 100644 --- a/backend-shared/CMakeLists.txt +++ b/backend-shared/CMakeLists.txt @@ -5,6 +5,8 @@ set(BACKEND_SRCS exportfuncs.h plannershared.cpp plannershared.h + roundrectitem.cpp + roundrectitem.h ) add_library(subsurface_backend_shared STATIC ${BACKEND_SRCS}) diff --git a/backend-shared/roundrectitem.cpp b/backend-shared/roundrectitem.cpp new file mode 100644 index 000000000..2dbfd7b03 --- /dev/null +++ b/backend-shared/roundrectitem.cpp @@ -0,0 +1,18 @@ +#include "roundrectitem.h" +#include +#include + +RoundRectItem::RoundRectItem(double radius, QGraphicsItem *parent) : QGraphicsRectItem(parent), + radius(radius) +{ +} + +void RoundRectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *) +{ + painter->save(); + painter->setClipRect(option->rect); + painter->setPen(pen()); + painter->setBrush(brush()); + painter->drawRoundedRect(rect(), radius, radius, Qt::AbsoluteSize); + painter->restore(); +} diff --git a/backend-shared/roundrectitem.h b/backend-shared/roundrectitem.h new file mode 100644 index 000000000..d3f58782f --- /dev/null +++ b/backend-shared/roundrectitem.h @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0 +#ifndef ROUNDRECTITEM_H +#define ROUNDRECTITEM_H + +#include + +class RoundRectItem : public QGraphicsRectItem { +public: + RoundRectItem(double radius, QGraphicsItem *parent); +private: + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override; + double radius; +}; + +#endif -- cgit v1.2.3-70-g09d2