20 #include "droptionview.h"
22 #include "driveritem.h"
25 #include <tqlineedit.h>
28 #include <tdelistbox.h>
29 #include <tqvbuttongroup.h>
30 #include <tqradiobutton.h>
31 #include <tqwidgetstack.h>
33 #include <tqapplication.h>
37 #include <tdelocale.h>
39 OptionBaseView::OptionBaseView(TQWidget *parent,
const char *name)
40 : TQWidget(parent,name)
45 void OptionBaseView::setOption(DrBase*)
49 void OptionBaseView::setValue(
const TQString&)
55 OptionNumericView::OptionNumericView(TQWidget *parent,
const char *name)
56 : OptionBaseView(parent,name)
58 m_edit =
new TQLineEdit(
this);
59 m_slider =
new TQSlider(TQt::Horizontal,
this);
60 m_slider->setTickmarks(TQSlider::Below);
61 TQLabel *lab =
new TQLabel(i18n(
"Value:"),
this);
62 m_minval =
new TQLabel(
this);
63 m_maxval =
new TQLabel(
this);
67 TQVBoxLayout *main_ =
new TQVBoxLayout(
this, 0, 10);
68 TQHBoxLayout *sub_ =
new TQHBoxLayout(0, 0, 10);
69 TQHBoxLayout *sub2_ =
new TQHBoxLayout(0, 0, 5);
71 main_->addLayout(sub_,0);
72 main_->addLayout(sub2_,0);
74 sub_->addWidget(lab,0);
75 sub_->addWidget(m_edit,0);
77 sub2_->addWidget(m_minval,0);
78 sub2_->addWidget(m_slider,1);
79 sub2_->addWidget(m_maxval,0);
81 connect(m_slider,TQ_SIGNAL(valueChanged(
int)),TQ_SLOT(slotSliderChanged(
int)));
82 connect(m_edit,TQ_SIGNAL(textChanged(
const TQString&)),TQ_SLOT(slotEditChanged(
const TQString&)));
85 void OptionNumericView::setOption(DrBase *opt)
87 if (opt->type() != DrBase::Integer && opt->type() != DrBase::Float)
91 if (opt->type() == DrBase::Integer)
94 int min_ = opt->get(
"minval").toInt();
95 int max_ = opt->get(
"maxval").toInt();
96 m_slider->setRange(min_,max_);
97 m_slider->setSteps(1,TQMAX((max_-min_)/20,1));
98 m_minval->setText(TQString::number(min_));
99 m_maxval->setText(TQString::number(max_));
104 int min_ = (int)rint(opt->get(
"minval").toFloat()*1000);
105 int max_ = (int)rint(opt->get(
"maxval").toFloat()*1000);
106 m_slider->setRange(min_,max_);
107 m_slider->setSteps(1,TQMAX((max_-min_)/20,1));
108 m_minval->setText(opt->get(
"minval"));
109 m_maxval->setText(opt->get(
"maxval"));
114 setValue(opt->valueText());
117 void OptionNumericView::setValue(
const TQString& val)
119 m_edit->setText(val);
122 void OptionNumericView::slotSliderChanged(
int value)
128 txt = TQString::number(value);
130 txt = TQString::number(
float(value)/1000.0,
'f',3);
132 m_edit->setText(txt);
134 emit valueChanged(txt);
137 void OptionNumericView::slotEditChanged(
const TQString& txt)
144 val = txt.toInt(&ok);
146 val = (int)rint(txt.toFloat(&ok)*1000);
150 m_slider->setValue(val);
152 emit valueChanged(txt);
157 TQApplication::beep();
163 OptionStringView::OptionStringView(TQWidget *parent,
const char *name)
164 : OptionBaseView(parent,name)
166 m_edit =
new TQLineEdit(
this);
167 TQLabel *lab =
new TQLabel(i18n(
"String value:"),
this);
169 TQVBoxLayout *main_ =
new TQVBoxLayout(
this, 0, 5);
170 main_->addStretch(1);
171 main_->addWidget(lab,0);
172 main_->addWidget(m_edit,0);
173 main_->addStretch(1);
175 connect(m_edit,TQ_SIGNAL(textChanged(
const TQString&)),TQ_SIGNAL(valueChanged(
const TQString&)));
178 void OptionStringView::setOption(DrBase *opt)
180 if (opt->type() == DrBase::String)
181 m_edit->setText(opt->valueText());
184 void OptionStringView::setValue(
const TQString& val)
186 m_edit->setText(val);
191 OptionListView::OptionListView(TQWidget *parent,
const char *name)
192 : OptionBaseView(parent,name)
194 m_list =
new TDEListBox(
this);
196 TQVBoxLayout *main_ =
new TQVBoxLayout(
this, 0, 10);
197 main_->addWidget(m_list);
199 connect(m_list,TQ_SIGNAL(selectionChanged()),TQ_SLOT(slotSelectionChanged()));
202 void OptionListView::setOption(DrBase *opt)
204 if (opt->type() == DrBase::List)
209 TQPtrListIterator<DrBase> it(*(((DrListOption*)opt)->choices()));
210 for (;it.current();++it)
212 m_list->insertItem(it.current()->get(
"text"));
213 m_choices.append(it.current()->name());
216 setValue(opt->valueText());
220 void OptionListView::setValue(
const TQString& val)
222 m_list->setCurrentItem(m_choices.findIndex(val));
225 void OptionListView::slotSelectionChanged()
229 TQString s = m_choices[m_list->currentItem()];
230 emit valueChanged(s);
235 OptionBooleanView::OptionBooleanView(TQWidget *parent,
const char *name)
236 : OptionBaseView(parent,name)
238 m_group =
new TQVButtonGroup(
this);
239 m_group->setFrameStyle(TQFrame::NoFrame);
241 TQRadioButton *btn =
new TQRadioButton(m_group);
242 btn->setCursor(KCursor::handCursor());
243 btn =
new TQRadioButton(m_group);
244 btn->setCursor(KCursor::handCursor());
246 TQVBoxLayout *main_ =
new TQVBoxLayout(
this, 0, 10);
247 main_->addWidget(m_group);
249 connect(m_group,TQ_SIGNAL(clicked(
int)),TQ_SLOT(slotSelected(
int)));
252 void OptionBooleanView::setOption(DrBase *opt)
254 if (opt->type() == DrBase::Boolean)
256 TQPtrListIterator<DrBase> it(*(((DrBooleanOption*)opt)->choices()));
258 static_cast<TQButton*
>(m_group->find(0))->setText(it.toFirst()->get(
"text"));
259 m_choices.append(it.toFirst()->name());
260 static_cast<TQButton*
>(m_group->find(1))->setText(it.toLast()->get(
"text"));
261 m_choices.append(it.toLast()->name());
262 setValue(opt->valueText());
266 void OptionBooleanView::setValue(
const TQString& val)
268 int ID = m_choices.findIndex(val);
269 m_group->setButton(ID);
272 void OptionBooleanView::slotSelected(
int ID)
274 TQString s = m_choices[ID];
275 emit valueChanged(s);
280 DrOptionView::DrOptionView(TQWidget *parent,
const char *name)
281 : TQGroupBox(parent,name)
283 m_stack =
new TQWidgetStack(
this);
285 OptionBaseView *w =
new OptionListView(m_stack);
286 connect(w,TQ_SIGNAL(valueChanged(
const TQString&)),TQ_SLOT(slotValueChanged(
const TQString&)));
287 m_stack->addWidget(w,DrBase::List);
289 w =
new OptionStringView(m_stack);
290 connect(w,TQ_SIGNAL(valueChanged(
const TQString&)),TQ_SLOT(slotValueChanged(
const TQString&)));
291 m_stack->addWidget(w,DrBase::String);
293 w =
new OptionNumericView(m_stack);
294 connect(w,TQ_SIGNAL(valueChanged(
const TQString&)),TQ_SLOT(slotValueChanged(
const TQString&)));
295 m_stack->addWidget(w,DrBase::Integer);
297 w =
new OptionBooleanView(m_stack);
298 connect(w,TQ_SIGNAL(valueChanged(
const TQString&)),TQ_SLOT(slotValueChanged(
const TQString&)));
299 m_stack->addWidget(w,DrBase::Boolean);
301 w =
new OptionBaseView(m_stack);
302 connect(w,TQ_SIGNAL(valueChanged(
const TQString&)),TQ_SLOT(slotValueChanged(
const TQString&)));
303 m_stack->addWidget(w,0);
305 m_stack->raiseWidget(w);
306 setTitle(i18n(
"No Option Selected"));
308 setColumnLayout(0, TQt::Vertical );
309 layout()->setSpacing( KDialog::spacingHint() );
310 layout()->setMargin( KDialog::marginHint() );
311 TQVBoxLayout *main_ =
new TQVBoxLayout(layout(), KDialog::marginHint());
312 main_->addWidget(m_stack);
319 void DrOptionView::slotItemSelected(TQListViewItem *i)
321 m_item = (DriverItem*)i;
322 if (m_item && !m_item->drItem()->isOption())
326 if (m_item->drItem()->type() == DrBase::Float) ID = DrBase::Integer;
327 else ID = m_item->drItem()->type();
329 OptionBaseView *w = (OptionBaseView*)m_stack->widget(ID);
336 w->setOption((m_item ? m_item->drItem() : 0));
337 setTitle(m_item->drItem()->get(
"text"));
338 enabled = ((m_item->drItem()->get(
"fixed") !=
"1") || m_allowfixed);
341 setTitle(i18n(
"No Option Selected"));
342 m_stack->raiseWidget(w);
343 w->setEnabled(enabled);
348 void DrOptionView::slotValueChanged(
const TQString& val)
350 if (m_item && m_item->drItem() && !m_block)
352 m_item->drItem()->setValueText(val);
353 m_item->updateText();
358 #include "droptionview.moc"