kapptemplate
choicepage.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
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
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");
00079 }
00080 QPixmap pixmap(picPath);
00081 ui_choice.pictureLabel->setPixmap(pixmap);
00082
00083 QString description;
00084 if (index.data(Qt::UserRole+1).toString().isEmpty()) {
00085 description = i18n("Template description");
00086 } else {
00087 description = index.data(Qt::UserRole+1).toString();
00088 }
00089 ui_choice.descriptionLabel->setText(description);
00090
00091 QStandardItem *item = templatesModel->itemFromIndex(index);
00092
00093 m_baseName = index.data(Qt::UserRole+3).toString();
00094
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"