Changeset 19729 in webkit
- Timestamp:
- Feb 20, 2007 4:30:12 AM (17 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r19728 r19729 1 2007-02-20 Zack Rusin <zrusin@trolltech.com> 2 3 Reviewed by Lars 4 5 Refactor and fix the implementation of theming of 6 form elements on the Qt platform. 7 8 * platform/qt/RenderThemeQt.cpp: 9 (WebCore::theme): 10 (WebCore::RenderThemeQt::RenderThemeQt): 11 (WebCore::RenderThemeQt::supportsHover): 12 (WebCore::RenderThemeQt::supportsFocusRing): 13 (WebCore::RenderThemeQt::baselinePosition): 14 (WebCore::RenderThemeQt::controlSupportsTints): 15 (WebCore::RenderThemeQt::supportsControlTints): 16 (WebCore::RenderThemeQt::adjustRepaintRect): 17 (WebCore::RenderThemeQt::paintResizeControl): 18 (WebCore::RenderThemeQt::platformActiveSelectionBackgroundColor): 19 (WebCore::RenderThemeQt::platformInactiveSelectionBackgroundColor): 20 (WebCore::RenderThemeQt::platformActiveSelectionForegroundColor): 21 (WebCore::RenderThemeQt::platformInactiveSelectionForegroundColor): 22 (WebCore::RenderThemeQt::systemFont): 23 (WebCore::RenderThemeQt::minimumMenuListSize): 24 (WebCore::RenderThemeQt::adjustSliderThumbSize): 25 (WebCore::RenderThemeQt::paintCheckbox): 26 (WebCore::RenderThemeQt::paintRadio): 27 (WebCore::RenderThemeQt::setRadioSize): 28 (WebCore::RenderThemeQt::adjustButtonStyle): 29 (WebCore::RenderThemeQt::setButtonSize): 30 (WebCore::RenderThemeQt::adjustTextFieldStyle): 31 (WebCore::RenderThemeQt::adjustMenuListStyle): 32 (WebCore::RenderThemeQt::paintMenuList): 33 (WebCore::RenderThemeQt::paintMenuListButton): 34 (WebCore::RenderThemeQt::adjustMenuListButtonStyle): 35 (WebCore::RenderThemeQt::paintSliderTrack): 36 (WebCore::RenderThemeQt::paintSliderThumb): 37 (WebCore::RenderThemeQt::paintSearchField): 38 (WebCore::RenderThemeQt::adjustSearchFieldStyle): 39 (WebCore::RenderThemeQt::adjustSearchFieldCancelButtonStyle): 40 (WebCore::RenderThemeQt::paintSearchFieldCancelButton): 41 (WebCore::RenderThemeQt::adjustSearchFieldDecorationStyle): 42 (WebCore::RenderThemeQt::paintSearchFieldDecoration): 43 (WebCore::RenderThemeQt::adjustSearchFieldResultsDecorationStyle): 44 (WebCore::RenderThemeQt::paintSearchFieldResultsDecoration): 45 (WebCore::RenderThemeQt::supportsFocus): 46 (WebCore::RenderThemeQt::getStylePainterAndWidgetFromPaintInfo): 47 (WebCore::RenderThemeQt::applyTheme): 48 (WebCore::RenderThemeQt::setSizeFromFont): 49 (WebCore::RenderThemeQt::sizeForFont): 50 (WebCore::RenderThemeQt::setButtonPadding): 51 (WebCore::RenderThemeQt::setPopupPadding): 52 (WebCore::RenderThemeQt::setPrimitiveSize): 53 * platform/qt/RenderThemeQt.h: Added. 54 1 55 2007-02-19 Lars Naesbye Christensen <lars@naesbye.dk> 2 56 -
trunk/WebCore/platform/qt/RenderThemeQt.cpp
r19395 r19729 2 2 * This file is part of the WebKit project. 3 3 * 4 * Copyright (C) 2006 Dirk Mueller <mueller@kde.org> 4 * Copyright (C) 2006 Zack Rusin <zack@kde.org> 5 * 2006 Dirk Mueller <mueller@kde.org> 5 6 * 2006 Nikolas Zimmermann <zimmermann@kde.org> 6 7 * … … 26 27 #include "config.h" 27 28 29 #include "RenderThemeQt.h" 30 28 31 #include <QApplication> 29 32 #include <QColor> … … 42 45 namespace WebCore { 43 46 44 class RenderThemeQt : public RenderTheme45 {46 public:47 RenderThemeQt() : RenderTheme() { }48 49 // A method asking if the theme's controls actually care about redrawing when hovered.50 virtual bool supportsHover(const RenderStyle*) const { return true; }51 virtual bool supportsFocusRing(const RenderStyle* style) const { return false; }52 53 virtual bool paintCheckbox(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r)54 {55 return paintButton(o, i, r);56 }57 58 virtual void setCheckboxSize(RenderStyle*) const;59 60 virtual bool paintRadio(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r)61 {62 return paintButton(o, i, r);63 }64 65 virtual void setRadioSize(RenderStyle*) const;66 67 virtual void adjustButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const;68 virtual bool paintButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);69 70 virtual void adjustTextFieldStyle(CSSStyleSelector*, RenderStyle*, Element*) const;71 virtual bool paintTextField(RenderObject*, const RenderObject::PaintInfo&, const IntRect&);72 73 virtual bool isControlStyled(const RenderStyle*, const BorderData&,74 const BackgroundLayer&, const Color&) const;75 76 virtual bool controlSupportsTints(const RenderObject*) const;77 78 virtual void systemFont(int propId, FontDescription&) const;79 80 // The platform selection color.81 virtual Color platformActiveSelectionBackgroundColor() const;82 virtual Color platformInactiveSelectionBackgroundColor() const;83 virtual Color platformActiveSelectionForegroundColor() const;84 virtual Color platformInactiveSelectionForegroundColor() const;85 86 void adjustMenuListStyle(CSSStyleSelector*, RenderStyle*, Element*) const;87 bool paintMenuList(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r);88 private:89 void addIntrinsicMargins(RenderStyle*) const;90 void close();91 92 bool supportsFocus(EAppearance) const;93 94 bool getStylePainterAndWidgetFromPaintInfo(const RenderObject::PaintInfo&, QStyle*&, QPainter*&, QWidget*&) const;95 EAppearance applyTheme(QStyleOption&, RenderObject*) const;96 };97 98 47 RenderTheme* theme() 99 48 { … … 102 51 } 103 52 104 bool RenderThemeQt::isControlStyled(const RenderStyle* style, const BorderData& border, 105 const BackgroundLayer& background, const Color& backgroundColor) const 106 { 107 if (style->appearance() == TextFieldAppearance || style->appearance() == TextAreaAppearance) 108 return style->border() != border; 109 110 return RenderTheme::isControlStyled(style, border, background, backgroundColor); 53 RenderThemeQt::RenderThemeQt() 54 : RenderTheme() 55 { 56 } 57 58 bool RenderThemeQt::supportsHover(const RenderStyle*) const 59 { 60 return true; 61 } 62 63 bool RenderThemeQt::supportsFocusRing(const RenderStyle* style) const 64 { 65 return true; 66 } 67 68 short RenderThemeQt::baselinePosition(const RenderObject* o) const 69 { 70 if (o->style()->appearance() == CheckboxAppearance || o->style()->appearance() == RadioAppearance) 71 return o->marginTop() + o->height() - 2; // Same as in old khtml 72 return RenderTheme::baselinePosition(o); 111 73 } 112 74 … … 124 86 } 125 87 88 bool RenderThemeQt::supportsControlTints() const 89 { 90 return true; 91 } 92 93 void RenderThemeQt::adjustRepaintRect(const RenderObject* o, IntRect& r) 94 { 95 switch (o->style()->appearance()) { 96 case CheckboxAppearance: { 97 break; 98 } 99 case RadioAppearance: { 100 break; 101 } 102 case PushButtonAppearance: 103 case ButtonAppearance: { 104 break; 105 } 106 case MenulistAppearance: { 107 break; 108 } 109 default: 110 break; 111 } 112 } 113 114 bool RenderThemeQt::isControlStyled(const RenderStyle* style, const BorderData& border, 115 const BackgroundLayer& background, const Color& backgroundColor) const 116 { 117 if (style->appearance() == TextFieldAppearance || style->appearance() == TextAreaAppearance) 118 return style->border() != border; 119 120 return RenderTheme::isControlStyled(style, border, background, backgroundColor); 121 } 122 123 void RenderThemeQt::paintResizeControl(GraphicsContext*, const IntRect&) 124 { 125 } 126 127 128 Color RenderThemeQt::platformActiveSelectionBackgroundColor() const 129 { 130 QPalette pal = QApplication::palette(); 131 return pal.brush(QPalette::Active, QPalette::Highlight).color(); 132 } 133 134 Color RenderThemeQt::platformInactiveSelectionBackgroundColor() const 135 { 136 QPalette pal = QApplication::palette(); 137 return pal.brush(QPalette::Inactive, QPalette::Highlight).color(); 138 } 139 140 Color RenderThemeQt::platformActiveSelectionForegroundColor() const 141 { 142 QPalette pal = QApplication::palette(); 143 return pal.brush(QPalette::Active, QPalette::HighlightedText).color(); 144 } 145 146 Color RenderThemeQt::platformInactiveSelectionForegroundColor() const 147 { 148 QPalette pal = QApplication::palette(); 149 return pal.brush(QPalette::Inactive, QPalette::HighlightedText).color(); 150 } 151 126 152 void RenderThemeQt::systemFont(int propId, FontDescription& fontDescription) const 127 153 { … … 129 155 } 130 156 131 void RenderThemeQt::addIntrinsicMargins(RenderStyle* style) const 132 { 133 // Cut out the intrinsic margins completely if we end up using a small font size 134 //if (style->fontSize() < 11) 135 // return; 136 137 // Intrinsic margin value. 138 const int m = 2; 139 140 // FIXME: Using width/height alone and not also dealing with min-width/max-width is flawed. 141 if (style->width().isIntrinsicOrAuto()) { 142 if (style->marginLeft().quirk()) 143 style->setMarginLeft(Length(m, Fixed)); 144 145 if (style->marginRight().quirk()) 146 style->setMarginRight(Length(m, Fixed)); 147 } 148 149 if (style->height().isAuto()) { 150 if (style->marginTop().quirk()) 151 style->setMarginTop(Length(m, Fixed)); 152 153 if (style->marginBottom().quirk()) 154 style->setMarginBottom(Length(m, Fixed)); 155 } 156 } 157 158 bool RenderThemeQt::getStylePainterAndWidgetFromPaintInfo(const RenderObject::PaintInfo& i, QStyle*& style, QPainter*& painter, QWidget*& widget) const 159 { 160 painter = (i.context ? static_cast<QPainter*>(i.context->platformContext()) : 0); 161 widget = (painter ? static_cast<QWidget*>(painter->device()) : 0); 162 style = (widget ? widget->style() : 0); 163 164 return (painter && widget && style); 157 int RenderThemeQt::minimumMenuListSize(RenderStyle*) const 158 { 159 const QFontMetrics &fm = QApplication::fontMetrics(); 160 return 7 * fm.width(QLatin1Char('x')); 161 } 162 163 void RenderThemeQt::adjustSliderThumbSize(RenderObject* o) const 164 { 165 RenderTheme::adjustSliderThumbSize(o); 166 } 167 168 bool RenderThemeQt::paintCheckbox(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) 169 { 170 return paintButton(o, i, r); 165 171 } 166 172 … … 187 193 } 188 194 195 bool RenderThemeQt::paintRadio(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) 196 { 197 return paintButton(o, i, r); 198 } 199 189 200 void RenderThemeQt::setRadioSize(RenderStyle* style) const 190 201 { 191 202 // This is the same as checkboxes. 192 203 setCheckboxSize(style); 204 } 205 206 void RenderThemeQt::adjustButtonStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const 207 { 208 // Ditch the border. 209 style->resetBorder(); 210 211 // Height is locked to auto. 212 style->setHeight(Length(Auto)); 213 214 // White-space is locked to pre 215 style->setWhiteSpace(PRE); 216 217 setButtonSize(style); 218 219 setButtonPadding(style); 220 } 221 222 bool RenderThemeQt::paintButton(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) 223 { 224 QStyle* style = 0; 225 QPainter* painter = 0; 226 QWidget* widget = 0; 227 228 if (!getStylePainterAndWidgetFromPaintInfo(i, style, painter, widget)) 229 return true; 230 231 QStyleOptionButton option; 232 option.initFrom(widget); 233 option.rect = r; 234 235 // Get the correct theme data for a button 236 EAppearance appearance = applyTheme(option, o); 237 238 if(appearance == PushButtonAppearance || appearance == ButtonAppearance) 239 style->drawControl(QStyle::CE_PushButton, &option, painter); 240 else if(appearance == RadioAppearance) 241 style->drawControl(QStyle::CE_RadioButton, &option, painter); 242 else if(appearance == CheckboxAppearance) 243 style->drawControl(QStyle::CE_CheckBox, &option, painter); 244 245 return false; 246 } 247 248 void RenderThemeQt::setButtonSize(RenderStyle* style) const 249 { 250 setPrimitiveSize(style); 251 } 252 253 bool RenderThemeQt::paintTextField(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) 254 { 255 QStyle* style = 0; 256 QPainter* painter = 0; 257 QWidget* widget = 0; 258 259 if (!getStylePainterAndWidgetFromPaintInfo(i, style, painter, widget)) 260 return true; 261 262 QStyleOptionFrameV2 panel; 263 panel.initFrom(widget); 264 panel.rect = r; 265 // Get the correct theme data for a button 266 EAppearance appearance = applyTheme(panel, o); 267 Q_ASSERT(appearance == TextFieldAppearance); 268 269 // Now paint the text field. 270 style->drawPrimitive(QStyle::PE_PanelLineEdit, &panel, painter, widget); 271 style->drawPrimitive(QStyle::PE_FrameLineEdit, &panel, painter, widget); 272 273 return false; 274 } 275 276 void RenderThemeQt::adjustTextFieldStyle(CSSStyleSelector*, RenderStyle* style, Element*) const 277 { 278 style->resetBorder(); 279 280 // Height is locked to auto. 281 style->setHeight(Length(Auto)); 282 283 // White-space is locked to pre 284 style->setWhiteSpace(PRE); 285 286 setPrimitiveSize(style); 287 } 288 289 void RenderThemeQt::adjustMenuListStyle(CSSStyleSelector*, RenderStyle* style, Element*) const 290 { 291 style->resetBorder(); 292 293 // Height is locked to auto. 294 style->setHeight(Length(Auto)); 295 296 // White-space is locked to pre 297 style->setWhiteSpace(PRE); 298 299 setPrimitiveSize(style); 300 301 // Add in the padding that we'd like to use. 302 setPopupPadding(style); 303 304 // Our font is locked to the appropriate system font size for the control. To clarify, we first use the CSS-specified font to figure out 305 // a reasonable control size, but once that control size is determined, we throw that font away and use the appropriate 306 // system font for the control size instead. 307 //setFontFromControlSize(selector, style); 308 } 309 310 bool RenderThemeQt::paintMenuList(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) 311 { 312 QStyle* style = 0; 313 QPainter* painter = 0; 314 QWidget* widget = 0; 315 316 if (!getStylePainterAndWidgetFromPaintInfo(i, style, painter, widget)) 317 return true; 318 319 QStyleOptionComboBox opt; 320 opt.initFrom(widget); 321 opt.rect = r; 322 opt.frame = false; 323 324 style->drawComplexControl(QStyle::CC_ComboBox, &opt, painter, widget); 325 return false; 326 } 327 328 329 bool RenderThemeQt::paintMenuListButton(RenderObject* o, const RenderObject::PaintInfo& pi, 330 const IntRect& r) 331 { 332 return RenderTheme::paintMenuListButton(o, pi, r); 333 } 334 335 void RenderThemeQt::adjustMenuListButtonStyle(CSSStyleSelector* selector, RenderStyle* style, 336 Element* e) const 337 { 338 RenderTheme::adjustMenuListButtonStyle(selector, style, e); 339 } 340 341 bool RenderThemeQt::paintSliderTrack(RenderObject* o, const RenderObject::PaintInfo& pi, 342 const IntRect& r) 343 { 344 return RenderTheme::paintSliderTrack(o, pi, r); 345 } 346 347 bool RenderThemeQt::paintSliderThumb(RenderObject* o, const RenderObject::PaintInfo& pi, 348 const IntRect& r) 349 { 350 return RenderTheme::paintSliderThumb(o, pi, r); 351 } 352 353 bool RenderThemeQt::paintSearchField(RenderObject* o, const RenderObject::PaintInfo& pi, 354 const IntRect& r) 355 { 356 return RenderTheme::paintSearchField(o, pi, r); 357 } 358 359 void RenderThemeQt::adjustSearchFieldStyle(CSSStyleSelector* selector, RenderStyle* style, 360 Element* e) const 361 { 362 RenderTheme::adjustSearchFieldStyle(selector, style, e); 363 } 364 365 void RenderThemeQt::adjustSearchFieldCancelButtonStyle(CSSStyleSelector* selector, RenderStyle* style, 366 Element* e) const 367 { 368 RenderTheme::adjustSearchFieldCancelButtonStyle(selector, style, e); 369 } 370 371 bool RenderThemeQt::paintSearchFieldCancelButton(RenderObject* o, const RenderObject::PaintInfo& pi, 372 const IntRect& r) 373 { 374 return RenderTheme::paintSearchFieldCancelButton(o, pi, r); 375 } 376 377 void RenderThemeQt::adjustSearchFieldDecorationStyle(CSSStyleSelector* selector, RenderStyle* style, 378 Element* e) const 379 { 380 RenderTheme::adjustSearchFieldDecorationStyle(selector, style, e); 381 } 382 383 bool RenderThemeQt::paintSearchFieldDecoration(RenderObject* o, const RenderObject::PaintInfo& pi, 384 const IntRect& r) 385 { 386 return RenderTheme::paintSearchFieldDecoration(o, pi, r); 387 } 388 389 void RenderThemeQt::adjustSearchFieldResultsDecorationStyle(CSSStyleSelector* selector, RenderStyle* style, 390 Element* e) const 391 { 392 RenderTheme::adjustSearchFieldResultsDecorationStyle(selector, style, e); 393 } 394 395 bool RenderThemeQt::paintSearchFieldResultsDecoration(RenderObject* o, const RenderObject::PaintInfo& pi, 396 const IntRect& r) 397 { 398 return RenderTheme::paintSearchFieldResultsDecoration(o, pi, r); 193 399 } 194 400 … … 206 412 } 207 413 414 bool RenderThemeQt::getStylePainterAndWidgetFromPaintInfo(const RenderObject::PaintInfo& i, QStyle*& style, 415 QPainter*& painter, QWidget*& widget) const 416 { 417 painter = (i.context ? static_cast<QPainter*>(i.context->platformContext()) : 0); 418 widget = (painter ? static_cast<QWidget*>(painter->device()) : 0); 419 style = (widget ? widget->style() : 0); 420 421 return (painter && widget && style); 422 } 423 208 424 EAppearance RenderThemeQt::applyTheme(QStyleOption& option, RenderObject* o) const 209 425 { … … 237 453 } 238 454 239 void RenderThemeQt::adjustButtonStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const 240 { 241 addIntrinsicMargins(style); 242 } 243 244 void RenderThemeQt::adjustMenuListStyle(CSSStyleSelector*, RenderStyle* style, Element*) const 245 { 246 addIntrinsicMargins(style); 247 } 248 249 bool RenderThemeQt::paintButton(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) 250 { 251 QStyle* style = 0; 252 QPainter* painter = 0; 253 QWidget* widget = 0; 254 255 if (!getStylePainterAndWidgetFromPaintInfo(i, style, painter, widget)) 256 return true; 257 258 QStyleOptionButton option; 259 option.initFrom(widget); 260 option.rect = r; 261 262 // Get the correct theme data for a button 263 EAppearance appearance = applyTheme(option, o); 264 265 if(appearance == PushButtonAppearance || appearance == ButtonAppearance) 266 style->drawControl(QStyle::CE_PushButton, &option, painter); 267 else if(appearance == RadioAppearance) 268 style->drawControl(QStyle::CE_RadioButton, &option, painter); 269 else if(appearance == CheckboxAppearance) 270 style->drawControl(QStyle::CE_CheckBox, &option, painter); 271 272 return false; 273 } 274 275 void RenderThemeQt::adjustTextFieldStyle(CSSStyleSelector*, RenderStyle* style, Element*) const 276 { 277 addIntrinsicMargins(style); 278 } 279 280 bool RenderThemeQt::paintTextField(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) 281 { 282 QStyle* style = 0; 283 QPainter* painter = 0; 284 QWidget* widget = 0; 285 286 if (!getStylePainterAndWidgetFromPaintInfo(i, style, painter, widget)) 287 return true; 288 289 QStyleOptionFrameV2 panel; 290 panel.initFrom(widget); 291 panel.rect = r; 292 // Get the correct theme data for a button 293 EAppearance appearance = applyTheme(panel, o); 294 Q_ASSERT(appearance == TextFieldAppearance); 295 296 // Now paint the text field. 297 style->drawPrimitive(QStyle::PE_PanelLineEdit, &panel, painter, widget); 298 style->drawPrimitive(QStyle::PE_FrameLineEdit, &panel, painter, widget); 299 300 return false; 301 } 302 303 Color RenderThemeQt::platformActiveSelectionBackgroundColor() const 304 { 305 QPalette pal = QApplication::palette(); 306 return pal.brush(QPalette::Active, QPalette::Highlight).color(); 307 } 308 309 Color RenderThemeQt::platformInactiveSelectionBackgroundColor() const 310 { 311 QPalette pal = QApplication::palette(); 312 return pal.brush(QPalette::Inactive, QPalette::Highlight).color(); 313 } 314 315 Color RenderThemeQt::platformActiveSelectionForegroundColor() const 316 { 317 QPalette pal = QApplication::palette(); 318 return pal.brush(QPalette::Active, QPalette::HighlightedText).color(); 319 } 320 321 Color RenderThemeQt::platformInactiveSelectionForegroundColor() const 322 { 323 QPalette pal = QApplication::palette(); 324 return pal.brush(QPalette::Inactive, QPalette::HighlightedText).color(); 325 } 326 327 bool RenderThemeQt::paintMenuList(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) 328 { 329 QStyle* style = 0; 330 QPainter* painter = 0; 331 QWidget* widget = 0; 332 333 if (!getStylePainterAndWidgetFromPaintInfo(i, style, painter, widget)) 334 return true; 335 336 QStyleOptionComboBox opt; 337 opt.initFrom(widget); 338 opt.rect = r; 339 opt.frame = false; 340 style->drawComplexControl(QStyle::CC_ComboBox, &opt, painter, widget); 341 return false; 455 void RenderThemeQt::setSizeFromFont(RenderStyle* style) const 456 { 457 // FIXME: Check is flawed, since it doesn't take min-width/max-width into account. 458 IntSize size = sizeForFont(style); 459 if (style->width().isIntrinsicOrAuto() && size.width() > 0) 460 style->setWidth(Length(size.width(), Fixed)); 461 if (style->height().isAuto() && size.height() > 0) 462 style->setHeight(Length(size.height(), Fixed)); 463 } 464 465 IntSize RenderThemeQt::sizeForFont(RenderStyle* style) const 466 { 467 const QFontMetrics &fm = QApplication::fontMetrics(); 468 QSize size(0, 0); 469 switch (style->appearance()) { 470 case CheckboxAppearance: { 471 break; 472 } 473 case RadioAppearance: { 474 break; 475 } 476 case PushButtonAppearance: 477 case ButtonAppearance: { 478 QSize sz = fm.size(Qt::TextShowMnemonic, QString::fromLatin1("X")); 479 QStyleOptionButton opt; 480 sz = QApplication::style()->sizeFromContents(QStyle::CT_PushButton, 481 &opt, sz, 0); 482 size.setHeight(sz.height()); 483 break; 484 } 485 case MenulistAppearance: { 486 QSize sz; 487 sz.setHeight(qMax(fm.lineSpacing(), 14) + 2); 488 QStyleOptionComboBox opt; 489 sz = QApplication::style()->sizeFromContents(QStyle::CT_ComboBox, 490 &opt, sz, 0); 491 size.setHeight(sz.height()); 492 break; 493 } 494 case TextFieldAppearance: { 495 const int verticalMargin = 1; 496 const int horizontalMargin = 2; 497 int h = qMax(fm.lineSpacing(), 14) + 2*verticalMargin; 498 int w = fm.width(QLatin1Char('x')) * 17 + 2*horizontalMargin; 499 QStyleOptionFrameV2 opt; 500 opt.lineWidth = QApplication::style()->pixelMetric(QStyle::PM_DefaultFrameWidth, 501 &opt, 0); 502 QSize sz = QApplication::style()->sizeFromContents(QStyle::CT_LineEdit, 503 &opt, 504 QSize(w, h).expandedTo(QApplication::globalStrut()), 505 0); 506 size.setHeight(sz.height()); 507 break; 508 } 509 default: 510 break; 511 } 512 return size; 513 } 514 515 void RenderThemeQt::setButtonPadding(RenderStyle* style) const 516 { 517 const int padding = 8; 518 style->setPaddingLeft(Length(padding, Fixed)); 519 style->setPaddingRight(Length(padding, Fixed)); 520 style->setPaddingTop(Length(1, Fixed)); 521 style->setPaddingBottom(Length(0, Fixed)); 522 } 523 524 void RenderThemeQt::setPopupPadding(RenderStyle* style) const 525 { 526 const int padding = 8; 527 style->setPaddingLeft(Length(padding, Fixed)); 528 style->setPaddingRight(Length(padding, Fixed)); 529 style->setPaddingTop(Length(1, Fixed)); 530 style->setPaddingBottom(Length(0, Fixed)); 531 } 532 533 void RenderThemeQt::setPrimitiveSize(RenderStyle* style) const 534 { 535 // If the width and height are both specified, then we have nothing to do. 536 if (!style->width().isIntrinsicOrAuto() && !style->height().isAuto()) 537 return; 538 539 // Use the font size to determine the intrinsic width of the control. 540 setSizeFromFont(style); 342 541 } 343 542
Note: See TracChangeset
for help on using the changeset viewer.