preferencesdlg.ui.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. /****************************************************************************
  2. ** ui.h extension file, included from the uic-generated form implementation.
  3. **
  4. ** If you want to add, delete, or rename functions or slots, use
  5. ** Qt Designer to update this file, preserving your code.
  6. **
  7. ** You should not define a constructor or destructor in this file.
  8. ** Instead, write your code in functions called init() and destroy().
  9. ** These will automatically be called by the form's constructor and
  10. ** destructor.
  11. *****************************************************************************/
  12. /*
  13. ktigcc - TIGCC IDE for KDE
  14. Copyright (C) 2006 Kevin Kofler
  15. This program is free software; you can redistribute it and/or modify
  16. it under the terms of the GNU General Public License as published by
  17. the Free Software Foundation; either version 2, or (at your option)
  18. any later version.
  19. This program is distributed in the hope that it will be useful,
  20. but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. GNU General Public License for more details.
  23. You should have received a copy of the GNU General Public License
  24. along with this program; if not, write to the Free Software Foundation,
  25. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  26. */
  27. #include "preferences.h"
  28. #include <qcheckbox.h>
  29. #include <qradiobutton.h>
  30. #include <qaccel.h>
  31. #include <knuminput.h>
  32. #include <kfontdialog.h>
  33. #include <kcolordialog.h>
  34. #include <kcombobox.h>
  35. #include <klistview.h>
  36. #include "ktigcc.h"
  37. #include "selectstyle.h"
  38. #include "selectcolors.h"
  39. class RenamableKListViewItem : public KListViewItem {
  40. public:
  41. RenamableKListViewItem(QListViewItem *parent, QString text)
  42. : KListViewItem(parent, text)
  43. {
  44. setRenameEnabled(0,TRUE);
  45. }
  46. RenamableKListViewItem(QListViewItem *parent, QListViewItem *after,
  47. QString text)
  48. : KListViewItem(parent, after, text)
  49. {
  50. setRenameEnabled(0,TRUE);
  51. }
  52. virtual int rtti(void) const {return 0x716CC8;}
  53. // Work around gratuitous API difference. Why do I have to do this? That's
  54. // what startRename is a virtual method for. KListViewItem should do this.
  55. virtual void startRename(int col)
  56. {
  57. static_cast<KListView *>(listView())->rename(this,col);
  58. }
  59. };
  60. void Preferences::init()
  61. {
  62. // General
  63. stopAtFirstError->setChecked(preferences.stopAtFirstError);
  64. jumpToError->setChecked(preferences.jumpToError);
  65. successMessage->setChecked(preferences.successMessage);
  66. deleteAsmFiles->setChecked(preferences.deleteAsmFiles);
  67. deleteObjFiles->setChecked(preferences.deleteObjFiles);
  68. splitSourceFiles->setChecked(preferences.splitSourceFiles);
  69. allowImplicitDeclaration->setChecked(preferences.allowImplicitDeclaration);
  70. autoSave->setChecked(preferences.autoSave);
  71. downloadHeadlines->setChecked(preferences.downloadHeadlines);
  72. deleteOverwrittenErrors->setChecked(preferences.deleteOverwrittenErrors);
  73. useSystemIcons->setChecked(preferences.useSystemIcons);
  74. // Transfer
  75. switch (preferences.linkTarget) {
  76. default: // LT_NONE
  77. targetNone->setChecked(TRUE);
  78. break;
  79. case LT_TIEMU:
  80. targetTiEmu->setChecked(TRUE);
  81. break;
  82. case LT_REALCALC:
  83. targetRealCalc->setChecked(TRUE);
  84. break;
  85. }
  86. switch (preferences.linkPort) {
  87. default: // PORT_1
  88. port1->setChecked(TRUE);
  89. break;
  90. case PORT_2:
  91. port2->setChecked(TRUE);
  92. break;
  93. case PORT_3:
  94. port3->setChecked(TRUE);
  95. break;
  96. case PORT_4:
  97. port4->setChecked(TRUE);
  98. break;
  99. }
  100. switch (preferences.linkCable) {
  101. default: // CABLE_GRY
  102. grayLink->setChecked(TRUE);
  103. break;
  104. case CABLE_BLK:
  105. blackLink->setChecked(TRUE);
  106. break;
  107. case CABLE_PAR:
  108. parallelLink->setChecked(TRUE);
  109. break;
  110. case CABLE_SLV:
  111. silverLink->setChecked(TRUE);
  112. break;
  113. case CABLE_USB:
  114. directLink->setChecked(TRUE);
  115. break;
  116. }
  117. // Don't allow selecting a USB cable if libticables2 hasn't been compiled
  118. // without USB support or if USB support can't be used.
  119. if (!have_usb) {
  120. if (silverLink->isChecked() || directLink->isChecked()) {
  121. grayLink->setChecked(TRUE);
  122. targetNone->setChecked(TRUE);
  123. }
  124. silverLink->setEnabled(FALSE);
  125. directLink->setEnabled(FALSE);
  126. }
  127. // Editor
  128. tabWidthC->setValue(preferences.tabWidthC);
  129. tabWidthAsm->setValue(preferences.tabWidthAsm);
  130. useBgColor->setChecked(preferences.useBgColor);
  131. bgColor->setBackgroundColor(preferences.bgColor);
  132. editorFont->setFont(preferences.editorFont);
  133. editorFont->setText(preferences.editorFont.family());
  134. useCalcCharset->setChecked(preferences.useCalcCharset);
  135. lazyLoading->setChecked(preferences.lazyLoading);
  136. autoBlocks->setChecked(preferences.autoBlocks);
  137. removeTrailingSpaces->setChecked(preferences.removeTrailingSpaces);
  138. // Syntax
  139. if (preferences.haveA68k)
  140. syntaxLanguage->insertItem("A68k Assembly Files");
  141. if (preferences.haveQuill)
  142. syntaxLanguage->insertItem("Quill Files");
  143. preferences.tempSynC=preferences.synC;
  144. preferences.tempSynS=preferences.synS;
  145. preferences.tempSynAsm=preferences.synAsm;
  146. preferences.tempSynQll=preferences.synQll;
  147. syntaxLanguage_activated(syntaxLanguage->currentItem());
  148. syntaxListView->setSorting(-1);
  149. syntaxListView->setColumnWidthMode(0,QListView::Maximum);
  150. syntaxListView->header()->hide();
  151. QListViewItem *rootListItem=syntaxListView->firstChild();
  152. QListViewItem *customStylesItem=rootListItem->firstChild();
  153. customStylesItem->setOpen(TRUE);
  154. QListViewItem *wordListsItem=customStylesItem->nextSibling();
  155. wordListsItem->setOpen(TRUE);
  156. QAccel *syntaxListViewAccel=new QAccel(syntaxListView);
  157. syntaxListViewAccel->insertItem(Key_Delete,0);
  158. connect(syntaxListViewAccel,SIGNAL(activated(int)),
  159. this,SLOT(syntaxListViewAccel_activated(int)));
  160. }
  161. void Preferences::destroy()
  162. {
  163. if (result()==Accepted) {
  164. // General
  165. preferences.stopAtFirstError=stopAtFirstError->isChecked();
  166. preferences.jumpToError=jumpToError->isChecked();
  167. preferences.successMessage=successMessage->isChecked();
  168. preferences.deleteAsmFiles=deleteAsmFiles->isChecked();
  169. preferences.deleteObjFiles=deleteObjFiles->isChecked();
  170. preferences.splitSourceFiles=splitSourceFiles->isChecked();
  171. preferences.allowImplicitDeclaration=allowImplicitDeclaration->isChecked();
  172. preferences.autoSave=autoSave->isChecked();
  173. preferences.downloadHeadlines=downloadHeadlines->isChecked();
  174. preferences.deleteOverwrittenErrors=deleteOverwrittenErrors->isChecked();
  175. preferences.useSystemIcons=useSystemIcons->isChecked();
  176. // Transfer
  177. preferences.linkTarget=targetTiEmu->isChecked()?LT_TIEMU
  178. :targetRealCalc->isChecked()?LT_REALCALC
  179. :LT_NONE;
  180. preferences.linkPort=port2->isChecked()?PORT_2
  181. :port3->isChecked()?PORT_3
  182. :port4->isChecked()?PORT_4
  183. :PORT_1;
  184. preferences.linkCable=blackLink->isChecked()?CABLE_BLK
  185. :parallelLink->isChecked()?CABLE_PAR
  186. :silverLink->isChecked()?CABLE_SLV
  187. :directLink->isChecked()?CABLE_USB
  188. :CABLE_GRY;
  189. // Editor
  190. preferences.tabWidthC=tabWidthC->value();
  191. preferences.tabWidthAsm=tabWidthAsm->value();
  192. preferences.useBgColor=useBgColor->isChecked();
  193. preferences.bgColor=bgColor->backgroundColor();
  194. preferences.editorFont=editorFont->font();
  195. preferences.useCalcCharset=useCalcCharset->isChecked();
  196. preferences.lazyLoading=lazyLoading->isChecked();
  197. preferences.autoBlocks=autoBlocks->isChecked();
  198. preferences.removeTrailingSpaces=removeTrailingSpaces->isChecked();
  199. // Syntax
  200. preferences.synC=preferences.tempSynC;
  201. preferences.synS=preferences.tempSynS;
  202. preferences.synAsm=preferences.tempSynAsm;
  203. preferences.synQll=preferences.tempSynQll;
  204. }
  205. }
  206. #define unused_on on __attribute__((unused))
  207. void Preferences::linkTarget_toggled(bool unused_on)
  208. {
  209. bool isRealCalc=targetRealCalc->isChecked();
  210. linkPort->setEnabled(isRealCalc);
  211. linkCable->setEnabled(isRealCalc);
  212. }
  213. void Preferences::bgColorChange_clicked()
  214. {
  215. QColor color=bgColor->backgroundColor();
  216. if (KColorDialog::getColor(color,this)==KColorDialog::Accepted) {
  217. useBgColor->setChecked(TRUE);
  218. bgColor->setBackgroundColor(color);
  219. }
  220. }
  221. void Preferences::editorFontChange_clicked()
  222. {
  223. QFont font=editorFont->font();
  224. if (KFontDialog::getFont(font,TRUE,this)==KFontDialog::Accepted) {
  225. editorFont->setFont(font);
  226. editorFont->setText(font.family());
  227. }
  228. }
  229. void Preferences::syntaxLanguage_activated(int index)
  230. {
  231. if (!index) preferences.syn=&preferences.tempSynC;
  232. else if (!--index) preferences.syn=&preferences.tempSynS;
  233. else if (preferences.haveA68k && !--index)
  234. preferences.syn=&preferences.tempSynAsm;
  235. else if (preferences.haveQuill && !--index)
  236. preferences.syn=&preferences.tempSynQll;
  237. else {
  238. qWarning("Preferences::syntaxLanguage_activated: Invalid index.");
  239. preferences.syn=&preferences.tempSynC;
  240. }
  241. syntaxEnabled->setChecked(preferences.syn->enabled);
  242. QListViewItem *rootListItem=syntaxListView->firstChild();
  243. QListViewItem *item, *nextItem;
  244. QListViewItem *customStylesItem=rootListItem->firstChild();
  245. for (item=customStylesItem->firstChild(); item; item=nextItem) {
  246. nextItem=item->nextSibling();
  247. delete item;
  248. }
  249. item=static_cast<QListViewItem *>(NULL);
  250. for (QValueList<Syn_CustomStyle>::ConstIterator it=
  251. preferences.syn->customStyles.begin();
  252. it!=preferences.syn->customStyles.end(); ++it) {
  253. item=new RenamableKListViewItem(customStylesItem,item,(*it).name);
  254. }
  255. QListViewItem *wordListsItem=customStylesItem->nextSibling();
  256. for (item=wordListsItem->firstChild(); item; item=nextItem) {
  257. nextItem=item->nextSibling();
  258. delete item;
  259. }
  260. item=static_cast<QListViewItem *>(NULL);
  261. for (QValueList<Syn_WordList>::ConstIterator it=
  262. preferences.syn->wordLists.begin();
  263. it!=preferences.syn->wordLists.end(); ++it) {
  264. item=new RenamableKListViewItem(wordListsItem,item,(*it).name);
  265. }
  266. }
  267. void Preferences::syntaxEnabled_toggled(bool on)
  268. {
  269. preferences.syn->enabled=on;
  270. resetButton->setEnabled(on);
  271. numberColorButton->setEnabled(on);
  272. numberStyleButton->setEnabled(on);
  273. symbolColorButton->setEnabled(on);
  274. symbolStyleButton->setEnabled(on);
  275. parenthesisColorsButton->setEnabled(on);
  276. parenthesisStyleButton->setEnabled(on);
  277. syntaxListView->setEnabled(on);
  278. newStyleButton->setEnabled(on);
  279. newListButton->setEnabled(on);
  280. QListViewItem *selectedItem=syntaxListView->selectedItem();
  281. editButton->setEnabled(on&&selectedItem&&selectedItem->rtti()==0x716CC8);
  282. }
  283. void Preferences::resetButton_clicked()
  284. {
  285. resetSyntaxPreference(preferences.syn);
  286. syntaxLanguage_activated(syntaxLanguage->currentItem());
  287. }
  288. void Preferences::numberColorButton_clicked()
  289. {
  290. QColor color=preferences.syn->numberColor;
  291. if (KColorDialog::getColor(color,this)==KColorDialog::Accepted)
  292. preferences.syn->numberColor=color;
  293. }
  294. void Preferences::numberStyleButton_clicked()
  295. {
  296. SelectStyle selectStyle(this);
  297. selectStyle.customStyle->setChecked(!!(preferences.syn->numberStyle&SYNS_CUSTOM));
  298. if (preferences.syn->numberStyle&SYNS_CUSTOM) {
  299. selectStyle.boldChk->setChecked(!!(preferences.syn->numberStyle&SYNS_BOLD));
  300. selectStyle.underlineChk->setChecked(!!(preferences.syn->numberStyle&SYNS_UNDERLINE));
  301. selectStyle.italicChk->setChecked(!!(preferences.syn->numberStyle&SYNS_ITALIC));
  302. selectStyle.strikeoutChk->setChecked(!!(preferences.syn->numberStyle&SYNS_STRIKEOUT));
  303. }
  304. selectStyle.exec();
  305. if (selectStyle.result()==QDialog::Accepted) {
  306. preferences.syn->numberStyle=0;
  307. if (selectStyle.customStyle->isChecked()) {
  308. preferences.syn->numberStyle|=SYNS_CUSTOM;
  309. if (selectStyle.boldChk->isChecked()) preferences.syn->numberStyle|=SYNS_BOLD;
  310. if (selectStyle.underlineChk->isChecked()) preferences.syn->numberStyle|=SYNS_UNDERLINE;
  311. if (selectStyle.italicChk->isChecked()) preferences.syn->numberStyle|=SYNS_ITALIC;
  312. if (selectStyle.strikeoutChk->isChecked()) preferences.syn->numberStyle|=SYNS_STRIKEOUT;
  313. }
  314. }
  315. }
  316. void Preferences::symbolColorButton_clicked()
  317. {
  318. QColor color=preferences.syn->symbolColor;
  319. if (KColorDialog::getColor(color,this)==KColorDialog::Accepted)
  320. preferences.syn->symbolColor=color;
  321. }
  322. void Preferences::symbolStyleButton_clicked()
  323. {
  324. SelectStyle selectStyle(this);
  325. selectStyle.customStyle->setChecked(!!(preferences.syn->symbolStyle&SYNS_CUSTOM));
  326. if (preferences.syn->symbolStyle&SYNS_CUSTOM) {
  327. selectStyle.boldChk->setChecked(!!(preferences.syn->symbolStyle&SYNS_BOLD));
  328. selectStyle.underlineChk->setChecked(!!(preferences.syn->symbolStyle&SYNS_UNDERLINE));
  329. selectStyle.italicChk->setChecked(!!(preferences.syn->symbolStyle&SYNS_ITALIC));
  330. selectStyle.strikeoutChk->setChecked(!!(preferences.syn->symbolStyle&SYNS_STRIKEOUT));
  331. }
  332. selectStyle.exec();
  333. if (selectStyle.result()==QDialog::Accepted) {
  334. preferences.syn->symbolStyle=0;
  335. if (selectStyle.customStyle->isChecked()) {
  336. preferences.syn->symbolStyle|=SYNS_CUSTOM;
  337. if (selectStyle.boldChk->isChecked()) preferences.syn->symbolStyle|=SYNS_BOLD;
  338. if (selectStyle.underlineChk->isChecked()) preferences.syn->symbolStyle|=SYNS_UNDERLINE;
  339. if (selectStyle.italicChk->isChecked()) preferences.syn->symbolStyle|=SYNS_ITALIC;
  340. if (selectStyle.strikeoutChk->isChecked()) preferences.syn->symbolStyle|=SYNS_STRIKEOUT;
  341. }
  342. }
  343. }
  344. void Preferences::parenthesisColorsButton_clicked()
  345. {
  346. }
  347. void Preferences::parenthesisStyleButton_clicked()
  348. {
  349. SelectStyle selectStyle(this);
  350. selectStyle.customStyle->setChecked(!!(preferences.syn->parenthesisStyle&SYNS_CUSTOM));
  351. if (preferences.syn->parenthesisStyle&SYNS_CUSTOM) {
  352. selectStyle.boldChk->setChecked(!!(preferences.syn->parenthesisStyle&SYNS_BOLD));
  353. selectStyle.underlineChk->setChecked(!!(preferences.syn->parenthesisStyle&SYNS_UNDERLINE));
  354. selectStyle.italicChk->setChecked(!!(preferences.syn->parenthesisStyle&SYNS_ITALIC));
  355. selectStyle.strikeoutChk->setChecked(!!(preferences.syn->parenthesisStyle&SYNS_STRIKEOUT));
  356. }
  357. selectStyle.exec();
  358. if (selectStyle.result()==QDialog::Accepted) {
  359. preferences.syn->parenthesisStyle=0;
  360. if (selectStyle.customStyle->isChecked()) {
  361. preferences.syn->parenthesisStyle|=SYNS_CUSTOM;
  362. if (selectStyle.boldChk->isChecked()) preferences.syn->parenthesisStyle|=SYNS_BOLD;
  363. if (selectStyle.underlineChk->isChecked()) preferences.syn->parenthesisStyle|=SYNS_UNDERLINE;
  364. if (selectStyle.italicChk->isChecked()) preferences.syn->parenthesisStyle|=SYNS_ITALIC;
  365. if (selectStyle.strikeoutChk->isChecked()) preferences.syn->parenthesisStyle|=SYNS_STRIKEOUT;
  366. }
  367. }
  368. }
  369. void Preferences::syntaxListView_selectionChanged()
  370. {
  371. QListViewItem *selectedItem=syntaxListView->selectedItem();
  372. editButton->setEnabled(syntaxEnabled->isChecked()
  373. && selectedItem && selectedItem->rtti()==0x716CC8);
  374. }
  375. #define unused_col col __attribute__((unused))
  376. void Preferences::syntaxListView_itemRenamed(QListViewItem *item, const QString &str, int unused_col)
  377. {
  378. QListViewItem *rootListItem=syntaxListView->firstChild();
  379. QListViewItem *customStylesItem=rootListItem->firstChild();
  380. QListViewItem *wordListsItem=customStylesItem->nextSibling();
  381. if (item->parent()==customStylesItem) {
  382. QListViewItem *i;
  383. QValueList<Syn_CustomStyle>::Iterator it;
  384. for (it=preferences.syn->customStyles.begin(), i=customStylesItem->firstChild();
  385. i!=item && it!=preferences.syn->customStyles.end() && i;
  386. ++it, i=i->nextSibling());
  387. if (it==preferences.syn->customStyles.end() || !i)
  388. qWarning("Preferences::syntaxListView_itemRenamed: Invalid item.");
  389. else
  390. (*it).name=str;
  391. } else if (item->parent()==wordListsItem) {
  392. QListViewItem *i;
  393. QValueList<Syn_WordList>::Iterator it;
  394. for (it=preferences.syn->wordLists.begin(), i=wordListsItem->firstChild();
  395. i!=item && it!=preferences.syn->wordLists.end() && i;
  396. ++it, i=i->nextSibling());
  397. if (it==preferences.syn->wordLists.end() || !i)
  398. qWarning("Preferences::syntaxListView_itemRenamed: Invalid item.");
  399. else
  400. (*it).name=str;
  401. } else qWarning("Preferences::syntaxListView_itemRenamed: Invalid parent.");
  402. }
  403. void Preferences::syntaxListViewAccel_activated(int id)
  404. {
  405. if (!id) {
  406. QListViewItem *currentItem=syntaxListView->currentItem();
  407. if (currentItem && currentItem->rtti()==0x716CC8) {
  408. QListViewItem *rootListItem=syntaxListView->firstChild();
  409. QListViewItem *customStylesItem=rootListItem->firstChild();
  410. QListViewItem *wordListsItem=customStylesItem->nextSibling();
  411. if (currentItem->parent()==customStylesItem) {
  412. QListViewItem *i;
  413. QValueList<Syn_CustomStyle>::Iterator it;
  414. for (it=preferences.syn->customStyles.begin(), i=customStylesItem->firstChild();
  415. i!=currentItem && it!=preferences.syn->customStyles.end() && i;
  416. ++it, i=i->nextSibling());
  417. if (it==preferences.syn->customStyles.end() || !i)
  418. qWarning("Preferences::syntaxListViewAccel_activated: Invalid item.");
  419. else {
  420. delete currentItem;
  421. preferences.syn->customStyles.remove(it);
  422. }
  423. } else if (currentItem->parent()==wordListsItem) {
  424. QListViewItem *i;
  425. QValueList<Syn_WordList>::Iterator it;
  426. for (it=preferences.syn->wordLists.begin(), i=wordListsItem->firstChild();
  427. i!=currentItem && it!=preferences.syn->wordLists.end() && i;
  428. ++it, i=i->nextSibling());
  429. if (it==preferences.syn->wordLists.end() || !i)
  430. qWarning("Preferences::syntaxListViewAccel_activated: Invalid item.");
  431. else {
  432. delete currentItem;
  433. preferences.syn->wordLists.remove(it);
  434. }
  435. } else qWarning("Preferences::syntaxListViewAccel_activated: Invalid parent.");
  436. }
  437. }
  438. }
  439. void Preferences::newStyleButton_clicked()
  440. {
  441. }
  442. void Preferences::newListButton_clicked()
  443. {
  444. }
  445. void Preferences::editButton_clicked()
  446. {
  447. }