Example #1
0
void KexiKIconTableEdit::setupContents(QPainter *p, bool /*focused*/, const QVariant& val,
                                       QString &/*txt*/, int &/*align*/, int &/*x*/, int &y_offset, int &w, int &h)
{
    Q_UNUSED(y_offset);

#if 0
#ifdef Q_WS_WIN
    y_offset = -1;
#else
    y_offset = 0;
#endif
    int s = qMax(h - 5, 12);
    s = qMin(h - 3, s);
    s = qMin(w - 3, s);//avoid too large box
    QRect r(qMax(w / 2 - s / 2, 0) , h / 2 - s / 2 /*- 1*/, s, s);
    p->setPen(QPen(colorGroup().text(), 1));
    p->drawRect(r);
    if (val.asBool()) {
        p->drawLine(r.x(), r.y(), r.right(), r.bottom());
        p->drawLine(r.x(), r.bottom(), r.right(), r.y());
    }
#endif

    QString key(val.toString());
    QPixmap pm;
    if (!key.isEmpty()) {
        QPixmap *cached = d->pixmapCache[ key ];
        if (cached)
            pm = *cached;
        if (pm.isNull()) {
            //cache pixmap
            pm = KIconLoader::global()->loadIcon(key, KIconLoader::Small,
                                                 0, KIconLoader::DefaultState , QStringList() , 0L, true/*canReturnNull*/);
            if (!pm.isNull())
                d->pixmapCache.insert(key, new QPixmap(pm));
        }
    }

    if (p && !pm.isNull())
        p->drawPixmap((w - pm.width()) / 2, (h - pm.height()) / 2, pm);
}
Example #2
0
void KexiKIconTableEdit::setupContents( QPainter *p, bool /*focused*/, const QVariant& val, 
	QString &/*txt*/, int &/*align*/, int &/*x*/, int &y_offset, int &w, int &h  )
{
	Q_UNUSED( y_offset );

#if 0
#ifdef Q_WS_WIN
	y_offset = -1;
#else
	y_offset = 0;
#endif
	int s = QMAX(h - 5, 12);
	s = QMIN( h-3, s );
	s = QMIN( w-3, s );//avoid too large box
	QRect r( QMAX( w/2 - s/2, 0 ) , h/2 - s/2 /*- 1*/, s, s);
	p->setPen(QPen(colorGroup().text(), 1));
	p->drawRect(r);
	if (val.asBool()) {
		p->drawLine(r.x(), r.y(), r.right(), r.bottom());
		p->drawLine(r.x(), r.bottom(), r.right(), r.y());
	}
#endif

	QString key = val.toString();
	QPixmap *pix = 0;
	if (!key.isEmpty() && !(pix = d->pixmapCache[ key ])) {
		//cache pixmap
		QPixmap pm = KGlobal::iconLoader()->loadIcon( key, KIcon::Small, 
			0, KIcon::DefaultState, 0L, true/*canReturnNull*/ );
		if (!pm.isNull()) {
			pix = new QPixmap(pm);
			d->pixmapCache.insert(key, pix);
		}
	}

	if (p && pix) {
		p->drawPixmap( (w-pix->width())/2, (h-pix->height())/2, *pix );
	}
}
Example #3
0
static void packVariant( UibStrTable& strings, QDataStream& out,
			 QVariant value, QString tag = "" )
{
    QStringList::ConstIterator s;

    Q_UINT8 type = value.type();
    if ( tag == "pixmap" ) {
	type = QVariant::Pixmap;
    } else if ( tag == "image" ) {
	type = QVariant::Image;
    } else if ( tag == "iconset" ) {
	type = QVariant::IconSet;
    }
    out << type;

    switch ( type ) {
    case QVariant::String:
    case QVariant::Pixmap:
    case QVariant::Image:
    case QVariant::IconSet:
	packString( strings, out, value.asString() );
	break;
    case QVariant::StringList:
	packUInt16( out, value.asStringList().count() );
	s = value.asStringList().begin();
	while ( s != value.asStringList().end() ) {
	    packString( strings, out, *s );
	    ++s;
	}
	break;
    case QVariant::Font:
	out << value.asFont();
	break;
    case QVariant::Rect:
	packUInt16( out, value.asRect().x() );
	packUInt16( out, value.asRect().y() );
	packUInt16( out, value.asRect().width() );
	packUInt16( out, value.asRect().height() );
	break;
    case QVariant::Size:
	packUInt16( out, value.asSize().width() );
	packUInt16( out, value.asSize().height() );
	break;
    case QVariant::Color:
	out << value.asColor();
	break;
    case QVariant::Point:
	packUInt16( out, value.asPoint().x() );
	packUInt16( out, value.asPoint().y() );
	break;
    case QVariant::Int:
	packUInt32( out, value.asInt() );
	break;
    case QVariant::Bool:
	out << (Q_UINT8) value.asBool();
	break;
    case QVariant::Double:
	out << value.asDouble();
	break;
    case QVariant::CString:
	packCString( strings, out, value.asCString() );
	break;
    case QVariant::Cursor:
	out << value.asCursor();
	break;
    case QVariant::Date:
	out << value.asDate();
	break;
    case QVariant::Time:
	out << value.asTime();
	break;
    case QVariant::DateTime:
	out << value.asDateTime();
	break;
    default:
	out << value;
    }
}