当前位置: 首页>>代码示例>>C++>>正文


C++ QPixmap::scaled方法代码示例

本文整理汇总了C++中QPixmap::scaled方法的典型用法代码示例。如果您正苦于以下问题:C++ QPixmap::scaled方法的具体用法?C++ QPixmap::scaled怎么用?C++ QPixmap::scaled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QPixmap的用法示例。


在下文中一共展示了QPixmap::scaled方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: initialize

void MenuEquipmentScreen::initialize(BattleCharacterItem *character, Inventory *inventory) {
	QFont font("Times", 12, QFont::Bold);
	QBrush brush(Qt::white);
	_state = EQUIPPED_SELECTION;

	// Set character and inventory
	_character = character;
	_inventory = inventory;

	// Set the character's equipment
	QPointF position(_equippedEquipmentItem->pos().x(), _equippedEquipmentItem->pos().y() + 40);

	QStringList equipmentHeaders;
	equipmentHeaders << "Main Hand: " << "Off Hand: "
		<< "Helmet: " << "Torso: " << "Leggings: " << "Gloves: " << "Boots: "
		<< "Earring: " << "Necklace: " << "Ring: ";
	QVector<EquipmentPiece*> equipment = _character->getEquipment()->getEquipment();
	_currentEquippedEquipmentPiece = equipment.at(0);
	_equippedEquipmentItem->setText("Equipment of " + _character->getName());

	for (int i = 0; i < equipment.size(); i++) {
		QString itemText;
		itemText.append(equipmentHeaders.at(i));
		
		if (!!equipment.at(i))
			itemText.append(equipment.at(i)->getName());

		QGraphicsSimpleTextItem *item = new QGraphicsSimpleTextItem(this);
		item->setText(itemText);
		item->setBrush(brush);
		item->setFont(font);
		item->setPos(position);

		_equippedEquipmentItems.append(item);
		position.setY(position.y() + 20);
	}

	setCurrentEquippedItem(_equippedEquipmentItems.at(0), equipment.at(0));

	// Set Image
	if (_character->getCharacter()->getBattleImage().second != QString()) {
		QPixmap battlerImage = _character->getCharacter()->getBattleImage().first;

		if ((battlerImage.width() > _characterImage->boundingRect().width()) || (battlerImage.height() > _characterImage->boundingRect().height()))
			battlerImage = battlerImage.scaled(QSize(200, 200), Qt::KeepAspectRatio);
		
		QPixmap frame(200, 200);
		frame.fill(Qt::transparent);
		QPainter painter(&frame);
		painter.setCompositionMode(QPainter::CompositionMode_SourceOver);

		QPoint position(0, 0);
		position.setX(frame.width()/2 - battlerImage.width()/2);
		position.setY(frame.height()/2 - battlerImage.height()/2);
		painter.drawPixmap(position, battlerImage);
		painter.end();

		_characterImage->setPixmap(frame);
		
	} else {
		QPixmap image(200, 200);
		image.fill(Qt::transparent);
		_characterImage->setPixmap(image);
	}
}
开发者ID:juniordiscart,项目名称:RPGMaker,代码行数:65,代码来源:MenuEquipmentScreen.cpp

示例2: CreateScreenshot

