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.h"
12 #include "qt_gldraw.h"
14 //#include "menuclasses.h"
15 #include "qt_dialogs.h"
17 #include "agar_logger.h"
21 extern const int s_freq_table[];
22 extern const double s_late_table[];
24 void Ui_MainWindow::set_latency(int num)
26 if((num < 0) || (num > 4)) return;
27 config.sound_latency = num;
28 emit sig_emu_update_config();
31 void Ui_MainWindow::set_freq(int num)
33 if((num < 0) || (num > 7)) return;
34 config.sound_frequency = num;
35 emit sig_emu_update_config();
38 void Ui_MainWindow::set_sound_device(int num)
40 #ifdef USE_SOUND_DEVICE_TYPE
41 if((num < 0) || (num >7)) return;
42 config.sound_device_type = num;
43 emit sig_emu_update_config();
49 void Ui_MainWindow::start_record_sound(bool start)
52 emit sig_emu_start_rec_sound();
54 emit sig_emu_stop_rec_sound();
58 void Ui_MainWindow::set_monitor_type(int num)
60 #ifdef USE_MONITOR_TYPE
61 if((num < 0) || (num >7)) return;
62 config.monitor_type = num;
63 emit sig_emu_update_config();
67 #if defined(USE_SCANLINE)
68 void Ui_MainWindow::set_scan_line(bool flag)
71 config.scan_line = ~0;
75 emit sig_emu_update_config();
79 #if defined(USE_SCREEN_ROTATE)
80 void Ui_MainWindow::set_screen_rotate(bool flag)
82 config.rotate_type = flag;
83 if(config.window_mode >= _SCREEN_MODE_NUM) config.window_mode = _SCREEN_MODE_NUM - 1;
84 if(config.window_mode < 0) config.window_mode = 0;
85 if(actionScreenSize[config.window_mode] != NULL) {
86 actionScreenSize[config.window_mode]->binds->set_screen_size();
90 #if defined(USE_CRT_FILTER)
91 void Ui_MainWindow::set_crt_filter(bool flag)
93 config.crt_filter = flag;
97 void Ui_MainWindow::set_gl_crt_filter(bool flag)
99 config.use_opengl_filters = flag;
103 void Ui_MainWindow::set_cmt_sound(bool flag)
105 config.tape_sound = flag;
106 emit sig_emu_update_config();
109 #ifdef USE_DEVICE_TYPE
110 void Ui_MainWindow::set_device_type(int num)
112 if((num < USE_DEVICE_TYPE) && (num >= 0)) {
113 config.device_type = num;
114 emit sig_emu_update_config();
119 #ifdef USE_DRIVE_TYPE
120 void Ui_MainWindow::set_drive_type(int num)
122 if((num < USE_DRIVE_TYPE) && (num >= 0)) {
123 config.drive_type = num;
124 emit sig_emu_update_config();
130 void Ui_MainWindow::set_screen_size(int w, int h)
132 if((w <= 0) || (h <= 0)) return;
133 #if defined(USE_SCREEN_ROTATE)
134 if(config.rotate_type) {
135 this->graphicsView->setFixedSize(h, w);
139 this->graphicsView->setFixedSize(w, h);
141 this->resize_statusbar(w, h);
143 MainWindow->centralWidget()->adjustSize();
144 MainWindow->adjustSize();
147 void Ui_MainWindow::set_screen_aspect(int num)
149 if((num < 0) || (num >= 3)) return;
153 // On Common Sourcecode Project / Agar,
154 // Scaling is done by Agar Widget.
155 // So, does need below action?
156 // Maybe, needs Agar's changing action.
158 config.stretch_type = num;
163 n = config.window_mode;
165 nd = actionScreenSize[n]->binds->getDoubleValue();
166 w = (int)(nd * (double)SCREEN_WIDTH);
167 h = (int)(nd * (double)SCREEN_HEIGHT);
168 #if defined(USE_CRT_MONITOR_4_3)
169 if(config.stretch_type == 1) {
170 h = (int)((double)h * ((double)SCREEN_WIDTH / (double)SCREEN_HEIGHT * 3.0 / 4.0));
171 } else if(config.stretch_type == 2) {
172 w = (int)((double)w * (4.0 / (3.0 * (double)SCREEN_WIDTH / (double)SCREEN_HEIGHT)));
174 //printf("%d x %d\n", w, h);
176 this->set_screen_size(w, h);
182 void Ui_MainWindow::ConfigDeviceType(void)
184 #if defined(USE_DEVICE_TYPE)
187 menuDeviceType = new QMenu(menuMachine);
188 menuDeviceType->setObjectName(QString::fromUtf8("menuDeviceType"));
189 menuMachine->addAction(menuDeviceType->menuAction());
191 actionGroup_DeviceType = new QActionGroup(this);
192 actionGroup_DeviceType->setExclusive(true);
193 for(ii = 0; ii < USE_DEVICE_TYPE; ii++) {
194 actionDeviceType[ii] = new Action_Control(this);
195 actionGroup_DeviceType->addAction(actionDeviceType[ii]);
196 actionDeviceType[ii]->setCheckable(true);
197 actionDeviceType[ii]->setVisible(true);
198 actionDeviceType[ii]->binds->setValue1(ii);
199 if(config.device_type == ii) actionDeviceType[ii]->setChecked(true);
200 menuDeviceType->addAction(actionDeviceType[ii]);
201 connect(actionDeviceType[ii], SIGNAL(triggered()),
202 actionDeviceType[ii]->binds, SLOT(do_set_device_type()));
203 connect(actionDeviceType[ii]->binds, SIGNAL(sig_device_type(int)),
204 this, SLOT(set_device_type(int)));
210 void Ui_MainWindow::ConfigDriveType(void)
213 #ifdef USE_DRIVE_TYPE
214 menuDriveType = new QMenu(menuMachine);
215 menuDriveType->setObjectName(QString::fromUtf8("menu_DriveType"));
217 actionGroup_DriveType = new QActionGroup(this);
218 actionGroup_DriveType->setObjectName(QString::fromUtf8("actionGroup_DriveType"));
219 actionGroup_DriveType->setExclusive(true);
220 menuMachine->addAction(menuDriveType->menuAction());
221 for(i = 0; i < USE_DRIVE_TYPE; i++) {
222 actionDriveType[i] = new Action_Control(this);
223 actionDriveType[i]->setCheckable(true);
224 actionDriveType[i]->setVisible(true);
225 actionDriveType[i]->binds->setValue1(i);
226 if(i == config.drive_type) actionDriveType[i]->setChecked(true); // Need to write configure
227 actionGroup_DriveType->addAction(actionDriveType[i]);
228 menuDriveType->addAction(actionDriveType[i]);
229 connect(actionDriveType[i], SIGNAL(triggered()),
230 actionDriveType[i]->binds, SLOT(do_set_drive_type()));
231 connect(actionDriveType[i]->binds, SIGNAL(sig_drive_type(int)),
232 this, SLOT(set_drive_type(int)));
237 void Ui_MainWindow::ConfigSoundDeviceType(void)
239 #ifdef USE_SOUND_DEVICE_TYPE
242 menuSoundDevice = new QMenu(menuMachine);
243 menuSoundDevice->setObjectName(QString::fromUtf8("menu_SoundDevice"));
245 actionGroup_SoundDevice = new QActionGroup(this);
246 actionGroup_SoundDevice->setObjectName(QString::fromUtf8("actionGroup_SoundDevice"));
247 actionGroup_SoundDevice->setExclusive(true);
248 menuMachine->addAction(menuSoundDevice->menuAction());
249 for(i = 0; i < USE_SOUND_DEVICE_TYPE; i++) {
250 actionSoundDevice[i] = new Action_Control(this);
251 actionSoundDevice[i]->setCheckable(true);
252 actionSoundDevice[i]->binds->setValue1(i);
253 if(i == config.sound_device_type) actionSoundDevice[i]->setChecked(true); // Need to write configure
254 tmps = QString::fromUtf8("actionSoundDevice_");
255 actionSoundDevice[i]->setObjectName(tmps + QString::number(i));
256 menuSoundDevice->addAction(actionSoundDevice[i]);
257 actionGroup_SoundDevice->addAction(actionSoundDevice[i]);
258 connect(actionSoundDevice[i], SIGNAL(triggered()),
259 actionSoundDevice[i]->binds, SLOT(do_set_sound_device()));
260 connect(actionSoundDevice[i]->binds, SIGNAL(sig_sound_device(int)),
261 this, SLOT(set_sound_device(int)));
266 void Ui_MainWindow::ConfigPrinterType(void)
268 #if defined(USE_PRINTER)
272 #if defined(USE_PRINTER_TYPE)
273 ilim = USE_PRINTER_TYPE;
275 menuPrintDevice = new QMenu(menuMachine);
276 menuPrintDevice->setObjectName(QString::fromUtf8("menu_PrintDevice"));
278 actionGroup_PrintDevice = new QActionGroup(this);
279 actionGroup_PrintDevice->setObjectName(QString::fromUtf8("actionGroup_PrintDevice"));
280 actionGroup_PrintDevice->setExclusive(true);
281 menuMachine->addAction(menuPrintDevice->menuAction());
282 for(i = 0; i < ilim; i++) {
283 actionPrintDevice[i] = new Action_Control(this);
284 actionPrintDevice[i]->setCheckable(true);
285 actionPrintDevice[i]->binds->setValue1(i);
286 if(i == config.printer_device_type) actionPrintDevice[i]->setChecked(true); // Need to write configure
287 tmps = QString::fromUtf8("actionPrintDevice_");
288 actionPrintDevice[i]->setObjectName(tmps + QString::number(i));
289 menuPrintDevice->addAction(actionPrintDevice[i]);
290 actionGroup_PrintDevice->addAction(actionPrintDevice[i]);
291 connect(actionPrintDevice[i], SIGNAL(triggered()),
292 actionPrintDevice[i]->binds, SLOT(do_set_printer_device()));
293 connect(actionPrintDevice[i]->binds, SIGNAL(sig_printer_device(int)),
294 this, SLOT(set_printer_device(int)));
300 #if defined(USE_PRINTER)
301 void Ui_MainWindow::set_printer_device(int p_type)
304 if(p_type < 0) p_type = 0; // OK?
305 #if defined(USE_PRINTER_TYPE)
306 if(p_type >= USE_PRINTER_TYPE) p_type = USE_PRINTER_TYPE - 1;
308 if(p_type >= 2) p_type = 1;
310 config.printer_device_type = p_type;