1 | /**********************************************************************
|
---|
2 | ** Copyright (C) 2005-2007 Trolltech ASA. All rights reserved.
|
---|
3 | **
|
---|
4 | ** This file is part of Qt Designer.
|
---|
5 | **
|
---|
6 | ** This file may be distributed and/or modified under the terms of the
|
---|
7 | ** GNU General Public License version 2 as published by the Free Software
|
---|
8 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
9 | ** packaging of this file.
|
---|
10 | **
|
---|
11 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
|
---|
12 | ** licenses may use this file in accordance with the Qt Commercial License
|
---|
13 | ** Agreement provided with the Software.
|
---|
14 | **
|
---|
15 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
---|
16 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
---|
17 | **
|
---|
18 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
---|
19 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
---|
20 | ** information about Qt Commercial License Agreements.
|
---|
21 | **
|
---|
22 | ** Contact info@trolltech.com if any conditions of this licensing are
|
---|
23 | ** not clear to you.
|
---|
24 | **
|
---|
25 | **********************************************************************/
|
---|
26 |
|
---|
27 | #include "arghintwidget.h"
|
---|
28 | #include <qbutton.h>
|
---|
29 | #include <qlabel.h>
|
---|
30 | #include <qlayout.h>
|
---|
31 | #include <qpainter.h>
|
---|
32 | #include <qpixmap.h>
|
---|
33 |
|
---|
34 | static const char * left_xpm[] = {
|
---|
35 | "16 16 3 1",
|
---|
36 | " c None",
|
---|
37 | ". c #FFFFFF",
|
---|
38 | "+ c #000000",
|
---|
39 | " ",
|
---|
40 | " ",
|
---|
41 | " + ",
|
---|
42 | " ++ ",
|
---|
43 | " +++ ",
|
---|
44 | " ++++ ",
|
---|
45 | " +++++ ",
|
---|
46 | " ++++++ ",
|
---|
47 | " ++++++ ",
|
---|
48 | " +++++ ",
|
---|
49 | " ++++ ",
|
---|
50 | " +++ ",
|
---|
51 | " ++ ",
|
---|
52 | " + ",
|
---|
53 | " ",
|
---|
54 | " "};
|
---|
55 |
|
---|
56 | static const char * right_xpm[] = {
|
---|
57 | "16 16 3 1",
|
---|
58 | " c None",
|
---|
59 | ". c #FFFFFF",
|
---|
60 | "+ c #000000",
|
---|
61 | " ",
|
---|
62 | " ",
|
---|
63 | " + ",
|
---|
64 | " ++ ",
|
---|
65 | " +++ ",
|
---|
66 | " ++++ ",
|
---|
67 | " +++++ ",
|
---|
68 | " ++++++ ",
|
---|
69 | " ++++++ ",
|
---|
70 | " +++++ ",
|
---|
71 | " ++++ ",
|
---|
72 | " +++ ",
|
---|
73 | " ++ ",
|
---|
74 | " + ",
|
---|
75 | " ",
|
---|
76 | " "};
|
---|
77 |
|
---|
78 | static const char * left_disabled_xpm[] = {
|
---|
79 | "16 16 3 1",
|
---|
80 | " c None",
|
---|
81 | ". c #FFFFFF",
|
---|
82 | "+ c darkgray",
|
---|
83 | " ",
|
---|
84 | " ",
|
---|
85 | " + ",
|
---|
86 | " ++ ",
|
---|
87 | " +++ ",
|
---|
88 | " ++++ ",
|
---|
89 | " +++++ ",
|
---|
90 | " ++++++ ",
|
---|
91 | " ++++++ ",
|
---|
92 | " +++++ ",
|
---|
93 | " ++++ ",
|
---|
94 | " +++ ",
|
---|
95 | " ++ ",
|
---|
96 | " + ",
|
---|
97 | " ",
|
---|
98 | " "};
|
---|
99 |
|
---|
100 | static const char * right_disabled_xpm[] = {
|
---|
101 | "16 16 3 1",
|
---|
102 | " c None",
|
---|
103 | ". c #FFFFFF",
|
---|
104 | "+ c darkgray",
|
---|
105 | " ",
|
---|
106 | " ",
|
---|
107 | " + ",
|
---|
108 | " ++ ",
|
---|
109 | " +++ ",
|
---|
110 | " ++++ ",
|
---|
111 | " +++++ ",
|
---|
112 | " ++++++ ",
|
---|
113 | " ++++++ ",
|
---|
114 | " +++++ ",
|
---|
115 | " ++++ ",
|
---|
116 | " +++ ",
|
---|
117 | " ++ ",
|
---|
118 | " + ",
|
---|
119 | " ",
|
---|
120 | " "};
|
---|
121 |
|
---|
122 | class ArrowButton : public QButton
|
---|
123 | {
|
---|
124 | Q_OBJECT
|
---|
125 |
|
---|
126 | public:
|
---|
127 | enum Dir { Left, Right };
|
---|
128 |
|
---|
129 | ArrowButton( QWidget *parent, const char *name, Dir d );
|
---|
130 | void drawButton( QPainter *p );
|
---|
131 |
|
---|
132 | private:
|
---|
133 | QPixmap pix, pix_disabled;
|
---|
134 |
|
---|
135 | };
|
---|
136 |
|
---|
137 | ArrowButton::ArrowButton( QWidget *parent, const char *name, Dir d )
|
---|
138 | : QButton( parent, name )
|
---|
139 | {
|
---|
140 | setFixedSize( 16, 16 );
|
---|
141 | if ( d == Left ) {
|
---|
142 | pix = QPixmap( left_xpm );
|
---|
143 | pix_disabled = QPixmap( left_disabled_xpm );
|
---|
144 | } else {
|
---|
145 | pix = QPixmap( right_xpm );
|
---|
146 | pix_disabled = QPixmap( right_disabled_xpm );
|
---|
147 | }
|
---|
148 | }
|
---|
149 |
|
---|
150 | void ArrowButton::drawButton( QPainter *p )
|
---|
151 | {
|
---|
152 | if ( isDown() )
|
---|
153 | p->fillRect( 0, 0, width(), height(), darkGray );
|
---|
154 | else
|
---|
155 | p->fillRect( 0, 0, width(), height(), lightGray );
|
---|
156 | if ( isEnabled() )
|
---|
157 | p->drawPixmap( 0, 0, pix );
|
---|
158 | else
|
---|
159 | p->drawPixmap( 0, 0, pix_disabled );
|
---|
160 | }
|
---|
161 |
|
---|
162 |
|
---|
163 | ArgHintWidget::ArgHintWidget( QWidget *parent, const char*name )
|
---|
164 | : QFrame( parent, name, WType_Popup ), curFunc( 0 ), numFuncs( 0 )
|
---|
165 | {
|
---|
166 | setFrameStyle( QFrame::Box | QFrame::Plain );
|
---|
167 | setLineWidth( 1 );
|
---|
168 | setBackgroundColor( white );
|
---|
169 | QHBoxLayout *hbox = new QHBoxLayout( this );
|
---|
170 | hbox->setMargin( 1 );
|
---|
171 | hbox->addWidget( ( prev = new ArrowButton( this, "editor_left_btn", ArrowButton::Left ) ) );
|
---|
172 | hbox->addWidget( ( funcLabel = new QLabel( this, "editor_func_lbl" ) ) );
|
---|
173 | hbox->addWidget( ( next = new ArrowButton( this, "editor_right_btn", ArrowButton::Right ) ) );
|
---|
174 | funcLabel->setBackgroundColor( white );
|
---|
175 | funcLabel->setAlignment( AlignCenter );
|
---|
176 | connect( prev, SIGNAL( clicked() ), this, SLOT( gotoPrev() ) );
|
---|
177 | connect( next, SIGNAL( clicked() ), this, SLOT( gotoNext() ) );
|
---|
178 | updateState();
|
---|
179 | setFocusPolicy( NoFocus );
|
---|
180 | prev->setFocusPolicy( NoFocus );
|
---|
181 | next->setFocusPolicy( NoFocus );
|
---|
182 | funcLabel->setFocusPolicy( NoFocus );
|
---|
183 | }
|
---|
184 |
|
---|
185 | void ArgHintWidget::setFunctionText( int func, const QString &text )
|
---|
186 | {
|
---|
187 | funcs.replace( func, text );
|
---|
188 | if ( func == curFunc ) {
|
---|
189 | funcLabel->clear();
|
---|
190 | funcLabel->setText( text );
|
---|
191 | }
|
---|
192 | }
|
---|
193 |
|
---|
194 | void ArgHintWidget::setNumFunctions( int num )
|
---|
195 | {
|
---|
196 | funcs.clear();
|
---|
197 | numFuncs = num;
|
---|
198 | curFunc = 0;
|
---|
199 | updateState();
|
---|
200 | }
|
---|
201 |
|
---|
202 | void ArgHintWidget::gotoPrev()
|
---|
203 | {
|
---|
204 | if ( curFunc > 0 ) {
|
---|
205 | curFunc--;
|
---|
206 | funcLabel->setText( funcs[ curFunc ] );
|
---|
207 | updateState();
|
---|
208 | }
|
---|
209 | }
|
---|
210 |
|
---|
211 | void ArgHintWidget::gotoNext()
|
---|
212 | {
|
---|
213 | if ( curFunc < numFuncs - 1 ) {
|
---|
214 | curFunc++;
|
---|
215 | funcLabel->setText( funcs[ curFunc ] );
|
---|
216 | updateState();
|
---|
217 | }
|
---|
218 | }
|
---|
219 |
|
---|
220 | void ArgHintWidget::updateState()
|
---|
221 | {
|
---|
222 | prev->setEnabled( curFunc > 0 );
|
---|
223 | next->setEnabled( curFunc < numFuncs - 1 );
|
---|
224 | }
|
---|
225 |
|
---|
226 | void ArgHintWidget::relayout()
|
---|
227 | {
|
---|
228 | funcLabel->setText( "" );
|
---|
229 | funcLabel->setText( funcs[ curFunc ] );
|
---|
230 | }
|
---|
231 |
|
---|
232 | #include "arghintwidget.moc"
|
---|