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
24 const QString& text,
25 QGraphicsObject* parent)
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}
37
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 SchemaGraphicNote::mouseDoubleClickEvent ( QGraphicsSceneMouseEvent* ) {
61}
62
63
64void SchemaGraphicNote::update_note (QString text) {
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}
71
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}
89
90void SchemaGraphicNote::paint (QPainter* painter,
91 const QStyleOptionGraphicsItem* /*option*/,
92 QWidget* /*widget*/ ) {
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}
104
105QPainterPath SchemaGraphicNote::shape() const {
106 QPainterPath path;
107 path.addRect ( boundingRect() );
108 return path;
109}
110} //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.
static QColor get_color(const QString &item, const QString &group)
static QFont get_font(const QString &group)