void MediaSourceDesktop::CreateScreenshot()
{
    AVFrame             *tRGBFrame;

    mMutexGrabberActive.lock();

    if (!mMediaSourceOpened)
    {
    	mMutexGrabberActive.unlock();
    	return;
    }

    if (mWidget == NULL)
    {
    	LOG(LOG_ERROR, "Capture widget is invalid");
    	mMutexGrabberActive.unlock();
    	return;
    }

    QTime tCurrentTime = QTime::currentTime();
    int tTimeDiff = mLastTimeGrabbed.msecsTo(tCurrentTime);

    //### skip capturing when we are too slow
    if (tTimeDiff < 1000 / (mFrameRate + 0.5 /* some tolerance! */))
    {
        #ifdef MSD_DEBUG_PACKETS
            LOG(LOG_VERBOSE, "Screen capturing skipped because system is too fast");
        #endif
		mMutexGrabberActive.unlock();
    	return;
    }

    if (mLastTimeGrabbed == QTime(0, 0, 0, 0))
    {
        mLastTimeGrabbed = tCurrentTime;
        mMutexGrabberActive.unlock();
        return;
    }else
        mLastTimeGrabbed = tCurrentTime;

    //### skip capturing when we are too slow
    if (tTimeDiff > 1000 / MIN_GRABBING_FPS)
    {
    	LOG(LOG_WARN, "Screen capturing skipped because system is too busy");
    	mMutexGrabberActive.unlock();
    	return;
    }

    //####################################################################
    //### do the grabbing and scaling stuff
    //####################################################################
    QPixmap tSourcePixmap;
    // screen capturing
	#ifdef APPLE
		CGImageRef tOSXWindowImage = CGWindowListCreateImage(CGRectInfinite, kCGWindowListOptionOnScreenOnly, mWidget->winId(), kCGWindowImageDefault);
		tSourcePixmap = QPixmap::fromMacCGImageRef(tOSXWindowImage).copy(mGrabOffsetX, mGrabOffsetY, mSourceResX, mSourceResY);
		CGImageRelease(tOSXWindowImage);
	#else
		tSourcePixmap = QPixmap::grabWindow(mWidget->winId(), mGrabOffsetX, mGrabOffsetY, mSourceResX, mSourceResY);
	#endif

    if(!tSourcePixmap.isNull())
    {
		// record screenshot via ffmpeg
		if (mRecording)
		{
			if ((tRGBFrame = AllocFrame()) == NULL)
			{
				LOG(LOG_ERROR, "Unable to allocate memory for RGB frame");
			}else
			{
				QImage tSourceImage = QImage((unsigned char*)mOriginalScreenshot, mSourceResX, mSourceResY, QImage::Format_RGB32);
				QPainter *tSourcePainter = new QPainter(&tSourceImage);
				tSourcePainter->drawPixmap(0, 0, tSourcePixmap);
				delete tSourcePainter;

				// Assign appropriate parts of buffer to image planes in tRGBFrame
				FillFrame(tRGBFrame, mOriginalScreenshot, PIX_FMT_RGB32, mSourceResX, mSourceResY);

				// set frame number in corresponding entries within AVFrame structure
				tRGBFrame->pts = mRecorderChunkNumber;
				tRGBFrame->coded_picture_number = mRecorderChunkNumber;
				tRGBFrame->display_picture_number = mRecorderChunkNumber;
                mRecorderChunkNumber++;

				// emulate set FPS
				tRGBFrame->pts = FpsEmulationGetPts();

				// re-encode the frame and write it to file
				RecordFrame(tRGBFrame);
			}
		}

		// get the scaled version of the capture screen segment
		QPixmap tTargetPixmap = tSourcePixmap.scaled(mTargetResX, mTargetResY);

		// lock screenshot buffer
		mMutexScreenshot.lock();
		QImage tTargetImage = QImage((unsigned char*)mOutputScreenshot, mTargetResX, mTargetResY, QImage::Format_RGB32);
		QPainter *tTargetPainter = new QPainter(&tTargetImage);
//.........这里部分代码省略.........
开发者ID:IcedLolly,项目名称:Homer-Conferencing,代码行数:101,代码来源:MediaSourceDesktop.cpp

示例3: bgChange

void Scene::bgChange()
{
    //A && D
    A = new Btn;
    QPixmap a;
    a.load(":/image/image/A.png");
    a = a.scaled(150,150);
    A->setPixmap(a);
    A->setPos(180,280);
    addItem(A);

    D = new Btn;
    QPixmap d;
    d.load(":/image/image/D.png");
    d = d.scaled(170,170);
    D->setPixmap(d);
    D->setPos(270,270);
    addItem(D);

    /*connect*/
    dis = 0;
    /*change background*/
    QImage bg;
    bg.load(":/image/image/7658225_656869.jpg");
    bg = bg.scaled(610,410);
    this->setBackgroundBrush(bg);

    /*remove button*/
    this->removeItem(btn_start);
    this->removeItem(btn_exit);

    /*rail picture setting*/
    rail = new Rail();
    QPixmap rl;
    rl.load(":/image/image/panel.png");
    rl = rl.scaled(610,100);
    rail->setPixmap(rl);
    rail->setPos(0,170);
    addItem(rail);

    /*matong pic setting*/
    matong = new Rail();
    QPixmap mt;
    mt.load(":/image/image/toilet-toilet-bowl_small.png");
    mt = mt.scaled(300,300);
    matong->setPixmap(mt);
    matong->setPos(-100,35);
    addItem(matong);

    /*back button setting*/
    btn_back = new Btn();
    QPixmap bk;
    bk.load(":/image/image/go.png");
    bk = bk.scaled(90,90);
    btn_back->setPixmap(bk);
    btn_back->setPos(0,5);
    btn_back_w = 80;
    btn_back_h = 85;
    addItem(btn_back);

    /*labi*/
    labi = new Rail();
    QPixmap lb;
    lb.load(":/image/image/0.gif");
    lb = lb.scaled(250,250);
    labi->setPixmap(lb);
    labi->setPos(450,40);
    addItem(labi);

    /*Score*/
    score1 = new Score();
    score1->setPos(420,35);
    addItem(score1);

    /*time count*/
    mytime = new myTimer();
    mytime->setPos(200,35);
    addItem(mytime);



}
开发者ID:F74045042,项目名称:pd2-Taiko,代码行数:82,代码来源:scene.cpp

示例4: slotThumbnailFromInterface

void KipiImageModel::slotThumbnailFromInterface(const KUrl& url, const QPixmap& pixmap)
{
    kDebug()<<url<<pixmap.size();
    if (pixmap.isNull())
        return;

    const int effectiveSize = qMax(pixmap.size().width(), pixmap.size().height());

    // find the item corresponding to the URL:
    const QModelIndex imageIndex = indexFromUrl(url);
    kDebug()<<url<<imageIndex.isValid();
    if (imageIndex.isValid())
    {
        // this is tricky: some kipi interfaces return pixmaps at the requested size, others do not.
        // therefore we check whether a pixmap of this size has been requested. If so, we send it on.
        // If a pixmap of this size has not been requested, we rescale it to fulfill all other requests.

        // index, size
        QList<QPair<int, int> > openRequests;
        for (int i=0; i<d->requestedPixmaps.count(); ++i)
        {
            if (d->requestedPixmaps.at(i).first==imageIndex)
            {
                const int requestedSize = d->requestedPixmaps.at(i).second;
                if (requestedSize==effectiveSize)
                {
                    // match, send it out.
                    d->requestedPixmaps.removeAt(i);
                    kDebug()<<i;

                    // save the pixmap:
                    const QString itemKeyString = CacheKeyFromSizeAndUrl(effectiveSize, url);
                    d->pixmapCache->insert(itemKeyString, pixmap);

                    emit(signalThumbnailForIndexAvailable(imageIndex, pixmap));
                    return;
                }
                else
                {
                    openRequests << QPair<int, int>(i, requestedSize);
                }
            }
        }

        // the pixmap was not requested at this size, fulfill all requests:
        for (int i=openRequests.count()-1; i>=0; --i)
        {
            const int targetSize = openRequests.at(i).second;
            d->requestedPixmaps.removeAt(openRequests.at(i).first);
            kDebug()<<i<<targetSize;

            QPixmap scaledPixmap = pixmap.scaled(targetSize, targetSize, Qt::KeepAspectRatio);

            // save the pixmap:
            const QString itemKeyString = CacheKeyFromSizeAndUrl(targetSize, url);
            d->pixmapCache->insert(itemKeyString, scaledPixmap);

            emit(signalThumbnailForIndexAvailable(imageIndex, scaledPixmap));
        }
        
    }
}
开发者ID:NathanDM,项目名称:kipi-plugins,代码行数:62,代码来源:kipiimagemodel.cpp

示例5: setImageFileName

void ImageFileNameBrowserWidget::setImageFileName(const QString& s) {
    _displayW->setText(s);
    QPixmap p;
    p.load(QFileInfo(_defaultPath, s).absoluteFilePath());
    _previewW->setPixmap(p.scaled(QSize(300, 300), Qt::KeepAspectRatio));
}
开发者ID:BackupTheBerlios,项目名称:profilelogger-svn,代码行数:6,代码来源:ImageFileNameBrowserWidget.cpp

示例6: waves

SeaScene::SeaScene(QObject *parent) :
    QGraphicsScene(parent)
{

    setItemPointersNull();

    paused_ = false;
    screenLitKeeper_.keepScreenLit(true);

    QSettings settings;

    //set background

    QPixmap waves (":/pix/meri.png");
    waves.scaled(20,20);
    setBackgroundBrush(QBrush(waves));

    //set random seed

    qsrand(QTime::currentTime().msec()+2);  //+2 to avoid setting it to 1



//Setup level sets

    QList<Level> levelList;
    Level level1(5,10);
    levelList.append(level1);
    Level level2(5,10,2,50);
    levelList.append(level2);
    Level level3(5,15,2,50);
    levelList.append(level3);
    Level level4(5,15,4,50);
    levelList.append(level4);
    Level level5(5,15,5,100);
    levelList.append(level5);

    Levelset set ("Original",levelList);
    availableLevelsets_.append(set);


    //Create another set of levels and place it in the available levelsets list
    levelList.clear();
    Level set2level1(8,15,4,50);
    levelList.append(set2level1);
    Level set2level2(8,20,4,50);
    levelList.append(set2level2);
    Level set2level3(8,20,5,80);
    levelList.append(set2level3);
    Level set2level4(8,20,6,120);
    levelList.append(set2level4);
    Level set2level5(8,25,8,150);
    levelList.append(set2level5);

    Levelset set2("Difficult",levelList);
    availableLevelsets_.append(set2);


    //Setup starting levelset

    QString levelname = settings.value("levelset","Original").toString();
    bool found = false;
    foreach (Levelset levelset, availableLevelsets_)
    {
        if (levelset.getName() == levelname)
        {
            levelset_ = levelset;
            found = true;
            break;
        }
    }

    if (!found)  //The last used level is not available
    {
        levelset_ = availableLevelsets_.value(0);
    }

    currentLevel_ = 0;

    totalScore_ = 0;



    connect(this,SIGNAL(allGhostsPicked()),this,SLOT(nextLevel()));

    pVibrateAction_ = new QAction(tr("Vibration effects"),this);
    pVibrateAction_->setCheckable(true);
    connect(pVibrateAction_,SIGNAL(toggled(bool)),this,SLOT(vibrationActivate(bool)));

    pVibrateAction_->setChecked(settings.value("vibration",false).toBool());


    pPauseAction_ = new QAction(tr("Pause"),this);
    pPauseAction_->setCheckable(true);
    connect(pPauseAction_,SIGNAL(toggled(bool)),this,SLOT(pause(bool)));


    deviceLockPollTimer_.setInterval(20*60);
    connect(&deviceLockPollTimer_,SIGNAL(timeout()),this,SLOT(pollDeviceLocked()));
    deviceLockPollTimer_.start();
//.........这里部分代码省略.........
开发者ID:helihyv,项目名称:Ghosts-Overboard,代码行数:101,代码来源:seascene.cpp

示例7: handleLogoDownloaded

/********************************************************************************************************
 * SLOTs for Logo Download
 *******************************************************************************************************
 */
void IRNowPlayingView::handleLogoDownloaded(IRQPreset* aPreset)
{
    LOG_METHOD;
    if( EIdle == iLogoDownloadState )
    {        
        return;
    } 
            
    if( NULL == aPreset )
    {        
        if( EDownloadLogo == iLogoDownloadState )
        {         
            iLogoNeedUpdate = false;  
#ifdef ADV_ENABLED
            QTimer::singleShot(1, this, SLOT(updateAdvImage()));
#endif            
        }
#ifdef ADV_ENABLED      
        else if( EDownLoadAdvImage == iLogoDownloadState )
        {
            iAdvImageNeedUpdate = false;            
        }
#endif
        iLogoDownloadState = EIdle;      
        return;
    }
    
 
    
    QPixmap logoPixmap;
    if( logoPixmap.loadFromData((const unsigned char*)aPreset->logoData.constData(), aPreset->logoData.size()) )
    {
        if( EDownloadLogo == iLogoDownloadState )
        {		
            saveStationLogo(logoPixmap);
            QPixmap newLogoPixmap = 
                 logoPixmap.scaled(QSize(KNowPlayingLogoSize,KNowPlayingLogoSize),Qt::KeepAspectRatio);
            QIcon logoQIcon(newLogoPixmap);
            HbIcon logoHbIcon(logoQIcon);
            iStationLogo->setIcon(logoHbIcon);
            iPlayController->emitStationLogoUpdated(true);
            iLogoNeedUpdate = false;          
            getViewManager()->saveScreenShot();
#ifdef ADV_ENABLED
            QTimer::singleShot(1, this, SLOT(updateAdvImage()));
#endif
        }
#ifdef ADV_ENABLED      
        else if( EDownLoadAdvImage == iLogoDownloadState )
        {
            QIcon logoQIcon(logoPixmap);
            HbIcon logoHbIcon(logoQIcon);            
            iAdvImage->setIcon(logoHbIcon); 
            iAdvUrl = iPlayController->getNowPlayingPreset()->advertisementUrl;  
            iAdvImageNeedUpdate = false;            
        }
#endif
    }
    else
    {
        if( EDownloadLogo == iLogoDownloadState )
        {         
            iLogoNeedUpdate = false;  
#ifdef ADV_ENABLED
            QTimer::singleShot(1, this, SLOT(updateAdvImage()));
#endif            
        }
#ifdef ADV_ENABLED      
        else if( EDownLoadAdvImage == iLogoDownloadState )
        {
            iAdvImageNeedUpdate = false;            
        }
#endif        
    }

    iLogoDownloadState = EIdle;      
    
    delete aPreset;
    aPreset = NULL;
}
开发者ID:cdaffara,项目名称:symbiandump-ossapps,代码行数:84,代码来源:irnowplayingview.cpp

示例8: showEvent

void MainWindow::showEvent(QShowEvent *)
{
    if(check==1){
        for(int i=0;i<itemList.size();++i){

        }
        itemList.clear();
        scene->removeItem(restart);
        scene->removeItem(exit);
        scene->addItem(birdtmp);
        scene->addItem(tool);
        itemList.clear();
        //bird,obticle,target
        birdNumber=0;
        ScreenMode=0;
        checkBird23=0;
        target1->hit=0;
//        qDebug()<<x<<" hit=0 "<<y<<endl;
    }
    if(playtimes==0){
        // Timer
        connect(&timer,SIGNAL(timeout()),this,SLOT(birdHit()));
        connect(&timer,SIGNAL(timeout()),this,SLOT(tick()));
        connect(this,SIGNAL(quitGame()),this,SLOT(QUITSLOT()));
        timer.start(100/6);
    }
// Setting the QGraphicsScene
    scene = new QGraphicsScene(0,0,width(),ui->graphicsView->height());
    ui->graphicsView->setScene(scene);
    QImage bg;
    bg.load(":/img/bg.jpg");
    bg=bg.scaled(960,540);
    ui->graphicsView->scene()->setBackgroundBrush(bg);
    //bg-bird
    birdtmp=new QGraphicsPixmapItem();
    QPixmap bir;
    bir.load(":/img/bird1.png");
    bir=bir.scaled(50,50);
    birdtmp->setPixmap(bir);
    birdtmp->setPos(205,360);
    ui->graphicsView->scene()->addItem(birdtmp);
    //bg-tool
    tool=new QGraphicsPixmapItem();
    QPixmap tol;
    tol.load(":/img/tool.png");
    tol=tol.scaled(50,70);
    tool->setPixmap(tol);
    tool->setPos(210,380);
    ui->graphicsView->scene()->addItem(tool);
    //score
    score=new Score();
    this->scene->addItem(score);
    //dot
    for(int i=0;i<15;++i){
        dots[i]=new QGraphicsPixmapItem();
        scene->addItem(dots[i]);
    }
    // Create world
    world = new b2World(b2Vec2(0.0f, -9.8f));

    // Setting Size
    GameItem::setGlobalSize(QSizeF(32,18),size());
//    qDebug()<<size().width()<<" "<<size().height()<<endl;
    // Create ground (You can edit here)

    land1=new Land(3,1.5,5,3,QPixmap(":/img/GROUND.png").scaled(225,height()/6.0),world,scene);
    itemList.push_back(land1);
    land2=new Land(25,1.5,20,3,QPixmap(":/img/GROUND.png").scaled(600,height()/6.0),world,scene);
    itemList.push_back(land2);

    //create target
    target1=new Target(20.2f,6.4f,0.1f,&timer,QPixmap(":/img/target1.png").scaled(40,40),world,scene);
    itemList.push_back(target1);

    target2=new Target(26.0f,5.8f,0.1f,&timer,QPixmap(":/img/target1.png").scaled(40,40),world,scene);
    itemList.push_back(target1);

    target3=new Target(22.0f,5.0f,0.1f,&timer,QPixmap(":/img/target2.png").scaled(40,40),world,scene);
    itemList.push_back(target1);

    target4=new Target(29.0f,5.0f,0.1f,&timer,QPixmap(":/img/target2.png").scaled(40,40),world,scene);
    itemList.push_back(target1);

    //create obticle
    createobticle();

}
开发者ID:vonchuang,项目名称:pd2-Angrybird,代码行数:87,代码来源:mainwindow.cpp

示例9: setCurrentIcon

void weatherwidget::setCurrentIcon(QString icon)
{
    // set icon for current weather conditions
    if (icon == "partlysunny" || icon == "mostlycloudy" ) {
        if(clock->hour() < 5 || clock->hour() > 20) {
            QPixmap *partlyMoony = new QPixmap(":Images/weather-moony-few-clouds.png");
            *partlyMoony = partlyMoony->scaled(72, 72, Qt::KeepAspectRatio);
            currentIcon->setPixmap(*partlyMoony);
        } else {
            QPixmap *partlySunny = new QPixmap(":Images/weather-few-clouds.png");
            *partlySunny = partlySunny->scaled(72,72,Qt::KeepAspectRatio);
            currentIcon->setPixmap(*partlySunny);
        }
    }
    else if (icon == "fog") {
        QPixmap *fog = new QPixmap(":Images/weather-fog.png");
        *fog = fog->scaled(72,72,Qt::KeepAspectRatio);
        currentIcon->setPixmap(*fog);
    }
    else if (icon == "hazy") {
        if(clock->hour() < 5 || clock->hour() > 20) {
            QPixmap *hazeyMoony = new QPixmap(":Images/weather-moony.png");
            *hazeyMoony = hazeyMoony->scaled(72, 72, Qt::KeepAspectRatio);
            currentIcon->setPixmap(*hazeyMoony);
        } else {
            QPixmap *haze = new QPixmap(":Images/weather-haze.png");
            *haze = haze->scaled(72,72,Qt::KeepAspectRatio);
            currentIcon->setPixmap(*haze);
        }
    }
    else if (icon == "cloudy") {
        QPixmap *cloudy = new QPixmap(":Images/weather-overcast.png");
        *cloudy = cloudy->scaled(72,72,Qt::KeepAspectRatio);
        currentIcon->setPixmap(*cloudy);
    }
    else if (icon == "rain" || icon == "chancerain") {
        QPixmap *showers = new QPixmap(":Images/weather-showers.png");
        *showers = showers->scaled(72,72,Qt::KeepAspectRatio);
        currentIcon->setPixmap(*showers);
    }
    else if (icon == "sleet" || icon == "chancesleet") {
        QPixmap *sleet = new QPixmap(":Images/weather-sleet.png");
        *sleet = sleet->scaled(72,72,Qt::KeepAspectRatio);
        currentIcon->setPixmap(*sleet);
    }
    else if (icon == "flurries" || icon == "snow" ||
              icon == "chanceflurries" || icon == "chancesnow") {
        QPixmap *snow = new QPixmap(":Images/weather-snow.png");
        *snow = snow->scaled(72,72,Qt::KeepAspectRatio);
        currentIcon->setPixmap(*snow);
    }
    else if (icon == "clear" || icon == "sunny") {
        if(clock->hour() < 5 || clock->hour() > 20) {
            QPixmap *moony = new QPixmap(":Images/weather-moony.png");
            *moony = moony->scaled(72, 72, Qt::KeepAspectRatio);
            currentIcon->setPixmap(*moony);
        } else {
            QPixmap *sunny = new QPixmap(":Images/weather-sunny.png");
            *sunny = sunny->scaled(72,72,Qt::KeepAspectRatio);
            currentIcon->setPixmap(*sunny);
        }
    }
    else if (icon == "mostlysunny" || icon == "partlycloudy" ||
             icon == "unknown") {
        if(clock->hour() < 5 || clock->hour() > 20) {
            QPixmap *partlyCloudy = new QPixmap(":Images/weather-moony-very-few-clouds");
            *partlyCloudy = partlyCloudy->scaled(72, 72, Qt::KeepAspectRatio);
            currentIcon->setPixmap(*partlyCloudy);
        } else {
            QPixmap *partlyCloudy = new QPixmap(":Images/weather-sunny-very-few-clouds.png");
            *partlyCloudy = partlyCloudy->scaled(72,72,Qt::KeepAspectRatio);
            currentIcon->setPixmap(*partlyCloudy);
        }
    }
    else if (icon == "tstorms" || icon == "chancetstorms") {
        QPixmap *thundershower = new QPixmap(":Images/weather-thundershower.png");
        *thundershower = thundershower->scaled(72,72,Qt::KeepAspectRatio);
        currentIcon->setPixmap(*thundershower);
    }


}
开发者ID:darwinbeing,项目名称:Hifi-Pod,代码行数:82,代码来源:weatherwidget.cpp

示例10: col

// titleAddText needs to be const char* for tr()
NetworkStyle::NetworkStyle(const QString &_appName, const int iconColorHueShift, const int iconColorSaturationReduction, const char *_titleAddText):
    appName(_appName),
    titleAddText(qApp->translate("SplashScreen", _titleAddText))
{
    // load pixmap
    QPixmap pixmap;
    if (std::char_traits<char>::length(_titleAddText) == 0) {
        pixmap.load(":/icons/bitcoin");
    } else {
        pixmap.load(":/icons/shillingcoin_splash");
    }

    if(iconColorHueShift != 0 && iconColorSaturationReduction != 0)
    {
        // generate QImage from QPixmap
        QImage img = pixmap.toImage();

        int h,s,l,a;

        // traverse though lines
        for(int y=0;y<img.height();y++)
        {
            QRgb *scL = reinterpret_cast< QRgb *>( img.scanLine( y ) );

            // loop through pixels
            for(int x=0;x<img.width();x++)
            {
                // preserve alpha because QColor::getHsl doesn't return the alpha value
                a = qAlpha(scL[x]);
                QColor col(scL[x]);

                // get hue value
                col.getHsl(&h,&s,&l);

                // rotate color on RGB color circle
                // 70° should end up with the typical "testnet" green
                h+=iconColorHueShift;

                // change saturation value
                if(s>iconColorSaturationReduction)
                {
                    s -= iconColorSaturationReduction;
                }
                col.setHsl(h,s,l,a);

                // set the pixel
                scL[x] = col.rgba();
            }
        }

        //convert back to QPixmap
#if QT_VERSION >= 0x040700
        pixmap.convertFromImage(img);
#else
        pixmap = QPixmap::fromImage(img);
#endif
    }

    appIcon             = QIcon(pixmap);
    trayAndWindowIcon   = QIcon(pixmap.scaled(QSize(256,256)));
}
开发者ID:yavwa,项目名称:Shilling,代码行数:62,代码来源:networkstyle.cpp

示例11: paint

void ProductDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
                         const QModelIndex &index) const
{
    //painting background when selected...
    //QPalette::ColorGroup cg = option.state & QStyle::State_Enabled
    //    ? QPalette::Normal : QPalette::Disabled;

    //Painting frame
    painter->setRenderHint(QPainter::Antialiasing);
    QString pixName = KStandardDirs::locate("appdata", "images/itemBox.png");
    painter->drawPixmap(option.rect.x()+5,option.rect.y()+5, QPixmap(pixName));

    //get item data
    const QAbstractItemModel *model = index.model();
    int row = index.row();
    QModelIndex nameIndex = model->index(row, 1);
    QString name = model->data(nameIndex, Qt::DisplayRole).toString();
    QByteArray pixData = model->data(index, Qt::DisplayRole).toByteArray();
    nameIndex = model->index(row, 3);
    double stockqty = model->data(nameIndex, Qt::DisplayRole).toDouble();
    nameIndex = model->index(row, 0);
    QString strCode = "# " + model->data(nameIndex, Qt::DisplayRole).toString();

    //preparing photo to paint it...
    QPixmap pix;
    if (!pixData.isEmpty() or !pixData.isNull()) {
      pix.loadFromData(pixData);
    }
    else {
      pix = QPixmap(DesktopIcon("lemon-box", 64));
    }
    int max = 128;
    if ((pix.height() > max) || (pix.width() > max) ) {
      if (pix.height() == pix.width()) {
        pix = pix.scaled(QSize(max, max));
      }
      else if (pix.height() > pix.width() ) {
        pix = pix.scaledToHeight(max);
      }
      else  {
        pix = pix.scaledToWidth(max);
      }
    }
    int x = option.rect.x() + (option.rect.width()/2) - (pix.width()/2);
    int y = option.rect.y() + (option.rect.height()/2) - (pix.height()/2) - 10;
    //painting photo
    if (!pix.isNull()) painter->drawPixmap(x,y, pix);

    //Painting name
    QFont font = QFont("Trebuchet MS", 10);
    font.setBold(true);
    //getting name size in pixels...
    QFontMetrics fm(font);
    int strSize = fm.width(name);
    int aproxPerChar = fm.width("A");
    QString nameToDisplay = name;
    int boxSize = option.rect.width()-15; //minus margin and frame-lines
    if (strSize > boxSize) {
      int excess = strSize-boxSize;
      int charEx = (excess/aproxPerChar)+2;
      nameToDisplay = name.left(name.length()-charEx-7) +"...";
      //qDebug()<<"Text does not fit, strSize="<<strSize<<" boxSize:"
      //<<boxSize<<" excess="<<excess<<" charEx="<<charEx<<"nameToDisplay="<<nameToDisplay;
    }
    painter->setFont(font);
    if (option.state & QStyle::State_Selected) {
      painter->setPen(Qt::yellow);
      painter->drawText(option.rect.x()+10,option.rect.y()+145, 150,20,  Qt::AlignCenter, nameToDisplay);
    }
    else {
      painter->setPen(Qt::white);
      painter->drawText(option.rect.x()+10,option.rect.y()+145, 150,20,  Qt::AlignCenter, nameToDisplay);
    }

    //painting stock Availability
    if (stockqty <= 0) {
      font = QFont("Trebuchet MS", 12);
      font.setBold(true);
      font.setItalic(true);
      painter->setFont(font);
      painter->setBackgroundMode(Qt::OpaqueMode);
      painter->setPen(Qt::red);
      painter->setBackground(QColor(255,225,0,160));
      QString naStr = i18n(" Out of stock ");
      painter->drawText(option.rect.x()+10,
                      option.rect.y()+(option.rect.height()/2)-10,
                      150, 20, Qt::AlignCenter, naStr);
      painter->setBackgroundMode(Qt::TransparentMode);
    }
    
    //painting code number
    font = QFont("Trebuchet MS", 9);
    font.setBold(false);
    font.setItalic(true);
    painter->setFont(font);
    painter->setBackgroundMode(Qt::TransparentMode);
    painter->setPen(Qt::white);
    painter->setBackground(QColor(255,225,0,160));
    painter->drawText(option.rect.x()+10,
                      option.rect.y()+5,
//.........这里部分代码省略.........
开发者ID:adlh,项目名称:lemonpos,代码行数:101,代码来源:productdelegate.cpp

示例12: decorationForVariant

QVariant Util::decorationForVariant(const QVariant &value)
{
  switch (value.type()) {
  case QVariant::Brush:
  {
    const QBrush b = value.value<QBrush>();
    if (b.style() != Qt::NoBrush) {
      QPixmap p(16, 16);
      p.fill(QColor(0, 0, 0, 0));
      QPainter painter(&p);
      painter.setBrush(b);
      painter.drawRect(0, 0, p.width() - 1, p.height() - 1);
      return p;
    }
  }
  case QVariant::Color:
  {
    const QColor c = value.value<QColor>();
    if (c.isValid()) {
      QPixmap p(16, 16);
      QPainter painter(&p);
      painter.setBrush(QBrush(c));
      painter.drawRect(0, 0, p.width() - 1, p.height() - 1);
      return p;
    }
  }
  case QVariant::Cursor:
  {
    const QCursor c = value.value<QCursor>();
    if (!c.pixmap().isNull()) {
      return c.pixmap().scaled(16, 16, Qt::KeepAspectRatio, Qt::FastTransformation);
    }
  }
  case QVariant::Icon:
  {
    return value;
  }
  case QVariant::Pen:
  {
    const QPen pen = value.value<QPen>();
    if (pen.style() != Qt::NoPen) {
      QPixmap p(16, 16);
      p.fill(QColor(0, 0, 0, 0));
      QPainter painter(&p);
      painter.setPen(pen);
      painter.translate(0, 8 - pen.width() / 2);
      painter.drawLine(0, 0, p.width(), 0);
      return p;
    }
  }
  case QVariant::Pixmap:
  {
    const QPixmap p = value.value<QPixmap>();
    if(!p.isNull()) {
      return QVariant::fromValue(p.scaled(16, 16, Qt::KeepAspectRatio, Qt::FastTransformation));
    }
  }
  default: break;
  }

  return QVariant();
}
开发者ID:jcfr,项目名称:GammaRay,代码行数:62,代码来源:util.cpp

示例13: pix

ToolButton*
Gui::findOrCreateToolButton(const PluginGroupNodePtr & treeNode)
{

    // Do not create an action for non user creatable plug-ins
    bool isUserCreatable = true;
    PluginPtr internalPlugin = treeNode->getPlugin();
    if (internalPlugin && treeNode->getChildren().empty() && !internalPlugin->getIsUserCreatable()) {
        isUserCreatable = false;
    }
    if (!isUserCreatable) {
        return 0;
    }

    // Check for existing toolbuttons
    for (std::size_t i = 0; i < _imp->_toolButtons.size(); ++i) {
        if (_imp->_toolButtons[i]->getPluginToolButton() == treeNode) {
            return _imp->_toolButtons[i];
        }
    }

    // Check for parent toolbutton
    ToolButton* parentToolButton = NULL;
    if ( treeNode->getParent() ) {
        assert(treeNode->getParent() != treeNode);
        if (treeNode->getParent() != treeNode) {
            parentToolButton = findOrCreateToolButton( treeNode->getParent() );
        }
    }

    QString resourcesPath;
    if (internalPlugin) {
        resourcesPath = QString::fromUtf8(internalPlugin->getProperty<std::string>(kNatronPluginPropResourcesPath).c_str());
    }
    QString iconFilePath = resourcesPath;
    StrUtils::ensureLastPathSeparator(iconFilePath);
    iconFilePath += treeNode->getTreeNodeIconFilePath();

    QIcon toolButtonIcon, menuIcon;
    // Create tool icon
    if ( !iconFilePath.isEmpty() && QFile::exists(iconFilePath) ) {
        QPixmap pix(iconFilePath);
        int menuSize = TO_DPIX(NATRON_MEDIUM_BUTTON_ICON_SIZE);
        int toolButtonSize = !treeNode->getParent() ? TO_DPIX(NATRON_TOOL_BUTTON_ICON_SIZE) : TO_DPIX(NATRON_MEDIUM_BUTTON_ICON_SIZE);
        QPixmap menuPix = pix, toolbuttonPix = pix;
        if ( (std::max( menuPix.width(), menuPix.height() ) != menuSize) && !menuPix.isNull() ) {
            menuPix = menuPix.scaled(menuSize, menuSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
        }
        if ( (std::max( toolbuttonPix.width(), toolbuttonPix.height() ) != toolButtonSize) && !toolbuttonPix.isNull() ) {
            toolbuttonPix = toolbuttonPix.scaled(toolButtonSize, toolButtonSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
        }
        menuIcon.addPixmap(menuPix);
        toolButtonIcon.addPixmap(toolbuttonPix);
    } else {
        // Set default icon only if it has no parent, otherwise leave action without an icon
        if ( !treeNode->getParent() ) {
            QPixmap toolbuttonPix, menuPix;
            getPixmapForGrouping( &toolbuttonPix, TO_DPIX(NATRON_TOOL_BUTTON_ICON_SIZE), treeNode->getTreeNodeName() );
            toolButtonIcon.addPixmap(toolbuttonPix);
            getPixmapForGrouping( &menuPix, TO_DPIX(NATRON_TOOL_BUTTON_ICON_SIZE), treeNode->getTreeNodeName() );
            menuIcon.addPixmap(menuPix);
        }
    }

    // If the tool-button has no children, this is a leaf, we must create an action
    // At this point any plug-in MUST be in a toolbutton, so it must have a parent.
    assert(!treeNode->getChildren().empty() || treeNode->getParent());

    int majorVersion = internalPlugin ? internalPlugin->getProperty<unsigned int>(kNatronPluginPropVersion, 0) : 1;
    int minorVersion = internalPlugin ? internalPlugin->getProperty<unsigned int>(kNatronPluginPropVersion, 1) : 0;

    ToolButton* pluginsToolButton = new ToolButton(getApp(),
                                                   treeNode,
                                                   treeNode->getTreeNodeID(),
                                                   majorVersion,
                                                   minorVersion,
                                                   treeNode->getTreeNodeName(),
                                                   toolButtonIcon,
                                                   menuIcon);

    if (!treeNode->getChildren().empty()) {
        // For grouping items, create the menu
        Menu* menu = new Menu(this);
        menu->setTitle( pluginsToolButton->getLabel() );
        menu->setIcon(menuIcon);
        pluginsToolButton->setMenu(menu);
        pluginsToolButton->setAction( menu->menuAction() );
    } else {
        // This is a leaf (plug-in)
        assert(internalPlugin);
        assert(parentToolButton);

        // If this is the highest major version for this plug-in use normal label, otherwise also append the major version
        bool isHighestMajorVersionForPlugin = internalPlugin->getIsHighestMajorVersion();

        std::string pluginLabel = !isHighestMajorVersionForPlugin ? internalPlugin->getLabelVersionMajorEncoded() : internalPlugin->getLabelWithoutSuffix();

        QKeySequence defaultNodeShortcut;
        QString shortcutGroup = QString::fromUtf8(kShortcutGroupNodes);
        std::vector<std::string> groupingSplit = internalPlugin->getPropertyN<std::string>(kNatronPluginPropGrouping);
//.........这里部分代码省略.........
开发者ID:azerupi,项目名称:Natron,代码行数:101,代码来源:Gui20.cpp

示例14: updateInfo

void UserInfoBox::updateInfo(const ServerInfo_User &user)
{
    const UserLevelFlags userLevel(user.user_level());
    
    QPixmap avatarPixmap;
    const std::string bmp = user.avatar_bmp();
    if (!avatarPixmap.loadFromData((const uchar *) bmp.data(), bmp.size()))
        avatarPixmap = UserLevelPixmapGenerator::generatePixmap(64, userLevel, false);
    avatarLabel.setPixmap(avatarPixmap.scaled(avatarLabel.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
    
    nameLabel.setText(QString::fromStdString(user.name()));
    realNameLabel2.setText(QString::fromStdString(user.real_name()));
    genderLabel2.setPixmap(GenderPixmapGenerator::generatePixmap(15, user.gender()));
    QString country = QString::fromStdString(user.country());

    if (country.length() != 0)
    {
        countryLabel2.setPixmap(CountryPixmapGenerator::generatePixmap(15, country));
        countryLabel3.setText(QString("(%1)").arg(country.toUpper()));
    }
    else
    {
        countryLabel2.setText("");
        countryLabel3.setText("");
    }
	
    userLevelLabel2.setPixmap(UserLevelPixmapGenerator::generatePixmap(15, userLevel, false));
    QString userLevelText;
    if (userLevel.testFlag(ServerInfo_User::IsAdmin))
        userLevelText = tr("Administrator");
    else if (userLevel.testFlag(ServerInfo_User::IsModerator))
        userLevelText = tr("Moderator");
    else if (userLevel.testFlag(ServerInfo_User::IsRegistered))
        userLevelText = tr("Registered user");
    else
        userLevelText = tr("Unregistered user");
    userLevelLabel3.setText(userLevelText);

    QString accountAgeString = tr("Unregistered user");
    if (userLevel.testFlag(ServerInfo_User::IsAdmin) || userLevel.testFlag(ServerInfo_User::IsModerator) || userLevel.testFlag(ServerInfo_User::IsRegistered)) {
        if (user.accountage_secs() == 0) 
            accountAgeString = tr("Unknown");
        else {
            qint64 seconds = user.accountage_secs();
            qint64 minutes =  seconds / SIXTY;
            qint64 hours = minutes / SIXTY;
            qint64 days = hours / HOURS_IN_A_DAY;
            qint64 years = days / DAYS_IN_A_YEAR;
            qint64 daysMinusYears = days - (years * DAYS_IN_A_YEAR);

            accountAgeString = "";
            if (years >= 1) {
                accountAgeString = QString::number(years);
                accountAgeString.append(" ");
                accountAgeString.append(years == 1 ? tr("Year") : tr("Years"));
                accountAgeString.append(" ");
            }

            accountAgeString.append(QString::number(daysMinusYears));
            accountAgeString.append(" ");
            accountAgeString.append(days == 1 ? tr("Day") : tr("Days"));
        }
    }
    accountAgeLabel2.setText(accountAgeString);
}
开发者ID:Wettoiletpaper,项目名称:Cockatrice,代码行数:65,代码来源:userinfobox.cpp

示例15: quickSetColor

void FormStyle::quickSetColor()
{
	QFont globalFont = SystemFont;

	if ( ui.ccB->isChecked() && !ResetColor )
	{
		qApp->setPalette( applicationPalette );

		QPalette qSliderPalette;
		qSliderPalette.setBrush( QPalette::Button, sliderButtonColor );
		qApp->setPalette( qSliderPalette, "QSlider" );

		if ( ui.use2->isChecked() )
		{
			QPalette tmpPalette = qApp->palette();

			if ( !mainWindowPixmap.isNull() )
			{
				QBrush brushW( mainWindowPixmap.scaled( f1.size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation ) );
				tmpPalette.setBrush( QPalette::Window, brushW );
			}

			QColor colorA;

			colorA = tmpPalette.button().color();
			colorA.setAlphaF( ui.bP2_1->value() );
			tmpPalette.setBrush( QPalette::Button, colorA );

			colorA = tmpPalette.base().color();
			colorA.setAlphaF( ui.bP2_1->value() );
			tmpPalette.setBrush( QPalette::Base, colorA );

			if ( ui.bHt2->isChecked() )
			{
				colorA = tmpPalette.highlight().color();
				colorA.setAlphaF( ui.bP2_1->value() );
				tmpPalette.setBrush( QPalette::Highlight, colorA );
			}

			if ( ui.bSt2->isChecked() )
			{
				colorA = tmpPalette.shadow().color();
				colorA.setAlphaF( ui.bP2_1->value() );
				tmpPalette.setBrush( QPalette::Shadow, colorA );
			}

			f1.setPalette( tmpPalette );
		}
		else
		{
			f1.setPalette( qApp->palette() );
		}

		globalFont = ui.bF1->currentFont();
		globalFont.setPointSize( ui.bFSize1->value() );
	}
	else
	{
		qApp->setPalette( systemPalette );
		f1.setPalette( qApp->palette() );
		sliderButtonColor = qApp->palette().brush( QPalette::Button ).color();
	}

	if ( ResetColor )
	{
		ResetColor = false;
		applicationPalette = systemPalette;
		ui.bF1->setCurrentFont( SystemFont.toString() );
		ui.bFSize1->setValue( SystemFont.pointSize() );
	}

	QColor col = qApp->palette().window().color();
	col.setAlphaF( ui.bP2_1->value() );
	fsl.SetColor( col );

	f1.ui.pbL->setPalette( qApp->palette() );
	f1.ui.pbR->setPalette( qApp->palette() );

	globalFont.setBold( false );
	globalFont.setItalic( false );
	globalFont.setUnderline( false );
	if ( globalFont.pointSize() > 14 )
		globalFont.setPointSize( 14 );
	else if ( globalFont.pointSize() < 6 )
		globalFont.setPointSize( 6 );
#ifndef Q_OS_MAC
	qApp->setFont( globalFont );
#endif
}
开发者ID:darwinbeing,项目名称:Hifi-Pod,代码行数:89,代码来源:formStyle.cpp


注:本文中的QPixmap::scaled方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。