示例#1
0
static QPixmap scalePixmap( const QPixmap& pm, int w, int h )
{
#if QT_VERSION >= 0x030200
	QPixmap result( 20, 20, pm.depth() );
	result.setMask( QBitmap( 20, 20, true ) );
	QPixmap scaled( pm.convertToImage().smoothScale( w, h ) );
	copyBlt( &result, (20 - w) / 2, (20 - h) / 2, &scaled, 0, 0, w, h );
	return result;
#else
	Q_UNUSED(w);
	Q_UNUSED(h);
	return pm;
#endif
}
示例#2
0
    void MapNetwork::requestFinished(int id, bool error)
    {
        // sleep(1);
        // qDebug() << "MapNetwork::requestFinished" << http->state() << ", id: " << id;
        if (error)
        {
            qDebug() << "network error: " << http->errorString();
            //restart query

        }
        else if (vectorMutex.tryLock())
        {
            // check if id is in map?
            if (loadingMap.contains(id))
            {

                QString url = loadingMap[id];
                loadingMap.remove(id);
                vectorMutex.unlock();
                // qDebug() << "request finished for id: " << id << ", belongs to: " << notifier.url << endl;
                QByteArray ax;

                if (http->bytesAvailable()>0)
                {
                    QPixmap pm;
                    ax = http->readAll();

                    if (pm.loadFromData(ax))
                    {
                        loaded += pm.size().width()*pm.size().height()*pm.depth()/8/1024;
                        // qDebug() << "Network loaded: " << (loaded);
                        parent->receivedImage(pm, url);
                    }
                    else
                    {
                        qDebug() << "NETWORK_PIXMAP_ERROR: " << ax;
                    }
                }

            }
            else
                vectorMutex.unlock();

        }
        if (loadingMap.size() == 0)
        {
            // qDebug () << "all loaded";
            parent->loadingQueueEmpty();
        }
    }
