📄 qvfbview.cpp
字号:
*dest++ = qRgb(c, c, c); } ++src; } for (int i = 0; i < width8; ++i) { c = ((*src & 0x80) >> 7) * 0xff; *dest++ = qRgb(c, c, c); c = ((*src & 0x40) >> 6) * 0xff; *dest++ = qRgb(c, c, c); c = ((*src & 0x20) >> 5) * 0xff; *dest++ = qRgb(c, c, c); c = ((*src & 0x10) >> 4) * 0xff; *dest++ = qRgb(c, c, c); c = ((*src & 0x08) >> 3) * 0xff; *dest++ = qRgb(c, c, c); c = ((*src & 0x04) >> 2) * 0xff; *dest++ = qRgb(c, c, c); c = ((*src & 0x02) >> 1) * 0xff; *dest++ = qRgb(c, c, c); c = ((*src & 0x01)) * 0xff; *dest++ = qRgb(c, c, c); ++src; } if (doTail) { switch (tail) { case 7: c = ((*src & 0x02) >> 1) * 0xff; dest[6] = qRgb(c, c, c); case 6: c = ((*src & 0x04) >> 2) * 0xff; dest[5] = qRgb(c, c, c); case 5: c = ((*src & 0x08) >> 3) * 0xff; dest[4] = qRgb(c, c, c); case 4: c = ((*src & 0x10) >> 4) * 0xff; dest[3] = qRgb(c, c, c); case 3: c = ((*src & 0x20) >> 5) * 0xff; dest[2] = qRgb(c, c, c); case 2: c = ((*src & 0x40) >> 6) * 0xff; dest[1] = qRgb(c, c, c); case 1: c = ((*src & 0x80) >> 7) * 0xff; dest[0] = qRgb(c, c, c); } } src += stride; } break; } case 4: { if (requiredSize > buffer.size()) buffer.resize(requiredSize); // XXX: hw: replace by drawhelper functionality const int pixelsPerByte = 2; const int doAlign = r.x() & 1; const int doTail = (r.width() - doAlign) & 1; const int width8 = (r.width() - doAlign) / pixelsPerByte; uchar *b = reinterpret_cast<uchar*>(buffer.data()); img = QImage(b, r.width(), r.height(), QImage::Format_RGB32); for (int y = 0; y < r.height(); ++y) { const quint8 *sptr = mView->data() + (r.y() + y) * mView->linestep() + r.x() / pixelsPerByte; quint32 *dptr = reinterpret_cast<quint32*>(img.scanLine(y)); if (doAlign) { quint8 c = (*sptr++ & 0x0f); c |= (c << 4); *dptr++ = qRgb(c, c, c); } for (int i = 0; i < width8; ++i) { quint8 c1 = (*sptr >> 4); quint8 c2 = (*sptr & 0x0f); c1 |= (c1 << 4); c2 |= (c2 << 4); *dptr++ = qRgb(c1, c1, c1); *dptr++ = qRgb(c2, c2, c2); ++sptr; } if (doTail) { quint8 c = *sptr >> 4; c |= (c << 4); *dptr = qRgb(c, c, c); } } break; } case 12: img = QImage((const uchar*)(mView->data() + r.y() * mView->linestep() + r.x() * 2), r.width(), r.height(), mView->linestep(), QImage::Format_RGB444); break; case 15: img = QImage((const uchar*)(mView->data() + r.y() * mView->linestep() + r.x() * 2), r.width(), r.height(), mView->linestep(), QImage::Format_RGB555); break; case 16: img = QImage((const uchar*)(mView->data() + r.y() * mView->linestep() + r.x() * 2), r.width(), r.height(), mView->linestep(), QImage::Format_RGB16); break; case 18: img = QImage((const uchar*)(mView->data() + r.y() * mView->linestep() + r.x() * 3), r.width(), r.height(), mView->linestep(), QImage::Format_RGB666); break; case 24: img = QImage((const uchar*)(mView->data() + r.y() * mView->linestep() + r.x() * 3), r.width(), r.height(), mView->linestep(), QImage::Format_RGB888); break; case 32: img = QImage((const uchar*)(mView->data() + r.y() * mView->linestep() + r.x() * 4), r.width(), r.height(), mView->linestep(), viewFormat == ARGBFormat ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32); break; case 8: img = QImage(mView->data() + r.y() * mView->linestep() + r.x(), r.width(), r.height(), mView->linestep(), QImage::Format_Indexed8); img.setColorTable(mView->clut()); if (img.numColors() <= 0) img = QImage(); break; } if ( brightness != 255 ) { if (img.format() == QImage::Format_Indexed8) { QVector<QRgb> c = img.colorTable(); dim(c.data(),c.count(),brightness); img.setColorTable(c); } else { if ( img.format() != QImage::Format_ARGB32_Premultiplied ) img = img.convertToFormat(QImage::Format_RGB32); // NOTE: calling bits() may change numBytes(), so do not // pass them as parameters (which are evaluated right-to-left). QRgb *b = (QRgb*)img.bits(); int n = img.numBytes()/4; dim(b,n,brightness); } } return img;}static int findMultiple(int start, double m, int limit, int step){ int r = start; while (r != limit) { if (int(int(r * m)/m) == r) break; r += step; } return r;}void QVFbView::drawScreen(const QRect &rect){ QRect r = QRect(0, 0, mView->width(), mView->height()); if (hzm == 1.0 && vzm == 1.0) // hw: workaround for 4.3.1 r &= rect; if (int(hzm) != hzm || int(vzm) != vzm) { r.setLeft(findMultiple(r.left(),hzm,0,-1)); r.setTop(findMultiple(r.top(),vzm,0,-1)); int w = findMultiple(r.width(),hzm,mView->width(),1); int h = findMultiple(r.height(),vzm,mView->height(),1); r.setRight(r.left()+w-1); r.setBottom(r.top()+h-1); } int leading; const QImage img = getBuffer(r, leading); QPixmap pm; if (hzm == 1.0 && vzm == 1.0) { pm = QPixmap::fromImage(img); } else if (emulateLcdScreen && hzm == 3.0 && vzm == 3.0) { QImage img2(img.width()*3, img.height(), QImage::Format_RGB32); for (int row = 0; row < img2.height(); row++) { QRgb *dptr = (QRgb*)img2.scanLine(row); QRgb *sptr = (QRgb*)img.scanLine(row); for (int col = 0; col < img.width(); col++) { QRgb s = *sptr++; *dptr++ = qRgb(qRed(s),0,0); *dptr++ = qRgb(0,qGreen(s),0); *dptr++ = qRgb(0,0,qBlue(s)); } } QMatrix m; m.scale(1.0, 3.0); pm = QPixmap::fromImage(img2); pm = pm.transformed(m); } else if (int(hzm) == hzm && int(vzm) == vzm) { QMatrix m; m.scale(hzm,vzm); pm = QPixmap::fromImage(img); pm = pm.transformed(m); } else { pm = QPixmap::fromImage(img.scaled(int(img.width()*hzm),int(img.height()*vzm), Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); } int x1 = r.x(); int y1 = r.y(); int leadingX = leading; int leadingY = 0; // Do the rotation thing int rotX1 = mView->width() - x1 - img.width(); int rotY1 = mView->height() - y1 - img.height(); int rotLeadingX = (leading) ? mView->width() - leadingX - img.width() : 0; int rotLeadingY = 0; switch (rotation) { case Rot0: break; case Rot90: leadingY = leadingX; leadingX = rotLeadingY; y1 = x1; x1 = rotY1; break; case Rot180: leadingX = rotLeadingX; leadingY = leadingY; x1 = rotX1; y1 = rotY1; break; case Rot270: leadingX = leadingY; leadingY = rotLeadingX; x1 = y1; y1 = rotX1; break; default: break; } x1 = int(x1*hzm); y1 = int(y1*vzm); leadingX = int(leadingX*hzm); leadingY = int(leadingY*vzm); if (rotation != 0) { QMatrix m; m.rotate(rotation * 90.0); pm = pm.transformed(m); } QPainter p(this); if (viewFormat == ARGBFormat) { QPixmap bg(":/res/images/logo-nt.png"); p.fillRect(x1,y1,pm.width(), pm.height(), QBrush(bg)); } p.drawPixmap(x1, y1, pm, leadingX, leadingY, pm.width(), pm.height());}//bool QVFbView::eventFilter(QObject *obj, QEvent *e)//{// if (obj == this &&// (e->type() == QEvent::FocusIn || e->type() == QEvent::FocusOut))// return true;//// return QWidgetView::eventFilter(obj, e);//}void QVFbView::paintEvent(QPaintEvent *e){ drawScreen(mapToDevice(e->rect(),QSize(int(width()/hzm), int(height()/vzm)),rotation));}void QVFbView::mousePressEvent(QMouseEvent *e){ sendMouseData(QPoint(int(e->x()/hzm),int(e->y()/vzm)), e->buttons(), 0);}void QVFbView::contextMenuEvent(QContextMenuEvent*){}void QVFbView::mouseDoubleClickEvent(QMouseEvent *e){ sendMouseData(QPoint(int(e->x()/hzm),int(e->y()/vzm)), e->buttons(), 0);}void QVFbView::mouseReleaseEvent(QMouseEvent *e){ sendMouseData(QPoint(int(e->x()/hzm),int(e->y()/vzm)), e->buttons(), 0);}void QVFbView::skinMouseEvent(QMouseEvent *e){ sendMouseData(QPoint(int(e->x()/hzm),int(e->y()/vzm)), e->buttons(), 0);}void QVFbView::mouseMoveEvent(QMouseEvent *e){ if (!emulateTouchscreen || (e->buttons() & Qt::MouseButtonMask)) sendMouseData(QPoint(int(e->x()/hzm),int(e->y()/vzm)), e->buttons(), 0);}void QVFbView::wheelEvent(QWheelEvent *e){ if (!e) return; sendMouseData(QPoint(int(e->x()/hzm),int(e->y()/vzm)), e->buttons(), e->delta());}void QVFbView::setTouchscreenEmulation(bool b){ emulateTouchscreen = b;}void QVFbView::setLcdScreenEmulation(bool b){ emulateLcdScreen = b;}void QVFbView::setViewFormat(PixelFormat f){ if (viewFormat == f) return; viewFormat = f; setAttribute(Qt::WA_PaintOnScreen, viewFormat != ARGBFormat);}#ifdef Q_WS_X11void QVFbView::embedDisplay(WId windowId){ if (windowId == 0) { delete embedContainer; embedContainer = 0; return; } if (!embedContainer) { embedContainer = new QX11EmbedContainer(this); embedContainer->setGeometry(rect()); embedContainer->show(); } embedContainer->embedClient(windowId);}#endifbool QVFbView::event(QEvent *e){ if (e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease) { QKeyEvent *ke = static_cast<QKeyEvent*>(e); sendKeyboardData(ke->text(), ke->key(), ke->modifiers()&(Qt::ShiftModifier|Qt::ControlModifier|Qt::AltModifier), ke->type() == QEvent::KeyPress, ke->isAutoRepeat()); ke->accept(); return true; } return QVFbAbstractView::event(e);}void QVFbView::keyPressEvent(QKeyEvent *e){ sendKeyboardData(e->text(), e->key(), e->modifiers()&(Qt::ShiftModifier|Qt::ControlModifier|Qt::AltModifier), true, e->isAutoRepeat());}void QVFbView::keyReleaseEvent(QKeyEvent *e){ sendKeyboardData(e->text(), e->key(), e->modifiers()&(Qt::ShiftModifier|Qt::ControlModifier|Qt::AltModifier), false, e->isAutoRepeat());}QImage QVFbView::image() const{ int l; QImage r = getBuffer(QRect(0, 0, mView->width(), mView->height()), l).copy(); return r;}void QVFbView::startAnimation(const QString& filename){ delete animation; animation = new QAnimationWriter(filename,"MNG"); animation->setFrameRate(refreshRate); animation->appendFrame(QImage(mView->data(), mView->width(), mView->height(), QImage::Format_RGB32));}void QVFbView::stopAnimation(){ delete animation; animation = 0;}void QVFbView::skinKeyPressEvent(int code, const QString& text, bool autorep){ QKeyEvent e(QEvent::KeyPress,code,0,text,autorep); keyPressEvent(&e);}void QVFbView::skinKeyReleaseEvent(int code, const QString& text, bool autorep){ QKeyEvent e(QEvent::KeyRelease,code,0,text,autorep); keyReleaseEvent(&e);}QT_END_NAMESPACE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -