QCursor KarbonCursor::crossHair()
{
    static unsigned char cross_bits[] = {
        0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00,
        0x80, 0x00, 0xff, 0x7f, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00,
        0x80, 0x00, 0x80, 0x00, 0x80, 0x00
    };

    QBitmap b = QBitmap::fromData(QSize(15, 15), cross_bits);
    QBitmap m = b.createHeuristicMask(false);

    return QCursor(b, m, 7, 7);
}
kpToolWidgetSpraycanSize::kpToolWidgetSpraycanSize (QWidget *parent, const char *name)
    : kpToolWidgetBase (parent, name)
{
#if DEBUG_KP_TOOL_WIDGET_SPRAYCAN_SIZE
    kdDebug () << "kpToolWidgetSpraycanSize::kpToolWidgetSpraycanSize() CALLED!" << endl;
#endif

    for (int i = 0; i < int (sizeof (spraycanSizes) / sizeof (spraycanSizes [0])); i++)
    {
        int s = spraycanSizes [i];
        QString iconName = QString ("tool_spraycan_%1x%1").arg (s).arg(s);
        
    #if DEBUG_KP_TOOL_WIDGET_SPRAYCAN_SIZE
        kdDebug () << "\ticonName=" << iconName << endl;
    #endif

        QPixmap pixmap (s, s);
        pixmap.fill (Qt::white);
        
        QPainter painter (&pixmap);
        painter.drawPixmap (0, 0, UserIcon (iconName));
        painter.end ();

        QImage image = kpPixmapFX::convertToImage (pixmap);

        QBitmap mask (pixmap.width (), pixmap.height ());
        mask.fill (Qt::color0);

        painter.begin (&mask);
        painter.setPen (Qt::color1);
        
        for (int y = 0; y < image.height (); y++)
        {
            for (int x = 0; x < image.width (); x++)
            {
                if ((image.pixel (x, y) & RGB_MASK) == 0/*black*/)
                    painter.drawPoint (x, y);  // mark as opaque
            }
        }

        painter.end ();

        pixmap.setMask (mask);
        
        addOption (pixmap, i18n ("%1x%2").arg (s).arg (s)/*tooltip*/);
        if (i == 1)
            startNewOptionRow ();
    }

    finishConstruction (0, 0);
}
QBitmap Slider::drawValue()
{
  QFontMetrics fm(this->font());
  QString st;
  st.setNum(value,'f',precision);
  QPainter painter;
  int _x,_y;
  QBitmap res;
  if (orientation == 0) {
    res.resize(width(),(height()-20)/2);
    res.fill(Qt::color0);
    painter.begin(&res);
    painter.setPen(Qt::color1);
    painter.setBrush(Qt::color1);
    painter.setFont(this->font());
    _x = (int)((res.width()-fm.width(st))/2);
    _y = (int)(res.height());
    painter.drawText(_x,_y,st);
  }
  else if (orientation == 1) {
         res.resize((width()-20)/2,height());
         res.fill(Qt::color0);
         painter.begin(&res);
         painter.setPen(Qt::color1);
         painter.setBrush(Qt::color1);
         painter.setFont(this->font());
         _x = 0;
         _y = (int)((res.height()+fm.height())/2);
         painter.drawText(_x,_y,st);
       }
  painter.end();
  return res;
}
Exemple #4
0
void VlcPrimitiveBackgroundWidget::paintEvent(QPaintEvent *e)
{
    int i_maxwidth, i_maxheight;
    QPixmap pixmap = QPixmap(_path);
    QPainter painter(this);
    QBitmap pMask;
    float f_alpha = 1.0;

    i_maxwidth  = __MIN(maximumWidth(), width()) - MARGIN * 2;
    i_maxheight = __MIN(maximumHeight(), height()) - MARGIN * 2;

    painter.setOpacity(property("opacity").toFloat());

    if (height() > MARGIN * 2)
    {
        /* Scale down the pixmap if the widget is too small */
        if (pixmap.width() > i_maxwidth || pixmap.height() > i_maxheight)
        {
            pixmap = pixmap.scaled(i_maxwidth, i_maxheight,
                            Qt::KeepAspectRatio, Qt::SmoothTransformation);
        }
        else
        if (b_expandPixmap &&
            pixmap.width() < width() && pixmap.height() < height())
        {
            /* Scale up the pixmap to fill widget's size */
            f_alpha = ((float) pixmap.height() / (float) height());
            pixmap = pixmap.scaled(
                    width() - MARGIN * 2,
                    height() - MARGIN * 2,
                    Qt::KeepAspectRatio,
                    (f_alpha < .2)? /* Don't waste cpu when not visible */
                        Qt::SmoothTransformation:
                        Qt::FastTransformation
                    );
            /* Non agressive alpha compositing when sizing up */
            pMask = QBitmap(pixmap.width(), pixmap.height());
            pMask.fill(QColor::fromRgbF(1.0, 1.0, 1.0, f_alpha));
            pixmap.setMask(pMask);
        }

        painter.drawPixmap(
                MARGIN + (i_maxwidth - pixmap.width()) /2,
                MARGIN + (i_maxheight - pixmap.height()) /2,
                pixmap);
    }
    QWidget::paintEvent( e );
}
Exemple #5
0
void tst_QPixmap::mask()
{
    QFETCH(QSize, size);

    QPixmap src = rasterPixmap(size);
    src.fill(Qt::transparent);
    {
        QPainter p(&src);
        p.drawLine(QPoint(0, 0), QPoint(src.width(), src.height()));
    }

    QBENCHMARK {
        QBitmap bitmap = src.mask();
        QVERIFY(bitmap.size() == src.size());
    }
}
Exemple #6
0
void OSDWidget::renderOSDText( const QString &text) {
	static QBitmap mask;

	// Set a sensible maximum size, don't cover the whole desktop or cross the screen
	//Actually unused but it definitly should
	//QSize max = QApplication::desktop() ->screen( m_screen ) ->size() - QSize( MARGIN*2 + 20, 100 );
	if(this->m_srt!=0){
		delete m_srt;
	}
	this->m_srt=new QSimpleRichText(text,this->font(),this->m_context);
	// The title cannnot be taller than one line
	// AlignAuto = align Arabic to the right, etc.
	int w=this->m_srt->widthUsed();
	int h=this->m_srt->height();
	osdBuffer.resize(w,h);
	mask.resize(w,h);

	// Start painting!
	QPainter bufferPainter( &osdBuffer );
	QPainter maskPainter( &mask );

	// Draw backing rectangle
	//bufferPainter.save();
	bufferPainter.setPen( Qt::black );
	bufferPainter.setBrush( backgroundColor() );
	bufferPainter.drawRoundRect( 0,0,w,h, 1500 /w, 1500/h);
	//bufferPainter.restore();
	this->m_srt->draw(&bufferPainter,0,0,QRect(),this->colorGroup());

	// Masking for transparency
	mask.fill( Qt::black );
	maskPainter.setBrush( Qt::white );
	maskPainter.drawRoundRect(0,0,w,h, 1500/w,1500/h);
	setMask( mask );

	//do last to reduce noticeable change when showing multiple OSDs in succession
	reposition(QSize(w,h));

	m_currentText = text;
	m_dirty = false;
	
	if(this->m_linking&&this==this->mouseGrabber()){
		this->releaseMouse();
		this->m_linking=false;
	}
	update();
}
Exemple #7
0
/*!
  \internal
  A static function for reading the sprite files containing
  pixmaps for displaying animated elements seen in the game.
 */
void KSprite::loadSprites()
{
    QString sprites_prefix = IMG_BACKGROUND;
    int sep = sprites_prefix.lastIndexOf("/");
    sprites_prefix.truncate(sep);

    int i = 0;
    QString file_name;
    QString base = sprites_prefix + '/';
    while (animations_[i].id_) {
	QList<QPixmap> p;
	if (animations_[i].frames_) {
	    for (int j=0; j<animations_[i].frames_; ++j) {
		QString s(animations_[i].path_);
		file_name = base + s.arg(j,4,10,QLatin1Char('0'));
		QPixmap pixmap(file_name);
		p.insert(j,pixmap);
	    }
	}
	else {
	    file_name = base + QString(animations_[i].path_);
	    QPixmap pixmap(file_name);
	    p.insert(0,pixmap);
	}

        QList<Frame> frameshape;
        for (int f = 0; f < p.size(); ++f) {
            QPixmap pixmap = p.at(f);
            Frame frame;
            frame.pixmap = pixmap;
            QPainterPath path;
            QBitmap m = pixmap.mask();
            if (m.width())
                path.addRegion(QRegion(m));
            else
                path.addRegion(QRect(pixmap.rect()));
            frame.shape = path;
            frame.boundingRect = path.controlPointRect();
            frameshape << frame;
        }
	shapemap_.insert(animations_[i].id_,frameshape);

        i++;
    }
    spritesLoaded_ = true;
}
void PixmapEditor::setValue(const QBitmap &aValue)
{
    mValue=QPixmap::fromImage(aValue.toImage());

    ui->valueEdit->setText(bitmapToString(aValue));
    setIcon(iconForPixmap(mValue));

    mDataType=BITMAP;
}
Exemple #9
0
void GLWidget::createCursors()
{
	QBitmap pic = QBitmap(":/zoomIn.png");
	if(pic.isNull())
	{
		ui.print("Warning: Null pic");
	}
	QBitmap mask = QBitmap(":/zoomIn-mask.png");
	if(mask.isNull())
	{
		ui.print("Warning: Null mask");
	}
	zoomInCursor = QCursor( pic, mask);  
	QBitmap pic2 = QBitmap(":/zoomOut.png");
	if(pic2.isNull())
	{
		ui.print("Warning: Null pic2");
	}
	zoomOutCursor = QCursor( pic2, mask);  
}
QRegion::QRegion( const QBitmap & bm )
{
    data = new QRegionData;
    Q_CHECK_PTR( data );
    data->hgt = 0;
    data->is_null = FALSE;
    if ( bm.isNull() )
        data->rgn = 0;
    else
	data->rgn = qt_pm_bitmapToRegion( bm );
}
void QPixmap::resize( int w, int h )
{
    if ( w < 1 || h < 1 ) {			// becomes null
	QPixmap pm( 0, 0, 0, data->bitmap, data->optim );
	*this = pm;
	return;
    }
    int d;
    if ( depth() > 0 )
	d = depth();
    else
	d = isQBitmap() ? 1 : -1;
    // Create new pixmap
    QPixmap pm( w, h, d, data->bitmap, data->optim );
#ifdef Q_WS_X11
    pm.x11SetScreen( x11Screen() );
#endif // Q_WS_X11
    if ( !data->uninit && !isNull() )		// has existing pixmap
	bitBlt( &pm, 0, 0, this, 0, 0,		// copy old pixmap
		QMIN(width(), w),
		QMIN(height(),h), CopyROP, TRUE );
#if defined(Q_WS_MAC)
    if(data->alphapm) {
	data->alphapm->resize(w, h);
    } else
#elif defined(Q_WS_X11) && !defined(QT_NO_XFTFREETYPE)
    if (data->alphapm)
	qWarning("QPixmap::resize: TODO: resize alpha data");
    else
#endif // Q_WS_X11
	if ( data->mask ) {				// resize mask as well
	    if ( data->selfmask ) {			// preserve self-mask
		pm.setMask( *((QBitmap*)&pm) );
	    } else {				// independent mask
		QBitmap m = *data->mask;
		m.resize( w, h );
		pm.setMask( m );
	    }
	}
    *this = pm;
}
Exemple #12
0
QPixmap BitmapFactoryInst::fillRect(int x, int y, int w, int h, const QPixmap& p, Qt::BGMode bgmode) const
{
    QBitmap b = p.mask();
    if (b.isNull())
        return p; // sorry, but cannot do anything

    QPixmap pix = p;

    // modify the mask
    QPainter pt;
    pt.begin(&b);
    if (bgmode == Qt::OpaqueMode)
        pt.fillRect(x, y, w, h, Qt::color1); // make opaque
    else // Qt::TransparentMode
        pt.fillRect(x, y, w, h, Qt::color0); // make transparent
    pt.end();

    pix.setMask(b);

    return pix;
}
Exemple #13
0
static PyObject *meth_QBitmap_clear(PyObject *sipSelf, PyObject *sipArgs)
{
    PyObject *sipParseErr = NULL;

    {
        QBitmap *sipCpp;

        if (sipParseArgs(&sipParseErr, sipArgs, "B", &sipSelf, sipType_QBitmap, &sipCpp))
        {
            sipCpp->clear();

            Py_INCREF(Py_None);
            return Py_None;
        }
    }

    /* Raise an exception if the arguments couldn't be parsed. */
    sipNoMethod(sipParseErr, sipName_QBitmap, sipName_clear, doc_QBitmap_clear);

    return NULL;
}
Exemple #14
0
void QCursor::setBitmap( const QBitmap &bitmap, const QBitmap &mask,
			 int hotX, int hotY )
{
    if ( !initialized )
	initialize();
    if ( bitmap.depth() != 1 || mask.depth() != 1 ||
	 bitmap.size() != mask.size() ) {
#if defined(QT_CHECK_NULL)
	qWarning( "QCursor: Cannot create bitmap cursor; invalid bitmap(s)" );
#endif
	QCursor *c = &cursorTable[arrowCursorIdx];
	c->data->ref();
	data = c->data;
	return;
    }
    data = new QCursorData;
    Q_CHECK_PTR( data );
    data->bm  = new QBitmap( bitmap );
    data->bmm = new QBitmap( mask );
    data->cshape = BitmapCursor;
    data->id = nextCursorId++;
    data->hx = hotX >= 0 ? hotX : bitmap.width()/2;
    data->hy = hotY >= 0 ? hotY : bitmap.height()/2;

    QPaintDevice::qwsDisplay()->defineCursor(data->id, *data->bm,
					    *data->bmm, data->hx, data->hy);
}
Exemple #15
0
void QCursor::setBitmap( const QBitmap &bitmap, const QBitmap &mask,
			 int hotX, int hotY )
{
    if ( !initialized )
	initialize();
    if ( bitmap.depth() != 1 || mask.depth() != 1 ||
	 bitmap.size() != mask.size() ) {
#if defined(QT_CHECK_NULL)
	qWarning( "QCursor: Cannot create bitmap cursor; invalid bitmap(s)" );
#endif
	QCursor *c = &cursorTable[arrowCursorIdx];
	c->data->ref();
	data = c->data;
	return;
    }
    data = new QCursorData;
    Q_CHECK_PTR( data );
    data->bm  = new QBitmap( bitmap );
    data->bmm = new QBitmap( mask );
    data->hcurs = 0;
    data->cshape = BitmapCursor;
    data->hx = hotX >= 0 ? hotX : bitmap.width()/2;
    data->hy = hotY >= 0 ? hotY : bitmap.height()/2;
    data->fg.red   = 0 << 8;
    data->fg.green = 0 << 8;
    data->fg.blue  = 0 << 8;
    data->bg.red   = 255 << 8;
    data->bg.green = 255 << 8;
    data->bg.blue  = 255 << 8;
    update(); // Xcursor's backward compatibility hack needs the cursor to be created
              // right after the bitmaps are created and filled with data
}
kpToolWidgetLineWidth::kpToolWidgetLineWidth (QWidget *parent, const char *name)
    : kpToolWidgetBase (parent, name)
{
    setInvertSelectedPixmap ();

    int numLineWidths = sizeof (lineWidths) / sizeof (lineWidths [0]);

    int w = (width () - 2/*margin*/) * 3 / 4;
    int h = (height () - 2/*margin*/ - (numLineWidths - 1)/*spacing*/) * 3 / (numLineWidths * 4);

    for (int i = 0; i < numLineWidths; i++)
    {
        QPixmap pixmap ((w <= 0 ? width () : w),
                        (h <= 0 ? height () : h));
        pixmap.fill (Qt::white);

        QBitmap maskBitmap (pixmap.width (), pixmap.height ());
        maskBitmap.fill (Qt::color0/*transparent*/);
        
        
        QPainter painter (&pixmap), maskPainter (&maskBitmap);
        painter.setPen (Qt::black), maskPainter.setPen (Qt::color1/*opaque*/);
        painter.setBrush (Qt::black), maskPainter.setBrush (Qt::color1/*opaque*/);

        QRect rect = QRect (0, (pixmap.height () - lineWidths [i]) / 2,
                            pixmap.width (), lineWidths [i]);
        painter.drawRect (rect), maskPainter.drawRect (rect);

        painter.end (), maskPainter.end ();
        
        
        pixmap.setMask (maskBitmap);

        addOption (pixmap, QString::number (lineWidths [i]));
        startNewOptionRow ();
    }

    finishConstruction (0, 0);
}
Exemple #17
0
//-------------------------------------------------------
void Terrain::createCrossCursor ()
{            
	//---------------------------------------------------
	// Define new cross cursor, more visible
	//---------------------------------------------------
/*		* B=1 and M=1 gives black.
		* B=0 and M=1 gives white.
		* B=0 and M=0 gives transparent.
		* B=1 and M=0 gives an XOR'd result.*/
	QBitmap *crossBits = new QBitmap(32,32);
	QBitmap *crossMask = new QBitmap(32,32);
	crossBits->clear();
 	crossMask->clear();
	QPainter pb (crossBits);
	QPainter pm (crossMask);
	QPen pen1(Qt::color1);
	pen1.setWidth(1);
	pb.setPen(pen1);
	pb.drawLine(6,16, 26,16);
	pb.drawLine(16,6, 16,26);
	pm.setPen(pen1);
	 // black
	pm.drawLine(6,16, 26,16);
	pm.drawLine(16,6, 16,26);
	// white
	pm.drawLine(6,15, 26,15);
	pm.drawLine(6,17, 26,17);
	
	pm.drawLine(15,6, 15,26);
	pm.drawLine(17,6, 17,26);
	
	pb.end();
	pm.end();
	myCrossCursor = QCursor(*crossBits, *crossMask);
    
    int v = 180;
    selectColor     = QColor(v,v,v);
    setCursor(myCrossCursor);
}
Exemple #18
0
QCursor KarbonCursor::horzMove()
{
/*
    #define horzMove_width 15
    #define horzMove_height 15
    static unsigned char horzMove_bits[] = {
        0x00, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x90, 0x04,
        0x98, 0x0c, 0xfc, 0x1f, 0x98, 0x0c, 0x90, 0x04, 0x80, 0x00, 0x80, 0x00,
        0x80, 0x00, 0x80, 0x00, 0x00, 0x00};
*/
    #define horzMove_width 15
    #define horzMove_height 15
    static unsigned char horzMove_bits[] = {
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08,
        0x0c, 0x18, 0xfe, 0x3f, 0x0c, 0x18, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

    QBitmap b = QBitmap::fromData( QSize(15, 15), horzMove_bits );
    QBitmap m = b.createHeuristicMask( false );

    return QCursor( b, m, 7, 7 );
}
Exemple #19
0
void QPixmap::setMask( const QBitmap &newmask )
{
    const QPixmap *tmp = &newmask;		// dec cxx bug
    if ( (data == tmp->data) ||
	 ( newmask.handle() && newmask.handle() == handle() ) ) {
	QPixmap m = tmp->copy( TRUE );
	setMask( *((QBitmap*)&m) );
	data->selfmask = TRUE;			// mask == pixmap
	return;
    }

    if ( newmask.isNull() ) {			// reset the mask
	if (data->mask) {
	    detach();
	    data->selfmask = FALSE;

	    delete data->mask;
	    data->mask = 0;
	}
	return;
    }

    detach();
    data->selfmask = FALSE;

    if ( newmask.width() != width() || newmask.height() != height() ) {
#if defined(QT_CHECK_RANGE)
	qWarning( "QPixmap::setMask: The pixmap and the mask must have "
		  "the same size" );
#endif
	return;
    }
#if defined(Q_WS_MAC) || (defined(Q_WS_X11) && !defined(QT_NO_XFTFREETYPE))
    // when setting the mask, we get rid of the alpha channel completely
    delete data->alphapm;
    data->alphapm = 0;
#endif // Q_WS_X11 && !QT_NO_XFTFREETYPE

    delete data->mask;
    QBitmap* newmaskcopy;
    if ( newmask.mask() )
	newmaskcopy = (QBitmap*)new QPixmap( tmp->copy( TRUE ) );
    else
	newmaskcopy = new QBitmap( newmask );
#ifdef Q_WS_X11
    newmaskcopy->x11SetScreen( x11Screen() );
#endif
    data->mask = newmaskcopy;
}
Exemple #20
0
HICON QPixmap::toWinHICON() const
{
    QBitmap maskBitmap = mask();
    if (maskBitmap.isNull()) {
        maskBitmap= QBitmap(size());
        maskBitmap.fill(Qt::color1);
    }

    ICONINFO ii;
    ii.fIcon    = true;
    ii.hbmMask  = qt_createIconMask(maskBitmap);
    ii.hbmColor = toWinHBITMAP(QPixmap::Alpha);
    ii.xHotspot = 0;
    ii.yHotspot = 0;

    HICON hIcon = CreateIconIndirect(&ii);

    DeleteObject(ii.hbmColor);
    DeleteObject(ii.hbmMask);

    return hIcon;
}
Exemple #21
0
HBITMAP qt_createIconMask(const QBitmap &bitmap)
{
    QImage bm = bitmap.toImage().convertToFormat(QImage::Format_Mono);
    int w = bm.width();
    int h = bm.height();
    int bpl = ((w+15)/16)*2;                        // bpl, 16 bit alignment
    uchar *bits = new uchar[bpl*h];
    bm.invertPixels();
    for (int y=0; y<h; y++)
        memcpy(bits+y*bpl, bm.scanLine(y), bpl);
    HBITMAP hbm = CreateBitmap(w, h, 1, 1, bits);
    delete [] bits;
    return hbm;
}
Exemple #22
0
KDEFX_EXPORT void kColorBitmaps(QPainter *p, const QColorGroup &g, int x, int y, int w,
                   int h, bool isXBitmaps, const uchar *lightColor,
                   const uchar *midColor, const uchar *midlightColor,
                   const uchar *darkColor, const uchar *blackColor,
                   const uchar *whiteColor)
{
    const uchar *data[]={lightColor, midColor, midlightColor, darkColor,
        blackColor, whiteColor};

    QColor colors[]={g.light(), g.mid(), g.midlight(), g.dark(),
        Qt::black, Qt::white};

    int i;
    QBitmap b;
    for(i=0; i < 6; ++i){
        if(data[i]){
            b = QBitmap(w, h, data[i], isXBitmaps);
            b.setMask(b);
            p->setPen(colors[i]);
            p->drawPixmap(x, y, b);
        }
    }
}
//!
//! Constructor of the ParameterTypeIcon class.
//!
//! \param color The color for the parameter type icon.
//!
ParameterTypeIcon::ParameterTypeIcon ( const QColor &color )
{
    m_color = color;

    const QRect pinRect (0, 4, 15, 8);
    const QColor penColor (109, 109, 109);
    QPixmap normalPixmap (16, 16);
    QPainter painter;
    if (painter.begin(&normalPixmap)) {
        // get the background color from the application style's standard palette
        QColor backgroundColor = QApplication::style()->standardPalette().color(QPalette::Base);
        // fill the pixmap with the background color
        painter.fillRect(normalPixmap.rect(), QBrush(backgroundColor));
        // draw the pin rect into the pixmap
        painter.setPen(QPen(penColor));
        painter.setBrush(QBrush(m_color));
        painter.drawRoundRect(pinRect);
        // end painting the pixmap
        if (painter.end()) {
            // create a bitmap for masking the pixmap
            QBitmap maskBitmap (normalPixmap.size());
            if (painter.begin(&maskBitmap)) {
                // fill the bitmap with white (meaning transparent)
                painter.fillRect(maskBitmap.rect(), QBrush(QColor(Qt::white)));
                // draw the pin rect as black (meaning opaque)
                painter.setPen(QPen(QColor(Qt::black)));
                painter.setBrush(QBrush(QColor(Qt::black)));
                painter.drawRoundRect(pinRect);
                // end painting the bitmap and set it as mask for the pixmap
                if (painter.end())
                    normalPixmap.setMask(maskBitmap);
            }
        }
    }
    // add the pixmap to the icon
    addPixmap(normalPixmap);
}
Exemple #24
0
//-----------------------------------------------------------------------------
bool KBusyPtr :: loadBitmap (QBitmap& bm, const QString& filename)
{
  QString f;
  bool rc;

  if (filename[0]=='/' || filename[0]=='.')
  {
    f = filename;
  }
  else 
  {
    f = app->kde_datadir().copy();
    f += "/kmail/pics/";
    f += filename;
  }
  rc = bm.load(f);
  if (!rc) printf ("ERROR: cannot load bitmap %s\n", f.data());
  return rc;
}
Exemple #25
0
QBitmap basicSegmentation::xand(QBitmap am, QBitmap bm) {
  int x, y, ap, bp;
  QImage a = am.toImage();
  QImage b = bm.toImage();
  QImage r = QImage(am.width(), am.height(), QImage::Format_Mono);
  for(x=0; x < am.width(); x++) {
    for(y=0;y < am.height(); y++) {
 	  ap=qRed(a.pixel(x,y));
 	  bp=qRed(b.pixel(x,y));
	  if(ap == 0 && bp == 0){  		  	
	  	r.setPixel(x, y, Qt::color0);
  	  } else {
  	  	r.setPixel(x, y, Qt::color1);
 	  } 
    }
  }
  return(QBitmap::fromImage(r));
}
Exemple #26
0
QBitmap basicSegmentation::erode(QBitmap mm, int count) {
  int x, y, p, p1, p2, p3, p4, n;
  QImage m = mm.toImage();
  p=qRed(m.pixel(1,1));
  for(n=0; n < count; n++) {  	
    QImage gm = QImage(m.width(), m.height(), QImage::Format_Mono);
    for(x=0; x < m.width(); x++) {
      gm.setPixel(x, 0, Qt::color1);	
      gm.setPixel(x, m.width()-1, Qt::color1);	
    }
    for(y=1;y < (m.height()-1); y++) {
      gm.setPixel(0, y, Qt::color1);	
      gm.setPixel(m.height()-1, y, Qt::color1);	
    }
    for(x=1; x < (m.width()-1); x++) {
      for(y=1;y < (m.height()-1); y++) {
  		p=qRed(m.pixel(x,y));
	    if(p == 0){  		  	
  		  p1 = qRed(m.pixel(x-1, y));
  		  p2 = qRed(m.pixel(x+1, y));
  		  p3 = qRed(m.pixel(x, y-1));
  		  p4 = qRed(m.pixel(x, y+1));
  		  if(p1 == 255 || p2 == 255 || p3 == 255 || p4 == 255) {
	  	     gm.setPixel(x,y, Qt::color1);  			      	
 		  } else {
	  	     gm.setPixel(x,y, Qt::color0);  			      
	   	  }  
 		 } else {
	  	   gm.setPixel(x,y, Qt::color1);  			       		    	
	     }
        }
      }
     m = gm;
  }
  return(QBitmap::fromImage(m));
}
QBitmap QPixmap::createHeuristicMask( bool clipTight ) const
{
    QBitmap m;
    m.convertFromImage( convertToImage().createHeuristicMask(clipTight) );
    return m;
}
Exemple #28
0
void OSDWidget::renderOSDText( const QString &txt )
{
                                                  // Escaped text
    QString text = Konversation::removeIrcMarkup(txt);

    static QBitmap mask;

    //This is various spacings and margins, based on the font to look "just right"
    const uint METRIC = fontMetrics().width( 'x' );

    // Set a sensible maximum size, don't cover the whole desktop or cross the screen
    QSize max = QApplication::desktop()->screen( m_screen )->size() - QSize( MARGIN*2 + METRIC*2, 100 );
    QFont titleFont( "Arial", 12, QFont::Bold );
    QFontMetrics titleFm( titleFont );

    // The title cannnot be taller than one line
    // AlignAuto = align Arabic to the right, etc.
    QRect titleRect = titleFm.boundingRect( 0, 0, max.width() - METRIC, titleFm.height(), AlignAuto, m_appName );
    // The osd cannot be larger than the screen
    QRect textRect = fontMetrics().boundingRect( 0, 0, max.width(), max.height(), AlignAuto | WordBreak, text );

    if ( textRect.width() < titleRect.width() )
        textRect.setWidth( titleRect.width() );

    //this should still be within the screen bounds
    textRect.addCoords( 0, 0, METRIC*2, titleRect.height() + METRIC );

    osdBuffer.resize( textRect.size() );
    mask.resize( textRect.size() );

    // Start painting!
    QPainter bufferPainter( &osdBuffer );
    QPainter maskPainter( &mask );

    // Draw backing rectangle
    const uint xround = (METRIC * 200) / textRect.width();
    const uint yround = (METRIC * 200) / textRect.height();

    bufferPainter.setPen( Qt::black );
    bufferPainter.setBrush( backgroundColor() );
    bufferPainter.drawRoundRect( textRect, xround, yround );
    bufferPainter.setFont( font() );

    const uint w = textRect.width()  - 1;
    const uint h = textRect.height() - 1;

    // Draw the text shadow
    if ( m_shadow )
    {
        bufferPainter.setPen( backgroundColor().dark( 175 ) );
        bufferPainter.drawText( METRIC + 3, (METRIC/2) + titleFm.height() + 1, w, h, AlignLeft | WordBreak, text );
    }

    // Draw the text
    bufferPainter.setPen( foregroundColor() );
    bufferPainter.drawText( METRIC, (METRIC/2) + titleFm.height() - 1, w, h, AlignLeft | WordBreak, text );

    // Draw the title text
    bufferPainter.setFont( titleFont );
    bufferPainter.drawText( METRIC * 2, (METRIC/2), w, h, AlignLeft, m_appName );

    // Masking for transparency
    mask.fill( Qt::black );
    maskPainter.setBrush( Qt::white );
    maskPainter.drawRoundRect( textRect, xround, yround );
    setMask( mask );

    //do last to reduce noticeable change when showing multiple OSDs in succession
    reposition( textRect.size() );

    m_currentText = text;
    m_dirty = false;

    update();
}
Exemple #29
0
QIntMatrix basicSegmentation::find(QBitmap mask, int minsize)
{
  int y, x, a, l, t, eqI, eqTI, eqV, w, h, eqMaxI=1, newID = 2;
  bool done;
  QIntMatrix r(mask.width(), mask.height());
  QImage im = mask.toImage();
  QVector<int> u, eq, counts;
  w = mask.width();
  h = mask.height();
     
  for(y = 0; y < h; y++) {
    for(x = 0; x < w; x++) {
      a = qRed(im.pixel(x, y));
      if(a == 0) {
        r.set(x, y, 1);      	
      } else {
      	r.set(x, y, 0);
      }
    }
  }


  eq =  QVector<int>(2);
  counts =  QVector<int>(2);
  for(y = 1; y < (h - 1); y++) {
    for(x = 1; x < (w - 1); x++) {
      a = r.at(x, y-1);
      l = r.at(x-1, y);
      t = r.at(x, y);
      if (t == 1) {
        if (a == l && a > 1) {
          r.set(x, y, a);
          if(a > (counts.size()-1)) {
          	counts.resize(a+1);
          }
          counts[a]++;
        } else if (a != l && a > 1 && l > 1) {
          r.set(x, y, mathmin(a, l));
          if(mathmin(a, l) > (counts.size()-1)) {
          	counts.resize(mathmin(a, l)+1);
          }
          counts[mathmin(a, l)]++;
          eqI = mathmax(a,l);
          eqV = mathmin(a,l);
          done = false;
          while (!done) {
            if (eqI > eqMaxI) {
              eq.resize(eqI+1);
              eqMaxI = eqI;
            }
            if ((eq.at(eqI) > 1)) {
              if (eqV != eq.at(eqI)) {
                eqTI = eqI;
                eqI = mathmax(eqV, eq.at(eqTI));
                eqV = mathmin(eqV, eq.at(eqTI));
                eq[eqTI] = eqV;
              } else {
                eq[eqI] = eqV;
                done = true;
              }
            } else {
              eq[eqI] = eqV;
              done = true;
            }
          }
        } else if (mathmax(a,l) > 1) {
            r.set(x, y, mathmax(a, l)); 
            if(mathmax(a, l) > (counts.size()-1)) {
            	counts.resize(mathmax(a, l)+1);
            }
            counts[mathmax(a, l)]++;
        } else  {
           r.set(x, y, newID++);
           counts.resize(newID+1);
           counts[newID]=1;
        }
      } else {
      	 r.set(x, y, 0);
      }
    }
  }

  //clean up edges 

  r.replace(1, 0);

  //resolve equivalent ids

  
  if(eqMaxI > 1) 
  {
    resolveEq(&r, eq, counts, minsize);
  }

   return(r);
}
Exemple #30
-1
QCursor KarbonCursor::needleArrow()
{
    static const unsigned char needle_bits[] = {
        0x00, 0x00, 0x10, 0x00, 0x20, 0x00, 0x60, 0x00, 0xc0, 0x00, 0xc0, 0x01,
        0x80, 0x03, 0x80, 0x07, 0x00, 0x0f, 0x00, 0x1f, 0x00, 0x3e, 0x00, 0x7e,
        0x00, 0x7c, 0x00, 0x1c, 0x00, 0x18, 0x00, 0x00
    };

    QBitmap b = QBitmap::fromData(QSize(16, 16), needle_bits);
    QBitmap m = b.createHeuristicMask(false);

    return QCursor(b, m, 2, 0);
}