kcalc
kcalcdisplay.h
Go to the documentation of this file.00001 /* 00002 00003 KCalc 00004 00005 Copyright (C) Bernd Johannes Wuebben 00006 wuebben@math.cornell.edu 00007 wuebben@kde.org 00008 00009 This program is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU General Public License 00011 as published by the Free Software Foundation; either version 2 00012 of the License, or (at your option) any later version. 00013 00014 This program is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU General Public License for more details. 00018 00019 You should have received a copy of the GNU General Public License 00020 along with this program; if not, write to the Free Software 00021 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00022 00023 */ 00024 00025 00026 #ifndef _D_KCALCDISPLAY_H_ 00027 #define _D_KCALCDISPLAY_H_ 00028 00029 #include <stdlib.h> 00030 #include <QLabel> 00031 #include <QTimer> 00032 #include "knumber.h" 00033 #include "kcalctype.h" 00034 00035 #if defined HAVE_LONG_DOUBLE && defined HAVE_L_FUNCS 00036 #define PRINT_FLOAT "%.*Lf" 00037 #define PRINT_LONG_BIG "%.*Lg" 00038 #define PRINT_LONG "%Lg" 00039 #else 00040 #define PRINT_FLOAT "%.*f" 00041 #define PRINT_LONG_BIG "%.*g" 00042 #define PRINT_LONG "%g" 00043 #endif 00044 00045 #ifdef HAVE_LONG_LONG 00046 #define PRINT_OCTAL "%llo" 00047 #define PRINT_HEX "%llX" 00048 #else 00049 #define PRINT_OCTAL "%lo" 00050 #define PRINT_HEX "%lX" 00051 #endif 00052 00053 #define NUM_STATUS_TEXT 4 00054 00055 /* 00056 This class provides a pocket calculator display. The display has 00057 implicitely two major modes: One is for editing and one is purely 00058 for displaying. 00059 00060 When one uses "setAmount", the given amount is displayed, and the 00061 amount which was possibly typed in before is lost. At the same time 00062 this new value can not be modified. 00063 00064 On the other hand, "addNewChar" adds a new digit to the amount that 00065 is being typed in. If "setAmount" was used before, the display is 00066 cleared and a new input starts. 00067 00068 TODO: Check overflows, number of digits and such... 00069 */ 00070 00071 enum NumBase { 00072 NB_BINARY = 2, 00073 NB_OCTAL = 8, 00074 NB_DECIMAL = 10, 00075 NB_HEX = 16 00076 }; 00077 00078 00079 class KCalcDisplay : public QLabel 00080 { 00081 Q_OBJECT 00082 00083 public: 00084 KCalcDisplay(QWidget *parent=0); 00085 ~KCalcDisplay(); 00086 00087 protected: 00088 void mousePressEvent ( QMouseEvent *); 00089 virtual void paintEvent(QPaintEvent *p); 00090 00091 public: 00092 enum Event { 00093 EventReset, // resets display 00094 EventClear, // if no _error reset display 00095 EventError, 00096 EventChangeSign 00097 }; 00098 bool sendEvent(Event const event); 00099 void deleteLastDigit(void); 00100 KNumber const & getAmount(void) const; 00101 void newCharacter(char const new_char); 00102 bool setAmount(KNumber const & new_amount); 00103 int setBase(NumBase new_base); 00104 void setBeep(bool flag); 00105 void setGroupDigits(bool flag); 00106 void setFixedPrecision(int precision); 00107 void setPrecision(int precision); 00108 void setText(QString const &string); 00109 QString text() const; 00110 bool updateDisplay(void); 00111 void setStatusText(int i, const QString& text); 00112 virtual QSize sizeHint() const; 00113 private: 00114 bool _beep; 00115 bool _groupdigits; 00116 int _button; 00117 bool _lit; 00118 NumBase _num_base; 00119 00120 int _precision; 00121 int _fixed_precision; // "-1" = no fixed_precision 00122 00123 KNumber _display_amount; 00124 private: 00125 bool changeSign(void); 00126 void invertColors(void); 00127 00128 // only used for input of new numbers 00129 bool _eestate; 00130 bool _period; 00131 bool _neg_sign; 00132 QString _str_int; 00133 QString _str_int_exp; 00134 QString _str_status[NUM_STATUS_TEXT]; 00135 00136 QTimer* selection_timer; 00137 00138 signals: 00139 void clicked(void); 00140 void changedText(QString const &); 00141 void changedAmount(const KNumber &); 00142 00143 public slots: 00144 void slotCut(void); 00145 void slotCopy(void); 00146 void slotPaste(bool bClipboard=true); 00147 00148 private slots: 00149 void slotSelectionTimedOut(void); 00150 void slotDisplaySelected(void); 00151 }; 00152 00153 #endif // _KCALCDISPLAY_H_
KDE 4.0 API Reference