preferencesdlg.cpp 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  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,TRUE,this)==KFontDialog::Accepted) {
  270. editorFont->setFont(font);
  271. editorFont->setText(font.family());
  272. }
  273. }
  274. void Preferences::syntaxLanguage_activated(int index)
  275. {
  276. if (!index) preferences.syn=&preferences.tempSynC;
  277. else if (!--index) preferences.syn=&preferences.tempSynS;
  278. else if (preferences.haveA68k && !--index)
  279. preferences.syn=&preferences.tempSynAsm;
  280. else if (preferences.haveQuill && !--index)
  281. preferences.syn=&preferences.tempSynQll;
  282. else {
  283. qWarning("Preferences::syntaxLanguage_activated: Invalid index.");
  284. preferences.syn=&preferences.tempSynC;
  285. }
  286. syntaxEnabled->setChecked(preferences.syn->enabled);
  287. Q3ListViewItem *rootListItem=syntaxListView->firstChild();
  288. Q3ListViewItem *item, *nextItem;
  289. Q3ListViewItem *customStylesItem=rootListItem->firstChild();
  290. for (item=customStylesItem->firstChild(); item; item=nextItem) {
  291. nextItem=item->nextSibling();
  292. delete item;
  293. }
  294. item=static_cast<Q3ListViewItem *>(NULL);
  295. for (QLinkedList<Syn_CustomStyle>::ConstIterator it=
  296. preferences.syn->customStyles.begin();
  297. it!=preferences.syn->customStyles.end(); ++it) {
  298. item=new RenamableKListViewItem(customStylesItem,item,(*it).name);
  299. }
  300. Q3ListViewItem *wordListsItem=customStylesItem->nextSibling();
  301. for (item=wordListsItem->firstChild(); item; item=nextItem) {
  302. nextItem=item->nextSibling();
  303. delete item;
  304. }
  305. item=static_cast<Q3ListViewItem *>(NULL);
  306. foreach (const Syn_WordList &wlist, preferences.syn->wordLists)
  307. item=new RenamableKListViewItem(wordListsItem,item,wlist.name);
  308. }
  309. void Preferences::syntaxEnabled_toggled(bool on)
  310. {
  311. preferences.syn->enabled=on;
  312. resetButton->setEnabled(on);
  313. numberColorButton->setEnabled(on);
  314. numberStyleButton->setEnabled(on);
  315. symbolColorButton->setEnabled(on);
  316. symbolStyleButton->setEnabled(on);
  317. parenthesisColorsButton->setEnabled(on);
  318. parenthesisStyleButton->setEnabled(on);
  319. syntaxListView->setEnabled(on);
  320. newStyleButton->setEnabled(on);
  321. newListButton->setEnabled(on);
  322. Q3ListViewItem *selectedItem=syntaxListView->selectedItem();
  323. editButton->setEnabled(on&&selectedItem&&selectedItem->rtti()==0x716CC8);
  324. }
  325. void Preferences::resetButton_clicked()
  326. {
  327. resetSyntaxPreference(preferences.syn);
  328. syntaxLanguage_activated(syntaxLanguage->currentItem());
  329. }
  330. void Preferences::numberColorButton_clicked()
  331. {
  332. QColor color=preferences.syn->numberColor;
  333. if (KColorDialog::getColor(color,this)==KColorDialog::Accepted)
  334. preferences.syn->numberColor=color;
  335. }
  336. void Preferences::numberStyleButton_clicked()
  337. {
  338. SelectStyle selectStyle(this);
  339. selectStyle.customStyle->setChecked(!!(preferences.syn->numberStyle&SYNS_CUSTOM));
  340. if (preferences.syn->numberStyle&SYNS_CUSTOM) {
  341. selectStyle.boldChk->setChecked(!!(preferences.syn->numberStyle&SYNS_BOLD));
  342. selectStyle.underlineChk->setChecked(!!(preferences.syn->numberStyle&SYNS_UNDERLINE));
  343. selectStyle.italicChk->setChecked(!!(preferences.syn->numberStyle&SYNS_ITALIC));
  344. selectStyle.strikeoutChk->setChecked(!!(preferences.syn->numberStyle&SYNS_STRIKEOUT));
  345. }
  346. selectStyle.exec();
  347. if (selectStyle.result()==QDialog::Accepted) {
  348. preferences.syn->numberStyle=0;
  349. if (selectStyle.customStyle->isChecked()) {
  350. preferences.syn->numberStyle|=SYNS_CUSTOM;
  351. if (selectStyle.boldChk->isChecked()) preferences.syn->numberStyle|=SYNS_BOLD;
  352. if (selectStyle.underlineChk->isChecked()) preferences.syn->numberStyle|=SYNS_UNDERLINE;
  353. if (selectStyle.italicChk->isChecked()) preferences.syn->numberStyle|=SYNS_ITALIC;
  354. if (selectStyle.strikeoutChk->isChecked()) preferences.syn->numberStyle|=SYNS_STRIKEOUT;
  355. }
  356. }
  357. }
  358. void Preferences::symbolColorButton_clicked()
  359. {
  360. QColor color=preferences.syn->symbolColor;
  361. if (KColorDialog::getColor(color,this)==KColorDialog::Accepted)
  362. preferences.syn->symbolColor=color;
  363. }
  364. void Preferences::symbolStyleButton_clicked()
  365. {
  366. SelectStyle selectStyle(this);
  367. selectStyle.customStyle->setChecked(!!(preferences.syn->symbolStyle&SYNS_CUSTOM));
  368. if (preferences.syn->symbolStyle&SYNS_CUSTOM) {
  369. selectStyle.boldChk->setChecked(!!(preferences.syn->symbolStyle&SYNS_BOLD));
  370. selectStyle.underlineChk->setChecked(!!(preferences.syn->symbolStyle&SYNS_UNDERLINE));
  371. selectStyle.italicChk->setChecked(!!(preferences.syn->symbolStyle&SYNS_ITALIC));
  372. selectStyle.strikeoutChk->setChecked(!!(preferences.syn->symbolStyle&SYNS_STRIKEOUT));
  373. }
  374. selectStyle.exec();
  375. if (selectStyle.result()==QDialog::Accepted) {
  376. preferences.syn->symbolStyle=0;
  377. if (selectStyle.customStyle->isChecked()) {
  378. preferences.syn->symbolStyle|=SYNS_CUSTOM;
  379. if (selectStyle.boldChk->isChecked()) preferences.syn->symbolStyle|=SYNS_BOLD;
  380. if (selectStyle.underlineChk->isChecked()) preferences.syn->symbolStyle|=SYNS_UNDERLINE;
  381. if (selectStyle.italicChk->isChecked()) preferences.syn->symbolStyle|=SYNS_ITALIC;
  382. if (selectStyle.strikeoutChk->isChecked()) preferences.syn->symbolStyle|=SYNS_STRIKEOUT;
  383. }
  384. }
  385. }
  386. void Preferences::parenthesisColorsButton_clicked()
  387. {
  388. SelectColors selectColors(this);
  389. selectColors.colorList->clear();
  390. foreach (const QColor &color, preferences.syn->parenthesisColors)
  391. new ColorListItem(selectColors.colorList,color);
  392. selectColors.exec();
  393. if (selectColors.result()==QDialog::Accepted) {
  394. preferences.syn->parenthesisColors.clear();
  395. for (Q3ListBoxItem *item=selectColors.colorList->firstItem(); item;
  396. item=item->next())
  397. preferences.syn->parenthesisColors.append(
  398. static_cast<ColorListItem *>(item)->color());
  399. }
  400. }
  401. void Preferences::parenthesisStyleButton_clicked()
  402. {
  403. SelectStyle selectStyle(this);
  404. selectStyle.customStyle->setChecked(!!(preferences.syn->parenthesisStyle&SYNS_CUSTOM));
  405. if (preferences.syn->parenthesisStyle&SYNS_CUSTOM) {
  406. selectStyle.boldChk->setChecked(!!(preferences.syn->parenthesisStyle&SYNS_BOLD));
  407. selectStyle.underlineChk->setChecked(!!(preferences.syn->parenthesisStyle&SYNS_UNDERLINE));
  408. selectStyle.italicChk->setChecked(!!(preferences.syn->parenthesisStyle&SYNS_ITALIC));
  409. selectStyle.strikeoutChk->setChecked(!!(preferences.syn->parenthesisStyle&SYNS_STRIKEOUT));
  410. }
  411. selectStyle.exec();
  412. if (selectStyle.result()==QDialog::Accepted) {
  413. preferences.syn->parenthesisStyle=0;
  414. if (selectStyle.customStyle->isChecked()) {
  415. preferences.syn->parenthesisStyle|=SYNS_CUSTOM;
  416. if (selectStyle.boldChk->isChecked()) preferences.syn->parenthesisStyle|=SYNS_BOLD;
  417. if (selectStyle.underlineChk->isChecked()) preferences.syn->parenthesisStyle|=SYNS_UNDERLINE;
  418. if (selectStyle.italicChk->isChecked()) preferences.syn->parenthesisStyle|=SYNS_ITALIC;
  419. if (selectStyle.strikeoutChk->isChecked()) preferences.syn->parenthesisStyle|=SYNS_STRIKEOUT;
  420. }
  421. }
  422. }
  423. void Preferences::syntaxListView_selectionChanged()
  424. {
  425. Q3ListViewItem *selectedItem=syntaxListView->selectedItem();
  426. editButton->setEnabled(syntaxEnabled->isChecked()
  427. && selectedItem && selectedItem->rtti()==0x716CC8);
  428. }
  429. #define unused_col col __attribute__((unused))
  430. void Preferences::syntaxListView_itemRenamed(Q3ListViewItem *item, const QString &str, int unused_col)
  431. {
  432. Q3ListViewItem *rootListItem=syntaxListView->firstChild();
  433. Q3ListViewItem *customStylesItem=rootListItem->firstChild();
  434. Q3ListViewItem *wordListsItem=customStylesItem->nextSibling();
  435. if (item->parent()==customStylesItem) {
  436. Q3ListViewItem *i;
  437. QLinkedList<Syn_CustomStyle>::Iterator it;
  438. for (it=preferences.syn->customStyles.begin(), i=customStylesItem->firstChild();
  439. i!=item && it!=preferences.syn->customStyles.end() && i;
  440. ++it, i=i->nextSibling());
  441. if (it==preferences.syn->customStyles.end() || !i)
  442. qWarning("Preferences::syntaxListView_itemRenamed: Invalid item.");
  443. else
  444. (*it).name=str;
  445. } else if (item->parent()==wordListsItem) {
  446. Q3ListViewItem *i;
  447. QLinkedList<Syn_WordList>::Iterator it;
  448. for (it=preferences.syn->wordLists.begin(), i=wordListsItem->firstChild();
  449. i!=item && it!=preferences.syn->wordLists.end() && i;
  450. ++it, i=i->nextSibling());
  451. if (it==preferences.syn->wordLists.end() || !i)
  452. qWarning("Preferences::syntaxListView_itemRenamed: Invalid item.");
  453. else
  454. (*it).name=str;
  455. } else qWarning("Preferences::syntaxListView_itemRenamed: Invalid parent.");
  456. }
  457. void Preferences::syntaxListViewAccel_activated(int id)
  458. {
  459. if (!id) {
  460. Q3ListViewItem *currentItem=syntaxListView->currentItem();
  461. if (currentItem && currentItem->rtti()==0x716CC8) {
  462. Q3ListViewItem *rootListItem=syntaxListView->firstChild();
  463. Q3ListViewItem *customStylesItem=rootListItem->firstChild();
  464. Q3ListViewItem *wordListsItem=customStylesItem->nextSibling();
  465. if (currentItem->parent()==customStylesItem) {
  466. Q3ListViewItem *i;
  467. QLinkedList<Syn_CustomStyle>::Iterator it;
  468. for (it=preferences.syn->customStyles.begin(), i=customStylesItem->firstChild();
  469. i!=currentItem && it!=preferences.syn->customStyles.end() && i;
  470. ++it, i=i->nextSibling());
  471. if (it==preferences.syn->customStyles.end() || !i)
  472. qWarning("Preferences::syntaxListViewAccel_activated: Invalid item.");
  473. else {
  474. delete currentItem;
  475. preferences.syn->customStyles.remove(it);
  476. }
  477. } else if (currentItem->parent()==wordListsItem) {
  478. Q3ListViewItem *i;
  479. QLinkedList<Syn_WordList>::Iterator it;
  480. for (it=preferences.syn->wordLists.begin(), i=wordListsItem->firstChild();
  481. i!=currentItem && it!=preferences.syn->wordLists.end() && i;
  482. ++it, i=i->nextSibling());
  483. if (it==preferences.syn->wordLists.end() || !i)
  484. qWarning("Preferences::syntaxListViewAccel_activated: Invalid item.");
  485. else {
  486. delete currentItem;
  487. preferences.syn->wordLists.remove(it);
  488. }
  489. } else qWarning("Preferences::syntaxListViewAccel_activated: Invalid parent.");
  490. }
  491. }
  492. }
  493. void Preferences::newStyleButton_clicked()
  494. {
  495. Syn_CustomStyle newStyle;
  496. newStyle.name="New Style";
  497. preferences.syn->customStyles.append(newStyle);
  498. Q3ListViewItem *rootListItem=syntaxListView->firstChild();
  499. Q3ListViewItem *customStylesItem=rootListItem->firstChild();
  500. Q3ListViewItem *item=customStylesItem->firstChild();
  501. while (item && item->nextSibling()) item=item->nextSibling();
  502. item=new RenamableKListViewItem(customStylesItem,item,newStyle.name);
  503. syntaxListView->setCurrentItem(item);
  504. syntaxListView->setSelected(item,TRUE);
  505. item->startRename(0);
  506. }
  507. void Preferences::newListButton_clicked()
  508. {
  509. Syn_WordList newList;
  510. newList.name="New List";
  511. preferences.syn->wordLists.append(newList);
  512. Q3ListViewItem *rootListItem=syntaxListView->firstChild();
  513. Q3ListViewItem *customStylesItem=rootListItem->firstChild();
  514. Q3ListViewItem *wordListsItem=customStylesItem->nextSibling();
  515. Q3ListViewItem *item=wordListsItem->firstChild();
  516. while (item && item->nextSibling()) item=item->nextSibling();
  517. item=new RenamableKListViewItem(wordListsItem,item,newList.name);
  518. syntaxListView->setCurrentItem(item);
  519. syntaxListView->setSelected(item,TRUE);
  520. item->startRename(0);
  521. }
  522. static QDialog *editDialog;
  523. static Syn_Style tempStyle;
  524. static QColor tempColor;
  525. void Preferences::editButton_clicked()
  526. {
  527. Q3ListViewItem *currentItem=syntaxListView->currentItem();
  528. if (currentItem && currentItem->rtti()==0x716CC8) {
  529. Q3ListViewItem *rootListItem=syntaxListView->firstChild();
  530. Q3ListViewItem *customStylesItem=rootListItem->firstChild();
  531. Q3ListViewItem *wordListsItem=customStylesItem->nextSibling();
  532. if (currentItem->parent()==customStylesItem) {
  533. Q3ListViewItem *i;
  534. QLinkedList<Syn_CustomStyle>::Iterator it;
  535. for (it=preferences.syn->customStyles.begin(), i=customStylesItem->firstChild();
  536. i!=currentItem && it!=preferences.syn->customStyles.end() && i;
  537. ++it, i=i->nextSibling());
  538. if (it==preferences.syn->customStyles.end() || !i)
  539. qWarning("Preferences::editButton_clicked: Invalid item.");
  540. else {
  541. Syn_CustomStyle &customStyle=*it;
  542. CustomStyle customStyleDlg(this);
  543. editDialog=&customStyleDlg;
  544. customStyleDlg.beginning->setText(customStyle.beginning);
  545. customStyleDlg.ending->setText(customStyle.ending=="\n"?"\\n"
  546. :customStyle.ending);
  547. customStyleDlg.ignoreEndingAfter->setText(QString(customStyle.ignoreEndingAfter));
  548. customStyleDlg.switchable->setChecked(customStyle.switchable);
  549. customStyleDlg.lineStartOnly->setChecked(customStyle.lineStartOnly);
  550. tempStyle=customStyle.style;
  551. tempColor=customStyle.color;
  552. connect(customStyleDlg.styleButton,SIGNAL(clicked()),
  553. this,SLOT(editDialog_styleButton_clicked()));
  554. connect(customStyleDlg.colorButton,SIGNAL(clicked()),
  555. this,SLOT(editDialog_colorButton_clicked()));
  556. customStyleDlg.exec();
  557. if (customStyleDlg.result()==QDialog::Accepted) {
  558. customStyle.beginning=customStyleDlg.beginning->text();
  559. customStyle.ending=customStyleDlg.ending->text()=="\\n"?"\n"
  560. :customStyleDlg.ending->text();
  561. QString ignoreEndingAfter=customStyleDlg.ignoreEndingAfter->text();
  562. customStyle.ignoreEndingAfter=ignoreEndingAfter.isEmpty()?QChar():ignoreEndingAfter[0];
  563. customStyle.switchable=customStyleDlg.switchable->isChecked();
  564. customStyle.lineStartOnly=customStyleDlg.lineStartOnly->isChecked();
  565. customStyle.style=tempStyle;
  566. customStyle.color=tempColor;
  567. }
  568. }
  569. } else if (currentItem->parent()==wordListsItem) {
  570. Q3ListViewItem *i;
  571. QLinkedList<Syn_WordList>::Iterator it;
  572. for (it=preferences.syn->wordLists.begin(), i=wordListsItem->firstChild();
  573. i!=currentItem && it!=preferences.syn->wordLists.end() && i;
  574. ++it, i=i->nextSibling());
  575. if (it==preferences.syn->wordLists.end() || !i)
  576. qWarning("Preferences::editButton_clicked: Invalid item.");
  577. else {
  578. Syn_WordList &wordList=*it;
  579. WordList wordListDlg(this);
  580. editDialog=&wordListDlg;
  581. wordListDlg.wordList->setItems(wordList.list);
  582. wordListDlg.caseSensitive->setChecked(wordList.caseSensitive);
  583. tempStyle=wordList.style;
  584. tempColor=wordList.color;
  585. connect(wordListDlg.styleButton,SIGNAL(clicked()),
  586. this,SLOT(editDialog_styleButton_clicked()));
  587. connect(wordListDlg.colorButton,SIGNAL(clicked()),
  588. this,SLOT(editDialog_colorButton_clicked()));
  589. wordListDlg.exec();
  590. if (wordListDlg.result()==QDialog::Accepted) {
  591. wordList.list=wordListDlg.wordList->items();
  592. wordList.caseSensitive=wordListDlg.caseSensitive->isChecked();
  593. wordList.style=tempStyle;
  594. wordList.color=tempColor;
  595. }
  596. }
  597. } else qWarning("Preferences::editButton_clicked: Invalid parent.");
  598. }
  599. }
  600. void Preferences::editDialog_colorButton_clicked()
  601. {
  602. QColor color=tempColor;
  603. if (KColorDialog::getColor(color,QColor(),editDialog)==KColorDialog::Accepted)
  604. tempColor=color;
  605. }
  606. void Preferences::editDialog_styleButton_clicked()
  607. {
  608. SelectStyle selectStyle(editDialog);
  609. selectStyle.customStyle->setChecked(!!(tempStyle&SYNS_CUSTOM));
  610. if (tempStyle&SYNS_CUSTOM) {
  611. selectStyle.boldChk->setChecked(!!(tempStyle&SYNS_BOLD));
  612. selectStyle.underlineChk->setChecked(!!(tempStyle&SYNS_UNDERLINE));
  613. selectStyle.italicChk->setChecked(!!(tempStyle&SYNS_ITALIC));
  614. selectStyle.strikeoutChk->setChecked(!!(tempStyle&SYNS_STRIKEOUT));
  615. }
  616. selectStyle.exec();
  617. if (selectStyle.result()==QDialog::Accepted) {
  618. tempStyle=0;
  619. if (selectStyle.customStyle->isChecked()) {
  620. tempStyle|=SYNS_CUSTOM;
  621. if (selectStyle.boldChk->isChecked()) tempStyle|=SYNS_BOLD;
  622. if (selectStyle.underlineChk->isChecked()) tempStyle|=SYNS_UNDERLINE;
  623. if (selectStyle.italicChk->isChecked()) tempStyle|=SYNS_ITALIC;
  624. if (selectStyle.strikeoutChk->isChecked()) tempStyle|=SYNS_STRIKEOUT;
  625. }
  626. }
  627. }
  628. void Preferences::clearSelectionButton_clicked()
  629. {
  630. Q3ListBoxItem *next;
  631. for (Q3ListBoxItem *item=templateListBox->firstItem(); item;
  632. item=next) {
  633. next=item->next();
  634. if (item->isSelected()) delete item;
  635. }
  636. }
  637. void Preferences::applyButton_clicked()
  638. {
  639. QString identifier=templateIdentifier->text();
  640. Q3ListBoxItem *item=templateListBox->findItem(identifier,Q3ListBox::ExactMatch);
  641. if (item) {
  642. static_cast<ListBoxTextPair *>(item)->setData(templateCode->text());
  643. } else {
  644. new ListBoxTextPair(templateListBox,identifier,templateCode->text());
  645. templateListBox->sort();
  646. }
  647. }
  648. void Preferences::templateListBox_selectionChanged()
  649. {
  650. for (Q3ListBoxItem *item=templateListBox->firstItem(); item;
  651. item=item->next()) {
  652. if (item->isSelected()) {
  653. clearSelectionButton->setEnabled(TRUE);
  654. return;
  655. }
  656. }
  657. clearSelectionButton->setEnabled(FALSE);
  658. }
  659. void Preferences::templateListBox_currentChanged(Q3ListBoxItem *item)
  660. {
  661. if (item) {
  662. templateIdentifier->setText(item->text());
  663. templateCode->setText(static_cast<ListBoxTextPair *>(item)->data());
  664. }
  665. }
  666. void Preferences::templateIdentifier_textChanged(const QString &text)
  667. {
  668. applyButton->setEnabled(!text.isEmpty());
  669. }
  670. void Preferences::regenCompletionInfoButton_clicked()
  671. {
  672. QMap<QString,CompletionInfo> sysHdrCompletion;
  673. QString dirName=KFileDialog::getExistingDirectory(
  674. KUrl("kfiledialog:SystemInclude"),this,
  675. "Pick Help Sources System/Include Folder");
  676. if (dirName.isEmpty()) return;
  677. setCursor(KCursor::waitCursor());
  678. if (!parseHelpSources(this,dirName,sysHdrCompletion)) {
  679. setCursor(QCursor());
  680. return;
  681. }
  682. setCursor(QCursor());
  683. // There is always at least one recent directory: the home directory.
  684. if (KRecentDirs::list(":IncludeC").count()==1)
  685. KRecentDirs::add(":IncludeC",QString("%1/include/c/").arg(tigcc_base));
  686. dirName=KFileDialog::getExistingDirectory(KUrl("kfiledialog:IncludeC"),this,
  687. "Pick C Header (include/c) Folder");
  688. if (dirName.isEmpty()) return;
  689. setCursor(KCursor::waitCursor());
  690. if (!parseSystemHeaders(this,dirName,sysHdrCompletion)) {
  691. setCursor(QCursor());
  692. return;
  693. }
  694. systemHeaderCompletion=sysHdrCompletion;
  695. saveSystemHeaderCompletion();
  696. setCursor(QCursor());
  697. }
  698. /*
  699. * Constructs a Preferences as a child of 'parent', with the
  700. * name 'name' and widget flags set to 'f'.
  701. *
  702. * The dialog will by default be modeless, unless you set 'modal' to
  703. * true to construct a modal dialog.
  704. */
  705. Preferences::Preferences(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl)
  706. : QDialog(parent, name, modal, fl)
  707. {
  708. setupUi(this);
  709. init();
  710. }
  711. /*
  712. * Destroys the object and frees any allocated resources
  713. */
  714. Preferences::~Preferences()
  715. {
  716. destroy();
  717. // no need to delete child widgets, Qt does it all for us
  718. }
  719. /*
  720. * Sets the strings of the subwidgets using the current
  721. * language.
  722. */
  723. void Preferences::languageChange()
  724. {
  725. retranslateUi(this);
  726. }