+++ /dev/null
-/*
- * This file is part of family-shop-mgr.
- *
- * family-shop-mgr 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.
- *
- * family-shop-mgr 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 family-shop-mgr. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Unai IRIGOYEN
- * Date: 12/07/2009
- *
- */
-
-#include "FamilyShoppingManagerMainWindow.h"
-#include <QMenuBar>
-#include <QMessageBox>
-#include <QInputDialog>
-
-#include "ListManagerView.h"
-#include "GoShoppingView.h"
-#include "ShoppingTreeModel.h"
-
-/*******************************************************************/
-FamilyShoppingManagerMainWindow::FamilyShoppingManagerMainWindow(QWidget *parent)
- : QMainWindow(parent), activityView(NULL), //editMenu(NULL),
- showCheckedItemsAction(NULL), goShoppingAction(NULL), endShoppingAction(NULL)
-{
- aboutAction = new QAction(tr("&About"), this);
- aboutAction->setSoftKeyRole(QAction::PositiveSoftKey);
- connect(aboutAction, SIGNAL(triggered()), this, SLOT(showAbout()));
- menuBar()->addAction(aboutAction);
-
-
- showListManager();
-}
-
-/*******************************************************************/
-FamilyShoppingManagerMainWindow::~FamilyShoppingManagerMainWindow()
-{
- delete activityView;
-}
-
-/*******************************************************************/
-void FamilyShoppingManagerMainWindow::showListManager()
-{
- menuBar()->clear();
-
- delete showCheckedItemsAction;
- delete endShoppingAction;
-
- delete activityView;
- activityView = new ListManagerView("ShoppingList.xml", this);
-
- addCategoryAction = new QAction(tr("Add category"), this);
- addCategoryAction->setSoftKeyRole(QAction::PositiveSoftKey);
- connect(addCategoryAction, SIGNAL(triggered()),
- this, SLOT(addCategory()));
- menuBar()->addAction(addCategoryAction);
- removeCategoryAction = new QAction(tr("Remove category"), this);
- removeCategoryAction->setSoftKeyRole(QAction::NegativeSoftKey);
- connect(removeCategoryAction, SIGNAL(triggered()),
- this, SLOT(removeCategoryOrItem()));
- menuBar()->addAction(removeCategoryAction);
- addItemAction = new QAction(tr("Add item"), this);
- addItemAction->setSoftKeyRole(QAction::PositiveSoftKey);
- connect(addItemAction, SIGNAL(triggered()),
- this, SLOT(addItem()));
- menuBar()->addAction(addItemAction);
- removeItemAction = new QAction(tr("Remove item"), this);
- removeItemAction->setSoftKeyRole(QAction::NegativeSoftKey);
- connect(removeItemAction, SIGNAL(triggered()),
- this, SLOT(removeCategoryOrItem()));
- menuBar()->addAction(removeItemAction);
-
- goShoppingAction = new QAction(tr("Go shopping!"), this);
- goShoppingAction->setSoftKeyRole(QAction::PositiveSoftKey);
- connect(goShoppingAction, SIGNAL(triggered()),
- this, SLOT(showGoShopping()));
- menuBar()->addAction(goShoppingAction);
-
- menuBar()->addAction(aboutAction);
-
- setCentralWidget(activityView);
- update();
-}
-
-/*******************************************************************/
-void FamilyShoppingManagerMainWindow::showGoShopping()
-{
- menuBar()->clear();
-
- delete addCategoryAction;
- delete addItemAction;
- delete removeCategoryAction;
- delete removeItemAction;
- delete goShoppingAction;
-
- delete activityView;
- activityView = new GoShoppingView("ShoppingList.xml", this);
- setCentralWidget(activityView);
-
- showCheckedItemsAction = new QAction(tr("&Show checked"), this);
- showCheckedItemsAction->setCheckable(true);
- showCheckedItemsAction->setSoftKeyRole(QAction::PositiveSoftKey);
- connect(showCheckedItemsAction, SIGNAL(toggled(bool)),
- activityView, SLOT(showChecked(bool)));
- menuBar()->addAction(showCheckedItemsAction);
-
- endShoppingAction = new QAction(tr("&End shopping"), this);
- endShoppingAction->setSoftKeyRole(QAction::NegativeSoftKey);
- connect(endShoppingAction, SIGNAL(triggered()),
- this, SLOT(showListManager()));
- menuBar()->addAction(endShoppingAction);
-
- menuBar()->addAction(aboutAction);
- update();
-}
-
-/*******************************************************************/
-void FamilyShoppingManagerMainWindow::showAbout()
-{
- QString text;
- text = tr("Application name:") + " Family shopping manager\n\n";
- text += tr("Project maintainer:") + "\n";
- text += "\tUnai IRIGOYEN";
- text += "\n\n";
- text += tr("Developers:") + "\n";
- text += "\tUnai IRIGOYEN";
- text += "\n\n";
- text += tr("Licence:") + " GPLv3";
- QMessageBox::about(this,tr("About"), text);
-}
-
-/*******************************************************************/
-void FamilyShoppingManagerMainWindow::addCategory()
-{
- ShoppingTreeModel *model = (ShoppingTreeModel*)
- ((ListManagerView*) activityView)->model();
-
- bool* ok = new bool(false);
- QString name = QInputDialog::getText(this, tr("Enter category name"),
- tr("Category name:"),
- QLineEdit::Normal, QString(), ok);
- if(!ok)
- return;
-
- if(model->addCategory(name))
- ((ListManagerView*) activityView)->updateActions();
- delete ok;
-}
-
-/*******************************************************************/
-void FamilyShoppingManagerMainWindow::addSubCategory()
-{
- QModelIndex index = ((ListManagerView*) activityView)->
- selectionModel()->currentIndex().parent();
- ShoppingTreeModel *model = (ShoppingTreeModel*)
- ((ListManagerView*) activityView)->model();
-
- bool* ok = new bool(false);
- QString name = QInputDialog::getText(this, tr("Enter category name"),
- tr("Category name:"),
- QLineEdit::Normal, QString(), ok);
- if(!ok)
- return;
-
- if(model->addSubCategory(name, index.row()+1, index))
- ((ListManagerView*) activityView)->updateActions();
-
- delete ok;
-}
-
-/*******************************************************************/
-void FamilyShoppingManagerMainWindow::addItem()
-{
- QModelIndex index = ((ListManagerView*) activityView)->
- selectionModel()->currentIndex().parent();
- ShoppingTreeModel *model = (ShoppingTreeModel*)
- ((ListManagerView*) activityView)->model();
-
- bool* ok = new bool(false);
- QString name = QInputDialog::getText(this, tr("Enter item name"),
- tr("Item name:"),
- QLineEdit::Normal, QString(), ok);
- if(!ok)
- return;
-
- if(model->addItem(name, index.row()+1, index))
- ((ListManagerView*) activityView)->updateActions();
-
- delete ok;
-}
-
-/*******************************************************************/
-void FamilyShoppingManagerMainWindow::removeCategoryOrItem()
-{
- QModelIndex index = ((ListManagerView*) activityView)->
- selectionModel()->currentIndex();
- ShoppingTreeModel *model = (ShoppingTreeModel*)
- ((ListManagerView*) activityView)->model();
- if (model->removeCategoryOrItem(index))
- ((ListManagerView*) activityView)->updateActions();
-}