MCPcopy Create free account
hub / github.com/KDE/kdevelop / sizeHint

Method sizeHint

kdevplatform/sublime/idealtoolbutton.cpp:56–94  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54}
55
56QSize IdealToolButton::sizeHint() const
57{
58 ensurePolished();
59
60 QStyleOptionToolButton opt;
61 initStyleOption(&opt);
62
63 QFontMetrics fm = fontMetrics();
64
65 const int charWidth = fm.horizontalAdvance(QLatin1Char('x'));
66 QSize textSize;
67 // Use text size only if we request text
68 if (toolButtonStyle() != Qt::ToolButtonIconOnly || opt.icon.isNull()) {
69 textSize = fm.size(Qt::TextShowMnemonic, opt.text);
70 textSize.rwidth() += 2 * charWidth;
71 }
72
73 int iconwidth = 0, iconheight = 0;
74 // Use icon size only if it's requested and the icon is valid
75 if (toolButtonStyle() != Qt::ToolButtonTextOnly && !opt.icon.isNull()) {
76 if (_area == Qt::TopDockWidgetArea || _area == Qt::BottomDockWidgetArea) {
77 iconwidth = opt.iconSize.width();
78 iconheight = opt.iconSize.height();
79 } else {
80 iconwidth = opt.iconSize.height();
81 iconheight = opt.iconSize.width();
82 }
83 }
84 // adding +4 to be consistent with qtoolbutton
85 int width = textSize.width() + iconwidth + 4;
86 int height = qMax(textSize.height(), iconheight);
87 QSize size = style()->sizeFromContents(QStyle::CT_ToolButton, &opt, QSize(width, height), this);
88
89 if (orientation() == Qt::Vertical) {
90 return QSize(size.height(), size.width()); // transposed
91 } else {
92 return size;
93 }
94}
95
96QSize IdealToolButton::minimumSizeHint() const
97{

Callers 3

addActionMethod · 0.45
addWidgetMethod · 0.45

Calls 2

isNullMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected