mainwindow.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 ** **
3 ** QcGauge, for instrumentation, and real time data measurement **
4 ** visualization widget for Qt. **
5 ** Copyright (C) 2015 Hadj Tahar Berrima **
6 ** **
7 ** This program is free software: you can redistribute it and/or modify **
8 ** it under the terms of the GNU Lesser General Public License as **
9 ** published by the Free Software Foundation, either version 3 of the **
10 ** License, or (at your option) any later version. **
11 ** **
12 ** This program is distributed in the hope that it will be useful, **
13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of **
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the **
15 ** GNU Lesser General Public License for more details. **
16 ** **
17 ** You should have received a copy of the GNU Lesser General Public **
18 ** License along with this program. **
19 ** If not, see http://www.gnu.org/licenses/. **
20 ** **
21 ****************************************************************************
22 ** Author: Hadj Tahar Berrima **
23 ** Website: http://pytricity.com/ **
24 ** Contact: berrima_tahar@yahoo.com **
25 ** Date: 1 dec 2014 **
26 ** Version: 1.0 **
27 ****************************************************************************/
28 
29 #include "mainwindow.h"
30 
31 #ifndef Q_MOC_RUN // MOC doesnt' parse boost correctly. See https://bugreports.qt.io/browse/QTBUG-22829
32 
33 #include <QMessageBox>
34 #include <QtGui>
35 #include <QtCore>
36 #include <QString>
37 
38 QT_BEGIN_NAMESPACE
39 
41 {
42 public:
43  QWidget *centralWidget;
44  QGridLayout *gridLayout;
45  QHBoxLayout *horizontalLayout;
46  QMenuBar *menuBar;
47  QToolBar *mainToolBar;
48  QStatusBar *statusBar;
49 
50  void setupUi(QMainWindow *MainWindow)
51  {
52  if (MainWindow->objectName().isEmpty())
53  MainWindow->setObjectName(QString("MainWindow"));
54  MainWindow->resize(400, 300);
55  centralWidget = new QWidget(MainWindow);
56  centralWidget->setObjectName(QString("centralWidget"));
57  gridLayout = new QGridLayout(centralWidget);
58  gridLayout->setSpacing(6);
59  gridLayout->setContentsMargins(11, 11, 11, 11);
60  gridLayout->setObjectName(QString("gridLayout"));
61  horizontalLayout = new QHBoxLayout();
62  horizontalLayout->setSpacing(6);
63  horizontalLayout->setObjectName(QString("horizontalLayout"));
64 
65  gridLayout->addLayout(horizontalLayout, 0, 0, 1, 1);
66 
67  MainWindow->setCentralWidget(centralWidget);
68  menuBar = new QMenuBar(MainWindow);
69  menuBar->setObjectName(QString("menuBar"));
70  menuBar->setGeometry(QRect(0, 0, 400, 20));
71  MainWindow->setMenuBar(menuBar);
72  mainToolBar = new QToolBar(MainWindow);
73  mainToolBar->setObjectName(QString("mainToolBar"));
74  MainWindow->addToolBar(Qt::TopToolBarArea, mainToolBar);
75  statusBar = new QStatusBar(MainWindow);
76  statusBar->setObjectName(QString("statusBar"));
77  MainWindow->setStatusBar(statusBar);
78 
79  retranslateUi(MainWindow);
80 
81  QMetaObject::connectSlotsByName(MainWindow);
82  } // setupUi
83 
84  void retranslateUi(QMainWindow *MainWindow)
85  {
86  MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0));
87  } // retranslateUi
88 
89 };
90 
91 namespace Ui {
92  class MainWindow: public Ui_MainWindow {};
93 } // namespace Ui
94 
95 QT_END_NAMESPACE
96 
97 
98 MainWindow::MainWindow(QWidget *parent, ros::NodeHandle* nh) :
99  QMainWindow(parent),
100  ui(new Ui::MainWindow)
101 {
102  ui->setupUi(this);
103 
107  bkg1->clearrColors();
108  bkg1->addColor(0.1,Qt::black);
109  bkg1->addColor(1.0,Qt::white);
110 
112  bkg2->clearrColors();
113  bkg2->addColor(0.1,Qt::gray);
114  bkg2->addColor(1.0,Qt::darkGray);
115 
116  // Range of the indicator
117  int minimum;
118  nh->getParam("minimum", minimum);
119  int maximum;
120  nh->getParam("maximum", maximum);
121  //mSpeedGauge->addArc(55);
122  mSpeedGauge->addDegrees(65)->setValueRange(minimum,maximum);
123  //mSpeedGauge->addColorBand(50);
124  mSpeedGauge->addValues(80)->setValueRange(minimum,maximum);
125 
126  // Gauge label
127  std::string gaugeName;
128  nh->getParam("gauge_name", gaugeName);
129  mSpeedGauge->addLabel(70)->setText(gaugeName.c_str());
130 
131  // The needle
132  QcLabelItem *lab = mSpeedGauge->addLabel(40);
133  lab->setText("0");
135  mSpeedNeedle->setLabel(lab);
136  mSpeedNeedle->setColor(Qt::black);
137  mSpeedNeedle->setValueRange(minimum,maximum);
139  mSpeedGauge->addGlass(88);
140  ui->horizontalLayout->addWidget(mSpeedGauge);
141 }
142 
144 {
145  delete ui;
146 }
147 #endif
QMenuBar * menuBar
Definition: mainwindow.cpp:46
Ui::MainWindow * ui
Definition: mainwindow.h:55
QcDegreesItem * addDegrees(float position)
QToolBar * mainToolBar
Definition: mainwindow.cpp:47
QcBackgroundItem * addBackground(float position)
Definition: mainwindow.h:41
QHBoxLayout * horizontalLayout
Definition: mainwindow.cpp:45
QcGlassItem * addGlass(float position)
void setText(const QString &text, bool repaint=true)
QcNeedleItem * addNeedle(float position)
QWidget * centralWidget
Definition: mainwindow.cpp:43
MainWindow(QWidget *parent=0, ros::NodeHandle *nh=0)
Definition: mainwindow.cpp:98
void retranslateUi(QMainWindow *MainWindow)
Definition: mainwindow.cpp:84
QStatusBar * statusBar
Definition: mainwindow.cpp:48
void setValueRange(float minValue, float maxValue)
void setLabel(QcLabelItem *)
QcValuesItem * addValues(float position)
QGridLayout * gridLayout
Definition: mainwindow.cpp:44
void setupUi(QMainWindow *MainWindow)
Definition: mainwindow.cpp:50
bool getParam(const std::string &key, std::string &s) const
void setColor(const QColor &color)
QcNeedleItem * mSpeedNeedle
Definition: mainwindow.h:52
QcLabelItem * addLabel(float position)
void addColor(float position, const QColor &color)
QcGaugeWidget * mSpeedGauge
Definition: mainwindow.h:57


gauges
Author(s): alexvs
autogenerated on Mon Nov 14 2016 03:55:02