00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
#include "cupsdoption.h"
00021
00022
#include <qcheckbox.h>
00023
#include <qlayout.h>
00024
#include <qframe.h>
00025
#include <klocale.h>
00026
#include <qtooltip.h>
00027
00028 CupsdOption::CupsdOption(
QWidget *parent,
const char *name)
00029 :
QWidget(parent, name)
00030 {
00031 cb_ =
new QCheckBox(
this);
00032 cb_->setChecked(
true);
00033 connect(cb_,SIGNAL(clicked()),SLOT(checkClicked()));
00034 QToolTip::add(cb_, i18n(
"Toggle default value"));
00035
00036
int w = (fontMetrics().width(i18n(
"Default")) - cb_->sizeHint().width()) / 2;
00037
00038 fr_ =
new QFrame(
this);
00039 fr_->setFrameStyle(QFrame::VLine|QFrame::Sunken);
00040 fr_->setLineWidth(1);
00041
00042 layout_ =
new QHBoxLayout(
this, 0, 10);
00043 layout_->addSpacing(5);
00044 layout_->addWidget(fr_, 0);
00045 layout_->addSpacing(w);
00046 layout_->addWidget(cb_, 0);
00047 layout_->addSpacing(w);
00048
00049 widget_ = 0;
00050 }
00051
00052 CupsdOption::~CupsdOption()
00053 {
00054 }
00055
00056
QSize CupsdOption::sizeHint()
const
00057
{
00058
QSize s1(cb_->sizeHint()), s2(widget_ ? widget_->sizeHint() :
QSize(0,0));
00059
int w = fontMetrics().width(i18n(
"Default"));
00060
return QSize(s2.width()+w+fr_->width()+10, QMAX(s1.height(), s2.height()));
00061 }
00062
00063
void CupsdOption::setDefault(
bool on)
00064 {
00065 cb_->setChecked(on);
00066 checkClicked();
00067 }
00068
00069
bool CupsdOption::isDefault()
const
00070
{
00071
return (cb_->isChecked());
00072 }
00073
00074
void CupsdOption::checkClicked()
00075 {
00076
if (widget_) widget_->setEnabled(!(cb_->isChecked()));
00077 }
00078
00079
void CupsdOption::childEvent(
QChildEvent *ev)
00080 {
00081 QObject::childEvent(ev);
00082
if (ev->inserted())
00083 {
00084
if (ev->child() != layout_ && ev->child() != cb_ && ev->child() != fr_ && ev->child()->isWidgetType())
00085 {
00086 widget_ = (
QWidget*)(ev->child());
00087 layout_->insertWidget(0, widget_, 1);
00088 checkClicked();
00089 }
00090 }
00091 }
00092
#include "cupsdoption.moc"