void Button::setIconWithSates(const QPixmap &pixmap, IconState s1, IconState s2, IconState s3, IconState s4) { int a = pixmap.width(); int b = pixmap.height(); int count = qMax(a, b)/qMin(a, b); bool hor = pixmap.height() < pixmap.width(); QPoint dp; if (hor) { a /= count; dp.setX(a); } else { b /= count; dp.setY(b); } QRect r(0, 0, a, b); setIconForState(s1, pixmap.copy(r)); if (count > 1) { r.translate(dp); setIconForState(s2, pixmap.copy(r)); if (count > 2) { r.translate(dp); setIconForState(s3, pixmap.copy(r)); if (count > 3) { r.translate(dp); setIconForState(s4, pixmap.copy(r)); } } } setIconState(iconState(), true); //TODO: other states set to existing icon }
bool Skin::handle_balance (const QPixmap &img) { if (img.isNull ()) return false; QPixmap p; QPixmapList list; list << img.copy (9, 15, 38, 13); for (int i = 1; i < 28; i++) { // use p to make use of Qt implicit sharing (I think it will not // work if appended and prepended Images are copied seperately) p = img.copy(9, i*15, 38, 13); list.append (p); list.prepend (p); } m_pixmaplists[SLIDER_BALANCEBAR_BGS] = list; if (img.height() > 421) { const int h = qMin (11, img.height () - 422); ButtonPixmaps button; button.addPixmap (img.copy (0, 422, 14, h), ButtonPixmaps::Normal); button.addPixmap (img.copy (15, 422, 14, h), ButtonPixmaps::Pressed); m_buttons[SLIDER_BALANCEBAR_BUTTON] = button; } return true; }
//______________________________________________________________ void TileSet::initPixmap( PixmapList& pixmaps, const QPixmap &source, int width, int height, const QRect &rect) { QSize size( width, height ); if( !( size.isValid() && rect.isValid() ) ) { pixmaps.append( QPixmap() ); } else if( size != rect.size() ) { const qreal dpiRatio( devicePixelRatio( source ) ); const QRect scaledRect( rect.topLeft()*dpiRatio, rect.size()*dpiRatio ); const QSize scaledSize( size*dpiRatio ); const QPixmap tile( source.copy(scaledRect) ); QPixmap pixmap( scaledSize ); pixmap.fill(Qt::transparent); QPainter painter(&pixmap); painter.drawTiledPixmap(0, 0, scaledSize.width(), scaledSize.height(), tile); setDevicePixelRatio( pixmap, dpiRatio ); pixmaps.append( pixmap ); } else { const qreal dpiRatio( devicePixelRatio( source ) ); const QRect scaledRect( rect.topLeft()*dpiRatio, rect.size()*dpiRatio ); QPixmap pixmap( source.copy( scaledRect ) ); setDevicePixelRatio( pixmap, dpiRatio ); pixmaps.append( pixmap ); } }
bool BoardTheme::loadBoard(const QString& board) { if(board.isEmpty()) { m_boardFilename = board; updateSquares(); return true; } QString themePath = AppSettings->getBoardPath(board); QPixmap big; if(!big.load(themePath)) { return false; } int realsize = big.height() / 2; if(realsize != big.width()) { return false; } m_originalSquare[0] = big.copy(0, 0, realsize, realsize); m_originalSquare[1] = big.copy(0, realsize, realsize, realsize); m_boardFilename = themePath; updateSquares(); return true; }
void pDockWidgetTitleBar::updateStandardIcons() { const QSize size( 16, 16 ); QPixmap pixmap; QRect rect( QPoint(), iconSize() ); QTransform transform; transform.rotate( 90 ); pixmap = style()->standardIcon( QStyle::SP_ToolBarHorizontalExtensionButton, 0, widgetForAction( aOrientation ) ).pixmap( size ); rect.moveCenter( pixmap.rect().center() ); pixmap = pixmap.copy( rect ); pixmap = pixmap.transformed( transform, Qt::SmoothTransformation ); aOrientation->setIcon( pixmap ); pixmap = style()->standardIcon( QStyle::SP_TitleBarNormalButton, 0, widgetForAction( aFloat ) ).pixmap( size ); rect.moveCenter( pixmap.rect().center() ); pixmap = pixmap.copy( rect ); aFloat->setIcon( pixmap ); pixmap = style()->standardIcon( QStyle::SP_TitleBarCloseButton, 0, widgetForAction( aClose ) ).pixmap( size ); rect.moveCenter( pixmap.rect().center() ); pixmap = pixmap.copy( rect ); aClose->setIcon( pixmap ); }
MyIcon RecordingDelegate::getIcon(QPixmap pix) { MyIcon icon; int w = pix.width(); int h = pix.height(); icon.setPixmap(pix.copy(0, 0, w, h/4 ), MyIcon::Normal, MyIcon::Off); icon.setPixmap(pix.copy(0, h/4, w, h/4 ), MyIcon::MouseOver, MyIcon::Off); icon.setPixmap(pix.copy(0, h/2, w, h/4 ), MyIcon::MouseDown, MyIcon::Off); icon.setPixmap(pix.copy(0, 3*h/4, w, h/4 ), MyIcon::Disabled, MyIcon::Off); return icon; }
void PanelSeeker::setKnobIcon( QPixmap pix ) { int w = pix.width(); int h = pix.height(); knobPix.setPixmap(pix.copy(0, 0, w, h/4 ), MyIcon::Normal, MyIcon::Off); knobPix.setPixmap(pix.copy(0, h/4, w, h/4 ), MyIcon::MouseOver, MyIcon::Off); knobPix.setPixmap(pix.copy(0, h/2, w, h/4 ), MyIcon::MouseDown, MyIcon::Off); knobPix.setPixmap(pix.copy(0, 3*h/4, w, h/4 ), MyIcon::Disabled, MyIcon::Off); knobCurrentPix = knobPix.pixmap(MyIcon::Normal, MyIcon::Off); /* setSliderValue(minimum()); */ setState(Normal, true); }
bool Skin::handle_monoster (const QPixmap &img) { if (img.isNull ()) return false; m_items[MONO_1] = img.copy(29, 0, 27, 12); m_items[MONO_0] = img.copy(29, 12, 27, 12); m_items[STEREO_1] = img.copy(0, 0, 29, 12); m_items[STEREO_0] = img.copy(0, 12, 29, 12); return true; }
static void initFadeTypes (void) { if (g_fadeTypes.isEmpty()) { const QPixmap pmFadeIn(":/images/fadeIn.png"); const QPixmap pmFadeOut(":/images/fadeOut.png"); for (int i = 0; g_aFadeTypeNames[i]; ++i) { FadeTypeInfo& info = g_fadeTypes[i]; info.name = QObject::tr(g_aFadeTypeNames[i], "fadeType"); info.iconFadeIn = pmFadeIn.copy(i << 4, 0, 16, 16); info.iconFadeOut = pmFadeOut.copy(i << 4, 0, 16, 16); } } }
void ToolButton::setMultiIcon(const QPixmap &image) { int w = image.width(); int h = image.height(); m_normalIcon = image.copy(0, 0, w, h / 4); m_hoverIcon = image.copy(0, h / 4, w, h / 4); m_activeIcon = image.copy(0, h / 2, w, h / 4); m_disabledIcon = image.copy(0, 3 * h / 4, w, h / 4); m_usingMultiIcon = true; setFixedSize(m_normalIcon.size()); }
bool Skin::handle_eq_ex (const QPixmap &img) { // This method has to be called after handle_eqmain! if (img.isNull ()) return false; m_items[EQ_WIN_SHADE_ACTIVE] = img.copy (0, 0, 275, 14); m_items[EQ_WIN_SHADE_INACTIVE] = img.copy (0, 15, 275, 14); m_buttons[BUTTON_EQ_SHADE].addPixmap (img.copy ( 1, 38, 9, 9), PBPixmaps::Pressed); return true; }
void Case::transmettreAttaque(int nbPV, Entite*e) { if (m_occupant!=NULL) { if(e->Getnom() == "Chevalier" || e->Getnom() == "Archer" || e->Getnom() == "Pretre" || e->Getnom() == "Magicien" || e->Getnom() == "Voleur" || e->Getnom() == "Guerrier") m_occupant->modifierVie(nbPV + ((Unite*)e)->getBonusUnite()[1]); else { m_occupant->modifierVie(nbPV); } if (!contientBatiment()&&isOccupee() &&getOccupant()->getVie()==0){ QPixmap *tombe; tombe=new QPixmap("images/Coffin.png"); (getOccupant())->setPixmap(tombe->copy(0,96,32,32)); getOccupant()->setFlag(QGraphicsItem::ItemIsSelectable,false); setOccupant(NULL); } else if(isOccupee() && getOccupant()->Getnom()== "Chateau" && getOccupant()->getVie()==0) { QPixmap *tombe; tombe=new QPixmap("images/ChateauDetruit.png"); (getOccupant())->setPixmap(tombe->copy(0,96,32,32)); QMessageBox popup; popup.setText("Victoire " + this->getOccupant()->getJoueur()->getPseudo() + "!"); popup.exec(); this->getOccupant()->getPosition()[0]->parent()->finDuJeu(); } else if(isOccupee() && getOccupant()->Getnom() == "Tour" && getOccupant()->getVie()==0) { QPixmap *tombe; tombe=new QPixmap("images/TourDetruite.png"); (getOccupant())->setPixmap(tombe->copy(0,96,32,32)); this->parent()->supprimerTour((Batiment*)this->getOccupant()); getOccupant()->setFlag(QGraphicsItem::ItemIsSelectable,false); setOccupant(NULL); } } }
void Scene::genFrames() { QPixmap pixmap = QPixmap( QString( ":Textures/pla1.bmp" ) ); const unsigned int step = pixmap.width() / 4; QPixmap copyPixmap; for ( unsigned int i = 0; i < 4; ++i ) { copyPixmap = pixmap.copy( i * step, 0, step, step ); framesToRight.push_back( copyPixmap ); } for( unsigned int i = 0; i < framesToRight.size(); ++i ) { QImage image = framesToRight[i].toImage(); framesToLeft.push_back( QPixmap::fromImage( image.mirrored( true, false ) ) ); } for( unsigned int i = 0; i < framesToRight.size(); ++i ) { QPixmap rotatedPixmap( framesToRight[i] ); QMatrix rm; rm.rotate( 90 ); framesToDown.push_back( rotatedPixmap.transformed( rm ) ); } for( unsigned int i = 0; i < framesToDown.size(); ++i ) { QImage image = framesToDown[i].toImage(); framesToUp.push_back( QPixmap::fromImage( image.mirrored( false, true ) ) ); } }
QPixmap *BoardPixmaps::getBoardPixmap(int x, int y, double w, double h) { if (w != width || h != height) { width = w; height = h; clearPix(); } QPixmap *scPixmap = scaledPixmap.value(0, NULL); if (scPixmap == NULL) { // Масштабирование картинки под целое количество единиц ширины и высоты scPixmap = new QPixmap(); w_cnt = boardPixmap->width() / w; h_cnt = boardPixmap->height() / h; // Тут можно ограничить максимальное количество кусков //-- *scPixmap = boardPixmap->scaled(QSize(w_cnt * w, h_cnt * h), Qt::IgnoreAspectRatio, Qt::FastTransformation); scaledPixmap[0] = scPixmap; } int curr_key = (x % w_cnt) * 100 + (y % h_cnt) + 1; QPixmap *scPixmap2 = scaledPixmap.value(curr_key, NULL); if (scPixmap2 == NULL) { // Вырезаем необходимый кусок картинки scPixmap2 = new QPixmap(); int xpixpos = (x % w_cnt) * w; int ypixpos = (y % h_cnt) * h; *scPixmap2 = scPixmap->copy(xpixpos, ypixpos, w, h); scaledPixmap[curr_key] = scPixmap2; } return scPixmap2; }
QPixmap NumberChoiceLive::outlineText(QString text) { QPixmap *canvas = new QPixmap(200,200); canvas->fill(Qt::transparent); QFont font; font.setPointSize(60); font.setBold(true); QPen pen; // Give a nice black outline pen.setWidth(5); QPainterPath path; // Have to use path to get an outline path.addText(0,90, font, text); QPainter painter(canvas); // Make the outlines text painter.setBrush(QBrush(Qt::yellow)); painter.setPen(pen); painter.setRenderHint(QPainter::Antialiasing); painter.drawPath(path); painter.setFont(font); // Remove the rubbish from the image so we only have the text QRect textBounds = painter.boundingRect(canvas->rect(), 0, text); return canvas->copy(textBounds); }
QPixmap ScoresLive::outlineText(QString text) { QPixmap *canvas = new QPixmap(1000,1000); canvas->fill(Qt::transparent); QFont font; font.setPointSize(150); font.setBold(true); QFontMetrics fontMetrics(font); // So we can determine the position of the text. We use the ascent function, this gives the distance between the baseline of the text and highest point. QPen pen; // Give a nice black outline pen.setWidth(10); QPainterPath path; // Have to use path to get an outline path.addText(0,fontMetrics.ascent(), font, text); // TODO Find out why I have to minus 10 from the ascent, I'm sure it's very simple, but a task for another day I think. QPainter painter(canvas); // Make the outlines text painter.setBrush(QBrush(Qt::green)); painter.setPen(pen); painter.setRenderHint(QPainter::Antialiasing); painter.drawPath(path); painter.setFont(font); // Remove the rubbish from the image so we only have the text QRect textBounds = painter.boundingRect(canvas->rect(), 0, text); return canvas->copy(textBounds); }
void KWaitedPlayerSetupDialog::fillWaitedPlayersCombo() { kDebug() << "Filling nations combo" << endl; QList<PlayerMatrix>::iterator it, it_end; it = m_automaton->game()->waitedPlayers().begin(); it_end = m_automaton->game()->waitedPlayers().end(); for (; it != it_end; it++) { kDebug() << "Adding waited player " << (*it).name << endl; QString imgName = m_automaton->game()->theWorld()->nationNamed((*it).nation)->flagFileName(); // load image QPixmap flag; QSize size(flag.width()/Sprites::SkinSpritesData::single().intData("flag-frames"),flag.height()); QImage image(size, QImage::Format_ARGB32_Premultiplied); image.fill(0); QPainter p(&image); QSvgRenderer renderer; renderer.load(imgName); renderer.render(&p/*, svgid*/); QPixmap allpm = QPixmap::fromImage(image); flag = allpm.copy(0, 0, size.width(), size.height()); // get name QString name = (*it).name; name += QString(" ("); name += (i18n((*it).nation.toUtf8().data())); name += QString(")"); // fill a combo entry waitedPlayersCombo->addItem(QIcon(flag),name); } }
bool Skin::handle_numbers (const QPixmap &img) { // This method handles both nums_ex and the fallback numbers if (img.isNull ()) return false; const int num = (img.width () >= 9 * 12) ? 12 : 11; for (int i = 0; i < num; i++) { m_numbers[i] = img.copy (i*9, 0, 9, qMin (13, img.height ())); } m_numbers[-1] = m_numbers[10]; // add Blank space to index -1 if (num < 12) { // We do not yet have a '-' Symbol, so we create one // from the '2' character and the blank as background QPixmap pix = m_numbers[10].copy (); QRect r (3, 6, 3, 1); QPainter painter (&pix); painter.drawPixmap (r, m_numbers[2], r); m_numbers[11] = pix; } return true; }
void QPdfEngine::drawPixmap (const QRectF &rectangle, const QPixmap &pixmap, const QRectF &sr) { if (sr.isEmpty() || rectangle.isEmpty() || pixmap.isNull()) return; Q_D(QPdfEngine); QBrush b = d->brush; QRect sourceRect = sr.toRect(); QPixmap pm = sourceRect != pixmap.rect() ? pixmap.copy(sourceRect) : pixmap; QImage image = pm.toImage(); bool bitmap = true; const int object = d->addImage(image, &bitmap, pm.cacheKey()); if (object < 0) return; *d->currentPage << "q\n/GSa gs\n"; *d->currentPage << QPdf::generateMatrix(QTransform(rectangle.width() / sr.width(), 0, 0, rectangle.height() / sr.height(), rectangle.x(), rectangle.y()) * (d->simplePen ? QTransform() : d->stroker.matrix)); if (bitmap) { // set current pen as d->brush d->brush = d->pen.brush(); } setBrush(); d->currentPage->streamImage(image.width(), image.height(), object); *d->currentPage << "Q\n"; d->brush = b; }
void BitmapImage::drawPattern(GraphicsContext* ctxt, const FloatRect& tileRect, const AffineTransform& patternTransform, const FloatPoint& phase, CompositeOperator op, const FloatRect& destRect) { QPixmap* framePixmap = nativeImageForCurrentFrame(); if (!framePixmap) // If it's too early we won't have an image yet. return; QPixmap pixmap = *framePixmap; QRect tr = QRectF(tileRect).toRect(); if (tr.x() || tr.y() || tr.width() != pixmap.width() || tr.height() != pixmap.height()) { pixmap = pixmap.copy(tr); } if (patternTransform.isIdentity()) { ctxt->save(); ctxt->setCompositeOperation(op); QPainter* p = ctxt->platformContext(); p->setBrushOrigin(phase); p->drawTiledPixmap(destRect, pixmap); ctxt->restore(); } else { QBrush b(pixmap); b.setMatrix(patternTransform); ctxt->save(); ctxt->setCompositeOperation(op); QPainter* p = ctxt->platformContext(); p->setBrushOrigin(phase); p->fillRect(destRect, b); ctxt->restore(); } }
void TsEnv::createThumbnail(const QPixmap& source, int angle, const void* userData) { try { QPixmap thumbnailSource; const Qt::Axis rotationAxis(Qt::ZAxis); if ( 270 <= angle ) { thumbnailSource = source.transformed(QTransform().rotate(270.0f, rotationAxis), Qt::SmoothTransformation); } else if( 180 <= angle ) { thumbnailSource = source.transformed(QTransform().rotate(180.0f, rotationAxis), Qt::SmoothTransformation); } else if( 90 <= angle ) { thumbnailSource = source.transformed(QTransform().rotate(90.0f, rotationAxis), Qt::SmoothTransformation); } else { thumbnailSource = source; } const QRect expectedRect(0, 0, thumbnailWidth, thumbnailHeight); const QPixmap thumbanail(thumbnailSource.scaled(expectedRect.size(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation)); emit thumbnailCreated(thumbanail.copy(expectedRect), userData); } catch (...) { } }
QPixmap FX::applyAlpha(const QPixmap &toThisPix, const QPixmap &fromThisPix, const QRect &rect, const QRect &alphaRect) { QPixmap pix; int sx,sy,ax,ay,w,h; if (rect.isNull()) { sx = sy = 0; w = toThisPix.width(); h = toThisPix.height(); } else rect.getRect(&sx,&sy,&w,&h); if (alphaRect.isNull()) { ax = ay = 0; } else { ax = alphaRect.x(); ay = alphaRect.y(); w = qMin(alphaRect.width(),w); h = qMin(alphaRect.height(),h); } if (w > fromThisPix.width() || h > fromThisPix.height()) pix = QPixmap(w, h); else pix = fromThisPix.copy(0,0,w,h); // cause slow depth conversion... pix.fill(Qt::transparent); QPainter p(&pix); p.drawPixmap(0, 0, toThisPix, sx, sy, w, h); p.setCompositionMode(QPainter::CompositionMode_DestinationIn); p.drawPixmap(0, 0, fromThisPix, ax, ay, w, h); p.end(); return pix; }
void QTextDocumentExporter::writePicture(cf::CEDPicture& pic) { if(!pic.image()) { qDebug() << Q_FUNC_INFO << "empty image given"; return; } if(!page_) { qDebug() << Q_FUNC_INFO << "NULL page pointer"; return; } QPixmap pixmap; QTransform t = QTransform().rotate(page_->angle()); ImageCache::load(page_->imageURL(), &pixmap); cf::Rect r = pic.boundingRect(); pixmap = pixmap.transformed(t); pixmap = pixmap.copy(r.x(), r.y(), r.width(), r.height()); static int image_counter = 0; cursor_.insertImage(pixmap.toImage(), QString("image %1").arg(++image_counter)); // QTextFrameFormat format; // cursor_.currentFrame()->setFrameFormat(format); }
QPixmap ContainerImage::pixmap(const Image &image, const QSize &size, const AspectRatioMode &mode) { QVector2D factors = calculateFactors_(size, image.size, mode); #ifdef IMAGEMAP_DEBUG wzLog(LOG_IM) << "\tContainer:" << m_filename; wzLog(LOG_IM) << "\tMode:" << mode; wzLog(LOG_IM) << "\tFactors:" << factors; wzLog(LOG_IM) << "\tSize:" << qRound(image.size.width() * factors.x()) << qRound(image.size.height() * factors.y()); wzLog(LOG_IM) << "\tPosition:" << qRound(image.xPosition * factors.x()) << qRound(image.yPosition * factors.y()); #endif // Creates a full scaled copy of the container image with the factors. QPixmap full = createScaledContainer_(factors); // Extracts the image. QPixmap result = full.copy(qRound(image.xPosition * factors.x()), qRound(image.yPosition * factors.y()), qRound(image.size.width() * factors.x()), qRound(image.size.height() * factors.y())); return result; }
void KPixmapSequence::Private::loadSequence(const QPixmap &bigPixmap, const QSize &frameSize) { if (bigPixmap.isNull()) { qWarning() << "Invalid pixmap specified."; return; } QSize size(frameSize); if (!size.isValid()) { size = QSize(bigPixmap.width(), bigPixmap.width()); } if (bigPixmap.width() % size.width() || bigPixmap.height() % size.height()) { qWarning() << "Invalid framesize."; return; } const int rowCount = bigPixmap.height() / size.height(); const int colCount = bigPixmap.width() / size.width(); mFrames.resize(rowCount * colCount); int pos = 0; for (int row = 0; row < rowCount; ++row) { for (int col = 0; col < colCount; ++col) { QPixmap pix = bigPixmap.copy(col * size.width(), row * size.height(), size.width(), size.height()); mFrames[pos++] = pix; } } }
PixmapButton::PixmapButton(const QPixmap& composite,const QRect& offCoords,const QRect& pressedCoords) { m_isToggleButton = true; m_offPixmap = composite.copy(offCoords); m_pressedPixmap = composite.copy(pressedCoords); m_active = false; m_pressed = false; prepareGeometryChange(); m_bounds = QRectF(0, 0, m_pressedPixmap.width(), m_pressedPixmap.height()); setPixmap(m_offPixmap); m_pExpandedHitTarget = 0; }
void Image::drawPattern(GraphicsContext* ctxt, const FloatRect& tileRect, const TransformationMatrix& patternTransform, const FloatPoint& phase, CompositeOperator op, const FloatRect& destRect) { QPixmap* framePixmap = nativeImageForCurrentFrame(); if (!framePixmap) // If it's too early we won't have an image yet. return; QPixmap pixmap = *framePixmap; QRect tr = QRectF(tileRect).toRect(); if (tr.x() || tr.y() || tr.width() != pixmap.width() || tr.height() != pixmap.height()) pixmap = pixmap.copy(tr); QBrush b(pixmap); b.setTransform(patternTransform); ctxt->save(); ctxt->setCompositeOperation(op); QPainter* p = ctxt->platformContext(); if (!pixmap.hasAlpha() && p->compositionMode() == QPainter::CompositionMode_SourceOver) p->setCompositionMode(QPainter::CompositionMode_Source); p->setBrushOrigin(phase); p->fillRect(destRect, b); ctxt->restore(); if (imageObserver()) imageObserver()->didDraw(this); }
QPixmap FX::tint(const QPixmap &mask, const QColor &color) { QPixmap pix = mask.copy(); pix.fill(Qt::transparent); #ifndef QT_NO_XRENDER if (useRender) { Q2XRenderColor(c, color); OXPicture tnt = createFill (dpy, &c); if (tnt == X::None) return pix; XRenderComposite( dpy, PictOpOver, tnt, mask.x11PictureHandle(), pix.x11PictureHandle(), 0, 0, 0, 0, 0, 0, mask.width(), mask.height()); XRenderFreePicture (dpy, tnt); } else #endif { QPainter p(&pix); p.setPen(Qt::NoPen); p.setBrush(color); p.drawRect(pix.rect()); p.end(); pix = FX::applyAlpha(pix, mask); } return pix; }
QPixmap IQSanComponentSkin::getPixmap(const QString &key, const QString &arg, bool cache) const { // the order of attempts are: // 1. if no arg, then just use key to find fileName. // 2. try key.arg(arg), if exists, then return the pixmap // 3. try key.arg(default), get fileName, and try fileName.arg(arg) QString totalKey; QString groupKey; QString fileName; QRect clipRegion; QSize scaleRegion; bool clipping = false; bool scaled = false; // case 1 and 2 if (arg.isNull()) totalKey = key; else totalKey = key.arg(arg); if (isImageKeyDefined(totalKey)) { // read from config file fileName = _readImageConfig(totalKey, clipRegion, clipping, scaleRegion, scaled); } else { // case 3: use default Q_ASSERT(!arg.isNull()); groupKey = key.arg(S_SKIN_KEY_DEFAULT); QString fileNameToResolve = _readImageConfig(groupKey, clipRegion, clipping, scaleRegion, scaled); fileName = fileNameToResolve.arg(arg); if (!QFile::exists(fileName)) { groupKey = key.arg(S_SKIN_KEY_DEFAULT_SECOND); QString fileNameToResolve = _readImageConfig(groupKey, clipRegion, clipping, scaleRegion, scaled); fileName = fileNameToResolve.arg(arg); } } // Hero skin? QString general_name = fileName.split("/").last().split(".").first(); if (Sanguosha->getGeneral(general_name)) { int skin_index = Config.value(QString("HeroSkin/%1").arg(general_name), 0).toInt(); if (skin_index > 0) { fileName.replace("image/", "image/heroskin/"); fileName.replace(general_name, QString("%1_%2").arg(general_name).arg(skin_index)); } } QPixmap pixmap = getPixmapFromFileName(fileName, cache); if (clipping) { QRect actualClip = clipRegion; if (actualClip.right() > pixmap.width()) actualClip.setRight(pixmap.width()); if (actualClip.bottom() > pixmap.height()) actualClip.setBottom(pixmap.height()); QPixmap clipped = QPixmap(clipRegion.size()); clipped.fill(Qt::transparent); QPainter painter(&clipped); painter.drawPixmap(0, 0, pixmap.copy(actualClip)); if (scaled) clipped = clipped.scaled(scaleRegion, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); pixmap = clipped; } return pixmap; }
QIcon CountryField::icon(const QString &code, const QPixmap &layout) { QPoint point = pos(code); if (point.isNull()) return QIcon(); return QIcon(layout.copy(point.x(), point.y(), 16, 11)); }