📄 render_form.cpp
字号:
} } return false;}void LineEditWidget::mouseMoveEvent(QMouseEvent *e){ // hack to prevent Qt from calling setCursor on the widget setDragEnabled(false); KLineEdit::mouseMoveEvent(e); setDragEnabled(true);}// -----------------------------------------------------------------------------RenderLineEdit::RenderLineEdit(HTMLInputElementImpl *element) : RenderFormElement(element){ LineEditWidget *edit = new LineEditWidget(element, view(), view()->viewport()); 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 = view()->formCompletionItems(element->name().string()); if (completions.count()) { edit->completionObject()->setItems(completions); edit->setContextMenuEnabled(true); edit->completionBox()->setTabHandling( false ); } } setQWidget(edit);}void RenderLineEdit::setStyle(RenderStyle* _style){ RenderFormElement::setStyle( _style ); widget()->setAlignment(textAlignment());}void RenderLineEdit::highLightWord( unsigned int length, unsigned int pos ){ LineEditWidget* w = static_cast<LineEditWidget*>(m_widget); if ( w ) w->highLightWord( length, pos );}void RenderLineEdit::slotReturnPressed(){ // don't submit the form when return was pressed in a completion-popup KCompletionBox *box = widget()->completionBox(false); if ( box && box->isVisible() && box->currentItem() != -1 ) { box->hide(); return; } // Emit onChange if necessary // Works but might not be enough, dirk said he had another solution at // hand (can't remember which) - David handleFocusOut(); HTMLFormElementImpl* fe = element()->form(); if ( fe ) fe->submitFromKeyboard();}void RenderLineEdit::handleFocusOut(){ if ( widget() && widget()->edited() ) { element()->onChange(); widget()->setEdited( false ); }}void RenderLineEdit::calcMinMaxWidth(){ KHTMLAssert( !minMaxKnown() ); const QFontMetrics &fm = style()->fontMetrics(); QSize s; int size = element()->size(); int h = fm.lineSpacing(); int w = fm.width( 'x' ) * (size > 0 ? size+1 : 17); // "some" s = QSize(w + 2 + 2*widget()->frameWidth(), kMax(h, 14) + 2 + 2*widget()->frameWidth()) .expandedTo(QApplication::globalStrut()); setIntrinsicWidth( s.width() ); setIntrinsicHeight( s.height() ); RenderFormElement::calcMinMaxWidth();}void RenderLineEdit::updateFromElement(){ int ml = element()->maxLength(); if ( ml < 0 || ml > 1024 ) ml = 1024; if ( widget()->maxLength() != ml ) { widget()->setMaxLength( ml ); } if (element()->value().string() != widget()->text()) { widget()->blockSignals(true); int pos = widget()->cursorPosition(); widget()->setText(element()->value().string()); widget()->setEdited( false ); widget()->setCursorPosition(pos); widget()->blockSignals(false); } widget()->setReadOnly(element()->readOnly()); RenderFormElement::updateFromElement();}void RenderLineEdit::slotTextChanged(const QString &string){ // don't use setValue here! element()->m_value = string; element()->m_unsubmittedFormChange = true;}void RenderLineEdit::select(){ static_cast<LineEditWidget*>(m_widget)->selectAll();}// ---------------------------------------------------------------------------RenderFieldset::RenderFieldset(HTMLGenericFormElementImpl *element) : RenderBlock(element){}RenderObject* RenderFieldset::layoutLegend(bool relayoutChildren){ RenderObject* legend = findLegend(); if (legend) { if (relayoutChildren) legend->setNeedsLayout(true); legend->layoutIfNeeded(); int xPos = borderLeft() + paddingLeft() + legend->marginLeft(); if (style()->direction() == RTL) xPos = m_width - paddingRight() - borderRight() - legend->width() - legend->marginRight(); int b = borderTop(); int h = legend->height(); legend->setPos(xPos, kMax((b-h)/2, 0)); m_height = kMax(b,h) + paddingTop(); } return legend;}RenderObject* RenderFieldset::findLegend(){ for (RenderObject* legend = firstChild(); legend; legend = legend->nextSibling()) { if (!legend->isFloatingOrPositioned() && legend->element() && legend->element()->id() == ID_LEGEND) return legend; } return 0;}void RenderFieldset::paintBoxDecorations(PaintInfo& pI, int _tx, int _ty){ //kdDebug( 6040 ) << renderName() << "::paintDecorations()" << endl; RenderObject* legend = findLegend(); if (!legend) return RenderBlock::paintBoxDecorations(pI, _tx, _ty); int w = width(); int h = height() + borderTopExtra() + borderBottomExtra(); int yOff = (legend->yPos() > 0) ? 0 : (legend->height()-borderTop())/2; h -= yOff; _ty += yOff - borderTopExtra(); int my = kMax(_ty,pI.r.y()); int end = kMin( pI.r.y() + pI.r.height(), _ty + h ); int mh = end - my; paintBackground(pI.p, style()->backgroundColor(), style()->backgroundLayers(), my, mh, _tx, _ty, w, h); if ( style()->hasBorder() ) paintBorderMinusLegend(pI.p, _tx, _ty, w, h, style(), legend->xPos(), legend->width());}void RenderFieldset::paintBorderMinusLegend(QPainter *p, int _tx, int _ty, int w, int h, const RenderStyle* style, int lx, int lw){ const QColor& tc = style->borderTopColor(); const QColor& bc = style->borderBottomColor(); EBorderStyle ts = style->borderTopStyle(); EBorderStyle bs = style->borderBottomStyle(); EBorderStyle ls = style->borderLeftStyle(); EBorderStyle rs = style->borderRightStyle(); bool render_t = ts > BHIDDEN; bool render_l = ls > BHIDDEN; bool render_r = rs > BHIDDEN; bool render_b = bs > BHIDDEN; if(render_t) { drawBorder(p, _tx, _ty, _tx + lx, _ty + style->borderTopWidth(), BSTop, tc, style->color(), ts, (render_l && (ls == DOTTED || ls == DASHED || ls == DOUBLE)?style->borderLeftWidth():0), 0); drawBorder(p, _tx+lx+lw, _ty, _tx + w, _ty + style->borderTopWidth(), BSTop, tc, style->color(), ts, 0, (render_r && (rs == DOTTED || rs == DASHED || rs == DOUBLE)?style->borderRightWidth():0)); } if(render_b) drawBorder(p, _tx, _ty + h - style->borderBottomWidth(), _tx + w, _ty + h, BSBottom, bc, style->color(), bs, (render_l && (ls == DOTTED || ls == DASHED || ls == DOUBLE)?style->borderLeftWidth():0), (render_r && (rs == DOTTED || rs == DASHED || rs == DOUBLE)?style->borderRightWidth():0)); if(render_l) { const QColor& lc = style->borderLeftColor(); bool ignore_top = (tc == lc) && (ls >= OUTSET) && (ts == DOTTED || ts == DASHED || ts == SOLID || ts == OUTSET); bool ignore_bottom = (bc == lc) && (ls >= OUTSET) && (bs == DOTTED || bs == DASHED || bs == SOLID || bs == INSET); drawBorder(p, _tx, _ty, _tx + style->borderLeftWidth(), _ty + h, BSLeft, lc, style->color(), ls, ignore_top?0:style->borderTopWidth(), ignore_bottom?0:style->borderBottomWidth()); } if(render_r) { const QColor& rc = style->borderRightColor(); bool ignore_top = (tc == rc) && (rs >= DOTTED || rs == INSET) && (ts == DOTTED || ts == DASHED || ts == SOLID || ts == OUTSET); bool ignore_bottom = (bc == rc) && (rs >= DOTTED || rs == INSET) && (bs == DOTTED || bs == DASHED || bs == SOLID || bs == INSET); drawBorder(p, _tx + w - style->borderRightWidth(), _ty, _tx + w, _ty + h, BSRight, rc, style->color(), rs, ignore_top?0:style->borderTopWidth(), ignore_bottom?0:style->borderBottomWidth()); }}void RenderFieldset::setStyle(RenderStyle* _style){ RenderBlock::setStyle(_style); // WinIE renders fieldsets with display:inline like they're inline-blocks. For us, // an inline-block is just a block element with replaced set to true and inline set // to true. Ensure that if we ended up being inline that we set our replaced flag // so that we're treated like an inline-block. if (isInline()) setReplaced(true);}// -------------------------------------------------------------------------RenderFileButton::RenderFileButton(HTMLInputElementImpl *element) : RenderFormElement(element){ KURLRequester* w = new KURLRequester( view()->viewport(), "__khtml" ); w->setMode(KFile::File | KFile::ExistingOnly); w->completionObject()->setDir(KGlobalSettings::documentPath()); connect(w->lineEdit(), SIGNAL(returnPressed()), this, SLOT(slotReturnPressed())); connect(w->lineEdit(), SIGNAL(textChanged(const QString &)),this,SLOT(slotTextChanged(const QString &))); setQWidget(w); m_haveFocus = false;}void RenderFileButton::calcMinMaxWidth(){ KHTMLAssert( !minMaxKnown() ); const QFontMetrics &fm = style()->fontMetrics(); int size = element()->size(); int h = fm.lineSpacing(); int w = fm.width( 'x' ) * (size > 0 ? size : 17); // "some" KLineEdit* edit = static_cast<KURLRequester*>( m_widget )->lineEdit(); QSize s = edit->style().sizeFromContents(QStyle::CT_LineEdit, edit, QSize(w + 2 + 2*edit->frameWidth(), kMax(h, 14) + 2 + 2*edit->frameWidth())) .expandedTo(QApplication::globalStrut()); QSize bs = static_cast<KURLRequester*>( m_widget )->sizeHint(); setIntrinsicWidth( s.width() + bs.width() ); setIntrinsicHeight( kMax(s.height(), bs.height()) ); RenderFormElement::calcMinMaxWidth();}void RenderFileButton::handleFocusOut(){ if ( widget()->lineEdit() && widget()->lineEdit()->edited() ) { element()->onChange(); widget()->lineEdit()->setEdited( false ); }}void RenderFileButton::updateFromElement(){ KLineEdit* edit = widget()->lineEdit(); edit->blockSignals(true); edit->setText(element()->value().string()); edit->blockSignals(false); int ml = element()->maxLength(); if ( ml < 0 || ml > 1024 ) ml = 1024; edit->setMaxLength( ml ); edit->setEdited( false ); RenderFormElement::updateFromElement();}void RenderFileButton::slotReturnPressed(){ handleFocusOut(); if (element()->form()) element()->form()->submitFromKeyboard();}void RenderFileButton::slotTextChanged(const QString &/*string*/){ element()->m_value = KURL( widget()->url() ).prettyURL( 0, KURL::StripFileProtocol );}void RenderFileButton::select(){ widget()->lineEdit()->selectAll();}// -------------------------------------------------------------------------RenderLabel::RenderLabel(HTMLGenericFormElementImpl *element) : RenderFormElement(element){}// -------------------------------------------------------------------------RenderLegend::RenderLegend(HTMLGenericFormElementImpl *element) : RenderBlock(element){}// -------------------------------------------------------------------------------ComboBoxWidget::ComboBoxWidget(QWidget *parent) : KComboBox(false, parent, "__khtml"){ setAutoMask(true); if (listBox()) listBox()->installEventFilter(this); setMouseTracking(true);}bool ComboBoxWidget::event(QEvent *e){ if (KComboBox::event(e)) return true; 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 false; } } return false;}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(HTMLSelectElementImpl *element) : RenderFormElement(element){ m_ignoreSelectEvents = false; m_multiple = element->multiple(); m_size = element->size(); m_useListBox = (m_multiple || m_size > 1); m_selectionChanged = true; m_optionsChanged = true;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -