preferencesdlg.cpp 29 KB

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