mainwindow.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002 **                                                                        **
00003 **  QcGauge, for instrumentation, and real time data measurement          **
00004 **  visualization widget for Qt.                                          **
00005 **  Copyright (C) 2015 Hadj Tahar Berrima                                 **
00006 **                                                                        **
00007 **  This program is free software: you can redistribute it and/or modify  **
00008 **  it under the terms of the GNU Lesser General Public License as        **
00009 **  published by the Free Software Foundation, either version 3 of the    **
00010 **  License, or (at your option) any later version.                       **
00011 **                                                                        **
00012 **  This program is distributed in the hope that it will be useful,       **
00013 **  but WITHOUT ANY WARRANTY; without even the implied warranty of        **
00014 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         **
00015 **  GNU Lesser General Public License for more details.                   **
00016 **                                                                        **
00017 **  You should have received a copy of the GNU Lesser General Public      **
00018 **  License along with this program.                                      **
00019 **  If not, see http://www.gnu.org/licenses/.                             **
00020 **                                                                        **
00021 ****************************************************************************
00022 **           Author:  Hadj Tahar Berrima                                  **
00023 **           Website: http://pytricity.com/                               **
00024 **           Contact: berrima_tahar@yahoo.com                             **
00025 **           Date:    1 dec 2014                                          **
00026 **           Version:  1.0                                                **
00027 ****************************************************************************/
00028 
00029 #include "mainwindow.h"
00030 
00031 #ifndef Q_MOC_RUN // MOC doesnt' parse boost correctly. See https://bugreports.qt.io/browse/QTBUG-22829
00032 
00033 #include <QMessageBox>
00034 #include <QtGui>
00035 #include <QtCore>
00036 #include <QString>
00037 
00038 QT_BEGIN_NAMESPACE
00039 
00040 class Ui_MainWindow
00041 {
00042 public:
00043     QWidget *centralWidget;
00044     QGridLayout *gridLayout;
00045     QHBoxLayout *horizontalLayout;
00046     QMenuBar *menuBar;
00047     QToolBar *mainToolBar;
00048     QStatusBar *statusBar;
00049 
00050     void setupUi(QMainWindow *MainWindow)
00051     {
00052         if (MainWindow->objectName().isEmpty())
00053             MainWindow->setObjectName(QString("MainWindow"));
00054         MainWindow->resize(400, 300);
00055         centralWidget = new QWidget(MainWindow);
00056         centralWidget->setObjectName(QString("centralWidget"));
00057         gridLayout = new QGridLayout(centralWidget);
00058         gridLayout->setSpacing(6);
00059         gridLayout->setContentsMargins(11, 11, 11, 11);
00060         gridLayout->setObjectName(QString("gridLayout"));
00061         horizontalLayout = new QHBoxLayout();
00062         horizontalLayout->setSpacing(6);
00063         horizontalLayout->setObjectName(QString("horizontalLayout"));
00064 
00065         gridLayout->addLayout(horizontalLayout, 0, 0, 1, 1);
00066 
00067         MainWindow->setCentralWidget(centralWidget);
00068         menuBar = new QMenuBar(MainWindow);
00069         menuBar->setObjectName(QString("menuBar"));
00070         menuBar->setGeometry(QRect(0, 0, 400, 20));
00071         MainWindow->setMenuBar(menuBar);
00072         mainToolBar = new QToolBar(MainWindow);
00073         mainToolBar->setObjectName(QString("mainToolBar"));
00074         MainWindow->addToolBar(Qt::TopToolBarArea, mainToolBar);
00075         statusBar = new QStatusBar(MainWindow);
00076         statusBar->setObjectName(QString("statusBar"));
00077         MainWindow->setStatusBar(statusBar);
00078 
00079         retranslateUi(MainWindow);
00080 
00081         QMetaObject::connectSlotsByName(MainWindow);
00082     } // setupUi
00083 
00084     void retranslateUi(QMainWindow *MainWindow)
00085     {
00086         MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0));
00087     } // retranslateUi
00088 
00089 };
00090 
00091 namespace Ui {
00092     class MainWindow: public Ui_MainWindow {};
00093 } // namespace Ui
00094 
00095 QT_END_NAMESPACE
00096 
00097 
00098 MainWindow::MainWindow(QWidget *parent, ros::NodeHandle* nh) :
00099     QMainWindow(parent),
00100     ui(new Ui::MainWindow)
00101 { 
00102     ui->setupUi(this);
00103 
00104     mSpeedGauge = new QcGaugeWidget;
00105     mSpeedGauge->addBackground(99);
00106     QcBackgroundItem *bkg1 = mSpeedGauge->addBackground(92);
00107     bkg1->clearrColors();
00108     bkg1->addColor(0.1,Qt::black);
00109     bkg1->addColor(1.0,Qt::white);
00110 
00111     QcBackgroundItem *bkg2 = mSpeedGauge->addBackground(88);
00112     bkg2->clearrColors();
00113     bkg2->addColor(0.1,Qt::gray);
00114     bkg2->addColor(1.0,Qt::darkGray);
00115 
00116     // Range of the indicator
00117     int minimum;
00118     nh->getParam("minimum", minimum);
00119     int maximum;
00120     nh->getParam("maximum", maximum);
00121     //mSpeedGauge->addArc(55);
00122     mSpeedGauge->addDegrees(65)->setValueRange(minimum,maximum);
00123     //mSpeedGauge->addColorBand(50);
00124     mSpeedGauge->addValues(80)->setValueRange(minimum,maximum);
00125     
00126     // Gauge label
00127     std::string gaugeName;
00128     nh->getParam("gauge_name", gaugeName);
00129     mSpeedGauge->addLabel(70)->setText(gaugeName.c_str());
00130     
00131     // The needle
00132     QcLabelItem *lab = mSpeedGauge->addLabel(40);
00133     lab->setText("0");
00134     mSpeedNeedle = mSpeedGauge->addNeedle(60);
00135     mSpeedNeedle->setLabel(lab);
00136     mSpeedNeedle->setColor(Qt::black);
00137     mSpeedNeedle->setValueRange(minimum,maximum);
00138     mSpeedGauge->addBackground(7);
00139     mSpeedGauge->addGlass(88);
00140     ui->horizontalLayout->addWidget(mSpeedGauge);
00141 }
00142 
00143 MainWindow::~MainWindow()
00144 {
00145     delete ui;
00146 }
00147 #endif


gauges
Author(s): alexvs
autogenerated on Mon Nov 14 2016 03:33:07