You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
132 lines
4.5 KiB
C++
132 lines
4.5 KiB
C++
#include "qtimedlg.h"
|
|
#pragma execution_character_set("utf-8")
|
|
QTimeDlg::QTimeDlg(QWidget *parent)
|
|
: QDialog(parent), m_clock(NULL)
|
|
{
|
|
ui.setupUi(this);
|
|
m_clock = new QClockDlg;
|
|
m_clock->setMinimumSize(QSize(100, 150));
|
|
ui.gridLayout->addWidget(m_clock);
|
|
setWindowIcon(QIcon(":/image/leaper"));
|
|
setWindowFlags(Qt::WindowCloseButtonHint);//|Qt::WindowContextHelpButtonHint | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint
|
|
//connect(ui.dial_timedlg, SIGNAL(valueChanged(int)), this, SLOT(valuechange(int)));
|
|
//connect(ui.dial_2_timedlg, SIGNAL(valueChanged(int)), this, SLOT(valuechange(int)));
|
|
connect(ui.hour_comboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(onCurrentStrChange(QString)));
|
|
connect(ui.minute_comboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(onCurrentStrChange(QString)));
|
|
connect(ui.pushButton_timedlg, SIGNAL(clicked()), this, SLOT(SlotOk()));
|
|
connect(ui.calendarWidget_timedlg, SIGNAL(clicked(const QDate &)), this, SLOT(SlotCalWidget(const QDate &)));
|
|
connect(ui.calendarWidget_timedlg, SIGNAL(currentPageChanged(int, int)), this, SLOT(oncurrentPageChanged(int, int)));
|
|
}
|
|
|
|
QTimeDlg::~QTimeDlg()
|
|
{
|
|
if (m_clock)
|
|
{
|
|
delete m_clock;
|
|
m_clock = NULL;
|
|
}
|
|
}
|
|
Q_SLOT void QTimeDlg::oncurrentPageChanged(int nyear, int nMonth)
|
|
{
|
|
m_Day = m_date.day();
|
|
m_date.setDate(nyear, nMonth, m_Day);
|
|
QString m_str = QString("%1 %2").arg(m_date.toString("yyyy-MM-dd")).arg(m_time.toString("hh:mm"));
|
|
ui.label_timedlg->setText(m_str);
|
|
}
|
|
|
|
Q_SLOT void QTimeDlg::onCurrentStrChange(QString str)
|
|
{
|
|
QString strObj = sender()->objectName();
|
|
if (strObj == "hour_comboBox"){
|
|
int m_minute = m_time.minute();
|
|
int m_value = str.toInt();
|
|
m_time.setHMS(m_value, m_minute, 0);
|
|
m_clock->SetTime(m_value, m_minute);
|
|
QString m_str = QString("%1 %2").arg(m_date.toString("yyyy-MM-dd")).arg(m_time.toString("hh:mm"));
|
|
ui.label_timedlg->setText(m_str);
|
|
}
|
|
else if (strObj == "minute_comboBox"){
|
|
int m_hour = m_time.hour();
|
|
int m_value = str.toInt();
|
|
m_clock->SetTime(m_hour, m_value);
|
|
m_time.setHMS(m_hour, m_value, 0);
|
|
QString m_str = QString("%1 %2").arg(m_date.toString("yyyy-MM-dd")).arg(m_time.toString("hh:mm"));
|
|
ui.label_timedlg->setText(m_str);
|
|
}
|
|
int a = 0;
|
|
}
|
|
|
|
Q_SLOT void QTimeDlg::valuechange(int m_value)
|
|
{
|
|
QObject *watch = sender();
|
|
QString m_objname = watch->objectName();
|
|
if (m_objname == "dial_timedlg")
|
|
{
|
|
int m_minute = m_time.minute();
|
|
m_time.setHMS(m_value, m_minute, 0);
|
|
m_clock->SetTime(m_value, m_minute);
|
|
QString m_str = QString("%1 %2").arg(m_date.toString("yyyy-MM-dd")).arg(m_time.toString("hh:mm"));
|
|
ui.label_timedlg->setText(m_str);
|
|
}
|
|
else if (m_objname == "dial_2_timedlg")
|
|
{
|
|
int m_hour = m_time.hour();
|
|
m_clock->SetTime(m_hour, m_value);
|
|
m_time.setHMS(m_hour, m_value, 0);
|
|
QString m_str = QString("%1 %2").arg(m_date.toString("yyyy-MM-dd")).arg(m_time.toString("hh:mm"));
|
|
ui.label_timedlg->setText(m_str);
|
|
}
|
|
}
|
|
|
|
Q_SLOT void QTimeDlg::SlotOk()
|
|
{
|
|
emit(QDialog::accept());
|
|
}
|
|
|
|
void QTimeDlg::SetDateTime(QDateTime m_datetime)
|
|
{
|
|
this->m_time = m_datetime.time();
|
|
this->m_date = m_datetime.date();
|
|
m_clock->InitTime(m_time.hour(), m_time.minute());
|
|
ui.hour_comboBox->setCurrentText(QString::number(m_time.hour()));
|
|
ui.minute_comboBox->setCurrentText(QString::number(m_time.minute()));
|
|
//ui.dial_timedlg->setValue(m_time.hour());
|
|
//ui.dial_2_timedlg->setValue(m_time.minute());
|
|
ui.calendarWidget_timedlg->setSelectedDate(m_date);
|
|
|
|
QString m_str = QString("%1 %2").arg(m_date.toString("yyyy-MM-dd")).arg(m_time.toString("hh:mm"));
|
|
ui.label_timedlg->setText(m_str);
|
|
}
|
|
|
|
void QTimeDlg::SetDateTime(QDate m_date, QTime m_time)
|
|
{
|
|
this->m_time = m_time;
|
|
this->m_date = m_date;
|
|
m_clock->InitTime(m_time.hour(), m_time.minute());
|
|
ui.hour_comboBox->setCurrentText(QString::number(m_time.hour()));
|
|
ui.minute_comboBox->setCurrentText(QString::number(m_time.minute()));
|
|
//ui.dial_timedlg->setValue(m_time.hour());
|
|
//ui.dial_2_timedlg->setValue(m_time.minute());
|
|
ui.calendarWidget_timedlg->setSelectedDate(m_date);
|
|
QString m_str = QString("%1 %2").arg(m_date.toString("yyyy-MM-dd")).arg(m_time.toString("hh:mm"));
|
|
ui.label_timedlg->setText(m_str);
|
|
}
|
|
void QTimeDlg::GetDateTime(QDateTime &m_datetime)
|
|
{
|
|
m_datetime.setDate(m_date);
|
|
m_datetime.setTime(m_time);
|
|
}
|
|
|
|
void QTimeDlg::GetDateTime(QDate &m_date, QTime &m_time)
|
|
{
|
|
m_time = this->m_time;
|
|
m_date = this->m_date;
|
|
}
|
|
|
|
Q_SLOT void QTimeDlg::SlotCalWidget(const QDate &mdate)
|
|
{
|
|
m_date = ui.calendarWidget_timedlg->selectedDate();
|
|
QString m_str = QString("%1 %2").arg(m_date.toString("yyyy-MM-dd")).arg(m_time.toString("hh:mm"));
|
|
ui.label_timedlg->setText(m_str);
|
|
}
|