File indexing completed on 2024-04-28 04:20:13
0001 0002 /* 0003 Copyright (c) 2003-2007 Clarence Dang <dang@kde.org> 0004 All rights reserved. 0005 0006 Redistribution and use in source and binary forms, with or without 0007 modification, are permitted provided that the following conditions 0008 are met: 0009 0010 1. Redistributions of source code must retain the above copyright 0011 notice, this list of conditions and the following disclaimer. 0012 2. Redistributions in binary form must reproduce the above copyright 0013 notice, this list of conditions and the following disclaimer in the 0014 documentation and/or other materials provided with the distribution. 0015 0016 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 0017 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 0018 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 0019 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 0020 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 0021 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 0022 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 0023 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0024 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 0025 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0026 */ 0027 0028 0029 #include "kpColorSimilarityDialog.h" 0030 0031 #include "widgets/colorSimilarity/kpColorSimilarityFrame.h" 0032 0033 #include <KLocalizedString> 0034 #include "../widgets/imagelib/effects/kpNumInput.h" 0035 0036 #include <QDialogButtonBox> 0037 #include <QGroupBox> 0038 #include <QLabel> 0039 #include <QPushButton> 0040 #include <QWhatsThis> 0041 #include <QVBoxLayout> 0042 0043 kpColorSimilarityDialog::kpColorSimilarityDialog (QWidget *parent) 0044 : QDialog (parent) 0045 { 0046 setWindowTitle (i18nc ("@title:window", "Color Similarity")); 0047 auto *buttons = new QDialogButtonBox (QDialogButtonBox::Ok | 0048 QDialogButtonBox::Cancel, this); 0049 connect (buttons, &QDialogButtonBox::accepted, this, &kpColorSimilarityDialog::accept); 0050 connect (buttons, &QDialogButtonBox::rejected, this, &kpColorSimilarityDialog::reject); 0051 0052 auto *baseWidget = new QWidget (this); 0053 0054 auto *dialogLayout = new QVBoxLayout (this); 0055 dialogLayout->addWidget (baseWidget); 0056 dialogLayout->addWidget (buttons); 0057 0058 auto *cubeGroupBox = new QGroupBox (i18n ("Preview"), baseWidget); 0059 0060 m_colorSimilarityFrame = new kpColorSimilarityFrame(cubeGroupBox); 0061 m_colorSimilarityFrame->setMinimumSize (240, 180); 0062 0063 auto *updatePushButton = new QPushButton (i18n ("&Update"), cubeGroupBox); 0064 0065 0066 auto *cubeLayout = new QVBoxLayout (cubeGroupBox); 0067 cubeLayout->addWidget (m_colorSimilarityFrame, 1/*stretch*/); 0068 cubeLayout->addWidget (updatePushButton, 0/*stretch*/, Qt::AlignHCenter); 0069 0070 0071 connect (updatePushButton, &QPushButton::clicked, 0072 this, &kpColorSimilarityDialog::slotColorSimilarityValueChanged); 0073 0074 0075 auto *inputGroupBox = new QGroupBox (i18n ("&RGB Color Cube Distance"), 0076 baseWidget); 0077 0078 m_colorSimilarityInput = new kpIntNumInput (inputGroupBox); 0079 m_colorSimilarityInput->setRange (0, int (kpColorSimilarityHolder::MaxColorSimilarity * 100 + 0.1/*don't floor below target int*/), 0080 5/*step*/); 0081 m_colorSimilarityInput->setSuffix (i18n ("%")); 0082 m_colorSimilarityInput->setSpecialValueText (i18n ("Exact Match")); 0083 0084 // TODO: We have a good handbook section on this, which we should 0085 // somehow link to. 0086 m_whatIsLabel = new QLabel ( 0087 i18n ("<a href=\"dummy_to_make_link_clickable\">" 0088 "What is Color Similarity?</a>"), 0089 inputGroupBox); 0090 m_whatIsLabel->setAlignment (Qt::AlignHCenter); 0091 connect (m_whatIsLabel, &QLabel::linkActivated, 0092 this, &kpColorSimilarityDialog::slotWhatIsLabelClicked); 0093 0094 0095 auto *inputLayout = new QVBoxLayout (inputGroupBox); 0096 0097 inputLayout->addWidget (m_colorSimilarityInput); 0098 inputLayout->addWidget (m_whatIsLabel); 0099 0100 0101 // COMPAT: This is not firing properly when the user is typing in a 0102 // new value. 0103 connect (m_colorSimilarityInput, &kpIntNumInput::valueChanged, 0104 this, &kpColorSimilarityDialog::slotColorSimilarityValueChanged); 0105 0106 0107 auto *baseLayout = new QVBoxLayout (baseWidget); 0108 baseLayout->setContentsMargins(0, 0, 0, 0); 0109 baseLayout->addWidget (cubeGroupBox, 1/*stretch*/); 0110 baseLayout->addWidget (inputGroupBox); 0111 } 0112 0113 kpColorSimilarityDialog::~kpColorSimilarityDialog () = default; 0114 0115 0116 // public 0117 double kpColorSimilarityDialog::colorSimilarity () const 0118 { 0119 return m_colorSimilarityFrame->colorSimilarity (); 0120 } 0121 0122 // public 0123 void kpColorSimilarityDialog::setColorSimilarity (double similarity) 0124 { 0125 m_colorSimilarityInput->setValue (qRound (similarity * 100)); 0126 } 0127 0128 0129 // private slot 0130 void kpColorSimilarityDialog::slotColorSimilarityValueChanged () 0131 { 0132 m_colorSimilarityFrame->setColorSimilarity (double (m_colorSimilarityInput->value ()) / 100); 0133 } 0134 0135 0136 // private slot 0137 void kpColorSimilarityDialog::slotWhatIsLabelClicked () 0138 { 0139 QWhatsThis::showText(QCursor::pos(), m_colorSimilarityFrame->whatsThis(), this); 0140 } 0141 0142 #include "moc_kpColorSimilarityDialog.cpp"