void DirectionalButton::updateTextBaseGeometry() { ILOG_TRACE_W(ILX_DIRBUTTON); int textHeight = textExtents().height(); int iconW = 0; int iconH = 0; int wUsed = stylist()->defaultParameter(StyleHint::ToolButtonLR); int x = stylist()->defaultParameter(StyleHint::ToolButtonLeft); if (_icon) { if (!_icon->size().isValid()) _icon->setSize(_icon->preferredSize()); iconW = _icon->width(); iconH = _icon->height(); _icon->moveTo(x, (height() - iconH) / 2); x += iconW + stylist()->defaultParameter(StyleHint::ButtonOffset); wUsed += iconW + stylist()->defaultParameter(StyleHint::ButtonOffset); } _layout.setBounds(x, (height() - textHeight) / 2, width() - wUsed, textHeight); _layout.doLayout(font()); }
Size DirectionalButton::preferredSize() const { ILOG_TRACE_W(ILX_DIRBUTTON); int imgW = 0; int imgH = 0; if (_icon) { Size s; if (_icon->size().isValid()) s = _icon->size(); else s = _icon->preferredSize(); imgW = s.width(); imgH = s.height(); } Size s = textExtents(); int w = 0; if (!text().empty()) { if (_icon) w = stylist()->defaultParameter(StyleHint::ButtonOffset); w += s.width(); } return Size(w + imgW + stylist()->defaultParameter(StyleHint::ToolButtonLR), std::max(s.height(), imgH) + stylist()->defaultParameter(StyleHint::ToolButtonTB)); }
Size CheckBox::preferredSize() const { ILOG_TRACE_W(ILX_CHECKBOX); int w = stylist()->defaultParameter(StyleHint::CheckBoxWidth); int h = stylist()->defaultParameter(StyleHint::CheckBoxHeight); if (!text().empty()) { Size s = textExtents(); w += stylist()->defaultParameter(StyleHint::ButtonOffset) + s.width(); h = std::max(s.height(), h); } return Size(w, h); }
void ToolButton::updateTextBaseGeometry() { ILOG_TRACE_W(ILX_TOOLBUTTON); int textHeight = textExtents().height(); int iconW = 0; int iconH = 0; int wUsed = drawFrame() ? stylist()->defaultParameter(StyleHint::ToolButtonLR) : 0; int x = drawFrame() ? stylist()->defaultParameter(StyleHint::ToolButtonLeft) : 0; int yTop = drawFrame() ? stylist()->defaultParameter(StyleHint::ToolButtonTop) : 0; if (checkable()) { if ((_toolButtonStyle == TextOnly) || (_toolButtonStyle == IconOnly) || (_toolButtonStyle == IconBeforeText)) { x += stylist()->defaultParameter(StyleHint::ToolButtonIndicator) + stylist()->defaultParameter(StyleHint::ButtonOffset); wUsed += stylist()->defaultParameter(StyleHint::ToolButtonIndicator) + stylist()->defaultParameter(StyleHint::ButtonOffset); } } if (_icon) { if (!_icon->size().isValid()) _icon->setSize(_icon->preferredSize()); iconW = _icon->width(); iconH = _icon->height() + 1; } if (_toolButtonStyle == TextOnly) { int y = (height() - textHeight) / 2; _layout.setBounds(x, y, width() - wUsed, textHeight); } else if (_toolButtonStyle == IconOnly) { _icon->moveTo(x, (height() - iconH) / 2); _layout.setBounds(0, 0, 0, 0); return; } else if (_toolButtonStyle == IconBeforeText) { if (iconW) { _icon->moveTo(x, (height() - iconH) / 2); x += iconW + stylist()->defaultParameter(StyleHint::ButtonOffset); wUsed += iconW + stylist()->defaultParameter(StyleHint::ButtonOffset); } _layout.setBounds(x, (height() - textHeight) / 2, width() - wUsed, textHeight); } else if (_toolButtonStyle == IconBelowText) { _layout.setBounds(x, yTop, width() - wUsed, textHeight); if (iconW) _icon->moveTo((width() - iconW) / 2, yTop + textHeight + 1 + stylist()->defaultParameter(StyleHint::ButtonOffset)); } else // IconAboveText { if (iconW) { _icon->moveTo((width() - iconW) / 2, yTop + 1); yTop += iconH + stylist()->defaultParameter(StyleHint::ButtonOffset) + 1; } _layout.setBounds(x, yTop, width() - wUsed, textHeight); } _layout.doLayout(font()); }
Size ToolButton::preferredSize() const { ILOG_TRACE_W(ILX_TOOLBUTTON); if (text().empty() && !icon()) return stylist()->defaultSize(StyleHint::PushButton); int w = (_tbOptions & DrawFrame) ? stylist()->defaultParameter(StyleHint::ToolButtonLR) : 0; int h = (_tbOptions & DrawFrame) ? stylist()->defaultParameter(StyleHint::ToolButtonTB) : 0; if (checkable()) { if ((_toolButtonStyle == IconBelowText) || (_toolButtonStyle == IconAboveText)) h += stylist()->defaultParameter(StyleHint::ToolButtonIndicator) + stylist()->defaultParameter(StyleHint::ButtonOffset); else w += stylist()->defaultParameter(StyleHint::ToolButtonIndicator) + stylist()->defaultParameter(StyleHint::ButtonOffset); } if (_toolButtonStyle == TextOnly) { Size s = textExtents(); if (s.isValid()) return Size(w + s.width(), h + s.height()); return stylist()->defaultSize(StyleHint::PushButton); } // calculate image size int imgW = 0; int imgH = 0; if (_icon) { Size s; if (_icon->size().isValid()) s = _icon->size(); else s = _icon->preferredSize(); imgW = s.width(); imgH = s.height() + 2; // 1px for button down movement } if (_toolButtonStyle == IconOnly) { ILOG_DEBUG(ILX_TOOLBUTTON, " -> icon only: %d, %d\n", w + imgW, h + imgH); if (imgW) return Size(w + imgW, h + imgH); return stylist()->defaultSize(StyleHint::PushButton); } else { Size s = textExtents(); if (s.isValid() && imgW) { if (_toolButtonStyle == IconBeforeText) { w += imgW + stylist()->defaultParameter(StyleHint::ButtonOffset) + s.width(); h += std::max(s.height(), imgH); return Size(w, h); } else { // IconBelowText or IconAboveText w += std::max(imgW, s.width()); h += imgH + s.height() + stylist()->defaultParameter(StyleHint::ButtonOffset); return Size(w, h); } } else if (imgW) return Size(w + imgW, h + imgH); else return Size(w + s.width(), h + s.height()); } }