📄 gwcalcvar.cpp
字号:
/* gwCalc.cpp by Dr. Gerhard Wanderer (gerhard.wanderer@i-dail.de) $Id: gwCalcVar.cpp,v 1.1 2002/12/15 20:32:52 gerhard Exp gerhard $ Pocket Calculator for the Zaurus and for Linux with QT-Library Variables List Popup =====================================================================*/#include <ctype.h>#include <malloc.h>#include <math.h>#include <stdio.h>#include <string.h>#include <qwidget.h>#include <qpushbutton.h>#include <qlabel.h>#include <qpainter.h>#include <qheader.h>#include <qscrollbar.h>#include <qlineedit.h>#include "gwCalc.h"//VarList::~VarList() // delete localy allocated memory { int i; for (i = 0; i < 100; i++) { if (vname[i]) free(vname[i]); }}VarList::VarList(int x, int y) : QDialog (0, 0, TRUE){ QHeader *header; int i; initial = 0;#ifdef ZAURUS setGeometry(0,16,240,MAINHEIGHT-90);#else setGeometry(x, y,240,MAINHEIGHT);#endif setCaption("Variables List"); header = new QHeader(this); header->setGeometry(0,0,240,VARHEIGHT); header->setOrientation(Horizontal); header->addLabel("Name", 112); header->addLabel("Content", 128); for (i = 0; i < VARANZ; i++) { n[i] = new QLineEdit(this); n[i]->setMaxLength(40); n[i]->setGeometry( 2, (i+1)*VARHEIGHT, 109, VARHEIGHT); v[i] = new QLineEdit(this); v[i]->setMaxLength(40); v[i]->setGeometry(112, (i+1)*VARHEIGHT, 109, VARHEIGHT); connect (n[i], SIGNAL(textChanged(const QString &)), this, SLOT (getValues())); connect (v[i], SIGNAL(textChanged(const QString &)), this, SLOT (getValues())); } for (i = 0; i < 100; i++) vname[i] = NULL; count = 0; sb = new QScrollBar(Vertical, this); sb->setGeometry(224,VARHEIGHT+2,14,VARANZ*VARHEIGHT); sb->setMinValue(0); sb->setMaxValue(90); sb->setPageStep(8); connect (sb, SIGNAL(valueChanged(int)), this, SLOT (setPosition(int))); #ifndef ZAURUS s01 = new QPushButton("Cancel", this); s01->setGeometry( 60, MAINHEIGHT-30, 60,26); s01->setFont (QFont("Helvetica", FONT10, QFont::Normal)); s02 = new QPushButton("OK", this); s02->setGeometry(130, MAINHEIGHT-30, 55,26); s02->setFont (QFont("Helvetica", FONT10, QFont::Normal)); connect (s01, SIGNAL(clicked()), this, SLOT (reject())); connect (s02, SIGNAL(clicked()), this, SLOT (accept()));#endif}voidVarList::setPosition(int beg) // // set position of the scroll-list according scrollbar position{ char value[40]; int i; initial = 0; vbeg = beg; for (i = 0; i < VARANZ; i++){ if (vname[beg+i]) { n[i]->setText(vname[beg+i]); sprintf(value, "%14.12g", vvalue[beg+i]); v[i]->setText(value); } else { n[i]->setText(""); v[i]->setText(""); } } initial = 1;} voidVarList::AddVar(char *name, double cont, int ref) // create local copy of variables{ vname[count] = (char*) malloc(strlen(name)+1); strcpy(vname[count], name); vvalue[count] = cont; vref[count] = ref; count++;}char*VarList::GetVar(int pos, double *cont, int *ref) // restore variables from local copy{ *cont = vvalue[pos]; *ref = vref[pos]; return vname[pos];}voidVarList::AddVarFinish(int refcnt) // finish creating of local copies; initial display{ setPosition(0); initial = 1; RefCnt = refcnt; }intVarList::GetRefCnt() // return changes in timestamp{ return RefCnt;}voidVarList::getValues() { // read values from Variable-List, if values changed char *tmp, *text; int i; QString qs; if (initial) { for (i = 0; i < VARANZ; i++){ qs = n[i]->text(); if(qs) { tmp = (char*)qs.latin1(); if (tmp && strlen(tmp)) { text = (char*)malloc(strlen(tmp)+1); strcpy(text, tmp); if (vbeg+i) { // 1.st Entry ANS may not be changed!! if (vname[vbeg+i]) free(vname[vbeg+i]); vname[vbeg+i] = text; qs = v[i]->text(); tmp = (char*)qs.latin1(); if (tmp && strlen(tmp)) { sscanf(tmp, "%lf", &vvalue[vbeg+i]); vref[vbeg+i] = RefCnt++; } else vvalue[vbeg+i] = 0; } } } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -