PageRenderTime 48ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/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
  1. /***************************************************************************
  2. * Copyright (C) 2010 by Thomas Keller *
  3. * me@thomaskeller.biz *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation, either version 3 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  17. ***************************************************************************/
  18. #include "BranchView.h"
  19. #include "vocab.h"
  20. #include <QMessageBox>
  21. BranchView::BranchView(QWidget * parent) : TreeView(parent)
  22. {
  23. setRootIsDecorated(false);
  24. setItemsExpandable(true);
  25. actSuspendBranch = new QAction(tr("suspend this branch"), this);
  26. actDisplayAsTree = new QAction(tr("display branches as tree"), this);
  27. actDisplayAsTree->setCheckable(true);
  28. actShowSuspended = new QAction(tr("show suspended branches"), this);
  29. actShowSuspended->setCheckable(true);
  30. actReloadList = new QAction(tr("reload branches"), this);
  31. connect(
  32. this, SIGNAL(contextMenuRequested(const QModelIndexList &, const QPoint &)),
  33. this, SLOT(slotContextMenuRequested(const QModelIndexList &, const QPoint &))
  34. );
  35. }
  36. BranchView::~BranchView()
  37. {
  38. delete actSuspendBranch;
  39. delete actDisplayAsTree;
  40. delete actShowSuspended;
  41. delete actReloadList;
  42. }
  43. void BranchView::slotContextMenuRequested(const QModelIndexList & indexes,
  44. const QPoint & pt)
  45. {
  46. QModelIndex index;
  47. if (indexes.size() > 0)
  48. index = indexes.at(0);
  49. QMenu popupMenu;
  50. if (index.isValid() && !index.data(Qt::UserRole).toBool())
  51. {
  52. popupMenu.addAction(actSuspendBranch);
  53. popupMenu.addSeparator();
  54. }
  55. popupMenu.addAction(actDisplayAsTree);
  56. popupMenu.addAction(actShowSuspended);
  57. popupMenu.addSeparator();
  58. popupMenu.addAction(actReloadList);
  59. QAction * act = popupMenu.exec(pt);
  60. if (act == actSuspendBranch)
  61. {
  62. I(index.isValid());
  63. QString branch = index.data(Qt::ToolTipRole).toString();
  64. QMessageBox::StandardButton btn = QMessageBox::question(
  65. this,
  66. tr("Suspend branch"),
  67. tr("Are you sure that you want to "
  68. "suspend the branch '%1'?").arg(branch),
  69. QMessageBox::Yes | QMessageBox::No
  70. );
  71. if (btn == QMessageBox::No)
  72. return;
  73. emit suspendBranch(branch);
  74. }
  75. else
  76. if (act == actDisplayAsTree)
  77. {
  78. emit displayBranchesAsTree(act->isChecked());
  79. }
  80. else
  81. if (act == actShowSuspended)
  82. {
  83. emit showSuspendedBranches(act->isChecked());
  84. }
  85. else
  86. if (act == actReloadList)
  87. {
  88. emit reloadBranchList();
  89. }
  90. }