Blame view

app/gui/oven_control/configdatetimedlg.cpp 4.38 KB
0603c0b43   고영탁   rtc 설정을 시스템에서 하도록 수정
1
  #include <QDateTime>
be7d2a625   고영탁   엔코더 기능 구현
2
  #include <QKeyEvent>
92fef6124   고영탁   환경 설정 - 설정 UI 완료
3
4
  #include "configdatetimedlg.h"
  #include "ui_configdatetimedlg.h"
0603c0b43   고영탁   rtc 설정을 시스템에서 하도록 수정
5
  #include "system.h"
66e60ceb5   김태훈   모든 버튼에 음향 효과 추가
6
  #include "soundplayer.h"
0603c0b43   고영탁   rtc 설정을 시스템에서 하도록 수정
7
92fef6124   고영탁   환경 설정 - 설정 UI 완료
8
9
10
11
12
13
14
15
  
  ConfigDateTimeDlg::ConfigDateTimeDlg(QWidget *parent) :
      QDialog(parent),
      ui(new Ui::ConfigDateTimeDlg)
  {
      ui->setupUi(this);
      this->setWindowFlags( Qt::FramelessWindowHint);
      this->setAttribute( Qt::WA_DeleteOnClose);
be7d2a625   고영탁   엔코더 기능 구현
16
17
      qApp->setActiveWindow(this);
      this->setFocus();
66e60ceb5   김태훈   모든 버튼에 음향 효과 추가
18
19
20
  
      foreach (QPushButton *button, findChildren<QPushButton *>())
          connect(button, &QPushButton::pressed, SoundPlayer::playClick);
92fef6124   고영탁   환경 설정 - 설정 UI 완료
21
      ui->ctrSpBxYear->setFormatterWidth(4);
0603c0b43   고영탁   rtc 설정을 시스템에서 하도록 수정
22
23
24
25
26
27
28
29
      QDateTime dt_tm = QDateTime::currentDateTime();
      QDate dt_ = dt_tm.date();
      QTime tm_ = dt_tm.time();
      ui->ctrSpBxYear->setValue(dt_.year());
      ui->ctrSpBxMonth->setValue(dt_.month());
      ui->ctrSpBxDay->setValue(dt_.day());
      ui->ctrSpBxHour->setValue(tm_.hour());
      ui->ctrSpBxMin->setValue(tm_.minute());
be7d2a625   고영탁   엔코더 기능 구현
30
31
32
  
      ui->ctrSpBxYear->setFocus();
      m_bInputState = true;
63a45681f   고영탁   엔코더 기능 구현
33
34
      connect(ui->keyboardwidget, SIGNAL(onOkKeyClicked()), this, SLOT(keyEnter_clicked()));
      connect(ui->keyboardwidget, SIGNAL(onCancelKeyClicked()), this, SLOT(keyCancel_clicked()));
be7d2a625   고영탁   엔코더 기능 구현
35
36
37
38
39
40
41
42
43
44
45
46
47
  
      m_pMapperSpins = new QSignalMapper(this);
      m_pMapperSpins->setMapping(ui->ctrSpBxYear, ui->ctrSpBxYear);
      m_pMapperSpins->setMapping(ui->ctrSpBxMonth, ui->ctrSpBxMonth);
      m_pMapperSpins->setMapping(ui->ctrSpBxDay, ui->ctrSpBxDay);
      m_pMapperSpins->setMapping(ui->ctrSpBxHour, ui->ctrSpBxHour);
      m_pMapperSpins->setMapping(ui->ctrSpBxMin, ui->ctrSpBxMin);
  
      connect(ui->ctrSpBxYear, SIGNAL(focusInEdit()), m_pMapperSpins, SLOT(map()));
      connect(ui->ctrSpBxMonth, SIGNAL(focusInEdit()), m_pMapperSpins, SLOT(map()));
      connect(ui->ctrSpBxDay, SIGNAL(focusInEdit()), m_pMapperSpins, SLOT(map()));
      connect(ui->ctrSpBxHour, SIGNAL(focusInEdit()), m_pMapperSpins, SLOT(map()));
      connect(ui->ctrSpBxMin, SIGNAL(focusInEdit()), m_pMapperSpins, SLOT(map()));
63a45681f   고영탁   엔코더 기능 구현
48
      connect(m_pMapperSpins, SIGNAL(mapped(QWidget*)), this, SLOT(focusInSpinBox(QWidget*)));
92fef6124   고영탁   환경 설정 - 설정 UI 완료
49
50
51
52
53
54
55
56
57
  }
  
  ConfigDateTimeDlg::~ConfigDateTimeDlg()
  {
      delete ui;
  }
  
  void ConfigDateTimeDlg::on_ctrBtnOk_clicked()
  {
0603c0b43   고영탁   rtc 설정을 시스템에서 하도록 수정
58
59
60
61
62
63
64
65
66
      time_t tm_t;
      QDate dt_(ui->ctrSpBxYear->value(), ui->ctrSpBxMonth->value(), ui->ctrSpBxDay->value());
      QTime tm_(ui->ctrSpBxHour->value(), ui->ctrSpBxMin->value());
      QDateTime dt_tm;
      dt_tm.setTime(tm_);
      dt_tm.setDate(dt_);
      tm_t = (time_t)dt_tm.toTime_t();
      System::setRtcTime(dt_tm);
      stime(&tm_t);
92fef6124   고영탁   환경 설정 - 설정 UI 완료
67
68
69
70
71
72
73
74
75
76
77
78
      this->accept();
  }
  
  void ConfigDateTimeDlg::on_spinBox_valueChanged(int arg1)
  {
  
  }
  
  void ConfigDateTimeDlg::on_ctrBtnCancel_clicked()
  {
      this->reject();
  }
