• Skip to content
  • Skip to link menu
KDE 4.0 API Reference
  • KDE API Reference
  • kdeutils
  • Sitemap
  • Contact Us
 

kcalc

dlabel.cpp

Go to the documentation of this file.
00001 /*
00002     $Id: dlabel.cpp 746469 2007-12-09 06:40:10Z brandybuck $
00003 
00004     KCalc, a scientific calculator for the X window system using the
00005     Qt widget libraries, available at no cost at http://www.troll.no
00006     
00007     Copyright (C) 1996 Bernd Johannes Wuebben   
00008                        wuebben@math.cornell.edu
00009 
00010     This program is free software; you can redistribute it and/or modify
00011     it under the terms of the GNU General Public License as published by
00012     the Free Software Foundation; either version 2 of the License, or
00013     (at your option) any later version.
00014 
00015     This program is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018     GNU General Public License for more details.
00019 
00020     You should have received a copy of the GNU General Public License
00021     along with this program; if not, write to the Free Software
00022     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00023 
00024 */
00025 
00026 //#include <QGlobal>
00027 #include <kactioncollection.h>
00028 #include <kaction.h>
00029 #include <kstandardaction.h>
00030 
00031 #include "kcalc_settings.h"
00032 #include "kcalc_core.h"
00033 #include "dlabel.h"
00034 #include "dlabel.moc"
00035 
00036 
00037 
00038 DispLogic::DispLogic(QWidget *parent)
00039     : KCalcDisplay(parent), _history_index(0)
00040 {
00041     KNumber::setDefaultFloatOutput(true);
00042     KNumber::setDefaultFractionalInput(true);
00043     setAutoFillBackground(true);
00044 }
00045 
00046 DispLogic::~DispLogic()
00047 {
00048 }
00049 
00050 void DispLogic::changeSettings()
00051 {
00052     QPalette pal = palette();
00053 
00054     pal.setColor(QPalette::Text, KCalcSettings::foreColor());
00055     pal.setColor(QPalette::Foreground, KCalcSettings::foreColor());
00056     pal.setColor(QPalette::Background, KCalcSettings::backColor());
00057 
00058     setPalette(pal);
00059 
00060     setFont(KCalcSettings::font());
00061 
00062     setPrecision(KCalcSettings::precision());
00063 
00064     if(KCalcSettings::fixed() == false)
00065         setFixedPrecision(-1);
00066     else
00067         setFixedPrecision(KCalcSettings::fixedPrecision());
00068 
00069     setBeep(KCalcSettings::beep());
00070     setGroupDigits(KCalcSettings::groupDigits());
00071     updateDisplay();
00072 }
00073 
00074 void DispLogic::update_from_core(CalcEngine const &core,
00075                  bool store_result_in_history)
00076 {
00077     bool tmp_error;
00078     KNumber const & output = core.lastOutput(tmp_error);
00079     if(tmp_error) sendEvent(EventError);
00080     if (setAmount(output)  &&  store_result_in_history  &&
00081         output != KNumber::Zero)
00082     {
00083       // add this latest value to our history
00084       _history_list.insert(_history_list.begin(), output);
00085       _history_index = 0;
00086     }
00087 }
00088 
00089 void DispLogic::EnterDigit(int data)
00090 {
00091     char tmp;
00092     switch(data)
00093     {
00094     case 0:
00095       tmp = '0';
00096       break;
00097     case 1:
00098       tmp = '1';
00099       break;
00100     case 2:
00101       tmp = '2';
00102       break;
00103     case 3:
00104       tmp = '3';
00105       break;
00106     case 4:
00107       tmp = '4';
00108       break;
00109     case 5:
00110       tmp = '5';
00111       break;
00112     case 6:
00113       tmp = '6';
00114       break;
00115     case 7:
00116       tmp = '7';
00117       break;
00118     case 8:
00119       tmp = '8';
00120       break;
00121     case 9:
00122       tmp = '9';
00123       break;
00124     case 0xA:
00125       tmp = 'A';
00126       break;
00127     case 0xB:
00128       tmp = 'B';
00129       break;
00130     case 0xC:
00131       tmp = 'C';
00132       break;
00133     case 0xD:
00134       tmp = 'D';
00135       break;
00136     case 0xE:
00137       tmp = 'E';
00138       break;
00139     case 0xF:
00140       tmp = 'F';
00141       break;
00142     default:
00143       tmp = '?';
00144       break;
00145     }
00146 
00147     newCharacter(tmp);
00148 }
00149 
00150 void DispLogic::history_forward()
00151 {
00152     if (_history_list.empty()) return;
00153     if (_history_index <= 0) return;
00154 
00155     _history_index --;
00156     setAmount(_history_list[_history_index]);
00157 }
00158 
00159 void DispLogic::history_back()
00160 {
00161     if ( _history_list.empty()) return;
00162     if (_history_index >= _history_list.size()) return;
00163 
00164     setAmount(_history_list[_history_index]);
00165     _history_index ++;
00166 }
00167 

kcalc

Skip menu "kcalc"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

kdeutils

Skip menu "kdeutils"
  • ark
  • kcalc
  • kcharselect
  • kdelirc
  • kdessh
  • kdf
  • kfloppy
  • kgpg
  • kjots
  • klaptopdaemon
  • kmilo
  • ksim
  • ktimer
  • kwallet
  • superkaramba
Generated for kdeutils by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal