preferencesdlg.ui.h 28 KB

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