summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2004-01-13 21:14:51 (UTC)
committer mickeyl <mickeyl>2004-01-13 21:14:51 (UTC)
commitffe47019a96da4e6b7057fca30bb64274443099b (patch) (unidiff)
treeae203606aee544bec92ac9cc139a713199cf5522
parent7f865d5f46330faf3574495cc68093490f896411 (diff)
downloadopie-ffe47019a96da4e6b7057fca30bb64274443099b.zip
opie-ffe47019a96da4e6b7057fca30bb64274443099b.tar.gz
opie-ffe47019a96da4e6b7057fca30bb64274443099b.tar.bz2
introduce libqtaux in order to get a LGPL clean libopie2 after the merge
with libopie1
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libqtaux/.cvsignore6
-rw-r--r--libqtaux/README12
-rw-r--r--libqtaux/config.in3
-rw-r--r--libqtaux/libqtaux.control10
-rwxr-xr-xlibqtaux/libqtaux.postinst4
-rw-r--r--libqtaux/libqtaux.pro23
-rw-r--r--libqtaux/ocolorpopupmenu.cpp173
-rw-r--r--libqtaux/ocolorpopupmenu.h255
-rw-r--r--libqtaux/qcolordialog.cpp1629
-rw-r--r--libqtaux/qcolordialog.h84
-rw-r--r--libqtaux/qinputdialog.cpp493
-rw-r--r--libqtaux/qinputdialog.h106
-rw-r--r--libqtaux/qlayoutengine_p.h108
-rw-r--r--libqtaux/qsplitter.cpp1128
-rw-r--r--libqtaux/qsplitter.h128
15 files changed, 4162 insertions, 0 deletions
diff --git a/libqtaux/.cvsignore b/libqtaux/.cvsignore
new file mode 100644
index 0000000..8f7300c
--- a/dev/null
+++ b/libqtaux/.cvsignore
@@ -0,0 +1,6 @@
1Makefile*
2moc*
3*moc
4*.o
5~*
6
diff --git a/libqtaux/README b/libqtaux/README
new file mode 100644
index 0000000..9d9d8a0
--- a/dev/null
+++ b/libqtaux/README
@@ -0,0 +1,12 @@
1This library contains auxilliary stuff from Qt/Embedded 2.3.x which
2is very useful but has been left out from qconfig-qpe.h.
3
4Note: We can't just enable the said classes in our qconfig, because that
5 would mean we no longer could link to a sharp rom libqpe.
6
7Also note: We don't ship that embedded in libopie2
8 (nor do we use it from libopie2), because we want to keep
9 libopie2 LGPL - hence Opie stuff using these classes is also here.
10
11It could be useful to eventually have some original classes
12providing similar functionality.
diff --git a/libqtaux/config.in b/libqtaux/config.in
new file mode 100644
index 0000000..d34a4cc
--- a/dev/null
+++ b/libqtaux/config.in
@@ -0,0 +1,3 @@
1 config LIBQTAUX
2 boolean "Qt/Embedded Auxilliary Library"
3 default "n"
diff --git a/libqtaux/libqtaux.control b/libqtaux/libqtaux.control
new file mode 100644
index 0000000..782a8f4
--- a/dev/null
+++ b/libqtaux/libqtaux.control
@@ -0,0 +1,10 @@
1Package: libqtaux2
2Files: $OPIEDIR/lib/libqtaux2.so.*
3Priority: optional
4Section: opie/system
5Maintainer: Opie Team <opie@handhelds.org>
6Architecture: arm
7Version: 2.3.7-1
8Depends: libqte2
9Provides: libqtaux
10Description: Qt/Embedded Auxilliary Stuff
diff --git a/libqtaux/libqtaux.postinst b/libqtaux/libqtaux.postinst
new file mode 100755
index 0000000..0c37b3d
--- a/dev/null
+++ b/libqtaux/libqtaux.postinst
@@ -0,0 +1,4 @@
1#!/bin/sh
2
3[ -x /sbin/ldconfig ] && /sbin/ldconfig
4exit 0
diff --git a/libqtaux/libqtaux.pro b/libqtaux/libqtaux.pro
new file mode 100644
index 0000000..2f7aa91
--- a/dev/null
+++ b/libqtaux/libqtaux.pro
@@ -0,0 +1,23 @@
1TEMPLATE = lib
2CONFIG += qte warn_on debug
3
4HEADERS = qcolordialog.h \
5 qsplitter.h \
6 qinputdialog.h \
7 \
8 ocolorpopupmenu.h
9
10
11SOURCES = qcolordialog.cpp \
12 qsplitter.cpp \
13 qinputdialog.cpp \
14 \
15 ocolorpopupmenu.cpp
16
17TARGET = qtaux2
18INCLUDEPATH += $(OPIEDIR)/include
19DESTDIR = $(OPIEDIR)/lib
20INTERFACES =
21
22
23include ( $(OPIEDIR)/include.pro )
diff --git a/libqtaux/ocolorpopupmenu.cpp b/libqtaux/ocolorpopupmenu.cpp
new file mode 100644
index 0000000..6a2321e
--- a/dev/null
+++ b/libqtaux/ocolorpopupmenu.cpp
@@ -0,0 +1,173 @@
1/*
2                This file is part of the Opie Project
3
4              Copyright (c) 2002 S. Prud'homme <prudhomme@laposte.net>
5              Dan Williams <williamsdr@acm.org>
6 =.
7 .=l.
8           .>+-=
9 _;:,     .>    :=|. This program is free software; you can
10.> <`_,   >  .   <= redistribute it and/or modify it under
11:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
12.="- .-=="i,     .._ License as published by the Free Software
13 - .   .-<_>     .<> Foundation; either version 2 of the License,
14     ._= =}       : or (at your option) any later version.
15    .%`+i>       _;_.
16    .i_,=:_.      -<s. This program is distributed in the hope that
17     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
18    : ..    .:,     . . . without even the implied warranty of
19    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
20  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
21..}^=.=       =       ; Library General Public License for more
22++=   -.     .`     .: details.
23 :     =  ...= . :.=-
24 -.   .:....=;==+<; You should have received a copy of the GNU
25  -_. . .   )=.  = Library General Public License along with
26    --        :-=` this library; see the file COPYING.LIB.
27 If not, write to the Free Software Foundation,
28 Inc., 59 Temple Place - Suite 330,
29 Boston, MA 02111-1307, USA.
30
31*/
32
33#include "ocolorpopupmenu.h"
34#include "qcolordialog.h"
35
36#include <qaction.h>
37#include <qlayout.h>
38#include <qpainter.h>
39
40OColorPanelButton::OColorPanelButton( const QColor& color, QWidget* parent, const char* name )
41 : QFrame( parent, name )
42{
43 m_color = color;
44
45 setFixedSize( 16, 16 );
46 setActive( FALSE );
47}
48
49OColorPanelButton::~OColorPanelButton()
50{
51}
52
53void OColorPanelButton::setActive( bool active )
54{
55 m_active = active;
56
57 if ( m_active ) {
58 setFrameStyle( Panel | Sunken );
59 } else {
60 setFrameStyle( NoFrame );
61 }
62}
63
64void OColorPanelButton::enterEvent( QEvent* )
65{
66 if ( !m_active ) {
67 setFrameStyle( Panel | Sunken );
68 }
69}
70
71void OColorPanelButton::leaveEvent( QEvent* )
72{
73 if ( !m_active ) {
74 setFrameStyle( NoFrame );
75 }
76}
77
78void OColorPanelButton::paintEvent( QPaintEvent* e )
79{
80 QFrame::paintEvent( e );
81
82 QPainter painter;
83 painter.begin( this );
84 painter.fillRect( 2, 2, 12, 12, m_color );
85 painter.setPen( Qt::black );
86 painter.drawRect( 2, 2, 12, 12 );
87 painter.end();
88}
89
90void OColorPanelButton::mouseReleaseEvent( QMouseEvent* )
91{
92 emit selected( m_color );
93}
94
95OColorPopupMenu::OColorPopupMenu( const QColor& color, QWidget* parent, const char* name )
96 : QPopupMenu( parent, name )
97{
98 m_color = color;
99
100 colorPanel = new QWidget( this );
101
102 colorLayout = new QGridLayout(colorPanel, 5, 6);
103
104 addColor(QColor(255, 255, 255), 0, 1);
105 addColor(QColor(192, 192, 192), 0, 2);
106 addColor(QColor(128, 128, 128), 0, 3);
107 addColor(QColor(64, 64, 64), 0, 4);
108 addColor(QColor(0, 0, 0), 0, 5);
109
110 addColor(QColor(255, 0, 0), 1, 0);
111 addColor(QColor(255, 128, 0), 1, 1);
112 addColor(QColor(255, 255, 0), 1, 2);
113 addColor(QColor(128, 255, 0), 1, 3);
114 addColor(QColor(0, 255, 0), 1, 4);
115 addColor(QColor(0, 255, 128), 1, 5);
116
117 addColor(QColor(128, 0, 0), 2, 0);
118 addColor(QColor(128, 64, 0), 2, 1);
119 addColor(QColor(128, 128, 0), 2, 2);
120 addColor(QColor(64, 128, 0), 2, 3);
121 addColor(QColor(0, 128, 0), 2, 4);
122 addColor(QColor(0, 128, 64), 2, 5);
123
124 addColor(QColor(0, 255, 255), 3, 0);
125 addColor(QColor(0, 128, 255), 3, 1);
126 addColor(QColor(0, 0, 255), 3, 2);
127 addColor(QColor(128, 0, 255), 3, 3);
128 addColor(QColor(255, 0, 255), 3, 4);
129 addColor(QColor(255, 0, 128), 3, 5);
130
131 addColor(QColor(0, 128, 128), 4, 0);
132 addColor(QColor(0, 64, 128), 4, 1);
133 addColor(QColor(0, 0, 128), 4, 2);
134 addColor(QColor(64, 0, 128), 4, 3);
135 addColor(QColor(128, 0, 128), 4, 4);
136 addColor(QColor(128, 0, 64), 4, 5);
137
138 insertItem( colorPanel );
139 insertSeparator();
140 insertItem(tr("More"),this,SLOT( moreColorClicked()));
141 /*
142 QAction* chooseColorAction = new QAction( tr( "More" ), tr( "More..." ), 0, colorPanel, "More" );
143 connect( chooseColorAction, SIGNAL( activated() ), this, SLOT( moreColorClicked() ) );
144 chooseColorAction->addTo( this );
145 */
146 activateItemAt( 0 );
147}
148
149OColorPopupMenu::~OColorPopupMenu()
150{
151}
152
153void OColorPopupMenu::addColor( const QColor& color, int row, int col )
154{
155 OColorPanelButton* panelButton = new OColorPanelButton( color, colorPanel );
156 connect( panelButton, SIGNAL( selected( const QColor& ) ), this, SLOT( buttonSelected( const QColor& ) ) );
157 colorLayout->addWidget( panelButton, row, col );
158}
159
160void OColorPopupMenu::buttonSelected( const QColor& color )
161{
162 m_color = color;
163 emit colorSelected( color );
164 hide();
165}
166
167void OColorPopupMenu::moreColorClicked()
168{
169 QColor color = QColorDialog::getColor( m_color );
170 m_color = color;
171 emit colorSelected( color );
172 hide();
173}
diff --git a/libqtaux/ocolorpopupmenu.h b/libqtaux/ocolorpopupmenu.h
new file mode 100644
index 0000000..90cfbed
--- a/dev/null
+++ b/libqtaux/ocolorpopupmenu.h
@@ -0,0 +1,255 @@
1/*
2                This file is part of the Opie Project
3
4              Copyright (c) 2002 S. Prud'homme <prudhomme@laposte.net>
5              Dan Williams <williamsdr@acm.org>
6 =.
7 .=l.
8           .>+-=
9 _;:,     .>    :=|. This program is free software; you can
10.> <`_,   >  .   <= redistribute it and/or modify it under
11:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
12.="- .-=="i,     .._ License as published by the Free Software
13 - .   .-<_>     .<> Foundation; either version 2 of the License,
14     ._= =}       : or (at your option) any later version.
15    .%`+i>       _;_.
16    .i_,=:_.      -<s. This program is distributed in the hope that
17     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
18    : ..    .:,     . . . without even the implied warranty of
19    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
20  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
21..}^=.=       =       ; Library General Public License for more
22++=   -.     .`     .: details.
23 :     =  ...= . :.=-
24 -.   .:....=;==+<; You should have received a copy of the GNU
25  -_. . .   )=.  = Library General Public License along with
26    --        :-=` this library; see the file COPYING.LIB.
27 If not, write to the Free Software Foundation,
28 Inc., 59 Temple Place - Suite 330,
29 Boston, MA 02111-1307, USA.
30
31*/
32
33#ifndef COLORPOPUPMENU_H
34#define COLORPOPUPMENU_H
35
36#include <qframe.h>
37#include <qpopupmenu.h>
38
39class QWidget;
40class QGridLayout;
41
42/**
43 * @class OColorPanelButton
44 * @brief The OColorPanelButton class provides a button for color selection.
45 *
46 * @see OColorPopupMenu
47 *
48 * The OColorPanelButton class provides a button for color selection. The button
49 * is drawn with the desired color and no border. This class is used internally
50 * by the OColorPopupMenu class to displaying colors in its menu.
51 */
52class OColorPanelButton : public QFrame
53{
54 Q_OBJECT
55
56public:
57
58/**
59 * @fn OColorPanelButton( const QColor& color, QWidget* parent = 0, const char* name = 0 )
60 * @brief Object constructor.
61 *
62 * @param color Desired color.
63 * @param parent Pointer to parent of this control.
64 * @param name Name of control.
65 *
66 * Constructs a new ColorPanelButton control with parent, name and desired color.
67 */
68 OColorPanelButton(const QColor& color, QWidget* parent = 0, const char* name = 0);
69
70/**
71 * @fn ~OColorPanelButton()
72 * @brief Object destructor.
73 */
74 ~OColorPanelButton();
75
76/**
77 * @fn setActive( bool active )
78 * @brief Sets button selection state.
79 *
80 * @param active Boolean indicator of new button state.
81 *
82 * Changes button selection state. If button is selected, a highlighted border
83 * is drawn.
84 */
85 void setActive(bool active);
86
87/**
88 * @fn enterEvent( QEvent* e )
89 * @brief Reimplemented for internal reasons.
90 *
91 * @param e Event currently being processed.
92 *
93 * Reimplemented to ensure correct display of button based on whether it is
94 * active or not.
95 */
96 void enterEvent(QEvent* e);
97
98/**
99 * @fn leaveEvent( QEvent* e )
100 * @brief Reimplemented for internal reasons.
101 *
102 * @param e Event currently being processed.
103 *
104 * Reimplemented to ensure correct display of button based on whether it is
105 * active or not.
106 */
107 void leaveEvent(QEvent* e);
108
109/**
110 * @fn paintEvent( QPaintEvent* e )
111 * @brief Reimplemented for internal reasons.
112 *
113 * @param e Event currently being processed.
114 * @reimp
115 * Reimplemented to ensure correct display of button.
116 */
117 void paintEvent(QPaintEvent* e);
118
119/**
120 * @fn mouseReleaseEvent( QMouseEvent* e )
121 * @brief Slot executed when button is pressed.
122 *
123 * @param e Mouse event currently being processed.
124 *
125 * @see selected()
126 *
127 * This slot executes when the button has been pressed. It emits the selected
128 * signal as notification that it has been pressed.
129 */
130 void mouseReleaseEvent(QMouseEvent* e);
131
132signals:
133
134/**
135 * @fn selected( const QColor& color )
136 * @brief Signal to indicate button has been pressed.
137 *
138 * @param color Button color.
139 *
140 * This signal is emitted when the button is pressed. It provides the color
141 * associated to this button.
142 */
143 void selected(const QColor&);
144
145private:
146 QColor m_color;
147 bool m_active : 1;
148 class ColorPanelButtonPrivate;
149 ColorPanelButtonPrivate *d;
150};
151
152/**
153 * @class OColorPopupMenu
154 * @brief The OColorPopupMenu class provides a small color selection
155 * popup menu.
156 *
157 * OColorPopupMenu is a derivation of TrollTech's QPopupMenu and provides
158 * a small color selection popup menu which can be attached to another control
159 * such as a toolbar button of menu item.
160 *
161 * The popup menu displays 30 default colors available in a grid, and also
162 * includes an option at the bottom to display a color selection dialog box for
163 * finer color control.
164 */
165class OColorPopupMenu : public QPopupMenu
166{
167 Q_OBJECT
168
169public:
170
171/**
172 * @fn OColorPopupMenu( const QColor& color, QWidget* parent = 0, const char* name = 0 )
173 * @brief Object constructor.
174 *
175 * @param color Initial color selected in menu.
176 * @param parent Pointer to parent of this control.
177 * @param name Name of control.
178 *
179 * Constructs a new OColorPopupMenu control with parent, name and initial color selected.
180 */
181 // FIXME add Wflags? -zecke
182 OColorPopupMenu( const QColor& color, QWidget* parent = 0, const char* name = 0 );
183
184/**
185 * @fn ~OColorPopupMenu()
186 * @brief Object destructor.
187 */
188 ~OColorPopupMenu();
189
190private:
191 class ColorPopupMenuPrivate;
192 ColorPopupMenuPrivate *d;
193 QColor m_color;
194 QWidget* colorPanel;
195 QGridLayout* colorLayout;
196
197/**
198 * @fn addColor( const QColor& color, int row, int col )
199 * @brief Adds color selection option to popup menu.
200 *
201 * @param color Color to be displayed in menu.
202 * @param row Row where color is to appear in menu.
203 * @param col Column where color is to appear in menu.
204 *
205 * Adds a color selection option to popup menu. Used internally when
206 * initially constructing the menu control.
207 */
208 void addColor( const QColor& color, int row, int col );
209
210signals:
211
212/**
213 * @fn colorSelected( const QColor& color )
214 * @brief Signal to indicate color chosen from the menu.
215 *
216 * @param color Color selected from the menu.
217 *
218 * This signal is emitted when a color has been selected either directly from
219 * the menu, or chosen from the color selection dialog.
220 */
221 void colorSelected( const QColor& color );
222
223protected slots:
224
225/**
226 * @fn buttonSelected( const QColor& color )
227 * @brief Slot to process selected color.
228 *
229 * @param color Color selected from the menu.
230 *
231 * @see colorSelected()
232 *
233 * This slot executes when a color has been selected from the menu. It performs
234 * two functions:
235 * - Emit the colorSelected signal with the color selected.
236 * - Hide the menu.
237 */
238 void buttonSelected( const QColor& color );
239
240/**
241 * @fn moreColorClicked()
242 * @brief Slot to process display color selection dialog.
243 *
244 * @see colorSelected()
245 *
246 * This slot executes when the 'More...' option is selected at the bottom of the menu.
247 * It performs the following functions:
248 * - Constructs and executes a QColorDialog to allow finer color selection.
249 * - Emit the colorSelected signal with the color selected.
250 * - Hide the menu.
251 */
252 void moreColorClicked();
253};
254
255#endif // COLORPOPUPMENUANEL_H
diff --git a/libqtaux/qcolordialog.cpp b/libqtaux/qcolordialog.cpp
new file mode 100644
index 0000000..5881a89
--- a/dev/null
+++ b/libqtaux/qcolordialog.cpp
@@ -0,0 +1,1629 @@
1/****************************************************************************
2** $Id$
3**
4** Implementation of QColorDialog class
5**
6** Created : 990222
7**
8** Copyright (C) 1999-2000 Trolltech AS. All rights reserved.
9**
10** This file is part of the dialogs module of the Qt GUI Toolkit.
11**
12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file.
15**
16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file.
20**
21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22** licenses may use this file in accordance with the Qt Commercial License
23** Agreement provided with the Software.
24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32**
33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you.
35**
36**********************************************************************/
37
38#include "qcolordialog.h"
39
40#include "qpainter.h"
41#include "qlayout.h"
42#include "qlabel.h"
43#include "qpushbutton.h"
44#include "qlineedit.h"
45#include "qimage.h"
46#include "qpixmap.h"
47#include "qdrawutil.h"
48#include "qvalidator.h"
49#include "qdragobject.h"
50#include "qapplication.h"
51#include "qdragobject.h"
52
53//////////// QWellArray BEGIN
54
55#include "qobjectdict.h"
56
57//
58// W A R N I N G
59// -------------
60//
61// This file is not part of the Qt API. It exists for the convenience
62// of qwellarray.cpp and qcolordialog.cpp.
63// This header file may change from version to version without notice,
64// or even be removed.
65//
66//
67
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 )
168 : QTableView( parent, name,
169 popup ? (WStyle_Customize|WStyle_Tool|WStyle_NoBorder) : 0 )
170{
171 d = 0;
172 setFocusPolicy( StrongFocus );
173 setBackgroundMode( PaletteButton );
174 nCols = 7;
175 nRows = 7;
176 int w = 24; // cell width
177 int h = 21; // cell height
178 smallStyle = popup;
179
180 if ( popup ) {
181 w = h = 18;
182 if ( style() == WindowsStyle )
183 setFrameStyle( QFrame::WinPanel | QFrame::Raised );
184 else
185 setFrameStyle( QFrame::Panel | QFrame::Raised );
186 setMargin( 1 );
187 setLineWidth( 2 );
188 }
189 setNumCols( nCols );
190 setNumRows( nRows );
191 setCellWidth( w );
192 setCellHeight( h );
193 curCol = 0;
194 curRow = 0;
195 selCol = -1;
196 selRow = -1;
197
198 if ( smallStyle )
199 setMouseTracking( TRUE );
200 setOffset( 5 , 10 );
201
202 resize( sizeHint() );
203
204}
205
206
207QSize QWellArray::sizeHint() const
208{
209 constPolish();
210 int f = frameWidth() * 2;
211 int w = nCols * cellWidth() + f;
212 int h = nRows * cellHeight() + f;
213 return QSize( w, h );
214}
215
216
217void QWellArray::paintCell( QPainter* p, int row, int col )
218{
219 int w = cellWidth( col ); // width of cell in pixels
220 int h = cellHeight( row ); // height of cell in pixels
221 int b = 1;
222
223 if ( !smallStyle )
224 b = 3;
225
226 const QColorGroup & g = colorGroup();
227 p->setPen( QPen( black, 0, SolidLine ) );
228 if ( !smallStyle && row ==selRow && col == selCol &&
229 style() != MotifStyle ) {
230 int n = 2;
231 p->drawRect( n, n, w-2*n, h-2*n );
232 }
233
234
235 if ( style() == WindowsStyle ) {
236 qDrawWinPanel( p, b, b , w - 2*b, h - 2*b,
237 g, TRUE );
238 b += 2;
239 } else {
240 if ( smallStyle ) {
241 qDrawShadePanel( p, b, b , w - 2*b, h - 2*b,
242 g, TRUE, 2 );
243 b += 2;
244 } else {
245 int t = ( row == selRow && col == selCol ) ? 2 : 0;
246 b -= t;
247 qDrawShadePanel( p, b, b , w - 2*b, h - 2*b,
248 g, TRUE, 2 );
249 b += 2 + t;
250 }
251 }
252
253
254 if ( (row == curRow) && (col == curCol) ) {
255 if ( smallStyle ) {
256 p->setPen ( white );
257 p->drawRect( 1, 1, w-2, h-2 );
258 p->setPen ( black );
259 p->drawRect( 0, 0, w, h );
260 p->drawRect( 2, 2, w-4, h-4 );
261 b = 3;
262 } else if ( hasFocus() ) {
263 style().drawFocusRect(p, QRect(0,0,w,h), g );
264 }
265 }
266 drawContents( p, row, col, QRect(b, b, w - 2*b, h - 2*b) );
267}
268
269/*!
270 Pass-through to QTableView::drawContents() to avoid hiding.
271*/
272void QWellArray::drawContents( QPainter *p )
273{
274 QTableView::drawContents(p);
275}
276
277/*!
278 Reimplement this function to change the contents of the well array.
279 */
280void QWellArray::drawContents( QPainter *p, int row, int col, const QRect &r )
281{
282
283 if ( d ) {
284 p->fillRect( r, d->brush[row*nCols+col] );
285 } else {
286 p->fillRect( r, white );
287 p->setPen( black );
288 p->drawLine( r.topLeft(), r.bottomRight() );
289 p->drawLine( r.topRight(), r.bottomLeft() );
290 }
291}
292
293
294/*\reimp
295*/
296void QWellArray::mousePressEvent( QMouseEvent* e )
297{
298 // The current cell marker is set to the cell the mouse is pressed
299 // in.
300 QPoint pos = e->pos();
301 setCurrent( findRow( pos.y() ), findCol( pos.x() ) );
302}
303
304/*\reimp
305*/
306void QWellArray::mouseReleaseEvent( QMouseEvent* )
307{
308 // The current cell marker is set to the cell the mouse is clicked
309 // in.
310 setSelected( curRow, curCol );
311}
312
313
314/*\reimp
315*/
316void QWellArray::mouseMoveEvent( QMouseEvent* e )
317{
318 // The current cell marker is set to the cell the mouse is
319 // clicked in.
320 if ( smallStyle ) {
321 QPoint pos = e->pos();
322 setCurrent( findRow( pos.y() ), findCol( pos.x() ) );
323 }
324}
325
326/*
327 Sets the cell currently having the focus. This is not necessarily
328 the same as the currently selected cell.
329*/
330
331void QWellArray::setCurrent( int row, int col )
332{
333
334 if ( (curRow == row) && (curCol == col) )
335 return;
336
337 if ( row < 0 || col < 0 )
338 row = col = -1;
339
340 int oldRow = curRow;
341 int oldCol = curCol;
342
343 curRow = row;
344 curCol = col;
345
346 updateCell( oldRow, oldCol );
347 updateCell( curRow, curCol );
348}
349
350
351/*!
352 Sets the currently selected cell to \a row, \a col. If \a row or \a
353 col are less than zero, the current cell is unselected.
354
355 Does not set the position of the focus indicator.
356*/
357
358void QWellArray::setSelected( int row, int col )
359{
360 if ( (selRow == row) && (selCol == col) )
361 return;
362
363 int oldRow = selRow;
364 int oldCol = selCol;
365
366 if ( row < 0 || col < 0 )
367 row = col = -1;
368
369 selCol = col;
370 selRow = row;
371
372 updateCell( oldRow, oldCol );
373 updateCell( selRow, selCol );
374 if ( row >= 0 )
375 emit selected( row, col );
376
377 if ( isVisible() && parentWidget() && parentWidget()->inherits("QPopupMenu") )
378 parentWidget()->close();
379
380}
381
382
383
384/*!\reimp
385*/
386void QWellArray::focusInEvent( QFocusEvent* )
387{
388 updateCell( curRow, curCol );
389}
390
391
392/*!
393 Sets the size of the well array to be \c rows cells by \c cols.
394 Resets any brush info set by setCellBrush().
395
396 Must be called by reimplementors.
397 */
398void QWellArray::setDimension( int rows, int cols )
399{
400 nRows = rows;
401 nCols = cols;
402 if ( d ) {
403 if ( d->brush )
404 delete[] d->brush;
405 delete d;
406 d = 0;
407 }
408 setNumCols( nCols );
409 setNumRows( nRows );
410}
411
412void QWellArray::setCellBrush( int row, int col, const QBrush &b )
413{
414 if ( !d ) {
415 d = new QWellArrayData;
416 d->brush = new QBrush[nRows*nCols];
417 }
418 if ( row >= 0 && row < nRows && col >= 0 && col < nCols )
419 d->brush[row*nCols+col] = b;
420#ifdef CHECK_RANGE
421 else
422 qWarning( "QWellArray::setCellBrush( %d, %d ) out of range", row, col );
423#endif
424}
425
426
427
428/*!
429 Returns the brush set for the cell at \a row, \a col. If no brush is set,
430 \c NoBrush is returned.
431*/
432
433QBrush QWellArray::cellBrush( int row, int col )
434{
435 if ( d && row >= 0 && row < nRows && col >= 0 && col < nCols )
436 return d->brush[row*nCols+col];
437 return NoBrush;
438}
439
440
441
442/*!\reimp
443*/
444
445void QWellArray::focusOutEvent( QFocusEvent* )
446{
447 updateCell( curRow, curCol );
448}
449
450/*\reimp
451*/
452void QWellArray::keyPressEvent( QKeyEvent* e )
453{
454 switch( e->key() ) { // Look at the key code
455 case Key_Left: // If 'left arrow'-key,
456 if( curCol > 0 ) { // and cr't not in leftmost col
457 setCurrent( curRow, curCol - 1);// set cr't to next left column
458 int edge = leftCell(); // find left edge
459 if ( curCol < edge ) // if we have moved off edge,
460 setLeftCell( edge - 1 );// scroll view to rectify
461 }
462 break;
463 case Key_Right: // Correspondingly...
464 if( curCol < numCols()-1 ) {
465 setCurrent( curRow, curCol + 1);
466 int edge = lastColVisible();
467 if ( curCol >= edge )
468 setLeftCell( leftCell() + 1 );
469 }
470 break;
471 case Key_Up:
472 if( curRow > 0 ) {
473 setCurrent( curRow - 1, curCol);
474 int edge = topCell();
475 if ( curRow < edge )
476 setTopCell( edge - 1 );
477 } else if ( smallStyle )
478 focusNextPrevChild( FALSE );
479 break;
480 case Key_Down:
481 if( curRow < numRows()-1 ) {
482 setCurrent( curRow + 1, curCol);
483 int edge = lastRowVisible();
484 if ( curRow >= edge )
485 setTopCell( topCell() + 1 );
486 } else if ( smallStyle )
487 focusNextPrevChild( TRUE );
488 break;
489 case Key_Space:
490 case Key_Return:
491 case Key_Enter:
492 setSelected( curRow, curCol );
493 break;
494 default: // If not an interesting key,
495 e->ignore(); // we don't accept the event
496 return;
497 }
498
499}
500
501//////////// QWellArray END
502
503static bool initrgb = FALSE;
504static QRgb stdrgb[6*8];
505static QRgb cusrgb[2*8];
506
507
508static void initRGB()
509{
510 if ( initrgb )
511 return;
512 initrgb = TRUE;
513 int i = 0;
514 for ( int g = 0; g < 4; g++ )
515 for ( int r = 0; r < 4; r++ )
516 for ( int b = 0; b < 3; b++ )
517 stdrgb[i++] = qRgb( r*255/3, g*255/3, b*255/2 );
518
519 for ( i = 0; i < 2*8; i++ )
520 cusrgb[i] = qRgb(0xff,0xff,0xff);
521}
522
523/*!
524 Returns the number of custom colors supported by
525 QColorDialog. All color dialogs share the same custom colors.
526*/
527int QColorDialog::customCount()
528{
529 return 2*8;
530}
531
532/*!
533 Returns custom color number \a i as a QRgb.
534 */
535QRgb QColorDialog::customColor( int i )
536{
537 initRGB();
538 if ( i < 0 || i >= customCount() ) {
539#ifdef CHECK_RANGE
540 qWarning( "QColorDialog::customColor() index %d out of range", i );
541 #endif
542 i = 0;
543 }
544 return cusrgb[i];
545}
546
547/*!
548 Sets custom color number \a i to the QRgb value \a c.
549*/
550void QColorDialog::setCustomColor( int i, QRgb c )
551{
552 initRGB();
553 if ( i < 0 || i >= customCount() ) {
554#ifdef CHECK_RANGE
555 qWarning( "QColorDialog::customColor() index %d out of range", i );
556 #endif
557 return;
558 }
559 cusrgb[i] = c;
560}
561
562static inline void rgb2hsv( QRgb rgb, int&h, int&s, int&v )
563{
564 QColor c;
565 c.setRgb( rgb );
566 c.getHsv(h,s,v);
567}
568
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
599{
600 return QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
601}
602
603void QColorWell::drawContents( QPainter *p, int row, int col, const QRect &r )
604{
605 int i = row + col*numRows();
606 p->fillRect( r, QColor( values[i] ) );
607}
608
609void QColorWell::mousePressEvent( QMouseEvent *e )
610{
611 oldCurrent = QPoint( selectedRow(), selectedColumn() );
612 QWellArray::mousePressEvent( e );
613 mousePressed = TRUE;
614 pressPos = e->pos();
615}
616
617void QColorWell::mouseMoveEvent( QMouseEvent *e )
618{
619 QWellArray::mouseMoveEvent( e );
620#ifndef QT_NO_DRAGANDDROP
621 if ( !mousePressed )
622 return;
623 if ( ( pressPos - e->pos() ).manhattanLength() > QApplication::startDragDistance() ) {
624 setCurrent( oldCurrent.x(), oldCurrent.y() );
625 int i = findRow( e->y() ) + findCol( e->x() ) * numRows();
626 QColor col( values[ i ] );
627 QColorDrag *drg = new QColorDrag( col, this );
628 QPixmap pix( cellWidth(), cellHeight() );
629 pix.fill( col );
630 QPainter p( &pix );
631 p.drawRect( 0, 0, pix.width(), pix.height() );
632 p.end();
633 drg->setPixmap( pix );
634 mousePressed = FALSE;
635 drg->dragCopy();
636 }
637#endif
638}
639
640#ifndef QT_NO_DRAGANDDROP
641void QColorWell::dragEnterEvent( QDragEnterEvent *e )
642{
643 setFocus();
644 if ( QColorDrag::canDecode( e ) )
645 e->accept();
646 else
647 e->ignore();
648}
649
650void QColorWell::dragLeaveEvent( QDragLeaveEvent * )
651{
652 if ( hasFocus() )
653 parentWidget()->setFocus();
654}
655
656void QColorWell::dragMoveEvent( QDragMoveEvent *e )
657{
658 if ( QColorDrag::canDecode( e ) ) {
659 setCurrent( findRow( e->pos().y() ), findCol( e->pos().x() ) );
660 e->accept();
661 } else
662 e->ignore();
663}
664
665void QColorWell::dropEvent( QDropEvent *e )
666{
667 if ( QColorDrag::canDecode( e ) ) {
668 int i = findRow( e->pos().y() ) + findCol( e->pos().x() ) * numRows();
669 QColor col;
670 QColorDrag::decode( e, col );
671 values[ i ] = col.rgb();
672 repaint( FALSE );
673 e->accept();
674 } else {
675 e->ignore();
676 }
677}
678
679#endif // QT_NO_DRAGANDDROP
680
681void QColorWell::mouseReleaseEvent( QMouseEvent *e )
682{
683 if ( !mousePressed )
684 return;
685 QWellArray::mouseReleaseEvent( e );
686 mousePressed = FALSE;
687}
688
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;
722static int pHeight = 200;
723
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 )
760{
761 int d = height() - 2*coff - 1;
762 return 255 - (y - coff)*255/d;
763}
764
765int QColorLuminancePicker::val2y( int v )
766{
767 int d = height() - 2*coff - 1;
768 return coff + (255-v)*d/255;
769}
770
771QColorLuminancePicker::QColorLuminancePicker(QWidget* parent,
772 const char* name)
773 :QWidget( parent, name )
774{
775 hue = 100; val = 100; sat = 100;
776 pix = 0;
777 // setBackgroundMode( NoBackground );
778}
779
780QColorLuminancePicker::~QColorLuminancePicker()
781{
782 delete pix;
783}
784
785void QColorLuminancePicker::mouseMoveEvent( QMouseEvent *m )
786{
787 setVal( y2val(m->y()) );
788}
789void QColorLuminancePicker::mousePressEvent( QMouseEvent *m )
790{
791 setVal( y2val(m->y()) );
792}
793
794void QColorLuminancePicker::setVal( int v )
795{
796 if ( val == v )
797 return;
798 val = QMAX( 0, QMIN(v,255));
799 delete pix; pix=0;
800 repaint( FALSE ); //###
801 emit newHsv( hue, sat, val );
802}
803
804//receives from a hue,sat chooser and relays.
805void QColorLuminancePicker::setCol( int h, int s )
806{
807 setCol( h, s, val );
808 emit newHsv( h, s, val );
809}
810
811void QColorLuminancePicker::paintEvent( QPaintEvent * )
812{
813 int w = width() - 5;
814
815 QRect r( 0, foff, w, height() - 2*foff );
816 int wi = r.width() - 2;
817 int hi = r.height() - 2;
818 if ( !pix || pix->height() != hi || pix->width() != wi ) {
819 delete pix;
820 QImage img( wi, hi, 32 );
821 int y;
822 for ( y = 0; y < hi; y++ ) {
823 QColor c( hue, sat, y2val(y+coff), QColor::Hsv );
824 QRgb r = c.rgb();
825 int x;
826 for ( x = 0; x < wi; x++ )
827 img.setPixel( x, y, r );
828 }
829 pix = new QPixmap;
830 pix->convertFromImage(img);
831 }
832 QPainter p(this);
833 p.drawPixmap( 1, coff, *pix );
834 QColorGroup g = colorGroup();
835 qDrawShadePanel( &p, r, g, TRUE );
836 p.setPen( g.foreground() );
837 p.setBrush( g.foreground() );
838 QPointArray a;
839 int y = val2y(val);
840 a.setPoints( 3, w, y, w+5, y+5, w+5, y-5 );
841 erase( w, 0, 5, height() );
842 p.drawPolygon( a );
843}
844
845void QColorLuminancePicker::setCol( int h, int s , int v )
846{
847 val = v;
848 hue = h;
849 sat = s;
850 delete pix; pix=0;
851 repaint( FALSE );//####
852}
853
854QPoint QColorPicker::colPt()
855{ return QPoint( (360-hue)*(pWidth-1)/360, (255-sat)*(pHeight-1)/255 ); }
856int QColorPicker::huePt( const QPoint &pt )
857{ return 360 - pt.x()*360/(pWidth-1); }
858int QColorPicker::satPt( const QPoint &pt )
859{ return 255 - pt.y()*255/(pHeight-1) ; }
860void QColorPicker::setCol( const QPoint &pt )
861{ setCol( huePt(pt), satPt(pt) ); }
862
863QColorPicker::QColorPicker(QWidget* parent, const char* name )
864 : QFrame( parent, name )
865{
866 hue = 0; sat = 0;
867 setCol( 150, 255 );
868
869 QImage img( pWidth, pHeight, 32 );
870 int x,y;
871 for ( y = 0; y < pHeight; y++ )
872 for ( x = 0; x < pWidth; x++ ) {
873 QPoint p( x, y );
874 img.setPixel( x, y, QColor(huePt(p), satPt(p),
875 200, QColor::Hsv).rgb() );
876 }
877 pix = new QPixmap;
878 pix->convertFromImage(img);
879 setBackgroundMode( NoBackground );
880}
881
882QColorPicker::~QColorPicker()
883{
884 delete pix;
885}
886
887QSize QColorPicker::sizeHint() const
888{
889 return QSize( pWidth + 2*frameWidth(), pHeight + 2*frameWidth() );
890}
891
892QSizePolicy QColorPicker::sizePolicy() const
893{
894 return QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
895}
896
897void QColorPicker::setCol( int h, int s )
898{
899 int nhue = QMIN( QMAX(0,h), 360 );
900 int nsat = QMIN( QMAX(0,s), 255);
901 if ( nhue == hue && nsat == sat )
902 return;
903 QRect r( colPt(), QSize(20,20) );
904 hue = nhue; sat = nsat;
905 r = r.unite( QRect( colPt(), QSize(20,20) ) );
906 r.moveBy( contentsRect().x()-9, contentsRect().y()-9 );
907 // update( r );
908 repaint( r, FALSE );
909}
910
911void QColorPicker::mouseMoveEvent( QMouseEvent *m )
912{
913 QPoint p = m->pos() - contentsRect().topLeft();
914 setCol( p );
915 emit newCol( hue, sat );
916}
917
918void QColorPicker::mousePressEvent( QMouseEvent *m )
919{
920 QPoint p = m->pos() - contentsRect().topLeft();
921 setCol( p );
922 emit newCol( hue, sat );
923}
924
925void QColorPicker::drawContents(QPainter* p)
926{
927 QRect r = contentsRect();
928
929 p->drawPixmap( r.topLeft(), *pix );
930 QPoint pt = colPt() + r.topLeft();
931 p->setPen( QPen(black) );
932
933 p->fillRect( pt.x()-9, pt.y(), 20, 2, black );
934 p->fillRect( pt.x(), pt.y()-9, 2, 20, black );
935
936}
937
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
953{
954 State state = QIntValidator::validate(s,pos);
955 if ( state == Valid ) {
956 long int val = s.toLong();
957 // This is not a general solution, assumes that top() > 0 and
958 // bottom >= 0
959 if ( val < 0 ) {
960 s = "0";
961 pos = 1;
962 } else if ( val > top() ) {
963 s.setNum( top() );
964 pos = s.length();
965 }
966 }
967 return state;
968}
969
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 )
1067{
1068 p->fillRect( contentsRect(), col );
1069}
1070
1071void QColorShower::showAlpha( bool b )
1072{
1073 if ( b ) {
1074 alphaLab->show();
1075 alphaEd->show();
1076 } else {
1077 alphaLab->hide();
1078 alphaEd->hide();
1079 }
1080}
1081
1082void QColorShowLabel::mousePressEvent( QMouseEvent *e )
1083{
1084 mousePressed = TRUE;
1085 pressPos = e->pos();
1086}
1087
1088void QColorShowLabel::mouseMoveEvent( QMouseEvent *e )
1089{
1090#ifndef QT_NO_DRAGANDDROP
1091 if ( !mousePressed )
1092 return;
1093 if ( ( pressPos - e->pos() ).manhattanLength() > QApplication::startDragDistance() ) {
1094 QColorDrag *drg = new QColorDrag( col, this );
1095 QPixmap pix( 30, 20 );
1096 pix.fill( col );
1097 QPainter p( &pix );
1098 p.drawRect( 0, 0, pix.width(), pix.height() );
1099 p.end();
1100 drg->setPixmap( pix );
1101 mousePressed = FALSE;
1102 drg->dragCopy();
1103 }
1104#endif
1105}
1106
1107#ifndef QT_NO_DRAGANDDROP
1108void QColorShowLabel::dragEnterEvent( QDragEnterEvent *e )
1109{
1110 if ( QColorDrag::canDecode( e ) )
1111 e->accept();
1112 else
1113 e->ignore();
1114}
1115
1116void QColorShowLabel::dragLeaveEvent( QDragLeaveEvent * )
1117{
1118}
1119
1120void QColorShowLabel::dropEvent( QDropEvent *e )
1121{
1122 if ( QColorDrag::canDecode( e ) ) {
1123 QColorDrag::decode( e, col );
1124 repaint( FALSE );
1125 emit colorDropped( col.rgb() );
1126 e->accept();
1127 } else {
1128 e->ignore();
1129 }
1130}
1131#endif // QT_NO_DRAGANDDROP
1132
1133void QColorShowLabel::mouseReleaseEvent( QMouseEvent * )
1134{
1135 if ( !mousePressed )
1136 return;
1137 mousePressed = FALSE;
1138}
1139
1140QColorShower::QColorShower( QWidget *parent, const char *name )
1141 :QWidget( parent, name)
1142{
1143 curCol = qRgb( -1, -1, -1 );
1144 QColIntValidator *val256 = new QColIntValidator( 0, 255, this );
1145 QColIntValidator *val360 = new QColIntValidator( 0, 360, this );
1146
1147 QGridLayout *gl = new QGridLayout( this, 1, 1, 6 );
1148 lab = new QColorShowLabel( this );
1149 lab->setMinimumWidth( 60 ); //###
1150 gl->addMultiCellWidget(lab, 0,-1,0,0);
1151 connect( lab, SIGNAL( colorDropped(QRgb) ),
1152 this, SIGNAL( newCol(QRgb) ) );
1153 connect( lab, SIGNAL( colorDropped(QRgb) ),
1154 this, SLOT( setRgb(QRgb) ) );
1155
1156 hEd = new QColNumLineEdit( this );
1157 hEd->setValidator( val360 );
1158 QLabel *l = new QLabel( hEd, QColorDialog::tr("Hu&e:"), this );
1159 l->setAlignment( AlignRight|AlignVCenter );
1160 gl->addWidget( l, 0, 1 );
1161 gl->addWidget( hEd, 0, 2 );
1162
1163 sEd = new QColNumLineEdit( this );
1164 sEd->setValidator( val256 );
1165 l = new QLabel( sEd, QColorDialog::tr("&Sat:"), this );
1166 l->setAlignment( AlignRight|AlignVCenter );
1167 gl->addWidget( l, 1, 1 );
1168 gl->addWidget( sEd, 1, 2 );
1169
1170 vEd = new QColNumLineEdit( this );
1171 vEd->setValidator( val256 );
1172 l = new QLabel( vEd, QColorDialog::tr("&Val:"), this );
1173 l->setAlignment( AlignRight|AlignVCenter );
1174 gl->addWidget( l, 2, 1 );
1175 gl->addWidget( vEd, 2, 2 );
1176
1177 rEd = new QColNumLineEdit( this );
1178 rEd->setValidator( val256 );
1179 l = new QLabel( rEd, QColorDialog::tr("&Red:"), this );
1180 l->setAlignment( AlignRight|AlignVCenter );
1181 gl->addWidget( l, 0, 3 );
1182 gl->addWidget( rEd, 0, 4 );
1183
1184 gEd = new QColNumLineEdit( this );
1185 gEd->setValidator( val256 );
1186 l = new QLabel( gEd, QColorDialog::tr("&Green:"), this );
1187 l->setAlignment( AlignRight|AlignVCenter );
1188 gl->addWidget( l, 1, 3 );
1189 gl->addWidget( gEd, 1, 4 );
1190
1191 bEd = new QColNumLineEdit( this );
1192 bEd->setValidator( val256 );
1193 l = new QLabel( bEd, QColorDialog::tr("Bl&ue:"), this );
1194 l->setAlignment( AlignRight|AlignVCenter );
1195 gl->addWidget( l, 2, 3 );
1196 gl->addWidget( bEd, 2, 4 );
1197
1198 alphaEd = new QColNumLineEdit( this );
1199 alphaEd->setValidator( val256 );
1200 alphaLab = new QLabel( alphaEd, QColorDialog::tr("A&lpha channel:"), this );
1201 alphaLab->setAlignment( AlignRight|AlignVCenter );
1202 gl->addMultiCellWidget( alphaLab, 3, 3, 1, 3 );
1203 gl->addWidget( alphaEd, 3, 4 );
1204 alphaEd->hide();
1205 alphaLab->hide();
1206
1207 connect( hEd, SIGNAL(textChanged(const QString&)), this, SLOT(hsvEd()) );
1208 connect( sEd, SIGNAL(textChanged(const QString&)), this, SLOT(hsvEd()) );
1209 connect( vEd, SIGNAL(textChanged(const QString&)), this, SLOT(hsvEd()) );
1210
1211 connect( rEd, SIGNAL(textChanged(const QString&)), this, SLOT(rgbEd()) );
1212 connect( gEd, SIGNAL(textChanged(const QString&)), this, SLOT(rgbEd()) );
1213 connect( bEd, SIGNAL(textChanged(const QString&)), this, SLOT(rgbEd()) );
1214}
1215
1216void QColorShower::showCurrentColor()
1217{
1218 lab->setColor( currentColor() );
1219 lab->repaint(FALSE); //###
1220}
1221
1222void QColorShower::rgbEd()
1223{
1224 rgbOriginal = TRUE;
1225 curCol = qRgb( rEd->val(), gEd->val(), bEd->val() );
1226 rgb2hsv(currentColor(), hue, sat, val );
1227
1228 hEd->setNum( hue );
1229 sEd->setNum( sat );
1230 vEd->setNum( val );
1231
1232 showCurrentColor();
1233 emit newCol( currentColor() );
1234}
1235
1236void QColorShower::hsvEd()
1237{
1238 rgbOriginal = FALSE;
1239 hue = hEd->val();
1240 sat = sEd->val();
1241 val = vEd->val();
1242
1243 curCol = QColor( hue, sat, val, QColor::Hsv ).rgb();
1244
1245 rEd->setNum( qRed(currentColor()) );
1246 gEd->setNum( qGreen(currentColor()) );
1247 bEd->setNum( qBlue(currentColor()) );
1248
1249 showCurrentColor();
1250 emit newCol( currentColor() );
1251}
1252
1253void QColorShower::setRgb( QRgb rgb )
1254{
1255 rgbOriginal = TRUE;
1256 curCol = rgb;
1257
1258 rgb2hsv( currentColor(), hue, sat, val );
1259
1260 hEd->setNum( hue );
1261 sEd->setNum( sat );
1262 vEd->setNum( val );
1263
1264 rEd->setNum( qRed(currentColor()) );
1265 gEd->setNum( qGreen(currentColor()) );
1266 bEd->setNum( qBlue(currentColor()) );
1267
1268 showCurrentColor();
1269}
1270
1271void QColorShower::setHsv( int h, int s, int v )
1272{
1273 rgbOriginal = FALSE;
1274 hue = h; val = v; sat = s; //Range check###
1275 curCol = QColor( hue, sat, val, QColor::Hsv ).rgb();
1276
1277 hEd->setNum( hue );
1278 sEd->setNum( sat );
1279 vEd->setNum( val );
1280
1281 rEd->setNum( qRed(currentColor()) );
1282 gEd->setNum( qGreen(currentColor()) );
1283 bEd->setNum( qBlue(currentColor()) );
1284
1285
1286 showCurrentColor();
1287}
1288
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
1319void QColorDialogPrivate::newHsv( int h, int s, int v )
1320{
1321 cs->setHsv( h, s, v );
1322 cp->setCol( h, s );
1323 lp->setCol( h, s, v );
1324}
1325
1326//sets all widgets to display rgb
1327void QColorDialogPrivate::setCurrentColor( QRgb rgb )
1328{
1329 cs->setRgb( rgb );
1330 newColorTypedIn( rgb );
1331}
1332
1333//sets all widgets exept cs to display rgb
1334void QColorDialogPrivate::newColorTypedIn( QRgb rgb )
1335{
1336 int h, s, v;
1337 rgb2hsv(rgb, h, s, v );
1338 cp->setCol( h, s );
1339 lp->setCol( h, s, v);
1340}
1341
1342void QColorDialogPrivate::newCustom( int r, int c )
1343{
1344 int i = r+2*c;
1345 setCurrentColor( cusrgb[i] );
1346 nextCust = i;
1347 standard->setSelected(-1,-1);
1348}
1349
1350void QColorDialogPrivate::newStandard( int r, int c )
1351{
1352 setCurrentColor( stdrgb[r+c*6] );
1353 custom->setSelected(-1,-1);
1354}
1355
1356QColorDialogPrivate::QColorDialogPrivate( QColorDialog *dialog ) :
1357 QObject(dialog)
1358{
1359 compact = FALSE;
1360 // small displays (e.g. PDAs cannot fit the full color dialog,
1361 // so just use the color picker.
1362 if ( qApp->desktop()->width() < 480 || qApp->desktop()->height() < 350 )
1363 compact = TRUE;
1364
1365 nextCust = 0;
1366 const int lumSpace = 3;
1367 int border = 12;
1368 if ( compact )
1369 border = 6;
1370 QHBoxLayout *topLay = new QHBoxLayout( dialog, border, 6 );
1371 QVBoxLayout *leftLay = 0;
1372
1373 if ( !compact )
1374 leftLay = new QVBoxLayout( topLay );
1375
1376 initRGB();
1377
1378 if ( !compact ) {
1379 standard = new QColorWell( dialog, 6, 8, stdrgb );
1380 standard->setCellSize( 28, 24 );
1381 QLabel * lab = new QLabel( standard,
1382 QColorDialog::tr( "&Basic colors"), dialog );
1383 connect( standard, SIGNAL(selected(int,int)), SLOT(newStandard(int,int)));
1384 leftLay->addWidget( lab );
1385 leftLay->addWidget( standard );
1386
1387
1388 leftLay->addStretch();
1389
1390 custom = new QColorWell( dialog, 2, 8, cusrgb );
1391 custom->setCellSize( 28, 24 );
1392 custom->setAcceptDrops( TRUE );
1393
1394 connect( custom, SIGNAL(selected(int,int)), SLOT(newCustom(int,int)));
1395 lab = new QLabel( custom, QColorDialog::tr( "&Custom colors") , dialog );
1396 leftLay->addWidget( lab );
1397 leftLay->addWidget( custom );
1398
1399 QPushButton *custbut =
1400 new QPushButton( QColorDialog::tr("&Define Custom Colors >>"),
1401 dialog );
1402 custbut->setEnabled( FALSE );
1403 leftLay->addWidget( custbut );
1404 } else {
1405 // better color picker size for small displays
1406 pWidth = 150;
1407 pHeight = 100;
1408 }
1409
1410 QVBoxLayout *rightLay = new QVBoxLayout( topLay );
1411
1412 QHBoxLayout *pickLay = new QHBoxLayout( rightLay );
1413
1414
1415 QVBoxLayout *cLay = new QVBoxLayout( pickLay );
1416 cp = new QColorPicker( dialog );
1417 cp->setFrameStyle( QFrame::Panel + QFrame::Sunken );
1418 cLay->addSpacing( lumSpace );
1419 cLay->addWidget( cp );
1420 cLay->addSpacing( lumSpace );
1421
1422 lp = new QColorLuminancePicker( dialog );
1423 lp->setFixedWidth( 20 ); //###
1424 pickLay->addWidget( lp );
1425
1426 connect( cp, SIGNAL(newCol(int,int)), lp, SLOT(setCol(int,int)) );
1427 connect( lp, SIGNAL(newHsv(int,int,int)), this, SLOT(newHsv(int,int,int)) );
1428
1429 rightLay->addStretch();
1430
1431 cs = new QColorShower( dialog );
1432 connect( cs, SIGNAL(newCol(QRgb)), this, SLOT(newColorTypedIn(QRgb)));
1433 rightLay->addWidget( cs );
1434
1435 QHBoxLayout *buttons;
1436 if ( compact )
1437 buttons = new QHBoxLayout( rightLay );
1438 else
1439 buttons = new QHBoxLayout( leftLay );
1440
1441 QPushButton *ok, *cancel;
1442 ok = new QPushButton( QColorDialog::tr("OK"), dialog );
1443 connect( ok, SIGNAL(clicked()), dialog, SLOT(accept()) );
1444 ok->setDefault(TRUE);
1445 cancel = new QPushButton( QColorDialog::tr("Cancel"), dialog );
1446 connect( cancel, SIGNAL(clicked()), dialog, SLOT(reject()) );
1447 buttons->addWidget( ok );
1448 buttons->addWidget( cancel );
1449 buttons->addStretch();
1450
1451 if ( !compact ) {
1452 QPushButton *addCusBt = new QPushButton(
1453 QColorDialog::tr("&Add To Custom Colors"),
1454 dialog );
1455 rightLay->addWidget( addCusBt );
1456 connect( addCusBt, SIGNAL(clicked()), this, SLOT(addCustom()) );
1457 }
1458}
1459
1460void QColorDialogPrivate::addCustom()
1461{
1462 cusrgb[nextCust] = cs->currentColor();
1463 custom->repaint( FALSE ); //###
1464 nextCust = (nextCust+1) % 16;
1465}
1466
1467
1468// BEING REVISED: jo
1469/*!
1470 \class QColorDialog qcolordialog.h
1471 \brief The QColorDialog class provides a dialog widget for specifying colors.
1472 \ingroup dialogs
1473
1474 The color dialog's function is to allow users to choose colors -
1475 for instance, you might use this in a drawing program to allow the
1476 user to set the brush color.
1477
1478 This version of Qt only provides modal color dialogs. The static
1479 getColor() function shows the dialog and allows the user to specify a color,
1480 while getRgba() does the same but allows the user to specify a color with an
1481 alpha channel (transparency) value.
1482
1483 The user can store customCount() different custom colors. The custom
1484 colors are shared by all color dialogs, and remembered during the
1485 execution of the program. Use setCustomColor() to set the
1486 custom colors, and customColor() to get them.
1487
1488 <img src=qcolordlg-m.png> <img src=qcolordlg-w.png>
1489*/
1490
1491/*!
1492 Constructs a default color dialog. Use setColor() for setting an initial value.
1493
1494 \sa getColor()
1495*/
1496
1497QColorDialog::QColorDialog(QWidget* parent, const char* name, bool modal) :
1498 QDialog(parent, name, modal )
1499{
1500 setSizeGripEnabled( TRUE );
1501 d = new QColorDialogPrivate( this );
1502}
1503
1504
1505/*!
1506 Pops up a modal color dialog letting the user choose a color and returns
1507 that color. The color is initially set to \a initial. Returns an \link QColor::isValid() invalid\endlink color if the user cancels
1508 the dialog. All colors allocated by the dialog will be deallocated
1509 before this function returns.
1510*/
1511
1512QColor QColorDialog::getColor( QColor initial, QWidget *parent,
1513 const char *name )
1514{
1515 int allocContext = QColor::enterAllocContext();
1516 QColorDialog *dlg = new QColorDialog( parent, name, TRUE ); //modal
1517 if ( parent && parent->icon() && !parent->icon()->isNull() )
1518 dlg->setIcon( *parent->icon() );
1519 else if ( qApp->mainWidget() && qApp->mainWidget()->icon() && !qApp->mainWidget()->icon()->isNull() )
1520 dlg->setIcon( *qApp->mainWidget()->icon() );
1521
1522 dlg->setCaption( QColorDialog::tr( "Select color" ) );
1523 dlg->setColor( initial );
1524 int resultCode = dlg->exec();
1525 QColor::leaveAllocContext();
1526 QColor result;
1527 if ( resultCode == QDialog::Accepted )
1528 result = dlg->color();
1529 QColor::destroyAllocContext(allocContext);
1530 delete dlg;
1531 return result;
1532}
1533
1534
1535/*!
1536 Pops up a modal color dialog, letting the user choose a color and an
1537 alpha channel value. The color+alpha is initially set to \a initial.
1538
1539 If \a ok is non-null, \c *ok is set to TRUE if the user clicked OK,
1540 and FALSE if the user clicked Cancel.
1541
1542 If the user clicks Cancel the \a initial value is returned.
1543*/
1544
1545QRgb QColorDialog::getRgba( QRgb initial, bool *ok,
1546 QWidget *parent, const char* name )
1547{
1548 int allocContext = QColor::enterAllocContext();
1549 QColorDialog *dlg = new QColorDialog( parent, name, TRUE ); //modal
1550 dlg->setColor( initial );
1551 dlg->setSelectedAlpha( qAlpha(initial) );
1552 int resultCode = dlg->exec();
1553 QColor::leaveAllocContext();
1554 QRgb result = initial;
1555 if ( resultCode == QDialog::Accepted ) {
1556 QRgb c = dlg->color().rgb();
1557 int alpha = dlg->selectedAlpha();
1558 result = qRgba( qRed(c), qGreen(c), qBlue(c), alpha );
1559 }
1560 if ( ok )
1561 *ok = resultCode == QDialog::Accepted;
1562
1563 QColor::destroyAllocContext(allocContext);
1564 delete dlg;
1565 return result;
1566}
1567
1568
1569
1570
1571
1572/*!
1573 Returns the color currently selected in the dialog.
1574
1575 \sa setColor()
1576*/
1577
1578QColor QColorDialog::color() const
1579{
1580 return QColor(d->currentColor());
1581}
1582
1583
1584/*! Destructs the dialog and frees any memory it allocated.
1585
1586*/
1587
1588QColorDialog::~QColorDialog()
1589{
1590 //d inherits QObject, so it is deleted by Qt.
1591}
1592
1593
1594/*!
1595 Sets the color shown in the dialog to \a c.
1596
1597 \sa color()
1598*/
1599
1600void QColorDialog::setColor( QColor c )
1601{
1602 d->setCurrentColor( c.rgb() );
1603}
1604
1605
1606
1607
1608/*!
1609 Sets the initial alpha channel value to \a a, and show the alpha channel
1610 entry box.
1611*/
1612
1613void QColorDialog::setSelectedAlpha( int a )
1614{
1615 d->showAlpha( TRUE );
1616 d->setCurrentAlpha( a );
1617}
1618
1619
1620/*!
1621 Returns the value selected for the alpha channel.
1622*/
1623
1624int QColorDialog::selectedAlpha() const
1625{
1626 return d->currentAlpha();
1627}
1628
1629
diff --git a/libqtaux/qcolordialog.h b/libqtaux/qcolordialog.h
new file mode 100644
index 0000000..89c6283
--- a/dev/null
+++ b/libqtaux/qcolordialog.h
@@ -0,0 +1,84 @@
1/****************************************************************************
2** $Id$
3**
4** Definition of QColorDialog class
5**
6** Created : 990222
7**
8** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
9**
10** This file is part of the dialogs module of the Qt GUI Toolkit.
11**
12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file.
15**
16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file.
20**
21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22** licenses may use this file in accordance with the Qt Commercial License
23** Agreement provided with the Software.
24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32**
33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you.
35**
36**********************************************************************/
37
38#ifndef QCOLORDIALOG_H
39#define QCOLORDIALOG_H
40
41#ifndef QT_H
42#include <qdialog.h>
43#endif // QT_H
44
45class QColorDialogPrivate;
46
47class Q_EXPORT QColorDialog : public QDialog
48{
49 Q_OBJECT
50
51public:
52 static QColor getColor( QColor, QWidget *parent=0, const char* name=0 ); // ### 3.0: make const QColor&
53 static QRgb getRgba( QRgb, bool* ok = 0,
54 QWidget *parent=0, const char* name=0 );
55
56
57 static int customCount();
58 static QRgb customColor( int );
59 static void setCustomColor( int, QRgb );
60
61private:
62 ~QColorDialog();
63
64 QColorDialog( QWidget* parent=0, const char* name=0, bool modal=FALSE );
65 void setColor( QColor ); // ### 3.0: make const QColor&
66 QColor color() const;
67
68private:
69 void setSelectedAlpha( int );
70 int selectedAlpha() const;
71
72 void showCustom( bool=TRUE );
73private:
74 QColorDialogPrivate *d;
75 friend class QColorDialogPrivate;
76
77 private:// Disabled copy constructor and operator=
78#if defined(Q_DISABLE_COPY)
79 QColorDialog( const QColorDialog & );
80 QColorDialog& operator=( const QColorDialog & );
81#endif
82};
83
84#endif
diff --git a/libqtaux/qinputdialog.cpp b/libqtaux/qinputdialog.cpp
new file mode 100644
index 0000000..821c74d
--- a/dev/null
+++ b/libqtaux/qinputdialog.cpp
@@ -0,0 +1,493 @@
1/****************************************************************************
2** $Id$
3**
4** Implementation of QInputDialog class
5**
6** Created : 991212
7**
8** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
9**
10** This file is part of the dialogs module of the Qt GUI Toolkit.
11**
12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file.
15**
16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file.
20**
21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22** licenses may use this file in accordance with the Qt Commercial License
23** Agreement provided with the Software.
24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32**
33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you.
35**
36**********************************************************************/
37
38#include "qinputdialog.h"
39
40#include <qlayout.h>
41#include <qlabel.h>
42#include <qlineedit.h>
43#include <qpushbutton.h>
44#include <qspinbox.h>
45#include <qcombobox.h>
46#include <qwidgetstack.h>
47#include <qvalidator.h>
48#include <qapplication.h>
49
50class QInputDialogPrivate
51{
52public:
53 friend class QInputDialog;
54 QLineEdit *lineEdit;
55 QSpinBox *spinBox;
56 QComboBox *comboBox, *editComboBox;
57 QPushButton *ok;
58 QWidgetStack *stack;
59 QInputDialog::Type type;
60};
61
62/*!
63 \class QInputDialog qinputdialog.h
64 \brief A convenience dialog to get a simple input from the user
65 \ingroup dialogs
66
67 The QInputDialog is a simple dialog which can be used if you
68 need a simple input from the user. This can be text, a number or
69 an item from a list. Also a label has to be set to tell the user
70 what he/she should input.
71
72 In this Qt version only the 4 static convenience functions
73 getText(), getInteger(), getDouble() and getItem() of QInputDialog
74 are available.
75
76 Use it like this:
77
78 \code
79 bool ok = FALSE;
80 QString text = QInputDialog::getText( tr( "Make an input" ), tr( "Please enter your name" ), QString::null, &ok, this );
81 if ( ok && !text.isEmpty() )
82 ;// user entered something and pressed ok
83 else
84 ;// user entered nothing or pressed cancel
85 \endcode
86
87 There are more static convenience methods!
88
89 \sa getText(), getInteger(), getDouble(), getItem()
90*/
91
92/*!
93 \enum QInputDialog::Type
94
95 This enum type specifies the type of the dialog
96 (which kind of input can be done):
97
98 <ul>
99 <li>\c LineEdit - A QLineEdit is used for taking the input, so a textual or
100 (e.g. using a QValidator) a numerical input can be done. Using lineEdit()
101 the QLineEdit can be accessed.
102 <li>\c SpinBox - A QSpinBox is used for taking the input, so a decimal
103 input can be done. Using spinBox() the QSpinBox can be accessed.
104 <li>\c ComboBox - A read-only QComboBox is used for taking the input,
105 so one item of a list can be chosen. Using comboBox() the QComboBox
106 can be accessed.
107 <li>\c EditableComboBox - An editable QComboBox is used for taking the input,
108 so either one item of a list can be chosen or a text can be entered. Using
109 editableComboBox() the QComboBox can be accessed.
110 </ul>
111*/
112
113/*!
114 Constructs the dialog. \a label is the text which is shown to the user (it should mention
115 to the user what he/she should input), \a parent the parent widget of the dialog, \a name
116 the name of it and if you set \a modal to TRUE, the dialog pops up modally, else it pops
117 up modeless. With \a type you specify the type of the dialog.
118
119 \sa getText(), getInteger(), getDouble(), getItem()
120*/
121
122QInputDialog::QInputDialog( const QString &label, QWidget* parent, const char* name,
123 bool modal, Type type)
124 : QDialog( parent, name, modal )
125{
126 if ( parent && parent->icon() &&!parent->icon()->isNull() )
127 setIcon( *parent->icon() );
128 else if ( qApp->mainWidget() && qApp->mainWidget()->icon() && !qApp->mainWidget()->icon()->isNull() )
129 QDialog::setIcon( *qApp->mainWidget()->icon() );
130
131 d = new QInputDialogPrivate;
132 d->lineEdit = 0;
133 d->spinBox = 0;
134 d->comboBox = 0;
135
136 QVBoxLayout *vbox = new QVBoxLayout( this, 6, 6 );
137
138 QLabel* l = new QLabel( label, this );
139 vbox->addWidget( l );
140
141 d->stack = new QWidgetStack( this );
142 vbox->addWidget( d->stack );
143 d->lineEdit = new QLineEdit( d->stack );
144 d->spinBox = new QSpinBox( d->stack );
145 d->comboBox = new QComboBox( FALSE, d->stack );
146 d->editComboBox = new QComboBox( TRUE, d->stack );
147
148 QHBoxLayout *hbox = new QHBoxLayout( 6 );
149 vbox->addLayout( hbox, AlignRight );
150
151 d->ok = new QPushButton( tr( "&OK" ), this );
152 d->ok->setDefault( TRUE );
153 QPushButton *cancel = new QPushButton( tr( "&Cancel" ), this );
154
155 QSize bs( d->ok->sizeHint() );
156 if ( cancel->sizeHint().width() > bs.width() )
157 bs.setWidth( cancel->sizeHint().width() );
158
159 d->ok->setFixedSize( bs );
160 cancel->setFixedSize( bs );
161
162 hbox->addWidget( new QWidget( this ) );
163 hbox->addWidget( d->ok );
164 hbox->addWidget( cancel );
165
166 connect( d->lineEdit, SIGNAL( returnPressed() ),
167 this, SLOT( tryAccept() ) );
168 connect( d->lineEdit, SIGNAL( textChanged(const QString&) ),
169 this, SLOT( textChanged(const QString&) ) );
170
171 connect( d->ok, SIGNAL( clicked() ), this, SLOT( accept() ) );
172 connect( cancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
173
174 resize( QMAX( sizeHint().width(), 400 ), sizeHint().height() );
175
176 setType( type );
177}
178
179/*!
180 Returns the line edit, which is used in the LineEdit mode
181*/
182
183QLineEdit *QInputDialog::lineEdit() const
184{
185 return d->lineEdit;
186}
187
188/*!
189 Returns the spinbox, which is used in the SpinBox mode
190*/
191
192QSpinBox *QInputDialog::spinBox() const
193{
194 return d->spinBox;
195}
196
197/*!
198 Returns the combobox, which is used in the ComboBox mode
199*/
200
201QComboBox *QInputDialog::comboBox() const
202{
203 return d->comboBox;
204}
205
206/*!
207 Returns the combobox, which is used in the EditableComboBox mode
208*/
209
210QComboBox *QInputDialog::editableComboBox() const
211{
212 return d->editComboBox;
213}
214
215/*!
216 Sets the input type of the dialog to \a t.
217*/
218
219void QInputDialog::setType( Type t )
220{
221 switch ( t ) {
222 case LineEdit:
223 d->stack->raiseWidget( d->lineEdit );
224 d->lineEdit->setFocus();
225 break;
226 case SpinBox:
227 d->stack->raiseWidget( d->spinBox );
228 d->spinBox->setFocus();
229 break;
230 case ComboBox:
231 d->stack->raiseWidget( d->comboBox );
232 d->comboBox->setFocus();
233 break;
234 case EditableComboBox:
235 d->stack->raiseWidget( d->editComboBox );
236 d->editComboBox->setFocus();
237 break;
238 }
239
240 d->type = t;
241}
242
243/*!
244 Returns the input type of the dialog.
245
246 \sa setType()
247*/
248
249QInputDialog::Type QInputDialog::type() const
250{
251 return d->type;
252}
253
254/*!
255 Destructor.
256*/
257
258QInputDialog::~QInputDialog()
259{
260 delete d;
261}
262
263/*!
264 Static convenience function to get a textual input from the user. \a caption is the text
265 which is displayed in the title bar of the dialog. \a label is the text which
266 is shown to the user (it should mention to the user what he/she should input), \a text
267 the default text which will be initially set to the line edit, \a ok a pointer to
268 a bool which will be (if not 0!) set to TRUE if the user pressed ok or to FALSE if the
269 user pressed cancel, \a parent the parent widget of the dialog and \a name
270 the name of it. The dialogs pops up modally!
271
272 This method returns the text which has been entered in the line edit.
273
274 You will use this static method like this:
275
276 \code
277 bool ok = FALSE;
278 QString text = QInputDialog::getText( tr( "Please enter your name" ), QString::null, &ok, this );
279 if ( ok && !text.isEmpty() )
280 ;// user entered something and pressed ok
281 else
282 ;// user entered nothing or pressed cancel
283 \endcode
284*/
285
286QString QInputDialog::getText( const QString &caption, const QString &label, const QString &text,
287 bool *ok, QWidget *parent, const char *name )
288{
289 return getText( caption, label, QLineEdit::Normal, text, ok, parent, name );
290}
291
292/*!
293 Like above, but accepts an a \a mode which the line edit will use to display text.
294
295 \sa getText()
296*/
297
298QString QInputDialog::getText( const QString &caption, const QString &label, QLineEdit::EchoMode mode,
299 const QString &text, bool *ok, QWidget *parent, const char *name )
300{
301 QInputDialog *dlg = new QInputDialog( label, parent, name, TRUE, LineEdit );
302 dlg->setCaption( caption );
303 dlg->lineEdit()->setText( text );
304 dlg->lineEdit()->setEchoMode( mode );
305 if ( !text.isEmpty() )
306 dlg->lineEdit()->selectAll();
307
308 bool ok_ = FALSE;
309 QString result;
310 ok_ = dlg->exec() == QDialog::Accepted;
311 if ( ok )
312 *ok = ok_;
313 if ( ok_ )
314 result = dlg->lineEdit()->text();
315
316 delete dlg;
317 return result;
318}
319
320/*!
321 Static convenience function to get an integral input from the user. \a caption is the text
322 which is displayed in the title bar of the dialog. \a label is the text which
323 is shown to the user (it should mention to the user what he/she should input), \a num
324 the default number which will be initially set to the spinbox, \a from and \a to the
325 range in which the entered number has to be, \a step the step in which the number can
326 be increased/decreased by the spinbox, \a ok a pointer to
327 a bool which will be (if not 0!) set to TRUE if the user pressed ok or to FALSE if the
328 user pressed cancel, \a parent the parent widget of the dialog and \a name
329 the name of it. The dialogs pops up modally!
330
331 This method returns the number which has been entered by the user.
332
333 You will use this static method like this:
334
335 \code
336 bool ok = FALSE;
337 int res = QInputDialog::getInteger( tr( "Please enter a number" ), 22, 0, 1000, 2, &ok, this );
338 if ( ok )
339 ;// user entered something and pressed ok
340 else
341 ;// user pressed cancel
342 \endcode
343*/
344
345int QInputDialog::getInteger( const QString &caption, const QString &label, int num, int from, int to, int step,
346 bool *ok, QWidget *parent, const char *name )
347{
348 QInputDialog *dlg = new QInputDialog( label, parent, name, TRUE, SpinBox );
349 dlg->setCaption( caption );
350 dlg->spinBox()->setRange( from, to );
351 dlg->spinBox()->setSteps( step, 0 );
352 dlg->spinBox()->setValue( num );
353
354 bool ok_ = FALSE;
355 int result;
356 ok_ = dlg->exec() == QDialog::Accepted;
357 if ( ok )
358 *ok = ok_;
359 result = dlg->spinBox()->value();
360
361 delete dlg;
362 return result;
363}
364
365/*!
366 Static convenience function to get a decimal input from the user. \a caption is the text
367 which is displayed in the title bar of the dialog. \a label is the text which
368 is shown to the user (it should mention to the user what he/she should input), \a num
369 the default decimal number which will be initially set to the line edit, \a from and \a to the
370 range in which the entered number has to be, \a decimals the number of decimal which
371 the number may have, \a ok a pointer to
372 a bool which will be (if not 0!) set to TRUE if the user pressed ok or to FALSE if the
373 user pressed cancel, \a parent the parent widget of the dialog and \a name
374 the name of it. The dialogs pops up modally!
375
376 This method returns the number which has been entered by the user.
377
378 You will use this static method like this:
379
380 \code
381 bool ok = FALSE;
382 double res = QInputDialog::getDouble( tr( "Please enter a decimal number" ), 33.7, 0, 1000, 2, &ok, this );
383 if ( ok )
384 ;// user entered something and pressed ok
385 else
386 ;// user pressed cancel
387 \endcode
388*/
389
390double QInputDialog::getDouble( const QString &caption, const QString &label, double num,
391 double from, double to, int decimals,
392 bool *ok, QWidget *parent, const char *name )
393{
394 QInputDialog *dlg = new QInputDialog( label, parent, name, TRUE, LineEdit );
395 dlg->setCaption( caption );
396 dlg->lineEdit()->setValidator( new QDoubleValidator( from, to, decimals, dlg->lineEdit() ) );
397 dlg->lineEdit()->setText( QString::number( num, 'f', decimals ) );
398 dlg->lineEdit()->selectAll();
399
400 bool accepted = ( dlg->exec() == QDialog::Accepted );
401 if ( ok )
402 *ok = accepted;
403
404 double result = dlg->lineEdit()->text().toDouble();
405
406 delete dlg;
407 return result;
408}
409
410/*!
411 Static convenience function to let the user select an item from a string list. \a caption is the text
412 which is displayed in the title bar of the dialog. \a label is the text which
413 is shown to the user (it should mention to the user what he/she should input), \a list the
414 string list which is inserted into the combobox, \a current the number of the item which should
415 be initially the current item, \a editable specifies if the combobox should be editable (if it is TRUE)
416 or read-only (if \a editable is FALSE), \a ok a pointer to
417 a bool which will be (if not 0!) set to TRUE if the user pressed ok or to FALSE if the
418 user pressed cancel, \a parent the parent widget of the dialog and \a name
419 the name of it. The dialogs pops up modally!
420
421 This method returns the text of the current item, or if \a editable was TRUE, the current
422 text of the combobox.
423
424 You will use this static method like this:
425
426 \code
427 QStringList lst;
428 lst << "First" << "Second" << "Third" << "Fourth" << "Fifth";
429 bool ok = FALSE;
430 QString res = QInputDialog::getItem( tr( "Please select an item" ), lst, 1, TRUE, &ok, this );
431 if ( ok )
432 ;// user selected an item and pressed ok
433 else
434 ;// user pressed cancel
435 \endcode
436*/
437
438QString QInputDialog::getItem( const QString &caption, const QString &label, const QStringList &list,
439 int current, bool editable,
440 bool *ok, QWidget *parent, const char *name )
441{
442 QInputDialog *dlg = new QInputDialog( label, parent, name, TRUE, editable ? EditableComboBox : ComboBox );
443 dlg->setCaption( caption );
444 if ( editable ) {
445 dlg->editableComboBox()->insertStringList( list );
446 dlg->editableComboBox()->setCurrentItem( current );
447 } else {
448 dlg->comboBox()->insertStringList( list );
449 dlg->comboBox()->setCurrentItem( current );
450 }
451
452 bool ok_ = FALSE;
453 QString result;
454 ok_ = dlg->exec() == QDialog::Accepted;
455 if ( ok )
456 *ok = ok_;
457 if ( editable )
458 result = dlg->editableComboBox()->currentText();
459 else
460 result = dlg->comboBox()->currentText();
461
462 delete dlg;
463 return result;
464}
465
466/*!
467 \internal
468*/
469
470void QInputDialog::textChanged( const QString &s )
471{
472 bool on;
473 if ( d->lineEdit->validator() ) {
474 QString str = d->lineEdit->text();
475 int index = d->lineEdit->cursorPosition();
476 on = ( d->lineEdit->validator()->validate(str, index) ==
477 QValidator::Acceptable );
478 } else {
479 on = !s.isEmpty();
480 }
481 d->ok->setEnabled( on );
482}
483
484/*!
485 \internal
486*/
487
488void QInputDialog::tryAccept()
489{
490 if ( !d->lineEdit->text().isEmpty() )
491 accept();
492}
493
diff --git a/libqtaux/qinputdialog.h b/libqtaux/qinputdialog.h
new file mode 100644
index 0000000..2583185
--- a/dev/null
+++ b/libqtaux/qinputdialog.h
@@ -0,0 +1,106 @@
1/****************************************************************************
2** $Id$
3**
4** Definition of QInputDialog class
5**
6** Created : 991212
7**
8** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
9**
10** This file is part of the dialogs module of the Qt GUI Toolkit.
11**
12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file.
15**
16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file.
20**
21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22** licenses may use this file in accordance with the Qt Commercial License
23** Agreement provided with the Software.
24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32**
33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you.
35**
36**********************************************************************/
37
38#ifndef QINPUTDIALOG_H
39#define QINPUTDIALOG_H
40
41#ifndef QT_H
42#include <qdialog.h>
43#include <qstring.h>
44#include <qlineedit.h>
45#endif // QT_H
46
47class QInputDialogPrivate;
48
49class QSpinBox;
50class QComboBox;
51
52class Q_EXPORT QInputDialog : public QDialog
53{
54#if defined(_CC_MSVC_)
55 friend class QInputDialog;
56#endif
57 Q_OBJECT
58
59private:
60 enum Type { LineEdit, SpinBox, ComboBox, EditableComboBox };
61
62 QInputDialog( const QString &label, QWidget* parent = 0, const char* name = 0,
63 bool modal = TRUE, Type type = LineEdit );
64 ~QInputDialog();
65
66 QLineEdit *lineEdit() const;
67 QSpinBox *spinBox() const;
68 QComboBox *comboBox() const;
69 QComboBox *editableComboBox() const;
70
71 void setType( Type t );
72 Type type() const;
73
74public:
75 static QString getText( const QString &caption, const QString &label, const QString &text = QString::null,
76 bool *ok = 0, QWidget *parent = 0, const char *name = 0 ); // ### merge with below in 3.0
77 static QString getText( const QString &caption, const QString &label, QLineEdit::EchoMode echo, //### make default Normal in 3.0
78 const QString &text = QString::null, bool *ok = 0, QWidget *parent = 0, const char *name = 0 );
79
80 static int getInteger( const QString &caption, const QString &label, int num = 0, int from = -2147483647,
81 int to = 2147483647,
82 int step = 1, bool *ok = 0, QWidget *parent = 0, const char *name = 0 );
83 static double getDouble( const QString &caption, const QString &label, double num = 0,
84 double from = -2147483647, double to = 2147483647,
85 int decimals = 1, bool *ok = 0, QWidget *parent = 0, const char *name = 0 );
86 static QString getItem( const QString &caption, const QString &label, const QStringList &list,
87 int current = 0, bool editable = TRUE,
88 bool *ok = 0, QWidget *parent = 0, const char *name = 0 );
89
90private slots:
91 void textChanged( const QString &s );
92 void tryAccept();
93
94private:
95 QInputDialogPrivate *d;
96 // just to avoid warnings...
97 friend class QInputDialogPrivate;
98
99 private:// Disabled copy constructor and operator=
100#if defined(Q_DISABLE_COPY)
101 QInputDialog( const QInputDialog & );
102 QInputDialog &operator=( const QInputDialog & );
103#endif
104};
105
106#endif // QINPUTDIALOG_H
diff --git a/libqtaux/qlayoutengine_p.h b/libqtaux/qlayoutengine_p.h
new file mode 100644
index 0000000..1b463b5
--- a/dev/null
+++ b/libqtaux/qlayoutengine_p.h
@@ -0,0 +1,108 @@
1/****************************************************************************
2** $Id$
3**
4** Internal header file.
5**
6** Created : 981027
7**
8** Copyright (C) 1998-99 by Trolltech AS. All rights reserved.
9**
10** This file is part of the kernel module of the Qt GUI Toolkit.
11**
12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file.
15**
16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file.
20**
21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22** licenses may use this file in accordance with the Qt Commercial License
23** Agreement provided with the Software.
24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32**
33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you.
35**
36**********************************************************************/
37
38#ifndef QLAYOUTENGINE_P_H
39#define QLAYOUTENGINE_P_H
40
41
42//
43// W A R N I N G
44// -------------
45//
46// This file is not part of the Qt API. It exists for the convenience
47// of qlayout.cpp, qlayoutengine.cpp, qmainwindow.cpp and qsplitter.cpp.
48// This header file may change from version to version without notice,
49// or even be removed.
50//
51// We mean it.
52//
53//
54
55
56#ifndef QT_H
57#include "qabstractlayout.h"
58#endif // QT_H
59#ifndef QT_NO_LAYOUT
60struct QLayoutStruct
61{
62 void init() { stretch = 0; initParameters(); }
63 void initParameters() { minimumSize = sizeHint = 0;
64 maximumSize = QWIDGETSIZE_MAX; expansive = FALSE; empty = TRUE; }
65 //permanent storage:
66 int stretch;
67 //parameters:
68 QCOORD sizeHint;
69 QCOORD maximumSize;
70 QCOORD minimumSize;
71 bool expansive;
72 bool empty;
73 //temporary storage:
74 bool done;
75 //result:
76 int pos;
77 int size;
78};
79
80
81void qGeomCalc( QArray<QLayoutStruct> &chain, int start, int count, int pos,
82 int space, int spacer );
83
84
85
86/*
87 Modify total maximum (max) and total expansion (exp)
88 when adding boxmax/boxexp.
89
90 Expansive boxes win over non-expansive boxes.
91*/
92static inline void qMaxExpCalc( QCOORD & max, bool &exp,
93 QCOORD boxmax, bool boxexp )
94{
95 if ( exp ) {
96 if ( boxexp )
97 max = QMAX( max, boxmax );
98 } else {
99 if ( boxexp )
100 max = boxmax;
101 else
102 max = QMIN( max, boxmax );
103 }
104 exp = exp || boxexp;
105}
106
107#endif //QT_NO_LAYOUT
108#endif
diff --git a/libqtaux/qsplitter.cpp b/libqtaux/qsplitter.cpp
new file mode 100644
index 0000000..ab6e01b
--- a/dev/null
+++ b/libqtaux/qsplitter.cpp
@@ -0,0 +1,1128 @@
1/****************************************************************************
2** $Id$
3**
4** Splitter widget
5**
6** Created: 980105
7**
8** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
9**
10** This file is part of the widgets module of the Qt GUI Toolkit.
11**
12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file.
15**
16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file.
20**
21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22** licenses may use this file in accordance with the Qt Commercial License
23** Agreement provided with the Software.
24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32**
33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you.
35**
36**********************************************************************/
37#include "qsplitter.h"
38
39#include "qpainter.h"
40#include "qdrawutil.h"
41#include "qbitmap.h"
42#include "qlayoutengine_p.h"
43#include "qlist.h"
44#include "qarray.h"
45#include "qobjectlist.h"
46#include "qapplication.h" //sendPostedEvents
47
48class QSplitterHandle : public QWidget
49{
50public:
51 QSplitterHandle( Qt::Orientation o,
52 QSplitter *parent, const char* name=0 );
53 void setOrientation( Qt::Orientation o );
54 Qt::Orientation orientation() const { return orient; }
55
56 bool opaque() const { return s->opaqueResize(); }
57
58 QSize sizeHint() const;
59 QSizePolicy sizePolicy() const;
60
61 int id() const { return myId; } // data->list.at(id())->wid == this
62 void setId( int i ) { myId = i; }
63
64protected:
65 void paintEvent( QPaintEvent * );
66 void mouseMoveEvent( QMouseEvent * );
67 void mousePressEvent( QMouseEvent * );
68 void mouseReleaseEvent( QMouseEvent * );
69
70private:
71 Qt::Orientation orient;
72 bool opaq;
73 int myId;
74
75 QSplitter *s;
76};
77
78static int mouseOffset;
79static int opaqueOldPos = -1; //### there's only one mouse, but this is a bit risky
80
81
82QSplitterHandle::QSplitterHandle( Qt::Orientation o,
83 QSplitter *parent, const char * name )
84 : QWidget( parent, name )
85{
86 s = parent;
87 setOrientation(o);
88}
89
90QSizePolicy QSplitterHandle::sizePolicy() const
91{
92 //### removeme 3.0
93 return QWidget::sizePolicy();
94}
95
96QSize QSplitterHandle::sizeHint() const
97{
98 int sw = style().splitterWidth();
99 return QSize(sw,sw).expandedTo( QApplication::globalStrut() );
100}
101
102void QSplitterHandle::setOrientation( Qt::Orientation o )
103{
104 orient = o;
105#ifndef QT_NO_CURSOR
106 if ( o == QSplitter::Horizontal )
107 setCursor( splitHCursor );
108 else
109 setCursor( splitVCursor );
110#endif
111}
112
113
114void QSplitterHandle::mouseMoveEvent( QMouseEvent *e )
115{
116 if ( !(e->state()&LeftButton) )
117 return;
118 QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos()))
119 - mouseOffset;
120 if ( opaque() ) {
121 s->moveSplitter( pos, id() );
122 } else {
123 int min = pos; int max = pos;
124 s->getRange( id(), &min, &max );
125 s->setRubberband( QMAX( min, QMIN(max, pos )));
126 }
127}
128
129void QSplitterHandle::mousePressEvent( QMouseEvent *e )
130{
131 if ( e->button() == LeftButton )
132 mouseOffset = s->pick(e->pos());
133}
134
135void QSplitterHandle::mouseReleaseEvent( QMouseEvent *e )
136{
137 if ( !opaque() && e->button() == LeftButton ) {
138 QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos()));
139 s->setRubberband( -1 );
140 s->moveSplitter( pos, id() );
141 }
142}
143
144void QSplitterHandle::paintEvent( QPaintEvent * )
145{
146 QPainter p( this );
147 s->drawSplitter( &p, 0, 0, width(), height() );
148}
149
150
151class QSplitterLayoutStruct
152{
153public:
154 QSplitter::ResizeMode mode;
155 QCOORD sizer;
156 bool isSplitter;
157 QWidget *wid;
158};
159
160class QSplitterData
161{
162public:
163 QSplitterData() : opaque( FALSE ), firstShow( TRUE ) {}
164
165 QList<QSplitterLayoutStruct> list;
166 bool opaque;
167 bool firstShow;
168};
169
170
171// NOT REVISED
172/*!
173 \class QSplitter qsplitter.h
174 \brief The QSplitter class implements a splitter widget.
175
176 \ingroup organizers
177
178 A splitter lets the user control the size of child widgets by
179 dragging the boundary between the children. Any number of widgets
180 may be controlled.
181
182 To show a QListBox, a QListView and a QMultiLineEdit side by side:
183
184 \code
185 QSplitter *split = new QSplitter( parent );
186 QListBox *lb = new QListBox( split );
187 QListView *lv = new QListView( split );
188 QMultiLineEdit *ed = new QMultiLineEdit( split );
189 \endcode
190
191 In QSplitter the boundary can be either horizontal or vertical. The
192 default is horizontal (the children are side by side) and you
193 can use setOrientation( QSplitter::Vertical ) to set it to vertical.
194
195 By default, all widgets can be as large or as small as the user
196 wishes, down to \link QWidget::minimumSizeHint() minimumSizeHint()\endlink.
197 You can naturally use setMinimumSize() and/or
198 setMaximumSize() on the children. Use setResizeMode() to specify that
199 a widget should keep its size when the splitter is resized.
200
201 QSplitter normally resizes the children only at the end of a
202 resize operation, but if you call setOpaqueResize( TRUE ), the
203 widgets are resized as often as possible.
204
205 The initial distribution of size between the widgets is determined
206 by the initial size of each widget. You can also use setSizes() to
207 set the sizes of all the widgets. The function sizes() returns the
208 sizes set by the user.
209
210 If you hide() a child, its space will be distributed among the other
211 children. When you show() it again, it will be reinstated.
212
213 <img src=qsplitter-m.png> <img src=qsplitter-w.png>
214
215 \sa QTabBar
216*/
217
218
219
220static QSize minSize( const QWidget *w )
221{
222 QSize min = w->minimumSize();
223 QSize s;
224 if ( min.height() <= 0 || min.width() <= 0 )
225 s = w->minimumSizeHint();
226 if ( min.height() > 0 )
227 s.setHeight( min.height() );
228 if ( min.width() > 0 )
229 s.setWidth( min.width() );
230 return s.expandedTo(QSize(0,0));
231}
232
233/*!
234 Constructs a horizontal splitter.
235*/
236
237QSplitter::QSplitter( QWidget *parent, const char *name )
238 :QFrame(parent,name,WPaintUnclipped)
239{
240 orient = Horizontal;
241 init();
242}
243
244
245/*!
246 Constructs splitter with orientation \a o.
247*/
248
249QSplitter::QSplitter( Orientation o, QWidget *parent, const char *name )
250 :QFrame(parent,name,WPaintUnclipped)
251{
252 orient = o;
253 init();
254}
255
256
257/*!
258 Destructs the splitter.
259*/
260
261QSplitter::~QSplitter()
262{
263 data->list.setAutoDelete( TRUE );
264 delete data;
265}
266
267
268void QSplitter::init()
269{
270 data = new QSplitterData;
271 if ( orient == Horizontal )
272 setSizePolicy( QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Minimum) );
273 else
274 setSizePolicy( QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Fixed) );
275}
276
277
278/*!
279 \fn void QSplitter::refresh()
280
281 Updates the splitter state. You should not need to call this
282 function during normal use of the splitter.
283*/
284
285
286/*! Sets the orientation to \a o. By default the orientation is
287 horizontal (the widgets are side by side).
288
289 \sa orientation()
290*/
291
292void QSplitter::setOrientation( Orientation o )
293{
294 if ( orient == o )
295 return;
296 orient = o;
297
298 if ( orient == Horizontal )
299 setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Minimum ) );
300 else
301 setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed ) );
302
303 QSplitterLayoutStruct *s = data->list.first();
304 while ( s ) {
305 if ( s->isSplitter )
306 ((QSplitterHandle*)s->wid)->setOrientation( o );
307 s = data->list.next(); // ### next at end of loop, no iterator
308 }
309 recalc( isVisible() );
310}
311
312
313/*!
314 \fn Orientation QSplitter::orientation() const
315
316 Returns the orientation (\c Horizontal or \c Vertical) of the splitter.
317 \sa setOrientation()
318*/
319
320/*!
321 \reimp
322*/
323void QSplitter::resizeEvent( QResizeEvent * )
324{
325 doResize();
326}
327
328
329/*!
330 Inserts the widget \a w at the end, or at the beginning if \a first is TRUE
331
332 It is the responsibility of the caller of this function to make sure
333 that \a w is not already in the splitter, and to call recalcId if
334 needed. (If \a first is TRUE, then recalcId is very probably
335 needed.)
336*/
337
338QSplitterLayoutStruct *QSplitter::addWidget( QWidget *w, bool first )
339{
340 QSplitterLayoutStruct *s;
341 QSplitterHandle *newHandle = 0;
342 if ( data->list.count() > 0 ) {
343 s = new QSplitterLayoutStruct;
344 s->mode = KeepSize;
345 newHandle = new QSplitterHandle( orientation(), this );
346 s->wid = newHandle;
347 newHandle->setId(data->list.count());
348 s->isSplitter = TRUE;
349 s->sizer = pick( newHandle->sizeHint() );
350 if ( first )
351 data->list.insert( 0, s );
352 else
353 data->list.append( s );
354 }
355 s = new QSplitterLayoutStruct;
356 s->mode = Stretch;
357 s->wid = w;
358 if ( !testWState( WState_Resized ) && w->sizeHint().isValid() )
359 s->sizer = pick( w->sizeHint() );
360 else
361 s->sizer = pick( w->size() );
362 s->isSplitter = FALSE;
363 if ( first )
364 data->list.insert( 0, s );
365 else
366 data->list.append( s );
367 if ( newHandle && isVisible() )
368 newHandle->show(); //will trigger sending of post events
369 return s;
370}
371
372
373/*!
374 Tells the splitter that a child widget has been inserted/removed.
375*/
376
377void QSplitter::childEvent( QChildEvent *c )
378{
379 if ( c->type() == QEvent::ChildInserted ) {
380 if ( !c->child()->isWidgetType() )
381 return;
382
383 if ( ((QWidget*)c->child())->testWFlags( WType_TopLevel ) )
384 return;
385
386 QSplitterLayoutStruct *s = data->list.first();
387 while ( s ) {
388 if ( s->wid == c->child() )
389 return;
390 s = data->list.next();
391 }
392 addWidget( (QWidget*)c->child() );
393 recalc( isVisible() );
394
395 } else if ( c->type() == QEvent::ChildRemoved ) {
396 QSplitterLayoutStruct *p = 0;
397 if ( data->list.count() > 1 )
398 p = data->list.at(1); //remove handle _after_ first widget.
399 QSplitterLayoutStruct *s = data->list.first();
400 while ( s ) {
401 if ( s->wid == c->child() ) {
402 data->list.removeRef( s );
403 delete s;
404 if ( p && p->isSplitter ) {
405 data->list.removeRef( p );
406 delete p->wid; //will call childEvent
407 delete p;
408 }
409 recalcId();
410 doResize();
411 return;
412 }
413 p = s;
414 s = data->list.next();
415 }
416 }
417}
418
419
420/*!
421 Shows a rubber band at position \a p. If \a p is negative, the
422 rubber band is removed.
423*/
424
425void QSplitter::setRubberband( int p )
426{
427 QPainter paint( this );
428 paint.setPen( gray );
429 paint.setBrush( gray );
430 paint.setRasterOp( XorROP );
431 QRect r = contentsRect();
432 const int rBord = 3; //Themable????
433 const int sw = style().splitterWidth();
434 if ( orient == Horizontal ) {
435 if ( opaqueOldPos >= 0 )
436 paint.drawRect( opaqueOldPos + sw/2 - rBord , r.y(),
437 2*rBord, r.height() );
438 if ( p >= 0 )
439 paint.drawRect( p + sw/2 - rBord, r.y(), 2*rBord, r.height() );
440 } else {
441 if ( opaqueOldPos >= 0 )
442 paint.drawRect( r.x(), opaqueOldPos + sw/2 - rBord,
443 r.width(), 2*rBord );
444 if ( p >= 0 )
445 paint.drawRect( r.x(), p + sw/2 - rBord, r.width(), 2*rBord );
446 }
447 opaqueOldPos = p;
448}
449
450
451/*! \reimp */
452
453bool QSplitter::event( QEvent *e )
454{
455 if ( e->type() == QEvent::LayoutHint || ( e->type() == QEvent::Show && data->firstShow ) ) {
456 recalc( isVisible() );
457 if ( e->type() == QEvent::Show )
458 data->firstShow = FALSE;
459 }
460 return QWidget::event( e );
461}
462
463
464/*!
465 Draws the splitter handle in the rectangle described by \a x, \a y,
466 \a w, \a h using painter \a p.
467 \sa QStyle::drawSplitter
468*/
469
470void QSplitter::drawSplitter( QPainter *p,
471 QCOORD x, QCOORD y, QCOORD w, QCOORD h )
472{
473 style().drawSplitter( p, x, y, w, h, colorGroup(), orient );
474}
475
476
477/*!
478 Returns the id of the splitter to the right of or below the widget \a w,
479 or 0 if there is no such splitter.
480 (ie. it is either not in this QSplitter, or it is at the end).
481*/
482
483int QSplitter::idAfter( QWidget* w ) const
484{
485 QSplitterLayoutStruct *s = data->list.first();
486 bool seen_w = FALSE;
487 while ( s ) {
488 if ( s->isSplitter && seen_w )
489 return data->list.at();
490 if ( !s->isSplitter && s->wid == w )
491 seen_w = TRUE;
492 s = data->list.next();
493 }
494 return 0;
495}
496
497
498/*!
499 Moves the left/top edge of the splitter handle with id \a id as
500 close as possible to \a p which is the distance from the left (or
501 top) edge of the widget.
502
503 \sa idAfter()
504*/
505void QSplitter::moveSplitter( QCOORD p, int id )
506{
507 p = adjustPos( p, id );
508
509 QSplitterLayoutStruct *s = data->list.at(id);
510 int oldP = orient == Horizontal? s->wid->x() : s->wid->y();
511 bool upLeft = p < oldP;
512
513 moveAfter( p, id, upLeft );
514 moveBefore( p-1, id-1, upLeft );
515
516 storeSizes();
517}
518
519
520void QSplitter::setG( QWidget *w, int p, int s )
521{
522 if ( orient == Horizontal )
523 w->setGeometry( p, contentsRect().y(), s, contentsRect().height() );
524 else
525 w->setGeometry( contentsRect().x(), p, contentsRect().width(), s );
526}
527
528
529/*!
530 Places the right/bottom edge of the widget at \a id at position \a pos.
531
532 \sa idAfter()
533*/
534
535void QSplitter::moveBefore( int pos, int id, bool upLeft )
536{
537 QSplitterLayoutStruct *s = data->list.at(id);
538 if ( !s )
539 return;
540 QWidget *w = s->wid;
541 if ( w->isHidden() ) {
542 moveBefore( pos, id-1, upLeft );
543 } else if ( s->isSplitter ) {
544 int dd = s->sizer;
545 if ( upLeft ) {
546 setG( w, pos-dd+1, dd );
547 moveBefore( pos-dd, id-1, upLeft );
548 } else {
549 moveBefore( pos-dd, id-1, upLeft );
550 setG( w, pos-dd+1, dd );
551 }
552 } else {
553 int left = pick( w->pos() );
554 int dd = pos - left + 1;
555 dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize())));
556 int newLeft = pos-dd+1;
557 setG( w, newLeft, dd );
558 if ( left != newLeft )
559 moveBefore( newLeft-1, id-1, upLeft );
560 }
561}
562
563
564/*!
565 Places the left/top edge of the widget at \a id at position \a pos.
566
567 \sa idAfter()
568*/
569
570void QSplitter::moveAfter( int pos, int id, bool upLeft )
571{
572 QSplitterLayoutStruct *s = id < int(data->list.count()) ?
573 data->list.at(id) : 0;
574 if ( !s )
575 return;
576 QWidget *w = s->wid;
577 if ( w->isHidden() ) {
578 moveAfter( pos, id+1, upLeft );
579 } else if ( pick( w->pos() ) == pos ) {
580 //No need to do anything if it's already there.
581 return;
582 } else if ( s->isSplitter ) {
583 int dd = s->sizer;
584 if ( upLeft ) {
585 setG( w, pos, dd );
586 moveAfter( pos+dd, id+1, upLeft );
587 } else {
588 moveAfter( pos+dd, id+1, upLeft );
589 setG( w, pos, dd );
590 }
591 } else {
592 int right = pick( w->geometry().bottomRight() );
593
594 int dd = right - pos + 1;
595 dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize())));
596 int newRight = pos+dd-1;
597 setG( w, pos, dd );
598 moveAfter( newRight+1, id+1, upLeft );
599 }
600}
601
602
603/*!
604 Returns the valid range of the splitter with id \a id in \a min and \a max.
605
606 \sa idAfter()
607*/
608
609void QSplitter::getRange( int id, int *min, int *max )
610{
611 int minB = 0;//before
612 int maxB = 0;
613 int minA = 0;
614 int maxA = 0;//after
615 int n = data->list.count();
616 if ( id < 0 || id >= n )
617 return;
618 int i;
619 for ( i = 0; i < id; i++ ) {
620 QSplitterLayoutStruct *s = data->list.at(i);
621 if ( s->wid->isHidden() ) {
622 //ignore
623 } else if ( s->isSplitter ) {
624 minB += s->sizer;
625 maxB += s->sizer;
626 } else {
627 minB += pick( minSize(s->wid) );
628 maxB += pick( s->wid->maximumSize() );
629 }
630 }
631 for ( i = id; i < n; i++ ) {
632 QSplitterLayoutStruct *s = data->list.at(i);
633 if ( s->wid->isHidden() ) {
634 //ignore
635 } else if ( s->isSplitter ) {
636 minA += s->sizer;
637 maxA += s->sizer;
638 } else {
639 minA += pick( minSize(s->wid) );
640 maxA += pick( s->wid->maximumSize() );
641 }
642 }
643 QRect r = contentsRect();
644 if ( min )
645 *min = pick(r.topLeft()) + QMAX( minB, pick(r.size())-maxA );
646 if ( max )
647 *max = pick(r.topLeft()) + QMIN( maxB, pick(r.size())-minA );
648
649}
650
651
652/*!
653 Returns the legal position closest to \a p of the splitter with id \a id.
654
655 \sa idAfter()
656*/
657
658int QSplitter::adjustPos( int p, int id )
659{
660 int min = 0;
661 int max = 0;
662 getRange( id, &min, &max );
663 p = QMAX( min, QMIN( p, max ) );
664
665 return p;
666}
667
668
669void QSplitter::doResize()
670{
671 QRect r = contentsRect();
672 int i;
673 int n = data->list.count();
674 QArray<QLayoutStruct> a( n );
675 for ( i = 0; i< n; i++ ) {
676 a[i].init();
677 QSplitterLayoutStruct *s = data->list.at(i);
678 if ( s->wid->isHidden() ) {
679 a[i].stretch = 0;
680 a[i].sizeHint = a[i].minimumSize = 0;
681 a[i].maximumSize = 0;
682 } else if ( s->isSplitter ) {
683 a[i].stretch = 0;
684 a[i].sizeHint = a[i].minimumSize = a[i].maximumSize = s->sizer;
685 a[i].empty = FALSE;
686 } else if ( s->mode == KeepSize ) {
687 a[i].stretch = 0;
688 a[i].minimumSize = pick( minSize(s->wid) );
689 a[i].sizeHint = s->sizer;
690 a[i].maximumSize = pick( s->wid->maximumSize() );
691 a[i].empty = FALSE;
692 } else if ( s->mode == FollowSizeHint ) {
693 a[i].stretch = 0;
694 a[i].minimumSize = a[i].sizeHint = pick( s->wid->sizeHint() );
695 a[i].maximumSize = pick( s->wid->maximumSize() );
696 a[i].empty = FALSE;
697 } else { //proportional
698 a[i].stretch = s->sizer;
699 a[i].maximumSize = pick( s->wid->maximumSize() );
700 a[i].sizeHint = a[i].minimumSize = pick( minSize(s->wid) );
701 a[i].empty = FALSE;
702 }
703 }
704
705 qGeomCalc( a, 0, n, pick( r.topLeft() ), pick( r.size() ), 0 );
706 for ( i = 0; i< n; i++ ) {
707 QSplitterLayoutStruct *s = data->list.at(i);
708 if ( orient == Horizontal )
709 s->wid->setGeometry( a[i].pos, r.top(), a[i].size, r.height() );
710 else
711 s->wid->setGeometry( r.left(), a[i].pos, r.width(), a[i].size );
712 }
713
714}
715
716
717void QSplitter::recalc( bool update )
718{
719 int fi = 2*frameWidth();
720 int maxl = fi;
721 int minl = fi;
722 int maxt = QWIDGETSIZE_MAX;
723 int mint = fi;
724 int n = data->list.count();
725 bool first = TRUE;
726 /*
727 The splitter before a hidden widget is always hidden.
728 The splitter before the first visible widget is hidden.
729 The splitter before any other visible widget is visible.
730 */
731 for ( int i = 0; i< n; i++ ) {
732 QSplitterLayoutStruct *s = data->list.at(i);
733 if ( !s->isSplitter ) {
734 QSplitterLayoutStruct *p = (i > 0) ? p = data->list.at( i-1 ) : 0;
735 if ( p && p->isSplitter )
736 if ( first || s->wid->isHidden() )
737 p->wid->hide(); //may trigger new recalc
738 else
739 p->wid->show(); //may trigger new recalc
740 if ( !s->wid->isHidden() )
741 first = FALSE;
742 }
743 }
744
745 bool empty=TRUE;
746 for ( int j = 0; j< n; j++ ) {
747 QSplitterLayoutStruct *s = data->list.at(j);
748 if ( !s->wid->isHidden() ) {
749 empty = FALSE;
750 if ( s->isSplitter ) {
751 minl += s->sizer;
752 maxl += s->sizer;
753 } else {
754 QSize minS = minSize(s->wid);
755 minl += pick( minS );
756 maxl += pick( s->wid->maximumSize() );
757 mint = QMAX( mint, trans( minS ));
758 int tm = trans( s->wid->maximumSize() );
759 if ( tm > 0 )
760 maxt = QMIN( maxt, tm );
761 }
762 }
763 }
764 if ( empty )
765 maxl = maxt = 0;
766 else
767 maxl = QMIN( maxl, QWIDGETSIZE_MAX );
768 if ( maxt < mint )
769 maxt = mint;
770
771 if ( orient == Horizontal ) {
772 setMaximumSize( maxl, maxt );
773 setMinimumSize( minl, mint );
774 } else {
775 setMaximumSize( maxt, maxl );
776 setMinimumSize( mint, minl );
777 }
778 if ( update )
779 doResize();
780}
781
782/*! \enum QSplitter::ResizeMode
783
784 This enum type describes how QSplitter will resize each of its child widgets. The currently defined values are: <ul>
785
786 <li> \c Stretch - the widget will be resized when the splitter
787 itself is resized.
788
789 <li> \c KeepSize - QSplitter will try to keep this widget's size
790 unchanged.
791
792 <li> \c FollowSizeHint - QSplitter will resize the widget when its
793 size hint changes.
794
795 </ul>
796
797*/
798
799/*!
800 Sets resize mode of \a w to \a mode.
801
802 \sa ResizeMode
803*/
804
805void QSplitter::setResizeMode( QWidget *w, ResizeMode mode )
806{
807 processChildEvents();
808 QSplitterLayoutStruct *s = data->list.first();
809 while ( s ) {
810 if ( s->wid == w ) {
811 s->mode = mode;
812 return;
813 }
814 s = data->list.next();
815 }
816 s = addWidget( w, TRUE );
817 s->mode = mode;
818}
819
820
821/*!
822 Returns TRUE if opaque resize is on, FALSE otherwise.
823
824 \sa setOpaqueResize()
825*/
826
827bool QSplitter::opaqueResize() const
828{
829 return data->opaque;
830}
831
832
833/*!
834 Sets opaque resize to \a on. Opaque resize is initially turned off.
835
836 \sa opaqueResize()
837*/
838
839void QSplitter::setOpaqueResize( bool on )
840{
841 data->opaque = on;
842}
843
844
845/*!
846 Moves \a w to the leftmost/top position.
847*/
848
849void QSplitter::moveToFirst( QWidget *w )
850{
851 processChildEvents();
852 bool found = FALSE;
853 QSplitterLayoutStruct *s = data->list.first();
854 while ( s ) {
855 if ( s->wid == w ) {
856 found = TRUE;
857 QSplitterLayoutStruct *p = data->list.prev();
858 if ( p ) { // not already at first place
859 data->list.take(); //take p
860 data->list.take(); // take s
861 data->list.insert( 0, p );
862 data->list.insert( 0, s );
863 }
864 break;
865 }
866 s = data->list.next();
867 }
868 if ( !found )
869 addWidget( w, TRUE );
870 recalcId();
871}
872
873
874/*!
875 Moves \a w to the rightmost/bottom position.
876*/
877
878void QSplitter::moveToLast( QWidget *w )
879{
880 processChildEvents();
881 bool found = FALSE;
882 QSplitterLayoutStruct *s = data->list.first();
883 while ( s ) {
884 if ( s->wid == w ) {
885 found = TRUE;
886 data->list.take(); // take s
887 QSplitterLayoutStruct *p = data->list.current();
888 if ( p ) { // the splitter handle after s
889 data->list.take(); //take p
890 data->list.append( p );
891 }
892 data->list.append( s );
893 break;
894 }
895 s = data->list.next();
896 }
897 if ( !found )
898 addWidget( w);
899 recalcId();
900}
901
902
903void QSplitter::recalcId()
904{
905 int n = data->list.count();
906 for ( int i = 0; i < n; i++ ) {
907 QSplitterLayoutStruct *s = data->list.at(i);
908 if ( s->isSplitter )
909 ((QSplitterHandle*)s->wid)->setId(i);
910 }
911}
912
913
914/*!\reimp
915*/
916QSize QSplitter::sizeHint() const
917{
918 constPolish();
919 int l = 0;
920 int t = 0;
921 if ( children() ) {
922 const QObjectList * c = children();
923 QObjectListIt it( *c );
924 QObject * o;
925
926 while( (o=it.current()) != 0 ) {
927 ++it;
928 if ( o->isWidgetType() &&
929 !((QWidget*)o)->isHidden() ) {
930 QSize s = ((QWidget*)o)->sizeHint();
931 if ( s.isValid() ) {
932 l += pick( s );
933 t = QMAX( t, trans( s ) );
934 }
935 }
936 }
937 }
938 return orientation() == Horizontal ? QSize( l, t ) : QSize( t, l );
939}
940
941
942/*!
943\reimp
944*/
945
946QSize QSplitter::minimumSizeHint() const
947{
948 constPolish();
949 int l = 0;
950 int t = 0;
951 if ( children() ) {
952 const QObjectList * c = children();
953 QObjectListIt it( *c );
954 QObject * o;
955
956 while( (o=it.current()) != 0 ) {
957 ++it;
958 if ( o->isWidgetType() &&
959 !((QWidget*)o)->isHidden() ) {
960 QSize s = minSize((QWidget*)o);
961 if ( s.isValid() ) {
962 l += pick( s );
963 t = QMAX( t, trans( s ) );
964 }
965 }
966 }
967 }
968 return orientation() == Horizontal ? QSize( l, t ) : QSize( t, l );
969}
970
971
972
973/*!\reimp
974*/
975QSizePolicy QSplitter::sizePolicy() const
976{
977 return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
978}
979
980
981/*!
982 Calculates stretch parameters from current sizes
983*/
984
985void QSplitter::storeSizes()
986{
987 QSplitterLayoutStruct *s = data->list.first();
988 while ( s ) {
989 if ( !s->isSplitter )
990 s->sizer = pick( s->wid->size() );
991 s = data->list.next();
992 }
993}
994
995
996#if 0 // ### remove this code ASAP
997
998/*!
999 Hides \a w if \a hide is TRUE, and updates the splitter.
1000
1001 \warning Due to a limitation in the current implementation,
1002 calling QWidget::hide() will not work.
1003*/
1004
1005void QSplitter::setHidden( QWidget *w, bool hide )
1006{
1007 if ( w == w1 ) {
1008 w1show = !hide;
1009 } else if ( w == w2 ) {
1010 w2show = !hide;
1011 } else {
1012#ifdef CHECK_RANGE
1013 qWarning( "QSplitter::setHidden(), unknown widget" );
1014#endif
1015 return;
1016 }
1017 if ( hide )
1018 w->hide();
1019 else
1020 w->show();
1021 recalc( TRUE );
1022}
1023
1024
1025/*!
1026 Returns the hidden status of \a w
1027*/
1028
1029bool QSplitter::isHidden( QWidget *w ) const
1030{
1031 if ( w == w1 )
1032 return !w1show;
1033 else if ( w == w2 )
1034 return !w2show;
1035#ifdef CHECK_RANGE
1036 else
1037 qWarning( "QSplitter::isHidden(), unknown widget" );
1038#endif
1039 return FALSE;
1040}
1041#endif
1042
1043
1044/*!
1045 Returns a list of the size parameters of all the widgets in this
1046 splitter.
1047
1048 Giving the values to setSizes() will give a splitter with the same
1049 layout as this one.
1050
1051 \sa setSizes()
1052*/
1053
1054QValueList<int> QSplitter::sizes() const
1055{
1056 if ( !testWState(WState_Polished) ) {
1057 QWidget* that = (QWidget*) this;
1058 that->polish();
1059 }
1060 QValueList<int> list;
1061 QSplitterLayoutStruct *s = data->list.first();
1062 while ( s ) {
1063 if ( !s->isSplitter )
1064 list.append( s->sizer );
1065 s = data->list.next();
1066 }
1067 return list;
1068}
1069
1070
1071
1072/*!
1073 Sets the size parameters to the values given in \a list.
1074 If the splitter is horizontal, the values set the sizes from
1075 left to right. If it is vertical, the sizes are applied from
1076 top to bottom.
1077 Extra values in \a list are ignored.
1078
1079 If \a list contains too few values, the result is undefined
1080 but the program will still be well-behaved.
1081
1082 \sa sizes()
1083*/
1084
1085void QSplitter::setSizes( QValueList<int> list )
1086{
1087 processChildEvents();
1088 QValueList<int>::Iterator it = list.begin();
1089 QSplitterLayoutStruct *s = data->list.first();
1090 while ( s && it != list.end() ) {
1091 if ( !s->isSplitter ) {
1092 s->sizer = *it;
1093 ++it;
1094 }
1095 s = data->list.next();
1096 }
1097 doResize();
1098}
1099
1100
1101/*!
1102 Gets all posted child events, ensuring that the internal state of
1103 the splitter is consistent with the programmer's idea.
1104*/
1105
1106void QSplitter::processChildEvents()
1107{
1108 QApplication::sendPostedEvents( this, QEvent::ChildInserted );
1109}
1110
1111
1112/*!
1113 \reimp
1114*/
1115
1116void QSplitter::styleChange( QStyle& old )
1117{
1118 int sw = style().splitterWidth();
1119 QSplitterLayoutStruct *s = data->list.first();
1120 while ( s ) {
1121 if ( s->isSplitter )
1122 s->sizer = sw;
1123 s = data->list.next();
1124 }
1125 doResize();
1126 QFrame::styleChange( old );
1127}
1128
diff --git a/libqtaux/qsplitter.h b/libqtaux/qsplitter.h
new file mode 100644
index 0000000..8625c4d
--- a/dev/null
+++ b/libqtaux/qsplitter.h
@@ -0,0 +1,128 @@
1/****************************************************************************
2** $Id$
3**
4** Defintion of QSplitter class
5**
6** Created: 980105
7**
8** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
9**
10** This file is part of the widgets module of the Qt GUI Toolkit.
11**
12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file.
15**
16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file.
20**
21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22** licenses may use this file in accordance with the Qt Commercial License
23** Agreement provided with the Software.
24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32**
33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you.
35**
36**********************************************************************/
37#ifndef QSPLITTER_H
38#define QSPLITTER_H
39
40#ifndef QT_H
41#include "qframe.h"
42#include "qvaluelist.h"
43#endif // QT_H
44
45class QSplitterHandle;
46class QSplitterData;
47class QSplitterLayoutStruct;
48
49class Q_EXPORT QSplitter : public QFrame
50{
51 Q_OBJECT
52 Q_PROPERTY( Orientation orientation READ orientation WRITE setOrientation )
53
54public:
55 enum ResizeMode { Stretch, KeepSize, FollowSizeHint };
56
57 QSplitter( QWidget *parent=0, const char *name=0 );
58 QSplitter( Orientation, QWidget *parent=0, const char *name=0 );
59 ~QSplitter();
60
61 virtual void setOrientation( Orientation );
62 Orientation orientation() const { return orient; }
63
64 virtual void setResizeMode( QWidget *w, ResizeMode );
65 virtual void setOpaqueResize( bool = TRUE );
66 bool opaqueResize() const;
67
68 void moveToFirst( QWidget * );
69 void moveToLast( QWidget * );
70
71 void refresh() { recalc( TRUE ); }
72 QSize sizeHint() const;
73 QSize minimumSizeHint() const;
74 QSizePolicy sizePolicy() const;
75
76 QValueList<int> sizes() const;
77 void setSizes( QValueList<int> );
78
79protected:
80 void childEvent( QChildEvent * );
81
82 bool event( QEvent * );
83 void resizeEvent( QResizeEvent * );
84
85 int idAfter( QWidget* ) const;
86
87 void moveSplitter( QCOORD pos, int id );
88 virtual void drawSplitter( QPainter*, QCOORD x, QCOORD y,
89 QCOORD w, QCOORD h );
90 void styleChange( QStyle& );
91 int adjustPos( int , int );
92 virtual void setRubberband( int );
93 void getRange( int id, int*, int* );
94
95private:
96 void init();
97 void recalc( bool update = FALSE );
98 void doResize();
99 void storeSizes();
100 void processChildEvents();
101 QSplitterLayoutStruct *addWidget( QWidget*, bool first = FALSE );
102 void recalcId();
103 void moveBefore( int pos, int id, bool upLeft );
104 void moveAfter( int pos, int id, bool upLeft );
105 void setG( QWidget *w, int p, int s );
106
107 QCOORD pick( const QPoint &p ) const
108 { return orient == Horizontal ? p.x() : p.y(); }
109 QCOORD pick( const QSize &s ) const
110 { return orient == Horizontal ? s.width() : s.height(); }
111
112 QCOORD trans( const QPoint &p ) const
113 { return orient == Vertical ? p.x() : p.y(); }
114 QCOORD trans( const QSize &s ) const
115 { return orient == Vertical ? s.width() : s.height(); }
116
117 QSplitterData *data;
118
119 Orientation orient;
120 friend class QSplitterHandle;
121 private:// Disabled copy constructor and operator=
122#if defined(Q_DISABLE_COPY)
123 QSplitter( const QSplitter & );
124 QSplitter& operator=( const QSplitter & );
125#endif
126};
127
128#endif // QSPLITTER_H