Changeset View
Changeset View
Standalone View
Standalone View
kstyle/breezestyle.cpp
- This file is larger than 256 KB, so syntax highlighting is disabled by default.
Show First 20 Lines • Show All 2546 Lines • ▼ Show 20 Line(s) | 155 | { | |||
---|---|---|---|---|---|
2547 | 2547 | | |||
2548 | //______________________________________________________________ | 2548 | //______________________________________________________________ | ||
2549 | QSize Style::lineEditSizeFromContents( const QStyleOption* option, const QSize& contentsSize, const QWidget* widget ) const | 2549 | QSize Style::lineEditSizeFromContents( const QStyleOption* option, const QSize& contentsSize, const QWidget* widget ) const | ||
2550 | { | 2550 | { | ||
2551 | // cast option and check | 2551 | // cast option and check | ||
2552 | const auto frameOption( qstyleoption_cast<const QStyleOptionFrame*>( option ) ); | 2552 | const auto frameOption( qstyleoption_cast<const QStyleOptionFrame*>( option ) ); | ||
2553 | if( !frameOption ) return contentsSize; | 2553 | if( !frameOption ) return contentsSize; | ||
2554 | 2554 | | |||
2555 | // output | ||||
2556 | QSize size(contentsSize); | ||||
2557 | | ||||
2558 | // force height consistency | ||||
2559 | size.setHeight(frameOption->fontMetrics.height()); | ||||
2560 | | ||||
2555 | const bool flat( frameOption->lineWidth == 0 ); | 2561 | const bool flat( frameOption->lineWidth == 0 ); | ||
2556 | const int frameWidth( pixelMetric( PM_DefaultFrameWidth, option, widget ) ); | 2562 | const int frameWidth( pixelMetric( PM_DefaultFrameWidth, option, widget ) ); | ||
2557 | return flat ? contentsSize : expandSize( contentsSize, frameWidth ); | 2563 | return flat ? size : expandSize( size, frameWidth ); | ||
2558 | } | 2564 | } | ||
2559 | 2565 | | |||
2560 | //______________________________________________________________ | 2566 | //______________________________________________________________ | ||
2561 | QSize Style::comboBoxSizeFromContents( const QStyleOption* option, const QSize& contentsSize, const QWidget* widget ) const | 2567 | QSize Style::comboBoxSizeFromContents( const QStyleOption* option, const QSize& contentsSize, const QWidget* widget ) const | ||
2562 | { | 2568 | { | ||
2563 | 2569 | | |||
2564 | // cast option and check | 2570 | // cast option and check | ||
2565 | const auto comboBoxOption( qstyleoption_cast<const QStyleOptionComboBox*>( option ) ); | 2571 | const auto comboBoxOption( qstyleoption_cast<const QStyleOptionComboBox*>( option ) ); | ||
2566 | if( !comboBoxOption ) return contentsSize; | 2572 | if( !comboBoxOption ) return contentsSize; | ||
2567 | 2573 | | |||
2568 | // copy size | 2574 | // copy size | ||
2569 | QSize size( contentsSize ); | 2575 | QSize size( contentsSize ); | ||
2570 | 2576 | | |||
2577 | // force height consistency | ||||
2578 | size.setHeight(comboBoxOption->fontMetrics.height()); | ||||
2579 | | ||||
2571 | // add relevant margin | 2580 | // add relevant margin | ||
2572 | const bool flat( !comboBoxOption->frame ); | 2581 | const bool flat( !comboBoxOption->frame ); | ||
2573 | const int frameWidth( pixelMetric( PM_ComboBoxFrameWidth, option, widget ) ); | 2582 | const int frameWidth( pixelMetric( PM_ComboBoxFrameWidth, option, widget ) ); | ||
2574 | if( !flat ) size = expandSize( size, frameWidth ); | 2583 | if( !flat ) size = expandSize( size, frameWidth ); | ||
2575 | 2584 | | |||
2576 | // make sure there is enough height for the button | | |||
2577 | size.setHeight( qMax( size.height(), int(Metrics::MenuButton_IndicatorWidth) ) ); | | |||
2578 | | ||||
2579 | // add button width and spacing | 2585 | // add button width and spacing | ||
2580 | size.rwidth() += Metrics::MenuButton_IndicatorWidth+2; | 2586 | size.rwidth() += Metrics::MenuButton_IndicatorWidth+2; | ||
2581 | 2587 | | |||
2582 | return size; | 2588 | return size; | ||
2583 | 2589 | | |||
2584 | } | 2590 | } | ||
2585 | 2591 | | |||
2586 | //______________________________________________________________ | 2592 | //______________________________________________________________ | ||
2587 | QSize Style::spinBoxSizeFromContents( const QStyleOption* option, const QSize& contentsSize, const QWidget* widget ) const | 2593 | QSize Style::spinBoxSizeFromContents( const QStyleOption* option, const QSize& contentsSize, const QWidget* widget ) const | ||
2588 | { | 2594 | { | ||
2589 | 2595 | | |||
2590 | // cast option and check | 2596 | // cast option and check | ||
2591 | const auto spinBoxOption( qstyleoption_cast<const QStyleOptionSpinBox*>( option ) ); | 2597 | const auto spinBoxOption( qstyleoption_cast<const QStyleOptionSpinBox*>( option ) ); | ||
2592 | if( !spinBoxOption ) return contentsSize; | 2598 | if( !spinBoxOption ) return contentsSize; | ||
2593 | 2599 | | |||
2594 | const bool flat( !spinBoxOption->frame ); | 2600 | const bool flat( !spinBoxOption->frame ); | ||
2595 | 2601 | | |||
2596 | // copy size | 2602 | // copy size | ||
2597 | QSize size( contentsSize ); | 2603 | QSize size( contentsSize ); | ||
2598 | 2604 | | |||
2605 | // force height consistency | ||||
2606 | size.setHeight(spinBoxOption->fontMetrics.height()); | ||||
2607 | | ||||
2599 | // add editor margins | 2608 | // add editor margins | ||
2600 | const int frameWidth( pixelMetric( PM_SpinBoxFrameWidth, option, widget ) ); | 2609 | const int frameWidth( pixelMetric( PM_SpinBoxFrameWidth, option, widget ) ); | ||
2601 | if( !flat ) size = expandSize( size, frameWidth ); | 2610 | if( !flat ) size = expandSize( size, frameWidth ); | ||
2602 | 2611 | | |||
2603 | // make sure there is enough height for the button | | |||
2604 | size.setHeight( qMax( size.height(), int(Metrics::SpinBox_ArrowButtonWidth) ) ); | | |||
2605 | | ||||
2606 | // add button width and spacing | 2612 | // add button width and spacing | ||
2607 | size.rwidth() += Metrics::SpinBox_ArrowButtonWidth; | 2613 | size.rwidth() += Metrics::SpinBox_ArrowButtonWidth; | ||
2608 | 2614 | | |||
2609 | return size; | 2615 | return size; | ||
2610 | 2616 | | |||
2611 | } | 2617 | } | ||
2612 | 2618 | | |||
2613 | //______________________________________________________________ | 2619 | //______________________________________________________________ | ||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | |||||
2658 | QSize Style::pushButtonSizeFromContents( const QStyleOption* option, const QSize& contentsSize, const QWidget* widget ) const | 2664 | QSize Style::pushButtonSizeFromContents( const QStyleOption* option, const QSize& contentsSize, const QWidget* widget ) const | ||
2659 | { | 2665 | { | ||
2660 | 2666 | | |||
2661 | // cast option and check | 2667 | // cast option and check | ||
2662 | const auto buttonOption( qstyleoption_cast<const QStyleOptionButton*>( option ) ); | 2668 | const auto buttonOption( qstyleoption_cast<const QStyleOptionButton*>( option ) ); | ||
2663 | if( !buttonOption ) return contentsSize; | 2669 | if( !buttonOption ) return contentsSize; | ||
2664 | 2670 | | |||
2665 | // output | 2671 | // output | ||
2666 | QSize size; | 2672 | QSize size(contentsSize); | ||
2667 | 2673 | | |||
2668 | // check text and icon | 2674 | // check text and icon | ||
2669 | const bool hasText( !buttonOption->text.isEmpty() ); | 2675 | const bool hasText( !buttonOption->text.isEmpty() ); | ||
2670 | const bool flat( buttonOption->features & QStyleOptionButton::Flat ); | 2676 | const bool flat( buttonOption->features & QStyleOptionButton::Flat ); | ||
2671 | bool hasIcon( !buttonOption->icon.isNull() ); | 2677 | bool hasIcon( !buttonOption->icon.isNull() ); | ||
2672 | 2678 | | |||
2673 | if( !( hasText||hasIcon ) ) | 2679 | if( hasText || hasIcon ) | ||
2674 | { | 2680 | { | ||
2675 | 2681 | | |||
2676 | /* | 2682 | /* | ||
2677 | no text nor icon is passed. | | |||
2678 | assume custom button and use contentsSize as a starting point | | |||
2679 | */ | | |||
2680 | size = contentsSize; | | |||
2681 | | ||||
2682 | } else { | | |||
2683 | | ||||
2684 | /* | | |||
2685 | rather than trying to guess what Qt puts into its contents size calculation, | 2683 | rather than trying to guess what Qt puts into its contents size calculation, | ||
2686 | we recompute the button size entirely, based on button option | 2684 | we recompute the button size entirely, based on button option | ||
2687 | this ensures consistency with the rendering stage | 2685 | this ensures consistency with the rendering stage | ||
2688 | */ | 2686 | */ | ||
2689 | 2687 | | |||
2690 | // update has icon to honour showIconsOnPushButtons, when possible | 2688 | // update has icon to honour showIconsOnPushButtons, when possible | ||
2691 | hasIcon &= (showIconsOnPushButtons() || flat || !hasText ); | 2689 | hasIcon &= (showIconsOnPushButtons() || flat || !hasText ); | ||
2692 | 2690 | | |||
2693 | // text | 2691 | // text | ||
2694 | if( hasText ) size = buttonOption->fontMetrics.size( Qt::TextShowMnemonic, buttonOption->text ); | 2692 | if( hasText ) size = buttonOption->fontMetrics.size( Qt::TextShowMnemonic, buttonOption->text ); | ||
2695 | 2693 | | |||
2696 | // icon | 2694 | // icon | ||
2697 | if( hasIcon ) | 2695 | if( hasIcon ) | ||
2698 | { | 2696 | { | ||
2699 | QSize iconSize = buttonOption->iconSize; | 2697 | QSize iconSize = buttonOption->iconSize; | ||
2700 | if( !iconSize.isValid() ) iconSize = QSize( pixelMetric( PM_SmallIconSize, option, widget ), pixelMetric( PM_SmallIconSize, option, widget ) ); | 2698 | if( !iconSize.isValid() ) iconSize = QSize( pixelMetric( PM_SmallIconSize, option, widget ), pixelMetric( PM_SmallIconSize, option, widget ) ); | ||
2701 | 2699 | | |||
2702 | size.setHeight( qMax( size.height(), iconSize.height() ) ); | | |||
2703 | size.rwidth() += iconSize.width(); | 2700 | size.rwidth() += iconSize.width(); | ||
2704 | 2701 | | |||
2705 | if( hasText ) size.rwidth() += Metrics::Button_ItemSpacing; | 2702 | if( hasText ) size.rwidth() += Metrics::Button_ItemSpacing; | ||
2706 | } | 2703 | } | ||
2707 | 2704 | | |||
2708 | } | 2705 | } | ||
2709 | 2706 | | |||
2710 | // menu | 2707 | // menu | ||
2711 | const bool hasMenu( buttonOption->features & QStyleOptionButton::HasMenu ); | 2708 | const bool hasMenu( buttonOption->features & QStyleOptionButton::HasMenu ); | ||
2712 | if( hasMenu ) | 2709 | if( hasMenu ) | ||
2713 | { | 2710 | { | ||
2714 | size.rwidth() += Metrics::MenuButton_IndicatorWidth; | 2711 | size.rwidth() += Metrics::MenuButton_IndicatorWidth; | ||
2715 | if( hasText||hasIcon ) size.rwidth() += Metrics::Button_ItemSpacing; | 2712 | if( hasText||hasIcon ) size.rwidth() += Metrics::Button_ItemSpacing; | ||
2716 | } | 2713 | } | ||
2717 | 2714 | | |||
2715 | // force height consistency | ||||
2716 | size.setHeight(buttonOption->fontMetrics.height()); | ||||
2717 | | ||||
2718 | // expand with buttons margin | 2718 | // expand with buttons margin | ||
2719 | size = expandSize( size, Metrics::Button_MarginWidth ); | 2719 | size = expandSize( size, Metrics::Button_MarginWidth ); | ||
2720 | 2720 | | |||
2721 | // make sure buttons have a minimum width | 2721 | // make sure buttons have a minimum width | ||
2722 | if( hasText ) | 2722 | if( hasText ) | ||
2723 | { size.setWidth( qMax( size.width(), int( Metrics::Button_MinWidth ) ) ); } | 2723 | { size.setWidth( qMax( size.width(), int( Metrics::Button_MinWidth ) ) ); } | ||
2724 | 2724 | | |||
2725 | // finally add frame margins | 2725 | return size; | ||
2726 | return expandSize( size, Metrics::Frame_FrameWidth ); | | |||
2727 | | ||||
2728 | } | 2726 | } | ||
2729 | 2727 | | |||
2730 | //______________________________________________________________ | 2728 | //______________________________________________________________ | ||
2731 | QSize Style::toolButtonSizeFromContents( const QStyleOption* option, const QSize& contentsSize, const QWidget* ) const | 2729 | QSize Style::toolButtonSizeFromContents( const QStyleOption* option, const QSize& contentsSize, const QWidget* ) const | ||
2732 | { | 2730 | { | ||
2733 | 2731 | | |||
2734 | // cast option and check | 2732 | // cast option and check | ||
2735 | const auto toolButtonOption = qstyleoption_cast<const QStyleOptionToolButton*>( option ); | 2733 | const auto toolButtonOption = qstyleoption_cast<const QStyleOptionToolButton*>( option ); | ||
2736 | if( !toolButtonOption ) return contentsSize; | 2734 | if( !toolButtonOption ) return contentsSize; | ||
2737 | 2735 | | |||
2738 | // copy size | 2736 | // copy size | ||
2739 | QSize size = contentsSize; | 2737 | QSize size = contentsSize; | ||
2740 | 2738 | | |||
2741 | // get relevant state flags | | |||
2742 | const State& state( option->state ); | | |||
2743 | const bool autoRaise( state & State_AutoRaise ); | | |||
2744 | const bool hasPopupMenu( toolButtonOption->features & QStyleOptionToolButton::MenuButtonPopup ); | 2739 | const bool hasPopupMenu( toolButtonOption->features & QStyleOptionToolButton::MenuButtonPopup ); | ||
2745 | const bool hasInlineIndicator( | 2740 | const bool hasInlineIndicator( | ||
2746 | toolButtonOption->features&QStyleOptionToolButton::HasMenu | 2741 | toolButtonOption->features&QStyleOptionToolButton::HasMenu | ||
2747 | && toolButtonOption->features&QStyleOptionToolButton::PopupDelay | 2742 | && toolButtonOption->features&QStyleOptionToolButton::PopupDelay | ||
2748 | && !hasPopupMenu ); | 2743 | && !hasPopupMenu ); | ||
2749 | 2744 | | |||
2750 | const int marginWidth( autoRaise ? Metrics::ToolButton_MarginWidth : Metrics::Button_MarginWidth + Metrics::Frame_FrameWidth ); | 2745 | const int marginWidth(Metrics::ToolButton_MarginWidth); | ||
2751 | 2746 | | |||
2752 | if( hasInlineIndicator ) size.rwidth() += Metrics::ToolButton_InlineIndicatorWidth; | 2747 | if( hasInlineIndicator ) size.rwidth() += Metrics::ToolButton_InlineIndicatorWidth; | ||
2748 | | ||||
2749 | // force height consistency | ||||
2750 | size.setHeight(toolButtonOption->fontMetrics.height()); | ||||
2751 | | ||||
2753 | size = expandSize( size, marginWidth ); | 2752 | size = expandSize( size, marginWidth ); | ||
2754 | 2753 | | |||
2755 | return size; | 2754 | return size; | ||
2756 | | ||||
2757 | } | 2755 | } | ||
2758 | 2756 | | |||
2759 | //______________________________________________________________ | 2757 | //______________________________________________________________ | ||
2760 | QSize Style::menuBarItemSizeFromContents( const QStyleOption*, const QSize& contentsSize, const QWidget* ) const | 2758 | QSize Style::menuBarItemSizeFromContents( const QStyleOption*, const QSize& contentsSize, const QWidget* ) const | ||
2761 | { | 2759 | { | ||
2762 | 2760 | | |||
2763 | return expandSize( contentsSize, Metrics::MenuBarItem_MarginWidth, Metrics::MenuBarItem_MarginHeight ); | 2761 | return expandSize( contentsSize, Metrics::MenuBarItem_MarginWidth, Metrics::MenuBarItem_MarginHeight ); | ||
2764 | 2762 | | |||
▲ Show 20 Lines • Show All 4515 Lines • Show Last 20 Lines |