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

Method paintEvent

kdevplatform/sublime/idealtoolbutton.cpp:125–186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

123
124
125void IdealToolButton::paintEvent(QPaintEvent *event)
126{
127 Q_UNUSED(event);
128
129 QStylePainter painter(this);
130 QStyleOptionToolButton option;
131 initStyleOption(&option);
132
133 if (_area == Qt::TopDockWidgetArea || _area == Qt::BottomDockWidgetArea) {
134 // elide text
135 int iconWidth = 0;
136 if (toolButtonStyle() != Qt::ToolButtonTextOnly && !option.icon.isNull()) {
137 iconWidth = option.iconSize.width();
138 }
139
140 // subtract 4 to be consistent with the size calculated by sizeHint, which adds 4,
141 // again to be consistent with QToolButton
142 option.text = fontMetrics().elidedText(text(), Qt::ElideRight, contentsRect().width() - iconWidth - 4);
143 painter.drawComplexControl(QStyle::CC_ToolButton, option);
144 } else {
145 // rotated paint
146 // elide text
147 int iconHeight = 0;
148 if (toolButtonStyle() != Qt::ToolButtonTextOnly && !option.icon.isNull()) {
149 iconHeight = option.iconSize.height();
150 }
151 QString textToDraw = fontMetrics().elidedText(text(), Qt::ElideRight, contentsRect().height() - iconHeight - 4);
152 // first draw normal frame and not text/icon
153 option.text = QString();
154 option.icon = QIcon();
155 painter.drawComplexControl(QStyle::CC_ToolButton, option);
156
157 // rotate the options
158 QSize size( option.rect.size() );
159 size.transpose();
160 option.rect.setSize( size );
161
162 // rotate the painter
163 if(_area == Qt::LeftDockWidgetArea) {
164 painter.translate( 0, height() );
165 painter.rotate( -90 );
166 } else {
167 painter.translate( width(), 0 );
168 painter.rotate( 90 );
169 }
170
171 // paint text and icon
172 option.text = textToDraw;
173
174 QIcon::Mode iconMode = (option.state & QStyle::State_MouseOver) ? QIcon::Active : QIcon::Normal;
175 QPixmap ic = icon().pixmap(option.iconSize, iconMode, QIcon::On);
176 QTransform tf;
177 if(_area == Qt::LeftDockWidgetArea) {
178 tf.rotate(90);
179 } else {
180 tf.rotate(-90);
181 }
182 option.icon = ic.transformed( tf, Qt::SmoothTransformation );

Callers

nothing calls this directly

Calls 6

isNullMethod · 0.80
pixmapMethod · 0.80
QIconClass · 0.70
QStringClass · 0.50
sizeMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected