git-svn-id: file:///svnroot/family-shop-mgr@21 26eb2498-383b-47a6-be48-5d6f36779e85
[family-shop-mgr] / code / family-shop-mgr / FamilyShoppingManagerMainWindow.cpp
1 /*
2  * This file is part of family-shop-mgr.
3  *
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.
8  *
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.
13  *
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/>.
16  *
17  * Author: Unai IRIGOYEN
18  * Date: 12/07/2009
19  *
20  */
21
22 #include "FamilyShoppingManagerMainWindow.h"
23 #include <QMenuBar>
24 #include <QMessageBox>
25
26 #include "ListManagerView.h"
27 #include "GoShoppingView.h"
28
29 /*******************************************************************/
30 FamilyShoppingManagerMainWindow::FamilyShoppingManagerMainWindow(QWidget *parent)
31     : QMainWindow(parent), activityView(NULL), showCheckedItemsAction(NULL),
32     endShoppingAction(NULL), goShoppingAction(NULL), editMenu(NULL)
33 {
34     aboutAction = new QAction(tr("&About"), this);
35     connect(aboutAction, SIGNAL(triggered()), this, SLOT(showAbout()));
36     menuBar()->addAction(aboutAction);
37
38
39     showListManager();
40 }
41
42 /*******************************************************************/
43 FamilyShoppingManagerMainWindow::~FamilyShoppingManagerMainWindow()
44 {
45     delete activityView;
46 }
47
48 /*******************************************************************/
49 void FamilyShoppingManagerMainWindow::showListManager()
50 {
51     menuBar()->clear();
52
53     delete showCheckedItemsAction;
54     delete endShoppingAction;
55
56     delete activityView;
57     activityView = new ListManagerView("ShoppingList.xml", this);
58     setCentralWidget(activityView);
59
60     editMenu = new QMenu(tr("&Edit"), this);
61     editMenu->addAction(tr("Add category"));
62     editMenu->addAction(tr("Remove category"));
63     editMenu->addAction(tr("Add item"));
64     editMenu->addAction(tr("Remove item"));
65     menuBar()->addMenu(editMenu);
66
67     goShoppingAction = new QAction(tr("Go shopping!"), this);
68     connect(goShoppingAction, SIGNAL(triggered()),
69             this, SLOT(showGoShopping()));
70     menuBar()->addAction(goShoppingAction);
71
72     menuBar()->addAction(aboutAction);
73     update();
74 }
75
76 /*******************************************************************/
77 void FamilyShoppingManagerMainWindow::showGoShopping()
78 {
79     menuBar()->clear();
80     delete editMenu;
81     delete goShoppingAction;
82
83     delete activityView;
84     activityView = new GoShoppingView("ShoppingList.xml", this);
85     setCentralWidget(activityView);
86
87     showCheckedItemsAction = new QAction(tr("&Show checked"), this);
88     showCheckedItemsAction->setCheckable(true);
89     connect(showCheckedItemsAction, SIGNAL(toggled(bool)),
90             activityView, SLOT(showChecked(bool)));
91     menuBar()->addAction(showCheckedItemsAction);
92
93     endShoppingAction = new QAction(tr("&End shopping"), this);
94     connect(endShoppingAction, SIGNAL(triggered()),
95             this, SLOT(showListManager()));
96     menuBar()->addAction(endShoppingAction);
97
98     menuBar()->addAction(aboutAction);
99     update();
100 }
101
102 /*******************************************************************/
103 void FamilyShoppingManagerMainWindow::showAbout()
104 {
105     QString text;
106     text = "Application name: Family shopping manager\n";
107     text += "Author: Unai IRIGOYEN\n\n";
108     text += "Licence: GPL";
109     QMessageBox::about(this,tr("About"), text);
110 }