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 <QButtonGroup>
  25. #include <QShortcut>
  26. #include <QColor>
  27. #include <QLinkedList>
  28. #include <QApplication>
  29. #include <QEventLoop>
  30. #include <QCursor>
  31. #include <QStringList>
  32. #include <knuminput.h>
  33. #include <kfontdialog.h>
  34. #include <kcolordialog.h>
  35. #include <kcombobox.h>
  36. #include <k3listview.h>
  37. #include <klineedit.h>
  38. #include <keditlistbox.h>
  39. #include <k3listbox.h>
  40. #include <kfiledialog.h>
  41. #include <kcursor.h>
  42. #include <kurl.h>
  43. #include "ktigcc.h"
  44. #include "selectstyle.h"
  45. #include "selectcolors.h"
  46. #include "colorlistitem.h"
  47. #include "customstyle.h"
  48. #include "wordlist.h"
  49. #include "completion.h"
  50. // No idea why krecentdirs.h is not installed (KRecentDirs is an exported
  51. // class), but KRecentDirs only has these 3 static methods anyway.
  52. class KRecentDirs {
  53. public:
  54. static QStringList list(const QString &fileClass);
  55. static QString dir(const QString &fileClass);
  56. static void add(const QString &fileClass, const QString &directory);
  57. };
  58. class RenamableKListViewItem : public K3ListViewItem {
  59. public:
  60. RenamableKListViewItem(Q3ListViewItem *parent, QString text)
  61. : K3ListViewItem(parent, text)
  62. {
  63. setRenameEnabled(0,TRUE);
  64. }
  65. RenamableKListViewItem(Q3ListViewItem *parent, Q3ListViewItem *after,
  66. QString text)
  67. : K3ListViewItem(parent, after, text)
  68. {
  69. setRenameEnabled(0,TRUE);
  70. }
  71. virtual int rtti(void) const {return 0x716CC8;}
  72. // Work around gratuitous API difference. Why do I have to do this? That's
  73. // what startRename is a virtual method for. K3ListViewItem should do this.
  74. virtual void startRename(int col)
  75. {
  76. // K3ListView::rename won't work properly if I don't do this. :-/
  77. QCoreApplication::processEvents(QEventLoop::ExcludeUserInput,1000);
  78. listView()->ensureItemVisible(this);
  79. QCoreApplication::processEvents(QEventLoop::ExcludeUserInput,1000);
  80. static_cast<K3ListView *>(listView())->rename(this,col);
  81. }
  82. };
  83. class ListBoxTextPair : public Q3ListBoxText {
  84. public:
  85. ListBoxTextPair(Q3ListBox *listbox, const QString &text,
  86. const QString &data)
  87. : Q3ListBoxText(listbox,text), m_data(data) {}
  88. virtual ~ListBoxTextPair() {}
  89. void setData(const QString &data) {m_data=data;}
  90. QString data() {return m_data;}
  91. private:
  92. QString m_data;
  93. };
  94. void Preferences::init()
  95. {
  96. // General
  97. stopAtFirstError->setChecked(preferences.stopAtFirstError);
  98. jumpToError->setChecked(preferences.jumpToError);
  99. successMessage->setChecked(preferences.successMessage);
  100. deleteAsmFiles->setChecked(preferences.deleteAsmFiles);
  101. deleteObjFiles->setChecked(preferences.deleteObjFiles);
  102. splitSourceFiles->setChecked(preferences.splitSourceFiles);
  103. allowImplicitDeclaration->setChecked(preferences.allowImplicitDeclaration);
  104. autoSave->setChecked(preferences.autoSave);
  105. downloadHeadlines->setChecked(preferences.downloadHeadlines);
  106. deleteOverwrittenErrors->setChecked(preferences.deleteOverwrittenErrors);
  107. useSystemIcons->setChecked(preferences.useSystemIcons);
  108. // Transfer
  109. QButtonGroup *group=new QButtonGroup(this);
  110. group->addButton(targetNone);
  111. group->addButton(targetTiEmu);
  112. group->addButton(targetRealCalc);
  113. switch (preferences.linkTarget) {
  114. default: // LT_NONE
  115. targetNone->setChecked(TRUE);
  116. break;
  117. case LT_TIEMU:
  118. targetTiEmu->setChecked(TRUE);
  119. break;
  120. case LT_REALCALC:
  121. targetRealCalc->setChecked(TRUE);
  122. break;
  123. }
  124. switch (preferences.linkPort) {
  125. default: // PORT_1
  126. port1->setChecked(TRUE);
  127. break;
  128. case PORT_2:
  129. port2->setChecked(TRUE);
  130. break;
  131. case PORT_3:
  132. port3->setChecked(TRUE);
  133. break;
  134. case PORT_4:
  135. port4->setChecked(TRUE);
  136. break;
  137. }
  138. switch (preferences.linkCable) {
  139. default: // CABLE_GRY
  140. grayLink->setChecked(TRUE);
  141. break;
  142. case CABLE_BLK:
  143. blackLink->setChecked(TRUE);
  144. break;
  145. case CABLE_PAR:
  146. parallelLink->setChecked(TRUE);
  147. break;
  148. case CABLE_SLV:
  149. silverLink->setChecked(TRUE);
  150. break;
  151. case CABLE_USB:
  152. directLink->setChecked(TRUE);
  153. break;
  154. }
  155. // Don't allow selecting a USB cable if libticables2 hasn't been compiled
  156. // without USB support or if USB support can't be used.
  157. if (!have_usb) {
  158. if (silverLink->isChecked() || directLink->isChecked()) {
  159. grayLink->setChecked(TRUE);
  160. targetNone->setChecked(TRUE);
  161. }
  162. silverLink->setEnabled(FALSE);
  163. directLink->setEnabled(FALSE);
  164. }
  165. // Editor
  166. tabWidthC->setValue(preferences.tabWidthC);
  167. tabWidthAsm->setValue(preferences.tabWidthAsm);
  168. useBgColor->setChecked(preferences.useBgColor);
  169. bgColor->setBackgroundColor(preferences.bgColor);
  170. editorFont->setFont(preferences.editorFont);
  171. editorFont->setText(preferences.editorFont.family());
  172. useCalcCharset->setChecked(preferences.useCalcCharset);
  173. autoBlocks->setChecked(preferences.autoBlocks);
  174. removeTrailingSpaces->setChecked(preferences.removeTrailingSpaces);
  175. // Syntax
  176. if (preferences.haveA68k)
  177. syntaxLanguage->insertItem("A68k Assembly Files");
  178. if (preferences.haveQuill)
  179. syntaxLanguage->insertItem("Quill Files");
  180. preferences.tempSynC=preferences.synC;
  181. preferences.tempSynS=preferences.synS;
  182. preferences.tempSynAsm=preferences.synAsm;
  183. preferences.tempSynQll=preferences.synQll;
  184. Q3ListViewItem *rootListItem=new Q3ListViewItem(syntaxListView,"Highlighting");
  185. Q3ListViewItem *customStylesItem=new Q3ListViewItem(rootListItem,"Custom Styles");
  186. Q3ListViewItem *wordListsItem=new Q3ListViewItem(rootListItem,"Word Lists");
  187. syntaxLanguage_activated(syntaxLanguage->currentItem());
  188. syntaxListView->setSorting(-1);
  189. syntaxListView->setColumnWidthMode(0,Q3ListView::Maximum);
  190. syntaxListView->header()->hide();
  191. syntaxListView->setAlternateBackground(QColor());
  192. customStylesItem->setOpen(TRUE);
  193. wordListsItem->setOpen(TRUE);
  194. rootListItem->setOpen(TRUE);
  195. QShortcut *syntaxListViewShortcut=new QShortcut(Qt::Key_Delete,syntaxListView);
  196. connect(syntaxListViewShortcut,SIGNAL(activated()),
  197. this,SLOT(syntaxListViewShortcut_activated()));
  198. // Coding
  199. templateListBox->clear();
  200. typedef const QPair<QString,QString> &StringPairConstRef;
  201. foreach (StringPairConstRef pair, preferences.templates)
  202. new ListBoxTextPair(templateListBox,pair.first,pair.second);
  203. templateListBox->sort();
  204. }
  205. void Preferences::destroy()
  206. {
  207. if (result()==Accepted) {
  208. // General
  209. preferences.stopAtFirstError=stopAtFirstError->isChecked();
  210. preferences.jumpToError=jumpToError->isChecked();
  211. preferences.successMessage=successMessage->isChecked();
  212. preferences.deleteAsmFiles=deleteAsmFiles->isChecked();
  213. preferences.deleteObjFiles=deleteObjFiles->isChecked();
  214. preferences.splitSourceFiles=splitSourceFiles->isChecked();
  215. preferences.allowImplicitDeclaration=allowImplicitDeclaration->isChecked();
  216. preferences.autoSave=autoSave->isChecked();
  217. preferences.downloadHeadlines=downloadHeadlines->isChecked();
  218. preferences.deleteOverwrittenErrors=deleteOverwrittenErrors->isChecked();
  219. preferences.useSystemIcons=useSystemIcons->isChecked();
  220. // Transfer
  221. preferences.linkTarget=targetTiEmu->isChecked()?LT_TIEMU
  222. :targetRealCalc->isChecked()?LT_REALCALC
  223. :LT_NONE;
  224. preferences.linkPort=port2->isChecked()?PORT_2
  225. :port3->isChecked()?PORT_3
  226. :port4->isChecked()?PORT_4
  227. :PORT_1;
  228. preferences.linkCable=blackLink->isChecked()?CABLE_BLK
  229. :parallelLink->isChecked()?CABLE_PAR
  230. :silverLink->isChecked()?CABLE_SLV
  231. :directLink->isChecked()?CABLE_USB
  232. :CABLE_GRY;
  233. // Editor
  234. preferences.tabWidthC=tabWidthC->value();
  235. preferences.tabWidthAsm=tabWidthAsm->value();
  236. preferences.useBgColor=useBgColor->isChecked();
  237. preferences.bgColor=bgColor->backgroundColor();
  238. preferences.editorFont=editorFont->font();
  239. preferences.useCalcCharset=useCalcCharset->isChecked();
  240. preferences.autoBlocks=autoBlocks->isChecked();
  241. preferences.removeTrailingSpaces=removeTrailingSpaces->isChecked();
  242. // Syntax
  243. preferences.synC=preferences.tempSynC;
  244. preferences.synS=preferences.tempSynS;
  245. preferences.synAsm=preferences.tempSynAsm;
  246. preferences.synQll=preferences.tempSynQll;
  247. // Coding
  248. preferences.templates.clear();
  249. for (Q3ListBoxItem *item=templateListBox->firstItem(); item;
  250. item=item->next())
  251. preferences.templates.append(qMakePair(item->text(),
  252. static_cast<ListBoxTextPair *>(item)->data()));
  253. }
  254. }
  255. void Preferences::linkTarget_toggled(bool on __attribute__((unused)))
  256. {
  257. bool isRealCalc=targetRealCalc->isChecked();
  258. linkPort->setEnabled(isRealCalc);
  259. linkCable->setEnabled(isRealCalc);
  260. }
  261. void Preferences::bgColorChange_clicked()
  262. {
  263. QColor color=bgColor->backgroundColor();
  264. if (KColorDialog::getColor(color,this)==KColorDialog::Accepted) {
  265. useBgColor->setChecked(TRUE);
  266. bgColor->setBackgroundColor(color);
  267. }
  268. }
  269. void Preferences::editorFontChange_clicked()
  270. {
  271. QFont font=editorFont->font();
  272. if (KFontDialog::getFont(font,KFontChooser::FixedFontsOnly,this)
  273. ==KFontDialog::Accepted) {
  274. editorFont->setFont(font);
  275. editorFont->setText(font.family());
  276. }
  277. }
  278. void Preferences::syntaxLanguage_activated(int index)
  279. {
  280. if (!index) preferences.syn=&preferences.tempSynC;
  281. else if (!--index) preferences.syn=&preferences.tempSynS;
  282. else if (preferences.haveA68k && !--index)
  283. preferences.syn=&preferences.tempSynAsm;
  284. else if (preferences.haveQuill && !--index)
  285. preferences.syn=&preferences.tempSynQll;
  286. else {
  287. qWarning("Preferences::syntaxLanguage_activated: Invalid index.");
  288. preferences.syn=&preferences.tempSynC;
  289. }
  290. syntaxEnabled->setChecked(preferences.syn->enabled);
  291. Q3ListViewItem *rootListItem=syntaxListView->firstChild();
  292. Q3ListViewItem *item, *nextItem;
  293. Q3ListViewItem *customStylesItem=rootListItem->firstChild();
  294. for (item=customStylesItem->firstChild(); item; item=nextItem) {
  295. nextItem=item->nextSibling();
  296. delete item;
  297. }
  298. item=static_cast<Q3ListViewItem *>(NULL);
  299. for (QLinkedList<Syn_CustomStyle>::ConstIterator it=
  300. preferences.syn->customStyles.begin();
  301. it!=preferences.syn->customStyles.end(); ++it) {
  302. item=new RenamableKListViewItem(customStylesItem,item,(*it).name);
  303. }
  304. Q3ListViewItem *wordListsItem=customStylesItem->nextSibling();
  305. for (item=wordListsItem->firstChild(); item; item=nextItem) {
  306. nextItem=item->nextSibling();
  307. delete item;
  308. }
  309. item=static_cast<Q3ListViewItem *>(NULL);
  310. foreach (const Syn_WordList &wlist, preferences.syn->wordLists)
  311. item=new RenamableKListViewItem(wordListsItem,item,wlist.name);
  312. }
  313. void Preferences::syntaxEnabled_toggled(bool on)
  314. {
  315. preferences.syn->enabled=on;
  316. resetButton->setEnabled(on);
  317. numberColorButton->setEnabled(on);
  318. numberStyleButton->setEnabled(on);
  319. symbolColorButton->setEnabled(on);
  320. symbolStyleButton->setEnabled(on);
  321. parenthesisColorsButton->setEnabled(on);
  322. parenthesisStyleButton->setEnabled(on);
  323. syntaxListView->setEnabled(on);
  324. newStyleButton->setEnabled(on);
  325. newListButton->setEnabled(on);
  326. Q3ListViewItem *selectedItem=syntaxListView->selectedItem();
  327. editButton->setEnabled(on&&selectedItem&&selectedItem->rtti()==0x716CC8);
  328. }
  329. void Preferences::resetButton_clicked()
  330. {
  331. resetSyntaxPreference(preferences.syn);
  332. syntaxLanguage_activated(syntaxLanguage->currentItem());
  333. }
  334. void Preferences::numberColorButton_clicked()
  335. {
  336. QColor color=preferences.syn->numberColor;
  337. if (KColorDialog::getColor(color,this)==KColorDialog::Accepted)
  338. preferences.syn->numberColor=color;
  339. }
  340. void Preferences::numberStyleButton_clicked()
  341. {
  342. SelectStyle selectStyle(this);
  343. selectStyle.customStyle->setChecked(!!(preferences.syn->numberStyle&SYNS_CUSTOM));
  344. if (preferences.syn->numberStyle&SYNS_CUSTOM) {
  345. selectStyle.boldChk->setChecked(!!(preferences.syn->numberStyle&SYNS_BOLD));
  346. selectStyle.underlineChk->setChecked(!!(preferences.syn->numberStyle&SYNS_UNDERLINE));
  347. selectStyle.italicChk->setChecked(!!(preferences.syn->numberStyle&SYNS_ITALIC));
  348. selectStyle.strikeoutChk->setChecked(!!(preferences.syn->numberStyle&SYNS_STRIKEOUT));
  349. }
  350. selectStyle.exec();
  351. if (selectStyle.result()==QDialog::Accepted) {
  352. preferences.syn->numberStyle=0;
  353. if (selectStyle.customStyle->isChecked()) {
  354. preferences.syn->numberStyle|=SYNS_CUSTOM;
  355. if (selectStyle.boldChk->isChecked()) preferences.syn->numberStyle|=SYNS_BOLD;
  356. if (selectStyle.underlineChk->isChecked()) preferences.syn->numberStyle|=SYNS_UNDERLINE;
  357. if (selectStyle.italicChk->isChecked()) preferences.syn->numberStyle|=SYNS_ITALIC;
  358. if (selectStyle.strikeoutChk->isChecked()) preferences.syn->numberStyle|=SYNS_STRIKEOUT;
  359. }
  360. }
  361. }
  362. void Preferences::symbolColorButton_clicked()
  363. {
  364. QColor color=preferences.syn->symbolColor;
  365. if (KColorDialog::getColor(color,this)==KColorDialog::Accepted)
  366. preferences.syn->symbolColor=color;
  367. }
  368. void Preferences::symbolStyleButton_clicked()
  369. {
  370. SelectStyle selectStyle(this);
  371. selectStyle.customStyle->setChecked(!!(preferences.syn->symbolStyle&SYNS_CUSTOM));
  372. if (preferences.syn->symbolStyle&SYNS_CUSTOM) {
  373. selectStyle.boldChk->setChecked(!!(preferences.syn->symbolStyle&SYNS_BOLD));
  374. selectStyle.underlineChk->setChecked(!!(preferences.syn->symbolStyle&SYNS_UNDERLINE));
  375. selectStyle.italicChk->setChecked(!!(preferences.syn->symbolStyle&SYNS_ITALIC));
  376. selectStyle.strikeoutChk->setChecked(!!(preferences.syn->symbolStyle&SYNS_STRIKEOUT));
  377. }
  378. selectStyle.exec();
  379. if (selectStyle.result()==QDialog::Accepted) {
  380. preferences.syn->symbolStyle=0;
  381. if (selectStyle.customStyle->isChecked()) {
  382. preferences.syn->symbolStyle|=SYNS_CUSTOM;
  383. if (selectStyle.boldChk->isChecked()) preferences.syn->symbolStyle|=SYNS_BOLD;
  384. if (selectStyle.underlineChk->isChecked()) preferences.syn->symbolStyle|=SYNS_UNDERLINE;
  385. if (selectStyle.italicChk->isChecked()) preferences.syn->symbolStyle|=SYNS_ITALIC;
  386. if (selectStyle.strikeoutChk->isChecked()) preferences.syn->symbolStyle|=SYNS_STRIKEOUT;
  387. }
  388. }
  389. }
  390. void Preferences::parenthesisColorsButton_clicked()
  391. {
  392. SelectColors selectColors(this);
  393. selectColors.colorList->clear();
  394. foreach (const QColor &color, preferences.syn->parenthesisColors)
  395. new ColorListItem(selectColors.colorList,color);
  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. void Preferences::syntaxListView_itemRenamed(Q3ListViewItem *item, const QString &str, int col __attribute__((unused)))
  434. {
  435. Q3ListViewItem *rootListItem=syntaxListView->firstChild();
  436. Q3ListViewItem *customStylesItem=rootListItem->firstChild();
  437. Q3ListViewItem *wordListsItem=customStylesItem->nextSibling();
  438. if (item->parent()==customStylesItem) {
  439. Q3ListViewItem *i;
  440. QLinkedList<Syn_CustomStyle>::Iterator it;
  441. for (it=preferences.syn->customStyles.begin(), i=customStylesItem->firstChild();
  442. i!=item && it!=preferences.syn->customStyles.end() && i;
  443. ++it, i=i->nextSibling());
  444. if (it==preferences.syn->customStyles.end() || !i)
  445. qWarning("Preferences::syntaxListView_itemRenamed: Invalid item.");
  446. else
  447. (*it).name=str;
  448. } else if (item->parent()==wordListsItem) {
  449. Q3ListViewItem *i;
  450. QLinkedList<Syn_WordList>::Iterator it;
  451. for (it=preferences.syn->wordLists.begin(), i=wordListsItem->firstChild();
  452. i!=item && it!=preferences.syn->wordLists.end() && i;
  453. ++it, i=i->nextSibling());
  454. if (it==preferences.syn->wordLists.end() || !i)
  455. qWarning("Preferences::syntaxListView_itemRenamed: Invalid item.");
  456. else
  457. (*it).name=str;
  458. } else qWarning("Preferences::syntaxListView_itemRenamed: Invalid parent.");
  459. }
  460. void Preferences::syntaxListViewShortcut_activated()
  461. {
  462. Q3ListViewItem *currentItem=syntaxListView->currentItem();
  463. if (currentItem && currentItem->rtti()==0x716CC8) {
  464. Q3ListViewItem *rootListItem=syntaxListView->firstChild();
  465. Q3ListViewItem *customStylesItem=rootListItem->firstChild();
  466. Q3ListViewItem *wordListsItem=customStylesItem->nextSibling();
  467. if (currentItem->parent()==customStylesItem) {
  468. Q3ListViewItem *i;
  469. QLinkedList<Syn_CustomStyle>::Iterator it;
  470. for (it=preferences.syn->customStyles.begin(), i=customStylesItem->firstChild();
  471. i!=currentItem && it!=preferences.syn->customStyles.end() && i;
  472. ++it, i=i->nextSibling());
  473. if (it==preferences.syn->customStyles.end() || !i)
  474. qWarning("Preferences::syntaxListViewShortcut_activated: Invalid item.");
  475. else {
  476. delete currentItem;
  477. preferences.syn->customStyles.remove(it);
  478. }
  479. } else if (currentItem->parent()==wordListsItem) {
  480. Q3ListViewItem *i;
  481. QLinkedList<Syn_WordList>::Iterator it;
  482. for (it=preferences.syn->wordLists.begin(), i=wordListsItem->firstChild();
  483. i!=currentItem && it!=preferences.syn->wordLists.end() && i;
  484. ++it, i=i->nextSibling());
  485. if (it==preferences.syn->wordLists.end() || !i)
  486. qWarning("Preferences::syntaxListViewShortcut_activated: Invalid item.");
  487. else {
  488. delete currentItem;
  489. preferences.syn->wordLists.remove(it);
  490. }
  491. } else qWarning("Preferences::syntaxListViewShortcut_activated: Invalid parent.");
  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. }