bool UIControllerSetting::eventFilter( QObject* object, QEvent* event ) { if ( event->type() == QEvent::Paint ) { QToolButton* tb = qobject_cast<QToolButton*>( object ); if ( tb ) { if ( tb->isChecked() ) { QStylePainter sp( tb ); QStyleOptionToolButton options; options.initFrom( tb ); options.arrowType = Qt::NoArrow; options.features = QStyleOptionToolButton::None; options.icon = tb->icon(); options.iconSize = tb->iconSize(); options.state = QStyle::State_Enabled | QStyle::State_HasFocus | QStyle::State_On | QStyle::State_AutoRaise; sp.drawComplexControl( QStyle::CC_ToolButton, options ); return true; } } } return false; }
void ColorDialog::setForeground() { QColor color = QColorDialog::getColor(fg); if (color.isValid()) { QToolButton *button = static_cast<QToolButton *>(sender()); button->setIcon(createIcon(button->iconSize(), color)); fg = color; } }
void KoResourcePopupAction::updateIcon() { QSize iconSize; QToolButton *toolButton = dynamic_cast<QToolButton*>(parentWidget()); if (toolButton) { iconSize = QSize(toolButton->iconSize()); } else { iconSize = QSize(16, 16); } // This must be a QImage, as drawing to a QPixmap outside the // UI thread will cause sporadic crashes. QImage pm = QImage(iconSize, QImage::Format_ARGB32_Premultiplied); pm.fill(Qt::transparent); QPainter p(&pm); QSharedPointer<KoGradientBackground> gradientBackground = qSharedPointerDynamicCast<KoGradientBackground>(d->background); QSharedPointer<KoPatternBackground> patternBackground = qSharedPointerDynamicCast<KoPatternBackground>(d->background); if (gradientBackground) { QRect innerRect(0, 0, iconSize.width(), iconSize.height()); QLinearGradient paintGradient; paintGradient.setStops(gradientBackground->gradient()->stops()); paintGradient.setStart(innerRect.topLeft()); paintGradient.setFinalStop(innerRect.topRight()); d->checkerPainter.paint(p, innerRect); p.fillRect(innerRect, QBrush(paintGradient)); } else if (patternBackground) { d->checkerPainter.paint(p, QRect(QPoint(),iconSize)); p.fillRect(0, 0, iconSize.width(), iconSize.height(), patternBackground->pattern()); } p.end(); setIcon(QIcon(QPixmap::fromImage(pm))); }
void KoColorPopupAction::updateIcon() { QSize iconSize; QToolButton *toolButton = dynamic_cast<QToolButton*>(parentWidget()); if (toolButton) { iconSize = QSize(toolButton->iconSize()); } else { iconSize = QSize(16, 16); } // This must be a QImage, as drawing to a QPixmap outside the // UI thread will cause sporadic crashes. QImage pm; if (icon().isNull()) { d->applyMode = false; } if(d->applyMode) { pm = icon().pixmap(iconSize).toImage(); if (pm.isNull()) { pm = QImage(iconSize, QImage::Format_ARGB32_Premultiplied); pm.fill(Qt::transparent); } QPainter p(&pm); p.fillRect(0, iconSize.height() - 4, iconSize.width(), 4, d->currentColor.toQColor()); p.end(); } else { pm = QImage(iconSize, QImage::Format_ARGB32_Premultiplied); pm.fill(Qt::transparent); QPainter p(&pm); d->checkerPainter.paint(p, QRect(QPoint(),iconSize)); p.fillRect(0, 0, iconSize.width(), iconSize.height(), d->currentColor.toQColor()); p.end(); } setIcon(QIcon(QPixmap::fromImage(pm))); }
ColorDialog::ColorDialog(const QColor &foreground, const QColor &background, const QVector<QColor> &colors, const QStringList &names, QWidget *parent) : QDialog(parent) { bg = background; fg = foreground; colorList = colors; mapper = new QSignalMapper(this); QGroupBox *buttonGroupBox = new QGroupBox(tr("Highlighting colors")); QGridLayout *buttonLayout = new QGridLayout; for (int i = 0; i < colors.size(); ++i) { QLabel *label = new QLabel(names[i]); QToolButton *button = new QToolButton; button->setText(tr("Choose...")); button->setIcon(createIcon(button->iconSize(), colors[i])); connect(button, SIGNAL(clicked()), mapper, SLOT(map())); mapper->setMapping(button, i); buttonLayout->addWidget(label, i, 0); buttonLayout->addWidget(button, i, 1); } buttonGroupBox->setLayout(buttonLayout); connect(mapper, SIGNAL(mapped(int)), this, SLOT(selectColor(int))); QGroupBox *autoColorGroupBox = new QGroupBox(tr("Base colors")); QLabel *foregroundLabel = new QLabel(tr("Foreground:")); QToolButton *foregroundButton = new QToolButton; foregroundButton->setText(tr("Choose...")); foregroundButton->setIcon(createIcon(foregroundButton->iconSize(), fg)); QLabel *backgroundLabel = new QLabel(tr("Background:")); QToolButton *backgroundButton = new QToolButton; backgroundButton->setText(tr("Choose...")); backgroundButton->setIcon(createIcon(backgroundButton->iconSize(), bg)); QPushButton *createButton = new QPushButton(tr("Create New Colors")); connect(foregroundButton, SIGNAL(clicked()), this, SLOT(setForeground())); connect(backgroundButton, SIGNAL(clicked()), this, SLOT(setBackground())); connect(createButton, SIGNAL(clicked()), this, SLOT(createNewColors())); QGridLayout *autoColorLayout = new QGridLayout; autoColorLayout->addWidget(foregroundLabel, 0, 0); autoColorLayout->addWidget(foregroundButton, 0, 1); autoColorLayout->addWidget(backgroundLabel, 1, 0); autoColorLayout->addWidget(backgroundButton, 1, 1); autoColorLayout->addWidget(createButton, 2, 0, 1, 2); autoColorGroupBox->setLayout(autoColorLayout); QDialogButtonBox *buttons = new QDialogButtonBox(Qt::Horizontal); buttons->addButton(QDialogButtonBox::Ok); buttons->addButton(QDialogButtonBox::Cancel); connect(buttons, SIGNAL(accepted()), this, SLOT(accept())); connect(buttons, SIGNAL(rejected()), this, SLOT(reject())); QGridLayout *mainLayout = new QGridLayout; mainLayout->addWidget(buttonGroupBox, 0, 0, 2, 1); mainLayout->addWidget(autoColorGroupBox, 0, 1); mainLayout->addWidget(buttons, 2, 0, 1, 2); setLayout(mainLayout); setWindowTitle(tr("Configure Highlighting Colors")); }
void ColorDialog::setColorButton(int index, const QColor &color) { QToolButton *button = static_cast<QToolButton *>(mapper->mapping(index)); button->setIcon(createIcon(button->iconSize(), color)); colorList[index] = color; }