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
formnewproject.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 "gui/formnewproject.h"
32 
33 #include "core/templateentrypoint.h"
34 #include "core/templatefactory.h"
35 #include "miscellaneous/iconfactory.h"
36 
37 #include <QShowEvent>
38 
39 
40 FormNewProject::FormNewProject(TemplateFactory *template_manager, QWidget *parent)
41  : QDialog(parent),
42  m_ui(new Ui::FormNewProject), m_adjusted(false) {
43  m_ui->setupUi(this);
44 
45  m_ui->m_lblThumbnail->setFixedSize(200, 213);
46  m_ui->m_listTemplates->setFixedWidth(200);
47 
48  QMargins description_margins = m_ui->m_lblDescription->contentsMargins();
49 
50  description_margins.setTop(20);
51 
52  m_ui->m_lblDescription->setContentsMargins(description_margins);
53 
54  connect(m_ui->m_listTemplates, SIGNAL(currentRowChanged(int)), this, SLOT(templateSelected(int)));
55  connect(m_ui->m_listTemplates, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(accept()));
56 
57  // This window mustn't be deleted when closed by user.
58  setAttribute(Qt::WA_DeleteOnClose, false);
59  setWindowIcon(IconFactory::instance()->fromTheme("project-new"));
60  setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog | (windowFlags() & ~Qt::WindowContextHelpButtonHint));
61 
62  loadTemplates(template_manager->availableTemplates());
63 }
64 
65 FormNewProject::~FormNewProject() {
66  delete m_ui;
67 }
68 
70  if (exec() == QDialog::Accepted && m_ui->m_listTemplates->currentRow() >= 0) {
71  return static_cast<TemplateEntryPoint*>(m_ui->m_listTemplates->currentItem()->data(Qt::UserRole).value<void*>());
72  }
73  else {
74  return NULL;
75  }
76 }
77 
78 void FormNewProject::showEvent(QShowEvent *e) {
79  if (!m_adjusted) {
80  adjustSize();
81  adjustPosition(parentWidget());
82 
83  m_adjusted = true;
84  }
85 
86  e->accept();
87 }
88 
89 void FormNewProject::templateSelected(int index) {
90  if (index >= 0) {
91  TemplateEntryPoint *entry_point = static_cast<TemplateEntryPoint*>(m_ui->m_listTemplates->currentItem()->data(Qt::UserRole).value<void*>());
92 
93  m_ui->m_lblDescription->setText(entry_point->description());
94  m_ui->m_lblThumbnail->setPixmap(QPixmap(APP_TEMPLATES_PATH + QDir::separator() +
95  entry_point->baseFolder() + QDir::separator() +
96  entry_point->thumbnailImage()));
97  }
98 }
99 
100 void FormNewProject::loadTemplates(const QList<TemplateEntryPoint*> &entry_points) {
101  foreach (TemplateEntryPoint *entry_point, entry_points) {
102  // Add the template.
103  (new QListWidgetItem(entry_point->humanName(),
104  m_ui->m_listTemplates))->setData(Qt::UserRole,
105  QVariant::fromValue((void*) entry_point));
106  }
107 
108  if (m_ui->m_listTemplates->count() > 0) {
109  m_ui->m_listTemplates->setCurrentRow(0);
110  }
111 }
virtual QString description() const
Description of template.
TemplateEntryPoint * startNewTemplate()
Displays the dialog and returns entry point of desired template which user wants to create new projec...
virtual QString humanName() const
Human-readable name of template.
The top-level manager of templates.
QList< TemplateEntryPoint * > availableTemplates()
Access to available templates.
The entry point for a template.
virtual QString baseFolder() const
Base folder of template.
Dialog for creating new projects.
virtual QString thumbnailImage() const
Relative path to thumbnail image.
static IconFactory * instance()
Singleton getter.
Definition: iconfactory.cpp:48