#include "dialog.h"
#include <QBoxLayout>
Dialog
::Dialog(int tempCelsius,
QWidget *parent
){
celsiusDia
= new QDial(celsiusGroupBox
);
fahrenheitDia
= new QDial(fahrenheitGroupBox
);
celsiusLDNumber
= new QLCDNumber(celsiusGroupBox
);
fahrenheitLDNumber
= new QLCDNumber(fahrenheitGroupBox
);
celsiusGroupBox->setTitle("Celsius");
fahrenheitGroupBox->setTitle("Fahrenheit");
leftLayout->addWidget(celsiusDia);
leftLayout->addWidget(celsiusLDNumber);
rightLayout->addWidget(fahrenheitDia);
rightLayout->addWidget(fahrenheitLDNumber);
connect(celsiusDia, SIGNAL(valueChanged(int)), this, SLOT(setTempCelsius()));
connect(celsiusDia, SIGNAL(valueChanged(int)), celsiusLDNumber, SLOT(display(int)));
connect(this, SIGNAL(tempCelsiusChanged(int)), celsiusDia, SLOT(setValue(int)));
connect(fahrenheitDia, SIGNAL(valueChanged(int)), this, SLOT(setTempFahrenheit()));
connect(fahrenheitDia, SIGNAL(valueChanged(int)), fahrenheitLDNumber, SLOT(display(int)));
connect(this, SIGNAL(tempFahrenheitChanged(int)), fahrenheitDia, SLOT(setValue(int)));
m_tempCelsius = 0;
setTempCelsius(tempCelsius);
}
int Dialog::tempCelsius() const
{
return m_tempCelsius;
}
int Dialog::tempFahrenheit() const
{
return m_tempCelsius*(9.0/5.0)+32;
}
void Dialog::setTempCelsius(int tempCelsius)
{
if (m_tempCelsius==tempCelsius)
return;
m_tempCelsius = tempCelsius;
emit tempCelsiusChanged(m_tempCelsius);
emit tempFahrenheitChanged(tempFahrenheit());
}
void Dialog::setTempFahrenheit(int tempFahrenheit)
{
int tempCelsius = (tempFahrenheit - 32) * (5.0/9.0);
setTempCelsius(tempCelsius);
}
#include "dialog.h"
#include <QBoxLayout>
Dialog::Dialog(int tempCelsius, QWidget *parent)
: QDialog(parent)
{
celsiusGroupBox = new QGroupBox(this);
fahrenheitGroupBox = new QGroupBox(this);
celsiusDia = new QDial(celsiusGroupBox);
fahrenheitDia = new QDial(fahrenheitGroupBox);
celsiusLDNumber = new QLCDNumber(celsiusGroupBox);
fahrenheitLDNumber = new QLCDNumber(fahrenheitGroupBox);
celsiusGroupBox->setTitle("Celsius");
fahrenheitGroupBox->setTitle("Fahrenheit");
leftLayout->addWidget(celsiusDia);
leftLayout->addWidget(celsiusLDNumber);
rightLayout->addWidget(fahrenheitDia);
rightLayout->addWidget(fahrenheitLDNumber);
connect(celsiusDia, SIGNAL(valueChanged(int)), this, SLOT(setTempCelsius()));
connect(celsiusDia, SIGNAL(valueChanged(int)), celsiusLDNumber, SLOT(display(int)));
connect(this, SIGNAL(tempCelsiusChanged(int)), celsiusDia, SLOT(setValue(int)));
connect(fahrenheitDia, SIGNAL(valueChanged(int)), this, SLOT(setTempFahrenheit()));
connect(fahrenheitDia, SIGNAL(valueChanged(int)), fahrenheitLDNumber, SLOT(display(int)));
connect(this, SIGNAL(tempFahrenheitChanged(int)), fahrenheitDia, SLOT(setValue(int)));
m_tempCelsius = 0;
setTempCelsius(tempCelsius);
}
int Dialog::tempCelsius() const
{
return m_tempCelsius;
}
int Dialog::tempFahrenheit() const
{
return m_tempCelsius*(9.0/5.0)+32;
}
void Dialog::setTempCelsius(int tempCelsius)
{
if (m_tempCelsius==tempCelsius)
return;
m_tempCelsius = tempCelsius;
emit tempCelsiusChanged(m_tempCelsius);
emit tempFahrenheitChanged(tempFahrenheit());
}
void Dialog::setTempFahrenheit(int tempFahrenheit)
{
int tempCelsius = (tempFahrenheit - 32) * (5.0/9.0);
setTempCelsius(tempCelsius);
}
To copy to clipboard, switch view to plain text mode
Bookmarks