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 14 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.

26 : QGraphicsObject (parent),
27 m_name(name),
28 m_text(text) {
29
30 setAcceptHoverEvents(true);
31
32 setFlag ( ItemIsMovable );
33 setFlag ( ItemSendsGeometryChanges, true );
34 setFlag ( ItemSendsScenePositionChanges, true );
35
36}

◆ ~SchemaGraphicNote()

dbse::SchemaGraphicNote::~SchemaGraphicNote ( )
default

Member Function Documentation

◆ boundingRect()

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

Definition at line 72 of file SchemaGraphicNote.cpp.

73{
74 QFontMetrics font_metrics(SchemaStyle::get_font("note"));
75 double height = font_metrics.height()/2;
76 double width = 0;
77 for (auto line: m_text.split("\n")) {
78 height += font_metrics.height();
79 QRectF font_rect = font_metrics.boundingRect(line);
80 if (font_rect.width() > width) {
81 width = font_rect.width();
82 }
83 }
84 width += font_metrics.averageCharWidth()*2;
85
86 return QRectF(0, 0, width, height);
87 //return font_metrics.boundingRect(m_text);
88}
static QFont get_font(const QString &group)

◆ mouseDoubleClickEvent()

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

Definition at line 59 of file SchemaGraphicNote.cpp.

◆ open_editor()

void dbse::SchemaGraphicNote::open_editor ( )

Definition at line 38 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}

◆ paint()

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

Definition at line 90 of file SchemaGraphicNote.cpp.

92 {
93
94 const QPen pen(SchemaStyle::get_color("foreground", "note"), 0.5);
95 const QBrush brush(SchemaStyle::get_color("background", "note"));
96 painter->setFont (SchemaStyle::get_font("note"));
97 painter->setBrush (brush);
98// painter->setBackgroundMode(Qt::OpaqueMode);
99 painter->setPen ( pen );
100 const auto rect = boundingRect();
101 painter->drawRect ( rect );
102 painter->drawText(rect.adjusted(5,5,-2,-2), Qt::AlignJustify, m_text);
103}
QRectF boundingRect() const override
static QColor get_color(const QString &item, const QString &group)

◆ shape()

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

Definition at line 105 of file SchemaGraphicNote.cpp.

105 {
106 QPainterPath path;
107 path.addRect ( boundingRect() );
108 return path;
109}

◆ text()

QString dbse::SchemaGraphicNote::text ( )
inlinenodiscard

Definition at line 29 of file SchemaGraphicNote.hpp.

29{return m_text;}

◆ update_note()

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

Definition at line 64 of file SchemaGraphicNote.cpp.

64 {
65 auto this_scene = dynamic_cast<SchemaGraphicsScene*>(scene());
66 this_scene->remove_note_object(this);
67 m_text = text;
68 this_scene->addItem(this);
69 emit updated();
70}

◆ updated

void dbse::SchemaGraphicNote::updated ( )
signal

Member Data Documentation

◆ m_name

QString dbse::SchemaGraphicNote::m_name
private

Definition at line 38 of file SchemaGraphicNote.hpp.

◆ m_text

QString dbse::SchemaGraphicNote::m_text
private

Definition at line 39 of file SchemaGraphicNote.hpp.


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