void JSR239_getWindowContents(JSR239_Pixmap *dst,
                              jobject srcGraphicsHandle, 
                              jint srcWidth, jint srcHeight,
                              jint deltaHeight) {

    QPixmap* pixmap;
    void* src;

    KNI_StartHandles(1);
    KNI_DeclareHandle(GraphicsClassHandle);

#ifdef DEBUG
    printf("JSR239_getWindowContents >>\n");
#endif

    KNI_FindClass("javax/microedition/lcdui/Graphics", GraphicsClassHandle);

    if (!KNI_IsInstanceOf(graphicsHandle, GraphicsClassHandle)) {
#ifdef DEBUG
        printf("JSR239_getWindowContents only implemented for graphicsHandle "
                "instanceof Graphics!\n");
#endif
    } else {
        pixmap = getGraphicsBuffer(graphicsHandle);

#ifdef DEBUG
        printf("JSR239_getWindowContents: pixmap=%p\n", pixmap);
        printf("  pixmap Bpp = %d\n", pixmap->depth()/8);
        printf("  pixmap width  = %d\n", pixmap->width());
        printf("  pixmap height = %d\n", pixmap->height());
        printf("  dst Bpp = %d\n", dst->pixelBytes);
        printf("  dst width  = %d\n", dst->width);
        printf("  dst height = %d\n", dst->height);
#endif

        src = (void*)pixmap->scanLine(0);

        /* IMPL_NOTE: get clip sizes into account. */
        copyFromScreenBuffer(dst,
                             src, srcWidth, srcHeight,
                             deltaHeight);
    }

#ifdef DEBUG
    printf("JSR239_getWindowContents <<\n");
#endif

    KNI_EndHandles();
}
示例#4
0
QSharedPointer<QGeoTileTexture> QGeoTileCache::addToTextureCache(const QGeoTileSpec &spec, const QPixmap &pixmap)
{
    QSharedPointer<QGeoTileTexture> tt(new QGeoTileTexture);
    tt->spec = spec;
    tt->texture = new QGLTexture2D();
    tt->texture->setPixmap(pixmap);
    tt->texture->setHorizontalWrap(QGL::ClampToEdge);
    tt->texture->setVerticalWrap(QGL::ClampToEdge);

    /* Do not bind/cleanImage on the texture here -- it needs to be done
     * in the render thread (by qgeomapscene) */

    int textureCost = pixmap.width() * pixmap.height() * pixmap.depth() / 8;
    textureCache_.insert(spec, tt, textureCost);

    return tt;
}
示例#5
0
int AdobeSurfacePrivate::getPixelLayout()
{
    //qDebug("depth %d", image_.depth());
    switch ( image_.depth() )
    {
    case 24:
        //qDebug("rgb pixel format");
        return dpdoc::PL_RGB;
    case 32:
        //qDebug("argb pixel format");
        return dpdoc::PL_ARGB;
    case 8:
        //qDebug("8-bits per channel format");
        return dpdoc::PL_L;
    }
    qDebug("bgr  pixel format");
    return dpdoc::PL_BGR;
}
void OSMRendererClient::finished( QNetworkReply* reply ) {
	long long id = reply->request().attribute( QNetworkRequest::User ).toLongLong();
	if ( reply->error() ) {
		m_cache.remove( id );
		qDebug() << "failed to get: " << reply->url();
		return;
	}

	QImage image;
	if ( !image.load( reply, "PNG" ) ) {
		m_cache.remove( id );
		qDebug() << "failed to load image: " << id;
		return;
	}
	QPixmap* tile = new QPixmap( QPixmap::fromImage( image ) );
	m_cache.insert( id, tile , tileSize * tileSize * tile->depth() / 8 );
	reply->deleteLater();
	emit changed();
}
示例#7
0
bool Shadow::init(const QVector< long > &data)
{
    for (int i=0; i<ShadowElementsCount; ++i) {
        QPixmap pix = QPixmap::fromX11Pixmap(data[i], QPixmap::ExplicitlyShared);
        if (pix.isNull() || pix.depth() != 32) {
            return false;
        }
        m_shadowElements[i] = pix.copy(0, 0, pix.width(), pix.height());
    }
    m_topOffset = data[ShadowElementsCount];
    m_rightOffset = data[ShadowElementsCount+1];
    m_bottomOffset = data[ShadowElementsCount+2];
    m_leftOffset = data[ShadowElementsCount+3];
    updateShadowRegion();
    if (!prepareBackend()) {
        return false;
    }
    buildQuads();
    return true;
}
示例#8
0
unsigned char* AdobeSurfacePrivate::checkOut( int xMin, int yMin, int xMax, int yMax, size_t * stride )
{
#ifndef USE_PIXMAP
    *stride = image_.bytesPerLine();
#else
    *stride = image_.qwsBytesPerLine();
#endif

    int bytes_per_pixel = image_.depth() / 8;
    if (bytes_per_pixel < 1)
    {
        bytes_per_pixel = 1;
    }

#ifndef USE_PIXMAP
    const uchar * buf = image_.bits();
#else
    const uchar * buf = image_.qwsBits();
#endif
    return (uchar*)buf + (*stride) * yMin + bytes_per_pixel * xMin;
}
示例#9
0
void wxQtDCImpl::DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
                          bool useMask )
{
    QPixmap pix = *bmp.GetHandle();
    if (pix.depth() == 1) {
        //Monochrome bitmap, draw using text fore/background
        
        //Save pen/brush
        QBrush savedBrush = m_qtPainter->background();
        QPen savedPen = m_qtPainter->pen();
        
        //Use text colors
        m_qtPainter->setBackground(QBrush(m_textBackgroundColour.GetHandle()));
        m_qtPainter->setPen(QPen(m_textForegroundColour.GetHandle()));

        //Draw
        m_qtPainter->drawPixmap(x, y, pix);
        
        //Restore saved settings
        m_qtPainter->setBackground(savedBrush);
        m_qtPainter->setPen(savedPen);
    } else {
        if ( !useMask && bmp.GetMask() )
        {
            // Temporarly disable mask
            QBitmap mask;
            mask = pix.mask();
            pix.setMask( QBitmap() );

            // Draw
            m_qtPainter->drawPixmap(x, y, pix);

            // Restore saved mask
            pix.setMask( mask );
        }
        else
            m_qtPainter->drawPixmap(x, y, pix);
    }
}
示例#10
0
void PluginView::paint(GraphicsContext* context, const IntRect& rect)
{
    if (!m_isStarted) {
        paintMissingPluginIcon(context, rect);
        return;
    }

    if (context->paintingDisabled())
        return;

    setNPWindowIfNeeded();

    if (m_isWindowed || !m_drawable)
        return;

    const bool syncX = m_pluginDisplay && m_pluginDisplay != QX11Info::display();

    QPainter* painter = context->platformContext();
    IntRect exposedRect(rect);
    exposedRect.intersect(frameRect());
    exposedRect.move(-frameRect().x(), -frameRect().y());

    QPixmap qtDrawable = QPixmap::fromX11Pixmap(m_drawable, QPixmap::ExplicitlyShared);
    const int drawableDepth = ((NPSetWindowCallbackStruct*)m_npWindow.ws_info)->depth;
    ASSERT(drawableDepth == qtDrawable.depth());

    // When printing, Qt uses a QPicture to capture the output in preview mode. The
    // QPicture holds a reference to the X Pixmap. As a result, the print preview would
    // update itself when the X Pixmap changes. To prevent this, we create a copy.
    if (m_element->document()->printing())
        qtDrawable = qtDrawable.copy();

    if (m_isTransparent && drawableDepth != 32) {
        // Attempt content propagation for drawable with no alpha by copying over from the backing store
        QPoint offset;
        QPaintDevice* backingStoreDevice =  QPainter::redirected(painter->device(), &offset);
        offset = -offset; // negating the offset gives us the offset of the view within the backing store pixmap

        const bool hasValidBackingStore = backingStoreDevice && backingStoreDevice->devType() == QInternal::Pixmap;
        QPixmap* backingStorePixmap = static_cast<QPixmap*>(backingStoreDevice);

        // We cannot grab contents from the backing store when painting on QGraphicsView items
        // (because backing store contents are already transformed). What we really mean to do 
        // here is to check if we are painting on QWebView, but let's be a little permissive :)
        QWebPageClient* client = m_parentFrame->view()->hostWindow()->platformPageClient();
        const bool backingStoreHasUntransformedContents = client && qobject_cast<QWidget*>(client->pluginParent());

        if (hasValidBackingStore && backingStorePixmap->depth() == drawableDepth 
            && backingStoreHasUntransformedContents) {
            GC gc = XDefaultGC(QX11Info::display(), QX11Info::appScreen());
            XCopyArea(QX11Info::display(), backingStorePixmap->handle(), m_drawable, gc,
                offset.x() + m_windowRect.x() + exposedRect.x(), offset.y() + m_windowRect.y() + exposedRect.y(),
                exposedRect.width(), exposedRect.height(), exposedRect.x(), exposedRect.y());
        } else { // no backing store, clean the pixmap because the plugin thinks its transparent
            QPainter painter(&qtDrawable);
            painter.fillRect(exposedRect, Qt::white);
        }

        if (syncX)
            QApplication::syncX();
    }

    XEvent xevent;
    memset(&xevent, 0, sizeof(XEvent));
    XGraphicsExposeEvent& exposeEvent = xevent.xgraphicsexpose;
    exposeEvent.type = GraphicsExpose;
    exposeEvent.display = QX11Info::display();
    exposeEvent.drawable = qtDrawable.handle();
    exposeEvent.x = exposedRect.x();
    exposeEvent.y = exposedRect.y();
    exposeEvent.width = exposedRect.x() + exposedRect.width(); // flash bug? it thinks width is the right in transparent mode
    exposeEvent.height = exposedRect.y() + exposedRect.height(); // flash bug? it thinks height is the bottom in transparent mode

    dispatchNPEvent(xevent);

    if (syncX)
        XSync(m_pluginDisplay, False); // sync changes by plugin

    painter->drawPixmap(QPoint(frameRect().x() + exposedRect.x(), frameRect().y() + exposedRect.y()), qtDrawable,
                        exposedRect);
}
示例#11
0
/*!
    Inserts a copy of the given \a pixmap into the cache and returns a key
    that can be used to retrieve it.

    When a pixmap is inserted and the cache is about to exceed its
    limit, it removes pixmaps until there is enough room for the
    pixmap to be inserted.

    The oldest pixmaps (least recently accessed in the cache) are
    deleted when more space is needed.

    \sa setCacheLimit(), replace()

    \since 4.6
*/
QPixmapCache::Key QPixmapCache::insert(const QPixmap &pixmap)
{
    return pm_cache()->insert(pixmap, pixmap.width() * pixmap.height() * pixmap.depth() / 8);
}
示例#12
0
bool QPixmapCache::insert(const QString &key, const QPixmap &pixmap)
{
    return pm_cache()->insert(key, pixmap, pixmap.width() * pixmap.height() * pixmap.depth() / 8);
}
示例#13
0
XRenderPicture::XRenderPicture( QPixmap pix )
    : d( new XRenderPictureData( createPicture( pix.handle(), pix.depth())))
    {
    }
