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


C++ QPixmap类代码示例

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


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

示例1: QPixmap

// Draws a cached pixmap with shadow
void StyleHelper::drawIconWithShadow(const QIcon &icon, const QRect &rect,
                                     QPainter *p, QIcon::Mode iconMode, int radius, const QColor &color, const QPoint &offset)
{
    QPixmap cache;
    QString pixmapName = QString::fromLatin1("icon %0 %1 %2").arg(icon.cacheKey()).arg(iconMode).arg(rect.height());

    if (!QPixmapCache::find(pixmapName, cache)) {
        QPixmap px = icon.pixmap(rect.size());
        cache = QPixmap(px.size() + QSize(radius * 2, radius * 2));
        cache.fill(Qt::transparent);

        QPainter cachePainter(&cache);
        if (iconMode == QIcon::Disabled) {
            QImage im = px.toImage().convertToFormat(QImage::Format_ARGB32);
            for (int y=0; y<im.height(); ++y) {
                QRgb *scanLine = (QRgb*)im.scanLine(y);
                for (int x=0; x<im.width(); ++x) {
                    QRgb pixel = *scanLine;
                    char intensity = qGray(pixel);
                    *scanLine = qRgba(intensity, intensity, intensity, qAlpha(pixel));
                    ++scanLine;
                }
            }
            px = QPixmap::fromImage(im);
        }

        // Draw shadow
        QImage tmp(px.size() + QSize(radius * 2, radius * 2 + 1), QImage::Format_ARGB32_Premultiplied);
        tmp.fill(Qt::transparent);

        QPainter tmpPainter(&tmp);
        tmpPainter.setCompositionMode(QPainter::CompositionMode_Source);
        tmpPainter.drawPixmap(QPoint(radius, radius), px);
        tmpPainter.end();

        // blur the alpha channel
        QImage blurred(tmp.size(), QImage::Format_ARGB32_Premultiplied);
        blurred.fill(Qt::transparent);
        QPainter blurPainter(&blurred);
        qt_blurImage(&blurPainter, tmp, radius, false, true);
        blurPainter.end();

        tmp = blurred;

        // blacken the image...
        tmpPainter.begin(&tmp);
        tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
        tmpPainter.fillRect(tmp.rect(), color);
        tmpPainter.end();

        tmpPainter.begin(&tmp);
        tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
        tmpPainter.fillRect(tmp.rect(), color);
        tmpPainter.end();

        // draw the blurred drop shadow...
        cachePainter.drawImage(QRect(0, 0, cache.rect().width(), cache.rect().height()), tmp);

        // Draw the actual pixmap...
        cachePainter.drawPixmap(QPoint(radius, radius) + offset, px);
        QPixmapCache::insert(pixmapName, cache);
    }

    QRect targetRect = cache.rect();
    targetRect.moveCenter(rect.center());
    p->drawPixmap(targetRect.topLeft() - offset, cache);
}
开发者ID:CNOT,项目名称:julia-studio,代码行数:68,代码来源:stylehelper.cpp

示例2: initStyleOption

