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

📄 q3header.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 4 页
字号:
                p->drawLine(fr.x(), fr.y() + fr.height() - 2,                             fr.x() + fr.width() - 1, fr.y() + fr.height() - 2);            }        }        p->restore();    }}/*!    Paints the label of the section at position \a index, inside    rectangle \a fr (which uses widget coordinates) using painter \a    p.    Called by paintSection()*/void Q3Header::paintSectionLabel(QPainter *p, int index, const QRect& fr){    int section = mapToSection(index);    if (section < 0)        return;    int dx = 0, dy = 0;    QStyleOptionHeader opt = getStyleOption(this, section);    if (d->sortSection == section)        opt.sortIndicator = d->sortDirection ? QStyleOptionHeader::SortDown : QStyleOptionHeader::SortUp;    if (index == handleIdx && (state == Pressed || state == Moving)) {        dx = style()->pixelMetric(QStyle::PM_ButtonShiftHorizontal, &opt, this);        dy = style()->pixelMetric(QStyle::PM_ButtonShiftVertical, &opt, this);        opt.state |= QStyle::State_Sunken;    }    if (isEnabled())        opt.state |= QStyle::State_Enabled;    opt.rect.setRect(fr.x() + style()->pixelMetric(QStyle::PM_HeaderMargin) + dx, fr.y() + 2 + dy,                     fr.width() - 6, fr.height() - 4);    style()->drawControl(QStyle::CE_HeaderLabel, &opt, p, this);    int arrowWidth = (orient == Qt::Horizontal ? height() : width()) / 2;    int arrowHeight = fr.height() - 6;    QSize ssh = sectionSizeHint(section, p->fontMetrics());    int tw = (orient == Qt::Horizontal ? ssh.width() : ssh.height());    int ew = 0;    if (style()->styleHint(QStyle::SH_Header_ArrowAlignment, 0, this) & Qt::AlignRight)        ew = fr.width() - tw - 8;    if (d->sortSection == section && tw <= fr.width()) {        if (reverse()) {            tw = fr.width() - tw;            ew = fr.width() - ew - tw;        }        opt.state = QStyle::State_None;        if (isEnabled())            opt.state |= QStyle::State_Enabled;        if (d->sortDirection)            opt.state |= QStyle::State_DownArrow;        else            opt.state |= QStyle::State_UpArrow;        QRect ar(fr.x() + tw - arrowWidth - 6 + ew, 4, arrowWidth, arrowHeight);        if (label(section).isRightToLeft())            ar.moveBy( 2*(fr.right() - ar.right()) + ar.width() - fr.width(), 0 );        opt.rect = ar;        style()->drawPrimitive(QStyle::PE_IndicatorHeaderArrow, &opt, p, this);    }}/*! \reimp */void Q3Header::paintEvent(QPaintEvent *e){    QPainter p(this);    p.setPen(palette().buttonText().color());    int pos = orient == Qt::Horizontal ? e->rect().left() : e->rect().top();    int id = mapToIndex(sectionAt(pos + offset()));    if (id < 0) {        if (pos > 0)            id = d->count;        else if (reverse())            id = d->count - 1;        else            id = 0;    }    if (reverse()) {        for (int i = id; i >= 0; i--) {            QRect r = sRect(i);            paintSection(&p, i, r);            if (r.right() >= e->rect().right())                return;        }    } else {        if (count() > 0) {            for (int i = id; i <= count(); i++) {                QRect r = sRect(i);                /*                  If the last section is clickable (and thus is                  painted raised), draw the virtual section count()                  as well. Otherwise it looks ugly.                */                if (i < count() || d->clicks[mapToSection(count() - 1)])                    paintSection(&p, i, r);                if (hasFocus() && d->focusIdx == i) {                    QStyleOptionFocusRect opt;                    opt.rect.setRect(r.x()+2, r.y()+2, r.width()-4, r.height()-4);                    opt.palette = palette();                    opt.state = QStyle::State_None;                    style()->drawPrimitive(QStyle::PE_FrameFocusRect, &opt, &p, this);                }                if (orient == Qt::Horizontal && r. right() >= e->rect().right() ||                     orient == Qt::Vertical && r. bottom() >= e->rect().bottom())                    return;            }        }    }}/*!    \overload    Sets the sort indicator to \a ascending. Use the other overload instead.*/void Q3Header::setSortIndicator(int section, bool ascending){    d->sortSection = section;    if (section != -1)        oldHandleIdx = section;    d->sortDirection = ascending;    update();    updateGeometry();}/*!  \fn void Q3Header::setSortIndicator(int section, Qt::SortOrder order)  Sets a sort indicator onto the specified \a section. The indicator's  \a order is either Ascending or Descending.  Only one section can show a sort indicator at any one time. If you  don't want any section to show a sort indicator pass a \a section  number of -1.  \sa sortIndicatorSection(), sortIndicatorOrder()*//*!    Returns the section showing the sort indicator or -1 if there is no sort indicator.    \sa setSortIndicator(), sortIndicatorOrder()*/int Q3Header::sortIndicatorSection() const{    return d->sortSection;}/*!    Returns the implied sort order of the Q3Headers sort indicator.    \sa setSortIndicator(), sortIndicatorSection()*/Qt::SortOrder Q3Header::sortIndicatorOrder() const{    return d->sortDirection ? Qt::AscendingOrder : Qt::DescendingOrder;}/*!    Resizes section \a section to \a s pixels wide (or high).*/void Q3Header::resizeSection(int section, int s){    setCellSize(section, s);    update();}/*!    Returns the width (or height) of the \a section in pixels.*/int Q3Header::sectionSize(int section) const{    if (section < 0 || section >= count())        return 0;    return d->sizes[section];}/*!    Returns the position (in pixels) at which the \a section starts.    \sa offset()*/int Q3Header::sectionPos(int section) const{    if (d->positionsDirty)        ((Q3Header *)this)->calculatePositions();    if (section < 0 || section >= count() )        return 0;    return d->positions[d->s2i[section]];}/*!    Returns the index of the section which contains the position \a    pos given in pixels from the left (or top).    \sa offset()*/int Q3Header::sectionAt(int pos) const{    if (reverse())        pos = d->lastPos - pos;    return d->sectionAt(pos);}/*!    Returns the number of the section that is displayed at index    position \a index.*/int Q3Header::mapToSection(int index) const{    return (index >= 0 && index < count()) ? d->i2s[index] : -1;}/*!    Returns the index position at which section \a section is    displayed.*/int Q3Header::mapToIndex(int section) const{    return (section >= 0 && section < count()) ? d->s2i[section] : -1;}/*!    Moves section \a section to index position \a toIndex.*/void Q3Header::moveSection(int section, int toIndex){    int fromIndex = mapToIndex(section);    if (fromIndex == toIndex ||         fromIndex < 0 || fromIndex > count() ||         toIndex < 0 || toIndex > count())        return;    int i;    int idx = d->i2s[fromIndex];    if (fromIndex < toIndex) {        for (i = fromIndex; i < toIndex - 1; i++) {            int t;            d->i2s[i] = t = d->i2s[i+1];            d->s2i[t] = i;        }        d->i2s[toIndex-1] = idx;        d->s2i[idx] = toIndex-1;    } else {        for (i = fromIndex; i > toIndex; i--) {            int t;            d->i2s[i] = t = d->i2s[i-1];            d->s2i[t] = i;        }        d->i2s[toIndex] = idx;        d->s2i[idx] = toIndex;    }    calculatePositions();}/*!    Returns true if section \a section is clickable; otherwise returns    false.    If \a section is out of range (negative or larger than count() -    1): returns true if all sections are clickable; otherwise returns    false.    \sa setClickEnabled()*/bool Q3Header::isClickEnabled(int section) const{    if (section >= 0 && section < count()) {        return (bool)d->clicks[section];    }    for (int i = 0; i < count(); ++i) {        if (!d->clicks[i])            return false;    }    return true;}/*!    Returns true if section \a section is resizeable; otherwise    returns false.    If \a section is -1 then this function applies to all sections,    i.e. returns true if all sections are resizeable; otherwise    returns false.    \sa setResizeEnabled()*/bool Q3Header::isResizeEnabled(int section) const{    if (section >= 0 && section < count()) {        return (bool)d->resize[section];    }    for (int i = 0; i < count();++i) {        if (!d->resize[i])            return false;    }    return true;}bool Q3Header::isMovingEnabled() const{    return d->move;}/*! \internal */void Q3Header::setUpdatesEnabled(bool enable){    if (enable)        calculatePositions();    QWidget::setUpdatesEnabled(enable);}bool Q3Header::reverse () const{#if 0    return (orient == Qt::Horizontal && QApplication::reverseLayout());#else    return false;#endif}/*! \reimp */void Q3Header::resizeEvent(QResizeEvent *e){    if (e)        QWidget::resizeEvent(e);    if(d->lastPos < width()) {            offs = 0;    }    if (e) {        adjustHeaderSize(orientation() == Qt::Horizontal ?                          width() - e->oldSize().width() : height() - e->oldSize().height());        if ((orientation() == Qt::Horizontal && height() != e->oldSize().height())             || (orientation() == Qt::Vertical && width() != e->oldSize().width()))            update();    } else        adjustHeaderSize();}/*!    \fn void Q3Header::adjustHeaderSize()    Adjusts the size of the sections to fit the size of the header as    completely as possible. Only sections for which isStretchEnabled()    is true will be resized.*/void Q3Header::adjustHeaderSize(int diff){    if (!count())        return;    // we skip the adjustHeaderSize when trying to resize the last column which is set to stretchable    if (d->fullSize == (count() -1) &&         (d->lastPos - d->sizes[count() -1]) > (orient == Qt::Horizontal ? width() : height()))        return;    if (d->fullSize >= 0) {        int sec = mapToSection(d->fullSize);        int lsec = mapToSection(count() - 1);        int ns = sectionSize(sec) +                 (orientation() == Qt::Horizontal ?                   width() : height()) - (sectionPos(lsec) + sectionSize(lsec));        int os = sectionSize(sec);        if (ns < 20)            ns = 20;        setCellSize(sec, ns);        repaint();        emit sizeChange(sec, os, ns);    } else if (d->fullSize == -1) {        int df = diff / count();        int part = orientation() == Qt::Horizontal ? width() / count() : height() / count();        for (int i = 0; i < count() - 1; ++i) {            int sec = mapToIndex(i);            int os = sectionSize(sec);            int ns = diff != -1 ? os + df : part;            if (ns < 20)                ns = 20;            setCellSize(sec, ns);            emit sizeChange(sec, os, ns);        }        int sec = mapToIndex(count() - 1);        int ns = (orientation() == Qt::Horizontal ? width() : height()) - sectionPos(sec);        int os = sectionSize(sec);        if (ns < 20)            ns = 20;        setCellSize(sec, ns);        repaint();        emit sizeChange(sec, os, ns);    }}/*!    Returns the total width of all the header columns.*/int Q3Header::headerWidth() const{    if (d->pos_dirty) {        ((Q3Header*)this)->calculatePositions();        d->pos_dirty = false;    }    return d->lastPos;}void Q3Header::calculatePositions(bool onlyVisible, int start){    d->positionsDirty = false;    d->lastPos = count() > 0 ? d->positions[start] : 0;    for (int i = start; i < count(); i++) {        d->positions[i] = d->lastPos;        d->lastPos += d->sizes[d->i2s[i]];        if (onlyVisible && d->lastPos > offset() +             (orientation() == Qt::Horizontal ? width() : height()))            break;    }    d->pos_dirty = onlyVisible;}/*!    \property Q3Header::stretching    \brief whether the header sections always take up the full width    (or height) of the header*//*!    If \a b is true, section \a section will be resized when the    header is resized, so that the sections take up the full width (or    height for vertical headers) of the header; otherwise section \a    section will be set to be unstretchable and will not resize when    the header is resized.    If \a section is -1, and if \a b is true, then all sections will    be resized equally when the header is resized so that they take up    the full width (or height for vertical headers) of the header;    otherwise all the sections will be set to be unstretchable and    will not resize when the header is resized.    \sa adjustHeaderSize()*/void Q3Header::setStretchEnabled(bool b, int section){    if (b)        d->fullSize = section;    else        d->fullSize = -2;    adjustHeaderSize();}bool Q3Header::isStretchEnabled() const{    return d->fullSize == -1;}/*!    \overload    Returns true if section \a section will resize to take up the full    width (or height) of the header; otherwise returns false. If at    least one section has stretch enabled the sections will always    take up the full width of the header.    \sa setStretchEnabled()*/bool Q3Header::isStretchEnabled(int section) const{    return d->fullSize == section;}/*!  \reimp*/void Q3Header::changeEvent(QEvent *ev){    if(ev->type() == QEvent::FontChange) {        QFontMetrics fm = fontMetrics();        d->height = (orient == Qt::Horizontal) ? fm.lineSpacing() + 6 : fm.width(QLatin1Char(' '));    }    QWidget::changeEvent(ev);}#endif // QT_NO_HEADER

⌨️ 快捷键说明

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