Exemplo n.º 1
0
DrBase* Foomatic2Loader::createOption( const QMap<QString,QVariant>& m ) const
{
	QString type = m.operator[]( "type" ).toString();
	DrBase *opt = NULL;
	if ( type == "enum" )
	{
		DrListOption *lopt = new DrListOption;
		QVariant a = m.operator[]( "vals_byname" );
		QMap<QString,QVariant>::ConstIterator it = a.mapBegin();
		for ( ; it!=a.mapEnd(); ++it )
		{
			if ( it.data().type() != QVariant::Map )
				continue;
			DrBase *ch = createValue( it.key(), it.data().toMap() );
			if ( ch )
				lopt->addChoice( ch );
		}
		opt = lopt;
	}
	else if ( type == "int" || type == "float" )
	{
		if ( type == "int" )
			opt = new DrIntegerOption;
		else
			opt = new DrFloatOption;
		opt->set( "minval", m.operator[]( "min" ).toString() );
		opt->set( "maxval", m.operator[]( "max" ).toString() );
	}
	else if ( type == "bool" )
	{
		DrBooleanOption *bopt = new DrBooleanOption;
		DrBase *choice;
		// choice 1
		choice = new DrBase;
		choice->setName( "0" );
		choice->set( "text", m.operator[]( "name_false" ).toString() );
		bopt->addChoice( choice );
		choice = new DrBase;
		choice->setName( "1" );
		choice->set( "text", m.operator[]( "name_true" ).toString() );
		bopt->addChoice( choice );
		opt = bopt;
	}
	else if ( type == "string" )
	{
		opt = new DrStringOption;
	}
	if ( opt )
	{
		opt->setName( m.operator[]( "name" ).toString() );
		opt->set( "text", m.operator[]( "comment" ).toString() );
		QString defval = m.operator[]( "default" ).toString();
		if ( !defval.isEmpty() )
		{
			opt->setValueText( defval );
			opt->set( "default", defval );
		}
	}
	return opt;
}
Exemplo n.º 2
0
DrBase *DrListOption::clone()
{
    DrListOption *opt = static_cast< DrListOption * >(DrBase::clone());

    QPtrListIterator< DrBase > it(m_choices);
    for(; it.current(); ++it)
        opt->addChoice(it.current()->clone());

    opt->setValueText(valueText());

    return static_cast< DrBase * >(opt);
}
Exemplo n.º 3
0
void KPMarginPage::initPageSize(const QString& ps, bool landscape)
{
	// first retrieve the Qt values for page size and margins
	QPrinter	prt(QPrinter::PrinterResolution);
	prt.setFullPage(true);
	prt.setPageSize((QPrinter::PageSize)(ps.isEmpty() ? KGlobal::locale()->pageSize() : ps.toInt()));
	QPaintDeviceMetrics	metrics(&prt);
	float	w = metrics.width();
	float	h = metrics.height();
	unsigned int	it, il, ib, ir;
	prt.margins( &it, &il, &ib, &ir );
	float	mt = it;
	float	ml = il;
	float	mb = ib;
	float	mr = ir;

	if (driver() && m_usedriver )
	{
		QString	pageSize(ps);

		if (pageSize.isEmpty())
		{
			DrListOption	*o = (DrListOption*)driver()->findOption("PageSize");
			if (o)
				pageSize = o->get("default");
		}
		if (!pageSize.isEmpty())
		{
			DrPageSize	*dps = driver()->findPageSize(pageSize);
			if (dps)
			{
				w = dps->pageWidth();
				h = dps->pageHeight();
				mt = QMAX( mt, dps->topMargin() );
				ml = QMAX( ml, dps->leftMargin() );
				mb = QMAX( mb, dps->bottomMargin() );
				mr = QMAX( mr, dps->rightMargin() );
			}
		}
	}
	m_margin->setPageSize(w, h);
	m_margin->setOrientation(landscape ? KPrinter::Landscape : KPrinter::Portrait);
	m_margin->setDefaultMargins( mt, mb, ml, mr );
	m_margin->setCustomEnabled(false);
}
Exemplo n.º 4
0
void KXmlCommandAdvancedDlg::slotApplyChanges()
{
	TQListViewItem	*item = m_view->currentItem();
	if (item)
	{
		if (m_name->text().isEmpty() || m_name->text() == "__root__")
		{
			KMessageBox::error(this, i18n("Invalid identification name. Empty strings and \"__root__\" are not allowed."));
			return;
		}

		m_apply->setEnabled(false);

		DrBase	*opt = (m_opts.contains(item->text(1)) ? m_opts[item->text(1)] : 0);
		m_opts.remove(item->text(1));
		delete opt;

		// update tree item
		item->setText(0, m_desc->text());
		item->setText(1, m_name->text());

		// recreate option
		if (m_type->isEnabled())
		{
			int	type = m_type->currentItem() + DrBase::String;
			switch (type)
			{
				case DrBase::Integer:
				case DrBase::Float:
					if (type == DrBase::Integer)
						opt = new DrIntegerOption;
					else
						opt = new DrFloatOption;
					opt->set("minval", m_edit1->text());
					opt->set("maxval", m_edit2->text());
					break;
				case DrBase::List:
				case DrBase::Boolean:
					{
						if (type == DrBase::List)
							opt = new DrListOption;
						else
							opt = new DrBooleanOption;
						DrListOption	*lopt = static_cast<DrListOption*>(opt);
						TQListViewItem	*item = m_values->firstChild();
						while (item)
						{
							DrBase	*choice = new DrBase;
							choice->setName(item->text(0));
							choice->set("text", item->text(1));
							lopt->addChoice(choice);
							item = item->nextSibling();
						}
						break;
					}
				case DrBase::String:
					opt = new DrStringOption;
					break;

			}
			opt->set("format", m_format->text());
			opt->set("default", m_default->text());
			opt->setValueText(opt->get("default"));
		}
		else
			opt = new DrGroup;

		opt->setName((m_name->text().isEmpty() ? generateId(m_opts) : m_name->text()));
		opt->set("text", m_desc->text());
		opt->set( "persistent", m_persistent->isChecked() ? "1" : "0" );

		m_opts[opt->name()] = opt;
	}
}
Exemplo n.º 5
0
void KPrinterImpl::preparePrinting(KPrinter *printer)
{
	// page size -> try to find page size and margins from driver file
	// use "PageSize" as option name to find the wanted page size. It's
	// up to the driver loader to use that option name.
	KMManager	*mgr = KMFactory::self()->manager();
	DrMain	*driver = mgr->loadPrinterDriver(mgr->findPrinter(printer->printerName()), false);
	if (driver)
	{
		// Find the page size:
		// 1) print option
		// 2) default driver option
		QString	psname = printer->option("PageSize");
		if (psname.isEmpty())
		{
			DrListOption	*opt = (DrListOption*)driver->findOption("PageSize");
			if (opt) psname = opt->get("default");
		}
		if (!psname.isEmpty())
		{
			printer->setOption("kde-pagesize",TQString::number((int)pageNameToPageSize(psname)));
			DrPageSize	*ps = driver->findPageSize(psname);
			if (ps)
			{
				printer->setRealPageSize( ps );
			}
		}

		// Find the numerical resolution
		// 1) print option (Resolution)
		// 2) default driver option (Resolution)
		// 3) default printer resolution
		// The resolution must have the format: XXXdpi or XXXxYYYdpi. In the second
		// case the YYY value is used as resolution.
		TQString res = printer->option( "Resolution" );
		if ( res.isEmpty() )
		{
			DrBase *opt = driver->findOption( "Resolution" );
			if ( opt )
				res = opt->get( "default" );
			if ( res.isEmpty() )
				res = driver->get( "resolution" );
		}
		if ( !res.isEmpty() )
		{
			TQRegExp re( "(\\d+)(?:x(\\d+))?dpi" );
			if ( re.search( res ) != -1 )
			{
				if ( !re.cap( 2 ).isEmpty() )
					printer->setOption( "kde-resolution", re.cap( 2 ) );
				else
					printer->setOption( "kde-resolution", re.cap( 1 ) );
			}
		}

		// Find the supported fonts
		TQString fonts = driver->get( "fonts" );
		if ( !fonts.isEmpty() )
			printer->setOption( "kde-fonts", fonts );

		delete driver;
	}

}