preferencesdlg.ui.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. /****************************************************************************
  2. ** ui.h extension file, included from the uic-generated form implementation.
  3. **
  4. ** If you want to add, delete, or rename functions or slots, use
  5. ** Qt Designer to update this file, preserving your code.
  6. **
  7. ** You should not define a constructor or destructor in this file.
  8. ** Instead, write your code in functions called init() and destroy().
  9. ** These will automatically be called by the form's constructor and
  10. ** destructor.
  11. *****************************************************************************/
  12. /*
  13. ktigcc - TIGCC IDE for KDE
  14. Copyright (C) 2006 Kevin Kofler
  15. This program is free software; you can redistribute it and/or modify
  16. it under the terms of the GNU General Public License as published by
  17. the Free Software Foundation; either version 2, or (at your option)
  18. any later version.
  19. This program is distributed in the hope that it will be useful,
  20. but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. GNU General Public License for more details.
  23. You should have received a copy of the GNU General Public License
  24. along with this program; if not, write to the Free Software Foundation,
  25. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  26. */
  27. #include "preferences.h"
  28. #include <qcheckbox.h>
  29. #include <qradiobutton.h>
  30. #include <qaccel.h>
  31. #include <qcolor.h>
  32. #include <qvaluelist.h>
  33. #include <qapplication.h>
  34. #include <qeventloop.h>
  35. #include <knuminput.h>
  36. #include <kfontdialog.h>
  37. #include <kcolordialog.h>
  38. #include <kcombobox.h>
  39. #include <klistview.h>
  40. #include <klineedit.h>
  41. #include <keditlistbox.h>
  42. #include <klistbox.h>
  43. #include "ktigcc.h"
  44. #include "selectstyle.h"
  45. #include "selectcolors.h"
  46. #include "colorlistitem.h"
  47. #include "customstyle.h"
  48. #include "wordlist.h"
  49. class RenamableKListViewItem : public KListViewItem {
  50. public:
  51. RenamableKListViewItem(QListViewItem *parent, QString text)
  52. : KListViewItem(parent, text)
  53. {
  54. setRenameEnabled(0,TRUE);
  55. }
  56. RenamableKListViewItem(QListViewItem *parent, QListViewItem *after,
  57. QString text)
  58. : KListViewItem(parent, after, text)
  59. {
  60. setRenameEnabled(0,TRUE);
  61. }
  62. virtual int rtti(void) const {return 0x716CC8;}
  63. // Work around gratuitous API difference. Why do I have to do this? That's
  64. // what startRename is a virtual method for. KListViewItem should do this.
  65. virtual void startRename(int col)
  66. {
  67. static_cast<KListView *>(listView())->rename(this,col);
  68. }
  69. };
  70. class ListBoxTextPair : public QListBoxText {
  71. public:
  72. ListBoxTextPair(QListBox *listbox, const QString &text,
  73. const QString &data)
  74. : QListBoxText(listbox,text), m_data(data) {}
  75. virtual ~ListBoxTextPair() {}
  76. void setData(const QString &data) {m_data=data;}
  77. QString data() {return m_data;}
  78. private:
  79. QString m_data;
  80. };
  81. void Preferences::init()
  82. {
  83. // General
  84. stopAtFirstError->setChecked(preferences.stopAtFirstError);
  85. jumpToError->setChecked(preferences.jumpToError);
  86. successMessage->setChecked(preferences.successMessage);
  87. deleteAsmFiles->setChecked(preferences.deleteAsmFiles);
  88. deleteObjFiles->setChecked(preferences.deleteObjFiles);
  89. splitSourceFiles->setChecked(preferences.splitSourceFiles);
  90. allowImplicitDeclaration->setChecked(preferences.allowImplicitDeclaration);
  91. autoSave->setChecked(preferences.autoSave);
  92. downloadHeadlines->setChecked(preferences.downloadHeadlines);
  93. deleteOverwrittenErrors->setChecked(preferences.deleteOverwrittenErrors);
  94. useSystemIcons->setChecked(preferences.useSystemIcons);
  95. // Transfer
  96. switch (preferences.linkTarget) {
  97. default: // LT_NONE
  98. targetNone->setChecked(TRUE);
  99. break;
  100. case LT_TIEMU:
  101. targetTiEmu->setChecked(TRUE);
  102. break;
  103. case LT_REALCALC:
  104. targetRealCalc->setChecked(TRUE);
  105. break;
  106. }
  107. switch (preferences.linkPort) {
  108. default: // PORT_1
  109. port1->setChecked(TRUE);
  110. break;
  111. case PORT_2:
  112. port2->setChecked(TRUE);
  113. break;
  114. case PORT_3:
  115. port3->setChecked(TRUE);
  116. break;
  117. case PORT_4:
  118. port4->setChecked(TRUE);
  119. break;
  120. }
  121. switch (preferences.linkCable) {
  122. default: // CABLE_GRY
  123. grayLink->setChecked(TRUE);
  124. break;
  125. case CABLE_BLK:
  126. blackLink->setChecked(TRUE);
  127. break;
  128. case CABLE_PAR:
  129. parallelLink->setChecked(TRUE);
  130. break;
  131. case CABLE_SLV:
  132. silverLink->setChecked(TRUE);
  133. break;
  134. case CABLE_USB:
  135. directLink->setChecked(TRUE);
  136. break;
  137. }
  138. // Don't allow selecting a USB cable if libticables2 hasn't been compiled
  139. // without USB support or if USB support can't be used.
  140. if (!have_usb) {
  141. if (silverLink->isChecked() || directLink->isChecked()) {
  142. grayLink->setChecked(TRUE);
  143. targetNone->setChecked(TRUE);
  144. }
  145. silverLink->setEnabled(FALSE);
  146. directLink->setEnabled(FALSE);
  147. }
  148. // Editor
  149. tabWidthC->setValue(preferences.tabWidthC);
  150. tabWidthAsm->setValue(preferences.tabWidthAsm);
  151. useBgColor->setChecked(preferences.useBgColor);
  152. bgColor->setBackgroundColor(preferences.bgColor);
  153. editorFont->setFont(preferences.editorFont);
  154. editorFont->setText(preferences.editorFont.family());
  155. useCalcCharset->setChecked(preferences.useCalcCharset);
  156. lazyLoading->setChecked(preferences.lazyLoading);
  157. autoBlocks->setChecked(preferences.autoBlocks);
  158. removeTrailingSpaces->setChecked(preferences.removeTrailingSpaces);
  159. // Syntax
  160. if (preferences.haveA68k)
  161. syntaxLanguage->insertItem("A68k Assembly Files");
  162. if (preferences.haveQuill)
  163. syntaxLanguage->insertItem("Quill Files");
  164. preferences.tempSynC=preferences.synC;
  165. preferences.tempSynS=preferences.synS;
  166. preferences.tempSynAsm=preferences.synAsm;
  167. preferences.tempSynQll=preferences.synQll;
  168. syntaxLanguage_activated(syntaxLanguage->currentItem());
  169. syntaxListView->setSorting(-1);
  170. syntaxListView->setColumnWidthMode(0,QListView::Maximum);
  171. syntaxListView->header()->hide();
  172. syntaxListView->setAlternateBackground(QColor());
  173. QListViewItem *rootListItem=syntaxListView->firstChild();
  174. QListViewItem *customStylesItem=rootListItem->firstChild();
  175. customStylesItem->setOpen(TRUE);
  176. QListViewItem *wordListsItem=customStylesItem->nextSibling();
  177. wordListsItem->setOpen(TRUE);
  178. QAccel *syntaxListViewAccel=new QAccel(syntaxListView);
  179. syntaxListViewAccel->insertItem(Key_Delete,0);
  180. connect(syntaxListViewAccel,SIGNAL(activated(int)),
  181. this,SLOT(syntaxListViewAccel_activated(int)));
  182. // Coding
  183. templateListBox->clear();
  184. for (QValueList<QPair<QString,QString> >::ConstIterator it=preferences.templates.begin();
  185. it!=preferences.templates.end(); ++it)
  186. new ListBoxTextPair(templateListBox,(*it).first,(*it).second);
  187. templateListBox->sort();
  188. }
  189. void Preferences::destroy()
  190. {
  191. if (result()==Accepted) {
  192. // General
  193. preferences.stopAtFirstError=stopAtFirstError->isChecked();
  194. preferences.jumpToError=jumpToError->isChecked();
  195. preferences.successMessage=successMessage->isChecked();
  196. preferences.deleteAsmFiles=deleteAsmFiles->isChecked();
  197. preferences.deleteObjFiles=deleteObjFiles->isChecked();
  198. preferences.splitSourceFiles=splitSourceFiles->isChecked();
  199. preferences.allowImplicitDeclaration=allowImplicitDeclaration->isChecked();
  200. preferences.autoSave=autoSave->isChecked();
  201. preferences.downloadHeadlines=downloadHeadlines->isChecked();
  202. preferences.deleteOverwrittenErrors=deleteOverwrittenErrors->isChecked();
  203. preferences.useSystemIcons=useSystemIcons->isChecked();
  204. // Transfer
  205. preferences.linkTarget=targetTiEmu->isChecked()?LT_TIEMU
  206. :targetRealCalc->isChecked()?LT_REALCALC
  207. :LT_NONE;
  208. preferences.linkPort=port2->isChecked()?PORT_2
  209. :port3->isChecked()?PORT_3
  210. :port4->isChecked()?PORT_4
  211. :PORT_1;
  212. preferences.linkCable=blackLink->isChecked()?CABLE_BLK
  213. :parallelLink->isChecked()?CABLE_PAR
  214. :silverLink->isChecked()?CABLE_SLV
  215. :directLink->isChecked()?CABLE_USB
  216. :CABLE_GRY;
  217. // Editor
  218. preferences.tabWidthC=tabWidthC->value();
  219. preferences.tabWidthAsm=tabWidthAsm->value();
  220. preferences.useBgColor=useBgColor->isChecked();
  221. preferences.bgColor=bgColor->backgroundColor();
  222. preferences.editorFont=editorFont->font();
  223. preferences.useCalcCharset=useCalcCharset->isChecked();
  224. preferences.lazyLoading=lazyLoading->isChecked();
  225. preferences.autoBlocks=autoBlocks->isChecked();
  226. preferences.removeTrailingSpaces=removeTrailingSpaces->isChecked();
  227. // Syntax
  228. preferences.synC=preferences.tempSynC;
  229. preferences.synS=preferences.tempSynS;
  230. preferences.synAsm=preferences.tempSynAsm;
  231. preferences.synQll=preferences.tempSynQll;
  232. // Coding
  233. preferences.templates.clear();
  234. for (QListBoxItem *item=templateListBox->firstItem(); item;
  235. item=item->next())
  236. preferences.templates.append(qMakePair(item->text(),
  237. static_cast<ListBoxTextPair *>(item)->data()));
  238. }
  239. }
  240. #define unused_on on __attribute__((unused))
  241. void Preferences::linkTarget_toggled(bool unused_on)
  242. {
  243. bool isRealCalc=targetRealCalc->isChecked();
  244. linkPort->setEnabled(isRealCalc);
  245. linkCable->setEnabled(isRealCalc);
  246. }
  247. void Preferences::bgColorChange_clicked()
  248. {
  249. QColor color=bgColor->backgroundColor();
  250. if (KColorDialog::getColor(color,this)==KColorDialog::Accepted) {
  251. useBgColor->setChecked(TRUE);
  252. bgColor->setBackgroundColor(color);
  253. }
  254. }
  255. void Preferences::editorFontChange_clicked()
  256. {
  257. QFont font=editorFont->font();
  258. if (KFontDialog::getFont(font,TRUE,this)==KFontDialog::Accepted) {
  259. editorFont->setFont(font);
  260. editorFont->setText(font.family());
  261. }
  262. }
  263. void Preferences::syntaxLanguage_activated(int index)
  264. {
  265. if (!index) preferences.syn=&preferences.tempSynC;
  266. else if (!--index) preferences.syn=&preferences.tempSynS;
  267. else if (preferences.haveA68k && !--index)
  268. preferences.syn=&preferences.tempSynAsm;
  269. else if (preferences.haveQuill && !--index)
  270. preferences.syn=&preferences.tempSynQll;
  271. else {
  272. qWarning("Preferences::syntaxLanguage_activated: Invalid index.");
  273. preferences.syn=&preferences.tempSynC;
  274. }
  275. syntaxEnabled->setChecked(preferences.syn->enabled);
  276. QListViewItem *rootListItem=syntaxListView->firstChild();
  277. QListViewItem *item, *nextItem;
  278. QListViewItem *customStylesItem=rootListItem->firstChild();
  279. for (item=customStylesItem->firstChild(); item; item=nextItem) {
  280. nextItem=item->nextSibling();
  281. delete item;
  282. }
  283. item=static_cast<QListViewItem *>(NULL);
  284. for (QValueList<Syn_CustomStyle>::ConstIterator it=
  285. preferences.syn->customStyles.begin();
  286. it!=preferences.syn->customStyles.end(); ++it) {
  287. item=new RenamableKListViewItem(customStylesItem,item,(*it).name);
  288. }
  289. QListViewItem *wordListsItem=customStylesItem->nextSibling();
  290. for (item=wordListsItem->firstChild(); item; item=nextItem) {
  291. nextItem=item->nextSibling();
  292. delete item;
  293. }
  294. item=static_cast<QListViewItem *>(NULL);
  295. for (QValueList<Syn_WordList>::ConstIterator it=
  296. preferences.syn->wordLists.begin();
  297. it!=preferences.syn->wordLists.end(); ++it) {
  298. item=new RenamableKListViewItem(wordListsItem,item,(*it).name);
  299. }
  300. }
  301. void Preferences::syntaxEnabled_toggled(bool on)
  302. {
  303. preferences.syn->enabled=on;
  304. resetButton->setEnabled(on);
  305. numberColorButton->setEnabled(on);
  306. numberStyleButton->setEnabled(on);
  307. symbolColorButton->setEnabled(on);
  308. symbolStyleButton->setEnabled(on);
  309. parenthesisColorsButton->setEnabled(on);
  310. parenthesisStyleButton->setEnabled(on);
  311. syntaxListView->setEnabled(on);
  312. newStyleButton->setEnabled(on);
  313. newListButton->setEnabled(on);
  314. QListViewItem *selectedItem=syntaxListView->selectedItem();
  315. editButton->setEnabled(on&&selectedItem&&selectedItem->rtti()==0x716CC8);
  316. }
  317. void Preferences::resetButton_clicked()
  318. {
  319. resetSyntaxPreference(preferences.syn);
  320. syntaxLanguage_activated(syntaxLanguage->currentItem());
  321. }
  322. void Preferences::numberColorButton_clicked()
  323. {
  324. QColor color=preferences.syn->numberColor;
  325. if (KColorDialog::getColor(color,this)==KColorDialog::Accepted)
  326. preferences.syn->numberColor=color;
  327. }
  328. void Preferences::numberStyleButton_clicked()
  329. {
  330. SelectStyle selectStyle(this);
  331. selectStyle.customStyle->setChecked(!!(preferences.syn->numberStyle&SYNS_CUSTOM));
  332. if (preferences.syn->numberStyle&SYNS_CUSTOM) {
  333. selectStyle.boldChk->setChecked(!!(preferences.syn->numberStyle&SYNS_BOLD));
  334. selectStyle.underlineChk->setChecked(!!(preferences.syn->numberStyle&SYNS_UNDERLINE));
  335. selectStyle.italicChk->setChecked(!!(preferences.syn->numberStyle&SYNS_ITALIC));
  336. selectStyle.strikeoutChk->setChecked(!!(preferences.syn->numberStyle&SYNS_STRIKEOUT));
  337. }
  338. selectStyle.exec();
  339. if (selectStyle.result()==QDialog::Accepted) {
  340. preferences.syn->numberStyle=0;
  341. if (selectStyle.customStyle->isChecked()) {
  342. preferences.syn->numberStyle|=SYNS_CUSTOM;
  343. if (selectStyle.boldChk->isChecked()) preferences.syn->numberStyle|=SYNS_BOLD;
  344. if (selectStyle.underlineChk->isChecked()) preferences.syn->numberStyle|=SYNS_UNDERLINE;
  345. if (selectStyle.italicChk->isChecked()) preferences.syn->numberStyle|=SYNS_ITALIC;
  346. if (selectStyle.strikeoutChk->isChecked()) preferences.syn->numberStyle|=SYNS_STRIKEOUT;
  347. }
  348. }
  349. }
  350. void Preferences::symbolColorButton_clicked()
  351. {
  352. QColor color=preferences.syn->symbolColor;
  353. if (KColorDialog::getColor(color,this)==KColorDialog::Accepted)
  354. preferences.syn->symbolColor=color;
  355. }
  356. void Preferences::symbolStyleButton_clicked()
  357. {
  358. SelectStyle selectStyle(this);
  359. selectStyle.customStyle->setChecked(!!(preferences.syn->symbolStyle&SYNS_CUSTOM));
  360. if (preferences.syn->symbolStyle&SYNS_CUSTOM) {
  361. selectStyle.boldChk->setChecked(!!(preferences.syn->symbolStyle&SYNS_BOLD));
  362. selectStyle.underlineChk->setChecked(!!(preferences.syn->symbolStyle&SYNS_UNDERLINE));
  363. selectStyle.italicChk->setChecked(!!(preferences.syn->symbolStyle&SYNS_ITALIC));
  364. selectStyle.strikeoutChk->setChecked(!!(preferences.syn->symbolStyle&SYNS_STRIKEOUT));
  365. }
  366. selectStyle.exec();
  367. if (selectStyle.result()==QDialog::Accepted) {
  368. preferences.syn->symbolStyle=0;
  369. if (selectStyle.customStyle->isChecked()) {
  370. preferences.syn->symbolStyle|=SYNS_CUSTOM;
  371. if (selectStyle.boldChk->isChecked()) preferences.syn->symbolStyle|=SYNS_BOLD;
  372. if (selectStyle.underlineChk->isChecked()) preferences.syn->symbolStyle|=SYNS_UNDERLINE;
  373. if (selectStyle.italicChk->isChecked()) preferences.syn->symbolStyle|=SYNS_ITALIC;
  374. if (selectStyle.strikeoutChk->isChecked()) preferences.syn->symbolStyle|=SYNS_STRIKEOUT;
  375. }
  376. }
  377. }
  378. void Preferences::parenthesisColorsButton_clicked()
  379. {
  380. SelectColors selectColors(this);
  381. selectColors.colorList->clear();
  382. for (QValueList<QColor>::ConstIterator it=preferences.syn->parenthesisColors.begin();
  383. it!=preferences.syn->parenthesisColors.end(); ++it)
  384. new ColorListItem(selectColors.colorList,*it);
  385. selectColors.exec();
  386. if (selectColors.result()==QDialog::Accepted) {
  387. preferences.syn->parenthesisColors.clear();
  388. for (QListBoxItem *item=selectColors.colorList->firstItem(); item;
  389. item=item->next())
  390. preferences.syn->parenthesisColors.append(
  391. static_cast<ColorListItem *>(item)->color());
  392. }
  393. }
  394. void Preferences::parenthesisStyleButton_clicked()
  395. {
  396. SelectStyle selectStyle(this);
  397. selectStyle.customStyle->setChecked(!!(preferences.syn->parenthesisStyle&SYNS_CUSTOM));
  398. if (preferences.syn->parenthesisStyle&SYNS_CUSTOM) {
  399. selectStyle.boldChk->setChecked(!!(preferences.syn->parenthesisStyle&SYNS_BOLD));
  400. selectStyle.underlineChk->setChecked(!!(preferences.syn->parenthesisStyle&SYNS_UNDERLINE));
  401. selectStyle.italicChk->setChecked(!!(preferences.syn->parenthesisStyle&SYNS_ITALIC));
  402. selectStyle.strikeoutChk->setChecked(!!(preferences.syn->parenthesisStyle&SYNS_STRIKEOUT));
  403. }
  404. selectStyle.exec();
  405. if (selectStyle.result()==QDialog::Accepted) {
  406. preferences.syn->parenthesisStyle=0;
  407. if (selectStyle.customStyle->isChecked()) {
  408. preferences.syn->parenthesisStyle|=SYNS_CUSTOM;
  409. if (selectStyle.boldChk->isChecked()) preferences.syn->parenthesisStyle|=SYNS_BOLD;
  410. if (selectStyle.underlineChk->isChecked()) preferences.syn->parenthesisStyle|=SYNS_UNDERLINE;
  411. if (selectStyle.italicChk->isChecked()) preferences.syn->parenthesisStyle|=SYNS_ITALIC;
  412. if (selectStyle.strikeoutChk->isChecked()) preferences.syn->parenthesisStyle|=SYNS_STRIKEOUT;
  413. }
  414. }
  415. }
  416. void Preferences::syntaxListView_selectionChanged()
  417. {
  418. QListViewItem *selectedItem=syntaxListView->selectedItem();
  419. editButton->setEnabled(syntaxEnabled->isChecked()
  420. && selectedItem && selectedItem->rtti()==0x716CC8);
  421. }
  422. #define unused_col col __attribute__((unused))
  423. void Preferences::syntaxListView_itemRenamed(QListViewItem *item, const QString &str, int unused_col)
  424. {
  425. QListViewItem *rootListItem=syntaxListView->firstChild();
  426. QListViewItem *customStylesItem=rootListItem->firstChild();
  427. QListViewItem *wordListsItem=customStylesItem->nextSibling();
  428. if (item->parent()==customStylesItem) {
  429. QListViewItem *i;
  430. QValueList<Syn_CustomStyle>::Iterator it;
  431. for (it=preferences.syn->customStyles.begin(), i=customStylesItem->firstChild();
  432. i!=item && it!=preferences.syn->customStyles.end() && i;
  433. ++it, i=i->nextSibling());
  434. if (it==preferences.syn->customStyles.end() || !i)
  435. qWarning("Preferences::syntaxListView_itemRenamed: Invalid item.");
  436. else
  437. (*it).name=str;
  438. } else if (item->parent()==wordListsItem) {
  439. QListViewItem *i;
  440. QValueList<Syn_WordList>::Iterator it;
  441. for (it=preferences.syn->wordLists.begin(), i=wordListsItem->firstChild();
  442. i!=item && it!=preferences.syn->wordLists.end() && i;
  443. ++it, i=i->nextSibling());
  444. if (it==preferences.syn->wordLists.end() || !i)
  445. qWarning("Preferences::syntaxListView_itemRenamed: Invalid item.");
  446. else
  447. (*it).name=str;
  448. } else qWarning("Preferences::syntaxListView_itemRenamed: Invalid parent.");
  449. }
  450. void Preferences::syntaxListViewAccel_activated(int id)
  451. {
  452. if (!id) {
  453. QListViewItem *currentItem=syntaxListView->currentItem();
  454. if (currentItem && currentItem->rtti()==0x716CC8) {
  455. QListViewItem *rootListItem=syntaxListView->firstChild();
  456. QListViewItem *customStylesItem=rootListItem->firstChild();
  457. QListViewItem *wordListsItem=customStylesItem->nextSibling();
  458. if (currentItem->parent()==customStylesItem) {
  459. QListViewItem *i;
  460. QValueList<Syn_CustomStyle>::Iterator it;
  461. for (it=preferences.syn->customStyles.begin(), i=customStylesItem->firstChild();
  462. i!=currentItem && it!=preferences.syn->customStyles.end() && i;
  463. ++it, i=i->nextSibling());
  464. if (it==preferences.syn->customStyles.end() || !i)
  465. qWarning("Preferences::syntaxListViewAccel_activated: Invalid item.");
  466. else {
  467. delete currentItem;
  468. preferences.syn->customStyles.remove(it);
  469. }
  470. } else if (currentItem->parent()==wordListsItem) {
  471. QListViewItem *i;
  472. QValueList<Syn_WordList>::Iterator it;
  473. for (it=preferences.syn->wordLists.begin(), i=wordListsItem->firstChild();
  474. i!=currentItem && it!=preferences.syn->wordLists.end() && i;
  475. ++it, i=i->nextSibling());
  476. if (it==preferences.syn->wordLists.end() || !i)
  477. qWarning("Preferences::syntaxListViewAccel_activated: Invalid item.");
  478. else {
  479. delete currentItem;
  480. preferences.syn->wordLists.remove(it);
  481. }
  482. } else qWarning("Preferences::syntaxListViewAccel_activated: Invalid parent.");
  483. }
  484. }
  485. }
  486. void Preferences::newStyleButton_clicked()
  487. {
  488. Syn_CustomStyle newStyle;
  489. newStyle.name="New Style";
  490. preferences.syn->customStyles.append(newStyle);
  491. QListViewItem *rootListItem=syntaxListView->firstChild();
  492. QListViewItem *customStylesItem=rootListItem->firstChild();
  493. QListViewItem *item=customStylesItem->firstChild();
  494. while (item && item->nextSibling()) item=item->nextSibling();
  495. item=new RenamableKListViewItem(customStylesItem,item,newStyle.name);
  496. syntaxListView->setCurrentItem(item);
  497. syntaxListView->setSelected(item,TRUE);
  498. // startRename won't work properly if I don't do this. :-/
  499. QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput,1000);
  500. syntaxListView->ensureItemVisible(item);
  501. QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput,1000);
  502. item->startRename(0);
  503. }
  504. void Preferences::newListButton_clicked()
  505. {
  506. Syn_WordList newList;
  507. newList.name="New List";
  508. preferences.syn->wordLists.append(newList);
  509. QListViewItem *rootListItem=syntaxListView->firstChild();
  510. QListViewItem *customStylesItem=rootListItem->firstChild();
  511. QListViewItem *wordListsItem=customStylesItem->nextSibling();
  512. QListViewItem *item=wordListsItem->firstChild();
  513. while (item && item->nextSibling()) item=item->nextSibling();
  514. item=new RenamableKListViewItem(wordListsItem,item,newList.name);
  515. syntaxListView->setCurrentItem(item);
  516. syntaxListView->setSelected(item,TRUE);
  517. // startRename won't work properly if I don't do this. :-/
  518. QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput,1000);
  519. syntaxListView->ensureItemVisible(item);
  520. QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput,1000);
  521. item->startRename(0);
  522. }
  523. static QDialog *editDialog;
  524. static Syn_Style tempStyle;
  525. static QColor tempColor;
  526. void Preferences::editButton_clicked()
  527. {
  528. QListViewItem *currentItem=syntaxListView->currentItem();
  529. if (currentItem && currentItem->rtti()==0x716CC8) {
  530. QListViewItem *rootListItem=syntaxListView->firstChild();
  531. QListViewItem *customStylesItem=rootListItem->firstChild();
  532. QListViewItem *wordListsItem=customStylesItem->nextSibling();
  533. if (currentItem->parent()==customStylesItem) {
  534. QListViewItem *i;
  535. QValueList<Syn_CustomStyle>::Iterator it;
  536. for (it=preferences.syn->customStyles.begin(), i=customStylesItem->firstChild();
  537. i!=currentItem && it!=preferences.syn->customStyles.end() && i;
  538. ++it, i=i->nextSibling());
  539. if (it==preferences.syn->customStyles.end() || !i)
  540. qWarning("Preferences::editButton_clicked: Invalid item.");
  541. else {
  542. Syn_CustomStyle &customStyle=*it;
  543. CustomStyle customStyleDlg(this);
  544. editDialog=&customStyleDlg;
  545. customStyleDlg.beginning->setText(customStyle.beginning);
  546. customStyleDlg.ending->setText(customStyle.ending=="\n"?"\\n"
  547. :customStyle.ending);
  548. customStyleDlg.ignoreEndingAfter->setText(QString(customStyle.ignoreEndingAfter));
  549. customStyleDlg.switchable->setChecked(customStyle.switchable);
  550. customStyleDlg.lineStartOnly->setChecked(customStyle.lineStartOnly);
  551. tempStyle=customStyle.style;
  552. tempColor=customStyle.color;
  553. connect(customStyleDlg.styleButton,SIGNAL(clicked()),
  554. this,SLOT(editDialog_styleButton_clicked()));
  555. connect(customStyleDlg.colorButton,SIGNAL(clicked()),
  556. this,SLOT(editDialog_colorButton_clicked()));
  557. customStyleDlg.exec();
  558. if (customStyleDlg.result()==QDialog::Accepted) {
  559. customStyle.beginning=customStyleDlg.beginning->text();
  560. customStyle.ending=customStyleDlg.ending->text()=="\\n"?"\n"
  561. :customStyleDlg.ending->text();
  562. customStyle.ignoreEndingAfter=customStyleDlg.ignoreEndingAfter->text()[0];
  563. customStyle.switchable=customStyleDlg.switchable->isChecked();
  564. customStyle.lineStartOnly=customStyleDlg.lineStartOnly->isChecked();
  565. customStyle.style=tempStyle;
  566. customStyle.color=tempColor;
  567. }
  568. }
  569. } else if (currentItem->parent()==wordListsItem) {
  570. QListViewItem *i;
  571. QValueList<Syn_WordList>::Iterator it;
  572. for (it=preferences.syn->wordLists.begin(), i=wordListsItem->firstChild();
  573. i!=currentItem && it!=preferences.syn->wordLists.end() && i;
  574. ++it, i=i->nextSibling());
  575. if (it==preferences.syn->wordLists.end() || !i)
  576. qWarning("Preferences::editButton_clicked: Invalid item.");
  577. else {
  578. Syn_WordList &wordList=*it;
  579. WordList wordListDlg(this);
  580. editDialog=&wordListDlg;
  581. wordListDlg.wordList->setItems(wordList.list);
  582. wordListDlg.caseSensitive->setChecked(wordList.caseSensitive);
  583. tempStyle=wordList.style;
  584. tempColor=wordList.color;
  585. connect(wordListDlg.styleButton,SIGNAL(clicked()),
  586. this,SLOT(editDialog_styleButton_clicked()));
  587. connect(wordListDlg.colorButton,SIGNAL(clicked()),
  588. this,SLOT(editDialog_colorButton_clicked()));
  589. wordListDlg.exec();
  590. if (wordListDlg.result()==QDialog::Accepted) {
  591. wordList.list=wordListDlg.wordList->items();
  592. wordList.caseSensitive=wordListDlg.caseSensitive->isChecked();
  593. wordList.style=tempStyle;
  594. wordList.color=tempColor;
  595. }
  596. }
  597. } else qWarning("Preferences::editButton_clicked: Invalid parent.");
  598. }
  599. }
  600. void Preferences::editDialog_colorButton_clicked()
  601. {
  602. QColor color=tempColor;
  603. if (KColorDialog::getColor(color,QColor(),editDialog)==KColorDialog::Accepted)
  604. tempColor=color;
  605. }
  606. void Preferences::editDialog_styleButton_clicked()
  607. {
  608. SelectStyle selectStyle(editDialog);
  609. selectStyle.customStyle->setChecked(!!(tempStyle&SYNS_CUSTOM));
  610. if (tempStyle&SYNS_CUSTOM) {
  611. selectStyle.boldChk->setChecked(!!(tempStyle&SYNS_BOLD));
  612. selectStyle.underlineChk->setChecked(!!(tempStyle&SYNS_UNDERLINE));
  613. selectStyle.italicChk->setChecked(!!(tempStyle&SYNS_ITALIC));
  614. selectStyle.strikeoutChk->setChecked(!!(tempStyle&SYNS_STRIKEOUT));
  615. }
  616. selectStyle.exec();
  617. if (selectStyle.result()==QDialog::Accepted) {
  618. tempStyle=0;
  619. if (selectStyle.customStyle->isChecked()) {
  620. tempStyle|=SYNS_CUSTOM;
  621. if (selectStyle.boldChk->isChecked()) tempStyle|=SYNS_BOLD;
  622. if (selectStyle.underlineChk->isChecked()) tempStyle|=SYNS_UNDERLINE;
  623. if (selectStyle.italicChk->isChecked()) tempStyle|=SYNS_ITALIC;
  624. if (selectStyle.strikeoutChk->isChecked()) tempStyle|=SYNS_STRIKEOUT;
  625. }
  626. }
  627. }
  628. void Preferences::clearSelectionButton_clicked()
  629. {
  630. QListBoxItem *next;
  631. for (QListBoxItem *item=templateListBox->firstItem(); item;
  632. item=next) {
  633. next=item->next();
  634. if (item->isSelected()) delete item;
  635. }
  636. }
  637. void Preferences::applyButton_clicked()
  638. {
  639. QString identifier=templateIdentifier->text();
  640. QListBoxItem *item=templateListBox->findItem(identifier,Qt::ExactMatch);
  641. if (item) {
  642. static_cast<ListBoxTextPair *>(item)->setData(templateCode->text());
  643. } else {
  644. new ListBoxTextPair(templateListBox,identifier,templateCode->text());
  645. templateListBox->sort();
  646. }
  647. }
  648. void Preferences::templateListBox_selectionChanged()
  649. {
  650. for (QListBoxItem *item=templateListBox->firstItem(); item;
  651. item=item->next()) {
  652. if (item->isSelected()) {
  653. clearSelectionButton->setEnabled(TRUE);
  654. return;
  655. }
  656. }
  657. clearSelectionButton->setEnabled(FALSE);
  658. }
  659. void Preferences::templateListBox_currentChanged(QListBoxItem *item)
  660. {
  661. if (item) {
  662. templateIdentifier->setText(item->text());
  663. templateCode->setText(static_cast<ListBoxTextPair *>(item)->data());
  664. }
  665. }
  666. void Preferences::templateIdentifier_textChanged(const QString &text)
  667. {
  668. applyButton->setEnabled(!text.isEmpty());
  669. }