| 1 | /*************************************************************************** |
| 2 | ingredientview.cpp |
| 3 | ------------------- |
| 4 | Ingredient view |
| 5 | ------------------- |
| 6 | Copyright 2006-2008, David Johnson |
| 7 | Please see the header file for copyright and license information |
| 8 | ***************************************************************************/ |
| 9 | |
| 10 | #include <QAction> |
| 11 | #include <QContextMenuEvent> |
| 12 | #include <QHeaderView> |
| 13 | #include <QMenu> |
| 14 | |
| 15 | #include "ingredientview.h"cxx . . $ `<file>/src/ingredientview.h`/ |
| 16 | |
| 17 | /////////////////////////////////////////////////////////////////////////////// |
| 18 | // IngredientView // |
| 19 | /////////////////////////////////////////////////////////////////////////////// |
| 20 | |
| 21 | ////////////////////////////////////////////////////////////////////////////// |
| 22 | // IngredientView() |
| 23 | // ------------ |
| 24 | // Constructor |
| 25 | |
| 26 | IngredientViewcxx . . $ IngredientView#::IngredientViewcxx . . $ IngredientView#IngredientView(108f35f7aa7f3cf9).(QWidgetcxx . . $ QWidget# *parent) |
| 27 | : QTableViewcxx . . $ QTableView#QTableView(108f35f7aa7f3cf9).(parent), addaction_cxx . . $ IngredientView#addaction_.(0), removeaction_cxx . . $ IngredientView#removeaction_.(0) |
| 28 | { |
| 29 | setSortingEnabledcxx . . $ QTableView#setSortingEnabled(b45ddcbc8423892c).(true); |
| 30 | |
| 31 | // create context menu actions |
| 32 | addaction_cxx . . $ IngredientView#addaction_. = new QActioncxx . . $ QAction#QAction(6b24f83d17022bd9).(trcxx . . $ IngredientView#tr(75d9f1c324b4579d).("&Add Ingredient"), this); |
| 33 | addaction_cxx . . $ IngredientView#addaction_.->setShortcutcxx . . $ QAction#setShortcut(462600f892e8a1ee).(QKeySequencecxx . . $ QKeySequence#QKeySequence(6905a94d1418a018).(trcxx . . $ IngredientView#tr(75d9f1c324b4579d).("Ctrl+Insert"))); |
| 34 | addaction_cxx . . $ IngredientView#addaction_.->setStatusTipcxx . . $ QAction#setStatusTip(3520e46b33348bf6).(trcxx . . $ IngredientView#tr(75d9f1c324b4579d).("Add a new ingredient")); |
| 35 | connectcxx . . $ QObject#connect(158df1d9a01a3410).(addaction_cxx . . $ IngredientView#addaction_., SIGNALcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:271:10`!(triggered()), this, SLOTcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:270:10`!(addIngredient())); |
| 36 | |
| 37 | removeaction_cxx . . $ IngredientView#removeaction_. = new QActioncxx . . $ QAction#QAction(6b24f83d17022bd9).(trcxx . . $ IngredientView#tr(75d9f1c324b4579d).("&Remove Ingredient"), this); |
| 38 | removeaction_cxx . . $ IngredientView#removeaction_.->setShortcutcxx . . $ QAction#setShortcut(462600f892e8a1ee).(QKeySequencecxx . . $ QKeySequence#QKeySequence(6905a94d1418a018).(trcxx . . $ IngredientView#tr(75d9f1c324b4579d).("Ctrl+Delete"))); |
| 39 | removeaction_cxx . . $ IngredientView#removeaction_.->setStatusTipcxx . . $ QAction#setStatusTip(3520e46b33348bf6).(trcxx . . $ IngredientView#tr(75d9f1c324b4579d).("Remove selected ingredient")); |
| 40 | connectcxx . . $ QObject#connect(158df1d9a01a3410).(removeaction_cxx . . $ IngredientView#removeaction_., SIGNALcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:271:10`!(triggered()), this, SLOTcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:270:10`!(removeIngredient())); |
| 41 | |
| 42 | clearaction_cxx . . $ IngredientView#clearaction_. = new QActioncxx . . $ QAction#QAction(6b24f83d17022bd9).(trcxx . . $ IngredientView#tr(75d9f1c324b4579d).("&Clear Selection"), this); |
| 43 | clearaction_cxx . . $ IngredientView#clearaction_.->setShortcutcxx . . $ QAction#setShortcut(462600f892e8a1ee).(QKeySequencecxx . . $ QKeySequence#QKeySequence(6905a94d1418a018).(trcxx . . $ IngredientView#tr(75d9f1c324b4579d).("Escape"))); |
| 44 | clearaction_cxx . . $ IngredientView#clearaction_.->setStatusTipcxx . . $ QAction#setStatusTip(3520e46b33348bf6).(trcxx . . $ IngredientView#tr(75d9f1c324b4579d).("Clear selection")); |
| 45 | connectcxx . . $ QObject#connect(158df1d9a01a3410).(clearaction_cxx . . $ IngredientView#clearaction_., SIGNALcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:271:10`!(triggered()), this, SLOTcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:270:10`!(clearSelection())); |
| 46 | |
| 47 | addActioncxx . . $ QWidget#addAction(92b1e80c0a7f1406).(addaction_cxx . . $ IngredientView#addaction_.); |
| 48 | addActioncxx . . $ QWidget#addAction(92b1e80c0a7f1406).(removeaction_cxx . . $ IngredientView#removeaction_.); |
| 49 | addActioncxx . . $ QWidget#addAction(92b1e80c0a7f1406).(clearaction_cxx . . $ IngredientView#clearaction_.); |
| 50 | } |
| 51 | |
| 52 | IngredientViewcxx . . $ IngredientView#::~cxx . . $ IngredientView#`~IngredientView`(ced63f7c635d850d).IngredientViewcxx . . $ IngredientView#() |
| 53 | { |
| 54 | } |
| 55 | |
| 56 | ////////////////////////////////////////////////////////////////////////////// |
| 57 | // contextMenuEvent() |
| 58 | // ------------------ |
| 59 | // Create and show context menu |
| 60 | |
| 61 | void IngredientViewcxx . . $ IngredientView#::contextMenuEventcxx . . $ IngredientView#contextMenuEvent(ebb2569a74e11126).(QContextMenuEventcxx . . $ QContextMenuEvent# *event) |
| 62 | { |
| 63 | QMenucxx . . $ QMenu# menucxx . . $ QMenu#QMenu(108f35f7aa7f3cf9).(this); |
| 64 | menu.addActioncxx . . $ QWidget#addAction(92b1e80c0a7f1406).(addaction_cxx . . $ IngredientView#addaction_.); |
| 65 | menu.addActioncxx . . $ QWidget#addAction(92b1e80c0a7f1406).(removeaction_cxx . . $ IngredientView#removeaction_.); |
| 66 | menu.addSeparatorcxx . . $ QMenu#addSeparator(a590eff9f1ec9a95).(); |
| 67 | menu.addActioncxx . . $ QWidget#addAction(92b1e80c0a7f1406).(clearaction_cxx . . $ IngredientView#clearaction_.); |
| 68 | menu.execcxx . . $ QMenu#exec(2535b15b88c544d4).(event->globalPoscxx . . $ QContextMenuEvent#globalPos(6de9f7a200ca710c).()); |
| 69 | } |
| 70 | |
| 71 | ////////////////////////////////////////////////////////////////////////////// |
| 72 | // addIngredient() |
| 73 | // --------------- |
| 74 | // Add a new blank ingredient |
| 75 | |
| 76 | void IngredientViewcxx . . $ IngredientView#::addIngredientcxx . . $ IngredientView#addIngredient(49f6e7a06ebc5aa8).() |
| 77 | { |
| 78 | modelcxx . . $ QAbstractItemView#model(c9c1e11e7bd96493).()->insertRowscxx . . $ QAbstractItemModel#insertRows(c4e00837c4ba3150).(currentIndexcxx . . $ QAbstractItemView#currentIndex(a394cbc57608ce34).().rowcxx . . $ QModelIndex#row(ea6fe5115c70a13f).(), 1, QModelIndexcxx . . $ QModelIndex#QModelIndex(ced63f7c635d850d).()); |
| 79 | } |
| 80 | |
| 81 | ////////////////////////////////////////////////////////////////////////////// |
| 82 | // removeIngredient() |
| 83 | // ------------------ |
| 84 | // Remove the selected ingredient |
| 85 | |
| 86 | void IngredientViewcxx . . $ IngredientView#::removeIngredientcxx . . $ IngredientView#removeIngredient(49f6e7a06ebc5aa8).() |
| 87 | { |
| 88 | // can only remove valid indexes |
| 89 | if (currentIndexcxx . . $ QAbstractItemView#currentIndex(a394cbc57608ce34).().isValidcxx . . $ QModelIndex#isValid(3482b152b9333168).()) { |
| 90 | modelcxx . . $ QAbstractItemView#model(c9c1e11e7bd96493).()->removeRowscxx . . $ QAbstractItemModel#removeRows(c4e00837c4ba3150).(currentIndexcxx . . $ QAbstractItemView#currentIndex(a394cbc57608ce34).().rowcxx . . $ QModelIndex#row(ea6fe5115c70a13f).(), 1, QModelIndexcxx . . $ QModelIndex#QModelIndex(ced63f7c635d850d).()); |
| 91 | clearSelectioncxx . . $ QAbstractItemView#clearSelection(49f6e7a06ebc5aa8).(); |
| 92 | } |
| 93 | } |