krita

kis_color_cup.cc

00001 /*
00002  * This file is part of Krita
00003  *
00004  * Copyright (c) 1999 Matthias Elter (me@kde.org)
00005  * Copyright (c) 2001-2002 Igor Jansen (rm@kde.org)
00006  *
00007  *  This program is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU General Public License as published by
00009  *  the Free Software Foundation; either version 2 of the License, or
00010  *  (at your option) any later version.
00011  *
00012  *  This program is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *  GNU General Public License for more details.
00016  *
00017  *  You should have received a copy of the GNU General Public License
00018  *  along with this program; if not, write to the Free Software
00019  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #include <qpushbutton.h>
00023 #include <qapplication.h>
00024 #include <qclipboard.h>
00025 #include <qcolor.h>
00026 #include <qdrawutil.h>
00027 #include <qhbox.h>
00028 #include <qlabel.h>
00029 #include <qlayout.h>
00030 #include <qpainter.h>
00031 #include <qspinbox.h>
00032 #include <qstyle.h>
00033 #include <qtooltip.h>
00034 #include <qwidget.h>
00035 #include <qframe.h>
00036 
00037 #include <kcolordialog.h>
00038 #include <klocale.h>
00039 #include <knuminput.h>
00040 #include <koFrameButton.h>
00041 
00042 #include <kis_canvas_subject.h>
00043 #include <kis_color.h>
00044 #include <kis_color_cup.h>
00045 
00046 KisColorPopup::KisColorPopup(QColor c, QWidget * parent, const char * name)
00047     : QFrame(parent, name, WType_Popup | WStyle_Customize | WStyle_NoBorder)
00048 {
00049     m_color = c;
00050     setMargin(4);
00051     setFocusPolicy(StrongFocus);
00052     QHBoxLayout * l  = new QHBoxLayout(this);
00053     l->add(m_khsSelector = new KHSSelector(this));
00054     m_khsSelector->setMinimumSize(140, 7);
00055     l->add(m_valueSelector = new KValueSelector(this));
00056     m_valueSelector->setMinimumSize(26, 70);
00057     m_khsSelector->show();
00058     m_valueSelector->show();
00059 
00060 }
00061 
00062 KisColorCup::KisColorCup(QWidget * parent, const char * name)
00063     : QPushButton(parent, name)
00064 {
00065     m_color = Qt::black;
00066     m_popup = new KisColorPopup(m_color, this, "colorpopup");
00067     connect(this, SIGNAL(clicked()), this, SLOT(slotClicked()));
00068     connect(m_popup, SIGNAL(changed( const QColor &)), this, SLOT(setColor(const QColor &)));
00069 }
00070 
00071 void KisColorCup::setColor(const QColor & c)
00072 {
00073     m_color = c;
00074     emit changed(c);
00075 }
00076 
00077 void KisColorCup::slotClicked()
00078 {    
00079 //    m_popup->move(this->mapToGlobal( this->rect().topRight() ) );
00080 //    m_popup->show();
00081     emit changed(m_color);
00082 }
00083 
00084 QSize KisColorCup::sizeHint() const
00085 {
00086     return style().sizeFromContents(QStyle::CT_PushButton, this, QSize(24, 24)).
00087             expandedTo(QApplication::globalStrut());
00088 }
00089 
00090 void KisColorCup::drawButtonLabel( QPainter *painter )
00091 {
00092     int x, y, w, h;
00093     QRect r = style().subRect( QStyle::SR_PushButtonContents, this );
00094     r.rect(&x, &y, &w, &h);
00095 
00096     int margin = 2; //style().pixelMetric( QStyle::PM_ButtonMargin, this );
00097     x += margin;
00098     y += margin;
00099     w -= 2*margin;
00100     h -= 2*margin;
00101 
00102     if (isOn() || isDown()) {
00103         x += style().pixelMetric( QStyle::PM_ButtonShiftHorizontal, this );
00104         y += style().pixelMetric( QStyle::PM_ButtonShiftVertical, this );
00105     }
00106 
00107     qDrawShadePanel( painter, x, y, w, h, colorGroup(), true, 1, NULL);
00108     if ( m_color.isValid() )
00109         painter->fillRect( x+1, y+1, w-2, h-2, m_color );
00110 
00111     if ( hasFocus() ) {
00112         QRect focusRect = style().subRect( QStyle::SR_PushButtonFocusRect, this );
00113         style().drawPrimitive( QStyle::PE_FocusRect, painter, focusRect, colorGroup() );
00114     }
00115 
00116 }
00117 
00118 #include "kis_color_cup.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys