DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
dbe
apps
SchemaEditor
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
14
#include "
dbe/SchemaGraphicNote.hpp
"
15
#include "
dbe/SchemaGraphicsScene.hpp
"
16
#include "
dbe/SchemaNoteEditor.hpp
"
17
#include "
dbe/SchemaStyle.hpp
"
18
19
#include <iostream>
20
21
namespace
dbse
{
22
23
SchemaGraphicNote::SchemaGraphicNote
(
const
QString& name,
const
QString&
text
, QGraphicsObject* parent)
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
}
35
36
void
37
SchemaGraphicNote::open_editor
()
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
}
58
59
void
60
SchemaGraphicNote::mouseDoubleClickEvent
(QGraphicsSceneMouseEvent*)
61
{
62
open_editor
();
63
}
64
65
void
66
SchemaGraphicNote::update_note
(QString
text
)
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
}
74
75
QRectF
76
SchemaGraphicNote::boundingRect
()
const
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
}
93
94
void
95
SchemaGraphicNote::paint
(QPainter* painter,
const
QStyleOptionGraphicsItem*
/*option*/
, QWidget*
/*widget*/
)
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
}
108
109
QPainterPath
110
SchemaGraphicNote::shape
()
const
111
{
112
QPainterPath path;
113
path.addRect(
boundingRect
());
114
return
path;
115
}
116
}
// namespace dbse
SchemaGraphicNote.hpp
SchemaGraphicsScene.hpp
SchemaNoteEditor.hpp
SchemaStyle.hpp
dbse::SchemaGraphicNote::paint
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
Definition
SchemaGraphicNote.cpp:95
dbse::SchemaGraphicNote::text
QString text()
Definition
SchemaGraphicNote.hpp:24
dbse::SchemaGraphicNote::shape
QPainterPath shape() const override
Definition
SchemaGraphicNote.cpp:110
dbse::SchemaGraphicNote::updated
void updated()
dbse::SchemaGraphicNote::SchemaGraphicNote
SchemaGraphicNote(const QString &name, const QString &text, QGraphicsObject *parent=nullptr)
Definition
SchemaGraphicNote.cpp:23
dbse::SchemaGraphicNote::open_editor
void open_editor()
Definition
SchemaGraphicNote.cpp:37
dbse::SchemaGraphicNote::boundingRect
QRectF boundingRect() const override
Definition
SchemaGraphicNote.cpp:76
dbse::SchemaGraphicNote::m_name
QString m_name
Definition
SchemaGraphicNote.hpp:34
dbse::SchemaGraphicNote::mouseDoubleClickEvent
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *ev) override
Definition
SchemaGraphicNote.cpp:60
dbse::SchemaGraphicNote::m_text
QString m_text
Definition
SchemaGraphicNote.hpp:35
dbse::SchemaGraphicNote::update_note
void update_note(QString text)
Definition
SchemaGraphicNote.cpp:66
dbse::SchemaGraphicsScene
Definition
SchemaGraphicsScene.hpp:15
dbse::SchemaGraphicsScene::remove_note_object
void remove_note_object(SchemaGraphicNote *obj)
Definition
SchemaGraphicsScene.cpp:370
dbse::SchemaNoteEditor
Definition
SchemaNoteEditor.hpp:13
dbse::SchemaNoteEditor::SchemaNoteEditor
SchemaNoteEditor(SchemaGraphicNote *note, QWidget *parent=0)
Definition
SchemaNoteEditor.cpp:9
dbse
Including QT Headers.
Definition
SchemaAttributeEditor.hpp:13
dbse::SchemaStyle::get_color
static QColor get_color(const QString &item, const QString &group)
Definition
SchemaStyle.cpp:105
dbse::SchemaStyle::get_font
static QFont get_font(const QString &group)
Definition
SchemaStyle.cpp:127
Generated on
for DUNE-DAQ by
1.18.0