Diffstat (limited to 'noncore/apps/tinykate/libkate/document/katedialogs.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/tinykate/libkate/document/katedialogs.cpp | 588 |
1 files changed, 588 insertions, 0 deletions
diff --git a/noncore/apps/tinykate/libkate/document/katedialogs.cpp b/noncore/apps/tinykate/libkate/document/katedialogs.cpp new file mode 100644 index 0000000..2f0ed7b --- a/dev/null +++ b/noncore/apps/tinykate/libkate/document/katedialogs.cpp | |||
@@ -0,0 +1,588 @@ | |||
1 | /*************************************************************************** | ||
2 | katedialogs.cpp - description | ||
3 | ------------------- | ||
4 | copyright : (C) 2001 by The Kate Team | ||
5 | (C) 2002 by Joseph Wenninger | ||
6 | email : kwrite-devel@kde.org | ||
7 | jowenn@kde.org | ||
8 | |||
9 | ***************************************************************************/ | ||
10 | |||
11 | /*************************************************************************** | ||
12 | * * | ||
13 | * This program is free software; you can redistribute it and/or modify * | ||
14 | * it under the terms of the GNU General Public License as published by * | ||
15 | * the Free Software Foundation; either version 2 of the License, or * | ||
16 | * (at your option) any later version. * | ||
17 | * * | ||
18 | ***************************************************************************/ | ||
19 | #include "katedialogs.h" | ||
20 | #include <klocale.h> | ||
21 | #include <kdebug.h> | ||
22 | #include <qgroupbox.h> | ||
23 | #include <qvgroupbox.h> | ||
24 | #include <qhgroupbox.h> | ||
25 | #include <qhbox.h> | ||
26 | #include <qvbox.h> | ||
27 | #include <qlayout.h> | ||
28 | #include <qpushbutton.h> | ||
29 | #include <qwidgetstack.h> | ||
30 | #include <qlabel.h> | ||
31 | #include <qlistview.h> | ||
32 | #include <qlineedit.h> | ||
33 | #include <qcombobox.h> | ||
34 | #include <qcheckbox.h> | ||
35 | //FIXME #include <kcharsets.h> | ||
36 | #include <kglobal.h> | ||
37 | #include <qmap.h> | ||
38 | #include <kmessagebox.h> | ||
39 | #include <kstddirs.h> | ||
40 | |||
41 | |||
42 | /******************************************************************************************************************* | ||
43 | * Context Editor * | ||
44 | *******************************************************************************************************************/ | ||
45 | |||
46 | StyleChanger::StyleChanger( QWidget *parent ) | ||
47 | : QWidget(parent) | ||
48 | { | ||
49 | QLabel *label; | ||
50 | |||
51 | QGridLayout *glay = new QGridLayout( this, 4, 3, 0, KDialog::spacingHint() ); | ||
52 | CHECK_PTR(glay); | ||
53 | glay->addColSpacing( 1, KDialog::spacingHint() ); // Looks better | ||
54 | glay->setColStretch( 2, 10 ); | ||
55 | |||
56 | col = new KColorButton(this); | ||
57 | CHECK_PTR(col); | ||
58 | connect(col,SIGNAL(changed(const QColor &)),this,SLOT(changed())); | ||
59 | label = new QLabel(col,i18n("Normal:"),this); | ||
60 | CHECK_PTR(label); | ||
61 | glay->addWidget(label,0,0); | ||
62 | glay->addWidget(col,1,0); | ||
63 | |||
64 | selCol = new KColorButton(this); | ||
65 | CHECK_PTR(selCol); | ||
66 | connect(selCol,SIGNAL(changed(const QColor &)),this,SLOT(changed())); | ||
67 | label = new QLabel(selCol,i18n("Selected:"),this); | ||
68 | CHECK_PTR(label); | ||
69 | glay->addWidget(label,2,0); | ||
70 | glay->addWidget(selCol,3,0); | ||
71 | |||
72 | bold = new QCheckBox(i18n("Bold"),this); | ||
73 | CHECK_PTR(bold); | ||
74 | connect(bold,SIGNAL(clicked()),SLOT(changed())); | ||
75 | glay->addWidget(bold,1,2); | ||
76 | |||
77 | italic = new QCheckBox(i18n("Italic"),this); | ||
78 | CHECK_PTR(italic); | ||
79 | connect(italic,SIGNAL(clicked()),SLOT(changed())); | ||
80 | glay->addWidget(italic,2,2); | ||
81 | } | ||
82 | |||
83 | void StyleChanger::setRef(ItemStyle *s) { | ||
84 | |||
85 | style = s; | ||
86 | col->setColor(style->col); | ||
87 | selCol->setColor(style->selCol); | ||
88 | bold->setChecked(style->bold); | ||
89 | italic->setChecked(style->italic); | ||
90 | |||
91 | } | ||
92 | |||
93 | void StyleChanger::setEnabled(bool enable) { | ||
94 | |||
95 | col->setEnabled(enable); | ||
96 | selCol->setEnabled(enable); | ||
97 | bold->setEnabled(enable); | ||
98 | italic->setEnabled(enable); | ||
99 | } | ||
100 | |||
101 | void StyleChanger::changed() { | ||
102 | |||
103 | if (style) { | ||
104 | style->col = col->color(); | ||
105 | style->selCol = selCol->color(); | ||
106 | style->bold = bold->isChecked(); | ||
107 | style->italic = italic->isChecked(); | ||
108 | } | ||
109 | } | ||
110 | |||
111 | HighlightDialog::HighlightDialog( HlManager *hlManager, ItemStyleList *styleList, | ||
112 | HlDataList *highlightDataList, | ||
113 | int hlNumber, QWidget *parent, | ||
114 | const char *name, bool modal ) | ||
115 | :KDialogBase(parent,name,modal,i18n("Highlight Settings"), Ok|Cancel, Ok) | ||
116 | { | ||
117 | // QVBox *page = makeVBoxMainWidget(); | ||
118 | QFrame *page=addPage("FIXME"); | ||
119 | (new QVBoxLayout(page))->setAutoAdd(true); | ||
120 | content=new HighlightDialogPage(hlManager,styleList,highlightDataList,hlNumber,page); | ||
121 | } | ||
122 | |||
123 | void HighlightDialog::done(int r) | ||
124 | { | ||
125 | kdDebug(13010)<<"HighlightDialod done"<<endl; | ||
126 | content->saveData(); | ||
127 | KDialogBase::done(r); | ||
128 | } | ||
129 | |||
130 | HighlightDialogPage::HighlightDialogPage(HlManager *hlManager, ItemStyleList *styleList, | ||
131 | HlDataList* highlightDataList, | ||
132 | int hlNumber,QWidget *parent, const char *name) | ||
133 | :QTabWidget(parent,name),defaultItemStyleList(styleList),hlData(0L) | ||
134 | |||
135 | { | ||
136 | |||
137 | // defaults ========================================================= | ||
138 | |||
139 | QFrame *page1 = new QFrame(this); | ||
140 | addTab(page1,i18n("&Defaults")); | ||
141 | QGridLayout *grid = new QGridLayout(page1, 1, 1); | ||
142 | |||
143 | QVGroupBox *dvbox1 = new QVGroupBox( i18n("Default Item Styles"), page1 ); | ||
144 | /*QLabel *label = */new QLabel( i18n("Item:"), dvbox1 ); | ||
145 | QComboBox *styleCombo = new QComboBox( false, dvbox1 ); | ||
146 | defaultStyleChanger = new StyleChanger( dvbox1 ); | ||
147 | for( int i = 0; i < hlManager->defaultStyles(); i++ ) { | ||
148 | styleCombo->insertItem(hlManager->defaultStyleName(i)); | ||
149 | } | ||
150 | connect(styleCombo, SIGNAL(activated(int)), this, SLOT(defaultChanged(int))); | ||
151 | grid->addWidget(dvbox1, 0,0); | ||
152 | |||
153 | defaultChanged(0); | ||
154 | |||
155 | // highlight modes ===================================================== | ||
156 | |||
157 | QFrame *page2 = new QFrame(this); | ||
158 | addTab(page2,i18n("&Highlight Modes")); | ||
159 | //grid = new QGridLayout(page2,2,2); | ||
160 | QVBoxLayout *bl=new QVBoxLayout(page2); | ||
161 | bl->setAutoAdd(true); | ||
162 | QHGroupBox *hbox1 = new QHGroupBox( i18n("Config Select"), page2 ); | ||
163 | hbox1->layout()->setMargin(5); | ||
164 | QVBox *vbox1=new QVBox(hbox1); | ||
165 | // grid->addMultiCellWidget(vbox1,0,0,0,1); | ||
166 | QVGroupBox *vbox2 = new QVGroupBox( i18n("Item Style"), page2 ); | ||
167 | // grid->addWidget(vbox2,1,0); | ||
168 | QVGroupBox *vbox3 = new QVGroupBox( i18n("Highlight Auto Select"), hbox1 ); | ||
169 | //grid->addWidget(vbox3,1,1); | ||
170 | |||
171 | QLabel *label = new QLabel( i18n("Highlight:"), vbox1 ); | ||
172 | hlCombo = new QComboBox( false, vbox1 ); | ||
173 | QHBox *modHl = new QHBox(vbox1); | ||
174 | // connect(new QPushButton(i18n("New"),modHl),SIGNAL(clicked()),this,SLOT(hlNew())); | ||
175 | // connect(new QPushButton(i18n("Edit"),modHl),SIGNAL(clicked()),this,SLOT(hlEdit())); | ||
176 | connect( hlCombo, SIGNAL(activated(int)), | ||
177 | this, SLOT(hlChanged(int)) ); | ||
178 | for( int i = 0; i < hlManager->highlights(); i++) { | ||
179 | hlCombo->insertItem(hlManager->hlName(i)); | ||
180 | } | ||
181 | hlCombo->setCurrentItem(hlNumber); | ||
182 | |||
183 | |||
184 | label = new QLabel( i18n("Item:"), vbox2 ); | ||
185 | itemCombo = new QComboBox( false, vbox2 ); | ||
186 | connect( itemCombo, SIGNAL(activated(int)), this, SLOT(itemChanged(int)) ); | ||
187 | |||
188 | label = new QLabel( i18n("File Extensions:"), vbox3 ); | ||
189 | wildcards = new QLineEdit( vbox3 ); | ||
190 | label = new QLabel( i18n("Mime Types:"), vbox3 ); | ||
191 | mimetypes = new QLineEdit( vbox3 ); | ||
192 | |||
193 | |||
194 | styleDefault = new QCheckBox(i18n("Default"), vbox2 ); | ||
195 | connect(styleDefault,SIGNAL(clicked()),SLOT(changed())); | ||
196 | styleChanger = new StyleChanger( vbox2 ); | ||
197 | |||
198 | hlDataList = highlightDataList; | ||
199 | hlChanged(hlNumber); | ||
200 | } | ||
201 | |||
202 | |||
203 | void HighlightDialogPage::defaultChanged(int z) | ||
204 | { | ||
205 | defaultStyleChanger->setRef(defaultItemStyleList->at(z)); | ||
206 | } | ||
207 | |||
208 | |||
209 | void HighlightDialogPage::hlChanged(int z) | ||
210 | { | ||
211 | writeback(); | ||
212 | |||
213 | hlData = hlDataList->at(z); | ||
214 | |||
215 | wildcards->setText(hlData->wildcards); | ||
216 | mimetypes->setText(hlData->mimetypes); | ||
217 | |||
218 | itemCombo->clear(); | ||
219 | for (ItemData *itemData = hlData->itemDataList.first(); itemData != 0L; | ||
220 | itemData = hlData->itemDataList.next()) { | ||
221 | kdDebug(13010) << itemData->name << endl; | ||
222 | itemCombo->insertItem(i18n(itemData->name.latin1())); | ||
223 | } | ||
224 | |||
225 | itemChanged(0); | ||
226 | } | ||
227 | |||
228 | void HighlightDialogPage::itemChanged(int z) | ||
229 | { | ||
230 | itemData = hlData->itemDataList.at(z); | ||
231 | |||
232 | styleDefault->setChecked(itemData->defStyle); | ||
233 | styleChanger->setRef(itemData); | ||
234 | } | ||
235 | |||
236 | void HighlightDialogPage::changed() | ||
237 | { | ||
238 | itemData->defStyle = styleDefault->isChecked(); | ||
239 | } | ||
240 | |||
241 | void HighlightDialogPage::writeback() { | ||
242 | if (hlData) { | ||
243 | hlData->wildcards = wildcards->text(); | ||
244 | hlData->mimetypes = mimetypes->text(); | ||
245 | } | ||
246 | } | ||
247 | |||
248 | void HighlightDialogPage::saveData() { | ||
249 | kdDebug(13010)<<"HighlightDialogPage::saveData()"<<endl; | ||
250 | writeback(); | ||
251 | } | ||
252 | |||
253 | |||
254 | void HighlightDialogPage::hlEdit() { | ||
255 | HlEditDialog diag(0,0,"hlEdit", true,hlData); | ||
256 | diag.show(); | ||
257 | } | ||
258 | |||
259 | void HighlightDialogPage::hlNew() { | ||
260 | HlEditDialog diag(0,0,"hlEdit",true,0); | ||
261 | diag.show(); | ||
262 | } | ||
263 | |||
264 | |||
265 | HlEditDialog::HlEditDialog(HlManager *,QWidget *parent, const char *name, bool modal,HlData *data) | ||
266 | :KDialogBase(KDialogBase::Swallow, i18n("Highlight Conditions"), Ok|Cancel, Ok, parent, name, modal) | ||
267 | { | ||
268 | currentItem=0; | ||
269 | transTableCnt=0; | ||
270 | QHBox *wid=new QHBox(this); | ||
271 | QVBox *lbox=new QVBox(wid); | ||
272 | contextList=new KListView(lbox); | ||
273 | contextList->setRootIsDecorated(true); | ||
274 | contextList->addColumn(i18n("Syntax structure")); | ||
275 | contextList->setSorting(-1); | ||
276 | QHBox *bbox=new QHBox(lbox); | ||
277 | QPushButton *addContext=new QPushButton(i18n("New Context"),bbox); | ||
278 | QPushButton *addItem=new QPushButton(i18n("New Item"),bbox); | ||
279 | QVGroupBox *opt = new QVGroupBox( i18n("Options"), wid); | ||
280 | stack=new QWidgetStack(opt); | ||
281 | initContextOptions(contextOptions=new QVBox(stack)); | ||
282 | stack->addWidget(contextOptions,HlEContext); | ||
283 | initItemOptions(itemOptions=new QVBox(stack)); | ||
284 | stack->addWidget(itemOptions,HlEItem); | ||
285 | stack->raiseWidget(HlEContext); | ||
286 | setMainWidget(wid); | ||
287 | if (data!=0) loadFromDocument(data); | ||
288 | else newDocument(); | ||
289 | connect(contextList,SIGNAL(currentChanged( QListViewItem*)),this,SLOT(currentSelectionChanged ( QListViewItem * ))); | ||
290 | connect(addContext,SIGNAL(clicked()),this,SLOT(contextAddNew())); | ||
291 | connect(addItem,SIGNAL(clicked()),this,SLOT(ItemAddNew())); | ||
292 | } | ||
293 | |||
294 | void HlEditDialog::newDocument() | ||
295 | { | ||
296 | KStandardDirs *dirs = KGlobal::dirs(); | ||
297 | QStringList list=dirs->findAllResources("data","kate/syntax/syntax.template",false,true); | ||
298 | for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) | ||
299 | { | ||
300 | HlData data("","",*it); | ||
301 | loadFromDocument(&data); | ||
302 | return; | ||
303 | } | ||
304 | KMessageBox::error(this,i18n("Can't find template file")); | ||
305 | } | ||
306 | |||
307 | |||
308 | void HlEditDialog::initContextOptions(QVBox *co) | ||
309 | { | ||
310 | if( co!=0) | ||
311 | { | ||
312 | QHBox *tmp = new QHBox(co); | ||
313 | (void) new QLabel(i18n("Description:"),tmp); | ||
314 | ContextDescr=new QLineEdit(tmp); | ||
315 | tmp= new QHBox(co); | ||
316 | (void) new QLabel(i18n("Attribute:"),tmp); | ||
317 | ContextAttribute=new QComboBox(tmp); | ||
318 | tmp= new QHBox(co); | ||
319 | (void) new QLabel(i18n("LineEnd:"),tmp); | ||
320 | ContextLineEnd = new QComboBox(tmp); | ||
321 | connect(ContextDescr,SIGNAL(textChanged(const QString&)),this,SLOT(contextDescrChanged(const QString&))); | ||
322 | connect(ContextLineEnd,SIGNAL(activated(int)),this,SLOT(contextLineEndChanged(int))); | ||
323 | connect(ContextAttribute,SIGNAL(activated(int)),this,SLOT(contextAttributeChanged(int))); | ||
324 | } | ||
325 | else | ||
326 | kdDebug(13010)<<"initContextOptions: Widget is 0"<<endl; | ||
327 | } | ||
328 | |||
329 | |||
330 | void HlEditDialog::insertTranslationList(QString tag, QString trans,int length) | ||
331 | { | ||
332 | ItemInfo data(trans,length); | ||
333 | id2tag.insert(transTableCnt,tag); | ||
334 | id2info.insert(transTableCnt,data); | ||
335 | tag2id.insert(tag,transTableCnt); | ||
336 | transTableCnt++; | ||
337 | } | ||
338 | |||
339 | |||
340 | void HlEditDialog::initItemOptions(QVBox *co) | ||
341 | { | ||
342 | if (co!=0) | ||
343 | { | ||
344 | QHBox *tmp = new QHBox(co); | ||
345 | (void) new QLabel(i18n("Type:"),tmp); | ||
346 | ItemType = new QComboBox(tmp); | ||
347 | tmp= new QHBox(co); | ||
348 | (void) new QLabel(i18n("Parameter:"),tmp); | ||
349 | ItemParameter= new QLineEdit(tmp); | ||
350 | tmp= new QHBox(co); | ||
351 | (void) new QLabel(i18n("Attribute:"),tmp); | ||
352 | ItemAttribute= new QComboBox(tmp); | ||
353 | (void) new QLabel(i18n("Context switch:"),tmp); | ||
354 | ItemContext = new QComboBox(tmp); | ||
355 | co->setSpacing(15); | ||
356 | QPushButton *delItem=new QPushButton(i18n("Delete this item"),co); | ||
357 | |||
358 | /* init translation lists */ | ||
359 | insertTranslationList("CharDetect","CharDetect",1); | ||
360 | insertTranslationList("2CharDetect","2CharDetect",2); | ||
361 | insertTranslationList("RangeDetect","RangeDetect",2); | ||
362 | insertTranslationList("StringDetect","StringDetect",-1); | ||
363 | insertTranslationList("AnyChar","AnyChar",-1); | ||
364 | insertTranslationList("RegExpr","RegExpr",-1); | ||
365 | insertTranslationList("Int","Int",0); | ||
366 | insertTranslationList("Float","Float",0); | ||
367 | insertTranslationList("keyword","keyword",0); | ||
368 | insertTranslationList("dataType","dataType",0); | ||
369 | ItemType->clear(); | ||
370 | for (int i=0; i<transTableCnt; i++) ItemType->insertItem(id2info[i].trans_i18n); | ||
371 | connect(ItemType,SIGNAL(activated(int)),this,SLOT(ItemTypeChanged(int))); | ||
372 | connect(ItemParameter,SIGNAL(textChanged(const QString&)),this,SLOT(ItemParameterChanged(const QString&))); | ||
373 | connect(ItemAttribute,SIGNAL(activated(int)),this,SLOT(ItemAttributeChanged(int))); | ||
374 | connect(ItemContext,SIGNAL(activated(int)),this,SLOT(ItemContextChanged(int))); | ||
375 | } | ||
376 | else | ||
377 | kdDebug(13010)<<"initItemOptions: Widget is 0"<<endl; | ||
378 | } | ||
379 | |||
380 | void HlEditDialog::loadFromDocument(HlData *hl) | ||
381 | { | ||
382 | struct syntaxContextData *data; | ||
383 | QListViewItem *last=0,*lastsub=0; | ||
384 | |||
385 | HlManager::self()->syntax->setIdentifier(hl->identifier); | ||
386 | data=HlManager::self()->syntax->getGroupInfo("highlighting","context"); | ||
387 | int i=0; | ||
388 | if (data) | ||
389 | { | ||
390 | while (HlManager::self()->syntax->nextGroup(data)) //<context tags> | ||
391 | { | ||
392 | kdDebug(13010)<< "Adding context to list"<<endl; | ||
393 | last= new QListViewItem(contextList,last, | ||
394 | HlManager::self()->syntax->groupData(data,QString("name")), | ||
395 | QString("%1").arg(i), | ||
396 | HlManager::self()->syntax->groupData(data,QString("attribute")), | ||
397 | HlManager::self()->syntax->groupData(data,QString("lineEndContext"))); | ||
398 | i++; | ||
399 | lastsub=0; | ||
400 | while (HlManager::self()->syntax->nextItem(data)) | ||
401 | { | ||
402 | kdDebug(13010)<< "Adding item to list"<<endl; | ||
403 | lastsub=addContextItem(last,lastsub,data); | ||
404 | } | ||
405 | |||
406 | |||
407 | } | ||
408 | if (data) HlManager::self()->syntax->freeGroupInfo(data); | ||
409 | } | ||
410 | ContextAttribute->clear(); | ||
411 | ItemAttribute->clear(); | ||
412 | data=HlManager::self()->syntax->getGroupInfo("highlighting","itemData"); | ||
413 | while (HlManager::self()->syntax->nextGroup(data)) | ||
414 | { | ||
415 | ContextAttribute->insertItem(HlManager::self()->syntax->groupData(data,QString("name"))); | ||
416 | ItemAttribute->insertItem(HlManager::self()->syntax->groupData(data,QString("name"))); | ||
417 | } | ||
418 | if (data) HlManager::self()->syntax->freeGroupInfo(data); | ||
419 | } | ||
420 | |||
421 | QListViewItem *HlEditDialog::addContextItem(QListViewItem *_parent,QListViewItem *prev,struct syntaxContextData *data) | ||
422 | { | ||
423 | |||
424 | kdDebug(13010)<<HlManager::self()->syntax->groupItemData(data,QString("name")) << endl; | ||
425 | |||
426 | QString dataname=HlManager::self()->syntax->groupItemData(data,QString("")); | ||
427 | QString attr=(HlManager::self()->syntax->groupItemData(data,QString("attribute"))); | ||
428 | QString context=(HlManager::self()->syntax->groupItemData(data,QString("context"))); | ||
429 | char chr; | ||
430 | if (! HlManager::self()->syntax->groupItemData(data,QString("char")).isEmpty()) | ||
431 | chr= (HlManager::self()->syntax->groupItemData(data,QString("char")).latin1())[0]; | ||
432 | else | ||
433 | chr=0; | ||
434 | QString stringdata=HlManager::self()->syntax->groupItemData(data,QString("String")); | ||
435 | char chr1; | ||
436 | if (! HlManager::self()->syntax->groupItemData(data,QString("char1")).isEmpty()) | ||
437 | chr1= (HlManager::self()->syntax->groupItemData(data,QString("char1")).latin1())[0]; | ||
438 | else | ||
439 | chr1=0; | ||
440 | bool insensitive=(HlManager::self()->syntax->groupItemData(data,QString("insensitive"))==QString("TRUE")); | ||
441 | QString param(""); | ||
442 | if ((dataname=="keyword") || (dataname=="dataType")) param=dataname; | ||
443 | else if (dataname=="CharDetect") param=chr; | ||
444 | else if ((dataname=="2CharDetect") || (dataname=="RangeDetect")) param=QString("%1%2").arg(chr).arg(chr1); | ||
445 | else if ((dataname=="StringDetect") || (dataname=="AnyChar") || (dataname=="RegExpr")) param=stringdata; | ||
446 | else kdDebug(13010)<<"***********************************"<<endl<<"Unknown entry for Context:"<<dataname<<endl; | ||
447 | kdDebug(13010)<<dataname << endl; | ||
448 | return new QListViewItem(_parent,prev,i18n(dataname.latin1())+" "+param,dataname,param,attr,context); | ||
449 | } | ||
450 | |||
451 | |||
452 | void HlEditDialog::currentSelectionChanged ( QListViewItem *it) | ||
453 | { | ||
454 | kdDebug(13010)<<"Update data view"<<endl<<"Depth:"<<it->depth()<<endl; | ||
455 | currentItem=it; | ||
456 | if (it->depth()==0) showContext(); | ||
457 | else showItem(); | ||
458 | } | ||
459 | |||
460 | |||
461 | /****************************************************************************/ | ||
462 | /* CONTEXTS */ | ||
463 | /****************************************************************************/ | ||
464 | |||
465 | |||
466 | void HlEditDialog::showContext() | ||
467 | { | ||
468 | stack->raiseWidget(HlEContext); | ||
469 | ContextDescr->setText(currentItem->text(0)); | ||
470 | ContextAttribute->setCurrentItem(currentItem->text(2).toInt()); | ||
471 | ContextLineEnd->clear(); | ||
472 | for (QListViewItem *it=contextList->firstChild();it;it=it->nextSibling()) | ||
473 | ContextLineEnd->insertItem(it->text(0)); | ||
474 | ContextLineEnd->setCurrentItem(currentItem->text(3).toInt()); | ||
475 | // ContextAttribute->setText(currentItem->text(1)); | ||
476 | // ContextLineEnd->setText(currentItem->text(2)); | ||
477 | } | ||
478 | |||
479 | void HlEditDialog::contextDescrChanged(const QString& name) | ||
480 | { | ||
481 | if (currentItem) | ||
482 | { | ||
483 | currentItem->setText(0,name); | ||
484 | ContextLineEnd->changeItem(name,currentItem->text(3).toInt()); | ||
485 | } | ||
486 | } | ||
487 | |||
488 | void HlEditDialog::contextAttributeChanged(int id) | ||
489 | { | ||
490 | if (currentItem) | ||
491 | { | ||
492 | currentItem->setText(2,QString("%1").arg(id)); | ||
493 | } | ||
494 | } | ||
495 | |||
496 | void HlEditDialog::contextLineEndChanged(int id) | ||
497 | { | ||
498 | kdDebug(13010)<<"contextLineEndChanged"<<endl; | ||
499 | if (currentItem) | ||
500 | { | ||
501 | currentItem->setText(3,QString("%1").arg(id)); | ||
502 | } | ||
503 | } | ||
504 | |||
505 | void HlEditDialog::contextAddNew() | ||
506 | { | ||
507 | QListViewItem *it=contextList->firstChild(); | ||
508 | for (;it->nextSibling()!=0;it=it->nextSibling()); | ||
509 | it=new QListViewItem(contextList,it,i18n("New Context"),QString("%1").arg(it->text(1).toInt()),"0","0"); | ||
510 | contextList->setSelected(it,true); | ||
511 | } | ||
512 | |||
513 | /****************************************************************************/ | ||
514 | /* ITEMS */ | ||
515 | /****************************************************************************/ | ||
516 | |||
517 | void HlEditDialog::showItem() | ||
518 | { | ||
519 | stack->raiseWidget(HlEItem); | ||
520 | ItemContext->clear(); | ||
521 | for (QListViewItem *it=contextList->firstChild();it;it=it->nextSibling()) | ||
522 | ItemContext->insertItem(it->text(0)); | ||
523 | ItemContext->setCurrentItem(currentItem->text(4).toInt()); | ||
524 | ItemAttribute->setCurrentItem(currentItem->text(3).toInt()); | ||
525 | QMap<QString,int>::Iterator iter=tag2id.find(currentItem->text(1)); | ||
526 | if (iter==tag2id.end()) | ||
527 | kdDebug(13010)<<"Oops, unknown itemtype in showItem: "<<currentItem->text(1)<<endl; | ||
528 | else | ||
529 | { | ||
530 | ItemType->setCurrentItem(*iter); | ||
531 | if (id2info[*iter].length==0) ItemParameter->hide(); | ||
532 | else | ||
533 | { | ||
534 | ItemParameter->setMaxLength(id2info[*iter].length); | ||
535 | ItemParameter->show(); | ||
536 | ItemParameter->setText(currentItem->text(2)); | ||
537 | } | ||
538 | } | ||
539 | |||
540 | } | ||
541 | |||
542 | void HlEditDialog::ItemTypeChanged(int id) | ||
543 | { | ||
544 | if (currentItem) | ||
545 | { | ||
546 | currentItem->setText(1,id2tag[id]); | ||
547 | ItemParameter->setMaxLength(id2info[id].length); | ||
548 | ItemParameterChanged(ItemParameter->text()); | ||
549 | } | ||
550 | } | ||
551 | |||
552 | void HlEditDialog::ItemParameterChanged(const QString& name) | ||
553 | { | ||
554 | if (currentItem) | ||
555 | { | ||
556 | currentItem->setText(2,name); | ||
557 | currentItem->setText(0,id2info[ItemType->currentItem()].trans_i18n+" "+currentItem->text(2)); | ||
558 | } | ||
559 | } | ||
560 | |||
561 | void HlEditDialog::ItemAttributeChanged(int attr) | ||
562 | { | ||
563 | if (currentItem) | ||
564 | { | ||
565 | currentItem->setText(3,QString("%1").arg(attr)); | ||
566 | } | ||
567 | } | ||
568 | |||
569 | void HlEditDialog::ItemContextChanged(int cont) | ||
570 | { | ||
571 | if (currentItem) | ||
572 | { | ||
573 | currentItem->setText(4,QString("%1").arg(cont)); | ||
574 | } | ||
575 | } | ||
576 | |||
577 | void HlEditDialog::ItemAddNew() | ||
578 | { | ||
579 | QListViewItem *it; | ||
580 | if (currentItem) | ||
581 | { | ||
582 | if (currentItem->depth()==0) it=currentItem->firstChild(); | ||
583 | else | ||
584 | it=currentItem; | ||
585 | if (it) for (;it->nextSibling();it=it->nextSibling()); | ||
586 | (void) new QListViewItem(it ? it->parent() : currentItem,it,"StringDetect "+i18n("New Item"),"StringDetect",i18n("New Item"),0,it ? it->parent()->text(1) : currentItem->text(1)); | ||
587 | } | ||
588 | } | ||