void SimpleButton::generateIcons() { if (!pixmap()) { return; } QImage image = pixmap()->convertToImage(); KIconEffect effect; m_normalIcon = effect.apply(image, KIcon::Panel, KIcon::DefaultState); m_activeIcon = effect.apply(image, KIcon::Panel, KIcon::ActiveState); }
void WeatherButton::generateIcons() { if ( !pixmap() ) return; QImage image = pixmap()->convertToImage(); image = image.smoothScale( pixmapSize(), QImage::ScaleMin ); KIconEffect effect; m_normalIcon = effect.apply( image, KIcon::Panel, KIcon::DefaultState ); m_activeIcon = effect.apply( image, KIcon::Panel, KIcon::ActiveState ); }
void HideButton::generateIcons() { if (icon().isNull()) { m_normalIcon = QPixmap(); m_activeIcon = QPixmap(); return; } QPixmap pix = icon().pixmap(); pix = pix.scaled(size() - QSize(4, 4), Qt::KeepAspectRatio, Qt::SmoothTransformation); KIconEffect effect; m_normalIcon = effect.apply(pix, KIconLoader::Panel, KIconLoader::DefaultState); m_activeIcon = effect.apply(pix, KIconLoader::Panel, KIconLoader::ActiveState); }
void KNotesApp::updateNoteActions() { unplugActionList( "notes" ); m_noteActions.clear(); for ( QDictIterator<KNote> it( m_noteList ); it.current(); ++it ) { KAction *action = new KAction( it.current()->name().replace("&", "&&"), KShortcut(), this, SLOT(slotShowNote()), (QObject *)0, it.current()->noteId().utf8() ); KIconEffect effect; QPixmap icon = effect.apply( kapp->miniIcon(), KIconEffect::Colorize, 1, it.current()->paletteBackgroundColor(), false ); action->setIconSet( icon ); m_noteActions.append( action ); } m_noteActions.sort(); if ( m_noteActions.isEmpty() ) { KAction *action = new KAction( i18n("No Notes") ); m_noteActions.append( action ); } plugActionList( "notes", m_noteActions ); }
void KxkbLabelController::initLayoutList(const QValueList< LayoutUnit > &layouts, const XkbRules &rules) { // KPopupMenu* menu = contextMenu(); QPopupMenu *menu = contextMenu; // int index = menu->indexOf(0); m_descriptionMap.clear(); // menu->clear(); // menu->insertTitle( kapp->miniIcon(), kapp->caption() ); for(int ii = 0; ii < m_prevLayoutCount; ++ii) { menu->removeItem(START_MENU_ID + ii); kdDebug() << "remove item: " << START_MENU_ID + ii << endl; } /* menu->removeItem(CONFIG_MENU_ID); menu->removeItem(HELP_MENU_ID);*/ KIconEffect iconeffect; int cnt = 0; QValueList< LayoutUnit >::ConstIterator it; for(it = layouts.begin(); it != layouts.end(); ++it) { const QString layoutName = (*it).layout; const QString variantName = (*it).variant; const QPixmap &layoutPixmap = LayoutIcon::getInstance().findPixmap(layoutName, m_showFlag, (*it).displayName); const QPixmap pix = iconeffect.apply(layoutPixmap, KIcon::Small, KIcon::DefaultState); QString fullName = i18n((rules.layouts()[layoutName])); if(variantName.isEmpty() == false) fullName += " (" + variantName + ")"; contextMenu->insertItem(pix, fullName, START_MENU_ID + cnt, m_menuStartIndex + cnt); m_descriptionMap.insert((*it).toPair(), fullName); cnt++; } m_prevLayoutCount = cnt; // if show config, if show help if(menu->indexOf(CONFIG_MENU_ID) == -1) { contextMenu->insertSeparator(); contextMenu->insertItem(SmallIcon("configure"), i18n("Configure..."), CONFIG_MENU_ID); if(menu->indexOf(HELP_MENU_ID) == -1) contextMenu->insertItem(SmallIcon("help"), i18n("Help"), HELP_MENU_ID); } /* if( index != -1 ) { //not first start menu->insertSeparator(); KAction* quitAction = KStdAction::quit(this, SIGNAL(quitSelected()), actionCollection()); if (quitAction) quitAction->plug(menu); }*/ }
QPixmap WindowPreview::hoverIcon() const { KIconEffect *effect = KIconLoader::global()->iconEffect(); if (effect->hasEffect(KIconLoader::Desktop, KIconLoader::ActiveState)) { return effect->apply( m_icon, KIconLoader::Desktop, KIconLoader::ActiveState); } else { return m_icon; } }
KIcon GlobalApplet::makeOverlayIcon( const KIcon &icon, const KIcon &overlayIcon, const QSize &overlaySize, int iconExtend ) { QPixmap pixmap = icon.pixmap( iconExtend ), pixmapOverlay = overlayIcon.pixmap( overlaySize ); QPainter p( &pixmap ); p.drawPixmap( QPoint( iconExtend - overlaySize.width(), iconExtend - overlaySize.height() ), pixmapOverlay ); p.end(); KIcon resultIcon = KIcon(); resultIcon.addPixmap( pixmap, QIcon::Normal ); KIconEffect iconEffect; pixmap = iconEffect.apply( pixmap, KIconLoader::Small, KIconLoader::ActiveState ); resultIcon.addPixmap( pixmap, QIcon::Selected ); resultIcon.addPixmap( pixmap, QIcon::Active ); return resultIcon; }
QPixmap Account::accountIcon(const int size) const { QString icon= d->customIcon.isEmpty() ? d->protocol->pluginIcon() : d->customIcon; // FIXME: this code is duplicated with OnlineStatus, can we merge it somehow? QPixmap base = KGlobal::instance()->iconLoader()->loadIcon( icon, KIcon::Small, size ); if ( d->color.isValid() ) { KIconEffect effect; base = effect.apply( base, KIconEffect::Colorize, 1, d->color, 0); } if ( size > 0 && base.width() != size ) { base = QPixmap( base.convertToImage().smoothScale( size, size ) ); } return base; }
QPixmap Account::accountIcon(const int size) const { QString icon= d->customIcon.isEmpty() ? d->protocol->pluginIcon() : d->customIcon; // FIXME: this code is duplicated with OnlineStatus, can we merge it somehow? QPixmap base = KIconLoader::global()->loadIcon( icon, KIconLoader::Small, size ); if ( d->color.isValid() ) { KIconEffect effect; base = effect.apply( base, KIconEffect::Colorize, 1, d->color, 0); } if ( size > 0 && base.width() != size ) { base.scaled( size, size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation ); } return base; }
void KxkbLabelController::setPixmap(const QPixmap &pixmap) { KIconEffect iconeffect; label->setPixmap(iconeffect.apply(pixmap, KIcon::Panel, KIcon::DefaultState)); }
void TitleWidget::setIcon( MainIconDisplay iconType ) { Q_ASSERT( m_icon ); KIcon icon; KIconEffect iconEffect; QPixmap pixmap; int iconExtend = m_icon->size().width(); // Create an icon of the given type. switch ( iconType ) { case DepartureListErrorIcon: { // Create an icon to be shown on errors with a departure/arrival board QList<KIcon> overlays; if ( m_settings->departureArrivalListType() == DepartureList ) { // Use a public transport stop icon with a house and an arrow away from it // to indicate that a departure list is shown overlays << KIcon("go-home") << KIcon("go-next"); } else { // Use a public transport stop icon with a house and an arrow towards it // to indicate that an arrival list is shown overlays << KIcon("go-next") << KIcon("go-home"); } icon = GlobalApplet::makeOverlayIcon( KIcon("public-transport-stop"), overlays, QSize(iconExtend / 2, iconExtend / 2), iconExtend ); pixmap = icon.pixmap( iconExtend ); pixmap = iconEffect.apply( pixmap, KIconLoader::Small, KIconLoader::DisabledState ); icon = KIcon(); icon.addPixmap( pixmap, QIcon::Normal ); break; } case DepartureListOkIcon: { // Create an icon to be shown for departure/arrival boards without errors. // This icon is the same as the departure error icon, but without the icon effect QList<KIcon> overlays; if ( m_settings->departureArrivalListType() == DepartureList ) { overlays << KIcon("go-home") << KIcon("go-next"); } else { overlays << KIcon("go-next") << KIcon("go-home"); } icon = GlobalApplet::makeOverlayIcon( KIcon("public-transport-stop"), overlays, QSize( iconExtend / 2, iconExtend / 2 ), iconExtend ); break; } case JourneyListOkIcon: // Create an icon to be shown for journey lists without errors. // This icon is the same as the journey error icon, but without the icon effect icon = GlobalApplet::makeOverlayIcon( KIcon("public-transport-stop"), QList<KIcon>() << KIcon("go-home") << KIcon("go-next-view") << KIcon("public-transport-stop"), QSize(iconExtend / 3, iconExtend / 3), iconExtend ); break; case JourneyListErrorIcon: // Create an icon to be shown on errors with a journey list icon = GlobalApplet::makeOverlayIcon( KIcon("public-transport-stop"), QList<KIcon>() << KIcon("go-home") << KIcon("go-next-view") << KIcon("public-transport-stop"), QSize(iconExtend / 3, iconExtend / 3), iconExtend ); pixmap = icon.pixmap( iconExtend ); pixmap = iconEffect.apply( pixmap, KIconLoader::Small, KIconLoader::DisabledState ); icon = KIcon(); icon.addPixmap( pixmap, QIcon::Normal ); break; case AbortJourneySearchIcon: // Create an icon to be shown for the journey search icon = KIcon("edit-delete"); break; case GoBackIcon: // Create an icon to be used for "go back" functionality icon = KIcon("arrow-left"); break; } m_icon->setIcon( icon ); }
void KStandardItemListWidget::updatePixmapCache() { // Precondition: Requires already updated m_textPos values to calculate // the remaining height when the alignment is vertical. const QSizeF widgetSize = size(); const bool iconOnTop = (m_layout == IconsLayout); const KItemListStyleOption& option = styleOption(); const qreal padding = option.padding; const int maxIconWidth = iconOnTop ? widgetSize.width() - 2 * padding : option.iconSize; const int maxIconHeight = option.iconSize; const QHash<QByteArray, QVariant> values = data(); bool updatePixmap = (m_pixmap.width() != maxIconWidth || m_pixmap.height() != maxIconHeight); if (!updatePixmap && m_dirtyContent) { updatePixmap = m_dirtyContentRoles.isEmpty() || m_dirtyContentRoles.contains("iconPixmap") || m_dirtyContentRoles.contains("iconName") || m_dirtyContentRoles.contains("iconOverlays"); } if (updatePixmap) { m_pixmap = values["iconPixmap"].value<QPixmap>(); if (m_pixmap.isNull()) { // Use the icon that fits to the MIME-type QString iconName = values["iconName"].toString(); if (iconName.isEmpty()) { // The icon-name has not been not resolved by KFileItemModelRolesUpdater, // use a generic icon as fallback iconName = QLatin1String("unknown"); } m_pixmap = pixmapForIcon(iconName, maxIconHeight); } else if (m_pixmap.width() != maxIconWidth || m_pixmap.height() != maxIconHeight) { // A custom pixmap has been applied. Assure that the pixmap // is scaled to the maximum available size. KPixmapModifier::scale(m_pixmap, QSize(maxIconWidth, maxIconHeight)); } const QStringList overlays = values["iconOverlays"].toStringList(); // Strangely KFileItem::overlays() returns empty string-values, so // we need to check first whether an overlay must be drawn at all. // It is more efficient to do it here, as KIconLoader::drawOverlays() // assumes that an overlay will be drawn and has some additional // setup time. foreach (const QString& overlay, overlays) { if (!overlay.isEmpty()) { // There is at least one overlay, draw all overlays above m_pixmap // and cancel the check KIconLoader::global()->drawOverlays(overlays, m_pixmap, KIconLoader::Desktop); break; } } if (m_isCut) { KIconEffect* effect = KIconLoader::global()->iconEffect(); m_pixmap = effect->apply(m_pixmap, KIconLoader::Desktop, KIconLoader::DisabledState); } if (m_isHidden) { KIconEffect::semiTransparent(m_pixmap); } if (isSelected()) { const QColor color = palette().brush(QPalette::Normal, QPalette::Highlight).color(); QImage image = m_pixmap.toImage(); KIconEffect::colorize(image, color, 1.0f); m_pixmap = QPixmap::fromImage(image); } } if (!m_overlay.isNull()) { QPainter painter(&m_pixmap); painter.drawPixmap(0, m_pixmap.height() - m_overlay.height(), m_overlay); } int scaledIconSize = 0; if (iconOnTop) { const TextInfo* textInfo = m_textInfo.value("text"); scaledIconSize = static_cast<int>(textInfo->pos.y() - 2 * padding); } else { const int textRowsCount = (m_layout == CompactLayout) ? visibleRoles().count() : 1; const qreal requiredTextHeight = textRowsCount * m_customizedFontMetrics.height(); scaledIconSize = (requiredTextHeight < maxIconHeight) ? widgetSize.height() - 2 * padding : maxIconHeight; } const int maxScaledIconWidth = iconOnTop ? widgetSize.width() - 2 * padding : scaledIconSize; const int maxScaledIconHeight = scaledIconSize; m_scaledPixmapSize = m_pixmap.size(); m_scaledPixmapSize.scale(maxScaledIconWidth, maxScaledIconHeight, Qt::KeepAspectRatio); if (iconOnTop) { // Center horizontally and align on bottom within the icon-area m_pixmapPos.setX((widgetSize.width() - m_scaledPixmapSize.width()) / 2); m_pixmapPos.setY(padding + scaledIconSize - m_scaledPixmapSize.height()); } else { // Center horizontally and vertically within the icon-area const TextInfo* textInfo = m_textInfo.value("text"); m_pixmapPos.setX(textInfo->pos.x() - 2 * padding - (scaledIconSize + m_scaledPixmapSize.width()) / 2); m_pixmapPos.setY(padding + (scaledIconSize - m_scaledPixmapSize.height()) / 2); } m_iconRect = QRectF(m_pixmapPos, QSizeF(m_scaledPixmapSize)); // Prepare the pixmap that is used when the item gets hovered if (isHovered()) { m_hoverPixmap = m_pixmap; KIconEffect* effect = KIconLoader::global()->iconEffect(); // In the KIconLoader terminology, active = hover. if (effect->hasEffect(KIconLoader::Desktop, KIconLoader::ActiveState)) { m_hoverPixmap = effect->apply(m_pixmap, KIconLoader::Desktop, KIconLoader::ActiveState); } else { m_hoverPixmap = m_pixmap; } } else if (hoverOpacity() <= 0.0) { // No hover animation is ongoing. Clear m_hoverPixmap to save memory. m_hoverPixmap = QPixmap(); } }
kDebug() << "pixmap is Null"; return icon; } QPainter p( &pixmap ); int x = 0, xStep = iconExtend / overlayIconsBottom.count(); foreach( const KIcon &overlayIcon, overlayIconsBottom ) { p.drawPixmap( QPoint( x, iconExtend - overlaySize.height() ), overlayIcon.pixmap( overlaySize ) ); x += xStep; } p.end(); KIcon resultIcon = KIcon(); resultIcon.addPixmap( pixmap, QIcon::Normal ); KIconEffect iconEffect; pixmap = iconEffect.apply( pixmap, KIconLoader::Small, KIconLoader::ActiveState ); resultIcon.addPixmap( pixmap, QIcon::Selected ); resultIcon.addPixmap( pixmap, QIcon::Active ); return resultIcon; } void GlobalApplet::startFadeAnimation( QGraphicsWidget* w, qreal targetOpacity ) { Plasma::Animation *anim = GlobalApplet::fadeAnimation( w, targetOpacity ); if ( anim ) { anim->start( QAbstractAnimation::DeleteWhenStopped ); } } Plasma::Animation* GlobalApplet::fadeAnimation( QGraphicsWidget* w, qreal targetOpacity )
void PushButton::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { if (!styleSheet().isNull() || Theme::defaultTheme()->useNativeWidgetStyle()) { QGraphicsProxyWidget::paint(painter, option, widget); return; } QPixmap bufferPixmap; //Normal button, pressed or not if (isEnabled()) { if (nativeWidget()->isDown() || nativeWidget()->isChecked()) { d->background->setElementPrefix("pressed"); } else { d->background->setElementPrefix("normal"); } //flat or disabled } else if (!isEnabled() || nativeWidget()->isFlat()) { bufferPixmap = QPixmap(rect().size().toSize()); bufferPixmap.fill(Qt::transparent); QPainter buffPainter(&bufferPixmap); d->background->paintFrame(&buffPainter); buffPainter.setCompositionMode(QPainter::CompositionMode_DestinationIn); buffPainter.fillRect(bufferPixmap.rect(), QColor(0, 0, 0, 128)); painter->drawPixmap(0, 0, bufferPixmap); } //if is under mouse draw the animated glow overlay if (!nativeWidget()->isDown() && !nativeWidget()->isChecked() && isEnabled() && acceptHoverEvents() && d->background->hasElementPrefix("active")) { if (d->hoverAnimation->state() == QAbstractAnimation::Running && !isUnderMouse() && !nativeWidget()->isDefault()) { d->background->setElementPrefix("active"); d->background->paintFrame(painter, d->activeRect.topLeft()); } else { painter->drawPixmap( d->activeRect.topLeft(), d->hoverAnimation->property("currentPixmap").value<QPixmap>()); } } else if (isEnabled()) { d->background->paintFrame(painter); } painter->setPen(Plasma::Theme::defaultTheme()->color(Theme::ButtonTextColor)); if (nativeWidget()->isDown()) { painter->translate(QPoint(1, 1)); } QRectF rect = contentsRect(); if (!nativeWidget()->icon().isNull()) { const qreal iconSize = qMin(rect.width(), rect.height()); QPixmap iconPix = nativeWidget()->icon().pixmap(iconSize); if (!isEnabled()) { KIconEffect *effect = KIconLoader::global()->iconEffect(); iconPix = effect->apply(iconPix, KIconLoader::Toolbar, KIconLoader::DisabledState); } QRect pixmapRect; if (nativeWidget()->text().isEmpty()) { pixmapRect = nativeWidget()->style()->alignedRect(option->direction, Qt::AlignCenter, iconPix.size(), rect.toRect()); } else { pixmapRect = nativeWidget()->style()->alignedRect(option->direction, Qt::AlignLeft|Qt::AlignVCenter, iconPix.size(), rect.toRect()); } painter->drawPixmap(pixmapRect.topLeft(), iconPix); if (option->direction == Qt::LeftToRight) { rect.adjust(rect.height(), 0, 0, 0); } else { rect.adjust(0, 0, -rect.height(), 0); } } QFontMetricsF fm(font()); // If the height is too small increase the Height of the button to shall the whole text #192988 if (rect.height() < fm.height()) { rect.setHeight(fm.height()); rect.moveTop(boundingRect().center().y() - rect.height() / 2); } // If there is not enough room for the text make it to fade out if (rect.width() < fm.width(nativeWidget()->text())) { if (bufferPixmap.isNull()) { bufferPixmap = QPixmap(rect.size().toSize()); } bufferPixmap.fill(Qt::transparent); QPainter p(&bufferPixmap); p.setPen(painter->pen()); p.setFont(font()); // Create the alpha gradient for the fade out effect QLinearGradient alphaGradient(0, 0, 1, 0); alphaGradient.setCoordinateMode(QGradient::ObjectBoundingMode); if (option->direction == Qt::LeftToRight) { alphaGradient.setColorAt(0, QColor(0, 0, 0, 255)); alphaGradient.setColorAt(1, QColor(0, 0, 0, 0)); p.drawText(bufferPixmap.rect(), Qt::AlignLeft|Qt::AlignVCenter|Qt::TextShowMnemonic, nativeWidget()->text()); } else { alphaGradient.setColorAt(0, QColor(0, 0, 0, 0)); alphaGradient.setColorAt(1, QColor(0, 0, 0, 255)); p.drawText(bufferPixmap.rect(), Qt::AlignRight|Qt::AlignVCenter|Qt::TextShowMnemonic, nativeWidget()->text()); } p.setCompositionMode(QPainter::CompositionMode_DestinationIn); p.fillRect(bufferPixmap.rect(), alphaGradient); painter->drawPixmap(rect.topLeft(), bufferPixmap); } else { painter->setFont(font()); painter->drawText(rect, Qt::AlignCenter|Qt::TextShowMnemonic, nativeWidget()->text()); } }