diff options
author | Slávek Banko <slavek.banko@axis.cz> | 2016-04-09 15:59:57 +0200 |
---|---|---|
committer | Slávek Banko <slavek.banko@axis.cz> | 2016-04-09 15:59:57 +0200 |
commit | ee0c9d4bc3e25a409b3127be2876079f69719978 (patch) | |
tree | 04d895b486c04df1fe2e5dedb7cd5705eff06a9b /src/kqalculate.h | |
download | qalculate-tde-ee0c9d4bc3e25a409b3127be2876079f69719978.tar.gz qalculate-tde-ee0c9d4bc3e25a409b3127be2876079f69719978.zip |
Initial import of qalculate-kde 0.9.7
Diffstat (limited to 'src/kqalculate.h')
-rw-r--r-- | src/kqalculate.h | 593 |
1 files changed, 593 insertions, 0 deletions
diff --git a/src/kqalculate.h b/src/kqalculate.h new file mode 100644 index 0000000..fb016e0 --- /dev/null +++ b/src/kqalculate.h @@ -0,0 +1,593 @@ +/*************************************************************************** + * 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. * + ***************************************************************************/ + +#ifndef KQALCULATE_H +#define KQALCULATE_H + +#include <qvariant.h> +#include <kmainwindow.h> +#include <qvaluevector.h> +#include <qlabel.h> +#include <qpushbutton.h> +#include <qstylesheet.h> +#include <ktextbrowser.h> +#include <klistview.h> +#include <kdialogbase.h> +#include <kshortcut.h> + +class Prefix; +class QalculatePrecisionDialog; +class Variable; +class MathFunction; +class Unit; +class QalculateDecimalsDialog; +class QalculateEditVariableDialog; +class QalculateEditMatrixVectorDialog; +class QalculateEditUnitDialog; +class QalculateEditFunctionDialog; +class QalculateEditDataSetDialog; +class QalculateEditUnknownVariableDialog; +class QalculateVariablesDialog; +class QalculateFunctionsDialog; +class QalculateUnitsDialog; +class QalculateDataSetsDialog; +class QalculateConvertUnitsDialog; +class KAction; +class KRadioAction; +class KToggleAction; +class QToolBar; +class QPopupMenu; +class KPushButton; +class QalculateExpressionEdit; +class QalculateResultDisplay; +class QFrame; +class QWidgetStack; +class QWidget; +class QComboBox; +class QalculateHistoryBrowser; +class QalculateConvertNumberBasesDialog; +class QalculatePeriodicTableDialog; +class QalculatePlotDialog; +class QalculateSetBaseDialog; +class KLineEdit; +class MathStructure; +class QalculateImportCSVDialog; +class QalculateExportCSVDialog; +class QalculatePreferencesDialog; +class QalculateInsertMatrixVectorDialog; +class KSystemTray; +class QalculateParseLabel; +class QButtonGroup; +class QRadioButton; +class QalculateButton; +class QVBoxLayout; +class KSeparator; +class KUniqueApplication; +class KConfig; +class QListViewItem; +class QalculateRPNStackListView; +class KGlobalAccel; +class KKeyButton; + +void *view_proc(void *pipe); +void *command_proc(void *pipe); + +enum { + COMMAND_FACTORIZE, + COMMAND_SIMPLIFY +}; + + +class ModeObject : public QObject { + + Q_OBJECT + + public: + + ModeObject(int mode); + int i_mode; + + public slots: + + void loadMode(); + +}; + +class KQalculate : public KMainWindow { + + Q_OBJECT + +public: + + KQalculate(KUniqueApplication *parent = 0, const char* name = 0, WFlags fl = WType_TopLevel | WDestructiveClose); + virtual ~KQalculate(); + + void setupActions(); + void setAssumptionsMenu(); + void setModeActions(); + void execute_expression(bool force = true); + void setResult(Prefix *prefix = NULL, bool update_history = true, bool update_parse = false, bool force = false, QString transformation = "", size_t stack_index = 0, bool register_moved = false); + void executeCommand(int command_type); + void result_display_updated(); + void result_format_updated(); + void result_action_executed(); + void result_prefix_changed(Prefix *prefix = NULL); + void expression_calculation_updated(); + void expression_format_updated(bool recalculate = false); + void display_errors(QString *new_text = NULL, int *inhistory_index = NULL); + void update_status_text(); + void display_function_hint(MathFunction *f, int arg_index = 1); + void clearresult(); + void create_fmenu(); + void create_vmenu(); + void create_umenu(); + void create_toumenu(); + void create_setpmenu(); + void recreate_recent_functions(); + void recreate_recent_variables(); + void recreate_recent_units(); + void function_inserted(MathFunction *object); + void variable_inserted(Variable *object); + void unit_inserted(Unit *object); + void updateStatusLabelFonts(); + void set_unicode_buttons(); + void insertButtonFunction(QString text, bool append_space = true); + void insertButtonFunction(MathFunction *f); + const MathStructure *getResultPart(int); + void insertMatrixVector(const MathStructure *m = NULL, bool do_vector = false, bool is_text_struct = false, bool is_result = false); + + void calculateRPN(int op); + void calculateRPN(MathFunction *f); + void RPNStackEnter(Variable *v); + void RPNRegisterAdded(const QString &text, size_t index = 0); + void RPNRegisterRemoved(size_t index); + void RPNRegisterChanged(const QString &text, size_t index = 0); + + QalculateInsertMatrixVectorDialog *insert_matrix_dialog; + QalculatePrecisionDialog *precisionDialog; + QalculateDecimalsDialog *decimalsDialog; + QalculateConvertUnitsDialog *convert_to_unit_expression_dialog; + QalculateEditVariableDialog *variable_edit_dialog, *store_dialog; + QalculateEditMatrixVectorDialog *matrix_edit_dialog; + QalculateEditUnitDialog *unit_edit_dialog; + QalculateEditFunctionDialog *function_edit_dialog; + QalculateEditDataSetDialog *dataset_edit_dialog; + QalculateEditUnknownVariableDialog *unknown_edit_dialog; + QalculateVariablesDialog *variables_dialog; + QalculateFunctionsDialog *functions_dialog; + QalculateUnitsDialog *units_dialog; + QalculateDataSetsDialog *datasets_dialog; + QalculateConvertNumberBasesDialog *convert_number_bases_dialog; + QalculatePeriodicTableDialog *periodic_table_dialog; + QalculateImportCSVDialog *import_csv_dialog; + QalculateExportCSVDialog *export_csv_dialog; + QalculatePlotDialog *plot_dialog; + QalculateSetBaseDialog *set_base_dialog; + QalculatePreferencesDialog *preferences_dialog; + QMap <int, Variable*> menu_variables_ids; + QMap <int, MathFunction*> menu_functions_ids; + QMap <int, Unit*> menu_units_ids, menu_to_unit_ids; + QMap <int, Prefix*> menu_units_prefixes_ids, menu_set_prefix_ids; + QValueVector<int> recent_function_ids; + QValueVector<int> recent_variable_ids; + QValueVector<int> recent_unit_ids; + + QalculateRPNStackListView *stackList; + QVBoxLayout *stackPageButtonsLayout; + QalculateButton *registerUpButton, *registerDownButton, *deleteRegisterButton, *editRegisterButton, *clearStackButton; + QPopupMenu *stackMenu; + KUniqueApplication *m_parent; + KSystemTray *trayicon; + QalculateButton *executeButton, *storeButton, *convertButton; + QalculateButton *functionsButton; + QVBoxLayout *leftButtonsLayout; + KSeparator *leftButtonsSeparator; + QalculateExpressionEdit* expressionEdit; + QLabel *statusLabel_r; + QalculateParseLabel *statusLabel_l; + QalculateResultDisplay* resultLabel; + QWidgetStack* mainStack; + QFrame *bottomLine; + QWidget *keypadPage, *historyPage, *stackPage; + QComboBox* kpNumericCombo, *kpBaseCombo; + QRadioButton *kpDegreesButton, *kpRadiansButton, *kpGradiansButton, *kpNoAngleUnitButton; + QButtonGroup *kpAngleGroup; + QPushButton *kpExact, *kpFraction; + QalculateButton *kpSquare, *kpLog, *kpHyp, *kpSqrt, *kpCos, *kpRaise, *kpInv, *kpSin; + QalculateButton *kpTan, *kpLn, *kpFactorial, *kpMod, *kpAns, *kp8, *kp0, *kp7, *kpDel, *kpDot, *kp5, *kpEquals, *kpClear; + QalculateButton *kp3, *kp1, *kp4, *kp9, *kpDivision, *kpExp, *kp6, *kp2, *kpMinus, *kpTimes, *kpPlus; + QalculateHistoryBrowser *historyBrowser; + QPushButton *historyButton, *keypadButton, *stackButton; + KMenuBar *menubar; + QPopupMenu *menu_functions, *menu_variables, *menu_units, *menu_to_unit, *menu_set_prefix, *menu_modes; + KToggleAction *ActionAbbreviateNames, *ActionReadPrecision, *ActionNonZeroDenominators, *ActionWarnAboutDenominatorsAssumedNonZero; + KToggleAction *ActionLimitImplicitMultiplication, *ActionRPNMode, *ActionRPNSyntax, *ActionIndicateInfiniteSeries, *ActionNegativeExponents, *ActionSortMinusLast; + KToggleAction *ActionShowEndingZeroes, *ActionRoundHalfwayNumbersToEven, *ActionEnablePrefixes; + KToggleAction *ActionEnableUseOfAllPrefixes, *ActionEnableDenominatorPrefixes, *ActionPlaceUnitsSeparately; + KToggleAction *ActionEnableVariables, *ActionEnableFunctions, *ActionEnableUnits, *ActionEnableUnknowns; + KToggleAction *ActionCalculateVariables, *ActionAllowComplexResult, *ActionAllowInfiniteResult; + KRadioAction *ActionApproximationAlwaysExact, *ActionApproximationTryExact, *ActionApproximationApproximate; + KRadioAction *ActionAlgebraicModeSimplify, *ActionAlgebraicModeFactorize, *ActionAlgebraicModeNone; + KRadioAction *ActionFractionalDisplayDecimal, *ActionFractionalDisplayDecimalTryExact; + KRadioAction *ActionFractionalDisplayFraction, *ActionFractionalDisplayCombined; + KRadioAction *ActionNumericalDisplayEngineering, *ActionNumericalDisplayScientific, *ActionNumericalDisplayPurelyScientific, *ActionNumericalDisplaySimple, *ActionNumericalDisplayNormal; + KRadioAction *ActionNumberBaseBinary, *ActionNumberBaseOctal, *ActionNumberBaseDecimal, *ActionNumberBaseHexadecimal, *ActionNumberBaseOther; + KRadioAction *ActionNumberBaseSexagesimal, *ActionNumberBaseTimeFormat, *ActionNumberBaseRomanNumerals; + KRadioAction *ActionAssumptionTypeUnknown, *ActionAssumptionTypeNonMatrix, *ActionAssumptionTypeNumber, *ActionAssumptionTypeComplex, *ActionAssumptionTypeReal; + KRadioAction *ActionAssumptionTypeRational, *ActionAssumptionTypeInteger, *ActionAssumptionSignUnknown, *ActionAssumptionSignNonZero; + KRadioAction *ActionAssumptionSignPositive, *ActionAssumptionSignNonNegative, *ActionAssumptionSignNegative; + KRadioAction *ActionAssumptionSignNonPositive, *ActionAngleUnitDegrees, *ActionAngleUnitRadians, *ActionAngleUnitGradians; + KRadioAction *ActionAngleUnitNone, *ActionAutoNoConversion, *ActionAutoConvertToBaseUnits, *ActionAutoConvertToBestUnit; + KAction *ActionSetBase, *ActionPrecision, *ActionDecimals, *ActionSaveModeAs, *ActionDeleteMode, *ActionSaveMode, *ActionQuit; + KAction *ActionUpdateExchangeRates, *ActionManageVariables, *ActionConvertToUnitExpression, *ActionStoreResult, *ActionClose; + KAction *ActionConvertNumberBases, *ActionManageFunctions, *ActionConvertToBaseUnits, *ActionConvertToBestUnit; + KAction *ActionManageUnits, *ActionManageDataSets, *ActionFactorize, *ActionSimplify, *ActionSetUnknowns, *ActionCopyResult; + KAction *ActionPreferences, *ActionSaveAsImage, *ActionImportCSVFile, *ActionExportCSVFile, *ActionPeriodicTable; + KAction *ActionPlotFunctionsData, *ActionSaveDefinitions, *ActionNewVariable, *ActionNewMatrix, *ActionNewVector; + KAction *ActionNewUnknownVariable, *ActionNewFunction, *ActionNewUnit, *ActionNewDataSet; + KAction *ActionInsertMatrix, *ActionInsertVector; + KAction *ActionClearHistory; + KAction *ActionHideSystemTrayIcon, *ActionHide; + KAction *ActionClearStack, *ActionDeleteRegister, *ActionEditRegister; + KAction *ActionConfigureGlobalShortcuts; + + KGlobalAccel *globalAccel; + + QValueVector<int>::size_type current_history_index; + QValueVector<ModeObject*> mode_objects; + +public slots: + + void executeCommand2(); + void setResult2(); + void execute_expression2(); + + void showHide(); + void configureGlobalShortcuts(); + + void update_fmenu(); + void update_vmenu(); + void update_umenus(); + void insertVariable(Variable*); + void insertFunction(MathFunction*, QWidget *parent); + void applyFunction(MathFunction*, QWidget *parent); + void onExpressionChanged(); + void onErrorTimeout(); + bool fetch_exchange_rates(int); + void update_completion(); + void insert_text(QString); + void aboutToQuit(); + void onVariableMenuItemActivated(int); + void onFunctionMenuItemActivated(int); + void onUnitMenuItemActivated(int); + void onUnitsPrefixMenuItemActivated(int); + void precisionRecalculate(); + void setMaxDecimals(int); + void setMinDecimals(int); + void execute(); + void toggleHistory(bool); + void toggleStack(bool); + void toggleKeypad(bool); + void showEndingZeroes(bool); + void approximationTryExact(); + void approximationAlwaysExact(); + void approximationApproximate(); + void fractionalDisplayDecimal(); + void fractionalDisplayDecimalTryExact(); + void fractionalDisplayFraction(); + void fractionalDisplayCombined(); + void numericalDisplayNormal(); + void numericalDisplayEngineering(); + void numericalDisplayScientific(); + void numericalDisplayPurelyScientific(); + void numericalDisplaySimple(); + void indicateInfiniteSeries(bool); + void sortMinusLast(bool); + void negativeExponents(bool); + void roundHalfwayNumbersToEven(bool); + void abbreviateNames(bool); + void updateBaseOther(); + void numberBaseBinary(); + void numberBaseOctal(); + void numberBaseDecimal(); + void numberBaseOther(); + void numberBaseHexadecimal(); + void numberBaseSexagesimal(); + void numberBaseTimeFormat(); + void numberBaseRomanNumerals(); + void setBaseInResultFromDialogGroup(int); + void setBaseInResultFromDialogBox(int); + void setBaseInExpressionFromDialogGroup(int); + void setBaseInExpressionFromDialogBox(int); + void setBase(); + void nonZeroDenominators(bool); + void warnAboutDenominatorsAssumedNonZero(bool); + void algebraicModeSimplify(); + void algebraicModeFactorize(); + void algebraicModeNone(); + void readPrecision(bool); + void limitImplicitMultiplication(bool); + void setPrecision(int); + void precision(); + void decimals(); + void rpnMode(bool); + void rpnSyntax(bool); + void assumptionSignUnknown(); + void assumptionSignNonZero(); + void assumptionSignPositive(); + void assumptionSignNonNegative(); + void assumptionSignNegative(); + void assumptionSignNonPositive(); + void assumptionTypeUnknown(); + void assumptionTypeNonMatrix(); + void assumptionTypeNumber(); + void assumptionTypeComplex(); + void assumptionTypeReal(); + void assumptionTypeRational(); + void assumptionTypeInteger(); + void loadMode(int); + void onModesMenuItemActivated(int); + void saveModeAs(); + void deleteMode(); + void saveMode(); + void angleUnitDegrees(); + void angleUnitRadians(); + void angleUnitGradians(); + void angleUnitNone(); + void autoNoConversion(); + void autoConvertToBaseUnits(); + void autoConvertToBestUnit(); + void enablePrefixes(bool); + void enableUseOfAllPrefixes(bool); + void enableDenominatorPrefixes(bool); + void placeUnitsSeparately(bool); + void enableVariables(bool); + void enableFunctions(bool); + void enableUnits(bool); + void enableUnknowns(bool); + void calculateVariables(bool); + void allowComplexResult(bool); + void allowInfiniteResult(bool); + void updateExchangeRates(); + void insertKP1(); + void insertKP2(); + void insertKP3(); + void insertKP4(); + void insertKP5(); + void insertKP6(); + void insertKP7(); + void insertKP8(); + void insertKP9(); + void insertKP0(); + void insertDot(); + void insertExp(); + void insertAns(); + void insertMinus(); + void insertPlus(); + void insertTimes(); + void insertDivision(); + void insertCos(); + void insertSin(); + void insertTan(); + void insertSqrt(); + void insertLog(); + void insertLn(); + void insertRaise(); + void clearExpression(); + void expressionDel(); + void insertSquare(); + void setExactMode(bool); + void setFractionMode(bool); + void kpSetAngleUnit(int); + void kpSetBaseSelected(int); + void kpSetBase(int); + void kpSetNumericalMode(int); + void insertFactorial(); + void insertMod(); + void storeResult(); + void manageVariables(); + void convertToUnitConvertToDialogExpression(); + void convertToUnitExpression(); + void convertNumberBases(); + void insertManagedFunction(MathFunction*); + void applyManagedFunction(MathFunction*); + void manageFunctions(); + void manageUnits(); + void insertUnit(Unit *u); + void convertResult(Unit *u); + void factorize(); + void simplify(); + void manageDataSets(); + void setUnknownsApplyClicked(); + void setUnknowns(); + void convertToBaseUnits(); + void convertToBestUnit(); + void copyResult(); + void clearHistory(); + void preferences(); + void applyPreferences(); + void onConvertToUnitMenuItemActivated(int); + void onSetPrefixMenuItemActivated(int); + void periodicTable(); + void plotFunctionsData(); + void saveDefinitions(); + void saveAsImage(); + void importCSVFile(); + void exportCSVFile(); + void newVariable(); + void newMatrix(); + void newVector(); + void newUnknownVariable(); + void newFunction(); + void newDataSet(); + void newUnit(); + void insertMatrix(); + void insertVector(); + void showSystemTrayIcon(bool); + void hideSystemTrayIcon(); + void displayParseStatus(); + void registerUp(); + void registerDown(); + void clearStack(); + void deleteRegister(); + void editRegister(); + void updateRPNIndexes(); + QListViewItem *getRPNRegister(size_t index); + void stackRegisterMoved(); + void stackRegisterSet(QListViewItem*); + void popupStackMenu(KListView*, QListViewItem*, const QPoint&); + void registerSelected(); + void editHistoryExpression(); + void editHistoryParse(); + void editHistoryResult(); + void insertHistoryResultVariable(); + +protected: + + void updateButtonWidths(); + void applySetUnknowns(bool okclicked); + bool b_unknowns_changed; + QValueVector<bool> unknown_changed; + MathStructure *mstruct_before_unknowns, *unknowns_mstruct; + QValueVector<KLineEdit*> unknowns_entries; + bool queryClose(); + QString parsed_expression; + void keyPressEvent(QKeyEvent *e); + void fontChange(const QFont &old_font); + void saveProperties(KConfig *cfg); + void readProperties(KConfig *cfg); + +private: + + bool close_to_systray_was; + bool display_expression_status_was; + int history_height; + +}; + +class QalculateHistoryBrowser : public KTextBrowser { + + Q_OBJECT + +public: + + QalculateHistoryBrowser(QWidget *parent, const char *name); + ~QalculateHistoryBrowser(); + +protected: + + QPopupMenu *createPopupMenu(const QPoint &pos); + +}; + +class QalculateParseLabel : public QLabel { + + Q_OBJECT + +public: + + QalculateParseLabel(QWidget *parent = 0, const char *name = 0); + virtual ~QalculateParseLabel(); + + void setText(QString text, bool break_begin, bool error_color, bool warning_color); + +protected: + + QString parsetext; + bool bb, ec, wc; + void drawContents(QPainter *p); + +}; + +class QalculateButton : public QPushButton { + + Q_OBJECT + +public: + + QalculateButton(QWidget *parent = 0, const char *name = 0); + QalculateButton(const QString &text, QWidget *parent = 0, const char *name = 0); + QalculateButton(const QIconSet &icon, const QString &text, QWidget *parent = 0, const char *name = 0); + virtual ~QalculateButton(); + + void setUseMinThreeCharWidth(bool b); + void setMarkup(const QString &str); + QSize sizeHint() const; + +private: + + bool umtcw; + +}; + +class QalculateStyleSheet : public QStyleSheet { + + Q_OBJECT + +public: + + QalculateStyleSheet(QObject *parent = 0, const char *name = 0); + virtual ~QalculateStyleSheet(); + + void scaleFont(QFont &font, int logicalSize) const; + +}; + +class QalculateRPNStackListView : public KListView { + + Q_OBJECT + +public: + + QalculateRPNStackListView(QWidget *parent = 0, const char *name = 0); + virtual ~QalculateRPNStackListView(); + +protected: + + void keyPressEvent(QKeyEvent *e); + +}; + +class QalculateModeDialog : public KDialogBase { + + Q_OBJECT + + protected: + + KKeyButton *keyButton; + KComboBox *modeCombo; + + public: + + QalculateModeDialog(QWidget *parent); + virtual ~QalculateModeDialog(); + + QString modeName(); + const KShortcut &modeShortcut(); + + public slots: + + void slotOk(); + void updateShortcut(const KShortcut&); + void modeSelected(int); + +}; + +#endif // QALCULATE_KWINDOW_H |