programoptions.cpp 13 KB

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