-rw-r--r-- | libqtaux/libqtaux.pro | 1 | ||||
-rw-r--r-- | libqtaux/qcolordialog.cpp | 358 | ||||
-rw-r--r-- | libqtaux/qcolordialog.h | 311 |
3 files changed, 348 insertions, 322 deletions
diff --git a/libqtaux/libqtaux.pro b/libqtaux/libqtaux.pro index 56ccc65..a1440e3 100644 --- a/libqtaux/libqtaux.pro +++ b/libqtaux/libqtaux.pro | |||
@@ -10,16 +10,15 @@ HEADERS = qcolordialog.h \ | |||
10 | 10 | ||
11 | 11 | ||
12 | SOURCES = qcolordialog.cpp \ | 12 | SOURCES = qcolordialog.cpp \ |
13 | qsplitter.cpp \ | 13 | qsplitter.cpp \ |
14 | qinputdialog.cpp \ | 14 | qinputdialog.cpp \ |
15 | \ | 15 | \ |
16 | ocolorpopupmenu.cpp \ | 16 | ocolorpopupmenu.cpp \ |
17 | ocolorbutton.cpp | 17 | ocolorbutton.cpp |
18 | 18 | ||
19 | TARGET = qtaux2 | 19 | TARGET = qtaux2 |
20 | INCLUDEPATH += $(OPIEDIR)/include | 20 | INCLUDEPATH += $(OPIEDIR)/include |
21 | DESTDIR = $(OPIEDIR)/lib | 21 | DESTDIR = $(OPIEDIR)/lib |
22 | INTERFACES = | ||
23 | 22 | ||
24 | 23 | ||
25 | include ( $(OPIEDIR)/include.pro ) | 24 | include ( $(OPIEDIR)/include.pro ) |
diff --git a/libqtaux/qcolordialog.cpp b/libqtaux/qcolordialog.cpp index 1574841..b960b04 100644 --- a/libqtaux/qcolordialog.cpp +++ b/libqtaux/qcolordialog.cpp | |||
@@ -28,49 +28,151 @@ | |||
28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for | 28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for |
29 | ** information about Qt Commercial License Agreements. | 29 | ** information about Qt Commercial License Agreements. |
30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information. | 30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information. |
31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
32 | ** | 32 | ** |
33 | ** Contact info@trolltech.com if any conditions of this licensing are | 33 | ** Contact info@trolltech.com if any conditions of this licensing are |
34 | ** not clear to you. | 34 | ** not clear to you. |
35 | ** | 35 | ** |
36 | **********************************************************************/ | 36 | **********************************************************************/ |
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 <qpushbutton.h> | 42 | #include "qlabel.h" |
43 | #include <qimage.h> | 43 | #include "qpushbutton.h" |
44 | #include <qpixmap.h> | 44 | #include "qlineedit.h" |
45 | #include <qdrawutil.h> | 45 | #include "qimage.h" |
46 | #include <qdragobject.h> | 46 | #include "qpixmap.h" |
47 | #include <qapplication.h> | 47 | #include "qdrawutil.h" |
48 | #include <qdragobject.h> | 48 | #include "qvalidator.h" |
49 | #include "qdragobject.h" | ||
50 | #include "qapplication.h" | ||
51 | #include "qdragobject.h" | ||
49 | 52 | ||
50 | //////////// QWellArray BEGIN | 53 | //////////// QWellArray BEGIN |
51 | 54 | ||
52 | #include <qobjectdict.h> | 55 | #include "qobjectdict.h" |
53 | 56 | ||
54 | // | 57 | // |
55 | // W A R N I N G | 58 | // W A R N I N G |
56 | // ------------- | 59 | // ------------- |
57 | // | 60 | // |
58 | // This file is not part of the Qt API. It exists for the convenience | 61 | // This file is not part of the Qt API. It exists for the convenience |
59 | // of qwellarray.cpp and qcolordialog.cpp. | 62 | // of qwellarray.cpp and qcolordialog.cpp. |
60 | // This header file may change from version to version without notice, | 63 | // This header file may change from version to version without notice, |
61 | // or even be removed. | 64 | // or even be removed. |
62 | // | 65 | // |
63 | // | 66 | // |
64 | 67 | ||
68 | |||
69 | #include "qtableview.h" | ||
70 | |||
71 | |||
72 | struct QWellArrayData; | ||
73 | |||
74 | class 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 | |||
82 | public: | ||
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 | |||
113 | signals: | ||
114 | void selected( int row, int col ); | ||
115 | |||
116 | protected: | ||
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 | |||
130 | private: | ||
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 | |||
153 | struct 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 | |||
65 | QWellArray::QWellArray( QWidget *parent, const char * name, bool popup ) | 167 | QWellArray::QWellArray( QWidget *parent, const char * name, bool popup ) |
66 | : QTableView( parent, name, | 168 | : QTableView( parent, name, |
67 | popup ? (WStyle_Customize|WStyle_Tool|WStyle_NoBorder) : 0 ) | 169 | popup ? (WStyle_Customize|WStyle_Tool|WStyle_NoBorder) : 0 ) |
68 | { | 170 | { |
69 | d = 0; | 171 | d = 0; |
70 | setFocusPolicy( StrongFocus ); | 172 | setFocusPolicy( StrongFocus ); |
71 | setBackgroundMode( PaletteButton ); | 173 | setBackgroundMode( PaletteButton ); |
72 | nCols = 7; | 174 | nCols = 7; |
73 | nRows = 7; | 175 | nRows = 7; |
74 | int w = 24; // cell width | 176 | int w = 24; // cell width |
75 | int h = 21; // cell height | 177 | int h = 21; // cell height |
76 | smallStyle = popup; | 178 | smallStyle = popup; |
@@ -455,24 +557,53 @@ void QColorDialog::setCustomColor( int i, QRgb c ) | |||
455 | return; | 557 | return; |
456 | } | 558 | } |
457 | cusrgb[i] = c; | 559 | cusrgb[i] = c; |
458 | } | 560 | } |
459 | 561 | ||
460 | static inline void rgb2hsv( QRgb rgb, int&h, int&s, int&v ) | 562 | static inline void rgb2hsv( QRgb rgb, int&h, int&s, int&v ) |
461 | { | 563 | { |
462 | QColor c; | 564 | QColor c; |
463 | c.setRgb( rgb ); | 565 | c.setRgb( rgb ); |
464 | c.getHsv(h,s,v); | 566 | c.getHsv(h,s,v); |
465 | } | 567 | } |
466 | 568 | ||
569 | class QColorWell : public QWellArray | ||
570 | { | ||
571 | public: | ||
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 | |||
577 | protected: | ||
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 | |||
590 | private: | ||
591 | QRgb *values; | ||
592 | bool mousePressed; | ||
593 | QPoint pressPos; | ||
594 | QPoint oldCurrent; | ||
595 | |||
596 | }; | ||
597 | |||
467 | QSizePolicy QColorWell::sizePolicy() const | 598 | QSizePolicy QColorWell::sizePolicy() const |
468 | { | 599 | { |
469 | return QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ); | 600 | return QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ); |
470 | } | 601 | } |
471 | 602 | ||
472 | void QColorWell::drawContents( QPainter *p, int row, int col, const QRect &r ) | 603 | void QColorWell::drawContents( QPainter *p, int row, int col, const QRect &r ) |
473 | { | 604 | { |
474 | int i = row + col*numRows(); | 605 | int i = row + col*numRows(); |
475 | p->fillRect( r, QColor( values[i] ) ); | 606 | p->fillRect( r, QColor( values[i] ) ); |
476 | } | 607 | } |
477 | 608 | ||
478 | void QColorWell::mousePressEvent( QMouseEvent *e ) | 609 | void QColorWell::mousePressEvent( QMouseEvent *e ) |
@@ -546,27 +677,94 @@ void QColorWell::dropEvent( QDropEvent *e ) | |||
546 | } | 677 | } |
547 | 678 | ||
548 | #endif // QT_NO_DRAGANDDROP | 679 | #endif // QT_NO_DRAGANDDROP |
549 | 680 | ||
550 | void QColorWell::mouseReleaseEvent( QMouseEvent *e ) | 681 | void QColorWell::mouseReleaseEvent( QMouseEvent *e ) |
551 | { | 682 | { |
552 | if ( !mousePressed ) | 683 | if ( !mousePressed ) |
553 | return; | 684 | return; |
554 | QWellArray::mouseReleaseEvent( e ); | 685 | QWellArray::mouseReleaseEvent( e ); |
555 | mousePressed = FALSE; | 686 | mousePressed = FALSE; |
556 | } | 687 | } |
557 | 688 | ||
689 | class QColorPicker : public QFrame | ||
690 | { | ||
691 | Q_OBJECT | ||
692 | public: | ||
693 | QColorPicker(QWidget* parent=0, const char* name=0); | ||
694 | ~QColorPicker(); | ||
695 | |||
696 | public slots: | ||
697 | void setCol( int h, int s ); | ||
698 | |||
699 | signals: | ||
700 | void newCol( int h, int s ); | ||
701 | |||
702 | protected: | ||
703 | QSize sizeHint() const; | ||
704 | QSizePolicy sizePolicy() const; | ||
705 | void drawContents(QPainter* p); | ||
706 | void mouseMoveEvent( QMouseEvent * ); | ||
707 | void mousePressEvent( QMouseEvent * ); | ||
708 | |||
709 | private: | ||
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 | |||
558 | static int pWidth = 200; | 721 | static int pWidth = 200; |
559 | static int pHeight = 200; | 722 | static int pHeight = 200; |
560 | 723 | ||
724 | class QColorLuminancePicker : public QWidget | ||
725 | { | ||
726 | Q_OBJECT | ||
727 | public: | ||
728 | QColorLuminancePicker(QWidget* parent=0, const char* name=0); | ||
729 | ~QColorLuminancePicker(); | ||
730 | |||
731 | public slots: | ||
732 | void setCol( int h, int s, int v ); | ||
733 | void setCol( int h, int s ); | ||
734 | |||
735 | signals: | ||
736 | void newHsv( int h, int s, int v ); | ||
737 | |||
738 | protected: | ||
739 | // QSize sizeHint() const; | ||
740 | // QSizePolicy sizePolicy() const; | ||
741 | void paintEvent( QPaintEvent*); | ||
742 | void mouseMoveEvent( QMouseEvent * ); | ||
743 | void mousePressEvent( QMouseEvent * ); | ||
744 | |||
745 | private: | ||
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 | |||
561 | int QColorLuminancePicker::y2val( int y ) | 759 | int QColorLuminancePicker::y2val( int y ) |
562 | { | 760 | { |
563 | int d = height() - 2*coff - 1; | 761 | int d = height() - 2*coff - 1; |
564 | return 255 - (y - coff)*255/d; | 762 | return 255 - (y - coff)*255/d; |
565 | } | 763 | } |
566 | 764 | ||
567 | int QColorLuminancePicker::val2y( int v ) | 765 | int QColorLuminancePicker::val2y( int v ) |
568 | { | 766 | { |
569 | int d = height() - 2*coff - 1; | 767 | int d = height() - 2*coff - 1; |
570 | return coff + (255-v)*d/255; | 768 | return coff + (255-v)*d/255; |
571 | } | 769 | } |
572 | 770 | ||
@@ -728,42 +926,152 @@ void QColorPicker::drawContents(QPainter* p) | |||
728 | { | 926 | { |
729 | QRect r = contentsRect(); | 927 | QRect r = contentsRect(); |
730 | 928 | ||
731 | p->drawPixmap( r.topLeft(), *pix ); | 929 | p->drawPixmap( r.topLeft(), *pix ); |
732 | QPoint pt = colPt() + r.topLeft(); | 930 | QPoint pt = colPt() + r.topLeft(); |
733 | p->setPen( QPen(black) ); | 931 | p->setPen( QPen(black) ); |
734 | 932 | ||
735 | p->fillRect( pt.x()-9, pt.y(), 20, 2, black ); | 933 | p->fillRect( pt.x()-9, pt.y(), 20, 2, black ); |
736 | p->fillRect( pt.x(), pt.y()-9, 2, 20, black ); | 934 | p->fillRect( pt.x(), pt.y()-9, 2, 20, black ); |
737 | 935 | ||
738 | } | 936 | } |
739 | 937 | ||
938 | class QColorShowLabel; | ||
939 | |||
940 | |||
941 | |||
942 | class QColIntValidator: public QIntValidator | ||
943 | { | ||
944 | public: | ||
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 | |||
740 | QValidator::State QColIntValidator::validate( QString &s, int &pos ) const | 952 | QValidator::State QColIntValidator::validate( QString &s, int &pos ) const |
741 | { | 953 | { |
742 | State state = QIntValidator::validate(s,pos); | 954 | State state = QIntValidator::validate(s,pos); |
743 | if ( state == Valid ) { | 955 | if ( state == Valid ) { |
744 | long int val = s.toLong(); | 956 | long int val = s.toLong(); |
745 | // This is not a general solution, assumes that top() > 0 and | 957 | // This is not a general solution, assumes that top() > 0 and |
746 | // bottom >= 0 | 958 | // bottom >= 0 |
747 | if ( val < 0 ) { | 959 | if ( val < 0 ) { |
748 | s = "0"; | 960 | s = "0"; |
749 | pos = 1; | 961 | pos = 1; |
750 | } else if ( val > top() ) { | 962 | } else if ( val > top() ) { |
751 | s.setNum( top() ); | 963 | s.setNum( top() ); |
752 | pos = s.length(); | 964 | pos = s.length(); |
753 | } | 965 | } |
754 | } | 966 | } |
755 | return state; | 967 | return state; |
756 | } | 968 | } |
757 | 969 | ||
970 | |||
971 | |||
972 | class QColNumLineEdit : public QLineEdit | ||
973 | { | ||
974 | public: | ||
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 | |||
992 | class QColorShower : public QWidget | ||
993 | { | ||
994 | Q_OBJECT | ||
995 | public: | ||
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 | |||
1008 | public slots: | ||
1009 | void setRgb( QRgb rgb ); | ||
1010 | |||
1011 | signals: | ||
1012 | void newCol( QRgb rgb ); | ||
1013 | private slots: | ||
1014 | void rgbEd(); | ||
1015 | void hsvEd(); | ||
1016 | private: | ||
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 | |||
1032 | class QColorShowLabel : public QFrame | ||
1033 | { | ||
1034 | Q_OBJECT | ||
1035 | |||
1036 | public: | ||
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 | |||
1045 | signals: | ||
1046 | void colorDropped( QRgb ); | ||
1047 | |||
1048 | protected: | ||
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 | |||
1059 | private: | ||
1060 | QColor col; | ||
1061 | bool mousePressed; | ||
1062 | QPoint pressPos; | ||
1063 | |||
1064 | }; | ||
1065 | |||
758 | void QColorShowLabel::drawContents( QPainter *p ) | 1066 | void QColorShowLabel::drawContents( QPainter *p ) |
759 | { | 1067 | { |
760 | p->fillRect( contentsRect(), col ); | 1068 | p->fillRect( contentsRect(), col ); |
761 | } | 1069 | } |
762 | 1070 | ||
763 | void QColorShower::showAlpha( bool b ) | 1071 | void QColorShower::showAlpha( bool b ) |
764 | { | 1072 | { |
765 | if ( b ) { | 1073 | if ( b ) { |
766 | alphaLab->show(); | 1074 | alphaLab->show(); |
767 | alphaEd->show(); | 1075 | alphaEd->show(); |
768 | } else { | 1076 | } else { |
769 | alphaLab->hide(); | 1077 | alphaLab->hide(); |
@@ -969,24 +1277,53 @@ void QColorShower::setHsv( int h, int s, int v ) | |||
969 | hEd->setNum( hue ); | 1277 | hEd->setNum( hue ); |
970 | sEd->setNum( sat ); | 1278 | sEd->setNum( sat ); |
971 | vEd->setNum( val ); | 1279 | vEd->setNum( val ); |
972 | 1280 | ||
973 | rEd->setNum( qRed(currentColor()) ); | 1281 | rEd->setNum( qRed(currentColor()) ); |
974 | gEd->setNum( qGreen(currentColor()) ); | 1282 | gEd->setNum( qGreen(currentColor()) ); |
975 | bEd->setNum( qBlue(currentColor()) ); | 1283 | bEd->setNum( qBlue(currentColor()) ); |
976 | 1284 | ||
977 | 1285 | ||
978 | showCurrentColor(); | 1286 | showCurrentColor(); |
979 | } | 1287 | } |
980 | 1288 | ||
1289 | class QColorDialogPrivate : public QObject | ||
1290 | { | ||
1291 | Q_OBJECT | ||
1292 | public: | ||
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 | |||
1301 | private 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 ); | ||
1308 | private: | ||
1309 | QColorPicker *cp; | ||
1310 | QColorLuminancePicker *lp; | ||
1311 | QWellArray *custom; | ||
1312 | QWellArray *standard; | ||
1313 | QColorShower *cs; | ||
1314 | int nextCust; | ||
1315 | bool compact; | ||
1316 | }; | ||
1317 | |||
981 | //sets all widgets to display h,s,v | 1318 | //sets all widgets to display h,s,v |
982 | void QColorDialogPrivate::newHsv( int h, int s, int v ) | 1319 | void QColorDialogPrivate::newHsv( int h, int s, int v ) |
983 | { | 1320 | { |
984 | cs->setHsv( h, s, v ); | 1321 | cs->setHsv( h, s, v ); |
985 | cp->setCol( h, s ); | 1322 | cp->setCol( h, s ); |
986 | lp->setCol( h, s, v ); | 1323 | lp->setCol( h, s, v ); |
987 | } | 1324 | } |
988 | 1325 | ||
989 | //sets all widgets to display rgb | 1326 | //sets all widgets to display rgb |
990 | void QColorDialogPrivate::setCurrentColor( QRgb rgb ) | 1327 | void QColorDialogPrivate::setCurrentColor( QRgb rgb ) |
991 | { | 1328 | { |
992 | cs->setRgb( rgb ); | 1329 | cs->setRgb( rgb ); |
@@ -1281,12 +1618,13 @@ void QColorDialog::setSelectedAlpha( int a ) | |||
1281 | 1618 | ||
1282 | 1619 | ||
1283 | /*! | 1620 | /*! |
1284 | Returns the value selected for the alpha channel. | 1621 | Returns the value selected for the alpha channel. |
1285 | */ | 1622 | */ |
1286 | 1623 | ||
1287 | int QColorDialog::selectedAlpha() const | 1624 | int QColorDialog::selectedAlpha() const |
1288 | { | 1625 | { |
1289 | return d->currentAlpha(); | 1626 | return d->currentAlpha(); |
1290 | } | 1627 | } |
1291 | 1628 | ||
1292 | 1629 | ||
1630 | #include "qcolordialog.moc" \ No newline at end of file | ||
diff --git a/libqtaux/qcolordialog.h b/libqtaux/qcolordialog.h index 50c6482..89c6283 100644 --- a/libqtaux/qcolordialog.h +++ b/libqtaux/qcolordialog.h | |||
@@ -33,306 +33,24 @@ | |||
33 | ** Contact info@trolltech.com if any conditions of this licensing are | 33 | ** Contact info@trolltech.com if any conditions of this licensing are |
34 | ** not clear to you. | 34 | ** not clear to you. |
35 | ** | 35 | ** |
36 | **********************************************************************/ | 36 | **********************************************************************/ |
37 | 37 | ||
38 | #ifndef QCOLORDIALOG_H | 38 | #ifndef QCOLORDIALOG_H |
39 | #define QCOLORDIALOG_H | 39 | #define QCOLORDIALOG_H |
40 | 40 | ||
41 | #ifndef QT_H | 41 | #ifndef QT_H |
42 | #include <qdialog.h> | 42 | #include <qdialog.h> |
43 | #endif // QT_H | 43 | #endif // QT_H |
44 | 44 | ||
45 | #include <qlabel.h> | ||
46 | #include <qlineedit.h> | ||
47 | #include <qtableview.h> | ||
48 | #include <qvalidator.h> | ||
49 | |||
50 | struct QWellArrayData; | ||
51 | |||
52 | class QWellArray : public QTableView | ||
53 | { | ||
54 | Q_OBJECT | ||
55 | // Q_PROPERTY( int numCols READ numCols ) | ||
56 | // Q_PROPERTY( int numRows READ numRows ) | ||
57 | // Q_PROPERTY( int selectedColumn READ selectedColumn ) | ||
58 | // Q_PROPERTY( int selectedRow READ selectedRow ) | ||
59 | |||
60 | public: | ||
61 | QWellArray( QWidget *parent=0, const char *name=0, bool popup = FALSE ); | ||
62 | |||
63 | ~QWellArray() {} | ||
64 | QString cellContent( int row, int col ) const; | ||
65 | // ### Paul !!! virtual void setCellContent( int row, int col, const QString &); | ||
66 | |||
67 | // ##### Obsolete since not const | ||
68 | int numCols() { return nCols; } | ||
69 | int numRows() { return nRows; } | ||
70 | |||
71 | int numCols() const { return nCols; } | ||
72 | int numRows() const { return nRows; } | ||
73 | |||
74 | // ##### Obsolete since not const | ||
75 | int selectedColumn() { return selCol; } | ||
76 | int selectedRow() { return selRow; } | ||
77 | |||
78 | int selectedColumn() const { return selCol; } | ||
79 | int selectedRow() const { return selRow; } | ||
80 | |||
81 | virtual void setSelected( int row, int col ); | ||
82 | |||
83 | void setCellSize( int w, int h ) { setCellWidth(w);setCellHeight( h ); } | ||
84 | |||
85 | QSize sizeHint() const; | ||
86 | |||
87 | virtual void setDimension( int rows, int cols ); | ||
88 | virtual void setCellBrush( int row, int col, const QBrush & ); | ||
89 | QBrush cellBrush( int row, int col ); | ||
90 | |||
91 | signals: | ||
92 | void selected( int row, int col ); | ||
93 | |||
94 | protected: | ||
95 | virtual void setCurrent( int row, int col ); | ||
96 | |||
97 | virtual void drawContents( QPainter *, int row, int col, const QRect& ); | ||
98 | void drawContents( QPainter * ); | ||
99 | |||
100 | void paintCell( QPainter*, int row, int col ); | ||
101 | void mousePressEvent( QMouseEvent* ); | ||
102 | void mouseReleaseEvent( QMouseEvent* ); | ||
103 | void mouseMoveEvent( QMouseEvent* ); | ||
104 | void keyPressEvent( QKeyEvent* ); | ||
105 | void focusInEvent( QFocusEvent* ); | ||
106 | void focusOutEvent( QFocusEvent* ); | ||
107 | |||
108 | private: | ||
109 | int curRow; | ||
110 | int curCol; | ||
111 | int selRow; | ||
112 | int selCol; | ||
113 | int nCols; | ||
114 | int nRows; | ||
115 | bool smallStyle; | ||
116 | QWellArrayData *d; | ||
117 | |||
118 | private: // Disabled copy constructor and operator= | ||
119 | #if defined(Q_DISABLE_COPY) | ||
120 | QWellArray( const QWellArray & ); | ||
121 | QWellArray& operator=( const QWellArray & ); | ||
122 | #endif | ||
123 | }; | ||
124 | |||
125 | struct QWellArrayData { | ||
126 | QBrush *brush; | ||
127 | }; | ||
128 | |||
129 | class QColNumLineEdit : public QLineEdit | ||
130 | { | ||
131 | public: | ||
132 | QColNumLineEdit( QWidget *parent, const char* name = 0 ) | ||
133 | : QLineEdit( parent, name ) { setMaxLength( 3 );} | ||
134 | QSize sizeHint() const { | ||
135 | return QSize( 30, //##### | ||
136 | QLineEdit::sizeHint().height() ); } | ||
137 | void setNum( int i ) { | ||
138 | QString s; | ||
139 | s.setNum(i); | ||
140 | bool block = signalsBlocked(); | ||
141 | blockSignals(TRUE); | ||
142 | setText( s ); | ||
143 | blockSignals(block); | ||
144 | } | ||
145 | int val() const { return text().toInt(); } | ||
146 | }; | ||
147 | |||
148 | class QColorShowLabel : public QFrame | ||
149 | { | ||
150 | Q_OBJECT | ||
151 | |||
152 | public: | ||
153 | QColorShowLabel( QWidget *parent ) :QFrame( parent ) { | ||
154 | setFrameStyle( QFrame::Panel|QFrame::Sunken ); | ||
155 | setBackgroundMode( PaletteBackground ); | ||
156 | setAcceptDrops( TRUE ); | ||
157 | mousePressed = FALSE; | ||
158 | } | ||
159 | void setColor( QColor c ) { col = c; } | ||
160 | |||
161 | signals: | ||
162 | void colorDropped( QRgb ); | ||
163 | |||
164 | protected: | ||
165 | void drawContents( QPainter *p ); | ||
166 | void mousePressEvent( QMouseEvent *e ); | ||
167 | void mouseMoveEvent( QMouseEvent *e ); | ||
168 | void mouseReleaseEvent( QMouseEvent *e ); | ||
169 | #ifndef QT_NO_DRAGANDDROP | ||
170 | void dragEnterEvent( QDragEnterEvent *e ); | ||
171 | void dragLeaveEvent( QDragLeaveEvent *e ); | ||
172 | void dropEvent( QDropEvent *e ); | ||
173 | #endif | ||
174 | |||
175 | private: | ||
176 | QColor col; | ||
177 | bool mousePressed; | ||
178 | QPoint pressPos; | ||
179 | |||
180 | }; | ||
181 | |||
182 | class QColorShower : public QWidget | ||
183 | { | ||
184 | Q_OBJECT | ||
185 | public: | ||
186 | QColorShower( QWidget *parent, const char *name = 0 ); | ||
187 | |||
188 | //things that don't emit signals | ||
189 | void setHsv( int h, int s, int v ); | ||
190 | |||
191 | int currentAlpha() const { return alphaEd->val(); } | ||
192 | void setCurrentAlpha( int a ) { alphaEd->setNum( a ); } | ||
193 | void showAlpha( bool b ); | ||
194 | |||
195 | |||
196 | QRgb currentColor() const { return curCol; } | ||
197 | |||
198 | public slots: | ||
199 | void setRgb( QRgb rgb ); | ||
200 | |||
201 | signals: | ||
202 | void newCol( QRgb rgb ); | ||
203 | private slots: | ||
204 | void rgbEd(); | ||
205 | void hsvEd(); | ||
206 | private: | ||
207 | void showCurrentColor(); | ||
208 | int hue, sat, val; | ||
209 | QRgb curCol; | ||
210 | QColNumLineEdit *hEd; | ||
211 | QColNumLineEdit *sEd; | ||
212 | QColNumLineEdit *vEd; | ||
213 | QColNumLineEdit *rEd; | ||
214 | QColNumLineEdit *gEd; | ||
215 | QColNumLineEdit *bEd; | ||
216 | QColNumLineEdit *alphaEd; | ||
217 | QLabel *alphaLab; | ||
218 | QColorShowLabel *lab; | ||
219 | bool rgbOriginal; | ||
220 | }; | ||
221 | |||
222 | class QColorPicker : public QFrame | ||
223 | { | ||
224 | Q_OBJECT | ||
225 | public: | ||
226 | QColorPicker(QWidget* parent=0, const char* name=0); | ||
227 | ~QColorPicker(); | ||
228 | |||
229 | public slots: | ||
230 | void setCol( int h, int s ); | ||
231 | |||
232 | signals: | ||
233 | void newCol( int h, int s ); | ||
234 | |||
235 | protected: | ||
236 | QSize sizeHint() const; | ||
237 | QSizePolicy sizePolicy() const; | ||
238 | void drawContents(QPainter* p); | ||
239 | void mouseMoveEvent( QMouseEvent * ); | ||
240 | void mousePressEvent( QMouseEvent * ); | ||
241 | |||
242 | private: | ||
243 | int hue; | ||
244 | int sat; | ||
245 | |||
246 | QPoint colPt(); | ||
247 | int huePt( const QPoint &pt ); | ||
248 | int satPt( const QPoint &pt ); | ||
249 | void setCol( const QPoint &pt ); | ||
250 | |||
251 | QPixmap *pix; | ||
252 | }; | ||
253 | |||
254 | class QColorLuminancePicker : public QWidget | ||
255 | { | ||
256 | Q_OBJECT | ||
257 | public: | ||
258 | QColorLuminancePicker(QWidget* parent=0, const char* name=0); | ||
259 | ~QColorLuminancePicker(); | ||
260 | |||
261 | public slots: | ||
262 | void setCol( int h, int s, int v ); | ||
263 | void setCol( int h, int s ); | ||
264 | |||
265 | signals: | ||
266 | void newHsv( int h, int s, int v ); | ||
267 | |||
268 | protected: | ||
269 | // QSize sizeHint() const; | ||
270 | // QSizePolicy sizePolicy() const; | ||
271 | void paintEvent( QPaintEvent*); | ||
272 | void mouseMoveEvent( QMouseEvent * ); | ||
273 | void mousePressEvent( QMouseEvent * ); | ||
274 | |||
275 | private: | ||
276 | enum { foff = 3, coff = 4 }; //frame and contents offset | ||
277 | int val; | ||
278 | int hue; | ||
279 | int sat; | ||
280 | |||
281 | int y2val( int y ); | ||
282 | int val2y( int val ); | ||
283 | void setVal( int v ); | ||
284 | |||
285 | QPixmap *pix; | ||
286 | }; | ||
287 | |||
288 | class QColorWell : public QWellArray | ||
289 | { | ||
290 | public: | ||
291 | QColorWell( QWidget *parent, int r, int c, QRgb *vals ) | ||
292 | :QWellArray( parent, "" ), values( vals ), mousePressed( FALSE ), oldCurrent( -1, -1 ) | ||
293 | { setDimension(r,c); setWFlags( WResizeNoErase ); } | ||
294 | QSizePolicy sizePolicy() const; | ||
295 | |||
296 | protected: | ||
297 | void drawContents( QPainter *, int row, int col, const QRect& ); | ||
298 | void drawContents( QPainter *p ) { QWellArray::drawContents(p); } | ||
299 | void mousePressEvent( QMouseEvent *e ); | ||
300 | void mouseMoveEvent( QMouseEvent *e ); | ||
301 | void mouseReleaseEvent( QMouseEvent *e ); | ||
302 | #ifndef QT_NO_DRAGANDDROP | ||
303 | void dragEnterEvent( QDragEnterEvent *e ); | ||
304 | void dragLeaveEvent( QDragLeaveEvent *e ); | ||
305 | void dragMoveEvent( QDragMoveEvent *e ); | ||
306 | void dropEvent( QDropEvent *e ); | ||
307 | #endif | ||
308 | |||
309 | private: | ||
310 | QRgb *values; | ||
311 | bool mousePressed; | ||
312 | QPoint pressPos; | ||
313 | QPoint oldCurrent; | ||
314 | |||
315 | }; | ||
316 | |||
317 | class QColIntValidator: public QIntValidator | ||
318 | { | ||
319 | public: | ||
320 | QColIntValidator( int bottom, int top, | ||
321 | QWidget * parent, const char *name = 0 ) | ||
322 | :QIntValidator( bottom, top, parent, name ) {} | ||
323 | |||
324 | QValidator::State validate( QString &, int & ) const; | ||
325 | }; | ||
326 | |||
327 | class QColorDialogPrivate; | 45 | class QColorDialogPrivate; |
328 | 46 | ||
329 | class Q_EXPORT QColorDialog : public QDialog | 47 | class Q_EXPORT QColorDialog : public QDialog |
330 | { | 48 | { |
331 | Q_OBJECT | 49 | Q_OBJECT |
332 | 50 | ||
333 | public: | 51 | public: |
334 | static QColor getColor( QColor, QWidget *parent=0, const char* name=0 ); // ### 3.0: make const QColor& | 52 | static QColor getColor( QColor, QWidget *parent=0, const char* name=0 ); // ### 3.0: make const QColor& |
335 | static QRgb getRgba( QRgb, bool* ok = 0, | 53 | static QRgb getRgba( QRgb, bool* ok = 0, |
336 | QWidget *parent=0, const char* name=0 ); | 54 | QWidget *parent=0, const char* name=0 ); |
337 | 55 | ||
338 | 56 | ||
@@ -354,42 +72,13 @@ private: | |||
354 | void showCustom( bool=TRUE ); | 72 | void showCustom( bool=TRUE ); |
355 | private: | 73 | private: |
356 | QColorDialogPrivate *d; | 74 | QColorDialogPrivate *d; |
357 | friend class QColorDialogPrivate; | 75 | friend class QColorDialogPrivate; |
358 | 76 | ||
359 | private: // Disabled copy constructor and operator= | 77 | private: // Disabled copy constructor and operator= |
360 | #if defined(Q_DISABLE_COPY) | 78 | #if defined(Q_DISABLE_COPY) |
361 | QColorDialog( const QColorDialog & ); | 79 | QColorDialog( const QColorDialog & ); |
362 | QColorDialog& operator=( const QColorDialog & ); | 80 | QColorDialog& operator=( const QColorDialog & ); |
363 | #endif | 81 | #endif |
364 | }; | 82 | }; |
365 | 83 | ||
366 | class QColorDialogPrivate : public QObject | ||
367 | { | ||
368 | Q_OBJECT | ||
369 | public: | ||
370 | QColorDialogPrivate( QColorDialog *p ); | ||
371 | QRgb currentColor() const { return cs->currentColor(); } | ||
372 | void setCurrentColor( QRgb rgb ); | ||
373 | |||
374 | int currentAlpha() const { return cs->currentAlpha(); } | ||
375 | void setCurrentAlpha( int a ) { cs->setCurrentAlpha( a ); } | ||
376 | void showAlpha( bool b ) { cs->showAlpha( b ); } | ||
377 | |||
378 | private slots: | ||
379 | void addCustom(); | ||
380 | |||
381 | void newHsv( int h, int s, int v ); | ||
382 | void newColorTypedIn( QRgb rgb ); | ||
383 | void newCustom( int, int ); | ||
384 | void newStandard( int, int ); | ||
385 | private: | ||
386 | QColorPicker *cp; | ||
387 | QColorLuminancePicker *lp; | ||
388 | QWellArray *custom; | ||
389 | QWellArray *standard; | ||
390 | QColorShower *cs; | ||
391 | int nextCust; | ||
392 | bool compact; | ||
393 | }; | ||
394 | |||
395 | #endif | 84 | #endif |