blob: 8d1addc02621ce89ea9c6d915a27e8ff2f9007b6 [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
52void
53NavStack::onNavigationRequested(ScreenEnum screen) {
Edric Milaret2cf34292015-06-22 16:27:03 -040054 if (navList_[screen] == stack_->currentWidget())
55 return;
Edric Milaret627500d2015-03-27 16:41:40 -040056 if (screen < CallScreen) {
Edric Milareted0b2802015-10-01 15:10:02 -040057 bar_->show();
58 if (auto barItem = navList_[screen])
59 bar_->setCurrentWidget(barItem);
60 else
61 bar_->hide();
Edric Milaret627500d2015-03-27 16:41:40 -040062 } else {
63 stack_->setCurrentWidget(navList_[screen]);
64 setNavBar(navList_[screen]);
65 stackNav_.append(screen);
66 }
67}
68
69void
70NavStack::onBackRequested() {
71
72 navList_[stackNav_.pop()]->atExit();
73 ScreenEnum screen;
74
75 if (stackNav_.size() == 0)
76 screen = CallScreen;
77 else
78 screen = stackNav_.first();
79
80 stack_->setCurrentWidget(navList_[screen]);
81 setNavBar(navList_[screen]);
82}
83
84void
85NavStack::setNavBar(NavWidget* navW) {
Edric Milareted0b2802015-10-01 15:10:02 -040086 if (navW->barDesired != END) {
Edric Milaret627500d2015-03-27 16:41:40 -040087 bar_->setCurrentWidget(navList_[navW->barDesired]);
Edric Milareted0b2802015-10-01 15:10:02 -040088 bar_->show();
89 } else {
90 bar_->hide();
91 }
Edric Milaret627500d2015-03-27 16:41:40 -040092}