File indexing completed on 2024-11-03 09:55:35

0001 #include "kiconeffecttest.h"
0002 
0003 #include <kiconeffect.h>
0004 #include <kiconloader.h>
0005 
0006 #include <KColorButton>
0007 
0008 #include <QApplication>
0009 #include <QGridLayout>
0010 #include <QLabel>
0011 #include <QSlider>
0012 
0013 KIconEffectTestWidget::KIconEffectTestWidget(QWidget *parent)
0014     : QScrollArea(parent)
0015 {
0016     setAttribute(Qt::WA_DeleteOnClose);
0017     QWidget *frame = new QWidget(this);
0018     setWidget(frame);
0019     setWidgetResizable(true);
0020     QGridLayout *layout = new QGridLayout(frame);
0021     layout->setColumnStretch(1, 1);
0022 
0023     img = QImage(KIconLoader::global()->iconPath(QStringLiteral("application-x-cd-image"), -128));
0024     QImage tmp;
0025     QSlider *slider;
0026 
0027     tmp = img;
0028     KIconEffect::toGray(tmp, 0.0);
0029     lbl[0] = new QLabel(frame);
0030     lbl[0]->setPixmap(QPixmap::fromImage(tmp));
0031     layout->addWidget(lbl[0], 0, 0, 3, 1);
0032     layout->addWidget(new QLabel(QStringLiteral("Grayscale"), frame), 0, 1);
0033     slider = new QSlider(Qt::Horizontal, frame);
0034     slider->setRange(0, 100);
0035     connect(slider, &QAbstractSlider::valueChanged, this, &KIconEffectTestWidget::slotGray);
0036     layout->addWidget(slider, 1, 1);
0037 
0038     tmp = img;
0039     KIconEffect::toMonochrome(tmp, Qt::black, Qt::white, 0.0);
0040     lbl[1] = new QLabel(frame);
0041     lbl[1]->setPixmap(QPixmap::fromImage(tmp));
0042     layout->addWidget(lbl[1], 4, 0, 3, 1);
0043     layout->addWidget(new QLabel(QStringLiteral("Monochrome"), frame), 4, 1);
0044     slider = new QSlider(Qt::Horizontal, frame);
0045     slider->setRange(0, 100);
0046     connect(slider, &QAbstractSlider::valueChanged, this, &KIconEffectTestWidget::slotMonochrome);
0047     layout->addWidget(slider, 5, 1);
0048 
0049     tmp = img;
0050     KIconEffect::deSaturate(tmp, 0.0);
0051     lbl[2] = new QLabel(frame);
0052     lbl[2]->setPixmap(QPixmap::fromImage(tmp));
0053     layout->addWidget(lbl[2], 8, 0, 3, 1);
0054     layout->addWidget(new QLabel(QStringLiteral("Desaturate"), frame), 8, 1);
0055     slider = new QSlider(Qt::Horizontal, frame);
0056     slider->setRange(0, 100);
0057     connect(slider, &QAbstractSlider::valueChanged, this, &KIconEffectTestWidget::slotDesaturate);
0058     layout->addWidget(slider, 9, 1);
0059 
0060     tmp = img;
0061     KIconEffect::toGamma(tmp, 0.0);
0062     lbl[3] = new QLabel(frame);
0063     lbl[3]->setPixmap(QPixmap::fromImage(tmp));
0064     layout->addWidget(lbl[3], 12, 0, 3, 1);
0065     layout->addWidget(new QLabel(QStringLiteral("Gamma"), frame), 12, 1);
0066     slider = new QSlider(Qt::Horizontal, frame);
0067     slider->setRange(0, 100);
0068     connect(slider, &QAbstractSlider::valueChanged, this, &KIconEffectTestWidget::slotGamma);
0069     layout->addWidget(slider, 13, 1);
0070 
0071     tmp = img;
0072     colorizedColor = Qt::blue;
0073     colorizedValue = 0.0;
0074     KIconEffect::colorize(tmp, colorizedColor, colorizedValue);
0075     lbl[4] = new QLabel(frame);
0076     lbl[4]->setPixmap(QPixmap::fromImage(tmp));
0077     layout->addWidget(lbl[4], 16, 0, 4, 1);
0078     layout->addWidget(new QLabel(QStringLiteral("Colorize"), frame), 16, 1);
0079     slider = new QSlider(Qt::Horizontal, frame);
0080     slider->setRange(0, 100);
0081     connect(slider, &QAbstractSlider::valueChanged, this, &KIconEffectTestWidget::slotColorizeValue);
0082     layout->addWidget(slider, 17, 1);
0083     KColorButton *btn = new KColorButton(colorizedColor, frame);
0084     connect(btn, &KColorButton::changed, this, &KIconEffectTestWidget::slotColorizeColor);
0085     layout->addWidget(btn, 18, 1);
0086 
0087     tmp = img;
0088     KIconEffect::semiTransparent(tmp);
0089     lbl[5] = new QLabel(frame);
0090     lbl[5]->setPixmap(QPixmap::fromImage(tmp));
0091     layout->addWidget(lbl[5], 20, 0, 3, 1);
0092     layout->addWidget(new QLabel(QStringLiteral("Semitransparent"), frame), 20, 1);
0093 
0094     layout->setRowStretch(21, 1);
0095     frame->resize(frame->sizeHint());
0096 }
0097 
0098 void KIconEffectTestWidget::slotGray(int value)
0099 {
0100     QImage tmp(img);
0101     KIconEffect::toGray(tmp, value * 0.01);
0102     lbl[0]->setPixmap(QPixmap::fromImage(tmp));
0103 }
0104 
0105 void KIconEffectTestWidget::slotMonochrome(int value)
0106 {
0107     QImage tmp(img);
0108     KIconEffect::toMonochrome(tmp, Qt::black, Qt::white, value * 0.01);
0109     lbl[1]->setPixmap(QPixmap::fromImage(tmp));
0110 }
0111 
0112 void KIconEffectTestWidget::slotDesaturate(int value)
0113 {
0114     QImage tmp(img);
0115     KIconEffect::deSaturate(tmp, value * 0.01);
0116     lbl[2]->setPixmap(QPixmap::fromImage(tmp));
0117 }
0118 
0119 void KIconEffectTestWidget::slotGamma(int value)
0120 {
0121     QImage tmp(img);
0122     KIconEffect::toGamma(tmp, value * 0.01);
0123     lbl[3]->setPixmap(QPixmap::fromImage(tmp));
0124 }
0125 
0126 void KIconEffectTestWidget::slotColorizeColor(const QColor &c)
0127 {
0128     colorizedColor = c;
0129     QImage tmp(img);
0130     KIconEffect::colorize(tmp, colorizedColor, colorizedValue);
0131     lbl[4]->setPixmap(QPixmap::fromImage(tmp));
0132 }
0133 
0134 void KIconEffectTestWidget::slotColorizeValue(int value)
0135 {
0136     colorizedValue = value * 0.01f;
0137     QImage tmp(img);
0138     KIconEffect::colorize(tmp, colorizedColor, colorizedValue);
0139     lbl[4]->setPixmap(QPixmap::fromImage(tmp));
0140 }
0141 
0142 int main(int argc, char **argv)
0143 {
0144     QApplication app(argc, argv);
0145     KIconEffectTestWidget *w = new KIconEffectTestWidget;
0146     w->show();
0147     return app.exec();
0148 }
0149 
0150 #include "moc_kiconeffecttest.cpp"