OSDN Git Service

[UI][Qt] Add option, "Print statistics", related by commit 324b522e8fe7a80d03ac12f9a5...
[csp-qt/common_source_project-fm7.git] / source / src / qt / gui / menu_main.cpp
1 /*
2  * Common Source code Project:
3  * Ui->Qt->gui->menu_main for generic.
4  * (C) 2015 K.Ohta <whatisthis.sowhat _at_ gmail.com>
5  *   License : GPLv2
6  *   History :
7  * Jan 14, 2015 : Initial, moved from qt/x1turboz/MainWindow.cpp .
8  */
9
10 #include <QVariant>
11 #include <QtGui>
12 #include <QIcon>
13 #include <QImage>
14 #include <QImageReader>
15 #include <QPixmap>
16 #include <QApplication>
17 #include <QLocale>
18 #include <QTranslator>
19 #include <QStatusBar>
20 #include <QHBoxLayout>
21 #include <QVBoxLayout>
22 #include <QDockWidget>
23 #include <QToolBar>
24
25 #include "commonclasses.h"
26 #include "display_about.h"
27 #include "display_text_document.h"
28 #include "mainwidget_base.h"
29 //#include "menuclasses.h"
30 #include "menu_disk.h"
31 #include "menu_cmt.h"
32 #include "menu_cart.h"
33 #include "menu_quickdisk.h"
34 #include "menu_binary.h"
35 #include "menu_compactdisc.h"
36 #include "menu_laserdisc.h"
37 #include "menu_bubble.h"
38 #include "dock_disks.h"
39
40 #include "qt_gldraw.h"
41 //#include "emu.h"
42 #include "qt_main.h"
43 #include "menu_flags.h"
44 #include "csp_logger.h"
45
46 extern EMU *emu;
47 //extern USING_FLAGS *using_flags;
48 void DLL_PREFIX _resource_init(void)
49 {
50         Q_INIT_RESOURCE(commontexts);
51         Q_INIT_RESOURCE(shaders);
52 }
53
54 void DLL_PREFIX _resource_free(void)
55 {
56         Q_CLEANUP_RESOURCE(shaders);
57         Q_CLEANUP_RESOURCE(commontexts);
58 }
59
60 Ui_MainWindowBase::Ui_MainWindowBase(USING_FLAGS *p, CSP_Logger *logger, QWidget *parent) : QMainWindow(parent)
61 {
62         csp_logger = logger;
63         using_flags = p;
64         p_config = p->get_config_ptr();
65         driveData = NULL;
66         ledUpdateTimer = NULL;
67         setupUi();
68         createContextMenu();
69         max_vm_nodes = 0;
70         ui_retranslate_completed = false;
71         //csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "GUI OK");
72 }
73
74 Ui_MainWindowBase::~Ui_MainWindowBase()
75 {
76         graphicsView->releaseKeyboard();
77         if(ledUpdateTimer != NULL) delete ledUpdateTimer;
78         if(driveData != NULL) delete driveData;
79         delete using_flags;
80 }
81
82 void Action_Control::do_check_grab_mouse(bool flag)
83 {
84         this->toggle();
85 }
86
87 void Action_Control::do_send_string(void)
88 {
89         emit sig_send_string(bindString);
90 }
91
92 void Action_Control::do_set_string(QString s)
93 {
94         bindString = s;
95 }
96
97 void Action_Control::do_select_render_platform(void)
98 {
99         int num = this->binds->getValue1();
100         emit sig_select_render_platform(num);
101 }
102
103 void Action_Control::do_set_window_focus_type(bool f)
104 {
105         emit sig_set_window_focus_type(f);
106 }
107
108 void Action_Control::do_set_emulate_cursor_as(void)
109 {
110         int num = this->binds->getValue1();
111         emit sig_set_emulate_cursor_as(num);
112 }
113
114 void Action_Control::do_set_dev_log_to_console(bool f)
115 {
116         int num = this->binds->getValue1();
117         emit sig_set_dev_log_to_console(num, f);
118 }
119
120 void Action_Control::do_set_dev_log_to_syslog(bool f)
121 {
122         int num = this->binds->getValue1();
123         emit sig_set_dev_log_to_syslog(num, f);
124 }
125
126
127 void Ui_MainWindowBase::do_set_window_focus_type(bool flag)
128 {
129         using_flags->get_config_ptr()->focus_with_click = flag;
130         if(flag) {
131                 graphicsView->setFocusPolicy(Qt::ClickFocus);
132                 graphicsView->setFocus(0);
133         } else {
134                 graphicsView->setFocusPolicy(Qt::NoFocus);
135                 graphicsView->clearFocus();
136         }
137 }
138
139 void Ui_MainWindowBase::do_show_about(void)
140 {
141         Dlg_AboutCSP *dlg = new Dlg_AboutCSP(using_flags);
142         dlg->show();
143 }
144
145 void Ui_MainWindowBase::do_browse_document(QString fname)
146 {
147         Dlg_BrowseText *dlg = new Dlg_BrowseText(fname, using_flags);
148         dlg->show();
149 }
150
151 void Ui_MainWindowBase::do_set_sound_files_fdd(bool f)
152 {
153         if(f) {
154                 using_flags->get_config_ptr()->sound_noise_fdd = 1;
155         } else {
156                 using_flags->get_config_ptr()->sound_noise_fdd = 0;
157         }
158 }
159
160 void Ui_MainWindowBase::do_set_sound_files_relay(bool f)
161 {
162         if(f) {
163                 using_flags->get_config_ptr()->sound_noise_cmt = 1;
164         } else {
165                 using_flags->get_config_ptr()->sound_noise_cmt = 0;
166         }
167 }
168
169
170 void Ui_MainWindowBase::do_set_conslog(bool f)
171 {
172         using_flags->get_config_ptr()->log_to_console = f;
173         csp_logger->set_log_stdout(-1, f);
174 }
175
176 void Ui_MainWindowBase::do_set_syslog(bool f)
177 {
178         using_flags->get_config_ptr()->log_to_syslog = f;
179         csp_logger->set_log_syslog(-1, f);
180 }
181
182 void Ui_MainWindowBase::do_update_device_node_name(int id, const _TCHAR *name)
183 {
184         if(action_DevLogToConsole[id] == NULL) return;
185         if(!ui_retranslate_completed) return;
186         if(using_flags->get_vm_node_size() > id) {
187                 action_DevLogToConsole[id]->setEnabled(true);
188                 action_DevLogToConsole[id]->setVisible(true);
189 #if !defined(Q_OS_WIN)
190                 action_DevLogToSyslog[id]->setEnabled(true);
191                 action_DevLogToSyslog[id]->setVisible(true);
192 #endif
193         } else {
194                 action_DevLogToConsole[id]->setEnabled(false);
195                 action_DevLogToConsole[id]->setVisible(false);
196                 
197 #if !defined(Q_OS_WIN)
198                 action_DevLogToSyslog[id]->setEnabled(false);
199                 action_DevLogToSyslog[id]->setVisible(false);
200 #endif
201         }
202         char s[64] = {0};
203         snprintf(s, 60, "#%02d: %s", id, name);
204         action_DevLogToConsole[id]->setText(QString::fromUtf8(s));
205 #if !defined(Q_OS_WIN)
206         action_DevLogToSyslog[id]->setText(QString::fromUtf8(s));
207 #endif
208 }
209
210
211 void Ui_MainWindowBase::do_set_logging_fdc(bool f)
212 {
213         using_flags->get_config_ptr()->special_debug_fdc = f;
214         emit sig_emu_update_config();
215 }
216
217 void Ui_MainWindowBase::do_set_dev_log_to_console(int num, bool f)
218 {
219         csp_logger->set_device_node_log(num, 2, CSP_LOG_DEBUG, f);
220         using_flags->get_config_ptr()->dev_log_to_console[num][0] = f;
221 }
222
223 void Ui_MainWindowBase::do_set_emulate_cursor_as(int num)
224 {
225         if((num < 0) || (num > 2)) return;
226         using_flags->get_config_ptr()->cursor_as_ten_key = num;
227         emit sig_emu_update_config();
228 }
229
230 void Ui_MainWindowBase::do_set_dev_log_to_syslog(int num, bool f)
231 {
232         csp_logger->set_device_node_log(num, 2, CSP_LOG_DEBUG, f);
233         using_flags->get_config_ptr()->dev_log_to_syslog[num][0] = f;
234 }
235
236 void Ui_MainWindowBase::do_select_render_platform(int num)
237 {
238         int _major = 0;
239         int _minor = 0;
240         int _type = -1;
241
242         switch(num) {
243         case RENDER_PLATFORMS_OPENGL3_MAIN:
244                 _type = CONFIG_RENDER_PLATFORM_OPENGL_MAIN;
245                 _major = 3;
246                 _minor = 0;
247                 break;
248         case RENDER_PLATFORMS_OPENGL2_MAIN:
249                 _type = CONFIG_RENDER_PLATFORM_OPENGL_MAIN;
250                 _major = 2;
251                 _minor = 0;
252                 break;
253         case RENDER_PLATFORMS_OPENGL_CORE:
254                 _type = CONFIG_RENDER_PLATFORM_OPENGL_CORE;
255                 _major = 3;
256                 _minor = 2;
257                 break;
258         default:
259                 break;
260         }
261         if(_type >= 0) {
262                 using_flags->get_config_ptr()->render_platform = _type;
263                 using_flags->get_config_ptr()->render_major_version = _major;
264                 using_flags->get_config_ptr()->render_minor_version = _minor;
265         }
266 }
267
268 void Ui_MainWindowBase::set_dipsw(int num, bool flag)
269 {
270         if((num < 0) || (num >= 32)) return;
271         if(flag) {
272                 using_flags->get_config_ptr()->dipswitch = using_flags->get_config_ptr()->dipswitch | (1 << num);
273         } else {
274                 using_flags->get_config_ptr()->dipswitch = using_flags->get_config_ptr()->dipswitch & ~(1 << num);
275         }
276 }
277
278 bool Ui_MainWindowBase::get_dipsw(int num)
279 {
280         if((num < 0) || (num >= 32)) return false;
281         if(((1 << num) & using_flags->get_config_ptr()->dipswitch) == 0) return false;
282         return true;
283 }
284
285
286 void Ui_MainWindowBase::setupUi(void)
287 {
288         int w, h;
289         //   QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
290         MainWindow = new QMainWindow();
291         if (MainWindow->objectName().isEmpty())
292                 MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
293         //MainWindow->resize(1288, 862);
294         ConfigControlMenu();
295         ConfigFloppyMenu();
296         ConfigCMTMenu();
297         if(!using_flags->is_without_sound()) {
298                 ConfigSoundMenu();
299         }
300         if(using_flags->is_use_binary_file()) {
301                 ConfigBinaryMenu(); 
302         }
303         if(using_flags->is_use_qd()) {
304                 ConfigQuickDiskMenu();
305         }
306         ConfigScreenMenu();
307         if(using_flags->is_use_cart()) {
308                 ConfigCartMenu();
309         }
310         if(using_flags->is_use_compact_disc()) {
311                 ConfigCDROMMenu();
312         }
313         if(using_flags->is_use_laser_disc()) {
314                 ConfigLaserdiscMenu();
315         }
316         if(using_flags->is_use_bubble()) {
317                 ConfigBubbleMenu();
318         }
319         ConfigEmulatorMenu();   
320         actionAbout = new Action_Control(this, using_flags);
321         actionAbout->setObjectName(QString::fromUtf8("actionAbout"));
322
323         {
324 #if defined(_USE_GLAPI_QT5_4)
325                 QSurfaceFormat fmt;
326 #else
327                 QGLFormat fmt;
328 #endif
329                 {
330                         int render_type = using_flags->get_config_ptr()->render_platform;
331                         //int _major_version = using_flags->get_config_ptr()->render_major_version;
332                         //int _minor_version = using_flags->get_config_ptr()->render_minor_version;
333 #if defined(_USE_GLAPI_QT5_4)
334                                 if(render_type == CONFIG_RENDER_PLATFORM_OPENGL_CORE) { 
335                                         fmt.setProfile(QSurfaceFormat::CoreProfile); // Requires >=Qt-4.8.0
336                                         csp_logger->debug_log(CSP_LOG_DEBUG,  CSP_LOG_TYPE_GENERAL, "Try to use OpenGL CORE profile.");
337                                 } else { // Fallback
338                                         fmt.setProfile(QSurfaceFormat::CompatibilityProfile); // Requires >=Qt-4.8.0
339                                         csp_logger->debug_log(CSP_LOG_DEBUG,  CSP_LOG_TYPE_GENERAL, "Try to use OpenGL Compatible(MAIN) profile.");
340                                 }
341 #else
342                                 if(render_type == CONFIG_RENDER_PLATFORM_OPENGL_CORE) { 
343                                         fmt.setProfile(QGLFormat::CoreProfile); // Requires >=Qt-4.8.0
344                                         csp_logger->debug_log(CSP_LOG_DEBUG,  CSP_LOG_TYPE_GENERAL, "Try to use OpenGL CORE profile.");
345                                         fmt.setVersion(3, 2);
346                                 } else {
347                                         fmt.setProfile(QGLFormat::CompatibilityProfile); // Requires >=Qt-4.8.0
348                                         csp_logger->debug_log(CSP_LOG_DEBUG,  CSP_LOG_TYPE_GENERAL, "Try to use OpenGL Compatible(MAIN) profile.");
349                                         fmt.setVersion(3, 0);
350                                 }                                       
351 #endif
352                 }
353                 graphicsView = new GLDrawClass(using_flags, csp_logger, this, fmt);
354                 graphicsView->setObjectName(QString::fromUtf8("graphicsView"));
355                 graphicsView->setMaximumSize(2560, 2560); // ?
356                 graphicsView->setMinimumSize(240, 192); // ?
357                 csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "GraphicsView OK");
358                 graphicsView->setAttribute(Qt::WA_InputMethodEnabled, false); // Disable [Zenkaku / Hankaku] with IM.
359                 graphicsView->setAttribute(Qt::WA_KeyboardFocusChange, false);
360                 graphicsView->setAttribute(Qt::WA_KeyCompression, false);
361                 connect(this, SIGNAL(sig_set_display_osd(bool)), graphicsView, SLOT(do_set_display_osd(bool)));
362                 connect(this, SIGNAL(sig_set_led_width(int)), graphicsView, SLOT(do_set_led_width(int)));
363         }
364         
365         bitmapImage = NULL;
366         driveData = new CSP_DockDisks(this, using_flags);
367         MainWindow->setDockOptions(QMainWindow::AnimatedDocks);
368         if(using_flags->get_config_ptr()->virtual_media_position > 0) {
369                 driveData->setVisible(true);
370         } else {        
371                 driveData->setVisible(false);
372         }       
373
374         pCentralWidget = new QWidget(this);
375         pCentralLayout = new QVBoxLayout(pCentralWidget);
376         pCentralLayout->setContentsMargins(0, 0, 0, 0);
377         pCentralWidget->setLayout(pCentralLayout);
378         MainWindow->setCentralWidget(pCentralWidget);
379         switch(using_flags->get_config_ptr()->virtual_media_position) {
380         case 0:
381                 pCentralLayout->addWidget(graphicsView);
382                 pCentralLayout->addWidget(driveData);
383                 driveData->setVisible(false);
384                 graphicsView->setVisible(true);
385                 //emit sig_set_display_osd(true);
386                 break;
387         case 1:
388                 pCentralLayout->addWidget(driveData);
389                 pCentralLayout->addWidget(graphicsView);
390                 driveData->setVisible(true);
391                 graphicsView->setVisible(true);
392                 //emit sig_set_display_osd(false);
393                 break;
394         case 2:
395                 pCentralLayout->addWidget(graphicsView);
396                 pCentralLayout->addWidget(driveData);
397                 driveData->setVisible(true);
398                 graphicsView->setVisible(true);
399                 //emit sig_set_display_osd(false);
400                 break;
401         default:
402                 pCentralLayout->addWidget(graphicsView);
403                 pCentralLayout->addWidget(driveData);
404                 driveData->setVisible(true);
405                 graphicsView->setVisible(true);
406                 //emit sig_set_display_osd(false);
407                 break;
408         }
409         if(using_flags->get_config_ptr()->focus_with_click) {
410                 graphicsView->setFocusPolicy(Qt::ClickFocus);
411                 graphicsView->setFocus(0);
412         } else {
413                 graphicsView->setFocusPolicy(Qt::NoFocus);
414         }
415         driveData->setOrientation(using_flags->get_config_ptr()->virtual_media_position);
416         connect(this, SIGNAL(sig_set_orientation_osd(int)), driveData, SLOT(setOrientation(int)));
417         connect(graphicsView, SIGNAL(sig_resize_osd(int)), driveData, SLOT(setScreenWidth(int)));
418
419         MainWindow->setFocusProxy(graphicsView);
420         MainWindow->centralWidget()->adjustSize();
421         MainWindow->adjustSize();
422
423         statusbar = new QStatusBar(this);
424         statusbar->setObjectName(QString::fromUtf8("statusbar"));
425         MainWindow->setStatusBar(statusbar);
426         initStatusBar();
427         
428         menubar = new QMenuBar(this);
429         menubar->setObjectName(QString::fromUtf8("menubar"));
430         menubar->setGeometry(QRect(0, 0, 1288, 27));
431         menuControl = new QMenu(menubar);
432         menuControl->setToolTipsVisible(true);
433         menuControl->setObjectName(QString::fromUtf8("menuControl"));
434         menuState = new QMenu(menuControl);
435         menuState->setToolTipsVisible(true);
436         menuState->setObjectName(QString::fromUtf8("menuState"));
437
438         menuSave_State = new QMenu(menuState);
439         menuSave_State->setToolTipsVisible(true);
440         menuSave_State->setObjectName(QString::fromUtf8("menuSaveState"));
441
442         menuLoad_State = new QMenu(menuState);
443         menuLoad_State->setToolTipsVisible(true);
444         menuLoad_State->setObjectName(QString::fromUtf8("menuLoadState"));
445
446         if(using_flags->is_use_auto_key()) {
447                 menuCopy_Paste = new QMenu(menuControl);
448                 menuCopy_Paste->setObjectName(QString::fromUtf8("menuCopy_Paste"));
449                 menuCopy_Paste->setToolTipsVisible(true);
450         }
451         menuCpu_Speed = new QMenu(menuControl);
452         menuCpu_Speed->setObjectName(QString::fromUtf8("menuCpu_Speed"));
453         menuCpu_Speed->setToolTipsVisible(true);
454         menuDebugger = new QMenu(menuControl);
455         menuDebugger->setObjectName(QString::fromUtf8("menuDebugger"));
456         menuDebugger->setToolTipsVisible(true);
457         if(using_flags->is_use_fd()) {
458                 int i;
459                 for(i = 0; i < using_flags->get_max_drive(); i++) CreateFloppyMenu(i, i + 1);
460         }
461         if(using_flags->is_use_qd()) {
462                 int i;
463                 for(i = 0; i < using_flags->get_max_qd(); i++) CreateQuickDiskMenu(i, i + 1);
464         }
465         if(using_flags->is_use_tape()) {
466                 for(int i = 0; i < using_flags->get_max_tape(); i++) CreateCMTMenu(i);
467         }
468         if(using_flags->get_max_scsi() > 0) {
469         }
470         CreateScreenMenu();
471         if(using_flags->is_use_cart()) {
472                 int i;
473                 for(i = 0; i < using_flags->get_max_cart(); i++) {
474                         CreateCartMenu(i, i + 1);
475                 }
476         }
477         if(using_flags->is_use_binary_file()) {
478                 int i;
479                 for(i = 0; i < using_flags->get_max_binary(); i++) {
480                         CreateBinaryMenu(i, i + 1);
481                 }
482         }
483         if(using_flags->is_use_compact_disc()) {
484                 CreateCDROMMenu();
485         }
486         if(using_flags->is_use_laser_disc()) {
487                 CreateLaserdiscMenu();
488         }
489         if(using_flags->is_use_bubble()) {
490                 int i;
491                 for(i = 0; i < using_flags->get_max_bubble(); i++) {
492                         CreateBubbleMenu(i, i + 1);
493                 }
494         }
495         connect(this, SIGNAL(sig_update_screen(void)), graphicsView, SLOT(update(void)));
496         //connect(this, SIGNAL(sig_update_screen(void)), graphicsView, SLOT(updateGL(void)));
497
498         menuMachine = new QMenu(menubar);
499         menuMachine->setObjectName(QString::fromUtf8("menuMachine"));
500         menuMachine->setToolTipsVisible(true);
501
502         if(using_flags->is_use_mouse()) {
503                 actionMouseEnable = new Action_Control(this, using_flags);
504                 actionMouseEnable->setCheckable(true);
505                 actionMouseEnable->setVisible(true);
506                 actionMouseEnable->setChecked(false);
507                 menuMachine->addAction(actionMouseEnable);
508                 connect(actionMouseEnable, SIGNAL(toggled(bool)),
509                                 this, SLOT(do_set_mouse_enable(bool)));
510                 connect(graphicsView, SIGNAL(sig_check_grab_mouse(bool)),
511                                 actionMouseEnable, SLOT(do_check_grab_mouse(bool)));
512         }
513
514         ConfigDeviceType();
515         ConfigMouseType();
516         ConfigKeyboardType();
517         ConfigJoystickType();
518         ConfigDriveType();
519         ConfigSoundDeviceType();
520         ConfigPrinterType();
521
522         if(!using_flags->is_without_sound()) {
523                 menuSound = new QMenu(menubar);
524                 menuSound->setObjectName(QString::fromUtf8("menuSound"));
525                 menuSound->setToolTipsVisible(true);
526         }
527         menuEmulator = new QMenu(menubar);
528         menuEmulator->setObjectName(QString::fromUtf8("menuEmulator"));
529         menuEmulator->setToolTipsVisible(true);
530
531         menuHELP = new QMenu(menubar);
532         menuHELP->setObjectName(QString::fromUtf8("menuHELP"));
533         menuHELP->setToolTipsVisible(true);
534         MainWindow->setMenuBar(menubar);
535
536         menubar->addAction(menuControl->menuAction());
537         connectActions_ControlMenu();
538         if(using_flags->is_use_fd()) {
539                 int i;
540                 for(i = 0; i < using_flags->get_max_drive(); i++) {
541                         menubar->addAction(menu_fds[i]->menuAction());
542                 }
543         }
544         if(using_flags->is_use_qd()) {
545                 int i;
546                 for(i = 0; i < using_flags->get_max_qd(); i++) {
547                         menubar->addAction(menu_QDs[i]->menuAction());
548                 }
549         }
550         if(using_flags->is_use_tape()) {
551                 for(int i = 0; i < using_flags->get_max_tape(); i++) menubar->addAction(menu_CMT[i]->menuAction());
552         }
553         if(using_flags->is_use_cart()) {
554                 int i;
555                 for(i = 0; i < using_flags->get_max_cart(); i++) {
556                         menubar->addAction(menu_Cart[i]->menuAction());
557                 }
558         }
559         if(using_flags->is_use_binary_file()) {
560                 int i;
561                 for(i = 0; i < using_flags->get_max_binary(); i++) {
562                         menubar->addAction(menu_BINs[i]->menuAction());
563                 }
564         }
565         if(using_flags->is_use_compact_disc()) {
566                 menubar->addAction(menu_CDROM->menuAction());
567         }
568         if(using_flags->is_use_laser_disc()) {
569                 menubar->addAction(menu_Laserdisc->menuAction());
570         }
571         if(using_flags->is_use_bubble()) {
572                 int i;
573                 for(i = 0; i < using_flags->get_max_bubble(); i++) {
574                         menubar->addAction(menu_bubbles[i]->menuAction());
575                 }
576         }
577         menubar->addAction(menuMachine->menuAction());
578         if(!using_flags->is_without_sound()) {
579                 menubar->addAction(menuSound->menuAction());
580         }
581
582         menubar->addAction(menuScreen->menuAction());
583 //      menubar->addAction(menuRecord->menuAction());
584         menubar->addAction(menuEmulator->menuAction());
585         menubar->addAction(menuHELP->menuAction());
586         if(using_flags->is_use_qd()) {
587                 int i;
588                 for(i = 0; i < using_flags->get_max_qd(); i++) {
589                         CreateQuickDiskPulldownMenu(i);
590                 }
591         }
592         if(using_flags->is_use_binary_file()) {
593                 int i;
594                 for(i = 0; i < using_flags->get_max_binary(); i++) {
595                         CreateBinaryPulldownMenu(1);
596                 }
597         }
598         if(!using_flags->is_without_sound()) {
599                 CreateSoundMenu();
600         }
601         CreateEmulatorMenu();
602   
603         menuHELP->addAction(actionAbout);
604         connect(actionAbout, SIGNAL(triggered()), this, SLOT(do_show_about()));
605         menuHELP->addSeparator();
606         
607         actionHelp_AboutQt = new Action_Control(this, using_flags);
608         actionHelp_AboutQt->setObjectName(QString::fromUtf8("menuHelp_AboutQt"));
609         menuHELP->addAction(actionHelp_AboutQt);
610         menuHELP->addSeparator();
611         menuHelp_Readme = new QMenu(menuHELP);
612         menuHelp_Readme->setObjectName(QString::fromUtf8("menuHelp_Readme_menu"));;
613         menuHelp_Readme->setToolTipsVisible(true);
614         menuHELP->addAction(menuHelp_Readme->menuAction());
615
616         SET_HELP_MENUENTRY(menuHelp_Readme, actionHelp_README, "menuHelp_README", "readme.txt");
617         SET_HELP_MENUENTRY(menuHelp_Readme, actionHelp_README_QT, "menuHelp_README_QT", "readme.qt.txt");
618         SET_HELP_MENUENTRY(menuHelp_Readme, actionHelp_README_Artane, "menuHelp_README_Artane", "readme_by_artane.txt");
619         SET_HELP_MENUENTRY(menuHelp_Readme, actionHelp_README_Umaiboux, "menuHelp_README_Umaiboux", "readme_by_umaiboux.txt");
620         menuHelp_Readme->addSeparator();
621         SET_HELP_MENUENTRY(menuHelp_Readme, actionHelp_README_BIOS, "menuHelp_README_BIOS", "bios_and_keys.txt");
622         menuHelp_Readme->addSeparator();
623         SET_HELP_MENUENTRY(menuHelp_Readme, actionHelp_README_MR_TANAM, "menuHelp_README_MR_TANAM", "readme_by_mr_tanam.txt");
624         menuHelp_Readme->addSeparator();
625         SET_HELP_MENUENTRY(menuHelp_Readme, actionHelp_README_FAQ, "menuHelp_README_FAQ", "FAQ.html");
626         SET_HELP_MENUENTRY(menuHelp_Readme, actionHelp_README_FAQ_JP, "menuHelp_README_FAQ_JP", "FAQ.ja.html");
627         menuHelp_Readme->addSeparator();
628         SET_HELP_MENUENTRY(menuHelp_Readme, actionHelp_README_FM7, "menuHelp_README_FM7", "readme_fm7.txt");
629         SET_HELP_MENUENTRY(menuHelp_Readme, actionHelp_README_FM7_JP, "menuHelp_README_FM7_JP", "readme_fm7.jp.txt");
630
631         menuHelp_Histories = new QMenu(menuHELP);
632         menuHelp_Histories->setObjectName(QString::fromUtf8("menuHelp_Histories"));;
633         menuHelp_Histories->setToolTipsVisible(true);
634         menuHELP->addAction(menuHelp_Histories->menuAction());
635
636         SET_HELP_MENUENTRY(menuHelp_Histories, actionHelp_History, "menuHelp_History", "history.txt");
637         SET_HELP_MENUENTRY(menuHelp_Histories, actionHelp_History_Relnote, "menuHelp_History_Relnote", "RELEASENOTE.txt");
638         SET_HELP_MENUENTRY(menuHelp_Histories, actionHelp_History_ChangeLog, "menuHelp_History_Changelog", "ChangeLog.txt");
639         SET_HELP_MENUENTRY(menuHelp_Histories, actionHelp_History_MR_TANAM, "menuHelp_History_MR_TANAM", "history_by_mr_tanam.txt");
640         
641         SET_HELP_MENUENTRY(menuHELP, actionHelp_License, "menuHelp_License", "LICENSE.txt");
642         SET_HELP_MENUENTRY(menuHELP, actionHelp_License_JP, "menuHelp_License_JP", "LICENSE.ja.txt");
643         
644         if(using_flags->get_config_ptr()->window_mode <= 0) using_flags->get_config_ptr()->window_mode = 0;
645         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;
646         w = using_flags->get_screen_width();
647         h = using_flags->get_screen_height();
648         if(actionScreenSize[using_flags->get_config_ptr()->window_mode] != NULL) {
649                 double nd = actionScreenSize[using_flags->get_config_ptr()->window_mode]->binds->getDoubleValue();
650                 w = (int)(nd * (double)w);
651                 h = (int)(nd * (double)h);
652                 if(using_flags->is_use_screen_rotate()) {
653                         if(using_flags->get_config_ptr()->rotate_type) {
654                                 int tmp_w = w;
655                                 w = h;
656                                 h = tmp_w;
657                         }
658                 }
659         } else {
660                 if(using_flags->is_use_screen_rotate()) {
661                         if(using_flags->get_config_ptr()->rotate_type) {
662                                 w = 600;
663                                 h = 960;
664                         } else {                   
665                                 w = 1280;
666                                 h = 800;
667                         }
668                 } else {
669                         w = 1280;
670                         h = 800;
671                 }
672         }
673         graphicsView->setFixedSize(w, h);
674         for(int i = 0; i < using_flags->get_screen_mode_num(); i++) {
675                 if(actionScreenSize[i] != NULL) {
676                         connect(actionScreenSize[i]->binds, SIGNAL(sig_screen_multiply(float)),
677                                 graphicsView, SLOT(do_set_screen_multiply(float)));
678                 }
679         }
680         this->set_screen_size(w, h);
681         this->set_screen_aspect(using_flags->get_config_ptr()->window_stretch_type);
682         if(actionScreenSize[using_flags->get_config_ptr()->window_mode] != NULL) {
683                 double nd = actionScreenSize[using_flags->get_config_ptr()->window_mode]->binds->getDoubleValue();
684                 graphicsView->do_set_screen_multiply(nd);
685         }
686         if(using_flags->is_use_joystick()) {
687                 connect(action_SetupJoystick, SIGNAL(triggered()), this, SLOT(rise_joystick_dialog()));
688         }
689
690         if(using_flags->is_use_sound_files_fdd()) {
691                 connect(action_SoundFilesFDD, SIGNAL(toggled(bool)), this, SLOT(do_set_sound_files_fdd(bool)));
692         }
693         if(using_flags->is_use_sound_files_relay()) {
694                 connect(action_SoundFilesRelay, SIGNAL(toggled(bool)), this, SLOT(do_set_sound_files_relay(bool)));
695         }
696         connect(action_SetupKeyboard, SIGNAL(triggered()), this, SLOT(rise_keyboard_dialog()));
697 #if !defined(Q_OS_WIN)
698         connect(action_LogToSyslog, SIGNAL(toggled(bool)), this, SLOT(do_set_syslog(bool)));
699 #endif  
700         connect(action_LogToConsole, SIGNAL(toggled(bool)), this, SLOT(do_set_conslog(bool)));
701         csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "Menu OK");
702            
703         QImageReader reader(":/default.ico");
704         QImage result = reader.read();
705
706         MainWindow->setWindowIcon(QPixmap::fromImage(result));
707         this->set_window_title();
708 //      QIcon WindowIcon;
709         InsertIcon = QApplication::style()->standardIcon(QStyle::SP_FileDialogStart);
710         EjectIcon  = QIcon(":/icon_eject.png");
711         StopIcon = QIcon(":/icon_process_stop.png");
712         RecordSoundIcon = QIcon(":/icon_record_to_wav.png");
713         ResetIcon = QApplication::style()->standardIcon(QStyle::SP_BrowserReload);
714
715         VolumeMutedIcon = QIcon(":/icon_volume_muted.png");
716         VolumeLowIcon = QIcon(":/icon_volume_low.png");
717         VolumeMidIcon = QIcon(":/icon_volume_mid.png");
718         VolumeHighIcon = QIcon(":/icon_volume_high.png");
719         
720         ExitIcon = QIcon(":/icon_exit.png");
721
722         QMetaObject::connectSlotsByName(MainWindow);
723         csp_logger->debug_log(CSP_LOG_INFO, CSP_LOG_TYPE_GENERAL, "setupUI() OK");
724 } // setupUi
725
726 // Emulator
727 #include "dropdown_joystick.h"
728 #include "dialog_set_key.h"
729
730 void Ui_MainWindowBase::retranslateEmulatorMenu(void)
731 {
732         if(using_flags->is_use_joystick()) {
733                 action_SetupJoystick->setText(QApplication::translate("MenuEmulator", "Configure Joysticks", 0));
734                 action_SetupJoystick->setToolTip(QApplication::translate("MenuEmulator", "Configure assigning buttons/directions of joysticks.", 0));
735                 action_SetupJoystick->setIcon(QIcon(":/icon_gamepad.png"));
736         }
737         if(using_flags->is_use_auto_key()) {
738                 action_UseRomaKana->setText(QApplication::translate("MenuEmulator", "ROMA-KANA Conversion", 0));
739                 action_UseRomaKana->setToolTip(QApplication::translate("MenuEmulator", "Use romaji-kana conversion assistant of emulator.", 0));
740         }
741         action_NumPadEnterAsFullkey->setText(QApplication::translate("MenuEmulator", "Numpad's Enter is Fullkey's", 0));
742         action_NumPadEnterAsFullkey->setToolTip(QApplication::translate("MenuEmulator", "Numpad's enter key makes full key's enter.\nUseful for some VMs.", 0));
743
744         action_PrintCpuStatistics->setText(QApplication::translate("MenuEmulator", "Print Statistics", 0));
745         action_PrintCpuStatistics->setToolTip(QApplication::translate("MenuEmulator", "Print statistics of CPUs (or some devices).\nUseful for debugging.", 0));
746
747         if(action_Logging_FDC != NULL) {
748                 action_Logging_FDC->setText(QApplication::translate("MenuEmulator", "FDC: Turn ON Debug log.", 0));
749                 action_Logging_FDC->setToolTip(QApplication::translate("MenuEmulator", "Turn ON debug logging for FDCs.Useful to resolve issues from guest software.", 0));
750         }
751         // ToDo
752         menu_EmulateCursorAs->setTitle(QApplication::translate("MenuEmulator", "Emulate cursor as", 0));
753         menu_EmulateCursorAs->setToolTip(QApplication::translate("MenuEmulator", "Emulate cursor as ten-key.", 0));
754         action_EmulateCursorAs[0]->setText(QApplication::translate("MenuEmulator", "None", 0));
755         action_EmulateCursorAs[1]->setText(QApplication::translate("MenuEmulator", "2 4 6 8", 0));
756         action_EmulateCursorAs[2]->setText(QApplication::translate("MenuEmulator", "1 2 3 5", 0));
757         
758         menuEmulator->setTitle(QApplication::translate("MenuEmulator", "Emulator", 0));
759
760         
761         action_FocusWithClick->setText(QApplication::translate("MenuEmulator", "Focus on click", 0));
762         action_FocusWithClick->setToolTip(QApplication::translate("MenuEmulator", "If set, focus with click, not mouse-over.", 0));
763         
764         action_SetupKeyboard->setText(QApplication::translate("MenuEmulator", "Configure Keyboard", 0));
765         action_SetupKeyboard->setToolTip(QApplication::translate("MenuEmulator", "Set addignation of keyboard.", 0));
766         action_SetupKeyboard->setIcon(QIcon(":/icon_keyboard.png"));
767         action_SetupMovie->setText(QApplication::translate("MenuEmulator", "Configure movie encoding", 0));
768         action_SetupMovie->setToolTip(QApplication::translate("MenuEmulator", "Configure parameters of movie encoding.", 0));
769
770         action_LogToConsole->setText(QApplication::translate("MenuEmulator", "Log to Console", 0));
771         action_LogToConsole->setToolTip(QApplication::translate("MenuEmulator", "Enable logging to STDOUT if checked.", 0));
772 #if !defined(Q_OS_WIN)
773         action_LogToSyslog->setText(QApplication::translate("MenuEmulator", "Log to Syslog", 0));
774         action_LogToSyslog->setToolTip(QApplication::translate("MenuEmulator", "Enable logging to SYSTEM log.\nMay be having permission to system and using *nix OS.", 0));
775         //action_LogRecord->setText(QApplication::translate("MenuEmulator", "Recording Log", 0));
776 #endif
777         if(using_flags->is_use_sound_files_fdd()) {
778                 action_SoundFilesFDD->setText(QApplication::translate("MenuEmulator", "Sound FDD Seek", 0));
779                 action_SoundFilesFDD->setToolTip(QApplication::translate("MenuEmulator", "Enable FDD HEAD seeking sound.\nNeeds sound file.\nSee HELP->READMEs->Bios and Key assigns", 0));
780         }
781         if(using_flags->is_use_sound_files_relay()) {
782                 action_SoundFilesRelay->setText(QApplication::translate("MenuEmulator", "Sound CMT Relay and Buttons", 0));
783                 action_SoundFilesRelay->setToolTip(QApplication::translate("MenuEmulator", "Enable CMT relay's sound and buttons's sounds.\nNeeds sound file.\nSee HELP->READMEs->Bios and Key assigns", 0));
784         }
785         menuDevLogToConsole->setTitle(QApplication::translate("MenuEmulator", "Per Device", 0));
786 #if !defined(Q_OS_WIN)
787         menuDevLogToSyslog->setTitle(QApplication::translate("MenuEmulator", "Per Device", 0));
788 #endif
789         menu_SetRenderPlatform->setTitle(QApplication::translate("MenuEmulator", "Video Platform(need restart)", 0));
790         action_SetRenderPlatform[RENDER_PLATFORMS_OPENGL3_MAIN]->setText(QApplication::translate("MenuEmulator", "OpenGLv3.0", 0));
791         action_SetRenderPlatform[RENDER_PLATFORMS_OPENGL2_MAIN]->setText(QApplication::translate("MenuEmulator", "OpenGLv2.0", 0));
792         action_SetRenderPlatform[RENDER_PLATFORMS_OPENGL_CORE]->setText(QApplication::translate("MenuEmulator", "OpenGL(Core profile)", 0));
793         action_SetRenderPlatform[RENDER_PLATFORMS_OPENGL3_MAIN]->setToolTip(QApplication::translate("MenuEmulator", "Using OpenGL v3.0(MAIN).\nThis is recommanded.\nIf changed, need to restart this emulator.", 0));
794         action_SetRenderPlatform[RENDER_PLATFORMS_OPENGL2_MAIN]->setToolTip(QApplication::translate("MenuEmulator", "Using OpenGLv2.\nThis is fallback of some systems.\nIf changed, need to restart this emulator.", 0));
795         action_SetRenderPlatform[RENDER_PLATFORMS_OPENGL_CORE]->setToolTip(QApplication::translate("MenuEmulator", "Using OpenGL core profile.\nThis still not implement.\nIf changed, need to restart this emulator.", 0));
796
797         menu_DispVirtualMedias->setTitle(QApplication::translate("MenuEmulator", "Show Virtual Medias.", 0));
798         action_DispVirtualMedias[0]->setText(QApplication::translate("MenuEmulator", "None.", 0));
799         action_DispVirtualMedias[1]->setText(QApplication::translate("MenuEmulator", "Upper.", 0));
800         action_DispVirtualMedias[2]->setText(QApplication::translate("MenuEmulator", "Lower.", 0));
801         //action_DispVirtualMedias[3]->setText(QApplication::translate("MenuEmulator", "Left.", 0));
802         //action_DispVirtualMedias[4]->setText(QApplication::translate("MenuEmulator", "Right.", 0));
803         action_LogView->setText(QApplication::translate("MenuEmulator", "View Log", 0));
804         action_LogView->setToolTip(QApplication::translate("MenuEmulator", "View emulator logs with a dialog.", 0));
805 }
806
807 void Ui_MainWindowBase::retranselateUi_Depended_OSD(void)
808 {
809         for(int i=0; i < (CSP_LOG_TYPE_VM_DEVICE_END - CSP_LOG_TYPE_VM_DEVICE_0 + 1) ; i++) {
810                 const _TCHAR *p;
811                 p = using_flags->get_vm_node_name(i);
812                 do_update_device_node_name(i, p);
813         }
814 }
815
816 void Ui_MainWindowBase::do_set_roma_kana(bool flag)
817 {
818         using_flags->get_config_ptr()->romaji_to_kana = flag;
819 }
820
821 void Ui_MainWindowBase::do_set_numpad_enter_as_fullkey(bool flag)
822 {
823         using_flags->get_config_ptr()->numpad_enter_as_fullkey = flag;
824 }
825
826 void Ui_MainWindowBase::do_set_print_cpu_statistics(bool flag)
827 {
828         using_flags->get_config_ptr()->print_statistics = flag;
829 }
830
831 void Ui_MainWindowBase::CreateEmulatorMenu(void)
832 {
833         //menuEmulator->addAction(action_LogRecord);
834         menuEmulator->addAction(action_FocusWithClick);
835         menuEmulator->addAction(menu_DispVirtualMedias->menuAction());
836         menuEmulator->addSeparator();
837         if(using_flags->is_use_auto_key()) {
838                 menuEmulator->addAction(action_UseRomaKana);
839         }
840         menuEmulator->addAction(action_NumPadEnterAsFullkey);
841         menuEmulator->addAction(menu_EmulateCursorAs->menuAction());
842         if(action_Logging_FDC != NULL) {
843                 menuEmulator->addSeparator();
844                 menuEmulator->addAction(action_Logging_FDC);
845         }
846         menuEmulator->addAction(action_PrintCpuStatistics);
847         menuEmulator->addSeparator();
848         menuEmulator->addAction(action_LogToConsole);
849         menuEmulator->addAction(menuDevLogToConsole->menuAction());
850         menuEmulator->addSeparator();
851 #if !defined(Q_OS_WIN)
852         menuEmulator->addAction(action_LogToSyslog);
853         menuEmulator->addAction(menuDevLogToSyslog->menuAction());
854 #endif
855         menuEmulator->addSeparator();
856         menuEmulator->addAction(action_LogView);
857         menuEmulator->addSeparator();
858         if(using_flags->is_use_sound_files_fdd() || using_flags->is_use_sound_files_relay()) {
859                 if(using_flags->is_use_sound_files_fdd())     menuEmulator->addAction(action_SoundFilesFDD);
860                 if(using_flags->is_use_sound_files_relay())   menuEmulator->addAction(action_SoundFilesRelay);
861                 menuEmulator->addSeparator();
862         }
863         menuEmulator->addAction(menu_SetRenderPlatform->menuAction());
864         
865         if(using_flags->is_use_joystick()) {
866                 menuEmulator->addAction(action_SetupJoystick);
867         }
868         menuEmulator->addAction(action_SetupKeyboard);
869         menuEmulator->addAction(action_SetupMovie);
870 }
871
872 void Ui_MainWindowBase::ConfigEmulatorMenu(void)
873 {
874         int i;
875         QString tmps;
876         actionGroup_DispVirtualMedias = new QActionGroup(this);
877         actionGroup_DispVirtualMedias->setExclusive(true);
878         menu_DispVirtualMedias = new QMenu(this);
879         menu_DispVirtualMedias->setToolTipsVisible(true);
880         for(i = 0; i < 3; i++) {
881                 action_DispVirtualMedias[i] = new Action_Control(this, using_flags);
882                 action_DispVirtualMedias[i]->setCheckable(true);
883                 action_DispVirtualMedias[i]->setChecked(false);
884                 if(i == using_flags->get_config_ptr()->virtual_media_position) action_DispVirtualMedias[i]->setChecked(true);
885                 action_DispVirtualMedias[i]->setEnabled(true);
886                 actionGroup_DispVirtualMedias->addAction(action_DispVirtualMedias[i]);
887                 menu_DispVirtualMedias->addAction(action_DispVirtualMedias[i]);
888         }
889         connect(action_DispVirtualMedias[0], SIGNAL(triggered()), this, SLOT(do_set_visible_virtual_media_none()));
890         connect(action_DispVirtualMedias[1], SIGNAL(triggered()), this, SLOT(do_set_visible_virtual_media_upper()));
891         connect(action_DispVirtualMedias[2], SIGNAL(triggered()), this, SLOT(do_set_visible_virtual_media_lower()));
892                         
893         if(using_flags->is_use_auto_key()) {
894                 SET_ACTION_SINGLE(action_UseRomaKana, true, true, (using_flags->get_config_ptr()->romaji_to_kana));
895                 connect(action_UseRomaKana, SIGNAL(toggled(bool)), this, SLOT(do_set_roma_kana(bool)));
896         }
897         SET_ACTION_SINGLE(action_NumPadEnterAsFullkey, true, true, (using_flags->get_config_ptr()->numpad_enter_as_fullkey));
898         connect(action_NumPadEnterAsFullkey, SIGNAL(toggled(bool)), this, SLOT(do_set_numpad_enter_as_fullkey(bool)));
899
900         SET_ACTION_SINGLE(action_PrintCpuStatistics, true, true, (using_flags->get_config_ptr()->print_statistics));
901         connect(action_PrintCpuStatistics, SIGNAL(toggled(bool)), this, SLOT(do_set_print_cpu_statistics(bool)));
902         
903         // Cursor to ten key.
904         menu_EmulateCursorAs = new QMenu(this);
905         menu_EmulateCursorAs->setToolTipsVisible(true);
906         actionGroup_EmulateCursorAs = new QActionGroup(this);
907         actionGroup_EmulateCursorAs->setExclusive(true);
908         {
909                 for(i = 0; i < 3; i++) {
910                         tmps = QString::number(i);
911                         action_EmulateCursorAs[i] = new Action_Control(this, using_flags);
912                         action_EmulateCursorAs[i]->setObjectName(QString::fromUtf8("action_EmulateCursorAs", -1) + tmps);
913                         action_EmulateCursorAs[i]->setCheckable(true);
914                         action_EmulateCursorAs[i]->binds->setValue1(i);
915                         actionGroup_EmulateCursorAs->addAction(action_EmulateCursorAs[i]);
916                         menu_EmulateCursorAs->addAction(action_EmulateCursorAs[i]);
917                         if(i == using_flags->get_config_ptr()->cursor_as_ten_key) action_EmulateCursorAs[i]->setChecked(true);
918                                 
919                         connect(action_EmulateCursorAs[i], SIGNAL(triggered()),
920                                         action_EmulateCursorAs[i], SLOT(do_set_emulate_cursor_as()));
921                         connect(action_EmulateCursorAs[i], SIGNAL(sig_set_emulate_cursor_as(int)),
922                                         this, SLOT(do_set_emulate_cursor_as(int)));
923                 }
924         }
925         
926         if(using_flags->is_use_joystick()) {
927                 action_SetupJoystick = new Action_Control(this, using_flags);
928         }
929         if(using_flags->is_use_sound_files_fdd()) {
930                 /*
931                 action_SoundFilesFDD = new Action_Control(this, using_flags);
932                 action_SoundFilesFDD->setCheckable(true);
933                 action_SoundFilesFDD->setEnabled(true);
934                 action_SoundFilesFDD->setChecked(false);
935                 if(using_flags->get_config_ptr()->sound_noise_fdd != 0) {
936                         action_SoundFilesFDD->setChecked(true);
937                 }
938                 */
939                 SET_ACTION_SINGLE(action_SoundFilesFDD, true, true, (using_flags->get_config_ptr()->sound_noise_fdd != 0));
940         }
941         if(using_flags->is_use_sound_files_relay()) {
942                 /*
943                 action_SoundFilesRelay = new Action_Control(this, using_flags);
944                 action_SoundFilesRelay->setCheckable(true);
945                 action_SoundFilesRelay->setEnabled(true);
946                 action_SoundFilesRelay->setChecked(false);
947                 if(using_flags->get_config_ptr()->sound_noise_cmt != 0) {
948                         action_SoundFilesRelay->setChecked(true);
949                 }
950                 */
951                 SET_ACTION_SINGLE(action_SoundFilesRelay, true, true, (using_flags->get_config_ptr()->sound_noise_cmt != 0));
952         }
953         action_FocusWithClick = new Action_Control(this, using_flags);
954         action_FocusWithClick->setCheckable(true);
955         action_FocusWithClick->setEnabled(true);
956         if(using_flags->get_config_ptr()->focus_with_click) {
957                 action_FocusWithClick->setChecked(true);
958         }
959
960         connect(action_FocusWithClick, SIGNAL(toggled(bool)),
961                                 this, SLOT(do_set_window_focus_type(bool)));
962         //connect(action_FocusWithClick, SIGNAL(sig_set_window_focus_type(bool)),
963         //                      this, SLOT(do_set_window_focus_type(bool)));
964
965         action_Logging_FDC = NULL;
966         if(using_flags->is_use_fd()) {
967                 SET_ACTION_SINGLE(action_Logging_FDC, true, true, (using_flags->get_config_ptr()->special_debug_fdc != 0));
968                 connect(action_Logging_FDC, SIGNAL(toggled(bool)), this, SLOT(do_set_logging_fdc(bool)));
969         }
970 #if !defined(Q_OS_WIN)
971         action_LogToSyslog = new Action_Control(this, using_flags);
972         action_LogToSyslog->setCheckable(true);
973         action_LogToSyslog->setEnabled(true);
974         if(using_flags->get_config_ptr()->log_to_syslog != 0) action_LogToSyslog->setChecked(true);
975         menuDevLogToSyslog = new QMenu(this);
976         menuDevLogToSyslog->setToolTipsVisible(true);
977         for(int i = 0; i < (CSP_LOG_TYPE_VM_DEVICE_END - CSP_LOG_TYPE_VM_DEVICE_0 + 1); i++) {
978                 action_DevLogToSyslog[i] = new Action_Control(this, using_flags);
979                 action_DevLogToSyslog[i]->setCheckable(true);
980                 action_DevLogToSyslog[i]->setEnabled(false);
981                 action_DevLogToSyslog[i]->binds->setValue1(i);
982                 menuDevLogToSyslog->addAction(action_DevLogToSyslog[i]);
983                 if(using_flags->get_config_ptr()->dev_log_to_syslog[i][0]) action_DevLogToSyslog[i]->setChecked(true);
984                 connect(action_DevLogToSyslog[i], SIGNAL(toggled(bool)),
985                                 action_DevLogToSyslog[i], SLOT(do_set_dev_log_to_syslog(bool)));
986                 connect(action_DevLogToSyslog[i], SIGNAL(sig_set_dev_log_to_syslog(int, bool)),
987                                 this, SLOT(do_set_dev_log_to_syslog(int, bool)));
988         }
989 #endif
990         action_LogToConsole = new Action_Control(this, using_flags);
991         action_LogToConsole->setCheckable(true);
992         action_LogToConsole->setEnabled(true);
993         if(using_flags->get_config_ptr()->log_to_console != 0) action_LogToConsole->setChecked(true);
994
995         //menuDevLogToConsole = new QMenu(menuEmulator);
996         menuDevLogToConsole = new QMenu(this);
997         menuDevLogToConsole->setToolTipsVisible(true);
998
999         SET_ACTION_CONTROL_ARRAY(0, (CSP_LOG_TYPE_VM_DEVICE_END - CSP_LOG_TYPE_VM_DEVICE_0 + 1),
1000                                                          this, using_flags,
1001                                                          menuDevLogToConsole, action_DevLogToConsole, true, false,
1002                                                          dev_log_to_console,
1003                                                          SIGNAL(toggled(bool)),
1004                                                          SLOT(do_set_dev_log_to_console(bool)),
1005                                                          SIGNAL(sig_set_dev_log_to_console(int, bool)),
1006                                                          SLOT(do_set_dev_log_to_console(int, bool)));
1007         /*
1008         for(int i = 0; i < (CSP_LOG_TYPE_VM_DEVICE_END - CSP_LOG_TYPE_VM_DEVICE_0 + 1); i++) {
1009                 action_DevLogToConsole[i] = new Action_Control(this, using_flags);
1010                 action_DevLogToConsole[i]->setCheckable(true);
1011                 action_DevLogToConsole[i]->setEnabled(false);
1012                 action_DevLogToConsole[i]->binds->setValue1(i);
1013                 menuDevLogToConsole->addAction(action_DevLogToConsole[i]);
1014                 if(using_flags->get_config_ptr()->dev_log_to_console[i][0]) action_DevLogToConsole[i]->setChecked(true);
1015                 connect(action_DevLogToConsole[i], SIGNAL(toggled(bool)),
1016                                 action_DevLogToConsole[i], SLOT(do_set_dev_log_to_console(bool)));
1017                 connect(action_DevLogToConsole[i], SIGNAL(sig_set_dev_log_to_console(int, bool)),
1018                                 this, SLOT(do_set_dev_log_to_console(int, bool)));
1019         }
1020         */
1021         action_LogView = new Action_Control(this, using_flags);
1022         connect(action_LogView, SIGNAL(triggered()),
1023                         this, SLOT(rise_log_viewer()));
1024         
1025         menu_SetRenderPlatform = new QMenu(this);
1026         menu_SetRenderPlatform->setToolTipsVisible(true);
1027         actionGroup_SetRenderPlatform = new QActionGroup(this);
1028         actionGroup_SetRenderPlatform->setExclusive(true);
1029         {
1030                         int render_type = using_flags->get_config_ptr()->render_platform;
1031                         int _major_version = using_flags->get_config_ptr()->render_major_version;
1032                         //int _minor_version = using_flags->get_config_ptr()->render_minor_version; // ToDo
1033                         for(i = 0; i < MAX_RENDER_PLATFORMS; i++) {
1034                                 tmps = QString::number(i);
1035                                 action_SetRenderPlatform[i] = new Action_Control(this, using_flags);
1036                                 action_SetRenderPlatform[i]->setObjectName(QString::fromUtf8("action_SetRenderPlatform", -1) + tmps);
1037                                 action_SetRenderPlatform[i]->setCheckable(true);
1038                                 action_SetRenderPlatform[i]->binds->setValue1(i);
1039                                 actionGroup_SetRenderPlatform->addAction(action_SetRenderPlatform[i]);
1040                                 menu_SetRenderPlatform->addAction(action_SetRenderPlatform[i]);
1041                                 if(i >= RENDER_PLATFORMS_END) {
1042                                         action_SetRenderPlatform[i]->setVisible(false);
1043                                 } else {
1044                                         if(render_type == CONFIG_RENDER_PLATFORM_OPENGL_MAIN) {
1045                                                 if(_major_version >= 3) {
1046                                                         if(i == RENDER_PLATFORMS_OPENGL3_MAIN) {
1047                                                                 action_SetRenderPlatform[i]->setChecked(true);
1048                                                         }
1049                                                 } else if(i == RENDER_PLATFORMS_OPENGL2_MAIN) {
1050                                                         action_SetRenderPlatform[i]->setChecked(true);
1051                                                 }
1052                                         } else if(render_type == CONFIG_RENDER_PLATFORM_OPENGL_CORE) {
1053                                                 if(i == RENDER_PLATFORMS_OPENGL_CORE) {
1054                                                         action_SetRenderPlatform[i]->setChecked(true);
1055                                                 }                                               
1056                                         }
1057                                         if(i == RENDER_PLATFORMS_OPENGL_CORE) {
1058                                                         action_SetRenderPlatform[i]->setEnabled(false);
1059                                                         //action_SetRenderPlatform[i]->setCheckable(false);
1060                                         }                                               
1061                                 }
1062                                 connect(action_SetRenderPlatform[i], SIGNAL(triggered()),
1063                                                 action_SetRenderPlatform[i], SLOT(do_select_render_platform(void)));
1064                                 connect(action_SetRenderPlatform[i], SIGNAL(sig_select_render_platform(int)),
1065                                                 this, SLOT(do_select_render_platform(int)));
1066                         }
1067         }
1068         action_SetupKeyboard = new Action_Control(this, using_flags);
1069
1070         action_SetupMovie = new Action_Control(this, using_flags);
1071   
1072 }
1073
1074 #include "display_log.h"
1075
1076 void Ui_MainWindowBase::rise_log_viewer(void)
1077 {
1078         Dlg_LogViewer *dlg = new Dlg_LogViewer(using_flags, csp_logger, NULL);
1079         dlg->show();
1080 }
1081
1082 void Ui_MainWindowBase::rise_joystick_dialog(void)
1083 {
1084         if(graphicsView != NULL) {
1085                 QStringList *lst = graphicsView->getVKNames();
1086                 CSP_DropDownJoysticks *dlg = new CSP_DropDownJoysticks(NULL, lst, using_flags);
1087                 dlg->setWindowTitle(QApplication::translate("CSP_DropDownJoysticks", "Configure Joysticks", 0));
1088                 dlg->show();
1089         }
1090 }
1091
1092 void Ui_MainWindowBase::rise_movie_dialog(void)
1093 {
1094
1095 }
1096
1097 void Ui_MainWindowBase::rise_keyboard_dialog(void)
1098 {
1099         if(graphicsView != NULL) {
1100                 CSP_KeySetDialog *dlg = new CSP_KeySetDialog(NULL, graphicsView);
1101                 dlg->setWindowTitle(QApplication::translate("KeySetDialog", "Configure Keyboard", 0));
1102                 dlg->show();
1103         }
1104 }
1105 // Retranslate
1106 void Ui_MainWindowBase::retranslateUI_Help(void)
1107 {
1108         menuHELP->setTitle(QApplication::translate("MenuHelp", "Help", 0));
1109         actionHelp_AboutQt->setText(QApplication::translate("MenuHelp", "About Qt", 0));
1110         actionHelp_AboutQt->setToolTip(QApplication::translate("MenuHelp", "Display Qt version.", 0));
1111         actionHelp_AboutQt->setIcon(QApplication::style()->standardIcon(QStyle::SP_TitleBarMenuButton));
1112         
1113         actionAbout->setText(QApplication::translate("MenuHelp", "About...", 0));
1114         actionAbout->setIcon(QApplication::style()->standardIcon(QStyle::SP_MessageBoxQuestion));
1115         actionAbout->setToolTip(QApplication::translate("MenuHelp", "About this emulator.", 0));
1116
1117         menuHelp_Readme->setTitle(QApplication::translate("MenuHelp", "READMEs", 0));
1118         
1119         actionHelp_README->setText(QApplication::translate("MenuHelp", "General Document", 0));
1120         actionHelp_README_QT->setText(QApplication::translate("MenuHelp", "About Qt ports", 0));
1121         actionHelp_README_Artane->setText(QApplication::translate("MenuHelp", "About Qt ports (Japanese).", 0));
1122         actionHelp_README_Umaiboux->setText(QApplication::translate("MenuHelp", "By Mr. Umaiboux.", 0));
1123         actionHelp_README_MR_TANAM->setText(QApplication::translate("MenuHelp", "By Mr. tanam", 0));
1124         actionHelp_README_FM7->setText(QApplication::translate("MenuHelp", "About eFM-7/8/77/AV.", 0));
1125         actionHelp_README_FM7_JP->setText(QApplication::translate("MenuHelp", "About eFM-7/8/77/AV (Japanese).", 0));
1126         actionHelp_README_FAQ->setText(QApplication::translate("MenuHelp", "FAQs(English)", 0));
1127         actionHelp_README_FAQ_JP->setText(QApplication::translate("MenuHelp", "FAQs(Japanese)", 0));
1128         actionHelp_README_BIOS->setText(QApplication::translate("MenuHelp", "BIOS and Key assigns", 0));
1129
1130         menuHelp_Histories->setTitle(QApplication::translate("MenuHelp", "Histories", 0));
1131         actionHelp_History->setText(QApplication::translate("MenuHelp", "General History", 0));
1132         actionHelp_History_Relnote->setText(QApplication::translate("MenuHelp", "Release Note", 0));
1133         actionHelp_History_ChangeLog->setText(QApplication::translate("MenuHelp", "Change Log", 0));
1134         actionHelp_History_MR_TANAM->setText(QApplication::translate("MenuHelp", "History by Tanam", 0));
1135
1136         actionHelp_License->setText(QApplication::translate("MenuHelp", "Show License", 0));
1137         actionHelp_License->setToolTip(QApplication::translate("MenuHelp", "Show general license (GPLv2).", 0));
1138         actionHelp_License_JP->setText(QApplication::translate("MenuHelp", "Show License (Japanese)", 0));
1139         actionHelp_License_JP->setToolTip(QApplication::translate("MenuHelp", "Show general license (GPLv2).\nTranslated to Japanese.", 0));
1140         ui_retranslate_completed = true;
1141 }
1142
1143 // You can Override this function: Re-define on foo/MainWindow.cpp.
1144 // This code is example: by X1(TurboZ).
1145 void Ui_MainWindowBase::retranslateMachineMenu(void)
1146 {
1147         int i;
1148         QString tmps;
1149         QString tmps2;
1150         menuMachine->setTitle(QApplication::translate("MenuMachine", "Machine", 0));
1151         if(using_flags->get_use_device_type() > 0) {
1152                 menuDeviceType->setTitle(QApplication::translate("MenuMachine", "Device Type", 0));
1153                 for(i = 0; i < using_flags->get_use_device_type(); i++) {
1154                         tmps2.setNum(i + 1);
1155                         tmps = QString::fromUtf8("Machine Device ") + tmps2;
1156                         actionDeviceType[i]->setText(tmps); 
1157                 }
1158         }
1159         if(using_flags->get_use_sound_device_type() > 0) {
1160                 menuSoundDevice->setTitle(QApplication::translate("MenuMachine", "Sound Cards", 0));
1161                 for(i = 0; i < using_flags->get_use_sound_device_type(); i++) {
1162                         tmps2.setNum(i + 1);
1163                         tmps = QString::fromUtf8("Sound Device ") + tmps2;
1164                         actionSoundDevice[i]->setText(tmps); 
1165                 }
1166         }
1167         if(using_flags->get_use_drive_type() > 0) {
1168                 menuDriveType->setTitle(QApplication::translate("MenuMachine", "Drive Type", 0));
1169                 for(i = 0; i < using_flags->get_use_drive_type(); i++) {
1170                         tmps2.setNum(i + 1);
1171                         tmps = QString::fromUtf8("Drive Type ") + tmps2;
1172                         actionDriveType[i]->setText(tmps); 
1173                 }
1174         }
1175         if(using_flags->is_use_printer()) {
1176                 menuPrintDevice->setTitle(QApplication::translate("MenuMachine", "Printer (Need RESET)", 0));
1177                 i = 1;
1178                 actionPrintDevice[0]->setText(QApplication::translate("MenuMachine", "Dump to File", 0));
1179                 actionPrintDevice[0]->setToolTip(QApplication::translate("MenuMachine", "Dump printer output to file.\nMaybe output only ascii text.", 0));
1180                 if(using_flags->get_use_printer_type() > 0) {
1181                         for(i = 1; i < (using_flags->get_use_printer_type() - 1); i++) {
1182                                 tmps2.setNum(i + 1);
1183                                 tmps = QApplication::translate("MenuMachine", "Printer", 0) + tmps2;
1184                                 actionPrintDevice[i]->setText(tmps); 
1185                                 actionPrintDevice[i]->setToolTip(tmps); 
1186                         }
1187                 }
1188                 actionPrintDevice[i]->setText(QApplication::translate("MenuMachine", "Not Connect", 0));
1189                 actionPrintDevice[i]->setToolTip(QApplication::translate("MenuMachine", "None devices connect to printer port.", 0));
1190         }
1191 }
1192 void Ui_MainWindowBase::retranslateUi(void)
1193 {
1194         retranslateControlMenu("NMI Reset",  true);
1195         retranslateFloppyMenu(0, 0);
1196         retranslateFloppyMenu(1, 1);
1197         retranslateCMTMenu(0);
1198         if(!using_flags->is_without_sound()) {
1199                 retranslateSoundMenu();
1200         }
1201         retranslateScreenMenu();
1202         retranslateCartMenu(0, 1);
1203         retranslateCartMenu(1, 2);
1204         retranslateCDROMMenu();
1205         
1206         retranslateBinaryMenu(0, 1);
1207         retranslateBinaryMenu(1, 2);
1208
1209         retranslateBubbleMenu(0, 1);
1210         retranslateBubbleMenu(1, 2);
1211         retranslateMachineMenu();
1212         retranslateEmulatorMenu();
1213         retranslateUI_Help();
1214    
1215 } // retranslateUi
1216
1217 void Ui_MainWindowBase::doBeforeCloseMainWindow(void)
1218 {
1219         //emit quit_debugger_thread();
1220         emit quit_emulator_all();
1221 }
1222
1223 void Ui_MainWindowBase::setCoreApplication(QApplication *p)
1224 {
1225         this->CoreApplication = p;
1226         connect(actionExit_Emulator, SIGNAL(triggered()),
1227                         this, SLOT(doBeforeCloseMainWindow())); // OnGuiExit()?
1228         connect(this, SIGNAL(quit_emulator_all()), CoreApplication, SLOT(closeAllWindows()));
1229         connect(actionHelp_AboutQt, SIGNAL(triggered()),
1230                         this->CoreApplication, SLOT(aboutQt()));
1231         
1232 }
1233
1234 #include <string>
1235 // Move from common/qt_main.cpp
1236 // menu
1237 std::string cpp_confdir;
1238 extern std::string my_procname;
1239 extern bool now_menuloop;
1240 // timing control
1241
1242 // screen
1243 extern unsigned int desktop_width;
1244 extern unsigned int desktop_height;
1245 //int desktop_bpp;
1246 extern int prev_window_mode;
1247 extern bool now_fullscreen;
1248 extern int window_mode_count;
1249
1250 void Ui_MainWindowBase::set_window(int mode)
1251 {
1252         //      static LONG style = WS_VISIBLE;
1253 }
1254
1255 void Ui_MainWindowBase::do_emu_update_volume_level(int num, int level)
1256 {
1257         emit sig_emu_update_volume_level(num, level);
1258 }
1259
1260 void Ui_MainWindowBase::do_emu_update_volume_balance(int num, int level)
1261 {
1262         emit sig_emu_update_volume_balance(num, level);
1263 }
1264
1265 void Ui_MainWindowBase::do_emu_update_config(void)
1266 {
1267         emit sig_emu_update_config();
1268 }
1269
1270 void Ui_MainWindowBase::doChangeMessage_EmuThread(QString message)
1271 {
1272       emit message_changed(message);
1273 }
1274
1275 void Ui_MainWindowBase::do_set_visible_virtual_media_none()
1276 {
1277         driveData->setVisible(false);
1278         using_flags->get_config_ptr()->virtual_media_position = 0;
1279         set_screen_size(graphicsView->width(), graphicsView->height());
1280         pCentralLayout->removeWidget(driveData);
1281         pCentralLayout->removeWidget(graphicsView);
1282         pCentralLayout->addWidget(driveData);
1283         pCentralLayout->addWidget(graphicsView);
1284         //emit sig_set_display_osd(true);
1285 }
1286
1287 void Ui_MainWindowBase::do_set_visible_virtual_media_upper()
1288 {
1289         driveData->setVisible(true);
1290         using_flags->get_config_ptr()->virtual_media_position = 1;
1291         set_screen_size(graphicsView->width(), graphicsView->height());
1292         emit sig_set_orientation_osd(1);
1293         pCentralLayout->removeWidget(driveData);
1294         pCentralLayout->removeWidget(graphicsView);
1295         pCentralLayout->addWidget(driveData);
1296         pCentralLayout->addWidget(graphicsView);
1297         //emit sig_set_display_osd(false);
1298 }
1299
1300 void Ui_MainWindowBase::do_set_visible_virtual_media_lower()
1301 {
1302         driveData->setVisible(true);
1303         using_flags->get_config_ptr()->virtual_media_position = 2;
1304         set_screen_size(graphicsView->width(), graphicsView->height());
1305         emit sig_set_orientation_osd(2);
1306         pCentralLayout->removeWidget(driveData);
1307         pCentralLayout->removeWidget(graphicsView);
1308         pCentralLayout->addWidget(graphicsView);
1309         pCentralLayout->addWidget(driveData);
1310         //emit sig_set_display_osd(false);
1311 }
1312
1313 void Ui_MainWindowBase::do_set_visible_virtual_media_left()
1314 {
1315 #if 0
1316         driveData->setVisible(true);
1317         using_flags->get_config_ptr()->virtual_media_position = 3;
1318         set_screen_size(graphicsView->width(), graphicsView->height());
1319         emit sig_set_orientation_osd(3);
1320         pCentralLayout->removeWidget(driveData);
1321         pCentralLayout->addWidget(driveData, 1, 0);
1322         //emit sig_set_display_osd(false);
1323 #endif
1324 }
1325
1326 void Ui_MainWindowBase::do_set_visible_virtual_media_right()
1327 {
1328 #if 0
1329         driveData->setVisible(true);
1330         using_flags->get_config_ptr()->virtual_media_position = 4;
1331         set_screen_size(graphicsView->width(), graphicsView->height());
1332         emit sig_set_orientation_osd(4);
1333         pCentralLayout->removeWidget(driveData);
1334         pCentralLayout->addWidget(driveData, 1, 2);
1335         //emit sig_set_display_osd(false);
1336 #endif
1337 }
1338
1339 void Ui_MainWindowBase::StopEmuThread(void)
1340 {
1341         emit quit_emu_thread();
1342 }
1343
1344 void Ui_MainWindowBase::delete_emu_thread(void)
1345 {
1346         //do_release_emu_resources();
1347         emit sig_quit_all();
1348 }  
1349 // Utility
1350 #include <QTextCodec>
1351 #include <QString>
1352 #include <QByteArray>
1353
1354 void Convert_CP932_to_UTF8(char *dst, char *src, int n_limit, int i_limit)
1355 {
1356         QTextCodec *srcCodec = QTextCodec::codecForName( "SJIS" );
1357         QTextCodec *dstCodec = QTextCodec::codecForName( "UTF-8" );
1358         QString dst_b;
1359         QByteArray dst_s;
1360         if(src == NULL) {
1361                 if(dst != NULL) dst[0] = '\0';
1362                 return;
1363         }
1364         if(dst == NULL) return;
1365         dst_b = srcCodec->toUnicode(src, strlen(src));
1366         dst_s = dstCodec->fromUnicode(dst_b);
1367         if(n_limit > 0) {
1368                 memset(dst, 0x00, n_limit);
1369                 strncpy(dst, dst_s.constData(), n_limit - 1);
1370         }
1371 }
1372
1373 void Ui_MainWindowBase::set_window_title()
1374 {
1375         QString tmps;
1376         tmps = QString::fromUtf8("emu");
1377         tmps = tmps + using_flags->get_config_name();
1378         tmps = tmps + QString::fromUtf8(" (");
1379         tmps = tmps + using_flags->get_device_name();
1380         tmps = tmps + QString::fromUtf8(")");
1381         MainWindow->setWindowTitle(tmps);
1382 }
1383
1384 void Ui_MainWindowBase::do_set_window_title(QString s)
1385 {
1386         QString tmps;
1387         tmps = QString::fromUtf8("emu");
1388         tmps = tmps + using_flags->get_config_name();
1389         tmps = tmps + QString::fromUtf8(" (");
1390         if(!s.isEmpty()) {
1391                 tmps = tmps + s;
1392         }
1393         tmps = tmps + QString::fromUtf8(")");
1394         MainWindow->setWindowTitle(tmps);
1395 }
1396
1397 void Ui_MainWindowBase::do_set_mouse_enable(bool flag)
1398 {
1399 }
1400
1401 void Ui_MainWindowBase::do_toggle_mouse(void)
1402 {
1403 }
1404
1405 void Ui_MainWindowBase::LaunchEmuThread(void)
1406 {
1407 }
1408
1409 void Ui_MainWindowBase::LaunchJoyThread(void)
1410 {
1411 }
1412
1413 void Ui_MainWindowBase::StopJoyThread(void)
1414 {
1415 }
1416
1417 void Ui_MainWindowBase::delete_joy_thread(void)
1418 {
1419 }
1420
1421 void Ui_MainWindowBase::on_actionExit_triggered()
1422 {
1423         OnMainWindowClosed();
1424 }
1425
1426 void Ui_MainWindowBase::OnWindowMove(void)
1427 {
1428 }
1429
1430
1431 void Ui_MainWindowBase::OnWindowRedraw(void)
1432 {
1433 }
1434
1435 bool Ui_MainWindowBase::GetPowerState(void)
1436 {
1437         return true;
1438 }
1439
1440 void Ui_MainWindowBase::OnMainWindowClosed(void)
1441 {
1442 }
1443
1444
1445 void Ui_MainWindowBase::do_release_emu_resources(void)
1446 {
1447 }
1448
1449 void Ui_MainWindowBase::OnOpenDebugger(int no)
1450 {
1451 }
1452
1453 void Ui_MainWindowBase::OnCloseDebugger(void )
1454 {
1455 }
1456
1457 /*
1458  * This is main for Qt.
1459  */
1460 DLL_PREFIX CSP_Logger *csp_logger;
1461