kdeprint Library API Documentation

cupsdoption.cpp

00001 /* 00002 * This file is part of the KDE libraries 00003 * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be> 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Library General Public 00007 * License version 2 as published by the Free Software Foundation. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Library General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Library General Public License 00015 * along with this library; see the file COPYING.LIB. If not, write to 00016 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00017 * Boston, MA 02111-1307, USA. 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"
KDE Logo
This file is part of the documentation for kdeprint Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 16 17:23:16 2005 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003