⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qt_spec.cpp

📁 Linux/windows 环境下跨平台开发程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:
//QT_Spec.cpp, Copyright (c) 2001, 2002, 2003, 2004, 2005 R.Lackner////    This file is part of RLPlot.////    RLPlot is free software; you can redistribute it and/or modify//    it under the terms of the GNU General Public License as published by//    the Free Software Foundation; either version 2 of the License, or//    (at your option) any later version.////    RLPlot is distributed in the hope that it will be useful,//    but WITHOUT ANY WARRANTY; without even the implied warranty of//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the//    GNU General Public License for more details.////    You should have received a copy of the GNU General Public License//    along with RLPlot; if not, write to the Free Software//    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA//#include <qmessagebox.h>#include <qpixmap.h>#include <qapplication.h>#include <qnamespace.h>#include <qfiledialog.h>#include <qpaintdevicemetrics.h>#include <qimage.h>#include <qcursor.h>#include <qcstring.h>#include <qclipboard.h>#include <qbuffer.h>#include <qbitmap.h>#include <stdio.h>#include <stdlib.h>#include <math.h>#include "QT_Spec.h"

extern tag_Units Units[];extern GraphObj *CurrGO;			//Selected Graphic Objectsextern Graph *CurrGraph;extern char *WWWbrowser;extern char *LoadFile;				//command line argumentextern char TmpTxt[];extern Default defs;extern UndoObj Undo;
QApplication *QAppl;QWidget *MainWidget =0L;POINT CurrWidgetPos = {0,0};//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// Menu item identifiers: synchronize this table with rlplot.rc for//    compatibility with windows//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#define CM_OPEN        500
#define CM_SAVEDATAAS  501
#define CM_EXIT        502
#define CM_NEWGRAPH    503
#define CM_NEWPAGE     504
#define CM_DELGRAPH    505
#define CM_ADDPLOT     506
#define CM_ABOUT       507
#define CM_ADDROWCOL   508
#define CM_COPYGRAPH   509
#define CM_SAVEGRAPHAS 510
#define CM_REDRAW      511
#define CM_ZOOM25      512
#define CM_ZOOM50      513
#define CM_ZOOM100     514
#define CM_ZOOM200     515
#define CM_ZOOM400     516
#define CM_PRINT       517
#define CM_EXPORT      518
#define CM_DELOBJ      519
#define CM_DEFAULTS    520
#define CM_COPY        521
#define CM_PASTE       522
#define CM_UPDATE      523
#define CM_ADDAXIS     524
#define CM_UNDO        525
#define CM_ZOOMIN      526
#define CM_ZOOMOUT     527
#define CM_ZOOMFIT     528
#define CM_FILE1       529
#define CM_FILE2       530
#define CM_FILE3       531
#define CM_FILE4       532
#define CM_FILE5       533
#define CM_FILE6       534
#define CM_FILLRANGE   535
#define CM_CUT         536
#define CM_LEGEND      537
#define CM_LAYERS      538
#define CM_INSROW      539
#define CM_INSCOL      540
#define CM_DELROW      541
#define CM_DELCOL      542