void
PlaylistDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
{
    QStyleOptionViewItemV4 opt = option;
    initStyleOption( &opt, QModelIndex() );
    qApp->style()->drawControl( QStyle::CE_ItemViewItem, &opt, painter );

    if ( option.state & QStyle::State_Selected && option.state & QStyle::State_Active )
    {
        opt.palette.setColor( QPalette::Text, opt.palette.color( QPalette::HighlightedText ) );
    }

    painter->save();
    painter->setRenderHint( QPainter::Antialiasing );
    painter->setPen( opt.palette.color( QPalette::Text ) );

    QTextOption to;
    to.setAlignment( Qt::AlignCenter );
    QFont font = opt.font;
    font.setPixelSize( 10 );

    QFont boldFont = font;
    boldFont.setBold( true );
    boldFont.setPixelSize( 11 );

    QFont figFont = boldFont;
    figFont.setPixelSize( 10 );

    QPixmap icon;
    RecentlyPlayedPlaylistsModel::PlaylistTypes type = (RecentlyPlayedPlaylistsModel::PlaylistTypes)index.data( RecentlyPlayedPlaylistsModel::PlaylistTypeRole ).toInt();
    if( type == RecentlyPlayedPlaylistsModel::StaticPlaylist )
        icon = m_playlistIcon;
    else if( type == RecentlyPlayedPlaylistsModel::AutoPlaylist )
        icon = m_autoIcon;
    else if( type == RecentlyPlayedPlaylistsModel::Station )
        icon = m_stationIcon;

    QRect pixmapRect = option.rect.adjusted( 10, 13, -option.rect.width() + 48, -13 );
    icon = icon.scaled( pixmapRect.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation );

    painter->drawPixmap( pixmapRect, icon );

    if ( type != RecentlyPlayedPlaylistsModel::Station )
    {
        painter->save();
        painter->setFont( figFont );
        QString tracks = index.data( RecentlyPlayedPlaylistsModel::TrackCountRole ).toString();
        int width = painter->fontMetrics().width( tracks );
//         int bottomEdge = pixmapRect
        // right edge 10px past right edge of pixmapRect
        // bottom edge flush with bottom of pixmap
        QRect rect( pixmapRect.right() - width , 0, width - 8, 0 );
        rect.adjust( -2, 0, 0, 0 );
        rect.setTop( pixmapRect.bottom() - painter->fontMetrics().height() - 1 );
        rect.setBottom( pixmapRect.bottom() + 1 );

        QColor figColor( "#464b55" );
        painter->setPen( figColor );
        painter->setBrush( figColor );

        TomahawkUtils::drawBackgroundAndNumbers( painter, tracks, rect );
        painter->restore();
    }

    QPixmap avatar = index.data( RecentlyPlayedPlaylistsModel::PlaylistRole ).value< Tomahawk::playlist_ptr >()->author()->avatar( Source::FancyStyle );
    if ( avatar.isNull() )
        avatar = m_defaultAvatar;
    QRect r( option.rect.width() - avatar.width() - 10, option.rect.top() + option.rect.height()/2 - avatar.height()/2, avatar.width(), avatar.height() );
    painter->drawPixmap( r, avatar );

    painter->setFont( font );
    QString author = index.data( RecentlyPlayedPlaylistsModel::PlaylistRole ).value< Tomahawk::playlist_ptr >()->author()->friendlyName();
    if ( author.indexOf( '@' ) > 0 )
        author = author.mid( 0, author.indexOf( '@' ) );

    const int w = painter->fontMetrics().width( author ) + 2;
    QRect avatarNameRect( opt.rect.width() - 10 - w, r.bottom(), w, opt.rect.bottom() - r.bottom() );
    painter->drawText( avatarNameRect, author, QTextOption( Qt::AlignCenter ) );

    const int leftEdge = opt.rect.width() - qMin( avatarNameRect.left(), r.left() );
    QString descText;
    if ( type == RecentlyPlayedPlaylistsModel::Station )
    {
        descText = index.data( RecentlyPlayedPlaylistsModel::DynamicPlaylistRole ).value< Tomahawk::dynplaylist_ptr >()->generator()->sentenceSummary();
    }
    else
    {
        descText = index.data( RecentlyPlayedPlaylistsModel::ArtistRole ).toString();
    }

    QColor c = painter->pen().color();
    if ( !( option.state & QStyle::State_Selected && option.state & QStyle::State_Active ) )
    {
        painter->setPen( QColor( Qt::gray ).darker() );
    }

    QRect rectText = option.rect.adjusted( 66, 20, -leftEdge - 10, -8 );
#ifdef Q_WS_MAC
    rectText.adjust( 0, 1, 0, 0 );
#elif defined Q_WS_WIN
//.........这里部分代码省略.........
开发者ID:nowrep,项目名称:tomahawk,代码行数:101,代码来源:WelcomeWidget.cpp

示例3: QPixmap

void BackgroundWidget::paintEvent( QPaintEvent *e )
{
    if ( !b_withart )
    {
        /* we just want background autofill */
        QWidget::paintEvent( e );
        return;
    }

    int i_maxwidth, i_maxheight;
    QPixmap pixmap = QPixmap( pixmapUrl );
    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 );
}
开发者ID:J861449197,项目名称:vlc,代码行数:55,代码来源:interface_widgets.cpp

