int QDockWidgetLayout::titleHeight() const { QDockWidget *q = qobject_cast<QDockWidget*>(parentWidget()); if (QWidget *title = widgetForRole(TitleBar)) return perp(verticalTitleBar, title->sizeHint()); QSize closeSize(0, 0); QSize floatSize(0, 0); if (QLayoutItem *item = item_list[CloseButton]) closeSize = item->widget()->sizeHint(); if (QLayoutItem *item = item_list[FloatButton]) floatSize = item->widget()->sizeHint(); int buttonHeight = qMax(perp(verticalTitleBar, closeSize), perp(verticalTitleBar, floatSize)); QFontMetrics titleFontMetrics = q->fontMetrics(); #ifdef Q_WS_MAC if (qobject_cast<QMacStyle *>(q->style())) { //### this breaks on proxy styles. (But is this code still called?) QFont font = qt_app_fonts_hash()->value("QToolButton", q->font()); titleFontMetrics = QFontMetrics(font); } #endif int mw = q->style()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, 0, q); return qMax(buttonHeight + 2, titleFontMetrics.height() + 2*mw); }
int QDockWidgetLayout::minimumTitleWidth() const { QDockWidget *q = qobject_cast<QDockWidget*>(parentWidget()); if (QWidget *title = widgetForRole(TitleBar)) return pick(verticalTitleBar, title->minimumSizeHint()); QSize closeSize(0, 0); QSize floatSize(0, 0); if (hasFeature(q, QDockWidget::DockWidgetClosable)) { if (QLayoutItem *item = item_list[CloseButton]) closeSize = item->widget()->sizeHint(); } if (hasFeature(q, QDockWidget::DockWidgetFloatable)) { if (QLayoutItem *item = item_list[FloatButton]) floatSize = item->widget()->sizeHint(); } int titleHeight = this->titleHeight(); int mw = q->style()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, 0, q); int fw = q->style()->pixelMetric(QStyle::PM_DockWidgetFrameWidth, 0, q); return pick(verticalTitleBar, closeSize) + pick(verticalTitleBar, floatSize) + titleHeight + 2*fw + 3*mw; }
void QDockWidgetLayout::setWidgetForRole(Role r, QWidget *w) { QWidget *old = widgetForRole(r); if (old != 0) { old->hide(); removeWidget(old); } if (w != 0) { addChildWidget(w); item_list[r] = new QWidgetItemV2(w); w->show(); } else { item_list[r] = 0; } invalidate(); }
int QDockWidgetLayout::titleHeight() const { QDockWidget *q = qobject_cast<QDockWidget*>(parentWidget()); if (QWidget *title = widgetForRole(TitleBar)) return perp(verticalTitleBar, title->sizeHint()); QSize closeSize(0, 0); QSize floatSize(0, 0); if (QLayoutItem *item = item_list[CloseButton]) closeSize = item->widget()->sizeHint(); if (QLayoutItem *item = item_list[FloatButton]) floatSize = item->widget()->sizeHint(); int buttonHeight = qMax(perp(verticalTitleBar, closeSize), perp(verticalTitleBar, floatSize)); QFontMetrics titleFontMetrics = q->fontMetrics(); int mw = q->style()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, 0, q); return qMax(buttonHeight + 2, titleFontMetrics.height() + 2*mw); }