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:
Le Tan 2016-11-06 15:36:30 +08:00
parent 29a41e8285
commit db0797a538
4 changed files with 70 additions and 2 deletions

View 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

View File

@ -46,8 +46,17 @@ void VEditWindow::setupCornerWidget()
rightMenu->addAction(splitAct);
rightMenu->addAction(removeSplitAct);
rightBtn->setMenu(rightMenu);
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()
@ -124,6 +133,8 @@ void VEditWindow::closeFile(const QString &notebook, const QString &relativePath
Q_ASSERT(editor);
removeTab(idx);
delete editor;
updateTabListMenu();
}
bool VEditWindow::closeAllFiles()
@ -159,7 +170,9 @@ int VEditWindow::openFileInTab(const QString &notebook, const QString &relativeP
tabJson["notebook"] = notebook;
tabJson["relative_path"] = relativePath;
tabJson["modifiable"] = modifiable;
return appendTabWithData(editor, tabJson);
int idx = appendTabWithData(editor, tabJson);
updateTabListMenu();
return idx;
}
int VEditWindow::findTabByFile(const QString &notebook, const QString &relativePath) const
@ -186,6 +199,7 @@ bool VEditWindow::handleTabCloseRequest(int index)
removeTab(index);
delete editor;
}
updateTabListMenu();
noticeTabStatus(currentIndex());
// User clicks the close button. We should make this window
// to be current window.
@ -306,3 +320,39 @@ void VEditWindow::contextMenuRequested(QPoint pos)
menu.addAction(removeSplitAct);
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);
}
}

View File

@ -11,6 +11,7 @@
class VNote;
class QPushButton;
class QActionGroup;
class VEditWindow : public QTabWidget
{
@ -52,6 +53,7 @@ private slots:
void removeSplit();
void handleTabbarClicked(int index);
void contextMenuRequested(QPoint pos);
void tabListJump(QAction *action);
private:
void setupCornerWidget();
@ -62,14 +64,18 @@ private:
inline QString getFileName(const QString &relativePath) const;
inline VEditTab *getTab(int tabIndex) const;
void noticeTabStatus(int index);
void updateTabListMenu();
VNote *vnote;
// Button in the right corner
QPushButton *rightBtn;
// Button in the left corner
QPushButton *leftBtn;
// Actions
QAction *splitAct;
QAction *removeSplitAct;
QActionGroup *tabListAct;
};
inline QString VEditWindow::getFileName(const QString &path) const

View File

@ -56,5 +56,6 @@
<file>resources/icons/split_window.svg</file>
<file>resources/icons/corner_menu.svg</file>
<file>resources/icons/remove_split.svg</file>
<file>resources/icons/corner_tablist.svg</file>
</qresource>
</RCC>