summaryrefslogtreecommitdiff
path: root/libqtaux/qcolordialog.cpp
Unidiff
Diffstat (limited to 'libqtaux/qcolordialog.cpp') (more/less context) (show whitespace changes)
-rw-r--r--libqtaux/qcolordialog.cpp357
1 files changed, 10 insertions, 347 deletions
diff --git a/libqtaux/qcolordialog.cpp b/libqtaux/qcolordialog.cpp
index 5881a89..1574841 100644
--- a/libqtaux/qcolordialog.cpp
+++ b/libqtaux/qcolordialog.cpp
@@ -37,22 +37,19 @@
37 37
38#include "qcolordialog.h" 38#include "qcolordialog.h"
39 39
40#include "qpainter.h" 40#include <qpainter.h>
41#include "qlayout.h" 41#include <qlayout.h>
42#include "qlabel.h" 42#include <qpushbutton.h>
43#include "qpushbutton.h" 43#include <qimage.h>
44#include "qlineedit.h" 44#include <qpixmap.h>
45#include "qimage.h" 45#include <qdrawutil.h>
46#include "qpixmap.h" 46#include <qdragobject.h>
47#include "qdrawutil.h" 47#include <qapplication.h>
48#include "qvalidator.h" 48#include <qdragobject.h>
49#include "qdragobject.h"
50#include "qapplication.h"
51#include "qdragobject.h"
52 49
53//////////// QWellArray BEGIN 50//////////// QWellArray BEGIN
54 51
55#include "qobjectdict.h" 52#include <qobjectdict.h>
56 53
57// 54//
58// W A R N I N G 55// W A R N I N G
@@ -65,105 +62,6 @@
65// 62//
66// 63//
67 64
68
69#include "qtableview.h"
70
71
72struct QWellArrayData;
73
74class QWellArray : public QTableView
75{
76 Q_OBJECT
77 Q_PROPERTY( int numCols READ numCols )
78 Q_PROPERTY( int numRows READ numRows )
79 Q_PROPERTY( int selectedColumn READ selectedColumn )
80 Q_PROPERTY( int selectedRow READ selectedRow )
81
82public:
83 QWellArray( QWidget *parent=0, const char *name=0, bool popup = FALSE );
84
85 ~QWellArray() {}
86 QString cellContent( int row, int col ) const;
87 // ### Paul !!! virtual void setCellContent( int row, int col, const QString &);
88
89 // ##### Obsolete since not const
90 int numCols() { return nCols; }
91 int numRows() { return nRows; }
92
93 int numCols() const { return nCols; }
94 int numRows() const { return nRows; }
95
96 // ##### Obsolete since not const
97 int selectedColumn() { return selCol; }
98 int selectedRow() { return selRow; }
99
100 int selectedColumn() const { return selCol; }
101 int selectedRow() const { return selRow; }
102
103 virtual void setSelected( int row, int col );
104
105 void setCellSize( int w, int h ) { setCellWidth(w);setCellHeight( h ); }
106
107 QSize sizeHint() const;
108
109 virtual void setDimension( int rows, int cols );
110 virtual void setCellBrush( int row, int col, const QBrush & );
111 QBrush cellBrush( int row, int col );
112
113signals:
114 void selected( int row, int col );
115
116protected:
117 virtual void setCurrent( int row, int col );
118
119 virtual void drawContents( QPainter *, int row, int col, const QRect& );
120 void drawContents( QPainter * );
121
122 void paintCell( QPainter*, int row, int col );
123 void mousePressEvent( QMouseEvent* );
124 void mouseReleaseEvent( QMouseEvent* );
125 void mouseMoveEvent( QMouseEvent* );
126 void keyPressEvent( QKeyEvent* );
127 void focusInEvent( QFocusEvent* );
128 void focusOutEvent( QFocusEvent* );
129
130private:
131 int curRow;
132 int curCol;
133 int selRow;
134 int selCol;
135 int nCols;
136 int nRows;
137 bool smallStyle;
138 QWellArrayData *d;
139
140 private:// Disabled copy constructor and operator=
141#if defined(Q_DISABLE_COPY)
142 QWellArray( const QWellArray & );
143 QWellArray& operator=( const QWellArray & );
144#endif
145};
146
147
148
149// non-interface ...
150
151
152
153struct QWellArrayData {
154 QBrush *brush;
155};
156
157// NOT REVISED
158/* WARNING, NOT
159 \class QWellArray qwellarray_p.h
160 \brief ....
161
162 ....
163
164 \ingroup advanced
165*/
166
167QWellArray::QWellArray( QWidget *parent, const char * name, bool popup ) 65QWellArray::QWellArray( QWidget *parent, const char * name, bool popup )
168 : QTableView( parent, name, 66 : QTableView( parent, name,
169 popup ? (WStyle_Customize|WStyle_Tool|WStyle_NoBorder) : 0 ) 67 popup ? (WStyle_Customize|WStyle_Tool|WStyle_NoBorder) : 0 )
@@ -566,35 +464,6 @@ static inline void rgb2hsv( QRgb rgb, int&h, int&s, int&v )
566 c.getHsv(h,s,v); 464 c.getHsv(h,s,v);
567} 465}
568 466
569class QColorWell : public QWellArray
570{
571public:
572 QColorWell( QWidget *parent, int r, int c, QRgb *vals )
573 :QWellArray( parent, "" ), values( vals ), mousePressed( FALSE ), oldCurrent( -1, -1 )
574 { setDimension(r,c); setWFlags( WResizeNoErase ); }
575 QSizePolicy sizePolicy() const;
576
577protected:
578 void drawContents( QPainter *, int row, int col, const QRect& );
579 void drawContents( QPainter *p ) { QWellArray::drawContents(p); }
580 void mousePressEvent( QMouseEvent *e );
581 void mouseMoveEvent( QMouseEvent *e );
582 void mouseReleaseEvent( QMouseEvent *e );
583#ifndef QT_NO_DRAGANDDROP
584 void dragEnterEvent( QDragEnterEvent *e );
585 void dragLeaveEvent( QDragLeaveEvent *e );
586 void dragMoveEvent( QDragMoveEvent *e );
587 void dropEvent( QDropEvent *e );
588#endif
589
590private:
591 QRgb *values;
592 bool mousePressed;
593 QPoint pressPos;
594 QPoint oldCurrent;
595
596};
597
598QSizePolicy QColorWell::sizePolicy() const 467QSizePolicy QColorWell::sizePolicy() const
599{ 468{
600 return QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ); 469 return QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
@@ -686,76 +555,9 @@ void QColorWell::mouseReleaseEvent( QMouseEvent *e )
686 mousePressed = FALSE; 555 mousePressed = FALSE;
687} 556}
688 557
689class QColorPicker : public QFrame
690{
691 Q_OBJECT
692public:
693 QColorPicker(QWidget* parent=0, const char* name=0);
694 ~QColorPicker();
695
696public slots:
697 void setCol( int h, int s );
698
699signals:
700 void newCol( int h, int s );
701
702protected:
703 QSize sizeHint() const;
704 QSizePolicy sizePolicy() const;
705 void drawContents(QPainter* p);
706 void mouseMoveEvent( QMouseEvent * );
707 void mousePressEvent( QMouseEvent * );
708
709private:
710 int hue;
711 int sat;
712
713 QPoint colPt();
714 int huePt( const QPoint &pt );
715 int satPt( const QPoint &pt );
716 void setCol( const QPoint &pt );
717
718 QPixmap *pix;
719};
720
721static int pWidth = 200; 558static int pWidth = 200;
722static int pHeight = 200; 559static int pHeight = 200;
723 560
724class QColorLuminancePicker : public QWidget
725{
726 Q_OBJECT
727public:
728 QColorLuminancePicker(QWidget* parent=0, const char* name=0);
729 ~QColorLuminancePicker();
730
731public slots:
732 void setCol( int h, int s, int v );
733 void setCol( int h, int s );
734
735signals:
736 void newHsv( int h, int s, int v );
737
738protected:
739// QSize sizeHint() const;
740// QSizePolicy sizePolicy() const;
741 void paintEvent( QPaintEvent*);
742 void mouseMoveEvent( QMouseEvent * );
743 void mousePressEvent( QMouseEvent * );
744
745private:
746 enum { foff = 3, coff = 4 }; //frame and contents offset
747 int val;
748 int hue;
749 int sat;
750
751 int y2val( int y );
752 int val2y( int val );
753 void setVal( int v );
754
755 QPixmap *pix;
756};
757
758
759int QColorLuminancePicker::y2val( int y ) 561int QColorLuminancePicker::y2val( int y )
760{ 562{
761 int d = height() - 2*coff - 1; 563 int d = height() - 2*coff - 1;
@@ -935,20 +737,6 @@ void QColorPicker::drawContents(QPainter* p)
935 737
936} 738}
937 739
938class QColorShowLabel;
939
940
941
942class QColIntValidator: public QIntValidator
943{
944public:
945 QColIntValidator( int bottom, int top,
946 QWidget * parent, const char *name = 0 )
947 :QIntValidator( bottom, top, parent, name ) {}
948
949 QValidator::State validate( QString &, int & ) const;
950};
951
952QValidator::State QColIntValidator::validate( QString &s, int &pos ) const 740QValidator::State QColIntValidator::validate( QString &s, int &pos ) const
953{ 741{
954 State state = QIntValidator::validate(s,pos); 742 State state = QIntValidator::validate(s,pos);
@@ -967,102 +755,6 @@ QValidator::State QColIntValidator::validate( QString &s, int &pos ) const
967 return state; 755 return state;
968} 756}
969 757
970
971
972class QColNumLineEdit : public QLineEdit
973{
974public:
975 QColNumLineEdit( QWidget *parent, const char* name = 0 )
976 : QLineEdit( parent, name ) { setMaxLength( 3 );}
977 QSize sizeHint() const {
978 return QSize( 30, //#####
979 QLineEdit::sizeHint().height() ); }
980 void setNum( int i ) {
981 QString s;
982 s.setNum(i);
983 bool block = signalsBlocked();
984 blockSignals(TRUE);
985 setText( s );
986 blockSignals(block);
987 }
988 int val() const { return text().toInt(); }
989};
990
991
992class QColorShower : public QWidget
993{
994 Q_OBJECT
995public:
996 QColorShower( QWidget *parent, const char *name = 0 );
997
998 //things that don't emit signals
999 void setHsv( int h, int s, int v );
1000
1001 int currentAlpha() const { return alphaEd->val(); }
1002 void setCurrentAlpha( int a ) { alphaEd->setNum( a ); }
1003 void showAlpha( bool b );
1004
1005
1006 QRgb currentColor() const { return curCol; }
1007
1008public slots:
1009 void setRgb( QRgb rgb );
1010
1011signals:
1012 void newCol( QRgb rgb );
1013private slots:
1014 void rgbEd();
1015 void hsvEd();
1016private:
1017 void showCurrentColor();
1018 int hue, sat, val;
1019 QRgb curCol;
1020 QColNumLineEdit *hEd;
1021 QColNumLineEdit *sEd;
1022 QColNumLineEdit *vEd;
1023 QColNumLineEdit *rEd;
1024 QColNumLineEdit *gEd;
1025 QColNumLineEdit *bEd;
1026 QColNumLineEdit *alphaEd;
1027 QLabel *alphaLab;
1028 QColorShowLabel *lab;
1029 bool rgbOriginal;
1030};
1031
1032class QColorShowLabel : public QFrame
1033{
1034 Q_OBJECT
1035
1036public:
1037 QColorShowLabel( QWidget *parent ) :QFrame( parent ) {
1038 setFrameStyle( QFrame::Panel|QFrame::Sunken );
1039 setBackgroundMode( PaletteBackground );
1040 setAcceptDrops( TRUE );
1041 mousePressed = FALSE;
1042 }
1043 void setColor( QColor c ) { col = c; }
1044
1045signals:
1046 void colorDropped( QRgb );
1047
1048protected:
1049 void drawContents( QPainter *p );
1050 void mousePressEvent( QMouseEvent *e );
1051 void mouseMoveEvent( QMouseEvent *e );
1052 void mouseReleaseEvent( QMouseEvent *e );
1053#ifndef QT_NO_DRAGANDDROP
1054 void dragEnterEvent( QDragEnterEvent *e );
1055 void dragLeaveEvent( QDragLeaveEvent *e );
1056 void dropEvent( QDropEvent *e );
1057#endif
1058
1059private:
1060 QColor col;
1061 bool mousePressed;
1062 QPoint pressPos;
1063
1064};
1065
1066void QColorShowLabel::drawContents( QPainter *p ) 758void QColorShowLabel::drawContents( QPainter *p )
1067{ 759{
1068 p->fillRect( contentsRect(), col ); 760 p->fillRect( contentsRect(), col );
@@ -1286,35 +978,6 @@ void QColorShower::setHsv( int h, int s, int v )
1286 showCurrentColor(); 978 showCurrentColor();
1287} 979}
1288 980
1289class QColorDialogPrivate : public QObject
1290{
1291Q_OBJECT
1292public:
1293 QColorDialogPrivate( QColorDialog *p );
1294 QRgb currentColor() const { return cs->currentColor(); }
1295 void setCurrentColor( QRgb rgb );
1296
1297 int currentAlpha() const { return cs->currentAlpha(); }
1298 void setCurrentAlpha( int a ) { cs->setCurrentAlpha( a ); }
1299 void showAlpha( bool b ) { cs->showAlpha( b ); }
1300
1301private slots:
1302 void addCustom();
1303
1304 void newHsv( int h, int s, int v );
1305 void newColorTypedIn( QRgb rgb );
1306 void newCustom( int, int );
1307 void newStandard( int, int );
1308private:
1309 QColorPicker *cp;
1310 QColorLuminancePicker *lp;
1311 QWellArray *custom;
1312 QWellArray *standard;
1313 QColorShower *cs;
1314 int nextCust;
1315 bool compact;
1316};
1317
1318//sets all widgets to display h,s,v 981//sets all widgets to display h,s,v
1319void QColorDialogPrivate::newHsv( int h, int s, int v ) 982void QColorDialogPrivate::newHsv( int h, int s, int v )
1320{ 983{