• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeprint
 

tdeprint

  • tdeprint
droptionview.cpp
1/*
2 * This file is part of the KDE libraries
3 * Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License version 2 as published by the Free Software Foundation.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 **/
19
20#include "droptionview.h"
21#include "driver.h"
22#include "driveritem.h"
23
24#include <math.h>
25#include <tqlineedit.h>
26#include <tqslider.h>
27#include <tqlabel.h>
28#include <tdelistbox.h>
29#include <tqvbuttongroup.h>
30#include <tqradiobutton.h>
31#include <tqwidgetstack.h>
32#include <tqlayout.h>
33#include <tqapplication.h>
34
35#include <kcursor.h>
36#include <kdialog.h>
37#include <tdelocale.h>
38
39OptionBaseView::OptionBaseView(TQWidget *parent, const char *name)
40: TQWidget(parent,name)
41{
42 blockSS = false;
43}
44
45void OptionBaseView::setOption(DrBase*)
46{
47}
48
49void OptionBaseView::setValue(const TQString&)
50{
51}
52
53//******************************************************************************************************
54
55OptionNumericView::OptionNumericView(TQWidget *parent, const char *name)
56: OptionBaseView(parent,name)
57{
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);
64
65 m_integer = true;
66
67 TQVBoxLayout *main_ = new TQVBoxLayout(this, 0, 10);
68 TQHBoxLayout *sub_ = new TQHBoxLayout(0, 0, 10);
69 TQHBoxLayout *sub2_ = new TQHBoxLayout(0, 0, 5);
70 main_->addStretch(1);
71 main_->addLayout(sub_,0);
72 main_->addLayout(sub2_,0);
73 main_->addStretch(1);
74 sub_->addWidget(lab,0);
75 sub_->addWidget(m_edit,0);
76 sub_->addStretch(1);
77 sub2_->addWidget(m_minval,0);
78 sub2_->addWidget(m_slider,1);
79 sub2_->addWidget(m_maxval,0);
80
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&)));
83}
84
85void OptionNumericView::setOption(DrBase *opt)
86{
87 if (opt->type() != DrBase::Integer && opt->type() != DrBase::Float)
88 return;
89
90 blockSS = true;
91 if (opt->type() == DrBase::Integer)
92 {
93 m_integer = true;
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_));
100 }
101 else
102 {
103 m_integer = false;
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"));
110 }
111 m_slider->update();
112 blockSS = false;
113
114 setValue(opt->valueText());
115}
116
117void OptionNumericView::setValue(const TQString& val)
118{
119 m_edit->setText(val);
120}
121
122void OptionNumericView::slotSliderChanged(int value)
123{
124 if (blockSS) return;
125
126 TQString txt;
127 if (m_integer)
128 txt = TQString::number(value);
129 else
130 txt = TQString::number(float(value)/1000.0,'f',3);
131 blockSS = true;
132 m_edit->setText(txt);
133 blockSS = false;
134 emit valueChanged(txt);
135}
136
137void OptionNumericView::slotEditChanged(const TQString& txt)
138{
139 if (blockSS) return;
140
141 bool ok(false);
142 int val(0);
143 if (m_integer)
144 val = txt.toInt(&ok);
145 else
146 val = (int)rint(txt.toFloat(&ok)*1000);
147 if (ok)
148 {
149 blockSS = true;
150 m_slider->setValue(val);
151 blockSS = false;
152 emit valueChanged(txt);
153 }
154 else
155 {
156 m_edit->selectAll();
157 TQApplication::beep();
158 }
159}
160
161//******************************************************************************************************
162
163OptionStringView::OptionStringView(TQWidget *parent, const char *name)
164: OptionBaseView(parent,name)
165{
166 m_edit = new TQLineEdit(this);
167 TQLabel *lab = new TQLabel(i18n("String value:"),this);
168
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);
174
175 connect(m_edit,TQ_SIGNAL(textChanged(const TQString&)),TQ_SIGNAL(valueChanged(const TQString&)));
176}
177
178void OptionStringView::setOption(DrBase *opt)
179{
180 if (opt->type() == DrBase::String)
181 m_edit->setText(opt->valueText());
182}
183
184void OptionStringView::setValue(const TQString& val)
185{
186 m_edit->setText(val);
187}
188
189//******************************************************************************************************
190
191OptionListView::OptionListView(TQWidget *parent, const char *name)
192: OptionBaseView(parent,name)
193{
194 m_list = new TDEListBox(this);
195
196 TQVBoxLayout *main_ = new TQVBoxLayout(this, 0, 10);
197 main_->addWidget(m_list);
198
199 connect(m_list,TQ_SIGNAL(selectionChanged()),TQ_SLOT(slotSelectionChanged()));
200}
201
202void OptionListView::setOption(DrBase *opt)
203{
204 if (opt->type() == DrBase::List)
205 {
206 blockSS = true;
207 m_list->clear();
208 m_choices.clear();
209 TQPtrListIterator<DrBase> it(*(((DrListOption*)opt)->choices()));
210 for (;it.current();++it)
211 {
212 m_list->insertItem(it.current()->get("text"));
213 m_choices.append(it.current()->name());
214 }
215 blockSS = false;
216 setValue(opt->valueText());
217 }
218}
219
220void OptionListView::setValue(const TQString& val)
221{
222 m_list->setCurrentItem(m_choices.findIndex(val));
223}
224
225void OptionListView::slotSelectionChanged()
226{
227 if (blockSS) return;
228
229 TQString s = m_choices[m_list->currentItem()];
230 emit valueChanged(s);
231}
232
233//******************************************************************************************************
234
235OptionBooleanView::OptionBooleanView(TQWidget *parent, const char *name)
236: OptionBaseView(parent,name)
237{
238 m_group = new TQVButtonGroup(this);
239 m_group->setFrameStyle(TQFrame::NoFrame);
240
241 TQRadioButton *btn = new TQRadioButton(m_group);
242 btn->setCursor(KCursor::handCursor());
243 btn = new TQRadioButton(m_group);
244 btn->setCursor(KCursor::handCursor());
245
246 TQVBoxLayout *main_ = new TQVBoxLayout(this, 0, 10);
247 main_->addWidget(m_group);
248
249 connect(m_group,TQ_SIGNAL(clicked(int)),TQ_SLOT(slotSelected(int)));
250}
251
252void OptionBooleanView::setOption(DrBase *opt)
253{
254 if (opt->type() == DrBase::Boolean)
255 {
256 TQPtrListIterator<DrBase> it(*(((DrBooleanOption*)opt)->choices()));
257 m_choices.clear();
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());
263 }
264}
265
266void OptionBooleanView::setValue(const TQString& val)
267{
268 int ID = m_choices.findIndex(val);
269 m_group->setButton(ID);
270}
271
272void OptionBooleanView::slotSelected(int ID)
273{
274 TQString s = m_choices[ID];
275 emit valueChanged(s);
276}
277
278//******************************************************************************************************
279
280DrOptionView::DrOptionView(TQWidget *parent, const char *name)
281: TQGroupBox(parent,name)
282{
283 m_stack = new TQWidgetStack(this);
284
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);
288
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);
292
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);
296
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);
300
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); // empty widget
304
305 m_stack->raiseWidget(w);
306 setTitle(i18n("No Option Selected"));
307
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);
313
314 m_item = 0;
315 m_block = false;
316 m_allowfixed = true;
317}
318
319void DrOptionView::slotItemSelected(TQListViewItem *i)
320{
321 m_item = (DriverItem*)i;
322 if (m_item && !m_item->drItem()->isOption())
323 m_item = 0;
324 int ID(0);
325 if (m_item)
326 if (m_item->drItem()->type() == DrBase::Float) ID = DrBase::Integer;
327 else ID = m_item->drItem()->type();
328
329 OptionBaseView *w = (OptionBaseView*)m_stack->widget(ID);
330 if (w)
331 {
332 m_block = true;
333 bool enabled(true);
334 if (m_item)
335 {
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);
339 }
340 else
341 setTitle(i18n("No Option Selected"));
342 m_stack->raiseWidget(w);
343 w->setEnabled(enabled);
344 m_block = false;
345 }
346}
347
348void DrOptionView::slotValueChanged(const TQString& val)
349{
350 if (m_item && m_item->drItem() && !m_block)
351 {
352 m_item->drItem()->setValueText(val);
353 m_item->updateText();
354 emit changed();
355 }
356}
357
358#include "droptionview.moc"

tdeprint

Skip menu "tdeprint"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeprint

Skip menu "tdeprint"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeprint by doxygen 1.9.4
This website is maintained by Timothy Pearson.