23 #include <QGraphicsView>
25 #include <kcombobox.h>
26 #include <kiconeffect.h>
27 #include <kiconloader.h>
28 #include <kmimetype.h>
32 #include "private/style_p.h"
33 #include "private/focusindicator_p.h"
34 #include "private/themedwidgetinterface_p.h"
40 class ComboBoxPrivate :
public ThemedWidgetInterface<ComboBox>
43 ComboBoxPrivate(ComboBox *comboBox)
44 : ThemedWidgetInterface<ComboBox>(comboBox),
54 void syncActiveRect();
58 FrameSvg *lineEditBackground;
59 FocusIndicator *focusIndicator;
67 void ComboBoxPrivate::syncActiveRect()
69 background->setElementPrefix(
"normal");
71 qreal left, top, right, bottom;
72 background->getMargins(left, top, right, bottom);
74 background->setElementPrefix(
"active");
75 qreal activeLeft, activeTop, activeRight, activeBottom;
76 background->getMargins(activeLeft, activeTop, activeRight, activeBottom);
78 activeRect = QRectF(QPointF(0, 0), q->size());
79 activeRect.adjust(left - activeLeft, top - activeTop,
80 -(right - activeRight), -(bottom - activeBottom));
82 background->setElementPrefix(
"normal");
85 void ComboBoxPrivate::syncBorders()
88 qreal left, top, right, bottom;
90 background->setElementPrefix(
"normal");
91 background->getMargins(left, top, right, bottom);
92 q->setContentsMargins(left, top, right, bottom);
98 q->setFont(q->font());
104 if (q->nativeWidget()->isEditable()) {
105 focusIndicator->setFrameSvg(lineEditBackground);
107 focusIndicator->setFrameSvg(background);
109 focusIndicator->setFlag(QGraphicsItem::ItemStacksBehindParent, !q->nativeWidget()->isEditable() || !lineEditBackground->hasElement(
"hint-focus-over-base"));
115 d(new ComboBoxPrivate(this))
118 d->background->setImagePath(
"widgets/button");
119 d->background->setCacheAllRenderedFrames(
true);
120 d->background->setElementPrefix(
"normal");
121 d->lineEditBackground =
new FrameSvg(
this);
122 d->lineEditBackground->setImagePath(
"widgets/lineedit");
123 d->lineEditBackground->setCacheAllRenderedFrames(
true);
126 setAcceptHoverEvents(
true);
128 d->style = Style::sharedStyle();
130 d->focusIndicator =
new FocusIndicator(
this, d->background);
132 connect(d->background, SIGNAL(repaintNeeded()), SLOT(syncBorders()));
139 Style::doneWithSharedStyle();
144 return static_cast<KComboBox*
>(widget())->currentText();
149 widget()->setStyleSheet(stylesheet);
154 return widget()->styleSheet();
160 widget()->deleteLater();
169 d->setWidget(nativeWidget);
170 nativeWidget->setWindowIcon(QIcon());
172 nativeWidget->setAttribute(Qt::WA_NoSystemBackground);
173 nativeWidget->setStyle(d->style.data());
180 return static_cast<KComboBox*
>(widget());
185 static_cast<KComboBox*
>(widget())->
addItem(text);
190 static_cast<KComboBox*
>(widget())->
clear();
199 d->background->setElementPrefix(
"focus");
200 d->background->resizeFrame(size());
202 d->background->setElementPrefix(
"active");
203 d->background->resizeFrame(d->activeRect.size());
205 d->background->setElementPrefix(
"normal");
206 d->background->resizeFrame(size());
209 QGraphicsProxyWidget::resizeEvent(event);
219 QGraphicsProxyWidget::paint(painter, option, widget);
224 QGraphicsProxyWidget::paint(painter, option, widget);
228 QPixmap bufferPixmap;
232 d->background->setElementPrefix(
"normal");
234 d->background->paintFrame(painter);
237 bufferPixmap = QPixmap(rect().size().toSize());
238 bufferPixmap.fill(Qt::transparent);
240 QPainter buffPainter(&bufferPixmap);
241 d->background->paintFrame(&buffPainter);
242 buffPainter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
243 buffPainter.fillRect(bufferPixmap.rect(), QColor(0, 0, 0, 128));
245 painter->drawPixmap(0, 0, bufferPixmap);
250 QStyleOptionComboBox comboOpt;
254 comboOpt.palette.setColor(
260 comboOpt.editable =
false;
263 QStyle::CE_ComboBoxLabel, &comboOpt, painter,
nativeWidget());
264 comboOpt.rect =
nativeWidget()->style()->subControlRect(
265 QStyle::CC_ComboBox, &comboOpt, QStyle::SC_ComboBoxArrow,
nativeWidget());
267 QStyle::PE_IndicatorArrowDown, &comboOpt, painter,
nativeWidget());
272 QGraphicsProxyWidget::focusInEvent(event);
280 while (!applet && widget) {
281 widget = widget->parentWidget();
290 QEvent closeEvent(QEvent::CloseSoftwareInputPanel);
292 if (
QGraphicsView *view = qobject_cast<QGraphicsView*>(qApp->focusWidget())) {
293 if (view->scene() && view->scene() == scene()) {
294 QApplication::sendEvent(view, &closeEvent);
300 QGraphicsProxyWidget::focusOutEvent(event);
305 d->underMouse =
true;
306 QGraphicsProxyWidget::hoverEnterEvent(event);
311 d->underMouse =
false;
312 QGraphicsProxyWidget::hoverLeaveEvent(event);
317 d->changeEvent(event);
318 QGraphicsProxyWidget::changeEvent(event);
326 while (!applet && widget) {
327 widget = widget->parentWidget();
334 QGraphicsProxyWidget::mousePressEvent(event);
354 #include <combobox.moc>