OSDN Git Service

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