From 15318cad33835e4e2dc620d033e43cd930676cdd Mon Sep 17 00:00:00 2001 From: kergoth Date: Fri, 25 Jan 2002 22:14:26 +0000 Subject: Initial revision --- (limited to 'noncore/tools/calc2') diff --git a/noncore/tools/calc2/Makefile b/noncore/tools/calc2/Makefile new file mode 100644 index 0000000..1e31a2f --- a/dev/null +++ b/noncore/tools/calc2/Makefile @@ -0,0 +1,138 @@ +############################################################################# +# Makefile for building calc +# Generated by tmake at 12:06, 2001/11/26 +# Project: calc +# Template: app +############################################################################# + +####### Compiler, tools and options + +CC = gcc +CXX = g++ +CFLAGS = -pipe -Wall -W -O2 -DNO_DEBUG +CXXFLAGS= -pipe -DQWS -fno-exceptions -fno-rtti -Wall -W -O2 -DNO_DEBUG +INCPATH = -I$(QPEDIR)/include -I$(QTDIR)/include +LINK = gcc +LFLAGS = +LIBS = $(SUBLIBS) -L$(QTDIR)/lib -lqpe -Wl,-export-dynamic -lqte +MOC = $(QTDIR)/bin/moc +UIC = $(QTDIR)/bin/uic + +TAR = tar -cf +GZIP = gzip -9f + +####### Files + +HEADERS = calc.h \ + plugininterface.h \ + instruction.h \ + engine.h \ + stdinstructions.h +SOURCES = calc.cpp \ + main.cpp \ + engine.cpp +OBJECTS = calc.o \ + main.o \ + engine.o +INTERFACES = +UICDECLS = +UICIMPLS = +SRCMOC = moc_calc.cpp \ + moc_engine.cpp +OBJMOC = moc_calc.o \ + moc_engine.o +DIST = +TARGET = calc +INTERFACE_DECL_PATH = . + +####### Implicit rules + +.SUFFIXES: .cpp .cxx .cc .C .c + +.cpp.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< + +.cxx.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< + +.cc.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< + +.C.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< + +.c.o: + $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $< + +####### Build rules + + +all: $(TARGET) + +$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) + $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJMOC) $(LIBS) + +moc: $(SRCMOC) + +tmake: + tmake calc.pro + +dist: + $(TAR) calc.tar calc.pro $(SOURCES) $(HEADERS) $(INTERFACES) $(DIST) + $(GZIP) calc.tar + +clean: + -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS) $(TARGET) + -rm -f *~ core + +####### Sub-libraries + + +###### Combined headers + + +####### Compile + +calc.o: calc.cpp \ + /home/luke/builds/2.3.2-emb/qpe/include/qpe/qpeapplication.h \ + calc.h \ + /home/luke/builds/2.3.2-emb/qpe/include/qpe/qlibrary.h \ + /home/luke/builds/2.3.2-emb/qpe/include/qpe/qcom.h \ + /home/luke/builds/2.3.2-emb/qpe/include/qpe/quuid.h \ + engine.h \ + instruction.h \ + plugininterface.h + +main.o: main.cpp \ + /home/luke/builds/2.3.2-emb/qpe/include/qpe/qpeapplication.h \ + calc.h \ + /home/luke/builds/2.3.2-emb/qpe/include/qpe/qlibrary.h \ + /home/luke/builds/2.3.2-emb/qpe/include/qpe/qcom.h \ + /home/luke/builds/2.3.2-emb/qpe/include/qpe/quuid.h \ + engine.h \ + instruction.h \ + plugininterface.h + +engine.o: engine.cpp \ + engine.h \ + instruction.h + +moc_calc.o: moc_calc.cpp \ + calc.h \ + /home/luke/builds/2.3.2-emb/qpe/include/qpe/qlibrary.h \ + /home/luke/builds/2.3.2-emb/qpe/include/qpe/qcom.h \ + /home/luke/builds/2.3.2-emb/qpe/include/qpe/quuid.h \ + engine.h \ + instruction.h \ + plugininterface.h + +moc_engine.o: moc_engine.cpp \ + engine.h \ + instruction.h + +moc_calc.cpp: calc.h + $(MOC) calc.h -o moc_calc.cpp + +moc_engine.cpp: engine.h + $(MOC) engine.h -o moc_engine.cpp + diff --git a/noncore/tools/calc2/binary/Makefile b/noncore/tools/calc2/binary/Makefile new file mode 100644 index 0000000..93cc0d5 --- a/dev/null +++ b/noncore/tools/calc2/binary/Makefile @@ -0,0 +1,146 @@ +############################################################################# +# Makefile for building libbinary.so.1.0.0 +# Generated by tmake at 12:03, 2001/11/22 +# Project: binary +# Template: lib +############################################################################# + +####### Compiler, tools and options + +CC = gcc +CXX = g++ +CFLAGS = -pipe -Wall -W -O2 -fPIC -DNO_DEBUG +CXXFLAGS= -pipe -DQWS -fno-exceptions -fno-rtti -Wall -W -O2 -fPIC -DNO_DEBUG +INCPATH = -I$(QPEDIR)/include -I$(QPEDIR)/calc2 -I$(QTDIR)/include +LINK = gcc +LFLAGS = -shared -Wl,-soname,libbinary.so.1 +LIBS = $(SUBLIBS) -L$(QTDIR)/lib -lqte +AR = ar cqs +RANLIB = +MOC = $(QTDIR)/bin/moc +UIC = $(QTDIR)/bin/uic + +TAR = tar -cf +GZIP = gzip -9f + +####### Files + +HEADERS = binaryimpl.h \ + binaryfactory.h +SOURCES = binaryimpl.cpp \ + binaryfactory.cpp +OBJECTS = binaryimpl.o \ + binaryfactory.o \ + binary.o +INTERFACES = binary.ui +UICDECLS = binary.h +UICIMPLS = binary.cpp +SRCMOC = moc_binaryimpl.cpp \ + moc_binary.cpp +OBJMOC = moc_binaryimpl.o \ + moc_binary.o +DIST = +TARGET = libbinary.so.1.0.0 +TARGETA = $(QPEDIR)/plugins/calculator/libbinary.a +TARGETD = libbinary.so.1.0.0 +TARGET0 = libbinary.so +TARGET1 = libbinary.so.1 +TARGET2 = libbinary.so.1.0 +INTERFACE_DECL_PATH = . + +####### Implicit rules + +.SUFFIXES: .cpp .cxx .cc .C .c + +.cpp.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< + +.cxx.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< + +.cc.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< + +.C.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< + +.c.o: + $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $< + +####### Build rules + + +all: $(QPEDIR)/plugins/calculator/libbinary.so.1.0.0 + +$(QPEDIR)/plugins/calculator/libbinary.so.1.0.0: $(OBJECTS) $(OBJMOC) $(SUBLIBS) + -rm -f $(TARGET) $(TARGET0) $(TARGET1) $(TARGET2) + $(LINK) $(LFLAGS) -o $(TARGETD) $(OBJECTS) $(OBJMOC) $(LIBS) + -ln -s $(TARGET) $(TARGET0) + -ln -s $(TARGET) $(TARGET1) + -ln -s $(TARGET) $(TARGET2) + -rm -f $(QPEDIR)/plugins/calculator/$(TARGET) + -rm -f $(QPEDIR)/plugins/calculator/$(TARGET0) + -rm -f $(QPEDIR)/plugins/calculator/$(TARGET1) + -rm -f $(QPEDIR)/plugins/calculator/$(TARGET2) + -mv $(TARGET) $(TARGET0) $(TARGET1) $(TARGET2) $(QPEDIR)/plugins/calculator/ + +staticlib: $(TARGETA) + +$(TARGETA): $(UICDECLS) $(OBJECTS) $(OBJMOC) + -rm -f $(TARGETA) + $(AR) $(TARGETA) $(OBJECTS) $(OBJMOC) + +moc: $(SRCMOC) + +tmake: + tmake binary.pro + +dist: + $(TAR) binary.tar binary.pro $(SOURCES) $(HEADERS) $(INTERFACES) $(DIST) + $(GZIP) binary.tar + +clean: + -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS) $(TARGET) + -rm -f $(TARGET0) $(TARGET1) $(TARGET2) $(TARGETA) + -rm -f *~ core + +####### Sub-libraries + + +###### Combined headers + + +####### Compile + +binaryimpl.o: binaryimpl.cpp \ + binaryimpl.h \ + binary.h + +binaryfactory.o: binaryfactory.cpp \ + binaryfactory.h \ + binaryimpl.h \ + binary.h + +binary.h: binary.ui + $(UIC) binary.ui -o $(INTERFACE_DECL_PATH)/binary.h + +binary.cpp: binary.ui + $(UIC) binary.ui -i binary.h -o binary.cpp + +binary.o: binary.cpp \ + binary.h \ + binary.ui + +moc_binaryimpl.o: moc_binaryimpl.cpp \ + binaryimpl.h \ + binary.h + +moc_binary.o: moc_binary.cpp \ + binary.h + +moc_binaryimpl.cpp: binaryimpl.h + $(MOC) binaryimpl.h -o moc_binaryimpl.cpp + +moc_binary.cpp: binary.h + $(MOC) binary.h -o moc_binary.cpp + diff --git a/noncore/tools/calc2/binary/README b/noncore/tools/calc2/binary/README new file mode 100644 index 0000000..4937038 --- a/dev/null +++ b/noncore/tools/calc2/binary/README @@ -0,0 +1 @@ +A binary interface with bitwise operations diff --git a/noncore/tools/calc2/binary/binary.pro b/noncore/tools/calc2/binary/binary.pro new file mode 100644 index 0000000..01ba6a4 --- a/dev/null +++ b/noncore/tools/calc2/binary/binary.pro @@ -0,0 +1,16 @@ +TEMPLATE = lib +CONFIG -= moc +CONFIG += qt release + +# Input +INTERFACES += binary.ui +HEADERS = binaryimpl.h \ + binaryfactory.h +SOURCES = binaryimpl.cpp \ + binaryfactory.cpp + +INCLUDEPATH += $(QPEDIR)/include \ + $(QPEDIR)/calc2 +DEPENDPATH += $(QPEDIR)/include + +DESTDIR = $(QPEDIR)/plugins/calculator diff --git a/noncore/tools/calc2/binary/binary.ui b/noncore/tools/calc2/binary/binary.ui new file mode 100644 index 0000000..26064d1 --- a/dev/null +++ b/noncore/tools/calc2/binary/binary.ui @@ -0,0 +1,177 @@ + +FormBinary + + QWidget + + name + FormBinary + + + geometry + + 0 + 0 + 332 + 114 + + + + caption + Binary + + + + margin + 0 + + + spacing + 0 + + + QPushButton + + name + PB0 + + + maximumSize + + 80 + 80 + + + + text + 0 + + + + QPushButton + + name + PB1 + + + maximumSize + + 80 + 80 + + + + text + 1 + + + + QPushButton + + name + PBAnd + + + maximumSize + + 80 + 80 + + + + text + AND + + + + QPushButton + + name + PBOr + + + maximumSize + + 80 + 80 + + + + text + OR + + + + QPushButton + + name + PBNot + + + maximumSize + + 80 + 80 + + + + text + NOT + + + + QPushButton + + name + PBSHL + + + maximumSize + + 80 + 80 + + + + text + <- + + + + QPushButton + + name + PBXor + + + maximumSize + + 80 + 80 + + + + text + XOR + + + + QPushButton + + name + PBSHR + + + maximumSize + + 80 + 80 + + + + text + -> + + + + + diff --git a/noncore/tools/calc2/binary/binaryfactory.cpp b/noncore/tools/calc2/binary/binaryfactory.cpp new file mode 100644 index 0000000..110334f --- a/dev/null +++ b/noncore/tools/calc2/binary/binaryfactory.cpp @@ -0,0 +1,51 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#include "binaryfactory.h" +#include "binaryimpl.h" +#include + +QWidget *BinaryInterface::getPlugin ( Engine *e, QWidget *parent ) { + if ( !input ) + input = new FormBinaryImpl ( e, parent ); + return input; +} + +#ifndef QT_NO_COMPONENT +QRESULT BinaryInterface::queryInterface( const QUuid &uuid, QUnknownInterface **iface ) +{ + *iface = 0; + if ( uuid == IID_QUnknown ) + *iface = this; + else if ( uuid == IID_Calc ) + *iface = this; + + if ( *iface ) + (*iface)->addRef(); + return QS_OK; +} + +Q_EXPORT_INTERFACE() +{ + Q_CREATE_INSTANCE( BinaryInterface ) +} +#endif diff --git a/noncore/tools/calc2/binary/binaryfactory.h b/noncore/tools/calc2/binary/binaryfactory.h new file mode 100644 index 0000000..e015384 --- a/dev/null +++ b/noncore/tools/calc2/binary/binaryfactory.h @@ -0,0 +1,46 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#ifndef BINARYIMPL_H +#define BINARYIMPL_H + +#include "binaryimpl.h" +#include +#include + +class BinaryInterface : public CalcInterface +{ +public: + BinaryInterface(){input = 0;}; + virtual ~BinaryInterface(){}; + +#ifndef QT_NO_COMPONENT + QRESULT queryInterface( const QUuid&, QUnknownInterface** ); + Q_REFCOUNT +#endif + + QWidget *getPlugin( Engine *, QWidget *parent ); + +private: + FormBinaryImpl *input; + ulong ref; +}; + +#endif diff --git a/noncore/tools/calc2/binary/binaryimpl.cpp b/noncore/tools/calc2/binary/binaryimpl.cpp new file mode 100644 index 0000000..ffc56ad --- a/dev/null +++ b/noncore/tools/calc2/binary/binaryimpl.cpp @@ -0,0 +1,110 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#include "binaryimpl.h" +#include + +class iXOR : public Instruction { +public: + iXOR():Instruction(){}; + ~iXOR(){}; + Data eval(Data num) { + Data result; + result.i = num.i ^ acc.i; + return result; + }; +}; +class iAND : public Instruction { +public: + iAND():Instruction(){}; + ~iAND(){}; + Data eval(Data num) { + Data result; + result.i = num.i & acc.i; + return result; + }; +}; +class iNOT : public Instruction { +public: + iNOT():Instruction(){}; + ~iNOT(){}; + Data eval(Data num) { + Data result; + result.i = ~ num.i; + return result; + }; +}; +class iOR : public Instruction { +public: + iOR():Instruction(){}; + ~iOR(){}; + Data eval(Data num) { + Data result; + result.i = num.i | acc.i; + return result; + }; +}; +class iLSH : public Instruction { +public: + iLSH():Instruction(){}; + ~iLSH(){}; + Data eval(Data num) { + Data result; + result.i = num.i << 1; + return result; + }; +}; +class iRSH : public Instruction { +public: + iRSH():Instruction(){}; + ~iRSH(){}; + Data eval(Data num) { + Data result; + result.i = num.i >> 1; + return result; + }; +}; + +void FormBinaryImpl::val0Clicked() { + engine->pushValue('0'); +} + +void FormBinaryImpl::val1Clicked() { + engine->pushValue('1'); +} + +void FormBinaryImpl::XORClicked() { + engine->pushInstruction(new iXOR()); +} +void FormBinaryImpl::ANDClicked() { + engine->pushInstruction(new iAND()); +} +void FormBinaryImpl::NOTClicked() { + engine->immediateInstruction(new iNOT()); +} +void FormBinaryImpl::ORClicked() { + engine->pushInstruction(new iOR()); +} +void FormBinaryImpl::LSHClicked() { + engine->immediateInstruction(new iLSH()); +} +void FormBinaryImpl::RSHClicked() { + engine->immediateInstruction(new iRSH()); +} diff --git a/noncore/tools/calc2/binary/binaryimpl.h b/noncore/tools/calc2/binary/binaryimpl.h new file mode 100644 index 0000000..bf9e3a7 --- a/dev/null +++ b/noncore/tools/calc2/binary/binaryimpl.h @@ -0,0 +1,50 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#ifndef FORMBINARYINPUTIMPL +#define FORMBINARYINPUTIMPL + +#include "binary.h" +#include + +class FormBinaryImpl : public FormBinary { +Q_OBJECT +public: + FormBinaryImpl(Engine *e,QWidget *p) : FormBinary (p,"Binary") { + engine = e; + engine->setRepresentation(rBin); + }; + ~FormBinaryImpl(){}; +private: + Engine *engine; + +private slots: + void val0Clicked(); + void val1Clicked(); + + void XORClicked(); + void ANDClicked(); + void NOTClicked(); + void ORClicked(); + + void LSHClicked(); + void RSHClicked(); +}; + +#endif diff --git a/noncore/tools/calc2/calc.cpp b/noncore/tools/calc2/calc.cpp new file mode 100644 index 0000000..883ab33 --- a/dev/null +++ b/noncore/tools/calc2/calc.cpp @@ -0,0 +1,104 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#include +#include +#include +#include + +#include "calc.h" +#include "plugininterface.h" + +calc::calc (QWidget * p = 0, const char *n = 0):QWidget (p, n) +{ + setCaption (tr ("Calculator")); + +// widgets + LCD = new QLCDNumber (this); + LCD->setMaximumSize (QSize (240, 30)); + LCD->setNumDigits(12); +LCD->setSegmentStyle(QLCDNumber::Filled); + pluginWidgetStack = new QWidgetStack (this); + +// layout widgets + calculatorLayout = new QVBoxLayout (this); + calculatorLayout->addWidget (LCD); + calculatorLayout->addWidget (pluginWidgetStack); + +// no formatting of display for now + connect (&engine, SIGNAL(display (double)), LCD, SLOT(display (double))); + connect (&engine, SIGNAL(display (const QString &)), LCD, SLOT(display (const QString &))); + connect (&engine, SIGNAL(setBinMode()), LCD, SLOT(setBinMode())); + connect (&engine, SIGNAL(setOctMode()), LCD, SLOT(setOctMode())); + connect (&engine, SIGNAL(setDecMode()), LCD, SLOT(setDecMode())); + connect (&engine, SIGNAL(setHexMode()), LCD, SLOT(setHexMode())); + +#ifndef NO_PLUGINS +// load plugins + QValueList < Plugin >::Iterator mit; + for (mit = pluginList.begin (); mit != pluginList.end (); ++mit) { + (*mit).interface->release (); + (*mit).library->unload (); + delete (*mit).library; + } + pluginList.clear (); + + QString path = QPEApplication::qpeDir() + "/plugins/calculator"; + QDir dir (path, "lib*.so"); + QStringList list = dir.entryList (); + + QStringList::Iterator it; + for (it = list.begin (); it != list.end (); ++it) { + CalcInterface *iface = 0; + QLibrary *lib = new QLibrary (path + "/" + *it); + + Plugin plugin; + plugin.pluginWidget = 0; + + if (lib->queryInterface (IID_Calc, (QUnknownInterface **) & iface) == + QS_OK) { + plugin.library = lib; + plugin.interface = iface; + plugin.pluginWidget = plugin.interface->getPlugin(&engine,pluginWidgetStack); + if (plugin.pluginWidget) + pluginWidgetStack->addWidget (plugin.pluginWidget, pluginList.count()); + pluginList.append (plugin); + } else { + delete lib; + } + } + setMode (1); +#else +// load simple interface +#endif +} + +calc::~calc () +{ +#ifndef NO_PLUGINS + QValueList < Plugin >::Iterator mit; + for (mit = pluginList.begin (); mit != pluginList.end (); ++mit) { + (*mit).interface->release (); + (*mit).library->unload (); + delete (*mit).library; + } +#endif +} + diff --git a/noncore/tools/calc2/calc.h b/noncore/tools/calc2/calc.h new file mode 100644 index 0000000..b52356d --- a/dev/null +++ b/noncore/tools/calc2/calc.h @@ -0,0 +1,69 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#ifndef CALC_H +#define CALC_H + +#ifdef QT_NO_COMPONENT +#define NO_PLUGINS +#endif + +#include +#include + +#ifndef NO_PLUGINS +#include +#include +#endif + +#include "engine.h" +#include "plugininterface.h" + +struct Plugin { +#ifndef NO_PLUGINS + QLibrary *library; +#endif + QWidget *pluginWidget; + CalcInterface *interface; + QString name; +}; + +class calc:public QWidget { + +Q_OBJECT +public: + calc (QWidget * p = 0, const char *n = 0); + ~calc (); + +private: +#ifndef NO_PLUGINS + void loadPlugins (); + QValueList < Plugin > pluginList; +#endif + QVBoxLayout *calculatorLayout; + QWidgetStack *pluginWidgetStack; + QLCDNumber *LCD; + Engine engine; + +public slots: + void setMode(int m){pluginWidgetStack->raiseWidget(m);}; +}; + +#endif diff --git a/noncore/tools/calc2/calc.pro b/noncore/tools/calc2/calc.pro new file mode 100644 index 0000000..c10232a --- a/dev/null +++ b/noncore/tools/calc2/calc.pro @@ -0,0 +1,11 @@ +TEMPLATE = app +CONFIG += qt release + +# Input +HEADERS += calc.h plugininterface.h instruction.h engine.h stdinstructions.h +SOURCES += calc.cpp main.cpp engine.cpp + +INCLUDEPATH += $(QPEDIR)/include +DEPENDPATH += $(QPEDIR)/include +LIBS += -lqpe -Wl,-export-dynamic + diff --git a/noncore/tools/calc2/engine.cpp b/noncore/tools/calc2/engine.cpp new file mode 100644 index 0000000..a9a47c4 --- a/dev/null +++ b/noncore/tools/calc2/engine.cpp @@ -0,0 +1,214 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#include "engine.h" +#include +#include +#include + +Data Engine::evalStack (Data num, bool inbrace = FALSE) +{ + if (state != sError) { + Instruction *i; + +// Pop the next op from the stack + while (!stack.isEmpty () && (braces || !inbrace)) { + i = stack.pop (); + +// Check this ops prec vs next ops prec + if (!stack.isEmpty ()) + if (i->precedence <= stack.top()->precedence) + i->acc = evalStack (i->acc, inbrace); + +// Evaluate this instruction + num = i->eval (num); + +// Error-check ( change this to work for all types ) + if (isnan (num.dbl) || isinf (num.dbl)) { + qDebug ("bad result from operation"); + state = sError; + clearData(&num); + return num; + } + } + } + return num; +} + +// Plugins call this to request the stack be evaluated +void Engine::eval () +{ + num = evalStack (num); + if (state != sError) { + displayData(num); + state = sStart; + } +// if the user didnt close all their braces, its no big deal + braces = 0; +} + +void Engine::immediateInstruction (Instruction * i) +{ + if (state != sError) { + i->setRep(currentRep); + num = i->eval (num); + displayData(num); + state = sStart; + } +} + +void Engine::pushInstruction (Instruction * i) +{ + if (state != sError) { + i->setRep(currentRep); + i->acc = num; + stack.push (i); + state = sStart; + } +} + +void Engine::pushValue (char v) +{ + if (state == sAppend) { + bool ok = FALSE; + switch (currentRep) { + case rDouble: + displayString.append(v); + num.dbl=displayString.toDouble(&ok); + break; + case rFraction: + break; + default: + displayString.append(v); + num.i=displayString.toInt(&ok, calcBase()); + }; + if (!ok) { + state = sError; + qDebug("pushValue() - num->string conversion"); + } else { + const QString constString = displayString; + emit(display(constString)); + }; + + } else if (state == sStart) { + softReset(); + displayString.truncate(0); + state = sAppend; + pushValue (v); + } else if (state == sError) { + qDebug ("in error state"); + return; + } +} + +void Engine::del () +{ + bool ok; + switch (currentRep) { + case rDouble: + displayString.truncate(displayString.length()); + num.dbl=displayString.toDouble(&ok); + break; + case rFraction: + qDebug("not available"); + break; + default: + displayString.truncate(displayString.length()); + num.i = displayString.toInt(&ok, calcBase()); + }; + + if (!ok) { + state = sError; + qDebug("del() - num->string conversion"); + } else { + const QString constString = displayString; + emit(display(constString)); + }; +} + +void Engine::displayData(Data d) { + switch (currentRep) { + case rDouble: + displayString.setNum(d.dbl); + break; + case rFraction: + qDebug("fractional display not yet impl"); + break; + default: + displayString.setNum(d.i, calcBase()); + break; + }; + const QString constString= displayString; + emit(display(constString)); +} + +// Returns the base when Rep is an integer type +int Engine::calcBase () { + switch (currentRep) { + case rBin: + return 2; + case rOct: + return 8; + case rDec: + return 10; + case rHex: + return 16; + default: + state = sError; + qDebug("Error - attempt to calc base for non-integer"); + return 10; + }; +} + +// Special instruction for internal use only +class iOpenBrace:public Instruction { + public: + iOpenBrace (Engine *e):Instruction (100) {engine = e;}; + ~iOpenBrace () {}; + + Data eval (Data num) { + engine->decBraces(); + return num; + }; + private: + Engine *engine; +}; + +void Engine::openBrace() { + pushInstruction(new iOpenBrace(this)); +} + +void Engine::closeBrace() { + braces++;evalStack(num,TRUE); +} + +// will need to show and hide display widgets +void Engine::setRepresentation(Representation r) { + currentRep = r; + clearData(&num); + clearData(&mem); + state = sStart; +} + +void Engine::clearData(Data *d) { + d->i = d->fraction.numerator = d->fraction.denominator = 0; + d->dbl = 0; +} + diff --git a/noncore/tools/calc2/engine.h b/noncore/tools/calc2/engine.h new file mode 100644 index 0000000..15c9aa1 --- a/dev/null +++ b/noncore/tools/calc2/engine.h @@ -0,0 +1,111 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#ifndef ENGINE_H +#define ENGINE_H + +#include +#include // Instruction stack +#include // Display +#include "instruction.h" + +// Possible states +enum State { + sStart, // start inputting a new number + sAppend, // continue inputting a number + sError +}; + +// State machine +class Engine:public QWidget { + +Q_OBJECT +public: + Engine (QWidget * parent = 0, const char *name = 0):QWidget (parent, name) { + hardReset(); + setRepresentation(rDec); + }; + + ~Engine () { }; + + void immediateInstruction (Instruction *); + void pushInstruction (Instruction *); + void eval (); + + void pushValue (char); + void del (); + + void openBrace (); + void closeBrace (); + + void softReset () { // clears the number being inputted + decimalPlaces = -1; + clearData(&num); + displayData(num); + state = sStart; + }; + void hardReset () { // a "real" reset of the stack + stack.clear (); + memClear(); + braces = 0; + softReset (); + }; + + void memSave () { + mem = num; + }; + void memRecall () { + num = mem; + state = sStart; + displayData(num); + }; + void memClear () { + clearData(&mem); + }; + + // rFraction will require a special display enabled here + void setRepresentation(Representation); + + // you dont want to call this + void decBraces(void){ braces--; }; + +private: + void displayData(Data d); + void clearData(Data *d); + int calcBase(); + Data evalStack (Data, bool); + Data num,mem; + State state; + QStack < Instruction > stack; + Representation currentRep; + int braces, decimalPlaces; // count of finishing 0's in num + QString displayString; // saves instatiating it over and over + +signals: + void display(const QString &); + void display(double); // could get rid of this and + // use a QLabel instead. + void setHexMode(); + void setBinMode(); + void setDecMode(); + void setOctMode(); +}; + +#endif diff --git a/noncore/tools/calc2/instruction.h b/noncore/tools/calc2/instruction.h new file mode 100644 index 0000000..6077bf0 --- a/dev/null +++ b/noncore/tools/calc2/instruction.h @@ -0,0 +1,69 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#ifndef INSTRUCTION_H +#define INSTRUCTION_H + +/* Internal representation of data +The first four types indicate an int, +that is, Data.i, and are incompatible +with the other two types. + +- Plugin is responsible for telling engine +which Rep to use at any given time +- Instructions from that plugin only +have to handle that representation +- Engine is responsible for error-checking +according to its current rep and display */ +enum Representation { + rBin, + rOct, + rDec, + rHex, + rDouble, + rFraction +}; + +// An atom of data +union Data { + int i; + double dbl; + struct Fraction { + int numerator, denominator; + } fraction; +}; + +// Instruction base class +class Instruction { +public: + Instruction (int p = 0) { + precedence = p; + }; + + virtual ~ Instruction () {}; + + virtual Data eval(Data) = 0; + void setRep(Representation r) { rep = r; }; + + Representation rep; + Data acc; + int precedence; +}; + +#endif diff --git a/noncore/tools/calc2/main.cpp b/noncore/tools/calc2/main.cpp new file mode 100644 index 0000000..ebfcc28 --- a/dev/null +++ b/noncore/tools/calc2/main.cpp @@ -0,0 +1,34 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#include +#include "calc.h" + +int main (int argc, char **argv) +{ + QPEApplication a (argc, argv); + + calc mw; + + QPEApplication::setInputMethodHint (&mw, QPEApplication::AlwaysOff); + mw.setCaption (calc::tr ("Calculator")); + a.showMainWidget (&mw); + + return a.exec (); +} diff --git a/noncore/tools/calc2/plugininterface.h b/noncore/tools/calc2/plugininterface.h new file mode 100644 index 0000000..df6db9d --- a/dev/null +++ b/noncore/tools/calc2/plugininterface.h @@ -0,0 +1,45 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#ifndef CALCINTERFACE_H +#define CALCINTERFACE_H + +#include +#include +#include +#include + +#include "engine.h" + +#ifndef QT_NO_COMPONENT +// {3CE88B66-B3FD-4580-9D04-77338A31A667} +#ifndef IID_Calc +#define IID_Calc QUuid( 0x3ce88b66, 0xb3fd, 0x4580, 0x9d, 0x04, 0x77, 0x33, 0x8a, 0x31, 0xa6, 0x67) +#endif +#endif + +class QWidget; +class QObject; + +struct CalcInterface:public QUnknownInterface { + virtual QWidget *getPlugin (Engine *e, QWidget * parent) = 0; +}; + +#endif diff --git a/noncore/tools/calc2/simple/README b/noncore/tools/calc2/simple/README new file mode 100644 index 0000000..37acb64 --- a/dev/null +++ b/noncore/tools/calc2/simple/README @@ -0,0 +1 @@ +A simple interface with no operator precedence. diff --git a/noncore/tools/calc2/simple/simple.pro b/noncore/tools/calc2/simple/simple.pro new file mode 100644 index 0000000..92378a6 --- a/dev/null +++ b/noncore/tools/calc2/simple/simple.pro @@ -0,0 +1,14 @@ +TEMPLATE = lib +CONFIG -= moc +CONFIG += qt release + +# Input +INTERFACES += simple.ui +HEADERS = simpleimpl.h simplefactory.h stdinstructions.h +SOURCES = simpleimpl.cpp simplefactory.cpp + +INCLUDEPATH += $(QPEDIR)/include \ + $(QPEDIR)/calc2 +DEPENDPATH += $(QPEDIR)/include + +DESTDIR = $(QPEDIR)/plugins/calculator diff --git a/noncore/tools/calc2/simple/simple.ui b/noncore/tools/calc2/simple/simple.ui new file mode 100644 index 0000000..af12905 --- a/dev/null +++ b/noncore/tools/calc2/simple/simple.ui @@ -0,0 +1,704 @@ + +FormSimple + + QWidget + + name + FormSimple + + + geometry + + 73 + 0 + 240 + 320 + + + + sizePolicy + + 4 + 4 + + + + maximumSize + + 240 + 320 + + + + baseSize + + 240 + 240 + + + + caption + Simple + + + + margin + 0 + + + spacing + 0 + + + QPushButton + + name + PBEval + + + sizePolicy + + 4 + 4 + + + + maximumSize + + 160 + 80 + + + + text + = + + + + QPushButton + + name + PB5 + + + sizePolicy + + 4 + 4 + + + + maximumSize + + 80 + 80 + + + + text + 5 + + + + QPushButton + + name + PBDecimal + + + sizePolicy + + 4 + 4 + + + + maximumSize + + 80 + 80 + + + + text + . + + + + QPushButton + + name + PB3 + + + sizePolicy + + 4 + 4 + + + + maximumSize + + 80 + 80 + + + + text + 3 + + + + QPushButton + + name + PB2 + + + sizePolicy + + 4 + 4 + + + + maximumSize + + 80 + 80 + + + + text + 2 + + + + QPushButton + + name + PB4 + + + sizePolicy + + 4 + 4 + + + + maximumSize + + 80 + 80 + + + + text + 4 + + + + QPushButton + + name + PB6 + + + sizePolicy + + 4 + 4 + + + + maximumSize + + 80 + 80 + + + + text + 6 + + + + QPushButton + + name + PBMul + + + sizePolicy + + 4 + 4 + + + + maximumSize + + 80 + 80 + + + + text + * + + + + QPushButton + + name + PBSub + + + sizePolicy + + 4 + 4 + + + + maximumSize + + 80 + 80 + + + + text + - + + + + QPushButton + + name + PBAdd + + + sizePolicy + + 4 + 4 + + + + maximumSize + + 80 + 80 + + + + text + + + + + + QPushButton + + name + PB9 + + + sizePolicy + + 4 + 4 + + + + maximumSize + + 80 + 80 + + + + text + 9 + + + + QPushButton + + name + PB7 + + + enabled + true + + + sizePolicy + + 4 + 4 + + + + maximumSize + + 80 + 80 + + + + text + 7 + + + + QPushButton + + name + PB1 + + + sizePolicy + + 4 + 4 + + + + maximumSize + + 80 + 80 + + + + text + 1 + + + + QPushButton + + name + PB0 + + + sizePolicy + + 4 + 4 + + + + maximumSize + + 160 + 80 + + + + text + 0 + + + + QPushButton + + name + PBDiv + + + sizePolicy + + 4 + 4 + + + + maximumSize + + 80 + 80 + + + + text + / + + + autoRepeat + true + + + + QPushButton + + name + PB8 + + + sizePolicy + + 4 + 4 + + + + maximumSize + + 80 + 80 + + + + text + 8 + + + + QPushButton + + name + PBMPlus + + + sizePolicy + + 4 + 4 + + + + maximumSize + + 80 + 80 + + + + text + M+ + + + + QPushButton + + name + PBCE + + + sizePolicy + + 4 + 4 + + + + maximumSize + + 80 + 80 + + + + text + CE + + + + QPushButton + + name + PBMC + + + sizePolicy + + 4 + 4 + + + + maximumSize + + 80 + 80 + + + + text + MC + + + + QPushButton + + name + PBMR + + + sizePolicy + + 4 + 4 + + + + maximumSize + + 80 + 80 + + + + text + MR + + + + + + + PB0 + clicked() + FormSimple + val0Clicked() + + + PB1 + clicked() + FormSimple + val1Clicked() + + + PB2 + clicked() + FormSimple + val2Clicked() + + + PB3 + clicked() + FormSimple + val3Clicked() + + + PB4 + clicked() + FormSimple + val4Clicked() + + + PB5 + clicked() + FormSimple + val5Clicked() + + + PB6 + clicked() + FormSimple + val6Clicked() + + + PB7 + clicked() + FormSimple + val7Clicked() + + + PB8 + clicked() + FormSimple + val8Clicked() + + + PB9 + clicked() + FormSimple + val9Clicked() + + + PBSub + clicked() + FormSimple + subClicked() + + + PBMul + clicked() + FormSimple + mulClicked() + + + PBDiv + clicked() + FormSimple + divClicked() + + + PBDecimal + clicked() + FormSimple + decimalClicked() + + + PBEval + clicked() + FormSimple + evalClicked() + + + PBMC + clicked() + FormSimple + MCClicked() + + + PBMPlus + clicked() + FormSimple + MPlusClicked() + + + PBMR + clicked() + FormSimple + MRClicked() + + + PBAdd + clicked() + FormSimple + addClicked() + + + PBCE + clicked() + FormSimple + CEClicked() + + CEClicked() + MCClicked() + MPlusClicked() + MRClicked() + addClicked() + decimalClicked() + divClicked() + evalClicked() + mulClicked() + subClicked() + val0Clicked() + val1Clicked() + val2Clicked() + val3Clicked() + val4Clicked() + val5Clicked() + val6Clicked() + val7Clicked() + val8Clicked() + val9Clicked() + + diff --git a/noncore/tools/calc2/simple/simplefactory.cpp b/noncore/tools/calc2/simple/simplefactory.cpp new file mode 100644 index 0000000..515418f --- a/dev/null +++ b/noncore/tools/calc2/simple/simplefactory.cpp @@ -0,0 +1,51 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#include "simplefactory.h" +#include "simpleimpl.h" +#include + +QWidget *SimpleInterface::getPlugin ( Engine *e, QWidget *parent ) { + if ( !input ) + input = new FormSimpleImpl ( e, parent ); + return input; +} + +#ifndef QT_NO_COMPONENT +QRESULT SimpleInterface::queryInterface( const QUuid &uuid, QUnknownInterface **iface ) +{ + *iface = 0; + if ( uuid == IID_QUnknown ) + *iface = this; + else if ( uuid == IID_Calc ) + *iface = this; + + if ( *iface ) + (*iface)->addRef(); + return QS_OK; +} + +Q_EXPORT_INTERFACE() +{ + Q_CREATE_INSTANCE( SimpleInterface ) +} +#endif diff --git a/noncore/tools/calc2/simple/simplefactory.h b/noncore/tools/calc2/simple/simplefactory.h new file mode 100644 index 0000000..e1022fd --- a/dev/null +++ b/noncore/tools/calc2/simple/simplefactory.h @@ -0,0 +1,46 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#ifndef BINARYIMPL_H +#define BINARYIMPL_H + +#include "simpleimpl.h" +#include +#include + +class SimpleInterface : public CalcInterface +{ +public: + SimpleInterface(){input = 0;}; + virtual ~SimpleInterface(){}; + +#ifndef QT_NO_COMPONENT + QRESULT queryInterface( const QUuid&, QUnknownInterface** ); + Q_REFCOUNT +#endif + + QWidget *getPlugin( Engine *, QWidget *parent ); + +private: + FormSimpleImpl *input; + ulong ref; +}; + +#endif diff --git a/noncore/tools/calc2/simple/simpleimpl.cpp b/noncore/tools/calc2/simple/simpleimpl.cpp new file mode 100644 index 0000000..f71f000 --- a/dev/null +++ b/noncore/tools/calc2/simple/simpleimpl.cpp @@ -0,0 +1,120 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#include +#include + +#include "simpleimpl.h" +#include + +void FormSimpleImpl::CEClicked() { + engine->hardReset(); +} + +void FormSimpleImpl::MCClicked() { + engine->memClear(); +} + +void FormSimpleImpl::MRClicked() { + engine->memRecall(); +} + +void FormSimpleImpl::MPlusClicked() { + engine->memSave(); +} + +void FormSimpleImpl::evalClicked() { + engine->eval(); +} + +void FormSimpleImpl::addClicked () +{ + engine->pushInstruction (new iAdd ()); +} + +void FormSimpleImpl::subClicked () +{ + engine->pushInstruction (new iSub ()); +} + +void FormSimpleImpl::mulClicked () +{ + engine->pushInstruction (new iMul ()); +} + +void FormSimpleImpl::divClicked () +{ + engine->pushInstruction (new iDiv ()); +} + +void FormSimpleImpl::decimalClicked () +{ + engine->pushValue ('.'); +} + +void FormSimpleImpl::val1Clicked () +{ + engine->pushValue ('1'); +} + +void FormSimpleImpl::val2Clicked () +{ + engine->pushValue ('2'); +} + +void FormSimpleImpl::val3Clicked () +{ + engine->pushValue ('3'); +} + +void FormSimpleImpl::val4Clicked () +{ + engine->pushValue ('4'); +} + +void FormSimpleImpl::val5Clicked () +{ + engine->pushValue ('5'); +} + +void FormSimpleImpl::val6Clicked () +{ + engine->pushValue ('6'); +} + +void FormSimpleImpl::val7Clicked () +{ + engine->pushValue ('7'); +} + +void FormSimpleImpl::val8Clicked () +{ + engine->pushValue ('8'); +} + +void FormSimpleImpl::val9Clicked () +{ + engine->pushValue ('9'); +} + +void FormSimpleImpl::val0Clicked () +{ + engine->pushValue ('0'); +} diff --git a/noncore/tools/calc2/simple/simpleimpl.h b/noncore/tools/calc2/simple/simpleimpl.h new file mode 100644 index 0000000..a2db154 --- a/dev/null +++ b/noncore/tools/calc2/simple/simpleimpl.h @@ -0,0 +1,65 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#ifndef STANDARDIMPL_H +#define STANDARDIMPL_H + +#include +#include + +#include "simple.h" +#include "engine.h" +#include "instruction.h" + +class FormSimpleImpl:public FormSimple { +Q_OBJECT +public: + FormSimpleImpl (Engine *e, QWidget * parent = 0, const char *name = 0) + :FormSimple (parent, name) {engine = e;engine->setRepresentation(rDouble);}; + + ~FormSimpleImpl () { }; + +private: + Engine *engine; + +private slots: + void MPlusClicked(); + void MCClicked(); + void MRClicked(); + void CEClicked(); + void evalClicked(); + void addClicked (); + void decimalClicked (); + void divClicked (); + void mulClicked (); + void subClicked (); + void val0Clicked (); + void val1Clicked (); + void val2Clicked (); + void val3Clicked (); + void val4Clicked (); + void val5Clicked (); + void val6Clicked (); + void val7Clicked (); + void val8Clicked (); + void val9Clicked (); +}; + +#endif diff --git a/noncore/tools/calc2/stdinstructions.h b/noncore/tools/calc2/stdinstructions.h new file mode 100644 index 0000000..a575968 --- a/dev/null +++ b/noncore/tools/calc2/stdinstructions.h @@ -0,0 +1,125 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ + +#ifndef STDINSTRUCTION_H +#define STDINSTRUCTION_H + +#include +#include "instruction.h" + +// Useful instructions for plugin writers +// If you use them, take note of their precedence +class iAdd:public Instruction { +public: + iAdd ():Instruction (10) { }; + ~iAdd () { }; + Data eval (Data num) { + Data result; + switch (rep) { + case rDouble: + result.dbl = acc.dbl + num.dbl; + break; + default: + result.i = acc.i + num.i; + }; + return result; + }; +}; +class iSub:public Instruction { +public: + iSub ():Instruction (10) { }; + ~iSub () { }; + Data eval (Data num) { + Data result; + switch (rep) { + case rDouble: + result.dbl = acc.dbl - num.dbl; + break; + default: + result.i = acc.i - num.i; + }; + return result; + }; +}; +class iMul:public Instruction { +public: + iMul ():Instruction (20) { }; + ~iMul () { }; + Data eval (Data num) { + Data result; + switch (rep) { + case rDouble: + result.dbl = acc.dbl * num.dbl; + break; + default: + result.i = acc.i * num.i; + }; + return result; + }; +}; +class iDiv:public Instruction { +public: + iDiv ():Instruction (20) { }; + ~iDiv () { }; + Data eval (Data num) { + Data result; + switch (rep) { + case rDouble: + result.dbl = acc.dbl / num.dbl; + break; + default: + result.i = acc.i / num.i; + }; + return result; + }; +}; + +// Immediate double instructions only +class iSin:public Instruction { +public: + iSin ():Instruction () { }; + ~iSin () { }; + Data eval (Data num) { + Data result; + result.dbl = qSin(num.dbl); + return result; + }; +}; +class iCos:public Instruction { +public: + iCos ():Instruction () { }; + ~iCos () { }; + Data eval (Data num) { + Data result; + result.dbl = qCos(num.dbl); + return result; + }; +}; +class iTan:public Instruction { +public: + iTan ():Instruction () { }; + ~iTan () {}; + Data eval (Data num) { + Data result; + result.dbl = qTan(num.dbl); + return result; + }; +}; +#endif -- cgit v0.9.0.2