DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dbse::SchemaGraphicNote Class Reference

#include <SchemaGraphicNote.hpp>

Inheritance diagram for dbse::SchemaGraphicNote:
[legend]
Collaboration diagram for dbse::SchemaGraphicNote:
[legend]

Signals

void updated ()

Public Member Functions

 SchemaGraphicNote (const QString &name, const QString &text, QGraphicsObject *parent=nullptr)
 ~SchemaGraphicNote ()=default
QRectF boundingRect () const override
QPainterPath shape () const override
void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
QString text ()
void update_note (QString text)
void open_editor ()

Protected Member Functions

void mouseDoubleClickEvent (QGraphicsSceneMouseEvent *ev) override

Private Attributes

QString m_name
QString m_text

Detailed Description

Definition at line 13 of file SchemaGraphicNote.hpp.

Constructor & Destructor Documentation

◆ SchemaGraphicNote()

dbse::SchemaGraphicNote::SchemaGraphicNote ( const QString & name,
const QString & text,
QGraphicsObject * parent = nullptr )
explicit

Definition at line 23 of file SchemaGraphicNote.cpp.

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}

◆ ~SchemaGraphicNote()

dbse::SchemaGraphicNote::~SchemaGraphicNote ( )
default

Member Function Documentation

◆ boundingRect()

QRectF dbse::SchemaGraphicNote::boundingRect ( ) const
nodiscardoverride

Definition at line 76 of file SchemaGraphicNote.cpp.

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}
static QFont get_font(const QString &group)

◆ mouseDoubleClickEvent()

void dbse::SchemaGraphicNote::mouseDoubleClickEvent ( QGraphicsSceneMouseEvent * ev)
overrideprotected

Definition at line 60 of file SchemaGraphicNote.cpp.

◆ open_editor()

void dbse::SchemaGraphicNote::open_editor ( )

Definition at line 37 of file SchemaGraphicNote.cpp.

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}
SchemaNoteEditor(SchemaGraphicNote *note, QWidget *parent=0)

◆ paint()

void dbse::SchemaGraphicNote::paint ( QPainter * painter,
const QStyleOptionGraphicsItem * option,
QWidget * widget )
override

Definition at line 95 of file SchemaGraphicNote.cpp.

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}
QRectF boundingRect() const override
static QColor get_color(const QString &item, const QString &group)

◆ shape()

QPainterPath dbse::SchemaGraphicNote::shape ( ) const
nodiscardoverride

Definition at line 110 of file SchemaGraphicNote.cpp.

111{
112 QPainterPath path;
113 path.addRect(boundingRect());
114 return path;
115}

◆ text()

QString dbse::SchemaGraphicNote::text ( )
inlinenodiscard

Definition at line 24 of file SchemaGraphicNote.hpp.

24{ return m_text; }

◆ update_note()

void dbse::SchemaGraphicNote::update_note ( QString text)

Definition at line 66 of file SchemaGraphicNote.cpp.

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}

◆ updated

void dbse::SchemaGraphicNote::updated ( )
signal

Member Data Documentation

◆ m_name

QString dbse::SchemaGraphicNote::m_name
private

Definition at line 34 of file SchemaGraphicNote.hpp.

◆ m_text

QString dbse::SchemaGraphicNote::m_text
private

Definition at line 35 of file SchemaGraphicNote.hpp.


The documentation for this class was generated from the following files: