OSDN Git Service

[UI][Qt] Not liking config, using_flags directly.
[csp-qt/common_source_project-fm7.git] / source / src / qt / gui / mainwindow_utils.cpp
1 /*
2  * UI->Qt->MainWindow : Some Utils.
3  * (C) 2015 K.Ohta <whatisthis.sowhat _at_ gmail.com>
4  * License: GPLv2
5  *
6  * History:
7  * Jan 24, 2014 : Moved from some files.
8  */
9
10 #include "commonclasses.h"
11 #include "mainwidget_base.h"
12 #include "qt_gldraw.h"
13
14 //#include "menuclasses.h"
15 #include "qt_dialogs.h"
16 #include "agar_logger.h"
17
18 extern const int s_freq_table[];
19 extern const double s_late_table[];
20
21 void Ui_MainWindowBase::set_latency(int num)
22 {
23         if((num < 0) || (num >= 8)) return;
24         using_flags->get_config_ptr()->sound_latency = num;
25         emit sig_emu_update_config();
26 }
27
28 void Ui_MainWindowBase::set_freq(int num)
29 {
30         if((num < 0) || (num >= 16)) return;
31         using_flags->get_config_ptr()->sound_frequency = num;
32         emit sig_emu_update_config();
33 }
34
35 void Ui_MainWindowBase::set_sound_device(int num)
36 {
37         if((num < 0) || (num >= using_flags->get_use_sound_device_type())) return;
38         using_flags->get_config_ptr()->sound_device_type = num;
39         emit sig_emu_update_config();
40 }
41
42
43
44 void Ui_MainWindowBase::start_record_sound(bool start)
45 {
46         if(start) {
47                 actionStart_Record->setText(QApplication::translate("MainWindow", "Stop Recorded Sound", 0));
48                 actionStart_Record->setIcon(StopIcon);
49                 emit sig_emu_start_rec_sound();
50         } else {
51                 actionStart_Record->setText(QApplication::translate("MainWindow", "Start Recording Sound", 0));
52                 actionStart_Record->setIcon(RecordSoundIcon);
53                 emit sig_emu_stop_rec_sound();
54         }
55 }
56
57 void Ui_MainWindowBase::set_monitor_type(int num)
58 {
59         if((num < 0) || (num >= using_flags->get_use_monitor_type())) return;
60         using_flags->get_config_ptr()->monitor_type = num;
61         emit sig_emu_update_config();
62 }
63
64 void Ui_MainWindowBase::set_scan_line(bool flag)
65 {
66         if(flag) {
67                 using_flags->get_config_ptr()->scan_line = ~0;
68         } else {
69                 using_flags->get_config_ptr()->scan_line = 0;
70         }
71         emit sig_emu_update_config();
72 }
73
74 void Ui_MainWindowBase::set_screen_rotate(bool flag)
75 {
76         using_flags->get_config_ptr()->rotate_type = flag;
77         if(using_flags->get_config_ptr()->window_mode >= using_flags->get_screen_mode_num()) using_flags->get_config_ptr()->window_mode = using_flags->get_screen_mode_num() - 1;
78         if(using_flags->get_config_ptr()->window_mode < 0) using_flags->get_config_ptr()->window_mode = 0;
79         if(actionScreenSize[using_flags->get_config_ptr()->window_mode] != NULL) {
80                 actionScreenSize[using_flags->get_config_ptr()->window_mode]->binds->set_screen_size();
81         }
82 }
83
84 void Ui_MainWindowBase::set_crt_filter(bool flag)
85 {
86         using_flags->get_config_ptr()->crt_filter = flag;
87 }
88
89 void Ui_MainWindowBase::set_gl_crt_filter(bool flag)
90 {
91         using_flags->get_config_ptr()->use_opengl_filters = flag;
92 }
93
94 void Ui_MainWindowBase::set_cmt_sound(bool flag)
95 {
96         using_flags->get_config_ptr()->tape_sound = flag;
97         emit sig_emu_update_config();
98 }
99
100 void Ui_MainWindowBase::set_device_type(int num)
101 {
102         if((num >= using_flags->get_use_device_type()) && (num < 0)) return;
103         using_flags->get_config_ptr()->device_type = num;
104         emit sig_emu_update_config();
105 }
106
107 void Ui_MainWindowBase::set_drive_type(int num)
108 {
109         if((num >= using_flags->get_use_drive_type()) && (num < 0)) return;
110         using_flags->get_config_ptr()->drive_type = num;
111         emit sig_emu_update_config();
112 }
113    
114
115 void Ui_MainWindowBase::set_screen_size(int w, int h)
116 {
117         if((w <= 0) || (h <= 0)) return;
118         if(using_flags->is_use_screen_rotate()) {
119                 if(using_flags->get_config_ptr()->rotate_type) {
120                         this->graphicsView->setFixedSize(h, w);
121                         this->resize_statusbar(h, w);
122                 } else {
123                         this->graphicsView->setFixedSize(w, h);
124                         this->resize_statusbar(w, h);
125                 }
126         } else  {
127                 this->graphicsView->setFixedSize(w, h);
128                 this->resize_statusbar(w, h);
129         }
130    
131         MainWindow->centralWidget()->adjustSize();
132         MainWindow->adjustSize();
133 }
134
135 void Ui_MainWindowBase::set_screen_aspect(int num)
136 {
137         if((num < 0) || (num >= 4)) return;
138         // 0 = DOT
139         // 1 = ASPECT(Scale X)
140         // 2 = ASPECT(SCale Y)
141         // 3 = ASPECT(Scale X,Y)
142         
143         using_flags->get_config_ptr()->window_stretch_type = num;
144         
145         if(emu) {
146                 int w, h, n;
147                 double nd, ww, hh;
148                 n = using_flags->get_config_ptr()->window_mode;
149                 if(n < 0) n = 1;
150                 nd = actionScreenSize[n]->binds->getDoubleValue();
151                 ww = nd * (double)using_flags->get_screen_width();
152                 hh = nd * (double)using_flags->get_screen_height();
153                 
154                 if((using_flags->get_screen_height_aspect() != using_flags->get_screen_height()) ||
155                    (using_flags->get_screen_width_aspect() != using_flags->get_screen_width())) {
156                         double par_w = (double)using_flags->get_screen_width_aspect() / (double)using_flags->get_screen_width();
157                         double par_h = (double)using_flags->get_screen_height_aspect() / (double)using_flags->get_screen_height();
158                         double par = par_h / par_w;
159                         if(using_flags->get_config_ptr()->window_stretch_type == 1) { // refer to X, scale Y.
160                                 hh = hh * par_h;
161                         } else if(using_flags->get_config_ptr()->window_stretch_type == 2) { // refer to Y, scale X only
162                                 ww = ww / par_h;
163                         } else if(using_flags->get_config_ptr()->window_stretch_type == 3) { // Scale both X, Y
164                                 ww = ww * par_w;
165                                 hh = hh * par_h;
166                         }
167                 }
168                 w = (int)ww;
169                 h = (int)hh;
170                 this->set_screen_size(w, h);
171         }
172 }
173
174
175 void Ui_MainWindowBase::ConfigDeviceType(void)
176 {
177         if(using_flags->get_use_device_type() > 0) {
178                 int ii;
179                 menuDeviceType = new QMenu(menuMachine);
180                 menuDeviceType->setObjectName(QString::fromUtf8("menuDeviceType"));
181                 menuMachine->addAction(menuDeviceType->menuAction());
182       
183                 actionGroup_DeviceType = new QActionGroup(this);
184                 actionGroup_DeviceType->setExclusive(true);
185                 for(ii = 0; ii < using_flags->get_use_device_type(); ii++) {
186                         actionDeviceType[ii] = new Action_Control(this, using_flags);
187                         actionGroup_DeviceType->addAction(actionDeviceType[ii]);
188                         actionDeviceType[ii]->setCheckable(true);
189                         actionDeviceType[ii]->setVisible(true);
190                         actionDeviceType[ii]->binds->setValue1(ii);
191                         if(using_flags->get_config_ptr()->device_type == ii) actionDeviceType[ii]->setChecked(true);
192                         menuDeviceType->addAction(actionDeviceType[ii]);
193                         connect(actionDeviceType[ii], SIGNAL(triggered()),
194                                 actionDeviceType[ii]->binds, SLOT(do_set_device_type()));
195                         connect(actionDeviceType[ii]->binds, SIGNAL(sig_device_type(int)),
196                                 this, SLOT(set_device_type(int)));
197                 }
198         }
199 }
200
201 void Ui_MainWindowBase::ConfigDriveType(void)
202 {
203         int i;
204         if(using_flags->get_use_drive_type() > 0) {
205                 menuDriveType = new QMenu(menuMachine);
206                 menuDriveType->setObjectName(QString::fromUtf8("menu_DriveType"));
207                 
208                 actionGroup_DriveType = new QActionGroup(this);
209                 actionGroup_DriveType->setObjectName(QString::fromUtf8("actionGroup_DriveType"));
210                 actionGroup_DriveType->setExclusive(true);
211                 menuMachine->addAction(menuDriveType->menuAction());
212                 for(i = 0; i < using_flags->get_use_drive_type(); i++) {
213                         actionDriveType[i] = new Action_Control(this, using_flags);
214                         actionDriveType[i]->setCheckable(true);
215                         actionDriveType[i]->setVisible(true);
216                         actionDriveType[i]->binds->setValue1(i);
217                         if(i == using_flags->get_config_ptr()->drive_type) actionDriveType[i]->setChecked(true); // Need to write configure
218                         actionGroup_DriveType->addAction(actionDriveType[i]);
219                         menuDriveType->addAction(actionDriveType[i]);
220                         connect(actionDriveType[i], SIGNAL(triggered()),
221                                         actionDriveType[i]->binds, SLOT(do_set_drive_type()));
222                         connect(actionDriveType[i]->binds, SIGNAL(sig_drive_type(int)),
223                                         this, SLOT(set_drive_type(int)));
224                 }
225         }
226 }
227
228 void Ui_MainWindowBase::ConfigSoundDeviceType(void)
229 {
230         if(using_flags->get_use_sound_device_type() > 0) {
231                 int i;
232                 QString tmps;
233                 menuSoundDevice = new QMenu(menuMachine);
234                 menuSoundDevice->setObjectName(QString::fromUtf8("menu_SoundDevice"));
235                 
236                 actionGroup_SoundDevice = new QActionGroup(this);
237                 actionGroup_SoundDevice->setObjectName(QString::fromUtf8("actionGroup_SoundDevice"));
238                 actionGroup_SoundDevice->setExclusive(true);
239                 menuMachine->addAction(menuSoundDevice->menuAction());   
240                 for(i = 0; i < using_flags->get_use_sound_device_type(); i++) {
241                         actionSoundDevice[i] = new Action_Control(this, using_flags);
242                         actionSoundDevice[i]->setCheckable(true);
243                         actionSoundDevice[i]->binds->setValue1(i);
244                         if(i == using_flags->get_config_ptr()->sound_device_type) actionSoundDevice[i]->setChecked(true); // Need to write configure
245                         tmps = QString::fromUtf8("actionSoundDevice_");
246                         actionSoundDevice[i]->setObjectName(tmps + QString::number(i));
247                         menuSoundDevice->addAction(actionSoundDevice[i]);
248                         actionGroup_SoundDevice->addAction(actionSoundDevice[i]);
249                         connect(actionSoundDevice[i], SIGNAL(triggered()),
250                                         actionSoundDevice[i]->binds, SLOT(do_set_sound_device()));
251                         connect(actionSoundDevice[i]->binds, SIGNAL(sig_sound_device(int)),
252                                         this, SLOT(set_sound_device(int)));
253                 }
254         }
255 }
256
257 void Ui_MainWindowBase::ConfigPrinterType(void)
258 {
259         if(using_flags->is_use_printer()) {
260                 int i;
261                 QString tmps;
262                 int ilim = 2;
263                 if(using_flags->get_use_printer_type() > 0) ilim = using_flags->get_use_printer_type();
264                 menuPrintDevice = new QMenu(menuMachine);
265                 menuPrintDevice->setObjectName(QString::fromUtf8("menu_PrintDevice"));
266                 
267                 actionGroup_PrintDevice = new QActionGroup(this);
268                 actionGroup_PrintDevice->setObjectName(QString::fromUtf8("actionGroup_PrintDevice"));
269                 actionGroup_PrintDevice->setExclusive(true);
270                 menuMachine->addAction(menuPrintDevice->menuAction());   
271                 for(i = 0; i < ilim; i++) {
272                         actionPrintDevice[i] = new Action_Control(this, using_flags);
273                         actionPrintDevice[i]->setCheckable(true);
274                         actionPrintDevice[i]->binds->setValue1(i);
275                         if(i == using_flags->get_config_ptr()->printer_device_type) actionPrintDevice[i]->setChecked(true); // Need to write configure
276                         tmps = QString::fromUtf8("actionPrintDevice_");
277                         actionPrintDevice[i]->setObjectName(tmps + QString::number(i));
278                         menuPrintDevice->addAction(actionPrintDevice[i]);
279                         actionGroup_PrintDevice->addAction(actionPrintDevice[i]);
280                         connect(actionPrintDevice[i], SIGNAL(triggered()),
281                                         actionPrintDevice[i]->binds, SLOT(do_set_printer_device()));
282                         connect(actionPrintDevice[i]->binds, SIGNAL(sig_printer_device(int)),
283                                         this, SLOT(set_printer_device(int)));
284                 }
285         }
286 }
287
288 void Ui_MainWindowBase::set_printer_device(int p_type)
289 {
290         // 0 = PRNFILE
291         if(p_type < 0) p_type = 0; // OK?
292         if(p_type >= using_flags->get_use_printer_type() > 0) {
293                 if(p_type >= using_flags->get_use_printer_type()) {
294                         p_type = using_flags->get_use_printer_type() - 1;
295                 }
296         } else {
297                 if(p_type >= 2) p_type = 1;
298         }
299         using_flags->get_config_ptr()->printer_device_type = p_type;
300         emit sig_emu_update_config();
301 }