preferencesdlg.ui.h 28 KB

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