OSDN Git Service

[KEYBOARD][UI][Qt][Win32] Set scan codes for Windows.
[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 <QtCore/QVariant>
11 #include <QtGui>
12 #include <QIcon>
13 #include <QImage>
14 #include <QImageReader>
15 #include <QPixmap>
16
17 #include "commonclasses.h"
18 #include "display_about.h"
19 #include "display_text_document.h"
20 #include "mainwidget.h"
21 #include "menuclasses.h"
22 #include "qt_gldraw.h"
23 #include "emu.h"
24 #include "qt_main.h"
25
26
27 extern EMU *emu;
28
29 QT_BEGIN_NAMESPACE
30
31 Ui_MainWindow::Ui_MainWindow(QWidget *parent) : QMainWindow(parent)
32 {
33         setupUi();
34         createContextMenu();
35 }
36
37 Ui_MainWindow::~Ui_MainWindow()
38 {
39 }
40
41 void Action_Control::do_check_grab_mouse(bool flag)
42 {
43         this->toggle();
44 }
45
46 void Action_Control::do_send_string(void)
47 {
48         emit sig_send_string(bindString);
49 }
50
51 void Action_Control::do_set_string(QString s)
52 {
53         bindString = s;
54 }
55
56
57 void Ui_MainWindow::do_show_about(void)
58 {
59         Dlg_AboutCSP *dlg = new Dlg_AboutCSP;
60         dlg->show();
61 }
62
63 void Ui_MainWindow::do_browse_document(QString fname)
64 {
65         Dlg_BrowseText *dlg = new Dlg_BrowseText(fname);
66         dlg->show();
67 }
68
69
70 void Ui_MainWindow::setupUi(void)
71 {
72         int w, h;
73         //   QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
74         MainWindow = new QMainWindow();
75         if (MainWindow->objectName().isEmpty())
76                 MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
77         //MainWindow->resize(1288, 862);
78    
79         ConfigControlMenu();
80         ConfigFloppyMenu();
81         ConfigCMTMenu();
82 #if !defined(WITHOUT_SOUND)     
83         ConfigSoundMenu();
84 #endif  
85 #if defined(USE_BINARY_FILE1)
86         ConfigBinaryMenu(); 
87 #endif
88
89 #if defined(USE_QD1) || defined(USE_QD2)
90         ConfigQuickDiskMenu();
91 #endif
92
93         ConfigScreenMenu();
94 #if defined(USE_CART1) || defined(USE_CART2)
95         ConfigCartMenu();
96 #endif
97         
98         actionAbout = new Action_Control(this);
99         actionAbout->setObjectName(QString::fromUtf8("actionAbout"));
100
101    
102         graphicsView = new GLDrawClass(this);
103         graphicsView->setObjectName(QString::fromUtf8("graphicsView"));
104         graphicsView->setMaximumSize(2560, 2560); // ?
105         graphicsView->setMinimumSize(240, 192); // ?
106 //#if defined(Q_OS_WIN) || defined(Q_OS_CYGWIN)
107         this->setFocusProxy(graphicsView);
108         graphicsView->setAttribute(Qt::WA_InputMethodEnabled, false); // Disable [Zenkaku / Hankaku] with IM.
109         //graphicsView->setAttribute(Qt::WA_KeyboardFocusChange, false); 
110
111    
112 #if defined(USE_BITMAP)
113         bitmapImage = NULL;
114 #endif   
115         MainWindow->setCentralWidget(graphicsView);
116         
117         MainWindow->centralWidget()->adjustSize();
118         MainWindow->adjustSize();
119         //MainWindow->setAttribute(Qt::WA_InputMethodEnabled, false); // Disable [Zenkaku / Hankaku] with IM.
120
121         statusbar = new QStatusBar(this);
122         statusbar->setObjectName(QString::fromUtf8("statusbar"));
123         MainWindow->setStatusBar(statusbar);
124         initStatusBar();
125         
126         menubar = new QMenuBar(this);
127         menubar->setObjectName(QString::fromUtf8("menubar"));
128         menubar->setGeometry(QRect(0, 0, 1288, 27));
129         menuControl = new QMenu(menubar);
130         menuControl->setObjectName(QString::fromUtf8("menuControl"));
131         menuState = new QMenu(menuControl);
132         menuState->setObjectName(QString::fromUtf8("menuState"));
133         menuCopy_Paste = new QMenu(menuControl);
134         menuCopy_Paste->setObjectName(QString::fromUtf8("menuCopy_Paste"));
135         menuCpu_Speed = new QMenu(menuControl);
136         menuCpu_Speed->setObjectName(QString::fromUtf8("menuCpu_Speed"));
137         menuDebugger = new QMenu(menuControl);
138         menuDebugger->setObjectName(QString::fromUtf8("menuDebugger"));
139 #ifdef USE_FD1  
140         CreateFloppyMenu(0, 1);
141 #endif
142 #ifdef USE_FD2  
143         CreateFloppyMenu(1, 2);
144 #endif
145 #ifdef USE_FD3  
146         CreateFloppyMenu(2, 3);
147 #endif
148 #ifdef USE_FD4  
149         CreateFloppyMenu(3, 4);
150 #endif
151 #ifdef USE_FD5  
152         CreateFloppyMenu(4, 5);
153 #endif
154 #ifdef USE_FD6  
155         CreateFloppyMenu(5, 6);
156 #endif
157 #ifdef USE_FD7  
158         CreateFloppyMenu(6, 7);
159 #endif
160 #ifdef USE_FD8  
161         CreateFloppyMenu(7, 8);
162 #endif
163
164 #if defined(USE_QD1)
165         CreateQuickDiskMenu(0, 1);
166 #endif
167 #if defined(USE_QD2)
168         CreateQuickDiskMenu(1, 2);
169 #endif
170 #ifdef USE_TAPE
171         CreateCMTMenu();
172 #endif
173
174         CreateScreenMenu();
175 #if defined(USE_CART1)
176         CreateCartMenu(0, 1);
177 #endif
178 #if defined(USE_CART2)
179         CreateCartMenu(1, 2);
180 #endif
181 #if defined(USE_BINARY_FILE1)
182         CreateBinaryMenu(0, 1);
183 #endif
184 #if defined(USE_BINARY_FILE2)
185         CreateBinaryMenu(1, 2);
186 #endif
187         
188         menuMachine = new QMenu(menubar);
189         menuMachine->setObjectName(QString::fromUtf8("menuMachine"));
190         actionMouseEnable = new Action_Control(this);
191         actionMouseEnable->setCheckable(true);
192         actionMouseEnable->setVisible(true);
193         actionMouseEnable->setChecked(false);
194         menuMachine->addAction(actionMouseEnable);
195         connect(actionMouseEnable, SIGNAL(toggled(bool)),
196                 this, SLOT(do_set_mouse_enable(bool)));
197         connect(graphicsView, SIGNAL(sig_check_grab_mouse(bool)),
198                 actionMouseEnable, SLOT(do_check_grab_mouse(bool)));
199         
200         ConfigDeviceType();
201         ConfigDriveType();
202         ConfigSoundDeviceType();
203
204 #if !defined(WITHOUT_SOUND)     
205         menuSound = new QMenu(menubar);
206         menuSound->setObjectName(QString::fromUtf8("menuSound"));
207 #endif
208         menuEmulator = new QMenu(menubar);
209         menuEmulator->setObjectName(QString::fromUtf8("menuEmulator"));
210         menuHELP = new QMenu(menubar);
211         menuHELP->setObjectName(QString::fromUtf8("menuHELP"));
212         MainWindow->setMenuBar(menubar);
213
214         menubar->addAction(menuControl->menuAction());
215         connectActions_ControlMenu();
216 #if defined(USE_FD1)
217         menubar->addAction(menuFD[0]->menuAction());
218 #endif
219 #if defined(USE_FD2)
220         menubar->addAction(menuFD[1]->menuAction());
221 #endif
222 #if defined(USE_FD3)
223         menubar->addAction(menuFD[2]->menuAction());
224 #endif
225 #if defined(USE_FD4)
226         menubar->addAction(menuFD[3]->menuAction());
227 #endif
228 #if defined(USE_FD5)
229         menubar->addAction(menuFD[4]->menuAction());
230 #endif
231 #if defined(USE_FD6)
232         menubar->addAction(menuFD[5]->menuAction());
233 #endif
234 #if defined(USE_FD7)
235         menubar->addAction(menuFD[6]->menuAction());
236 #endif
237 #if defined(USE_FD8)
238         menubar->addAction(menuFD[7]->menuAction());
239 #endif
240 #if defined(USE_QD1)
241         menubar->addAction(menuQD[0]->menuAction());
242 #endif
243 #if defined(USE_QD2)
244         menubar->addAction(menuQD[1]->menuAction());
245 #endif
246 #if defined(USE_TAPE)
247         menubar->addAction(menuCMT->menuAction());
248 #endif
249 #if defined(USE_CART1)
250         menubar->addAction(menuCART[0]->menuAction());
251 #endif
252 #if defined(USE_CART2)
253         menubar->addAction(menuCART[1]->menuAction());
254 #endif
255 #if defined(USE_BINARY_FILE1)
256         menubar->addAction(menuBIN[0]->menuAction());
257 #endif
258 #if defined(USE_BINARY_FILE2)
259         menubar->addAction(menuBIN[1]->menuAction());
260 #endif
261         menubar->addAction(menuMachine->menuAction());
262         
263 #if !defined(WITHOUT_SOUND)     
264         menubar->addAction(menuSound->menuAction());
265 #endif   
266         menubar->addAction(menuScreen->menuAction());
267 //      menubar->addAction(menuRecord->menuAction());
268         menubar->addAction(menuEmulator->menuAction());
269         menubar->addAction(menuHELP->menuAction());
270 #if defined(USE_FD1)
271         CreateFloppyPulldownMenu(0);
272 #endif
273 #if defined(USE_FD2)
274         CreateFloppyPulldownMenu(1);
275 #endif
276 #if defined(USE_FD3)
277         CreateFloppyPulldownMenu(2);
278 #endif
279 #if defined(USE_FD4)
280         CreateFloppyPulldownMenu(3);
281 #endif
282 #if defined(USE_FD5)
283         CreateFloppyPulldownMenu(4);
284 #endif
285 #if defined(USE_FD6)
286         CreateFloppyPulldownMenu(5);
287 #endif
288 #if defined(USE_FD7)
289         CreateFloppyPulldownMenu(6);
290 #endif
291 #if defined(USE_FD8)
292         CreateFloppyPulldownMenu(7);
293 #endif
294 #ifdef USE_TAPE
295         CreateCMTPulldownMenu();
296 #endif
297 #if defined(USE_QD1)
298         CreateQuickDiskPulldownMenu(0);
299 #endif
300 #if defined(USE_QD2)
301         CreateQuickDiskPulldownMenu(1);
302 #endif
303 #if defined(USE_CART1)
304         CreateCartPulldownMenu(0);
305 #endif
306 #if defined(USE_CART2)
307         CreateCartPulldownMenu(1);
308 #endif
309 #if defined(USE_BINARY_FILE1)
310         CreateBinaryPulldownMenu(0);
311 #endif
312 #if defined(USE_BINARY_FILE2)
313         CreateBinaryPulldownMenu(1);
314 #endif
315 #if !defined(WITHOUT_SOUND)     
316         CreateSoundMenu();
317 #endif
318   
319         menuHELP->addAction(actionAbout);
320         connect(actionAbout, SIGNAL(triggered()), this, SLOT(do_show_about()));
321         menuHELP->addSeparator();
322         
323         actionHelp_AboutQt = new Action_Control(this);
324         actionHelp_AboutQt->setObjectName(QString::fromUtf8("menuHelp_AboutQt"));
325         menuHELP->addAction(actionHelp_AboutQt);
326         menuHELP->addSeparator();
327         menuHelp_Readme = new QMenu(menuHELP);
328         menuHelp_Readme->setObjectName(QString::fromUtf8("menuHelp_Readme_menu"));;
329         menuHELP->addAction(menuHelp_Readme->menuAction());
330
331         actionHelp_README = new Action_Control(this);
332         actionHelp_README->setObjectName(QString::fromUtf8("menuHelp_README"));
333         actionHelp_README->do_set_string(QString::fromUtf8("readme.txt"));
334         connect(actionHelp_README, SIGNAL(triggered()), actionHelp_README, SLOT(do_send_string()));
335         connect(actionHelp_README, SIGNAL(sig_send_string(QString)), this, SLOT(do_browse_document(QString)));
336         menuHelp_Readme->addAction(actionHelp_README);
337         
338         actionHelp_README_QT = new Action_Control(this);
339         actionHelp_README_QT->setObjectName(QString::fromUtf8("menuHelp_README_QT"));
340         actionHelp_README_QT->do_set_string(QString::fromUtf8("readme.qt.txt"));
341         menuHelp_Readme->addAction(actionHelp_README_QT);
342         connect(actionHelp_README_QT, SIGNAL(triggered()), actionHelp_README_QT, SLOT(do_send_string()));
343         connect(actionHelp_README_QT, SIGNAL(sig_send_string(QString)), this, SLOT(do_browse_document(QString)));
344         actionHelp_README_Artane = new Action_Control(this);
345         actionHelp_README_Artane->setObjectName(QString::fromUtf8("menuHelp_README_Artane"));
346         actionHelp_README_Artane->do_set_string(QString::fromUtf8("readme_by_artane.txt"));
347         connect(actionHelp_README_Artane, SIGNAL(triggered()), actionHelp_README_Artane, SLOT(do_send_string()));
348         connect(actionHelp_README_Artane, SIGNAL(sig_send_string(QString)), this, SLOT(do_browse_document(QString)));
349         menuHelp_Readme->addAction(actionHelp_README_Artane);
350         menuHelp_Readme->addSeparator();
351         
352         actionHelp_README_MR_TANAM = new Action_Control(this);
353         actionHelp_README_MR_TANAM->setObjectName(QString::fromUtf8("menuHelp_README_MR_TANAM"));
354         actionHelp_README_MR_TANAM->do_set_string(QString::fromUtf8("readme_by_mr_tanam.txt"));
355         connect(actionHelp_README_MR_TANAM, SIGNAL(triggered()), actionHelp_README_MR_TANAM, SLOT(do_send_string()));
356         connect(actionHelp_README_MR_TANAM, SIGNAL(sig_send_string(QString)), this, SLOT(do_browse_document(QString)));
357         menuHelp_Readme->addAction(actionHelp_README_MR_TANAM);
358         
359         menuHelp_Readme->addSeparator();
360         
361         actionHelp_README_FM7 = new Action_Control(this);
362         actionHelp_README_FM7->setObjectName(QString::fromUtf8("menuHelp_README_FM7"));
363         actionHelp_README_FM7->do_set_string(QString::fromUtf8("readme_fm7.txt"));
364         connect(actionHelp_README_FM7, SIGNAL(triggered()), actionHelp_README_FM7, SLOT(do_send_string()));
365         connect(actionHelp_README_FM7, SIGNAL(sig_send_string(QString)), this, SLOT(do_browse_document(QString)));
366         menuHelp_Readme->addAction(actionHelp_README_FM7);
367         
368         actionHelp_README_FM7_JP = new Action_Control(this);
369         actionHelp_README_FM7_JP->setObjectName(QString::fromUtf8("menuHelp_README_FM7_JP"));
370         actionHelp_README_FM7_JP->do_set_string(QString::fromUtf8("readme_fm7.jp.txt"));
371         connect(actionHelp_README_FM7_JP, SIGNAL(triggered()), actionHelp_README_FM7_JP, SLOT(do_send_string()));
372         connect(actionHelp_README_FM7_JP, SIGNAL(sig_send_string(QString)), this, SLOT(do_browse_document(QString)));
373         menuHelp_Readme->addAction(actionHelp_README_FM7_JP);
374
375         menuHelp_Histories = new QMenu(menuHELP);
376         menuHelp_Histories->setObjectName(QString::fromUtf8("menuHelp_Histories"));;
377         menuHELP->addAction(menuHelp_Histories->menuAction());
378
379         actionHelp_History = new Action_Control(this);
380         actionHelp_History->setObjectName(QString::fromUtf8("menuHelp_History"));
381         actionHelp_History->do_set_string(QString::fromUtf8("history.txt"));
382         connect(actionHelp_History, SIGNAL(triggered()), actionHelp_History, SLOT(do_send_string()));
383         connect(actionHelp_History, SIGNAL(sig_send_string(QString)), this, SLOT(do_browse_document(QString)));
384         menuHelp_Histories->addAction(actionHelp_History);
385         
386         actionHelp_History_Relnote = new Action_Control(this);
387         actionHelp_History_Relnote->setObjectName(QString::fromUtf8("menuHelp_History_Relnote"));
388         actionHelp_History_Relnote->do_set_string(QString::fromUtf8("RELEASENOTE.txt"));
389         connect(actionHelp_History_Relnote, SIGNAL(triggered()), actionHelp_History_Relnote, SLOT(do_send_string()));
390         connect(actionHelp_History_Relnote, SIGNAL(sig_send_string(QString)), this, SLOT(do_browse_document(QString)));
391         menuHelp_Histories->addAction(actionHelp_History_Relnote);
392         
393         actionHelp_History_ChangeLog = new Action_Control(this);
394         actionHelp_History_ChangeLog->setObjectName(QString::fromUtf8("menuHelp_History_ChangeLog"));
395         actionHelp_History_ChangeLog->do_set_string(QString::fromUtf8("ChangeLog.txt"));
396         connect(actionHelp_History_ChangeLog, SIGNAL(triggered()), actionHelp_History_ChangeLog, SLOT(do_send_string()));
397         connect(actionHelp_History_ChangeLog, SIGNAL(sig_send_string(QString)), this, SLOT(do_browse_document(QString)));
398         menuHelp_Histories->addAction(actionHelp_History_ChangeLog);
399
400         actionHelp_History_MR_TANAM = new Action_Control(this);
401         actionHelp_History_MR_TANAM->setObjectName(QString::fromUtf8("menuHelp_History_MR_TANAM"));
402         actionHelp_History_MR_TANAM->do_set_string(QString::fromUtf8("history_by_mr_tanam.txt"));
403         connect(actionHelp_History_MR_TANAM, SIGNAL(triggered()), actionHelp_History_MR_TANAM, SLOT(do_send_string()));
404         connect(actionHelp_History_MR_TANAM, SIGNAL(sig_send_string(QString)), this, SLOT(do_browse_document(QString)));
405         menuHelp_Histories->addAction(actionHelp_History_MR_TANAM);
406         
407         actionHelp_License = new Action_Control(this);
408         actionHelp_License->setObjectName(QString::fromUtf8("menuHelp_License"));
409         actionHelp_License->do_set_string(QString::fromUtf8("LICENSE.txt"));
410         connect(actionHelp_License, SIGNAL(triggered()), actionHelp_License, SLOT(do_send_string()));
411         connect(actionHelp_License, SIGNAL(sig_send_string(QString)), this, SLOT(do_browse_document(QString)));
412         menuHELP->addAction(actionHelp_License);
413         
414         actionHelp_License_JP = new Action_Control(this);
415         actionHelp_License_JP->setObjectName(QString::fromUtf8("menuHelp_License_JP"));
416         actionHelp_License_JP->do_set_string(QString::fromUtf8("LICENSE.ja.txt"));
417         connect(actionHelp_License_JP, SIGNAL(triggered()), actionHelp_License_JP, SLOT(do_send_string()));
418         connect(actionHelp_License_JP, SIGNAL(sig_send_string(QString)), this, SLOT(do_browse_document(QString)));
419         menuHELP->addAction(actionHelp_License_JP);
420         
421         if(config.window_mode <= 0) config.window_mode = 0;
422         if(config.window_mode >= _SCREEN_MODE_NUM) config.window_mode = _SCREEN_MODE_NUM - 1;
423         w = SCREEN_WIDTH;
424         h = SCREEN_HEIGHT;
425         if(actionScreenSize[config.window_mode] != NULL) {
426                 double nd = actionScreenSize[config.window_mode]->binds->getDoubleValue();
427                 w = (int)(nd * (double)w);
428                 h = (int)(nd * (double)h);
429 #if defined(USE_SCREEN_ROTATE)
430                 if(config.rotate_type) {
431                         int tmp_w = w;
432                         w = h;
433                         h = tmp_w;
434                 }
435 #endif     
436         } else {
437 #if defined(USE_SCREEN_ROTATE)
438                 if(config.rotate_type) {
439                         w = 600;
440                         h = 960;
441                 } else 
442 #endif
443                 {                  
444                         w = 1280;
445                         h = 800;
446                 }
447         }
448         graphicsView->setFixedSize(w, h);
449         this->set_screen_size(w, h);
450         this->set_screen_aspect(config.stretch_type);
451         QImageReader reader(":/default.ico");
452         QImage result = reader.read();
453         MainWindow->setWindowIcon(QPixmap::fromImage(result));
454         QMetaObject::connectSlotsByName(MainWindow);
455 } // setupUi
456
457
458 void Ui_MainWindow::retranslateUI_Help(void)
459 {
460         menuHELP->setTitle(QApplication::translate("MainWindow", "HELP", 0));
461         actionHelp_AboutQt->setText(QApplication::translate("MainWindow", "About Qt", 0));
462         actionAbout->setText(QApplication::translate("MainWindow", "About...", 0));
463
464         menuHelp_Readme->setTitle(QApplication::translate("MainWindow", "READMEs", 0));
465         
466         actionHelp_README->setText(QApplication::translate("MainWindow", "General Document", 0));
467         actionHelp_README_QT->setText(QApplication::translate("MainWindow", "About Qt ports", 0));
468         actionHelp_README_Artane->setText(QApplication::translate("MainWindow", "About Qt ports (Japanese).", 0));
469         actionHelp_README_MR_TANAM->setText(QApplication::translate("MainWindow", "By Mr. tanam", 0));
470         actionHelp_README_FM7->setText(QApplication::translate("MainWindow", "About eFM-7/8/77/AV.", 0));
471         actionHelp_README_FM7_JP->setText(QApplication::translate("MainWindow", "About eFM-7/8/77/AV (Japanese).", 0));
472
473         menuHelp_Histories->setTitle(QApplication::translate("MainWindow", "Histories", 0));
474         actionHelp_History->setText(QApplication::translate("MainWindow", "General History", 0));
475         actionHelp_History_Relnote->setText(QApplication::translate("MainWindow", "Release Note", 0));
476         actionHelp_History_ChangeLog->setText(QApplication::translate("MainWindow", "Change Log", 0));
477         actionHelp_History_MR_TANAM->setText(QApplication::translate("MainWindow", "History by Tanam", 0));
478
479         actionHelp_License->setText(QApplication::translate("MainWindow", "Show License", 0));
480         actionHelp_License_JP->setText(QApplication::translate("MainWindow", "Show License (Japanese)", 0));
481         
482 }
483
484 // You can Override this function: Re-define on foo/MainWindow.cpp.
485 // This code is example: by X1(TurboZ).
486 void Ui_MainWindow::retranslateUi(void)
487 {
488         retranslateControlMenu("NMI Reset",  true);
489         retranslateFloppyMenu(0, 0);
490         retranslateFloppyMenu(1, 1);
491         retranslateCMTMenu();
492 #if !defined(WITHOUT_SOUND)     
493         retranslateSoundMenu();
494 #endif   
495         retranslateScreenMenu();
496         retranslateCartMenu(0, 1);
497         retranslateCartMenu(1, 2);
498         retranslateBinaryMenu(0, 1);
499         retranslateBinaryMenu(1, 2);
500         retranslateUI_Help();
501    
502         this->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0));
503
504
505         menuEmulator->setTitle(QApplication::translate("MainWindow", "Emulator", 0));
506         menuMachine->setTitle(QApplication::translate("MainWindow", "Machine", 0));
507 } // retranslateUi
508
509 void Ui_MainWindow::setCoreApplication(QApplication *p)
510 {
511         this->CoreApplication = p;
512         connect(actionExit_Emulator, SIGNAL(triggered()),
513                         this->CoreApplication, SLOT(closeAllWindows())); // OnGuiExit()?  
514         connect(actionHelp_AboutQt, SIGNAL(triggered()),
515                         this->CoreApplication, SLOT(aboutQt()));
516         
517 }
518 QT_END_NAMESPACE