equal3_mf.cpp
来自「图形软件,用QT编写的,可以用来学习软件的」· C++ 代码 · 共 1,017 行 · 第 1/3 页
CPP
1,017 行
/************************************************************************************************************************************************************** **** equal III the graphic builder **** **** Copyright (C) 2003 Oleksiy Pylypenko **** **** 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 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. **** **** Contact earthman@inbox.ru if any conditions of this licensing are **** not clear to you. **** **** ********************************************************************************* *****************************************************************************/#include <qapplication.h>#include <qlayout.h>#include <qlabel.h>#include <qwidget.h>#include <qpushbutton.h>#include <qtimer.h>#include <qpainter.h>#include <qpixmap.h>#include <qmessagebox.h>#include <qtoolbar.h>#include <qmenubar.h>#include <qstatusbar.h>#include <qtoolbutton.h>#include <qhbox.h>#include <qtranslator.h>#include <qaccel.h>#include <qfiledialog.h>#include <qfile.h>#include <qtextstream.h>#include <qmessagebox.h>#include <qiconset.h>#include <qregexp.h>#include "mylogo.h"#include "equal3_mf.h"#include "xpms.h"equal2_mainframe::equal2_mainframe( const char *, QWidget *parent, const char *name): QMainWindow( parent, name, QMainWindow::WDestructiveClose ){ alicense = 0; justOpened = false; // QMenuBar *mb = menuBar(); // QPopupMenu *fileMenu = new QPopupMenu; // fileMenu->insertItem( "E&xit", this, SLOT(close()), CTRL+Key_X ); // mb->insertItem( "&File", fileMenu ); panelSize = 250; QMenuBar *menubar = menuBar();//new QMenuBar( this ); // menubar->setSeparator( QMenuBar::InWindowsStyle ); QPopupMenu* popup; popup = new QPopupMenu( this ); popup->insertItem( QIconSet( QPixmap(new_icon) ), tr("&New"), this, SLOT(makeNew()) ); popup->insertSeparator(); popup->insertItem( QIconSet( QPixmap(open_icon) ), tr("&Open..."), this, SLOT(open()) ); popup->insertItem( QIconSet( QPixmap(save_icon) ), tr("&Save"), this, SLOT(save()) ); popup->insertItem( tr("Save &As..."), this, SLOT(saveAs()) ); popup->insertSeparator(); popup->insertItem( tr("&Quit"), this, SLOT(quit()) ); menubar->insertItem( tr("&File"), popup ); QToolBar *tb = new QToolBar( this ); //setToolBarsMovable(false); new QToolButton( QPixmap(new_icon), tr("New"),tr("New"), this,SLOT(makeNew()), tb); tb->addSeparator(); new QToolButton( QPixmap(open_icon), tr("Open"),tr("Open"), this,SLOT(open()), tb); new QToolButton( QPixmap(save_icon), tr("Save"),tr("Save"), this,SLOT(save()), tb); tb->addSeparator(); new QToolButton( QPixmap(help_icon), tr("Help"),tr("Help"), this,SLOT(call_for_help()), tb); // new QToolButton(QPixmap(equal3two),tr("new","new",this,SLOT(close()),tb); // new QToolButton(QPixmap(equal3one),tr("new","new",this,SLOT(close()),tb); addToolBar( tb, tr("toolbar"), Top, FALSE ); setIcon(QPixmap(equal3)); setMouseTracking(false); QHBox *hbox = new QHBox(this); tabwidget = new QTabWidget(hbox); graphiclist = new myGraphicList(tabwidget); scalecontrol = new myScaleControl(tabwidget); parameter = new myParameter(tabwidget); // scalecontrol->setBackgroundColor(QColor(255,255,255)); tabwidget->addTab(graphiclist,tr("&Graphics")); tabwidget->addTab(scalecontrol,tr("S&cale")); tabwidget->addTab(parameter,tr("&Parameter")); tabwidget->setFixedWidth(panelSize); hbox->setStretchFactor(tabwidget,1); QHBox *graphicbox = new QHBox(hbox); graphicbox->setMargin(20); graphic = new myGraphic(graphicbox); hbox->setStretchFactor( graphicbox, 10 ); setCentralWidget( hbox ); updateTimer = new QTimer(this); connect(updateTimer,SIGNAL(timeout()),SLOT(updateData())); connect(graphic,SIGNAL(updateSize(QSize)),SLOT(updateSize(QSize))); connect(graphiclist,SIGNAL(update()),SLOT(updateDataWithTimeOut())); connect(scalecontrol,SIGNAL(update()),SLOT(updateDataWithTimeOut())); connect(parameter,SIGNAL(update()),SLOT(updateDataWithTimeOut())); QAccel *accels = new QAccel( this ); accels->connectItem( accels->insertItem(QAccel::Key_Left+QAccel::ALT),this,SLOT(panelMoveLeft())); accels->connectItem( accels->insertItem(QAccel::Key_Right+QAccel::ALT),this,SLOT(panelMoveRight())); accels->connectItem( accels->insertItem(QAccel::Key_Left+QAccel::SHIFT+QAccel::ALT),this,SLOT(resizeLeft())); accels->connectItem( accels->insertItem(QAccel::Key_Right+QAccel::SHIFT+QAccel::ALT),this,SLOT(resizeRight())); accels->connectItem( accels->insertItem(QAccel::Key_Up+QAccel::SHIFT+QAccel::ALT),this,SLOT(resizeUp())); accels->connectItem( accels->insertItem(QAccel::Key_Down+QAccel::SHIFT+QAccel::ALT),this,SLOT(resizeDown())); accels->connectItem( accels->insertItem(QAccel::Key_Up+QAccel::ALT),this,SLOT(paramDown())); accels->connectItem( accels->insertItem(QAccel::Key_Down+QAccel::ALT),this,SLOT(paramUp())); accels->connectItem( accels->insertItem(QAccel::Key_F1),this,SLOT(call_for_help())); accels->connectItem( accels->insertItem(QAccel::Key_R + QAccel::ALT), scalecontrol,SLOT(clear())); accels->connectItem( accels->insertItem(QAccel::Key_W + QAccel::ALT), scalecontrol,SLOT(pushUp())); accels->connectItem( accels->insertItem(QAccel::Key_S + QAccel::ALT), scalecontrol,SLOT(pushDown())); accels->connectItem( accels->insertItem(QAccel::Key_D + QAccel::ALT), scalecontrol,SLOT(pushRight())); accels->connectItem( accels->insertItem(QAccel::Key_A + QAccel::ALT), scalecontrol,SLOT(pushLeft())); accels->connectItem( accels->insertItem(QAccel::Key_Q + QAccel::ALT), scalecontrol,SLOT(pushZoomIn())); accels->connectItem( accels->insertItem(QAccel::Key_E + QAccel::ALT), scalecontrol,SLOT(pushZoomOut())); accels->connectItem( accels->insertItem(QAccel::Key_T + QAccel::ALT), parameter,SLOT(clear())); QStatusBar *sb = statusBar(); parameter->paramLabel = new QLabel("",sb); sb->addWidget(parameter->paramLabel); parameter->setParameter(0); popup = new QPopupMenu( this ); popup->insertItem( tr("E&xport bitmap"), graphic, SLOT(export_bitmap()) ); menubar->insertItem( tr("E&xport"), popup ); popup = new QPopupMenu( this ); popup->insertItem( QIconSet( QPixmap(help_icon) ), tr("&Call for help"), this, SLOT(call_for_help()) ); popup->insertItem( tr("&License"), this, SLOT(license()) ); popup->insertItem( tr("&About"), this, SLOT(about()) ); menubar->insertItem( tr("&Help"), popup ); helpsystem = 0; start(); changed = false; filename = ""; makeNew();}void equal2_mainframe::updateTitle(void){ setCaption( tr("equal III") + QString(" - [") + (filename.isEmpty() ? tr("New file") : filename) + QString(changed ? tr("*") : tr("")) + QString("]") );}void equal2_mainframe::panelMoveLeft(void){ panelSize-=30; if(panelSize < 50)panelSize = 50; tabwidget->setFixedWidth(panelSize);}void equal2_mainframe::panelMoveRight(void){ panelSize+=30; if(panelSize > 600)panelSize = 600; tabwidget->setFixedWidth(panelSize);}void equal2_mainframe::resizeUp(void){ QSize sz = size(); sz.setHeight(sz.height()-30); if(sz.height() < 100)sz.setHeight(100); resize(sz);}void equal2_mainframe::resizeDown(void){ QSize sz = size(); sz.setHeight(sz.height()+30); resize(sz);}void equal2_mainframe::resizeLeft(void){ QSize sz = size(); sz.setWidth(sz.width()-30); if(sz.width() < 100)sz.setWidth(100); resize(sz);}void equal2_mainframe::resizeRight(void){ QSize sz = size(); sz.setWidth(sz.width()+30); resize(sz);}void equal2_mainframe::paramDown(void){ parameter->setParameter(parameter->parameter()+parameter->step());}void equal2_mainframe::paramUp(void){ parameter->setParameter(parameter->parameter()-parameter->step());}void equal2_mainframe::closeEvent( QCloseEvent * e){ //QMessageBox::information(this,"hi","closeEvent"); if(close()) qApp->quit(); else e->ignore();}void equal2_mainframe::updateView(void){ // builder}void equal2_mainframe::mouseReleaseEvent( QMouseEvent * ){ clicked();}// catchs events from build threadbool equal2_mainframe::event(QEvent *e){ return QMainWindow::event(e);}void equal2_mainframe::job(void){ GraphicBuilder abuilder; statusBar()->message(tr("building...")); vector<buildGraphicEvent::buildObject *> & objs = buildData.objectsToBuild; vector<string> names; vector<QRgb> colors; abuilder.width = buildData.w; abuilder.height = buildData.h; abuilder.scale.top = buildData.top; abuilder.scale.left = buildData.left; abuilder.scale.right = buildData.right; abuilder.scale.bottom = buildData.bottom; abuilder.Init(); abuilder.DefineAVariable("t",&buildData.parameter); names.push_back(string((const char *)tr("<nothing>"))); colors.push_back(qRgb(255,255,255)); QString error = ""; for(unsigned int i = 0;i < objs.size();i++) { switch(objs[i]->type){ case(buildGraphicEvent::buildObject::Definition): { buildGraphicEvent::buildDefinition *obj = (buildGraphicEvent::buildDefinition *)objs[i]; try{ abuilder.MakeADefinition(string((const char*)obj->defintion)); } 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 >");} catch(GraphicBuilder::errDefineFunction){error=tr("wrong definition syntax");} } break; case(buildGraphicEvent::buildObject::Graphic): { buildGraphicEvent::buildGraphic *obj = (buildGraphicEvent::buildGraphic *)objs[i]; GraphicBuilder::ImageInfo info = {names.size()}; string aname;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?