mirror of
https://github.com/jorenchik/mdemory.git
synced 2026-03-22 00:26:21 +00:00
menu and directory chooser
This commit is contained in:
@@ -36,6 +36,9 @@
|
||||
#include <QStringList>
|
||||
#include <QListView>
|
||||
#include <QWindow>
|
||||
#include <QMenuBar>
|
||||
#include <QMenu>
|
||||
#include <QFileDialog>
|
||||
#include <qabstractitemmodel.h>
|
||||
|
||||
#include "api.h"
|
||||
@@ -73,7 +76,8 @@ struct Page {
|
||||
};
|
||||
|
||||
QString workingPath = "/home/jorenchik/Code/mdemory/memorybase";
|
||||
std::string currentPath = "";
|
||||
std::string currentPath = "/home/jorenchik/Code/mdemory/memorybase";
|
||||
QFileSystemModel *model;
|
||||
|
||||
// Mdem list
|
||||
QLabel *deckListLabel;
|
||||
@@ -462,8 +466,30 @@ int main(int argc, char *argv[]) {
|
||||
QApplication app(argc, argv);
|
||||
QMainWindow window;
|
||||
|
||||
QSplitter *hSplitter = new QSplitter();
|
||||
QMenuBar *menuBar = new QMenuBar;
|
||||
QFileDialog *fileDialog = new QFileDialog;
|
||||
|
||||
QMenu *menu = new QMenu("File");
|
||||
QAction *actionOpen = menu->addAction("Open memorybase");
|
||||
QObject::connect(actionOpen, &QAction::triggered, [fileDialog]() {
|
||||
fileDialog->setDirectory(QDir::homePath());
|
||||
fileDialog->setFileMode(QFileDialog::FileMode::Directory);
|
||||
fileDialog->open();
|
||||
QObject::disconnect(fileDialog, 0, 0, 0);
|
||||
fileDialog->connect(
|
||||
fileDialog,
|
||||
&QFileDialog::fileSelected,
|
||||
[](QString directory
|
||||
) {
|
||||
workingPath = directory;
|
||||
model->setRootPath(workingPath);
|
||||
});
|
||||
});
|
||||
menuBar->addMenu(menu);
|
||||
|
||||
window.setMenuBar(menuBar);
|
||||
|
||||
QSplitter *hSplitter = new QSplitter();
|
||||
|
||||
// LeftSide
|
||||
QWidget *leftWidget = new QWidget();
|
||||
@@ -471,8 +497,11 @@ int main(int argc, char *argv[]) {
|
||||
QWidget *leftTop = new QWidget();
|
||||
QVBoxLayout *vLeftTop = new QVBoxLayout();
|
||||
QLabel *mdemLabel = new QLabel("mdems");
|
||||
QFileSystemModel *model = new QFileSystemModel();
|
||||
QTreeView *mdemList = new QTreeView();
|
||||
model = new QFileSystemModel();
|
||||
if (workingPath.length() > 0) {
|
||||
model->setRootPath(workingPath);
|
||||
}
|
||||
mdemLabel->setStyleSheet(
|
||||
"font-size: 17px;"
|
||||
"font-weight: 400;"
|
||||
@@ -484,14 +513,13 @@ int main(int argc, char *argv[]) {
|
||||
leftTop->setLayout(vLeftTop);
|
||||
leftTop->setMinimumSize(0, 40);
|
||||
vLeftTop->addWidget(mdemLabel);
|
||||
model->setRootPath(workingPath);
|
||||
// Hide all columns except the first one
|
||||
mdemList->setModel(model);
|
||||
|
||||
QObject::connect(
|
||||
mdemList,
|
||||
&QTreeView::doubleClicked,
|
||||
[model](const QModelIndex &index) {
|
||||
[](const QModelIndex &index) {
|
||||
auto fileInfo = model->fileInfo(index);
|
||||
currentPath = fileInfo.filePath().toStdString();
|
||||
loadMdem();
|
||||
|
||||
Reference in New Issue
Block a user