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
 
QFont m_font
 
QFont m_bold_font
 
QColor m_default_color
 
QColor m_highlight_color
 
QColor m_background_color
 

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 20 of file SchemaGraphicNote.cpp.

23 : QGraphicsObject (parent),
24 m_name(name),
25 m_text(text) {
26
27 setAcceptHoverEvents(true);
28 m_font = QFont( "Helvetica [Cronyx]", 9);
29 m_bold_font = QFont( "Helvetica [Cronyx]", 9, QFont::DemiBold);
30 m_default_color = QColor ( 0x1e1b18 );
31 m_highlight_color = QColor ( 0x14aaff );
32 m_background_color = QColor ( 0xf8f8ff );
33
34 setFlag ( ItemIsMovable );
35 setFlag ( ItemSendsGeometryChanges, true );
36 setFlag ( ItemSendsScenePositionChanges, true );
37
38}

◆ ~SchemaGraphicNote()

dbse::SchemaGraphicNote::~SchemaGraphicNote ( )
default

Member Function Documentation

◆ boundingRect()

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

Definition at line 74 of file SchemaGraphicNote.cpp.

75{
76 QFontMetrics font_metrics(m_font);
77 double height = font_metrics.height()/2;
78 double width = 0;
79 for (auto line: m_text.split("\n")) {
80 height += font_metrics.height();
81 QRectF font_rect = font_metrics.boundingRect(line);
82 if (font_rect.width() > width) {
83 width = font_rect.width();
84 }
85 }
86 width += font_metrics.averageCharWidth()*2;
87
88 return QRectF(0, 0, width, height);
89 //return font_metrics.boundingRect(m_text);
90}

◆ mouseDoubleClickEvent()

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

Definition at line 61 of file SchemaGraphicNote.cpp.

◆ open_editor()

void dbse::SchemaGraphicNote::open_editor ( )

Definition at line 40 of file SchemaGraphicNote.cpp.

40 {
41 bool editorFound = false;
42
43 for ( auto widget : QApplication::allWidgets() ) {
44 auto editor = dynamic_cast<SchemaNoteEditor*> (widget);
45 if ( editor != nullptr ) {
46 if ( (editor->objectName() ).compare (m_name) == 0 ) {
47 editor->raise();
48 editor->setVisible ( true );
49 editor->activateWindow();
50 editorFound = true;
51 }
52 }
53 }
54
55 if ( !editorFound ) {
56 auto editor = new SchemaNoteEditor ( this );
57 editor->show();
58 }
59}

◆ paint()

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

Definition at line 92 of file SchemaGraphicNote.cpp.

94 {
95
96 const QPen pen(m_default_color, 0.5);
97 QBrush brush(m_background_color);
98 painter->setFont ( m_font );
99 painter->setBrush (brush);//m_background_color);
100// painter->setBackgroundMode(Qt::OpaqueMode);
101 painter->setPen ( pen );
102 auto rect = boundingRect();
103 painter->drawRect ( rect );
104 painter->drawText(rect.adjusted(5,5,-2,-2), Qt::AlignJustify, m_text);
105}
QRectF boundingRect() const override

◆ shape()

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

Definition at line 107 of file SchemaGraphicNote.cpp.

107 {
108 QPainterPath path;
109 path.addRect ( boundingRect() );
110 return path;
111}

◆ 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 66 of file SchemaGraphicNote.cpp.

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

◆ updated

void dbse::SchemaGraphicNote::updated ( )
signal

Member Data Documentation

◆ m_background_color

QColor dbse::SchemaGraphicNote::m_background_color
private

Definition at line 44 of file SchemaGraphicNote.hpp.

◆ m_bold_font

QFont dbse::SchemaGraphicNote::m_bold_font
private

Definition at line 41 of file SchemaGraphicNote.hpp.

◆ m_default_color

QColor dbse::SchemaGraphicNote::m_default_color
private

Definition at line 42 of file SchemaGraphicNote.hpp.

◆ m_font

QFont dbse::SchemaGraphicNote::m_font
private

Definition at line 40 of file SchemaGraphicNote.hpp.

◆ m_highlight_color

QColor dbse::SchemaGraphicNote::m_highlight_color
private

Definition at line 43 of file SchemaGraphicNote.hpp.

◆ 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: