mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
add left corner widget to VEditWindow to display a list of tab
Signed-off-by: Le Tan <tamlokveer@gmail.com>
This commit is contained in:
parent
29a41e8285
commit
db0797a538
11
src/resources/icons/corner_tablist.svg
Normal file
11
src/resources/icons/corner_tablist.svg
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Generator: Adobe Illustrator 16.2.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||||
|
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||||
|
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||||
|
width="512px" height="512px" viewBox="0 0 512 512" style="enable-background:new 0 0 512 512;" xml:space="preserve">
|
||||||
|
<g>
|
||||||
|
<path d="M464,144v288H48V144H464 M480,128H32v320h448V128L480,128z"/>
|
||||||
|
<rect x="72" y="96" width="368" height="16"/>
|
||||||
|
<rect x="104" y="64" width="304" height="16"/>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 669 B |
@ -46,8 +46,17 @@ void VEditWindow::setupCornerWidget()
|
|||||||
rightMenu->addAction(splitAct);
|
rightMenu->addAction(splitAct);
|
||||||
rightMenu->addAction(removeSplitAct);
|
rightMenu->addAction(removeSplitAct);
|
||||||
rightBtn->setMenu(rightMenu);
|
rightBtn->setMenu(rightMenu);
|
||||||
|
|
||||||
setCornerWidget(rightBtn, Qt::TopRightCorner);
|
setCornerWidget(rightBtn, Qt::TopRightCorner);
|
||||||
|
|
||||||
|
// Left corner button
|
||||||
|
tabListAct = new QActionGroup(this);
|
||||||
|
connect(tabListAct, &QActionGroup::triggered,
|
||||||
|
this, &VEditWindow::tabListJump);
|
||||||
|
leftBtn = new QPushButton(QIcon(":/resources/icons/corner_tablist.svg"),
|
||||||
|
"", this);
|
||||||
|
QMenu *leftMenu = new QMenu(this);
|
||||||
|
leftBtn->setMenu(leftMenu);
|
||||||
|
setCornerWidget(leftBtn, Qt::TopLeftCorner);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VEditWindow::splitWindow()
|
void VEditWindow::splitWindow()
|
||||||
@ -124,6 +133,8 @@ void VEditWindow::closeFile(const QString ¬ebook, const QString &relativePath
|
|||||||
Q_ASSERT(editor);
|
Q_ASSERT(editor);
|
||||||
removeTab(idx);
|
removeTab(idx);
|
||||||
delete editor;
|
delete editor;
|
||||||
|
|
||||||
|
updateTabListMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VEditWindow::closeAllFiles()
|
bool VEditWindow::closeAllFiles()
|
||||||
@ -159,7 +170,9 @@ int VEditWindow::openFileInTab(const QString ¬ebook, const QString &relativeP
|
|||||||
tabJson["notebook"] = notebook;
|
tabJson["notebook"] = notebook;
|
||||||
tabJson["relative_path"] = relativePath;
|
tabJson["relative_path"] = relativePath;
|
||||||
tabJson["modifiable"] = modifiable;
|
tabJson["modifiable"] = modifiable;
|
||||||
return appendTabWithData(editor, tabJson);
|
int idx = appendTabWithData(editor, tabJson);
|
||||||
|
updateTabListMenu();
|
||||||
|
return idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
int VEditWindow::findTabByFile(const QString ¬ebook, const QString &relativePath) const
|
int VEditWindow::findTabByFile(const QString ¬ebook, const QString &relativePath) const
|
||||||
@ -186,6 +199,7 @@ bool VEditWindow::handleTabCloseRequest(int index)
|
|||||||
removeTab(index);
|
removeTab(index);
|
||||||
delete editor;
|
delete editor;
|
||||||
}
|
}
|
||||||
|
updateTabListMenu();
|
||||||
noticeTabStatus(currentIndex());
|
noticeTabStatus(currentIndex());
|
||||||
// User clicks the close button. We should make this window
|
// User clicks the close button. We should make this window
|
||||||
// to be current window.
|
// to be current window.
|
||||||
@ -306,3 +320,39 @@ void VEditWindow::contextMenuRequested(QPoint pos)
|
|||||||
menu.addAction(removeSplitAct);
|
menu.addAction(removeSplitAct);
|
||||||
menu.exec(this->mapToGlobal(pos));
|
menu.exec(this->mapToGlobal(pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VEditWindow::tabListJump(QAction *action)
|
||||||
|
{
|
||||||
|
if (!action) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonObject tabJson = action->data().toJsonObject();
|
||||||
|
int idx = findTabByFile(tabJson["notebook"].toString(),
|
||||||
|
tabJson["relative_path"].toString());
|
||||||
|
Q_ASSERT(idx >= 0);
|
||||||
|
setCurrentIndex(idx);
|
||||||
|
noticeTabStatus(idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
void VEditWindow::updateTabListMenu()
|
||||||
|
{
|
||||||
|
// Re-generate the tab list menu
|
||||||
|
QMenu *menu = leftBtn->menu();
|
||||||
|
QList<QAction *> actions = menu->actions();
|
||||||
|
int nrActions = actions.size();
|
||||||
|
for (int i = 0; i < nrActions; ++i) {
|
||||||
|
QAction *tmpAct = actions.at(i);
|
||||||
|
menu->removeAction(tmpAct);
|
||||||
|
tabListAct->removeAction(tmpAct);
|
||||||
|
delete tmpAct;
|
||||||
|
}
|
||||||
|
|
||||||
|
QTabBar *tabbar = tabBar();
|
||||||
|
int nrTab = tabbar->count();
|
||||||
|
for (int i = 0; i < nrTab; ++i) {
|
||||||
|
QAction *action = new QAction(tabbar->tabText(i), tabListAct);
|
||||||
|
action->setData(tabbar->tabData(i));
|
||||||
|
menu->addAction(action);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
class VNote;
|
class VNote;
|
||||||
class QPushButton;
|
class QPushButton;
|
||||||
|
class QActionGroup;
|
||||||
|
|
||||||
class VEditWindow : public QTabWidget
|
class VEditWindow : public QTabWidget
|
||||||
{
|
{
|
||||||
@ -52,6 +53,7 @@ private slots:
|
|||||||
void removeSplit();
|
void removeSplit();
|
||||||
void handleTabbarClicked(int index);
|
void handleTabbarClicked(int index);
|
||||||
void contextMenuRequested(QPoint pos);
|
void contextMenuRequested(QPoint pos);
|
||||||
|
void tabListJump(QAction *action);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupCornerWidget();
|
void setupCornerWidget();
|
||||||
@ -62,14 +64,18 @@ private:
|
|||||||
inline QString getFileName(const QString &relativePath) const;
|
inline QString getFileName(const QString &relativePath) const;
|
||||||
inline VEditTab *getTab(int tabIndex) const;
|
inline VEditTab *getTab(int tabIndex) const;
|
||||||
void noticeTabStatus(int index);
|
void noticeTabStatus(int index);
|
||||||
|
void updateTabListMenu();
|
||||||
|
|
||||||
VNote *vnote;
|
VNote *vnote;
|
||||||
// Button in the right corner
|
// Button in the right corner
|
||||||
QPushButton *rightBtn;
|
QPushButton *rightBtn;
|
||||||
|
// Button in the left corner
|
||||||
|
QPushButton *leftBtn;
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
QAction *splitAct;
|
QAction *splitAct;
|
||||||
QAction *removeSplitAct;
|
QAction *removeSplitAct;
|
||||||
|
QActionGroup *tabListAct;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline QString VEditWindow::getFileName(const QString &path) const
|
inline QString VEditWindow::getFileName(const QString &path) const
|
||||||
|
@ -56,5 +56,6 @@
|
|||||||
<file>resources/icons/split_window.svg</file>
|
<file>resources/icons/split_window.svg</file>
|
||||||
<file>resources/icons/corner_menu.svg</file>
|
<file>resources/icons/corner_menu.svg</file>
|
||||||
<file>resources/icons/remove_split.svg</file>
|
<file>resources/icons/remove_split.svg</file>
|
||||||
|
<file>resources/icons/corner_tablist.svg</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user