1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
/**********************************************************************
This file is based on Qt Designer, Copyright (C) 2000 Trolltech AS. �All rights reserved.
This file may be distributed and/or modified under the terms of the
GNU General Public License version 2 as published by the Free Software
Foundation and appearing in the file LICENSE.GPL included in the
packaging of this file.
This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
See http://www.trolltech.com/gpl/ for GPL licensing information.
Modified for Kommander:
(C) 2004 Michal Rudolf <[email protected]>
**********************************************************************/
#include "newformimpl.h"
#include "mainwindow.h"
#include "pixmapchooser.h"
#include "metadatabase.h"
#include "formwindow.h"
#include "widgetfactory.h"
#include "widgetdatabase.h"
#include "actioneditorimpl.h"
#include "hierarchyview.h"
#include "resource.h"
#include "formfile.h"
#include <qiconview.h>
#include <qlabel.h>
#include <qfileinfo.h>
#include <qdir.h>
#include <qregexp.h>
#include <qpushbutton.h>
#include <stdlib.h>
#include <qcombobox.h>
#include <qworkspace.h>
#include <qmessagebox.h>
#include <klocale.h>
#include <kglobal.h>
#include <kstandarddirs.h>
#include "dialog.h"
static int _forms = 0;
FormItem::FormItem(QIconView *view, const QString &text) : NewItem(view, text)
{
}
void FormItem::insert()
{
QString n = "Form" + QString::number(++_forms);
FormWindow *fw = 0;
FormFile *ff = new FormFile(FormFile::createUnnamedFileName(), true);
fw = new FormWindow(ff, MainWindow::self, MainWindow::self->qWorkspace(), n);
MetaDataBase::addEntry(fw);
QWidget *w = 0L;
if (fType == Dialog)
{
w = WidgetFactory::create(WidgetDatabase::idFromClassName("Dialog"), fw, n.latin1());
fw->setMainContainer(w);
}
else if (fType == Wizard)
{
w = WidgetFactory::create(WidgetDatabase::idFromClassName("Wizard"), fw, n.latin1());
fw->setMainContainer(w);
}
if (w)
{
w->setProperty("useInternalParser", true);
MetaDataBase::setPropertyChanged(w, "useInternalParser", true);
}
fw->setCaption(n);
fw->resize(600, 480);
MainWindow::self->insertFormWindow(fw);
// the wizard might have changed a lot, lets update everything
MainWindow::self->actioneditor()->setFormWindow(fw);
MainWindow::self->objectHierarchy()->setFormWindow(fw, fw);
fw->killAccels(fw);
fw->setFocus();
}
CustomFormItem::CustomFormItem(QIconView *view, const QString &text)
: NewItem(view, text)
{
}
static void unifyFormName(FormWindow *fw, QWorkspace *qworkspace)
{
QStringList lst;
QWidgetList windows = qworkspace->windowList();
for (QWidget* w = windows.first(); w; w = windows.next())
if (w != fw)
lst << w->name();
if (lst.findIndex(fw->name()) == -1)
return;
QString origName = fw->name();
QString n = origName;
int i = 1;
while (lst.findIndex(n) != -1)
n = origName + QString::number(i++);
fw->setName(n);
fw->setCaption(n);
}
void CustomFormItem::insert()
{
QString filename = templateFileName();
if (!filename.isEmpty() && QFile::exists(filename))
{
Resource resource(MainWindow::self);
FormFile *ff = new FormFile(filename, true);
if (!resource.load(ff))
{
QMessageBox::information(MainWindow::self, i18n("Load Template"),
i18n("Could not load form description from template '%1'").arg(filename));
delete ff;
return;
}
ff->setFileName(QString::null);
if (MainWindow::self->formWindow())
{
MainWindow::self->formWindow()->setFileName(QString::null);
unifyFormName(MainWindow::self->formWindow(), MainWindow::self->qWorkspace());
}
}
}
NewForm::NewForm(QWidget *parent, const QString &templatePath)
: NewFormBase(parent, 0, true)
{
connect(helpButton, SIGNAL(clicked()), MainWindow::self, SLOT(showDialogHelp()));
QIconViewItem *cur = 0;
FormItem *fi = new FormItem(templateView, i18n("Dialog"));
allItems.append(fi);
fi->setFormType(FormItem::Dialog);
fi->setPixmap(PixmapChooser::loadPixmap("newform.xpm"));
fi->setDragEnabled(false);
cur = fi;
fi = new FormItem(templateView, i18n("Wizard"));
allItems.append(fi);
fi->setFormType(FormItem::Wizard);
fi->setPixmap(PixmapChooser::loadPixmap("newform.xpm"));
fi->setDragEnabled(false);
QStringList searchPaths = KGlobal::dirs()->findDirs("data", "kmdr-editor/templates");
if (!templatePath.isEmpty())
searchPaths.append(templatePath);
// search each path
for (QStringList::ConstIterator it = searchPaths.begin(); it != searchPaths.end(); ++it)
{
if (!QFile::exists(*it))
continue;
QDir dir(*it);
const QFileInfoList* fileList = dir.entryInfoList(QDir::DefaultFilter, QDir::DirsFirst | QDir::Name);
if (fileList)
for (QFileInfoListIterator fit(*fileList); fit.current(); ++fit)
{
QFileInfo* fi = fit.current();
if (!fi->isFile() || fi->extension() != "kmdr")
continue;
QString name = fi->baseName();
name = name.replace("_", " ");
CustomFormItem *ci = new CustomFormItem(templateView, name);
allItems.append(ci);
ci->setDragEnabled(false);
ci->setPixmap(PixmapChooser::loadPixmap("newform.xpm"));
ci->setTemplateFile(fi->absFilePath());
}
}
templateView->viewport()->setFocus();
templateView->setCurrentItem(cur);
}
void NewForm::accept()
{
if (!templateView->currentItem())
return;
((NewItem *) templateView->currentItem())->insert();
NewFormBase::accept();
}
void NewForm::itemChanged(QIconViewItem *item)
{
Q_UNUSED(item);
}
#include "newformimpl.moc"
|