📄 qpaintengine_pic.cpp
字号:
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the QtGui module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file. Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "private/qpaintengine_p.h"#include "private/qpainter_p.h"#include "private/qpicture_p.h"#include "private/qfont_p.h"#ifndef QT_NO_PICTURE#include "qbuffer.h"#include "qbytearray.h"#include "qdatastream.h"#include "qpaintengine_pic_p.h"#include "qpicture.h"#include "qpolygon.h"#include "qrect.h"#include <private/qtextengine_p.h>//#define QT_PICTURE_DEBUG#include <qdebug.h>#include <private/qmath_p.h>class QPicturePaintEnginePrivate : public QPaintEnginePrivate{ Q_DECLARE_PUBLIC(QPicturePaintEngine)public: QDataStream s; QPainter *pt; QPicturePrivate *pic_d;};QPicturePaintEngine::QPicturePaintEngine() : QPaintEngine(*(new QPicturePaintEnginePrivate), AllFeatures){ Q_D(QPicturePaintEngine); d->pt = 0;}QPicturePaintEngine::QPicturePaintEngine(QPaintEnginePrivate &dptr) : QPaintEngine(dptr, AllFeatures){ Q_D(QPicturePaintEngine); d->pt = 0;}QPicturePaintEngine::~QPicturePaintEngine(){}bool QPicturePaintEngine::begin(QPaintDevice *pd){ Q_D(QPicturePaintEngine);#ifdef QT_PICTURE_DEBUG qDebug() << "QPicturePaintEngine::begin()";#endif Q_ASSERT(pd); QPicture *pic = static_cast<QPicture *>(pd); d->pdev = pd; d->pic_d = pic->d_func(); Q_ASSERT(d->pic_d); d->s.setDevice(&d->pic_d->pictb); d->s.setVersion(d->pic_d->formatMajor); d->pic_d->pictb.open(QIODevice::WriteOnly | QIODevice::Truncate); d->s.writeRawData(qt_mfhdr_tag, 4); d->s << (quint16) 0 << (quint16) d->pic_d->formatMajor << (quint16) d->pic_d->formatMinor; d->s << (quint8) QPicturePrivate::PdcBegin << (quint8) sizeof(qint32); d->pic_d->brect = QRect(); if (d->pic_d->formatMajor >= 4) { QRect r = pic->boundingRect(); d->s << (qint32) r.left() << (qint32) r.top() << (qint32) r.width() << (qint32) r.height(); } d->pic_d->trecs = 0; d->s << (quint32)d->pic_d->trecs; // total number of records d->pic_d->formatOk = false; setActive(true); return true;}bool QPicturePaintEngine::end(){ Q_D(QPicturePaintEngine);#ifdef QT_PICTURE_DEBUG qDebug() << "QPicturePaintEngine::end()";#endif d->pic_d->trecs++; d->s << (quint8) QPicturePrivate::PdcEnd << (quint8) 0; int cs_start = sizeof(quint32); // pos of checksum word int data_start = cs_start + sizeof(quint16); int brect_start = data_start + 2*sizeof(qint16) + 2*sizeof(quint8); int pos = d->pic_d->pictb.pos(); d->pic_d->pictb.seek(brect_start); if (d->pic_d->formatMajor >= 4) { // bounding rectangle QRect r = static_cast<QPicture *>(d->pdev)->boundingRect(); d->s << (qint32) r.left() << (qint32) r.top() << (qint32) r.width() << (qint32) r.height(); } d->s << (quint32) d->pic_d->trecs; // write number of records d->pic_d->pictb.seek(cs_start); QByteArray buf = d->pic_d->pictb.buffer(); quint16 cs = (quint16) qChecksum(buf.constData() + data_start, pos - data_start); d->s << cs; // write checksum d->pic_d->pictb.close(); setActive(false); return true;}#define SERIALIZE_CMD(c) \ d->pic_d->trecs++; \ d->s << (quint8) c; \ d->s << (quint8) 0; \ pos = d->pic_d->pictb.pos()void QPicturePaintEngine::updatePen(const QPen &pen){ Q_D(QPicturePaintEngine);#ifdef QT_PICTURE_DEBUG qDebug() << " -> updatePen(): width:" << pen.width() << "style:" << pen.style() << "color:" << pen.color();#endif int pos; SERIALIZE_CMD(QPicturePrivate::PdcSetPen); d->s << pen; writeCmdLength(pos, QRect(), false);}void QPicturePaintEngine::updateCompositionMode(QPainter::CompositionMode cmode){ Q_D(QPicturePaintEngine);#ifdef QT_PICTURE_DEBUG qDebug() << " -> updateCompositionMode():" << cmode;#endif int pos; SERIALIZE_CMD(QPicturePrivate::PdcSetCompositionMode); d->s << (qint32)cmode; writeCmdLength(pos, QRectF(), false);}void QPicturePaintEngine::updateClipEnabled(bool enabled){ Q_D(QPicturePaintEngine);#ifdef QT_PICTURE_DEBUG qDebug() << " -> updateClipEnabled():" << enabled;#endif int pos; SERIALIZE_CMD(QPicturePrivate::PdcSetClipEnabled); d->s << enabled; writeCmdLength(pos, QRectF(), false);}void QPicturePaintEngine::updateOpacity(qreal opacity){ Q_D(QPicturePaintEngine);#ifdef QT_PICTURE_DEBUG qDebug() << " -> updateOpacity():" << opacity;#endif int pos; SERIALIZE_CMD(QPicturePrivate::PdcSetOpacity); d->s << double(opacity); writeCmdLength(pos, QRectF(), false);}void QPicturePaintEngine::updateBrush(const QBrush &brush){ Q_D(QPicturePaintEngine);#ifdef QT_PICTURE_DEBUG qDebug() << " -> updateBrush(): style:" << brush.style();#endif int pos; SERIALIZE_CMD(QPicturePrivate::PdcSetBrush); d->s << brush; writeCmdLength(pos, QRect(), false);}void QPicturePaintEngine::updateBrushOrigin(const QPointF &p){ Q_D(QPicturePaintEngine);#ifdef QT_PICTURE_DEBUG qDebug() << " -> updateBrushOrigin(): " << p;#endif int pos; SERIALIZE_CMD(QPicturePrivate::PdcSetBrushOrigin); d->s << p; writeCmdLength(pos, QRect(), false);}void QPicturePaintEngine::updateFont(const QFont &font){ Q_D(QPicturePaintEngine);#ifdef QT_PICTURE_DEBUG qDebug() << " -> updateFont(): pt sz:" << font.pointSize();#endif int pos; SERIALIZE_CMD(QPicturePrivate::PdcSetFont); QFont fnt = font; d->s << fnt; writeCmdLength(pos, QRectF(), false);}void QPicturePaintEngine::updateBackground(Qt::BGMode bgMode, const QBrush &bgBrush){ Q_D(QPicturePaintEngine);#ifdef QT_PICTURE_DEBUG qDebug() << " -> updateBackground(): mode:" << bgMode << "style:" << bgBrush.style();#endif int pos;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -