/guitone-1.0rc5/src/view/widgets/BranchView.cpp
C++ | 109 lines | 73 code | 19 blank | 17 comment | 13 complexity | ed3b1764f319c7b839f79436d4764e94 MD5 | raw file
Possible License(s): GPL-3.0
- /***************************************************************************
- * Copyright (C) 2010 by Thomas Keller *
- * me@thomaskeller.biz *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation, either version 3 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program. If not, see <http://www.gnu.org/licenses/>. *
- ***************************************************************************/
- #include "BranchView.h"
- #include "vocab.h"
- #include <QMessageBox>
- BranchView::BranchView(QWidget * parent) : TreeView(parent)
- {
- setRootIsDecorated(false);
- setItemsExpandable(true);
- actSuspendBranch = new QAction(tr("suspend this branch"), this);
- actDisplayAsTree = new QAction(tr("display branches as tree"), this);
- actDisplayAsTree->setCheckable(true);
- actShowSuspended = new QAction(tr("show suspended branches"), this);
- actShowSuspended->setCheckable(true);
- actReloadList = new QAction(tr("reload branches"), this);
- connect(
- this, SIGNAL(contextMenuRequested(const QModelIndexList &, const QPoint &)),
- this, SLOT(slotContextMenuRequested(const QModelIndexList &, const QPoint &))
- );
- }
- BranchView::~BranchView()
- {
- delete actSuspendBranch;
- delete actDisplayAsTree;
- delete actShowSuspended;
- delete actReloadList;
- }
- void BranchView::slotContextMenuRequested(const QModelIndexList & indexes,
- const QPoint & pt)
- {
- QModelIndex index;
- if (indexes.size() > 0)
- index = indexes.at(0);
- QMenu popupMenu;
- if (index.isValid() && !index.data(Qt::UserRole).toBool())
- {
- popupMenu.addAction(actSuspendBranch);
- popupMenu.addSeparator();
- }
- popupMenu.addAction(actDisplayAsTree);
- popupMenu.addAction(actShowSuspended);
- popupMenu.addSeparator();
- popupMenu.addAction(actReloadList);
- QAction * act = popupMenu.exec(pt);
- if (act == actSuspendBranch)
- {
- I(index.isValid());
- QString branch = index.data(Qt::ToolTipRole).toString();
- QMessageBox::StandardButton btn = QMessageBox::question(
- this,
- tr("Suspend branch"),
- tr("Are you sure that you want to "
- "suspend the branch '%1'?").arg(branch),
- QMessageBox::Yes | QMessageBox::No
- );
- if (btn == QMessageBox::No)
- return;
- emit suspendBranch(branch);
- }
- else
- if (act == actDisplayAsTree)
- {
- emit displayBranchesAsTree(act->isChecked());
- }
- else
- if (act == actShowSuspended)
- {
- emit showSuspendedBranches(act->isChecked());
- }
- else
- if (act == actReloadList)
- {
- emit reloadBranchList();
- }
- }