OSDN Git Service

454619bca02b6716458f537a26988f082f3d374c
[csp-qt/common_source_project-fm7.git] / source / src / qt / gui / display_statusbar.cpp
1 /*
2  * Common Source code project : GUI
3  * (C) 2015 K.Ohta <whatisthis.sowhat _at_ gmail.com>
4  *     License : GPLv2
5  *     History:
6  *      Jan 14, 2015 : Initial
7  *
8  * [qt -> gui -> status bar]
9  */
10
11 #include <QtCore/QVariant>
12 #include <QtGui>
13 #include <QSize>
14 #include <QHBoxLayout>
15 #include <QPainter>
16 #include <QBrush>
17 #include <QGraphicsView>
18 #include <QTransform>
19
20 #include "menuclasses.h"
21 #include "emu.h"
22 #include "qt_main.h"
23 #include "vm.h"
24
25 extern EMU* emu;
26
27 void Ui_MainWindow::initStatusBar(void)
28 {
29         int i;
30         int wfactor;
31         statusUpdateTimer = new QTimer;
32         messagesStatusBar = new QLabel;
33         //dummyStatusArea1 = new QWidget;
34         QSize size1, size2, size3;
35         QString tmpstr;
36         //   QHBoxLayout *layout = new QHBoxLayout();
37         
38         //statusbar->addWidget(layout, 0);
39         messagesStatusBar->setFixedWidth(400);
40         statusbar->addPermanentWidget(messagesStatusBar, 0);
41         messagesStatusBar->font().setPointSize(12);
42         dummyStatusArea1 = new QWidget;
43         statusbar->addPermanentWidget(dummyStatusArea1, 1);
44         
45 #if defined(USE_FD1) && defined(USE_QD1) && defined(USE_TAPE)
46         wfactor = (1280 - 400 - 100 - 100) / (MAX_FD + MAX_QD);
47 #elif defined(USE_FD1) && defined(USE_TAPE)
48         wfactor = (1280 - 400 - 100 - 100) / MAX_FD;
49 #elif defined(USE_QD1) && defined(USE_TAPE)
50         wfactor = (1280 - 400 - 100 - 100) / MAX_QD;
51 #elif defined(USE_FD1)
52         wfactor = (1280 - 400 - 100) / MAX_FD;
53 #elif defined(USE_QD1)
54         wfactor = (1280 - 400 - 100) / MAX_QD;
55 #elif defined(USE_QD1) && defined(USE_FD1)
56         wfactor = (1280 - 400 - 100) / (MAX_QD + MAX_FD);
57 #else
58         wfactor = 0;
59 #endif
60
61 #ifdef USE_FD1   
62         for(i = 0; i < MAX_FD; i++) osd_str_fd[i].clear();
63 #endif   
64 #ifdef USE_QD1   
65         for(i = 0; i < 2; i++) osd_str_qd[i].clear();
66 #endif   
67 #ifdef USE_TAPE
68         osd_str_cmt.clear();
69 #endif
70 #ifdef USE_LED_DEVICE
71         osd_led_data = 0x00000000;
72 #endif   
73
74 #ifdef USE_FD1
75         for(i = 0; i < MAX_FD; i++) { // Will Fix
76                 fd_StatusBar[i] = new QLabel;
77                 fd_StatusBar[i]->font().setPointSize(12);
78                 fd_StatusBar[i]->setFixedWidth((wfactor > 200) ? 200 : wfactor);
79                 //      fd_StatusBar[i]->setAlignment(Qt::AlignRight);
80                 statusbar->addPermanentWidget(fd_StatusBar[i]);
81         }
82 #endif
83 #ifdef USE_QD1
84         for(i = 0; i < MAX_QD; i++) {
85                 qd_StatusBar[i] = new QLabel;
86                 qd_StatusBar[i]->font().setPointSize(12);
87                 qd_StatusBar[i]->setFixedWidth((wfactor > 150) ? 150 : wfactor);
88                 //     qd_StatusBar[i]->setAlignment(Qt::AlignRight);
89                 statusbar->addPermanentWidget(qd_StatusBar[i]);
90         }
91 #endif
92 #ifdef USE_TAPE
93         cmt_StatusBar = new QLabel;
94         cmt_StatusBar->setFixedWidth(100);
95         cmt_StatusBar->font().setPointSize(12);
96         statusbar->addPermanentWidget(cmt_StatusBar);
97 #endif
98         dummyStatusArea2 = new QWidget;
99         dummyStatusArea2->setFixedWidth(100);
100 #ifdef USE_LED_DEVICE
101         for(i = 0; i < USE_LED_DEVICE; i++) {
102                 flags_led[i] = false;
103                 flags_led_bak[i] = false;
104         }
105         led_graphicsView = new QGraphicsView(dummyStatusArea2);
106         
107         led_gScene = new QGraphicsScene(0.0f, 0.0f, (float)dummyStatusArea2->width(), (float)dummyStatusArea2->height());
108         QPen pen;
109         QBrush bbrush(QColor(Qt::black));
110         led_graphicsView->setBackgroundBrush(bbrush);
111         connect(this, SIGNAL(sig_led_update(QRectF)), led_graphicsView, SLOT(updateSceneRect(QRectF)));
112         {
113                 QBrush rbrush(QColor(Qt::red));
114                 float bitwidth = (float)dummyStatusArea2->width() / ((float)USE_LED_DEVICE * 2.0);
115                 float start = -(float)dummyStatusArea2->width()  / 2.0f + bitwidth * 3.0f;
116
117                 pen.setColor(Qt::black);
118                 led_gScene->addRect(0, 0, 
119                                     -(float)dummyStatusArea2->width(),
120                                     (float)dummyStatusArea2->height(),
121                                     pen, bbrush);
122                 for(i = 0; i < USE_LED_DEVICE; i++) {
123                         led_leds[i] = NULL;
124                         pen.setColor(Qt::red);
125                         led_leds[i] = led_gScene->addEllipse(start,
126                                   (float)dummyStatusArea2->height() / 3.0f,
127                                    bitwidth - 2.0f, bitwidth - 2.0f,
128                                    pen, rbrush);
129                         start = start + bitwidth * 1.5f;
130                 }
131         }
132 #endif
133         statusbar->addPermanentWidget(dummyStatusArea2, 0);
134         //   statusbar->addWidget(dummyStatusArea2);
135         connect(statusUpdateTimer, SIGNAL(timeout()), this, SLOT(redraw_status_bar()));
136         statusUpdateTimer->start(33);
137 #ifdef USE_LED_DEVICE
138         ledUpdateTimer = new QTimer;
139         connect(statusUpdateTimer, SIGNAL(timeout()), this, SLOT(redraw_leds()));
140         statusUpdateTimer->start(5);
141 #endif
142 }
143
144 void Ui_MainWindow::resize_statusbar(int w, int h)
145 {
146         int wfactor;
147         QSize nowSize;
148         double height, width;
149         double scaleFactor;
150         int ww;
151         int pt;
152         int i;
153         int qd_width, fd_width;
154         int sfactor = 0;;
155
156         nowSize = messagesStatusBar->size();
157         height = (double)(nowSize.height());
158         width  = (double)(nowSize.width());
159         scaleFactor = (double)w / 1280.0;
160    
161         statusbar->setFixedWidth(w);
162         pt = (int)(14.0 * scaleFactor);
163         if(pt < 4) pt = 4;
164         sfactor = (int)(400.0 * scaleFactor);
165         messagesStatusBar->setFixedWidth((int)(400.0 * scaleFactor));
166         messagesStatusBar->font().setPointSize(pt);
167    
168 #if defined(USE_FD1) && defined(USE_QD1) && defined(USE_TAPE)
169         wfactor = (1280 - 400 - 100 - 100) / (MAX_FD + MAX_QD);
170 #elif defined(USE_FD1) && defined(USE_TAPE)
171         wfactor = (1280 - 400 - 100 - 100) / MAX_FD;
172 #elif defined(USE_QD1) && defined(USE_TAPE)
173         wfactor = (1280 - 400 - 100 - 100) / MAX_QD;
174 #elif defined(USE_FD1)
175         wfactor = (1280 - 400 - 100) / MAX_FD;
176 #elif defined(USE_QD1)
177         wfactor = (1280 - 400 - 100) / MAX_QD;
178 #elif defined(USE_QD1) && defined(USE_FD1)
179         wfactor = (1280 - 400 - 100) / (MAX_QD + MAX_FD);
180 #else
181         wfactor = 100;
182 #endif
183         fd_width = wfactor;
184         qd_width = wfactor;
185         if(fd_width > 200) fd_width = 200;
186         if(fd_width < 50) fd_width = 50;
187         if(qd_width > 150) qd_width = 150;
188         if(qd_width < 50) qd_width = 50;
189
190 #ifdef USE_FD1
191         ww = (int)(scaleFactor * (double)fd_width);
192         for(i = 0; i < MAX_FD; i++) { // Will Fix
193                 fd_StatusBar[i]->font().setPointSize(pt);
194                 fd_StatusBar[i]->setFixedWidth(ww);
195                 sfactor += ww;
196         }
197 #endif
198 #ifdef USE_QD1
199         ww = (int)(scaleFactor * (double)fd_width);
200         for(i = 0; i < MAX_QD; i++) { // Will Fix
201                 qd_StatusBar[i]->font().setPointSize(pt);
202                 qd_StatusBar[i]->setFixedWidth(ww);
203                 sfactor += ww;
204         }
205 #endif
206 #ifdef USE_TAPE
207         cmt_StatusBar->setFixedWidth((int)(100.0 * scaleFactor));
208         cmt_StatusBar->font().setPointSize(pt);
209         sfactor += (int)(100.0 * scaleFactor);
210 #endif
211 #ifdef USE_LED_DEVICE
212         led_graphicsView->setFixedWidth((int)(100.0 * scaleFactor)); 
213 #endif   
214         dummyStatusArea2->setFixedWidth((int)(108.0 * scaleFactor));
215         sfactor += (int)(100.0 * scaleFactor);
216         sfactor = (int)(1280.0 * scaleFactor) - sfactor;
217         if(sfactor > 10) {
218                 dummyStatusArea1->setVisible(true);
219         } else {
220                 dummyStatusArea1->setVisible(false);
221                 sfactor = 10;
222         }
223         dummyStatusArea1->setFixedWidth(sfactor);   
224 #ifdef USE_LED_DEVICE
225         {
226                 QPen pen;
227                 QBrush rbrush(QColor(Qt::red));
228                 QBrush bbrush(QColor(Qt::black));
229                 float bitwidth = (float)dummyStatusArea2->width() / ((float)USE_LED_DEVICE * 2.0);
230                 float start = -(float)dummyStatusArea2->width()  / 2.0f + bitwidth * 3.0f;
231
232                 led_gScene->clear();
233
234                 pen.setColor(Qt::black);
235                 led_gScene->addRect(0, 0, 
236                                     -(float)dummyStatusArea2->width(),
237                                     (float)dummyStatusArea2->height(),
238                                     pen, bbrush);
239                 for(i = 0; i < USE_LED_DEVICE; i++) {
240                         led_leds[i] = NULL;
241                         pen.setColor(Qt::red);
242                         led_leds[i] = led_gScene->addEllipse(start,
243                                   (float)dummyStatusArea2->height() / 3.0f,
244                                    bitwidth - 2.0f, bitwidth - 2.0f,
245                                    pen, rbrush);
246                         start = start + bitwidth * 1.5f;
247                 }
248                 //redraw_leds();
249         }
250 #endif
251 }
252
253 #ifdef USE_LED_DEVICE
254 void Ui_MainWindow::do_recv_data_led(quint32 d)
255 {
256         osd_led_data = (uint32_t)d;
257 }
258
259 void Ui_MainWindow::redraw_leds(void)
260 {
261                 uint32_t drawflags;
262                 int i;
263                 float bitwidth = (float)dummyStatusArea2->width() / ((float)USE_LED_DEVICE * 2.0);
264                 float start = -(float)dummyStatusArea2->width() + bitwidth * 4.0f;
265                 drawflags = osd_led_data;
266                 
267                 for(i = 0; i < USE_LED_DEVICE; i++) {
268                         flags_led[i] = ((drawflags & (1 << i)) != 0);
269                         if(led_leds[i] != NULL) {
270                                 if(flags_led[i]) {
271                                         led_leds[i]->setVisible(true);
272                                 } else {
273                                         led_leds[i]->setVisible(false);
274                                 }
275                         }
276                         emit sig_led_update(QRectF(start,
277                                            0.0f, bitwidth * 2.0f, bitwidth * 2.0f));
278                         start = start + bitwidth * 1.5f;
279                 }
280                 led_graphicsView->setScene(led_gScene);
281 }       
282 #endif  
283
284 #if defined(USE_QD1)
285 void Ui_MainWindow::do_change_osd_qd(int drv, QString tmpstr)
286 {
287         if((drv < 0) || (drv > 1)) return;
288         osd_str_qd[drv] = tmpstr;
289 }
290 #endif
291
292 #if defined(USE_FD1)
293 void Ui_MainWindow::do_change_osd_fd(int drv, QString tmpstr)
294 {
295         if((drv < 0) || (drv >= MAX_FD)) return;
296         osd_str_fd[drv] = tmpstr;
297 }
298 #endif
299 #if defined(USE_TAPE)
300 void Ui_MainWindow::do_change_osd_cmt(QString tmpstr)
301 {
302         osd_str_cmt = tmpstr;
303 }
304 #endif
305
306 void Ui_MainWindow::redraw_status_bar(void)
307 {
308         int access_drv;
309         int tape_counter;
310         int i;
311 #ifdef USE_FD1   
312         for(i = 0; i < MAX_FD; i++) {      
313                 if(osd_str_fd[i] != fd_StatusBar[i]->text()) fd_StatusBar[i]->setText(osd_str_fd[i]);
314         }
315 #endif   
316 #ifdef USE_QD1   
317         for(i = 0; i < MAX_QD; i++) {      
318                 if(osd_str_qd[i] != qd_StatusBar[i]->text()) qd_StatusBar[i]->setText(osd_str_qd[i]);
319         }
320 #endif   
321 #ifdef USE_TAPE
322         if(osd_str_cmt != cmt_StatusBar->text()) cmt_StatusBar->setText(osd_str_cmt);
323 #endif
324 }
325
326
327 void Ui_MainWindow::message_status_bar(QString str)
328 {
329         //QString tmpstr;
330         if(messagesStatusBar == NULL) return;
331         if(str != messagesStatusBar->text()) messagesStatusBar->setText(str);
332 }