preferencesdlg.cpp 29 KB

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