OSDN Git Service

4cfe90419ed8c1c3fa27d8191856b21a9dd9b9e7
[csp-qt/common_source_project-fm7.git] / source / src / qt / gui / menu_cmt.cpp
1 /*
2  * Qt / Tape Menu, Utilities
3  * (C) 2015 K.Ohta <whatisthis.sowhat _at_ gmail.com>
4  * License : GPLv2
5  *   History : 
6  *     Jan 13 2015 : Start
7  */
8
9 #include <QApplication>
10 #include <QStyle>
11 #include <QActionGroup>
12
13 #include "commonclasses.h"
14 #include "mainwidget_base.h"
15 #include "menu_cmt.h"
16
17 #include "qt_dialogs.h"
18 //#include "emu.h"
19
20
21 Menu_CMTClass::Menu_CMTClass(QMenuBar *root_entry, QString desc, std::shared_ptr<USING_FLAGS> p, QWidget *parent, int drv, int base_drv) : Menu_MetaClass(root_entry, desc, p, parent, drv, base_drv)
22 {
23         use_write_protect = true;
24         use_d88_menus = false;
25
26         ext_rec_filter.clear();
27
28         icon_cmt = QIcon(":/icon_cmt.png");
29         icon_play_start = QApplication::style()->standardIcon(QStyle::SP_MediaPlay);
30         icon_play_stop = QApplication::style()->standardIcon(QStyle::SP_MediaStop);
31         icon_ff = QApplication::style()->standardIcon(QStyle::SP_MediaSkipForward);
32         icon_rew = QApplication::style()->standardIcon(QStyle::SP_MediaSkipBackward);
33         icon_apss_forward = QApplication::style()->standardIcon(QStyle::SP_MediaSeekForward);
34         icon_apss_backward = QApplication::style()->standardIcon(QStyle::SP_MediaSeekBackward);
35         icon_record_to_wav = QIcon(":/icon_record_to_tape.png");
36 }
37
38 Menu_CMTClass::~Menu_CMTClass()
39 {
40 }
41
42 void Menu_CMTClass::do_push_play_tape(void)
43 {
44         emit sig_push_play_tape(media_drive);
45 }
46
47 void Menu_CMTClass::do_push_stop_tape(void)
48 {
49         emit sig_push_stop_tape(media_drive);
50 }
51
52 void Menu_CMTClass::do_push_fast_forward_tape(void)
53 {
54         emit sig_push_fast_forward_tape(media_drive);
55 }
56
57 void Menu_CMTClass::do_push_rewind_tape(void)
58 {
59         emit sig_push_rewind_tape(media_drive);
60 }
61
62 void Menu_CMTClass::do_push_apss_forward_tape(void)
63 {
64         emit sig_push_apss_forward_tape(media_drive);
65 }
66
67 void Menu_CMTClass::do_push_apss_rewind_tape(void)
68 {
69         emit sig_push_apss_rewind_tape(media_drive);
70 }
71
72 void Menu_CMTClass::set_wave_shaper(bool flag)
73 {
74         emit sig_wave_shaper(media_drive, flag);
75 }
76
77 void Menu_CMTClass::set_direct_load_mzt(bool flag)
78 {
79         emit sig_direct_load_mzt(media_drive, flag);
80 }
81
82 void Menu_CMTClass::do_open_write_cmt(QString s)
83 {
84         emit sig_open_write_cmt(media_drive, s);
85 }
86
87
88 void Menu_CMTClass::create_pulldown_menu_device_sub(void)
89 {
90         action_wave_shaper = new Action_Control(p_wid, using_flags);
91         action_wave_shaper->setVisible(true);
92         action_wave_shaper->setCheckable(true);
93
94         if(using_flags->is_machine_cmt_mz_series()) {
95                 action_direct_load_mzt = new Action_Control(p_wid, using_flags);
96                 action_direct_load_mzt->setVisible(true);
97                 action_direct_load_mzt->setCheckable(true);
98         }
99         action_recording = new Action_Control(p_wid, using_flags);
100         action_recording->setVisible(true);
101         action_recording->setCheckable(false);
102
103         if(p_config->wave_shaper[media_drive] == 0) {
104                 action_wave_shaper->setChecked(false);
105         } else {
106                 action_wave_shaper->setChecked(true);
107         }
108         if(using_flags->is_machine_cmt_mz_series()) {
109                 if(p_config->direct_load_mzt[media_drive] == 0) {
110                         action_direct_load_mzt->setChecked(false);
111                 } else {
112                         action_direct_load_mzt->setChecked(true);
113                 }
114         }
115         /*if(using_flags->is_use_tape_button())*/ {
116                 action_play_start = new Action_Control(p_wid, using_flags);
117                 action_play_start->setVisible(true);
118                 action_play_start->setCheckable(true);
119                 
120                 action_play_stop = new Action_Control(p_wid, using_flags);
121                 action_play_stop->setVisible(true);
122                 action_play_stop->setCheckable(true);
123                 
124                 action_fast_forward = new Action_Control(p_wid, using_flags);
125                 action_fast_forward->setVisible(true);
126                 action_fast_forward->setCheckable(true);
127                 
128                 action_fast_rewind = new Action_Control(p_wid, using_flags);
129                 action_fast_rewind->setVisible(true);
130                 action_fast_rewind->setCheckable(true);
131                 
132                 action_apss_forward = new Action_Control(p_wid, using_flags);
133                 action_apss_forward->setVisible(true);
134                 action_apss_forward->setCheckable(true);
135                 
136                 action_apss_rewind = new Action_Control(p_wid, using_flags);
137                 action_apss_rewind->setVisible(true);
138                 action_apss_rewind->setCheckable(true);
139
140                 action_group_tape_button = new QActionGroup(p_wid);
141
142                 action_group_tape_button->setExclusive(true);
143                 action_group_tape_button->addAction(action_play_start);
144                 action_group_tape_button->addAction(action_play_stop);
145                 action_group_tape_button->addAction(action_fast_forward);
146                 action_group_tape_button->addAction(action_fast_rewind);
147                 action_group_tape_button->addAction(action_apss_forward);
148                 action_group_tape_button->addAction(action_apss_rewind);
149         }
150 }
151
152
153 void Menu_CMTClass::connect_menu_device_sub(void)
154 {
155         if(using_flags->is_use_tape()) {
156                 this->addSeparator();
157                 this->addAction(action_recording);
158                 this->addSeparator();
159                 /*if(using_flags->is_use_tape_button())*/ {
160                         this->addAction(action_play_start);
161                         this->addAction(action_play_stop);
162                         this->addSeparator();
163                         
164                         this->addAction(action_fast_forward);
165                         this->addAction(action_fast_rewind);
166                         this->addSeparator();
167         
168                         this->addAction(action_apss_forward);
169                         this->addAction(action_apss_rewind);
170                         this->addSeparator();
171                 }
172                 this->addAction(action_wave_shaper);
173                 connect(action_wave_shaper, SIGNAL(toggled(bool)), this, SLOT(set_wave_shaper(bool)));
174                 connect(this, SIGNAL(sig_wave_shaper(int, bool)), p_wid, SLOT(set_wave_shaper(int, bool)));
175                 
176                 if(using_flags->is_machine_cmt_mz_series()) {
177                         this->addAction(action_direct_load_mzt);
178                         connect(action_direct_load_mzt, SIGNAL(toggled(bool)), this, SLOT(set_direct_load_mzt(bool)));
179                         connect(this, SIGNAL(sig_direct_load_mzt(int, bool)), p_wid, SLOT(set_direct_load_from_mzt(int, bool)));
180                 }
181                 connect(action_recording, SIGNAL(triggered()), this, SLOT(do_open_rec_dialog()));
182                 connect(this, SIGNAL(sig_open_media(int, QString)),     p_wid, SLOT(do_open_read_cmt(int, QString)));
183                 
184                 connect(this, SIGNAL(sig_eject_media(int)),     this, SLOT(do_eject_cmt(int)));
185                 connect(this, SIGNAL(sig_close_tape(int)), p_wid, SLOT(eject_cmt(int)));
186                 
187                 connect(this, SIGNAL(sig_write_protect_media(int, bool)), p_wid, SLOT(do_write_protect_cmt(int, bool)));        
188                 connect(this, SIGNAL(sig_set_recent_media(int, int)), p_wid, SLOT(set_recent_cmt(int, int)));
189                 /*if(using_flags->is_use_tape_button())*/ {
190                         connect(action_play_start, SIGNAL(triggered()), this, SLOT(do_push_play_tape(void)));
191                         connect(action_play_stop,  SIGNAL(triggered()), this, SLOT(do_push_stop_tape(void)));
192                         connect(action_fast_forward,  SIGNAL(triggered()), this, SLOT(do_push_fast_forward_tape(void)));
193                         connect(action_fast_rewind,   SIGNAL(triggered()), this, SLOT(do_push_rewind_tape(void)));
194                         connect(action_apss_forward,  SIGNAL(triggered()), this, SLOT(do_push_apss_forward_tape(void)));
195                         connect(action_apss_rewind,   SIGNAL(triggered()), this, SLOT(do_push_apss_rewind_tape(void)));
196
197                         connect(this, SIGNAL(sig_push_play_tape(int)), p_wid, SLOT(do_push_play_tape(int)));
198                         connect(this,  SIGNAL(sig_push_stop_tape(int)), p_wid, SLOT(do_push_stop_tape(int)));
199                         connect(this,  SIGNAL(sig_push_fast_forward_tape(int)), p_wid, SLOT(do_push_fast_forward_tape(int)));
200                         connect(this,   SIGNAL(sig_push_rewind_tape(int)), p_wid, SLOT(do_push_rewind_tape(int)));
201                         connect(this,  SIGNAL(sig_push_apss_forward_tape(int)), p_wid, SLOT(do_push_apss_forward_tape(int)));
202                         connect(this,   SIGNAL(sig_push_apss_rewind_tape(int)), p_wid, SLOT(do_push_apss_rewind_tape(int)));
203                 }
204         }
205 }
206
207 void Menu_CMTClass::do_add_rec_media_extension(QString ext, QString description)
208 {
209         QString tmps = description;
210         QString all = QString::fromUtf8("All Files (*.*)");
211
212         tmps.append(QString::fromUtf8(" ("));
213         tmps.append(ext.toLower());
214         tmps.append(QString::fromUtf8(" "));
215         tmps.append(ext.toUpper());
216         tmps.append(QString::fromUtf8(")"));
217
218         ext_rec_filter << tmps;
219         ext_rec_filter << all;
220         
221         ext_rec_filter.removeDuplicates();
222 }
223
224 void Menu_CMTClass::do_open_rec_dialog()
225 {
226         CSP_DiskDialog *dlg = new CSP_DiskDialog(nullptr);
227         
228         if(initial_dir.isEmpty()) { 
229                 QDir dir;
230                 char app[PATH_MAX];
231                 initial_dir = dir.currentPath();
232                 strncpy(app, initial_dir.toLocal8Bit().constData(), PATH_MAX - 1);
233                 initial_dir = QString::fromLocal8Bit(get_parent_dir(app));
234         }
235         dlg->setOption(QFileDialog::ReadOnly, false);
236         dlg->setOption(QFileDialog::DontUseNativeDialog, true);
237         dlg->setAcceptMode(QFileDialog::AcceptSave);
238         dlg->param->setDrive(media_drive);
239         dlg->setDirectory(initial_dir);
240         dlg->setNameFilters(ext_rec_filter);
241         dlg->setWindowTitle(desc_rec);
242         dlg->setWindowTitle(QApplication::translate("MenuMedia", "Save Tape", 0));
243         
244         connect(dlg, SIGNAL(fileSelected(QString)), this, SLOT(do_open_write_cmt(QString))); 
245         connect(this, SIGNAL(sig_open_write_cmt(int, QString)), p_wid, SLOT(do_open_write_cmt(int, QString))); 
246         connect(dlg, SIGNAL(accepted()), this, SLOT(do_close_window()), Qt::QueuedConnection); 
247         connect(dlg, SIGNAL(rejected()), this, SLOT(do_close_window()), Qt::QueuedConnection); 
248         connect(dlg, SIGNAL(finished(int)), this, SLOT(do_finish(int)), Qt::QueuedConnection); 
249         
250         dialogs.append(dlg);
251         dlg->setModal(false);
252         dlg->show();
253
254         return;
255 }
256
257 void Menu_CMTClass::do_eject_cmt(int drive) 
258 {
259         emit sig_close_tape(drive);
260 }
261
262 void Menu_CMTClass::retranslate_pulldown_menu_device_sub(void)
263 {
264         action_insert->setText(QApplication::translate("MenuMedia", "Insert CMT", 0));
265         action_insert->setToolTip(QApplication::translate("MenuMedia", "Insert a TAPE image file.", 0));
266         action_eject->setText(QApplication::translate("MenuMedia", "Eject CMT", 0));
267         action_eject->setToolTip(QApplication::translate("MenuMedia", "Eject a TAPE image file.", 0));
268
269         action_wave_shaper->setText(QApplication::translate("MenuMedia", "Enable Wave Shaper", 0));
270         action_wave_shaper->setToolTip(QApplication::translate("MenuMedia", "Enable wave shaping.\nUseful for some images.", 0));
271
272         if(using_flags->is_machine_cmt_mz_series()) {
273                 action_direct_load_mzt->setText(QApplication::translate("MenuMedia", "Direct load from MZT", 0));
274                 action_direct_load_mzt->setToolTip(QApplication::translate("MenuMedia", "Direct loading to memory.\nOnly for MZT image file.", 0));
275         }
276         this->setTitle(QApplication::translate("MenuMedia", "Cassette Tape" , 0));
277         action_insert->setIcon(icon_cmt);
278
279         /*if(using_flags->is_use_tape_button())*/ {
280                 action_play_start->setIcon(icon_play_start);
281                 action_play_stop->setIcon(icon_play_stop);
282                 action_fast_forward->setIcon(icon_ff);
283                 action_fast_rewind->setIcon(icon_rew);
284                 action_apss_forward->setIcon(icon_apss_forward);
285                 action_apss_rewind->setIcon(icon_apss_backward);
286                 
287                 action_play_stop->setText(QApplication::translate("MenuMedia", "Play Stop", 0));
288                 action_play_start->setText(QApplication::translate("MenuMedia", "Play Start", 0));
289                 action_fast_forward->setText(QApplication::translate("MenuMedia", "Fast Forward", 0));
290                 action_fast_rewind->setText(QApplication::translate("MenuMedia", "Rewind", 0));
291                 action_apss_forward->setText(QApplication::translate("MenuMedia", "APSS Forward", 0));
292                 action_apss_rewind->setText(QApplication::translate("MenuMedia", "APSS Rewind", 0));
293         }
294         action_recording->setIcon(icon_record_to_wav);
295         action_recording->setText(QApplication::translate("MenuMedia", "Record to a WAV File", 0));
296         action_recording->setToolTip(QApplication::translate("MenuMedia", "Record CMT output to a file.", 0));
297 }