be7d2a625   고영탁   엔코더 기능 구현
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
  
  void ConfigDateTimeDlg::keyPressEvent(QKeyEvent *event){
      int i = 0;
      switch (event->key())
      {
      case 0x01000030:    // Turn left
          if(focusWidget() == ui->ctrSpBxYear) ui->ctrBtnCancel->setFocus();
          else focusPreviousChild();
          break;
      case 0x01000031:    // Push
  
          break;
      case 0x01000032:    // Turn right
          if(focusWidget() == ui->ctrBtnCancel) ui->ctrSpBxYear->setFocus();
          else focusNextChild();
  
          break;
      }
  }
  
  void ConfigDateTimeDlg::keyReleaseEvent(QKeyEvent *event){
      int i = 0;
      switch (event->key())
      {
      case 0x01000030:    // Turn left
          if(focusWidget() == ui->ctrSpBxYear) ui->ctrBtnCancel->setFocus();
          else focusPreviousChild();
          break;
      case 0x01000031:    // Push
      {
          QPushButton *btn = qobject_cast<QPushButton*>(focusWidget());
          if(btn != NULL){
              btn->click();
          }
          else{
              QSpinBox *spbx = qobject_cast<QSpinBox*>(focusWidget());
              qDebug() << "grab keyboard";
              if(spbx != NULL) ui->keyboardwidget->focusInKeyboard();
          }
          break;
      }
      case 0x01000032:    // Turn right
          if(focusWidget() == ui->ctrBtnCancel) ui->ctrSpBxYear->setFocus();
          else focusNextChild();
          break;
      }
  }
63a45681f   고영탁   엔코더 기능 구현
126
  void ConfigDateTimeDlg::keyCancel_clicked(){
be7d2a625   고영탁   엔코더 기능 구현
127
128
129
130
131
132
      QSpinBox *spbx = qobject_cast<QSpinBox*>(focusWidget());
      if(spbx != NULL){
          spbx->setValue(m_nFocusValue);
      }
      ui->keyboardwidget->focusOutKeyboard();
  }
63a45681f   고영탁   엔코더 기능 구현
133
  void ConfigDateTimeDlg::keyEnter_clicked(){
be7d2a625   고영탁   엔코더 기능 구현
134
135
      ui->keyboardwidget->focusOutKeyboard();
  }
63a45681f   고영탁   엔코더 기능 구현
136
  void ConfigDateTimeDlg::focusInSpinBox(QWidget *widget){
be7d2a625   고영탁   엔코더 기능 구현
137
138
139
140
141
      QSpinBox *spbx = qobject_cast<QSpinBox*>(widget);
      if(spbx != NULL){
          m_nFocusValue = spbx->value();
      }
  }