示例4: updatePdfMiniatureScreenshot

void MiniatureViewLandscape::updatePdfMiniatureScreenshot(QPixmap& screenshot)
{
    if (screenshot.isNull()) return;
    m_screenshot = screenshot;
    screenshotLbl->setPixmap(screenshot.scaled(screenshotLbl->size()));
}
开发者ID:oskrs111,项目名称:3p.cervantes,代码行数:6,代码来源:MiniatureViewLandscape.cpp

示例5: PrintPixmap

/* Prints a QPixmap, optionally displaying the print setup dialog first */
void PrintPixmap(QPixmap pixmap, bool displayDialog, QWidget *pParent, QPrinter *pPrinter)
{
   bool deletePrinter = false;
   if (pixmap.isNull() == true)
   {
      return;
   }

   // Create a printer device. Analogous to a Windows device context
   if (pPrinter == NULL)
   {
      deletePrinter = true;
      pPrinter = new QPrinter();
      if (pPrinter == NULL)
      {
         return;
      }
   }

   bool bPrint = true;
   if (displayDialog)
   {
      QPrintDialog dlg(pPrinter, pParent);
      if (dlg.exec() == QDialog::Rejected)
      {
         bPrint = false;
      }
   }

   if (bPrint == true)
   {
      double dAspect = 1.0; // the aspect ratio of the pixmap = width / height
      dAspect = static_cast<double>(pixmap.width()) / static_cast<double>(pixmap.height());

      // the QPainter provides an interface for drawing to a device, analogous
      // to Windows GDI, with the printer being the device context in this case
      QPainter p;
      if (p.begin(pPrinter) == false)
      {
         if (deletePrinter)
         {
            delete pPrinter;
         }

         return;
      }

      QRect rcViewport = p.viewport(); // the printable area in device coords

      // Determine how large we can make the pixmap on the paper without
      // losing any of it off the edges of the paper. iPrintWidth and iPrintHeight
      // will be the size of the pixmap on the paper, in printer device coords.
      int iPrintWidth = rcViewport.width();
      int iPrintHeight = rcViewport.height();
      double pAspect = static_cast<double>(iPrintWidth) /
         static_cast<double>(iPrintHeight); // aspect ratio of the paper

      // unless the aspect ratios of the paper and pixmap are equal, we will have unused
      // space above and below or left and right of the printed image. 
      double ratioAspects = pAspect / dAspect;
      if (ratioAspects > 1.0)
      { 
         // paper is wider than the image: empty space left and right
         // reduce iPrintWidth accordingly
         iPrintWidth = iPrintWidth / ratioAspects;
      }
      else
      { 
         // paper is taller than the image: empty space above and below
         // reduce iPrintHeight accordingly
         iPrintHeight = iPrintHeight * ratioAspects;
      }

      // specify the pixel dimensions of the pixmap
      p.setWindow(pixmap.rect());

      // specify the location and size to draw the pixmap on the paper
      p.setViewport(rcViewport.left() + (rcViewport.width() - iPrintWidth) / 2,
         rcViewport.top() + (rcViewport.height() - iPrintHeight) / 2,
         iPrintWidth, iPrintHeight);

      // draw the pixmap to the print device
      p.drawPixmap(0, 0, pixmap);

      // tell the printer that we are done; this will trigger a form feed
      p.end();
   }

   if (deletePrinter)
   {
      delete pPrinter;
   }
}
开发者ID:Siddharthk,项目名称:opticks,代码行数:94,代码来源:PrintPixmap.cpp

