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

kapptemplate

choicepage.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright 2001 Bernd Gehrmann <bernd@kdevelop.org>                    *
00003  *   Copyright 2004-2005 Sascha Cunz <sascha@kdevelop.org>                 *
00004  *   Copyright 2007 Alexander Dymo <adymo@kdevelop.org>                    *
00005  *   Copyright 2008 Anne-Marie Mahfouf <annma@kde.org>                     *
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
00021  ***************************************************************************/
00022 
00023 #include <QString>
00024 #include <QPixmap>
00025 #include <QStandardItem>
00026 
00027 #include <KDebug>
00028 #include <kstandarddirs.h>
00029 
00030 #include "choicepage.h"
00031 #include "prefs.h"
00032 #include "apptemplatesmodel.h"
00033 
00034 ChoicePage::ChoicePage( QWidget *parent)
00035     : QWizardPage(parent)
00036 {
00037     setTitle(i18n("Choose your project template"));
00038     ui_choice.setupUi(this);
00039     //Get the model
00040     templatesModel = new AppTemplatesModel(this);
00041     templatesModel->refresh();
00042     ui_choice.appTree->setModel(templatesModel); 
00043     ui_choice.appTree->expandAll();
00044     connect(ui_choice.kcfg_appName, SIGNAL(textChanged(const QString &)), this, SIGNAL(completeChanged()));
00045     connect(this, SIGNAL(completeChanged()), this, SLOT(saveConfig()));
00046     connect(ui_choice.appTree->selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), this, SLOT(itemSelected(QModelIndex)));
00047     QRegExp rx("[a-zA-Z0-9_]*");
00048     QValidator *validator = new QRegExpValidator(rx, this);
00049     ui_choice.kcfg_appName->setValidator(validator);
00050     registerField("appName*", ui_choice.kcfg_appName);
00051 }
00052 
00053 bool ChoicePage::isComplete () const{
00054     if(!m_baseName.isEmpty() && !ui_choice.kcfg_appName->text().isEmpty()){
00055         return true;
00056     }
00057 
00058     return false;
00059 }
00060 
00061 void ChoicePage::saveConfig()
00062 {
00063     Prefs::setAppName(ui_choice.kcfg_appName->text());
00064     Prefs::self()->writeConfig();
00065 }
00066 
00067 void ChoicePage::itemSelected(const QModelIndex &index)
00068 {
00069     if (!index.isValid()){
00070         emit completeChanged();
00071     return;
00072     }
00073     //get picture 
00074     KStandardDirs* dirs = KGlobal::dirs();
00075     kDebug() << index.data(Qt::UserRole+2);
00076     QString picPath = dirs->findResource("apptemplate_previews", index.data(Qt::UserRole+2).toString());
00077     if (index.data(Qt::UserRole+2).toString().isEmpty()) {
00078     picPath = dirs->findResource("apptemplate_previews", "default.png");//default if none
00079     }
00080     QPixmap pixmap(picPath);
00081     ui_choice.pictureLabel->setPixmap(pixmap);
00082     //and description
00083     QString description;
00084     if (index.data(Qt::UserRole+1).toString().isEmpty())  {
00085     description = i18n("Template description");//default if none
00086     } else {
00087     description = index.data(Qt::UserRole+1).toString();
00088     }
00089     ui_choice.descriptionLabel->setText(description);
00090     //Template view name
00091     QStandardItem *item = templatesModel->itemFromIndex(index);
00092 
00093     m_baseName = index.data(Qt::UserRole+3).toString();
00094     //baseName can check if an item is selected.
00095     if (!m_baseName.isEmpty())  {
00096         ui_choice.kcfg_appName->setFocus(Qt::MouseFocusReason);
00097     }
00098     registerField("tempName", this);
00099     setField("tempName", m_baseName);
00100     emit completeChanged();
00101 }
00102 
00103 #include "choicepage.moc"

kapptemplate

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

kdesdk

Skip menu "kdesdk"
  • kapptemplate
  • kate
  •     kate
  • kbugbuster
  • kcachegrind
  • kompare
  • lokalize
  • umbrello
  •   umbrello
Generated for kdesdk by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal