QSize CQGroupBox:: minimumSizeHint() const { QFontMetrics fm(titleFont_); int baseWidth = fm.width(title_) + 4; int baseHeight = fm.height(); if (isCheckable()) baseWidth += fm.height() + 4; if (isCollapsible()) baseWidth += fm.height(); QSize size; if (! isCollapsed()) { QStyleOptionGroupBox option; size = style()->sizeFromContents(QStyle::CT_GroupBox, &option, QSize(baseWidth, baseHeight), this); } else { size = QSize(baseWidth, baseHeight); } return size.expandedTo(QWidget::minimumSizeHint()); }
void CQGroupBox:: mouseReleaseEvent(QMouseEvent *e) { if (isCheckable()) { bool inside = checkRect_.contains(e->pos()) || titleRect_.contains(e->pos()); if (inside) { setChecked(! isChecked()); checkPress_ = false; emit clicked(isChecked()); update(); } } if (isCollapsible()) { bool inside = collapseRect_.contains(e->pos()); if (inside) { setCollapsed(! isCollapsed()); collapsePress_ = false; update(); } } QWidget::mouseReleaseEvent(e); }
void CQGroupBox:: mousePressEvent(QMouseEvent *e) { if (isCheckable()) { bool inside = checkRect_.contains(e->pos()) || titleRect_.contains(e->pos()); if (inside) { checkPress_ = true; update(); return; } } if (isCollapsible()) { bool inside = collapseRect_.contains(e->pos()); if (inside) { collapsePress_ = true; update(); return; } } QWidget::mousePressEvent(e); }
void CQGroupBox:: mouseMoveEvent(QMouseEvent *e) { if (isCheckable()) { bool inside = checkRect_.contains(e->pos()) || titleRect_.contains(e->pos()); bool oldCheckPress = checkPress_; if (! checkPress_ && inside) checkPress_ = true; else if ( checkPress_ && ! inside) checkPress_ = false; if (checkPress_ != oldCheckPress) update(); } if (isCollapsible()) { bool inside = collapseRect_.contains(e->pos()); bool oldCollapsePress = collapsePress_; if (! collapsePress_ && inside) collapsePress_ = true; else if ( collapsePress_ && ! inside) collapsePress_ = false; if (collapsePress_ != oldCollapsePress) update(); } QWidget::mouseMoveEvent(e); }
void WPanel::expand() { if (isCollapsible()) { collapseIcon_->showIcon1(); doExpand(); } }
void WPanel::collapse() { if (isCollapsible()) { collapseIcon_->showIcon2(); doCollapse(); } }
void CQGroupBox:: setCollapsed(bool collapsed) { if (collapsed != collapsed_) { collapsed_ = collapsed; if (isCollapsible()) { updateCollapsed(); emit collapse(isCollapsed()); update(); } } }
void CQGroupBox:: paintEvent(QPaintEvent *) { QPainter p(this); p.setRenderHints(QPainter::Antialiasing); p.fillRect(rect(), QBrush(palette().color(QPalette::Background))); QFontMetrics fm(titleFont_); // set check size int checkSize = (isCheckable() ? fm.height() + 4 : 0); // set collapse size int collapseSize = (isCollapsible() ? fm.ascent() : 0); // set text position int textX = 0; int tw = (title_ != "" ? fm.width(title_) : 0); if (titleAlignment_ & Qt::AlignRight) textX = width() - dx_ - tw - collapseSize; else if (titleAlignment_ & Qt::AlignHCenter) textX = (width() - tw - checkSize - collapseSize)/2 + checkSize; else if (titleAlignment_ & Qt::AlignLeft) textX = dx_ + checkSize; int textY = 0; if (titleAlignment_ & Qt::AlignBottom) textY = spaceTop() - fm.descent() - 2; else if (titleAlignment_ & Qt::AlignTop) textY = fm.ascent() + 2; else if (titleAlignment_ & Qt::AlignVCenter) textY = spaceTop()/2 + fm.descent() + 2; // set check position int checkX = textX - checkSize; int checkY = textY - fm.ascent()/2; // set collapse position int collapseX = width() - collapseSize; int collapseY = textY - fm.ascent()/2; // draw top line if (hasLineTop()) { int lineY; if (lineTopAlignment_ & Qt::AlignTop) lineY = 2; else if (lineTopAlignment_ & Qt::AlignVCenter) lineY = spaceTop()/2; else lineY = spaceTop() - 2; p.setPen(lineColor_); p.drawLine(dx_, lineY, width() - 2*dx_, lineY); } // draw title if (title_ != "") { p.setFont(titleFont_); int tw1 = width() - checkSize - collapseSize - 4*dx_; int tw2 = std::min(tw, tw1); titleRect_ = QRect(textX - dx_, textY - fm.ascent() + fm.descent(), tw2 + dx_, fm.height()); p.fillRect(titleRect_, QBrush(palette().color(QPalette::Background))); if (isEnabled()) p.setPen(palette().color(QPalette::Active, QPalette::WindowText)); else p.setPen(palette().color(QPalette::Disabled, QPalette::WindowText)); p.drawText(textX, textY, title_); } // draw bottom line if (lineBottom_) { int lineY; if (lineTopAlignment_ & Qt::AlignTop) lineY = height() - spaceBottom() + 2; else if (lineTopAlignment_ & Qt::AlignVCenter) lineY = height() - spaceBottom()/2; else lineY = height() - 2; p.setPen(lineColor_); p.drawLine(dx_, lineY, width() - 2*dx_, lineY); } //------ // draw check (if checkable) if (isCheckable()) { int checkX1 = checkX + 2; int checkSize1 = checkSize - 4; int checkY1 = checkY - checkSize1/2; checkRect_ = QRect(checkX1, checkY1, checkSize1, checkSize1); p.fillRect(QRect(checkX1 - 2, checkY1 - 2, checkSize1 + 4, checkSize1 + 4), QBrush(palette().color(QPalette::Background))); QStylePainter p(this); QStyleOptionButton opt; opt.initFrom(this); opt.rect = checkRect_; opt.state |= (isChecked() ? QStyle::State_On : QStyle::State_Off); if (checkPress_) opt.state |= QStyle::State_Sunken; #if 0 if (testAttribute(Qt::WA_Hover) && underMouse()) { if (d->hovering) opt.state |= QStyle::State_MouseOver; else opt.state &= ~QStyle::State_MouseOver; } opt.text = d->text; opt.icon = d->icon; opt.iconSize = iconSize(); #endif p.drawControl(QStyle::CE_CheckBox, opt); } //------ // draw collpase state (if collapsible) if (isCollapsible()) { double collapseSize1 = collapseSize - 4; double collapseX1 = collapseX + 2; double collapseY1 = collapseY - collapseSize1/2; double collapseX2 = collapseX1 + collapseSize1; double collapseY2 = collapseY1 + collapseSize1; collapseRect_ = QRect(collapseX1, collapseY1, collapseSize1, collapseSize1); p.fillRect(QRect(collapseX1 - 2, collapseY1 - 2, collapseSize1 + 4, collapseSize1 + 4), QBrush(palette().color(QPalette::Background))); double collapseXM = (collapseX1 + collapseX2)/2; double collapseYM = (collapseY1 + collapseY2)/2; p.setPen(Qt::NoPen); if (collapsePress_) p.setBrush(palette().color(QPalette::Active, QPalette::Dark)); else p.setBrush(palette().color(QPalette::Active, QPalette::Text)); if (! isCollapsed()) { drawArcShape(&p, collapseXM, collapseYM, collapseSize1/2, 90, 3); } else { drawArcShape(&p, collapseXM, collapseYM, collapseSize1/2, -90, 3); } } }