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 <QStringList>
|
||||||
#include <QListView>
|
#include <QListView>
|
||||||
#include <QWindow>
|
#include <QWindow>
|
||||||
|
#include <QMenuBar>
|
||||||
|
#include <QMenu>
|
||||||
|
#include <QFileDialog>
|
||||||
#include <qabstractitemmodel.h>
|
#include <qabstractitemmodel.h>
|
||||||
|
|
||||||
#include "api.h"
|
#include "api.h"
|
||||||
@@ -73,7 +76,8 @@ struct Page {
|
|||||||
};
|
};
|
||||||
|
|
||||||
QString workingPath = "/home/jorenchik/Code/mdemory/memorybase";
|
QString workingPath = "/home/jorenchik/Code/mdemory/memorybase";
|
||||||
std::string currentPath = "";
|
std::string currentPath = "/home/jorenchik/Code/mdemory/memorybase";
|
||||||
|
QFileSystemModel *model;
|
||||||
|
|
||||||
// Mdem list
|
// Mdem list
|
||||||
QLabel *deckListLabel;
|
QLabel *deckListLabel;
|
||||||
@@ -462,8 +466,30 @@ int main(int argc, char *argv[]) {
|
|||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
QMainWindow window;
|
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
|
// LeftSide
|
||||||
QWidget *leftWidget = new QWidget();
|
QWidget *leftWidget = new QWidget();
|
||||||
@@ -471,8 +497,11 @@ int main(int argc, char *argv[]) {
|
|||||||
QWidget *leftTop = new QWidget();
|
QWidget *leftTop = new QWidget();
|
||||||
QVBoxLayout *vLeftTop = new QVBoxLayout();
|
QVBoxLayout *vLeftTop = new QVBoxLayout();
|
||||||
QLabel *mdemLabel = new QLabel("mdems");
|
QLabel *mdemLabel = new QLabel("mdems");
|
||||||
QFileSystemModel *model = new QFileSystemModel();
|
|
||||||
QTreeView *mdemList = new QTreeView();
|
QTreeView *mdemList = new QTreeView();
|
||||||
|
model = new QFileSystemModel();
|
||||||
|
if (workingPath.length() > 0) {
|
||||||
|
model->setRootPath(workingPath);
|
||||||
|
}
|
||||||
mdemLabel->setStyleSheet(
|
mdemLabel->setStyleSheet(
|
||||||
"font-size: 17px;"
|
"font-size: 17px;"
|
||||||
"font-weight: 400;"
|
"font-weight: 400;"
|
||||||
@@ -484,14 +513,13 @@ int main(int argc, char *argv[]) {
|
|||||||
leftTop->setLayout(vLeftTop);
|
leftTop->setLayout(vLeftTop);
|
||||||
leftTop->setMinimumSize(0, 40);
|
leftTop->setMinimumSize(0, 40);
|
||||||
vLeftTop->addWidget(mdemLabel);
|
vLeftTop->addWidget(mdemLabel);
|
||||||
model->setRootPath(workingPath);
|
|
||||||
// Hide all columns except the first one
|
// Hide all columns except the first one
|
||||||
mdemList->setModel(model);
|
mdemList->setModel(model);
|
||||||
|
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
mdemList,
|
mdemList,
|
||||||
&QTreeView::doubleClicked,
|
&QTreeView::doubleClicked,
|
||||||
[model](const QModelIndex &index) {
|
[](const QModelIndex &index) {
|
||||||
auto fileInfo = model->fileInfo(index);
|
auto fileInfo = model->fileInfo(index);
|
||||||
currentPath = fileInfo.filePath().toStdString();
|
currentPath = fileInfo.filePath().toStdString();
|
||||||
loadMdem();
|
loadMdem();
|
||||||
|
|||||||
Reference in New Issue
Block a user