PageRenderTime 56ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 1ms

/qalculate-kde-0.9.7/src/kqalculate.cpp

#
C++ | 6676 lines | 6122 code | 512 blank | 42 comment | 1344 complexity | 17355f2590d00cf9a7d9cb719f846222 MD5 | raw file
Possible License(s): GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. /***************************************************************************
  2. * Copyright (C) 2005-2007 by Niklas Knutsson *
  3. * nq@altern.org *
  4. * *
  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 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, write to the *
  17. * Free Software Foundation, Inc., *
  18. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  19. ***************************************************************************/
  20. #ifdef HAVE_CONFIG_H
  21. # include <config.h>
  22. #endif
  23. #include <kdialog.h>
  24. #include <klocale.h>
  25. #include "kqalculate.h"
  26. #include "qalculateinsertfunctiondialog.h"
  27. #include "qalculate_kde_utils.h"
  28. #include "preferences.h"
  29. #include "qalculatepreferencesdialog.h"
  30. #include "qalculateimportcsvdialog.h"
  31. #include "qalculateexportcsvdialog.h"
  32. #include "qalculateexpressionedit.h"
  33. #include "qalculateprecisiondialog.h"
  34. #include "qalculatedecimalsdialog.h"
  35. #include "qalculateeditvariabledialog.h"
  36. #include "qalculateeditmatrixvectordialog.h"
  37. #include "qalculateeditunitdialog.h"
  38. #include "qalculateeditfunctiondialog.h"
  39. #include "qalculateeditdatasetdialog.h"
  40. #include "qalculateeditunknownvariabledialog.h"
  41. #include "qalculatevariablesdialog.h"
  42. #include "qalculatefunctionsdialog.h"
  43. #include "qalculateunitsdialog.h"
  44. #include "qalculatedatasetsdialog.h"
  45. #include "qalculateconvertunitsdialog.h"
  46. #include "qalculateconvertnumberbasesdialog.h"
  47. #include "qalculateperiodictabledialog.h"
  48. #include "qalculateplotdialog.h"
  49. #include "qalculatesetbasedialog.h"
  50. #include "qalculateinsertmatrixvectordialog.h"
  51. #include <kwin.h>
  52. #include <kglobalsettings.h>
  53. #include <kuniqueapplication.h>
  54. #include <kstringhandler.h>
  55. #include <qtable.h>
  56. #include <kseparator.h>
  57. #include <kiconloader.h>
  58. #include <qframe.h>
  59. #include <qvariant.h>
  60. #include <qtooltip.h>
  61. #include <qwhatsthis.h>
  62. #include <qclipboard.h>
  63. #include <qstylesheet.h>
  64. #include <kcompletion.h>
  65. #include <klineedit.h>
  66. #include <qlabel.h>
  67. #include <kmessagebox.h>
  68. #include <qpixmap.h>
  69. #include <qpicture.h>
  70. #include <qpainter.h>
  71. #include <qfontmetrics.h>
  72. #include <sys/stat.h>
  73. #include <unistd.h>
  74. #include <time.h>
  75. #include <math.h>
  76. #include <dirent.h>
  77. #include <pthread.h>
  78. #include <qsimplerichtext.h>
  79. #include <qstatusbar.h>
  80. #include <qwidgetstack.h>
  81. #include <ktextbrowser.h>
  82. #include <kpushbutton.h>
  83. #include "qalculateresultdisplay.h"
  84. #include <qbitmap.h>
  85. #include <qscrollview.h>
  86. #include <qobject.h>
  87. #include <kapplication.h>
  88. #include <kaction.h>
  89. #include <qspinbox.h>
  90. #include <kprogress.h>
  91. #include <kpopupmenu.h>
  92. #include <kmenubar.h>
  93. #include <qlayout.h>
  94. #include <qtimer.h>
  95. #include <kcompletionbox.h>
  96. #include <qstringlist.h>
  97. #include <qcombobox.h>
  98. #include <ksystemtray.h>
  99. #if KDE_VERSION_MAJOR > 3 || KDE_VERSION_MINOR > 1
  100. #include <kactionclasses.h>
  101. #endif
  102. #if KDE_VERSION_MAJOR > 3 || KDE_VERSION_MINOR >= 4
  103. #include <kaccelmanager.h>
  104. #endif
  105. #include <qbuttongroup.h>
  106. #include <qvbuttongroup.h>
  107. #include <qradiobutton.h>
  108. #include <qgrid.h>
  109. #include <kfiledialog.h>
  110. #include <qimage.h>
  111. #include <kaccel.h>
  112. #include <kio/netaccess.h>
  113. #if KDE_VERSION_MAJOR > 3 || KDE_VERSION_MINOR >= 2
  114. #include <kinputdialog.h>
  115. #endif
  116. #include <kdeversion.h>
  117. #include <qstyle.h>
  118. #include <kglobalaccel.h>
  119. #include <kkeydialog.h>
  120. #include <kkeybutton.h>
  121. #include <kcombobox.h>
  122. MathStructure *mstruct, *matrix_mstruct, *parsed_mstruct, *parsed_tostruct;
  123. QString result_text, result_history_text, parsed_text;
  124. QWidget *expressionWidget, *resultWidget, *statusWidget_l;
  125. QWidget *topWidget;
  126. KQalculate *mainWin = 0;
  127. bool prev_result_approx;
  128. extern bool close_to_systray;
  129. extern bool display_expression_status;
  130. extern QColor status_error_color;
  131. extern QColor status_warning_color;
  132. extern int use_icon_buttons;
  133. extern bool enable_expression_completion;
  134. extern QString initial_history;
  135. extern tree_struct function_cats, unit_cats, variable_cats;
  136. extern vector<void*> ia_units, ia_variables, ia_functions;
  137. extern vector<MathFunction*> recent_functions;
  138. extern vector<Variable*> recent_variables;
  139. extern vector<Unit*> recent_units;
  140. vector<MathStructure> result_parts;
  141. KnownVariable *vans[5];
  142. int vans_id_start[5];
  143. int vans_id_end[5];
  144. extern PrintOptions printops;
  145. extern EvaluationOptions evalops;
  146. extern bool rpn_mode, rpn_keypad_only;
  147. extern bool save_mode_on_exit, save_defs_on_exit;
  148. extern bool canplot;
  149. extern bool use_custom_result_font, use_custom_expression_font, use_custom_status_font;
  150. extern QString custom_result_font, custom_expression_font, custom_status_font;
  151. extern QTimer *error_timer;
  152. extern QStringList expression_history;
  153. bool expression_has_changed, expression_has_changed2, had_errors_before, had_warnings_before, block_result_update;
  154. FILE *view_pipe_r, *view_pipe_w, *command_pipe_r, *command_pipe_w;
  155. pthread_t view_thread, command_thread;
  156. pthread_attr_t view_thread_attr, command_thread_attr;
  157. bool b_busy, command_thread_started;
  158. int saved_divisionline_height = 0;
  159. uint initial_result_index = 0;
  160. extern bool show_keypad, show_history, show_stack;
  161. extern vector<mode_struct> modes;
  162. extern QValueVector<QString> inhistory;
  163. extern QValueVector<int> inhistory_type;
  164. extern QValueVector<int> inhistory_id;
  165. extern int inhistory_current_id;
  166. int initial_inhistory_index = 0;
  167. const MathStructure *KQalculate::getResultPart(int i) {
  168. if(i < 1 || (size_t) i > result_parts.size()) return NULL;
  169. return &result_parts[(size_t) i - 1];
  170. }
  171. #if KDE_VERSION_MAJOR < 4 && KDE_VERSION_MINOR < 2
  172. #include <kiconloader.h>
  173. #include <kconfig.h>
  174. QPixmap loadSystrayIcon(const QString &icon) {
  175. KConfig *appCfg = kapp->config();
  176. KConfigGroupSaver configSaver(appCfg, "System Tray");
  177. int iconWidth = appCfg->readNumEntry("systrayIconWidth", 22);
  178. return KGlobal::instance()->iconLoader()->loadIcon(icon, KIcon::Panel, iconWidth);
  179. }
  180. #endif
  181. #if KDE_VERSION_MAJOR > 3 || KDE_VERSION_MINOR >= 3
  182. #define ICON_SIZE_SMALL_MEDIUM KIcon::SizeSmallMedium
  183. #else
  184. #define ICON_SIZE_SMALL_MEDIUM 22
  185. #endif
  186. ModeObject::ModeObject(int mode) : i_mode(mode) {}
  187. void ModeObject::loadMode() {
  188. mainWin->loadMode(i_mode);
  189. }
  190. KQalculate::KQalculate(KUniqueApplication *parent, const char* name, WFlags fl) : KMainWindow(0, name, fl) {
  191. if(!name) setName("kqalculate");
  192. m_parent = parent;
  193. vans_id_start[0] = -1;
  194. vans_id_end[0] = -1;
  195. vans_id_start[1] = -1;
  196. vans_id_end[1] = -1;
  197. vans_id_start[2] = -1;
  198. vans_id_end[2] = -1;
  199. vans_id_start[3] = -1;
  200. vans_id_end[3] = -1;
  201. vans_id_start[4] = -1;
  202. vans_id_end[4] = -1;
  203. QStyleSheet::setDefaultSheet(new QalculateStyleSheet());
  204. insert_matrix_dialog = NULL;
  205. preferences_dialog = NULL;
  206. precisionDialog = NULL;
  207. decimalsDialog = NULL;
  208. variable_edit_dialog = NULL;
  209. store_dialog = NULL;
  210. matrix_edit_dialog = NULL;
  211. import_csv_dialog = NULL;
  212. export_csv_dialog = NULL;
  213. unit_edit_dialog = NULL;
  214. function_edit_dialog = NULL;
  215. dataset_edit_dialog = NULL;
  216. unknown_edit_dialog = NULL;
  217. variables_dialog = NULL;
  218. functions_dialog = NULL;
  219. units_dialog = NULL;
  220. datasets_dialog = NULL;
  221. convert_to_unit_expression_dialog = NULL;
  222. convert_number_bases_dialog = NULL;
  223. periodic_table_dialog = NULL;
  224. plot_dialog = NULL;
  225. set_base_dialog = NULL;
  226. prev_result_approx = false;
  227. expression_has_changed = false;
  228. expression_has_changed2 = false;
  229. had_errors_before = false;
  230. had_warnings_before = false;
  231. block_result_update = false;
  232. history_height = 0;
  233. trayicon = NULL;
  234. ActionHideSystemTrayIcon = new KAction(i18n("Remove from System Tray"), "hidesystemtrayicon", 0, this, SLOT(hideSystemTrayIcon()), actionCollection(), "hide_system_tray_icon");
  235. ActionHide = new KAction(i18n("Hide"), "hide", 0, this, SLOT(hide()), actionCollection(), "hide");
  236. showSystemTrayIcon(close_to_systray);
  237. setCentralWidget(new QWidget(this));
  238. QVBoxLayout *mainLayout = new QVBoxLayout(centralWidget(), 11, 6);
  239. mainLayout->setResizeMode(QLayout::Minimum);
  240. QHBoxLayout *topLayout = new QHBoxLayout(0, 0, 6);
  241. bool use_button_pixmaps = false;
  242. if(use_icon_buttons > 0) {
  243. use_button_pixmaps = true;
  244. } else if(use_icon_buttons < 0) {
  245. KConfig config("kdeglobals", true, false);
  246. config.setGroup("KDE");
  247. use_button_pixmaps = config.readBoolEntry("ShowIconsOnPushButtons", false);
  248. }
  249. if(use_button_pixmaps) leftButtonsLayout = new QVBoxLayout(0, 0, 3);
  250. else leftButtonsLayout = new QVBoxLayout(0, 0, 6);
  251. if(use_button_pixmaps) executeButton = new QalculateButton(KApplication::kApplication()->iconLoader()->loadIconSet("exec", KIcon::Small, ICON_SIZE_SMALL_MEDIUM), "", centralWidget());
  252. else if(rpn_mode) executeButton = new QalculateButton(i18n("Enter"), centralWidget());
  253. else executeButton = new QalculateButton(i18n("="), centralWidget());
  254. executeButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed, false);
  255. if(rpn_mode) QToolTip::add(executeButton, i18n("Calculate expression and add to stack"));
  256. else QToolTip::add(executeButton, i18n("Calculate expression"));
  257. leftButtonsLayout->addWidget(executeButton);
  258. leftButtonsSeparator = new KSeparator(Qt::Horizontal, centralWidget());
  259. leftButtonsLayout->addWidget(leftButtonsSeparator);
  260. if(use_button_pixmaps) leftButtonsSeparator->hide();
  261. if(use_button_pixmaps) storeButton = new QalculateButton(KApplication::kApplication()->iconLoader()->loadIconSet("filesaveas", KIcon::Small, ICON_SIZE_SMALL_MEDIUM), "", centralWidget());
  262. else storeButton = new QalculateButton(i18n("Store"), centralWidget());
  263. storeButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed, false);
  264. QToolTip::add(storeButton, i18n("Store result as variable"));
  265. leftButtonsLayout->addWidget(storeButton);
  266. if(use_button_pixmaps) convertButton = new QalculateButton(KApplication::kApplication()->iconLoader()->loadIconSet("qalculate_convert", KIcon::Small, ICON_SIZE_SMALL_MEDIUM), "", centralWidget());
  267. else convertButton = new QalculateButton(i18n("Convert"), centralWidget());
  268. convertButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed, false);
  269. QToolTip::add(convertButton, i18n("Convert units in result"));
  270. leftButtonsLayout->addWidget(convertButton);
  271. leftButtonsLayout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::Minimum));
  272. QVBoxLayout *expressionLayout = new QVBoxLayout(0, 0, 0);
  273. expressionEdit = new QalculateExpressionEdit(true, centralWidget());
  274. expressionLayout->addWidget(expressionEdit);
  275. expressionEdit->setFocus();
  276. expressionEdit->expression_history = expression_history;
  277. if(!enable_expression_completion) expressionEdit->disableCompletion();
  278. QToolTip::add(expressionEdit, i18n("Enter expression here"));
  279. QHBoxLayout *statusLayout = new QHBoxLayout(0, 0, 6);
  280. statusLabel_l = new QalculateParseLabel(centralWidget());
  281. statusLabel_l->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum, false);
  282. statusLabel_l->setLineWidth(0);
  283. statusLabel_l->setMargin(0);
  284. statusLabel_l->setAlignment(int(QLabel::AlignTop | QLabel::AlignLeft));
  285. if(!display_expression_status) statusLabel_l->hide();
  286. statusLayout->addWidget(statusLabel_l);
  287. statusLabel_r = new QLabel(i18n("status"), centralWidget());
  288. statusLabel_r->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum, false);
  289. statusLabel_r->setLineWidth(0);
  290. statusLabel_r->setMargin(0);
  291. statusLabel_r->setTextFormat(Qt::RichText);
  292. statusLabel_r->setAlignment(int(QLabel::AlignTop | QLabel::AlignRight));
  293. statusLayout->addWidget(statusLabel_r);
  294. expressionLayout->addLayout(statusLayout);
  295. resultLabel = new QalculateResultDisplay(centralWidget());
  296. resultLabel->setRightMargin(10);
  297. expressionLayout->addWidget(resultLabel);
  298. topLayout->addLayout(expressionLayout);
  299. topLayout->addLayout(leftButtonsLayout);
  300. mainLayout->addLayout(topLayout);
  301. resultLabel->setWordWrap(QTextEdit::WidgetWidth);
  302. resultLabel->setMargin(0);
  303. bottomLine = new KSeparator(Qt::Horizontal, centralWidget());
  304. mainLayout->addWidget(bottomLine);
  305. mainStack = new QWidgetStack(centralWidget());
  306. mainStack->setEnabled(true);
  307. mainStack->setSizePolicy(QSizePolicy((QSizePolicy::SizeType) 5, (QSizePolicy::SizeType) 7, 0, 0, mainStack->sizePolicy().hasHeightForWidth()));
  308. keypadPage = new QWidget(mainStack);
  309. QVBoxLayout *keypadPageLayout = new QVBoxLayout(keypadPage, 0, 12);
  310. keypadPageLayout->addWidget(new KSeparator(Qt::Horizontal, keypadPage));
  311. QHBoxLayout *keypadTopLayout = new QHBoxLayout(0, 0, 6);
  312. kpExact = new QalculateButton(i18n("Exact"), keypadPage);
  313. QToolTip::add(kpExact, i18n("Toggle exact mode"));
  314. kpExact->setToggleButton(true);
  315. keypadTopLayout->addWidget(kpExact);
  316. kpFraction = new QalculateButton(i18n("Fraction"), keypadPage);
  317. QToolTip::add(kpFraction, i18n("Toggle fractional display"));
  318. kpFraction->setToggleButton(true);
  319. keypadTopLayout->addWidget(kpFraction);
  320. kpNumericCombo = new QComboBox(true, keypadPage);
  321. QToolTip::add(kpNumericCombo, i18n("Numerical display"));
  322. kpNumericCombo->setEditable(false);
  323. keypadTopLayout->addWidget(kpNumericCombo);
  324. kpNumericCombo->insertItem(i18n("Normal"));
  325. kpNumericCombo->insertItem(i18n("Engineering"));
  326. kpNumericCombo->insertItem(i18n("Scientific"));
  327. kpNumericCombo->insertItem(i18n("Pure"));
  328. kpNumericCombo->insertItem(i18n("Simple"));
  329. kpBaseCombo = new QComboBox(true, keypadPage);
  330. QToolTip::add(kpBaseCombo, i18n("Base in result"));
  331. kpBaseCombo->setEditable(false);
  332. keypadTopLayout->addWidget(kpBaseCombo);
  333. keypadPageLayout->addLayout(keypadTopLayout);
  334. kpBaseCombo->insertItem(i18n("Binary"));
  335. kpBaseCombo->insertItem(i18n("Octal"));
  336. kpBaseCombo->insertItem(i18n("Decimal"));
  337. kpBaseCombo->insertItem(i18n("Hexadecimal"));
  338. kpBaseCombo->insertItem(i18n("Sexagesimal"));
  339. kpBaseCombo->insertItem(i18n("Time Format"));
  340. kpBaseCombo->insertItem(i18n("Roman"));
  341. kpBaseCombo->insertItem(i18n("Other..."));
  342. QHBoxLayout *keypadBottomLayout = new QHBoxLayout(0, 0, 24);
  343. QGridLayout *keypadFunctionsLayout = new QGridLayout(0, 5, 3, 0, 6);
  344. functionsButton = new QalculateButton(i18n("f(x)"), keypadPage);
  345. QFont fb_font(functionsButton->font());
  346. fb_font.setItalic(true);
  347. functionsButton->setFont(fb_font);
  348. QToolTip::add(functionsButton, i18n("Open functions manager"));
  349. keypadFunctionsLayout->addWidget(functionsButton, 0, 0);
  350. kpSqrt = new QalculateButton(i18n("sqrt"), keypadPage);
  351. QToolTip::add(kpSqrt, i18n("Square root"));
  352. keypadFunctionsLayout->addWidget(kpSqrt, 1, 0);
  353. kpRaise = new QalculateButton(keypadPage);
  354. kpRaise->setMarkup(i18n("x<sup>y</sup>"));
  355. QToolTip::add(kpRaise, i18n("Raise (Ctrl+*)"));
  356. keypadFunctionsLayout->addWidget(kpRaise, 0, 1);
  357. kpSquare = new QalculateButton(keypadPage);
  358. kpSquare->setMarkup(i18n("x<sup>2</sup>"));
  359. QToolTip::add(kpSquare, i18n("Square"));
  360. keypadFunctionsLayout->addWidget(kpSquare, 0, 2);
  361. kpLog = new QalculateButton(i18n("log"), keypadPage);
  362. QToolTip::add(kpLog, i18n("Base-10 logarithm"));
  363. keypadFunctionsLayout->addWidget(kpLog, 1, 1);
  364. kpLn = new QalculateButton(i18n("ln"), keypadPage);
  365. QToolTip::add(kpLn, i18n("Natural logarithm"));
  366. keypadFunctionsLayout->addWidget(kpLn, 1, 2);
  367. kpFactorial = new QalculateButton(i18n("x!"), keypadPage);
  368. QToolTip::add(kpFactorial, i18n("Factorial"));
  369. keypadFunctionsLayout->addWidget(kpFactorial, 2, 0);
  370. kpCos = new QalculateButton(i18n("cos"), keypadPage);
  371. QToolTip::add(kpCos, i18n("Cosine"));
  372. keypadFunctionsLayout->addWidget(kpCos, 2, 1);
  373. kpTan = new QalculateButton(i18n("tan"), keypadPage);
  374. QToolTip::add(kpTan, i18n("Tangent"));
  375. keypadFunctionsLayout->addWidget(kpTan, 2, 2);
  376. kpHyp = new QalculateButton(i18n("hyp"), keypadPage);
  377. QToolTip::add(kpHyp, i18n("Toggle hyperbolic functions"));
  378. kpHyp->setToggleButton(true);
  379. keypadFunctionsLayout->addWidget(kpHyp, 3, 0);
  380. kpInv = new QalculateButton(i18n("inv"), keypadPage);
  381. QToolTip::add(kpInv, i18n("Toggle inverse functions"));
  382. kpInv->setToggleButton(true);
  383. keypadFunctionsLayout->addWidget(kpInv, 3, 1);
  384. kpSin = new QalculateButton(i18n("sin"), keypadPage);
  385. QToolTip::add(kpSin, i18n("Sine"));
  386. keypadFunctionsLayout->addWidget(kpSin, 3, 2);
  387. QHBoxLayout *keypadAngleLayout = new QHBoxLayout(0, 0, 6);
  388. kpAngleGroup = new QButtonGroup();
  389. kpAngleGroup->setExclusive(true);
  390. kpDegreesButton = new QRadioButton(i18n("Deg"), keypadPage);
  391. QToolTip::add(kpDegreesButton, i18n("Angle Unit: Degrees"));
  392. kpAngleGroup->insert(kpDegreesButton, 0);
  393. keypadAngleLayout->addWidget(kpDegreesButton);
  394. kpRadiansButton = new QRadioButton(i18n("Rad"), keypadPage);
  395. QToolTip::add(kpRadiansButton, i18n("Angle Unit: Radians"));
  396. kpAngleGroup->insert(kpRadiansButton, 1);
  397. keypadAngleLayout->addWidget(kpRadiansButton);
  398. kpGradiansButton = new QRadioButton(i18n("Gra"), keypadPage);
  399. QToolTip::add(kpGradiansButton, i18n("Angle Unit: Gradians"));
  400. kpAngleGroup->insert(kpGradiansButton, 2);
  401. keypadAngleLayout->addWidget(kpGradiansButton);
  402. kpNoAngleUnitButton = new QRadioButton(i18n("None"), keypadPage);
  403. kpAngleGroup->insert(kpNoAngleUnitButton, 3);
  404. keypadAngleLayout->addWidget(kpNoAngleUnitButton);
  405. kpNoAngleUnitButton->hide();
  406. keypadAngleLayout->addItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
  407. keypadFunctionsLayout->addMultiCellLayout(keypadAngleLayout, 4, 4, 0, 2);
  408. #if KDE_VERSION_MAJOR > 3 || KDE_VERSION_MINOR >= 4
  409. KAcceleratorManager::setNoAccel(kpDegreesButton);
  410. KAcceleratorManager::setNoAccel(kpRadiansButton);
  411. KAcceleratorManager::setNoAccel(kpGradiansButton);
  412. KAcceleratorManager::setNoAccel(kpNoAngleUnitButton);
  413. #endif
  414. keypadBottomLayout->addLayout(keypadFunctionsLayout);
  415. QGridLayout *keypadBasicsLayout = new QGridLayout(0, 1, 1, 0, 6);
  416. kp7 = new QalculateButton(i18n("7"), keypadPage);
  417. keypadBasicsLayout->addWidget(kp7, 0, 0);
  418. kp8 = new QalculateButton(i18n("8"), keypadPage);
  419. keypadBasicsLayout->addWidget(kp8, 0, 1);
  420. kp9 = new QalculateButton(i18n("9"), keypadPage);
  421. keypadBasicsLayout->addWidget(kp9, 0, 2);
  422. kp4 = new QalculateButton(i18n("4"), keypadPage);
  423. keypadBasicsLayout->addWidget(kp4, 1, 0);
  424. kp5 = new QalculateButton(i18n("5"), keypadPage);
  425. keypadBasicsLayout->addWidget(kp5, 1, 1);
  426. kp6 = new QalculateButton(i18n("6"), keypadPage);
  427. keypadBasicsLayout->addWidget(kp6, 1, 2);
  428. kp1 = new QalculateButton(i18n("1"), keypadPage);
  429. keypadBasicsLayout->addWidget(kp1, 2, 0);
  430. kp2 = new QalculateButton(i18n("2"), keypadPage);
  431. keypadBasicsLayout->addWidget(kp2, 2, 1);
  432. kp3 = new QalculateButton(i18n("3"), keypadPage);
  433. keypadBasicsLayout->addWidget(kp3, 2, 2);
  434. kp0 = new QalculateButton(i18n("0"), keypadPage);
  435. keypadBasicsLayout->addWidget(kp0, 3, 0);
  436. kpDot = new QalculateButton(".", keypadPage);
  437. QToolTip::add(kpDot, i18n("Decimal point"));
  438. keypadBasicsLayout->addWidget(kpDot, 3, 1);
  439. kpExp = new QalculateButton(i18n("EXP"), keypadPage);
  440. QToolTip::add(kpExp, i18n("10^x (Ctrl+Shift+E)"));
  441. keypadBasicsLayout->addWidget(kpExp, 3, 2);
  442. kpDel = new QalculateButton(i18n("Del"), keypadPage);
  443. QToolTip::add(kpDel, i18n("Delete"));
  444. keypadBasicsLayout->addWidget(kpDel, 0, 3);
  445. kpClear = new QalculateButton(i18n("AC"), keypadPage);
  446. QToolTip::add(kpClear, i18n("Clear"));
  447. keypadBasicsLayout->addWidget(kpClear, 0, 4);
  448. kpTimes = new QalculateButton("*", keypadPage);
  449. QToolTip::add(kpTimes, i18n("Multiply"));
  450. keypadBasicsLayout->addWidget(kpTimes, 1, 3);
  451. kpDivision = new QalculateButton("/", keypadPage);
  452. QToolTip::add(kpDivision, i18n("Divide"));
  453. keypadBasicsLayout->addWidget(kpDivision, 1, 4);
  454. kpPlus = new QalculateButton("+", keypadPage);
  455. QToolTip::add(kpPlus, i18n("Add"));
  456. keypadBasicsLayout->addWidget(kpPlus, 2, 3);
  457. kpMinus = new QalculateButton("-", keypadPage);
  458. QToolTip::add(kpMinus, i18n("Subtract"));
  459. keypadBasicsLayout->addWidget(kpMinus, 2, 4);
  460. kpAns = new QalculateButton(i18n("Ans"), keypadPage);
  461. QToolTip::add(kpAns, i18n("Previous result"));
  462. keypadBasicsLayout->addWidget(kpAns, 3, 3);
  463. if(rpn_mode) kpEquals = new QalculateButton(i18n("Ent"), keypadPage);
  464. else kpEquals = new QalculateButton(i18n("="), keypadPage);
  465. if(rpn_mode) QToolTip::add(kpEquals, i18n("Calculate expression and add to stack"));
  466. else QToolTip::add(kpEquals, i18n("Calculate expression"));
  467. keypadBasicsLayout->addWidget(kpEquals, 3, 4);
  468. keypadBottomLayout->addLayout(keypadBasicsLayout);
  469. keypadPageLayout->addLayout(keypadBottomLayout);
  470. keypadPageLayout->addWidget(new KSeparator(Qt::Horizontal, keypadPage));
  471. mainStack->addWidget(keypadPage, 0);
  472. historyPage = new QWidget(mainStack, "historyPage");
  473. QVBoxLayout *historyPageLayout = new QVBoxLayout(historyPage, 0, 0);
  474. historyBrowser = new QalculateHistoryBrowser(historyPage, "historyBrowser");
  475. historyBrowser->setTextFormat(KTextBrowser::RichText);
  476. historyBrowser->setWordWrap(KTextBrowser::NoWrap);
  477. historyPageLayout->addWidget(historyBrowser);
  478. mainStack->addWidget(historyPage, 1);
  479. stackPage = new QWidget(mainStack, "stackPage");
  480. QHBoxLayout *stackPageLayout = new QHBoxLayout(stackPage, 0, 6);
  481. stackList = new QalculateRPNStackListView(stackPage, "stackList");
  482. stackList->addColumn(i18n("Index"));
  483. stackList->addColumn(i18n("Value"));
  484. stackList->setColumnAlignment(0, Qt::AlignCenter);
  485. stackList->setColumnAlignment(1, Qt::AlignRight);
  486. stackList->setFullWidth(true);
  487. stackList->setResizeMode(QListView::LastColumn);
  488. stackList->setSelectionMode(QListView::Single);
  489. stackList->setAllColumnsShowFocus(true);
  490. stackList->setRootIsDecorated(false);
  491. stackList->setItemsMovable(true);
  492. stackList->setDragEnabled(true);
  493. stackList->setAcceptDrops(true);
  494. stackList->setSorting(-1);
  495. stackList->setItemsRenameable(true);
  496. stackList->setRenameable(1, true);
  497. stackList->setRenameable(0, false);
  498. stackPageLayout->addWidget(stackList);
  499. if(use_button_pixmaps) stackPageButtonsLayout = new QVBoxLayout(stackPageLayout, 3);
  500. else stackPageButtonsLayout = new QVBoxLayout(stackPageLayout, 6);
  501. if(use_button_pixmaps) registerUpButton = new QalculateButton(KApplication::kApplication()->iconLoader()->loadIconSet("up", KIcon::Small, ICON_SIZE_SMALL_MEDIUM), "", stackPage);
  502. else registerUpButton = new QalculateButton(i18n("Up"), stackPage);
  503. QToolTip::add(registerUpButton, i18n("Move selected register up"));
  504. registerUpButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed, false);
  505. stackPageButtonsLayout->addWidget(registerUpButton);
  506. if(use_button_pixmaps) registerDownButton = new QalculateButton(KApplication::kApplication()->iconLoader()->loadIconSet("down", KIcon::Small, ICON_SIZE_SMALL_MEDIUM), "", stackPage);
  507. else registerDownButton = new QalculateButton(i18n("Down"), stackPage);
  508. QToolTip::add(registerDownButton, i18n("Move selected register down"));
  509. registerDownButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed, false);
  510. stackPageButtonsLayout->addWidget(registerDownButton);
  511. if(use_button_pixmaps) editRegisterButton = new QalculateButton(KApplication::kApplication()->iconLoader()->loadIconSet("edit", KIcon::Small, ICON_SIZE_SMALL_MEDIUM), "", stackPage);
  512. else editRegisterButton = new QalculateButton(i18n("Edit"), stackPage);
  513. QToolTip::add(editRegisterButton, i18n("Edit value of selected register"));
  514. editRegisterButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed, false);
  515. stackPageButtonsLayout->addWidget(editRegisterButton);
  516. if(use_button_pixmaps) deleteRegisterButton = new QalculateButton(KApplication::kApplication()->iconLoader()->loadIconSet("editdelete", KIcon::Small, ICON_SIZE_SMALL_MEDIUM), "", stackPage);
  517. else deleteRegisterButton = new QalculateButton(i18n("Delete"), stackPage);
  518. QToolTip::add(deleteRegisterButton, i18n("Delete selected register"));
  519. deleteRegisterButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed, false);
  520. stackPageButtonsLayout->addWidget(deleteRegisterButton);
  521. if(use_button_pixmaps) clearStackButton = new QalculateButton(KApplication::kApplication()->iconLoader()->loadIconSet("view_remove", KIcon::Small, ICON_SIZE_SMALL_MEDIUM), "", stackPage);
  522. else clearStackButton = new QalculateButton(i18n("Clear"), stackPage);
  523. QToolTip::add(clearStackButton, i18n("Clear the RPN stack"));
  524. clearStackButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed, false);
  525. registerUpButton->setEnabled(false);
  526. registerDownButton->setEnabled(false);
  527. editRegisterButton->setEnabled(false);
  528. deleteRegisterButton->setEnabled(false);
  529. clearStackButton->setEnabled(false);
  530. stackPageButtonsLayout->addWidget(clearStackButton);
  531. stackPageButtonsLayout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding));
  532. mainStack->addWidget(stackPage, 2);
  533. updateButtonWidths();
  534. mainLayout->addWidget(mainStack);
  535. QHBoxLayout *bottomLayout = new QHBoxLayout(0, 0, 6);
  536. keypadButton = new QPushButton(i18n("Keypad"), centralWidget());
  537. QToolTip::add(keypadButton, i18n("Show/hide keypad"));
  538. keypadButton->setToggleButton(true);
  539. bottomLayout->addWidget(keypadButton);
  540. historyButton = new QPushButton(i18n("History"), centralWidget());
  541. QToolTip::add(historyButton, i18n("Show/hide history"));
  542. historyButton->setToggleButton(true);
  543. bottomLayout->addWidget(historyButton);
  544. stackButton = new QPushButton(i18n("RPN Stack"), centralWidget());
  545. QToolTip::add(stackButton, i18n("Show/hide RPN stack"));
  546. stackButton->setToggleButton(true);
  547. bottomLayout->addWidget(stackButton);
  548. if(!rpn_mode) stackButton->hide();
  549. bottomLayout->addItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
  550. mainLayout->addLayout(bottomLayout);
  551. connect(stackList, SIGNAL(selectionChanged()), this, SLOT(registerSelected()));
  552. connect(stackList, SIGNAL(itemRenamed(QListViewItem*)), this, SLOT(stackRegisterSet(QListViewItem*)));
  553. connect(stackList, SIGNAL(moved()), this, SLOT(stackRegisterMoved()));
  554. connect(stackList, SIGNAL(contextMenu(KListView*, QListViewItem*, const QPoint&)), this, SLOT(popupStackMenu(KListView*, QListViewItem*, const QPoint&)));
  555. connect(registerUpButton, SIGNAL(clicked()), this, SLOT(registerUp()));
  556. connect(registerDownButton, SIGNAL(clicked()), this, SLOT(registerDown()));
  557. connect(editRegisterButton, SIGNAL(clicked()), this, SLOT(editRegister()));
  558. connect(deleteRegisterButton, SIGNAL(clicked()), this, SLOT(deleteRegister()));
  559. connect(clearStackButton, SIGNAL(clicked()), this, SLOT(clearStack()));
  560. connect(stackButton, SIGNAL(toggled(bool)), this, SLOT(toggleStack(bool)));
  561. connect(historyButton, SIGNAL(toggled(bool)), this, SLOT(toggleHistory(bool)));
  562. connect(keypadButton, SIGNAL(toggled(bool)), this, SLOT(toggleKeypad(bool)));
  563. connect(kp0, SIGNAL(clicked()), this, SLOT(insertKP0()));
  564. connect(kp1, SIGNAL(clicked()), this, SLOT(insertKP1()));
  565. connect(kp2, SIGNAL(clicked()), this, SLOT(insertKP2()));
  566. connect(kp3, SIGNAL(clicked()), this, SLOT(insertKP3()));
  567. connect(kp4, SIGNAL(clicked()), this, SLOT(insertKP4()));
  568. connect(kp5, SIGNAL(clicked()), this, SLOT(insertKP5()));
  569. connect(kp6, SIGNAL(clicked()), this, SLOT(insertKP6()));
  570. connect(kp7, SIGNAL(clicked()), this, SLOT(insertKP7()));
  571. connect(kp8, SIGNAL(clicked()), this, SLOT(insertKP8()));
  572. connect(kp9, SIGNAL(clicked()), this, SLOT(insertKP9()));
  573. connect(kpDot, SIGNAL(clicked()), this, SLOT(insertDot()));
  574. connect(kpExp, SIGNAL(clicked()), this, SLOT(insertExp()));
  575. connect(kpAns, SIGNAL(clicked()), this, SLOT(insertAns()));
  576. connect(kpEquals, SIGNAL(clicked()), this, SLOT(execute()));
  577. connect(kpPlus, SIGNAL(clicked()), this, SLOT(insertPlus()));
  578. connect(kpMinus, SIGNAL(clicked()), this, SLOT(insertMinus()));
  579. connect(kpTimes, SIGNAL(clicked()), this, SLOT(insertTimes()));
  580. connect(kpDivision, SIGNAL(clicked()), this, SLOT(insertDivision()));
  581. connect(kpDel, SIGNAL(clicked()), this, SLOT(expressionDel()));
  582. connect(kpClear, SIGNAL(clicked()), this, SLOT(clearExpression()));
  583. connect(kpSin, SIGNAL(clicked()), this, SLOT(insertSin()));
  584. connect(kpCos, SIGNAL(clicked()), this, SLOT(insertCos()));
  585. connect(kpTan, SIGNAL(clicked()), this, SLOT(insertTan()));
  586. connect(kpSqrt, SIGNAL(clicked()), this, SLOT(insertSqrt()));
  587. connect(kpLog, SIGNAL(clicked()), this, SLOT(insertLog()));
  588. connect(kpLn, SIGNAL(clicked()), this, SLOT(insertLn()));
  589. connect(kpRaise, SIGNAL(clicked()), this, SLOT(insertRaise()));
  590. connect(kpSquare, SIGNAL(clicked()), this, SLOT(insertSquare()));
  591. connect(kpFraction, SIGNAL(toggled(bool)), this, SLOT(setFractionMode(bool)));
  592. connect(kpExact, SIGNAL(toggled(bool)), this, SLOT(setExactMode(bool)));
  593. connect(kpAngleGroup, SIGNAL(clicked(int)), this, SLOT(kpSetAngleUnit(int)));
  594. connect(kpBaseCombo->listBox(), SIGNAL(selected(int)), this, SLOT(kpSetBaseSelected(int)));
  595. connect(kpBaseCombo, SIGNAL(activated(int)), this, SLOT(kpSetBase(int)));
  596. connect(kpNumericCombo, SIGNAL(activated(int)), this, SLOT(kpSetNumericalMode(int)));
  597. //connect(kpMod, SIGNAL(clicked()), this, SLOT(insertMod()));
  598. connect(kpFactorial, SIGNAL(clicked()), this, SLOT(insertFactorial()));
  599. //connect(expressionEdit, SIGNAL(returnPressed()), this, SLOT(execute()));
  600. connect(expressionEdit, SIGNAL(textChanged(const QString&)), this, SLOT(onExpressionChanged()));
  601. connect(storeButton, SIGNAL(clicked()), this, SLOT(storeResult()));
  602. connect(executeButton, SIGNAL(clicked()), this, SLOT(execute()));
  603. connect(convertButton, SIGNAL(clicked()), this, SLOT(convertToUnitExpression()));
  604. connect(functionsButton, SIGNAL(clicked()), this, SLOT(manageFunctions()));
  605. connect(expressionEdit, SIGNAL(cursorMoved()), this, SLOT(displayParseStatus()));
  606. connect(expressionEdit->qalculateCompletionBox, SIGNAL(hidden()), statusLabel_l, SLOT(update()));
  607. //tab order
  608. setTabOrder(expressionEdit, resultLabel);
  609. setTabOrder(resultLabel, historyBrowser);
  610. setTabOrder(historyBrowser, keypadButton);
  611. setTabOrder(keypadButton, historyButton);
  612. setTabOrder(historyButton, stackButton);
  613. if(show_stack && rpn_mode) {
  614. bottomLine->hide();
  615. stackButton->setOn(true);
  616. mainStack->raiseWidget(2);
  617. mainStack->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding, false);
  618. resultLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum, false);
  619. } else if(show_keypad) {
  620. bottomLine->hide();
  621. keypadButton->setOn(true);
  622. mainStack->raiseWidget(0);
  623. mainStack->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum, false);
  624. resultLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding, false);
  625. } else if(show_history) {
  626. bottomLine->hide();
  627. historyButton->setOn(true);
  628. mainStack->raiseWidget(1);
  629. mainStack->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding, false);
  630. resultLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum, false);
  631. } else {
  632. mainStack->hide();
  633. mainStack->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum, false);
  634. resultLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding, false);
  635. }
  636. initial_history = "";
  637. for(QValueVector<QString>::size_type i = 0; i < inhistory.size(); i++) {
  638. switch(inhistory_type[i]) {
  639. case QALCULATE_HISTORY_EXPRESSION: {
  640. if(i != 0) {
  641. initial_history += "<br><hr>";
  642. }
  643. initial_history += "<a name=\"";
  644. initial_history += QString::number(inhistory_id[i]);
  645. initial_history += "\">";
  646. initial_history += inhistory[i];
  647. initial_history += "</a>";
  648. initial_history += " ";
  649. break;
  650. }
  651. case QALCULATE_HISTORY_REGISTER_MOVED: {
  652. if(i != 0) {
  653. initial_history += "<br><hr>";
  654. }
  655. initial_history += i18n("RPN Register Moved");
  656. initial_history += "<br>";
  657. break;
  658. }
  659. case QALCULATE_HISTORY_TRANSFORMATION: {
  660. initial_history += "<i>";
  661. initial_history += "<b>";
  662. initial_history += inhistory[i];
  663. initial_history += "</i>";
  664. initial_history += ": ";
  665. break;
  666. }
  667. case QALCULATE_HISTORY_RESULT: {
  668. initial_history += "<a name=\"";
  669. initial_history += QString::number(inhistory_id[i]);
  670. initial_history += "\">";
  671. initial_history += "= ";
  672. initial_history += "</a>";
  673. initial_history += "<b>";
  674. initial_history += "<a name=\"";
  675. initial_history += QString::number(inhistory_id[i]);
  676. initial_history += "\">";
  677. initial_history += inhistory[i];
  678. initial_history += "</a>";
  679. initial_history += "</b>";
  680. initial_history += "<br>";
  681. break;
  682. }
  683. case QALCULATE_HISTORY_RESULT_APPROXIMATE: {
  684. initial_history += "<a name=\"";
  685. initial_history += QString::number(inhistory_id[i]);
  686. initial_history += "\">";
  687. if(printops.use_unicode_signs && can_display_unicode_string_function(SIGN_ALMOST_EQUAL, (void*) historyBrowser)) {
  688. initial_history += SIGN_ALMOST_EQUAL " ";
  689. } else {
  690. initial_history += "= ";
  691. initial_history += i18n("approx.");
  692. initial_history += " ";
  693. }
  694. initial_history += "</a>";
  695. initial_history += "<b>";
  696. initial_history += "<a name=\"";
  697. initial_history += QString::number(inhistory_id[i]);
  698. initial_history += "\">";
  699. initial_history += inhistory[i];
  700. initial_history += "</a>";
  701. initial_history += "</b>";
  702. initial_history += "<br>";
  703. break;
  704. }
  705. case QALCULATE_HISTORY_PARSE: {
  706. initial_history += "&nbsp;&nbsp;= ";
  707. initial_history += "<font color=\"gray40\"><i>";
  708. initial_history += "<a name=\"";
  709. initial_history += QString::number(inhistory_id[i]);
  710. initial_history += "\">";
  711. initial_history += inhistory[i];
  712. initial_history += "</a>";
  713. initial_history += "</i></font>";
  714. initial_history += "<br>";
  715. break;
  716. }
  717. case QALCULATE_HISTORY_PARSE_APPROXIMATE: {
  718. initial_history += "&nbsp;&nbsp;";
  719. if(printops.use_unicode_signs && can_display_unicode_string_function(SIGN_ALMOST_EQUAL, (void*) historyBrowser)) {
  720. initial_history += SIGN_ALMOST_EQUAL " ";
  721. } else {
  722. initial_history += "= ";
  723. initial_history += i18n("approx.");
  724. initial_history += " ";
  725. }
  726. initial_history += "<font color=\"gray40\"><i>";
  727. initial_history += "<a name=\"";
  728. initial_history += QString::number(inhistory_id[i]);
  729. initial_history += "\">";
  730. initial_history += inhistory[i];
  731. initial_history += "</a>";
  732. initial_history += "</i></font>";
  733. initial_history += "<br>";
  734. break;
  735. }
  736. case QALCULATE_HISTORY_WARNING: {
  737. initial_history += "<font color=\"blue\">";
  738. initial_history += "- ";
  739. initial_history += inhistory[i];
  740. initial_history += "</font>";
  741. initial_history += "<br>";
  742. break;
  743. }
  744. case QALCULATE_HISTORY_ERROR: {
  745. initial_history += "<font color=\"red\">";
  746. initial_history += "- ";
  747. initial_history += inhistory[i];
  748. initial_history += "</font>";
  749. initial_history += "<br>";
  750. break;
  751. }
  752. case QALCULATE_HISTORY_OLD: {
  753. initial_history += inhistory[i];
  754. initial_history += "<br>";
  755. break;
  756. }
  757. }
  758. }
  759. historyBrowser->setText(initial_history);
  760. initial_history = "";
  761. if(use_custom_result_font) {
  762. QFont new_font(resultLabel->font());
  763. new_font.fromString(custom_result_font);
  764. resultLabel->setFont(new_font);
  765. } else {
  766. resultLabel->unsetFont();
  767. }
  768. if(use_custom_expression_font) {
  769. QFont new_font(expressionEdit->font());
  770. new_font.fromString(custom_expression_font);
  771. expressionEdit->setFont(new_font);
  772. } else {
  773. expressionEdit->unsetFont();
  774. }
  775. updateStatusLabelFonts();
  776. set_unicode_buttons();
  777. setupActions();
  778. stackMenu = new QPopupMenu(this);
  779. ActionEditRegister->plug(stackMenu);
  780. ActionDeleteRegister->plug(stackMenu);
  781. stackMenu->insertSeparator();
  782. ActionClearStack->plug(stackMenu);
  783. update_status_text();
  784. bottomLine->setMinimumWidth(1000);
  785. createGUI("qalculate_kdeui.rc");
  786. menuBar()->sizeHint();
  787. int h = menuBar()->height();
  788. int w = 300;
  789. while(menuBar()->heightForWidth(w) > h && w < 1000) {
  790. w += 10;
  791. }
  792. if(w >= 1000) {
  793. bottomLine->setMinimumWidth(0);
  794. w = 0;
  795. } else {
  796. bottomLine->setMinimumWidth(w - 22);
  797. }
  798. if(!isShown()) adjustSize();
  799. setAutoSaveSettings();
  800. if(show_history || (rpn_mode && show_stack)) {
  801. resize(QSize(10, height()).expandedTo(minimumSizeHint()));
  802. } else if(show_keypad) {
  803. resize(minimumSizeHint());
  804. } else {
  805. resize(QSize(width(), 10).expandedTo(minimumSizeHint()));
  806. }
  807. menu_functions = (QPopupMenu*) factory()->container("functions", this);
  808. menu_variables = (QPopupMenu*) factory()->container("variables", this);
  809. menu_units = (QPopupMenu*) factory()->container("units", this);
  810. menu_to_unit = (QPopupMenu*) factory()->container("convert_to_unit", this);
  811. menu_set_prefix = (QPopupMenu*) factory()->container("set_prefix", this);
  812. menu_modes = (QPopupMenu*) factory()->container("modes", this);
  813. QObject::connect(menu_modes, SIGNAL(activated(int)), this, SLOT(onModesMenuItemActivated(int)));
  814. for(size_t i = 0; i < modes.size(); i++) {
  815. menu_modes->insertItem(modes[i].name, -1, i);
  816. if(i > 1) {
  817. ModeObject *mo = new ModeObject(i);
  818. mo->i_mode = i;
  819. mode_objects.push_back(mo);
  820. accel()->insert(QString("Load mode: ") + modes[i].name, i18n("Load meta mode: %1").arg(modes[i].name), QString::null, modes[i].shortcut, mo, SLOT(loadMode()));
  821. }
  822. }
  823. QObject::connect(menu_functions, SIGNAL(activated(int)), this, SLOT(onFunctionMenuItemActivated(int)));
  824. QObject::connect(menu_variables, SIGNAL(activated(int)), this, SLOT(onVariableMenuItemActivated(int)));
  825. QObject::connect(menu_units, SIGNAL(activated(int)), this, SLOT(onUnitMenuItemActivated(int)));
  826. QObject::connect(menu_to_unit, SIGNAL(activated(int)), this, SLOT(onConvertToUnitMenuItemActivated(int)));
  827. QObject::connect(menu_set_prefix, SIGNAL(activated(int)), this, SLOT(onSetPrefixMenuItemActivated(int)));
  828. }
  829. KQalculate::~KQalculate() {}
  830. void KQalculate::updateStatusLabelFonts() {
  831. if(use_custom_status_font) {
  832. QFont new_font(statusLabel_l->font());
  833. new_font.fromString(custom_status_font);
  834. statusLabel_l->setFont(new_font);
  835. new_font.setPointSizeFloat(new_font.pointSizeFloat() / 1.2);
  836. statusLabel_r->setFont(new_font);
  837. } else {
  838. statusLabel_l->unsetFont();
  839. statusLabel_r->unsetFont();
  840. QFont new_font = statusLabel_l->font();
  841. new_font.setPointSizeFloat(new_font.pointSizeFloat() / 1.2);
  842. statusLabel_l->setFont(new_font);
  843. new_font = statusLabel_r->font();
  844. new_font.setPointSizeFloat(new_font.pointSizeFloat() / 1.44);
  845. statusLabel_r->setFont(new_font);
  846. }
  847. }
  848. void KQalculate::updateButtonWidths() {
  849. int button_width = executeButton->sizeHint().width();
  850. if(storeButton->sizeHint().width() > button_width) button_width = storeButton->sizeHint().width();
  851. if(convertButton->sizeHint().width() > button_width) button_width = convertButton->sizeHint().width();
  852. if(registerUpButton->sizeHint().width() > button_width) button_width = registerUpButton->sizeHint().width();
  853. if(registerDownButton->sizeHint().width() > button_width) button_width = registerDownButton->sizeHint().width();
  854. if(editRegisterButton->sizeHint().width() > button_width) button_width = editRegisterButton->sizeHint().width();
  855. if(deleteRegisterButton->sizeHint().width() > button_width) button_width = deleteRegisterButton->sizeHint().width();
  856. if(clearStackButton->sizeHint().width() > button_width) button_width = clearStackButton->sizeHint().width();
  857. clearStackButton->setMinimumWidth(button_width);
  858. executeButton->setMinimumWidth(button_width);
  859. }
  860. void KQalculate::fontChange(const QFont &old_font) {
  861. updateStatusLabelFonts();
  862. functionsButton->unsetFont();
  863. QFont fb_font(functionsButton->font());
  864. fb_font.setItalic(true);
  865. functionsButton->setFont(fb_font);
  866. kpSquare->setMarkup(i18n("x<sup>2</sup>"));
  867. kpRaise->setMarkup(i18n("x<sup>y</sup>"));
  868. result_display_updated();
  869. KMainWindow::fontChange(old_font);
  870. updateButtonWidths();
  871. }
  872. void KQalculate::showSystemTrayIcon(bool do_show) {
  873. if(do_show && !trayicon) {
  874. trayicon = new KSystemTray(this);
  875. QObject::connect(trayicon, SIGNAL(quitSelected()), qApp, SLOT(quit()));
  876. #if KDE_VERSION_MAJOR < 4 && KDE_VERSION_MINOR < 2
  877. trayicon->setPixmap(loadSystrayIcon(PACKAGE));
  878. #else
  879. trayicon->setPixmap(trayicon->loadIcon(PACKAGE));
  880. #endif
  881. #if KDE_VERSION_MAJOR > 3 || KDE_VERSION_MINOR >= 2
  882. KPopupMenu* traypop = trayicon->contextMenu();
  883. ActionHideSystemTrayIcon->plug(traypop, 1);
  884. #endif
  885. QToolTip::add(trayicon, i18n("Qalculate! - Scientific Calculator"));
  886. }
  887. if(do_show) {
  888. trayicon->show();
  889. } else if(trayicon) {
  890. trayicon->hide();
  891. }
  892. }
  893. void KQalculate::hideSystemTrayIcon() {
  894. showSystemTrayIcon(false);
  895. close_to_systray = false;
  896. show();
  897. }
  898. #define SET_TOGGLE_ACTION(action, value) action->blockSignals(true); action->setChecked(value); action->blockSignals(false);
  899. #define SET_TOGGLE_ACTION_ON(action) action->blockSignals(true); action->setChecked(true); action->blockSignals(false);
  900. void KQalculate::setupActions() {
  901. ActionNewVariable = new KAction(i18n("Variable"), "filenew", 0, this, SLOT(newVariable()), actionCollection(), "new_variable");
  902. ActionNewMatrix = new KAction(i18n("Matrix"), "filenew", 0, this, SLOT(newMatrix()), actionCollection(), "new_matrix");
  903. ActionNewVector = new KAction(i18n("Vector"), "filenew", 0, this, SLOT(newVector()), actionCollection(), "new_vector");
  904. ActionNewUnknownVariable = new KAction(i18n("Unknown Variable"), "filenew", 0, this, SLOT(newUnknownVariable()), actionCollection(), "new_unknown_variable");
  905. ActionNewFunction = new KAction(i18n("Function"), "filenew", 0, this, SLOT(newFunction()), actionCollection(), "new_function");
  906. ActionNewDataSet = new KAction(i18n("Data Set"), "filenew", 0, this, SLOT(newDataSet()), actionCollection(), "new_data_set");
  907. ActionNewUnit = new KAction(i18n("Unit"), "filenew", 0, this, SLOT(newUnit()), actionCollection(), "new_unit");
  908. ActionImportCSVFile = new KAction(i18n("Import CSV File..."), "fileimport", 0, this, SLOT(importCSVFile()), actionCollection(), "import_csv_file");
  909. ActionExportCSVFile = new KAction(i18n("Export CSV File..."), "filexport", 0, this, SLOT(exportCSVFile()), actionCollection(), "export_csv_file");
  910. ActionStoreResult = new KAction(i18n("Store Result..."), "filesave", CTRL+Key_S, this, SLOT(storeResult()), actionCollection(), "store_result");
  911. ActionSaveAsImage = new KAction(i18n("Save Result Image..."), "filesave", 0, this, SLOT(saveAsImage()), actionCollection(), "save_as_image");
  912. ActionSaveDefinitions = new KAction(i18n("Save Definitions"), "filesave", 0, this, SLOT(saveDefinitions()), actionCollection(), "save_definitions");
  913. ActionUpdateExchangeRates = new KAction(i18n("Update Exchange Rates"), "reload", 0, this, SLOT(updateExchangeRates()), actionCollection(), "update_exchange_rates");
  914. ActionPlotFunctionsData = new KAction(i18n("Plot Functions/Data"), 0, this, SLOT(plotFunctionsData()), actionCollection(), "plot_functions_data");
  915. ActionPlotFunctionsData->setEnabled(canplot);
  916. ActionConvertNumberBases = new KAction(i18n("Convert Number Bases"), 0, this, SLOT(convertNumberBases()), actionCollection(), "convert_number_bases");
  917. ActionPeriodicTable = new KAction(i18n("Periodic Table"), 0, this, SLOT(periodicTable()), actionCollection(), "periodic_table");
  918. if(close_to_systray) {
  919. ActionClose = KStdAction::close(this, SLOT(close()), actionCollection());
  920. } else {
  921. ActionClose = NULL;
  922. }
  923. globalAccel = new KGlobalAccel(this);
  924. globalAccel->insert("Show/hide Qalculate!", i18n("Show/hide main Qalculate! window"), QString::null, KShortcut(), KShortcut(), this, SLOT(showHide()));
  925. globalAccel->readSettings();
  926. globalAccel->updateConnections();
  927. ActionConfigureGlobalShortcuts = new KAction(i18n("Configure &Global Shortcuts..."), "configure_shortcuts", 0, this, SLOT(configureGlobalShortcuts()), actionCollection(), "configure_global_shortcuts");
  928. ActionQuit = KStdAction::quit(qApp, SLOT(quit()), actionCollection());
  929. ActionManageVariables = new KAction(i18n("Manage Variables"), Key_F2, this, SLOT(manageVariables()), actionCollection(), "manage_variables");
  930. ActionManageFunctions = new KAction(i18n("Manage Functions"), Key_F3, this, SLOT(manageFunctions()), actionCollection(), "manage_functions");
  931. ActionManageUnits = new KAction(i18n("Manage Units"), Key_F4, this, SLOT(manageUnits()), actionCollection(), "manage_units");
  932. ActionManageDataSets = new KAction(i18n("Manage Data Sets"), 0, this, SLOT(manageDataSets()), actionCollection(), "manage_data_sets");
  933. ActionFactorize = new KAction(i18n("Factorize"), 0, this, SLOT(factorize()), actionCollection(), "factorize");
  934. ActionSimplify = new KAction(i18n("Simplify"), 0, this, SLOT(simplify()), actionCollection(), "simplify");
  935. ActionSetUnknowns = new KAction(i18n("Set Unknowns..."), 0, this, SLOT(setUnknowns()), actionCollection(), "set_unknowns");
  936. ActionConvertToUnitExpression = new KAction(i18n("Convert to Unit Expression..."), CTRL+Key_T, this, SLOT(convertToUnitExpression()), actionCollection(), "convert_to_unit_expression");
  937. ActionConvertToBaseUnits = new KAction(i18n("Convert to Base Units"), 0, this, SLOT(convertToBaseUnits()), actionCollection(), "convert_to_base_units");
  938. ActionConvertToBestUnit = new KAction(i18n("Convert to Best Unit"), 0, this, SLOT(convertToBestUnit()), actionCollection(), "convert_to_best_unit");
  939. ActionInsertMatrix = new KAction(i18n("Insert Matrix..."), 0, this, SLOT(insertMatrix()), actionCollection(), "insert_matrix");
  940. ActionInsertVector = new KAction(i18n("Insert Vector..."), 0, this, SLOT(insertVector()), actionCollection(), "insert_vector");
  941. ActionCopyResult = new KAction(i18n("Copy Result"), "editcopy", Key_F5, this, SLOT(copyResult()), actionCollection(), "copy_result");
  942. ActionClearHistory = new KAction(i18n("Clear History"), "editclear", 0, this, SLOT(clearHistory()), actionCollection(), "clear_history");
  943. ActionPreferences = new KAction(i18n("Configure Qalculate!"), "configure", 0, this, SLOT(preferences()), actionCollection(), "preferences");
  944. KStdAction::keyBindings(guiFactory(), SLOT(configureShortcuts()), actionCollection(), "keybindings");
  945. ActionNumberBaseBinary = new KRadioAction(i18n("Binary"), 0, this, SLOT(numberBaseBinary()), actionCollection(), "number_base_binary");
  946. ActionNumberBaseBinary->setExclusiveGroup("group_number_base");
  947. ActionNumberBaseOctal = new KRadioAction(i18n("Octal"), 0, this, SLOT(numberBaseOctal()), actionCollection(), "number_base_octal");
  948. ActionNumberBaseOctal->setExclusiveGroup("group_number_base");
  949. ActionNumberBaseDecimal = new KRadioAction(i18n("Decimal"), 0, this, SLOT(numberBaseDecimal()), actionCollection(), "number_base_decimal");
  950. ActionNumberBaseDecimal->setExclusiveGroup("group_number_base");
  951. ActionNumberBaseHexadecimal = new KRadioAction(i18n("Hexadecimal"), 0, this, SLOT(numberBaseHexadecimal()), actionCollection(), "number_base_hexadecimal");
  952. ActionNumberBaseHexadecimal->setExclusiveGroup("group_number_base");
  953. ActionNumberBaseOther = new KRadioAction(i18n("Other..."), 0, this, SLOT(numberBaseOther()), actionCollection(), "number_base_other");
  954. ActionNumberBaseOther->setExclusiveGroup("group_number_base");
  955. ActionNumberBaseSexagesimal = new KRadioAction(i18n("Sexagesimal"), 0, this, SLOT(numberBaseSexagesimal()), actionCollection(), "number_base_sexagesimal");
  956. ActionNumberBaseSexagesimal->setExclusiveGroup("group_number_base");
  957. ActionNumberBaseTimeFormat = new KRadioAction(i18n("Time Format"), 0, this, SLOT(numberBaseTimeFormat()), actionCollection(), "number_base_time_format");
  958. ActionNumberBaseTimeFormat->setExclusiveGroup("group_number_base");
  959. ActionNumberBaseRomanNumerals = new KRadioAction(i18n("Roman Numerals"), 0, this, SLOT(numberBaseRomanNumerals()), actionCollection(), "number_base_roman_numerals");
  960. ActionNumberBaseRomanNumerals->setExclusiveGroup("group_number_base");
  961. ActionSetBase = new KAction(i18n("Select Result and Expression Base..."), CTRL+Key_B, this, SLOT(setBase()), actionCollection(), "set_base");
  962. ActionNumericalDisplayNormal = new KRadioAction(i18n("Normal"), 0, this, SLOT(numericalDisplayNormal()), actionCollection(), "numerical_display_normal");
  963. ActionNumericalDisplayNormal->setExclusiveGroup("group_numberical_display");
  964. ActionNumericalDisplayEngineering = new KRadioAction(i18n("Engineering"), 0, this, SLOT(numericalDisplayEngineering()), actionCollection(), "numerical_display_engineering");
  965. ActionNumericalDisplayEngineering->setExclusiveGroup("group_numberical_display");
  966. ActionNumericalDisplayScientific = new KRadioAction(i18n("Scientific"), 0, this, SLOT(numericalDisplayScientific()), actionCollection(), "numerical_display_scientific");
  967. ActionNumericalDisplayScientific->setExclusiveGroup("group_numberical_display");
  968. ActionNumericalDisplayPurelyScientific = new KRadioAction(i18n("Purely Scientific"), 0, this, SLOT(numericalDisplayPurelyScientific()), actionCollection(), "numerical_display_purely_scientific");
  969. ActionNumericalDisplayPurelyScientific->setExclusiveGroup("group_numberical_display");
  970. ActionNumericalDisplaySimple = new KRadioAction(i18n("Simple"), 0, this, SLOT(numericalDisplaySimple()), actionCollection(), "numerical_display_simple");
  971. ActionNumericalDisplaySimple->setExclusiveGroup("group_numberical_display");
  972. ActionIndicateInfiniteSeries = new KToggleAction(i18n("Indicate Infinite Series"), 0, actionCollection(), "indicate_infinite_series");
  973. QObject::connect(ActionIndicateInfiniteSeries, SIGNAL(toggled(bool)), this, SLOT(indicateInfiniteSeries(bool)));
  974. ActionSortMinusLast = new KToggleAction(i18n("Sort Minus Last"), 0, actionCollection(), "sort_minus_last");
  975. QObject::connect(ActionSortMinusLast, SIGNAL(toggled(bool)), this, SLOT(sortMinusLast(bool)));
  976. ActionNegativeExponents = new KToggleAction(i18n("Negative Exponents"), 0, actionCollection(), "negative_exponents");
  977. QObject::connect(ActionNegativeExponents, SIGNAL(tog

Large files files are truncated, but you can click here to view the full file