21 #include "driveritem.h"
24 #include <tqstringlist.h>
35 : m_type(DrBase::Base), m_conflict(false)
43 TQString DrBase::valueText()
45 return TQString::null;
48 TQString DrBase::prettyText()
53 void DrBase::setValueText(
const TQString&)
57 DriverItem* DrBase::createItem(DriverItem *parent, DriverItem *after)
59 return new DriverItem(parent, after,
this);
62 void DrBase::setOptions(
const TQMap<TQString,TQString>& opts)
64 if (opts.contains(name())) setValueText(opts[name()]);
67 void DrBase::getOptions(TQMap<TQString,TQString>& opts,
bool incldef)
69 QString val = valueText();
70 if ( incldef ||
get(
"persistent" ) ==
"1" ||
get(
"default") != val )
74 DrBase* DrBase::clone()
79 case Main: opt =
new DrMain;
break;
80 case Group: opt =
new DrGroup;
break;
81 case String: opt =
new DrStringOption;
break;
82 case Integer: opt =
new DrIntegerOption;
break;
83 case Float: opt =
new DrFloatOption;
break;
84 case List: opt =
new DrListOption;
break;
85 case Boolean: opt =
new DrBooleanOption;
break;
86 default: opt =
new DrBase;
break;
90 opt->m_conflict = m_conflict;
91 opt->setValueText(valueText());
103 m_type = DrBase::Main;
104 m_constraints.setAutoDelete(
true);
105 m_pagesizes.setAutoDelete(
true);
111 if (has(
"temporary"))
112 TQFile::remove(
get(
"temporary"));
115 DriverItem* DrMain::createTreeView(TQListView *parent)
117 DriverItem *root =
new DriverItem(parent,
this);
122 int DrMain::checkConstraints()
126 TQPtrListIterator<DrConstraint> it(m_constraints);
127 for (;it.current();++it)
128 if (it.current()->check(
this))
133 void DrMain::addPageSize(DrPageSize *ps)
135 m_pagesizes.insert(ps->pageName(),ps);
138 void DrMain::removeOptionGlobally(
const TQString& name)
141 DrBase *opt = findOption(name, &grp);
145 grp->removeOption(name);
151 void DrMain::removeGroupGlobally(DrGroup *grp)
154 if (findGroup(grp, &parent) && parent)
156 parent->removeGroup(grp);
157 if (parent->isEmpty() && parent !=
this)
158 removeGroupGlobally(parent);
162 TQMap<TQString, DrBase*> DrMain::flatten()
164 TQMap<TQString, DrBase*> optmap;
166 flattenGroup(optmap, index);
170 DrMain* DrMain::cloneDriver()
172 DrMain *driver =
static_cast<DrMain*
>(clone());
174 TQPtrListIterator<DrConstraint> cit(m_constraints);
175 for (; cit.current(); ++cit)
176 driver->addConstraint(
new DrConstraint(*(cit.current())));
178 TQDictIterator<DrPageSize> pit(m_pagesizes);
179 for (; pit.current(); ++pit)
180 driver->addPageSize(
new DrPageSize(*(pit.current())));
192 m_type = DrBase::Group;
194 m_subgroups.setAutoDelete(
true);
195 m_options.setAutoDelete(
true);
196 m_listoptions.setAutoDelete(
false);
203 void DrGroup::addOption(DrBase *opt)
205 if (!opt->name().isEmpty())
207 m_options.insert(opt->name(),opt);
208 m_listoptions.append(opt);
212 void DrGroup::addGroup(DrGroup *grp)
214 m_subgroups.append(grp);
217 void DrGroup::addObject(DrBase *optgrp)
219 if (optgrp->isOption())
221 else if (optgrp->type() == DrBase::Group)
222 addGroup(static_cast<DrGroup*>(optgrp));
225 void DrGroup::removeOption(
const TQString& name)
227 DrBase *opt = m_options.find(name);
230 m_listoptions.removeRef(opt);
231 m_options.remove(name);
235 void DrGroup::removeGroup(DrGroup *grp)
237 m_subgroups.removeRef(grp);
240 bool DrGroup::isEmpty()
242 return (m_options.count()+m_subgroups.count() == 0);
245 DriverItem* DrGroup::createItem(DriverItem *parent, DriverItem *after)
247 DriverItem *item = DrBase::createItem(parent, after);
252 void DrGroup::createTree(DriverItem *parent)
256 TQPtrListIterator<DrGroup> lit(m_subgroups);
257 for (;lit.current();++lit)
258 item = lit.current()->createItem(parent, item);
260 TQPtrListIterator<DrBase> dit(m_listoptions);
261 for (;dit.current();++dit)
262 item = dit.current()->createItem(parent, item);
265 DrBase* DrGroup::findOption(
const TQString& name, DrGroup **parentGroup)
267 DrBase *opt = m_options.find(name);
270 TQPtrListIterator<DrGroup> it(m_subgroups);
271 for (;it.current() && !opt; ++it)
272 opt = it.current()->findOption(name, parentGroup);
274 else if (parentGroup)
279 DrGroup* DrGroup::findGroup(DrGroup *grp, DrGroup ** parentGroup)
281 DrGroup *group = (m_subgroups.findRef(grp) == -1 ? 0 : grp);
284 TQPtrListIterator<DrGroup> it(m_subgroups);
285 for (;it.current() && !group; ++it)
286 group = it.current()->findGroup(grp, parentGroup);
288 else if (parentGroup)
293 void DrGroup::clearConflict()
295 TQDictIterator<DrBase> dit(m_options);
296 for (;dit.current();++dit)
297 dit.current()->setConflict(
false);
299 TQPtrListIterator<DrGroup> lit(m_subgroups);
300 for (;lit.current();++lit)
301 lit.current()->clearConflict();
304 void DrGroup::setOptions(
const TQMap<TQString,TQString>& opts)
306 TQDictIterator<DrBase> dit(m_options);
307 for (;dit.current();++dit)
308 dit.current()->setOptions(opts);
310 TQPtrListIterator<DrGroup> lit(m_subgroups);
311 for (;lit.current();++lit)
312 lit.current()->setOptions(opts);
315 void DrGroup::getOptions(TQMap<TQString,TQString>& opts,
bool incldef)
317 TQDictIterator<DrBase> dit(m_options);
318 for (;dit.current();++dit)
319 dit.current()->getOptions(opts,incldef);
321 TQPtrListIterator<DrGroup> lit(m_subgroups);
322 for (;lit.current();++lit)
323 lit.current()->getOptions(opts,incldef);
326 void DrGroup::flattenGroup(TQMap<TQString, DrBase*>& optmap,
int& index)
328 TQPtrListIterator<DrGroup> git(m_subgroups);
329 for (; git.current(); ++git)
330 git.current()->flattenGroup(optmap, index);
332 TQDictIterator<DrBase> oit(m_options);
333 for (; oit.current(); ++oit)
334 optmap[oit.current()->name()] = oit.current();
336 if (name().isEmpty())
337 optmap[TQString::fromLatin1(
"group%1").arg(index++)] =
this;
339 optmap[name()] =
this;
341 m_subgroups.setAutoDelete(
false);
342 m_options.setAutoDelete(
false);
345 m_listoptions.clear();
346 m_subgroups.setAutoDelete(
true);
347 m_options.setAutoDelete(
true);
350 DrBase* DrGroup::clone()
352 DrGroup *grp =
static_cast<DrGroup*
>(DrBase::clone());
354 TQPtrListIterator<DrGroup> git(m_subgroups);
355 for (; git.current(); ++git)
356 grp->addGroup(static_cast<DrGroup*>(git.current()->clone()));
358 TQPtrListIterator<DrBase> oit(m_listoptions);
359 for (; oit.current(); ++oit)
360 grp->addOption(oit.current()->clone());
362 return static_cast<DrBase*
>(grp);
365 TQString DrGroup::groupForOption(
const TQString& optname )
368 if ( optname ==
"PageSize" ||
369 optname ==
"InputSlot" ||
370 optname ==
"ManualFeed" ||
371 optname ==
"MediaType" ||
372 optname ==
"MediaColor" ||
373 optname ==
"MediaWeight" ||
374 optname ==
"Duplex" ||
375 optname ==
"DoubleSided" ||
376 optname ==
"Copies" )
377 grpname = i18n(
"General" );
378 else if ( optname.startsWith(
"stp" ) ||
380 optname ==
"Yellow" ||
381 optname ==
"Magenta" ||
382 optname ==
"Black" ||
383 optname ==
"Density" ||
384 optname ==
"Contrast" )
385 grpname = i18n(
"Adjustments" );
386 else if ( optname.startsWith(
"JCL" ) )
387 grpname = i18n(
"JCL" );
389 grpname = i18n(
"Others" );
397 DrChoiceGroup::DrChoiceGroup()
400 m_type = DrBase::ChoiceGroup;
403 DrChoiceGroup::~DrChoiceGroup()
407 DriverItem* DrChoiceGroup::createItem(DriverItem *parent, DriverItem*)
417 DrStringOption::DrStringOption()
420 m_type = DrBase::String;
423 DrStringOption::~DrStringOption()
427 TQString DrStringOption::valueText()
432 void DrStringOption::setValueText(
const TQString& s)
441 DrIntegerOption::DrIntegerOption()
444 m_type = DrBase::Integer;
450 DrIntegerOption::~DrIntegerOption()
454 TQString DrIntegerOption::valueText()
456 QString s = TQString::number(m_value);
460 void DrIntegerOption::setValueText(
const TQString& s)
465 TQString DrIntegerOption::fixedVal()
467 TQStringList vals = TQStringList::split(
"|",
get(
"fixedvals"),
false);
468 if (vals.count() == 0)
472 for (TQStringList::Iterator it=vals.begin(); it!=vals.end(); ++it)
474 int thisVal = (*it).toInt();
475 if (val.isEmpty() || abs(thisVal - m_value) < d)
477 d = abs(thisVal - m_value);
491 DrFloatOption::DrFloatOption()
494 m_type = DrBase::Float;
500 DrFloatOption::~DrFloatOption()
504 TQString DrFloatOption::valueText()
506 QString s = TQString::number(m_value,
'f',3);
510 void DrFloatOption::setValueText(
const TQString& s)
512 m_value = s.toFloat();
515 TQString DrFloatOption::fixedVal()
517 TQStringList vals = TQStringList::split(
"|",
get(
"fixedvals"),
false);
518 if (vals.count() == 0)
522 for (TQStringList::Iterator it=vals.begin(); it!=vals.end(); ++it)
524 float thisVal = (*it).toFloat();
525 if (val.isEmpty() || fabs(thisVal - m_value) < d)
527 d = fabs(thisVal - m_value);
541 DrListOption::DrListOption()
544 m_type = DrBase::List;
546 m_choices.setAutoDelete(
true);
550 DrListOption::~DrListOption()
554 TQString DrListOption::valueText()
556 QString s = (m_current ? m_current->name() : TQString::null);
560 TQString DrListOption::prettyText()
563 return m_current->get(
"text");
565 return TQString::null;
568 void DrListOption::setValueText(
const TQString& s)
570 m_current = findChoice(s);
574 int index = s.toInt(&ok);
580 DrBase* DrListOption::findChoice(
const TQString& txt)
582 TQPtrListIterator<DrBase> it(m_choices);
583 for (;it.current();++it)
584 if (it.current()->name() == txt)
589 DrBase* DrListOption::clone()
591 DrListOption *opt =
static_cast<DrListOption*
>(DrBase::clone());
593 TQPtrListIterator<DrBase> it(m_choices);
594 for (; it.current(); ++it)
595 opt->addChoice(it.current()->clone());
597 opt->setValueText(valueText());
599 return static_cast<DrBase*
>(opt);
602 void DrListOption::getOptions(TQMap<TQString,TQString>& opts,
bool incldef)
604 DrBase::getOptions(opts, incldef);
605 if (currentChoice() && currentChoice()->type() == DrBase::ChoiceGroup)
606 currentChoice()->getOptions(opts, incldef);
609 void DrListOption::setOptions(
const TQMap<TQString,TQString>& opts)
611 DrBase::setOptions(opts);
612 if (currentChoice() && currentChoice()->type() == DrBase::ChoiceGroup)
613 currentChoice()->setOptions(opts);
616 DriverItem* DrListOption::createItem(DriverItem *parent, DriverItem *after)
618 DriverItem *item = DrBase::createItem(parent, after);
626 void DrListOption::setChoice(
int choicenum)
628 if (choicenum >= 0 && choicenum < (
int)m_choices.count())
630 setValueText(m_choices.at(choicenum)->name());
638 DrConstraint::DrConstraint(
const TQString& o1,
const TQString& o2,
const TQString& c1,
const TQString& c2)
639 : m_opt1(o1), m_opt2(o2), m_choice1(c1), m_choice2(c2), m_option1(0), m_option2(0)
643 DrConstraint::DrConstraint(
const DrConstraint& d)
644 : m_opt1(d.m_opt1), m_opt2(d.m_opt2), m_choice1(d.m_choice1), m_choice2(d.m_choice2), m_option1(0), m_option2(0)
648 bool DrConstraint::check(DrMain *driver)
650 if (!m_option1) m_option1 = (DrListOption*)driver->findOption(m_opt1);
651 if (!m_option2) m_option2 = (DrListOption*)driver->findOption(m_opt2);
652 if (m_option1 && m_option2 && m_option1->currentChoice() && m_option2->currentChoice())
654 bool f1(
false), f2(
false);
655 QString c1(m_option1->currentChoice()->name()), c2(m_option2->currentChoice()->name());
657 if (m_choice1.isEmpty())
658 f1 = (c1 !=
"None" && c1 !=
"Off" && c1 !=
"False");
660 f1 = (c1 == m_choice1);
661 if (m_choice2.isEmpty())
662 f2 = (c2 !=
"None" && c2 !=
"Off" && c2 !=
"False");
664 f2 = (c2 == m_choice2);
666 QString s((f1 && f2 ?
"1" :
"0"));
667 if (!m_option1->conflict()) m_option1->setConflict(f1 && f2);
668 if (!m_option2->conflict()) m_option2->setConflict(f1 && f2);
679 DrPageSize::DrPageSize(
const TQString& s,
float width,
float height,
float left,
float bottom,
float right,
float top)
690 DrPageSize::DrPageSize(
const DrPageSize& d)
692 m_width( d.m_width ),
693 m_height( d.m_height ),
695 m_bottom( d.m_bottom ),
696 m_right( d.m_right ),
701 TQSize DrPageSize::pageSize()
const
703 return TQSize( (
int )m_width, (
int )m_height );
706 TQRect DrPageSize::pageRect()
const
708 return TQRect( (
int )( m_left+0.5 ), (
int )( m_top+0.5 ), (
int )( m_width-m_left-m_right ), (
int )( m_height-m_top-m_bottom ) );
711 TQSize DrPageSize::margins()
const
713 return TQSize( (
int )( m_left+0.5 ), (
int )( m_top+0.5 ) );