示例6: while

        void TutorialSelector::openAttribute(TiXmlElement* element,  Q3ListViewItem *item)
        {
            if (!element || !item) return;
            TiXmlAttribute* attribute=element->FirstAttribute();
            std::string typeElement=element->Value() ;

            std::map<std::string, std::string> attributes;

            while (attribute)
              {
                const std::string &nameOfAttribute=(attribute->Name());
                const std::string &valueOfAttribute=(attribute->Value());

                attributes.insert(std::make_pair(nameOfAttribute,valueOfAttribute));
                attribute=attribute->Next();

                if (nameOfAttribute == "name")
                {
                    item->setText(0, QString(valueOfAttribute.c_str()));
                }
              }

            if (typeElement == "Group")
            {
                static QPixmap pixNode((const char**)iconnode_xpm);
                item->setPixmap(0, pixNode);
            }
            else if (typeElement == "Category")
            {
                static QImage imageScene(QString(sofa::helper::system::DataRepository.getFirstPath().c_str()) + "/textures/media-seek-forward.png");
                static QPixmap pixScene;
                if (imageScene.width() != 20)
                {
                    imageScene=imageScene.smoothScale(20,10);
                    pixScene.convertFromImage(imageScene);
                }
                item->setPixmap(0,pixScene);

                Category C(item->text(0).ascii(), attributes["xml"], attributes["html"]);
                if (C.htmlFilename.empty() && C.xmlFilename.size() >= 4)
                {
                    std::string htmlFile=C.xmlFilename;
                    //Open Description
                    htmlFile = htmlFile.substr(0,htmlFile.size()-4);
                    htmlFile += ".html";

                    if ( sofa::helper::system::DataRepository.findFile (htmlFile) )
                        htmlFile = sofa::helper::system::DataRepository.getFile ( htmlFile );
                    else htmlFile.clear();

                    C.htmlFilename=htmlFile;
                }
                if (!C.xmlFilename.empty())
                {
                    if ( sofa::helper::system::DataRepository.findFile (C.xmlFilename) )
                        C.xmlFilename = sofa::helper::system::DataRepository.getFile ( C.xmlFilename);
                }
                 itemToCategory.insert(std::make_pair(item, C));
            }
            else if (typeElement == "Tutorial")
            {
                static QImage imageScene(QString(sofa::helper::system::DataRepository.getFirstPath().c_str()) + "/icons/SOFA.png");
                static QPixmap pixScene;
                if (imageScene.width() != 20)
                {
                    imageScene=imageScene.smoothScale(20,20);
                    pixScene.convertFromImage(imageScene);
                }

                item->setPixmap(0,pixScene);
                Tutorial T(item->text(0).ascii(), attributes["scene"], attributes["html"]);
                if (T.htmlFilename.empty() && T.sceneFilename.size() >= 4)
                {
                    std::string htmlFile=T.sceneFilename;
                    //Open Description
                    htmlFile = htmlFile.substr(0,htmlFile.size()-4);
                    htmlFile += ".html";

                    if ( sofa::helper::system::DataRepository.findFile (htmlFile) )
                        htmlFile = sofa::helper::system::DataRepository.getFile ( htmlFile );
                    else htmlFile.clear();

                    T.htmlFilename=htmlFile;
                }

                if (!T.sceneFilename.empty())
                {
                    if ( sofa::helper::system::DataRepository.findFile (T.sceneFilename) )
                        T.sceneFilename = sofa::helper::system::DataRepository.getFile ( T.sceneFilename);
                }

                itemToTutorial.insert(std::make_pair(item, T));
            }
        }
开发者ID:conanhung,项目名称:sofa_rc1,代码行数:94,代码来源:TutorialSelector.cpp

示例7: setPixmap

//ÉèÖÃÌùͼº¯Êý
void AlphaWidget::setPixmap(QPixmap pixmap)
{
	this->pixmap = pixmap;
	setMask(QBitmap(pixmap.mask()));
}
开发者ID:billhhh,项目名称:whLBS,代码行数:6,代码来源:AlphaWidget.cpp

示例8: setIcon

void AmeNavBarItem::setIcon (const QPixmap& icon) {
	if (icon.height() > 20)
		d->labelIcon->setPixmap(icon.scaledToHeight(20, Qt::SmoothTransformation));
	else
		d->labelIcon->setPixmap(icon);
}
开发者ID:admiral0,项目名称:Antico-Deluxe,代码行数:6,代码来源:navbaritem.cpp

