Exemplo n.º 1
0
void AnimatedLayer::updateHorizontalStep()
{
    m_currentHorizontalStep += (m_horizontalStep * m_factor * m_direction);

    if (m_currentHorizontalStep <= -width()) {
        drawPixmap();
        m_currentHorizontalStep = 0;
    } else if (m_currentHorizontalStep >= 0) {
        drawPixmap();
        m_currentHorizontalStep = -width();
    }
}
Exemplo n.º 2
0
void StaticLayer::moveX(qreal value)
{
    m_globalXPos += value; // XXX should multiply by -1??
    m_localXPos += value;

    if (m_localXPos > 0) {
        drawPixmap();
        m_localXPos =  -width() + value;
    } else if (m_localXPos * m_factor <= -width()) {
        drawPixmap();
        m_localXPos = 0;
    }
}
Exemplo n.º 3
0
void QPaintEngineEx::drawPixmapFragments(const QRectF *targetRects, const QRectF *sourceRects, int fragmentCount,
                                         const QPixmap &pixmap, QPainter::PixmapFragmentHints /*hints*/)
{
    if (pixmap.isNull())
        return;

    if (sourceRects) {
        for (int i = 0; i < fragmentCount; ++i)
            drawPixmap(targetRects[i], pixmap, sourceRects[i]);
    } else {
        QRectF sourceRect = pixmap.rect();
        for (int i = 0; i < fragmentCount; ++i)
            drawPixmap(targetRects[i], pixmap, sourceRect);
    }
}
Exemplo n.º 4
0
void ImageWidget::setPicture(const QString name)
{
    clear();
    eType = ImageWidget::Picture;
#ifdef WEBP_SUPPORT
    if (name.indexOf(".webp") != -1) {
        WebpDecoder wepI;
        wepI.setFile(name);
        pixmap = wepI.getPixmap();
    } else
        pixmap = QPixmap(name);
#else
    if (name.indexOf(".webp") != -1)
        emit couldOpen(false);

    else
        pixmap = QPixmap(name);
#endif

    if (invertedColors) {
        egg();
    }

    drawPixmap();
    emit couldOpen(true);
    prevFile = name;
}
Exemplo n.º 5
0
void EmfPaintEngine::drawTiledPixmap(const QRectF &r, const QPixmap & pix, const QPointF &)
{
	setClipping();

#ifdef Q_WS_WIN
	HBITMAP hBmp = pix.toWinHBITMAP();
	HBRUSH wbrush = CreatePatternBrush(hBmp);

	QMatrix m = painter()->worldMatrix();
	QRectF dr = m.mapRect(r);

	RECT rect;
	rect.left = qRound(dr.left());
	rect.top = qRound(dr.top());
	rect.right = qRound(dr.right());
	rect.bottom = qRound(dr.bottom());

	FillRect(metaDC, &rect, wbrush);

	DeleteObject(hBmp);
	DeleteObject(wbrush);
#else
	int width = qRound(r.width());
	int height = qRound(r.height());

	QPixmap pixmap(width, height);
	QPainter p(&pixmap);
	p.drawTiledPixmap(0, 0, width, height, pix);
	p.end();

	drawPixmap(r, pixmap, QRectF());
#endif

	resetClipping();
}
Exemplo n.º 6
0
void ImageWidget::movieSlot()
{
    if(stopWhenFinish && (movie->currentFrameNumber() == movie->frameCount() - 1)){
        movie->stop();
    }

    pixmap = movie->currentPixmap();
    makeDynamicTransformation();

    if(invertedColors){
        egg();
    }

    drawPixmap();

    if(scaleFactor==1){
        scaleFactor = 1;
        imageLabel->adjustSize();
        this->adjustSize();
        return;
    }

    imageLabel->resize(pixmap.size() * scaleFactor);
    this->resize((pixmap.size() + bugSize) * scaleFactor);
}
Exemplo n.º 7
0
void WaveRenderArea::resizeEvent(QResizeEvent *e)
{
  Q_D(WaveRenderArea);
  QMutexLocker(d->sampleBufferMutex);
  d->pixmap = QPixmap(e->size());
  drawPixmap();
}
Exemplo n.º 8
0
void QPaintEngineEx::drawPixmapFragments(const QPainter::PixmapFragment *fragments, int fragmentCount,
                                         const QPixmap &pixmap, QPainter::PixmapFragmentHints /*hints*/)
{
    if (pixmap.isNull())
        return;

    qreal oldOpacity = state()->opacity;
    QTransform oldTransform = state()->matrix;

    for (int i = 0; i < fragmentCount; ++i) {
        QTransform transform = oldTransform;
        transform.translate(fragments[i].x, fragments[i].y);
        transform.rotate(fragments[i].rotation);
        state()->opacity = oldOpacity * fragments[i].opacity;
        state()->matrix = transform;
        opacityChanged();
        transformChanged();

        qreal w = fragments[i].scaleX * fragments[i].width;
        qreal h = fragments[i].scaleY * fragments[i].height;
        QRectF sourceRect(fragments[i].sourceLeft, fragments[i].sourceTop,
                          fragments[i].width, fragments[i].height);
        drawPixmap(QRectF(-0.5 * w, -0.5 * h, w, h), pixmap, sourceRect);
    }

    state()->opacity = oldOpacity;
    state()->matrix = oldTransform;
    opacityChanged();
    transformChanged();
}
Exemplo n.º 9
0
void SkyQPainter::drawPointSource(const QPointF& pos, float size, char sp)
{
    int isize = qMin(static_cast<int>(size), 14);
    if( !m_vectorStars || starColorMode == 0  ) {
        // Draw stars as bitmaps, either because we were asked to, or because we're painting real colors
        QPixmap* im = imageCache[ harvardToIndex(sp) ][isize];
        float offset = 0.5 * im->width();
        drawPixmap( QPointF(pos.x()-offset, pos.y()-offset), *im );
    }
    else {
        // Draw stars as vectors, for better printing / SVG export etc.
        if ( starColorMode != 4 ) {
            setPen( m_starColor );
            setBrush( m_starColor );
        }
        else {
            // Note: This is not efficient, but we use vector stars only when plotting SVG, not when drawing the skymap, so speed is not very important.
            QColor c = ColorMap.value( sp, Qt::white );
            setPen( c );
            setBrush( c );
        }

        // Be consistent with old raster representation
        if( size > 14 )
            size = 14;
        if( size >= 2 )
            drawEllipse( pos.x() - 0.5 * size, pos.y() - 0.5 * size, int(size), int(size) );
        else if( size >= 1 )
            drawPoint( pos.x(), pos.y() );
    }
}
Exemplo n.º 10
0
void
makePixmap(PluginInstance *This)
{
    createPixmap(This);
    drawPixmap(This);
    setCursor(This);
    addXtEventHandler(This);
}
Exemplo n.º 11
0
void WaveRenderArea::mouseMoveEvent(QMouseEvent *e)
{
  Q_D(WaveRenderArea);
  if (d->mouseDown) {
    d->pos2 = e->x();
    drawPixmap();
  }
}
Exemplo n.º 12
0
void WaveRenderArea::mouseReleaseEvent(QMouseEvent *e)
{
  Q_D(WaveRenderArea);
  if (e->button() == Qt::LeftButton) {
    d->mouseDown = false;
    drawPixmap();
    d->lockTimeNs = (qMax(d->pos1, d->pos2) - qMin(d->pos1, d->pos2)) * 1000 * d->audioFormat.durationForFrames(d->sampleBuffer.size()) / width();
  }
}
Exemplo n.º 13
0
void WaveRenderArea::setData(const SampleBufferType &data, qint64 processedUSecs)
{
  Q_D(WaveRenderArea);
  QMutexLocker(d->sampleBufferMutex);
  d->sampleBuffer = data;
  d->frameTimestampNs = 1000 * processedUSecs;
  findPeaks();
  d->lastFrameTimestampNs = d->frameTimestampNs;
  drawPixmap();
}
Exemplo n.º 14
0
void WaveRenderArea::mousePressEvent(QMouseEvent *e)
{
  Q_D(WaveRenderArea);
  if (e->button() == Qt::LeftButton) {
    d->mouseDown = true;
    d->pos1 = e->x();
    d->pos2 = d->pos1;
    drawPixmap();
  }
}
//! [1]
MyGraphicsEffect::draw(QPainter *painter)
{
    ...
    QPoint offset;
    if (sourceIsPixmap()) {
        // No point in drawing in device coordinates (pixmap will be scaled anyways).
        const QPixmap pixmap = sourcePixmap(Qt::LogicalCoordinates, &offset);
        ...
        painter->drawPixmap(offset, pixmap);
    } else {
Exemplo n.º 16
0
void QPaintEngine::drawImage(const QRectF &r, const QImage &image, const QRectF &sr,
                             Qt::ImageConversionFlags flags)
{
    QRectF baseSize(0, 0, image.width(), image.height());
    QImage im = image;
    if (baseSize != sr)
        im = im.copy(qFloor(sr.x()), qFloor(sr.y()),
                     qCeil(sr.width()), qCeil(sr.height()));
    QPixmap pm = QPixmap::fromImage(im, flags);
    drawPixmap(r, pm, QRectF(QPointF(0, 0), pm.size()));
}
Exemplo n.º 17
0
void MSToggleButtonBase::redraw(void)
{
  if (owner()->mapped()==MSTrue)
   {
     MSWidgetCommon::drawBackground();
     if(highlighted()==MSTrue) drawHighlight();
     else undrawHighlight();
     drawSymbol();
     if (pixmap()==0) drawLabel();
     else drawPixmap();
   }
}
Exemplo n.º 18
0
void FileListDelegate::paint(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const {
    auto path = index.data(Qt::UserRole).toString();
    FileListItem* item = fileListWidget->getItem(path);
    File* file = item->getFile();
    auto bgRect = option.rect;
    bgRect.adjust(0, 0, -4, -37);
    auto textRect = QRect(bgRect.x() + 6, bgRect.bottom(), bgRect.width() - 12, 28);
    p->setPen(Qt::NoPen);

    // draw icon
    if (file->isFolder()) {
        if (file->isDotDot()) {
            drawPixmap(p, fileListWidget->backPixmap, bgRect, false);
        } else {
            drawPixmap(p, fileListWidget->folderPixmap, bgRect, false);
        }
    } else if (file->isImage()) {
        p->setBrush(backgroundBrush);
        p->drawRect(bgRect);
    }
    drawPixmap(p, item->pixmap, bgRect, file->isFolder() && !item->pixmap.isNull());

    // draw selection
    if (item->isSelected()) {
        auto selRect = option.rect;
        selRect.adjust(0, 0, -4, -4);
        p->setBrush(selectionBrush);
        p->drawRect(selRect);
    }

    // draw text
    QString text = index.data().toString();
    auto font = p->font();
    QFontMetrics fontMetrics(font);
    auto elidedText = fontMetrics.elidedText(text, Qt::ElideMiddle, textRect.width());
    p->setPen(textPen);
    p->drawText(textRect, Qt::AlignCenter, elidedText);
}
Exemplo n.º 19
0
static void
xt_event_handler(Widget xt_w, PluginInstance *This, XEvent *xevent, Boolean *b)
{
    switch (xevent->type)
    {
        case Expose:
            /* get rid of all other exposure events */
            while(XCheckTypedWindowEvent(This->display, This->window, Expose, xevent));
            drawPixmap(This);
            break;
        case ButtonRelease:
            if (xevent->xbutton.button == Button1)
            {
                makeWidget(This);
            } 
            break;
        default:
            break;
    }
}
Exemplo n.º 20
0
void SkyQPainter::drawPointSource(const QPointF& pos, float size, char sp)
{
    int isize = qMin(static_cast<int>(size), 14);
    if( !m_vectorStars || ( starColorMode <=0 || starColorMode > 3 )  ) {
        // Draw stars as bitmaps, either because we were asked to, or because we're painting real colors
        QPixmap* im = imageCache[ harvardToIndex(sp) ][isize];
        float offset = 0.5 * im->width();
        drawPixmap( QPointF(pos.x()-offset, pos.y()-offset), *im );
    }
    else {
        // Draw stars as vectors, for better printing / SVG export etc.
        static QColor color; // FIXME: This slows down things a bit, but we won't care because we're not painting the SkyMap this way anyway.
        switch( Options::starColorMode() ) {
        case 1:
            color = QColor::fromRgb(255, 0, 0);
            break;
        case 2:
            color = QColor::fromRgb(0, 0, 0);
            break;
        case 3:
            color = QColor::fromRgb(255, 255, 255);
            break;
        default:
            Q_ASSERT( false );
        }
        setPen( color );
        setBrush( color );

        // Be consistent with old raster representation
        if( size > 14 )
            size = 14;
        if( size >= 2 )
            drawEllipse( pos.x() - 0.5 * size, pos.y() - 0.5 * size, int(size), int(size) );
        else if( size >= 1 )
            drawPoint( pos.x(), pos.y() );
    }
}
Exemplo n.º 21
0
/*!
  Draw a color bar into a rectangle

  \param painter Painter
  \param colorMap Color map
  \param interval Value range
  \param scaleMap Scale map
  \param orientation Orientation
  \param rect Traget rectangle
*/
void QwtPainter::drawColorBar( QPainter *painter,
        const QwtColorMap &colorMap, const QwtInterval &interval,
        const QwtScaleMap &scaleMap, Qt::Orientation orientation,
        const QRectF &rect )
{
    QVector<QRgb> colorTable;
    if ( colorMap.format() == QwtColorMap::Indexed )
        colorTable = colorMap.colorTable( interval );

    QColor c;

    const QRect devRect = rect.toAlignedRect();

    /*
      We paint to a pixmap first to have something scalable for printing
      ( f.e. in a Pdf document )
     */

    QPixmap pixmap( devRect.size() );
    QPainter pmPainter( &pixmap );
    pmPainter.translate( -devRect.x(), -devRect.y() );

    if ( orientation == Qt::Horizontal )
    {
        QwtScaleMap sMap = scaleMap;
        sMap.setPaintInterval( rect.left(), rect.right() );

        for ( int x = devRect.left(); x <= devRect.right(); x++ )
        {
            const double value = sMap.invTransform( x );

            if ( colorMap.format() == QwtColorMap::RGB )
                c.setRgb( colorMap.rgb( interval, value ) );
            else
                c = colorTable[colorMap.colorIndex( interval, value )];

            pmPainter.setPen( c );
            pmPainter.drawLine( x, devRect.top(), x, devRect.bottom() );
        }
    }
    else // Vertical
    {
        QwtScaleMap sMap = scaleMap;
        sMap.setPaintInterval( rect.bottom(), rect.top() );

        for ( int y = devRect.top(); y <= devRect.bottom(); y++ )
        {
            const double value = sMap.invTransform( y );

            if ( colorMap.format() == QwtColorMap::RGB )
                c.setRgb( colorMap.rgb( interval, value ) );
            else
                c = colorTable[colorMap.colorIndex( interval, value )];

            pmPainter.setPen( c );
            pmPainter.drawLine( devRect.left(), y, devRect.right(), y );
        }
    }
    pmPainter.end();

    drawPixmap( painter, rect, pixmap );
}
Exemplo n.º 22
0
void Layer::updateTiles()
{
    if ((boundingRect().width() == 0) || (boundingRect().height() == 0))
        return;

    // TODO create enums to define image aspect, auto tile, etc...
    QPixmap pix(source()); // TODO

    if (m_drawType == Quasi::PlaneDrawType) {
        m_tileWidth = width();
        m_tileHeight = height();

        if (pix.width() % (int)width() != 0) {
            // XXX create some log system?
            qCritical() << QString("Quasi>>Image \'%1\' doesn't contains a proper size... CROPPING!").arg(source());

            int newWidth = pix.width() - (pix.width() % (int)width());
            pix = pix.copy(0, 0, newWidth, height());
        }
    }

    if (pix.width() < boundingRect().width()) {
        QPixmap temp(boundingRect().width(), boundingRect().height());
        QPainter p(&temp);
            p.drawTiledPixmap(boundingRect(), pix, QPoint(0,0));
        p.end();

        pix = temp;
    }

    QPixmap mirrored;
    if (m_type == Quasi::MirroredType){
        QImage image = pix.toImage();

        mirrored = QPixmap::fromImage(image.mirrored(true, false));
    }

    // visible tiles
    m_numColumns = boundingRect().width() / m_tileWidth;
    m_numRows = boundingRect().height() / m_tileHeight;

    // total of columns and rows
    m_totalColumns = pix.width() / m_tileWidth;
    m_totalRows = pix.height() / m_tileHeight;

    int i, j;
    for (i = 0; i < m_totalRows; i++) {
        for (j = 0; j < m_totalColumns; j++){
            QPixmap temp(m_tileWidth, m_tileHeight);

            QPainter p(&temp);
                p.setCompositionMode(QPainter::CompositionMode_Source);
                p.drawPixmap(0, 0, m_tileWidth, m_tileHeight,
                        pix, j * m_tileWidth, i * m_tileHeight, m_tileWidth, m_tileHeight);
            p.end();

            addTile(temp);

            if (m_type == Quasi::MirroredType) {
                QPainter p(&temp);
                    p.drawPixmap(0, 0, m_tileWidth, m_tileHeight,
                            mirrored, j * m_tileWidth, i * m_tileHeight, m_tileWidth, m_tileHeight);
                p.end();

                m_mirroredTiles.append(temp);
            }
        }
    }

    generateOffsets();
    drawPixmap();
}
Exemplo n.º 23
0
void MapBox::createMenus()
{
    QAction * menuItem;
    QMenu * subMenuItem;
    m_popupMenu = new QMenu(this);
    m_popupMenuMapObject = new QMenu(this);

    //**************************************************************

    // MapObject-specific context menu. The map object is in m_lastClickedMapObject.
    subMenuItem = m_popupMenuMapObject->addMenu(tr("MapObject"));

    menuItem = subMenuItem->addAction(tr("Remove"));
    connect(menuItem, SIGNAL(triggered()),
            this, SLOT(removeMapObject()));

    //**************************************************************

    /*

    // These are gread for testing, but not really what we want in
    // an example application.
    // We should probably creating a testing branch which tracks
    // the master branch and has various "test enabled" versions
    // of the examples at some point anyhow.

    subMenuItem = m_popupMenuMapObject->addMenu(tr("Spawn stuff"));
    m_popupMenu->addMenu(subMenuItem);

    menuItem = subMenuItem->addAction(tr("Items near the dateline"));
    connect(menuItem, SIGNAL(triggered()),
            this, SLOT(demo1()));

    menuItem = subMenuItem->addAction(tr("Regular grid of items"));
    connect(menuItem, SIGNAL(triggered()),
            this, SLOT(demo2()));

    menuItem = subMenuItem->addAction(tr("Clusters"));
    connect(menuItem, SIGNAL(triggered()),
            this, SLOT(demo3()));

    */

    //**************************************************************
    subMenuItem = m_popupMenuMapObject->addMenu(tr("Marker"));
    m_popupMenu->addMenu(subMenuItem);

    menuItem = subMenuItem->addAction(tr("Set marker"));
    connect(menuItem, SIGNAL(triggered()),
            this, SLOT(drawPixmap()));

    menuItem = subMenuItem->addAction(tr("Remove markers"));
    connect(menuItem, SIGNAL(triggered()),
            this, SLOT(removePixmaps()));

    menuItem = subMenuItem->addAction(tr("Select objects"));
    connect(menuItem, SIGNAL(triggered()),
            this, SLOT(selectObjects()));

    //**************************************************************
    subMenuItem = m_popupMenu->addMenu(tr("Draw"));
    m_popupMenu->addMenu(subMenuItem);

    menuItem = subMenuItem->addAction(tr("Rectangle"));
    connect(menuItem, SIGNAL(triggered()),
            this, SLOT(drawRect()));

    menuItem = subMenuItem->addAction(tr("Polyline"));
    connect(menuItem, SIGNAL(triggered()),
            this, SLOT(drawPolyline()));

    menuItem = subMenuItem->addAction(tr("Polygon"));
    connect(menuItem, SIGNAL(triggered()),
            this, SLOT(drawPolygon()));

    menuItem = subMenuItem->addAction(tr("Circle"));
    connect(menuItem, SIGNAL(triggered()),
            this, SLOT(drawCircle()));

    menuItem = subMenuItem->addAction(tr("Text"));
    connect(menuItem, SIGNAL(triggered()),
            this, SLOT(drawText()));

    //**************************************************************
    subMenuItem = m_popupMenuMapObject->addMenu(tr("Route"));
    m_popupMenu->addMenu(subMenuItem);

    menuItem = subMenuItem->addAction(tr("Calculate route"));
    connect(menuItem, SIGNAL(triggered()),
            this, SLOT(calcRoute()));

    //**************************************************************
    subMenuItem = m_popupMenuMapObject->addMenu(tr("Coordinates"));
    m_popupMenu->addMenu(subMenuItem);

    menuItem = subMenuItem->addAction(tr("Capture"));
    connect(menuItem, SIGNAL(triggered()),
            this, SLOT(captureCoordinates()));
    connect(menuItem, SIGNAL(triggered()),
            m_coordControlDialog, SLOT(show()));

    menuItem = subMenuItem->addAction(tr("Go to"));
    connect(menuItem, SIGNAL(triggered()),
            m_coordControlDialog, SLOT(show()));

    //**************************************************************
    subMenuItem = m_popupMenuMapObject->addMenu(tr("Tests"));
    m_popupMenu->addMenu(subMenuItem);

    menuItem = subMenuItem->addAction(tr("Dateline"));
    connect(menuItem, SIGNAL(triggered()),
            this, SLOT(testDateline()));
}
Exemplo n.º 24
0
CScreenShotView::CScreenShotView(const QList<QRect> &rectList,
                                 QScreen *screen, bool onlySelect,
                                 QWidget *parent)
    :QGraphicsView(parent)
    ,m_windowRectList(rectList)
    ,m_desktopScreen(screen)
    ,m_screen(NULL)
    ,m_backgroundItem(NULL)
    ,m_selectRectItem(NULL)
    ,m_toolbarItem(NULL)
    ,m_currentRectItem(NULL)
    ,m_tooltipSizeItem(NULL)
    ,m_previewItem(NULL)
    ,m_positionType(CSCREEN_POSITION_TYPE_NOT_CONTAIN)
    ,m_shotStatus(CSCREEN_SHOT_STATE_INITIALIZED)
    ,m_screenButtonType(CSCREEN_BUTTON_TYPE_UNDEFINED)
    ,m_isPressed(false)
    ,m_isLocked(false)
    ,m_isValid(false)
    ,m_onlySelect(onlySelect)
{
    C_SCREENSHOT_LOG_FUNCTION;
    this->setMouseTracking(true);
    m_screen = new CScreenShotScene(this);
    this->setScene(m_screen);
    QRect geometry= screen->geometry();
    C_SCREENSHOT_LOG_INFO(QString("screen->geometry() (%1,%2,%3,%4)")
                           .arg(geometry.x())
                           .arg(geometry.y())
                           .arg(geometry.width())
                           .arg(geometry.height()));
    C_SCREENSHOT_LOG_TEST;
    QPixmap pixmap = createDesktopPixmap();
    C_SCREENSHOT_LOG_TEST;
    drawPixmap(pixmap);
    m_backgroundItem = new QGraphicsPixmapItem(m_backgroundPixmap);
    m_screen->addItem(m_backgroundItem);
    C_SCREENSHOT_LOG_TEST;
    this->setGeometry(geometry);
    m_screen->setSceneRect(QRect(0,0,geometry.width(),geometry.height()));
    m_sx = 1.0 * geometry.width() / pixmap.width();
    m_sy = 1.0 * geometry.height() / pixmap.height();

    m_backgroundItem->setScale(m_sx);
    m_selectRectItem = new CScreenSelectRectItem(m_desktopPixmap);
    m_selectRectItem->setScale(m_sx);
    m_selectRectItem->setVisible(false);
    m_screen->addItem(m_selectRectItem);
    C_SCREENSHOT_LOG_TEST;
    //====================
    m_toolbarItem = new CScreenEditorToolbarItem;
    connect(m_toolbarItem,SIGNAL(sigButtonClicked(CScreenButtonType)),
            this,SLOT(onButtonClicked(CScreenButtonType)));
    m_toolbarItem->setVisible(false);
    m_toolbarItem->setZValue(m_selectRectItem->zValue() + 1);
    m_screen->addItem(m_toolbarItem);
    m_tooltipSizeItem = new CScreenTooltipItem;
    C_SCREENSHOT_LOG_TEST;
    m_tooltipSizeItem->setVisible(false);
    m_screen->addItem(m_tooltipSizeItem);
    m_previewItem = new QGraphicsPixmapItem;
    m_previewItem->setVisible(false);
    m_previewItem->setZValue(m_toolbarItem->zValue() + 1);
    C_SCREENSHOT_LOG_TEST;
    m_screen->addItem(m_previewItem);
    this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    this->setStyleSheet("QWidget{border: 0px solid #1880ed;}");
#ifdef Q_OS_MAC
    qApp->installEventFilter(this);
#endif
    QPoint pos = QCursor::pos();
    if(geometry.contains(pos))
    {
        //TODO 暂时屏蔽 为了快速启动,耗时400ms
//        updatePreviewItem(this->mapFromGlobal(pos));
    }
    C_SCREENSHOT_LOG_TEST;
}
void KStandardItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
    const_cast<KStandardItemListWidget*>(this)->triggerCacheRefreshing();

    KItemListWidget::paint(painter, option, widget);

    if (!m_expansionArea.isEmpty()) {
        drawSiblingsInformation(painter);
    }

    const KItemListStyleOption& itemListStyleOption = styleOption();
    if (isHovered()) {
        // Blend the unhovered and hovered pixmap if the hovering
        // animation is ongoing
        if (hoverOpacity() < 1.0) {
            drawPixmap(painter, m_pixmap);
        }

        const qreal opacity = painter->opacity();
        painter->setOpacity(hoverOpacity() * opacity);
        drawPixmap(painter, m_hoverPixmap);
        painter->setOpacity(opacity);
    } else {
        drawPixmap(painter, m_pixmap);
    }

    painter->setFont(m_customizedFont);
    painter->setPen(m_isHidden ? m_additionalInfoTextColor : textColor());
    const TextInfo* textInfo = m_textInfo.value("text");

    if (!textInfo) {
        // It seems that we can end up here even if m_textInfo does not contain
        // the key "text", see bug 306167. According to triggerCacheRefreshing(),
        // this can only happen if the index is negative. This can happen when
        // the item is about to be removed, see KItemListView::slotItemsRemoved().
        // TODO: try to reproduce the crash and find a better fix.
        return;
    }

    painter->drawStaticText(textInfo->pos, textInfo->staticText);

    bool clipAdditionalInfoBounds = false;
    if (m_supportsItemExpanding) {
        // Prevent a possible overlapping of the additional-information texts
        // with the icon. This can happen if the user has minimized the width
        // of the name-column to a very small value.
        const qreal minX = m_pixmapPos.x() + m_pixmap.width() + 4 * itemListStyleOption.padding;
        if (textInfo->pos.x() + columnWidth("text") > minX) {
            clipAdditionalInfoBounds = true;
            painter->save();
            painter->setClipRect(minX, 0, size().width() - minX, size().height(), Qt::IntersectClip);
        }
    }

    painter->setPen(m_additionalInfoTextColor);
    painter->setFont(m_customizedFont);

    for (int i = 1; i < m_sortedVisibleRoles.count(); ++i) {
        const TextInfo* textInfo = m_textInfo.value(m_sortedVisibleRoles[i]);
        painter->drawStaticText(textInfo->pos, textInfo->staticText);
    }

    if (!m_rating.isNull()) {
        const TextInfo* ratingTextInfo = m_textInfo.value("rating");
        QPointF pos = ratingTextInfo->pos;
        const Qt::Alignment align = ratingTextInfo->staticText.textOption().alignment();
        if (align & Qt::AlignHCenter) {
            pos.rx() += (size().width() - m_rating.width()) / 2 - 2;
        }
        painter->drawPixmap(pos, m_rating);
    }

    if (clipAdditionalInfoBounds) {
        painter->restore();
    }

#ifdef KSTANDARDITEMLISTWIDGET_DEBUG
    painter->setBrush(Qt::NoBrush);
    painter->setPen(Qt::green);
    painter->drawRect(m_iconRect);

    painter->setPen(Qt::red);
    painter->drawText(QPointF(0, m_customizedFontMetrics.height()), QString::number(index()));
    painter->drawRect(rect());
#endif
}
Exemplo n.º 26
0
void WaveRenderArea::setThreshold(int threshold)
{
  Q_D(WaveRenderArea);
  d->threshold = threshold;
  drawPixmap();
}
Exemplo n.º 27
0
void WaveRenderArea::setLockTimeNs(qint64 lockTimeNs)
{
  Q_D(WaveRenderArea);
  d->lockTimeNs = lockTimeNs;
  drawPixmap();
}
Exemplo n.º 28
0
void QPaintEngineEx::drawPixmap(const QPointF &pos, const QPixmap &pm)
{
    drawPixmap(QRectF(pos, pm.size()), pm, pm.rect());
}
Exemplo n.º 29
0
/** Draws the label */
int MLabelObject::draw(FLStylePainter *p)
{
  // Draw the pixmap
  if (!paintFunction.isEmpty()) {
    FLDomNodeInterface *dni = 0;
    QSArgumentList l;
    l << QVariant(text);
    if (!domNodeData.isNull()) {
      dni = new FLDomNodeInterface(domNodeData);
      l << dni;
    }

    QSArgument v = aqApp->call(paintFunction, l, 0);
    QSArgument::Type tp = v.type();
    if (tp != QSArgument::Invalid) {
      QPixmap pix;
      if (tp == QSArgument::VoidPointer) {
        QPixmap *vPix = static_cast<QPixmap *>(v.ptr());
        if (vPix)
          pix = *vPix;
      } else if (tp == QSArgument::Variant)
        pix = v.variant().toPixmap();

      if (!pix.isNull() && drawPixmap(p, &pix))
        return (changeHeight ? height : 0);
    }
  }

  if (pixmap && pixmap->isNull()) {
    delete pixmap;
    pixmap = 0;
  } else if (pixmap && drawPixmap(p, pixmap))
    return (changeHeight ? height : 0);

  if (text.isEmpty()) {
    drawBase(p);
    return 0;
  }

#if defined(Q_OS_MACX)
  FLStylePainter *pt = new FLStylePainter;
  int retVal = 0;
  uint originalHeight = height;
  QFont fnt;
  int tf;

  // Horizontal
  switch (hAlignment) {
    case MLabelObject::Left:
      tf = QPainter::AlignLeft;
      break;
    case MLabelObject::Center:
      tf = QPainter::AlignHCenter;
      break;
    case MLabelObject::Right:
      tf = QPainter::AlignRight;
  }

  // Vertical
  switch (vAlignment) {
    case MLabelObject::Top:
      tf = tf | QPainter::AlignTop;
      break;
    case MLabelObject::Bottom:
      tf = tf | QPainter::AlignBottom;
      break;
    case MLabelObject::Middle:
      tf = tf | QPainter::AlignVCenter;
  }

  // Word wrap
  if (wordWrap)
    tf = tf | QPainter::WordBreak;

  int nw = width * 4;
  int nh = height * 4;
  QPixmap pm(nw, nh);
  pm.fill(backgroundColor);
  pt->painter()->begin(&pm);

  fnt.setFamily(fontFamily);
  fnt.setPointSizeFloat(fontSize * 4);
  fnt.setWeight(fontWeight);
  fnt.setItalic(fontItalic);
  pt->painter()->setFont(fnt);

  if (changeHeight) {
    QRect maxRect(p->painter()->boundingRect(0, 0, nw, nh, tf, text));
    if (maxRect.height() > height) {
      height = maxRect.height();
      retVal = height;
    }
  }

  drawBase(pt);

  pt->painter()->setPen(foregroundColor);

  if (!transparent) {
    pt->painter()->setBackgroundColor(backgroundColor);
    pt->painter()->setBackgroundMode(Qt::OpaqueMode);
  }

  if (adjustFontSize && !wordWrap && !changeHeight) {
    float factor = (float)nw / (float)p->painter()->fontMetrics().width(text);
    if (factor < 1.0) {
      QFont f = p->painter()->font();
      f.setPointSizeFloat(f.pointSizeFloat() * factor);
      p->painter()->setFont(f);
    }
  }

  pt->painter()->drawText(0, 0, nw, nh, tf, text);

  pt->painter()->end();
  delete pt;

  drawPixmap(p, &pm);

  height = originalHeight;
  return retVal;
#else
  int retVal = 0;
  uint originalHeight = height;
  QFont fnt;
  int tf;
  Qt::BGMode oldBgMode;
  QColor oldBgColor;
  bool restoreBg = false;

  // Horizontal
  switch (hAlignment) {
    case MLabelObject::Left:
      tf = QPainter::AlignLeft;
      break;
    case MLabelObject::Center:
      tf = QPainter::AlignHCenter;
      break;
    case MLabelObject::Right:
      tf = QPainter::AlignRight;
  }

  // Vertical
  switch (vAlignment) {
    case MLabelObject::Top:
      tf = tf | QPainter::AlignTop;
      break;
    case MLabelObject::Bottom:
      tf = tf | QPainter::AlignBottom;
      break;
    case MLabelObject::Middle:
      tf = tf | QPainter::AlignVCenter;
  }

  // Word wrap
  if (wordWrap)
    tf = tf | QPainter::WordBreak;

  fnt.setFamily(fontFamily);
  fnt.setPointSizeFloat(fontSize);
  fnt.setWeight(fontWeight);
  fnt.setItalic(fontItalic);
  p->painter()->setFont(fnt);

  if (changeHeight) {
    QRect maxRect(p->painter()->boundingRect(0, 0, width, height, tf, text));
    if (maxRect.height() > height) {
      height = maxRect.height();
      retVal = height;
    }
  }

  drawBase(p);

  p->painter()->setPen(foregroundColor);

  if (!transparent) {
    restoreBg = true;
    oldBgMode = p->painter()->backgroundMode();
    oldBgColor = p->painter()->backgroundColor();
    p->painter()->setBackgroundColor(backgroundColor);
    p->painter()->setBackgroundMode(Qt::OpaqueMode);
  }

  if (!p->drawText(text, tf, this)) {
    bool restore = false;
    if (p->errCode() == FLStylePainter::IdNotFound) {
      p->painter()->save(QObject::name());
      p->applyTransforms();
      p->painter()->translate(xpos, ypos);
      restore = true;
    }

    if (adjustFontSize && !wordWrap && !changeHeight) {
      float factor = (float)width / (float)p->painter()->fontMetrics().width(text);
      if (factor < 1.0) {
        QFont f = p->painter()->font();
        f.setPointSizeFloat(f.pointSizeFloat() * factor);
        p->painter()->setFont(f);
      }
    }

    p->painter()->drawText(0, 0, width, height, tf, text);

    if (restore)
      p->painter()->restore();
  }

  if (restoreBg) {
    p->painter()->setBackgroundMode(oldBgMode);
    p->painter()->setBackgroundColor(oldBgColor);
  }

  height = originalHeight;
  return retVal;
#endif
}