File indexing completed on 2024-04-21 04:52:30

0001 /*
0002     SPDX-FileCopyrightText: 2010 Till Theato <root@ttill.de>
0003 
0004 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #include "choosecolorwidget.h"
0008 #include "colorpickerwidget.h"
0009 
0010 #include <QHBoxLayout>
0011 #include <QLabel>
0012 #include <QTextStream>
0013 
0014 #include <KColorButton>
0015 
0016 ChooseColorWidget::ChooseColorWidget(QWidget *parent, const QColor &color, bool alphaEnabled)
0017     : QWidget(parent)
0018 {
0019     auto *layout = new QHBoxLayout(this);
0020     layout->setContentsMargins(0, 0, 0, 0);
0021     layout->setSpacing(0);
0022 
0023     m_button = new KColorButton(color, this);
0024     if (alphaEnabled) {
0025         m_button->setAlphaChannelEnabled(alphaEnabled);
0026     }
0027     auto *picker = new ColorPickerWidget(this);
0028 
0029     layout->addWidget(m_button, 2);
0030     layout->addWidget(picker);
0031 
0032     connect(picker, &ColorPickerWidget::colorPicked, this, &ChooseColorWidget::setColor);
0033     connect(picker, &ColorPickerWidget::disableCurrentFilter, this, &ChooseColorWidget::disableCurrentFilter);
0034     connect(m_button, &KColorButton::changed, this, &ChooseColorWidget::modified);
0035 
0036     setMinimumHeight(m_button->sizeHint().height());
0037 }
0038 
0039 QColor ChooseColorWidget::color() const
0040 {
0041     return m_button->color();
0042 }
0043 
0044 void ChooseColorWidget::setColor(const QColor &color)
0045 {
0046     m_button->setColor(color);
0047 }
0048 
0049 bool ChooseColorWidget::isAlphaChannelEnabled() const
0050 {
0051     return m_button->isAlphaChannelEnabled();
0052 }
0053 
0054 void ChooseColorWidget::setAlphaChannelEnabled(bool alpha)
0055 {
0056     m_button->setAlphaChannelEnabled(alpha);
0057 }
0058 
0059 void ChooseColorWidget::slotColorModified(const QColor &color)
0060 {
0061     blockSignals(true);
0062     m_button->setColor(color);
0063     blockSignals(false);
0064 }