diff options
author | Joerg Bornemann <joerg.bornemann@nokia.com> | 2009-10-21 10:14:30 (GMT) |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@nokia.com> | 2009-10-21 10:17:45 (GMT) |
commit | 3ce94323a886abf6047135f188a6e10082a3e28d (patch) | |
tree | 29b98a536b1b760326287d4d1479e142cc002b5a /src/gui | |
parent | 895046d54eee97d838dea1fdcb34a7dff3d91f98 (diff) | |
download | Qt-3ce94323a886abf6047135f188a6e10082a3e28d.zip Qt-3ce94323a886abf6047135f188a6e10082a3e28d.tar.gz Qt-3ce94323a886abf6047135f188a6e10082a3e28d.tar.bz2 |
fix editable comboboxes in the Windows mobile style
In editable QComboBoxes we used cutting-edge technology to display the
text. But that's not always wanted. We actually want to see all pixels
of a string like "why oh why". The lower edge was cut off.
Reviewed-by: thartman
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/styles/qwindowsmobilestyle.cpp | 104 |
1 files changed, 73 insertions, 31 deletions
diff --git a/src/gui/styles/qwindowsmobilestyle.cpp b/src/gui/styles/qwindowsmobilestyle.cpp index a617102..5fa6251 100644 --- a/src/gui/styles/qwindowsmobilestyle.cpp +++ b/src/gui/styles/qwindowsmobilestyle.cpp @@ -5592,8 +5592,43 @@ void QWindowsMobileStyle::drawControl(ControlElement element, const QStyleOption painter->drawLine(rect.bottomLeft(), rect.bottomRight()); } #endif // QT_NO_SCROLLAREA - break; } - + break; + } +#ifndef QT_NO_COMBOBOX + case CE_ComboBoxLabel: + // This is copied from qcommonstyle.cpp with the difference, that + // the editRect isn't adjusted when calling drawItemText. + if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) { + QRect editRect = proxy()->subControlRect(CC_ComboBox, cb, SC_ComboBoxEditField, widget); + painter->save(); + painter->setClipRect(editRect); + if (!cb->currentIcon.isNull()) { + QIcon::Mode mode = cb->state & State_Enabled ? QIcon::Normal + : QIcon::Disabled; + QPixmap pixmap = cb->currentIcon.pixmap(cb->iconSize, mode); + QRect iconRect(editRect); + iconRect.setWidth(cb->iconSize.width() + 4); + iconRect = alignedRect(cb->direction, + Qt::AlignLeft | Qt::AlignVCenter, + iconRect.size(), editRect); + if (cb->editable) + painter->fillRect(iconRect, option->palette.brush(QPalette::Base)); + proxy()->drawItemPixmap(painter, iconRect, Qt::AlignCenter, pixmap); + + if (cb->direction == Qt::RightToLeft) + editRect.translate(-4 - cb->iconSize.width(), 0); + else + editRect.translate(cb->iconSize.width() + 4, 0); + } + if (!cb->currentText.isEmpty() && !cb->editable) { + proxy()->drawItemText(painter, editRect, + visualAlignment(cb->direction, Qt::AlignLeft | Qt::AlignVCenter), + cb->palette, cb->state & State_Enabled, cb->currentText); + } + painter->restore(); + } + break; +#endif // QT_NO_COMBOBOX #ifndef QT_NO_DOCKWIDGET case CE_DockWidgetTitle: if (const QStyleOptionDockWidget *dwOpt = qstyleoption_cast<const QStyleOptionDockWidget *>(option)) { @@ -6154,24 +6189,24 @@ void QWindowsMobileStyle::drawComplexControl(ComplexControl control, const QStyl qDrawPlainRect(painter, option->rect, option->palette.shadow().color(), proxy()->pixelMetric(PM_ComboBoxFrameWidth, option, widget), &editBrush); else painter->fillRect(option->rect, editBrush); - State flags = State_None; - QRect ar = proxy()->subControlRect(CC_ComboBox, cmb, SC_ComboBoxArrow, widget); - if ((option->state & State_On)) { - painter->fillRect(ar.adjusted(0, 0, 1, 1),cmb->palette.brush(QPalette::Shadow)); - } - if (d->doubleControls) - ar.adjust(5, 0, 5, 0); - else - ar.adjust(2, 0, -2, 0); - if (option->state & State_Enabled) - flags |= State_Enabled; - if (option->state & State_On) - flags |= State_Sunken; - QStyleOption arrowOpt(0); - arrowOpt.rect = ar; - arrowOpt.palette = cmb->palette; - arrowOpt.state = flags; - proxy()->drawPrimitive(PrimitiveElement(PE_IndicatorArrowDownBig), &arrowOpt, painter, widget); + State flags = State_None; + QRect ar = proxy()->subControlRect(CC_ComboBox, cmb, SC_ComboBoxArrow, widget); + if ((option->state & State_On)) { + painter->fillRect(ar.adjusted(0, 0, 1, 1),cmb->palette.brush(QPalette::Shadow)); + } + if (d->doubleControls) + ar.adjust(5, 0, 5, 0); + else + ar.adjust(2, 0, -2, 0); + if (option->state & State_Enabled) + flags |= State_Enabled; + if (option->state & State_On) + flags |= State_Sunken; + QStyleOption arrowOpt(0); + arrowOpt.rect = ar; + arrowOpt.palette = cmb->palette; + arrowOpt.state = flags; + proxy()->drawPrimitive(PrimitiveElement(PE_IndicatorArrowDownBig), &arrowOpt, painter, widget); if (cmb->subControls & SC_ComboBoxEditField) { QRect re = proxy()->subControlRect(CC_ComboBox, cmb, SC_ComboBoxEditField, widget); if (cmb->state & State_HasFocus && !cmb->editable) @@ -6335,7 +6370,7 @@ QSize QWindowsMobileStyle::sizeFromContents(ContentsType type, const QStyleOptio case CT_ComboBox: if (const QStyleOptionComboBox *comboBox = qstyleoption_cast<const QStyleOptionComboBox *>(option)) { int fw = comboBox->frame ? proxy()->pixelMetric(PM_ComboBoxFrameWidth, option, widget) * 2 : 0; - newSize = QSize(newSize.width() + fw + 9, newSize.height() + fw-4); //Nine is a magic Number - See CommonStyle for real magic (23) + newSize = QSize(newSize.width() + fw + 9, newSize.height() + fw); //Nine is a magic Number - See CommonStyle for real magic (23) } break; #endif @@ -6618,14 +6653,21 @@ QRect QWindowsMobileStyle::subControlRect(ComplexControl control, const QStyleOp switch (subControl) { case SC_ComboBoxArrow: rect.setRect(xpos, y + bmarg, he - 2*bmarg, he - 2*bmarg); - rect.setRect(xpos, y + bmarg, int((he - 2*bmarg)), he - 2*bmarg); break; - case SC_ComboBoxEditField: - rect.setRect(x + margin+4, y + margin+2, wi - 4 * margin - int((he - 2*bmarg) * 0.84f) -2, he - 2 * margin-4); - break; - case SC_ComboBoxFrame: - rect = comboBox->rect; - break; + case SC_ComboBoxEditField: + rect.setRect(x + margin, y + margin, wi - 2 * margin - int((he - 2*bmarg) * 0.84f), he - 2 * margin); + if (d->doubleControls) { + if (comboBox->editable) + rect.adjust(2, 0, 0, 0); + else + rect.adjust(4, 2, 0, -2); + } else if (!comboBox->editable) { + rect.adjust(2, 1, 0, -1); + } + break; + case SC_ComboBoxFrame: + rect = comboBox->rect; + break; default: break; } @@ -6999,7 +7041,7 @@ int QWindowsMobileStyle::pixelMetric(PixelMetric pm, const QStyleOption *opt, co } else { d->doubleControls ? ret = 36 : ret = 18; } - break; + break; case PM_ScrollBarExtent: { if (d->smartphone) @@ -7055,7 +7097,7 @@ int QWindowsMobileStyle::pixelMetric(PixelMetric pm, const QStyleOption *opt, co break; case PM_TextCursorWidth: ret = 2; - break; + break; case PM_TabBar_ScrollButtonOverlap: ret = 0; break; @@ -7089,7 +7131,7 @@ int QWindowsMobileStyle::styleHint(StyleHint hint, const QStyleOption *opt, cons #endif case SH_ToolBar_Movable: ret = false; - break; + break; case SH_ScrollBar_ContextMenu: ret = false; break; |