⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 htmlform.cpp

📁 一种效率高
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// CRH QSize size( 14, 14 );	QFontMetrics fm(widget->font());	QSize size(fm.height(), fm.height());	widget->resize( size );	descent = 1;	ascent = size.height() - descent;	width = size.width() + 6;}QString HTMLCheckBox::encoding(){	QString _encoding = "";	if ( ((QCheckBox *)widget)->isChecked() )	{		_encoding = encodeString( elementName() );		_encoding += '=';		_encoding += encodeString( value() );	}	return _encoding;}void HTMLCheckBox::resetElement(){	((QCheckBox *)widget)->setChecked( _defCheck );}//----------------------------------------------------------------------------HTMLHidden::HTMLHidden( const char *n, const char *v )	: HTMLInput( n, v ){}QString HTMLHidden::encoding(){	QString _encoding;	if ( elementName().length() )	{		_encoding = encodeString( elementName() );		_encoding += '=';		_encoding += encodeString( value() );	}		return _encoding;}//----------------------------------------------------------------------------HTMLRadio::HTMLRadio( QWidget *parent, const char *n, const char *v,		      bool ch, const HTMLFont *f )	: HTMLInput( n, v, f ){	_defCheck = ch;	widget = new QRadioButton( parent );	if( font )	    widget->setFont( *font );	((QRadioButton *)widget)->setChecked( ch );// CRH	QSize size( 14, 14 );	QFontMetrics fm(widget->font());	QSize size(fm.height(), fm.height());	widget->resize( size );	descent = 1;	ascent = size.height() - descent;	width = size.width() + 6;	connect( widget, SIGNAL( clicked() ), SLOT( slotClicked() ) );}QString HTMLRadio::encoding(){	QString _encoding = "";	if ( ((QRadioButton *)widget)->isChecked() )	{		_encoding = encodeString( elementName() );		_encoding += '=';		_encoding += encodeString( value() );	}	return _encoding;}void HTMLRadio::resetElement(){	((QRadioButton *)widget)->setChecked( _defCheck );}void HTMLRadio::slotClicked(){	emit radioSelected( elementName(), value() );}void HTMLRadio::slotRadioSelected( const char *n, const char *v ){	if ( strcasecmp( n, elementName().data() ) != 0 )		return;	if ( strcasecmp( v, value().data() ) != 0 )		((QRadioButton *)widget)->setChecked( false );}//----------------------------------------------------------------------------HTMLReset::HTMLReset( QWidget *parent, const char *v, const HTMLFont *f )	: HTMLInput( "", v, f ){	widget = new QPushButton( parent );	if( font )	    widget->setFont( *font );	if ( strlen( value() ) != 0 )		((QPushButton *)widget)->setText( value() );	else		((QPushButton *)widget)->setText( "Reset" );	QSize size = widget->sizeHint();	widget->resize( size );	descent = 5;	ascent = size.height() - descent;	width = size.width();	connect( widget, SIGNAL( clicked() ), SLOT( slotClicked() ) );}void HTMLReset::slotClicked(){	emit resetForm();}//----------------------------------------------------------------------------HTMLSubmit::HTMLSubmit( QWidget *parent, const char *n, const char *v,			const HTMLFont *f)	: HTMLInput( n, v, f ){	widget = new QPushButton( parent );	if( font )	    widget->setFont( *font );	if ( strlen( value() ) != 0 )		((QPushButton *)widget)->setText( value() );	else		((QPushButton *)widget)->setText( "Submit Query" );	QSize size = widget->sizeHint();	widget->resize( size );	descent = 5;	ascent = size.height() - descent;	width = size.width();	connect( widget, SIGNAL( clicked() ), SLOT( slotClicked() ) );	activated = false;}QString HTMLSubmit::encoding(){	QString _encoding = "";	if ( elementName().length() && activated )	{		_encoding = encodeString( elementName() );		_encoding += '=';		_encoding += encodeString( value() );	}	return _encoding;}void HTMLSubmit::slotClicked(){	activated = true;	emit submitForm();}//----------------------------------------------------------------------------HTMLTextInput::HTMLTextInput( QWidget *parent, const char *n, const char *v,			      int s, int ml, bool password, const HTMLFont *f )	: HTMLInput( n, v, f ){	_defText = v;	widget = new QLineEdit( parent );	if( font )	    widget->setFont( *font );	if ( strlen( value() ) != 0 )		((QLineEdit *)widget)->setText( value() );	if ( password )	    ((QLineEdit *)widget)->setEchoMode ( QLineEdit::Password );	if ( ml > 0 )	    ((QLineEdit *)widget)->setMaxLength( ml );	QFontMetrics m = widget->fontMetrics();	// this is a bit better if using proportional fonts and	// small inputs fields	QSize size( s * m.width('a') + 4, m.height() + 6);	if(s<5)	    size.setWidth( s * m.width('M') + 4);		widget->resize( size );	descent = 5;	ascent = size.height() - descent;	width = size.width();	connect( widget, SIGNAL( textChanged( const char * ) ),			SLOT( slotTextChanged( const char * ) ) );	connect( widget, SIGNAL( returnPressed() ),			SLOT( slotReturnPressed() ) );}QString HTMLTextInput::encoding(){	QString _encoding = "";	if ( elementName().length() )	{		_encoding = encodeString( elementName() );		_encoding += '=';		_encoding += encodeString( value() );	}	return _encoding;}void HTMLTextInput::resetElement(){	((QLineEdit *)widget)->setText( _defText );}void HTMLTextInput::slotTextChanged( const char *t ){  setValue( t );}void HTMLTextInput::slotReturnPressed(){	emit submitForm();}//----------------------------------------------------------------------------#ifdef EXEC_EXTENSIONSHTMLImageInput::HTMLImageInput( KHTMLWidget *widget, const char *f, int mw,	const char *n )    : HTMLImage( widget, f, 0, 0, 0, mw ), HTMLElement( n )#elseHTMLImageInput::HTMLImageInput( KHTMLWidget *widget, const char *f, int mw,	const char *n )    : HTMLImage( widget, f, 0, 0, mw ), HTMLElement( n )#endif{    _xp = _yp = 0;    pressed = false;    activated = false;}QString HTMLImageInput::encoding(){    QString _encoding = "";    if ( elementName().length() && activated )    {	QString num;	num.setNum( _xp );	_encoding = encodeString( elementName() );	_encoding += ".x=";	_encoding += num;	_encoding += "&";	num.setNum( _yp );	_encoding += encodeString( elementName() );	_encoding += ".y=";	_encoding += num;    }    return _encoding;}HTMLObject *HTMLImageInput::mouseEvent( int _x, int _y, int button, int state ){    if ( _x < x || _x > x + width )	return 0;    if ( _y <= y - ascent || _y > y + descent )	return 0;    if ( button == LeftButton )    {	if ( ! ( state & LeftButton ) )	{	    pressed = true;	}	else if ( pressed )	{	    _xp = _x - x;	    _yp = _y - ( y - ascent );	    activated = true;	    emit submitForm();	    pressed = false;	}	return this;    }    return 0;}//----------------------------------------------------------------------------HTMLForm::HTMLForm( const char *a, const char *m ){    _action = a;    _method = m;    elements.setAutoDelete( false );    hidden.setAutoDelete( true );    timer = new QTimer( this );    connect( timer, SIGNAL(timeout()), SLOT(slotTimeout()) );}void HTMLForm::addElement( HTMLElement *e ){    elements.append( e );}void HTMLForm::addHidden( HTMLHidden *e ){    elements.append( e );    hidden.append( e );}void HTMLForm::removeElement( HTMLElement *e ){    elements.removeRef( e );}void HTMLForm::position( int _x, int _y, int _width, int _height ){  if ( !timer->isActive() )    {      // Repositioning has started.  We first hide the elements, then      // start a timer to perform the actual positioning once moving has      // finished.  This makes scrolling a document with form controls      // smoother.      for ( HTMLElement *e = elements.first(); e != 0; e = elements.next() )	{	  if (e->positionChanged(_x, _y, _width, _height))	    e->hideElement();	}    }  else    {      timer->stop();    }    dx = _x;  dy = _y;  width = _width;  height = _height;      timer->start( 200, true );}void HTMLForm::slotReset(){    HTMLElement *e;    for ( e = elements.first(); e != 0; e = elements.next() )    {	e->resetElement();    }}void HTMLForm::slotSubmit(){	HTMLElement *e;	QString encoding = "";	bool first = true;	for ( e = elements.first(); e != 0; e = elements.next() )	{		QString enc = e->encoding();				if ( enc.length() )		{			if ( !first )				encoding += '&';			encoding += enc;			first = false;		}	}	QString url = action();	       	emit submitted( method(), url, (const char *)encoding );}void HTMLForm::slotRadioSelected( const char *n, const char *v ){    emit radioSelected( n, v );}void HTMLForm::slotTimeout(){    for ( HTMLElement *e = elements.first(); e != 0; e = elements.next() )    {        e->position( dx, dy, width, height );    }}HTMLForm::~HTMLForm(){    HTMLElement *e;    for ( e = elements.first(); e != 0; e = elements.next() )    {	e->setForm( 0 );    }    delete timer;}#include "htmlform.moc"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -