OSDN Git Service

[UI][Qt][WIP] Re-factoring of UIs to integrate one lib as possible, this is WIP,...
[csp-qt/common_source_project-fm7.git] / source / src / qt / gui / menu_screen.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 "commonclasses.h"
13 #include "mainwidget.h"
14 //#include "menuclasses.h"
15 #include "emu.h"
16 #include "qt_main.h"
17 #include "qt_gldraw.h"
18
19 QT_BEGIN_NAMESPACE
20
21 // WIP: Move another header.
22 #if (SCREEN_WIDTH > 320)
23 const static float screen_multiply_table[] = {0.5, 1.0, 1.5, 2.0, 2.25, 2.5, 3.0, 3.5, 4.0, 5.0, 6.0, 8.0, 0.0};
24 #else
25 const static float screen_multiply_table[] = {0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 5.0, 6.0, 7.5, 10.0, 12.0, 15.0, 0.0};
26 #endif
27 void Object_Menu_Control::set_screen_aspect(void) {
28         int num = getValue1();
29         emit sig_screen_aspect(num);
30 }
31
32 void Object_Menu_Control::set_screen_size(void) {
33         int w, h;
34         double nd, ww, hh;
35         config.window_mode = getNumber();
36         nd = getDoubleValue();
37         ww = nd * (double)using_flags.get_screen_width();
38         hh = nd * (double)using_flags.get_screen_height();
39         if((using_flags->get_screen_height_aspect() != using_flags->get_screen_height()) ||
40            (using_flags->get_screen_width_aspect() != using_flags->get_screen_width())) {
41                 double par_w = (double)using_flags.get_screen_width_aspect() / (double)using_flags.get_screen_width();
42                 double par_h = (double)using_flags.get_screen_height_aspect() / (double)using_flags.get_screen_height();
43                 double par = par_h / par_w;
44                 if(config.window_stretch_type == 1) { // refer to X, scale Y.
45                         hh = hh * par_h;
46                 } else if(config.window_stretch_type == 2) { // refer to Y, scale X only
47                         ww = ww / par_h;
48                 } else if(config.window_stretch_type == 3) { // Scale both X, Y
49                         ww = ww * par_w;
50                         hh = hh * par_h;
51                 }
52         }
53         w = (int)ww;
54         h = (int)hh;
55         emit sig_screen_size(w, h);
56         emit sig_screen_multiply(nd);
57 }
58
59 void Ui_MainWindow::set_gl_scan_line_vert(bool f)
60 {
61         config.opengl_scanline_vert = f;
62 }
63
64 void Ui_MainWindow::set_gl_scan_line_horiz(bool f)
65 {
66         config.opengl_scanline_horiz = f;
67 }
68
69 void Ui_MainWindow::ConfigScreenMenu_List(void)
70 {
71         int w, h;
72         QString tmps;
73         int i;
74         
75         actionGroup_ScreenSize = new QActionGroup(this);
76         actionGroup_ScreenSize->setExclusive(true);
77         screen_mode_count = 0;
78         for(i = 0; i < _SCREEN_MODE_NUM; i++) {
79                 w = (int)(screen_multiply_table[i] * (double)using_flags->get_screen_width());
80                 h = (int)(screen_multiply_table[i] * (double)using_flags->get_screen_height());
81                 if((w <= 0) || (h <= 0)) {
82                         break;
83                 }
84                 screen_mode_count++;
85                 tmps = QString::number(i);
86                 actionScreenSize[i] = new Action_Control(this);
87                 actionScreenSize[i]->setObjectName(QString::fromUtf8("actionScreenSize", -1) + tmps);
88                 actionScreenSize[i]->setCheckable(true);
89                 actionScreenSize[i]->binds->setNumber(i);
90
91                 if(i == config.window_mode)  actionScreenSize[i]->setChecked(true);  // OK?
92
93                 actionGroup_ScreenSize->addAction(actionScreenSize[i]);
94                 actionScreenSize[i]->binds->setDoubleValue(screen_multiply_table[i]);
95                 
96                 connect(actionScreenSize[i], SIGNAL(triggered()),
97                         actionScreenSize[i]->binds, SLOT(set_screen_size()));
98
99                 connect(actionScreenSize[i]->binds, SIGNAL(sig_screen_size(int, int)),
100                         this, SLOT(set_screen_size(int, int)));
101         }
102         for(; i < _SCREEN_MODE_NUM; i++) {
103                 actionScreenSize[i] = NULL;
104         }
105 }
106 void Ui_MainWindow::ConfigScreenMenu(void)
107 {
108         actionZoom = new Action_Control(this);
109         actionZoom->setObjectName(QString::fromUtf8("actionZoom"));
110         actionDisplay_Mode = new Action_Control(this);
111         actionDisplay_Mode->setObjectName(QString::fromUtf8("actionDisplay_Mode"));
112         
113         if(using_flags->is_scan_line()) {
114                 actionScanLine = new Action_Control(this);
115                 actionScanLine->setObjectName(QString::fromUtf8("actionScanLine"));
116                 actionScanLine->setCheckable(true);
117                 if(config.scan_line != 0) {
118                         actionScanLine->setChecked(true);
119                 } else {
120                         actionScanLine->setChecked(false);
121                 }
122                 connect(actionScanLine, SIGNAL(toggled(bool)),
123                         this, SLOT(set_scan_line(bool)));
124         }
125         if(!using_flags->is_use_one_board_computer() && (using_flags->get_max_buttons() <= 0)) {
126                 actionGLScanLineHoriz = new Action_Control(this);
127                 actionGLScanLineHoriz->setObjectName(QString::fromUtf8("actionGLScanLineHoriz"));
128                 actionGLScanLineHoriz->setCheckable(true);
129                 if(config.opengl_scanline_horiz != 0) {
130                         actionGLScanLineHoriz->setChecked(true);
131                 } else {
132                         actionGLScanLineHoriz->setChecked(false);
133                 }
134                 connect(actionGLScanLineHoriz, SIGNAL(toggled(bool)),
135                                 this, SLOT(set_gl_scan_line_horiz(bool)));
136                 if(using_flags->is_use_vertical_pixel_lines()) {
137                         actionGLScanLineVert = new Action_Control(this);
138                         actionGLScanLineVert->setObjectName(QString::fromUtf8("actionGLScanLineVert"));
139                         actionGLScanLineVert->setCheckable(true);
140                         if(config.opengl_scanline_vert != 0) {
141                                 actionGLScanLineVert->setChecked(true);
142                         } else {
143                                 actionGLScanLineVert->setChecked(false);
144                         }
145                         connect(actionGLScanLineVert, SIGNAL(toggled(bool)),
146                                         this, SLOT(set_gl_scan_line_vert(bool)));
147                 }
148         }
149         if(using_flags->is_use_screen_rotate()) {
150                 actionRotate = new Action_Control(this);
151                 actionRotate->setObjectName(QString::fromUtf8("actionScanLine"));
152                 actionRotate->setCheckable(true);
153                 if(config.rotate_type) {
154                         actionRotate->setChecked(true);
155                 } else {
156                         actionRotate->setChecked(false);
157                 }
158                 connect(actionRotate, SIGNAL(toggled(bool)),
159                                 this, SLOT(set_screen_rotate(bool)));
160         }
161         if(using_flags->is_use_crt_filter()) {
162                 actionCRT_Filter = new Action_Control(this);
163                 actionCRT_Filter->setObjectName(QString::fromUtf8("actionCRT_Filter"));
164                 actionCRT_Filter->setEnabled(true);
165                 actionCRT_Filter->setCheckable(true);
166                 if(config.crt_filter == 0) actionCRT_Filter->setChecked(true);
167                 connect(actionCRT_Filter, SIGNAL(toggled(bool)), this, SLOT(set_crt_filter(bool)));
168         }
169         actionOpenGL_Filter = new Action_Control(this);
170         actionOpenGL_Filter->setObjectName(QString::fromUtf8("actionOpenGL_Filter"));
171         actionOpenGL_Filter->setEnabled(true);
172         actionOpenGL_Filter->setCheckable(true);
173         if(config.use_opengl_filters) actionOpenGL_Filter->setChecked(true);
174         connect(actionOpenGL_Filter, SIGNAL(toggled(bool)), this, SLOT(set_gl_crt_filter(bool)));
175
176         if((using_flags->get_screen_height_aspect() != using_flags->get_screen_height()) ||
177            (using_flags->get_screen_width_aspect() != using_flags->get_screen_width())) {
178                 actionDot_by_Dot = new Action_Control(this);
179                 actionDot_by_Dot->setObjectName(QString::fromUtf8("actionDot_by_Dot"));
180                 actionDot_by_Dot->setCheckable(true);
181                 if(config.window_stretch_type == 0) actionDot_by_Dot->setChecked(true);
182                 actionDot_by_Dot->binds->setValue1(0);
183                 
184                 actionReferToX_Display = new Action_Control(this);
185                 actionReferToX_Display->setObjectName(QString::fromUtf8("actionReferToX_Display"));
186                 actionReferToX_Display->setCheckable(true);
187                 actionReferToX_Display->binds->setValue1(1);
188                 if(config.window_stretch_type == 1) actionReferToX_Display->setChecked(true);
189                 
190                 actionReferToY_Display = new Action_Control(this);
191                 actionReferToY_Display->setObjectName(QString::fromUtf8("actionReferToY_Display"));
192                 actionReferToY_Display->setCheckable(true);
193                 actionReferToY_Display->binds->setValue1(2);
194                 if(config.window_stretch_type == 2) actionReferToY_Display->setChecked(true);
195         
196                 actionFill_Display = new Action_Control(this);
197                 actionFill_Display->setObjectName(QString::fromUtf8("actionFill_Display"));
198                 actionFill_Display->setCheckable(true);
199                 actionFill_Display->binds->setValue1(3);
200                 if(config.window_stretch_type == 3) actionFill_Display->setChecked(true);
201         
202                 actionGroup_Stretch = new QActionGroup(this);
203                 actionGroup_Stretch->setExclusive(true);
204                 actionGroup_Stretch->addAction(actionDot_by_Dot);
205                 actionGroup_Stretch->addAction(actionReferToX_Display);
206                 actionGroup_Stretch->addAction(actionReferToY_Display);
207                 actionGroup_Stretch->addAction(actionFill_Display);
208                 connect(actionDot_by_Dot,   SIGNAL(triggered()), actionDot_by_Dot->binds,   SLOT(set_screen_aspect()));
209                 connect(actionDot_by_Dot->binds,   SIGNAL(sig_screen_aspect(int)), this,    SLOT(set_screen_aspect(int)));
210                 
211                 connect(actionReferToX_Display,  SIGNAL(triggered()), actionReferToX_Display->binds,  SLOT(set_screen_aspect()));
212                 connect(actionReferToX_Display->binds,  SIGNAL(sig_screen_aspect(int)), this,    SLOT(set_screen_aspect(int)));
213                 
214                 connect(actionReferToY_Display,  SIGNAL(triggered()), actionReferToY_Display->binds,  SLOT(set_screen_aspect()));
215                 connect(actionReferToY_Display->binds,  SIGNAL(sig_screen_aspect(int)), this,    SLOT(set_screen_aspect(int)));
216                 
217                 connect(actionFill_Display, SIGNAL(triggered()), actionFill_Display->binds, SLOT(set_screen_aspect()));
218                 connect(actionFill_Display->binds, SIGNAL(sig_screen_aspect(int)), this, SLOT(set_screen_aspect(int)));
219         }
220         actionCapture_Screen = new Action_Control(this);
221         actionCapture_Screen->setObjectName(QString::fromUtf8("actionCapture_Screen"));
222
223         actionStart_Record_Movie = new Action_Control(this);
224         actionStart_Record_Movie->setObjectName(QString::fromUtf8("actionStart_Record_Movie"));
225         actionStart_Record_Movie->setCheckable(true);
226         
227         actionStop_Record_Movie = new Action_Control(this);
228         actionStop_Record_Movie->setObjectName(QString::fromUtf8("actionStop_Record_Movie"));
229         actionStop_Record_Movie->setCheckable(false);
230
231         ConfigScreenMenu_List();  
232 }
233
234 void Ui_MainWindow::CreateScreenMenu(void)
235 {
236         int i;
237         menuScreen = new QMenu(menubar);
238         menuScreen->setObjectName(QString::fromUtf8("menuScreen"));
239         if((using_flags->get_screen_height_aspect() != using_flags->get_screen_height()) ||
240            (using_flags->get_screen_width_aspect() != using_flags->get_screen_width())) {
241                 menuStretch_Mode = new QMenu(menuScreen);
242                 menuStretch_Mode->setObjectName(QString::fromUtf8("menuStretch_Mode"));
243         }
244
245         menuScreenSize = new QMenu(menuScreen);
246         menuScreenSize->setObjectName(QString::fromUtf8("menuScreen_Size"));
247         menuScreen->addSeparator();
248         menuRecord_as_movie = new QMenu(menuScreen);
249         menuRecord_as_movie->setObjectName(QString::fromUtf8("menuRecord_as_movie"));
250
251         menuScreen->addAction(actionZoom);
252         menuScreen->addAction(menuScreenSize->menuAction());
253         for(i = 0; i < _SCREEN_MODE_NUM; i++) {
254                 if(actionScreenSize[i] == NULL) continue;
255                 menuScreenSize->addAction(actionScreenSize[i]);
256                 actionScreenSize[i]->setVisible(true);
257         }
258
259         if((using_flags->get_screen_height_aspect() != using_flags->get_screen_height()) ||
260            (using_flags->get_screen_width_aspect() != using_flags->get_screen_width())) {
261                 menuScreen->addSeparator();
262                 menuScreen->addAction(menuStretch_Mode->menuAction());
263
264                 menuStretch_Mode->addAction(actionDot_by_Dot);
265                 menuStretch_Mode->addAction(actionReferToX_Display);
266                 menuStretch_Mode->addAction(actionReferToY_Display);
267                 menuStretch_Mode->addAction(actionFill_Display);
268         }
269         menuScreen->addSeparator();
270
271         if(using_flags->is_use_scanline()) {
272                 menuScreen->addAction(actionScanLine);
273         }
274
275         if(!using_flags->is_use_one_board_computer() && (using_flags->get_max_buttons() <= 0)) {
276                 menuScreen->addAction(actionGLScanLineHoriz);
277                 if(!using_flags->is_use_vertical_pixel_lines()) {
278                         menuScreen->addAction(actionGLScanLineVert);
279                 }
280         }
281         if(!using_flags->is_use_screen_rotate()) {
282                 menuScreen->addAction(actionRotate);
283         }
284         if(!using_flags->is_use_crt_filter()) {
285                 menuScreen->addAction(actionCRT_Filter);
286         }
287
288         menuScreen->addAction(actionOpenGL_Filter);
289         menuScreen->addAction(actionCapture_Screen);
290         menuScreen->addSeparator();
291         menuScreen->addAction(menuRecord_as_movie->menuAction());
292         menuRecord_as_movie->addAction(actionStart_Record_Movie);
293         menuRecord_as_movie->addAction(actionStop_Record_Movie);
294 }
295
296 void Ui_MainWindow::retranslateScreenMenu(void)
297 {
298         int i;
299         QString tmps;
300         int w, h;
301         actionZoom->setText(QApplication::translate("MainWindow", "Zoom Screen", 0));
302         actionDisplay_Mode->setText(QApplication::translate("MainWindow", "Display Mode", 0));
303
304         if(!using_flags->is_use_scanline()) {
305                 actionScanLine->setText(QApplication::translate("MainWindow", "Software Scan Line", 0));
306         }
307         if(!using_flags->is_use_screen_rotate()) {
308                 actionRotate->setText(QApplication::translate("MainWindow", "Rotate Screen", 0));
309         }
310         if(!using_flags->is_use_crt_filter()) {
311                 actionCRT_Filter->setText(QApplication::translate("MainWindow", "Software Filter", 0));
312         }
313         if(!using_flags->is_use_one_board_computer() && (using_flags->get_max_buttons() <= 0)) {
314                 actionGLScanLineHoriz->setText(QApplication::translate("MainWindow", "OpenGL Scan Line", 0));
315                 if(!using_flags->is_use_vertical_pixel_lines()) {
316                         actionGLScanLineVert->setText(QApplication::translate("MainWindow", "OpenGL Pixel Line", 0));
317                 }
318         }
319         
320         actionOpenGL_Filter->setText(QApplication::translate("MainWindow", "OpenGL Filter", 0));
321
322         if((using_flags->get_screen_height_aspect() != using_flags->get_screen_height()) ||
323            (using_flags->get_screen_width_aspect() != using_flags->get_screen_width())) {
324                 actionDot_by_Dot->setText(QApplication::translate("MainWindow", "Dot by Dot", 0));
325                 actionReferToX_Display->setText(QApplication::translate("MainWindow", "Keep Aspect: Refer to X", 0));
326                 actionReferToY_Display->setText(QApplication::translate("MainWindow", "Keep Aspect: Refer to Y", 0));
327                 actionFill_Display->setText(QApplication::translate("MainWindow", "Keep Aspect: Fill", 0));
328                 menuStretch_Mode->setTitle(QApplication::translate("MainWindow", "Stretch Mode", 0));
329         }
330
331         actionCapture_Screen->setText(QApplication::translate("MainWindow", "Capture Screen", 0));
332
333         menuScreen->setTitle(QApplication::translate("MainWindow", "Screen", 0));
334         actionStart_Record_Movie->setText(QApplication::translate("MainWindow", "Start Recording Movie", 0));
335         actionStop_Record_Movie->setText(QApplication::translate("MainWindow", "Stop Recording Movie", 0));
336
337         menuRecord_as_movie->setTitle(QApplication::translate("MainWindow", "Record as Movie", 0));
338
339
340         menuScreenSize->setTitle(QApplication::translate("MainWindow", "Screen Size", 0));
341         double s_mul;
342         for(i = 0; i < _SCREEN_MODE_NUM; i++) {
343                 if(actionScreenSize[i] == NULL) continue;
344                 s_mul = screen_multiply_table[i];
345                 if(s_mul <= 0) break;
346                 tmps = QString::number(s_mul);
347                 tmps = QString::fromUtf8("x", -1) + tmps;
348                 actionScreenSize[i]->setText(tmps);
349         }
350 }
351