void WFormWidget::setEmptyText(const WString& emptyText) { emptyText_ = emptyText; WApplication* app = WApplication::instance(); const WEnvironment& env = app->environment(); if (env.ajax()) { if (!emptyText_.empty()) { if (!flags_.test(BIT_JS_OBJECT)) defineJavaScript(); else updateEmptyText(); if (!removeEmptyText_) { removeEmptyText_ = new JSlot(this); focussed().connect(*removeEmptyText_); blurred().connect(*removeEmptyText_); keyWentDown().connect(*removeEmptyText_); std::string jsFunction = "function(obj, event) {" """jQuery.data(" + jsRef() + ", 'obj').applyEmptyText();" "}"; removeEmptyText_->setJavaScript(jsFunction); } } else { delete removeEmptyText_; removeEmptyText_ = 0; } } else { setToolTip(emptyText); } }
void WLineEdit::defineJavaScript() { if (javaScriptDefined_) return; javaScriptDefined_ = true; WApplication *app = WApplication::instance(); LOAD_JAVASCRIPT(app, "js/WLineEdit.js", "WLineEdit", wtjs1); std::u32string space; space += spaceChar_; std::string jsObj = "new " WT_CLASS ".WLineEdit(" + app->javaScriptClass() + "," + jsRef() + "," + WWebWidget::jsStringLiteral(mask_) + "," + WWebWidget::jsStringLiteral(raw_) + "," + WWebWidget::jsStringLiteral(displayContent_) + "," + WWebWidget::jsStringLiteral(case_) + "," + WWebWidget::jsStringLiteral(space) + "," + (inputMaskFlags_.test(InputMaskFlag::KeepMaskWhileBlurred) ? "0x1" : "0x0") + ");"; setJavaScriptMember(" WLineEdit", jsObj); #ifdef WT_CNOR EventSignalBase& b = mouseMoved(); EventSignalBase& c = keyWentDown(); #endif connectJavaScript(keyWentDown(), "keyDown"); connectJavaScript(keyPressed(), "keyPressed"); connectJavaScript(focussed(), "focussed"); connectJavaScript(blurred(), "blurred"); connectJavaScript(clicked(), "clicked"); }
void BlurPushButton::resizeEvent(QResizeEvent* event) { background = blurred(original, QRect(mapToGlobal(rect().topLeft()), event->size()), 20, false); blur = QPixmap(event->size()); blur.fill(QColor(168,195,205,20*2.55)); event->accept(); }
void PropertiesDialog::setMultipleCover() { ComicDB lastComic = comics.last(); QPixmap last = lastComic.info.getCover(basePath); last = last.scaledToHeight(444,Qt::SmoothTransformation); coverImage = QPixmap::fromImage(blurred(last.toImage(),QRect(0,0,last.width(),last.height()),15)); }
void FlatInput::focusOutEvent(QFocusEvent *e) { a_phColor.start(_st.phColor->c); if (_notingBene <= 0) { a_borderColor.start(_st.borderColor->c); } a_bgColor.start(_st.bgColor->c); anim::start(this); QLineEdit::focusOutEvent(e); emit blurred(); }
void Shadow::draw(QPainter* painter) { // if nothing to show outside the item, just draw source if ((blurRadius() + distance()) <= 0) { drawSource(painter); return; } PixmapPadMode mode = QGraphicsEffect::PadToEffectiveBoundingRect; QPoint offset; const QPixmap px = sourcePixmap(Qt::DeviceCoordinates, &offset, mode); // return if no source if (px.isNull()) return; // save world transform QTransform restoreTransform = painter->worldTransform(); painter->setWorldTransform(QTransform()); // Calculate size for the background image QSize szi(px.size().width() + 2 * distance(), px.size().height() + 2 * distance()); QImage tmp(szi, QImage::Format_ARGB32_Premultiplied); QPixmap scaled = px.scaled(szi); tmp.fill(0); QPainter tmpPainter(&tmp); tmpPainter.setCompositionMode(QPainter::CompositionMode_Source); tmpPainter.drawPixmap(QPointF(-distance(), -distance()), scaled); tmpPainter.end(); // blur the alpha channel QImage blurred(tmp.size(), QImage::Format_ARGB32_Premultiplied); blurred.fill(0); QPainter blurPainter(&blurred); qt_blurImage(&blurPainter, tmp, blurRadius(), false, true); blurPainter.end(); tmp = blurred; // blacken the image... tmpPainter.begin(&tmp); tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn); tmpPainter.fillRect(tmp.rect(), color()); tmpPainter.end(); // draw the blurred shadow... painter->drawImage(offset, tmp); // draw the actual pixmap... painter->drawPixmap(offset, px, QRectF()); // restore world transform painter->setWorldTransform(restoreTransform); }
// addDropShadow is inspired by QPixmapDropShadowFilter::draw in // qt/src/gui/effects/qpixmapfilter.cpp QPixmap addDropShadow( const QPixmap& source, const QSize& targetSize ) { const QPoint offset( 2, 4 ); const int radius = 4; const QColor shadowColor( 100, 100, 100, 100 ); // If there is no targetSize, then return a larger pixmap with the shadow added on // otherwise, return a bounded pixmap and shrink the source const QSize sizeToUse = targetSize.isEmpty() ? QSize( source.width() + offset.x() + radius, source.height() + offset.y() + radius ) : targetSize; const QSize shrunkToFit( sizeToUse.width() - offset.x() - radius, sizeToUse.height() - offset.y() - radius ); const QPixmap shrunk = source.scaled( shrunkToFit, Qt::KeepAspectRatio, Qt::SmoothTransformation ); QImage tmp( sizeToUse, QImage::Format_ARGB32_Premultiplied ); tmp.fill( 0 ); QPainter tmpPainter( &tmp ); tmpPainter.setCompositionMode( QPainter::CompositionMode_Source ); tmpPainter.drawPixmap( offset, shrunk ); tmpPainter.end(); // blur the alpha channel QImage blurred( sizeToUse, QImage::Format_ARGB32_Premultiplied ); blurred.fill( 0 ); QPainter blurPainter( &blurred ); qt_blurImage( &blurPainter, tmp, radius, false, true ); blurPainter.end(); // blacken the image... QPainter blackenPainter( &blurred ); blackenPainter.setCompositionMode( QPainter::CompositionMode_SourceIn ); blackenPainter.fillRect( blurred.rect(), shadowColor ); blackenPainter.end(); const QRect resultRect( shrunk.rect().united( shrunk.rect().translated( offset ).adjusted( -radius, -radius, radius, radius ) ) ); QPixmap result( resultRect.size() ); result.fill( Qt::transparent ); QPainter resultPainter( &result ); // draw the blurred drop shadow... resultPainter.drawImage( 0, 0, blurred ); // Draw the actual pixmap... resultPainter.drawPixmap( 0, 0, shrunk ); return result; }
void WidgetFadeHelper::CaptureParent() { // Take a "screenshot" of the window original_pixmap_ = QPixmap::grabWidget(parent_); QImage original_image = original_pixmap_.toImage(); // Blur it QImage blurred(original_image.size(), QImage::Format_ARGB32_Premultiplied); blurred.fill(Qt::transparent); QPainter blur_painter(&blurred); blur_painter.save(); qt_blurImage(&blur_painter, original_image, 10.0, true, false); blur_painter.restore(); // Draw some loading text over the top QFont loading_font(font()); loading_font.setBold(true); QFontMetrics loading_font_metrics(loading_font); const QString loading_text = tr("Loading..."); const QSize loading_size( kLoadingPadding * 2 + loading_font_metrics.width(loading_text), kLoadingPadding * 2 + loading_font_metrics.height()); const QRect loading_rect((blurred.width() - loading_size.width()) / 2, 100, loading_size.width(), loading_size.height()); blur_painter.setRenderHint(QPainter::Antialiasing); blur_painter.setRenderHint(QPainter::HighQualityAntialiasing); blur_painter.translate(0.5, 0.5); blur_painter.setPen(QColor(200, 200, 200, 255)); blur_painter.setBrush(QColor(200, 200, 200, 192)); blur_painter.drawRoundedRect(loading_rect, kLoadingBorderRadius, kLoadingBorderRadius); blur_painter.setPen(palette().brush(QPalette::Text).color()); blur_painter.setFont(loading_font); blur_painter.drawText(loading_rect.translated(-1, -1), Qt::AlignCenter, loading_text); blur_painter.translate(-0.5, -0.5); blur_painter.end(); blurred_pixmap_ = QPixmap::fromImage(blurred); resize(parent_->size()); }
QT_END_NAMESPACE void ShadowEffect::draw(QPainter* painter){ if((blurRadius() + distance()) <= 0){ drawSource(painter); return; } PixmapPadMode mode = QGraphicsEffect::PadToEffectiveBoundingRect; QPoint offset; const QPixmap px = sourcePixmap(Qt::DeviceCoordinates, &offset, mode); if(px.isNull()) return; QTransform restoreTransform = painter->worldTransform(); painter->setWorldTransform(QTransform()); QSize szi(px.size().width() + 2 * distance(), px.size().height() + 2 * distance()); QImage tmp(szi, QImage::Format_ARGB32_Premultiplied); QPixmap scaled = px.scaled(szi); tmp.fill(0); QPainter tmpPainter(&tmp); tmpPainter.setCompositionMode(QPainter::CompositionMode_Source); tmpPainter.drawPixmap(QPointF(-distance(), -distance()), scaled); tmpPainter.end(); QImage blurred(tmp.size(), QImage::Format_ARGB32_Premultiplied); blurred.fill(0); QPainter blurPainter(&blurred); qt_blurImage(&blurPainter, tmp, blurRadius(), false, true); blurPainter.end(); tmp = blurred; tmpPainter.begin(&tmp); tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn); tmpPainter.fillRect(tmp.rect(), color()); tmpPainter.end(); painter->drawImage(offset, tmp); painter->drawPixmap(offset, px, QRectF()); painter->setWorldTransform(restoreTransform); }
void ContextWidget::updateImage(QImage img, bool created) { DBUG << img.isNull() << currentBackdrop.isNull(); oldBackdrop=currentBackdrop; oldIsAlbumCoverBackdrop=albumCoverBackdrop; currentBackdrop=QPixmap(); animator.stop(); if (img.isNull() && oldBackdrop.isNull()) { return; } if (img.isNull()) { currentImage=img; } else { if (backdropOpacity<100) { img=TreeView::setOpacity(img, (backdropOpacity*1.0)/100.0); } if (backdropBlur>0) { QImage blurred(img.size(), QImage::Format_ARGB32_Premultiplied); blurred.fill(Qt::transparent); QPainter painter(&blurred); qt_blurImage(&painter, img, backdropBlur, true, false); painter.end(); img = blurred; } #ifdef SCALE_CONTEXT_BGND currentImage=img; #else currentBackdrop=QPixmap::fromImage(img); #endif } albumCoverBackdrop=created; resizeBackdrop(); animator.stop(); if (PlayQueueView::BI_Custom==backdropType || !isVisible()) { setFade(1.0); } else { fadeValue=0.0; animator.setDuration(250); animator.setEndValue(1.0); animator.start(); } }
void SearchTermWidget::Overlay::Grab() { hide(); // Take a "screenshot" of the window QPixmap pixmap = QPixmap::grabWidget(parent_); QImage image = pixmap.toImage(); // Blur it QImage blurred(image.size(), QImage::Format_ARGB32_Premultiplied); blurred.fill(Qt::transparent); QPainter blur_painter(&blurred); qt_blurImage(&blur_painter, image, 10.0, true, false); blur_painter.end(); pixmap_ = QPixmap::fromImage(blurred); resize(parent_->size()); show(); update(); }
void PlaylistView::set_background_image(const QImage& image) { // Save previous image, for fading previous_background_image_ = cached_scaled_background_image_; if (image.isNull() || image.format() == QImage::Format_ARGB32) { background_image_ = image; } else { background_image_ = image.convertToFormat(QImage::Format_ARGB32); } if (!background_image_.isNull()) { // Apply opacity filter uchar* bits = background_image_.bits(); for (int i = 0; i < background_image_.height() * background_image_.bytesPerLine(); i += 4) { bits[i + 3] = (opacity_level_ / 100.0) * 255; } if (blur_radius_ != 0) { QImage blurred(background_image_.size(), QImage::Format_ARGB32_Premultiplied); blurred.fill(Qt::transparent); QPainter blur_painter(&blurred); qt_blurImage(&blur_painter, background_image_, blur_radius_, true, false); blur_painter.end(); background_image_ = blurred; } } if (isVisible()) { previous_background_image_opacity_ = 1.0; fade_animation_->start(); } }
// 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("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); }
// Draws a cached pixmap with shadow void FancyTabBar::drawIconWithShadow(const QIcon &icon, const QRect &rect, QPainter *p, QIcon::Mode iconMode, int dipRadius, const QColor &color, const QPoint &dipOffset) { QPixmap cache; QString pixmapName = QString::fromLatin1("icon %0 %1 %2").arg(icon.cacheKey()).arg(iconMode).arg(rect.height()); if (!QPixmapCache::find(pixmapName, cache)) { // High-dpi support: The in parameters (rect, radius, offset) are in // device-independent pixels. The call to QIcon::pixmap() below might // return a high-dpi pixmap, which will in that case have a devicePixelRatio // different than 1. The shadow drawing caluculations are done in device // pixels. QPixmap px = icon.pixmap(rect.size()); //jassuncao int devicePixelRatio = qCeil(px.devicePixelRatio()); int devicePixelRatio = 1; int radius = dipRadius * devicePixelRatio; QPoint offset = dipOffset * devicePixelRatio; 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(QRect(radius, radius, px.width(), px.height()), 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(QRect(QPoint(radius, radius) + offset, QSize(px.width(), px.height())), px); //jassuncao: cache.setDevicePixelRatio(devicePixelRatio); QPixmapCache::insert(pixmapName, cache); } QRect targetRect = cache.rect(); //jassuncao targetRect.setSize(targetRect.size() / cache.devicePixelRatio()); targetRect.moveCenter(rect.center() - dipOffset); p->drawPixmap(targetRect, cache); }
//--------------------------------------------------------------------------------------- void ScorePlayerCtrl::on_draw(Drawer* pDrawer, RenderOptions& UNUSED(opt)) { Color color = (m_fEnabled ? m_currentColor : Color(192, 192, 192)); Color white(255, 255, 255); Color black(0, 0, 0); Color dark(83, 80, 72); Color clear = white; LUnits x = m_pos.x; LUnits y = m_pos.y; LUnits width = m_width; //m_fFullView ? 4000.0f : m_width; //draw box gradient and border //dark.a = 45; Color light(dark); light = light.gradient(white, 0.2); pDrawer->begin_path(); pDrawer->fill(dark); pDrawer->stroke(black); pDrawer->stroke_width(15.0); pDrawer->gradient_color(white, 0.0, 0.1); pDrawer->gradient_color(white, dark, 0.1, 0.7); pDrawer->gradient_color(dark, light, 0.7, 1.0); pDrawer->fill_linear_gradient(m_pos.x, m_pos.y, m_pos.x, m_pos.y + m_height); pDrawer->rect(UPoint(x, y), USize(width, m_height), 100.0f); pDrawer->end_path(); switch (m_playButtonState) { case k_play: // //triangle (play) // pDrawer->begin_path(); // pDrawer->fill(clear); // pDrawer->stroke(color); // pDrawer->move_to(x + 360.0f, y + 130.0f); // pDrawer->line_to(x + 640.0f, y + 300.0f); // pDrawer->line_to(x + 360.0f, y + 470.0f); // pDrawer->close_subpath(); // pDrawer->end_path(); // break; //triangle (play) if (!m_fFullView) { //mouse out pDrawer->begin_path(); pDrawer->fill(clear); pDrawer->stroke(color); pDrawer->move_to(x + 360.0f, y + 130.0f); pDrawer->line_to(x + 640.0f, y + 300.0f); pDrawer->line_to(x + 360.0f, y + 470.0f); pDrawer->close_subpath(); pDrawer->end_path(); } else { //mouse in pDrawer->begin_path(); Color blurred(255, 255, 220); // = color; Color none(255, 255, 255, 0); blurred.a = 150; pDrawer->fill(blurred); pDrawer->stroke(none); pDrawer->move_to(x + 360.0f - 50.0f, y + 130.0f - 80.0f); pDrawer->line_to(x + 640.0f + 100.0f, y + 300.0f); pDrawer->line_to(x + 360.0f - 50.0f, y + 470.0f + 80.0f); pDrawer->close_subpath(); pDrawer->end_path(); pDrawer->begin_path(); blurred.a = 220; pDrawer->fill(blurred); pDrawer->stroke(none); pDrawer->move_to(x + 360.0f - 25.0f, y + 130.0f - 40.0f); pDrawer->line_to(x + 640.0f + 50.0f, y + 300.0f); pDrawer->line_to(x + 360.0f - 25.0f, y + 470.0f + 40.0f); pDrawer->close_subpath(); pDrawer->end_path(); // pDrawer->begin_path(); // pDrawer->fill(color); // pDrawer->stroke(color); // pDrawer->move_to(x + 360.0f, y + 130.0f); // pDrawer->line_to(x + 640.0f, y + 300.0f); // pDrawer->line_to(x + 360.0f, y + 470.0f); // pDrawer->close_subpath(); // pDrawer->end_path(); // see www.crossgl.com/aggpas/documentation Color red(255,0,0); Color yellow(255,255,0); red = red.gradient(red, 0.2); pDrawer->begin_path(); pDrawer->fill(red); pDrawer->stroke(red); pDrawer->stroke_width(10.0); pDrawer->gradient_color(red, 0.0, 0.1); pDrawer->gradient_color(red, yellow, 0.1, 0.90); pDrawer->gradient_color(yellow, white, 0.90, 1.0); pDrawer->fill_linear_gradient(x, y+130.0f, x, y+470.0f); pDrawer->move_to(x + 360.0f, y + 130.0f); pDrawer->line_to(x + 640.0f, y + 300.0f); pDrawer->line_to(x + 360.0f, y + 470.0f); pDrawer->close_subpath(); pDrawer->end_path(); } break; // //draw glowing line // glow effect is just drawing a blured layer in light color, under main layer. // in this test, instaed of blurring the original shape, just do a secon drawing more // light // set_alpha(0.2) // set_line_width(5) // draw_line // set_alpha(0.07) // set_line_width(15) // draw_line case k_stop: //square (stop) pDrawer->begin_path(); pDrawer->fill(clear); pDrawer->stroke(color); pDrawer->rect(UPoint(x+370.0f, y+170.0f), USize(260.0f, 260.0f), 0.0f); pDrawer->end_path(); break; case k_pause: //two bars (pause) pDrawer->begin_path(); pDrawer->fill(clear); pDrawer->stroke(color); pDrawer->rect(UPoint(x+150.0f, y+150.0f), USize(120.0f, 300.0f), 0.0f); pDrawer->rect(UPoint(x+330.0f, y+150.0f), USize(120.0f, 300.0f), 0.0f); pDrawer->end_path(); break; default: ; } }