示例9: size

Window::Window(const QString &title, const QSizeF &size)
    :title(title), size(size), keep_when_disappear(false)
{
    setFlags(ItemIsMovable);

    QPixmap *bg;
    bg = size.width()>size.height() ?
                new QPixmap("image/system/tip.png")
              : new QPixmap("image/system/about.png");
    QImage bgimg = bg->toImage();
    outimg = new QImage(size.toSize(),QImage::Format_ARGB32);

    qreal pad = 10;

    int w = bgimg.width();
    int h = bgimg.height();

    int tw = outimg->width();
    int th  =outimg->height();

    qreal xc = (w - 2*pad)/(tw - 2*pad);
    qreal yc = (h - 2*pad)/(th - 2*pad);

    for(int i=0;i<tw;i++)
        for(int j=0;j<th;j++)
        {
            int x = i;
            int y = j;

            if( x>=pad && x<=(tw - pad) ) x = pad + (x - pad)*xc;
            else if(x>=(tw-pad))x = w - (tw - x);

            if( y>=pad && y<=(th - pad) ) y = pad + (y - pad)*yc;
            else if(y>=(th-pad))y = h - (th - y);


            QRgb rgb = bgimg.pixel(x,y);
            outimg->setPixel(i,j,rgb);
        }


    scaleTransform = new QGraphicsScale(this);
    scaleTransform->setXScale(1.05);
    scaleTransform->setYScale(0.95);
    scaleTransform->setOrigin(QVector3D(
                                  this->boundingRect().width()/2,
                                  this->boundingRect().height()/2,
                                  0
                                  ));

    QList<QGraphicsTransform *> transforms;
    transforms << scaleTransform;
    setTransformations(transforms);

    this->setOpacity(0.0);

    QGraphicsTextItem * titleItem = new QGraphicsTextItem(this);

    QString style;
    style.append("font-size:18pt; ");
    style.append("color:#77c379; ");
    style.append(QString("font-family: %1").arg(Config.SmallFont.family()));

    QString content;
    content.append(QString("<h style=\"%1\">%2</h>")
                   .arg(style).arg(title));

    titleItem->setHtml(content);
    titleItem->moveBy(size.width()/2 - titleItem->boundingRect().width()/2,10);
}
开发者ID:,项目名称:,代码行数:70,代码来源:

示例10: displayImage

void MainWidget::displayImage( const QImage& image ){
	const QPixmap pix = QPixmap::fromImage(image);
	const QSize size = _ui->displayLabel->size();
	this->_ui->displayLabel->setPixmap(pix.scaled(size,Qt::KeepAspectRatio));
} 
开发者ID:ajapco,项目名称:MinotaurMBEDLabyrinthSolver,代码行数:5,代码来源:MainWidget.cpp

