diff --git a/libs/ui/widgets/KisCheckbox.cpp b/libs/ui/widgets/KisCheckbox.cpp index 88b4dd5b03..d7db06f634 100644 --- a/libs/ui/widgets/KisCheckbox.cpp +++ b/libs/ui/widgets/KisCheckbox.cpp @@ -1,76 +1,115 @@ /* This file is part of the KDE project * Copyright 2019 (C) Scott Petrovic * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "KisCheckbox.h" +#include "krita_utils.h" + +#include +#include +#include KisCheckbox::KisCheckbox(QWidget* parent) { initialize(parent, ""); } KisCheckbox::KisCheckbox(const QString &text, QWidget *parent) { initialize(parent, text); } void KisCheckbox::initialize(QWidget *parent, const QString &text) { m_label = new KisClickableLabel(text, parent); m_label->setWordWrap(true); m_checkbox = new QCheckBox(parent); m_layout = new QHBoxLayout(parent); m_layout->addWidget(m_checkbox); m_layout->addWidget(m_label); setLayout(m_layout); - connect(m_label, SIGNAL(clicked()), this, SLOT(toggle())); + connect(m_label, SIGNAL(pressed(QMouseEvent*)), this, SLOT(pressedEvent(QMouseEvent*))); + connect(m_label, SIGNAL(moved(QMouseEvent*)), this, SLOT(movedEvent(QMouseEvent*))); + connect(m_label, SIGNAL(released(QMouseEvent*)), this, SLOT(releasedEvent(QMouseEvent*))); } KisCheckbox::~KisCheckbox() { } void KisCheckbox::setText(const QString &text) { m_label->setText(text); } void KisCheckbox::setChecked(bool isChecked) { m_checkbox->setChecked(isChecked); } void KisCheckbox::toggle() { m_checkbox->toggle(); } +void KisCheckbox::pressedEvent(QMouseEvent *event) +{ + // give small style "down" state visually to help give feedback + QColor textColor = qApp->palette().color(QPalette::Text); + QColor backgroundColor = qApp->palette().color(QPalette::Background); + QColor blendedColor = KritaUtils::blendColors(textColor, backgroundColor, 0.1); + QString finalStylesheet = QString("QCheckBox{ background:").append(blendedColor.name()).append(" }") ; + m_checkbox->setStyleSheet(finalStylesheet); + + KisCheckbox::mousePressEvent(event); +} + +void KisCheckbox::movedEvent(QMouseEvent *event) +{ + KisCheckbox::mouseMoveEvent(event); +} + +void KisCheckbox::releasedEvent(QMouseEvent *event) +{ + m_checkbox->setStyleSheet(""); + toggle(); + KisCheckbox::mouseReleaseEvent(event); +} // KisClickableLabel implementation (mostly empty) KisClickableLabel::KisClickableLabel(QWidget* parent):QLabel(parent) {} KisClickableLabel::KisClickableLabel(const QString &text, QWidget* parent):QLabel(text, parent) {} KisClickableLabel::~KisClickableLabel() {} void KisClickableLabel::mouseReleaseEvent(QMouseEvent *event) { - Q_UNUSED(event); - emit clicked(); + emit released(event); +} + +void KisClickableLabel::mousePressEvent(QMouseEvent *event) +{ + emit pressed(event); +} + +void KisClickableLabel::mouseMoveEvent(QMouseEvent *event) +{ + emit moved(event); } diff --git a/libs/ui/widgets/KisCheckbox.h b/libs/ui/widgets/KisCheckbox.h index 60884f5bce..f9b1665930 100644 --- a/libs/ui/widgets/KisCheckbox.h +++ b/libs/ui/widgets/KisCheckbox.h @@ -1,78 +1,85 @@ /* This file is part of the KDE project * Copyright 2019 (C) Scott Petrovic * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KIS_CHECKBOX_H #define KIS_CHECKBOX_H #include #include #include #include #include #include - /* Labels are not clickable, so we need to make a tiny internal class to allow them do that */ class KRITAUI_EXPORT KisClickableLabel : public QLabel { Q_OBJECT public: KisClickableLabel(QWidget *parent = 0); KisClickableLabel(const QString &text, QWidget *parent = 0); ~KisClickableLabel(); Q_SIGNALS: - void clicked(); + void clicked(QMouseEvent *event); + void pressed(QMouseEvent *event); + void moved(QMouseEvent *event); + void released(QMouseEvent *event); protected: void mouseReleaseEvent(QMouseEvent *ev); + void mousePressEvent(QMouseEvent *ev); + void mouseMoveEvent(QMouseEvent *ev); }; /* the default QCheckbox widget has no ability to word wrap its text * This causes issues with making our user interfaces work on smaller * screen sizes and making layouts smaller */ class KRITAUI_EXPORT KisCheckbox : public QWidget { Q_OBJECT public: KisCheckbox(QWidget *parent = 0); KisCheckbox(const QString &text, QWidget *parent = 0); ~KisCheckbox(); void setText(const QString &text); void setChecked(bool isChecked); public Q_SLOTS: void toggle(); + void pressedEvent(QMouseEvent *event); + void movedEvent(QMouseEvent *event); + void releasedEvent(QMouseEvent *event); protected: void initialize(QWidget *parent = 0, const QString &text = ""); private: KisClickableLabel *m_label; QCheckBox *m_checkbox; QHBoxLayout *m_layout; }; #endif // KIS_CHECKBOX_H