MNE-CPP 0.1.9
A Framework for Electrophysiology
Loading...
Searching...
No Matches
graph.cpp
Go to the documentation of this file.
1//=============================================================================================================
36//=============================================================================================================
37// INCLUDES
38//=============================================================================================================
39
40#include "graph.h"
41
42//=============================================================================================================
43// QT INCLUDES
44//=============================================================================================================
45
46#include <QResizeEvent>
47#include <QPainter>
48
49//=============================================================================================================
50// EIGEN INCLUDES
51//=============================================================================================================
52
53//=============================================================================================================
54// USED NAMESPACES
55//=============================================================================================================
56
57using namespace DISPLIB;
58using namespace Eigen;
59
60//=============================================================================================================
61// DEFINE MEMBER METHODS
62//=============================================================================================================
63
64Graph::Graph(QWidget *parent)
65: QWidget(parent)
66{
67 init();
68}
69
70//=============================================================================================================
71
73{
74 m_sTitle = QString("");
75 m_sXLabel = QString("");
76 m_sYLabel = QString("");
77
78 //Set Borders
81
82 this->setMinimumWidth(m_iBorderLeftRight*2.5);
83 this->setMinimumHeight(m_iBorderTopBottom*2.5);
84
85 //Set Fonts
86 m_qFontAxes.setPixelSize(12);
87 m_qPenAxes = QPen(Qt::black);
88
89 m_qFontTitle.setPixelSize(20);
90 m_qFontTitle.setBold(true);
91 m_qPenTitle = QPen(Qt::black);
92}
93
94//=============================================================================================================
95
96void Graph::setTitle(const QString &p_sTitle)
97{
98 m_sTitle = p_sTitle;
99 update();
100}
101
102//=============================================================================================================
103
104void Graph::setXLabel(const QString &p_sXLabel)
105{
106 m_sXLabel = p_sXLabel;
107 update();
108}
109
110//=============================================================================================================
111
112void Graph::setYLabel(const QString &p_sYLabel)
113{
114 m_sYLabel = p_sYLabel;
115 update();
116}
117
118//=============================================================================================================
119
120void Graph::drawLabels(qint32 p_iContentWidth, qint32 p_iContentHeight)
121{
122 QPainter painter(this);
123
124 qint32 t_iLabelWidth = m_qSizeWidget.width()-2*m_iBorderLeftRight;
125 qint32 t_iLabelHeight = 100;
126
127 // -- Title --
128 if(!m_sTitle.isEmpty())
129 {
130 painter.save();
131 painter.setPen(m_qPenTitle);
132 painter.setFont(m_qFontTitle);
133
134 painter.translate((m_qSizeWidget.width()-t_iLabelWidth)/2, (m_qSizeWidget.height()-p_iContentHeight)/2 - m_iBorderTopBottom*1.5);
135 painter.drawText(QRect(0, 0, t_iLabelWidth, t_iLabelHeight), Qt::AlignCenter, m_sTitle);
136
137 painter.restore();
138 }
139
140 // -- Axes --
141 painter.setPen(m_qPenAxes);
142 painter.setFont(m_qFontAxes);
143
144 // X Label
145 if(!m_sXLabel.isEmpty())
146 {
147 painter.save();
148 painter.translate((m_qSizeWidget.width()-t_iLabelWidth)/2, p_iContentHeight+((m_qSizeWidget.height()-p_iContentHeight-m_iBorderTopBottom)/2));
149 painter.drawText(QRect(0, 0, t_iLabelWidth, t_iLabelHeight), Qt::AlignCenter, m_sXLabel);
150 painter.restore();
151 }
152
153 //Y Label
154 if(!m_sYLabel.isEmpty())
155 {
156 painter.save();
157 painter.rotate(270);
158 painter.translate(-(m_qSizeWidget.height()+t_iLabelWidth)/2,(m_qSizeWidget.width()-p_iContentWidth)/2-t_iLabelHeight*0.75);
159 painter.drawText(QRect(0, 0, t_iLabelWidth, t_iLabelHeight), Qt::AlignCenter, m_sYLabel);
160 painter.restore();
161 }
162}
163
164//=============================================================================================================
165
166void Graph::resizeEvent(QResizeEvent* event)
167{
168 m_qSizeWidget = event->size();
169 // Call base class impl
170 QWidget::resizeEvent(event);
171}
172
Graph class declaration.
QFont m_qFontTitle
Definition graph.h:149
QPen m_qPenAxes
Definition graph.h:158
Graph(QWidget *parent=0)
Definition graph.cpp:64
QString m_sXLabel
Definition graph.h:155
void init()
Definition graph.cpp:72
QSize m_qSizeWidget
Definition graph.h:146
QFont m_qFontAxes
Definition graph.h:157
void setYLabel(const QString &p_sYLabel)
Definition graph.cpp:112
QString m_sTitle
Definition graph.h:148
QString m_sYLabel
Definition graph.h:156
QPen m_qPenTitle
Definition graph.h:150
qint32 m_iBorderLeftRight
Definition graph.h:153
void setTitle(const QString &p_sTitle)
Definition graph.cpp:96
void resizeEvent(QResizeEvent *event)
Definition graph.cpp:166
qint32 m_iBorderTopBottom
Definition graph.h:152
void drawLabels(qint32 p_iContentWidth, qint32 p_iContentHeight)
Definition graph.cpp:120
void setXLabel(const QString &p_sXLabel)
Definition graph.cpp:104