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