#define CM_T_STANDARD  560
#define CM_T_DRAW      561
#define CM_T_POLYLINE  562
#define CM_T_POLYGON   563
#define CM_T_RECTANGLE 564
#define CM_T_ROUNDREC  565
#define CM_T_ELLIPSE   566
#define CM_T_ARROW     567
#define CM_T_TEXT      568

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// Exute a file open dialog for the different situations//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~static char UserFileName[600];// Get a new file name to store data inchar *SaveDataAsName(char *oldname){	QString fileName = QFileDialog::getSaveFileName(oldname?oldname:defs.currPath,		"RLPlot workbook (*.rlw)\ndata files (*.csv)\ntab separated (*.tsv)\nXML (*.xml)", QAppl->focusWidget());	if(!fileName.isEmpty()){		strcpy(UserFileName, fileName);		defs.FileHistory(UserFileName);		return UserFileName;		}	return 0L;}//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// Get a new file name to store graphchar *SaveGraphAsName(char *oldname){	QString fileName = QFileDialog::getSaveFileName(oldname?oldname:defs.currPath,		"RLPlot files (*.rlp)", QAppl->focusWidget());	if(!fileName.isEmpty()){		strcpy(UserFileName, fileName);		defs.FileHistory(UserFileName);		return UserFileName;		}	return 0L;}//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// Get file name to read graphchar *OpenGraphName(char *oldname){	QString fileName = QFileDialog::getOpenFileName(oldname?oldname:defs.currPath,		"RLPlot files (*.rlp)", QAppl->focusWidget());	if(!fileName.isEmpty()){		strcpy(UserFileName, fileName);		defs.FileHistory(UserFileName);		return UserFileName;		}	return 0L;}//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// Get a file name to load datachar *OpenDataName(char *oldname){	QString fileName = QFileDialog::getOpenFileName(oldname?oldname:defs.currPath,		"RLPlot workbook (*.rlw)\ndata files (*.csv)\ntab separated file (*.tsv)\n"
		"RLPlot files (*.rlp)\nall files (*.*)", QAppl->focusWidget());	if(!fileName.isEmpty()){		strcpy(UserFileName, fileName);		defs.FileHistory(UserFileName);		return UserFileName;		}	return 0L;}//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// Get a file name to export graphvoid OpenExportName(GraphObj *g, char *oldname){	int i;	PrintQT *out=0L;	if (!g) return;	QString fileName = QFileDialog::getSaveFileName(oldname?oldname:defs.currPath,		"Scalable Vector Graphics (*.svg)\nEncapsulated Post Script (*.eps)\n"		"MSWindows MetaFile (*.wmf)\nTag Image File Format(*.tif *.tiff)", 		QAppl->focusWidget());	if(!fileName.isEmpty()){		strcpy(UserFileName, fileName);		i = strlen(UserFileName);		g->Command(CMD_BUSY, 0L, 0L);		if(0==strcasecmp(".svg", UserFileName+i-4)) {			DoExportSvg(g, UserFileName, 0L);			}		else if(0==strcasecmp(".wmf", UserFileName+i-4)) {			DoExportWmf(g, UserFileName, 600.0f, 0L);			}		else if(0==strcasecmp(".eps", UserFileName+i-4)) {			DoExportEps(g, UserFileName, 0L);			}		else if(0==strcasecmp(".tif", UserFileName+i-4)) {			DoExportTif(g, UserFileName, 0L);			}		else if(0==strcasecmp(".tiff", UserFileName+i-5)) {			DoExportTif(g, UserFileName, 0L);			}		else ErrorBox("Unknown file extension or format");		g->Command(CMD_MOUSECURSOR, 0L, 0L);		}}//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// Common alert boxes//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~void InfoBox(char *Msg){
	QMessageBox::information(QAppl->focusWidget(), "Info", Msg);
}
void ErrorBox(char *Msg){	QMessageBox::critical(QAppl->focusWidget(), "ERROR", Msg);}bool YesNoBox(char *Msg){	if(QMessageBox::information(QAppl->focusWidget(), "RLPlot", Msg,		"&Yes", "&No", 0L, 0, -1)) return false;	return true;}
int YesNoCancelBox(char *Msg)
{
	int res;

	res = QMessageBox::information(QAppl->focusWidget(), "RLPlot", Msg,
		"&Yes", "&No", "&Cancel", 0, -1);
	switch(res) {
	case 0:		return 1;
	case 1:		return 0;
	default:	return 2;
		}
	return 0;
}
void Qt_Box(){	QMessageBox::aboutQt(QAppl->focusWidget(), "RLPlot uses Qt");}//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// Display blinking text cursor//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~anyOutput *oTxtCur = 0L;RECT rTxtCur, rCopyMark;bool bTxtCur = false;DWORD coTxtCur = 0x0L;TxtCurBlink *cTxtCur = 0L;POINT ptTxtCurLine[2];void HideTextCursor(){	if(oTxtCur) {		bTxtCur = false;		oTxtCur->UpdateRect(&rTxtCur, false);		}	oTxtCur = 0L;}void HideTextCursorObj(anyOutput *out){	if(oTxtCur && oTxtCur == out) HideTextCursor();}void ShowTextCursor(anyOutput *out, RECT *disp, DWORD color){	coTxtCur = color;	HideTextCursor();	oTxtCur = out;	memcpy(&rTxtCur, disp, sizeof(RECT));	ptTxtCurLine[0].x = rTxtCur.left;	ptTxtCurLine[0].y = rTxtCur.top;	ptTxtCurLine[1].x = rTxtCur.right;	ptTxtCurLine[1].y = rTxtCur.bottom;	rTxtCur.bottom++;		rTxtCur.right++;	bTxtCur = true;	if(cTxtCur) cTxtCur->Show();}void InitTextCursor(bool init){	if(init && !cTxtCur) cTxtCur = new TxtCurBlink();	else if(!init && cTxtCur) {		delete cTxtCur;		cTxtCur = 0L;		}}void HideCopyMark(){	if(cTxtCur && cTxtCur->bmCopyMark && cTxtCur->oCopyMark) {		cTxtCur->oCopyMark->UpdateRect(&rCopyMark, false);		delete cTxtCur->bmCopyMark;		}	cTxtCur->bmCopyMark = 0L;	cTxtCur->oCopyMark = 0L;}void ShowCopyMark(anyOutput *out, RECT *mrk, int nRec){	int i;	if(!out || !mrk || !nRec || !cTxtCur) return;	cTxtCur->oCopyMark = out;	rCopyMark.left = mrk[0].left;	rCopyMark.right = mrk[0].right;	rCopyMark.top = mrk[0].top;		rCopyMark.bottom = mrk[0].bottom;	for(i = 1; i < nRec; i++) {		UpdateMinMaxRect(&rCopyMark, mrk[i].left, mrk[i].top);		UpdateMinMaxRect(&rCopyMark, mrk[i].right, mrk[i].bottom);		}	cTxtCur->bmCopyMark = new BitMapQT(rCopyMark.right - rCopyMark.left+1, 		rCopyMark.bottom - rCopyMark.top+1, out->hres, out->vres);}LineDEF liCopyMark1 = {0.0f, 1.0f, 0x00ffffffL, 0L};LineDEF liCopyMark2 = {0.0f, 6.0f, 0x0L, 0xf0f0f0f0L};TxtCurBlink::TxtCurBlink():QObject(MainWidget, 0){	isVis = false;	oCopyMark = 0L;		bmCopyMark = 0L;	count = cp_mark = 0;	startTimer(60);}voidTxtCurBlink::Show(){	count = -4;	isVis = true;	if(bTxtCur && oTxtCur)oTxtCur->ShowLine(ptTxtCurLine, 2, coTxtCur);}voidTxtCurBlink::showCopyMark(){	if(bmCopyMark && oCopyMark) {		bmCopyMark->CopyBitmap(0, 0, oCopyMark, rCopyMark.left, rCopyMark.top, 			rCopyMark.right - rCopyMark.left, rCopyMark.bottom - rCopyMark.top, false);		bmCopyMark->SetLine(&liCopyMark1);		line[0].x = line[1].x = line[4].x = 0;		line[0].y = line[3].y = line[4].y = 0;		line[1].y = line[2].y = rCopyMark.bottom-rCopyMark.top-1;		line[2].x = line[3].x = rCopyMark.right-rCopyMark.left-1;		bmCopyMark->oPolyline(line, 5);		bmCopyMark->SetLine(&liCopyMark2);		bmCopyMark->RLP.finc = 1.0;		bmCopyMark->RLP.fp = (cp_mark & 0x7);		bmCopyMark->oPolyline(line, 5);		oCopyMark->ShowBitmap(rCopyMark.left, rCopyMark.top, bmCopyMark);		cp_mark++;		if(isVis && oTxtCur && ptTxtCurLine[0].y != ptTxtCurLine[1].y &&			oTxtCur == oCopyMark && OverlapRect(&rCopyMark, &rTxtCur)){			oTxtCur->ShowLine(ptTxtCurLine, 2, coTxtCur);			}		}}voidTxtCurBlink::timerEvent(QTimerEvent *ev){	showCopyMark();	if(!oTxtCur || (ptTxtCurLine[0].x == ptTxtCurLine[1].x &&		ptTxtCurLine[0].y == ptTxtCurLine[1].y)) return;	count++;	if(count<0) oTxtCur->ShowLine(ptTxtCurLine, 2, coTxtCur);	if(count < 8) return;	count = 0;	if(bTxtCur && oTxtCur) {		if(isVis) {			oTxtCur->UpdateRect(&rTxtCur, false);			isVis = false;			}		else {			oTxtCur->ShowLine(ptTxtCurLine, 2, coTxtCur);			isVis = true;			}		}}#define MIME_KSPREAD "application/x-kspread-snippet"#define MIME_RLPLOT "application/x-rlplot-snippet"#define MIME_RLPGRAPH "application/x-rlplot-graph"#define MIME_RLPOBJ "application/x-rlplot-object"//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// Clipboard support// based on KDEs KSpread source: kspread_table.cc// copyright (C) 1998, 1999 Torben Weis//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~KSpreadTextDrag::KSpreadTextDrag(QWidget *dragSource, const char *name )	:QTextDrag(dragSource, name){	go = 0L;}KSpreadTextDrag::~KSpreadTextDrag(){}boolKSpreadTextDrag::provides(const char *mimeType){	if(0 == strcmp(mimeType, "text/plain")) return true;	if(0 == strcmp(mimeType, MIME_RLPLOT)) return true;	if(0 == strcmp(mimeType, selectionMimeType())) return true;	return false;}QByteArrayKSpreadTextDrag::encodedData(const char *mime) const{	static QByteArray b;	char *ptr = 0L;	long cb;	if(!go || go->Id != GO_SPREADDATA) return 0L;	if(0 == strcmp(mime, MIME_RLPLOT)) {		go->Command(CMD_COPY_XML, &ptr, 0L);		}	else if(0 == strcmp(mime, "text/plain")) {		go->Command(CMD_COPY_TSV, &ptr, 0L);		}	else if(0 == strcmp(mime, selectionMimeType())){		go->Command(CMD_COPY_XML, &ptr, 0L);		}
	else return 0L;
	if(!ptr) ptr = (char*)calloc(cb = 4, 1);
	else cb = strlen(ptr)+1;	if(ptr && b.resize(cb)) {		memcpy(b.data(), ptr, cb);		free (ptr);		return (b);		}	return 0L;}boolKSpreadTextDrag::canDecode(QMimeSource *e){	if(e->provides(selectionMimeType())) return true;	return false;}const char *KSpreadTextDrag::format(int i) const{	static const char *fmt;	switch(i) {	case 0:	case 1:		fmt = "text/plain";		return fmt;	case 2:	case 3:	case 4:		return selectionMimeType();	default:		return 0L;		}}const char *KSpreadTextDrag::selectionMimeType(){	return(MIME_RLPLOT);}RLPGraphDrag::RLPGraphDrag(QWidget *dragSource, const char *name)	:QTextDrag(dragSource, name){	go1 = go2 = 0L;}RLPGraphDrag::~RLPGraphDrag(){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -