示例#1
0
void Slider::setNewMask ()
{
  QBitmap bm(size());
  bm.fill(Qt::color0);

  QBitmap bm_sld(slider->size());
  QPixmap pm = QPixmap::grabWidget(slider);
  bm_sld = pm.createHeuristicMask();

  QPainter painter;
  QBitmap bm_val,bm_min,bm_max;
  bm_val = drawValue();
  bm_min = drawMinValue();
  bm_max = drawMaxValue();

  painter.begin(&bm);
  painter.drawPixmap(slider->x(),slider->y(),bm_sld);
  if (orientation == 0) painter.drawPixmap(0,0,bm_val);
    else if (orientation == 1) painter.drawPixmap(width()/2+10,0,bm_val);
  if (orientation == 0) painter.drawPixmap(0,height()/2+10,bm_min);
    else if (orientation == 1) painter.drawPixmap(0,0,bm_min);
  if (orientation == 0) painter.drawPixmap(width()/2,height()/2+10,bm_max);
    else if (orientation == 1) painter.drawPixmap(0,height()/2,bm_max);
  painter.end();

  setMask(bm);
}
示例#2
0
文件: UnitSync.cpp 项目: ObKo/HoSpLo
QList<QIcon> CUnitSync::getModSideIcons(const QString& name) const
{
    int index = Mods.indexOf(name);
    if(index < 0)
        return QList<QIcon>();

    QList<QIcon> list;

    m_AddAllArchives(m_GetPrimaryModArchive(index));
    int sideCount = m_GetSideCount();

    for(int j = 0; j < sideCount; j++)
    {
        int F = m_OpenFileVFS(QString("SidePics/%1.bmp").arg(QString(m_GetSideName(j))).toAscii().data());
        if(F)
        {
            qint64 size = m_FileSizeVFS(F);
            char *data = new char[size];
            m_ReadFileVFS(F, data, size);
            QPixmap pixmap;
            pixmap.loadFromData((uchar *)data, size, "BMP");
            pixmap.setMask(pixmap.createHeuristicMask());
            delete data;
            list.append(QIcon(pixmap));
            m_CloseFileVFS(F);
        }
        else
            list.append(QIcon(":/icons/unknown.png"));
    }

    return list;
}
示例#3
0
QPixmap * RazorDeskIconBase::initialPainting(QIcon::Mode mode)
{
    qDebug() << "RazorDeskIconBase::initialPainting";
    
    if (icon().isNull())
    {
        qDebug() << "RazorDeskIconBase::setPos - icon() is null. Skipping for now.";
        return 0;
    }
    
    QPixmap * pm = new QPixmap(70, 70);
    pm->fill(QColor(0,0,0,0));

    QPainter painter(pm);
    painter.setRenderHint(QPainter::Antialiasing);
    painter.setRenderHint(QPainter::HighQualityAntialiasing);
    painter.setRenderHint(QPainter::NonCosmeticDefaultPen);
    
    // now the icon
    QPixmap appIcon = icon().pixmap(iconSize(), mode);
    // HACK: in some cases we can get larger icon than expected so rescale
    //       it with brute force if it's required...
    if (appIcon.size().width() > iconSize().width())
        appIcon = appIcon.scaled(iconSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation);

    QRect source(0, 0, 32, 32);
    int w = pm->width() / 2;
    int h = pm->height() / 2;
    int iw = iconSize().width() / 2;
    int ih = iconSize().height() / 2;
    QRect target(w - iw, h - ih - 10,
                 iconSize().width(), iconSize().height());
    painter.drawPixmap(target, appIcon, source);

    // text now - it has to follow potential QSS
    QColor txt = palette().color(QPalette::WindowText);
    painter.setPen(txt);
    painter.setBrush(palette().color(QPalette::Window));
    painter.drawText(QRectF(2, h+ih-10, pm->width()-4, pm->height()-h-ih+10),
                     Qt::AlignCenter | Qt::TextWordWrap | Qt::TextIncludeTrailingSpaces | Qt::TextDontClip,
                     text());
    painter.end();

    pm->setMask(pm->createHeuristicMask());
    setMask(pm->mask());
    
    return pm;
}
示例#4
0
void QWidgetPrivate::setWindowIcon_sys(bool /*forceReset*/)
{
#if 0
     QTLWExtra* x = d->topData();
     delete x->icon;
     x->icon = 0;
    QBitmap mask;
    if (unscaledPixmap.isNull()) {
    } else {
        QImage unscaledIcon = unscaledPixmap.toImage();
        QPixmap pixmap =
            QPixmap::fromImage(unscaledIcon.scale(16, 16, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
        x->icon = new QPixmap(pixmap);
        mask = pixmap.mask() ? *pixmap.mask() : pixmap.createHeuristicMask();
    }
#endif
}
示例#5
0
QPixmap NetworkSetup::devicePixmap( void ) {
    QPixmap pm = NSResources->getPixmap(
            getToplevel()->nextNode()->pixmapName()+"-large");

    QPixmap Mini = NSResources->getPixmap(
            device()->netNode()->pixmapName() );

    if( pm.isNull() || Mini.isNull() )
	return Resource::loadPixmap("Unknown");

    QPainter painter( &pm );
    painter.drawPixmap( pm.width()-Mini.width(),
                        pm.height()-Mini.height(),
                        Mini );
    pm.setMask( pm.createHeuristicMask( TRUE ) );
    return pm;
}
示例#6
0
QPixmap HostListItem::generateGradient( int type )
{
  QPixmap temp;
  
  if( type == PixRight )
    temp = QPixmap( locate( "data", "amarok/images/nmm-gradient-right.png" ) );
  else // PixLeft
    temp = QPixmap( locate( "data", "amarok/images/nmm-gradient-left.png" ) );
  const QBitmap mask( temp.createHeuristicMask() );

  KPixmap result = QPixmap( 113, 24 );
  if( type == PixRight)
    KPixmapEffect::gradient( result, listView()->colorGroup().background(), listView()->colorGroup().highlight(), KPixmapEffect::HorizontalGradient );
  else
    KPixmapEffect::gradient( result, listView()->colorGroup().highlight(), listView()->colorGroup().background(), KPixmapEffect::HorizontalGradient );

  result.setMask( mask);
  return result;
}
示例#7
0
void QWidget::setIcon( const QPixmap &unscaledPixmap )
{
    if ( extra && extra->topextra ) {
	delete extra->topextra->icon;
	extra->topextra->icon = 0;
    } else {
	createTLExtra();
    }
    QBitmap mask;
    if ( unscaledPixmap.isNull() ) {
    } else {
	QImage unscaledIcon = unscaledPixmap.convertToImage();
	QPixmap pixmap;
#ifndef QT_NO_IMAGE_SMOOTHSCALE
	pixmap.convertFromImage( unscaledIcon.smoothScale( 16, 16 ) );
#else
	pixmap.convertFromImage( unscaledIcon );
#endif
	extra->topextra->icon = new QPixmap( pixmap );
	mask = pixmap.mask() ? *pixmap.mask() : pixmap.createHeuristicMask();
    }
    // XXX
}
示例#8
0
SoundSlider::SoundSlider( QWidget *_parent, float _i_step,
                          char *psz_colors, int max )
                        : QAbstractSlider( _parent )
{
    qreal scalingFactorX = static_cast<qreal>(logicalDpiX()) / DPI_REF_VALUE;
    qreal scalingFactorY = static_cast<qreal>(logicalDpiY()) / DPI_REF_VALUE;

    wlength = WLENGTH_BASE * scalingFactorX;
    wheight = WHEIGHT_BASE * scalingFactorY;

    f_step = (float)(_i_step * 10000)
           / (float)((max - SOUNDMIN) * AOUT_VOLUME_DEFAULT);
    setRange( SOUNDMIN, max);
    setMouseTracking( true );
    isSliding = false;
    b_mouseOutside = true;
    b_isMuted = false;

    const QPixmap pixOutsideRaw(Helper::getIconPath("volume-slider-outside.png"));
    const QSize pixOutsideSize(
                static_cast<qreal>(pixOutsideRaw.width()) * scalingFactorX,
                static_cast<qreal>(pixOutsideRaw.height()) * scalingFactorY
            );
    pixOutside = pixOutsideRaw.scaled(pixOutsideSize);

    const QPixmap tempRaw(Helper::getIconPath("volume-slider-inside.png"));
    const QSize tempSize(
                    static_cast<qreal>(tempRaw.width()) * scalingFactorX,
                    static_cast<qreal>(tempRaw.height()) * scalingFactorY
            );
    const QPixmap temp = tempRaw.scaled(tempSize);

    const QBitmap mask( temp.createHeuristicMask() );

    setFixedSize( pixOutside.size() );

    pixGradient = QPixmap( mask.size() );
    pixGradient2 = QPixmap( mask.size() );

    /* Gradient building from the preferences */
    QLinearGradient gradient( paddingL, 2, wlength + paddingL , 2 );
    QLinearGradient gradient2( paddingL, 2, wlength + paddingL , 2 );

    QStringList colorList = qfu( psz_colors ).split( ";" );
    free( psz_colors );

    /* Fill with 255 if the list is too short */
    if( colorList.count() < 12 )
        for( int i = colorList.count(); i < 12; i++)
            colorList.append( "255" );

    background = palette().color( QPalette::Active, QPalette::Window );
    foreground = palette().color( QPalette::Active, QPalette::WindowText );
    foreground.setHsv( foreground.hue(),
                    ( background.saturation() + foreground.saturation() ) / 2,
                    ( background.value() + foreground.value() ) / 2 );

    textfont.setPointSize( 9 );
    textrect.setRect( 0, 0, 34.0*scalingFactorX, 15.0*scalingFactorY );

    /* Regular colors */
#define c(i) colorList.at(i).toInt()
#define add_color(gradient, range, c1, c2, c3) \
    gradient.setColorAt( range, QColor( c(c1), c(c2), c(c3) ) );

    /* Desaturated colors */
#define desaturate(c) c->setHsvF( c->hueF(), 0.2 , 0.5, 1.0 )
#define add_desaturated_color(gradient, range, c1, c2, c3) \
    foo = new QColor( c(c1), c(c2), c(c3) );\
    desaturate( foo ); gradient.setColorAt( range, *foo );\
    delete foo;

    /* combine the two helpers */
#define add_colors( gradient1, gradient2, range, c1, c2, c3 )\
    add_color( gradient1, range, c1, c2, c3 ); \
    add_desaturated_color( gradient2, range, c1, c2, c3 );

    float f_mid_point = ( 100.0 / maximum() );
    QColor * foo;
    add_colors( gradient, gradient2, 0.0, 0, 1, 2 );
    if (f_mid_point + 0.05 <= 1.0) {
        add_colors( gradient, gradient2, f_mid_point - 0.05, 3, 4, 5 );
        add_colors( gradient, gradient2, f_mid_point + 0.05, 6, 7, 8 );
    }
    add_colors( gradient, gradient2, 1.0, 9, 10, 11 );

    painter.begin( &pixGradient );
    painter.setPen( Qt::NoPen );
    painter.setBrush( gradient );
    painter.drawRect( pixGradient.rect() );
    painter.end();

    painter.begin( &pixGradient2 );
    painter.setPen( Qt::NoPen );
    painter.setBrush( gradient2 );
    painter.drawRect( pixGradient2.rect() );
    painter.end();

    pixGradient.setMask( mask );
    pixGradient2.setMask( mask );
}
示例#9
0
SoundSlider::SoundSlider( QWidget *_parent, int _i_step, bool b_hard,
                          char *psz_colors )
                        : QAbstractSlider( _parent )
{
    f_step = ( _i_step * 100 ) / AOUT_VOLUME_MAX ;
    setRange( SOUNDMIN, b_hard ? (2 * SOUNDMAX) : SOUNDMAX  );
    setMouseTracking( true );
    isSliding = false;
    b_mouseOutside = true;
    b_isMuted = false;

    pixOutside = QPixmap( ":/toolbar/volslide-outside" );

    const QPixmap temp( ":/toolbar/volslide-inside" );
    const QBitmap mask( temp.createHeuristicMask() );

    setFixedSize( pixOutside.size() );

    pixGradient = QPixmap( mask.size() );
    pixGradient2 = QPixmap( mask.size() );

    /* Gradient building from the preferences */
    QLinearGradient gradient( paddingL, 2, WLENGTH + paddingL , 2 );
    QLinearGradient gradient2( paddingL, 2, WLENGTH + paddingL , 2 );

    QStringList colorList = qfu( psz_colors ).split( ";" );
    free( psz_colors );

    /* Fill with 255 if the list is too short */
    if( colorList.count() < 12 )
        for( int i = colorList.count(); i < 12; i++)
            colorList.append( "255" );

    background = palette().color( QPalette::Active, QPalette::Background );
    foreground = palette().color( QPalette::Active, QPalette::WindowText );
    foreground.setHsv( foreground.hue(),
                    ( background.saturation() + foreground.saturation() ) / 2,
                    ( background.value() + foreground.value() ) / 2 );

    textfont.setPixelSize( 9 );
    textrect.setRect( 0, 0, 34, 15 );

    /* Regular colors */
#define c(i) colorList.at(i).toInt()
#define add_color(gradient, range, c1, c2, c3) \
    gradient.setColorAt( range, QColor( c(c1), c(c2), c(c3) ) );

    /* Desaturated colors */
#define desaturate(c) c->setHsvF( c->hueF(), 0.2 , 0.5, 1.0 )
#define add_desaturated_color(gradient, range, c1, c2, c3) \
    foo = new QColor( c(c1), c(c2), c(c3) );\
    desaturate( foo ); gradient.setColorAt( range, *foo );\
    delete foo;

    /* combine the two helpers */
#define add_colors( gradient1, gradient2, range, c1, c2, c3 )\
    add_color( gradient1, range, c1, c2, c3 ); \
    add_desaturated_color( gradient2, range, c1, c2, c3 );

    float f_mid_point = ( 100.0 / maximum() );
    QColor * foo;
    add_colors( gradient, gradient2, 0.0, 0, 1, 2 );
    add_colors( gradient, gradient2, f_mid_point - 0.05, 3, 4, 5 );
    add_colors( gradient, gradient2, f_mid_point + 0.05, 6, 7, 8 );
    add_colors( gradient, gradient2, 1.0, 9, 10, 11 );

    painter.begin( &pixGradient );
    painter.setPen( Qt::NoPen );
    painter.setBrush( gradient );
    painter.drawRect( pixGradient.rect() );
    painter.end();

    painter.begin( &pixGradient2 );
    painter.setPen( Qt::NoPen );
    painter.setBrush( gradient2 );
    painter.drawRect( pixGradient2.rect() );
    painter.end();

    pixGradient.setMask( mask );
    pixGradient2.setMask( mask );
}
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
** $QT_END_LICENSE$
**
****************************************************************************/

//! [0]
static const char * const start_xpm[]={
    "16 15 8 1",
    "a c #cec6bd",
....
//! [0]


//! [1]
QPixmap myPixmap;
myPixmap->setMask(myPixmap->createHeuristicMask());
//! [1]

//! [2]
QPixmap pixmap("background.png");
QRegion exposed;
pixmap.scroll(10, 10, pixmap.rect(), &exposed);
//! [2]
示例#11
0
void KIconEditGrid::createCursors()
{
  KIconLoader *loader = kapp->getIconLoader();
  QBitmap bmp, mask(22, 22);
  QPixmap pix;

  cursor_normal = QCursor(arrowCursor);

  pix = loader->loadIcon("paintbrush.xpm");
  if(pix.isNull())
  {
    cursor_paint = cursor_normal;
    debug("KIconEditGrid: Error loading pixmap: paintbrush.xpm"); 
  }
  else
  {
    mask = pix.createHeuristicMask();
    bmp = pix;
    cursor_paint = QCursor(bmp, mask, 6, 18);
  }

  pix = loader->loadIcon("flood.xpm");
  if(pix.isNull())
  {
    cursor_flood = cursor_normal;
    debug("KIconEditGrid: Error loading pixmap: flood.xpm"); 
  }
  else
  {
    mask = pix.createHeuristicMask();
    bmp = pix;
    cursor_flood = QCursor(bmp, mask, 5, 16);
  }

  pix = loader->loadIcon("aim.xpm");
  if(pix.isNull())
  {
    cursor_aim = cursor_normal;
    debug("KIconEditGrid: Error loading pixmap: aim.xpm"); 
  }
  else
  {
    mask = pix.createHeuristicMask();
    bmp = pix;
    cursor_aim = QCursor(bmp, mask);
  }

  pix = loader->loadIcon("spraycan.xpm");
  if(pix.isNull())
  {
    cursor_spray = cursor_normal;
    debug("KIconEditGrid: Error loading pixmap: aim.xpm"); 
  }
  else
  {
    mask = pix.createHeuristicMask(true);
    bmp = pix;
    cursor_spray = QCursor(bmp, mask);
  }

  pix = loader->loadIcon("eraser.xpm");
  if(pix.isNull())
  {
    cursor_erase = cursor_normal;
    debug("KIconEditGrid: Error loading pixmap: aim.xpm"); 
  }
  else
  {
    mask = pix.createHeuristicMask(true);
    bmp = pix;
    cursor_erase = QCursor(bmp, mask, 5, 16);
  }
}
示例#12
0
void KniftyClient::update_captionBuffer()
{
    if (!KniftyHandler::initialized()) return;

    const uint maxCaptionLength = 300; // truncate captions longer than this!
    QString captionText(caption() );
    if (captionText.length() > maxCaptionLength) {
        captionText.truncate(maxCaptionLength);
        captionText.append(" [...]");
    }

    QFontMetrics fm(s_titleFont);
    int captionWidth  = fm.width(captionText);

    QPixmap textPixmap;
    QPainter painter;
    if(KniftyHandler::titleShadow())
    {
        // prepare the shadow
        textPixmap = QPixmap(captionWidth+2*2, s_titleHeight ); // 2*2 px shadow space
        textPixmap.fill(QColor(0,0,0));
        textPixmap.setMask( textPixmap.createHeuristicMask(TRUE) );
        painter.begin(&textPixmap);
        painter.setFont(s_titleFont);
        painter.setPen(white);
        painter.drawText(textPixmap.rect(), AlignCenter, captionText );
        painter.end();
    }

    QImage shadow;
    ShadowEngine se;

    // active
    aCaptionBuffer->resize(captionWidth+4, s_titleHeight ); // 4 px shadow
    painter.begin(aCaptionBuffer);
    painter.drawTiledPixmap(aCaptionBuffer->rect(), *aTitleBarTile);
    if(KniftyHandler::titleShadow())
    {
        shadow = se.makeShadow(textPixmap, QColor(0, 0, 0));
        painter.drawImage(1, 1, shadow);
    }
    painter.setFont(s_titleFont);
    painter.setPen(options()->color(KDecoration::ColorFont, true));
    painter.drawText(aCaptionBuffer->rect(), AlignCenter, captionText );
    painter.end();


    // inactive
    iCaptionBuffer->resize(captionWidth+4, s_titleHeight );
    painter.begin(iCaptionBuffer);
    painter.drawTiledPixmap(iCaptionBuffer->rect(), *iTitleBarTile);
    if(KniftyHandler::titleShadow())
    {
        painter.drawImage(1, 1, shadow);
    }
    painter.setFont(s_titleFont);
    painter.setPen(options()->color(KDecoration::ColorFont, false));
    painter.drawText(iCaptionBuffer->rect(), AlignCenter, captionText );
    painter.end();

    captionBufferDirty = false;
}