projectoptions.ui.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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) 2004-2006 Kevin Kofler
  15. Copyright (C) 2006 Joey Adams
  16. This program is free software; you can redistribute it and/or modify
  17. it under the terms of the GNU General Public License as published by
  18. the Free Software Foundation; either version 2, or (at your option)
  19. any later version.
  20. This program is distributed in the hope that it will be useful,
  21. but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. GNU General Public License for more details.
  24. You should have received a copy of the GNU General Public License
  25. along with this program; if not, write to the Free Software Foundation,
  26. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  27. */
  28. #include <qaccel.h>
  29. #include <kmessagebox.h>
  30. #include <kurl.h>
  31. #include "tpr.h"
  32. #include "programoptions.h"
  33. extern tprSettings settings;
  34. ProgramOptions *programoptions;
  35. //the program options subdialog is created at initialization of a ProjectOptions and remains existant until the ProjectOptions is destroyed.
  36. #define UnwrapLabel(theQLabel) ((theQLabel)->setAlignment((theQLabel)->alignment()&~WordBreak))
  37. //Qt automatically sets RichText labels to have word wrap, which makes labels with underlines in them look bad. This simply undoes the wrapping.
  38. //manually created accelerators
  39. QAccel *AOncalcVariableName_1;
  40. QAccel *AOncalcVariableName_2;
  41. QAccel *AGCCSwitches;
  42. QAccel *AAsSwitches;
  43. QAccel *AA68kSwitches;
  44. QAccel *ACallAfterBuilding;
  45. QAccel *AParameters;
  46. void ProjectOptions::init()
  47. {
  48. //Qt automatically sets QLabels to wrapped when they are RichText. This undoes this change.
  49. UnwrapLabel(LOncalcVariableName_1);
  50. UnwrapLabel(LOncalcVariableName_2);
  51. UnwrapLabel(LGCCSwitches);
  52. UnwrapLabel(LAsSwitches);
  53. UnwrapLabel(LA68kSwitches);
  54. UnwrapLabel(LCallAfterBuilding);
  55. UnwrapLabel(LParameters);
  56. //Toggle controls to match settings.
  57. ImportSettings();
  58. //Create the Program Options dialog and toggle its controls
  59. programoptions=new ProgramOptions(this);
  60. programoptions->ImportSettings();
  61. //Update stuff
  62. CheckOncalcNames();
  63. UpdateVisibilities();
  64. //Create accelerators for text boxes manually
  65. QAccel *accel; //for temporarily holding the accelerator pointer
  66. #define MakeAccelerator(destaccelptr,thewidget,thepage,thekey) destaccelptr=accel=new QAccel(PO_TabWidget->page(thepage)); \
  67. accel->connectItem(accel->insertItem(thekey),thewidget,SLOT(setFocus()));
  68. MakeAccelerator(AOncalcVariableName_1,OncalcVariableName_1,0,ALT+Key_V);
  69. MakeAccelerator(AOncalcVariableName_2,OncalcVariableName_2,0,ALT+Key_I);
  70. MakeAccelerator(AGCCSwitches,GCCSwitches,1,ALT+Key_G);
  71. MakeAccelerator(AAsSwitches,AsSwitches,1,ALT+Key_S);
  72. MakeAccelerator(AA68kSwitches,A68kSwitches,1,ALT+Key_A);
  73. MakeAccelerator(ACallAfterBuilding,CallAfterBuilding,3,ALT+Key_A);
  74. MakeAccelerator(AParameters,Parameters,3,ALT+Key_R);
  75. #undef MakeAccelerator
  76. }
  77. void ProjectOptions::destroy()
  78. {
  79. delete(AOncalcVariableName_1);
  80. delete(AOncalcVariableName_2);
  81. delete(AGCCSwitches);
  82. delete(AAsSwitches);
  83. delete(AA68kSwitches);
  84. delete(ACallAfterBuilding);
  85. delete(AParameters);
  86. delete(programoptions);
  87. if (result()!=QDialog::Accepted)
  88. return;
  89. //Save settings
  90. ExportSettings();
  91. }
  92. void ProjectOptions::ImportSettings(void)
  93. {
  94. Boolean isregular;
  95. //Tab: General
  96. OncalcVariableName_1->setText(settings.data_var);
  97. if (settings.copy_data_var)
  98. {
  99. if (settings.copy_data_var_arc)
  100. CreateCopyIfArchived->toggle();
  101. else
  102. CreateCopyAlways->toggle();
  103. }
  104. OncalcVariableName_2->setText(settings.pack_name);
  105. isregular=TRUE;
  106. if (settings.fargo)
  107. FargoProgram->toggle(),isregular=FALSE;
  108. if (settings.flash_os)
  109. FlashOperatingSystem->toggle(),isregular=FALSE;
  110. if (settings.archive)
  111. FunctionArchive->toggle(),isregular=FALSE;
  112. if (isregular)
  113. {
  114. if (settings.use_data_var)
  115. {
  116. ExternalDataVariable->toggle();
  117. LOncalcVariableName_1->setEnabled(TRUE);
  118. OncalcVariableName_1->setEnabled(TRUE);
  119. LCreateCopyNever->setEnabled(TRUE);
  120. CreateCopyNever->setEnabled(TRUE);
  121. CreateCopyIfArchived->setEnabled(TRUE);
  122. CreateCopyAlways->setEnabled(TRUE);
  123. }
  124. if (settings.pack)
  125. {
  126. CompressProgram->toggle();
  127. LOncalcVariableName_2->setEnabled(TRUE);
  128. OncalcVariableName_2->setEnabled(TRUE);
  129. }
  130. }
  131. else
  132. {
  133. ExternalDataVariable->setEnabled(FALSE);
  134. CompressProgram->setEnabled(FALSE);
  135. }
  136. //Tab: Compilation
  137. GCCSwitches->setText(settings.cc_switches);
  138. AsSwitches->setText(settings.as_switches);
  139. A68kSwitches->setText(settings.a68k_switches);
  140. if (settings.debug_info)
  141. GenerateDebugInformation->toggle();
  142. //Tab: Linking
  143. if (settings.optimize_nops)
  144. NOPs->toggle();
  145. if (settings.optimize_returns)
  146. ReturnSequences->toggle();
  147. if (settings.optimize_branches)
  148. Branches->toggle();
  149. if (settings.optimize_moves)
  150. MoveLoadPushInstructions->toggle();
  151. if (settings.optimize_tests)
  152. TestCompareInstructions->toggle();
  153. if (settings.optimize_calcs)
  154. CalculationInstructions->toggle();
  155. if (settings.remove_unused)
  156. RemoveUnusedSections->toggle();
  157. if (settings.reorder_sections)
  158. ReorderSections->toggle();
  159. if (settings.cut_ranges)
  160. CutUnusedRanges->toggle();
  161. if (settings.merge_constants)
  162. MergeConstants->toggle();
  163. if (settings.std_lib)
  164. LinkAgainstStandardLibrary->toggle();
  165. if (settings.initialize_bss)
  166. InitializeBSSSection->toggle();
  167. if (settings.outputbin)
  168. OutputVariableImageWithoutWrapper->toggle();
  169. //Tab: Post-Build
  170. CallAfterBuilding->setText(settings.post_build);
  171. Parameters->setText(settings.cmd_line);
  172. }
  173. void ProjectOptions::ExportSettings(void)
  174. {
  175. //Tab: General
  176. settings.fargo=FALSE;
  177. settings.flash_os=FALSE;
  178. settings.archive=FALSE;
  179. settings.use_data_var=FALSE;
  180. settings.pack=FALSE;
  181. if (FargoProgram->isOn())
  182. settings.fargo=TRUE;
  183. else if (FlashOperatingSystem->isOn())
  184. settings.flash_os=TRUE;
  185. else if (FunctionArchive->isOn())
  186. settings.archive=TRUE;
  187. else if (RegularProgram->isOn()) //the original TIGCC IDE automatically unchecked External data variable and Compress program when you toggled away from Regular Program, so we will only consider these two if Regular Program is toggled
  188. {
  189. if (ExternalDataVariable->isOn())
  190. settings.use_data_var=TRUE;
  191. if (CompressProgram->isOn())
  192. settings.pack=TRUE;
  193. }
  194. //Subselections for External data variable and Compress program are always preserved.
  195. settings.data_var=OncalcVariableName_1->text();
  196. settings.copy_data_var_arc=FALSE;
  197. if (CreateCopyNever->isOn())
  198. settings.copy_data_var=FALSE;
  199. else
  200. {
  201. settings.copy_data_var=TRUE;
  202. if (CreateCopyIfArchived->isOn())
  203. settings.copy_data_var_arc=TRUE;
  204. }
  205. settings.pack_name=OncalcVariableName_2->text();
  206. //Tab: Compilation
  207. }
  208. void ProjectOptions::RegularProgramToggle()
  209. {
  210. int state;
  211. buttonOk->setAccel(0);
  212. buttonOk->setText("OK");
  213. state=RegularProgram->isOn()?TRUE:FALSE;
  214. if (!state)
  215. {
  216. if (ExternalDataVariable->isOn())
  217. ExternalDataVariable->toggle();
  218. if (CompressProgram->isOn())
  219. CompressProgram->toggle();
  220. }
  221. ExternalDataVariable->setEnabled(state);
  222. CompressProgram->setEnabled(state);
  223. ExternalDataVariableToggle();
  224. CompressProgramToggle();
  225. }
  226. void ProjectOptions::ExternalDataVariableToggle()
  227. {
  228. int state;
  229. state=ExternalDataVariable->isOn()?TRUE:FALSE;
  230. LOncalcVariableName_1->setEnabled(state);
  231. OncalcVariableName_1->setEnabled(state);
  232. LCreateCopyNever->setEnabled(state);
  233. CreateCopyNever->setEnabled(state);
  234. CreateCopyIfArchived->setEnabled(state);
  235. CreateCopyAlways->setEnabled(state);
  236. CheckOncalcNames();
  237. }
  238. void ProjectOptions::CompressProgramToggle()
  239. {
  240. int state;
  241. state=CompressProgram->isOn()?TRUE:FALSE;
  242. LOncalcVariableName_2->setEnabled(state);
  243. OncalcVariableName_2->setEnabled(state);
  244. CheckOncalcNames();
  245. }
  246. void ProjectOptions::CheckOncalcNames()
  247. {
  248. const QString &edvname=OncalcVariableName_1->text();
  249. const QString &compname=OncalcVariableName_2->text();
  250. Boolean edvon=OncalcVariableName_1->isEnabled();
  251. Boolean compon=OncalcVariableName_2->isEnabled();
  252. if ((edvon&&edvname.isEmpty()) || (compon&&compname.isEmpty()) || (edvon&&compon&&!edvname.compare(compname)))
  253. buttonOk->setEnabled(FALSE);
  254. else
  255. buttonOk->setEnabled(TRUE);
  256. }
  257. void ProjectOptions::UpdateVisibilities()
  258. {
  259. Boolean regularprogram=RegularProgram->isOn();
  260. Boolean functionarchive=FunctionArchive->isOn();
  261. if (regularprogram)
  262. ProgramOptionsButton->show();
  263. else
  264. ProgramOptionsButton->hide();
  265. PO_TabWidget->setTabEnabled(PO_TabWidget->page(2),!functionarchive);
  266. PO_TabWidget->setTabEnabled(PO_TabWidget->page(3),!functionarchive);
  267. }
  268. void ProjectOptions::ProgramOptionsFunc()
  269. {
  270. programoptions->exec();
  271. }