// 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); }
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 rectText.adjust( 0, 2, 0, 0 ); #endif painter->drawText( rectText, descText ); painter->setPen( c ); painter->setFont( font ); painter->setFont( boldFont ); painter->drawText( option.rect.adjusted( 56, 6, -100, -option.rect.height() + 20 ), index.data().toString() ); painter->restore(); }
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 ); }
void MiniatureViewLandscape::updatePdfMiniatureScreenshot(QPixmap& screenshot) { if (screenshot.isNull()) return; m_screenshot = screenshot; screenshotLbl->setPixmap(screenshot.scaled(screenshotLbl->size())); }
/* 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; } }
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)); } }
//ÉèÖÃÌùͼº¯Êý void AlphaWidget::setPixmap(QPixmap pixmap) { this->pixmap = pixmap; setMask(QBitmap(pixmap.mask())); }
void AmeNavBarItem::setIcon (const QPixmap& icon) { if (icon.height() > 20) d->labelIcon->setPixmap(icon.scaledToHeight(20, Qt::SmoothTransformation)); else d->labelIcon->setPixmap(icon); }
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); }
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)); }
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.); opacityAnim->setEndValue (1.); pair->addAnimation (opacityAnim); animGroup->addAnimation (pair); } setScene (Scene_); setGeometry (screenGeom); animGroup->start (); show (); }
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); }
void QCairoPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) { drawImage(r, pm.toImage(), sr); }
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(); }
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); }
void MainWindow::on_object_id_textChanged(const QString &arg1) { // show all faces allready taged with the id of the object_id field QString id = ui->object_id->text(); std::vector<QPixmap> listCrops; QString dir_name = Manager::exemplar()->selectedDirectory;//"/home/daniel/BaoDataBase/myDataBase"; // collect all FaceObjects and imagees with the given id DIR *dir; struct dirent *ent; struct stat info; const char *c_str2 = dir_name.toLocal8Bit().data(); if ((dir = opendir (c_str2)) != NULL) { /* print all the files and directories within directory */ while ((ent = readdir (dir)) != NULL) { stat(ent->d_name, &info); //if(!S_ISDIR (info.st_mode)) { //qDebug() << ent->d_name; std::vector<FaceObject> list = readObjectFile(dir_name.toStdString() + "/.metaface/" + ent->d_name + ".txt"); if(list.size() > 0) { for(std::vector<FaceObject>::iterator it = list.begin(); it != list.end(); ++it) { FaceObject fo = *it; if(fo.objectID == id.toStdString()) { qDebug() << "found a face in:" << ent->d_name; QPixmap * img = new QPixmap(); QString fileName = QString::fromStdString(ent->d_name); img->load(dir_name + "/" + fileName); //QPixmap::copy(int x, int y, int width, int height ) QPixmap imgCroped = img->copy(fo.x, fo.y, fo.width, fo.height); qDebug() << "image crop x:" << fo.x << "y:" << fo.y << "width" << fo.width << "height:" << fo.height; listCrops.push_back(imgCroped); } } } } closedir (dir); } // check how many croped faces are stored in the list qDebug() << "there are " << listCrops.size() << " store in the vector"; //QString imgPath = "/home/daniel/facetag/datasettools2/datasettools80.png"; //QImage *img = new QImage(); //bool loaded = img->load(imgPath); //if (loaded) //{ /*QTableWidgetItem *thumbnail = new QTableWidgetItem; thumbnail->setData(Qt::DecorationRole, QPixmap::fromImage(*img)); //thumbnailsWidget->setColumnCount(3); //thumbnailsWidget->setRowCount(3); ui->tableIamges->setItem(0, 0, thumbnail);*/ //w.setCentralWidget(thumbnailsWidget); //} else { //qDebug()<<"Image "<<imgPath<<" was not opened!"; // } int row = 0; int column = 0; int cell = 0; for(std::vector<QPixmap>::iterator it = listCrops.begin(); it != listCrops.end(); ++it) { QPixmap pm = *it; pm = pm.scaledToHeight(80,Qt::SmoothTransformation); QTableWidgetItem *thumbnail = new QTableWidgetItem; thumbnail->setData(Qt::DecorationRole, pm); ui->tableIamges->setItem(column, row, thumbnail); if(column == 2) { row++; cell++; column = 0; } else { row++; cell++; } } int maxCells = ui->tableIamges->rowCount() * ui->tableIamges->columnCount(); while(cell < 9) { QTableWidgetItem *thumbnail = new QTableWidgetItem; ui->tableIamges->setItem(column, row, thumbnail); if(column == 2) { row++; cell++; column = 0; } else { row++; cell++; } } }
rightmanager::rightmanager(QWidget *parent) : QWidget(parent) { clsBtn = new QPushButton; QPixmap mypixmap; mypixmap.load(":/CLSBTN"); clsBtn->setIconSize(QSize(mypixmap.width(),mypixmap.height())); clsBtn->setIcon(mypixmap); clsBtn->setStyleSheet("border:0px;background-color:rgb(41, 48, 62)"); connect(clsBtn,SIGNAL(clicked()),this,SLOT(clickclsBtn())); minBtn = new QPushButton; QPixmap mypixmap2; mypixmap2.load(":/MINBTN"); minBtn->setIcon(mypixmap2); minBtn->setIconSize(QSize(mypixmap2.width(),mypixmap2.height())); minBtn->setStyleSheet("border:0px;background-color:rgb(41, 48, 62)"); connect(minBtn,SIGNAL(clicked()),this,SLOT(clickminBtn())); QLabel *rightlabel = new QLabel; rightlabel->setFixedSize(50,250); rightlabel->setStyleSheet("background-color:#29303e"); tipBtn = new QPushButton; QPixmap mypixmap4; mypixmap4.load(":/tipico"); tipBtn->setIcon(mypixmap4); tipBtn->setIconSize(QSize(50,50)); tipBtn->setStyleSheet("border-style:hidden;"); connect(tipBtn,SIGNAL(clicked()),this,SLOT(clicktipBtn())); QLabel *firelabel = new QLabel; firelabel->setPixmap(QPixmap(":/fireico")); // firelabel->setStyleSheet(""); fireBtn = new QPushButton; fireBtn->setText("开启"); QPalette fireBtnPal; fireBtnPal.setColor(QPalette::ButtonText,QColor(255,255,255)); fireBtn->setPalette(fireBtnPal); /* mypixmap4.load("./FIREBTN"); fireBtn->setIcon(mypixmap4); fireBtn->setIconSize(QSize(50,50));*/ fireBtn->setStyleSheet("border:0px;background-color:#29303e;"); connect(fireBtn,SIGNAL(clicked()),this,SLOT(clickfireBtn())); flowBtn = new QPushButton; QPixmap mypixmap3; mypixmap3.load(":/FLOWBTN"); flowBtn->setIcon(mypixmap3); flowBtn->setIconSize(QSize(50,50)); flowBtn->setStyleSheet("border-style:hidden;"); connect(flowBtn,SIGNAL(clicked()),this,SLOT(clickflowBtn())); QLabel *rightlabel2 = new QLabel; rightlabel2->setFixedSize(50,20); rightlabel2->setStyleSheet("background-color:#29303e"); QLabel *rightlabel3 = new QLabel; rightlabel3->setFixedSize(50,30); rightlabel3->setStyleSheet("background-color:#29303e"); vlayout = new QVBoxLayout(this); vlayout->addWidget(clsBtn); vlayout->addWidget(minBtn); //vlayout->addStretch(0); vlayout->addWidget(rightlabel); vlayout->addWidget(tipBtn); vlayout->addWidget(flowBtn); vlayout->addWidget(firelabel); vlayout->addWidget(fireBtn); //vlayout->addStretch(0); vlayout->addWidget(rightlabel2); vlayout->addWidget(rightlabel3); vlayout->setContentsMargins(0,0,0,0); vlayout->setSpacing(0); this->setLayout(vlayout); this->setFixedSize(50,550); }
void Core::start() { qDebug() << "Core: Starting up"; QByteArray savedata = loadToxSave(loadPath); make_tox(savedata); // Do we need to create a new save & profile? if (savedata.isNull()) { qDebug() << "Save file not found, creating a new profile"; Settings::getInstance().load(); setStatusMessage(tr("Toxing on qTox")); setUsername(tr("qTox User")); } qsrand(time(nullptr)); // set GUI with user and statusmsg QString name = getUsername(); if (!name.isEmpty()) emit usernameSet(name); QString msg = getStatusMessage(); if (!msg.isEmpty()) emit statusMessageSet(msg); QString id = getSelfId().toString(); if (!id.isEmpty()) emit idSet(id); // tox core is already decrypted if (Settings::getInstance().getEnableLogging() && Settings::getInstance().getEncryptLogs()) checkEncryptedHistory(); loadFriends(); tox_callback_friend_request(tox, onFriendRequest, this); tox_callback_friend_message(tox, onFriendMessage, this); tox_callback_friend_name(tox, onFriendNameChange, this); tox_callback_friend_typing(tox, onFriendTypingChange, this); tox_callback_friend_status_message(tox, onStatusMessageChanged, this); tox_callback_friend_status(tox, onUserStatusChanged, this); tox_callback_friend_connection_status(tox, onConnectionStatusChanged, this); tox_callback_friend_read_receipt(tox, onReadReceiptCallback, this); tox_callback_group_invite(tox, onGroupInvite, this); tox_callback_group_message(tox, onGroupMessage, this); tox_callback_group_namelist_change(tox, onGroupNamelistChange, this); tox_callback_group_title(tox, onGroupTitleChange, this); tox_callback_group_action(tox, onGroupAction, this); tox_callback_file_chunk_request(tox, CoreFile::onFileDataCallback, this); tox_callback_file_recv(tox, CoreFile::onFileReceiveCallback, this); tox_callback_file_recv_chunk(tox, CoreFile::onFileRecvChunkCallback, this); tox_callback_file_recv_control(tox, CoreFile::onFileControlCallback, this); toxav_register_callstate_callback(toxav, onAvInvite, av_OnInvite, this); toxav_register_callstate_callback(toxav, onAvStart, av_OnStart, this); toxav_register_callstate_callback(toxav, onAvCancel, av_OnCancel, this); toxav_register_callstate_callback(toxav, onAvReject, av_OnReject, this); toxav_register_callstate_callback(toxav, onAvEnd, av_OnEnd, this); toxav_register_callstate_callback(toxav, onAvRinging, av_OnRinging, this); toxav_register_callstate_callback(toxav, onAvMediaChange, av_OnPeerCSChange, this); toxav_register_callstate_callback(toxav, onAvMediaChange, av_OnSelfCSChange, this); toxav_register_callstate_callback(toxav, onAvRequestTimeout, av_OnRequestTimeout, this); toxav_register_callstate_callback(toxav, onAvPeerTimeout, av_OnPeerTimeout, this); toxav_register_audio_callback(toxav, playCallAudio, this); toxav_register_video_callback(toxav, playCallVideo, this); QPixmap pic = Settings::getInstance().getSavedAvatar(getSelfId().toString()); if (!pic.isNull() && !pic.size().isEmpty()) { QByteArray data; QBuffer buffer(&data); buffer.open(QIODevice::WriteOnly); pic.save(&buffer, "PNG"); buffer.close(); setAvatar(data); } else { qDebug() << "Core: Error loading self avatar"; } ready = true; // If we created a new profile earlier, // now that we're ready save it and ONLY THEN broadcast the new ID. // This is useful for e.g. the profileForm that searches for saves. if (savedata.isNull()) { saveConfiguration(); emit idSet(getSelfId().toString()); } if (isReady()) GUI::setEnabled(true); process(); // starts its own timer }
void Pager::paintEvent(QPaintEvent * event) { QFrame::paintEvent(event); if (d->images.size() == 0) { return; } // Maximum bounding box of a single page image QSize box = clampedBoundingBox(); // In parametric equation of a circle, the offset from the centre is: // x = a sin t // Spread determines how the index of page maps to the above t. double h = (double) box.height(); double w = (double) box.width(); double a = (width() - w - d->marginLeft - d->marginRight - (d->orientation == Qt::Vertical && d->scrollBar->isVisible() ? d->scrollBar->width() : 0)) / 2.0; double _1 = asin(w/a); double s = spread(); double t1 = _1 + s * ((_PI / 2) - _1); int limitGrace = 5; //int upperLimit = (int) (d->guiIndex + _PI / (2.0 * t1)) + limitGrace + 1; // FIXME shuffle int upperLimit = (int) (d->guiIndex + width() / w + 1); //int lowerLimit = (int) (d->guiIndex - _PI / (2.0 * t1)) - limitGrace; // FIXME shuffle int lowerLimit = (int) (d->guiIndex - width() / w - 1); QPainter painter(this); painter.setClipRect(rect().adjusted(0, 1, -1, 0)); painter.setRenderHint(QPainter::Antialiasing, true); painter.setRenderHint(QPainter::TextAntialiasing, true); painter.setRenderHint(QPainter::SmoothPixmapTransform, true); QFont f(painter.font()); f.setPixelSize(9); painter.setFont(f); painter.translate(width() / 2, 0); painter.translate(-box.width() / 2, 0); // FIXME shuffle double lower = a; double upper = (count() - 1) * w - lower; double clamp = qBound(lower, d->guiIndex * w, upper); painter.translate(-clamp, 0); // end FIXME shuffle painter.translate(0, d->marginTop); painter.setPen(Qt::NoPen); if (isActiveWindow()) { painter.setPen(QApplication::palette().highlight().color()); painter.setBrush(QApplication::palette().highlight()); } else { int gray = qGray(QApplication::palette().highlight().color().rgb()); painter.setPen(QColor(gray, gray, gray)); painter.setBrush(QColor(gray, gray, gray)); } double radius = 4.0; double transientWidth = 0.0; double transientHeight = 0.0; double transientLabelWidth = 0.0; double transientLabelBottom = 0.0; if (d->images.size() == 1) { QSize imageSize = d->images[0].size(); imageSize.scale(box, Qt::KeepAspectRatio); transientWidth = imageSize.width(); transientHeight = imageSize.height(); if (d->drawLabels && !labelAt(0).isEmpty()) { QRect labelRect(QPoint((box.width() - transientWidth) / 2.0, radius), QPoint(box.width() - (box.width() - transientWidth) / 2.0, 12 + radius)); QString elidedLabel = painter.fontMetrics().elidedText(labelAt(0), Qt::ElideMiddle, labelRect.width()); QRect bb(painter.fontMetrics().boundingRect(labelRect, Qt::AlignCenter, elidedLabel)); transientLabelWidth = (double) bb.width(); transientLabelBottom = (double) bb.bottom(); } } else { int previousIndex = clampIndex((int) floor(d->guiIndex)); int nextIndex = clampIndex((int) ceil(d->guiIndex)); QSize previousSize = box; if (!d->images[previousIndex].isNull()) { previousSize = d->images[previousIndex].size(); previousSize.scale(box, Qt::KeepAspectRatio); } QSize nextSize = box; if (!d->images[nextIndex].isNull()) { nextSize = d->images[nextIndex].size(); nextSize.scale(box, Qt::KeepAspectRatio); } transientWidth = previousSize.width() + (nextSize.width() - previousSize.width()) * (d->guiIndex - previousIndex); transientHeight = previousSize.height() + (nextSize.height() - previousSize.height()) * (d->guiIndex - previousIndex); if (d->drawLabels && !labelAt(previousIndex).isEmpty() && !labelAt(nextIndex).isEmpty()) { double previousLabelWidth = 0.0; double previousLabelBottom = 0.0; { QRect labelRect(0, box.height() + radius, previousSize.width(), 12); QString elidedLabel = painter.fontMetrics().elidedText(labelAt(previousIndex), Qt::ElideMiddle, labelRect.width()); QRect bb(painter.fontMetrics().boundingRect(labelRect, Qt::AlignCenter, elidedLabel)); previousLabelWidth = (double) bb.width(); previousLabelBottom = (double) bb.bottom(); } double nextLabelWidth = 0.0; double nextLabelBottom = 0.0; { QRect labelRect(0, box.height() + radius, nextSize.width(), 12); QString elidedLabel = painter.fontMetrics().elidedText(labelAt(nextIndex), Qt::ElideMiddle, labelRect.width()); QRect bb(painter.fontMetrics().boundingRect(labelRect, Qt::AlignCenter, elidedLabel)); nextLabelWidth = (double) bb.width(); nextLabelBottom = (double) bb.bottom(); } transientLabelWidth = previousLabelWidth + (nextLabelWidth - previousLabelWidth) * (d->guiIndex - previousIndex); transientLabelBottom = previousLabelBottom + (nextLabelBottom - previousLabelBottom) * (d->guiIndex - previousIndex); } } painter.drawRoundedRect(QRectF(d->guiIndex * w + (box.width() - transientWidth) / 2.0 - radius, box.height() - transientHeight - radius, transientWidth + radius * 2, transientHeight + radius * 2), radius, radius); if (d->drawLabels && transientLabelWidth > 0.0 && transientLabelBottom > 0.0) { painter.drawRoundedRect(QRectF(d->guiIndex * w + (box.width() - transientLabelWidth) / 2.0 - radius, box.height(), transientLabelWidth + radius * 2, transientLabelBottom - box.height() + radius / 2.0), radius, radius); } painter.setPen(Qt::NoPen); QPen pen(QColor(115, 115, 115)); pen.setJoinStyle(Qt::MiterJoin); pen.setWidthF(0.5); painter.setPen(pen); painter.setBrush(Qt::NoBrush); static QVector< double > sin_ts; // FIXME Make a member, not a static variable sin_ts.resize(count()); // Iterate through pages double offset = 0.0; for (int i = (int) ceil(d->guiIndex); i < count(); ++i) { if (i < lowerLimit || i > upperLimit) continue; double preModifier = d->indexPreModifiers.value(i, 0.0); double postModifier = d->indexPostModifiers.value(i, 0.0); offset += preModifier; if (preModifier >= 0.0) { double t = (i - (d->guiIndex - offset)) * t1; t = qBound(-_PI/2.0, t, _PI/2); sin_ts[i] = sin(t); } else { sin_ts[i] = 10.0; } offset += postModifier; } offset = 0.0; for (int i = (int) ceil(d->guiIndex) - 1; i >= 0; --i) { if (i < lowerLimit || i > upperLimit) continue; double preModifier = d->indexPreModifiers.value(i, 0.0); double postModifier = d->indexPostModifiers.value(i, 0.0); offset += postModifier; if (preModifier >= 0.0) { double t = (i - (d->guiIndex + offset)) * t1; t = qBound(-_PI/2.0, t, _PI/2); sin_ts[i] = sin(t); } else { sin_ts[i] = 10.0; } offset += preModifier; } for (int i = 0; i < d->guiIndex; ++i) { if (i < lowerLimit || i > upperLimit) continue; double sin_t = sin_ts.at(i); if (sin_t > 1.0) continue; double opacity = 1.0; if (d->transitionTimes.contains(i) && !d->transitionTimes[i].isNull()) { opacity *= d->transitionTimes[i].elapsed() / 500.0; } if (i < lowerLimit + limitGrace) { // opacity *= (i - lowerLimit) / (double) limitGrace; // FIXME shuffle } painter.setOpacity(opacity); QPixmap image = d->images[i].isNull() ? QPixmap(":/images/pager_loading.png") : d->images[i]; QSize size = image.size(); size.scale(box, Qt::KeepAspectRatio); //double x = sin_t * (a + (w - size.width()) / 2.0) + (w - size.width()) / 2.0; // FIXME shuffle double x = w * i + (w - size.width()) / 2.0; double y = h - size.height(); QRect rect((int) x, (int) y, size.width(), size.height()); painter.drawPixmap(rect, image); painter.drawRect(rect); if (d->drawLabels) { QString label = labelAt(i); if (!label.isEmpty()) { QRect labelRect(rect.bottomLeft() + QPoint(0, radius), rect.bottomRight() + QPoint(0, 12 + radius)); QString elidedLabel = painter.fontMetrics().elidedText(label, Qt::ElideMiddle, rect.width()); painter.save(); painter.setPen(QColor(0, 0, 0)); QFontMetrics fm(painter.font()); QSize numSize = fm.boundingRect(elidedLabel).size(); double lozengeRadius = 1 + numSize.height() / 2.0; numSize += QSize(numSize.height(), 0); QRect numRect(0, 0, numSize.width() + 2, numSize.height() + 2); numRect.moveCenter(rect.center()); numRect.moveBottom(rect.bottom() + radius + 1); painter.setBrush(Qt::yellow); painter.setPen(QColor(140, 140, 0)); painter.drawRoundedRect(numRect, lozengeRadius, lozengeRadius); painter.setPen(Qt::black); painter.drawText(numRect, Qt::AlignCenter, elidedLabel); painter.restore(); } } if (d->hasAnnotation.value(i, 0) > 0) { drawAnnotationTag(&painter, rect); } if (!d->spotlightsHidden && !d->searchHits.isEmpty()) { drawSearchHits(&painter, d->searchHits.value(i, 0), rect); } painter.setOpacity(1.0); } for (int i = count() - 1; i >= d->guiIndex; --i) { if (i < lowerLimit || i > upperLimit) continue; double sin_t = sin_ts.at(i); if (sin_t > 1.0) continue; double opacity = 1.0; if (d->transitionTimes.contains(i) && !d->transitionTimes[i].isNull()) { opacity *= d->transitionTimes[i].elapsed() / 500.0; } if (i > upperLimit - limitGrace) { // opacity *= (limitGrace + i - upperLimit) / (double) limitGrace; // FIXME shuffle } painter.setOpacity(opacity); QPixmap image = d->images[i].isNull() ? QPixmap(":/images/pager_loading.png") : d->images[i]; QSize size = image.size(); size.scale(box, Qt::KeepAspectRatio); //double x = sin_t * (a + (w - size.width()) / 2.0) + (w - size.width()) / 2.0; // FIXME shuffle double x = w * i + (w - size.width()) / 2.0; double y = h - size.height(); QRect rect((int) x, (int) y, size.width(), size.height()); painter.drawPixmap(rect, image); painter.drawRect(rect); if (d->drawLabels) { QString label = labelAt(i); if (!label.isEmpty()) { QRect labelRect(rect.bottomLeft() + QPoint(0, radius), rect.bottomRight() + QPoint(0, 12 + radius)); QString elidedLabel = painter.fontMetrics().elidedText(label, Qt::ElideMiddle, labelRect.width()); painter.save(); painter.setPen(QColor(200, 200, 200)); painter.setPen(QColor(0, 0, 0)); painter.drawText(labelRect, Qt::AlignCenter, elidedLabel); painter.restore(); } } if (d->hasAnnotation.value(i, 0) > 0) { drawAnnotationTag(&painter, rect); } if (!d->spotlightsHidden && !d->searchHits.isEmpty()) { drawSearchHits(&painter, d->searchHits.value(i, 0), rect); } painter.setOpacity(1.0); } sin_ts.clear(); }
SplashScreen::SplashScreen(const QPixmap &pixmap, Qt::WindowFlags f, bool isTestNet) : QSplashScreen(pixmap, f) { setAutoFillBackground(true); // set reference point, paddings int paddingRight = 50; int paddingTop = 50; int titleVersionVSpace = 17; int titleCopyrightVSpace = 40; float fontFactor = 1.0; // define text to place QString titleText = tr("Coinaaa Core"); QString versionText = QString("Version %1").arg(QString::fromStdString(FormatFullVersion())); QString copyrightText = QChar(0xA9)+QString(" 2009-%1 ").arg(COPYRIGHT_YEAR) + QString(tr("The Bitcoin Core developers")); QString copyrightText2 = QChar(0xA9)+QString(" 2014 ") + QString(tr("Coinaaa AS")); QString testnetAddText = QString(tr("[testnet]")); // define text to place as single text object 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, 33*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-paddingRight,paddingTop,titleText); pixPaint.setFont(QFont(font, 15*fontFactor)); // if the version string is to long, reduce size fm = pixPaint.fontMetrics(); int versionTextWidth = fm.width(versionText); if(versionTextWidth > titleTextWidth+paddingRight-10) { pixPaint.setFont(QFont(font, 10*fontFactor)); titleVersionVSpace -= 5; } pixPaint.drawText(newPixmap.width()-titleTextWidth-paddingRight+2,paddingTop+titleVersionVSpace,versionText); // draw copyright stuff pixPaint.setFont(QFont(font, 10*fontFactor)); pixPaint.drawText(newPixmap.width()-titleTextWidth-paddingRight,paddingTop+titleCopyrightVSpace,copyrightText); pixPaint.drawText(newPixmap.width()-titleTextWidth-paddingRight,paddingTop+titleCopyrightVSpace+13,copyrightText2); // draw testnet string if testnet is on if(isTestNet) { QFont boldFont = QFont(font, 10*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(); }
DFileChooseInput::DFileChooseInput(QWidget *parent) : QWidget(parent) { QHBoxLayout * inputlayout = new QHBoxLayout(); edit_ = new QLineEdit(); QString style = "" "QLineEdit {" "color: #b4b4b4;" "font-size: 13px;" "border-top: 1px solid #080808;" "border-bottom: 1px solid #474747;" "border-right: 0px solid #474747;" "border-left: 1px solid #080808;" "border-top-left-radius: 3px;" "border-top-right-radius: 0;" "border-bottom-right-radius: 0;" "border-bottom-left-radius: 3px;" "background: qlineargradient(x1: 1, y1: 0, x2: 0, y2: 0," "stop: 0 rgba(0, 0, 0, 50%), stop: 1 rgba(0, 0, 0, 40%));" "}"; edit_->setStyleSheet(style); edit_->setEnabled(false); edit_->setFixedHeight(22); QPixmap pixmapfile (":/ui/images/loadfile_normal.png"); btWidth_ = pixmapfile.size().width() + 4; bt_ = new QPushButton(this); style = "QPushButton{" "border-top: 1px solid #080808;" "border-bottom: 1px solid #474747;" "border-right: 1px solid #080808;" "border-left: 1px solid #474747;" "border-top-left-radius: 0;" "border-top-right-radius: 3px;" "border-bottom-right-radius: 3px;" "border-bottom-left-radius: 0px;" "background:url(:/ui/images/loadfile_normal.png);" "}" "QPushButton:hover{" "border-top: 1px solid #080808;" "border-bottom: 1px solid #474747;" "border-right: 1px solid #080808;" "border-left: 1px solid #474747;" "border-top-left-radius: 0;" "border-top-right-radius: 3px;" "border-bottom-right-radius: 3px;" "border-bottom-left-radius: 0px;" "background:url(:/ui/images/loadfile_hover.png);" "}" "QPushButton:pressed{" "border-top: 1px solid #080808;" "border-bottom: 1px solid #474747;" "border-right: 1px solid #080808;" "border-left: 1px solid #474747;" "border-top-left-radius: 0;" "border-top-right-radius: 3px;" "border-bottom-right-radius: 3px;" "border-bottom-left-radius: 0px;" "background:url(:/ui/images/loadfile_press.png);" "}"; bt_->setStyleSheet(style); bt_->setFixedHeight(22); bt_->setFixedWidth(pixmapfile.size().width() + 4); inputlayout->setSpacing(0); inputlayout->setMargin(0); inputlayout->addWidget(edit_); inputlayout->addWidget(bt_); inputlayout->addStretch(); connect(bt_, SIGNAL(clicked()), this, SLOT(selectFile())); this->setLayout(inputlayout); }
void Core::start() { bool isNewProfile = profile.isNewProfile(); if (isNewProfile) { qDebug() << "Creating a new profile"; makeTox(QByteArray()); setStatusMessage(tr("Toxing on qTox")); setUsername(profile.getName()); } else { qDebug() << "Loading user profile"; QByteArray savedata = profile.loadToxSave(); if (savedata.isEmpty()) { emit failedToStart(); return; } makeTox(savedata); } qsrand(time(nullptr)); if (!tox) { ready = true; GUI::setEnabled(true); return; } // set GUI with user and statusmsg QString name = getUsername(); if (!name.isEmpty()) emit usernameSet(name); QString msg = getStatusMessage(); if (!msg.isEmpty()) emit statusMessageSet(msg); QString id = getSelfId().toString(); if (!id.isEmpty()) emit idSet(id); /// TODO: NOTE: This is a backwards compatibility check, /// once most people have been upgraded away from the old HistoryKeeper, remove this if (Nexus::getProfile()->isEncrypted()) checkEncryptedHistory(); loadFriends(); tox_callback_friend_request(tox, onFriendRequest, this); tox_callback_friend_message(tox, onFriendMessage, this); tox_callback_friend_name(tox, onFriendNameChange, this); tox_callback_friend_typing(tox, onFriendTypingChange, this); tox_callback_friend_status_message(tox, onStatusMessageChanged, this); tox_callback_friend_status(tox, onUserStatusChanged, this); tox_callback_friend_connection_status(tox, onConnectionStatusChanged, this); tox_callback_friend_read_receipt(tox, onReadReceiptCallback, this); tox_callback_group_invite(tox, onGroupInvite, this); tox_callback_group_message(tox, onGroupMessage, this); tox_callback_group_namelist_change(tox, onGroupNamelistChange, this); tox_callback_group_title(tox, onGroupTitleChange, this); tox_callback_group_action(tox, onGroupAction, this); tox_callback_file_chunk_request(tox, CoreFile::onFileDataCallback, this); tox_callback_file_recv(tox, CoreFile::onFileReceiveCallback, this); tox_callback_file_recv_chunk(tox, CoreFile::onFileRecvChunkCallback, this); tox_callback_file_recv_control(tox, CoreFile::onFileControlCallback, this); QPixmap pic = profile.loadAvatar(); if (!pic.isNull() && !pic.size().isEmpty()) { QByteArray data; QBuffer buffer(&data); buffer.open(QIODevice::WriteOnly); pic.save(&buffer, "PNG"); buffer.close(); setAvatar(data); } else { qDebug() << "Self avatar not found, will broadcast empty avatar to friends"; setAvatar({}); } ready = true; // If we created a new profile earlier, // now that we're ready save it and ONLY THEN broadcast the new ID. // This is useful for e.g. the profileForm that searches for saves. if (isNewProfile) { profile.saveToxSave(); emit idSet(getSelfId().toString()); } if (isReady()) GUI::setEnabled(true); process(); // starts its own timer av->start(); }
void GcWindow::paintEvent(QPaintEvent * /*event*/) { static QPixmap closeImage = QPixmap(":images/toolbar/popbutton.png"); static QPixmap aluBar = QPixmap(":images/aluBar.png"); static QPixmap aluBarDark = QPixmap(":images/aluBarDark.png"); static QPixmap aluLight = QPixmap(":images/aluLight.jpg"); static QPixmap carbon = QPixmap(":images/carbon.jpg"); static QPalette defaultPalette; // setup a painter and the area to paint QPainter painter(this); // background light gray for now? QRect all(0,0,width(),height()); painter.fillRect(all, property("color").value<QColor>()); if (contentsMargins().top() > 0) { // fill in the title bar QRect bar(0,0,width(),contentsMargins().top()); //if (contentsMargins().top() < 25) { //QColor bg; //if (property("active").toBool() == true) { //bg = GColor(CTILEBARSELECT); //painter.drawPixmap(bar, aluBar); //} else { //bg = GColor(CTILEBAR); //painter.drawPixmap(bar, aluBarDark); //} //} else { painter.setPen(Qt::darkGray); painter.drawRect(QRect(0,0,width()-1,height()-1)); //} // heading QFont font; font.setPointSize((contentsMargins().top()/2)+2); font.setWeight(QFont::Bold); painter.setFont(font); QString subtitle = property("subtitle").toString(); QString title = property("title").toString(); QString heading = subtitle != "" ? subtitle : title; // embossed... //QRect shad = bar; //shad.setY(bar.y()+2); //shad.setX(bar.x()+2); //painter.setPen(QColor(255,255,255,180)); //painter.drawText(shad, heading, Qt::AlignVCenter | Qt::AlignCenter); // pen color needs to contrast to background color QColor bgColor = property("color").value<QColor>(); QColor fgColor; if (bgColor == Qt::black) fgColor = Qt::white; else if (bgColor == Qt::white) fgColor = Qt::black; else { QColor cRGB = bgColor.convertTo(QColor::Rgb); // lets work it out.. int r = cRGB.red() < 128 ? 255 : 0; int g = cRGB.green() < 128 ? 255 : 0; int b = cRGB.blue() < 128 ? 255 : 0; fgColor = QColor(r,g,b); } painter.setPen(fgColor); painter.drawText(bar, heading, Qt::AlignVCenter | Qt::AlignCenter); // border painter.setBrush(Qt::NoBrush); if (underMouse()) { QPixmap sized = closeImage.scaled(QSize(contentsMargins().top()-6, contentsMargins().top()-6)); //painter.drawPixmap(width()-3-sized.width(), 3, sized.width(), sized.height(), sized); } else { painter.setPen(Qt::darkGray); //painter.drawRect(QRect(0,0,width()-1,height()-1)); //XXX pointless } } else { // is this a layout manager? // background light gray for now? QRect all(0,0,width(),height()); if (property("isManager").toBool() == true) { //painter.drawTiledPixmap(all, carbon); painter.fillRect(all, QColor("#B3B4BA")); } else { //painter.drawTiledPixmap(all, aluLight); } } }
inline bool isValid() { return endMark || !(pixmap.isNull() && (delay == QMOVIE_INVALID_DELAY)); }
void DeviceWidget::loadFirmware() { myDevice->verticalGroupBox_loaded->setVisible(false); myDevice->groupCustom->setVisible(false); filename = setOpenFileName(); myDevice->confirmCheckBox->setVisible(false); myDevice->confirmCheckBox->setChecked(false); if (filename.isEmpty()) { status("Empty filename", STATUSICON_FAIL); return; } QFile file(filename); if (!file.open(QIODevice::ReadOnly)) { status("Can't open file", STATUSICON_FAIL); return; } loadedFW = file.readAll(); QByteArray desc = loadedFW.right(100); QPixmap px; if (loadedFW.length() > m_dfu->devices[deviceID].SizeOfCode) { myDevice->lblCRCL->setText(tr("Can't calculate, file too big for device")); } else { myDevice->lblCRCL->setText(QString::number(DFUObject::CRCFromQBArray(loadedFW, m_dfu->devices[deviceID].SizeOfCode))); } // myDevice->lblFirmwareSizeL->setText(QString("Firmware size: ")+QVariant(loadedFW.length()).toString()+ QString(" bytes")); if (populateLoadedStructuredDescription(desc)) { myDevice->confirmCheckBox->setChecked(true); myDevice->verticalGroupBox_loaded->setVisible(true); myDevice->groupCustom->setVisible(false); if (myDevice->lblCRC->text() == myDevice->lblCRCL->text()) { myDevice->statusLabel->setText(tr("The board has the same firmware as loaded. No need to update.")); px.load(QString(":/uploader/images/warning.svg")); } else if (myDevice->lblDevName->text() != myDevice->lblBrdNameL->text()) { myDevice->statusLabel->setText(tr("WARNING: the loaded firmware is for different hardware. Do not update!")); px.load(QString(":/uploader/images/error.svg")); } else if (QDateTime::fromString(onBoardDescription.gitDate) > QDateTime::fromString(LoadedDescription.gitDate)) { myDevice->statusLabel->setText(tr("The board has newer firmware than loaded. Are you sure you want to update?")); px.load(QString(":/uploader/images/warning.svg")); } else if (!LoadedDescription.gitTag.startsWith("RELEASE", Qt::CaseSensitive)) { myDevice->statusLabel->setText(tr("The loaded firmware is untagged or custom build. Update only if it was received from a trusted source (official website or your own build).")); px.load(QString(":/uploader/images/warning.svg")); } else { myDevice->statusLabel->setText(tr("This is the tagged officially released OpenPilot firmware.")); px.load(QString(":/uploader/images/gtk-info.svg")); } } else { myDevice->statusLabel->setText(tr("WARNING: the loaded firmware was not packaged with the OpenPilot format. Do not update unless you know what you are doing.")); px.load(QString(":/uploader/images/error.svg")); myDevice->confirmCheckBox->setChecked(false); myDevice->confirmCheckBox->setVisible(true); myDevice->verticalGroupBox_loaded->setVisible(false); myDevice->groupCustom->setVisible(true); } myDevice->statusIcon->setPixmap(px); }
void TupCanvas::wakeUpLibrary() { QString graphicPath = QFileDialog::getOpenFileName (this, tr("Import a SVG file..."), QDir::homePath(), tr("Vector") + " (*.svg *.png *.jpg *.jpeg *.gif)"); if (graphicPath.isEmpty()) return; QFile f(graphicPath); QFileInfo fileInfo(f); if (graphicPath.toLower().endsWith(".svg")) { QString tag = fileInfo.fileName(); if (f.open(QIODevice::ReadOnly)) { QByteArray data = f.readAll(); f.close(); // int projectWidth = k->size.width(); // int projectHeight = k->size.height(); TupProjectRequest request = TupRequestBuilder::createLibraryRequest(TupProjectRequest::Add, tag, TupLibraryObject::Svg, TupProject::FRAMES_EDITION, data, QString(), k->scene->currentSceneIndex(), k->scene->currentLayerIndex(), k->scene->currentFrameIndex()); emit requestTriggered(&request); } } else { QString symName = fileInfo.fileName(); if (f.open(QIODevice::ReadOnly)) { QByteArray data = f.readAll(); f.close(); QPixmap *pixmap = new QPixmap(graphicPath); int picWidth = pixmap->width(); int picHeight = pixmap->height(); int projectWidth = k->size.width(); int projectHeight = k->size.height(); if (picWidth > projectWidth || picHeight > projectHeight) { QDesktopWidget desktop; QMessageBox msgBox; msgBox.setWindowTitle(tr("Information")); msgBox.setIcon(QMessageBox::Question); msgBox.setText(tr("Image is bigger than workspace.")); msgBox.setInformativeText(tr("Do you want to resize it?")); msgBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes); msgBox.setDefaultButton(QMessageBox::Ok); msgBox.show(); msgBox.move((int) (desktop.screenGeometry().width() - msgBox.width())/2, (int) (desktop.screenGeometry().height() - msgBox.height())/2); int answer = msgBox.exec(); if (answer == QMessageBox::Yes) { pixmap = new QPixmap(); QString extension = fileInfo.suffix().toUpper(); QByteArray ba = extension.toAscii(); const char* ext = ba.data(); if (pixmap->loadFromData(data, ext)) { QPixmap newpix; if (picWidth > projectWidth) newpix = QPixmap(pixmap->scaledToWidth(projectWidth, Qt::SmoothTransformation)); else newpix = QPixmap(pixmap->scaledToHeight(projectHeight, Qt::SmoothTransformation)); QBuffer buffer(&data); buffer.open(QIODevice::WriteOnly); newpix.save(&buffer, ext); } } } QString tag = symName; TupProjectRequest request = TupRequestBuilder::createLibraryRequest(TupProjectRequest::Add, tag, TupLibraryObject::Image, TupProject::FRAMES_EDITION, data, QString(), k->scene->currentSceneIndex(), k->scene->currentLayerIndex(), k->scene->currentFrameIndex()); emit requestTriggered(&request); data.clear(); } } }
void MGLES2Renderer::bindTexture(const QPixmap &pixmap, quint32 unit, const QString &uniformName) { glActiveTexture(GL_TEXTURE0 + unit); bindTexture(d_ptr->m_glContext->bindTexture(pixmap, GL_TEXTURE_2D, GL_RGBA, QGLContext::PremultipliedAlphaBindOption), pixmap.size(), unit, uniformName); //bindTexture(d_ptr->m_glContext->bindTexture(pixmap, GL_TEXTURE_2D, GL_RGBA, QGLContext::NoBindOption), pixmap.size(), unit, uniformName); }
void PlaylistLargeItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const { TrackModelItem* item = m_model->itemFromIndex( m_model->mapToSource( index ) ); Q_ASSERT( item ); QStyleOptionViewItemV4 opt = option; prepareStyleOption( &opt, index, item ); opt.text.clear(); qApp->style()->drawControl( QStyle::CE_ItemViewItem, &opt, painter ); if ( m_view->header()->visualIndex( index.column() ) > 0 ) return; QPixmap pixmap, avatar; QString artist, track, lowerText; unsigned int duration = 0; if ( item->query()->results().count() ) { artist = item->query()->results().first()->artist()->name(); track = item->query()->results().first()->track(); duration = item->query()->results().first()->duration(); } else { artist = item->query()->artist(); track = item->query()->track(); } QSize avatarSize( 32, 32 ); source_ptr source = item->query()->playedBy().first; if ( m_mode == RecentlyPlayed && !source.isNull() ) { avatar = source->avatar( Source::FancyStyle, avatarSize ); QString playtime = TomahawkUtils::ageToString( QDateTime::fromTime_t( item->query()->playedBy().second ), true ); if ( source == SourceList::instance()->getLocal() ) lowerText = QString( tr( "played %1 by you" ) ).arg( playtime ); else lowerText = QString( tr( "played %1 by %2" ) ).arg( playtime ).arg( source->friendlyName() ); } if ( m_mode == LatestAdditions && item->query()->numResults() ) { QString playtime = TomahawkUtils::ageToString( QDateTime::fromTime_t( item->query()->results().first()->modificationTime() ), true ); lowerText = QString( tr( "added %1" ) ).arg( playtime ); } if ( m_mode == LovedTracks ) lowerText = item->query()->socialActionDescription( "Love", Query::Detailed ); painter->save(); { QRect r = opt.rect.adjusted( 3, 6, 0, -6 ); // Paint Now Playing Speaker Icon if ( item->isPlaying() ) { QPixmap nowPlayingIcon = TomahawkUtils::defaultPixmap( TomahawkUtils::NowPlayingSpeaker ); QRect npr = r.adjusted( 3, r.height() / 2 - nowPlayingIcon.height() / 2, 18 - r.width(), -r.height() / 2 + nowPlayingIcon.height() / 2 ); nowPlayingIcon = TomahawkUtils::defaultPixmap( TomahawkUtils::NowPlayingSpeaker, TomahawkUtils::Original, npr.size() ); painter->drawPixmap( npr, nowPlayingIcon ); r.adjust( 22, 0, 0, 0 ); } painter->setPen( opt.palette.text().color() ); QRect pixmapRect = r.adjusted( 6, 0, -option.rect.width() + option.rect.height() - 6 + r.left(), 0 ); QRect avatarRect = r.adjusted( option.rect.width() - r.left() - 12 - avatarSize.width(), ( option.rect.height() - avatarSize.height() ) / 2 - 5, 0, 0 ); avatarRect.setSize( avatarSize ); pixmap = item->query()->cover( pixmapRect.size(), false ); if ( !pixmap ) { pixmap = TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultTrackImage, TomahawkUtils::ScaledCover, pixmapRect.size() ); } painter->drawPixmap( pixmapRect, pixmap ); if ( !avatar.isNull() ) painter->drawPixmap( avatarRect, avatar ); QFont boldFont = opt.font; boldFont.setPixelSize( 15 ); boldFont.setWeight( 99 ); QFont smallBoldFont = opt.font; smallBoldFont.setPixelSize( 12 ); smallBoldFont.setBold( true ); smallBoldFont.setWeight( 60 ); QFont smallFont = opt.font; smallFont.setPixelSize( 10 ); r.adjust( pixmapRect.width() + 12, 1, -28 - avatar.width(), 0 ); QRect leftRect = r.adjusted( 0, 0, -48, 0 ); QRect rightRect = r.adjusted( r.width() - 40, 0, 0, 0 ); painter->setFont( boldFont ); QString text = painter->fontMetrics().elidedText( track, Qt::ElideRight, leftRect.width() ); painter->drawText( leftRect, text, m_topOption ); painter->setFont( smallBoldFont ); text = painter->fontMetrics().elidedText( artist, Qt::ElideRight, leftRect.width() ); painter->drawText( leftRect.adjusted( 0, 19, 0, 0 ), text, m_topOption ); painter->setFont( smallFont ); painter->setPen( Qt::gray ); QTextDocument textDoc; textDoc.setHtml( lowerText ); textDoc.setDocumentMargin( 0 ); textDoc.setDefaultFont( painter->font() ); textDoc.setDefaultTextOption( m_bottomOption ); if ( textDoc.idealWidth() > leftRect.width() ) textDoc.setHtml( item->query()->socialActionDescription( "Love", Query::Short ) ); drawRichText( painter, leftRect, Qt::AlignBottom, textDoc ); if ( duration > 0 ) { painter->setFont( smallBoldFont ); text = painter->fontMetrics().elidedText( TomahawkUtils::timeToString( duration ), Qt::ElideRight, rightRect.width() ); painter->drawText( rightRect, text, m_centerRightOption ); } } painter->restore(); }
/** Albums have covers usually. */ void LibraryItemDelegate::drawAlbum(QPainter *painter, QStyleOptionViewItem &option, QStandardItem *item) const { /// XXX: reload cover with high resolution when one has increased coverSize (every 64px) static QImageReader imageReader; SettingsPrivate *settingsPrivate = SettingsPrivate::instance(); // Album has no picture yet bool itemHasNoIcon = item->icon().isNull(); if (itemHasNoIcon) { // Check first if an inner cover should be displayed if (item->data(Miam::DF_InternalCover).toString().isEmpty()) { QString coverPath = item->data(Miam::DF_CoverPath).toString(); if (!coverPath.isEmpty()) { // qDebug() << Q_FUNC_INFO << "loading external cover from harddrive"; imageReader.setFileName(QDir::fromNativeSeparators(coverPath)); imageReader.setScaledSize(QSize(_coverSize, _coverSize)); item->setIcon(QPixmap::fromImage(imageReader.read())); itemHasNoIcon = false; } } else { FileHelper fh(item->data(Miam::DF_InternalCover).toString()); std::unique_ptr<Cover> cover(fh.extractCover()); if (cover) { QPixmap p; if (p.loadFromData(cover->byteArray(), cover->format())) { if (!p.isNull()) { item->setIcon(p); itemHasNoIcon = false; } //} else { // qDebug() << Q_FUNC_INFO << "couldn't load data into QPixmap"; } //} else { // qDebug() << Q_FUNC_INFO << "couldn't extract inner cover"; } } } painter->save(); QRect cover; if (QGuiApplication::isLeftToRight()) { cover = QRect(option.rect.x() + 1, option.rect.y() + 1, _coverSize, _coverSize); } else { cover = QRect(option.rect.width() + 19 - _coverSize - 1, option.rect.y() + 1, _coverSize, _coverSize); } // If font size is greater than the cover, align it if (_coverSize < option.rect.height() - 2) { painter->translate(0, (option.rect.height() - 1 - _coverSize) / 2); } if (itemHasNoIcon) { if (_iconOpacity <= 0.25) { painter->setOpacity(_iconOpacity); } else { painter->setOpacity(0.25); } painter->drawPixmap(cover, QPixmap(":/icons/disc")); } else { painter->setOpacity(_iconOpacity); QPixmap p = option.icon.pixmap(QSize(_coverSize, _coverSize)); painter->drawPixmap(cover, p); } painter->restore(); // Add an icon on the right if album is from some remote location bool isRemote = item->data(Miam::DF_IsRemote).toBool(); int offsetWidth = 0; if (isRemote) { int iconSize = 31; QRect iconRemoteRect(option.rect.x() + option.rect.width() - (iconSize + 4), (option.rect.height() - iconSize)/ 2 + option.rect.y() + 2, iconSize, iconSize); QPixmap iconRemote(item->data(Miam::DF_IconPath).toString()); painter->save(); painter->setOpacity(0.5); painter->drawPixmap(iconRemoteRect, iconRemote); painter->restore(); offsetWidth = iconSize; } option.textElideMode = Qt::ElideRight; QRect rectText; // It's possible to have missing covers in your library, so we need to keep alignment. if (QGuiApplication::isLeftToRight()) { rectText = QRect(option.rect.x() + _coverSize + 5, option.rect.y(), option.rect.width() - (_coverSize + 7) - offsetWidth, option.rect.height() - 1); } else { rectText = QRect(option.rect.x(), option.rect.y(), option.rect.width() - _coverSize - 5, option.rect.height()); } QFontMetrics fmf(settingsPrivate->font(SettingsPrivate::FF_Library)); QString s = fmf.elidedText(option.text, Qt::ElideRight, rectText.width()); this->paintText(painter, option, rectText, s, item); }
QPixmap MainWindowView::scaleImage(const QPixmap &i, int max) const { if (i.width() > i.height()) return i.scaledToWidth(max); return i.scaledToHeight(max); }