DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
SchemaGraphicNote.cpp
Go to the documentation of this file.
1
2#include <QApplication>
3#include <QCursor>
4#include <QEvent>
5#include <QGraphicsScene>
6#include <QGraphicsSceneHoverEvent>
7#include <QGraphicsView>
8#include <QPainter>
9#include <QPainterPath>
10#include <QPen>
11
12#include <QToolTip>
13
17#include "dbe/SchemaStyle.hpp"
18
19#include <iostream>
20
21namespace dbse {
22
23SchemaGraphicNote::SchemaGraphicNote(const QString& name, const QString& text, QGraphicsObject* parent)
24 : QGraphicsObject(parent)
25 , m_name(name)
26 , m_text(text)
27{
28
29 setAcceptHoverEvents(true);
30
31 setFlag(ItemIsMovable);
32 setFlag(ItemSendsGeometryChanges, true);
33 setFlag(ItemSendsScenePositionChanges, true);
34}
35
36void
38{
39 bool editorFound = false;
40
41 for (auto widget : QApplication::allWidgets()) {
42 auto editor = dynamic_cast<SchemaNoteEditor*>(widget);
43 if (editor != nullptr) {
44 if ((editor->objectName()).compare(m_name) == 0) {
45 editor->raise();
46 editor->setVisible(true);
47 editor->activateWindow();
48 editorFound = true;
49 }
50 }
51 }
52
53 if (!editorFound) {
54 auto editor = new SchemaNoteEditor(this);
55 editor->show();
56 }
57}
58
59void
61{
63}
64
65void
67{
68 auto this_scene = dynamic_cast<SchemaGraphicsScene*>(scene());
69 this_scene->remove_note_object(this);
70 m_text = text;
71 this_scene->addItem(this);
72 emit updated();
73}
74
75QRectF
77{
78 QFontMetrics font_metrics(SchemaStyle::get_font("note"));
79 double height = font_metrics.height() / 2;
80 double width = 0;
81 for (auto line : m_text.split("\n")) {
82 height += font_metrics.height();
83 QRectF font_rect = font_metrics.boundingRect(line);
84 if (font_rect.width() > width) {
85 width = font_rect.width();
86 }
87 }
88 width += font_metrics.averageCharWidth() * 2;
89
90 return QRectF(0, 0, width, height);
91 // return font_metrics.boundingRect(m_text);
92}
93
94void
95SchemaGraphicNote::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget* /*widget*/)
96{
97
98 const QPen pen(SchemaStyle::get_color("foreground", "note"), 0.5);
99 const QBrush brush(SchemaStyle::get_color("background", "note"));
100 painter->setFont(SchemaStyle::get_font("note"));
101 painter->setBrush(brush);
102 // painter->setBackgroundMode(Qt::OpaqueMode);
103 painter->setPen(pen);
104 const auto rect = boundingRect();
105 painter->drawRect(rect);
106 painter->drawText(rect.adjusted(5, 5, -2, -2), Qt::AlignJustify, m_text);
107}
108
109QPainterPath
111{
112 QPainterPath path;
113 path.addRect(boundingRect());
114 return path;
115}
116} // namespace dbse
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
QPainterPath shape() const override
SchemaGraphicNote(const QString &name, const QString &text, QGraphicsObject *parent=nullptr)
QRectF boundingRect() const override
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *ev) override
void update_note(QString text)
void remove_note_object(SchemaGraphicNote *obj)
SchemaNoteEditor(SchemaGraphicNote *note, QWidget *parent=0)
Including QT Headers.
static QColor get_color(const QString &item, const QString &group)
static QFont get_font(const QString &group)