OSDN Git Service

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