void TitleWidget::updateCounter() { if (!Adaptive::OneColumn() || !MTP::authedId()) return; int32 counter = App::histories().unreadBadge(); bool muted = App::histories().unreadOnlyMuted(); style::color bg = muted ? st::counterMuteBG : st::counterBG; if (counter > 0) { int32 size = cRetina() ? -32 : -16; switch (cScale()) { case dbisOneAndQuarter: size = -20; break; case dbisOneAndHalf: size = -24; break; case dbisTwo: size = -32; break; } _counter = App::pixmapFromImageInPlace(App::wnd()->iconWithCounter(size, counter, bg, false)); _counter.setDevicePixelRatio(cRetinaFactor()); update(QRect(st::titleCounterPosition, _counter.size() / cIntRetinaFactor())); } else { if (!_counter.isNull()) { update(QRect(st::titleCounterPosition, _counter.size() / cIntRetinaFactor())); _counter = QPixmap(); } } }
bool Float::fillFrame() { auto creating = _frame.isNull(); if (creating) { _frame = QImage(getInnerRect().size() * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied); _frame.setDevicePixelRatio(cRetinaFactor()); } auto frameInner = [this] { return QRect(0, 0, _frame.width() / cIntRetinaFactor(), _frame.height() / cIntRetinaFactor()); }; if (auto reader = getReader()) { updatePlayback(); auto frame = reader->current(); if (!frame.isNull()) { _frame.fill(Qt::transparent); Painter p(&_frame); PainterHighQualityEnabler hq(p); p.drawPixmap(frameInner(), frame); return true; } } if (creating) { _frame.fill(Qt::transparent); Painter p(&_frame); PainterHighQualityEnabler hq(p); p.setPen(Qt::NoPen); p.setBrush(st::imageBg); p.drawEllipse(frameInner()); } return false; }
void PhotoCropBox::init(const QImage &img, PeerData *peer) { if (peerIsChat(_peerId) || (peer && peer->isMegagroup())) { _title = lang(lng_create_group_crop); } else if (peerIsChannel(_peerId)) { _title = lang(lng_create_channel_crop); } else { _title = lang(lng_settings_crop_profile); } connect(&_done, SIGNAL(clicked()), this, SLOT(onSend())); connect(&_cancel, SIGNAL(clicked()), this, SLOT(onClose())); if (peerToBareInt(_peerId)) { connect(this, SIGNAL(ready(const QImage&)), this, SLOT(onReady(const QImage&))); } int32 s = st::boxWideWidth - st::boxPhotoPadding.left() - st::boxPhotoPadding.right(); _thumb = App::pixmapFromImageInPlace(img.scaled(s * cIntRetinaFactor(), s * cIntRetinaFactor(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); _thumb.setDevicePixelRatio(cRetinaFactor()); _thumbw = _thumb.width() / cIntRetinaFactor(); _thumbh = _thumb.height() / cIntRetinaFactor(); if (_thumbw > _thumbh) { _cropw = _thumbh - 20; } else { _cropw = _thumbw - 20; } _cropx = (_thumbw - _cropw) / 2; _cropy = (_thumbh - _cropw) / 2; _thumbx = (st::boxWideWidth - _thumbw) / 2; _thumby = st::boxPhotoPadding.top(); setMouseTracking(true); resizeMaxHeight(st::boxWideWidth, st::boxPhotoPadding.top() + _thumbh + st::boxPhotoPadding.bottom() + st::boxTextFont->height + st::cropSkip + st::boxButtonPadding.top() + _done.height() + st::boxButtonPadding.bottom()); }
void paintUnreadBadge(Painter &p, const QRect &rect, const UnreadBadgeStyle &st) { t_assert(rect.height() == st.size); int index = (st.muted ? 0x03 : 0x00) + (st.active ? 0x02 : (st.selected ? 0x01 : 0x00)); int size = st.size, sizehalf = size / 2; unreadBadgeStyle.createIfNull(); auto badgeData = unreadBadgeStyle->sizes; if (st.sizeId > 0) { t_assert(st.sizeId < UnreadBadgeSizesCount); badgeData = &unreadBadgeStyle->sizes[st.sizeId]; } auto bg = unreadBadgeStyle->bg[index]; if (badgeData->left[index].isNull()) { int imgsize = size * cIntRetinaFactor(), imgsizehalf = sizehalf * cIntRetinaFactor(); createCircleMask(badgeData, size); badgeData->left[index] = App::pixmapFromImageInPlace(colorizeCircleHalf(badgeData, imgsize, imgsizehalf, 0, bg)); badgeData->right[index] = App::pixmapFromImageInPlace(colorizeCircleHalf(badgeData, imgsize, imgsizehalf, imgsize - imgsizehalf, bg)); } int bar = rect.width() - 2 * sizehalf; p.drawPixmap(rect.x(), rect.y(), badgeData->left[index]); if (bar) { p.fillRect(rect.x() + sizehalf, rect.y(), bar, rect.height(), bg); } p.drawPixmap(rect.x() + sizehalf + bar, rect.y(), badgeData->right[index]); }
QPixmap ItemBase::getResultContactAvatar(int width, int height) const { if (_result->_type == Result::Type::Contact) { auto result = EmptyUserpic(qHash(_result->_id) % kUserColorsCount, _result->getLayoutTitle()).generate(width); if (result.height() != height * cIntRetinaFactor()) { result = result.scaled(QSize(width, height) * cIntRetinaFactor(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); } return result; } return QPixmap(); }
RippleAnimation::Ripple::Ripple(const style::RippleAnimation &st, const QPixmap &mask, Fn<void()> update) : _st(st) , _update(update) , _origin(mask.width() / (2 * cIntRetinaFactor()), mask.height() / (2 * cIntRetinaFactor())) , _radiusFrom(mask.width() + mask.height()) , _frame(mask.size(), QImage::Format_ARGB32_Premultiplied) { _frame.setDevicePixelRatio(mask.devicePixelRatio()); _radiusTo = _radiusFrom; _hide.start(_update, 0., 1., _st.hideDuration); }
void InputField::insertEmoji(EmojiPtr emoji, QTextCursor c) { QTextImageFormat imageFormat; int32 ew = ESize + st::emojiPadding * cIntRetinaFactor() * 2, eh = _st->font->height * cIntRetinaFactor(); imageFormat.setWidth(ew / cIntRetinaFactor()); imageFormat.setHeight(eh / cIntRetinaFactor()); imageFormat.setName(qsl("emoji://e.") + QString::number(emojiKey(emoji), 16)); imageFormat.setVerticalAlignment(QTextCharFormat::AlignBaseline); static QString objectReplacement(QChar::ObjectReplacementCharacter); c.insertText(objectReplacement, imageFormat); }
void FlatTextarea::insertEmoji(EmojiPtr emoji, QTextCursor c) { c.removeSelectedText(); QPixmap img(App::emojiSingle(emoji, _st.font->height)); QString url = qsl("emoji://e.") + QString::number(emojiKey(emoji), 16); document()->addResource(QTextDocument::ImageResource, QUrl(url), QVariant(img)); QTextImageFormat imageFormat; imageFormat.setWidth(img.width() / cIntRetinaFactor()); imageFormat.setHeight(img.height() / cIntRetinaFactor()); imageFormat.setName(url); imageFormat.setVerticalAlignment(QTextCharFormat::AlignBaseline); c.insertImage(imageFormat); }
void HistoryPhoto::validateGroupedCache( const QRect &geometry, RectParts corners, not_null<uint64*> cacheKey, not_null<QPixmap*> cache) const { using Option = Images::Option; const auto loaded = _data->loaded(); const auto loadLevel = loaded ? 2 : (_data->thumbnailInline() || _data->thumbnail()->loaded() || _data->thumbnailSmall()->loaded()) ? 1 : 0; const auto width = geometry.width(); const auto height = geometry.height(); const auto options = Option::Smooth | Option::RoundedLarge | (loaded ? Option::None : Option::Blurred) | ((corners & RectPart::TopLeft) ? Option::RoundedTopLeft : Option::None) | ((corners & RectPart::TopRight) ? Option::RoundedTopRight : Option::None) | ((corners & RectPart::BottomLeft) ? Option::RoundedBottomLeft : Option::None) | ((corners & RectPart::BottomRight) ? Option::RoundedBottomRight : Option::None); const auto key = (uint64(width) << 48) | (uint64(height) << 32) | (uint64(options) << 16) | (uint64(loadLevel)); if (*cacheKey == key) { return; } const auto originalWidth = ConvertScale(_data->width()); const auto originalHeight = ConvertScale(_data->height()); const auto pixSize = Ui::GetImageScaleSizeForGeometry( { originalWidth, originalHeight }, { width, height }); const auto pixWidth = pixSize.width() * cIntRetinaFactor(); const auto pixHeight = pixSize.height() * cIntRetinaFactor(); const auto image = loaded ? _data->large().get() : _data->thumbnail()->loaded() ? _data->thumbnail().get() : _data->thumbnailSmall()->loaded() ? _data->thumbnailSmall().get() : _data->thumbnailInline() ? _data->thumbnailInline() : Image::BlankMedia().get(); *cacheKey = key; *cache = image->pixNoCache(_realParent->fullId(), pixWidth, pixHeight, options, width, height); }
void StickerPreviewWidget::paintEvent(QPaintEvent *e) { Painter p(this); QRect r(e->rect()); const QPixmap &draw(currentImage()); uint32 w = draw.width() / cIntRetinaFactor(), h = draw.height() / cIntRetinaFactor(); if (_a_shown.animating()) { float64 shown = a_shown.current(); p.setOpacity(shown); // w = qMax(qRound(w * (st::stickerPreviewMin + ((1. - st::stickerPreviewMin) * shown)) / 2.) * 2 + int(w % 2), 1); // h = qMax(qRound(h * (st::stickerPreviewMin + ((1. - st::stickerPreviewMin) * shown)) / 2.) * 2 + int(h % 2), 1); } p.fillRect(r, st::stickerPreviewBg); p.drawPixmap((width() - w) / 2, (height() - h) / 2, draw); }
void RoundImageCheckbox::prepareWideCheckIconCache(Icon *icon) { auto cacheWidth = _wideCheckBgCache.width() / _wideCheckBgCache.devicePixelRatio(); auto cacheHeight = _wideCheckBgCache.height() / _wideCheckBgCache.devicePixelRatio(); auto wideCache = QImage(cacheWidth * cIntRetinaFactor(), cacheHeight * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied); wideCache.setDevicePixelRatio(cRetinaFactor()); { Painter p(&wideCache); p.setCompositionMode(QPainter::CompositionMode_Source); auto iconRadius = kWideScale * _st.checkRadius; auto divider = qRound((kWideScale - 2) * _st.checkRadius + icon->fadeIn.current(1.) * (kWideScale - 1) * _st.checkRadius); p.drawPixmapLeft(QRect(0, 0, divider, iconRadius * 2), cacheWidth, _wideCheckFullCache, QRect(0, 0, divider * cIntRetinaFactor(), _wideCheckFullCache.height())); p.drawPixmapLeft(QRect(divider, 0, iconRadius * 2 - divider, iconRadius * 2), cacheWidth, _wideCheckBgCache, QRect(divider * cIntRetinaFactor(), 0, _wideCheckBgCache.width() - divider * cIntRetinaFactor(), _wideCheckBgCache.height())); } icon->wideCheckCache = App::pixmapFromImageInPlace(std_::move(wideCache)); icon->wideCheckCache.setDevicePixelRatio(cRetinaFactor()); }
void RoundImageCheckbox::prepareWideCache() { if (_wideCache.isNull()) { auto size = _st.imageRadius * 2; auto wideSize = size * kWideScale; QImage cache(wideSize * cIntRetinaFactor(), wideSize * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied); cache.setDevicePixelRatio(cRetinaFactor()); { Painter p(&cache); p.setCompositionMode(QPainter::CompositionMode_Source); p.fillRect(0, 0, wideSize, wideSize, Qt::transparent); p.setCompositionMode(QPainter::CompositionMode_SourceOver); _paintRoundImage(p, (wideSize - size) / 2, (wideSize - size) / 2, wideSize, size); } _wideCache = App::pixmapFromImageInPlace(std_::move(cache)); } }
void NewAvatarButton::setImage(const QImage &image) { auto small = image.scaled(size() * cIntRetinaFactor(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); Images::prepareCircle(small); _image = App::pixmapFromImageInPlace(std::move(small)); _image.setDevicePixelRatio(cRetinaFactor()); update(); }
void SlideAnimation::paintFrame(Painter &p, int x, int y, int outerWidth) { auto dt = _animation.value(1.); if (!animating()) return; auto easeOut = anim::easeOutCirc(1., dt); auto easeIn = anim::easeInCirc(1., dt); auto arrivingAlpha = easeIn; auto departingAlpha = 1. - easeOut; auto leftCoord = (_slideLeft ? anim::interpolate(-_leftSnapshotWidth, 0, easeOut) : anim::interpolate(0, -_leftSnapshotWidth, easeIn)); auto leftAlpha = (_slideLeft ? arrivingAlpha : departingAlpha); auto rightCoord = (_slideLeft ? anim::interpolate(0, _rightSnapshotWidth, easeIn) : anim::interpolate(_rightSnapshotWidth, 0, easeOut)); auto rightAlpha = (_slideLeft ? departingAlpha : arrivingAlpha); if (_overflowHidden) { auto leftWidth = (_leftSnapshotWidth + leftCoord); if (leftWidth > 0) { p.setOpacity(leftAlpha); p.drawPixmap(x, y, leftWidth, _leftSnapshotHeight, _leftSnapshot, (_leftSnapshot.width() - leftWidth * cIntRetinaFactor()), 0, leftWidth * cIntRetinaFactor(), _leftSnapshot.height()); } auto rightWidth = _rightSnapshotWidth - rightCoord; if (rightWidth > 0) { p.setOpacity(rightAlpha); p.drawPixmap(x + rightCoord, y, _rightSnapshot, 0, 0, rightWidth * cIntRetinaFactor(), _rightSnapshot.height()); } } else { p.setOpacity(leftAlpha); p.drawPixmap(x + leftCoord, y, _leftSnapshot); p.setOpacity(rightAlpha); p.drawPixmap(x + rightCoord, y, _rightSnapshot); } }
void PopupMenu::startShowAnimation() { if (!_useTransparency) { _a_show.finish(); update(); return; } if (!_a_show.animating()) { auto opacityAnimation = base::take(_a_opacity); showChildren(); auto cache = grabForPanelAnimation(); _a_opacity = base::take(opacityAnimation); _showAnimation = std::make_unique<PanelAnimation>(_st.animation, _origin); _showAnimation->setFinalImage(std::move(cache), QRect(_inner.topLeft() * cIntRetinaFactor(), _inner.size() * cIntRetinaFactor())); if (_useTransparency) { auto corners = App::cornersMask(ImageRoundRadius::Small); _showAnimation->setCornerMasks(QImage(*corners[0]), QImage(*corners[1]), QImage(*corners[2]), QImage(*corners[3])); } else { _showAnimation->setSkipShadow(true); } _showAnimation->start(); } hideChildren(); _a_show.start([this] { showAnimationCallback(); }, 0., 1., _st.showDuration); }
void ReplyPreview::prepare( not_null<Image*> image, FileOrigin origin, Images::Options options) { int w = image->width(), h = image->height(); if (w <= 0) w = 1; if (h <= 0) h = 1; auto thumbSize = (w > h) ? QSize( w * st::msgReplyBarSize.height() / h, st::msgReplyBarSize.height()) : QSize( st::msgReplyBarSize.height(), h * st::msgReplyBarSize.height() / w); thumbSize *= cIntRetinaFactor(); const auto prepareOptions = Images::Option::Smooth | Images::Option::TransparentBackground | options; auto outerSize = st::msgReplyBarSize.height(); auto bitmap = image->pixNoCache( origin, thumbSize.width(), thumbSize.height(), prepareOptions, outerSize, outerSize); _data = std::make_unique<ReplyPreview::Data>( std::make_unique<Images::ImageSource>( bitmap.toImage(), "PNG"), ((options & Images::Option::Blurred) == 0)); }
QSize StickerPreviewWidget::currentDimensions() const { if (!_doc) return QSize(_cache.width() / cIntRetinaFactor(), _cache.height() / cIntRetinaFactor()); QSize result(qMax(convertScale(_doc->dimensions.width()), 1), qMax(convertScale(_doc->dimensions.height()), 1)); if (gif() && _gif->ready()) { result = QSize(qMax(convertScale(_gif->width()), 1), qMax(convertScale(_gif->height()), 1)); } if (result.width() > st::maxStickerSize) { result.setHeight(qMax(qRound((st::maxStickerSize * result.height()) / result.width()), 1)); result.setWidth(st::maxStickerSize); } if (result.height() > st::maxStickerSize) { result.setWidth(qMax(qRound((st::maxStickerSize * result.width()) / result.height()), 1)); result.setHeight(st::maxStickerSize); } return result; }
void BackgroundInner::gotWallpapers(const MTPVector<MTPWallPaper> &result) { App::WallPapers wallpapers; wallpapers.push_back(App::WallPaper(0, ImagePtr(st::msgBG0), ImagePtr(st::msgBG0))); const QVector<MTPWallPaper> &v(result.c_vector().v); for (int i = 0, l = v.size(); i < l; ++i) { const MTPWallPaper w(v.at(i)); switch (w.type()) { case mtpc_wallPaper: { const MTPDwallPaper &d(w.c_wallPaper()); const QVector<MTPPhotoSize> &sizes(d.vsizes.c_vector().v); const MTPPhotoSize *thumb = 0, *full = 0; int32 thumbLevel = -1, fullLevel = -1; for (QVector<MTPPhotoSize>::const_iterator j = sizes.cbegin(), e = sizes.cend(); j != e; ++j) { char size = 0; int32 w = 0, h = 0; switch (j->type()) { case mtpc_photoSize: { const string &s(j->c_photoSize().vtype.c_string().v); if (s.size()) size = s[0]; w = j->c_photoSize().vw.v; h = j->c_photoSize().vh.v; } break; case mtpc_photoCachedSize: { const string &s(j->c_photoCachedSize().vtype.c_string().v); if (s.size()) size = s[0]; w = j->c_photoCachedSize().vw.v; h = j->c_photoCachedSize().vh.v; } break; } if (!size || !w || !h) continue; int32 newThumbLevel = qAbs((st::backgroundSize.width() * cIntRetinaFactor()) - w), newFullLevel = qAbs(2560 - w); if (thumbLevel < 0 || newThumbLevel < thumbLevel) { thumbLevel = newThumbLevel; thumb = &(*j); } if (fullLevel < 0 || newFullLevel < fullLevel) { fullLevel = newFullLevel; full = &(*j); } } if (thumb && full && full->type() != mtpc_photoSizeEmpty) { wallpapers.push_back(App::WallPaper(d.vid.v ? d.vid.v : INT_MAX, App::image(*thumb), App::image(*full))); } } break; case mtpc_wallPaperSolid: { const MTPDwallPaperSolid &d(w.c_wallPaperSolid()); } break; } } App::cSetServerBackgrounds(wallpapers); updateWallpapers(); }
void HistoryVideo::validateGroupedCache( const QRect &geometry, RectParts corners, not_null<uint64*> cacheKey, not_null<QPixmap*> cache) const { using Option = Images::Option; const auto good = _data->goodThumbnail(); const auto useGood = (good && good->loaded()); const auto image = useGood ? good : _data->thumb.get(); if (good && !useGood) { good->load({}); } const auto loaded = useGood ? true : _data->thumb->loaded(); const auto loadLevel = loaded ? 1 : 0; const auto width = geometry.width(); const auto height = geometry.height(); const auto options = Option::Smooth | Option::RoundedLarge | (useGood ? Option(0) : Option::Blurred) | ((corners & RectPart::TopLeft) ? Option::RoundedTopLeft : Option::None) | ((corners & RectPart::TopRight) ? Option::RoundedTopRight : Option::None) | ((corners & RectPart::BottomLeft) ? Option::RoundedBottomLeft : Option::None) | ((corners & RectPart::BottomRight) ? Option::RoundedBottomRight : Option::None); const auto key = (uint64(width) << 48) | (uint64(height) << 32) | (uint64(options) << 16) | (uint64(loadLevel)); if (*cacheKey == key) { return; } const auto originalWidth = ConvertScale(_data->thumb->width()); const auto originalHeight = ConvertScale(_data->thumb->height()); const auto pixSize = Ui::GetImageScaleSizeForGeometry( { originalWidth, originalHeight }, { width, height }); const auto pixWidth = pixSize.width() * cIntRetinaFactor(); const auto pixHeight = pixSize.height() * cIntRetinaFactor(); *cacheKey = key; *cache = image->pixNoCache(_realParent->fullId(), pixWidth, pixHeight, options, width, height); }
QPixmap SendButton::grabContent() { auto result = QImage(kWideScale * size() * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied); result.setDevicePixelRatio(cRetinaFactor()); result.fill(Qt::transparent); { Painter p(&result); p.drawPixmap((kWideScale - 1) / 2 * width(), (kWideScale - 1) / 2 * height(), myGrab(this)); } return App::pixmapFromImageInPlace(std::move(result)); }
void LocationManager::init() { if (manager) delete manager; manager = new QNetworkAccessManager(); App::setProxySettings(*manager); connect(manager, SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)), this, SLOT(onFailed(QNetworkReply*))); #ifndef OS_MAC_OLD connect(manager, SIGNAL(sslErrors(QNetworkReply*, const QList<QSslError>&)), this, SLOT(onFailed(QNetworkReply*))); #endif // OS_MAC_OLD connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(onFinished(QNetworkReply*))); if (notLoadedPlaceholder) { delete notLoadedPlaceholder->v(); delete notLoadedPlaceholder; } auto data = QImage(cIntRetinaFactor(), cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied); data.fill(st::white->c); data.setDevicePixelRatio(cRetinaFactor()); notLoadedPlaceholder = new ImagePtr(App::pixmapFromImageInPlace(std_::move(data)), "GIF"); }
void PhotoSendBox::paintEvent(QPaintEvent *e) { QPainter p(this); p.setOpacity(a_opacity.current()); // fill bg p.fillRect(QRect(QPoint(0, 0), size()), st::boxBG->b); // paint shadows p.fillRect(0, _height - st::btnSelectCancel.height - st::scrollDef.bottomsh, _width, st::scrollDef.bottomsh, st::scrollDef.shColor->b); // paint button sep p.fillRect(st::btnSelectCancel.width, _height - st::btnSelectCancel.height, st::lineWidth, st::btnSelectCancel.height, st::btnSelectSep->b); p.setFont(st::boxFont->f); p.setPen(st::boxGrayTitle->p); if (_img && _img->type == ToPreparePhoto) { p.drawText(QRect(st::boxPadding.left(), st::boxPadding.top(), _width - st::boxPadding.left() - st::boxPadding.right(), st::boxFont->height), lang(lng_really_send_image), style::al_center); p.drawPixmap((_width - _thumbw) / 2, st::boxPadding.top() * 2 + st::boxFont->height, _thumb); } else { p.drawText(QRect(st::boxPadding.left(), st::boxPadding.top(), _width - st::boxPadding.left() - st::boxPadding.right(), st::boxFont->height), lang(_img ? lng_really_send_file : lng_really_share_contact), style::al_center); int32 w = _width - st::boxPadding.left() - st::boxPadding.right(), h = st::mediaPadding.top() + st::mediaThumbSize + st::mediaPadding.bottom(); int32 tleft = st::mediaPadding.left() + st::mediaThumbSize + st::mediaPadding.right(); int32 twidth = w - tleft - st::mediaPadding.right(); if (twidth > _textw) { w -= (twidth - _textw); twidth = _textw; } int32 x = (_width - w) / 2, y = st::boxPadding.top() * 2 + st::boxFont->height; p.fillRect(QRect(x, y, w, h), st::msgOutBG->b); p.fillRect(x, y + h, w, st::msgShadow, st::msgOutShadow->b); if (_thumbw) { int32 rf(cIntRetinaFactor()); p.drawPixmap(QPoint(x + st::mediaPadding.left(), y + st::mediaPadding.top()), _thumb, QRect(_thumbx * rf, _thumby * rf, st::mediaThumbSize * rf, st::mediaThumbSize * rf)); } else if (_img) { p.drawPixmap(QPoint(x + st::mediaPadding.left(), y + st::mediaPadding.top()), App::sprite(), st::mediaDocOutImg); } else { p.drawPixmap(x + st::mediaPadding.left(), y + st::mediaPadding.top(), userDefPhoto(1)->pix(st::mediaThumbSize)); } p.setFont(st::mediaFont->f); p.setPen(st::black->c); if (twidth < _namew) { p.drawText(x + tleft, y + st::mediaPadding.top() + st::mediaNameTop + st::mediaFont->ascent, st::mediaFont->m.elidedText(_name, Qt::ElideRight, twidth)); } else { p.drawText(x + tleft, y + st::mediaPadding.top() + st::mediaNameTop + st::mediaFont->ascent, _name); } p.setPen(st::mediaOutColor->p); p.drawText(x + tleft, y + st::mediaPadding.top() + st::mediaThumbSize - st::mediaDetailsShift - st::mediaFont->descent, _size); } }
RippleAnimation::Ripple::Ripple(const style::RippleAnimation &st, QPoint origin, int startRadius, const QPixmap &mask, Fn<void()> update) : _st(st) , _update(update) , _origin(origin) , _radiusFrom(startRadius) , _frame(mask.size(), QImage::Format_ARGB32_Premultiplied) { _frame.setDevicePixelRatio(mask.devicePixelRatio()); QPoint points[] = { { 0, 0 }, { _frame.width() / cIntRetinaFactor(), 0 }, { _frame.width() / cIntRetinaFactor(), _frame.height() / cIntRetinaFactor() }, { 0, _frame.height() / cIntRetinaFactor() }, }; for (auto point : points) { accumulate_max(_radiusTo, style::point::dotProduct(_origin - point, _origin - point)); } _radiusTo = qRound(sqrt(_radiusTo)); _show.start(_update, 0., 1., _st.showDuration, anim::easeOutQuint); }
const QPixmap &Image::pixBlurred(int32 w, int32 h) const { restore(); checkload(); if (w <= 0 || !width() || !height()) { w = width() * cIntRetinaFactor(); } else if (cRetina()) { w *= cIntRetinaFactor(); h *= cIntRetinaFactor(); } uint64 k = 0x8000000000000000L | (uint64(w) << 32) | uint64(h); Sizes::const_iterator i = _sizesCache.constFind(k); if (i == _sizesCache.cend()) { QPixmap p(pixBlurredNoCache(w, h)); if (cRetina()) p.setDevicePixelRatio(cRetinaFactor()); i = _sizesCache.insert(k, p); if (!p.isNull()) { globalAquiredSize += int64(p.width()) * p.height() * 4; } } return i.value(); }
void RippleAnimation::paint(QPainter &p, int x, int y, int outerWidth, const QColor *colorOverride) { if (_ripples.empty()) { return; } if (rtl()) x = outerWidth - x - (_mask.width() / cIntRetinaFactor()); p.translate(x, y); for (const auto &ripple : _ripples) { ripple->paint(p, _mask, colorOverride); } p.translate(-x, -y); clearFinished(); }
QPixmap PeerData::genUserpicRounded(int size) const { if (auto userpic = currentUserpic()) { return userpic->pixRounded(size, size, ImageRoundRadius::Small); } auto result = QImage(QSize(size, size) * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied); result.setDevicePixelRatio(cRetinaFactor()); result.fill(Qt::transparent); { Painter p(&result); paintUserpicRounded(p, 0, 0, size); } return App::pixmapFromImageInPlace(std::move(result)); }
QSize MediaPreviewWidget::currentDimensions() const { if (!_cachedSize.isEmpty()) { return _cachedSize; } if (!_document && !_photo) { _cachedSize = QSize(_cache.width() / cIntRetinaFactor(), _cache.height() / cIntRetinaFactor()); return _cachedSize; } QSize result, box; if (_photo) { result = QSize(_photo->full->width(), _photo->full->height()); box = QSize(width() - 2 * st::boxVerticalMargin, height() - 2 * st::boxVerticalMargin); } else { result = _document->dimensions; if (gif() && _gif->ready()) { result = QSize(_gif->width(), _gif->height()); } if (_document->sticker()) { box = QSize(st::maxStickerSize, st::maxStickerSize); } else { box = QSize(2 * st::maxStickerSize, 2 * st::maxStickerSize); } } result = QSize(qMax(convertScale(result.width()), 1), qMax(convertScale(result.height()), 1)); if (result.width() > box.width()) { result.setHeight(qMax((box.width() * result.height()) / result.width(), 1)); result.setWidth(box.width()); } if (result.height() > box.height()) { result.setWidth(qMax((box.height() * result.width()) / result.height(), 1)); result.setHeight(box.height()); } if (_photo) { _cachedSize = result; } return result; }
QImage RippleAnimation::maskByDrawer(QSize size, bool filled, Fn<void(QPainter &p)> drawer) { auto result = QImage(size * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied); result.setDevicePixelRatio(cRetinaFactor()); result.fill(filled ? QColor(255, 255, 255) : Qt::transparent); if (drawer) { Painter p(&result); PainterHighQualityEnabler hq(p); p.setPen(Qt::NoPen); p.setBrush(QColor(255, 255, 255)); drawer(p); } return result; }
void Float::prepareShadow() { auto shadow = QImage(size() * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied); shadow.fill(Qt::transparent); shadow.setDevicePixelRatio(cRetinaFactor()); { Painter p(&shadow); PainterHighQualityEnabler hq(p); p.setPen(Qt::NoPen); p.setBrush(st::shadowFg); auto extend = 2 * st::lineWidth; p.drawEllipse(getInnerRect().marginsAdded(QMargins(extend, extend, extend, extend))); } _shadow = App::pixmapFromImageInPlace(Images::prepareBlur(std::move(shadow))); }
QPixmap FadeAnimation::grabContent() { SendPendingMoveResizeEvents(_widget); _size = _widget->size(); if (_size.isEmpty()) { auto image = QImage( cIntRetinaFactor(), cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied); image.fill(Qt::transparent); return App::pixmapFromImageInPlace(std::move(image)); } auto widgetContent = GrabWidget(_widget); if (_scale < 1.) { auto result = QImage(kWideScale * _size * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied); result.setDevicePixelRatio(cRetinaFactor()); result.fill(Qt::transparent); { Painter p(&result); p.drawPixmap((kWideScale - 1) / 2 * _size.width(), (kWideScale - 1) / 2 * _size.height(), widgetContent); } return App::pixmapFromImageInPlace(std::move(result)); } return widgetContent; }