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,
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
38
void
SchemaGraphicNote::open_editor
() {
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
SchemaGraphicNote::mouseDoubleClickEvent
( QGraphicsSceneMouseEvent* ) {
60
open_editor
();
61
}
62
63
64
void
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
72
QRectF
SchemaGraphicNote::boundingRect
()
const
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
90
void
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
105
QPainterPath
SchemaGraphicNote::shape
()
const
{
106
QPainterPath path;
107
path.addRect (
boundingRect
() );
108
return
path;
109
}
110
}
//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:90
dbse::SchemaGraphicNote::text
QString text()
Definition
SchemaGraphicNote.hpp:29
dbse::SchemaGraphicNote::shape
QPainterPath shape() const override
Definition
SchemaGraphicNote.cpp:105
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:38
dbse::SchemaGraphicNote::boundingRect
QRectF boundingRect() const override
Definition
SchemaGraphicNote.cpp:72
dbse::SchemaGraphicNote::m_name
QString m_name
Definition
SchemaGraphicNote.hpp:38
dbse::SchemaGraphicNote::mouseDoubleClickEvent
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *ev) override
Definition
SchemaGraphicNote.cpp:59
dbse::SchemaGraphicNote::m_text
QString m_text
Definition
SchemaGraphicNote.hpp:39
dbse::SchemaGraphicNote::update_note
void update_note(QString text)
Definition
SchemaGraphicNote.cpp:64
dbse::SchemaGraphicsScene
Definition
SchemaGraphicsScene.hpp:16
dbse::SchemaGraphicsScene::remove_note_object
void remove_note_object(SchemaGraphicNote *obj)
Definition
SchemaGraphicsScene.cpp:387
dbse::SchemaNoteEditor
Definition
SchemaNoteEditor.hpp:12
dbse
Including QT Headers.
Definition
SchemaAttributeEditor.hpp:14
dbse::SchemaStyle::get_color
static QColor get_color(const QString &item, const QString &group)
Definition
SchemaStyle.cpp:103
dbse::SchemaStyle::get_font
static QFont get_font(const QString &group)
Definition
SchemaStyle.cpp:125
Generated on
for DUNE-DAQ by
1.17.0