3 Copyright (C) 2001 The Kompany
4 2002-2003 Ilya Konstantinov <kde-devel@future.shiny.co.il>
5 2002-2003 Marcus Meissner <marcus@jet.franken.de>
6 2003 Nadeem Hasan <nhasan@nadmm.com>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 #include <qcheckbox.h>
28 #include <qradiobutton.h>
29 #include <qlineedit.h>
30 #include <qcombobox.h>
32 #include <Q3ButtonGroup>
35 #include <qtabwidget.h>
39 #include <QVBoxLayout>
43 #include "kameraconfigdialog.h"
44 #include "kameraconfigdialog.moc"
46 KameraConfigDialog::KameraConfigDialog(Camera */
*camera*/
,
53 setButtons( Ok
|Cancel
);
54 setDefaultButton( Ok
);
57 QFrame
*main
= new QFrame( this );
58 setMainWidget( main
);
59 QVBoxLayout
*topLayout
= new QVBoxLayout(main
);
60 topLayout
->setSpacing(spacingHint());
61 topLayout
->setMargin(0);
65 appendWidget(main
, widget
);
66 connect(this,SIGNAL(okClicked()),this,SLOT(slotOk()));
69 void KameraConfigDialog::appendWidget(QWidget
*parent
, CameraWidget
*widget
)
71 QWidget
*newParent
= parent
;
73 CameraWidgetType widget_type
;
74 const char *widget_name
;
75 const char *widget_info
;
76 const char *widget_label
;
77 float widget_value_float
;
79 const char *widget_value_string
;
80 gp_widget_get_type(widget
, &widget_type
);
81 gp_widget_get_label(widget
, &widget_label
);
82 gp_widget_get_info(widget
, &widget_info
);
83 gp_widget_get_name(widget
, &widget_name
);
85 QString whats_this
= QString::fromLocal8Bit(widget_info
); // gphoto2 doesn't seem to have any standard for i18n
87 // Add this widget to parent
89 case GP_WIDGET_WINDOW
:
91 setCaption(widget_label
);
95 case GP_WIDGET_SECTION
:
98 m_tabWidget
= new QTabWidget(parent
);
99 parent
->layout()->addWidget(m_tabWidget
);
101 QWidget
*tab
= new QWidget(m_tabWidget
);
102 // widgets are to be aligned vertically in the tab
103 QVBoxLayout
*tabLayout
= new QVBoxLayout(tab
, marginHint(),
105 m_tabWidget
->insertTab(tab
, widget_label
);
106 KVBox
*tabContainer
= new KVBox(tab
);
107 tabContainer
->setSpacing(spacingHint());
108 tabLayout
->addWidget(tabContainer
);
109 newParent
= tabContainer
;
111 tabLayout
->addStretch();
117 gp_widget_get_value(widget
, &widget_value_string
);
119 Q3Grid
*grid
= new Q3Grid(2, Qt::Horizontal
, parent
);
120 parent
->layout()->addWidget(grid
);
121 grid
->setSpacing(spacingHint());
122 new QLabel(QString::fromLocal8Bit( widget_label
)+':', grid
);
123 QLineEdit
*lineEdit
= new QLineEdit(widget_value_string
, grid
);
124 m_wmap
.insert(widget
, lineEdit
);
126 if (!whats_this
.isEmpty())
127 grid
->setWhatsThis( whats_this
);
131 case GP_WIDGET_RANGE
:
135 float widget_increment
;
136 gp_widget_get_range(widget
, &widget_low
, &widget_high
, &widget_increment
);
137 gp_widget_get_value(widget
, &widget_value_float
);
139 Q3GroupBox
*groupBox
= new Q3GroupBox(1, Qt::Horizontal
,widget_label
, parent
);
140 parent
->layout()->addWidget(groupBox
);
141 QSlider
*slider
= new QSlider(
144 ( int )widget_increment
,
145 ( int )widget_value_float
,
148 m_wmap
.insert(widget
, slider
);
150 if (!whats_this
.isEmpty())
151 groupBox
->setWhatsThis( whats_this
);
155 case GP_WIDGET_TOGGLE
:
157 gp_widget_get_value(widget
, &widget_value_int
);
159 QCheckBox
*checkBox
= new QCheckBox(widget_label
, parent
);
160 parent
->layout()->addWidget(checkBox
);
161 checkBox
->setChecked(widget_value_int
);
162 m_wmap
.insert(widget
, checkBox
);
164 if (!whats_this
.isEmpty())
165 checkBox
->setWhatsThis( whats_this
);
169 case GP_WIDGET_RADIO
:
171 gp_widget_get_value(widget
, &widget_value_string
);
173 int count
= gp_widget_count_choices(widget
);
175 // for less than 5 options, align them horizontally
176 Q3ButtonGroup
*buttonGroup
;
178 buttonGroup
= new Q3VButtonGroup(widget_label
, parent
);
180 buttonGroup
= new Q3HButtonGroup(widget_label
, parent
);
181 parent
->layout()->addWidget(buttonGroup
);
183 for(int i
= 0; i
< count
; ++i
) {
184 const char *widget_choice
;
185 gp_widget_get_choice(widget
, i
, &widget_choice
);
187 new QRadioButton(widget_choice
, buttonGroup
);
188 if(!strcmp(widget_value_string
, widget_choice
))
189 buttonGroup
->setButton(i
);
191 m_wmap
.insert(widget
, buttonGroup
);
193 if (!whats_this
.isEmpty())
194 buttonGroup
->setWhatsThis( whats_this
);
200 gp_widget_get_value(widget
, &widget_value_string
);
202 QComboBox
*comboBox
= new QComboBox(parent
);
203 parent
->layout()->addWidget(comboBox
);
205 for(int i
= 0; i
< gp_widget_count_choices(widget
); ++i
) {
206 const char *widget_choice
;
207 gp_widget_get_choice(widget
, i
, &widget_choice
);
209 comboBox
->insertItem(widget_choice
);
210 if(!strcmp(widget_value_string
, widget_choice
))
211 comboBox
->setCurrentItem(i
);
213 m_wmap
.insert(widget
, comboBox
);
215 if (!whats_this
.isEmpty())
216 comboBox
->setWhatsThis( whats_this
);
220 case GP_WIDGET_BUTTON
:
223 // I can't see a way of implementing this. Since there is
224 // no way of telling which button sent you a signal, we
225 // can't map to the appropriate widget->callback
226 QLabel
*label
= new QLabel(i18n("Button (not supported by KControl)"), parent
);
227 parent
->layout()->addWidget(label
);
234 QLabel
* label
= new QLabel(i18n("Date (not supported by KControl)"), parent
);
235 parent
->layout()->addWidget(label
);
243 // Append all this widgets children
244 for(int i
= 0; i
< gp_widget_count_children(widget
); ++i
) {
245 CameraWidget
*widget_child
;
246 gp_widget_get_child(widget
, i
, &widget_child
);
247 appendWidget(newParent
, widget_child
);
250 // Things that must be done after all children were added
252 switch (widget_type) {
253 case GP_WIDGET_SECTION:
255 tabLayout->addItem( new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding) );
262 void KameraConfigDialog::updateWidgetValue(CameraWidget
*widget
)
264 CameraWidgetType widget_type
;
265 gp_widget_get_type(widget
, &widget_type
);
267 switch(widget_type
) {
268 case GP_WIDGET_WINDOW
:
271 case GP_WIDGET_SECTION
:
276 QLineEdit
*lineEdit
= static_cast<QLineEdit
*>(m_wmap
[widget
]);
277 gp_widget_set_value(widget
, (void *)lineEdit
->text().toLocal8Bit().data());
281 case GP_WIDGET_RANGE
:
283 QSlider
*slider
= static_cast<QSlider
*>(m_wmap
[widget
]);
284 float value_float
= slider
->value();
285 gp_widget_set_value(widget
, (void *)&value_float
);
289 case GP_WIDGET_TOGGLE
:
291 QCheckBox
*checkBox
= static_cast<QCheckBox
*>(m_wmap
[widget
]);
292 int value_int
= checkBox
->isChecked() ? 1 : 0;
293 gp_widget_set_value(widget
, (void *)&value_int
);
297 case GP_WIDGET_RADIO
:
299 Q3ButtonGroup
*buttonGroup
= static_cast<Q3VButtonGroup
*>(m_wmap
[widget
]);
300 gp_widget_set_value(widget
, (void *)buttonGroup
->selected()->text().toLocal8Bit().data());
306 QComboBox
*comboBox
= static_cast<QComboBox
*>(m_wmap
[widget
]);
307 gp_widget_set_value(widget
, (void *)comboBox
->currentText().toLocal8Bit().data());
311 case GP_WIDGET_BUTTON
:
321 // Copy child widget values
322 for(int i
= 0; i
< gp_widget_count_children(widget
); ++i
) {
323 CameraWidget
*widget_child
;
324 gp_widget_get_child(widget
, i
, &widget_child
);
325 updateWidgetValue(widget_child
);
329 void KameraConfigDialog::slotOk()
331 // Copy Qt widget values into CameraWidget hierarchy
332 updateWidgetValue(m_widgetRoot
);