void ShortcutButton::updateIcons() { const QColor color = getDefaultIconColor(*m_buttonAddShortcut, QPalette::Window); m_buttonAddShortcut->setIcon( getIcon("list-add", IconPlus, color, color) ); const int h = m_buttonAddShortcut->sizeHint().height(); m_buttonAddShortcut->setMaximumSize(h, h); }
void Notification::updateIcon() { const QColor color = getDefaultIconColor(*this); IconFactory *iconFactory = ConfigurationManager::instance()->iconFactory(); const int height = m_msgLabel->fontMetrics().lineSpacing() * 1.2; const QPixmap pixmap = iconFactory->createPixmap(m_icon, color, height); m_iconLabel->setPixmap(pixmap); m_iconLabel->resize(pixmap.size()); }
QColor getDefaultIconColor(const QWidget &widget, bool selected) { const QWidget *parent = &widget; while ( parent->parentWidget() && !parent->isTopLevel() && !parent->testAttribute(Qt::WA_OpaquePaintEvent) ) { parent = parent->parentWidget(); } QPalette::ColorRole role = selected ? QPalette::Highlight : parent->backgroundRole(); return getDefaultIconColor( parent->palette().color(QPalette::Active, role) ); }
IconFactory::IconFactory() : m_iconColor() , m_iconColorActive() , m_useSystemIcons(true) , m_loaded(false) , m_iconCache() , m_resourceIconCache() { m_loaded = QFontDatabase::addApplicationFont(":/images/fontawesome-webfont.ttf") != -1; // Try to get menu color more precisely by rendering dummy widget and getting color of pixel // that is presumably menu background. QMenu menu; QImage img(1, 1, QImage::Format_RGB32); menu.resize(16, 16); menu.render(&img, QPoint(-8, -8)); m_iconColor = getDefaultIconColor( img.pixel(0, 0) ); menu.setActiveAction( menu.addAction(QString()) ); menu.render(&img, QPoint(-8, -8)); m_iconColorActive = getDefaultIconColor( img.pixel(0, 0) ); }
QColor getDefaultIconColor(const QWidget &widget, QPalette::ColorRole colorRole) { return getDefaultIconColor( widget.palette().color(QPalette::Active, colorRole) ); }
void ShortcutButton::updateIcons() { const QColor color = getDefaultIconColor(*m_buttonAddShortcut, QPalette::Window); m_buttonAddShortcut->setIcon( getIcon("list-add", IconPlus, color, color) ); }