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
10#include <QToolTip>
11
15
16#include <iostream>
17
18namespace dbse {
19
21 const QString& text,
22 QGraphicsObject* parent)
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}
39
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}
60
61void SchemaGraphicNote::mouseDoubleClickEvent ( QGraphicsSceneMouseEvent* ) {
63}
64
65
66void SchemaGraphicNote::update_note (QString text) {
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}
73
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}
91
92void SchemaGraphicNote::paint (QPainter* painter,
93 const QStyleOptionGraphicsItem* /*option*/,
94 QWidget* /*widget*/ ) {
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}
106
107QPainterPath SchemaGraphicNote::shape() const {
108 QPainterPath path;
109 path.addRect ( boundingRect() );
110 return path;
111}
112} //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)
Including QT Headers.