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

📄 render_form.cpp

📁 将konqueror浏览器移植到ARM9 2410中
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    for(unsigned int i = 0; i < value.length(); i++) {        raw += value[i];        if(value[i] == '&')            raw += '&';    }    static_cast<QPushButton*>(m_widget)->setText(raw);    static_cast<QPushButton*>(m_widget)->setFont(style()->font());    // this is a QLineEdit/RenderLineEdit compatible sizehint    QFontMetrics fm = fontMetrics( m_widget->font() );    m_widget->constPolish();    QSize ts = fm.size( ShowPrefix, raw );    int h = ts.height() + 8;    int w = ts.width() + 2*fm.width( ' ' );    if ( m_widget->style().guiStyle() == Qt::WindowsStyle && h < 26 )        h = 22;    QSize s = QSize( w + 8, h ).expandedTo( m_widget->minimumSizeHint()).expandedTo( QApplication::globalStrut() );    setIntrinsicWidth( s.width() );    setIntrinsicHeight( s.height() );    RenderButton::calcMinMaxWidth();}QString RenderSubmitButton::defaultLabel() {    return i18n("Submit");}short RenderSubmitButton::baselinePosition( bool f ) const{    return RenderFormElement::baselinePosition( f );}// -------------------------------------------------------------------------------RenderImageButton::RenderImageButton(HTMLInputElementImpl *element)    : RenderImage(element){    m_element = element;    // ### support DOMActivate event when clicked}// -------------------------------------------------------------------------------RenderResetButton::RenderResetButton(QScrollView *view, HTMLInputElementImpl *element)    : RenderSubmitButton(view, element){}QString RenderResetButton::defaultLabel() {    return i18n("Reset");}// -------------------------------------------------------------------------------RenderPushButton::RenderPushButton(QScrollView *view, HTMLInputElementImpl *element)    : RenderSubmitButton(view, element){}QString RenderPushButton::defaultLabel(){    return QString::null;}// -------------------------------------------------------------------------------LineEditWidget::LineEditWidget(QWidget *parent)        : KLineEdit(parent){    setMouseTracking(true);}bool LineEditWidget::event( QEvent *e ){    if ( e->type() == QEvent::AccelAvailable && isReadOnly() ) {        QKeyEvent* ke = (QKeyEvent*) e;        if ( ke->state() & ControlButton ) {            switch ( ke->key() ) {                case Key_Left:                case Key_Right:                case Key_Up:                case Key_Down:                case Key_Home:                case Key_End:                    ke->accept();                default:                break;            }        }    }    return KLineEdit::event( e );}// -----------------------------------------------------------------------------RenderLineEdit::RenderLineEdit(QScrollView *view, HTMLInputElementImpl *element)    : RenderFormElement(view, element){    LineEditWidget *edit = new LineEditWidget(view->viewport());    edit->installEventFilter(this);    connect(edit,SIGNAL(returnPressed()), this, SLOT(slotReturnPressed()));    connect(edit,SIGNAL(textChanged(const QString &)),this,SLOT(slotTextChanged(const QString &)));    if(element->inputType() == HTMLInputElementImpl::PASSWORD)        edit->setEchoMode( QLineEdit::Password );    if ( element->autoComplete() ) {        QStringList completions =            static_cast<KHTMLView *>(view)->formCompletionItems(element->name().string());        if (completions.count()) {            edit->completionObject()->setItems(completions);            edit->setContextMenuEnabled(true);        }    }    setQWidget(edit);}void RenderLineEdit::slotReturnPressed(){    // don't submit the form when return was pressed in a completion-popup    KCompletionBox *box = (static_cast<KLineEdit*>(m_widget))->completionBox(false);    if ( box && box->isVisible() && box->currentItem() != -1 )	return;    HTMLFormElementImpl* fe = m_element->form();    if ( fe )	fe->prepareSubmit();}void RenderLineEdit::calcMinMaxWidth(){    if ( minMaxKnown() ) return;    QFontMetrics fm = fontMetrics( style()->font() );    QSize s;    KLineEdit *edit = static_cast<KLineEdit*>(m_widget);    HTMLInputElementImpl *input = static_cast<HTMLInputElementImpl*>(m_element);    int size = input->size();    int h = fm.height();    int w = fm.width( 'x' ) * (size > 0 ? size : 17); // "some"    if ( edit->frame() ) {        h += 8;        // ### this is not really portable between all styles.        // I think one should try to find a generic solution which        // works with all possible styles. Lars.        // ### well, it is. it's the 1:1 copy of QLineEdit::sizeHint()        // the only reason that made me including this thingie is        // that I cannot get a sizehint for a specific number of characters        // in the lineedit from it. It's not my fault, it's Qt's. Dirk        if ( m_widget->style().guiStyle() == Qt::WindowsStyle && h < 26 )            h = 22;        s = QSize( w + 8, h ).expandedTo( QApplication::globalStrut() );    } else	s = QSize( w + 4, h + 4 ).expandedTo( QApplication::globalStrut() );    setIntrinsicWidth( s.width() );    setIntrinsicHeight( s.height() );    RenderFormElement::calcMinMaxWidth();}void RenderLineEdit::layout(){    if ( layouted() ) return;    KLineEdit *edit = static_cast<KLineEdit*>(m_widget);    HTMLInputElementImpl *input = static_cast<HTMLInputElementImpl*>(m_element);    edit->blockSignals(true);    int pos = edit->cursorPosition();    edit->setText(static_cast<HTMLInputElementImpl*>(m_element)->value().string().visual());    edit->setCursorPosition(pos);    edit->blockSignals(false);    int ml = input->maxLength();    if ( ml < 0 || ml > 1024 )        ml = 1024;    edit->setMaxLength( ml );    edit->setReadOnly(m_element->readOnly());    RenderFormElement::layout();}void RenderLineEdit::slotTextChanged(const QString &string){    // don't use setValue here!    static_cast<HTMLInputElementImpl*>(m_element)->m_value = string;}void RenderLineEdit::select(){    static_cast<LineEditWidget*>(m_widget)->selectAll();}// ---------------------------------------------------------------------------RenderFieldset::RenderFieldset(QScrollView *view,                               HTMLGenericFormElementImpl *element)    : RenderFormElement(view, element){}// -------------------------------------------------------------------------RenderFileButton::RenderFileButton(QScrollView *view, HTMLInputElementImpl *element)    : RenderFormElement(view, element){    QHBox *w = new QHBox(view->viewport());    m_edit = new LineEditWidget(w);    m_edit->installEventFilter(this);    connect(m_edit, SIGNAL(returnPressed()), this, SLOT(slotReturnPressed()));    connect(m_edit, SIGNAL(textChanged(const QString &)),this,SLOT(slotTextChanged(const QString &)));    m_button = new QPushButton(i18n("Browse..."), w);    m_button->setFocusPolicy(QWidget::ClickFocus);    connect(m_button,SIGNAL(clicked()), this, SLOT(slotClicked()));    w->setStretchFactor(m_edit, 2);    w->setFocusProxy(m_edit);    setQWidget(w);    m_haveFocus = false;}void RenderFileButton::calcMinMaxWidth(){    if ( minMaxKnown() ) return;    QFontMetrics fm = fontMetrics( style()->font() );    QSize s;    HTMLInputElementImpl *input = static_cast<HTMLInputElementImpl*>(m_element);    int size = input->size();    int h = fm.height();    int w = fm.width( 'x' ) * (size > 0 ? size : 17);    w += fm.width( m_button->text() ) + 2*fm.width( ' ' );    if ( m_edit->frame() ) {        h += 8;        if ( m_widget->style().guiStyle() == Qt::WindowsStyle && h < 26 )            h = 22;        s = QSize( w + 8, h );    } else        s = QSize( w + 4, h + 4 );    setIntrinsicWidth( s.width() );    setIntrinsicHeight( s.height() );    RenderFormElement::calcMinMaxWidth();}void RenderFileButton::slotClicked(){    QString file_name = KFileDialog::getOpenFileName(QString::null, QString::null, 0, i18n("Browse..."));    if (!file_name.isNull()) {        // ### truncate if > maxLength        static_cast<HTMLInputElementImpl*>(m_element)->setFilename(DOMString(file_name));        m_edit->setText(file_name);    }}void RenderFileButton::layout( ){    // this is largely taken from the RenderLineEdit layout    QFontMetrics fm = fontMetrics( m_edit->font() );    HTMLInputElementImpl *input = static_cast<HTMLInputElementImpl*>(m_element);    m_edit->blockSignals(true);    m_edit->setText(static_cast<HTMLInputElementImpl*>(m_element)->filename().string());    m_edit->blockSignals(false);    int ml = input->maxLength();    if ( ml < 0 || ml > 1024 )        ml = 1024;    m_edit->setMaxLength( ml );    m_edit->setReadOnly(m_element->readOnly());    RenderFormElement::layout();}void RenderFileButton::slotReturnPressed(){    if (m_element->form())	m_element->form()->prepareSubmit();}void RenderFileButton::slotTextChanged(const QString &string){    static_cast<HTMLInputElementImpl*>(m_element)->setFilename(DOMString(string));}void RenderFileButton::select(){    m_edit->selectAll();}// -------------------------------------------------------------------------RenderLabel::RenderLabel(QScrollView *view,                         HTMLGenericFormElementImpl *element)    : RenderFormElement(view, element){}// -------------------------------------------------------------------------RenderLegend::RenderLegend(QScrollView *view,                           HTMLGenericFormElementImpl *element)    : RenderFormElement(view, element){}// -------------------------------------------------------------------------------ComboBoxWidget::ComboBoxWidget(QWidget *parent)    : KComboBox(false, parent){    setAutoMask(true);    if (listBox()) listBox()->installEventFilter(this);    setMouseTracking(true);}bool ComboBoxWidget::event(QEvent *e){    if (e->type()==QEvent::KeyPress)    {	QKeyEvent *ke = static_cast<QKeyEvent *>(e);	switch(ke->key())	{	case Key_Return:	case Key_Enter:	    popup();	    ke->accept();	    return true;	default:	    return KComboBox::event(e);	}    }    return KComboBox::event(e);}bool ComboBoxWidget::eventFilter(QObject *dest, QEvent *e){    if (dest==listBox() &&  e->type()==QEvent::KeyPress)    {	QKeyEvent *ke = static_cast<QKeyEvent *>(e);	bool forward = false;	switch(ke->key())	{	case Key_Tab:	    forward=true;	case Key_BackTab:	    // ugly hack. emulate popdownlistbox() (private in QComboBox)	    // we re-use ke here to store the reference to the generated event.	    ke = new QKeyEvent(QEvent::KeyPress, Key_Escape, 0, 0);	    QApplication::sendEvent(dest,ke);	    focusNextPrevChild(forward);	    delete ke;	    return true;	default:	    return KComboBox::eventFilter(dest, e);	}    }    return KComboBox::eventFilter(dest, e);}// -------------------------------------------------------------------------RenderSelect::RenderSelect(QScrollView *view, HTMLSelectElementImpl *element)    : RenderFormElement(view, element){    m_ignoreSelectEvents = false;    m_multiple = element->multiple();    m_size = element->size();    m_useListBox = (m_multiple || m_size > 1);    if(m_useListBox)        setQWidget(createListBox());    else	setQWidget(createComboBox());}void RenderSelect::calcMinMaxWidth(){    // ### ugly HACK FIXME!!!    if ( !layouted() )        layout();    setLayouted( false );    RenderFormElement::calcMinMaxWidth();}void RenderSelect::layout( ){    // ### maintain selection properly between type/size changes, and work    // out how to handle multiselect->singleselect (probably just select    // first selected one)    // ### reconnect mouse signals when we change widget type

⌨️ 快捷键说明

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