programoptions.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. /*
  2. ktigcc - TIGCC IDE for KDE
  3. Copyright (C) 2004-2007 Kevin Kofler
  4. Copyright (C) 2006 Joey Adams
  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 "programoptions.h"
  18. #include <QVariant>
  19. #include <QImage>
  20. #include <QPixmap>
  21. #include <QApplication>
  22. #include <QEvent>
  23. #include <QEventLoop>
  24. #include <QMouseEvent>
  25. #include <QAssistantClient>
  26. #include <QButtonGroup>
  27. #include <kpushbutton.h>
  28. #include "ktigcc.h"
  29. #include "tpr.h"
  30. ProgramOptions::ProgramOptions(QWidget* parent, const char* name, bool modal, Qt::WindowFlags fl)
  31. : QDialog(parent, name, modal, fl)
  32. {
  33. setupUi(this);
  34. buttonClose->setGuiItem(KStandardGuiItem::Close);
  35. // Create button groups
  36. QButtonGroup *group;
  37. //Tab: Reloc Format
  38. group=new QButtonGroup(this);
  39. group->addButton(RelocAMS);
  40. group->addButton(RelocKernel);
  41. group->addButton(RelocCompressed);
  42. group->addButton(RelocMlink);
  43. group=new QButtonGroup(this);
  44. group->addButton(ROMCallDirect);
  45. group->addButton(ROMCallKernel);
  46. group->addButton(ROMCallCompressed);
  47. group->addButton(ROMCallMlink);
  48. group->addButton(ROMCallFLine);
  49. //Tab: BSS/Data Format
  50. group=new QButtonGroup(this);
  51. group->addButton(BSSMerge);
  52. group->addButton(BSSKernel);
  53. group->addButton(BSSCompressed);
  54. group->addButton(BSSMlink);
  55. group=new QButtonGroup(this);
  56. group->addButton(DataVarKernel);
  57. group->addButton(DataVarCompressed);
  58. group->addButton(DataVarMlink);
  59. }
  60. ProgramOptions::~ProgramOptions()
  61. {
  62. }
  63. void ProgramOptions::ImportSettings()
  64. {
  65. //Tab: Calculator
  66. TI89->setChecked(libopts.use_ti89);
  67. TI92Plus->setChecked(libopts.use_ti92p);
  68. V200->setChecked(libopts.use_v200);
  69. OptimizeCalcConsts->setChecked(libopts.opt_calc_consts);
  70. //Tab: Operating System
  71. if (libopts.use_preos)
  72. PreOS->setChecked(TRUE);
  73. else if (libopts.use_kernel)
  74. UseKernel->setChecked(TRUE);
  75. else
  76. Nostub->setChecked(TRUE);
  77. CMinimumAMSVersion->setChecked(libopts.use_minams);
  78. MinimumAMSVersion->setText(QString("%1.%2%3").arg(libopts.minams/100).arg((libopts.minams/10)%10).arg(libopts.minams%10));
  79. MinimumAMSVersion->setEnabled(libopts.use_minams);
  80. UnofficialOSSupport->setChecked(libopts.unofficial_os);
  81. //Tab: Reloc Format
  82. if (libopts.reloc_format==RT_KERNEL)
  83. RelocKernel->setChecked(TRUE);
  84. else if (libopts.reloc_format==RT_COMPRESSED)
  85. RelocCompressed->setChecked(TRUE);
  86. else if (libopts.reloc_format==RT_MLINK)
  87. RelocMlink->setChecked(TRUE);
  88. else
  89. RelocAMS->setChecked(TRUE);
  90. UseFLineJumps->setChecked(libopts.use_fline_jumps);
  91. Use4ByteFLineJumps->setChecked(libopts.use_4b_fline_jumps);
  92. if (libopts.rom_call_format==RT_KERNEL)
  93. ROMCallKernel->setChecked(TRUE);
  94. else if (libopts.rom_call_format==RT_COMPRESSED)
  95. ROMCallCompressed->setChecked(TRUE);
  96. else if (libopts.rom_call_format==RT_MLINK)
  97. ROMCallMlink->setChecked(TRUE);
  98. else if (libopts.rom_call_format==RT_FLINE)
  99. ROMCallFLine->setChecked(TRUE);
  100. else
  101. ROMCallDirect->setChecked(TRUE);
  102. OptimizeROMCalls->setChecked(libopts.opt_rom_calls);
  103. UseInternalFLineEmulator->setChecked(libopts.use_internal_fline_emu);
  104. //Tab: BSS/Data Format
  105. if (libopts.bss_ref_format==RT_KERNEL)
  106. BSSKernel->setChecked(TRUE);
  107. else if (libopts.bss_ref_format==RT_COMPRESSED)
  108. BSSCompressed->setChecked(TRUE);
  109. else if (libopts.bss_ref_format==RT_MLINK)
  110. BSSMlink->setChecked(TRUE);
  111. else
  112. BSSMerge->setChecked(TRUE);
  113. if (libopts.data_ref_format==RT_COMPRESSED)
  114. DataVarCompressed->setChecked(TRUE);
  115. else if (libopts.data_ref_format==RT_MLINK)
  116. DataVarMlink->setChecked(TRUE);
  117. else
  118. DataVarKernel->setChecked(TRUE);
  119. //Tab: Home Screen
  120. if (libopts.use_return_value)
  121. HomeCustomValue->setChecked(TRUE);
  122. else
  123. HomeDone->setChecked(TRUE);
  124. EnableReturningErrors->setChecked(libopts.enable_error_return);
  125. SaveScreen->setChecked(libopts.save_screen);
  126. }
  127. void ProgramOptions::ExportSettings()
  128. {
  129. //Tab: Calculator
  130. libopts.use_ti89=TI89->isChecked();
  131. libopts.use_ti92p=TI92Plus->isChecked();
  132. libopts.use_v200=V200->isChecked();
  133. libopts.opt_calc_consts=OptimizeCalcConsts->isChecked();
  134. //Tab: Operating System
  135. libopts.use_preos=PreOS->isChecked();
  136. libopts.use_kernel=UseKernel->isChecked();
  137. libopts.use_minams=CMinimumAMSVersion->isChecked();
  138. QString minams=MinimumAMSVersion->text();
  139. libopts.minams=minams.section('.',0,0).toUInt()*100+minams.section('.',1,1).toUInt();
  140. libopts.unofficial_os=UnofficialOSSupport->isChecked();
  141. //Tab: Reloc Format
  142. if (RelocKernel->isChecked())
  143. libopts.reloc_format=RT_KERNEL;
  144. else if (RelocCompressed->isChecked())
  145. libopts.reloc_format=RT_COMPRESSED;
  146. else if (RelocMlink->isChecked())
  147. libopts.reloc_format=RT_MLINK;
  148. else
  149. libopts.reloc_format=RT_AMS;
  150. libopts.use_fline_jumps=UseFLineJumps->isChecked();
  151. libopts.use_4b_fline_jumps=Use4ByteFLineJumps->isChecked();
  152. if (ROMCallKernel->isChecked())
  153. libopts.rom_call_format=RT_KERNEL;
  154. else if (ROMCallCompressed->isChecked())
  155. libopts.rom_call_format=RT_COMPRESSED;
  156. else if (ROMCallMlink->isChecked())
  157. libopts.rom_call_format=RT_MLINK;
  158. else if (ROMCallFLine->isChecked())
  159. libopts.rom_call_format=RT_FLINE;
  160. else
  161. libopts.rom_call_format=RT_DIRECT;
  162. libopts.opt_rom_calls=OptimizeROMCalls->isChecked();
  163. libopts.use_internal_fline_emu=UseInternalFLineEmulator->isChecked();
  164. //Tab: BSS/Data Format
  165. if (BSSKernel->isChecked())
  166. libopts.bss_ref_format=RT_KERNEL;
  167. else if (BSSCompressed->isChecked())
  168. libopts.bss_ref_format=RT_COMPRESSED;
  169. else if (BSSMlink->isChecked())
  170. libopts.bss_ref_format=RT_MLINK;
  171. else
  172. libopts.bss_ref_format=RT_NONE;
  173. if (DataVarCompressed->isChecked())
  174. libopts.data_ref_format=RT_COMPRESSED;
  175. else if (DataVarMlink->isChecked())
  176. libopts.data_ref_format=RT_MLINK;
  177. else
  178. libopts.data_ref_format=RT_KERNEL;
  179. //Tab: Home Screen
  180. libopts.use_return_value=HomeCustomValue->isChecked();
  181. libopts.enable_error_return=EnableReturningErrors->isChecked();
  182. libopts.save_screen=SaveScreen->isChecked();
  183. }
  184. void ProgramOptions::CMinimumAMSVersion_toggled(bool on)
  185. {
  186. MinimumAMSVersion->setEnabled(on);
  187. }
  188. void ProgramOptions::CalcCheckbox_toggled(bool on __attribute__((unused)))
  189. {
  190. static bool inEvent=FALSE;
  191. if (!inEvent) {
  192. inEvent=TRUE;
  193. unsigned numCalcs=TI89->isChecked()+TI92Plus->isChecked()+V200->isChecked();
  194. // OPTIMIZE_CALC_CONSTS makes no sense for only 1 calculator (calculator
  195. // constants are already optimized for that calculator at compile-time in
  196. // that case, no need to do it at link time).
  197. // Moreover, we can't enable it for old projects (no calculator checked,
  198. // calculators selected through int _ti89 and such in the code).
  199. OptimizeCalcConsts->setEnabled(numCalcs>=2);
  200. if (numCalcs<2) OptimizeCalcConsts->setChecked(numCalcs);
  201. inEvent=FALSE;
  202. }
  203. }
  204. void ProgramOptions::KernelRadiobutton_toggled(bool on __attribute__((unused)))
  205. {
  206. static bool inEvent=FALSE;
  207. if (!inEvent) {
  208. inEvent=TRUE;
  209. bool nostub=Nostub->isChecked();
  210. bool kernel=UseKernel->isChecked();
  211. bool preos=PreOS->isChecked();
  212. // SAVE_SCREEN is currently always on in kernel mode.
  213. SaveScreen->setEnabled(nostub);
  214. if (!nostub) SaveScreen->setChecked(TRUE);
  215. if (kernel) {
  216. // Kernel mode, enable kernel reloc types.
  217. RelocKernel->setEnabled(TRUE);
  218. ROMCallKernel->setEnabled(TRUE);
  219. BSSKernel->setEnabled(TRUE);
  220. // Default to them if an unsupported reloc type was selected.
  221. if (RelocAMS->isChecked() || RelocCompressed->isChecked()
  222. || RelocMlink->isChecked())
  223. RelocKernel->setChecked(TRUE);
  224. if (ROMCallDirect->isChecked() || ROMCallCompressed->isChecked()
  225. || ROMCallMlink->isChecked())
  226. ROMCallKernel->setChecked(TRUE);
  227. if (BSSCompressed->isChecked() || BSSMlink->isChecked())
  228. BSSKernel->setChecked(TRUE);
  229. // Now disable the unsupported types.
  230. RelocAMS->setEnabled(FALSE);
  231. RelocCompressed->setEnabled(FALSE);
  232. RelocMlink->setEnabled(FALSE);
  233. ROMCallDirect->setEnabled(FALSE);
  234. ROMCallCompressed->setEnabled(FALSE);
  235. ROMCallMlink->setEnabled(FALSE);
  236. BSSCompressed->setEnabled(FALSE);
  237. BSSMlink->setEnabled(FALSE);
  238. } else if (preos) {
  239. // Kernel with compressed reloc tables mode, enable compressed reloc types.
  240. RelocCompressed->setEnabled(TRUE);
  241. ROMCallCompressed->setEnabled(TRUE);
  242. BSSCompressed->setEnabled(TRUE);
  243. // Default to them if an unsupported reloc type was selected.
  244. if (RelocAMS->isChecked() || RelocKernel->isChecked()
  245. || RelocMlink->isChecked())
  246. RelocCompressed->setChecked(TRUE);
  247. if (ROMCallDirect->isChecked() || ROMCallKernel->isChecked()
  248. || ROMCallMlink->isChecked())
  249. ROMCallCompressed->setChecked(TRUE);
  250. if (BSSKernel->isChecked() || BSSMlink->isChecked())
  251. BSSCompressed->setChecked(TRUE);
  252. // Now disable the unsupported types.
  253. RelocAMS->setEnabled(FALSE);
  254. RelocKernel->setEnabled(FALSE);
  255. RelocMlink->setEnabled(FALSE);
  256. ROMCallDirect->setEnabled(FALSE);
  257. ROMCallKernel->setEnabled(FALSE);
  258. ROMCallMlink->setEnabled(FALSE);
  259. BSSKernel->setEnabled(FALSE);
  260. BSSMlink->setEnabled(FALSE);
  261. } else {
  262. // In _nostub mode, all reloc types are allowed.
  263. RelocAMS->setEnabled(TRUE);
  264. RelocKernel->setEnabled(TRUE);
  265. RelocCompressed->setEnabled(TRUE);
  266. RelocMlink->setEnabled(TRUE);
  267. ROMCallDirect->setEnabled(TRUE);
  268. ROMCallKernel->setEnabled(TRUE);
  269. ROMCallCompressed->setEnabled(TRUE);
  270. ROMCallMlink->setEnabled(TRUE);
  271. BSSKernel->setEnabled(TRUE);
  272. BSSCompressed->setEnabled(TRUE);
  273. BSSMlink->setEnabled(TRUE);
  274. }
  275. RelocSettings_toggled(0);
  276. inEvent=FALSE;
  277. }
  278. }
  279. void ProgramOptions::RelocSettings_toggled(bool on __attribute__((unused)))
  280. {
  281. static bool inEvent=FALSE;
  282. if (!inEvent) {
  283. inEvent=TRUE;
  284. // 4-byte F-Line jumps only make sense if F-Line jumps are enabled
  285. if (UseFLineJumps->isChecked())
  286. Use4ByteFLineJumps->setEnabled(TRUE);
  287. else {
  288. Use4ByteFLineJumps->setEnabled(FALSE);
  289. Use4ByteFLineJumps->setChecked(FALSE);
  290. }
  291. if (Use4ByteFLineJumps->isChecked()) {
  292. // 4-byte F-Line jumps require the internal emulator
  293. UseInternalFLineEmulator->setEnabled(FALSE);
  294. UseInternalFLineEmulator->setChecked(TRUE);
  295. } else if (UseFLineJumps->isChecked() || ROMCallFLine->isChecked()) {
  296. // using F-Line instructions where the internal emulator can be used
  297. UseInternalFLineEmulator->setEnabled(TRUE);
  298. } else {
  299. // no F-Line instructions to emulate, internally or otherwise
  300. UseInternalFLineEmulator->setEnabled(FALSE);
  301. UseInternalFLineEmulator->setChecked(FALSE);
  302. }
  303. // OPTIMIZE_ROM_CALLS only allowed with direct or F-Line ROM_CALLs in _nostub mode
  304. if (Nostub->isChecked() && (ROMCallDirect->isChecked() || ROMCallFLine->isChecked()))
  305. OptimizeROMCalls->setEnabled(TRUE);
  306. else {
  307. OptimizeROMCalls->setEnabled(FALSE);
  308. OptimizeROMCalls->setChecked(FALSE);
  309. }
  310. inEvent=FALSE;
  311. }
  312. }
  313. void ProgramOptions::mousePressEvent( QMouseEvent * e )
  314. {
  315. if (e->button()==Qt::RightButton) {
  316. QWidget *widgetUnderCursor=childAt(e->pos());
  317. if (!widgetUnderCursor) return;
  318. QString toolTip=widgetUnderCursor->toolTip();
  319. if (toolTip.isEmpty()) return;
  320. QString docFile=lookup_doc_keyword(toolTip);
  321. if (docFile.isEmpty()) return;
  322. force_qt_assistant_page(1);
  323. // wait for Qt Assistant to actually open
  324. while (!assistant->isOpen())
  325. QCoreApplication::processEvents(QEventLoop::ExcludeUserInput,1000);
  326. assistant->showPage(QString(tigcc_base)+QString("/doc/html/")+docFile);
  327. }
  328. }
  329. void ProgramOptions::languageChange()
  330. {
  331. retranslateUi(this);
  332. }