示例11: qWarning

	void GlanceShower::Start ()
	{
		if (!TabWidget_)
		{
			qWarning () << Q_FUNC_INFO
				<< "no tab widget set";
			return;
		}

		int count = TabWidget_->count ();
		if (count < 2)
			return;

		QSequentialAnimationGroup *animGroup = new QSequentialAnimationGroup;

		int sqr = std::sqrt ((double)count);
		int rows = sqr;
		int cols = sqr;
		if (rows * cols < count)
			++cols;
		if (rows * cols < count)
			++rows;

		QRect screenGeom = QApplication::desktop ()->
				screenGeometry (Core::Instance ().GetReallyMainWindow ());
		int width = screenGeom.width ();
		int height = screenGeom.height ();

		int singleW = width / cols;
		int singleH = height / rows;

		int wW = singleW * 4 / 5;
		int wH = singleH * 4 / 5;

		qreal scaleFactor = 0;
		QSize sSize;

		int animLength = 500 / (sqr);

		QProgressDialog pg;
		pg.setMinimumDuration (1000);
		pg.setRange (0, count);

		for (int row = 0; row < rows; ++row)
			for (int column = 0;
					column < cols && column + row * cols < count;
					++column)
			{
				int idx = column + row * cols;
				pg.setValue (idx);
				QWidget *w = TabWidget_->widget (idx);

				if (!sSize.isValid ())
					sSize = w->size () / 2;
				if (sSize != w->size ())
					w->resize (sSize * 2);

				if (!scaleFactor)
					scaleFactor = std::min (static_cast<qreal> (wW) / sSize.width (),
							static_cast<qreal> (wH) / sSize.height ());

				QPixmap pixmap (sSize * 2);
				w->render (&pixmap);
				pixmap = pixmap.scaled (sSize,
						Qt::IgnoreAspectRatio, Qt::SmoothTransformation);

				{
					QPainter p (&pixmap);
					QPen pen (Qt::black);
					pen.setWidth (2 / scaleFactor + 1);
					p.setPen (pen);
					p.drawRect (QRect (QPoint (0, 0), sSize));
				}

				GlanceItem *item = new GlanceItem (pixmap);
				item->SetIndex (idx);
				connect (item,
						SIGNAL (clicked (int)),
						this,
						SLOT (handleClicked (int)));

				Scene_->addItem (item);
				item->setTransformOriginPoint (sSize.width () / 2, sSize.height () / 2);
				item->setScale (scaleFactor);
				item->SetIdealScale (scaleFactor);
				item->setOpacity (0);
				item->moveBy (column * singleW, row * singleH);

				QParallelAnimationGroup *pair = new QParallelAnimationGroup;

				QPropertyAnimation *posAnim = new QPropertyAnimation (item, "Pos");
				posAnim->setDuration (animLength);
				posAnim->setStartValue (QPointF (0, 0));
				posAnim->setEndValue (QPointF (column * singleW, row * singleH));
				posAnim->setEasingCurve (QEasingCurve::OutSine);
				pair->addAnimation (posAnim);

				QPropertyAnimation *opacityAnim = new QPropertyAnimation (item, "Opacity");
				opacityAnim->setDuration (animLength);
				opacityAnim->setStartValue (0.);
//.........这里部分代码省略.........
开发者ID:grio,项目名称:leechcraft,代码行数:101,代码来源:glanceshower.cpp

示例12: dragResource

void jsBridge::dragResource(QString hash) {

    Resource *res = Resource::fromHash(hash);
    if (res == NULL)
        return;

    QString mime = res->mimeType();
    QString fileName = res->getFileName();
    QByteArray data = res->getData();

    QPixmap pix;
    if (res->isImage()) {
        pix.loadFromData(data);
    } else if (res->isPDF()) {
        pix.load(":/img/application-pdf.png");
    } else {
        pix.load(":/img/application-octet-stream.png");
    }

    delete res;

    if (fileName.isEmpty())
        fileName = hash;

    if (mime == "application/pdf") {
        if (!fileName.endsWith(".pdf", Qt::CaseInsensitive))
            fileName += ".pdf";
    } else if (mime == "image/jpeg") {
        if (!fileName.endsWith(".jpg", Qt::CaseInsensitive) && !fileName.endsWith(".jpeg", Qt::CaseInsensitive))
            fileName += ".jpg";
    } else if (mime == "image/png") {
        if (!fileName.endsWith(".png", Qt::CaseInsensitive))
            fileName += ".png";
    } else if (mime == "image/gif") {
        if (!fileName.endsWith(".gif", Qt::CaseInsensitive))
            fileName += ".gif";
    }

    QString tmpl = QDir::tempPath() + QDir::separator() + fileName;

    QFile* f = new QFile(tmpl);

    if (!f->open(QIODevice::WriteOnly))
        return;

    f->write(data);
    f->close();
    files.enqueue(f);

    QTimer::singleShot(60000, this, SLOT(removeTmpFile()));

    QDrag *drag = new QDrag(new QWidget());
    QMimeData *mimeData = new QMimeData;

    QFileInfo fileInfo(tmpl);
    QUrl url = QUrl::fromLocalFile(fileInfo.absoluteFilePath());
    mimeData->setUrls(QList<QUrl>() << url);

    drag->setMimeData(mimeData);

    if (!pix.isNull())
        drag->setPixmap(pix.scaled(128,128, Qt::KeepAspectRatio, Qt::SmoothTransformation));

    drag->exec(Qt::CopyAction | Qt::MoveAction);
}
开发者ID:MidoriYakumo,项目名称:hippo,代码行数:65,代码来源:jsbridge.cpp

示例13: drawPixmap

void QCairoPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr)
{
    drawImage(r, pm.toImage(), sr);
}
开发者ID:jkriege2,项目名称:cairoQPaintDevice,代码行数:4,代码来源:qcairopaintengine.cpp

示例14: QSplashScreen

SplashScreen::SplashScreen(const QPixmap &pixmap, Qt::WindowFlags f, bool isTestNet) :
    QSplashScreen(pixmap, f)
{
    setAutoFillBackground(true);

    // set reference point, paddings
    int paddingLeftCol2         = 230;
    int paddingTopCol2          = 376;
    int line1                   = 0;
    int line2                   = 13;
    int line3                   = 26;

    float fontFactor            = 1.0;

    // define text to place
    QString titleText       = QString(QApplication::applicationName()).replace(QString("-testnet"), QString(""), Qt::CaseSensitive);
    QString versionText     = QString("Version %1 ").arg(QString::fromStdString(FormatFullVersion()));
    QString copyrightText1   = QChar(0xA9)+QString(" 2009-%1 ").arg(COPYRIGHT_YEAR) + QString(tr("The Bitcoin developers"));
    QString copyrightText2   = QChar(0xA9)+QString(" 2011-%1 ").arg(COPYRIGHT_YEAR) + QString(tr("The Auroracoin developers"));
    QString testnetAddText  = QString(tr("[testnet]"));

    QString font            = "Arial";

    // load the bitmap for writing some text over it
    QPixmap newPixmap;
    if(isTestNet) {
        newPixmap     = QPixmap(":/images/splash_testnet");
    }
    else {
        newPixmap     = QPixmap(":/images/splash");
    }

    QPainter pixPaint(&newPixmap);
    pixPaint.setPen(QColor(100,100,100));

    // check font size and drawing with
    pixPaint.setFont(QFont(font, 9*fontFactor));
    QFontMetrics fm = pixPaint.fontMetrics();
    int titleTextWidth  = fm.width(titleText);
    if(titleTextWidth > 160) {
        // strange font rendering, Arial probably not found
        fontFactor = 0.75;
    }

    pixPaint.setFont(QFont(font, 33*fontFactor));
    fm = pixPaint.fontMetrics();
    titleTextWidth = fm.width(titleText);
    pixPaint.drawText(newPixmap.width()-titleTextWidth-paddingLeftCol2,paddingTopCol2,titleText);

    // if the version string is to long, reduce size
    fm = pixPaint.fontMetrics();
    int versionTextWidth  = fm.width(versionText);
    if(versionTextWidth > titleTextWidth) {
        pixPaint.setFont(QFont(font, 3*fontFactor));
    }
    pixPaint.drawText(paddingLeftCol2,paddingTopCol2+line1,versionText);

    // draw copyright stuff
    pixPaint.setFont(QFont(font, 9*fontFactor));
    pixPaint.drawText(paddingLeftCol2,paddingTopCol2+line2,copyrightText1);
    pixPaint.drawText(paddingLeftCol2,paddingTopCol2+line3,copyrightText2);

    // draw testnet string if testnet is on
    if(isTestNet) {
        QFont boldFont = QFont(font, 3*fontFactor);
        boldFont.setWeight(QFont::Bold);
        pixPaint.setFont(boldFont);
        fm = pixPaint.fontMetrics();
        int testnetAddTextWidth  = fm.width(testnetAddText);
        pixPaint.drawText(newPixmap.width()-testnetAddTextWidth-10,15,testnetAddText);
    }

    pixPaint.end();

    this->setPixmap(newPixmap);

    subscribeToCoreSignals();
}
开发者ID:BioMike,项目名称:Auroracoin,代码行数:78,代码来源:splashscreen.cpp

示例15: createCursor

QCursor createCursor(QString path)
{
	if (path.isEmpty())
        return QCursor();
	
	// read file headers
	QFile curFile(path);
	curFile.open(QIODevice::ReadOnly);
	QDataStream curStream(&curFile);
	curStream.setByteOrder(QDataStream::LittleEndian);
	
	struct {
		quint16 zero;
		quint16 type;
		quint16 icons;
	} header2;
	curStream >> header2.zero >> header2.type >> header2.icons;

	struct {
		quint8 width;
		quint8 height;
		quint8 ncolours;
		quint8 zero;
		quint16 xhot;
		quint16 yhot;
		quint32 bytes;
		quint32 dibOffset;
	} directory2;
	curStream >> directory2.width >> directory2.height >> directory2.ncolours >> directory2.zero >> directory2.xhot >> directory2.yhot >> directory2.bytes >> directory2.dibOffset;
	
	curFile.seek(directory2.dibOffset);
	
	// prepare a .bmp for delegating decoding to qt
	struct {
		unsigned char magic[2];
		quint32 size;
		quint32 zero;
		quint32 rdataOffset;
	} bmpHeader;
	int bmpHeaderSize = (2+4+4+4);
	struct {
		quint32 hdrSize;
		quint32 width;
		quint32 height;
		quint16 planes;
		quint16 bpp;
		quint32 compression;
		quint32 dataSize;
		quint32 unused1;
		quint32 unused2;
		quint32 unused3;
		quint32 unused4;
	} dibHeader;
	int dibHeaderSize = (4+4+4+2+2+4+4+4+4+4+4);
	
	bmpHeader.magic[0] = 'B'; bmpHeader.magic[1] = 'M';
	bmpHeader.zero = 0;
	bmpHeader.size = bmpHeaderSize + directory2.bytes;
	bmpHeader.rdataOffset = bmpHeaderSize + dibHeaderSize + directory2.ncolours * 4;
	
	curStream >> dibHeader.hdrSize >> dibHeader.width >> dibHeader.height >> dibHeader.planes >> dibHeader.bpp >> dibHeader.compression >> dibHeader.dataSize >> dibHeader.unused1 >> dibHeader.unused2 >> dibHeader.unused3 >> dibHeader.unused4;
	dibHeader.height >>= 1;
	
	// the bmp bytes are in 'bmpData'
	QByteArray bmpData;
	QDataStream bmpStream(&bmpData, QIODevice::WriteOnly);
	bmpStream.setByteOrder(QDataStream::LittleEndian);
	bmpStream.writeRawData((char*) bmpHeader.magic, 2);
	bmpStream << bmpHeader.size << bmpHeader.zero << bmpHeader.rdataOffset;
	bmpStream << dibHeader.hdrSize << dibHeader.width << dibHeader.height << dibHeader.planes << dibHeader.bpp << dibHeader.compression << dibHeader.dataSize << dibHeader.unused1 << dibHeader.unused2 << dibHeader.unused3 << dibHeader.unused4;
	bmpData.append(curFile.read(directory2.bytes - dibHeaderSize));
	
	// decode the image into 'pix'
	int width = directory2.width;
	int height = directory2.height;
	QImage image;
	image.loadFromData(bmpData);
	//qDebug() << image.rect() << path;
	QPixmap pix = QPixmap::fromImage(image);
	
	// now we need the mask (transparency)
	QByteArray maskData = bmpData.right((width * height) / 8);
	QImage maskImage = QBitmap::fromData(QSize(width, height), (const uchar*) maskData.constData(), QImage::Format_Mono).toImage().mirrored(false, true);
	maskImage.invertPixels();
	pix.setMask(QBitmap::fromImage(maskImage));
	
	return QCursor(pix, directory2.xhot, directory2.yhot);
}
开发者ID:Greedysky,项目名称:qmmp,代码行数:88,代码来源:cursorimage.cpp


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