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') 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 diff --git a/noncore/tools/calculator/.cvsignore b/noncore/tools/calculator/.cvsignore new file mode 100644 index 0000000..f5bf2df --- a/dev/null +++ b/noncore/tools/calculator/.cvsignore @@ -0,0 +1,4 @@ +moc_* +Makefile +calculator.h +calculator.cpp diff --git a/noncore/tools/calculator/Makefile.in b/noncore/tools/calculator/Makefile.in new file mode 100644 index 0000000..d62b046 --- a/dev/null +++ b/noncore/tools/calculator/Makefile.in @@ -0,0 +1,139 @@ +############################################################################# + +####### Compiler, tools and options + +CXX = $(SYSCONF_CXX) $(QT_CXX_MT) +CXXFLAGS= $(SYSCONF_CXXFLAGS_QT) $(SYSCONF_CXXFLAGS) +CC = $(SYSCONF_CC) $(QT_C_MT) +CFLAGS = $(SYSCONF_CFLAGS) +INCPATH = -I$(QPEDIR)/include +LFLAGS = $(SYSCONF_LFLAGS_QT) $(SYSCONF_RPATH_QT) $(SYSCONF_LFLAGS) $(QT_LFLAGS_MT) +LIBS = $(SUBLIBS) -lqpe $(SYSCONF_LIBS_QT) $(SYSCONF_LIBS) $(SYSCONF_LIBS_QTAPP) +MOC = $(SYSCONF_MOC) +UIC = $(SYSCONF_UIC) + +####### Target + +DESTDIR = $(QPEDIR)/bin/ +VER_MAJ = 1 +VER_MIN = 0 +VER_PATCH = 0 +TARGET = calculator +TARGET1 = lib$(TARGET).so.$(VER_MAJ) + +####### Files + +HEADERS = calculatorimpl.h +SOURCES = calculatorimpl.cpp \ + main.cpp +OBJECTS = calculatorimpl.o \ + main.o \ + calculator.o +INTERFACES = calculator.ui +UICDECLS = calculator.h +UICIMPLS = calculator.cpp +SRCMOC = moc_calculatorimpl.cpp \ + moc_calculator.cpp +OBJMOC = moc_calculatorimpl.o \ + moc_calculator.o + + +####### 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: $(DESTDIR)$(TARGET) + +$(DESTDIR)$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS) + $(SYSCONF_LINK) $(LFLAGS) -o $(DESTDIR)$(TARGET) $(OBJECTS) $(OBJMOC) $(LIBS) + +moc: $(SRCMOC) + +tmake: + tmake calculator.pro + +clean: + -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS) + -rm -f *~ core + -rm -f allmoc.cpp + +####### Extension Modules + +listpromodules: + @echo + +listallmodules: + @echo + +listaddonpromodules: + @echo + +listaddonentmodules: + @echo + + +REQUIRES= + +####### Sub-libraries + + +###### Combined headers + + + +####### Compile + +calculatorimpl.o: calculatorimpl.cpp \ + calculatorimpl.h \ + calculator.h \ + $(QPEDIR)/include/qpe/resource.h \ + $(QPEDIR)/include/qpe/qmath.h \ + $(QPEDIR)/include/qpe/qpeapplication.h + +main.o: main.cpp \ + calculatorimpl.h \ + calculator.h \ + $(QPEDIR)/include/qpe/qpeapplication.h + +calculator.h: calculator.ui + $(UIC) calculator.ui -o calculator.h + +calculator.cpp: calculator.ui + $(UIC) calculator.ui -i calculator.h -o calculator.cpp + +calculator.o: calculator.cpp \ + calculator.h \ + calculator.ui + +moc_calculatorimpl.o: moc_calculatorimpl.cpp \ + calculatorimpl.h \ + calculator.h + +moc_calculator.o: moc_calculator.cpp \ + calculator.h + +moc_calculatorimpl.cpp: calculatorimpl.h + $(MOC) calculatorimpl.h -o moc_calculatorimpl.cpp + +moc_calculator.cpp: calculator.h + $(MOC) calculator.h -o moc_calculator.cpp + + diff --git a/noncore/tools/calculator/calculator.pro b/noncore/tools/calculator/calculator.pro new file mode 100644 index 0000000..1281fd5 --- a/dev/null +++ b/noncore/tools/calculator/calculator.pro @@ -0,0 +1,13 @@ +DESTDIR = $(QPEDIR)/bin +TEMPLATE = app +CONFIG = qt warn_on release +HEADERS = calculatorimpl.h +SOURCES = calculatorimpl.cpp \ + main.cpp +INCLUDEPATH += $(QPEDIR)/include +DEPENDPATH += $(QPEDIR)/include +LIBS += -lqpe +INTERFACES = calculator.ui +TARGET = calculator + +TRANSLATIONS = ../i18n/de/calculator.ts diff --git a/noncore/tools/calculator/calculator.ui b/noncore/tools/calculator/calculator.ui new file mode 100644 index 0000000..e8218ab --- a/dev/null +++ b/noncore/tools/calculator/calculator.ui @@ -0,0 +1,1026 @@ + +Calculator +********************************************************************* +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qt Palmtop 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. +** +********************************************************************* + + QWidget + + name + Calculator + + + geometry + + 0 + 0 + 271 + 404 + + + + sizePolicy + + 5 + 5 + + + + maximumSize + + 32767 + 32767 + + + + baseSize + + 235 + 100 + + + + caption + Experimental Calculator + + + layoutMargin + + + layoutSpacing + + + + margin + 0 + + + spacing + 0 + + + QLCDNumber + + name + LCD + + + sizePolicy + + 1 + 1 + + + + font + + 7 + + + + numDigits + 15 + + + segmentStyle + Flat + + + + QLayoutWidget + + name + Layout4 + + + + margin + 0 + + + spacing + 0 + + + QComboBox + + name + ComboBoxFunction + + + sizePolicy + + 1 + 1 + + + + + QPushButton + + name + PushButtonMPlus + + + sizePolicy + + 5 + 5 + + + + focusPolicy + TabFocus + + + text + M+ + + + + QPushButton + + name + PushButtonMR + + + sizePolicy + + 5 + 5 + + + + focusPolicy + TabFocus + + + text + MR + + + + QPushButton + + name + PushButtonMC + + + sizePolicy + + 5 + 5 + + + + focusPolicy + TabFocus + + + text + MC + + + + QPushButton + + name + PushButtonCE + + + sizePolicy + + 5 + 5 + + + + focusPolicy + TabFocus + + + text + CE + + + + + + QLayoutWidget + + name + Layout10 + + + layoutSpacing + + + + margin + 0 + + + spacing + 0 + + + QPushButton + + name + PushButtonF6 + + + sizePolicy + + 5 + 5 + + + + text + + + + + QPushButton + + name + PushButtonF7 + + + sizePolicy + + 5 + 5 + + + + text + + + + + QPushButton + + name + PushButtonF8 + + + sizePolicy + + 5 + 5 + + + + text + log + + + + QPushButton + + name + PushButtonF9 + + + sizePolicy + + 5 + 5 + + + + focusPolicy + TabFocus + + + text + ln + + + + QPushButton + + name + PushButtonF11 + + + sizePolicy + + 5 + 5 + + + + text + ( + + + + QPushButton + + name + PushButtonF12 + + + sizePolicy + + 5 + 5 + + + + text + ) + + + + + + QLayoutWidget + + name + Layout11 + + + layoutSpacing + + + + margin + 0 + + + spacing + 0 + + + QPushButton + + name + PushButtonF1 + + + sizePolicy + + 5 + 5 + + + + focusPolicy + TabFocus + + + text + sin + + + + QPushButton + + name + PushButtonF2 + + + sizePolicy + + 5 + 5 + + + + focusPolicy + TabFocus + + + text + cos + + + + QPushButton + + name + PushButtonF3 + + + sizePolicy + + 5 + 5 + + + + focusPolicy + TabFocus + + + text + tan + + + + QPushButton + + name + PushButtonF4 + + + sizePolicy + + 5 + 5 + + + + focusPolicy + TabFocus + + + text + + + + + QPushButton + + name + PushButtonF5 + + + sizePolicy + + 5 + 5 + + + + focusPolicy + TabFocus + + + text + % + + + + QPushButton + + name + PushButtonF10 + + + sizePolicy + + 5 + 5 + + + + focusPolicy + TabFocus + + + text + +/- + + + + + + QLayoutWidget + + name + Layout5 + + + + margin + 0 + + + spacing + 0 + + + QPushButton + + name + PushButton3 + + + sizePolicy + + 5 + 5 + + + + font + + adobe-helvetica + 24 + + + + focusPolicy + TabFocus + + + text + 3 + + + + QPushButton + + name + PushButton6 + + + sizePolicy + + 5 + 5 + + + + font + + adobe-helvetica + 24 + + + + focusPolicy + TabFocus + + + text + 6 + + + + QPushButton + + name + PushButtonEquals + + + sizePolicy + + 5 + 5 + + + + font + + adobe-helvetica + 24 + + + + focusPolicy + TabFocus + + + text + = + + + + QPushButton + + name + PushButton0 + + + sizePolicy + + 5 + 5 + + + + font + + adobe-helvetica + 24 + + + + focusPolicy + TabFocus + + + text + 0 + + + + QPushButton + + name + PushButtonMinus + + + sizePolicy + + 5 + 5 + + + + font + + adobe-helvetica + 24 + + + + focusPolicy + TabFocus + + + text + - + + + + QPushButton + + name + PushButtonTimes + + + sizePolicy + + 5 + 5 + + + + font + + adobe-helvetica + 24 + + + + focusPolicy + TabFocus + + + text + x + + + + QPushButton + + name + PushButton4 + + + sizePolicy + + 5 + 5 + + + + font + + adobe-helvetica + 24 + + + + focusPolicy + TabFocus + + + text + 4 + + + + QPushButton + + name + PushButton8 + + + sizePolicy + + 5 + 5 + + + + font + + adobe-helvetica + 24 + + + + focusPolicy + TabFocus + + + text + 8 + + + + QPushButton + + name + PushButtonDivide + + + sizePolicy + + 5 + 5 + + + + font + + adobe-helvetica + 24 + + + + focusPolicy + TabFocus + + + text + / + + + + QPushButton + + name + PushButtonAdd + + + sizePolicy + + 5 + 5 + + + + font + + adobe-helvetica + 24 + + + + focusPolicy + TabFocus + + + text + + + + + + QPushButton + + name + PushButton1 + + + sizePolicy + + 5 + 5 + + + + font + + adobe-helvetica + 24 + + + + focusPolicy + TabFocus + + + text + 1 + + + + QPushButton + + name + PushButtonDecimal + + + sizePolicy + + 5 + 5 + + + + font + + adobe-helvetica + 24 + + + + focusPolicy + TabFocus + + + text + . + + + + QPushButton + + name + PushButton5 + + + sizePolicy + + 5 + 5 + + + + font + + adobe-helvetica + 24 + + + + focusPolicy + TabFocus + + + text + 5 + + + + QPushButton + + name + PushButton7 + + + sizePolicy + + 5 + 5 + + + + font + + adobe-helvetica + 24 + + + + focusPolicy + TabFocus + + + text + 7 + + + + QPushButton + + name + PushButton9 + + + sizePolicy + + 5 + 5 + + + + font + + adobe-helvetica + 24 + + + + focusPolicy + TabFocus + + + text + 9 + + + + QPushButton + + name + PushButton2 + + + sizePolicy + + 5 + 5 + + + + font + + adobe-helvetica + 24 + + + + focusPolicy + TabFocus + + + text + 2 + + + + + + + + ComboBoxFunction + PushButtonMPlus + PushButtonMR + PushButtonMC + PushButtonCE + PushButtonF6 + PushButtonF7 + PushButtonF8 + PushButtonF9 + PushButtonF11 + PushButtonF12 + PushButtonF1 + PushButtonF2 + PushButtonF3 + PushButtonF4 + PushButtonF5 + PushButtonF10 + PushButton7 + PushButton8 + PushButton9 + PushButtonAdd + PushButton4 + PushButton5 + PushButton6 + PushButtonMinus + PushButton1 + PushButton2 + PushButton3 + PushButtonTimes + PushButton0 + PushButtonDecimal + PushButtonEquals + PushButtonDivide + + diff --git a/noncore/tools/calculator/calculatorimpl.cpp b/noncore/tools/calculator/calculatorimpl.cpp new file mode 100644 index 0000000..2f7d7ce --- a/dev/null +++ b/noncore/tools/calculator/calculatorimpl.cpp @@ -0,0 +1,601 @@ +/********************************************************************** +** 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 "calculatorimpl.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +CalculatorImpl::CalculatorImpl( QWidget * parent, const char * name, + WFlags f ) + : Calculator( parent, name, f ) +{ + xtopowerofy = Resource::loadPixmap("xtopowerofy"); + ythrootofx = Resource::loadPixmap("ythrootofx"); + oneoverx = Resource::loadPixmap("oneoverx"); + + memMark = new QLabel( "m", LCD ); + memMark->setFont( QFont( "helvetica", 12, QFont::Bold, TRUE ) ); + memMark->resize( 12, 12 ); + memMark->move( 4, 2 ); + memMark->hide(); + mem = 0; + + PushButtonMR->setEnabled( FALSE ); + + current_mode = max_mode = conversion_mode_count = 0; + last_conversion = -1; + +//bgr_command.insert( PushButtonFunction); + bgr_command.insert( PushButtonMPlus); + bgr_command.insert( PushButtonMR); + bgr_command.insert( PushButtonMC); + bgr_command.insert( PushButtonCE); + connect( &bgr_command, SIGNAL(clicked(int) ), this, SLOT(command_buttons(int))); + + bgr_digits.insert(PushButton0); + bgr_digits.insert(PushButton1); + bgr_digits.insert(PushButton2); + bgr_digits.insert(PushButton3); + bgr_digits.insert(PushButton4); + bgr_digits.insert(PushButton5); + bgr_digits.insert(PushButton6); + bgr_digits.insert(PushButton7); + bgr_digits.insert(PushButton8); + bgr_digits.insert(PushButton9); + connect( &bgr_digits, SIGNAL(clicked(int) ), this, SLOT(enterNumber(int))); + + + bgr_std.insert(PushButtonEquals); + bgr_std.insert(PushButtonDecimal); + bgr_std.insert(PushButtonAdd); + bgr_std.insert(PushButtonMinus); + bgr_std.insert(PushButtonDivide); + bgr_std.insert(PushButtonTimes); + connect( &bgr_std, SIGNAL(clicked(int) ), this, SLOT(std_buttons(int))); + +// change the / to a proper division signal + PushButtonDivide->setText(QChar(0xF7)); + + func_buttons[0] = PushButtonF1; + func_buttons[1] = PushButtonF2; + func_buttons[2] = PushButtonF3; + func_buttons[3] = PushButtonF4; + func_buttons[4] = PushButtonF5; + func_buttons[5] = PushButtonF6; + func_buttons[6] = PushButtonF7; + func_buttons[7] = PushButtonF8; + func_buttons[8] = PushButtonF9; + func_buttons[9] = PushButtonF10; + func_buttons[10] = PushButtonF11; + func_buttons[11] = PushButtonF12; + + for ( int x = 0 ; x < func_button_count ; x++ ) { + QPushButton* tmpbutton = func_buttons[x]; + faces << tmpbutton->text(); + bgr_function.insert(tmpbutton); + } + connect( &bgr_function, SIGNAL(clicked(int) ) , this, SLOT(do_convert(int) ) ); + connect( &bgr_function, SIGNAL(clicked(int) ) , this, SLOT(std_funcs (int) ) ); + + connect(ComboBoxFunction, SIGNAL(activated(int) ), this, SLOT(function_button(int) ) ); + + captions.append("Standard"); + ComboBoxFunction->insertItem(captions.last()); + + // now add in the conversion modes + // when the menu gets done, these should be in a submenu + QString tmp = QPEApplication::qpeDir(); + tmp += "/etc/unit_conversion.dat"; + QFile myfile(tmp); + if ( !myfile.open( IO_Translate | IO_ReadOnly ) ) { + // QMessageBox::warning(this, "Warning", "Data file\nunit_conversion.dat\nnot found\nNo conversion\nfeatures will\nbe available"); + // disable the f button if no conv file available + ComboBoxFunction->setEnabled(FALSE); + } + else { + QString line, line2; + QTextStream ts(&myfile); + + // first pass, see how many conversion types there are in order to allocate for them + while ( ! ts.eof() ) { + line = ts.readLine(); + if ( line.contains ("STARTTYPE" ) ) + conversion_mode_count++; + } + + entry_list = new double[conversion_mode_count*func_button_count]; + + myfile.close(); + myfile.open( IO_Translate | IO_ReadOnly ); + QTextStream ts2(&myfile); + + // second pass, read in values + int x = 0; + while ( ! ts2.eof() ) { + line = ts2.readLine(); + if ( line.contains("STARTTYPE") ) { + captions << line.remove(0,10); + ComboBoxFunction->insertItem(captions.last()); + while ( !line.contains("ENDTYPE") ) { + line = ts2.readLine(); + if ( line.contains("NAME") ) { + faces << line.remove(0,5); + line2 = ts2.readLine(); + line2.remove(0,6); + entry_list[x] = line2.toDouble(); + x++; + } + } + } + } + } + myfile.close(); + clear(); + max_mode = pre_conv_modes_count + conversion_mode_count + post_conv_modes_count - 1; + display_pixmap_faces(); + + qApp->installEventFilter( this ); +} + +bool CalculatorImpl::eventFilter( QObject *o, QEvent *e ) +{ + if ( e->type() == QEvent::KeyPress && state != sError ) { + QKeyEvent *k = (QKeyEvent*)e; + if ( k->key() >= Key_0 && k->key() <= Key_9 ) { + enterNumber( k->key() - Key_0 ); + return true; + } else { + switch ( k->key() ) { + case Key_Equal: + std_buttons(0); + return true; + case Key_Period: + std_buttons(1); + return true; + case Key_Plus: + std_buttons(2); + return true; + case Key_Minus: + std_buttons(3); + return true; + case Key_Slash: + std_buttons(4); + return true; + case Key_Asterisk: + std_buttons(5); + return true; + case Key_Percent: + execOp( oPercent ); + return true; + case Key_ParenLeft: + if ( current_mode < pre_conv_modes_count ) + execOp( oOpenBrace ); + return true; + case Key_ParenRight: + if ( current_mode < pre_conv_modes_count ) + execOp( oCloseBrace ); + return true; + default: + break; + } + } + } + return Calculator::eventFilter( o, e ); +} + +void CalculatorImpl::do_convert(int button) { + if ( state == sError ) + return; + if ( current_mode >= pre_conv_modes_count && current_mode <= (max_mode - post_conv_modes_count) && + button < changeable_func_button_count ) { + if ( last_conversion > -1 ) { + if( state == sNewNumber ){ + acc = num + / (entry_list[(current_mode - pre_conv_modes_count) * func_button_count + last_conversion]) + * (entry_list[(current_mode - pre_conv_modes_count) * func_button_count + button]) ; + num = acc; + LCD->display( acc ); + } else { + state = sNewNumber; + num = num + / (entry_list[(current_mode - pre_conv_modes_count) * func_button_count + last_conversion]) + * (entry_list[(current_mode - pre_conv_modes_count) * func_button_count + button]) ; + LCD->display( num ); + acc = num; + } + } + last_conversion = button; + } +} + + +void CalculatorImpl::function_button(int mode){ + if ( state == sError ) + clear(); + // dont need the next line when using a popup menu + current_mode = mode; + + // reset the last conv + last_conversion = -1; + + // set the caption + this->setCaption( captions[current_mode] ); + + reset_conv(); + + for ( int x = 0 ; x < changeable_func_button_count ; x++ ) { + QPushButton* tmpbutton = func_buttons[x]; + + // if its a conversion , make it a toggle button + if ( current_mode >= pre_conv_modes_count && current_mode <= (max_mode - post_conv_modes_count) ) { + tmpbutton->setToggleButton(TRUE); + } else { + tmpbutton->setToggleButton(FALSE); + } + tmpbutton->setText( faces[current_mode * func_button_count + x] ); + } + + if ( current_mode == 0 ) display_pixmap_faces(); + + if ( current_mode >= pre_conv_modes_count && current_mode <= (max_mode - post_conv_modes_count) ) { + bgr_function.setExclusive(TRUE); + } else { + bgr_function.setExclusive(FALSE); + } +} + +void CalculatorImpl::display_pixmap_faces() { + QPushButton* tmpbutton = func_buttons[5]; + tmpbutton->setPixmap(xtopowerofy); + + tmpbutton = func_buttons[6]; + tmpbutton->setPixmap(ythrootofx); + + tmpbutton = func_buttons[3]; + tmpbutton->setPixmap(oneoverx); +} + +void CalculatorImpl::clear() { + acc = num = 0; + operationStack.clear(); + state = sStart; + numDecimals = 0; + numOpenBraces = 0; + flPoint = FALSE; + LCD->display( 0 ); + fake = QString::null; + + reset_conv(); +} + +void CalculatorImpl::reset_conv() { + for ( int x = 0 ; x < changeable_func_button_count ; x++ ) { + QPushButton* tmpbutton = func_buttons[x]; + + // dont carry any selections into the next mode + if ( tmpbutton->state() == QPushButton::On ) { + tmpbutton->toggle(); + } + } + + last_conversion = -1; +} + +void CalculatorImpl::std_buttons(int button) +{ + if ( state == sError ) + return; + execOp( (Operation)(button + oSum) ); +} + +void CalculatorImpl::std_funcs(int button) { + if ( state == sError ) + return; + if ( current_mode < pre_conv_modes_count || + button > changeable_func_button_count-1 ) { + Operation op; + if ( button < 10 ) + op = (Operation)(button + oSin); + else if ( button == 10 ) + op = oOpenBrace; + else + op = oCloseBrace; + execOp( op ); + } +} + +void CalculatorImpl::execOp( Operation i ) +{ + switch (i) { + // these operators only affect the current number. + case oDivX: + case oLog: + case oLn: + case oSin: + case oCos: + case oTan: + num = evalExpr(i); + break; + + case oAdd: + case oSub: { + processStack( oAdd ); + Op op( num, i ); + operationStack.push( op ); + break; + } + case oDiv: + case oMult: + case oRoot: + case oXsquared: { + processStack( oDiv ); + Op op( num, i ); + operationStack.push( op ); + break; + } + case oChSign: + num = -num; + LCD->display(num); + return; + + case oOpenBrace: { + Op op( 0, oOpenBrace ); + operationStack.push( op ); + numOpenBraces++; + state = sNewNumber; + return; + } + case oCloseBrace: { + if ( numOpenBraces == 0 ) + return; + processStack( oAdd ); + if ( operationStack.top().operation != oOpenBrace ) + qDebug( "Calculator: internal Error" ); + operationStack.pop(); + state = sNewNumber; + numOpenBraces--; + break; + } + + case oPoint: + flPoint = TRUE; + return; + + case oPercent: + processStack( oPercent ); + break; + + + case oSum: + processStack( oSum ); + break; + + default: + return; + }; + + if ( state == sError ) { + LCD->display( "Error" ); + return; + } else { + LCD->display(num); + } + state = sNewNumber; + numDecimals = 0; + flPoint = FALSE; +} + + +void CalculatorImpl::processStack( int op ) +{ + //dubious percent hack, since the changeable operator precedences are + //pretty much hardwired to be less than the non-changeable + bool percent = FALSE; + if ( op == oPercent ) { + percent = TRUE; + op = oSum; + } + while( !operationStack.isEmpty() && operationStack.top().operation >= op ) { + Op operation = operationStack.pop(); + acc = operation.number; + if ( percent ) { + if ( operation.operation == oAdd || operation.operation == oSub ) + num = acc*num/100; + else + num = num / 100; + } + num = evalExpr( operation.operation ); + percent = FALSE; + } +} + + +double CalculatorImpl::evalExpr( int op ) { + double sum = 0; + + switch( op ){ + case oPercent: sum = num / 100.; break; + case oDivX: + if (num == 0) + state = sError; + else + sum = 1 / num; + break; + case oXsquared: + sum = pow(acc,num); + break; + case oChSign: (state == sStart) ? sum = -num : sum = -acc; break; + case oSub: sum = acc - num; break; + case oMult: sum = acc * num; break; + case oAdd: sum = acc + num; break; + case oDiv: { + if (num == 0) { + state = sError; + } else { + sum = acc / num; + } + break; + } + case oRoot: + /* the linux library is dumb, and can't to -x to 1/n + when n is odd. (even and error of course is acceptable */ + if((acc < 0) && (int(num) == num) && (int(num) % 2 == 1 )) { + sum = pow(-acc, 1 / num); + sum = -sum; + } else { + sum = pow(acc, 1 / num); + } + break; + case oLog: + sum = log10(num); + break; + case oLn: + sum = log(num); + break; + case oTan: sum = qTan(num);break; + case oSin: sum = qSin(num);break; + case oCos: sum = qCos(num);break; + default: sum = num; break; + } + + if ( isinf( sum ) || isnan( sum ) ) + state = sError; + return sum; +} + + +void CalculatorImpl::enterNumber( int n ) +{ + if ( state == sError ) + return; + if( state == sStart ){ + if( LCD->value() > 0 ){ + QString s = QString::number( LCD->value(), 'g', LCD->numDigits()); + if( s.length() > (uint)(LCD->numDigits() - 2)) return; + + } else if( (int)fake.length() >= LCD->numDigits() || numDecimals >=12 ){ + return; + } + } + + if( state == sNewNumber ){ + state = sStart; + acc = 0; + if( flPoint ){ + numDecimals = 1; + num = n / pow(10, numDecimals); + } else + num = n; + } else if( flPoint ){ + numDecimals++; + if( num < 0 ){ + num -= n / pow(10, numDecimals); + } else { + num += n / pow(10, numDecimals); + } + } else { + num *= 10; + if( num < 0 ) + num -= n; + else + num += n; + } + + // We need feedback in the calc display while entering fl.point zeros. + // This is a small hack to display sequences like: 0.000 and 1.100 + double integer, fraction; + fraction = modf( num, &integer ); + if( flPoint ){ + QString is, fs, zeros; + + is = QString::number( integer, 'g', 13 ); + fs = QString::number( fraction, 'g', numDecimals ); + if( fs.contains('e') ){ + fs = QString::number( fraction, 'f', LCD->numDigits() ); + } + fs = fs.mid( 2, numDecimals ); + + if( (integer == 0) && (fraction == 0) ) + fake = "0."; + else if( (integer != 0) && (fraction == 0) ) + fake = is + "."; + else + fake = is + "." + fs; + + zeros.fill( '0', (numDecimals - fs.length()) ); + fake += zeros; + // ### This code sets LCD->value() to zero since it sets a text + // ### Avoid getting the current value from LCD->value() for + // ### calculations. + LCD->display( fake ); + } else + LCD->display( num ); +} + +void CalculatorImpl::command_buttons(int i) { + if ( state == sError && i != 3 ) + return; + switch (i) { + case 0: // M+ + mem += num; + if( mem != 0 ){ + memMark->show(); + PushButtonMR->setEnabled( TRUE ); }; + state = sNewNumber; + break; + case 1: // MR + acc = num = mem; + state = sNewNumber; + LCD->display( mem ); + break; + case 2: // MC + mem = 0; + memMark->hide(); + PushButtonMR->setEnabled( FALSE ); + break; + case 3: // CE + if ( state == sStart ) { + // clear the entered number on the first press + state = sNewNumber; + num = acc = 0; + flPoint = FALSE; + LCD->display( 0 ); + fake = QString::null; + numDecimals = 0; + } else { + clear(); + } + break; + }; + +} diff --git a/noncore/tools/calculator/calculatorimpl.h b/noncore/tools/calculator/calculatorimpl.h new file mode 100644 index 0000000..bfb726f --- a/dev/null +++ b/noncore/tools/calculator/calculatorimpl.h @@ -0,0 +1,135 @@ +/********************************************************************** +** 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 CALCULATORIMPL_H +#define CALCULATORIMPL_H + + +#include +#include "calculator.h" +#include +#include +#include + +// mode x functions +enum Operation { + oNop, + oOpenBrace, + oCloseBrace, + oSum, + oPoint, + oAdd, + oSub, + oDiv, + oMult, + +// mode 0 functions + oSin, + oCos, + oTan, + oDivX, + oPercent, + oXsquared, + oRoot, + oLog, + oLn, + oChSign +}; + +// states +#define sStart 0 +#define sNewNumber 1 +#define sError 2 + +struct Op +{ + Op() { number = 0; operation = oNop; } + Op( double num, Operation op ) + { number = num; operation = op; } + double number; + Operation operation; +}; + +class QLabel; +class CalculatorImpl : public Calculator +{ + Q_OBJECT + +public: + CalculatorImpl( QWidget * parent = 0, const char * name = 0, + WFlags f = 0 ); + +public slots: + void command_buttons(int); + void enterNumber(int i); + void std_buttons(int); + void std_funcs(int); + void do_convert(int); + void function_button(int); + +protected: + virtual bool eventFilter( QObject *o, QEvent *e ); + +private: + void clear(); + + void reset_conv(); + + void processStack( int op ); + + QValueStack operationStack; + int state; + + double acc, num, mem; + int numDecimals; + bool flPoint; + int numOpenBraces; + + void execOp( Operation i ); + double evalExpr( int op ); + QLabel * memMark; + QString fake; + + // useful values for conversion stuff + int current_mode, max_mode, conversion_mode_count, last_conversion; + + // make adding new modes easier for ourselves + static const int pre_conv_modes_count = 1; + static const int post_conv_modes_count = 0; + + // an array of pointers to the func buttons + static const int func_button_count = 12; + // this is an abomination + static const int changeable_func_button_count = 10; + QPushButton* func_buttons[func_button_count]; + + QButtonGroup bgr_function, bgr_digits, bgr_std, bgr_command; + QStringList faces, captions; + + // an array of doubles holding the conversion ratios + double* entry_list; + + QPixmap xtopowerofy; + QPixmap ythrootofx; + QPixmap oneoverx; + + void display_pixmap_faces(void); +}; + +#endif diff --git a/noncore/tools/calculator/main.cpp b/noncore/tools/calculator/main.cpp new file mode 100644 index 0000000..74cd5d3 --- a/dev/null +++ b/noncore/tools/calculator/main.cpp @@ -0,0 +1,35 @@ +/********************************************************************** +** 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 "calculatorimpl.h" + +#include + +int main( int argc, char ** argv ) +{ + QPEApplication a( argc, argv ); + + CalculatorImpl mw; + QPEApplication::setInputMethodHint( &mw, QPEApplication::AlwaysOff ); + mw.setCaption( CalculatorImpl::tr("Calculator") ); + a.showMainWidget( &mw ); + + return a.exec(); +} diff --git a/noncore/tools/calculator/qpe-calculator.control b/noncore/tools/calculator/qpe-calculator.control new file mode 100644 index 0000000..afef70b --- a/dev/null +++ b/noncore/tools/calculator/qpe-calculator.control @@ -0,0 +1,10 @@ +Files: bin/calculator apps/Applications/calculator.desktop etc/unit_conversion.dat +Priority: optional +Section: qpe/applications +Maintainer: Warwick Allison +Architecture: arm +Version: $QPE_VERSION-3 +Depends: qpe-base ($QPE_VERSION) +Description: Calculator + A multi-function calculator for the Qtopia environment. + Includes units conversion. diff --git a/noncore/tools/clock/.cvsignore b/noncore/tools/clock/.cvsignore new file mode 100644 index 0000000..6fe2396 --- a/dev/null +++ b/noncore/tools/clock/.cvsignore @@ -0,0 +1,2 @@ +moc_* +Makefile diff --git a/noncore/tools/clock/Makefile.in b/noncore/tools/clock/Makefile.in new file mode 100644 index 0000000..adda9e6 --- a/dev/null +++ b/noncore/tools/clock/Makefile.in @@ -0,0 +1,118 @@ +############################################################################# + +####### Compiler, tools and options + +CXX = $(SYSCONF_CXX) $(QT_CXX_MT) +CXXFLAGS= $(SYSCONF_CXXFLAGS_QT) $(SYSCONF_CXXFLAGS) +CC = $(SYSCONF_CC) $(QT_C_MT) +CFLAGS = $(SYSCONF_CFLAGS) +INCPATH = -I$(QPEDIR)/include +LFLAGS = $(SYSCONF_LFLAGS_QT) $(SYSCONF_RPATH_QT) $(SYSCONF_LFLAGS) $(QT_LFLAGS_MT) +LIBS = $(SUBLIBS) -lqpe $(SYSCONF_LIBS_QT) $(SYSCONF_LIBS) $(SYSCONF_LIBS_QTAPP) +MOC = $(SYSCONF_MOC) +UIC = $(SYSCONF_UIC) + +####### Target + +DESTDIR = $(QPEDIR)/bin/ +VER_MAJ = 1 +VER_MIN = 0 +VER_PATCH = 0 +TARGET = clock +TARGET1 = lib$(TARGET).so.$(VER_MAJ) + +####### Files + +HEADERS = clock.h +SOURCES = clock.cpp \ + main.cpp +OBJECTS = clock.o \ + main.o +INTERFACES = +UICDECLS = +UICIMPLS = +SRCMOC = moc_clock.cpp +OBJMOC = moc_clock.o + + +####### 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: $(DESTDIR)$(TARGET) + +$(DESTDIR)$(TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS) + $(SYSCONF_LINK) $(LFLAGS) -o $(DESTDIR)$(TARGET) $(OBJECTS) $(OBJMOC) $(LIBS) + +moc: $(SRCMOC) + +tmake: + tmake clock.pro + +clean: + -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS) + -rm -f *~ core + -rm -f allmoc.cpp + +####### Extension Modules + +listpromodules: + @echo + +listallmodules: + @echo + +listaddonpromodules: + @echo + +listaddonentmodules: + @echo + + +REQUIRES= + +####### Sub-libraries + + +###### Combined headers + + + +####### Compile + +clock.o: clock.cpp \ + clock.h \ + $(QPEDIR)/include/qpe/qpeapplication.h \ + $(QPEDIR)/include/qpe/qcopenvelope_qws.h \ + $(QPEDIR)/include/qpe/config.h \ + $(QPEDIR)/include/qpe/timestring.h + +main.o: main.cpp \ + clock.h \ + $(QPEDIR)/include/qpe/qpeapplication.h + +moc_clock.o: moc_clock.cpp \ + clock.h + +moc_clock.cpp: clock.h + $(MOC) clock.h -o moc_clock.cpp + + diff --git a/noncore/tools/clock/clock.cpp b/noncore/tools/clock/clock.cpp new file mode 100644 index 0000000..ef93e11 --- a/dev/null +++ b/noncore/tools/clock/clock.cpp @@ -0,0 +1,319 @@ +/********************************************************************** +** 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 "clock.h" + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +const double deg2rad = 0.017453292519943295769; // pi/180 +const int sw_prec = 2; + +static void toggleScreenSaver( bool on ) +{ + QCopEnvelope e("QPE/System", "setScreenSaverMode(int)" ); + e << (on ? QPEApplication::Enable: QPEApplication::DisableSuspend ); +} + +Clock::Clock( QWidget * parent, const char * name, WFlags f ) + : QVBox( parent, name , f ) +{ + setSpacing( 4 ); + setMargin( 1 ); + + Config config( "qpe" ); + config.setGroup("Time"); + ampm = config.readBoolEntry( "AMPM", TRUE ); + + aclock = new AnalogClock( this ); + aclock->display( QTime::currentTime() ); + aclock->setLineWidth( 2 ); + + QHBox *hb = new QHBox( this ); + hb->setMargin( 0 ); + QWidget *space = new QWidget( hb ); + lcd = new QLCDNumber( hb ); + lcd->setSegmentStyle( QLCDNumber::Flat ); + lcd->setFrameStyle( QFrame::NoFrame ); + lcd->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) ); + lcd->setFixedHeight( 23 ); + + ampmLabel = new QLabel( "PM", hb ); + ampmLabel->setFont( QFont( "Helvetica", 14, QFont::Bold ) ); + ampmLabel->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Preferred ) ); + ampmLabel->setAlignment( AlignLeft | AlignBottom ); + space = new QWidget( hb ); + + date = new QLabel( this ); + date->setAlignment( AlignHCenter | AlignVCenter ); + date->setFont( QFont( "Helvetica", 14, QFont::Bold ) ); + date->setText( TimeString::longDateString( QDate::currentDate() ) ); + + QWidget *controls = new QWidget( this ); + QGridLayout *gl = new QGridLayout( controls, 2, 2, 6, 4 ); + + QButtonGroup *grp = new QButtonGroup( controls ); + grp->setRadioButtonExclusive( true ); + grp->hide(); + + clockRB = new QRadioButton ( tr( "Clock" ), controls ); + gl->addWidget( clockRB, 0, 0 ); + grp->insert( clockRB ); + + swatchRB = new QRadioButton ( tr( "Stopwatch" ), controls ); + gl->addWidget( swatchRB, 1, 0 ); + grp->insert( swatchRB ); + + connect( grp, SIGNAL(clicked(int)), this, SLOT(modeSelect(int)) ); + grp->setButton( 0 ); + + set = new QPushButton ( controls ); + gl->addWidget( set, 0, 1 ); + set->setText( tr( "Start" ) ); + set->setEnabled( FALSE ); + grp->insert( set ); + + reset = new QPushButton ( controls ); + gl->addWidget( reset, 1, 1 ); + reset->setText( tr( "Reset" ) ); + reset->setEnabled( FALSE ); + grp->insert( reset ); + + connect( set, SIGNAL( pressed() ), SLOT( slotSet() ) ); + connect( reset, SIGNAL( clicked() ), SLOT( slotReset() ) ); + + t = new QTimer( this ); + connect( t, SIGNAL( timeout() ), SLOT( updateClock() ) ); + t->start( 1000 ); + + connect( qApp, SIGNAL( timeChanged() ), SLOT( updateClock() ) ); + + swatch_running = FALSE; + swatch_totalms = 0; + + connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(changeClock(bool)) ); + + QTimer::singleShot( 0, this, SLOT(updateClock()) ); + modeSelect(0); +} + +Clock::~Clock() +{ + toggleScreenSaver( true ); +} + +void Clock::updateClock() +{ + if ( clockRB->isChecked() ) { + QTime tm = QDateTime::currentDateTime().time(); + QString s; + if ( ampm ) { + int hour = tm.hour(); + if (hour == 0) + hour = 12; + if (hour > 12) + hour -= 12; + s.sprintf( "%2d%c%02d", hour, ':', tm.minute() ); + ampmLabel->setText( (tm.hour() >= 12) ? "PM" : "AM" ); + ampmLabel->show(); + } else { + s.sprintf( "%2d%c%02d", tm.hour(), ':', tm.minute() ); + ampmLabel->hide(); + } + lcd->display( s ); + lcd->repaint( FALSE ); + aclock->display( QTime::currentTime() ); + date->setText( TimeString::longDateString( QDate::currentDate() ) ); + } else { + QTime swatch_time; + QString lcdtext; + int totalms = swatch_totalms; + if ( swatch_running ) + totalms += swatch_start.elapsed(); + swatch_time = QTime(0,0,0).addMSecs(totalms); + QString d = swatch_running ? QString(" ") + : QString::number(totalms%1000+1000); + lcdtext = swatch_time.toString() + "." + d.right(3).left(sw_prec); + lcd->display( lcdtext ); + lcd->repaint( FALSE ); + aclock->display( swatch_time ); + date->setText( TimeString::longDateString( QDate::currentDate() ) ); + } +} + +void Clock::changeClock( bool a ) +{ + ampm = a; + updateClock(); +} + +void Clock::clearClock( void ) +{ + lcd->display( QTime( 0,0,0 ).toString() ); + aclock->display( QTime( 0,0,0 ) ); +} + +void Clock::slotSet() +{ + if ( t->isActive() ) { + swatch_totalms += swatch_start.elapsed(); + set->setText( tr( "Start" ) ); + t->stop(); + swatch_running = FALSE; + toggleScreenSaver( TRUE ); + updateClock(); + } else { + swatch_start.start(); + set->setText( tr( "Stop" ) ); + t->start( 1000 ); + swatch_running = TRUE; + // disable screensaver while stop watch is running + toggleScreenSaver( FALSE ); + } +} + +void Clock::slotReset() +{ + t->stop(); + swatch_start.start(); + swatch_totalms = 0; + + if (swatch_running ) + t->start(1000); + + updateClock(); +} + +void Clock::modeSelect( int m ) +{ + if ( m ) { + lcd->setNumDigits( 8+1+sw_prec ); + lcd->setMinimumWidth( lcd->sizeHint().width() ); + set->setEnabled( TRUE ); + reset->setEnabled( TRUE ); + ampmLabel->hide(); + + if ( !swatch_running ) + t->stop(); + } else { + lcd->setNumDigits( 5 ); + lcd->setMinimumWidth( lcd->sizeHint().width() ); + set->setEnabled( FALSE ); + reset->setEnabled( FALSE ); + t->start(1000); + } + updateClock(); +} + +QSizePolicy AnalogClock::sizePolicy() const +{ + return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); +} + +void AnalogClock::drawContents( QPainter *p ) +{ + QRect r = contentsRect(); + QPoint center( r.x() + r.width() / 2, r.y() + r.height() / 2 ); + + QPoint l1( r.x() + r.width() / 2, r.y() + 2 ); + QPoint l2( r.x() + r.width() / 2, r.y() + 8 ); + + QPoint h1( r.x() + r.width() / 2, r.y() + r.height() / 4 ); + QPoint h2( r.x() + r.width() / 2, r.y() + r.height() / 2 ); + + QPoint m1( r.x() + r.width() / 2, r.y() + r.height() / 8 ); + QPoint m2( r.x() + r.width() / 2, r.y() + r.height() / 2 ); + + QPoint s1( r.x() + r.width() / 2, r.y() + 8 ); + QPoint s2( r.x() + r.width() / 2, r.y() + r.height() / 2 ); + + QColor color( clear ? backgroundColor() : black ); + QTime time = clear ? prevTime : currTime; + + if ( clear && prevTime.secsTo(currTime) > 1 ) { + p->eraseRect( rect() ); + return; + } + + if ( !clear ) { + // draw ticks + p->setPen( QPen( color, 1 ) ); + for ( int i = 0; i < 12; i++ ) + p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) ); + } + + if ( !clear || prevTime.minute() != currTime.minute() || + prevTime.hour() != currTime.hour() ) { + // draw hour pointer + h1 = rotate( center, h1, 30 * ( time.hour() % 12 ) + time.minute() / 2 ); + h2 = rotate( center, h2, 30 * ( time.hour() % 12 ) + time.minute() / 2 ); + p->setPen( QPen( color, 3 ) ); + p->drawLine( h1, h2 ); + } + + if ( !clear || prevTime.minute() != currTime.minute() ) { + // draw minute pointer + m1 = rotate( center, m1, time.minute() * 6 ); + m2 = rotate( center, m2, time.minute() * 6 ); + p->setPen( QPen( color, 2 ) ); + p->drawLine( m1, m2 ); + } + + // draw second pointer + s1 = rotate( center, s1, time.second() * 6 ); + s2 = rotate( center, s2, time.second() * 6 ); + p->setPen( QPen( color, 1 ) ); + p->drawLine( s1, s2 ); + + if ( !clear ) + prevTime = currTime; +} + +void AnalogClock::display( const QTime& t ) +{ + currTime = t; + clear = true; + repaint( false ); + clear = false; + repaint( false ); +} + +QPoint AnalogClock::rotate( QPoint c, QPoint p, int a ) +{ + double angle = deg2rad * ( - a + 180 ); + double nx = c.x() - ( p.x() - c.x() ) * cos( angle ) - + ( p.y() - c.y() ) * sin( angle ); + double ny = c.y() - ( p.y() - c.y() ) * cos( angle ) + + ( p.x() - c.x() ) * sin( angle ); + return QPoint( nx, ny ); +} diff --git a/noncore/tools/clock/clock.h b/noncore/tools/clock/clock.h new file mode 100644 index 0000000..6dbebf7 --- a/dev/null +++ b/noncore/tools/clock/clock.h @@ -0,0 +1,87 @@ +/********************************************************************** +** 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 CLOCK_H +#define CLOCK_H + +#include +#include + +class QLCDNumber; +class QLabel; +class QTimer; +class QRadioButton; +class QPushButton; + +class AnalogClock : public QFrame +{ + Q_OBJECT + +public: + AnalogClock( QWidget * parent = 0, const char * name = 0 ) + : QFrame( parent, name ), clear(false) {} + + QSizePolicy sizePolicy() const; + + void display( const QTime& time ); + +protected: + void drawContents( QPainter *p ); + +private: + QPoint rotate( QPoint center, QPoint p, int angle ); + + QTime currTime; + QTime prevTime; + bool clear; +}; + +class Clock : public QVBox +{ + Q_OBJECT + +public: + Clock( QWidget * parent = 0, const char * name = 0, WFlags f=0 ); + ~Clock(); + +private slots: + void slotSet(); + void slotReset(); + void modeSelect(int); + void updateClock(); + void changeClock( bool ); + +private: + void clearClock(); + + QTimer *t; + QLCDNumber *lcd; + QLabel *date; + QLabel *ampmLabel; + QPushButton *set, *reset; + QRadioButton *clockRB, *swatchRB; + AnalogClock *aclock; + QTime swatch_start; + int swatch_totalms; + bool swatch_running; + bool ampm; +}; + +#endif + diff --git a/noncore/tools/clock/clock.pro b/noncore/tools/clock/clock.pro new file mode 100644 index 0000000..97f4d2c --- a/dev/null +++ b/noncore/tools/clock/clock.pro @@ -0,0 +1,13 @@ +TEMPLATE = app +CONFIG = qt warn_on release +DESTDIR = $(QPEDIR)/bin +HEADERS = clock.h +SOURCES = clock.cpp \ + main.cpp +INCLUDEPATH += $(QPEDIR)/include +DEPENDPATH += $(QPEDIR)/include +LIBS += -lqpe +INTERFACES = +TARGET = clock + +TRANSLATIONS = ../i18n/de/clock.ts diff --git a/noncore/tools/clock/main.cpp b/noncore/tools/clock/main.cpp new file mode 100644 index 0000000..cbfb73b --- a/dev/null +++ b/noncore/tools/clock/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 "clock.h" + +#include + +int main( int argc, char ** argv ) +{ + QPEApplication a( argc, argv ); + + Clock mw; + mw.setCaption( Clock::tr("Clock") ); + a.showMainWidget( &mw ); + + return a.exec(); +} diff --git a/noncore/tools/clock/qpe-clock.control b/noncore/tools/clock/qpe-clock.control new file mode 100644 index 0000000..62f377f --- a/dev/null +++ b/noncore/tools/clock/qpe-clock.control @@ -0,0 +1,9 @@ +Files: bin/clock apps/Applications/clock.desktop +Priority: optional +Section: qpe/applications +Maintainer: Warwick Allison +Architecture: arm +Version: $QPE_VERSION-3 +Depends: qpe-base ($QPE_VERSION) +Description: Clock and stop-watch + A simple clock and stop-watch for the Qtopia environment. -- cgit v0.9.0.2