示例#14
0
void
JSR239_putWindowContents(jobject graphicsHandle,
                         jint delta_height,
                         JSR239_Pixmap *src, 
                         jint clipX, jint clipY, jint clipWidth, jint clipHeight,
                         jint flipY) {

    void* s;
    void* d;
    QPixmap* pixmap;

    KNI_StartHandles(1);
    KNI_DeclareHandle(GraphicsClassHandle);

#ifdef DEBUG
    printf("JSR239_putWindowContents >>\n");
#endif

    KNI_FindClass("javax/microedition/lcdui/Graphics", GraphicsClassHandle);
    if (!KNI_IsInstanceOf(graphicsHandle, GraphicsClassHandle)) {
#ifdef DEBUG
        printf("JSR239_putWindowContents only implemented for graphicsHandle "
               "instanceof Graphics!\n");
#endif
    } else {
        const jint bytes_for_depth = 2;
        const jint bits_per_byte = 8;
        jint min_height;

        pixmap = getGraphicsBuffer(graphicsHandle);

        min_height = (pixmap->height() > src->height) ? src->height :
            pixmap->height();

#ifdef DEBUG
        printf("JSR239_putWindowContent: pixmap=%p\n", pixmap);
        printf("  pixmap Bpp = %d\n",  pixmap->depth()/bits_per_byte);
        printf("  pixmap width  = %d\n", pixmap->width());
        printf("  pixmap height = %d\n", pixmap->height());
        printf("  src Bpp = %d\n", src->pixelBytes);
        printf("  src width = %d\n", src->width);
        printf("  src height = %d\n", src->height);
        printf("  min height = %d\n", min_height);
#endif

        /* IMPL_NOTE: get clip sizes into account. */
        copyToScreenBuffer(src, delta_height, 
                           clipX, clipY, 
                           clipWidth, clipHeight, 
                           clipWidth, clipHeight,
                           flipY);

        /* src->screen_buffer is an output of copyToScreenBuffer function. */
        s = (void*)src->screen_buffer;
        d = (void*)pixmap->scanLine(0);

        if ((pixmap->width() != src->width) ||
            (pixmap->depth() != bits_per_byte * bytes_for_depth)) {
#ifdef DEBUG
            printf("JSR239: offscreen buffer data is incorrect.\n");
#endif
        } else {
            /* Source data must be in 16bit 565 format. */
            JSR239_memcpy(
                d, s, pixmap->width() * min_height * bytes_for_depth);
        }
    }

#ifdef DEBUG
    printf("JSR239_putWindowContents <<\n");
#endif

    KNI_EndHandles();
}
示例#15
0
void FreshStyle::drawPopupMenuItem( QPainter* p, bool checkable, int maxpmw, int tab, QMenuItem* mi,
				       const QPalette& pal,
				       bool act, bool enabled, int x, int y, int w, int h)
{
#ifndef QT_NO_MENUDATA
    const QColorGroup & g = pal.active();
    bool dis	  = !enabled;
    QColorGroup itemg = dis ? pal.disabled() : pal.active();

    if ( checkable )
	maxpmw = QMAX( maxpmw, 8 ); // space for the checkmarks

    int checkcol	  =     maxpmw;

    if ( mi && mi->isSeparator() ) {			// draw separator
	p->setPen( g.dark() );
	p->drawLine( x, y, x+w, y );
	p->setPen( g.light() );
	p->drawLine( x, y+1, x+w, y+1 );
	return;
    }

    QBrush fill = act? g.brush( QColorGroup::Highlight ) :
			    g.brush( QColorGroup::Button );
    p->fillRect( x, y, w, h, fill);

    if ( !mi )
	return;

    if ( mi->isChecked() ) {
	if ( act && !dis ) {
	    qDrawShadePanel( p, x, y, checkcol, h,
			     g, TRUE, 1, &g.brush( QColorGroup::Button ) );
	} else {
	    qDrawShadePanel( p, x, y, checkcol, h,
			     g, TRUE, 1, &g.brush( QColorGroup::Midlight ) );
	}
    } else if ( !act ) {
	p->fillRect(x, y, checkcol , h,
		    g.brush( QColorGroup::Button ));
    }

    if ( mi->iconSet() ) {		// draw iconset
	QIconSet::Mode mode = dis ? QIconSet::Disabled : QIconSet::Normal;
	if (act && !dis )
	    mode = QIconSet::Active;
    QPixmap pixmap;
    if ( mode == QIconSet::Disabled )
        pixmap = mi->iconSet()->pixmap( QIconSet::Automatic, mode );
    else
        pixmap = mi->iconSet()->pixmap();
	int pixw = pixmap.width();
	int pixh = pixmap.height();
	if ( act && !dis ) {
	    if ( !mi->isChecked() )
		qDrawShadePanel( p, x, y, checkcol, h, g, FALSE,  1, &g.brush( QColorGroup::Button ) );
	}
	QRect cr( x, y, checkcol, h );
	QRect pmr( 0, 0, pixw, pixh );
	pmr.moveCenter( cr.center() );
	p->setPen( itemg.text() );
	p->drawPixmap( pmr.topLeft(), pixmap );

	QBrush fill = act? g.brush( QColorGroup::Highlight ) :
			      g.brush( QColorGroup::Button );
	p->fillRect( x+checkcol + 1, y, w - checkcol - 1, h, fill);
    } else  if ( checkable ) {	// just "checking"...
	int mw = checkcol + motifItemFrame;
	int mh = h - 2*motifItemFrame;
	if ( mi->isChecked() ) {
	    drawCheckMark( p, x + motifItemFrame + 2,
			   y+motifItemFrame, mw, mh, itemg, act, dis );
	}
    }

    p->setPen( act ? g.highlightedText() : g.buttonText() );

    QColor discol;
    if ( dis ) {
	discol = itemg.text();
	p->setPen( discol );
    }

    int xm = motifItemFrame + checkcol + motifItemHMargin;

    if ( mi->custom() ) {
	int m = motifItemVMargin;
	p->save();
	if ( dis && !act ) {
	    p->setPen( g.light() );
	    mi->custom()->paint( p, itemg, act, enabled,
				 x+xm+1, y+m+1, w-xm-tab+1, h-2*m );
	    p->setPen( discol );
	}
	mi->custom()->paint( p, itemg, act, enabled,
			     x+xm, y+m, w-xm-tab+1, h-2*m );
	p->restore();
    }
    QString s = mi->text();
    if ( !s.isNull() ) {			// draw text
	int t = s.find( '\t' );
	int m = motifItemVMargin;
	const int text_flags = AlignVCenter|ShowPrefix | DontClip | SingleLine;
	if ( t >= 0 ) {				// draw tab text
	    if ( dis && !act ) {
		p->setPen( g.light() );
		p->drawText( x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame+1,
			     y+m+1, tab, h-2*m, text_flags, s.mid( t+1 ));
		p->setPen( discol );
	    }
	    p->drawText( x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame,
			 y+m, tab, h-2*m, text_flags, s.mid( t+1 ) );
	}
	if ( dis && !act ) {
	    p->setPen( g.light() );
	    p->drawText( x+xm+1, y+m+1, w-xm+1, h-2*m, text_flags, s, t );
	    p->setPen( discol );
	}
	p->drawText( x+xm, y+m, w-xm-tab+1, h-2*m, text_flags, s, t );
    } else if ( mi->pixmap() ) {			// draw pixmap
	QPixmap *pixmap = mi->pixmap();
	if ( pixmap->depth() == 1 )
	    p->setBackgroundMode( OpaqueMode );
	p->drawPixmap( x+xm, y+motifItemFrame, *pixmap );
	if ( pixmap->depth() == 1 )
	    p->setBackgroundMode( TransparentMode );
    }
    if ( mi->popup() ) {			// draw sub menu arrow
	int dim = (h-2*motifItemFrame) / 2;
	if ( act ) {
	    if ( !dis )
		discol = white;
	    QColorGroup g2( discol, g.highlight(),
			    white, white,
			    dis ? discol : white,
			    discol, white );
	    drawArrow( p, RightArrow, FALSE,
			       x+w - motifArrowHMargin - motifItemFrame - dim,  y+h/2-dim/2,
			       dim, dim, g2, TRUE );
	} else {
	    drawArrow( p, RightArrow,
			       FALSE,
			       x+w - motifArrowHMargin - motifItemFrame - dim,  y+h/2-dim/2,
			       dim, dim, g, mi->isEnabled() );
	}
    }
#endif
}
示例#16
0
bool QPixmapCache::insert(const QString &key, const QPixmap &pm)
{
    return pm_cache()->insert(key, pm, pm.width() * pm.height() * pm.depth() / 8);
}
示例#17
0
/*! \reimp */
void QCompactStyle::drawControl( ControlElement element, QPainter *p, const QWidget *widget, const QRect &r,
		  const QColorGroup &g, SFlags flags, const QStyleOption& opt )
{
    switch ( element ) {
    case CE_PopupMenuItem:
	{
	    if (! widget || opt.isDefault())
		break;

	    const QPopupMenu *popupmenu = (const QPopupMenu *) widget;
	    QMenuItem *mi = opt.menuItem();
	    if ( !mi )
		break;

	    int tab = opt.tabWidth();
	    int maxpmw = opt.maxIconWidth();
	    bool dis = !(flags & Style_Enabled);
	    bool checkable = popupmenu->isCheckable();
	    bool act = flags & Style_Active;
	    int x, y, w, h;
	    r.rect( &x, &y, &w, &h );

	    QColorGroup itemg = g;

	    if ( checkable )
		maxpmw = QMAX( maxpmw, 8 ); // space for the checkmarks

	    int checkcol	  =     maxpmw;

	    if ( mi && mi->isSeparator() ) {			// draw separator
		p->setPen( g.dark() );
		p->drawLine( x, y, x+w, y );
		p->setPen( g.light() );
		p->drawLine( x, y+1, x+w, y+1 );
		return;
	    }

	    QBrush fill = act? g.brush( QColorGroup::Highlight ) :
				    g.brush( QColorGroup::Button );
	    p->fillRect( x, y, w, h, fill);

	    if ( !mi )
		return;

	    if ( mi->isChecked() ) {
		if ( act && !dis ) {
		    qDrawShadePanel( p, x, y, checkcol, h,
				     g, TRUE, 1, &g.brush( QColorGroup::Button ) );
		} else {
		    qDrawShadePanel( p, x, y, checkcol, h,
				     g, TRUE, 1, &g.brush( QColorGroup::Midlight ) );
		}
	    } else if ( !act ) {
		p->fillRect(x, y, checkcol , h,
			    g.brush( QColorGroup::Button ));
	    }

	    if ( mi->iconSet() ) {		// draw iconset
		QIconSet::Mode mode = dis ? QIconSet::Disabled : QIconSet::Normal;
		if (act && !dis )
		    mode = QIconSet::Active;
		QPixmap pixmap;
		if ( checkable && mi->isChecked() )
		    pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode, QIconSet::On );
		else
		    pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode );
		int pixw = pixmap.width();
		int pixh = pixmap.height();
		if ( act && !dis ) {
		    if ( !mi->isChecked() )
			qDrawShadePanel( p, x, y, checkcol, h, g, FALSE,  1, &g.brush( QColorGroup::Button ) );
		}
		QRect cr( x, y, checkcol, h );
		QRect pmr( 0, 0, pixw, pixh );
		pmr.moveCenter( cr.center() );
		p->setPen( itemg.text() );
		p->drawPixmap( pmr.topLeft(), pixmap );

		QBrush fill = act? g.brush( QColorGroup::Highlight ) :
				      g.brush( QColorGroup::Button );
		p->fillRect( x+checkcol + 1, y, w - checkcol - 1, h, fill);
	    } else  if ( checkable ) {	// just "checking"...
		int mw = checkcol + motifItemFrame;
		int mh = h - 2*motifItemFrame;
		if ( mi->isChecked() ) {

		    SFlags cflags = Style_Default;
		    if (! dis)
			cflags |= Style_Enabled;
		    if (act)
			cflags |= Style_On;

		    drawPrimitive( PE_CheckMark, p, QRect(x + motifItemFrame + 2, y + motifItemFrame,
				    mw, mh), itemg, cflags, opt );
		}
	    }

	    p->setPen( act ? g.highlightedText() : g.buttonText() );

	    QColor discol;
	    if ( dis ) {
		discol = itemg.text();
		p->setPen( discol );
	    }

	    int xm = motifItemFrame + checkcol + motifItemHMargin;

	    if ( mi->custom() ) {
		int m = motifItemVMargin;
		p->save();
		if ( dis && !act ) {
		    p->setPen( g.light() );
		    mi->custom()->paint( p, itemg, act, !dis,
					 x+xm+1, y+m+1, w-xm-tab+1, h-2*m );
		    p->setPen( discol );
		}
		mi->custom()->paint( p, itemg, act, !dis,
				     x+xm, y+m, w-xm-tab+1, h-2*m );
		p->restore();
	    }
	    QString s = mi->text();
	    if ( !s.isNull() ) {			// draw text
		int t = s.find( '\t' );
		int m = motifItemVMargin;
		const int text_flags = AlignVCenter|ShowPrefix | DontClip | SingleLine;
		if ( t >= 0 ) {				// draw tab text
		    if ( dis && !act ) {
			p->setPen( g.light() );
			p->drawText( x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame+1,
				     y+m+1, tab, h-2*m, text_flags, s.mid( t+1 ));
			p->setPen( discol );
		    }
		    p->drawText( x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame,
				 y+m, tab, h-2*m, text_flags, s.mid( t+1 ) );
		    s = s.left( t );
		}
		if ( dis && !act ) {
		    p->setPen( g.light() );
		    p->drawText( x+xm+1, y+m+1, w-xm+1, h-2*m, text_flags, s, t );
		    p->setPen( discol );
		}
		p->drawText( x+xm, y+m, w-xm-tab+1, h-2*m, text_flags, s, t );
	    } else if ( mi->pixmap() ) {			// draw pixmap
		QPixmap *pixmap = mi->pixmap();
		if ( pixmap->depth() == 1 )
		    p->setBackgroundMode( OpaqueMode );
		p->drawPixmap( x+xm, y+motifItemFrame, *pixmap );
		if ( pixmap->depth() == 1 )
		    p->setBackgroundMode( TransparentMode );
	    }
	    if ( mi->popup() ) {			// draw sub menu arrow
		int dim = (h-2*motifItemFrame) / 2;
		if ( act ) {
		    if ( !dis )
			discol = white;
		    QColorGroup g2( discol, g.highlight(),
				    white, white,
				    dis ? discol : white,
				    discol, white );
		    drawPrimitive(PE_ArrowRight, p, QRect(x+w - motifArrowHMargin - motifItemFrame - dim, y + h / 2 - dim / 2, dim, dim),
				  g2, Style_Enabled);
		} else {
		    drawPrimitive(PE_ArrowRight, p, QRect(x+w - motifArrowHMargin - motifItemFrame - dim, y + h / 2 - dim / 2, dim, dim),
				  g, !dis ? Style_Enabled : Style_Default);
		}
	    }
	}
	break;

    default:
	QWindowsStyle::drawControl( element, p, widget, r, g, flags, opt );
	break;
    }
}
示例#18
0
void KGrCanvas::initView()
{
    changeColours (& colourScheme [0]);		// Set "KGoldrunner" landscape.

    // Set up the pixmaps for the editable objects.
    freebg	= 0;		// Free space.
    nuggetbg	= 1;		// Nugget.
    polebg	= 2;		// Pole or bar.
    ladderbg	= 3;		// Ladder.
    hladderbg	= 4;		// Hidden ladder (for editing).
    edherobg	= 5;		// Static hero (for editing).
    edenemybg	= 6;		// Static enemy (for editing).
    betonbg	= 7;		// Concrete.

    // The bricks have 10 pixmaps (showing various stages of digging).
    brickbg	= 8;		// Solid brick - 1st pixmap.
    fbrickbg	= 15;		// False brick - 8th pixmap (for editing).

    QPixmap pixmap;
    QImage image;

    pixmap = QPixmap (hgbrick_xpm);

    bgw = pixmap.width();	// Save dimensions for "getPixmap".
    bgh = pixmap.height();
    bgd = pixmap.depth();

    // Assemble the background and editing pixmaps into a strip (18 pixmaps).
    bgPix	= QPixmap ((brickbg + 10) * bgw, bgh, bgd);

    makeTiles();		// Fill the strip with 18 tiles.

    // Define the canvas as an array of tiles.  Default tile is 0 (free space).
    int frame = frameWidth()*2;
    field = new QCanvas ((FIELDWIDTH+border) * bgw, (FIELDHEIGHT+border) * bgh);
    field->setTiles (bgPix, (FIELDWIDTH+border), (FIELDHEIGHT+border),
			bgw, bgh);

    // Embed the canvas in the view and make it occupy the whole of the view.
    setCanvas (field);
    setVScrollBarMode (QScrollView::AlwaysOff);
    setHScrollBarMode (QScrollView::AlwaysOff);
    setFixedSize (field->width() + frame, field->height() + frame);

    //////////////////////////////////////////////////////////////////////////
    // The pixmaps for hero and enemies are arranged in strips of 20: walk  //
    // right (4), walk left (4), climb right along bar (4), climb left (4), //
    // climb up ladder (2) and fall (2) --- total 20.                       //
    //////////////////////////////////////////////////////////////////////////

    // Convert the pixmap strip for hero animation into a QCanvasPixmapArray.
    pixmap = QPixmap (hero_xpm);
    image = pixmap.convertToImage ();

#ifdef QT3
    QPixmap   pm;
    QValueList<QPixmap> pmList;

    for (int i = 0; i < 20; i++) {
	pm.convertFromImage (image.copy (i * 16, 0, 16, 16));
	pmList.append (pm);
    }

    heroArray = new QCanvasPixmapArray (pmList);	// Hot spots all (0,0).
#else
    QPixmap * pm;
    QPoint  * pt;
    QList<QPixmap> pmList;
    QList<QPoint>  ptList;

    pt = new QPoint (0, 0);		// "Hot spot" not used in KGoldrunner.

    for (int i = 0; i < 20; i++) {
	pm = new QPixmap ();
	pm->convertFromImage (image.copy (i * 16, 0, 16, 16));
	pmList.append (pm);
	ptList.append (pt);
    }

    heroArray = new QCanvasPixmapArray (pmList, ptList);
#endif

    // Convert pixmap strips for enemy animations into a QCanvasPixmapArray.
    // First convert the pixmaps for enemies with no gold ...
    pixmap = QPixmap (enemy1_xpm);
    image = pixmap.convertToImage ();

    pmList.clear();

#ifdef QT3
    for (int i = 0; i < 20; i++) {
	pm.convertFromImage (image.copy (i * 16, 0, 16, 16));
	pmList.append (pm);
    }
#else
    ptList.clear();

    for (int i = 0; i < 20; i++) {
	pm = new QPixmap ();
	pm->convertFromImage (image.copy (i * 16, 0, 16, 16));
	pmList.append (pm);
	ptList.append (pt);
    }
#endif

    // ... then convert the gold-carrying enemies.
    pixmap = QPixmap (enemy2_xpm);
    image = pixmap.convertToImage ();

#ifdef QT3
    for (int i = 0; i < 20; i++) {
	pm.convertFromImage (image.copy (i * 16, 0, 16, 16));
	pmList.append (pm);
    }

    enemyArray = new QCanvasPixmapArray (pmList);	// Hot spots all (0,0).
#else
    for (int i = 0; i < 20; i++) {
	pm = new QPixmap ();
	pm->convertFromImage (image.copy (i * 16, 0, 16, 16));
	pmList.append (pm);
	ptList.append (pt);
    }

    enemyArray = new QCanvasPixmapArray (pmList, ptList);
#endif

    goldEnemy = 20;			// Offset of gold-carrying frames.

    // Draw the border around the playing area (z = 0).
    makeBorder();

    // Create a title item, in off-white colour, on top of the border.
    title = 0;
    makeTitle();

    // Create an empty list of enemy sprites.
#ifdef QT3
    enemySprites = new QPtrList<QCanvasSprite> ();
#else
    enemySprites = new QList<QCanvasSprite> ();
#endif
    enemySprites->setAutoDelete(TRUE);
}