mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
remove buttons in VFileList
Signed-off-by: Le Tan <tamlokveer@gmail.com>
This commit is contained in:
parent
99353c37bd
commit
dce6396874
@ -15,34 +15,12 @@ VFileList::VFileList(VNote *vnote, QWidget *parent)
|
|||||||
|
|
||||||
void VFileList::setupUI()
|
void VFileList::setupUI()
|
||||||
{
|
{
|
||||||
newFileBtn = new QPushButton(QIcon(":/resources/icons/create_note.svg"), "");
|
|
||||||
newFileBtn->setToolTip(tr("Create a new note"));
|
|
||||||
deleteFileBtn = new QPushButton(QIcon(":/resources/icons/delete_note.svg"), "");
|
|
||||||
deleteFileBtn->setToolTip(tr("Delete current note"));
|
|
||||||
fileInfoBtn = new QPushButton(QIcon(":/resources/icons/note_info.svg"), "");
|
|
||||||
fileInfoBtn->setToolTip(tr("View and edit current note's information"));
|
|
||||||
|
|
||||||
fileList = new QListWidget(this);
|
fileList = new QListWidget(this);
|
||||||
fileList->setContextMenuPolicy(Qt::CustomContextMenu);
|
fileList->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
|
|
||||||
QHBoxLayout *topLayout = new QHBoxLayout;
|
|
||||||
topLayout->addStretch();
|
|
||||||
topLayout->addWidget(newFileBtn);
|
|
||||||
topLayout->addWidget(deleteFileBtn);
|
|
||||||
topLayout->addWidget(fileInfoBtn);
|
|
||||||
|
|
||||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||||
mainLayout->addLayout(topLayout);
|
|
||||||
mainLayout->addWidget(fileList);
|
mainLayout->addWidget(fileList);
|
||||||
|
|
||||||
// Signals
|
|
||||||
connect(newFileBtn, &QPushButton::clicked,
|
|
||||||
this, &VFileList::onNewFileBtnClicked);
|
|
||||||
connect(deleteFileBtn, &QPushButton::clicked,
|
|
||||||
this, &VFileList::onDeleteFileBtnClicked);
|
|
||||||
connect(fileInfoBtn, &QPushButton::clicked,
|
|
||||||
this, &VFileList::onFileInfoBtnClicked);
|
|
||||||
|
|
||||||
connect(fileList, &QListWidget::customContextMenuRequested,
|
connect(fileList, &QListWidget::customContextMenuRequested,
|
||||||
this, &VFileList::contextMenuRequested);
|
this, &VFileList::contextMenuRequested);
|
||||||
connect(fileList, &QListWidget::itemClicked,
|
connect(fileList, &QListWidget::itemClicked,
|
||||||
@ -53,15 +31,23 @@ void VFileList::setupUI()
|
|||||||
|
|
||||||
void VFileList::initActions()
|
void VFileList::initActions()
|
||||||
{
|
{
|
||||||
newFileAct = new QAction(tr("&New note"), this);
|
newFileAct = new QAction(QIcon(":/resources/icons/create_note.svg"),
|
||||||
|
tr("&New note"), this);
|
||||||
newFileAct->setStatusTip(tr("Create a new note in current directory"));
|
newFileAct->setStatusTip(tr("Create a new note in current directory"));
|
||||||
connect(newFileAct, SIGNAL(triggered(bool)),
|
connect(newFileAct, SIGNAL(triggered(bool)),
|
||||||
this, SLOT(newFile()));
|
this, SLOT(newFile()));
|
||||||
|
|
||||||
deleteFileAct = new QAction(tr("&Delete"), this);
|
deleteFileAct = new QAction(QIcon(":/resources/icons/delete_note.svg"),
|
||||||
|
tr("&Delete"), this);
|
||||||
deleteFileAct->setStatusTip(tr("Delete selected note"));
|
deleteFileAct->setStatusTip(tr("Delete selected note"));
|
||||||
connect(deleteFileAct, &QAction::triggered,
|
connect(deleteFileAct, &QAction::triggered,
|
||||||
this, &VFileList::deleteFile);
|
this, &VFileList::deleteFile);
|
||||||
|
|
||||||
|
fileInfoAct = new QAction(QIcon(":/resources/icons/note_info.svg"),
|
||||||
|
tr("&Info"), this);
|
||||||
|
fileInfoAct->setStatusTip(tr("View and edit current note's information"));
|
||||||
|
connect(fileInfoAct, &QAction::triggered,
|
||||||
|
this, &VFileList::fileInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VFileList::setDirectory(QJsonObject dirJson)
|
void VFileList::setDirectory(QJsonObject dirJson)
|
||||||
@ -128,29 +114,9 @@ void VFileList::updateFileList()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void VFileList::onNewFileBtnClicked()
|
void VFileList::fileInfo()
|
||||||
{
|
|
||||||
if (relativePath.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
newFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
void VFileList::onDeleteFileBtnClicked()
|
|
||||||
{
|
{
|
||||||
QListWidgetItem *curItem = fileList->currentItem();
|
QListWidgetItem *curItem = fileList->currentItem();
|
||||||
if (!curItem) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
deleteFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
void VFileList::onFileInfoBtnClicked()
|
|
||||||
{
|
|
||||||
QListWidgetItem *curItem = fileList->currentItem();
|
|
||||||
if (!curItem) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
QJsonObject curItemJson = curItem->data(Qt::UserRole).toJsonObject();
|
QJsonObject curItemJson = curItem->data(Qt::UserRole).toJsonObject();
|
||||||
Q_ASSERT(!curItemJson.isEmpty());
|
Q_ASSERT(!curItemJson.isEmpty());
|
||||||
QString curItemName = curItemJson["name"].toString();
|
QString curItemName = curItemJson["name"].toString();
|
||||||
@ -269,6 +235,7 @@ void VFileList::contextMenuRequested(QPoint pos)
|
|||||||
menu.addAction(newFileAct);
|
menu.addAction(newFileAct);
|
||||||
if (item) {
|
if (item) {
|
||||||
menu.addAction(deleteFileAct);
|
menu.addAction(deleteFileAct);
|
||||||
|
menu.addAction(fileInfoAct);
|
||||||
}
|
}
|
||||||
|
|
||||||
menu.exec(fileList->mapToGlobal(pos));
|
menu.exec(fileList->mapToGlobal(pos));
|
||||||
|
@ -31,9 +31,7 @@ signals:
|
|||||||
private slots:
|
private slots:
|
||||||
void contextMenuRequested(QPoint pos);
|
void contextMenuRequested(QPoint pos);
|
||||||
void handleItemClicked(QListWidgetItem *currentItem);
|
void handleItemClicked(QListWidgetItem *currentItem);
|
||||||
void onNewFileBtnClicked();
|
void fileInfo();
|
||||||
void onDeleteFileBtnClicked();
|
|
||||||
void onFileInfoBtnClicked();
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setDirectory(QJsonObject dirJson);
|
void setDirectory(QJsonObject dirJson);
|
||||||
@ -65,13 +63,11 @@ private:
|
|||||||
QString rootPath;
|
QString rootPath;
|
||||||
|
|
||||||
QListWidget *fileList;
|
QListWidget *fileList;
|
||||||
QPushButton *newFileBtn;
|
|
||||||
QPushButton *deleteFileBtn;
|
|
||||||
QPushButton *fileInfoBtn;
|
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
QAction *newFileAct;
|
QAction *newFileAct;
|
||||||
QAction *deleteFileAct;
|
QAction *deleteFileAct;
|
||||||
|
QAction *fileInfoAct;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline QString VFileList::getDirectoryName()
|
inline QString VFileList::getDirectoryName()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user