/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
- /***************************************************************************
- * Copyright (C) 2005-2007 by Niklas Knutsson *
- * nq@altern.org *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
- ***************************************************************************/
- #ifdef HAVE_CONFIG_H
- # include <config.h>
- #endif
- #include <kdialog.h>
- #include <klocale.h>
- #include "kqalculate.h"
- #include "qalculateinsertfunctiondialog.h"
- #include "qalculate_kde_utils.h"
- #include "preferences.h"
- #include "qalculatepreferencesdialog.h"
- #include "qalculateimportcsvdialog.h"
- #include "qalculateexportcsvdialog.h"
- #include "qalculateexpressionedit.h"
- #include "qalculateprecisiondialog.h"
- #include "qalculatedecimalsdialog.h"
- #include "qalculateeditvariabledialog.h"
- #include "qalculateeditmatrixvectordialog.h"
- #include "qalculateeditunitdialog.h"
- #include "qalculateeditfunctiondialog.h"
- #include "qalculateeditdatasetdialog.h"
- #include "qalculateeditunknownvariabledialog.h"
- #include "qalculatevariablesdialog.h"
- #include "qalculatefunctionsdialog.h"
- #include "qalculateunitsdialog.h"
- #include "qalculatedatasetsdialog.h"
- #include "qalculateconvertunitsdialog.h"
- #include "qalculateconvertnumberbasesdialog.h"
- #include "qalculateperiodictabledialog.h"
- #include "qalculateplotdialog.h"
- #include "qalculatesetbasedialog.h"
- #include "qalculateinsertmatrixvectordialog.h"
- #include <kwin.h>
- #include <kglobalsettings.h>
- #include <kuniqueapplication.h>
- #include <kstringhandler.h>
- #include <qtable.h>
- #include <kseparator.h>
- #include <kiconloader.h>
- #include <qframe.h>
- #include <qvariant.h>
- #include <qtooltip.h>
- #include <qwhatsthis.h>
- #include <qclipboard.h>
- #include <qstylesheet.h>
- #include <kcompletion.h>
- #include <klineedit.h>
- #include <qlabel.h>
- #include <kmessagebox.h>
- #include <qpixmap.h>
- #include <qpicture.h>
- #include <qpainter.h>
- #include <qfontmetrics.h>
- #include <sys/stat.h>
- #include <unistd.h>
- #include <time.h>
- #include <math.h>
- #include <dirent.h>
- #include <pthread.h>
- #include <qsimplerichtext.h>
- #include <qstatusbar.h>
- #include <qwidgetstack.h>
- #include <ktextbrowser.h>
- #include <kpushbutton.h>
- #include "qalculateresultdisplay.h"
- #include <qbitmap.h>
- #include <qscrollview.h>
- #include <qobject.h>
- #include <kapplication.h>
- #include <kaction.h>
- #include <qspinbox.h>
- #include <kprogress.h>
- #include <kpopupmenu.h>
- #include <kmenubar.h>
- #include <qlayout.h>
- #include <qtimer.h>
- #include <kcompletionbox.h>
- #include <qstringlist.h>
- #include <qcombobox.h>
- #include <ksystemtray.h>
- #if KDE_VERSION_MAJOR > 3 || KDE_VERSION_MINOR > 1
- #include <kactionclasses.h>
- #endif
- #if KDE_VERSION_MAJOR > 3 || KDE_VERSION_MINOR >= 4
- #include <kaccelmanager.h>
- #endif
- #include <qbuttongroup.h>
- #include <qvbuttongroup.h>
- #include <qradiobutton.h>
- #include <qgrid.h>
- #include <kfiledialog.h>
- #include <qimage.h>
- #include <kaccel.h>
- #include <kio/netaccess.h>
- #if KDE_VERSION_MAJOR > 3 || KDE_VERSION_MINOR >= 2
- #include <kinputdialog.h>
- #endif
- #include <kdeversion.h>
- #include <qstyle.h>
- #include <kglobalaccel.h>
- #include <kkeydialog.h>
- #include <kkeybutton.h>
- #include <kcombobox.h>
- MathStructure *mstruct, *matrix_mstruct, *parsed_mstruct, *parsed_tostruct;
- QString result_text, result_history_text, parsed_text;
- QWidget *expressionWidget, *resultWidget, *statusWidget_l;
- QWidget *topWidget;
- KQalculate *mainWin = 0;
- bool prev_result_approx;
- extern bool close_to_systray;
- extern bool display_expression_status;
- extern QColor status_error_color;
- extern QColor status_warning_color;
- extern int use_icon_buttons;
- extern bool enable_expression_completion;
- extern QString initial_history;
- extern tree_struct function_cats, unit_cats, variable_cats;
- extern vector<void*> ia_units, ia_variables, ia_functions;
- extern vector<MathFunction*> recent_functions;
- extern vector<Variable*> recent_variables;
- extern vector<Unit*> recent_units;
- vector<MathStructure> result_parts;
- KnownVariable *vans[5];
- int vans_id_start[5];
- int vans_id_end[5];
- extern PrintOptions printops;
- extern EvaluationOptions evalops;
- extern bool rpn_mode, rpn_keypad_only;
- extern bool save_mode_on_exit, save_defs_on_exit;
- extern bool canplot;
- extern bool use_custom_result_font, use_custom_expression_font, use_custom_status_font;
- extern QString custom_result_font, custom_expression_font, custom_status_font;
- extern QTimer *error_timer;
- extern QStringList expression_history;
- bool expression_has_changed, expression_has_changed2, had_errors_before, had_warnings_before, block_result_update;
- FILE *view_pipe_r, *view_pipe_w, *command_pipe_r, *command_pipe_w;
- pthread_t view_thread, command_thread;
- pthread_attr_t view_thread_attr, command_thread_attr;
- bool b_busy, command_thread_started;
- int saved_divisionline_height = 0;
- uint initial_result_index = 0;
- extern bool show_keypad, show_history, show_stack;
- extern vector<mode_struct> modes;
- extern QValueVector<QString> inhistory;
- extern QValueVector<int> inhistory_type;
- extern QValueVector<int> inhistory_id;
- extern int inhistory_current_id;
- int initial_inhistory_index = 0;
- const MathStructure *KQalculate::getResultPart(int i) {
- if(i < 1 || (size_t) i > result_parts.size()) return NULL;
- return &result_parts[(size_t) i - 1];
- }
- #if KDE_VERSION_MAJOR < 4 && KDE_VERSION_MINOR < 2
- #include <kiconloader.h>
- #include <kconfig.h>
- QPixmap loadSystrayIcon(const QString &icon) {
- KConfig *appCfg = kapp->config();
- KConfigGroupSaver configSaver(appCfg, "System Tray");
- int iconWidth = appCfg->readNumEntry("systrayIconWidth", 22);
- return KGlobal::instance()->iconLoader()->loadIcon(icon, KIcon::Panel, iconWidth);
- }
- #endif
- #if KDE_VERSION_MAJOR > 3 || KDE_VERSION_MINOR >= 3
- #define ICON_SIZE_SMALL_MEDIUM KIcon::SizeSmallMedium
- #else
- #define ICON_SIZE_SMALL_MEDIUM 22
- #endif
- ModeObject::ModeObject(int mode) : i_mode(mode) {}
- void ModeObject::loadMode() {
- mainWin->loadMode(i_mode);
- }
- KQalculate::KQalculate(KUniqueApplication *parent, const char* name, WFlags fl) : KMainWindow(0, name, fl) {
- if(!name) setName("kqalculate");
- m_parent = parent;
- vans_id_start[0] = -1;
- vans_id_end[0] = -1;
- vans_id_start[1] = -1;
- vans_id_end[1] = -1;
- vans_id_start[2] = -1;
- vans_id_end[2] = -1;
- vans_id_start[3] = -1;
- vans_id_end[3] = -1;
- vans_id_start[4] = -1;
- vans_id_end[4] = -1;
-
- QStyleSheet::setDefaultSheet(new QalculateStyleSheet());
- insert_matrix_dialog = NULL;
- preferences_dialog = NULL;
- precisionDialog = NULL;
- decimalsDialog = NULL;
- variable_edit_dialog = NULL;
- store_dialog = NULL;
- matrix_edit_dialog = NULL;
- import_csv_dialog = NULL;
- export_csv_dialog = NULL;
- unit_edit_dialog = NULL;
- function_edit_dialog = NULL;
- dataset_edit_dialog = NULL;
- unknown_edit_dialog = NULL;
- variables_dialog = NULL;
- functions_dialog = NULL;
- units_dialog = NULL;
- datasets_dialog = NULL;
- convert_to_unit_expression_dialog = NULL;
- convert_number_bases_dialog = NULL;
- periodic_table_dialog = NULL;
- plot_dialog = NULL;
- set_base_dialog = NULL;
-
- prev_result_approx = false;
- expression_has_changed = false;
- expression_has_changed2 = false;
- had_errors_before = false;
- had_warnings_before = false;
- block_result_update = false;
-
- history_height = 0;
-
- trayicon = NULL;
- ActionHideSystemTrayIcon = new KAction(i18n("Remove from System Tray"), "hidesystemtrayicon", 0, this, SLOT(hideSystemTrayIcon()), actionCollection(), "hide_system_tray_icon");
- ActionHide = new KAction(i18n("Hide"), "hide", 0, this, SLOT(hide()), actionCollection(), "hide");
- showSystemTrayIcon(close_to_systray);
- setCentralWidget(new QWidget(this));
- QVBoxLayout *mainLayout = new QVBoxLayout(centralWidget(), 11, 6);
- mainLayout->setResizeMode(QLayout::Minimum);
- QHBoxLayout *topLayout = new QHBoxLayout(0, 0, 6);
- bool use_button_pixmaps = false;
- if(use_icon_buttons > 0) {
- use_button_pixmaps = true;
- } else if(use_icon_buttons < 0) {
- KConfig config("kdeglobals", true, false);
- config.setGroup("KDE");
- use_button_pixmaps = config.readBoolEntry("ShowIconsOnPushButtons", false);
- }
- if(use_button_pixmaps) leftButtonsLayout = new QVBoxLayout(0, 0, 3);
- else leftButtonsLayout = new QVBoxLayout(0, 0, 6);
- if(use_button_pixmaps) executeButton = new QalculateButton(KApplication::kApplication()->iconLoader()->loadIconSet("exec", KIcon::Small, ICON_SIZE_SMALL_MEDIUM), "", centralWidget());
- else if(rpn_mode) executeButton = new QalculateButton(i18n("Enter"), centralWidget());
- else executeButton = new QalculateButton(i18n("="), centralWidget());
- executeButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed, false);
- if(rpn_mode) QToolTip::add(executeButton, i18n("Calculate expression and add to stack"));
- else QToolTip::add(executeButton, i18n("Calculate expression"));
- leftButtonsLayout->addWidget(executeButton);
- leftButtonsSeparator = new KSeparator(Qt::Horizontal, centralWidget());
- leftButtonsLayout->addWidget(leftButtonsSeparator);
- if(use_button_pixmaps) leftButtonsSeparator->hide();
- if(use_button_pixmaps) storeButton = new QalculateButton(KApplication::kApplication()->iconLoader()->loadIconSet("filesaveas", KIcon::Small, ICON_SIZE_SMALL_MEDIUM), "", centralWidget());
- else storeButton = new QalculateButton(i18n("Store"), centralWidget());
- storeButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed, false);
- QToolTip::add(storeButton, i18n("Store result as variable"));
- leftButtonsLayout->addWidget(storeButton);
- if(use_button_pixmaps) convertButton = new QalculateButton(KApplication::kApplication()->iconLoader()->loadIconSet("qalculate_convert", KIcon::Small, ICON_SIZE_SMALL_MEDIUM), "", centralWidget());
- else convertButton = new QalculateButton(i18n("Convert"), centralWidget());
- convertButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed, false);
- QToolTip::add(convertButton, i18n("Convert units in result"));
- leftButtonsLayout->addWidget(convertButton);
- leftButtonsLayout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::Minimum));
-
- QVBoxLayout *expressionLayout = new QVBoxLayout(0, 0, 0);
- expressionEdit = new QalculateExpressionEdit(true, centralWidget());
- expressionLayout->addWidget(expressionEdit);
- expressionEdit->setFocus();
- expressionEdit->expression_history = expression_history;
- if(!enable_expression_completion) expressionEdit->disableCompletion();
- QToolTip::add(expressionEdit, i18n("Enter expression here"));
- QHBoxLayout *statusLayout = new QHBoxLayout(0, 0, 6);
- statusLabel_l = new QalculateParseLabel(centralWidget());
- statusLabel_l->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum, false);
- statusLabel_l->setLineWidth(0);
- statusLabel_l->setMargin(0);
- statusLabel_l->setAlignment(int(QLabel::AlignTop | QLabel::AlignLeft));
- if(!display_expression_status) statusLabel_l->hide();
- statusLayout->addWidget(statusLabel_l);
- statusLabel_r = new QLabel(i18n("status"), centralWidget());
- statusLabel_r->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum, false);
- statusLabel_r->setLineWidth(0);
- statusLabel_r->setMargin(0);
- statusLabel_r->setTextFormat(Qt::RichText);
- statusLabel_r->setAlignment(int(QLabel::AlignTop | QLabel::AlignRight));
- statusLayout->addWidget(statusLabel_r);
- expressionLayout->addLayout(statusLayout);
- resultLabel = new QalculateResultDisplay(centralWidget());
- resultLabel->setRightMargin(10);
- expressionLayout->addWidget(resultLabel);
-
- topLayout->addLayout(expressionLayout);
- topLayout->addLayout(leftButtonsLayout);
- mainLayout->addLayout(topLayout);
-
- resultLabel->setWordWrap(QTextEdit::WidgetWidth);
- resultLabel->setMargin(0);
- bottomLine = new KSeparator(Qt::Horizontal, centralWidget());
- mainLayout->addWidget(bottomLine);
- mainStack = new QWidgetStack(centralWidget());
- mainStack->setEnabled(true);
- mainStack->setSizePolicy(QSizePolicy((QSizePolicy::SizeType) 5, (QSizePolicy::SizeType) 7, 0, 0, mainStack->sizePolicy().hasHeightForWidth()));
- keypadPage = new QWidget(mainStack);
- QVBoxLayout *keypadPageLayout = new QVBoxLayout(keypadPage, 0, 12);
-
- keypadPageLayout->addWidget(new KSeparator(Qt::Horizontal, keypadPage));
- QHBoxLayout *keypadTopLayout = new QHBoxLayout(0, 0, 6);
- kpExact = new QalculateButton(i18n("Exact"), keypadPage);
- QToolTip::add(kpExact, i18n("Toggle exact mode"));
- kpExact->setToggleButton(true);
- keypadTopLayout->addWidget(kpExact);
- kpFraction = new QalculateButton(i18n("Fraction"), keypadPage);
- QToolTip::add(kpFraction, i18n("Toggle fractional display"));
- kpFraction->setToggleButton(true);
- keypadTopLayout->addWidget(kpFraction);
- kpNumericCombo = new QComboBox(true, keypadPage);
- QToolTip::add(kpNumericCombo, i18n("Numerical display"));
- kpNumericCombo->setEditable(false);
- keypadTopLayout->addWidget(kpNumericCombo);
- kpNumericCombo->insertItem(i18n("Normal"));
- kpNumericCombo->insertItem(i18n("Engineering"));
- kpNumericCombo->insertItem(i18n("Scientific"));
- kpNumericCombo->insertItem(i18n("Pure"));
- kpNumericCombo->insertItem(i18n("Simple"));
- kpBaseCombo = new QComboBox(true, keypadPage);
- QToolTip::add(kpBaseCombo, i18n("Base in result"));
- kpBaseCombo->setEditable(false);
- keypadTopLayout->addWidget(kpBaseCombo);
- keypadPageLayout->addLayout(keypadTopLayout);
- kpBaseCombo->insertItem(i18n("Binary"));
- kpBaseCombo->insertItem(i18n("Octal"));
- kpBaseCombo->insertItem(i18n("Decimal"));
- kpBaseCombo->insertItem(i18n("Hexadecimal"));
- kpBaseCombo->insertItem(i18n("Sexagesimal"));
- kpBaseCombo->insertItem(i18n("Time Format"));
- kpBaseCombo->insertItem(i18n("Roman"));
- kpBaseCombo->insertItem(i18n("Other..."));
- QHBoxLayout *keypadBottomLayout = new QHBoxLayout(0, 0, 24);
- QGridLayout *keypadFunctionsLayout = new QGridLayout(0, 5, 3, 0, 6);
-
- functionsButton = new QalculateButton(i18n("f(x)"), keypadPage);
- QFont fb_font(functionsButton->font());
- fb_font.setItalic(true);
- functionsButton->setFont(fb_font);
- QToolTip::add(functionsButton, i18n("Open functions manager"));
- keypadFunctionsLayout->addWidget(functionsButton, 0, 0);
- kpSqrt = new QalculateButton(i18n("sqrt"), keypadPage);
- QToolTip::add(kpSqrt, i18n("Square root"));
- keypadFunctionsLayout->addWidget(kpSqrt, 1, 0);
- kpRaise = new QalculateButton(keypadPage);
- kpRaise->setMarkup(i18n("x<sup>y</sup>"));
- QToolTip::add(kpRaise, i18n("Raise (Ctrl+*)"));
- keypadFunctionsLayout->addWidget(kpRaise, 0, 1);
- kpSquare = new QalculateButton(keypadPage);
- kpSquare->setMarkup(i18n("x<sup>2</sup>"));
- QToolTip::add(kpSquare, i18n("Square"));
- keypadFunctionsLayout->addWidget(kpSquare, 0, 2);
- kpLog = new QalculateButton(i18n("log"), keypadPage);
- QToolTip::add(kpLog, i18n("Base-10 logarithm"));
- keypadFunctionsLayout->addWidget(kpLog, 1, 1);
- kpLn = new QalculateButton(i18n("ln"), keypadPage);
- QToolTip::add(kpLn, i18n("Natural logarithm"));
- keypadFunctionsLayout->addWidget(kpLn, 1, 2);
- kpFactorial = new QalculateButton(i18n("x!"), keypadPage);
- QToolTip::add(kpFactorial, i18n("Factorial"));
- keypadFunctionsLayout->addWidget(kpFactorial, 2, 0);
- kpCos = new QalculateButton(i18n("cos"), keypadPage);
- QToolTip::add(kpCos, i18n("Cosine"));
- keypadFunctionsLayout->addWidget(kpCos, 2, 1);
- kpTan = new QalculateButton(i18n("tan"), keypadPage);
- QToolTip::add(kpTan, i18n("Tangent"));
- keypadFunctionsLayout->addWidget(kpTan, 2, 2);
- kpHyp = new QalculateButton(i18n("hyp"), keypadPage);
- QToolTip::add(kpHyp, i18n("Toggle hyperbolic functions"));
- kpHyp->setToggleButton(true);
- keypadFunctionsLayout->addWidget(kpHyp, 3, 0);
- kpInv = new QalculateButton(i18n("inv"), keypadPage);
- QToolTip::add(kpInv, i18n("Toggle inverse functions"));
- kpInv->setToggleButton(true);
- keypadFunctionsLayout->addWidget(kpInv, 3, 1);
- kpSin = new QalculateButton(i18n("sin"), keypadPage);
- QToolTip::add(kpSin, i18n("Sine"));
- keypadFunctionsLayout->addWidget(kpSin, 3, 2);
- QHBoxLayout *keypadAngleLayout = new QHBoxLayout(0, 0, 6);
- kpAngleGroup = new QButtonGroup();
- kpAngleGroup->setExclusive(true);
- kpDegreesButton = new QRadioButton(i18n("Deg"), keypadPage);
- QToolTip::add(kpDegreesButton, i18n("Angle Unit: Degrees"));
- kpAngleGroup->insert(kpDegreesButton, 0);
- keypadAngleLayout->addWidget(kpDegreesButton);
- kpRadiansButton = new QRadioButton(i18n("Rad"), keypadPage);
- QToolTip::add(kpRadiansButton, i18n("Angle Unit: Radians"));
- kpAngleGroup->insert(kpRadiansButton, 1);
- keypadAngleLayout->addWidget(kpRadiansButton);
- kpGradiansButton = new QRadioButton(i18n("Gra"), keypadPage);
- QToolTip::add(kpGradiansButton, i18n("Angle Unit: Gradians"));
- kpAngleGroup->insert(kpGradiansButton, 2);
- keypadAngleLayout->addWidget(kpGradiansButton);
- kpNoAngleUnitButton = new QRadioButton(i18n("None"), keypadPage);
- kpAngleGroup->insert(kpNoAngleUnitButton, 3);
- keypadAngleLayout->addWidget(kpNoAngleUnitButton);
- kpNoAngleUnitButton->hide();
- keypadAngleLayout->addItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
- keypadFunctionsLayout->addMultiCellLayout(keypadAngleLayout, 4, 4, 0, 2);
-
- #if KDE_VERSION_MAJOR > 3 || KDE_VERSION_MINOR >= 4
- KAcceleratorManager::setNoAccel(kpDegreesButton);
- KAcceleratorManager::setNoAccel(kpRadiansButton);
- KAcceleratorManager::setNoAccel(kpGradiansButton);
- KAcceleratorManager::setNoAccel(kpNoAngleUnitButton);
- #endif
-
- keypadBottomLayout->addLayout(keypadFunctionsLayout);
-
- QGridLayout *keypadBasicsLayout = new QGridLayout(0, 1, 1, 0, 6);
- kp7 = new QalculateButton(i18n("7"), keypadPage);
- keypadBasicsLayout->addWidget(kp7, 0, 0);
- kp8 = new QalculateButton(i18n("8"), keypadPage);
- keypadBasicsLayout->addWidget(kp8, 0, 1);
- kp9 = new QalculateButton(i18n("9"), keypadPage);
- keypadBasicsLayout->addWidget(kp9, 0, 2);
- kp4 = new QalculateButton(i18n("4"), keypadPage);
- keypadBasicsLayout->addWidget(kp4, 1, 0);
- kp5 = new QalculateButton(i18n("5"), keypadPage);
- keypadBasicsLayout->addWidget(kp5, 1, 1);
- kp6 = new QalculateButton(i18n("6"), keypadPage);
- keypadBasicsLayout->addWidget(kp6, 1, 2);
- kp1 = new QalculateButton(i18n("1"), keypadPage);
- keypadBasicsLayout->addWidget(kp1, 2, 0);
- kp2 = new QalculateButton(i18n("2"), keypadPage);
- keypadBasicsLayout->addWidget(kp2, 2, 1);
- kp3 = new QalculateButton(i18n("3"), keypadPage);
- keypadBasicsLayout->addWidget(kp3, 2, 2);
- kp0 = new QalculateButton(i18n("0"), keypadPage);
- keypadBasicsLayout->addWidget(kp0, 3, 0);
- kpDot = new QalculateButton(".", keypadPage);
- QToolTip::add(kpDot, i18n("Decimal point"));
- keypadBasicsLayout->addWidget(kpDot, 3, 1);
- kpExp = new QalculateButton(i18n("EXP"), keypadPage);
- QToolTip::add(kpExp, i18n("10^x (Ctrl+Shift+E)"));
- keypadBasicsLayout->addWidget(kpExp, 3, 2);
-
- kpDel = new QalculateButton(i18n("Del"), keypadPage);
- QToolTip::add(kpDel, i18n("Delete"));
- keypadBasicsLayout->addWidget(kpDel, 0, 3);
- kpClear = new QalculateButton(i18n("AC"), keypadPage);
- QToolTip::add(kpClear, i18n("Clear"));
- keypadBasicsLayout->addWidget(kpClear, 0, 4);
- kpTimes = new QalculateButton("*", keypadPage);
- QToolTip::add(kpTimes, i18n("Multiply"));
- keypadBasicsLayout->addWidget(kpTimes, 1, 3);
- kpDivision = new QalculateButton("/", keypadPage);
- QToolTip::add(kpDivision, i18n("Divide"));
- keypadBasicsLayout->addWidget(kpDivision, 1, 4);
- kpPlus = new QalculateButton("+", keypadPage);
- QToolTip::add(kpPlus, i18n("Add"));
- keypadBasicsLayout->addWidget(kpPlus, 2, 3);
- kpMinus = new QalculateButton("-", keypadPage);
- QToolTip::add(kpMinus, i18n("Subtract"));
- keypadBasicsLayout->addWidget(kpMinus, 2, 4);
- kpAns = new QalculateButton(i18n("Ans"), keypadPage);
- QToolTip::add(kpAns, i18n("Previous result"));
- keypadBasicsLayout->addWidget(kpAns, 3, 3);
- if(rpn_mode) kpEquals = new QalculateButton(i18n("Ent"), keypadPage);
- else kpEquals = new QalculateButton(i18n("="), keypadPage);
- if(rpn_mode) QToolTip::add(kpEquals, i18n("Calculate expression and add to stack"));
- else QToolTip::add(kpEquals, i18n("Calculate expression"));
- keypadBasicsLayout->addWidget(kpEquals, 3, 4);
- keypadBottomLayout->addLayout(keypadBasicsLayout);
-
- keypadPageLayout->addLayout(keypadBottomLayout);
- keypadPageLayout->addWidget(new KSeparator(Qt::Horizontal, keypadPage));
- mainStack->addWidget(keypadPage, 0);
- historyPage = new QWidget(mainStack, "historyPage");
- QVBoxLayout *historyPageLayout = new QVBoxLayout(historyPage, 0, 0);
- historyBrowser = new QalculateHistoryBrowser(historyPage, "historyBrowser");
- historyBrowser->setTextFormat(KTextBrowser::RichText);
- historyBrowser->setWordWrap(KTextBrowser::NoWrap);
- historyPageLayout->addWidget(historyBrowser);
- mainStack->addWidget(historyPage, 1);
- stackPage = new QWidget(mainStack, "stackPage");
- QHBoxLayout *stackPageLayout = new QHBoxLayout(stackPage, 0, 6);
- stackList = new QalculateRPNStackListView(stackPage, "stackList");
- stackList->addColumn(i18n("Index"));
- stackList->addColumn(i18n("Value"));
- stackList->setColumnAlignment(0, Qt::AlignCenter);
- stackList->setColumnAlignment(1, Qt::AlignRight);
- stackList->setFullWidth(true);
- stackList->setResizeMode(QListView::LastColumn);
- stackList->setSelectionMode(QListView::Single);
- stackList->setAllColumnsShowFocus(true);
- stackList->setRootIsDecorated(false);
- stackList->setItemsMovable(true);
- stackList->setDragEnabled(true);
- stackList->setAcceptDrops(true);
- stackList->setSorting(-1);
- stackList->setItemsRenameable(true);
- stackList->setRenameable(1, true);
- stackList->setRenameable(0, false);
- stackPageLayout->addWidget(stackList);
- if(use_button_pixmaps) stackPageButtonsLayout = new QVBoxLayout(stackPageLayout, 3);
- else stackPageButtonsLayout = new QVBoxLayout(stackPageLayout, 6);
- if(use_button_pixmaps) registerUpButton = new QalculateButton(KApplication::kApplication()->iconLoader()->loadIconSet("up", KIcon::Small, ICON_SIZE_SMALL_MEDIUM), "", stackPage);
- else registerUpButton = new QalculateButton(i18n("Up"), stackPage);
- QToolTip::add(registerUpButton, i18n("Move selected register up"));
- registerUpButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed, false);
- stackPageButtonsLayout->addWidget(registerUpButton);
- if(use_button_pixmaps) registerDownButton = new QalculateButton(KApplication::kApplication()->iconLoader()->loadIconSet("down", KIcon::Small, ICON_SIZE_SMALL_MEDIUM), "", stackPage);
- else registerDownButton = new QalculateButton(i18n("Down"), stackPage);
- QToolTip::add(registerDownButton, i18n("Move selected register down"));
- registerDownButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed, false);
- stackPageButtonsLayout->addWidget(registerDownButton);
- if(use_button_pixmaps) editRegisterButton = new QalculateButton(KApplication::kApplication()->iconLoader()->loadIconSet("edit", KIcon::Small, ICON_SIZE_SMALL_MEDIUM), "", stackPage);
- else editRegisterButton = new QalculateButton(i18n("Edit"), stackPage);
- QToolTip::add(editRegisterButton, i18n("Edit value of selected register"));
- editRegisterButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed, false);
- stackPageButtonsLayout->addWidget(editRegisterButton);
- if(use_button_pixmaps) deleteRegisterButton = new QalculateButton(KApplication::kApplication()->iconLoader()->loadIconSet("editdelete", KIcon::Small, ICON_SIZE_SMALL_MEDIUM), "", stackPage);
- else deleteRegisterButton = new QalculateButton(i18n("Delete"), stackPage);
- QToolTip::add(deleteRegisterButton, i18n("Delete selected register"));
- deleteRegisterButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed, false);
- stackPageButtonsLayout->addWidget(deleteRegisterButton);
- if(use_button_pixmaps) clearStackButton = new QalculateButton(KApplication::kApplication()->iconLoader()->loadIconSet("view_remove", KIcon::Small, ICON_SIZE_SMALL_MEDIUM), "", stackPage);
- else clearStackButton = new QalculateButton(i18n("Clear"), stackPage);
- QToolTip::add(clearStackButton, i18n("Clear the RPN stack"));
- clearStackButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed, false);
- registerUpButton->setEnabled(false);
- registerDownButton->setEnabled(false);
- editRegisterButton->setEnabled(false);
- deleteRegisterButton->setEnabled(false);
- clearStackButton->setEnabled(false);
- stackPageButtonsLayout->addWidget(clearStackButton);
- stackPageButtonsLayout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding));
- mainStack->addWidget(stackPage, 2);
- updateButtonWidths();
- mainLayout->addWidget(mainStack);
-
- QHBoxLayout *bottomLayout = new QHBoxLayout(0, 0, 6);
- keypadButton = new QPushButton(i18n("Keypad"), centralWidget());
- QToolTip::add(keypadButton, i18n("Show/hide keypad"));
- keypadButton->setToggleButton(true);
- bottomLayout->addWidget(keypadButton);
- historyButton = new QPushButton(i18n("History"), centralWidget());
- QToolTip::add(historyButton, i18n("Show/hide history"));
- historyButton->setToggleButton(true);
- bottomLayout->addWidget(historyButton);
- stackButton = new QPushButton(i18n("RPN Stack"), centralWidget());
- QToolTip::add(stackButton, i18n("Show/hide RPN stack"));
- stackButton->setToggleButton(true);
- bottomLayout->addWidget(stackButton);
- if(!rpn_mode) stackButton->hide();
- bottomLayout->addItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
- mainLayout->addLayout(bottomLayout);
- connect(stackList, SIGNAL(selectionChanged()), this, SLOT(registerSelected()));
- connect(stackList, SIGNAL(itemRenamed(QListViewItem*)), this, SLOT(stackRegisterSet(QListViewItem*)));
- connect(stackList, SIGNAL(moved()), this, SLOT(stackRegisterMoved()));
- connect(stackList, SIGNAL(contextMenu(KListView*, QListViewItem*, const QPoint&)), this, SLOT(popupStackMenu(KListView*, QListViewItem*, const QPoint&)));
- connect(registerUpButton, SIGNAL(clicked()), this, SLOT(registerUp()));
- connect(registerDownButton, SIGNAL(clicked()), this, SLOT(registerDown()));
- connect(editRegisterButton, SIGNAL(clicked()), this, SLOT(editRegister()));
- connect(deleteRegisterButton, SIGNAL(clicked()), this, SLOT(deleteRegister()));
- connect(clearStackButton, SIGNAL(clicked()), this, SLOT(clearStack()));
- connect(stackButton, SIGNAL(toggled(bool)), this, SLOT(toggleStack(bool)));
- connect(historyButton, SIGNAL(toggled(bool)), this, SLOT(toggleHistory(bool)));
- connect(keypadButton, SIGNAL(toggled(bool)), this, SLOT(toggleKeypad(bool)));
- connect(kp0, SIGNAL(clicked()), this, SLOT(insertKP0()));
- connect(kp1, SIGNAL(clicked()), this, SLOT(insertKP1()));
- connect(kp2, SIGNAL(clicked()), this, SLOT(insertKP2()));
- connect(kp3, SIGNAL(clicked()), this, SLOT(insertKP3()));
- connect(kp4, SIGNAL(clicked()), this, SLOT(insertKP4()));
- connect(kp5, SIGNAL(clicked()), this, SLOT(insertKP5()));
- connect(kp6, SIGNAL(clicked()), this, SLOT(insertKP6()));
- connect(kp7, SIGNAL(clicked()), this, SLOT(insertKP7()));
- connect(kp8, SIGNAL(clicked()), this, SLOT(insertKP8()));
- connect(kp9, SIGNAL(clicked()), this, SLOT(insertKP9()));
- connect(kpDot, SIGNAL(clicked()), this, SLOT(insertDot()));
- connect(kpExp, SIGNAL(clicked()), this, SLOT(insertExp()));
- connect(kpAns, SIGNAL(clicked()), this, SLOT(insertAns()));
- connect(kpEquals, SIGNAL(clicked()), this, SLOT(execute()));
- connect(kpPlus, SIGNAL(clicked()), this, SLOT(insertPlus()));
- connect(kpMinus, SIGNAL(clicked()), this, SLOT(insertMinus()));
- connect(kpTimes, SIGNAL(clicked()), this, SLOT(insertTimes()));
- connect(kpDivision, SIGNAL(clicked()), this, SLOT(insertDivision()));
- connect(kpDel, SIGNAL(clicked()), this, SLOT(expressionDel()));
- connect(kpClear, SIGNAL(clicked()), this, SLOT(clearExpression()));
- connect(kpSin, SIGNAL(clicked()), this, SLOT(insertSin()));
- connect(kpCos, SIGNAL(clicked()), this, SLOT(insertCos()));
- connect(kpTan, SIGNAL(clicked()), this, SLOT(insertTan()));
- connect(kpSqrt, SIGNAL(clicked()), this, SLOT(insertSqrt()));
- connect(kpLog, SIGNAL(clicked()), this, SLOT(insertLog()));
- connect(kpLn, SIGNAL(clicked()), this, SLOT(insertLn()));
- connect(kpRaise, SIGNAL(clicked()), this, SLOT(insertRaise()));
- connect(kpSquare, SIGNAL(clicked()), this, SLOT(insertSquare()));
- connect(kpFraction, SIGNAL(toggled(bool)), this, SLOT(setFractionMode(bool)));
- connect(kpExact, SIGNAL(toggled(bool)), this, SLOT(setExactMode(bool)));
- connect(kpAngleGroup, SIGNAL(clicked(int)), this, SLOT(kpSetAngleUnit(int)));
- connect(kpBaseCombo->listBox(), SIGNAL(selected(int)), this, SLOT(kpSetBaseSelected(int)));
- connect(kpBaseCombo, SIGNAL(activated(int)), this, SLOT(kpSetBase(int)));
- connect(kpNumericCombo, SIGNAL(activated(int)), this, SLOT(kpSetNumericalMode(int)));
- //connect(kpMod, SIGNAL(clicked()), this, SLOT(insertMod()));
- connect(kpFactorial, SIGNAL(clicked()), this, SLOT(insertFactorial()));
- //connect(expressionEdit, SIGNAL(returnPressed()), this, SLOT(execute()));
- connect(expressionEdit, SIGNAL(textChanged(const QString&)), this, SLOT(onExpressionChanged()));
- connect(storeButton, SIGNAL(clicked()), this, SLOT(storeResult()));
- connect(executeButton, SIGNAL(clicked()), this, SLOT(execute()));
- connect(convertButton, SIGNAL(clicked()), this, SLOT(convertToUnitExpression()));
- connect(functionsButton, SIGNAL(clicked()), this, SLOT(manageFunctions()));
- connect(expressionEdit, SIGNAL(cursorMoved()), this, SLOT(displayParseStatus()));
- connect(expressionEdit->qalculateCompletionBox, SIGNAL(hidden()), statusLabel_l, SLOT(update()));
- //tab order
- setTabOrder(expressionEdit, resultLabel);
- setTabOrder(resultLabel, historyBrowser);
- setTabOrder(historyBrowser, keypadButton);
- setTabOrder(keypadButton, historyButton);
- setTabOrder(historyButton, stackButton);
- if(show_stack && rpn_mode) {
- bottomLine->hide();
- stackButton->setOn(true);
- mainStack->raiseWidget(2);
- mainStack->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding, false);
- resultLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum, false);
- } else if(show_keypad) {
- bottomLine->hide();
- keypadButton->setOn(true);
- mainStack->raiseWidget(0);
- mainStack->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum, false);
- resultLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding, false);
- } else if(show_history) {
- bottomLine->hide();
- historyButton->setOn(true);
- mainStack->raiseWidget(1);
- mainStack->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding, false);
- resultLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum, false);
- } else {
- mainStack->hide();
- mainStack->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum, false);
- resultLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding, false);
- }
-
- initial_history = "";
- for(QValueVector<QString>::size_type i = 0; i < inhistory.size(); i++) {
- switch(inhistory_type[i]) {
- case QALCULATE_HISTORY_EXPRESSION: {
- if(i != 0) {
- initial_history += "<br><hr>";
- }
- initial_history += "<a name=\"";
- initial_history += QString::number(inhistory_id[i]);
- initial_history += "\">";
- initial_history += inhistory[i];
- initial_history += "</a>";
- initial_history += " ";
- break;
- }
- case QALCULATE_HISTORY_REGISTER_MOVED: {
- if(i != 0) {
- initial_history += "<br><hr>";
- }
- initial_history += i18n("RPN Register Moved");
- initial_history += "<br>";
- break;
- }
- case QALCULATE_HISTORY_TRANSFORMATION: {
- initial_history += "<i>";
- initial_history += "<b>";
- initial_history += inhistory[i];
- initial_history += "</i>";
- initial_history += ": ";
- break;
- }
- case QALCULATE_HISTORY_RESULT: {
- initial_history += "<a name=\"";
- initial_history += QString::number(inhistory_id[i]);
- initial_history += "\">";
- initial_history += "= ";
- initial_history += "</a>";
- initial_history += "<b>";
- initial_history += "<a name=\"";
- initial_history += QString::number(inhistory_id[i]);
- initial_history += "\">";
- initial_history += inhistory[i];
- initial_history += "</a>";
- initial_history += "</b>";
- initial_history += "<br>";
- break;
- }
- case QALCULATE_HISTORY_RESULT_APPROXIMATE: {
- initial_history += "<a name=\"";
- initial_history += QString::number(inhistory_id[i]);
- initial_history += "\">";
- if(printops.use_unicode_signs && can_display_unicode_string_function(SIGN_ALMOST_EQUAL, (void*) historyBrowser)) {
- initial_history += SIGN_ALMOST_EQUAL " ";
- } else {
- initial_history += "= ";
- initial_history += i18n("approx.");
- initial_history += " ";
- }
- initial_history += "</a>";
- initial_history += "<b>";
- initial_history += "<a name=\"";
- initial_history += QString::number(inhistory_id[i]);
- initial_history += "\">";
- initial_history += inhistory[i];
- initial_history += "</a>";
- initial_history += "</b>";
- initial_history += "<br>";
- break;
- }
- case QALCULATE_HISTORY_PARSE: {
- initial_history += " = ";
- initial_history += "<font color=\"gray40\"><i>";
- initial_history += "<a name=\"";
- initial_history += QString::number(inhistory_id[i]);
- initial_history += "\">";
- initial_history += inhistory[i];
- initial_history += "</a>";
- initial_history += "</i></font>";
- initial_history += "<br>";
- break;
- }
- case QALCULATE_HISTORY_PARSE_APPROXIMATE: {
- initial_history += " ";
- if(printops.use_unicode_signs && can_display_unicode_string_function(SIGN_ALMOST_EQUAL, (void*) historyBrowser)) {
- initial_history += SIGN_ALMOST_EQUAL " ";
- } else {
- initial_history += "= ";
- initial_history += i18n("approx.");
- initial_history += " ";
- }
- initial_history += "<font color=\"gray40\"><i>";
- initial_history += "<a name=\"";
- initial_history += QString::number(inhistory_id[i]);
- initial_history += "\">";
- initial_history += inhistory[i];
- initial_history += "</a>";
- initial_history += "</i></font>";
- initial_history += "<br>";
- break;
- }
- case QALCULATE_HISTORY_WARNING: {
- initial_history += "<font color=\"blue\">";
- initial_history += "- ";
- initial_history += inhistory[i];
- initial_history += "</font>";
- initial_history += "<br>";
- break;
- }
- case QALCULATE_HISTORY_ERROR: {
- initial_history += "<font color=\"red\">";
- initial_history += "- ";
- initial_history += inhistory[i];
- initial_history += "</font>";
- initial_history += "<br>";
- break;
- }
- case QALCULATE_HISTORY_OLD: {
- initial_history += inhistory[i];
- initial_history += "<br>";
- break;
- }
- }
- }
- historyBrowser->setText(initial_history);
- initial_history = "";
- if(use_custom_result_font) {
- QFont new_font(resultLabel->font());
- new_font.fromString(custom_result_font);
- resultLabel->setFont(new_font);
- } else {
- resultLabel->unsetFont();
- }
- if(use_custom_expression_font) {
- QFont new_font(expressionEdit->font());
- new_font.fromString(custom_expression_font);
- expressionEdit->setFont(new_font);
- } else {
- expressionEdit->unsetFont();
- }
- updateStatusLabelFonts();
-
- set_unicode_buttons();
- setupActions();
- stackMenu = new QPopupMenu(this);
- ActionEditRegister->plug(stackMenu);
- ActionDeleteRegister->plug(stackMenu);
- stackMenu->insertSeparator();
- ActionClearStack->plug(stackMenu);
- update_status_text();
- bottomLine->setMinimumWidth(1000);
- createGUI("qalculate_kdeui.rc");
-
- menuBar()->sizeHint();
- int h = menuBar()->height();
- int w = 300;
- while(menuBar()->heightForWidth(w) > h && w < 1000) {
- w += 10;
- }
- if(w >= 1000) {
- bottomLine->setMinimumWidth(0);
- w = 0;
- } else {
- bottomLine->setMinimumWidth(w - 22);
- }
- if(!isShown()) adjustSize();
- setAutoSaveSettings();
-
- if(show_history || (rpn_mode && show_stack)) {
- resize(QSize(10, height()).expandedTo(minimumSizeHint()));
- } else if(show_keypad) {
- resize(minimumSizeHint());
- } else {
- resize(QSize(width(), 10).expandedTo(minimumSizeHint()));
- }
- menu_functions = (QPopupMenu*) factory()->container("functions", this);
- menu_variables = (QPopupMenu*) factory()->container("variables", this);
- menu_units = (QPopupMenu*) factory()->container("units", this);
- menu_to_unit = (QPopupMenu*) factory()->container("convert_to_unit", this);
- menu_set_prefix = (QPopupMenu*) factory()->container("set_prefix", this);
- menu_modes = (QPopupMenu*) factory()->container("modes", this);
-
- QObject::connect(menu_modes, SIGNAL(activated(int)), this, SLOT(onModesMenuItemActivated(int)));
- for(size_t i = 0; i < modes.size(); i++) {
- menu_modes->insertItem(modes[i].name, -1, i);
- if(i > 1) {
- ModeObject *mo = new ModeObject(i);
- mo->i_mode = i;
- mode_objects.push_back(mo);
- 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()));
- }
- }
- QObject::connect(menu_functions, SIGNAL(activated(int)), this, SLOT(onFunctionMenuItemActivated(int)));
- QObject::connect(menu_variables, SIGNAL(activated(int)), this, SLOT(onVariableMenuItemActivated(int)));
- QObject::connect(menu_units, SIGNAL(activated(int)), this, SLOT(onUnitMenuItemActivated(int)));
- QObject::connect(menu_to_unit, SIGNAL(activated(int)), this, SLOT(onConvertToUnitMenuItemActivated(int)));
- QObject::connect(menu_set_prefix, SIGNAL(activated(int)), this, SLOT(onSetPrefixMenuItemActivated(int)));
- }
- KQalculate::~KQalculate() {}
- void KQalculate::updateStatusLabelFonts() {
- if(use_custom_status_font) {
- QFont new_font(statusLabel_l->font());
- new_font.fromString(custom_status_font);
- statusLabel_l->setFont(new_font);
- new_font.setPointSizeFloat(new_font.pointSizeFloat() / 1.2);
- statusLabel_r->setFont(new_font);
- } else {
- statusLabel_l->unsetFont();
- statusLabel_r->unsetFont();
- QFont new_font = statusLabel_l->font();
- new_font.setPointSizeFloat(new_font.pointSizeFloat() / 1.2);
- statusLabel_l->setFont(new_font);
- new_font = statusLabel_r->font();
- new_font.setPointSizeFloat(new_font.pointSizeFloat() / 1.44);
- statusLabel_r->setFont(new_font);
- }
- }
- void KQalculate::updateButtonWidths() {
- int button_width = executeButton->sizeHint().width();
- if(storeButton->sizeHint().width() > button_width) button_width = storeButton->sizeHint().width();
- if(convertButton->sizeHint().width() > button_width) button_width = convertButton->sizeHint().width();
- if(registerUpButton->sizeHint().width() > button_width) button_width = registerUpButton->sizeHint().width();
- if(registerDownButton->sizeHint().width() > button_width) button_width = registerDownButton->sizeHint().width();
- if(editRegisterButton->sizeHint().width() > button_width) button_width = editRegisterButton->sizeHint().width();
- if(deleteRegisterButton->sizeHint().width() > button_width) button_width = deleteRegisterButton->sizeHint().width();
- if(clearStackButton->sizeHint().width() > button_width) button_width = clearStackButton->sizeHint().width();
- clearStackButton->setMinimumWidth(button_width);
- executeButton->setMinimumWidth(button_width);
- }
- void KQalculate::fontChange(const QFont &old_font) {
- updateStatusLabelFonts();
- functionsButton->unsetFont();
- QFont fb_font(functionsButton->font());
- fb_font.setItalic(true);
- functionsButton->setFont(fb_font);
- kpSquare->setMarkup(i18n("x<sup>2</sup>"));
- kpRaise->setMarkup(i18n("x<sup>y</sup>"));
- result_display_updated();
- KMainWindow::fontChange(old_font);
- updateButtonWidths();
- }
- void KQalculate::showSystemTrayIcon(bool do_show) {
- if(do_show && !trayicon) {
- trayicon = new KSystemTray(this);
- QObject::connect(trayicon, SIGNAL(quitSelected()), qApp, SLOT(quit()));
- #if KDE_VERSION_MAJOR < 4 && KDE_VERSION_MINOR < 2
- trayicon->setPixmap(loadSystrayIcon(PACKAGE));
- #else
- trayicon->setPixmap(trayicon->loadIcon(PACKAGE));
- #endif
- #if KDE_VERSION_MAJOR > 3 || KDE_VERSION_MINOR >= 2
- KPopupMenu* traypop = trayicon->contextMenu();
- ActionHideSystemTrayIcon->plug(traypop, 1);
- #endif
- QToolTip::add(trayicon, i18n("Qalculate! - Scientific Calculator"));
- }
- if(do_show) {
- trayicon->show();
- } else if(trayicon) {
- trayicon->hide();
- }
- }
- void KQalculate::hideSystemTrayIcon() {
- showSystemTrayIcon(false);
- close_to_systray = false;
- show();
- }
- #define SET_TOGGLE_ACTION(action, value) action->blockSignals(true); action->setChecked(value); action->blockSignals(false);
- #define SET_TOGGLE_ACTION_ON(action) action->blockSignals(true); action->setChecked(true); action->blockSignals(false);
- void KQalculate::setupActions() {
- ActionNewVariable = new KAction(i18n("Variable"), "filenew", 0, this, SLOT(newVariable()), actionCollection(), "new_variable");
- ActionNewMatrix = new KAction(i18n("Matrix"), "filenew", 0, this, SLOT(newMatrix()), actionCollection(), "new_matrix");
- ActionNewVector = new KAction(i18n("Vector"), "filenew", 0, this, SLOT(newVector()), actionCollection(), "new_vector");
- ActionNewUnknownVariable = new KAction(i18n("Unknown Variable"), "filenew", 0, this, SLOT(newUnknownVariable()), actionCollection(), "new_unknown_variable");
- ActionNewFunction = new KAction(i18n("Function"), "filenew", 0, this, SLOT(newFunction()), actionCollection(), "new_function");
- ActionNewDataSet = new KAction(i18n("Data Set"), "filenew", 0, this, SLOT(newDataSet()), actionCollection(), "new_data_set");
- ActionNewUnit = new KAction(i18n("Unit"), "filenew", 0, this, SLOT(newUnit()), actionCollection(), "new_unit");
- ActionImportCSVFile = new KAction(i18n("Import CSV File..."), "fileimport", 0, this, SLOT(importCSVFile()), actionCollection(), "import_csv_file");
- ActionExportCSVFile = new KAction(i18n("Export CSV File..."), "filexport", 0, this, SLOT(exportCSVFile()), actionCollection(), "export_csv_file");
- ActionStoreResult = new KAction(i18n("Store Result..."), "filesave", CTRL+Key_S, this, SLOT(storeResult()), actionCollection(), "store_result");
- ActionSaveAsImage = new KAction(i18n("Save Result Image..."), "filesave", 0, this, SLOT(saveAsImage()), actionCollection(), "save_as_image");
- ActionSaveDefinitions = new KAction(i18n("Save Definitions"), "filesave", 0, this, SLOT(saveDefinitions()), actionCollection(), "save_definitions");
- ActionUpdateExchangeRates = new KAction(i18n("Update Exchange Rates"), "reload", 0, this, SLOT(updateExchangeRates()), actionCollection(), "update_exchange_rates");
- ActionPlotFunctionsData = new KAction(i18n("Plot Functions/Data"), 0, this, SLOT(plotFunctionsData()), actionCollection(), "plot_functions_data");
- ActionPlotFunctionsData->setEnabled(canplot);
- ActionConvertNumberBases = new KAction(i18n("Convert Number Bases"), 0, this, SLOT(convertNumberBases()), actionCollection(), "convert_number_bases");
- ActionPeriodicTable = new KAction(i18n("Periodic Table"), 0, this, SLOT(periodicTable()), actionCollection(), "periodic_table");
- if(close_to_systray) {
- ActionClose = KStdAction::close(this, SLOT(close()), actionCollection());
- } else {
- ActionClose = NULL;
- }
- globalAccel = new KGlobalAccel(this);
- globalAccel->insert("Show/hide Qalculate!", i18n("Show/hide main Qalculate! window"), QString::null, KShortcut(), KShortcut(), this, SLOT(showHide()));
- globalAccel->readSettings();
- globalAccel->updateConnections();
- ActionConfigureGlobalShortcuts = new KAction(i18n("Configure &Global Shortcuts..."), "configure_shortcuts", 0, this, SLOT(configureGlobalShortcuts()), actionCollection(), "configure_global_shortcuts");
- ActionQuit = KStdAction::quit(qApp, SLOT(quit()), actionCollection());
- ActionManageVariables = new KAction(i18n("Manage Variables"), Key_F2, this, SLOT(manageVariables()), actionCollection(), "manage_variables");
- ActionManageFunctions = new KAction(i18n("Manage Functions"), Key_F3, this, SLOT(manageFunctions()), actionCollection(), "manage_functions");
- ActionManageUnits = new KAction(i18n("Manage Units"), Key_F4, this, SLOT(manageUnits()), actionCollection(), "manage_units");
- ActionManageDataSets = new KAction(i18n("Manage Data Sets"), 0, this, SLOT(manageDataSets()), actionCollection(), "manage_data_sets");
- ActionFactorize = new KAction(i18n("Factorize"), 0, this, SLOT(factorize()), actionCollection(), "factorize");
- ActionSimplify = new KAction(i18n("Simplify"), 0, this, SLOT(simplify()), actionCollection(), "simplify");
- ActionSetUnknowns = new KAction(i18n("Set Unknowns..."), 0, this, SLOT(setUnknowns()), actionCollection(), "set_unknowns");
- ActionConvertToUnitExpression = new KAction(i18n("Convert to Unit Expression..."), CTRL+Key_T, this, SLOT(convertToUnitExpression()), actionCollection(), "convert_to_unit_expression");
- ActionConvertToBaseUnits = new KAction(i18n("Convert to Base Units"), 0, this, SLOT(convertToBaseUnits()), actionCollection(), "convert_to_base_units");
- ActionConvertToBestUnit = new KAction(i18n("Convert to Best Unit"), 0, this, SLOT(convertToBestUnit()), actionCollection(), "convert_to_best_unit");
- ActionInsertMatrix = new KAction(i18n("Insert Matrix..."), 0, this, SLOT(insertMatrix()), actionCollection(), "insert_matrix");
- ActionInsertVector = new KAction(i18n("Insert Vector..."), 0, this, SLOT(insertVector()), actionCollection(), "insert_vector");
- ActionCopyResult = new KAction(i18n("Copy Result"), "editcopy", Key_F5, this, SLOT(copyResult()), actionCollection(), "copy_result");
- ActionClearHistory = new KAction(i18n("Clear History"), "editclear", 0, this, SLOT(clearHistory()), actionCollection(), "clear_history");
- ActionPreferences = new KAction(i18n("Configure Qalculate!"), "configure", 0, this, SLOT(preferences()), actionCollection(), "preferences");
- KStdAction::keyBindings(guiFactory(), SLOT(configureShortcuts()), actionCollection(), "keybindings");
- ActionNumberBaseBinary = new KRadioAction(i18n("Binary"), 0, this, SLOT(numberBaseBinary()), actionCollection(), "number_base_binary");
- ActionNumberBaseBinary->setExclusiveGroup("group_number_base");
- ActionNumberBaseOctal = new KRadioAction(i18n("Octal"), 0, this, SLOT(numberBaseOctal()), actionCollection(), "number_base_octal");
- ActionNumberBaseOctal->setExclusiveGroup("group_number_base");
- ActionNumberBaseDecimal = new KRadioAction(i18n("Decimal"), 0, this, SLOT(numberBaseDecimal()), actionCollection(), "number_base_decimal");
- ActionNumberBaseDecimal->setExclusiveGroup("group_number_base");
- ActionNumberBaseHexadecimal = new KRadioAction(i18n("Hexadecimal"), 0, this, SLOT(numberBaseHexadecimal()), actionCollection(), "number_base_hexadecimal");
- ActionNumberBaseHexadecimal->setExclusiveGroup("group_number_base");
- ActionNumberBaseOther = new KRadioAction(i18n("Other..."), 0, this, SLOT(numberBaseOther()), actionCollection(), "number_base_other");
- ActionNumberBaseOther->setExclusiveGroup("group_number_base");
- ActionNumberBaseSexagesimal = new KRadioAction(i18n("Sexagesimal"), 0, this, SLOT(numberBaseSexagesimal()), actionCollection(), "number_base_sexagesimal");
- ActionNumberBaseSexagesimal->setExclusiveGroup("group_number_base");
- ActionNumberBaseTimeFormat = new KRadioAction(i18n("Time Format"), 0, this, SLOT(numberBaseTimeFormat()), actionCollection(), "number_base_time_format");
- ActionNumberBaseTimeFormat->setExclusiveGroup("group_number_base");
- ActionNumberBaseRomanNumerals = new KRadioAction(i18n("Roman Numerals"), 0, this, SLOT(numberBaseRomanNumerals()), actionCollection(), "number_base_roman_numerals");
- ActionNumberBaseRomanNumerals->setExclusiveGroup("group_number_base");
- ActionSetBase = new KAction(i18n("Select Result and Expression Base..."), CTRL+Key_B, this, SLOT(setBase()), actionCollection(), "set_base");
- ActionNumericalDisplayNormal = new KRadioAction(i18n("Normal"), 0, this, SLOT(numericalDisplayNormal()), actionCollection(), "numerical_display_normal");
- ActionNumericalDisplayNormal->setExclusiveGroup("group_numberical_display");
- ActionNumericalDisplayEngineering = new KRadioAction(i18n("Engineering"), 0, this, SLOT(numericalDisplayEngineering()), actionCollection(), "numerical_display_engineering");
- ActionNumericalDisplayEngineering->setExclusiveGroup("group_numberical_display");
- ActionNumericalDisplayScientific = new KRadioAction(i18n("Scientific"), 0, this, SLOT(numericalDisplayScientific()), actionCollection(), "numerical_display_scientific");
- ActionNumericalDisplayScientific->setExclusiveGroup("group_numberical_display");
- ActionNumericalDisplayPurelyScientific = new KRadioAction(i18n("Purely Scientific"), 0, this, SLOT(numericalDisplayPurelyScientific()), actionCollection(), "numerical_display_purely_scientific");
- ActionNumericalDisplayPurelyScientific->setExclusiveGroup("group_numberical_display");
- ActionNumericalDisplaySimple = new KRadioAction(i18n("Simple"), 0, this, SLOT(numericalDisplaySimple()), actionCollection(), "numerical_display_simple");
- ActionNumericalDisplaySimple->setExclusiveGroup("group_numberical_display");
- ActionIndicateInfiniteSeries = new KToggleAction(i18n("Indicate Infinite Series"), 0, actionCollection(), "indicate_infinite_series");
- QObject::connect(ActionIndicateInfiniteSeries, SIGNAL(toggled(bool)), this, SLOT(indicateInfiniteSeries(bool)));
- ActionSortMinusLast = new KToggleAction(i18n("Sort Minus Last"), 0, actionCollection(), "sort_minus_last");
- QObject::connect(ActionSortMinusLast, SIGNAL(toggled(bool)), this, SLOT(sortMinusLast(bool)));
- ActionNegativeExponents = new KToggleAction(i18n("Negative Exponents"), 0, actionCollection(), "negative_exponents");
- QObject::connect(ActionNegativeExponents, SIGNAL(tog…
Large files files are truncated, but you can click here to view the full file