Blame view

app/gui/oven_control/configpanelbutton.cpp 3.26 KB
5a38a241e   김태훈   환경 설정 뼈대 추가
1
2
3
4
5
  #include "configpanelbutton.h"
  #include "ui_configpanelbutton.h"
  
  #include <QPixmap>
  #include <QPainter>
81b55e046   고영탁   config pannel but...
6
  #include <QDebug>
80c5eb48b   고영탁   configwindow 엔코더 ...
7
  #include <QFocusEvent>
5a38a241e   김태훈   환경 설정 뼈대 추가
8
66e60ceb5   김태훈   모든 버튼에 음향 효과 추가
9
  #include "soundplayer.h"
81b55e046   고영탁   config pannel but...
10
  ConfigPanelButton::ConfigPanelButton(QWidget *parent, uint16_t btn_id) :
5a38a241e   김태훈   환경 설정 뼈대 추가
11
12
13
14
      QWidget(parent),
      ui(new Ui::ConfigPanelButton)
  {
      ui->setupUi(this);
81b55e046   고영탁   config pannel but...
15
      btnid = btn_id;
5a38a241e   김태훈   환경 설정 뼈대 추가
16
17
18
19
20
      showingFavoriteButton = false;
      ui->favoriteButton->hide();
  
      textRect = QRect(20, 0, 556, 65);
      valueRect = QRect(556, 0, 265, 65);
81b55e046   고영탁   config pannel but...
21
22
23
24
25
  //    connect(ui->pushButton, SIGNAL(pressed()), SIGNAL(pressed()));
  //    connect(ui->pushButton, SIGNAL(released()), SIGNAL(released()));
  //    connect(ui->pushButton, SIGNAL(clicked()), SIGNAL(clicked()));
  
  //    connect(ui->favoriteButton,SIGNAL(clicked(bool)),SIGNAL(checkButtonClicked(bool)));
66e60ceb5   김태훈   모든 버튼에 음향 효과 추가
26
27
      foreach (QPushButton *button, findChildren<QPushButton *>())
          connect(button, &QPushButton::pressed, SoundPlayer::playClick);
5a38a241e   김태훈   환경 설정 뼈대 추가
28
29
30
31
32
33
  }
  
  ConfigPanelButton::~ConfigPanelButton()
  {
      delete ui;
  }
80c5eb48b   고영탁   configwindow 엔코더 ...
34
35
36
37
  bool ConfigPanelButton::isFavoriteFocused()
  {
      return (focusWidget() == ui->favoriteButton);
  }
40f5d047f   고영탁   엔코더 작업 진행 중
38
39
40
41
42
43
44
45
  QWidget *ConfigPanelButton::getFavoriteBtn()
  {
      return ui->favoriteButton;
  }
  
  QWidget* ConfigPanelButton::getBtn(){
      return ui->pushButton;
  }
5a38a241e   김태훈   환경 설정 뼈대 추가
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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
  void ConfigPanelButton::setText(const QString &text)
  {
      if (text_ == text)
          return;
  
      text_ = text;
  
      updateIcon();
  }
  
  void ConfigPanelButton::setValue(const QString &value)
  {
      if (value_ == value)
          return;
  
      value_ = value;
  
      updateIcon();
  }
  
  void ConfigPanelButton::showFavoriteButton()
  {
      if (showingFavoriteButton)
          return;
  
      showingFavoriteButton = true;
      ui->favoriteButton->show();
  
      textRect = QRect(20 + 77, 0, 556 - 77, 65);
      updateIcon();
  }
  
  void ConfigPanelButton::hideFavoriteButton()
  {
      if (!showingFavoriteButton)
          return;
  
      showingFavoriteButton = false;
      ui->favoriteButton->hide();
  
      textRect = QRect(20, 0, 556, 65);
      updateIcon();
  }
  
  void ConfigPanelButton::updateIcon()
  {
      QPixmap pixmap(ui->pushButton->size());
      pixmap.fill(Qt::transparent);
  
      QFont font = ui->pushButton->font();
      font.setPixelSize(30);
  
      QPainter painter(&pixmap);
      painter.setFont(font);
      painter.setPen(Qt::white);
      painter.drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, text_);
      painter.setPen(Qt::gray);
      painter.drawText(valueRect, Qt::AlignCenter, value_);
  
      QIcon icon(pixmap);
      ui->pushButton->setIcon(icon);
      ui->pushButton->setIconSize(pixmap.size());
  }
81b55e046   고영탁   config pannel but...
109
110
111
112
113
114
115
116
  
  bool ConfigPanelButton::isFavoriteChecked(){
      return ui->favoriteButton->isChecked();
  }
  
  void ConfigPanelButton::setFavoriteCheck(bool checked){
      ui->favoriteButton->setChecked(checked);
  }
80c5eb48b   고영탁   configwindow 엔코더 ...
117
118
119
120
121
122
123
124
125
126
127
128
  void ConfigPanelButton::focusInEvent(QFocusEvent *event)
  {
      switch (event->reason())
      {
      case Qt::TabFocusReason:
          ui->pushButton->setFocus();
          break;
      case Qt::BacktabFocusReason:
          ui->favoriteButton->setFocus();
          break;
      }
  }
81b55e046   고영탁   config pannel but...
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
  void ConfigPanelButton::on_favoriteButton_clicked(bool checked)
  {
      emit checkButtonClicked(btnid,checked);
  }
  
  
  
  void ConfigPanelButton::on_pushButton_clicked()
  {
      emit clicked(btnid);
  }
  
  
  
  void ConfigPanelButton::on_pushButton_released()
  {
      emit released(btnid);
  }
  
  
  void ConfigPanelButton::on_pushButton_pressed()
  {
      emit pressed(btnid);
  }