BuildmLearn Toolkit  2.0.4
BuildmLearn Toolkit is an easy-to-use program that helps users make mobile apps without any knowledge of application development.
 All Classes Functions Enumerations Groups Pages
basicmlearningsimulator.cpp
1 /*
2  Copyright (c) 2012, BuildmLearn Contributors listed at http://buildmlearn.org/people/
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are met:
7 
8  * Redistributions of source code must retain the above copyright notice, this
9  list of conditions and the following disclaimer.
10 
11  * Redistributions in binary form must reproduce the above copyright notice,
12  this list of conditions and the following disclaimer in the documentation
13  and/or other materials provided with the distribution.
14 
15  * Neither the name of the BuildmLearn nor the names of its
16  contributors may be used to endorse or promote products derived from
17  this software without specific prior written permission.
18 
19  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30 
31 #include "templates/mlearning/basicmlearningsimulator.h"
32 
33 #include "templates/mlearning/basicmlearningeditor.h"
34 #include "core/templatecore.h"
35 
36 
37 BasicmLearningSimulator::BasicmLearningSimulator(TemplateCore *core, QWidget *parent) :
38  TemplateSimulator(core, parent), m_ui(new Ui::BasicmLearningSimulator) {
39  m_ui->setupUi(this);
40 
41  connect(m_ui->m_listItems, SIGNAL(itemClicked(QListWidgetItem*)),
42  this, SLOT(displayDescription(QListWidgetItem*)));
43 }
44 
45 BasicmLearningSimulator::~BasicmLearningSimulator() {
46  delete m_ui;
47 }
48 
49 bool BasicmLearningSimulator::startSimulation() {
50  BasicmLearningEditor *editor = static_cast<BasicmLearningEditor*>(core()->editor());
51 
52  if (!editor->canGenerateApplications()) {
53  // There are no active questions or quiz does not
54  // containt its name or author name.
55  return false;
56  }
57 
58  // Remove existing items.
59  m_ui->m_listItems->clear();
60 
61  // Add new items.
62  foreach (const BasicmLearningItem &item, editor->activeItems()) {
63  QListWidgetItem *list_item = new QListWidgetItem(item.title(), m_ui->m_listItems);
64  list_item->setData(Qt::UserRole, QVariant::fromValue(item));
65  }
66 
67  m_ui->m_phoneWidget->setCurrentIndex(1);
68 
69  return true;
70 }
71 
72 bool BasicmLearningSimulator::stopSimulation() {
73  m_ui->m_phoneWidget->setCurrentIndex(0);
74 
75  emit canGoBackChanged(false);
76 
77  return true;
78 }
79 
80 bool BasicmLearningSimulator::goBack() {
81  if (m_ui->m_phoneWidget->currentIndex() == 2) {
82  m_ui->m_phoneWidget->setCurrentIndex(1);
83  m_ui->m_listItems->setCurrentRow(-1);
84 
85  emit canGoBackChanged(false);
86 
87  return true;
88  }
89  else {
90  return false;
91  }
92 }
93 
94 void BasicmLearningSimulator::displayDescription(QListWidgetItem *list_item) {
95  m_ui->m_lblDetails->setText(list_item->data(Qt::UserRole).value<BasicmLearningItem>().description());
96  m_ui->m_phoneWidget->setCurrentIndex(2);
97 
98  emit canGoBackChanged(true);
99 }
virtual TemplateEditor * editor() const
Access to editor widget of the template.
Definition: templatecore.h:84
void canGoBackChanged(bool can_go_back)
Emitted if "can go back" status of simulator changes.
bool canGenerateApplications()
Specifies if template can generate applications or not.
TemplateCore * core() const
Access to associated template core.
The core class container for single template.
Definition: templatecore.h:43
Base widget which represents simulator of the template.