keduca
kgroupeduca.cpp
Go to the documentation of this file.00001 /*************************************************************************** 00002 kgroupeduca.cpp - description 00003 ------------------- 00004 begin : Thu Sep 7 2000 00005 copyright : (C) 2000 by Javier Campos Morales 00006 email : javi@asyris.org 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #include "kgroupeduca.h" 00019 #include "kgroupeduca.moc" 00020 #include "kcheckeduca.h" 00021 #include "kradioeduca.h" 00022 00023 #include <klocale.h> 00024 00025 KGroupEduca::KGroupEduca(QWidget *parent, const char *name ) : QVButtonGroup(i18n("Answers"), parent, name) 00026 { 00027 _sv = new QScrollView(this); 00028 _sv->setVScrollBarMode(QScrollView::Auto); 00029 _sv->setHScrollBarMode(QScrollView::Auto); 00030 _sv->setFrameStyle( QFrame::NoFrame | QFrame::Plain ); 00031 _vbox2 = new QVBox( _sv->viewport() ); 00032 _vbox2->setSpacing( 6 ); 00033 _vbox2->setMargin( 11 ); 00034 _sv->viewport()->setBackgroundMode( _vbox2->backgroundMode() ); 00035 _sv->setStaticBackground(true); 00036 _sv->addChild( _vbox2 ); 00037 _typeMode = Radio; 00038 } 00039 00040 KGroupEduca::~KGroupEduca(){ 00041 } 00042 00044 void KGroupEduca::insertAnswer( const QString& text) 00045 { 00046 QButton *answer = 0; 00047 00048 switch( _typeMode ) 00049 { 00050 case Radio: 00051 answer = new KRadioEduca( _vbox2 ); 00052 break; 00053 case Check: 00054 answer = new KCheckEduca( _vbox2 ); 00055 break; 00056 } 00057 answer->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)0 ) ); 00058 answer->setText( text ); 00059 answer->show(); 00060 insert(answer); 00061 } 00062 00064 void KGroupEduca::setType(ButtonType type) 00065 { 00066 _typeMode = type; 00067 } 00068 00070 void KGroupEduca::clearAnswers() 00071 { 00072 unsigned int maxButton = count(); 00073 for( unsigned int i=0 ; i<maxButton ; ++i ) 00074 { 00075 QButton *tmpButton; 00076 if( (tmpButton = find(i)) ) 00077 remove(tmpButton); 00078 delete tmpButton; 00079 } 00080 00081 } 00082 00084 bool KGroupEduca::isChecked(int id) 00085 { 00086 switch( _typeMode ) 00087 { 00088 case Radio: 00089 { 00090 KRadioEduca *tmpRadioButton = (KRadioEduca*) find(id); 00091 if(tmpRadioButton != 0) return tmpRadioButton->isChecked(); 00092 } 00093 break; 00094 case Check: 00095 { 00096 KCheckEduca *tmpCheckButton = (KCheckEduca*) find(id); 00097 if(tmpCheckButton != 0) return tmpCheckButton->isChecked(); 00098 } 00099 break; 00100 } 00101 return 0; 00102 }