OSDN Git Service

[UI][Qt] Fix unconnected event.
[csp-qt/common_source_project-fm7.git] / source / src / qt / gui / menu_control.cpp
1 /*
2  * Common Source Project/ Qt
3  * (C) 2015 K.Ohta <whatisthis.sowhat _at_ gmail.com>
4  *  History: Jan 10, 2015 : Initial
5  */
6
7 #include <QString>
8 #include <QMenu>
9 #include <QStyle>
10
11 #include "commonclasses.h"
12 #include "mainwidget_base.h"
13 #include "menu_flags.h"
14
15 //extern USING_FLAGS *using_flags;
16
17 void Object_Menu_Control::set_boot_mode(void) {
18         emit on_boot_mode(bindValue);
19 }
20    
21 void Object_Menu_Control::set_cpu_type(void) {
22         emit on_cpu_type(bindValue);
23 }
24 void Object_Menu_Control::set_cpupower(void) {
25         emit on_cpu_power(bindValue);
26 }
27 void Object_Menu_Control::open_debugger(void) {
28         emit on_open_debugger(bindValue);
29 }
30 void Object_Menu_Control::do_set_device_type(void){
31         emit sig_device_type(this->getValue1());
32 }
33 void Object_Menu_Control::do_set_printer_device(void){
34         emit sig_printer_device(this->getValue1());
35 }
36 void Object_Menu_Control::do_set_sound_device(void){
37         emit sig_sound_device(this->getValue1());
38 }
39 void Object_Menu_Control::do_set_drive_type(void)
40 {
41         emit sig_drive_type(getValue1());
42 }
43
44 void Action_Control::do_load_state(void)
45 {
46         emit sig_load_state(binds->getStringValue());
47 }
48
49 void Action_Control::do_save_state(void)
50 {
51         emit sig_save_state(binds->getStringValue());
52 }
53
54 void Ui_MainWindowBase::ConfigCpuSpeed(void)
55 {
56         actionSpeed_x1 = new Action_Control(this, using_flags);
57         actionSpeed_x1->setObjectName(QString::fromUtf8("actionSpeed_x1"));
58         actionSpeed_x1->setCheckable(true);
59         actionSpeed_x1->setChecked(true);
60         actionSpeed_x1->binds->setValue1(0);
61         connect(actionSpeed_x1, SIGNAL(triggered()), actionSpeed_x1->binds, SLOT(set_cpupower())); // OK?  
62         connect(actionSpeed_x1->binds, SIGNAL(on_cpu_power(int)), this, SLOT(set_cpu_power(int))); // OK?  
63   
64         actionSpeed_x2 = new Action_Control(this, using_flags);
65         actionSpeed_x2->setObjectName(QString::fromUtf8("actionSpeed_x2"));
66         actionSpeed_x2->setCheckable(true);
67         actionSpeed_x2->binds->setValue1(1);
68         connect(actionSpeed_x2, SIGNAL(triggered()), actionSpeed_x2->binds, SLOT(set_cpupower())); // OK?  
69         connect(actionSpeed_x2->binds, SIGNAL(on_cpu_power(int)), this, SLOT(set_cpu_power(int))); // OK?  
70   
71         actionSpeed_x4 = new Action_Control(this, using_flags);
72         actionSpeed_x4->setObjectName(QString::fromUtf8("actionSpeed_x4"));
73         actionSpeed_x4->setCheckable(true);
74         actionSpeed_x4->binds->setValue1(2);
75         connect(actionSpeed_x4, SIGNAL(triggered()), actionSpeed_x4->binds, SLOT(set_cpupower())); // OK?  
76         connect(actionSpeed_x4->binds, SIGNAL(on_cpu_power(int)), this, SLOT(set_cpu_power(int))); // OK?  
77   
78         actionSpeed_x8 = new Action_Control(this, using_flags);
79         actionSpeed_x8->setObjectName(QString::fromUtf8("actionSpeed_x8"));
80         actionSpeed_x8->setCheckable(true);
81         actionSpeed_x8->binds->setValue1(3);
82         connect(actionSpeed_x8, SIGNAL(triggered()), actionSpeed_x8->binds, SLOT(set_cpupower())); // OK?  
83         connect(actionSpeed_x8->binds, SIGNAL(on_cpu_power(int)), this, SLOT(set_cpu_power(int))); // OK?  
84   
85         actionSpeed_x16 = new Action_Control(this, using_flags);
86         actionSpeed_x16->setObjectName(QString::fromUtf8("actionSpeed_x16"));
87         actionSpeed_x16->setCheckable(true);
88         actionSpeed_x16->binds->setValue1(4);
89         connect(actionSpeed_x16, SIGNAL(triggered()), actionSpeed_x16->binds, SLOT(set_cpupower())); // OK?  
90         connect(actionSpeed_x16->binds, SIGNAL(on_cpu_power(int)), this, SLOT(set_cpu_power(int))); // OK?  
91
92         actionGroup_CpuSpeed = new QActionGroup(this);
93         actionGroup_CpuSpeed->setExclusive(true);
94         actionGroup_CpuSpeed->addAction(actionSpeed_x1);
95         actionGroup_CpuSpeed->addAction(actionSpeed_x2);
96         actionGroup_CpuSpeed->addAction(actionSpeed_x4);
97         actionGroup_CpuSpeed->addAction(actionSpeed_x8);
98         actionGroup_CpuSpeed->addAction(actionSpeed_x16);
99 }
100 void Ui_MainWindowBase::do_change_boot_mode(int mode)
101 {
102         if((mode < 0) || (mode >= 8)) return;
103         using_flags->get_config_ptr()->boot_mode = mode;
104         emit sig_emu_update_config();
105 }
106
107
108
109 void Ui_MainWindowBase::ConfigCPUBootMode(int num)
110 {
111         int i;
112         QString tmps;
113         if(num <= 0) return;
114         if(num >= 8) num = 7;
115   
116         actionGroup_BootMode = new QActionGroup(this);
117         actionGroup_BootMode->setExclusive(true);
118         for(i = 0; i < num; i++) {
119                 actionBootMode[i] = new Action_Control(this, using_flags);
120                 tmps = tmps.setNum(i);
121                 tmps = QString::fromUtf8("actionBootMode_") + tmps;
122                 actionBootMode[i]->setObjectName(tmps);
123                 actionBootMode[i]->setCheckable(true);
124                 if(i == using_flags->get_config_ptr()->boot_mode) actionBootMode[i]->setChecked(true);
125                 actionBootMode[i]->binds->setValue1(i);
126                 menuBootMode->addAction(actionBootMode[i]);
127                 actionGroup_BootMode->addAction(actionBootMode[i]);
128                 connect(actionBootMode[i], SIGNAL(triggered()), actionBootMode[i]->binds, SLOT(set_boot_mode())); // OK?  
129                 connect(actionBootMode[i]->binds, SIGNAL(on_boot_mode(int)), this, SLOT(do_change_boot_mode(int))); // OK?  
130         }
131 }
132
133 void Ui_MainWindowBase::do_change_cpu_type(int mode)
134 {
135         if((mode < 0) || (mode >= 8)) return;
136         using_flags->get_config_ptr()->cpu_type = mode;
137         emit sig_emu_update_config();
138 }
139
140 void Ui_MainWindowBase::ConfigCPUTypes(int num)
141 {
142         int i;
143         QString tmps;
144         if(num <= 0) return;
145         if(num >= 8) num = 7;
146    
147         actionGroup_CpuType = new QActionGroup(this);
148         actionGroup_CpuType->setExclusive(true);
149         for(i = 0; i < num; i++) {
150                 actionCpuType[i] = new Action_Control(this, using_flags);
151                 tmps = tmps.setNum(i);
152                 tmps = QString::fromUtf8("actionCpuType_") + tmps;
153                 actionCpuType[i]->setObjectName(tmps);
154                 actionCpuType[i]->setCheckable(true);
155                 if(i == using_flags->get_config_ptr()->cpu_type) actionCpuType[i]->setChecked(true);
156                 actionCpuType[i]->binds->setValue1(i);
157                 menuCpuType->addAction(actionCpuType[i]);
158                 actionGroup_CpuType->addAction(actionCpuType[i]);
159                 connect(actionCpuType[i], SIGNAL(triggered()), actionCpuType[i]->binds, SLOT(set_cpu_type())); // OK?  
160                 connect(actionCpuType[i]->binds, SIGNAL(on_cpu_type(int)), this, SLOT(do_change_cpu_type(int))); // OK?  
161         }
162 }
163
164 void Ui_MainWindowBase::ConfigControlMenu(void)
165 {
166         int i;
167         actionReset = new Action_Control(this, using_flags);
168         actionReset->setObjectName(QString::fromUtf8("actionReset"));
169         connect(actionReset, SIGNAL(triggered()),
170                 this, SLOT(OnReset())); // OK?  
171         if(using_flags->is_use_special_reset()) {
172                 actionSpecial_Reset = new Action_Control(this, using_flags);
173                 actionSpecial_Reset->setObjectName(QString::fromUtf8("actionSpecial_Reset"));
174                 connect(actionSpecial_Reset, SIGNAL(triggered()),
175                                 this, SLOT(OnSpecialReset())); // OK?
176         }
177
178         actionExit_Emulator = new Action_Control(this, using_flags);
179         actionExit_Emulator->setObjectName(QString::fromUtf8("actionExit_Emulator"));
180         //connect(actionExit_Emulator, SIGNAL(triggered()),
181         //      this, SLOT(on_actionExit_triggered())); // OnGuiExit()?  
182
183         if(using_flags->is_use_auto_key()) {
184                 actionPaste_from_Clipboard = new Action_Control(this, using_flags);
185                 actionPaste_from_Clipboard->setObjectName(QString::fromUtf8("actionPaste_from_Clipboard"));
186                 connect(actionPaste_from_Clipboard, SIGNAL(triggered()),
187                                 this, SLOT(OnStartAutoKey())); // OK?  
188                 actionStop_Pasting = new Action_Control(this, using_flags);
189                 actionStop_Pasting->setObjectName(QString::fromUtf8("actionStop_Pasting"));
190                 connect(actionStop_Pasting, SIGNAL(triggered()),
191                                 this, SLOT(OnStopAutoKey())); // OK?
192         }
193         if(using_flags->is_use_state()) {
194                 for(i = 0; i < 10; i++) {
195                         QString tmps;
196                         QString tmpss;
197                         _TCHAR tmpbuf[_MAX_PATH];
198                         actionSave_State[i] = new Action_Control(this, using_flags);
199
200                         strncpy(tmpbuf, create_local_path(_T("%s.sta%d"), using_flags->get_config_name().toLocal8Bit().constData(), i), _MAX_PATH);
201                                 
202                         tmps = QString::fromUtf8("");
203                         tmpss = QString::fromUtf8("");
204                         tmpss.setNum(i);
205                         tmps = QString::fromUtf8("actionSave_State") + tmpss;
206                         actionSave_State[i]->setObjectName(tmps);
207                         actionLoad_State[i] = new Action_Control(this, using_flags);
208                         tmps = QString::fromUtf8("actionLoad_State") + tmpss;
209                         actionLoad_State[i]->setObjectName(tmps);
210                         tmps = QString::fromLocal8Bit(tmpbuf);
211                         actionSave_State[i]->binds->setStringValue(tmps);
212                         actionLoad_State[i]->binds->setStringValue(tmps);
213                                 
214                 
215                         connect(actionLoad_State[i], SIGNAL(triggered()),
216                                         actionLoad_State[i], SLOT(do_load_state())); // OK?
217                         connect(actionSave_State[i], SIGNAL(triggered()),
218                                         actionSave_State[i], SLOT(do_save_state())); // OK?
219                         
220                 }
221         }
222         if(using_flags->is_use_debugger()) {
223                 for(i = 0; i < _MAX_DEBUGGER; i++) {
224                         QString tmps;
225                         tmps.setNum(i);
226                         actionDebugger[i] = new Action_Control(this, using_flags);
227                         actionDebugger[i]->setObjectName(QString::fromUtf8("actionDebugger") + tmps);
228                         actionDebugger[i]->binds->setValue1(i);
229                         connect(actionDebugger[i], SIGNAL(triggered()),
230                                         actionDebugger[i]->binds, SLOT(open_debugger())); // OK?  
231                         connect(actionDebugger[i]->binds, SIGNAL(on_open_debugger(int)),
232                                         this, SLOT(OnOpenDebugger(int))); // OK?
233                 }
234         }
235         ConfigCpuSpeed();
236 }
237
238 void Ui_MainWindowBase::connectActions_ControlMenu(void)
239 {
240         menuControl->addAction(actionReset);
241         if(using_flags->is_use_special_reset()) {
242                 menuControl->addAction(actionSpecial_Reset);
243         }
244         menuControl->addSeparator();
245         menuControl->addAction(menuCpu_Speed->menuAction());
246
247         if(using_flags->is_use_auto_key()) {
248                 menuControl->addSeparator();
249                 menuControl->addAction(menuCopy_Paste->menuAction());
250         }
251         menuControl->addSeparator();
252         menuControl->addAction(menuState->menuAction());
253
254         if(using_flags->is_use_debugger()) {
255                 menuControl->addAction(menuDebugger->menuAction());
256         }
257         menuControl->addSeparator();
258         menuControl->addAction(actionExit_Emulator);
259
260         if(using_flags->is_use_state()) {
261                 for(int i = 0; i < 10; i++) {
262                         menuLoad_State->addAction(actionLoad_State[i]);
263                         menuSave_State->addAction(actionSave_State[i]);
264                 }
265                 menuState->addAction(menuSave_State->menuAction());
266                 menuState->addSeparator();
267                 menuState->addAction(menuLoad_State->menuAction());
268         }
269
270         if(using_flags->is_use_auto_key()) {
271                 menuCopy_Paste->addAction(actionPaste_from_Clipboard);
272                 menuCopy_Paste->addAction(actionStop_Pasting);
273         }
274         menuCpu_Speed->addAction(actionSpeed_x1);
275         menuCpu_Speed->addAction(actionSpeed_x2);
276         menuCpu_Speed->addAction(actionSpeed_x4);
277         menuCpu_Speed->addAction(actionSpeed_x8);
278         menuCpu_Speed->addAction(actionSpeed_x16);
279         
280         if(using_flags->is_use_debugger()) {
281                 int i;
282                 for(i = 0; i < _MAX_DEBUGGER; i++) {
283                         menuDebugger->addAction(actionDebugger[i]);
284                         if(i > 0) actionDebugger[i]->setVisible(false);
285                 }
286         }
287 }
288
289 void Ui_MainWindowBase::createContextMenu(void)
290 {
291         addAction(actionReset);
292
293         if(using_flags->is_use_special_reset()) {
294                 addAction(actionSpecial_Reset);
295         }
296         addAction(menuCpu_Speed->menuAction());
297
298         if(using_flags->is_use_auto_key()) {
299                 addAction(menuCopy_Paste->menuAction());
300         }
301         addAction(menuState->menuAction());
302
303         if(using_flags->is_use_debugger()) {
304                 addAction(menuDebugger->menuAction());
305         }
306         addAction(actionExit_Emulator);
307 }
308
309
310 void Ui_MainWindowBase::retranslateControlMenu(const char *SpecialResetTitle,  bool WithSpecialReset)
311 {
312         actionReset->setText(QApplication::translate("MainWindow", "Reset", 0));
313         actionReset->setToolTip(QApplication::translate("MainWindow", "Reset virtual machine.", 0));
314         actionReset->setIcon(ResetIcon);
315         if(using_flags->is_use_special_reset()) {
316                 actionSpecial_Reset->setText(QApplication::translate("MainWindow", SpecialResetTitle, 0));
317                 actionSpecial_Reset->setIcon(QIcon(":/icon_reset.png"));
318         }
319
320         actionExit_Emulator->setText(QApplication::translate("MainWindow", "Exit Emulator", 0));
321         actionExit_Emulator->setToolTip(QApplication::translate("MainWindow", "Exit emulator.\n**WARN: WITHOUT confirming.**", 0));
322         actionExit_Emulator->setIcon(ExitIcon);
323
324         actionSpeed_x1->setText(QApplication::translate("MainWindow", "Speed x1", 0));
325         actionSpeed_x2->setText(QApplication::translate("MainWindow", "Speed x2", 0));
326         actionSpeed_x4->setText(QApplication::translate("MainWindow", "Speed x4", 0));
327         actionSpeed_x8->setText(QApplication::translate("MainWindow", "Speed x8", 0));
328         actionSpeed_x16->setText(QApplication::translate("MainWindow", "Speed x16", 0));
329         
330         if(using_flags->is_use_auto_key()) {
331                 actionPaste_from_Clipboard->setText(QApplication::translate("MainWindow", "Paste from Clipboard", 0));
332                 actionPaste_from_Clipboard->setToolTip(QApplication::translate("MainWindow", "Paste ANK text to virtual machine from desktop's clop board.", 0));
333                 actionPaste_from_Clipboard->setIcon(QIcon(":/icon_paste.png"));
334                 actionStop_Pasting->setText(QApplication::translate("MainWindow", "Stop Pasting", 0));
335                 actionStop_Pasting->setToolTip(QApplication::translate("MainWindow", "Abort pasting ANK text to virtual machine.", 0));
336                 actionStop_Pasting->setIcon(QApplication::style()->standardIcon(QStyle::SP_DialogCancelButton));
337         }
338         if(using_flags->is_use_state()) {
339                 menuSave_State->setTitle(QApplication::translate("MainWindow", "Save State", 0));
340                 menuSave_State->setIcon(QApplication::style()->standardIcon(QStyle::SP_DialogSaveButton));
341                 menuSave_State->setToolTip(QApplication::translate("MainWindow", "Save snapshot to fixed bin file.", 0));
342                 menuLoad_State->setTitle(QApplication::translate("MainWindow", "Load State", 0));
343                 menuLoad_State->setIcon(QApplication::style()->standardIcon(QStyle::SP_DialogOpenButton));
344                 menuLoad_State->setToolTip(QApplication::translate("MainWindow", "Load snapshot from fixed bin file.", 0));
345                 for(int i = 0; i < 10; i++) {
346                         QString tmps;
347                         tmps.clear();
348                         tmps.setNum(i);
349                         tmps = QString::fromUtf8("Slot #") + tmps;
350                         actionSave_State[i]->setText(tmps);
351                         actionLoad_State[i]->setText(tmps);
352                 }
353         }
354         if(using_flags->is_use_debugger()) {
355                 actionDebugger[0]->setText(QApplication::translate("MainWindow", "Main CPU", 0));
356                 actionDebugger[1]->setText(QApplication::translate("MainWindow", "Sub CPU", 0));
357                 actionDebugger[2]->setText(QApplication::translate("MainWindow", "Debugger 3", 0));
358                 actionDebugger[3]->setText(QApplication::translate("MainWindow", "Debugger 4", 0));
359                 menuDebugger->setTitle(QApplication::translate("MainWindow", "Debugger", 0));
360         }
361         menuControl->setTitle(QApplication::translate("MainWindow", "Control", 0));
362         menuState->setTitle(QApplication::translate("MainWindow", "State", 0));
363         
364         if(using_flags->is_use_auto_key()) {
365                 menuCopy_Paste->setTitle(QApplication::translate("MainWindow", "Copy/Paste", 0));
366         }
367         menuCpu_Speed->setTitle(QApplication::translate("MainWindow", "CPU Speed", 0));
368         if(using_flags->is_use_mouse()) {
369                 actionMouseEnable->setText(QApplication::translate("MainWindow", "Grab MOUSE", 0));
370                 actionMouseEnable->setToolTip(QApplication::translate("MainWindow", "Grabbing host's mouse.\nPress RIGHT Application key (or another) to toggle enable/disable.", 0));
371         }
372 }
373
374 void Ui_MainWindowBase::do_set_sound_device(int num)
375 {
376         if((num < 0) || (num >= using_flags->get_use_sound_device_type())) return;
377         using_flags->get_config_ptr()->sound_type = num;
378         emit sig_emu_update_config();
379 }