From: <ai...@us...> - 2009-07-31 18:17:49
|
Revision: 10196 http://plplot.svn.sourceforge.net/plplot/?rev=10196&view=rev Author: airwin Date: 2009-07-31 18:17:38 +0000 (Fri, 31 Jul 2009) Log Message: ----------- AWI for Alban Rochel. Whitespace cleanup. Modified Paths: -------------- trunk/bindings/qt_gui/plqt.cpp trunk/drivers/qt.cpp trunk/examples/c++/qt_PlotWindow.cpp trunk/include/qt.h Modified: trunk/bindings/qt_gui/plqt.cpp =================================================================== --- trunk/bindings/qt_gui/plqt.cpp 2009-07-31 18:07:55 UTC (rev 10195) +++ trunk/bindings/qt_gui/plqt.cpp 2009-07-31 18:17:38 UTC (rev 10196) @@ -1,33 +1,33 @@ /* - This software is provided under the LGPL in March 2009 by the - Cluster Science Centre - QSAS team, - Imperial College, London +This software is provided under the LGPL in March 2009 by the +Cluster Science Centre +QSAS team, +Imperial College, London - Copyright (C) 2009 Imperial College, London - Copyright (C) 2009 Alan W. Irwin +Copyright (C) 2009 Imperial College, London +Copyright (C) 2009 Alan W. Irwin - This is free software; you can redistribute it and/or modify - it under the terms of the GNU General Lesser Public License as published - by the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. +This is free software; you can redistribute it and/or modify +it under the terms of the GNU General Lesser Public License as published +by the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. - This software 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 Lesser General Public License for more details. +This software 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 Lesser General Public License for more details. - To received a copy of the GNU Library General Public License - write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - History: +To received a copy of the GNU Library General Public License +write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - March 2009: v1.00 - Initial release. - +History: + + +March 2009: v1.00 +Initial release. + */ @@ -41,33 +41,33 @@ // Only handles multiple Qt devices MasterHandler::MasterHandler():QObject() { - masterDevice=NULL; + masterDevice=NULL; } bool MasterHandler::isMasterDevice(QtPLDriver* d) { - return d==masterDevice; + return d==masterDevice; } void MasterHandler::setMasterDevice(QtPLDriver* d) { - masterDevice=d; + masterDevice=d; } void MasterHandler::DeviceChangedPage(QtPLDriver* d) { - if(d==masterDevice) + if(d==masterDevice) { - emit MasterChangedPage(); + emit MasterChangedPage(); } } void MasterHandler::DeviceClosed(QtPLDriver* d) { - if(d==masterDevice) + if(d==masterDevice) { - emit MasterClosed(); - masterDevice=NULL; + emit MasterClosed(); + masterDevice=NULL; } } @@ -76,8 +76,8 @@ QtPLDriver::QtPLDriver(PLINT i_iWidth, PLINT i_iHeight) { - m_dWidth=i_iWidth; - m_dHeight=i_iHeight; + m_dWidth=i_iWidth; + m_dHeight=i_iHeight; } QtPLDriver::~QtPLDriver() @@ -86,298 +86,298 @@ void QtPLDriver::drawLine(short x1, short y1, short x2, short y2) { - if(!m_painterP->isActive()) return; - QLineF line( (PLFLT)x1*downscale, - m_dHeight-(PLFLT)y1*downscale, - (PLFLT)x2*downscale, - m_dHeight-(PLFLT)y2*downscale - ); + if(!m_painterP->isActive()) return; + QLineF line( (PLFLT)x1*downscale, + m_dHeight-(PLFLT)y1*downscale, + (PLFLT)x2*downscale, + m_dHeight-(PLFLT)y2*downscale + ); - m_painterP->drawLine(line); + m_painterP->drawLine(line); } void QtPLDriver::drawPolyline(short * x, short * y, PLINT npts) { - if(!m_painterP->isActive()) return; - QPointF * polyline=new QPointF[npts]; - for(int i=0; i<npts; ++i) - { - polyline[i].setX((PLFLT)x[i]*downscale); - polyline[i].setY(m_dHeight-(PLFLT)y[i]*downscale); - } - m_painterP->drawPolyline(polyline, npts); - delete[] polyline; + if(!m_painterP->isActive()) return; + QPointF * polyline=new QPointF[npts]; + for(int i=0; i<npts; ++i) + { + polyline[i].setX((PLFLT)x[i]*downscale); + polyline[i].setY(m_dHeight-(PLFLT)y[i]*downscale); + } + m_painterP->drawPolyline(polyline, npts); + delete[] polyline; } void QtPLDriver::drawPolygon(short * x, short * y, PLINT npts) { - if(!m_painterP->isActive()) return; - QPointF * polygon=new QPointF[npts]; - for(int i=0; i<npts; ++i) - { - polygon[i].setX((PLFLT)x[i]*downscale); - polygon[i].setY(m_dHeight-(PLFLT)y[i]*downscale); - } - m_painterP->drawPolygon(polygon, npts); - delete[] polygon; + if(!m_painterP->isActive()) return; + QPointF * polygon=new QPointF[npts]; + for(int i=0; i<npts; ++i) + { + polygon[i].setX((PLFLT)x[i]*downscale); + polygon[i].setY(m_dHeight-(PLFLT)y[i]*downscale); + } + m_painterP->drawPolygon(polygon, npts); + delete[] polygon; } QFont QtPLDriver::getFont(PLUNICODE unicode) { - // Get new font parameters - unsigned char fontFamily, fontStyle, fontWeight; + // Get new font parameters + unsigned char fontFamily, fontStyle, fontWeight; - plP_fci2hex(unicode, &fontFamily, PL_FCI_FAMILY); - plP_fci2hex(unicode, &fontStyle, PL_FCI_STYLE); - plP_fci2hex(unicode, &fontWeight, PL_FCI_WEIGHT); - - QFont f; + plP_fci2hex(unicode, &fontFamily, PL_FCI_FAMILY); + plP_fci2hex(unicode, &fontStyle, PL_FCI_STYLE); + plP_fci2hex(unicode, &fontWeight, PL_FCI_WEIGHT); - f.setPointSizeF(currentFontSize*currentFontScale<4 ? 4 : currentFontSize*currentFontScale); + QFont f; + + f.setPointSizeF(currentFontSize*currentFontScale<4 ? 4 : currentFontSize*currentFontScale); switch(fontFamily) { - case 1: - f.setStyleHint(QFont::Serif); - break; - case 2: - f.setStyleHint(QFont::TypeWriter); - break; - case 0: case 3: case 4:default: - f.setStyleHint(QFont::SansSerif); - break; - } - f.setFamily(""); // no family name, forcing Qt to find an appropriate font by itself + case 1: + f.setStyleHint(QFont::Serif); + break; + case 2: + f.setStyleHint(QFont::TypeWriter); + break; + case 0: case 3: case 4:default: + f.setStyleHint(QFont::SansSerif); + break; + } + f.setFamily(""); // no family name, forcing Qt to find an appropriate font by itself - if(fontStyle) f.setItalic(true); - if(fontWeight) f.setWeight(QFont::Bold); - else f.setWeight(QFont::Normal); - - f.setUnderline(underlined); - f.setOverline(overlined); + if(fontStyle) f.setItalic(true); + if(fontWeight) f.setWeight(QFont::Bold); + else f.setWeight(QFont::Normal); - return f; + f.setUnderline(underlined); + f.setOverline(overlined); + + return f; } void QtPLDriver::drawTextInPicture(QPainter* p, const QString& text) { - QRectF rect(0., 0., 0., 0.); - QRectF bounding; - QPicture tempPic; - QPainter tempPainter(&tempPic); - tempPainter.setFont(p->font()); - - if(vectorize) - { - bounding=tempPainter.boundingRect(rect, Qt::AlignHCenter|Qt::AlignVCenter|Qt::TextDontClip, text); - + QRectF rect(0., 0., 0., 0.); + QRectF bounding; + QPicture tempPic; + QPainter tempPainter(&tempPic); + tempPainter.setFont(p->font()); + + if(vectorize) + { + bounding=tempPainter.boundingRect(rect, Qt::AlignHCenter|Qt::AlignVCenter|Qt::TextDontClip, text); + tempPainter.save(); // QPen savePen=tempPainter.pen(); QPen pen=QPen(Qt::NoPen); - tempPainter.setPen(pen); - - double offset=QFontMetrics(tempPainter.font(), &tempPic).boundingRect(text).top(); // Distance between the baseline and the top of the bounding box - - QPainterPath path; - path.addText(QPointF(bounding.left(), bounding.top()-offset), tempPainter.font(), text); - tempPainter.drawPath(path); + tempPainter.setPen(pen); + + double offset=QFontMetrics(tempPainter.font(), &tempPic).boundingRect(text).top(); // Distance between the baseline and the top of the bounding box + + QPainterPath path; + path.addText(QPointF(bounding.left(), bounding.top()-offset), tempPainter.font(), text); + tempPainter.drawPath(path); tempPainter.restore(); - } - else - { - tempPainter.drawText(rect, Qt::AlignHCenter|Qt::AlignVCenter|Qt::TextDontClip, text, &bounding); - } - - tempPainter.end(); - - p->drawPicture((int)(xOffset+bounding.width()/2.), -yOffset, tempPic); - - xOffset+=bounding.width(); + } + else + { + tempPainter.drawText(rect, Qt::AlignHCenter|Qt::AlignVCenter|Qt::TextDontClip, text, &bounding); + } + + tempPainter.end(); + + p->drawPicture((int)(xOffset+bounding.width()/2.), -yOffset, tempPic); + + xOffset+=bounding.width(); } QPicture QtPLDriver::getTextPicture(PLUNICODE fci, PLUNICODE* text, int len, PLFLT chrht) { - char plplotEsc; - plgesc( &plplotEsc ); - - double old_fontScale; - - QPicture res; - QPainter p(&res); - - QString currentString; + char plplotEsc; + plgesc( &plplotEsc ); - yOffset=0.; - xOffset=0.; + double old_fontScale; - // Scaling factor of 1.6 determined empirically to make all qt results - // have the same character size as cairo results (taking into account - // the slightly different actual glyph sizes for the different - // default fonts found by cairo and qt). - currentFontSize=chrht*POINTS_PER_INCH/25.4*1.45; - currentFontScale=1.; - underlined=false; - overlined=false; - - p.setFont(getFont(fci)); + QPicture res; + QPainter p(&res); - int i=0; - while(i < len) - { - if(text[i]<PL_FCI_MARK) // Not a font change - { - if(text[i]!=(PLUNICODE)plplotEsc) - { - currentString.append(QString(QChar(text[i]))); - ++i; - continue; - } - ++i; // Now analyse the escaped character - switch(text[i]) - { - case 'd': - drawTextInPicture(&p, currentString); - currentString.clear(); - old_fontScale=currentFontScale; + QString currentString; + + yOffset=0.; + xOffset=0.; + + // Scaling factor of 1.6 determined empirically to make all qt results + // have the same character size as cairo results (taking into account + // the slightly different actual glyph sizes for the different + // default fonts found by cairo and qt). + currentFontSize=chrht*POINTS_PER_INCH/25.4*1.45; + currentFontScale=1.; + underlined=false; + overlined=false; + + p.setFont(getFont(fci)); + + int i=0; + while(i < len) + { + if(text[i]<PL_FCI_MARK) // Not a font change + { + if(text[i]!=(PLUNICODE)plplotEsc) + { + currentString.append(QString(QChar(text[i]))); + ++i; + continue; + } + ++i; // Now analyse the escaped character + switch(text[i]) + { + case 'd': + drawTextInPicture(&p, currentString); + currentString.clear(); + old_fontScale=currentFontScale; if( yOffset>-0.000000000001 ) // I've already encountered precision issues here, so changed 0 into -epsilon { - currentFontScale *= 1.25; /* Subscript scaling parameter */ + currentFontScale *= 1.25; /* Subscript scaling parameter */ } - else + else { - currentFontScale *= 0.8; /* Subscript scaling parameter */ + currentFontScale *= 0.8; /* Subscript scaling parameter */ } - yOffset -= currentFontSize * old_fontScale / 2.; - - p.setFont(getFont(fci)); - break; + yOffset -= currentFontSize * old_fontScale / 2.; - case 'u': - drawTextInPicture(&p, currentString); - - currentString.clear(); + p.setFont(getFont(fci)); + break; + + case 'u': + drawTextInPicture(&p, currentString); + + currentString.clear(); if( yOffset<-0.000000000001 ) { - currentFontScale *= 1.25; /* Subscript scaling parameter */ + currentFontScale *= 1.25; /* Subscript scaling parameter */ } - else + else { - currentFontScale *= 0.8; /* Subscript scaling parameter */ + currentFontScale *= 0.8; /* Subscript scaling parameter */ } - yOffset += currentFontSize * currentFontScale / 2.; - p.setFont(getFont(fci)); - break; + yOffset += currentFontSize * currentFontScale / 2.; + p.setFont(getFont(fci)); + break; - case '-': - drawTextInPicture(&p, currentString); - - currentString.clear(); - underlined=!underlined; - p.setFont(getFont(fci)); - break; + case '-': + drawTextInPicture(&p, currentString); - case '+': - drawTextInPicture(&p, currentString); + currentString.clear(); + underlined=!underlined; + p.setFont(getFont(fci)); + break; - currentString.clear(); - overlined=!overlined; - p.setFont(getFont(fci)); - break; + case '+': + drawTextInPicture(&p, currentString); + currentString.clear(); + overlined=!overlined; + p.setFont(getFont(fci)); + break; + - case '#': - currentString.append(QString((QChar*)&(text[i]), 1)); - break; + case '#': + currentString.append(QString((QChar*)&(text[i]), 1)); + break; - default : - std::cout << "unknown escape char " << ((QChar)text[i]).toLatin1() << std::endl; - break; - } - } - else // Font change - { - drawTextInPicture(&p, currentString); + default : + std::cout << "unknown escape char " << ((QChar)text[i]).toLatin1() << std::endl; + break; + } + } + else // Font change + { + drawTextInPicture(&p, currentString); - currentString.clear(); - fci=text[i]; - p.setFont(getFont(fci)); - } - ++i; - } - drawTextInPicture(&p, currentString); - - p.end(); - return res; + currentString.clear(); + fci=text[i]; + p.setFont(getFont(fci)); + } + ++i; + } + drawTextInPicture(&p, currentString); + + p.end(); + return res; } void QtPLDriver::drawText(PLStream* pls, EscText* txt) { - if(!m_painterP->isActive()) return; + if(!m_painterP->isActive()) return; - /* Check that we got unicode, warning message and return if not */ + /* Check that we got unicode, warning message and return if not */ if( txt->unicode_array_len == 0 ) { - printf( "Non unicode string passed to a Qt driver, ignoring\n" ); - return; - } - - /* Check that unicode string isn't longer then the max we allow */ + printf( "Non unicode string passed to a Qt driver, ignoring\n" ); + return; + } + + /* Check that unicode string isn't longer then the max we allow */ if( txt->unicode_array_len >= 500 ) { - printf( "Sorry, the Qt drivers only handle strings of length < %d\n", 500 ); - return; - } + printf( "Sorry, the Qt drivers only handle strings of length < %d\n", 500 ); + return; + } - PLFLT rotation, shear, stride; - plRotationShear( txt->xform, &rotation, &shear, &stride); - - double picDpi; - PLUNICODE fci; - plgfci( &fci ); - QPicture picText=getTextPicture(fci, txt->unicode_array, txt->unicode_array_len, pls->chrht); - picDpi=picText.logicalDpiY(); + PLFLT rotation, shear, stride; + plRotationShear( txt->xform, &rotation, &shear, &stride); + + double picDpi; + PLUNICODE fci; + plgfci( &fci ); + QPicture picText=getTextPicture(fci, txt->unicode_array, txt->unicode_array_len, pls->chrht); + picDpi=picText.logicalDpiY(); - m_painterP->setClipping(true); - m_painterP->setClipRect(QRect((int)(pls->clpxmi*downscale), (int)(m_dHeight-pls->clpyma*downscale), (int)((pls->clpxma-pls->clpxmi)*downscale), (int)((pls->clpyma-pls->clpymi)*downscale)), Qt::ReplaceClip); + m_painterP->setClipping(true); + m_painterP->setClipRect(QRect((int)(pls->clpxmi*downscale), (int)(m_dHeight-pls->clpyma*downscale), (int)((pls->clpxma-pls->clpxmi)*downscale), (int)((pls->clpyma-pls->clpymi)*downscale)), Qt::ReplaceClip); - rotation -= pls->diorot * M_PI / 2.0; - m_painterP->translate(txt->x*downscale, m_dHeight-txt->y*downscale); - QMatrix rotShearMatrix(cos(rotation)*stride, -sin(rotation)*stride, cos(rotation)*sin(shear)+sin(rotation)*cos(shear), -sin(rotation)*sin(shear)+cos(rotation)*cos(shear), 0., 0.); + rotation -= pls->diorot * M_PI / 2.0; + m_painterP->translate(txt->x*downscale, m_dHeight-txt->y*downscale); + QMatrix rotShearMatrix(cos(rotation)*stride, -sin(rotation)*stride, cos(rotation)*sin(shear)+sin(rotation)*cos(shear), -sin(rotation)*sin(shear)+cos(rotation)*cos(shear), 0., 0.); - m_painterP->setWorldMatrix(rotShearMatrix, true); + m_painterP->setWorldMatrix(rotShearMatrix, true); - m_painterP->translate(-txt->just*xOffset*m_painterP->device()->logicalDpiY()/picDpi, 0.); + m_painterP->translate(-txt->just*xOffset*m_painterP->device()->logicalDpiY()/picDpi, 0.); - m_painterP->drawPicture(0, 0, picText); + m_painterP->drawPicture(0, 0, picText); m_painterP->resetTransform();; - m_painterP->setClipping(false); + m_painterP->setClipping(false); } void QtPLDriver::setColor(int r, int g, int b, double alpha) { - if(!m_painterP->isActive()) return; + if(!m_painterP->isActive()) return; - QPen p=m_painterP->pen(); - p.setColor(QColor(r, g, b, (int)(alpha*255))); - m_painterP->setPen(p); - - QBrush B=m_painterP->brush(); - B.setColor(QColor(r, g, b, (int)(alpha*255))); - B.setStyle(Qt::SolidPattern); - m_painterP->setBrush(B); + QPen p=m_painterP->pen(); + p.setColor(QColor(r, g, b, (int)(alpha*255))); + m_painterP->setPen(p); + + QBrush B=m_painterP->brush(); + B.setColor(QColor(r, g, b, (int)(alpha*255))); + B.setStyle(Qt::SolidPattern); + m_painterP->setBrush(B); } void QtPLDriver::setWidth(PLINT w) { - if(!m_painterP->isActive()) return; + if(!m_painterP->isActive()) return; - QPen p=m_painterP->pen(); - p.setWidth(w); - m_painterP->setPen(p); + QPen p=m_painterP->pen(); + p.setWidth(w); + m_painterP->setPen(p); } // void QtPLDriver::setDashed(PLINT nms, PLINT* mark, PLINT* space) @@ -397,98 +397,98 @@ void QtPLDriver::setSolid() { - if(!m_painterP->isActive()) return; + if(!m_painterP->isActive()) return; - QPen p=m_painterP->pen(); - p.setStyle(Qt::SolidLine); - m_painterP->setPen(p); + QPen p=m_painterP->pen(); + p.setStyle(Qt::SolidLine); + m_painterP->setPen(p); } ////////////////// Raster driver-specific definitions: class and interface functions ///////// #if defined (PLD_bmpqt) || defined(PLD_jpgqt) || defined (PLD_pngqt) || defined(PLD_ppmqt) || defined(PLD_tiffqt) QtRasterDevice::QtRasterDevice(int i_iWidth, int i_iHeight): - QtPLDriver(i_iWidth, i_iHeight), - QImage(i_iWidth, i_iHeight, QImage::Format_RGB32) + QtPLDriver(i_iWidth, i_iHeight), + QImage(i_iWidth, i_iHeight, QImage::Format_RGB32) { - // Painter initialised in the constructor contrary - // to buffered drivers, which paint only in doPlot(). - m_painterP=new QPainter(this); - QBrush b=m_painterP->brush(); - b.setStyle(Qt::SolidPattern); - m_painterP->setBrush(b); - m_painterP->setRenderHint(QPainter::Antialiasing, true); + // Painter initialised in the constructor contrary + // to buffered drivers, which paint only in doPlot(). + m_painterP=new QPainter(this); + QBrush b=m_painterP->brush(); + b.setStyle(Qt::SolidPattern); + m_painterP->setBrush(b); + m_painterP->setRenderHint(QPainter::Antialiasing, true); } QtRasterDevice::~QtRasterDevice() { - delete m_painterP; + delete m_painterP; } void QtRasterDevice::definePlotName(const char* fileName, const char* format) { - // Avoid buffer overflows - strncpy(this->format, format, 4); - this->format[4]='\0'; - - this->fileName=QString(fileName); + // Avoid buffer overflows + strncpy(this->format, format, 4); + this->format[4]='\0'; + + this->fileName=QString(fileName); } void QtRasterDevice::savePlot() { - m_painterP->end(); - save(fileName, format, 85); + m_painterP->end(); + save(fileName, format, 85); - m_painterP->begin(this); - m_painterP->setRenderHint(QPainter::Antialiasing, true); - QBrush b=m_painterP->brush(); - b.setStyle(Qt::SolidPattern); - m_painterP->setBrush(b); + m_painterP->begin(this); + m_painterP->setRenderHint(QPainter::Antialiasing, true); + QBrush b=m_painterP->brush(); + b.setStyle(Qt::SolidPattern); + m_painterP->setBrush(b); } void QtRasterDevice::setBackgroundColor(int r, int g, int b, double alpha) { - if(!m_painterP->isActive()) return; + if(!m_painterP->isActive()) return; - QBrush brush(QColor(r, g, b, (int)(alpha*255))); - m_painterP->fillRect(0, 0, width(), height(), brush); + QBrush brush(QColor(r, g, b, (int)(alpha*255))); + m_painterP->fillRect(0, 0, width(), height(), brush); } #endif #if defined(PLD_svgqt) && QT_VERSION >= 0x040300 QtSVGDevice::QtSVGDevice(int i_iWidth, int i_iHeight): - QtPLDriver(i_iWidth, i_iHeight) + QtPLDriver(i_iWidth, i_iHeight) { - m_painterP=NULL; + m_painterP=NULL; } QtSVGDevice::~QtSVGDevice() { - delete m_painterP; + delete m_painterP; } void QtSVGDevice::definePlotName(const char* fileName) { - setFileName(QString(fileName)); - setResolution(POINTS_PER_INCH); - setSize(QSize((int)m_dWidth, (int)m_dHeight)); + setFileName(QString(fileName)); + setResolution(POINTS_PER_INCH); + setSize(QSize((int)m_dWidth, (int)m_dHeight)); #if QT_VERSION >= 0x040500 - setViewBox(QRect(0, 0, (int)m_dWidth, (int)m_dHeight)); + setViewBox(QRect(0, 0, (int)m_dWidth, (int)m_dHeight)); #endif - m_painterP=new QPainter(this); + m_painterP=new QPainter(this); } void QtSVGDevice::savePlot() { - m_painterP->end(); + m_painterP->end(); } void QtSVGDevice::setBackgroundColor(int r, int g, int b, double alpha) { - if(!m_painterP->isActive()) return; + if(!m_painterP->isActive()) return; - QBrush brush(QColor(r, g, b, (int)(alpha*255))); - m_painterP->fillRect(0, 0, width(), height(), brush); + QBrush brush(QColor(r, g, b, (int)(alpha*255))); + m_painterP->fillRect(0, 0, width(), height(), brush); } #endif @@ -496,98 +496,98 @@ QtEPSDevice::QtEPSDevice(int i_iWidth, int i_iHeight) { #if QT_VERSION < 0x040400 - setPageSize(QPrinter::A4); + setPageSize(QPrinter::A4); #else - setFullPage(true); - setPaperSize(QSizeF(i_iHeight, i_iWidth), QPrinter::Point); + setFullPage(true); + setPaperSize(QSizeF(i_iHeight, i_iWidth), QPrinter::Point); #endif - setResolution(POINTS_PER_INCH); - setColorMode(QPrinter::Color); - setOrientation(QPrinter::Landscape); - setPrintProgram(QString("lpr")); - - if(i_iWidth<=0 || i_iHeight<=0) - { - m_dWidth=pageRect().width(); - m_dHeight=pageRect().height(); - } - else - { - m_dWidth=i_iWidth; - m_dHeight=i_iHeight; - } - m_painterP=NULL; + setResolution(POINTS_PER_INCH); + setColorMode(QPrinter::Color); + setOrientation(QPrinter::Landscape); + setPrintProgram(QString("lpr")); + + if(i_iWidth<=0 || i_iHeight<=0) + { + m_dWidth=pageRect().width(); + m_dHeight=pageRect().height(); + } + else + { + m_dWidth=i_iWidth; + m_dHeight=i_iHeight; + } + m_painterP=NULL; } QtEPSDevice::~QtEPSDevice() { - delete m_painterP; + delete m_painterP; } void QtEPSDevice::definePlotName(const char* fileName, int ifeps) { - setOutputFileName(QString(fileName)); - if(ifeps) - { - setOutputFormat(QPrinter::PostScriptFormat); - } - else - { - setOutputFormat(QPrinter::PdfFormat); - } - - m_painterP=new QPainter(this); + setOutputFileName(QString(fileName)); + if(ifeps) + { + setOutputFormat(QPrinter::PostScriptFormat); + } + else + { + setOutputFormat(QPrinter::PdfFormat); + } + + m_painterP=new QPainter(this); } void QtEPSDevice::savePlot() { - m_painterP->end(); + m_painterP->end(); } void QtEPSDevice::setBackgroundColor(int r, int g, int b, double alpha) { - if(!m_painterP->isActive()) return; + if(!m_painterP->isActive()) return; - QBrush brush(QColor(r, g, b, (int)(alpha*255))); - m_painterP->fillRect(0, 0, width(), height(), brush); + QBrush brush(QColor(r, g, b, (int)(alpha*255))); + m_painterP->fillRect(0, 0, width(), height(), brush); } #endif #if defined (PLD_qtwidget) || defined(PLD_extqt) QtPLWidget::QtPLWidget(int i_iWidth, int i_iHeight, QWidget* parent): - QWidget(parent), QtPLDriver(i_iWidth, i_iHeight) + QWidget(parent), QtPLDriver(i_iWidth, i_iHeight) { - m_painterP=new QPainter; - - m_dAspectRatio=m_dWidth/m_dHeight; - - m_pixPixmap=NULL; - m_iOldSize=0; - pageNumber=0; - resize(i_iWidth, i_iHeight); + m_painterP=new QPainter; + + m_dAspectRatio=m_dWidth/m_dHeight; + + m_pixPixmap=NULL; + m_iOldSize=0; + pageNumber=0; + resize(i_iWidth, i_iHeight); lastColour.r=-1; } QtPLWidget::~QtPLWidget() { - clearBuffer(); - delete m_pixPixmap; + clearBuffer(); + delete m_pixPixmap; } void QtPLWidget::clearWidget() { - clearBuffer(); - m_bAwaitingRedraw=true; - update(); + clearBuffer(); + m_bAwaitingRedraw=true; + update(); } void QtPLWidget::clearBuffer() { lastColour.r=-1; - for(QLinkedList<BufferElement>::iterator i=m_listBuffer.begin(); i!=m_listBuffer.end(); ++i) - { - switch(i->Element) - { + for(QLinkedList<BufferElement>::iterator i=m_listBuffer.begin(); i!=m_listBuffer.end(); ++i) + { + switch(i->Element) + { case LINE: delete i->Data.Line; break; @@ -595,54 +595,54 @@ delete i->Data.Rect; break; - case POLYLINE: - case POLYGON: + case POLYLINE: + case POLYGON: delete i->Data.Polyline; - break; - + break; + case TEXT: delete[] i->Data.TextStruct->text; delete i->Data.TextStruct; - break; - - case SET_COLOUR: - case SET_BG_COLOUR: - delete i->Data.ColourStruct; - break; - - default: - break; - } - } - - m_listBuffer.clear(); + break; + + case SET_COLOUR: + case SET_BG_COLOUR: + delete i->Data.ColourStruct; + break; + + default: + break; + } + } + + m_listBuffer.clear(); } void QtPLWidget::drawLine(short x1, short y1, short x2, short y2) { - BufferElement el; - el.Element=LINE; + BufferElement el; + el.Element=LINE; el.Data.Line=new QLineF(QPointF((PLFLT)x1*downscale, (PLFLT)(m_dHeight-y1*downscale)), QPointF((PLFLT)x2*downscale, (PLFLT)(m_dHeight-y2*downscale))); - m_listBuffer.append(el); + m_listBuffer.append(el); } void QtPLWidget::drawPolyline(short * x, short * y, PLINT npts) { - BufferElement el; - el.Element=POLYLINE; + BufferElement el; + el.Element=POLYLINE; el.Data.Polyline=new QPolygonF; - for(int i=0; i<npts; ++i) - { + for(int i=0; i<npts; ++i) + { (*el.Data.Polyline) << QPointF((PLFLT)(x[i])*downscale, (PLFLT)(m_dHeight-(y[i])*downscale)); - } - - m_listBuffer.append(el); + } + + m_listBuffer.append(el); } void QtPLWidget::drawPolygon(short * x, short * y, PLINT npts) { - BufferElement el; + BufferElement el; bool isRect=false; if(npts==4) // Check if it's a rectangle. If so, it can be made faster to display @@ -704,185 +704,185 @@ } else { - el.Element=POLYGON; + el.Element=POLYGON; el.Data.Polyline=new QPolygonF; - for(int i=0; i<npts; ++i) - { + for(int i=0; i<npts; ++i) + { (*el.Data.Polyline) << QPointF((PLFLT)(x[i])*downscale, (PLFLT)(m_dHeight-(y[i])*downscale)); - } + } } - - m_listBuffer.append(el); + + m_listBuffer.append(el); } void QtPLWidget::setColor(int r, int g, int b, double alpha) { if(lastColour.r!=r || lastColour.g!=g || lastColour.b!=b || lastColour.alpha!=alpha) { - BufferElement el; - el.Element=SET_COLOUR; - el.Data.ColourStruct=new struct ColourStruct_; - el.Data.ColourStruct->R=r; - el.Data.ColourStruct->G=g; - el.Data.ColourStruct->B=b; - el.Data.ColourStruct->A=alpha*255.; - - m_listBuffer.append(el); + BufferElement el; + el.Element=SET_COLOUR; + el.Data.ColourStruct = new struct ColourStruct_; + el.Data.ColourStruct->R=r; + el.Data.ColourStruct->G=g; + el.Data.ColourStruct->B=b; + el.Data.ColourStruct->A=alpha*255.; + + m_listBuffer.append(el); lastColour.r=r; lastColour.g=g; lastColour.b=b; lastColour.alpha=alpha; + } } -} void QtPLWidget::setBackgroundColor(int r, int g, int b, double alpha) { - BufferElement el; - el.Element=SET_BG_COLOUR; - el.Data.ColourStruct=new struct ColourStruct_; - el.Data.ColourStruct->R=r; - el.Data.ColourStruct->G=g; - el.Data.ColourStruct->B=b; - el.Data.ColourStruct->A=alpha*255.; - - m_listBuffer.append(el); + BufferElement el; + el.Element=SET_BG_COLOUR; + el.Data.ColourStruct=new struct ColourStruct_; + el.Data.ColourStruct->R=r; + el.Data.ColourStruct->G=g; + el.Data.ColourStruct->B=b; + el.Data.ColourStruct->A=alpha*255.; + + m_listBuffer.append(el); } void QtPLWidget::setWidth(PLINT w) { - BufferElement el; - el.Element=SET_WIDTH; - el.Data.intParam=w; - m_listBuffer.append(el); + BufferElement el; + el.Element=SET_WIDTH; + el.Data.intParam=w; + m_listBuffer.append(el); } void QtPLWidget::drawText(PLStream* pls, EscText* txt) { - BufferElement el; - el.Element=TEXT; - el.Data.TextStruct=new struct TextStruct_; - el.Data.TextStruct->x=txt->x*downscale; - el.Data.TextStruct->y=m_dHeight-txt->y*downscale; - el.Data.TextStruct->clipxmin=pls->clpxmi*downscale; - el.Data.TextStruct->clipymin=m_dHeight-pls->clpymi*downscale; - el.Data.TextStruct->clipxmax=pls->clpxma*downscale; - el.Data.TextStruct->clipymax=m_dHeight-pls->clpyma*downscale; - PLUNICODE fci; - plgfci(&fci); - el.Data.TextStruct->fci=fci; - PLFLT rotation, shear, stride; - plRotationShear( txt->xform, &rotation, &shear, &stride); - rotation -= pls->diorot * M_PI / 2.0; - el.Data.TextStruct->rotation=rotation; - el.Data.TextStruct->shear=shear; - el.Data.TextStruct->stride=stride; - el.Data.TextStruct->just=txt->just; - el.Data.TextStruct->text=new PLUNICODE[txt->unicode_array_len]; - memcpy(el.Data.TextStruct->text, txt->unicode_array, txt->unicode_array_len*sizeof(PLUNICODE)); - el.Data.TextStruct->len=txt->unicode_array_len; - el.Data.TextStruct->chrht=pls->chrht; - - m_listBuffer.append(el); + BufferElement el; + el.Element=TEXT; + el.Data.TextStruct=new struct TextStruct_; + el.Data.TextStruct->x=txt->x*downscale; + el.Data.TextStruct->y=m_dHeight-txt->y*downscale; + el.Data.TextStruct->clipxmin=pls->clpxmi*downscale; + el.Data.TextStruct->clipymin=m_dHeight-pls->clpymi*downscale; + el.Data.TextStruct->clipxmax=pls->clpxma*downscale; + el.Data.TextStruct->clipymax=m_dHeight-pls->clpyma*downscale; + PLUNICODE fci; + plgfci(&fci); + el.Data.TextStruct->fci=fci; + PLFLT rotation, shear, stride; + plRotationShear( txt->xform, &rotation, &shear, &stride); + rotation -= pls->diorot * M_PI / 2.0; + el.Data.TextStruct->rotation=rotation; + el.Data.TextStruct->shear=shear; + el.Data.TextStruct->stride=stride; + el.Data.TextStruct->just=txt->just; + el.Data.TextStruct->text=new PLUNICODE[txt->unicode_array_len]; + memcpy(el.Data.TextStruct->text, txt->unicode_array, txt->unicode_array_len*sizeof(PLUNICODE)); + el.Data.TextStruct->len=txt->unicode_array_len; + el.Data.TextStruct->chrht=pls->chrht; + + m_listBuffer.append(el); } void QtPLWidget::renderText(QPainter* p, struct TextStruct_* s, double x_fact, double x_offset, double y_fact, double y_offset) { - if(s->len<=0 || s->len>=500) return; - QPicture picText=getTextPicture(s->fci, s->text, s->len, s->chrht*y_fact); - - double picDpi=picText.logicalDpiY(); + if(s->len<=0 || s->len>=500) return; + QPicture picText=getTextPicture(s->fci, s->text, s->len, s->chrht*y_fact); - p->setClipping(true); - p->setClipRect(QRectF(s->clipxmin*x_fact+x_offset, s->clipymax*y_fact+y_offset, (s->clipxmax-s->clipxmin)*x_fact, (-s->clipymax+s->clipymin)*y_fact), Qt::ReplaceClip); - p->translate(s->x*x_fact+x_offset, s->y*y_fact+y_offset); - QMatrix rotShearMatrix(cos(s->rotation)*s->stride, -sin(s->rotation)*s->stride, cos(s->rotation)*sin(s->shear)+sin(s->rotation)*cos(s->shear), -sin(s->rotation)*sin(s->shear)+cos(s->rotation)*cos(s->shear), 0.,0.); - p->setWorldMatrix(rotShearMatrix, true); + double picDpi=picText.logicalDpiY(); - p->translate(-s->just*xOffset*p->device()->logicalDpiY()/picDpi, 0.); - - p->drawPicture(0., 0., picText); - + p->setClipping(true); + p->setClipRect(QRectF(s->clipxmin*x_fact+x_offset, s->clipymax*y_fact+y_offset, (s->clipxmax-s->clipxmin)*x_fact, (-s->clipymax+s->clipymin)*y_fact), Qt::ReplaceClip); + p->translate(s->x*x_fact+x_offset, s->y*y_fact+y_offset); + QMatrix rotShearMatrix(cos(s->rotation)*s->stride, -sin(s->rotation)*s->stride, cos(s->rotation)*sin(s->shear)+sin(s->rotation)*cos(s->shear), -sin(s->rotation)*sin(s->shear)+cos(s->rotation)*cos(s->shear), 0.,0.); + p->setWorldMatrix(rotShearMatrix, true); + + p->translate(-s->just*xOffset*p->device()->logicalDpiY()/picDpi, 0.); + + p->drawPicture(0., 0., picText); + p->resetTransform(); - p->setClipping(false); + p->setClipping(false); } void QtPLWidget::mouseReleaseEvent ( QMouseEvent * event ) { - if(event->button()==Qt::RightButton) - { - handler.DeviceChangedPage(this); - } + if(event->button()==Qt::RightButton) + { + handler.DeviceChangedPage(this); + } } void QtPLWidget::keyPressEvent(QKeyEvent* event) { - if(event->key()==Qt::Key_Enter || event->key()==Qt::Key_Return) - { - handler.DeviceChangedPage(this); - } + if(event->key()==Qt::Key_Enter || event->key()==Qt::Key_Return) + { + handler.DeviceChangedPage(this); + } } void QtPLWidget::closeEvent(QCloseEvent* event) { - handler.DeviceClosed(this); - event->ignore(); + handler.DeviceClosed(this); + event->ignore(); } void QtPLWidget::nextPage() { - clearWidget(); - pageNumber++; + clearWidget(); + pageNumber++; } void QtPLWidget::resizeEvent( QResizeEvent * ) { - m_bAwaitingRedraw=true; - delete m_pixPixmap; - m_pixPixmap=NULL; + m_bAwaitingRedraw=true; + delete m_pixPixmap; + m_pixPixmap=NULL; } void QtPLWidget::paintEvent( QPaintEvent * ) { - double x_fact, y_fact, x_offset(0.), y_offset(0.); //Parameters to scale and center the plot on the widget - - getPlotParameters(x_fact, y_fact, x_offset, y_offset); - if(m_bAwaitingRedraw || m_pixPixmap==NULL || m_listBuffer.size()!=m_iOldSize) // If must regenerate image, draw it in the pixmap - { - delete m_pixPixmap; - m_pixPixmap=new QPixmap(width(), height()); - QPainter* painter=new QPainter; - painter->begin(m_pixPixmap); - - // Draw the margins and the background - painter->fillRect(0, 0, width(), height(), QBrush(Qt::white)); - painter->fillRect(0, 0, width(), height(), QBrush(Qt::gray, Qt::Dense4Pattern)); - - // Draw the plot - doPlot(painter, x_fact, y_fact, x_offset, y_offset); - painter->end(); - - m_bAwaitingRedraw=false; - m_iOldSize=m_listBuffer.size(); - - delete painter; - } - - // draw the current pixmap - m_painterP->begin(this); - - m_painterP->drawPixmap(0, 0, *m_pixPixmap); - - m_painterP->end(); + double x_fact, y_fact, x_offset(0.), y_offset(0.); //Parameters to scale and center the plot on the widget + + getPlotParameters(x_fact, y_fact, x_offset, y_offset); + if(m_bAwaitingRedraw || m_pixPixmap==NULL || m_listBuffer.size()!=m_iOldSize) // If must regenerate image, draw it in the pixmap + { + delete m_pixPixmap; + m_pixPixmap=new QPixmap(width(), height()); + QPainter* painter=new QPainter; + painter->begin(m_pixPixmap); + + // Draw the margins and the background + painter->fillRect(0, 0, width(), height(), QBrush(Qt::white)); + painter->fillRect(0, 0, width(), height(), QBrush(Qt::gray, Qt::Dense4Pattern)); + + // Draw the plot + doPlot(painter, x_fact, y_fact, x_offset, y_offset); + painter->end(); + + m_bAwaitingRedraw=false; + m_iOldSize=m_listBuffer.size(); + + delete painter; + } + + // draw the current pixmap + m_painterP->begin(this); + + m_painterP->drawPixmap(0, 0, *m_pixPixmap); + + m_painterP->end(); } void QtPLWidget::doPlot(QPainter* p, double x_fact, double y_fact, double x_offset, double y_offset) { - QLineF line; - QPointF * polyline; - PLINT npts; - QVector<qreal> vect; + QLineF line; + QPointF * polyline; + PLINT npts; + QVector<qreal> vect; QRectF rect; QPen SolidPen; @@ -892,8 +892,8 @@ p->setPen(SolidPen); bool hasPen=true; - p->setRenderHints(QPainter::Antialiasing, true); - + p->setRenderHints(QPainter::Antialiasing, true); + QBrush SolidBrush(Qt::SolidPattern); p->setBrush(SolidBrush); @@ -903,33 +903,33 @@ p->setTransform(trans); - if(m_listBuffer.empty()) - { + if(m_listBuffer.empty()) + { p->fillRect(0, 0, 1, 1, QBrush()); - return; - } - // unrolls the buffer and draws each element accordingly - for(QLinkedList<BufferElement>::const_iterator i=m_listBuffer.begin(); i!=m_listBuffer.end(); ++i) - { - switch(i->Element) - { - case LINE: + return; + } + // unrolls the buffer and draws each element accordingly + for(QLinkedList<BufferElement>::const_iterator i=m_listBuffer.begin(); i!=m_listBuffer.end(); ++i) + { + switch(i->Element) + { + case LINE: if(!hasPen) { p->setPen(SolidPen); hasPen=true; } p->drawLine(*(i->Data.Line)); - break; - - case POLYLINE: + break; + + case POLYLINE: if(!hasPen) - { + { p->setPen(SolidPen); hasPen=true; - } + } p->drawPolyline(*(i->Data.Polyline)); - break; + break; case RECTANGLE: p->setRenderHints(QPainter::Antialiasing, false); @@ -942,18 +942,18 @@ p->setRenderHints(QPainter::Antialiasing, true); break; - case POLYGON: + case POLYGON: p->setRenderHints(QPainter::Antialiasing, false); if(hasPen) - { + { p->setPen(NoPen); hasPen=false; - } + } p->drawConvexPolygon(*(i->Data.Polyline)); p->setRenderHints(QPainter::Antialiasing, true); - break; + break; - case TEXT: + case TEXT: if(!hasPen) { p->setPen(SolidPen); @@ -962,19 +962,19 @@ p->save(); p->resetTransform(); - renderText(p, i->Data.TextStruct, x_fact, x_offset, y_fact, y_offset); + renderText(p, i->Data.TextStruct, x_fact, x_offset, y_fact, y_offset); p->restore(); - break; - - case SET_WIDTH: + break; + + case SET_WIDTH: SolidPen.setWidthF(i->Data.intParam); if(hasPen) { p->setPen(SolidPen); } - break; - - case SET_COLOUR: + break; + + case SET_COLOUR: SolidPen.setColor(QColor(i->Data.ColourStruct->R, i->Data.ColourStruct->G, i->Data.ColourStruct->B, i->Data.ColourStruct->A)); if(hasPen) { @@ -982,102 +982,102 @@ } SolidBrush.setColor(QColor(i->Data.ColourStruct->R, i->Data.ColourStruct->G, i->Data.ColourStruct->B, i->Data.ColourStruct->A)); p->setBrush(SolidBrush); - break; + break; - case SET_BG_COLOUR: + case SET_BG_COLOUR: SolidBrush.setColor(QColor(i->Data.ColourStruct->R, i->Data.ColourStruct->G, i->Data.ColourStruct->B, i->Data.ColourStruct->A)); p->fillRect(0., 0., m_dWidth, m_dHeight, SolidBrush); - break; + break; - default: - break; - } - } + default: + break; + } + } } void QtPLWidget::getPlotParameters(double & io_dXFact, double & io_dYFact, double & io_dXOffset, double & io_dYOffset) { - double w=(double)width(); - double h=(double)height(); - if(w/h>m_dAspectRatio) //Too wide, h is the limitating factor - { - io_dYFact=h/m_dHeight; - io_dXFact=h*m_dAspectRatio/m_dWidth; - io_dYOffset=0.; - io_dXOffset=(w-io_dXFact*m_dWidth)/2.; - } - else - { - io_dXFact=w/m_dWidth; - io_dYFact=w/m_dAspectRatio/m_dHeight; - io_dXOffset=0.; - io_dYOffset=(h-io_dYFact*m_dHeight)/2.; - } + double w=(double)width(); + double h=(double)height(); + if(w/h>m_dAspectRatio) //Too wide, h is the limitating factor + { + io_dYFact=h/m_dHeight; + io_dXFact=h*m_dAspectRatio/m_dWidth; + io_dYOffset=0.; + io_dXOffset=(w-io_dXFact*m_dWidth)/2.; + } + else + { + io_dXFact=w/m_dWidth; + io_dYFact=w/m_dAspectRatio/m_dHeight; + io_dXOffset=0.; + io_dYOffset=(h-io_dYFact*m_dHeight)/2.; + } } #endif #if defined(PLD_extqt) QtExtWidget::QtExtWidget(int i_iWidth, int i_iHeight, QWidget* parent): - QtPLWidget(i_iWidth, i_iHeight, parent) + QtPLWidget(i_iWidth, i_iHeight, parent) { - cursorParameters.isTracking=false; - cursorParameters.cursor_x=-1.0; - cursorParameters.cursor_y=-1.0; - killed=false; + cursorParameters.isTracking=false; + cursorParameters.cursor_x=-1.0; + cursorParameters.cursor_y=-1.0; + killed=false; } QtExtWidget::~QtExtWidget() { - killed=true; - QCoreApplication::processEvents(QEventLoop::AllEvents, 10); - delete m_pixPixmap; - delete m_painterP; - m_pixPixmap=NULL; - m_painterP=NULL; + killed=true; + QCoreApplication::processEvents(QEventLoop::AllEvents, 10); + delete m_pixPixmap; + delete m_painterP; + m_pixPixmap=NULL; + m_painterP=NULL; } void QtExtWidget::captureMousePlotCoords(PLFLT* x, PLFLT* y) { - setMouseTracking(true); - cursorParameters.isTracking=true; - cursorParameters.cursor_x= - cursorParameters.cursor_y=-1.; - do - { - QCoreApplication::processEvents(QEventLoop::AllEvents, 10); - } while(cursorParameters.isTracking && !killed); - - *x=cursorParameters.cursor_x; - *y=cursorParameters.cursor_y; + setMouseTracking(true); + cursorParameters.isTracking=true; + cursorParameters.cursor_x= + cursorParameters.cursor_y=-1.; + do + { + QCoreApplication::processEvents(QEventLoop::AllEvents, 10); + } while(cursorParameters.isTracking && !killed); + + *x=cursorParameters.cursor_x; + *y=cursorParameters.cursor_y; } void QtExtWidget::mouseMoveEvent(QMouseEvent* event) { - if(!cursorParameters.isTracking) return; + if(!cursorParameters.isTracking) return; - double x_fact, y_fact, x_offset, y_offset; //Parameters to scale and center the plot on the widget - - getPlotParameters(x_fact, y_fact, x_offset, y_offset); - - cursorParameters.cursor_x=(PLFLT)event->x(); - cursorParameters.cursor_y=(PLFLT)event->y(); + double x_fact, y_fact, x_offset, y_offset; //Parameters to scale and center the plot on the widget - double ratio_x; - double ratio_y; - ratio_x=(cursorParameters.cursor_x-x_offset)/(width()-2.*x_offset); - ratio_y=(cursorParameters.cursor_y-y_offset)/(height()-2.*y_offset); + getPlotParameters(x_fact, y_fact, x_offset, y_offset); - PLFLT a,b; - PLINT c; - plcalc_world(ratio_x, 1.-ratio_y, &a, &b, &c); + cursorParameters.cursor_x=(PLFLT)event->x(); + cursorParameters.cursor_y=(PLFLT)event->y(); - if(c<0) - { - cursorParameters.cursor_x=-1.; - cursorParameters.cursor_y=-1.; - } + double ratio_x; + double ratio_y; + ratio_x=(cursorParameters.cursor_x-x_offset)/(width()-2.*x_offset); + ratio_y=(cursorParameters.cursor_y-y_offset)/(height()-2.*y_offset); - update(); + PLFLT a,b; + PLINT c; + plcalc_world(ratio_x, 1.-ratio_y, &a, &b, &c); + + if(c<0) + { + cursorParameters.cursor_x=-1.; + cursorParameters.cursor_y=-1.; + } + + update(); } void QtExtWidget::mousePressEvent(QMouseEvent* event) @@ -1086,65 +1086,65 @@ void QtExtWidget::mouseReleaseEvent(QMouseEvent* event) { - if(!cursorParameters.isTracking) return; + if(!cursorParameters.isTracking) return; - double x_fact, y_fact, x_offset, y_offset; //Parameters to scale and center the plot on the widget - - getPlotParameters(x_fact, y_fact, x_offset, y_offset); + double x_fact, y_fact, x_offset, y_offset; //Parameters to scale and center the plot on the widget + + getPlotParameters(x_fact, y_fact, x_offset, y_offset); - cursorParameters.cursor_x=(PLFLT)event->x(); - cursorParameters.cursor_y=(PLFLT)event->y(); - cursorParameters.isTracking=false; - setMouseTracking(false); + cursorParameters.cursor_x=(PLFLT)event->x(); + cursorParameters.cursor_y=(PLFLT)event->y(); + cursorParameters.isTracking=false; + setMouseTracking(false); + + double ratio_x; + double ratio_y; + ratio_x=(cursorParameters.cursor_x-x_offset)/(width()-2.*x_offset); + ratio_y=(cursorParameters.cursor_y-y_offset)/(height()-2.*y_offset); - double ratio_x; - double ratio_y; - ratio_x=(cursorParameters.cursor_x-x_offset)/(width()-2.*x_offset); - ratio_y=(cursorParameters.cursor_y-y_offset)/(height()-2.*y_offset); + PLFLT a,b; + PLINT c; + plcalc_world(ratio_x, 1.-ratio_y, &a, &b, &c); - PLFLT a,b; - PLINT c; - plcalc_world(ratio_x, 1.-ratio_y, &a, &b, &c); + if(c<0) + { + cursorParameters.cursor_x=-1.; + cursorParameters.cursor_y=-1.; + } + else + { + cursorParameters.cursor_x=a; + cursorParameters.cursor_y=b; + } - if(c<0) - { - cursorParameters.cursor_x=-1.; - cursorParameters.cursor_y=-1.; - } - else - { - cursorParameters.cursor_x=a; - cursorParameters.cursor_y=b; - } - - update(); + update(); } void QtExtWidget::paintEvent(QPaintEvent* event) { - QtPLWidget::paintEvent(event); + QtPLWidget::paintEvent(event); - if(!cursorParameters.isTracking || cursorParameters.cursor_x<0) return; + if(!cursorParameters.isTracking || cursorParameters.cursor_x<0) return; - QPainter p(this); + QPainter p(this); - p.setPen(QPen(Qt::white)); + p.setPen(QPen(Qt::white)); - p.drawLine((int)cursorParameters.cursor_x, 0, (int)cursorParameters.cursor_x, height()); - p.drawLine(0, (int)cursorParameters.cursor_y, width(), (int)cursorParameters.cursor_y); + p.drawLine((int)cursorParameters.cursor_x, 0, (int)cursorParameters.cursor_x, height()); + p.drawLine(0, (int)cursorParameters.cursor_y, width(), (int)cursorParameters.cursor_y); - p.end(); + p.end(); } void plsetqtdev(QtExtWidget* widget) { - plsc->dev = (void*)widget; + plsc->dev = (void*)widget; } void plfreeqtdev() { - delete ((QtExtWidget*)plsc->dev); - plsc->dev=NULL; + delete ((QtExtWidget*)plsc->dev); + plsc->dev=NULL; } #endif Modified: trunk/drivers/qt.cpp =================================================================== --- trunk/drivers/qt.cpp 2009-07-31 18:07:55 UTC (rev 10195) +++ trunk/drivers/qt.cpp 2009-07-31 18:17:38 UTC (rev 10196) @@ -1,33 +1,33 @@ /* - This software is provided under the LGPL in March 2009 by the - Cluster Science Centre - QSAS team, - Imperial College, London +This software is provided under the LGPL in March 2009 by the +Cluster Science Centre +QSAS team, +Imperial College, London - Copyright (C) 2009 Imperial College, London - Copyright (C) 2009 Alan W. Irwin +Copyright (C) 2009 Imperial College, London +Copyright (C) 2009 Alan W. Irwin - This is free software; you can redistribute it and/or modify - it under the terms of the GNU General Lesser Public License as published - by the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. +This is free software; you can redistribute it and/or modify +it under the terms of the GNU General Lesser Public License as published +by the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. - This software 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 Lesser General Public License for more details. +This software 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 Lesser General Public License for more details. - To received a copy of the GNU Library General Public License - write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - History: +To received a copy of the GNU Library General Public License +write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - March 2009: v1.00 - Initial release. - +History: + + +March 2009: v1.00 +Initial release. + */ @@ -77,65 +77,65 @@ #endif ; -static DrvOpt qt_options[]={ {"text_vectorize", DRV_INT, &vectorize, "Vectorize fonts on output (0|1)"}, - {NULL, DRV_INT, NULL, NULL}}; +static DrvOpt qt_options[]={ {"text_vectorize", DRV_INT, &vectorize, "Vectorize fonts on output (0|1)"}, + {NULL, DRV_INT, NULL, NULL}}; bool initQtApp(bool isGUI) { - QMutexLocker locker(&QtPLDriver::mutex); - bool res=false; - ++appCounter; - if(qApp==NULL && appCounter==1) - { - argc=1; - argv=new char*[2]; - argv[0]=new char[10]; - argv[1]=new char[1]; - snprintf(argv[0], 10, "qt_driver"); - argv[1][0]='\0'; - new QApplication(argc, argv, isGUI); - res=true; - } - return res; + QMutexLocker locker(&QtPLDriver::mutex); + bool res=false; + ++appCounter; + if(qApp==NULL && appCounter==1) + { + argc=1; + argv=new char*[2]; + argv[0]=new char[10]; + argv[1]=new char[1]; + snprintf(argv[0], 10, "qt_driver"); + argv[1][0]='\0'; + new QApplication(argc, argv, isGUI); + res=true; + } + return res; } void closeQtApp() { - QMutexLocker locker(&QtPLDriver::mutex); - --appCounter; - if(qApp!=NULL && appCounter==0) - { - delete qApp; - delete[] argv[0]; - delete[] argv[1]; - delete[] argv; - argv=NULL; - } + QMutexLocker locker(&QtPLDriver::mutex); + --appCounter; + if(qApp!=NULL && appCounter==0) + { + delete qApp; + delete[] argv[0]; + delete[] argv[1]; + delete[] argv; + argv=NULL; + } } /*--------------------------------------------------------------------- - qt_family_check () - - support function to help supress more than one page if family file - output not specified by the user (e.g., with the -fam command-line option). - Adapted directly from svg.c - ---------------------------------------------------------------------*/ +qt_family_check () + +support function to help supress more than one page if family file +output not specified by the user (e.g., with the -fam command-line option). +Adapted directly from svg.c +---------------------------------------------------------------------*/ static int already_warned = 0; static int qt_family_check(PLStream *pls) { - if (pls->family || pls->page == 1) - { - return 0; - } - else - { - if(! already_warned) + if (pls->family || pls->page == 1) { - already_warned = 1; - plwarn("All pages after the first skipped because family file output not specified.\n"); + return 0; } - return 1; - } + else + { + if(! already_warned) + { + already_warned = 1; + plwarn("All pages after the first skipped because family file output not specified.\n"); + } + return 1; + } } // Declaration of the driver-specific interface functions @@ -233,175 +233,175 @@ #if defined (PLD_bmpqt) || defined(PLD_jpgqt) || defined (PLD_pngqt) || defined(PLD_ppmqt) || defined(PLD_tiffqt) void plD_init_rasterqt(PLStream * pls) { - double dpi; - - vectorize=0; - plParseDrvOpts(qt_options); - - /* Stream setup */ - pls->color = 1; - pls->plbuf_write=0; - pls->dev_fill0 = 1; - pls->dev_fill1 = 0; - /* Let the PLplot core handle dashed lines since - * the driver results for this capability have a number of issues. - pls->dev_dash=1; */ - pls->dev_dash=0; - pls->dev_flush=1; - /* Driver does not have a clear capability so use (good) PLplot core - * fallback for that instead. */ - pls->dev_clear=0; - pls->termin=0; - pls->page = 0; - pls->dev_text = 1; // want to draw text - pls->dev_unicode = 1; // want unicode - - bool isMaster=initQtApp(/*false*/true); // Is it still a problem? - - if (pls->xdpi <=0.) - dpi = DEFAULT_DPI; - else - dpi = pls->xdpi; + double dpi; + + vectorize=0; + plParseDrvOpts(qt_options); + + /* Stream setup */ + pls->color = 1; + pls->plbuf_write=0; + pls->dev_fill0 = 1; + pls->dev_fill1 = 0; + /* Let the PLplot core handle dashed lines since + * the driver results for this capability have a number of issues. + pls->dev_dash=1; */ + pls->dev_dash=0; + pls->dev_flush=1; + /* Driver does not have a clear capability so use (good) PLplot core + * fallback for that instead. */ + pls->dev_clear=0; + pls->termin=0; + pls->page = 0; + pls->dev_text = 1; // want to draw text + pls->dev_unicode = 1; // want unicode - // Shamelessly copied on the Cairo stuff :) - if (pls->xlength <= 0 || pls->ylength <= 0) - { - pls->dev=new QtRasterDevice; - pls->xlength = (PLINT)(((QtRasterDevice*)(pls->dev))->m_dWidth); - pls->ylength = (PLINT)(((QtRasterDevice*)(pls->dev))->m_dHeight); - } - else - { - pls->dev=new QtRasterDevice(pls->xlength, pls->ylength); - } + bool isMaster=initQtApp(/*false*/true); // Is it still a problem? + + if (pls->xdpi <=0.) + dpi = DEFAULT_DPI; + else + dpi = pls->xdpi; + + // Shamelessly copied on the Cairo stuff :) + if (pls->xlength <= 0 || pls->ylength <= 0) + { + pls->dev=new QtRasterDevice; + pls->xlength = (PLINT)(((QtRasterDevice*)(pls->dev))->m_dWidth); + pls->ylength = (PLINT)(((QtRasterDevice*)(pls->dev))->m_dHeight); + } + else + { + pls->dev=new QtRasterDevice(pls->xlength, pls->ylength); + } - if(isMaster) handler.setMasterDevice((QtRasterDevice*)(pls->dev)); + if(isMaster) handler.setMasterDevice((QtRasterDevice*)(pls->dev)); - if (pls->xlength > pls->ylength) - ((QtRasterDevice*)(pls->dev))->downscale = (PLFLT)pls->xlength/(PLFLT)(PIXELS_X-1); - else - ((QtRasterDevice*)(pls->dev))->downscale = (PLFLT)pls->ylength/(PLFLT)PIXELS_Y; - - plP_setphy((PLINT) 0, (PLINT) (pls->xlength / ((QtRasterDevice*)(pls->dev))->downscale), (PLINT) 0, (PLINT) (pls->ylength / ((QtRasterDevice*)(pls->dev))->downscale)); - - plP_setpxl(dpi/25.4/((QtRasterDevice*)(pls->dev))->downscale, dpi/25.4/((QtRasterDevice*)(pls->dev))->downscale); - - ((QtRasterDevice*)(pls->dev))->setResolution(dpi); + if (pls->xlength > pls->ylength) + ((QtRasterDevice*)(pls->dev))->downscale = (PLFLT)pls->xlength/(PLFLT)(PIXELS_X-1); + else + ((QtRasterDevice*)(pls->dev))->downscale = (PLFLT)pls->ylength/(PLFLT)PIXELS_Y; + + plP_setphy((PLINT) 0, (PLINT) (pls->xlength / ((QtRasterDevice*)(pls->dev))->downscale), (PLINT) 0, (PLINT) (pls->ylength / ((QtRasterDevice*)(pls->dev))->downscale)); + + plP_setpxl(dpi/25.4/((QtRasterDevice*)(pls->dev))->downscale, dpi/25.4/((QtRasterDevice*)(pls->dev))->downscale); + + ((QtRasterDevice*)(pls->dev))->setResolution(dpi); - /* Initialize family file info */ - plFamInit(pls); - - plOpenFile(pls); + /* Initialize family file info */ + plFamInit(pls); + + plOpenFile(pls); } void plD_eop_rasterqt(PLStream *pls) { - if(qt_family_check(pls)) {return;} - ((QtRasterDevice *)pls->dev)->savePlot(); - handler.DeviceChangedPage((QtRasterDevice *)pls->dev); + if(qt_family_check(pls)) {return;} + ((QtRasterDevice *)pls->dev)->savePlot(); + handler.DeviceChangedPage((QtRasterDevice *)pls->dev); } void plD_line_rasterqt(PLStream * pls, short x1a, short y1a, short x2a, short y2a) { - QtRasterDevice* widget=(QtRasterDevice*)pls->dev; - if(widget!=NULL && qt_family_check(pls)) {return;} - if(widget==NULL) return; + QtRasterDevice* widget=(QtRasterDevice*)pls->dev; + if(widget!=NULL && qt_family_check(pls)) {return;} + if(widget==NULL) return; - widget->QtPLDriver::setColor(pls->curcolor.r, pls->curcolor.g, pls->curcolor.b, pls->curcolor.a); - widget->drawLine(x1a, y1a, x2a, y2a); + widget->QtPLDriver::setColor(pls->curcolor.r, pls->curcolor.g, pls->curcolor.b, pls->curcolor.a); + widget->drawLine(x1a, y1a, x2a, y2a); } void plD_polyline_rasterqt(PLStream *pls, short *xa, short *ya, PLINT npts) { - QtRasterDevice * widget=(QtRasterDevice *) pls->dev; - if(widget!=NULL && qt_family_check(pls)) {return;} - if(widget==NULL) return; + QtRasterDevice * widget=(QtRasterDevice *) pls->dev; + if(widget!=NULL && qt_family_check(pls)) {return;} + if(widget==NULL) return; - widget->QtPLDriver::setColor(pls->curcolor.r, pls->curcolor.g, pls->curcolor.b, pls->curcolor.a); - widget->drawPolyline(xa, ya, npts); + widget->QtPLDriver::setColor(pls->curcolor.r, pls->curcolor.g, pls->curcolor.b, pls->curcolor.a); + widget->drawPolyline(xa, ya, npts); } void plD_esc_rasterqt(PLStream * pls, PLINT op, void* ptr) { - short *xa, *ya; - PLINT i, j; - QtRasterDevice * widget=(QtRasterDevice *) pls->dev; - if(widget!=NULL && qt_family_check(pls)) {return;} - if(widget==NULL) return; - - switch(op) - { + short *xa, *ya; + PLINT i, j; + QtRasterDevice * widget=(QtRasterDevice *) pls->dev; + if(widget!=NULL && qt_family_check(pls)) {return;} + if(widget==NULL) return; + + switch(op) + { // case PLESC_DASH: // widget->setDashed(pls->nms, pls->mark, pls->space); // widget->QtPLDriver::setColor(pls->curcolor.r, pls->curcolor.g, pls->curcolor.b, pls->curcolor.a); // ... [truncated message content] |