Logo Search packages:      
Sourcecode: qalculate-kde version File versions  Download package

kqalculate.h

/***************************************************************************
 *   Copyright (C) 2005 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>

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 KPopupMenu;
class KPushButton;
class QalculateExpressionEdit;
class QalculateResultDisplay;
class QFrame;
class QWidgetStack;
class QWidget;
class QComboBox;
class QalculateHistoryBrowser;
class QalculateConvertNumberBasesDialog;
class QalculatePeriodicTableDialog;
class QalculatePlotDialog;
class QalculateSetBaseInExpressionDialog;
class QalculateSetBaseOtherDialog;
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;

void *view_proc(void *pipe);
void *command_proc(void *pipe);

enum {
      COMMAND_FACTORIZE,
      COMMAND_SIMPLIFY
};


class KQalculate : public KMainWindow {
      Q_OBJECT

public:
      KQalculate( QWidget* 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 = "");
      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);
      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);

      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;
      QalculateSetBaseInExpressionDialog *set_base_in_expression_dialog;
      QalculateSetBaseOtherDialog *set_base_other_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;

      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;
      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;
      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, *ActionIndicateInfiniteSeries;
      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, *ActionNumericalDisplayNormal;
      KRadioAction *ActionNumericalDisplayScientific, *ActionNumericalDisplayPurelyScientific;
      KRadioAction *ActionNumericalDisplaySimple, *ActionNumberBaseBinary, *ActionNumberBaseOctal, *ActionNumberBaseDecimal, *ActionNumberBaseHexadecimal;
      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 *ActionNumberBaseOther, *ActionSetBaseInExpression, *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;

public slots:

      void executeCommand2();
      void setResult2();
      void execute_expression2();

      void update_fmenu();
      void update_vmenu();    
      void update_umenus();
      void insertVariable(Variable*);
      void insertFunction(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 toggleKeypad(bool);
      void showEndingZeroes(bool);
      void approximationTryExact();
      void approximationAlwaysExact();
      void approximationApproximate();
      void fractionalDisplayDecimal();
      void fractionalDisplayDecimalTryExact();
      void fractionalDisplayFraction();
      void fractionalDisplayCombined();
      void numericalDisplayNormal();
      void numericalDisplayScientific();
      void numericalDisplayPurelyScientific();
      void numericalDisplaySimple();
      void indicateInfiniteSeries(bool);
      void roundHalfwayNumbersToEven(bool);
      void abbreviateNames(bool);
      void updateBaseOther();
      void numberBaseBinary();
      void numberBaseOctal();
      void numberBaseDecimal();
      void setOtherNumberBase(int);
      void numberBaseOther();
      void numberBaseHexadecimal();
      void numberBaseSexagesimal();
      void numberBaseTimeFormat();
      void numberBaseRomanNumerals();
      void setBaseInExpressionFromDialogGroup(int);
      void setBaseInExpressionFromDialogBox(int);
      void setBaseInExpression();
      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 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 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 displayParseStatus();

protected:

      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);
      
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;

};


#endif // QALCULATE_KWINDOW_H

Generated by  Doxygen 1.6.0   Back to index