2 * This file is part of family-shop-mgr.
4 * family-shop-mgr is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * family-shop-mgr is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with family-shop-mgr. If not, see <http://www.gnu.org/licenses/>.
17 * Author: Unai IRIGOYEN
22 #include "FamilyShoppingManagerMainWindow.h"
24 #include <QMessageBox>
25 #include <QInputDialog>
27 #include "ListManagerView.h"
28 #include "GoShoppingView.h"
29 #include "ShoppingTreeModel.h"
31 /*******************************************************************/
32 FamilyShoppingManagerMainWindow::FamilyShoppingManagerMainWindow(QWidget *parent)
33 : QMainWindow(parent), activityView(NULL), //editMenu(NULL),
34 showCheckedItemsAction(NULL), goShoppingAction(NULL), endShoppingAction(NULL)
36 aboutAction = new QAction(tr("&About"), this);
37 aboutAction->setSoftKeyRole(QAction::PositiveSoftKey);
38 connect(aboutAction, SIGNAL(triggered()), this, SLOT(showAbout()));
39 menuBar()->addAction(aboutAction);
45 /*******************************************************************/
46 FamilyShoppingManagerMainWindow::~FamilyShoppingManagerMainWindow()
51 /*******************************************************************/
52 void FamilyShoppingManagerMainWindow::showListManager()
56 delete showCheckedItemsAction;
57 delete endShoppingAction;
60 activityView = new ListManagerView("ShoppingList.xml", this);
62 addCategoryAction = new QAction(tr("Add category"), this);
63 addCategoryAction->setSoftKeyRole(QAction::PositiveSoftKey);
64 connect(addCategoryAction, SIGNAL(triggered()),
65 this, SLOT(addCategory()));
66 menuBar()->addAction(addCategoryAction);
67 removeCategoryAction = new QAction(tr("Remove category"), this);
68 removeCategoryAction->setSoftKeyRole(QAction::NegativeSoftKey);
69 connect(removeCategoryAction, SIGNAL(triggered()),
70 this, SLOT(removeCategoryOrItem()));
71 menuBar()->addAction(removeCategoryAction);
72 addItemAction = new QAction(tr("Add item"), this);
73 addItemAction->setSoftKeyRole(QAction::PositiveSoftKey);
74 connect(addItemAction, SIGNAL(triggered()),
75 this, SLOT(addItem()));
76 menuBar()->addAction(addItemAction);
77 removeItemAction = new QAction(tr("Remove item"), this);
78 removeItemAction->setSoftKeyRole(QAction::NegativeSoftKey);
79 connect(removeItemAction, SIGNAL(triggered()),
80 this, SLOT(removeCategoryOrItem()));
81 menuBar()->addAction(removeItemAction);
83 goShoppingAction = new QAction(tr("Go shopping!"), this);
84 goShoppingAction->setSoftKeyRole(QAction::PositiveSoftKey);
85 connect(goShoppingAction, SIGNAL(triggered()),
86 this, SLOT(showGoShopping()));
87 menuBar()->addAction(goShoppingAction);
89 menuBar()->addAction(aboutAction);
91 setCentralWidget(activityView);
95 /*******************************************************************/
96 void FamilyShoppingManagerMainWindow::showGoShopping()
100 delete addCategoryAction;
101 delete addItemAction;
102 delete removeCategoryAction;
103 delete removeItemAction;
104 delete goShoppingAction;
107 activityView = new GoShoppingView("ShoppingList.xml", this);
108 setCentralWidget(activityView);
110 showCheckedItemsAction = new QAction(tr("&Show checked"), this);
111 showCheckedItemsAction->setCheckable(true);
112 showCheckedItemsAction->setSoftKeyRole(QAction::PositiveSoftKey);
113 connect(showCheckedItemsAction, SIGNAL(toggled(bool)),
114 activityView, SLOT(showChecked(bool)));
115 menuBar()->addAction(showCheckedItemsAction);
117 endShoppingAction = new QAction(tr("&End shopping"), this);
118 endShoppingAction->setSoftKeyRole(QAction::NegativeSoftKey);
119 connect(endShoppingAction, SIGNAL(triggered()),
120 this, SLOT(showListManager()));
121 menuBar()->addAction(endShoppingAction);
123 menuBar()->addAction(aboutAction);
127 /*******************************************************************/
128 void FamilyShoppingManagerMainWindow::showAbout()
131 text = tr("Application name:") + " Family shopping manager\n\n";
132 text += tr("Project maintainer:") + "\n";
133 text += "\tUnai IRIGOYEN";
135 text += tr("Developers:") + "\n";
136 text += "\tUnai IRIGOYEN";
138 text += tr("Licence:") + " GPLv3";
139 QMessageBox::about(this,tr("About"), text);
142 /*******************************************************************/
143 void FamilyShoppingManagerMainWindow::addCategory()
145 ShoppingTreeModel *model = (ShoppingTreeModel*)
146 ((ListManagerView*) activityView)->model();
148 bool* ok = new bool(false);
149 QString name = QInputDialog::getText(this, tr("Enter category name"),
150 tr("Category name:"),
151 QLineEdit::Normal, QString(), ok);
155 if(model->addCategory(name))
156 ((ListManagerView*) activityView)->updateActions();
160 /*******************************************************************/
161 void FamilyShoppingManagerMainWindow::addSubCategory()
163 QModelIndex index = ((ListManagerView*) activityView)->
164 selectionModel()->currentIndex().parent();
165 ShoppingTreeModel *model = (ShoppingTreeModel*)
166 ((ListManagerView*) activityView)->model();
168 bool* ok = new bool(false);
169 QString name = QInputDialog::getText(this, tr("Enter category name"),
170 tr("Category name:"),
171 QLineEdit::Normal, QString(), ok);
175 if(model->addSubCategory(name, index.row()+1, index))
176 ((ListManagerView*) activityView)->updateActions();
181 /*******************************************************************/
182 void FamilyShoppingManagerMainWindow::addItem()
184 QModelIndex index = ((ListManagerView*) activityView)->
185 selectionModel()->currentIndex().parent();
186 ShoppingTreeModel *model = (ShoppingTreeModel*)
187 ((ListManagerView*) activityView)->model();
189 bool* ok = new bool(false);
190 QString name = QInputDialog::getText(this, tr("Enter item name"),
192 QLineEdit::Normal, QString(), ok);
196 if(model->addItem(name, index.row()+1, index))
197 ((ListManagerView*) activityView)->updateActions();
202 /*******************************************************************/
203 void FamilyShoppingManagerMainWindow::removeCategoryOrItem()
205 QModelIndex index = ((ListManagerView*) activityView)->
206 selectionModel()->currentIndex();
207 ShoppingTreeModel *model = (ShoppingTreeModel*)
208 ((ListManagerView*) activityView)->model();
209 if (model->removeCategoryOrItem(index))
210 ((ListManagerView*) activityView)->updateActions();