• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

kapptemplate

  • sources
  • kde-4.12
  • kdesdk
  • kapptemplate
choicepage.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright 2001 Bernd Gehrmann <bernd@kdevelop.org> *
3  * Copyright 2004-2005 Sascha Cunz <sascha@kdevelop.org> *
4  * Copyright 2007 Alexander Dymo <adymo@kdevelop.org> *
5  * Copyright 2008 Anne-Marie Mahfouf <annma@kde.org> *
6  * *
7  * This program is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program; if not, write to the *
19  * Free Software Foundation, Inc., *
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
21  ***************************************************************************/
22 
23 #include <QString>
24 #include <QPixmap>
25 #include <QStandardItem>
26 
27 #include <KDebug>
28 #include <kstandarddirs.h>
29 
30 #include "choicepage.h"
31 #include "prefs.h"
32 #include "apptemplatesmodel.h"
33 
34 ChoicePage::ChoicePage( QWidget *parent)
35  : QWizardPage(parent)
36 {
37  setTitle(i18n("Choose your project template"));
38  ui_choice.setupUi(this);
39  //Get the model
40  templatesModel = new AppTemplatesModel(this);
41  templatesModel->refresh();
42  ui_choice.appTree->setModel(templatesModel);
43  ui_choice.appTree->expandAll();
44  connect(ui_choice.kcfg_appName, SIGNAL(textChanged(const QString &)), this, SIGNAL(completeChanged()));
45  connect(this, SIGNAL(completeChanged()), this, SLOT(saveConfig()));
46  connect(ui_choice.appTree->selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), this, SLOT(itemSelected(QModelIndex)));
47  QRegExp rx("[a-zA-Z0-9_]*");
48  QValidator *validator = new QRegExpValidator(rx, this);
49  ui_choice.kcfg_appName->setValidator(validator);
50  registerField("appName*", ui_choice.kcfg_appName);
51 }
52 
53 bool ChoicePage::isComplete () const{
54  if(!m_baseName.isEmpty() && !ui_choice.kcfg_appName->text().isEmpty()){
55  return true;
56  }
57 
58  return false;
59 }
60 
61 void ChoicePage::saveConfig()
62 {
63  Prefs::setAppName(ui_choice.kcfg_appName->text());
64  Prefs::self()->writeConfig();
65 }
66 
67 void ChoicePage::itemSelected(const QModelIndex &index)
68 {
69  if (!index.isValid()){
70  emit completeChanged();
71  return;
72  }
73  //get picture
74  KStandardDirs* dirs = KGlobal::dirs();
75  kDebug() << index.data(Qt::UserRole+2);
76  QString picPath = dirs->findResource("apptemplate_previews", index.data(Qt::UserRole+2).toString());
77  if (index.data(Qt::UserRole+2).toString().isEmpty()) {
78  picPath = dirs->findResource("apptemplate_previews", "default.png");//default if none
79  }
80  QPixmap pixmap(picPath);
81  ui_choice.pictureLabel->setPixmap(pixmap);
82  //and description
83  QString description;
84  if (index.data(Qt::UserRole+1).toString().isEmpty()) {
85  description = i18n("Template description");//default if none
86  } else {
87  description = index.data(Qt::UserRole+1).toString();
88  }
89  ui_choice.descriptionLabel->setText(description);
90  //Template view name
91  QStandardItem *item = templatesModel->itemFromIndex(index);
92 
93  m_baseName = index.data(Qt::UserRole+3).toString();
94  //baseName can check if an item is selected.
95  if (!m_baseName.isEmpty()) {
96  ui_choice.kcfg_appName->setFocus(Qt::MouseFocusReason);
97  }
98  registerField("tempName", this);
99  setField("tempName", m_baseName);
100  emit completeChanged();
101 }
102 
103 #include "choicepage.moc"
apptemplatesmodel.h
QWizardPage
prefs.h
QWidget
class @6 QWidget
This is the main view class for %{APPNAME}.
ChoicePage::m_baseName
QString m_baseName
Definition: choicepage.h:39
Prefs::self
static Prefs * self()
Definition: prefs.cpp:17
Prefs::setAppName
static void setAppName(const QString &v)
Set Name of the project.
Definition: prefs.h:22
AppTemplatesModel
Templates Model class.
Definition: apptemplatesmodel.h:38
ChoicePage::itemSelected
void itemSelected(const QModelIndex &index)
Definition: choicepage.cpp:67
AppTemplatesModel::refresh
void refresh()
Definition: apptemplatesmodel.cpp:73
ChoicePage::isComplete
bool isComplete() const
Definition: choicepage.cpp:53
description
static const char description[]
Definition: main.cpp:29
ChoicePage::ChoicePage
ChoicePage(QWidget *parent=0)
Definition: choicepage.cpp:34
QStandardItem
choicepage.h
ChoicePage::templatesModel
AppTemplatesModel * templatesModel
Definition: choicepage.h:38
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:03:23 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kapptemplate

Skip menu "kapptemplate"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal