00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
00080
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;
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"