equal3_mf.cpp
来自「图形软件,用QT编写的,可以用来学习软件的」· C++ 代码 · 共 1,017 行 · 第 1/3 页
CPP
1,017 行
for(unsigned int j = 0;j < obj->system.size();j++){ if(j != 0)aname += ","; aname += obj->system[j]; } names.push_back(aname); colors.push_back(obj->color.rgb()); try{ abuilder.DrawSystem(obj->system,info); } catch(errBrackets){error=tr("wrong brackets expression");} catch(errParseWrongExpression){error=tr("wrong syntax");} catch(errBadConstant){error=tr("wrong constant");} catch(GraphicBuilder::errSignError){error=tr("missing =,< or >");} break; } } } graphic->scale = abuilder.scale; graphic->UpdateAnImage(abuilder.width,abuilder.height, (unsigned int *)abuilder.image,colors,names); // DrawSystem(); // buildData. // sleep(1); if(error != "") statusBar()->message(tr("errors:") + error); else statusBar()->clear(); }// build threadvoid equal2_mainframe::run(void){ while(1){ startWork.wait(); dataMutex.lock(); job(); dataMutex.unlock(); }}void equal2_mainframe::updateData(void){ if(dataMutex.locked()){ updateTimer->start(1000,TRUE); return; } dataMutex.lock(); scalecontrol->readScales(); buildData.clear(); double deltay = fabs(scalecontrol->bottom - scalecontrol->top) / 1.E6; double deltax = fabs(scalecontrol->right - scalecontrol->left) / 1.E6; bool changed = false; if(fabs(scalecontrol->top - buildData.top) > deltay)changed = true; if(fabs(scalecontrol->bottom - buildData.bottom) > deltay)changed = true; if(fabs(scalecontrol->right - buildData.right) > deltax)changed = true; if(fabs(scalecontrol->left - buildData.left) > deltax)changed = true; if(fabs(parameter->parameter() - buildData.parameter) > 1.E-6 || buildData.parameterset == 0)changed = true; buildData.top = scalecontrol->top; buildData.left = scalecontrol->left; buildData.right = scalecontrol->right; buildData.bottom = scalecontrol->bottom; buildData.parameter = parameter->parameter(); buildData.parameterset = 1; QSize sz = graphic->size(); if(QSize(buildData.w,buildData.h) != sz) changed = true; buildData.w = sz.width(); buildData.h = sz.height(); QMultiLineEdit *e = graphiclist->aneditbox; if(e->edited()){ changed = true; } e->setEdited(false); if(!changed){ dataMutex.unlock(); return; } int lines = 0; for(int i = 0;i < e->numLines();i++){ QString s = e->textLine(i).stripWhiteSpace(); if(s.length() > 0){ if(s[0] == '#')continue; while(s.at(s.length()-1) == ',' && ++i < e->numLines()){ QString s2 = e->textLine(i).stripWhiteSpace(); if(s2.length() == 0)continue; if(s2[0] == '#')continue; s += s2; } if(s.find(":=") != -1){//found definition buildGraphicEvent::buildDefinition *definition = new buildGraphicEvent::buildDefinition; definition->defintion = s; // graphic->system.push_back(); buildData.objectsToBuild.push_back(definition); }else{ buildGraphicEvent::buildGraphic *graphic = new buildGraphicEvent::buildGraphic;// QStringList slist = QStringList::split(",",s);// for(QStringList::Iterator it = slist.begin(); it != slist.end();it++) graphic->system = string((const char *)s); graphic->color = QColor(0,0,0); buildData.objectsToBuild.push_back(graphic); lines++; } } } if(!justOpened) equal2_mainframe::changed = lines > 0; else justOpened = false; updateTitle(); dataMutex.unlock(); startWork.wakeOne(); // job();}// makes thread to update data;void equal2_mainframe::updateDataWithTimeOut(void){ updateData(); // updateTimer->start(1000,TRUE);}void equal2_mainframe::call_for_help(void){ if(helpsystem == 0) helpsystem = new myHelp; helpsystem->show(); helpsystem->setActiveWindow();}void equal2_mainframe::makeNew(void){ if(changed){ switch( QMessageBox::information( this, 0, tr("The document contains unsaved work\n" "Do you want to save it?"), "&Save", "&Don't Save", "&Cancel", 0, // Enter == button 0 2 ) ) { // Escape == button 2 case 0: if(!save()) return; break; case 1:break; case 2:return;break; } } graphiclist->clear(); graphic->clear(); scalecontrol->clear(); parameter->clear(); graphic->update(); justOpened = true; changed = false; filename = ""; updateTitle();}bool equal2_mainframe::close(void){ if(changed){ switch( QMessageBox::information( this, 0, tr("The document contains unsaved work\n" "Do you want to save it before quit?"), tr("&Save"), tr("&Don't Save"), tr("&Cancel"), 0, // Enter == button 0 2 ) ) { // Escape == button 2 case 0: if(!save()) return false; break; case 1:return true;break; case 2:return false;break; } } return true;}bool equal2_mainframe::save(void){ if(filename.isEmpty()){ if(!saveAs()) return false; } QFile f(filename); if(!f.open(IO_WriteOnly | IO_Truncate)) return false; QTextStream stream(&f); stream << graphiclist->aneditbox->text(); f.close(); changed = false; updateTitle(); return true;}bool equal2_mainframe::saveAs(void){ QString fn = QFileDialog::getSaveFileName( QString::null , "Equal III files(*.eq3)", this ); if(!fn.isEmpty()){ if(fn.find(QRegExp("\\.[^\\.\\\\]*$"))==-1) fn += ".eq3"; filename = fn; return save(); } return false;}void equal2_mainframe::open(QString fn){ changed = false; makeNew(); filename = fn; QFile f(filename); f.open(IO_ReadOnly | IO_Translate); graphiclist->aneditbox->setText(QTextStream(&f).read()); f.close(); justOpened = true; updateDataWithTimeOut();}void equal2_mainframe::about(void){ QMessageBox::about(this, tr("equal III about"), tr( "equal III (C) 2003 Oleksiy Pylypenko\n" "\n" "\"equal III\" is a graphic builder.\n" "It can:\n" " - build graphics of eqautions and inequations\n" " - build systems inequations\n" " - change parameter variable in realtime \n" " - create custom functions/oprators\n" " - navigate on mathematical plain\n" "\n" "It supports simple full futured compiler with:\n" " - x87/86 generated code\n" " - simple optimizer\n" "\n" "\n" "\"equal III\" is build on Qt library.\n" "That\'s why you can build it on any\n" "x86 system with Qt support.\n" "\n" "Tested systems are:\n" "Windows 2000/98/XP, FreeBSD, Linux.\n" "\n" ));}void equal2_mainframe::license(void){ if(!alicense){ alicense = new QTextBrowser; alicense->setCaption("equal III is distributed under GPL license"); alicense->setText(tr( "<pre>\n" "\n" " You may use, distribute and copy the equal III under the terms of\n" " GNU General Public License version 2, which is displayed below.\n" "\n" "-------------------------------------------------------------------------\n" "\n" " GNU GENERAL PUBLIC LICENSE\n" " Version 2, June 1991\n" "\n" " Copyright (C) 1989, 1991 Free Software Foundation, Inc.\n" " 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n" " Everyone is permitted to copy and distribute verbatim copies\n" " of this license document, but changing it is not allowed.\n" "\n" " Preamble\n" "\n" " The licenses for most software are designed to take away your\n" "freedom to share and change it. By contrast, the GNU General Public\n" "License is intended to guarantee your freedom to share and change free\n" "software--to make sure the software is free for all its users. This\n" "General Public License applies to most of the Free Software\n" "Foundation\'s software and to any other program whose authors commit to\n" "using it. (Some other Free Software Foundation software is covered by\n" "the GNU Library General Public License instead.) You can apply it to\n" "your programs, too.\n" "\n" " When we speak of free software, we are referring to freedom, not\n" "price. Our General Public Licenses are designed to make sure that you\n" "have the freedom to distribute copies of free software (and charge for\n" "this service if you wish), that you receive source code or can get it\n" "if you want it, that you can change the software or use pieces of it\n" "in new free programs; and that you know you can do these things.\n" "\n" " To protect your rights, we need to make restrictions that forbid\n" "anyone to deny you these rights or to ask you to surrender the rights.\n" "These restrictions translate to certain responsibilities for you if you\n" "distribute copies of the software, or if you modify it.\n" "\n" " For example, if you distribute copies of such a program, whether\n" "gratis or for a fee, you must give the recipients all the rights that\n" "you have. You must make sure that they, too, receive or can get the\n" "source code. And you must show them these terms so they know their\n" "rights.\n" "\n" " We protect your rights with two steps: (1) copyright the software, and\n" "(2) offer you this license which gives you legal permission to copy,\n" "distribute and/or modify the software.\n" "\n" " Also, for each author\'s protection and ours, we want to make certain\n" "that everyone understands that there is no warranty for this free\n" "software. If the software is modified by someone else and passed on, we\n" "want its recipients to know that what they have is not the original, so\n" "that any problems introduced by others will not reflect on the original\n" "authors\' reputations.\n" "\n" " Finally, any free program is threatened constantly by software\n" "patents. We wish to avoid the danger that redistributors of a free\n" "program will individually obtain patent licenses, in effect making the\n" "program proprietary. To prevent this, we have made it clear that any\n" "patent must be licensed for everyone\'s free use or not licensed at all.\n" "\n" " The precise terms and conditions for copying, distribution and\n" "modification follow.\n" "\n" " GNU GENERAL PUBLIC LICENSE\n" " TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n" "\n" " 0. This License applies to any program or other work which contains\n" "a notice placed by the copyright holder saying it may be distributed\n" "under the terms of this General Public License. The \"Program\", below,\n" "refers to any such program or work, and a \"work based on the Program\"\n" "means either the Program or any derivative work under copyright law:\n" "that is to say, a work containing the Program or a portion of it,\n" "either verbatim or with modifications and/or translated into another\n" "language. (Hereinafter, translation is included without limitation in\n" "the term \"modification\".) Each licensee is addressed as \"you\".\n"
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?