• R/O
  • HTTP
  • SSH
  • HTTPS

common_source_project-fm7: Commit

Common Source Code Project for Qt (a.k.a for FM-7).


Commit MetaInfo

Revisión7b8aaba8dd5bba29859942f40b6373a543118a82 (tree)
Tiempo2020-03-03 04:03:24
AutorK.Ohta <whatisthis.sowhat@gmai...>
CommiterK.Ohta

Log Message

[UI][Qt] Add HARDDISK create widget.Still not working, only dummy.

Cambiar Resumen

Diferencia incremental

--- a/source/src/qt/common/mainwidget.h
+++ b/source/src/qt/common/mainwidget.h
@@ -61,7 +61,7 @@ public slots:
6161 void _open_bubble(int drv, const QString fname);
6262 void eject_bubble(int drv);
6363 #endif
64-
64+ void do_create_hard_disk(int drv, int sector_size, int sectors, int surfaces, int cylinders, QString name);
6565 void do_create_d88_media(int drv, quint8 media_type, QString name);
6666 #if defined(USE_DEBUGGER)
6767 void OnOpenDebugger(int n);
--- a/source/src/qt/common/qt_utils.cpp
+++ b/source/src/qt/common/qt_utils.cpp
@@ -364,8 +364,23 @@ void Ui_MainWindow::do_create_d88_media(int drv, quint8 media_type, QString name
364364 #if defined(USE_FLOPPY_DISK)
365365 if(drv < USE_FLOPPY_DISK) {
366366 const _TCHAR* path = (const _TCHAR *)(name.toLocal8Bit().data());
367- emu->create_blank_floppy_disk(path, media_type);
368- emit sig_open_disk(drv, name, 0);
367+ if(emu->create_blank_floppy_disk(path, media_type)) {
368+ emit sig_open_disk(drv, name, 0);
369+ }
370+ }
371+#endif
372+ }
373+}
374+
375+void Ui_MainWindow::do_create_hard_disk(int drv, int sector_size, int sectors, int surfaces, int cylinders, QString name)
376+{
377+ if(!(name.isEmpty()) && (drv >= 0)) {
378+#if defined(USE_HARD_DISK)
379+ if(drv < USE_HARD_DISK) {
380+ const _TCHAR* path = (const _TCHAR *)(name.toLocal8Bit().data());
381+ if(emu->create_blank_hard_disk(path, sector_size, sectors, surfaces, cylinders)) {
382+ emit sig_open_hard_disk(drv, name);
383+ }
369384 }
370385 #endif
371386 }
--- a/source/src/qt/gui/CMakeLists.txt
+++ b/source/src/qt/gui/CMakeLists.txt
@@ -1,6 +1,6 @@
11 message("* qt/gui")
22
3-set(THIS_LIB_VERSION 2.19.12)
3+set(THIS_LIB_VERSION 2.20.0)
44 #include(cotire)
55 #include(PrecompiledHeader)
66
--- a/source/src/qt/gui/mainwidget_base.h
+++ b/source/src/qt/gui/mainwidget_base.h
@@ -668,6 +668,8 @@ public slots:
668668 void eject_fd(int drv);
669669 void eject_hard_disk(int drv);
670670 virtual void do_create_d88_media(int drv, quint8 media_type, QString name) { }
671+ virtual void do_create_hard_disk(int drv, int sector_size, int sectors, int surfaces, int cylinders, QString name) { }
672+
671673 // Bubble Casette
672674 int write_protect_bubble(int drv, bool flag);
673675
--- a/source/src/qt/gui/menu_harddisk.cpp
+++ b/source/src/qt/gui/menu_harddisk.cpp
@@ -24,16 +24,22 @@ Menu_HDDClass::~Menu_HDDClass()
2424
2525 void Menu_HDDClass::create_pulldown_menu_device_sub(void)
2626 {
27+ action_create_hdd = new Action_Control(p_wid, using_flags);
28+ action_create_hdd->setVisible(true);
29+ action_create_hdd->setCheckable(false);
2730 }
2831
2932
3033 void Menu_HDDClass::connect_menu_device_sub(void)
3134 {
3235 this->addSeparator();
36+ this->addAction(action_create_hdd);
37+ this->addSeparator();
3338
3439 connect(this, SIGNAL(sig_open_media(int, QString)), p_wid, SLOT(_open_hard_disk(int, QString)));
3540 connect(this, SIGNAL(sig_eject_media(int)), p_wid, SLOT(eject_hard_disk(int)));
3641 connect(this, SIGNAL(sig_set_recent_media(int, int)), p_wid, SLOT(set_recent_hard_disk(int, int)));
42+ connect(action_create_hdd, SIGNAL(triggered()), this, SLOT(do_open_dialog_create_hd()));
3743 }
3844
3945 void Menu_HDDClass::retranslate_pulldown_menu_device_sub(void)
@@ -45,4 +51,52 @@ void Menu_HDDClass::retranslate_pulldown_menu_device_sub(void)
4551 action_eject->setText(QApplication::translate("MenuHDD", "Unmount", 0));
4652 action_eject->setToolTip(QApplication::translate("MenuHDD", "Unmount virtual hard disk.", 0));
4753
54+ action_create_hdd->setText(QApplication::translate("MenuHDD", "Create Virtual HDD", 0));
55+ action_create_hdd->setToolTip(QApplication::translate("MenuHDD", "Create and mount virtual blank-hard disk.\nThis makes only NHD/HDI format.", 0));
4856 }
57+
58+void Menu_HDDClass::do_open_dialog_create_hd()
59+{
60+ CSP_CreateHardDiskDialog dlg(512, 15, 4, 1024);
61+
62+ if(initial_dir.isEmpty()) {
63+ QDir dir;
64+ char app[PATH_MAX];
65+ initial_dir = dir.currentPath();
66+ strncpy(app, initial_dir.toLocal8Bit().constData(), PATH_MAX - 1);
67+ initial_dir = QString::fromLocal8Bit(get_parent_dir(app));
68+ }
69+ dlg.dlg->setDirectory(initial_dir);
70+ QString create_ext = QString::fromUtf8("*.nhd *.hdi");
71+ QString create_desc = QString::fromUtf8("Virtual HARDDISK Image.");
72+ QString all = QString::fromUtf8("All Files (*.*)");
73+ QString tmps = create_desc;
74+ tmps.append(QString::fromUtf8(" ("));
75+ tmps.append(create_ext.toLower());
76+ tmps.append(QString::fromUtf8(" "));
77+ tmps.append(create_ext.toUpper());
78+ tmps.append(QString::fromUtf8(")"));
79+ QStringList __filter;
80+ __filter.clear();
81+ __filter << tmps;
82+ __filter << all;
83+ __filter.removeDuplicates();
84+ dlg.dlg->setNameFilters(__filter);
85+
86+ tmps.clear();
87+ tmps = QApplication::translate("MenuMedia", "Create NHD/HDI Virtual HARDDISK", 0);
88+ if(!window_title.isEmpty()) {
89+ tmps = tmps + QString::fromUtf8(" ") + window_title;
90+ } else {
91+ tmps = tmps + QString::fromUtf8(" ") + this->title();
92+ }
93+ dlg.dlg->setWindowTitle(tmps);
94+
95+// QObject::connect(&dlg, SIGNAL(sig_create_disk(QString)), this, SLOT(do_create_media(QString)));
96+// QObject::connect(this, SIGNAL(sig_create_d88_media(int, quint8, QString)), p_wid, SLOT(do_create_d88_media(int, quint8, QString)));
97+
98+ dlg.show();
99+ dlg.dlg->exec();
100+ return;
101+}
102+
--- a/source/src/qt/gui/menu_harddisk.h
+++ b/source/src/qt/gui/menu_harddisk.h
@@ -16,12 +16,17 @@ QT_BEGIN_NAMESPACE
1616 class DLL_PREFIX Menu_HDDClass: public Menu_MetaClass {
1717 Q_OBJECT
1818 protected:
19+ class Action_Control *action_create_hdd;
1920 public:
2021 Menu_HDDClass(QMenuBar *root_entry, QString desc, USING_FLAGS *p, QWidget *parent = 0, int drv = 0, int base_drv = 1);
2122 ~Menu_HDDClass();
2223 void create_pulldown_menu_device_sub();
2324 void connect_menu_device_sub(void);
2425 void retranslate_pulldown_menu_device_sub(void);
26+public slots:
27+ void do_open_dialog_create_hd();
28+signals:
29+// int sig_create_media(int, quint8, QString);
2530 };
2631
2732 QT_END_NAMESPACE
--- a/source/src/qt/gui/qt_dialogs.cpp
+++ b/source/src/qt/gui/qt_dialogs.cpp
@@ -72,3 +72,145 @@ CSP_CreateDiskDialog::CSP_CreateDiskDialog(bool *masks, QWidget *parent) : QWidg
7272
7373 }
7474
75+CSP_CreateHardDiskDialog::CSP_CreateHardDiskDialog(int sector_size, int sectors, int surfaces, int cylinders, QWidget *parent) : QWidget(parent)
76+{
77+ dlg = new QFileDialog(NULL, Qt::Widget);
78+ dlg->setParent(this);
79+ dlg->setOption(QFileDialog::ReadOnly, false);
80+ dlg->setOption(QFileDialog::DontConfirmOverwrite, false);
81+ dlg->setOption(QFileDialog::DontUseNativeDialog, true);
82+ dlg->setAcceptMode(QFileDialog::AcceptSave);
83+ dlg->setFileMode(QFileDialog::AnyFile);
84+
85+ if(sector_size < 0) sector_size = 0;
86+ if(sector_size > 4) sector_size = 4;
87+ _sector_size.addItem(QString::fromUtf8("256bytes"));
88+ _sector_size.addItem(QString::fromUtf8("512bytes"));
89+ _sector_size.addItem(QString::fromUtf8("1024bytes"));
90+ _sector_size.addItem(QString::fromUtf8("2048bytes"));
91+ _sector_size.addItem(QString::fromUtf8("4096bytes"));
92+ _sectors.setRange(15, 33);
93+ _surfaces.setRange(2, 16);
94+ _cylinders.setRange(128, 16383);
95+
96+ _label_sector_size.setText(QString::fromUtf8("Sector Size"));
97+ _label_sectors.setText(QString::fromUtf8("Sector in cylinder"));
98+ _label_surfaces.setText(QString::fromUtf8("Heads"));
99+ _label_cylinders.setText(QString::fromUtf8("Cylinders"));
100+ _label_preset_type.setText(QString::fromUtf8("Preset size"));
101+
102+ if(sectors < 15) sectors = 15;
103+ if(sectors > 33) sectors = 33;
104+ if(surfaces < 2) surfaces = 2;
105+ if(surfaces > 16) surfaces = 16;
106+ if(cylinders < 128) cylinders = 128;
107+ if(cylinders > 16383) cylinders = 16383;
108+
109+ // Preset:
110+ // 10MB
111+ // 20MB
112+ // 40MB
113+ // 80MB
114+ // 100MB
115+ // 200MB
116+ // 320MB
117+ // 500MB
118+ // 540MB
119+ _preset_type.addItem(QString::fromUtf8("10MB"));
120+ _preset_type.addItem(QString::fromUtf8("20MB"));
121+ _preset_type.addItem(QString::fromUtf8("40MB"));
122+ _preset_type.addItem(QString::fromUtf8("80MB"));
123+ _preset_type.addItem(QString::fromUtf8("100MB"));
124+ _preset_type.addItem(QString::fromUtf8("200MB"));
125+ _preset_type.addItem(QString::fromUtf8("320MB"));
126+ _preset_type.addItem(QString::fromUtf8("500MB"));
127+ _preset_type.addItem(QString::fromUtf8("540MB"));
128+ _size_label_label.setText(QString::fromUtf8("Total Size:"));
129+
130+ layout.addWidget(&_label_preset_type, 1, 0);
131+ layout.addWidget(&_preset_type, 1, 1);
132+ layout.addWidget(&_label_sector_size, 2, 0);
133+ layout.addWidget(&_sector_size, 2, 1);
134+ layout.addWidget(&_label_sectors, 2, 2);
135+ layout.addWidget(&_sectors, 2, 3);
136+
137+ layout.addWidget(&_label_surfaces, 3, 0);
138+ layout.addWidget(&_surfaces, 3, 1);
139+ layout.addWidget(&_label_cylinders, 3, 2);
140+ layout.addWidget(&_cylinders, 3, 3);
141+ layout.addWidget(&_size_label_label, 4, 2);
142+ layout.addWidget(&_size_label, 4, 3);
143+ layout.addWidget(dlg, 5, 0, 5, 4);
144+
145+ this->setLayout(&layout);
146+ connect(&_preset_type, SIGNAL(activated(int)), this, SLOT(do_preset(int)));
147+ connect(this, SIGNAL(sig_update_total_size(uint64_t)), this, SLOT(do_update_total_size(uint64_t)));
148+// connect(&_sector_size, SIGNAL(activated(int)), this, SLOT(do_change_sector_size(int)));
149+ connect(&_sector_size, SIGNAL(activated(int)), this, SLOT(do_update_values(int)));
150+ connect(&_sectors, SIGNAL(valueChanged(int)), this, SLOT(do_update_values(int)));
151+ connect(&_surfaces, SIGNAL(valueChanged(int)), this, SLOT(do_update_values(int)));
152+ connect(&_cylinders, SIGNAL(valueChanged(int)), this, SLOT(do_update_values(int)));
153+ connect(dlg, SIGNAL(fileSelected(QString)), this, SLOT(do_create_disk(QString)));
154+
155+ do_preset(0); // Update label.
156+}
157+
158+void CSP_CreateHardDiskDialog::do_create_disk(QString filename)
159+{
160+ int secnum = _sector_size.currentIndex();
161+ if(secnum < 0) secnum = 0;
162+ if(secnum > 4) secnum = 4;
163+ static const uint64_t valtbl_sec[] = { 256, 512, 1024, 2048, 4096 };
164+ int secsize = valtbl_sec[secnum];
165+ int secs = _sectors.value();
166+ int heads = _surfaces.value();
167+ int cyl = _cylinders.value();
168+
169+ printf("ToDo: Will create media.Filename = %s SEC_SIZE=%d SECS=%d SURFACES=%d CYL=%d\n",
170+ filename.toLocal8Bit().constData(), secsize, secs, heads, cyl);
171+// emit sig_create_disk(secsize, secs, heads, cyl, filename);
172+}
173+
174+void CSP_CreateHardDiskDialog::do_update_values(int dummy)
175+{
176+ int secnum = _sector_size.currentIndex();
177+ int heads = _surfaces.value();
178+ int secs = _sectors.value();
179+ int cyl = _cylinders.value();
180+ static const uint64_t secsize[] = {256, 512, 1024, 2048, 4096};
181+ if(secnum < 0) secnum = 0;
182+ if(secnum > 4) secnum = 4;
183+ uint64_t totalsize = (secsize[secnum] * (uint64_t)secs * (uint64_t)heads * (uint64_t)cyl);
184+ do_update_total_size(totalsize);
185+}
186+void CSP_CreateHardDiskDialog::do_preset(int num)
187+{
188+ if(num >= _preset_type.count()) num = _preset_type.count() - 1;
189+ if(num < 0) num = 0;
190+
191+ static const uint64_t valtbl[] = { 10, 20, 40, 80, 100, 200, 320, 500, 540 };
192+ uint64_t total_size = valtbl[num] * 1024 * 1024;
193+ uint64_t sectors_in_track = 15;
194+ uint64_t __heads = 4;
195+ uint64_t cyl;
196+ if(total_size > (100 * 1024 * 1024)) {
197+ sectors_in_track = 33;
198+ __heads = 8;
199+ }
200+ if(total_size > (300 * 1024 * 1024)) {
201+ __heads = 15;
202+ }
203+ cyl = (total_size / (512 * sectors_in_track * __heads)) + 1;
204+ _sector_size.setCurrentIndex(1); // 512bytes
205+ _sectors.setValue((int)sectors_in_track);
206+ _surfaces.setValue((int)__heads);
207+ _cylinders.setValue((int)cyl);
208+ emit sig_update_total_size(total_size);
209+}
210+
211+void CSP_CreateHardDiskDialog::do_update_total_size(uint64_t size)
212+{
213+ uint64_t nsize = size / (1024 * 1024);
214+ QString label = QString("%1MB (%2bytes)").arg(nsize).arg(size);
215+ _size_label.setText(label);
216+}
--- a/source/src/qt/gui/qt_dialogs.h
+++ b/source/src/qt/gui/qt_dialogs.h
@@ -12,6 +12,7 @@
1212
1313 #include <QFileDialog>
1414 #include <QComboBox>
15+#include <QSpinBox>
1516 #include <QGridLayout>
1617 #include <QLabel>
1718 #include <QApplication>
@@ -97,6 +98,40 @@ public slots:
9798 }
9899 };
99100
101+class CSP_CreateHardDiskDialog : public QWidget {
102+ Q_OBJECT
103+ QComboBox _preset_type;
104+ QComboBox _sector_size;
105+ QSpinBox _sectors;
106+ QSpinBox _surfaces;
107+ QSpinBox _cylinders;
108+
109+ QLabel _label_preset_type;
110+ QLabel _label_sector_size;
111+ QLabel _label_sectors;
112+ QLabel _label_surfaces;
113+ QLabel _label_cylinders;
114+ QLabel type_label;
115+ QLabel _size_label_label;
116+ QLabel _size_label;
117+
118+ QGridLayout layout;
119+public:
120+ QFileDialog* dlg;
121+ CSP_CreateHardDiskDialog(int secsize, int sectors, int surfaces, int cylinders, QWidget *parent = 0);
122+ ~CSP_CreateHardDiskDialog() {
123+ delete dlg;
124+ }
125+signals:
126+ int sig_update_total_size(uint64_t);
127+ int sig_create_disk(int, int, int, int, QString);
128+public slots:
129+ void do_preset(int num);
130+ void do_update_total_size(uint64_t size);
131+ void do_create_disk(QString filename);
132+ void do_update_values(int dummy);
133+};
134+
100135 QT_END_NAMESPACE
101136
102137 #endif //End.
Show on old repository browser