aboutsummaryrefslogtreecommitdiffstats
path: root/backend-shared
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2021-01-03 12:46:56 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2021-01-03 13:56:05 -0800
commitb188560ae57304676fb10d8015dc2e3985e44c42 (patch)
tree81bd406f2de74d186c1113eb0634f1a38ba6f85f /backend-shared
parent9759d5b21a330ae2908fe91ff1533d06f6a59f4f (diff)
downloadsubsurface-b188560ae57304676fb10d8015dc2e3985e44c42.tar.gz
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 <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'backend-shared')
-rw-r--r--backend-shared/CMakeLists.txt2
-rw-r--r--backend-shared/roundrectitem.cpp18
-rw-r--r--backend-shared/roundrectitem.h15
3 files changed, 35 insertions, 0 deletions
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 <QPainter>
+#include <QStyleOptionGraphicsItem>
+
+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 <QGraphicsRectItem>
+
+class RoundRectItem : public QGraphicsRectItem {
+public:
+ RoundRectItem(double radius, QGraphicsItem *parent);
+private:
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
+ double radius;
+};
+
+#endif