blob: f1605a916c87cc32269ddbb052e5026c3e34c7fc [file] [log] [blame]
Edric Milaret627500d2015-03-27 16:41:40 -04001/***************************************************************************
Edric Milaret5f316da2015-09-28 11:57:42 -04002 * Copyright (C) 2015 by Savoir-faire Linux *
Edric Milaret627500d2015-03-27 16:41:40 -04003 * Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>*
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
19#include "navstack.h"
20
21NavStack::NavStack(QStackedWidget* bar, QStackedWidget* stack, QWidget *parent)
22 : bar_(bar)
23 , stack_(stack)
24{
Edric Milareted0b2802015-10-01 15:10:02 -040025 Q_UNUSED(parent)
26
Edric Milaret627500d2015-03-27 16:41:40 -040027 navList_.append(new NavBar());
28
29 navList_.append(new CallWidget());
30 navList_.append(new ConfigurationWidget());
31
Edric Milaret627500d2015-03-27 16:41:40 -040032 for (int i = 0; i < END; i++) {
33 if (i < CallScreen)
34 bar_->addWidget(navList_[i]);
35 else
36 stack_->addWidget(navList_[i]);
37 connect(navList_[i], SIGNAL(NavigationRequested(ScreenEnum)),
38 this, SLOT(onNavigationRequested(ScreenEnum)));
39 connect(navList_[i], SIGNAL(BackRequested()),
40 this, SLOT(onBackRequested()));
41 }
Edric Milareted0b2802015-10-01 15:10:02 -040042 bar_->hide();
Edric Milaret627500d2015-03-27 16:41:40 -040043}
44
45NavStack::~NavStack()
Edric Milaret01f23842015-06-22 14:46:01 -040046{
47 for (int i = 0; i < END; i++) {
48 delete navList_[i];
49 }
50}
Edric Milaret627500d2015-03-27 16:41:40 -040051
Nicolas Jager97a21b42015-12-03 16:55:45 -050052NavWidget*
53NavStack::getNavWidget(ScreenEnum wantedNavWidget)
54{
55 return navList_[wantedNavWidget];
56}
57
Edric Milaret627500d2015-03-27 16:41:40 -040058void
59NavStack::onNavigationRequested(ScreenEnum screen) {
Edric Milaret2cf34292015-06-22 16:27:03 -040060 if (navList_[screen] == stack_->currentWidget())
61 return;
Edric Milaret627500d2015-03-27 16:41:40 -040062 if (screen < CallScreen) {
Edric Milareted0b2802015-10-01 15:10:02 -040063 bar_->show();
64 if (auto barItem = navList_[screen])
65 bar_->setCurrentWidget(barItem);
66 else
67 bar_->hide();
Edric Milaret627500d2015-03-27 16:41:40 -040068 } else {
69 stack_->setCurrentWidget(navList_[screen]);
70 setNavBar(navList_[screen]);
71 stackNav_.append(screen);
72 }
73}
74
75void
76NavStack::onBackRequested() {
77
78 navList_[stackNav_.pop()]->atExit();
79 ScreenEnum screen;
80
81 if (stackNav_.size() == 0)
82 screen = CallScreen;
83 else
84 screen = stackNav_.first();
85
86 stack_->setCurrentWidget(navList_[screen]);
87 setNavBar(navList_[screen]);
88}
89
90void
91NavStack::setNavBar(NavWidget* navW) {
Edric Milareted0b2802015-10-01 15:10:02 -040092 if (navW->barDesired != END) {
Edric Milaret627500d2015-03-27 16:41:40 -040093 bar_->setCurrentWidget(navList_[navW->barDesired]);
Edric Milareted0b2802015-10-01 15:10:02 -040094 bar_->show();
95 } else {
96 bar_->hide();
97 }
Edric Milaret627500d2015-03-27 16:41:40 -040098}