189 lines
6.3 KiB
C++
189 lines
6.3 KiB
C++
/*******************************************************************************
|
|
* *
|
|
* Société de Transports de Montréal. *
|
|
* 2012 *
|
|
* *
|
|
* Projet Zones Tests *
|
|
* *
|
|
* *
|
|
* *
|
|
*******************************************************************************/
|
|
/*
|
|
Description:
|
|
Page offrant différentes option pour l'entretien de la ZT
|
|
|
|
*/
|
|
|
|
/* ************************************************************************** */
|
|
/* Revision:
|
|
### 20131021 JFM
|
|
Verision d'origine.
|
|
|
|
### YYYMMDD Description du besoin ou du bug
|
|
Description du changement.
|
|
*/
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
#include "GeneralSettingsPage.h"
|
|
#include <QPainter>
|
|
#include "GlobalDefine.h"
|
|
#include <QDialog>
|
|
#include <QMainWindow>
|
|
#include "Zonetest.h"
|
|
#include <QDateTime>
|
|
#include <QFont>
|
|
#include <QGraphicsProxyWidget>
|
|
#include <sys/time.h>
|
|
#include "ZTLog.h"
|
|
|
|
|
|
|
|
CGeneralSettingsPage::CGeneralSettingsPage(QGraphicsWidget *Parent)
|
|
{
|
|
Q_UNUSED(Parent)
|
|
|
|
|
|
mProgramHandle = 0;
|
|
|
|
mBackgroundRect = new QGraphicsRectItem(boundingRect(), this);
|
|
QBrush BackgroundBrush(QColor(245, 245, 255));
|
|
mBackgroundRect->setBrush(BackgroundBrush);
|
|
|
|
QGraphicsTextItem *Title = new QGraphicsTextItem("Paramètres généraux",this);
|
|
QFont font;
|
|
font.setPointSize(18);
|
|
Title->setFont(font);
|
|
Title->setPos(40,10);
|
|
|
|
Title = new QGraphicsTextItem("Ajuster date & heure",this);
|
|
Title->setFont(font);
|
|
Title->setPos(270,80);
|
|
|
|
mCancelButton = new CTextButtonWidget("Fermer");
|
|
mCancelButton->setParentItem(this);
|
|
mCancelButton->setPos(700,550);
|
|
connect(mCancelButton,SIGNAL(TxtButtonClicked(CTextButtonWidget*)),this,SLOT(ButtonClicked(CTextButtonWidget*)));
|
|
|
|
QGraphicsProxyWidget *Proxy = new QGraphicsProxyWidget(this);
|
|
mCalendarWidget = new QCalendarWidget();
|
|
Proxy->setWidget(mCalendarWidget);
|
|
Proxy->setPos(100,150);
|
|
|
|
mTimeEdit = new QTimeEdit();
|
|
Proxy = new QGraphicsProxyWidget(this);
|
|
Proxy->setWidget(mTimeEdit);
|
|
Proxy->setPos(475,150);
|
|
mTimeEdit->setTime(QTime::currentTime());
|
|
mTimeEdit->setDisplayFormat("hh:mm");
|
|
|
|
mApplyDateTimeBtn = new CTextButtonWidget("Changer date & heure");
|
|
mApplyDateTimeBtn->setParentItem(this);
|
|
mApplyDateTimeBtn->setPos(450,250);
|
|
connect(mApplyDateTimeBtn,SIGNAL(TxtButtonClicked(CTextButtonWidget*)),this,SLOT(ButtonClicked(CTextButtonWidget*)));
|
|
|
|
QGraphicsRectItem *Frame = new QGraphicsRectItem(80,70,600,300,this);
|
|
QPen FramePen;
|
|
FramePen.setWidth(3);
|
|
Frame->setPen(FramePen);
|
|
|
|
|
|
Title = new QGraphicsTextItem("Seuil Pneu de Guidage",this);
|
|
Title->setFont(font);
|
|
Title->setPos(270,400);
|
|
Frame = new QGraphicsRectItem(80,405,600,175,this);
|
|
Frame->setPen(FramePen);
|
|
|
|
mPGTresholdValueSpinBox = new QSpinBox();
|
|
Proxy = new QGraphicsProxyWidget(this);
|
|
Proxy->setWidget(mPGTresholdValueSpinBox);
|
|
Proxy->setPos(125,500);
|
|
mPGTresholdValueSpinBox->resize(70,30);
|
|
mPGTresholdValueSpinBox->setMinimum(1);
|
|
mPGTresholdValueSpinBox->setMaximum(2000);
|
|
mPGTresholdValueSpinBox->setValue(255);
|
|
|
|
mPGValueSetBtn = new CTextButtonWidget("Changer Seuil",0,30);
|
|
mPGValueSetBtn->setParentItem(this);
|
|
mPGValueSetBtn->setPos(200,500);
|
|
connect(mPGValueSetBtn,SIGNAL(TxtButtonClicked(CTextButtonWidget*)),this,SLOT(ButtonClicked(CTextButtonWidget*)));
|
|
|
|
mActualPGTresholdValueText = new QGraphicsTextItem(this);
|
|
mActualPGTresholdValueText->setPos(125,450);
|
|
font.setPointSize(14);
|
|
mActualPGTresholdValueText->setFont(font);
|
|
mActualPGTresholdValueText->setPlainText("Valeur actuelle : 255");
|
|
|
|
}
|
|
|
|
void CGeneralSettingsPage::resizeEvent(QGraphicsSceneResizeEvent *event)
|
|
{
|
|
Q_UNUSED(event)
|
|
|
|
|
|
mBackgroundRect->setRect(boundingRect());
|
|
}
|
|
|
|
void CGeneralSettingsPage::ButtonClicked(CTextButtonWidget *BtnPtr)
|
|
{
|
|
if(BtnPtr == mCancelButton)
|
|
{
|
|
mProgramHandle->CloseGeneralSettingsPage();
|
|
hide();
|
|
}
|
|
else if(BtnPtr == mApplyDateTimeBtn)
|
|
{
|
|
|
|
time_t time_data = time(0);
|
|
struct tm* tm_ptr = localtime(&time_data);
|
|
|
|
tm_ptr->tm_min = mTimeEdit->time().minute();
|
|
tm_ptr->tm_hour = mTimeEdit->time().hour();
|
|
tm_ptr->tm_mday = mCalendarWidget->selectedDate().day();
|
|
tm_ptr->tm_mon = mCalendarWidget->selectedDate().month()-1;
|
|
tm_ptr->tm_year = mCalendarWidget->selectedDate().year()-1900;
|
|
|
|
const struct timeval tv = {mktime(tm_ptr),0};
|
|
if(settimeofday(&tv,0) < 0)
|
|
{
|
|
qDebug("Settimeofday failed");
|
|
CZTLog::instance()->AddLogString("Échec du changement de la date & de l'heure",true);
|
|
}
|
|
else
|
|
{
|
|
if ( system("/sbin/hwclock --systohc") < 0 )
|
|
{
|
|
//qDebug("hwclock sync failed");
|
|
CZTLog::instance()->AddLogString("Échec du changement de la date & de l'heure (hwsync failure)",true);
|
|
}
|
|
else
|
|
CZTLog::instance()->AddLogString(QString().sprintf("Changement de date & heure: %s %s",mCalendarWidget->selectedDate().toString("yyyy/MM/dd").toUtf8().data(),mTimeEdit->time().toString("hh:mm").toUtf8().data()),true);
|
|
}
|
|
}
|
|
else if(BtnPtr == mPGValueSetBtn)
|
|
{
|
|
CZTLog::instance()->AddLogString(QString().sprintf("Seuil PG changé. Ancien: %d, Nouveau: %d",mProgramHandle->GetPGTreshold(),mPGTresholdValueSpinBox->value()),true);
|
|
mProgramHandle->SetPGTreshold(mPGTresholdValueSpinBox->value());
|
|
mActualPGTresholdValueText->setPlainText(QString().sprintf("Valeur seuil PG actuelle %d",mProgramHandle->GetPGTreshold()));
|
|
}
|
|
}
|
|
|
|
void CGeneralSettingsPage::showEvent(QShowEvent *event)
|
|
{
|
|
Q_UNUSED(event)
|
|
mTimeEdit->setTime(QTime::currentTime());
|
|
mActualPGTresholdValueText->setPlainText(QString().sprintf("Valeur seuil PG actuelle %d",mProgramHandle->GetPGTreshold()));
|
|
mPGTresholdValueSpinBox->setValue(mProgramHandle->GetPGTreshold());
|
|
}
|
|
|
|
//Grab the mouse if the user clicks outside buttons
|
|
void CGeneralSettingsPage::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
{
|
|
Q_UNUSED(event)
|
|
}
|
|
void CGeneralSettingsPage::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|
{
|
|
Q_UNUSED(event)
|
|
}
|