combine view panel actions in toolbar

Signed-off-by: Le Tan <tamlokveer@gmail.com>
This commit is contained in:
Le Tan 2016-12-10 17:24:33 +08:00
parent f36ed97694
commit 68e6a214e9
2 changed files with 52 additions and 30 deletions

View File

@ -171,26 +171,7 @@ void VMainWindow::initActions()
connect(saveNoteAct, &QAction::triggered, connect(saveNoteAct, &QAction::triggered,
editArea, &VEditArea::saveFile); editArea, &VEditArea::saveFile);
viewAct = new QActionGroup(this); initViewActions();
twoPanelViewAct = new QAction(QIcon(":/resources/icons/two_panels.svg"),
tr("&Two Panels"), viewAct);
twoPanelViewAct->setStatusTip(tr("Display the directory and notes browser panel"));
twoPanelViewAct->setCheckable(true);
twoPanelViewAct->setData(2);
onePanelViewAct = new QAction(QIcon(":/resources/icons/one_panel.svg"),
tr("&Single panel"), viewAct);
onePanelViewAct->setStatusTip(tr("Display only the notes browser panel"));
onePanelViewAct->setCheckable(true);
onePanelViewAct->setData(1);
expandViewAct = new QAction(QIcon(":/resources/icons/expand.svg"),
tr("&Expand"), viewAct);
expandViewAct->setStatusTip(tr("Expand the editing area"));
expandViewAct->setCheckable(true);
expandViewAct->setData(0);
connect(viewAct, &QActionGroup::triggered,
this, &VMainWindow::changePanelView);
// Must be called after setting up the signal to sync the state and settings
twoPanelViewAct->setChecked(true);
importNoteAct = new QAction(tr("&Import note from file"), this); importNoteAct = new QAction(tr("&Import note from file"), this);
importNoteAct->setStatusTip(tr("Import notes into current directory from files")); importNoteAct->setStatusTip(tr("Import notes into current directory from files"));
@ -249,6 +230,34 @@ void VMainWindow::initActions()
this, &VMainWindow::setRenderBackgroundColor); this, &VMainWindow::setRenderBackgroundColor);
} }
void VMainWindow::initViewActions()
{
onePanelViewAct = new QAction(QIcon(":/resources/icons/one_panel.svg"),
tr("&Single Panel"), this);
onePanelViewAct->setStatusTip(tr("Display only the notes browser panel"));
connect(onePanelViewAct, &QAction::triggered,
this, &VMainWindow::onePanelView);
twoPanelViewAct = new QAction(QIcon(":/resources/icons/two_panels.svg"),
tr("&Two Panels"), this);
twoPanelViewAct->setStatusTip(tr("Display the directory and notes browser panel"));
connect(twoPanelViewAct, &QAction::triggered,
this, &VMainWindow::twoPanelView);
QMenu *panelMenu = new QMenu(this);
panelMenu->addAction(onePanelViewAct);
panelMenu->addAction(twoPanelViewAct);
expandViewAct = new QAction(QIcon(":/resources/icons/expand.svg"),
tr("&Expand"), this);
expandViewAct->setStatusTip(tr("Expand the editing area"));
expandViewAct->setCheckable(true);
expandViewAct->setMenu(panelMenu);
connect(expandViewAct, &QAction::triggered,
this, &VMainWindow::expandPanelView);
}
void VMainWindow::initToolBar() void VMainWindow::initToolBar()
{ {
m_fileToolBar = addToolBar(tr("Note")); m_fileToolBar = addToolBar(tr("Note"));
@ -277,8 +286,6 @@ void VMainWindow::initToolBar()
m_viewToolBar = addToolBar(tr("View")); m_viewToolBar = addToolBar(tr("View"));
m_viewToolBar->setObjectName("ViewToolBar"); m_viewToolBar->setObjectName("ViewToolBar");
m_viewToolBar->setMovable(false); m_viewToolBar->setMovable(false);
m_viewToolBar->addAction(twoPanelViewAct);
m_viewToolBar->addAction(onePanelViewAct);
m_viewToolBar->addAction(expandViewAct); m_viewToolBar->addAction(expandViewAct);
} }
@ -557,14 +564,27 @@ void VMainWindow::handleCurTabStatusChanged(const VFile *p_file, bool p_editMode
m_curFile = const_cast<VFile *>(p_file); m_curFile = const_cast<VFile *>(p_file);
} }
void VMainWindow::changePanelView(QAction *action) void VMainWindow::onePanelView()
{ {
if (!action) { changeSplitterView(1);
return; expandViewAct->setChecked(false);
} }
int nrPanel = action->data().toInt();
changeSplitterView(nrPanel); void VMainWindow::twoPanelView()
{
changeSplitterView(2);
expandViewAct->setChecked(false);
}
void VMainWindow::expandPanelView(bool p_checked)
{
int nrSplits = 0;
if (p_checked) {
nrSplits = 0;
} else {
nrSplits = 2;
}
changeSplitterView(nrSplits);
} }
void VMainWindow::changeSplitterView(int nrPanel) void VMainWindow::changeSplitterView(int nrPanel)

View File

@ -44,7 +44,9 @@ private slots:
void setEditorBackgroundColor(QAction *action); void setEditorBackgroundColor(QAction *action);
void setRenderBackgroundColor(QAction *action); void setRenderBackgroundColor(QAction *action);
void handleCurTabStatusChanged(const VFile *p_file, bool p_editMode); void handleCurTabStatusChanged(const VFile *p_file, bool p_editMode);
void changePanelView(QAction *action); void onePanelView();
void twoPanelView();
void expandPanelView(bool p_checked);
void curEditFileInfo(); void curEditFileInfo();
void deleteCurNote(); void deleteCurNote();
void handleCurrentDirectoryChanged(const VDirectory *p_dir); void handleCurrentDirectoryChanged(const VDirectory *p_dir);
@ -58,6 +60,7 @@ private:
void setupUI(); void setupUI();
QWidget *setupDirectoryPanel(); QWidget *setupDirectoryPanel();
void initActions(); void initActions();
void initViewActions();
void initToolBar(); void initToolBar();
void initMenuBar(); void initMenuBar();
void initDockWindows(); void initDockWindows();
@ -98,7 +101,6 @@ private:
QAction *saveNoteAct; QAction *saveNoteAct;
QAction *saveExitAct; QAction *saveExitAct;
QAction *discardExitAct; QAction *discardExitAct;
QActionGroup *viewAct;
QAction *twoPanelViewAct; QAction *twoPanelViewAct;
QAction *onePanelViewAct; QAction *onePanelViewAct;
QAction *expandViewAct; QAction *expandViewAct;