preferencesdlg.cpp 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  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. Preferences::Preferences(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl)
  95. : QDialog(parent, name, modal, fl)
  96. {
  97. setupUi(this);
  98. // General
  99. stopAtFirstError->setChecked(preferences.stopAtFirstError);
  100. jumpToError->setChecked(preferences.jumpToError);
  101. successMessage->setChecked(preferences.successMessage);
  102. deleteAsmFiles->setChecked(preferences.deleteAsmFiles);
  103. deleteObjFiles->setChecked(preferences.deleteObjFiles);
  104. splitSourceFiles->setChecked(preferences.splitSourceFiles);
  105. allowImplicitDeclaration->setChecked(preferences.allowImplicitDeclaration);
  106. autoSave->setChecked(preferences.autoSave);
  107. downloadHeadlines->setChecked(preferences.downloadHeadlines);
  108. deleteOverwrittenErrors->setChecked(preferences.deleteOverwrittenErrors);
  109. useSystemIcons->setChecked(preferences.useSystemIcons);
  110. // Transfer
  111. QButtonGroup *group=new QButtonGroup(this);
  112. group->addButton(targetNone);
  113. group->addButton(targetTiEmu);
  114. group->addButton(targetRealCalc);
  115. switch (preferences.linkTarget) {
  116. default: // LT_NONE
  117. targetNone->setChecked(TRUE);
  118. break;
  119. case LT_TIEMU:
  120. targetTiEmu->setChecked(TRUE);
  121. break;
  122. case LT_REALCALC:
  123. targetRealCalc->setChecked(TRUE);
  124. break;
  125. }
  126. switch (preferences.linkPort) {
  127. default: // PORT_1
  128. port1->setChecked(TRUE);
  129. break;
  130. case PORT_2:
  131. port2->setChecked(TRUE);
  132. break;
  133. case PORT_3:
  134. port3->setChecked(TRUE);
  135. break;
  136. case PORT_4:
  137. port4->setChecked(TRUE);
  138. break;
  139. }
  140. switch (preferences.linkCable) {
  141. default: // CABLE_GRY
  142. grayLink->setChecked(TRUE);
  143. break;
  144. case CABLE_BLK:
  145. blackLink->setChecked(TRUE);
  146. break;
  147. case CABLE_PAR:
  148. parallelLink->setChecked(TRUE);
  149. break;
  150. case CABLE_SLV:
  151. silverLink->setChecked(TRUE);
  152. break;
  153. case CABLE_USB:
  154. directLink->setChecked(TRUE);
  155. break;
  156. }
  157. // Don't allow selecting a USB cable if libticables2 hasn't been compiled
  158. // without USB support or if USB support can't be used.
  159. if (!have_usb) {
  160. if (silverLink->isChecked() || directLink->isChecked()) {
  161. grayLink->setChecked(TRUE);
  162. targetNone->setChecked(TRUE);
  163. }
  164. silverLink->setEnabled(FALSE);
  165. directLink->setEnabled(FALSE);
  166. }
  167. // Editor
  168. tabWidthC->setValue(preferences.tabWidthC);
  169. tabWidthAsm->setValue(preferences.tabWidthAsm);
  170. useBgColor->setChecked(preferences.useBgColor);
  171. bgColor->setBackgroundColor(preferences.bgColor);
  172. editorFont->setFont(preferences.editorFont);
  173. editorFont->setText(preferences.editorFont.family());
  174. useCalcCharset->setChecked(preferences.useCalcCharset);
  175. autoBlocks->setChecked(preferences.autoBlocks);
  176. removeTrailingSpaces->setChecked(preferences.removeTrailingSpaces);
  177. // Syntax
  178. if (preferences.haveA68k)
  179. syntaxLanguage->insertItem("A68k Assembly Files");
  180. if (preferences.haveQuill)
  181. syntaxLanguage->insertItem("Quill Files");
  182. preferences.tempSynC=preferences.synC;
  183. preferences.tempSynS=preferences.synS;
  184. preferences.tempSynAsm=preferences.synAsm;
  185. preferences.tempSynQll=preferences.synQll;
  186. Q3ListViewItem *rootListItem=new Q3ListViewItem(syntaxListView,"Highlighting");
  187. Q3ListViewItem *customStylesItem=new Q3ListViewItem(rootListItem,"Custom Styles");
  188. Q3ListViewItem *wordListsItem=new Q3ListViewItem(rootListItem,"Word Lists");
  189. syntaxLanguage_activated(syntaxLanguage->currentItem());
  190. syntaxListView->setSorting(-1);
  191. syntaxListView->setColumnWidthMode(0,Q3ListView::Maximum);
  192. syntaxListView->header()->hide();
  193. syntaxListView->setAlternateBackground(QColor());
  194. customStylesItem->setOpen(TRUE);
  195. wordListsItem->setOpen(TRUE);
  196. rootListItem->setOpen(TRUE);
  197. QShortcut *syntaxListViewShortcut=new QShortcut(Qt::Key_Delete,syntaxListView);
  198. connect(syntaxListViewShortcut,SIGNAL(activated()),
  199. this,SLOT(syntaxListViewShortcut_activated()));
  200. // Coding
  201. templateListBox->clear();
  202. typedef const QPair<QString,QString> &StringPairConstRef;
  203. foreach (StringPairConstRef pair, preferences.templates)
  204. new ListBoxTextPair(templateListBox,pair.first,pair.second);
  205. templateListBox->sort();
  206. }
  207. Preferences::~Preferences()
  208. {
  209. if (result()==Accepted) {
  210. // General
  211. preferences.stopAtFirstError=stopAtFirstError->isChecked();
  212. preferences.jumpToError=jumpToError->isChecked();
  213. preferences.successMessage=successMessage->isChecked();
  214. preferences.deleteAsmFiles=deleteAsmFiles->isChecked();
  215. preferences.deleteObjFiles=deleteObjFiles->isChecked();
  216. preferences.splitSourceFiles=splitSourceFiles->isChecked();
  217. preferences.allowImplicitDeclaration=allowImplicitDeclaration->isChecked();
  218. preferences.autoSave=autoSave->isChecked();
  219. preferences.downloadHeadlines=downloadHeadlines->isChecked();
  220. preferences.deleteOverwrittenErrors=deleteOverwrittenErrors->isChecked();
  221. preferences.useSystemIcons=useSystemIcons->isChecked();
  222. // Transfer
  223. preferences.linkTarget=targetTiEmu->isChecked()?LT_TIEMU
  224. :targetRealCalc->isChecked()?LT_REALCALC
  225. :LT_NONE;
  226. preferences.linkPort=port2->isChecked()?PORT_2
  227. :port3->isChecked()?PORT_3
  228. :port4->isChecked()?PORT_4
  229. :PORT_1;
  230. preferences.linkCable=blackLink->isChecked()?CABLE_BLK
  231. :parallelLink->isChecked()?CABLE_PAR
  232. :silverLink->isChecked()?CABLE_SLV
  233. :directLink->isChecked()?CABLE_USB
  234. :CABLE_GRY;
  235. // Editor
  236. preferences.tabWidthC=tabWidthC->value();
  237. preferences.tabWidthAsm=tabWidthAsm->value();
  238. preferences.useBgColor=useBgColor->isChecked();
  239. preferences.bgColor=bgColor->backgroundColor();
  240. preferences.editorFont=editorFont->font();
  241. preferences.useCalcCharset=useCalcCharset->isChecked();
  242. preferences.autoBlocks=autoBlocks->isChecked();
  243. preferences.removeTrailingSpaces=removeTrailingSpaces->isChecked();
  244. // Syntax
  245. preferences.synC=preferences.tempSynC;
  246. preferences.synS=preferences.tempSynS;
  247. preferences.synAsm=preferences.tempSynAsm;
  248. preferences.synQll=preferences.tempSynQll;
  249. // Coding
  250. preferences.templates.clear();
  251. for (Q3ListBoxItem *item=templateListBox->firstItem(); item;
  252. item=item->next())
  253. preferences.templates.append(qMakePair(item->text(),
  254. static_cast<ListBoxTextPair *>(item)->data()));
  255. }
  256. }
  257. void Preferences::linkTarget_toggled(bool on __attribute__((unused)))
  258. {
  259. bool isRealCalc=targetRealCalc->isChecked();
  260. linkPort->setEnabled(isRealCalc);
  261. linkCable->setEnabled(isRealCalc);
  262. }
  263. void Preferences::bgColorChange_clicked()
  264. {
  265. QColor color=bgColor->backgroundColor();
  266. if (KColorDialog::getColor(color,this)==KColorDialog::Accepted) {
  267. useBgColor->setChecked(TRUE);
  268. bgColor->setBackgroundColor(color);
  269. }
  270. }
  271. void Preferences::editorFontChange_clicked()
  272. {
  273. QFont font=editorFont->font();
  274. if (KFontDialog::getFont(font,KFontChooser::FixedFontsOnly,this)
  275. ==KFontDialog::Accepted) {
  276. editorFont->setFont(font);
  277. editorFont->setText(font.family());
  278. }
  279. }
  280. void Preferences::syntaxLanguage_activated(int index)
  281. {
  282. if (!index) preferences.syn=&preferences.tempSynC;
  283. else if (!--index) preferences.syn=&preferences.tempSynS;
  284. else if (preferences.haveA68k && !--index)
  285. preferences.syn=&preferences.tempSynAsm;
  286. else if (preferences.haveQuill && !--index)
  287. preferences.syn=&preferences.tempSynQll;
  288. else {
  289. qWarning("Preferences::syntaxLanguage_activated: Invalid index.");
  290. preferences.syn=&preferences.tempSynC;
  291. }
  292. syntaxEnabled->setChecked(preferences.syn->enabled);
  293. Q3ListViewItem *rootListItem=syntaxListView->firstChild();
  294. Q3ListViewItem *item, *nextItem;
  295. Q3ListViewItem *customStylesItem=rootListItem->firstChild();
  296. for (item=customStylesItem->firstChild(); item; item=nextItem) {
  297. nextItem=item->nextSibling();
  298. delete item;
  299. }
  300. item=static_cast<Q3ListViewItem *>(NULL);
  301. for (QLinkedList<Syn_CustomStyle>::ConstIterator it=
  302. preferences.syn->customStyles.begin();
  303. it!=preferences.syn->customStyles.end(); ++it) {
  304. item=new RenamableKListViewItem(customStylesItem,item,(*it).name);
  305. }
  306. Q3ListViewItem *wordListsItem=customStylesItem->nextSibling();
  307. for (item=wordListsItem->firstChild(); item; item=nextItem) {
  308. nextItem=item->nextSibling();
  309. delete item;
  310. }
  311. item=static_cast<Q3ListViewItem *>(NULL);
  312. foreach (const Syn_WordList &wlist, preferences.syn->wordLists)
  313. item=new RenamableKListViewItem(wordListsItem,item,wlist.name);
  314. }
  315. void Preferences::syntaxEnabled_toggled(bool on)
  316. {
  317. preferences.syn->enabled=on;
  318. resetButton->setEnabled(on);
  319. numberColorButton->setEnabled(on);
  320. numberStyleButton->setEnabled(on);
  321. symbolColorButton->setEnabled(on);
  322. symbolStyleButton->setEnabled(on);
  323. parenthesisColorsButton->setEnabled(on);
  324. parenthesisStyleButton->setEnabled(on);
  325. syntaxListView->setEnabled(on);
  326. newStyleButton->setEnabled(on);
  327. newListButton->setEnabled(on);
  328. Q3ListViewItem *selectedItem=syntaxListView->selectedItem();
  329. editButton->setEnabled(on&&selectedItem&&selectedItem->rtti()==0x716CC8);
  330. }
  331. void Preferences::resetButton_clicked()
  332. {
  333. resetSyntaxPreference(preferences.syn);
  334. syntaxLanguage_activated(syntaxLanguage->currentItem());
  335. }
  336. void Preferences::numberColorButton_clicked()
  337. {
  338. QColor color=preferences.syn->numberColor;
  339. if (KColorDialog::getColor(color,this)==KColorDialog::Accepted)
  340. preferences.syn->numberColor=color;
  341. }
  342. void Preferences::numberStyleButton_clicked()
  343. {
  344. SelectStyle selectStyle(this);
  345. selectStyle.customStyle->setChecked(!!(preferences.syn->numberStyle&SYNS_CUSTOM));
  346. if (preferences.syn->numberStyle&SYNS_CUSTOM) {
  347. selectStyle.boldChk->setChecked(!!(preferences.syn->numberStyle&SYNS_BOLD));
  348. selectStyle.underlineChk->setChecked(!!(preferences.syn->numberStyle&SYNS_UNDERLINE));
  349. selectStyle.italicChk->setChecked(!!(preferences.syn->numberStyle&SYNS_ITALIC));
  350. selectStyle.strikeoutChk->setChecked(!!(preferences.syn->numberStyle&SYNS_STRIKEOUT));
  351. }
  352. selectStyle.exec();
  353. if (selectStyle.result()==QDialog::Accepted) {
  354. preferences.syn->numberStyle=0;
  355. if (selectStyle.customStyle->isChecked()) {
  356. preferences.syn->numberStyle|=SYNS_CUSTOM;
  357. if (selectStyle.boldChk->isChecked()) preferences.syn->numberStyle|=SYNS_BOLD;
  358. if (selectStyle.underlineChk->isChecked()) preferences.syn->numberStyle|=SYNS_UNDERLINE;
  359. if (selectStyle.italicChk->isChecked()) preferences.syn->numberStyle|=SYNS_ITALIC;
  360. if (selectStyle.strikeoutChk->isChecked()) preferences.syn->numberStyle|=SYNS_STRIKEOUT;
  361. }
  362. }
  363. }
  364. void Preferences::symbolColorButton_clicked()
  365. {
  366. QColor color=preferences.syn->symbolColor;
  367. if (KColorDialog::getColor(color,this)==KColorDialog::Accepted)
  368. preferences.syn->symbolColor=color;
  369. }
  370. void Preferences::symbolStyleButton_clicked()
  371. {
  372. SelectStyle selectStyle(this);
  373. selectStyle.customStyle->setChecked(!!(preferences.syn->symbolStyle&SYNS_CUSTOM));
  374. if (preferences.syn->symbolStyle&SYNS_CUSTOM) {
  375. selectStyle.boldChk->setChecked(!!(preferences.syn->symbolStyle&SYNS_BOLD));
  376. selectStyle.underlineChk->setChecked(!!(preferences.syn->symbolStyle&SYNS_UNDERLINE));
  377. selectStyle.italicChk->setChecked(!!(preferences.syn->symbolStyle&SYNS_ITALIC));
  378. selectStyle.strikeoutChk->setChecked(!!(preferences.syn->symbolStyle&SYNS_STRIKEOUT));
  379. }
  380. selectStyle.exec();
  381. if (selectStyle.result()==QDialog::Accepted) {
  382. preferences.syn->symbolStyle=0;
  383. if (selectStyle.customStyle->isChecked()) {
  384. preferences.syn->symbolStyle|=SYNS_CUSTOM;
  385. if (selectStyle.boldChk->isChecked()) preferences.syn->symbolStyle|=SYNS_BOLD;
  386. if (selectStyle.underlineChk->isChecked()) preferences.syn->symbolStyle|=SYNS_UNDERLINE;
  387. if (selectStyle.italicChk->isChecked()) preferences.syn->symbolStyle|=SYNS_ITALIC;
  388. if (selectStyle.strikeoutChk->isChecked()) preferences.syn->symbolStyle|=SYNS_STRIKEOUT;
  389. }
  390. }
  391. }
  392. void Preferences::parenthesisColorsButton_clicked()
  393. {
  394. SelectColors selectColors(this);
  395. selectColors.colorList->clear();
  396. foreach (const QColor &color, preferences.syn->parenthesisColors)
  397. new ColorListItem(selectColors.colorList,color);
  398. selectColors.exec();
  399. if (selectColors.result()==QDialog::Accepted) {
  400. preferences.syn->parenthesisColors.clear();
  401. for (Q3ListBoxItem *item=selectColors.colorList->firstItem(); item;
  402. item=item->next())
  403. preferences.syn->parenthesisColors.append(
  404. static_cast<ColorListItem *>(item)->color());
  405. }
  406. }
  407. void Preferences::parenthesisStyleButton_clicked()
  408. {
  409. SelectStyle selectStyle(this);
  410. selectStyle.customStyle->setChecked(!!(preferences.syn->parenthesisStyle&SYNS_CUSTOM));
  411. if (preferences.syn->parenthesisStyle&SYNS_CUSTOM) {
  412. selectStyle.boldChk->setChecked(!!(preferences.syn->parenthesisStyle&SYNS_BOLD));
  413. selectStyle.underlineChk->setChecked(!!(preferences.syn->parenthesisStyle&SYNS_UNDERLINE));
  414. selectStyle.italicChk->setChecked(!!(preferences.syn->parenthesisStyle&SYNS_ITALIC));
  415. selectStyle.strikeoutChk->setChecked(!!(preferences.syn->parenthesisStyle&SYNS_STRIKEOUT));
  416. }
  417. selectStyle.exec();
  418. if (selectStyle.result()==QDialog::Accepted) {
  419. preferences.syn->parenthesisStyle=0;
  420. if (selectStyle.customStyle->isChecked()) {
  421. preferences.syn->parenthesisStyle|=SYNS_CUSTOM;
  422. if (selectStyle.boldChk->isChecked()) preferences.syn->parenthesisStyle|=SYNS_BOLD;
  423. if (selectStyle.underlineChk->isChecked()) preferences.syn->parenthesisStyle|=SYNS_UNDERLINE;
  424. if (selectStyle.italicChk->isChecked()) preferences.syn->parenthesisStyle|=SYNS_ITALIC;
  425. if (selectStyle.strikeoutChk->isChecked()) preferences.syn->parenthesisStyle|=SYNS_STRIKEOUT;
  426. }
  427. }
  428. }
  429. void Preferences::syntaxListView_selectionChanged()
  430. {
  431. Q3ListViewItem *selectedItem=syntaxListView->selectedItem();
  432. editButton->setEnabled(syntaxEnabled->isChecked()
  433. && selectedItem && selectedItem->rtti()==0x716CC8);
  434. }
  435. void Preferences::syntaxListView_itemRenamed(Q3ListViewItem *item, const QString &str, int col __attribute__((unused)))
  436. {
  437. Q3ListViewItem *rootListItem=syntaxListView->firstChild();
  438. Q3ListViewItem *customStylesItem=rootListItem->firstChild();
  439. Q3ListViewItem *wordListsItem=customStylesItem->nextSibling();
  440. if (item->parent()==customStylesItem) {
  441. Q3ListViewItem *i;
  442. QLinkedList<Syn_CustomStyle>::Iterator it;
  443. for (it=preferences.syn->customStyles.begin(), i=customStylesItem->firstChild();
  444. i!=item && it!=preferences.syn->customStyles.end() && i;
  445. ++it, i=i->nextSibling());
  446. if (it==preferences.syn->customStyles.end() || !i)
  447. qWarning("Preferences::syntaxListView_itemRenamed: Invalid item.");
  448. else
  449. (*it).name=str;
  450. } else if (item->parent()==wordListsItem) {
  451. Q3ListViewItem *i;
  452. QLinkedList<Syn_WordList>::Iterator it;
  453. for (it=preferences.syn->wordLists.begin(), i=wordListsItem->firstChild();
  454. i!=item && it!=preferences.syn->wordLists.end() && i;
  455. ++it, i=i->nextSibling());
  456. if (it==preferences.syn->wordLists.end() || !i)
  457. qWarning("Preferences::syntaxListView_itemRenamed: Invalid item.");
  458. else
  459. (*it).name=str;
  460. } else qWarning("Preferences::syntaxListView_itemRenamed: Invalid parent.");
  461. }
  462. void Preferences::syntaxListViewShortcut_activated()
  463. {
  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. QLinkedList<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::syntaxListViewShortcut_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. QLinkedList<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::syntaxListViewShortcut_activated: Invalid item.");
  489. else {
  490. delete currentItem;
  491. preferences.syn->wordLists.remove(it);
  492. }
  493. } else qWarning("Preferences::syntaxListViewShortcut_activated: Invalid parent.");
  494. }
  495. }
  496. void Preferences::newStyleButton_clicked()
  497. {
  498. Syn_CustomStyle newStyle;
  499. newStyle.name="New Style";
  500. preferences.syn->customStyles.append(newStyle);
  501. Q3ListViewItem *rootListItem=syntaxListView->firstChild();
  502. Q3ListViewItem *customStylesItem=rootListItem->firstChild();
  503. Q3ListViewItem *item=customStylesItem->firstChild();
  504. while (item && item->nextSibling()) item=item->nextSibling();
  505. item=new RenamableKListViewItem(customStylesItem,item,newStyle.name);
  506. syntaxListView->setCurrentItem(item);
  507. syntaxListView->setSelected(item,TRUE);
  508. item->startRename(0);
  509. }
  510. void Preferences::newListButton_clicked()
  511. {
  512. Syn_WordList newList;
  513. newList.name="New List";
  514. preferences.syn->wordLists.append(newList);
  515. Q3ListViewItem *rootListItem=syntaxListView->firstChild();
  516. Q3ListViewItem *customStylesItem=rootListItem->firstChild();
  517. Q3ListViewItem *wordListsItem=customStylesItem->nextSibling();
  518. Q3ListViewItem *item=wordListsItem->firstChild();
  519. while (item && item->nextSibling()) item=item->nextSibling();
  520. item=new RenamableKListViewItem(wordListsItem,item,newList.name);
  521. syntaxListView->setCurrentItem(item);
  522. syntaxListView->setSelected(item,TRUE);
  523. item->startRename(0);
  524. }
  525. static QDialog *editDialog;
  526. static Syn_Style tempStyle;
  527. static QColor tempColor;
  528. void Preferences::editButton_clicked()
  529. {
  530. Q3ListViewItem *currentItem=syntaxListView->currentItem();
  531. if (currentItem && currentItem->rtti()==0x716CC8) {
  532. Q3ListViewItem *rootListItem=syntaxListView->firstChild();
  533. Q3ListViewItem *customStylesItem=rootListItem->firstChild();
  534. Q3ListViewItem *wordListsItem=customStylesItem->nextSibling();
  535. if (currentItem->parent()==customStylesItem) {
  536. Q3ListViewItem *i;
  537. QLinkedList<Syn_CustomStyle>::Iterator it;
  538. for (it=preferences.syn->customStyles.begin(), i=customStylesItem->firstChild();
  539. i!=currentItem && it!=preferences.syn->customStyles.end() && i;
  540. ++it, i=i->nextSibling());
  541. if (it==preferences.syn->customStyles.end() || !i)
  542. qWarning("Preferences::editButton_clicked: Invalid item.");
  543. else {
  544. Syn_CustomStyle &customStyle=*it;
  545. CustomStyle customStyleDlg(this);
  546. editDialog=&customStyleDlg;
  547. customStyleDlg.beginning->setText(customStyle.beginning);
  548. customStyleDlg.ending->setText(customStyle.ending=="\n"?"\\n"
  549. :customStyle.ending);
  550. customStyleDlg.ignoreEndingAfter->setText(QString(customStyle.ignoreEndingAfter));
  551. customStyleDlg.switchable->setChecked(customStyle.switchable);
  552. customStyleDlg.lineStartOnly->setChecked(customStyle.lineStartOnly);
  553. tempStyle=customStyle.style;
  554. tempColor=customStyle.color;
  555. connect(customStyleDlg.styleButton,SIGNAL(clicked()),
  556. this,SLOT(editDialog_styleButton_clicked()));
  557. connect(customStyleDlg.colorButton,SIGNAL(clicked()),
  558. this,SLOT(editDialog_colorButton_clicked()));
  559. customStyleDlg.exec();
  560. if (customStyleDlg.result()==QDialog::Accepted) {
  561. customStyle.beginning=customStyleDlg.beginning->text();
  562. customStyle.ending=customStyleDlg.ending->text()=="\\n"?"\n"
  563. :customStyleDlg.ending->text();
  564. QString ignoreEndingAfter=customStyleDlg.ignoreEndingAfter->text();
  565. customStyle.ignoreEndingAfter=ignoreEndingAfter.isEmpty()?QChar():ignoreEndingAfter[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. QLinkedList<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(Qt::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(Qt::WaitCursor);
  693. if (!parseSystemHeaders(this,dirName,sysHdrCompletion)) {
  694. setCursor(QCursor());
  695. return;
  696. }
  697. systemHeaderCompletion=sysHdrCompletion;
  698. saveSystemHeaderCompletion();
  699. setCursor(QCursor());
  700. }
  701. void Preferences::languageChange()
  702. {
  703. retranslateUi(this);
  704. }