📄 qscreentransformed_qws.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.******************************************************************************/#ifndef QT_NO_QWS_TRANSFORMED#include "qscreentransformed_qws.h"#include <qscreendriverfactory_qws.h>#include <qvector.h>#include <private/qpainter_p.h>#include <private/qdrawhelper_p.h>#include <qmatrix.h>#include <unistd.h>#include <sys/ioctl.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/mman.h>#include <fcntl.h>#include <errno.h>#include <qwindowsystem_qws.h>#include <qwsdisplay_qws.h>//#define QT_REGION_DEBUGclass QTransformedScreenPrivate{public: QTransformedScreenPrivate(QTransformedScreen *parent); void configure(); QTransformedScreen::Transformation transformation;#ifdef QT_QWS_DEPTH_GENERIC bool doGenericColors;#endif QScreen *subscreen; QTransformedScreen *q;};QTransformedScreenPrivate::QTransformedScreenPrivate(QTransformedScreen *parent) : transformation(QTransformedScreen::None),#ifdef QT_QWS_DEPTH_GENERIC doGenericColors(false),#endif subscreen(0), q(parent){}// Global function -----------------------------------------------------------static QTransformedScreen *qt_trans_screen = 0;void qws_setScreenTransformation(int t){ if (qt_trans_screen) { qt_trans_screen->setTransformation((QTransformedScreen::Transformation)t); qwsServer->refresh(); }}// ---------------------------------------------------------------------------// Transformed Screen// ---------------------------------------------------------------------------/*! \internal \class QTransformedScreen \ingroup qws \brief The QTransformedScreen class implements a screen driver for a transformed screen. Note that this class is only available in \l {Qtopia Core}. Custom screen drivers can be added by subclassing the QScreenDriverPlugin class, using the QScreenDriverFactory class to dynamically load the driver into the application, but there should only be one screen object per application. Use the QScreen::isTransformed() function to determine if a screen is transformed. The QTransformedScreen class itself provides means of rotating the screen with its setTransformation() function; the transformation() function returns the currently set rotation in terms of the \l Transformation enum (which describes the various available rotation settings). Alternatively, QTransformedScreen provides an implementation of the QScreen::transformOrientation() function, returning the current rotation as an integer value. \sa QScreen, QScreenDriverPlugin, {Running Applications}*//*! \enum QTransformedScreen::Transformation This enum describes the various rotations a transformed screen can have. \value None No rotation \value Rot90 90 degrees rotation \value Rot180 180 degrees rotation \value Rot270 270 degrees rotation*//*! \fn bool QTransformedScreen::isTransformed() const \reimp*//*! Constructs a QTransformedScreen object. The \a displayId argument identifies the Qtopia Core server to connect to.*/QTransformedScreen::QTransformedScreen(int displayId) : QScreen(displayId){ d_ptr = new QTransformedScreenPrivate(this); d_ptr->transformation = None; qt_trans_screen = this;#ifdef QT_REGION_DEBUG qDebug() << "QTransformedScreen::QTransformedScreen";#endif}void QTransformedScreenPrivate::configure(){ q->d = subscreen->depth(); q->w = subscreen->width(); q->h = subscreen->height(); q->dw = subscreen->deviceWidth(); q->dh = subscreen->deviceHeight(); q->lstep = subscreen->linestep(); q->data = subscreen->base(); q->lstep = subscreen->linestep(); q->size = subscreen->screenSize(); q->setOffset(subscreen->offset()); // ###: works because setTransformation recalculates unconditionally q->setTransformation(transformation);}/*! Destroys the QTransformedScreen object.*/QTransformedScreen::~QTransformedScreen(){ delete d_ptr;}static int getDisplayId(const QString &spec){ QRegExp regexp(QLatin1String(":(\\d+)\\b")); if (regexp.lastIndexIn(spec) != -1) { const QString capture = regexp.cap(1); return capture.toInt(); } return 0;}static QTransformedScreen::Transformation filterTransformation(QString &spec){ QRegExp regexp(QLatin1String("\\bRot(\\d+):?\\b"), Qt::CaseInsensitive); if (regexp.indexIn(spec) == -1) return QTransformedScreen::None; const int degrees = regexp.cap(1).toInt(); spec.remove(regexp.pos(0), regexp.matchedLength()); return static_cast<QTransformedScreen::Transformation>(degrees / 90);}/*! \reimp*/bool QTransformedScreen::connect(const QString &displaySpec){ QString dspec = displaySpec.trimmed(); if (dspec.startsWith(QLatin1String("Transformed:"), Qt::CaseInsensitive)) dspec = dspec.mid(QString(QLatin1String("Transformed:")).size()); else if (!dspec.compare(QLatin1String("Transformed"), Qt::CaseInsensitive)) dspec = QString(); const QString displayIdSpec = QString(QLatin1String(" :%1")).arg(displayId); if (dspec.endsWith(displayIdSpec)) dspec = dspec.left(dspec.size() - displayIdSpec.size()); d_ptr->transformation = filterTransformation(dspec); QString driver = dspec; int colon = driver.indexOf(QLatin1Char(':')); if (colon >= 0) driver.truncate(colon); if (!QScreenDriverFactory::keys().contains(driver, Qt::CaseInsensitive)) if (!dspec.isEmpty()) dspec.prepend(QLatin1String(":")); const int id = getDisplayId(dspec); d_ptr->subscreen = qt_get_screen(id, dspec.toLatin1().constData());#ifdef QT_QWS_DEPTH_GENERIC d_ptr->doGenericColors = dspec.contains(QLatin1String("genericcolors"));#endif d_ptr->configure(); // XXX qt_screen = this; return true;}/*! Returns the currently set rotation. \sa setTransformation(), QScreen::transformOrientation()*/QTransformedScreen::Transformation QTransformedScreen::transformation() const{ return d_ptr->transformation;}/*! \reimp*/int QTransformedScreen::transformOrientation() const{ return (int)d_ptr->transformation;}/*! Rotates this screen object according to the specified \a transformation. \sa transformation()*/void QTransformedScreen::setTransformation(Transformation transformation){ d_ptr->transformation = transformation; QSize s = mapFromDevice(QSize(dw, dh)); w = s.width(); h = s.height(); const QScreen *screen = d_ptr->subscreen; s = mapFromDevice(QSize(screen->physicalWidth(), screen->physicalHeight())); physWidth = s.width(); physHeight = s.height();#ifdef QT_REGION_DEBUG qDebug() << "QTransformedScreen::setTransformation" << transformation << "size" << w << h << "dev size" << dw << dh;#endif}static inline QRect correctNormalized(const QRect &r) { const int x1 = qMin(r.left(), r.right()); const int x2 = qMax(r.left(), r.right()); const int y1 = qMin(r.top(), r.bottom()); const int y2 = qMax(r.top(), r.bottom()); return QRect( QPoint(x1,y1), QPoint(x2,y2) );}template <class DST, class SRC>static inline void blit90(QScreen *screen, const QImage &image, const QRect &rect, const QPoint &topLeft){ const int sstride = image.bytesPerLine() / sizeof(SRC); const int dstride = screen->linestep() / sizeof(DST); const SRC *src = reinterpret_cast<const SRC *>(image.bits()) + rect.top() * sstride + rect.left(); DST *dest = reinterpret_cast<DST*>(screen->base()) + topLeft.y() * dstride + topLeft.x(); const int h = rect.height(); const int w = rect.width(); qt_memrotate90(src, w, h, sstride, dest, dstride);}template <class DST, class SRC>static inline void blit180(QScreen *screen, const QImage &image, const QRect &rect, const QPoint &topLeft){ const int sstride = image.bytesPerLine() / sizeof(SRC); const int dstride = screen->linestep() / sizeof(DST); const SRC *src = reinterpret_cast<const SRC *>(image.bits()) + rect.top() * sstride + rect.left(); DST *dest = reinterpret_cast<DST*>(screen->base()) + topLeft.y() * dstride + topLeft.x(); const int h = rect.height(); const int w = rect.width(); qt_memrotate180(src, w, h, sstride, dest, dstride);}template <class DST, class SRC>static inline void blit270(QScreen *screen, const QImage &image, const QRect &rect, const QPoint &topLeft){ const int sstride = image.bytesPerLine() / sizeof(SRC); const int dstride = screen->linestep() / sizeof(DST); const SRC *src = reinterpret_cast<const SRC *>(image.bits()) + rect.top() * sstride + rect.left(); DST *dest = reinterpret_cast<DST*>(screen->base()) + topLeft.y() * dstride + topLeft.x(); const int h = rect.height(); const int w = rect.width(); qt_memrotate270(src, w, h, sstride, dest, dstride);}typedef void (*BlitFunc)(QScreen *, const QImage &, const QRect &, const QPoint &);#define SET_BLIT_FUNC(dst, src, rotation, func) \do { \ switch (rotation) { \ case Rot90: \ func = blit90<dst, src>; \ break; \ case Rot180: \ func = blit180<dst, src>; \ break; \ case Rot270: \ func = blit270<dst, src>; \ break; \ default: \ break; \ } \} while (0)/*! \reimp*/void QTransformedScreen::blit(const QImage &image, const QPoint &topLeft, const QRegion ®ion){ const Transformation trans = d_ptr->transformation; if (trans == None) { d_ptr->subscreen->blit(image, topLeft, region); return; } const QVector<QRect> rects = region.rects(); const QRect bound = QRect(0, 0, QScreen::w, QScreen::h) & QRect(topLeft, image.size()); BlitFunc func = 0;#ifdef QT_QWS_DEPTH_GENERIC if (d_ptr->doGenericColors && depth() == 16) { if (image.depth() == 16) SET_BLIT_FUNC(qrgb_generic16, quint16, trans, func); else SET_BLIT_FUNC(qrgb_generic16, quint32, trans, func); } else#endif switch (depth()) {#ifdef QT_QWS_DEPTH_32 case 32:#ifdef QT_QWS_DEPTH_16 if (image.depth() == 16) SET_BLIT_FUNC(quint32, quint16, trans, func); else#endif SET_BLIT_FUNC(quint32, quint32, trans, func); break;#endif#ifdef QT_QWS_DEPTH_24 case 24: SET_BLIT_FUNC(quint24, quint32, trans, func); break;#endif#ifdef QT_QWS_DEPTH_18 case 18: SET_BLIT_FUNC(quint18, quint32, trans, func); break;#endif#ifdef QT_QWS_DEPTH_16 case 16: if (image.depth() == 16) SET_BLIT_FUNC(quint16, quint16, trans, func); else SET_BLIT_FUNC(quint16, quint32, trans, func); break;#endif#ifdef QT_QWS_DEPTH_8 case 8: if (image.depth() == 16) SET_BLIT_FUNC(quint8, quint16, trans, func); else SET_BLIT_FUNC(quint8, quint32, trans, func); break;#endif default: return; } if (!func) return; QWSDisplay::grab(); for (int i = 0; i < rects.size(); ++i) { const QRect r = rects.at(i) & bound; QPoint dst; switch (trans) { case Rot90: dst = mapToDevice(r.topRight(), QSize(w, h)); break; case Rot180: dst = mapToDevice(r.bottomRight(), QSize(w, h)); break; case Rot270: dst = mapToDevice(r.bottomLeft(), QSize(w, h)); break; default: break; } func(this, image, r.translated(-topLeft), dst); } QWSDisplay::ungrab();}/*! \reimp*/void QTransformedScreen::solidFill(const QColor &color, const QRegion ®ion){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -