2 * UI->Qt->MainWindow : Some Utils.
3 * (C) 2015 K.Ohta <whatisthis.sowhat _at_ gmail.com>
7 * Jan 24, 2014 : Moved from some files.
10 #include "commonclasses.h"
11 #include "mainwidget_base.h"
12 #include "qt_gldraw.h"
14 //#include "menuclasses.h"
15 #include "qt_dialogs.h"
16 #include "agar_logger.h"
18 extern const int s_freq_table[];
19 extern const double s_late_table[];
21 void Ui_MainWindowBase::set_latency(int num)
23 if((num < 0) || (num >= 8)) return;
24 using_flags->get_config_ptr()->sound_latency = num;
25 emit sig_emu_update_config();
28 void Ui_MainWindowBase::set_freq(int num)
30 if((num < 0) || (num >= 16)) return;
31 using_flags->get_config_ptr()->sound_frequency = num;
32 emit sig_emu_update_config();
35 void Ui_MainWindowBase::set_sound_device(int num)
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();
44 void Ui_MainWindowBase::start_record_sound(bool start)
47 actionStart_Record->setText(QApplication::translate("MainWindow", "Stop Recorded Sound", 0));
48 actionStart_Record->setIcon(StopIcon);
49 emit sig_emu_start_rec_sound();
51 actionStart_Record->setText(QApplication::translate("MainWindow", "Start Recording Sound", 0));
52 actionStart_Record->setIcon(RecordSoundIcon);
53 emit sig_emu_stop_rec_sound();
57 void Ui_MainWindowBase::set_monitor_type(int num)
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();
64 void Ui_MainWindowBase::set_scan_line(bool flag)
67 using_flags->get_config_ptr()->scan_line = ~0;
69 using_flags->get_config_ptr()->scan_line = 0;
71 emit sig_emu_update_config();
74 void Ui_MainWindowBase::set_screen_rotate(bool flag)
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();
84 void Ui_MainWindowBase::set_crt_filter(bool flag)
86 using_flags->get_config_ptr()->crt_filter = flag;
89 void Ui_MainWindowBase::set_gl_crt_filter(bool flag)
91 using_flags->get_config_ptr()->use_opengl_filters = flag;
94 void Ui_MainWindowBase::set_cmt_sound(bool flag)
96 using_flags->get_config_ptr()->tape_sound = flag;
97 emit sig_emu_update_config();
100 void Ui_MainWindowBase::set_device_type(int num)
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();
107 void Ui_MainWindowBase::set_drive_type(int num)
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();
115 void Ui_MainWindowBase::set_screen_size(int w, int h)
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);
123 this->graphicsView->setFixedSize(w, h);
124 this->resize_statusbar(w, h);
127 this->graphicsView->setFixedSize(w, h);
128 this->resize_statusbar(w, h);
131 MainWindow->centralWidget()->adjustSize();
132 MainWindow->adjustSize();
135 void Ui_MainWindowBase::set_screen_aspect(int num)
137 if((num < 0) || (num >= 4)) return;
139 // 1 = ASPECT(Scale X)
140 // 2 = ASPECT(SCale Y)
141 // 3 = ASPECT(Scale X,Y)
143 using_flags->get_config_ptr()->window_stretch_type = num;
148 n = using_flags->get_config_ptr()->window_mode;
150 nd = actionScreenSize[n]->binds->getDoubleValue();
151 ww = nd * (double)using_flags->get_screen_width();
152 hh = nd * (double)using_flags->get_screen_height();
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.
161 } else if(using_flags->get_config_ptr()->window_stretch_type == 2) { // refer to Y, scale X only
163 } else if(using_flags->get_config_ptr()->window_stretch_type == 3) { // Scale both X, Y
170 this->set_screen_size(w, h);
175 void Ui_MainWindowBase::ConfigDeviceType(void)
177 if(using_flags->get_use_device_type() > 0) {
179 menuDeviceType = new QMenu(menuMachine);
180 menuDeviceType->setObjectName(QString::fromUtf8("menuDeviceType"));
181 menuMachine->addAction(menuDeviceType->menuAction());
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)));
201 void Ui_MainWindowBase::ConfigDriveType(void)
204 if(using_flags->get_use_drive_type() > 0) {
205 menuDriveType = new QMenu(menuMachine);
206 menuDriveType->setObjectName(QString::fromUtf8("menu_DriveType"));
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)));
228 void Ui_MainWindowBase::ConfigSoundDeviceType(void)
230 if(using_flags->get_use_sound_device_type() > 0) {
233 menuSoundDevice = new QMenu(menuMachine);
234 menuSoundDevice->setObjectName(QString::fromUtf8("menu_SoundDevice"));
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)));
257 void Ui_MainWindowBase::ConfigPrinterType(void)
259 if(using_flags->is_use_printer()) {
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"));
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)));
288 void Ui_MainWindowBase::set_printer_device(int p_type)
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;
297 if(p_type >= 2) p_type = 1;
299 using_flags->get_config_ptr()->printer_device_type = p_type;
300 emit sig_emu_update_config();