preferencesdlg.cpp 28 KB

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