- Timestamp:
- Mar 22, 2008, 10:24:09 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/styles/qwarp4style.cpp
r181 r182 2580 2580 { 2581 2581 #ifndef QT_NO_TABBAR 2582 case CE_TabBarTab: 2583 { 2584 if(!widget || !widget->parentWidget() || !opt.tab()) 2585 break; 2586 2587 QTabBar const* tb = (QTabBar const*)widget; 2588 QTab const* t = opt.tab(); 2589 bool selected = flags & Style_Selected, 2590 bottom = (QTabBar::RoundedBelow == tb->shape()) || 2591 (QTabBar::TriangularBelow == tb->shape()); 2592 int id = tb->indexOf(t->identifier()); 2593 2594 static const QColor tabCols[10] = 2595 { 2596 QColor(85, 219, 255), 2597 QColor(128, 219, 170), 2598 QColor(128, 146, 255), 2599 QColor(213, 182, 170), 2600 QColor(255, 255, 170), 2601 QColor(170, 146, 170), 2602 QColor(255, 146, 85), 2603 QColor(255, 219, 85), 2604 QColor(255, 182, 170), 2605 QColor(255, 219, 170) 2606 }; 2607 2608 qDrawTabBar(p, r, cg, tabCols[id % 10], selected, bottom); 2609 2610 if(QApplication::reverseLayout()) 2611 { 2612 p->setPen(cg.dark()); 2613 int right = tb->size().width() - 1; 2614 if(bottom) 2615 p->drawLine(right, r.top(), right, r.top() + 4); 2616 else 2617 p->drawLine(right, r.bottom(), right, r.bottom() - 4); 2618 2619 } 2620 p->setPen(cg.light()); 2582 case CE_TabBarTab: 2583 { 2584 if(!widget || !widget->parentWidget() || !opt.tab()) 2585 break; 2586 2587 QTabBar const* tb = (QTabBar const*)widget; 2588 QTab const* t = opt.tab(); 2589 bool selected = flags & Style_Selected, 2590 bottom = (QTabBar::RoundedBelow == tb->shape()) || 2591 (QTabBar::TriangularBelow == tb->shape()); 2592 int id = tb->indexOf(t->identifier()); 2593 2594 static const QColor tabCols[10] = 2595 { 2596 QColor(85, 219, 255), 2597 QColor(128, 219, 170), 2598 QColor(128, 146, 255), 2599 QColor(213, 182, 170), 2600 QColor(255, 255, 170), 2601 QColor(170, 146, 170), 2602 QColor(255, 146, 85), 2603 QColor(255, 219, 85), 2604 QColor(255, 182, 170), 2605 QColor(255, 219, 170) 2606 }; 2607 2608 qDrawTabBar(p, r, cg, tabCols[id % 10], selected, bottom); 2609 2610 if(QApplication::reverseLayout()) 2611 { 2612 p->setPen(cg.dark()); 2613 int right = tb->size().width() - 1; 2621 2614 if(bottom) 2622 p->drawLine( 0, r.top(), 0, r.top() + 4);2615 p->drawLine(right, r.top(), right, r.top() + 4); 2623 2616 else 2624 p->drawLine(0, r.bottom(), 0, r.bottom() - 4); 2625 2617 p->drawLine(right, r.bottom(), right, r.bottom() - 4); 2618 2619 } 2620 p->setPen(cg.light()); 2621 if(bottom) 2622 p->drawLine(0, r.top(), 0, r.top() + 4); 2623 else 2624 p->drawLine(0, r.bottom(), 0, r.bottom() - 4); 2625 2626 break; 2627 } 2628 2629 case CE_TabBarLabel: 2630 { 2631 if(opt.isDefault()) 2626 2632 break; 2627 } 2628 2629 case CE_TabBarLabel: 2630 { 2631 if(opt.isDefault()) 2632 break; 2633 2634 QTabBar const* tb = (QTabBar const*)widget; 2635 QTab const* t = opt.tab(); 2636 bool selected = flags & Style_Selected, 2637 bottom = (QTabBar::RoundedBelow == tb->shape()) || 2638 (QTabBar::TriangularBelow == tb->shape()); 2639 2640 QRect tr(r); 2641 if(bottom) 2642 tr.addCoords(3, 4, 1, 0); 2643 else 2644 tr.addCoords(3, 1, 1, -3); 2645 2646 if(selected) 2647 { 2648 QFont f = p->font(); 2649 QRect rold = QFontMetrics(f).boundingRect(t->text()); 2650 f.setBold(true); 2651 QRect rnew = QFontMetrics(f).boundingRect(t->text()); 2652 p->setFont(f); 2653 int hdiff = rnew.width() - rold.width() + 1; 2654 tr.addCoords(-hdiff / 2, 0, hdiff / 2, 0); 2633 2634 QTabBar const* tb = (QTabBar const*)widget; 2635 QTab const* t = opt.tab(); 2636 bool selected = flags & Style_Selected, 2637 bottom = (QTabBar::RoundedBelow == tb->shape()) || 2638 (QTabBar::TriangularBelow == tb->shape()); 2639 2640 QRect tr(r); 2641 if(bottom) 2642 tr.addCoords(3, 4, 1, 0); 2643 else 2644 tr.addCoords(3, 1, 1, -3); 2645 2646 if(selected) 2647 { 2648 QFont f = p->font(); 2649 QRect rold = QFontMetrics(f).boundingRect(t->text()); 2650 f.setBold(true); 2651 QRect rnew = QFontMetrics(f).boundingRect(t->text()); 2652 p->setFont(f); 2653 int hdiff = rnew.width() - rold.width() + 1; 2654 tr.addCoords(-hdiff / 2, 0, hdiff / 2, 0); 2655 2655 2656 2656 #ifndef QT_PM_NO_TABWIDGET_HEADERS 2657 QWidget* pw = widget->parentWidget(); 2658 if (pw != 0 && pw->inherits ("QTabWidget")) 2657 QWidget* pw = widget->parentWidget(); 2658 if (pw != 0 && pw->inherits ("QTabWidget")) 2659 { 2660 QTabWidget *tw = (QTabWidget *) pw; 2661 QWarpTabPanelHeader *tph = 2662 (QWarpTabPanelHeader *) tw->child ("qt_warp_tabpanel_header", 2663 "QWarpTabPanelHeader", false); 2664 if (tph != 0) 2659 2665 { 2660 QTabWidget *tw = (QTabWidget *) pw; 2661 QWarpTabPanelHeader *tph = 2662 (QWarpTabPanelHeader *) tw->child ("qt_warp_tabpanel_header", 2663 "QWarpTabPanelHeader", false); 2664 if (tph != 0) 2665 { 2666 tph->setCaption (t->text()); 2667 QRect r (tph->visibleRect()); 2668 tph->repaint(); 2669 } 2666 tph->setCaption (t->text()); 2667 QRect r (tph->visibleRect()); 2668 tph->repaint(); 2670 2669 } 2670 } 2671 2671 #endif // QT_PM_NO_TABWIDGET_HEADERS 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2672 } 2673 2674 int alignment = AlignCenter | ShowPrefix; 2675 if(!styleHint(SH_UnderlineAccelerator, widget, QStyleOption::Default, 0)) 2676 alignment |= NoAccel; 2677 drawItem(p, tr, alignment, cg, flags & Style_Enabled, 0, t->text()); 2678 2679 if((flags & Style_HasFocus) && !t->text().isEmpty()) 2680 drawPrimitive(PE_FocusRect, p, tr, cg); 2681 2682 break; 2683 } 2684 2684 #endif // QT_NO_TABBAR 2685 2685 … … 2705 2705 2706 2706 #ifndef QT_NO_PROGRESSBAR 2707 case CE_ProgressBarContents: 2708 { 2709 QProgressBar const* progressbar = (QProgressBar const*)widget; 2710 QColorGroup cgh = cg; 2711 cgh.setColor(QColorGroup::Highlight, QColor(0, 0, 170)); 2712 bool reverse = QApplication::reverseLayout(); 2707 case CE_ProgressBarContents: 2708 { 2709 QProgressBar const* progressbar = (QProgressBar const*)widget; 2710 QColorGroup cgh = cg; 2711 cgh.setColor(QColorGroup::Highlight, QColor(0, 0, 170)); 2712 bool reverse = QApplication::reverseLayout(); 2713 QRect br(r); 2714 br.addCoords(3, 3, -3, -2); 2715 2716 if(!progressbar->totalSteps()) 2717 { 2718 // draw busy indicator 2719 static const int indWidth = 30; 2720 br.addCoords(indWidth / 2, 0, -indWidth / 2, 0); 2721 int bw = br.width(); 2722 int x = progressbar->progress() % (bw * 2); 2723 if(x > bw) 2724 x = 2 * bw - x; 2725 x = reverse ? br.right() - x : br.left() + x; 2726 p->setPen(QPen(cgh.highlight(), indWidth)); 2727 p->drawLine(x, br.top(), x, br.bottom()); 2728 } 2729 2730 else 2731 { 2732 int pos = (progressbar->progress() * br.width()) / 2733 progressbar->totalSteps(); 2734 pos = reverse ? 2735 br.right() - pos : 2736 br.left() + pos; 2737 2738 p->setPen(cgh.dark()); 2739 p->drawLine(pos, br.top(), pos, br.bottom()); 2740 2741 if(reverse) 2742 br.setLeft(pos + 1); 2743 else 2744 br.setRight(pos - 1); 2745 2746 p->fillRect(br, cgh.highlight()); 2747 } 2748 2749 break; 2750 } 2751 2752 case CE_ProgressBarLabel: 2753 { 2754 QProgressBar const* progressbar = (QProgressBar const*)widget; 2755 if(0 == progressbar->totalSteps()) 2756 break; 2757 2758 if(progressbar->indicatorFollowsStyle() || 2759 progressbar->centerIndicator()) 2760 { 2713 2761 QRect br(r); 2714 2762 br.addCoords(3, 3, -3, -2); 2715 2716 if(!progressbar->totalSteps()) 2717 { 2718 // draw busy indicator 2719 static const int indWidth = 30; 2720 br.addCoords(indWidth / 2, 0, -indWidth / 2, 0); 2721 int bw = br.width(); 2722 int x = progressbar->progress() % (bw * 2); 2723 if(x > bw) 2724 x = 2 * bw - x; 2725 x = reverse ? br.right() - x : br.left() + x; 2726 p->setPen(QPen(cgh.highlight(), indWidth)); 2727 p->drawLine(x, br.top(), x, br.bottom()); 2728 } 2729 2763 int pos = (progressbar->progress() * br.width()) / 2764 progressbar->totalSteps(); 2765 bool reverse = QApplication::reverseLayout(); 2766 if(reverse) 2767 pos = br.right() - pos; 2730 2768 else 2731 { 2732 int pos = (progressbar->progress() * br.width()) / 2733 progressbar->totalSteps(); 2734 pos = reverse ? 2735 br.right() - pos : 2736 br.left() + pos; 2737 2738 p->setPen(cgh.dark()); 2739 p->drawLine(pos, br.top(), pos, br.bottom()); 2740 2741 if(reverse) 2742 br.setLeft(pos + 1); 2743 else 2744 br.setRight(pos - 1); 2745 2746 p->fillRect(br, cgh.highlight()); 2747 } 2748 2769 pos = br.left() + pos; 2770 2771 // paint label black in background area 2772 QRect clip(br); 2773 if(reverse) 2774 clip.setRight(pos); 2775 else 2776 clip.setLeft(pos); 2777 p->setClipRect(clip); 2778 drawItem(p, br, AlignCenter | SingleLine, cg, flags & Style_Enabled, 0, 2779 progressbar->progressString()); 2780 2781 // paint label "light" in blue ribbonstrip area 2782 clip = br; 2783 if(reverse) 2784 clip.setLeft(pos); 2785 else 2786 clip.setRight(pos); 2787 p->setClipRect(clip); 2788 drawItem(p, br, AlignCenter | SingleLine, cg, flags & Style_Enabled, 0, 2789 progressbar->progressString(), -1, &cg.highlightedText()); 2790 } 2791 2792 else 2793 { 2794 drawItem(p, r, AlignCenter | SingleLine, cg, flags & Style_Enabled, 0, 2795 progressbar->progressString(), -1, 0); 2796 } 2797 2798 break; 2799 } 2800 #endif // QT_NO_PROGRESSBAR 2801 2802 #ifndef QT_NO_POPUPMENU 2803 case CE_PopupMenuItem: 2804 { 2805 if (!widget || opt.isDefault()) 2749 2806 break; 2750 } 2751 2752 case CE_ProgressBarLabel: 2753 { 2754 QProgressBar const* progressbar = (QProgressBar const*)widget; 2755 if(0 == progressbar->totalSteps()) 2756 break; 2757 2758 if(progressbar->indicatorFollowsStyle() || 2759 progressbar->centerIndicator()) 2760 { 2761 QRect br(r); 2762 br.addCoords(3, 3, -3, -2); 2763 int pos = (progressbar->progress() * br.width()) / 2764 progressbar->totalSteps(); 2765 bool reverse = QApplication::reverseLayout(); 2766 if(reverse) 2767 pos = br.right() - pos; 2768 else 2769 pos = br.left() + pos; 2770 2771 // paint label black in background area 2772 QRect clip(br); 2773 if(reverse) 2774 clip.setRight(pos); 2775 else 2776 clip.setLeft(pos); 2777 p->setClipRect(clip); 2778 drawItem(p, br, AlignCenter | SingleLine, cg, flags & Style_Enabled, 0, 2779 progressbar->progressString()); 2780 2781 // paint label "light" in blue ribbonstrip area 2782 clip = br; 2783 if(reverse) 2784 clip.setLeft(pos); 2785 else 2786 clip.setRight(pos); 2787 p->setClipRect(clip); 2788 drawItem(p, br, AlignCenter | SingleLine, cg, flags & Style_Enabled, 0, 2789 progressbar->progressString(), -1, &cg.highlightedText()); 2790 } 2791 2807 2808 // QPopupMenu has WResizeNoErase and WRepaintNoErase flags, so we 2809 // must erase areas not covered by menu items (this is requested by 2810 // QPopupMenu using 0 as the menu item argument). 2811 // note: we do this with the frame drawing (PE_PanelPopup) 2812 2813 QPopupMenu const* popupmenu = (const QPopupMenu *) widget; 2814 QMenuItem* mi = opt.menuItem(); 2815 if (!mi) 2816 break; 2817 2818 int tabw = opt.tabWidth() + 3; 2819 int iconw = QMAX(11, opt.maxIconWidth()) + 6; 2820 bool dis = !(flags & Style_Enabled); 2821 bool act = flags & Style_Active; 2822 bool reverse = QApplication::reverseLayout(); 2823 int subw = (qPopupMenuHasSub (popupmenu) ? 19 : 0); 2824 2825 int x, y, w, h; 2826 r.rect (&x, &y, &w, &h); 2827 2828 if (mi && mi->isSeparator()) // draw separator 2829 { 2830 p->setPen (cg.dark()); 2831 p->drawLine (x, y + 3, x + w, y + 3); 2832 p->setPen (cg.light()); 2833 p->drawLine (x, y + 4, x + w, y + 4); 2834 return; 2835 } 2836 2837 if (act) 2838 { 2839 QRect hr (r); 2840 hr.addCoords (3, 0, -3, 0); 2841 p->fillRect (hr, cg.highlight()); 2842 p->setPen (cg.highlightedText()); 2843 } 2844 else 2845 { 2846 p->setPen (cg.text()); 2847 } 2848 2849 if (mi->iconSet()) // draw iconset 2850 { 2851 QIconSet::Mode mode = dis ? QIconSet::Disabled : QIconSet::Normal; 2852 if (act && !dis) 2853 mode = QIconSet::Active; 2854 QPixmap pixmap; 2855 if (popupmenu->isCheckable() && mi->isChecked()) 2856 pixmap = mi->iconSet()->pixmap (QIconSet::Small, mode, 2857 QIconSet::On); 2792 2858 else 2793 { 2794 drawItem(p, r, AlignCenter | SingleLine, cg, flags & Style_Enabled, 0, 2795 progressbar->progressString(), -1, 0); 2796 } 2797 2798 break; 2799 } 2800 #endif // QT_NO_PROGRESSBAR 2801 2802 #ifndef QT_NO_POPUPMENU 2803 case CE_PopupMenuItem: 2804 { 2805 if(!widget || opt.isDefault()) 2806 break; 2807 2808 // QPopupMenu has WResizeNoErase and WRepaintNoErase flags, so we 2809 // must erase areas not covered by menu items (this is requested by 2810 // QPopupMenu using 0 as the menu item argument). 2811 // note: we do this with the frame drawing (PE_PanelPopup) 2812 2813 QPopupMenu const* popupmenu = (QPopupMenu const*)widget; 2814 QMenuItem* mi = opt.menuItem(); 2815 if(!mi) 2816 break; 2817 2818 int tabw = opt.tabWidth() + 3; 2819 int iconw = QMAX(11, opt.maxIconWidth()) + 6; 2820 bool dis = !(flags & Style_Enabled); 2821 bool act = flags & Style_Active; 2822 bool reverse = QApplication::reverseLayout(); 2823 int subw = (qPopupMenuHasSub(popupmenu) ? 19 : 0); 2824 2825 // the popup menu adds 1 pixel vertically on top and bottom, but 2826 // actually needs only 2 at the bottom, so we move all items 2827 // 1 pixel up 2828 2829 QRect rr(r); 2830 rr.moveBy(0, -1); 2831 2832 int x, y, w, h; 2833 rr.rect(&x, &y, &w, &h); 2834 2835 if(mi && mi->isSeparator()) // draw separator 2836 { 2837 p->setPen(cg.dark()); 2838 p->drawLine(x, y + 4, x + w, y + 4); 2839 p->setPen(cg.light()); 2840 p->drawLine(x, y + 5, x + w, y + 5); 2841 return; 2842 } 2843 2844 if(act) 2845 { 2846 QRect hr(rr); 2847 hr.addCoords(3, 0, -3, 1); 2848 p->fillRect(hr, cg.highlight()); 2849 p->setPen(cg.highlightedText()); 2859 pixmap = mi->iconSet()->pixmap (QIconSet::Small, mode); 2860 int px = (reverse ? (w - pixmap.width() - 6) : 6); 2861 p->drawPixmap (px, y + (h - pixmap.height()) / 2, pixmap); 2862 } 2863 else if (popupmenu->isCheckable() && mi->isChecked()) // just "checking"... 2864 { 2865 SFlags cflags = Style_Default; 2866 if (!dis) 2867 cflags |= Style_Enabled; 2868 if (act) 2869 cflags |= Style_On; 2870 2871 int xc = (reverse ? w - iconw + 15 : iconw - 15), 2872 yc = (r.top() + r.bottom()) / 2 - 4; 2873 drawPrimitive (PE_CheckMark, p, QRect (xc, yc, 16, 8), cg, cflags); 2874 } 2875 2876 if (mi->custom()) 2877 { 2878 p->save(); 2879 // margins must be in sync with the draw text code below 2880 int tx = (reverse ? tabw + subw : iconw); 2881 mi->custom()->paint (p, cg, act, !dis, tx, y, 2882 w - iconw - tabw - subw, h); 2883 p->restore(); 2884 } 2885 2886 QString s = mi->text(); 2887 if (!s.isNull()) // draw text 2888 { 2889 int text_flags = AlignVCenter | ShowPrefix | DontClip | SingleLine; 2890 if (!styleHint (SH_UnderlineAccelerator, widget)) 2891 text_flags |= NoAccel; 2892 text_flags |= (reverse ? AlignRight : AlignLeft); 2893 2894 // tab text 2895 int t = s.find ('\t'); 2896 QString ts; 2897 if (t >= 0) 2898 { 2899 ts = s.mid (t + 1); 2900 s = s.left (t); 2901 int tx = (reverse ? subw : w - tabw - subw); 2902 p->drawText (tx, y, tabw, h, text_flags, ts); 2903 } 2904 2905 // normal text 2906 int tx = (reverse ? tabw + subw : iconw); 2907 p->drawText (tx, y, w - iconw - tabw - subw, h, text_flags, s); 2908 } 2909 else if (mi->pixmap()) // draw pixmap 2910 { 2911 QPixmap* pixmap = mi->pixmap(); 2912 if (pixmap->depth() == 1) 2913 p->setBackgroundMode(OpaqueMode); 2914 int px = (reverse ? (w - pixmap->width() - iconw) : iconw); 2915 if (dis) 2916 { 2917 QIconSet is (*pixmap); 2918 p->drawPixmap (px, y, is.pixmap (QIconSet::Automatic, 2919 QIconSet::Disabled)); 2850 2920 } 2851 2921 else 2852 2922 { 2853 p->setPen(cg.text()); 2854 } 2855 2856 if(mi->iconSet()) // draw iconset 2857 { 2858 QIconSet::Mode mode = dis ? QIconSet::Disabled : QIconSet::Normal; 2859 if(act && !dis) 2860 mode = QIconSet::Active; 2861 QPixmap pixmap; 2862 if(popupmenu->isCheckable() && mi->isChecked()) 2863 pixmap = mi->iconSet()->pixmap(QIconSet::Small, mode, QIconSet::On); 2864 else 2865 pixmap = mi->iconSet()->pixmap(QIconSet::Small, mode); 2866 int px = (reverse ? (w - pixmap.width() - 6) : 6); 2867 p->drawPixmap(px, y, pixmap); 2868 } 2869 2870 else if(popupmenu->isCheckable() && mi->isChecked()) // just "checking"... 2871 { 2872 SFlags cflags = Style_Default; 2873 if(!dis) 2874 cflags |= Style_Enabled; 2875 if(act) 2876 cflags |= Style_On; 2877 2878 int xc = (reverse ? w - iconw + 15 : iconw - 15), 2879 yc = (rr.top() + rr.bottom()) / 2 - 3; 2880 drawPrimitive(PE_CheckMark, p, QRect(xc, yc, 16, 8), cg, cflags); 2881 } 2882 2883 if(mi->custom()) 2884 { 2885 mi->custom()->paint(p, cg, act, !dis, 0, 10, 8, 8); 2886 } 2887 2888 QString s = mi->text(); 2889 if(!s.isNull()) // draw text 2890 { 2891 int text_flags = AlignVCenter | ShowPrefix | DontClip | SingleLine; 2892 if(!styleHint(SH_UnderlineAccelerator, widget)) 2893 text_flags |= NoAccel; 2894 text_flags |= (reverse ? AlignRight : AlignLeft); 2895 2896 // tab text 2897 int t = s.find('\t'); 2898 QString ts; 2899 if(t >= 0) 2900 { 2901 ts = s.mid(t + 1); 2902 s = s.left(t); 2903 int tx = (reverse ? subw : w - tabw - subw); 2904 p->drawText(tx, y + 1, tabw, h, text_flags, ts); 2905 } 2906 2907 // normal text 2908 int tx = (reverse ? tabw + subw : iconw); 2909 p->drawText(tx, y + 1, w - iconw - tabw - subw, h, text_flags, s); 2910 } 2911 2912 else if(mi->pixmap()) // draw pixmap 2913 { 2914 QPixmap* pixmap = mi->pixmap(); 2915 if(pixmap->depth() == 1) 2916 p->setBackgroundMode(OpaqueMode); 2917 int px = (reverse ? (w - pixmap->width() - iconw) : iconw); 2918 if(dis) 2919 { 2920 QIconSet is(*pixmap); 2921 p->drawPixmap(px, y, is.pixmap(QIconSet::Automatic, QIconSet::Disabled)); 2922 } 2923 else 2924 { 2925 p->drawPixmap(px, y, *pixmap); 2926 } 2927 if(pixmap->depth() == 1) 2928 p->setBackgroundMode(TransparentMode); 2929 } 2930 2931 if(mi->popup()) // draw sub menu arrow 2932 { 2933 PrimitiveElement arrow; 2934 arrow = (reverse ? PE_ArrowLeft : PE_ArrowRight); 2935 int xa = (reverse ? 5 : w - 15), 2936 ya = (rr.top() + rr.bottom()) / 2 - 4; 2937 drawPrimitive(arrow, p, QRect(xa, ya, 12, 12), 2938 cg, dis ? Style_Default : Style_Enabled); 2939 } 2940 break; 2941 } 2923 p->drawPixmap (px, y, *pixmap); 2924 } 2925 if (pixmap->depth() == 1) 2926 p->setBackgroundMode (TransparentMode); 2927 } 2928 2929 if (mi->popup()) // draw sub menu arrow 2930 { 2931 PrimitiveElement arrow; 2932 arrow = (reverse ? PE_ArrowLeft : PE_ArrowRight); 2933 int xa = (reverse ? 5 : w - 15), 2934 ya = (r.top() + r.bottom()) / 2 - 5; 2935 drawPrimitive (arrow, p, QRect (xa, ya, 12, 12), 2936 cg, dis ? Style_Default : Style_Enabled); 2937 } 2938 2939 break; 2940 } 2942 2941 #endif // QT_NO_POPUPMENU 2943 2942 … … 2980 2979 2981 2980 #ifndef QT_NO_TOOLBUTTON 2982 case CE_ToolButtonLabel: 2983 { 2984 if (!qstrcmp (widget->name(), "qt_left_btn") || 2985 !qstrcmp (widget->name(), "qt_right_btn")) 2986 { 2987 // do nothing in this case! 2981 case CE_ToolButtonLabel: 2982 { 2983 if (!qstrcmp (widget->name(), "qt_left_btn") || 2984 !qstrcmp (widget->name(), "qt_right_btn")) 2985 { 2986 // do nothing in this case! 2987 } 2988 else 2989 { 2990 QToolButton const *toolbutton = (QToolButton const *) widget; 2991 QRect rect = r; 2992 Qt::ArrowType arrowType = opt.isDefault() ? 2993 Qt::DownArrow : opt.arrowType(); 2994 2995 if (flags & (Style_Down | Style_On)) 2996 rect.moveBy (pixelMetric(PM_ButtonShiftHorizontal, widget), 2997 pixelMetric(PM_ButtonShiftVertical, widget)); 2998 2999 if (!opt.isDefault()) 3000 { 3001 PrimitiveElement pe; 3002 switch (arrowType) 3003 { 3004 case Qt::LeftArrow: 3005 pe = PE_ArrowLeft; 3006 break; 3007 case Qt::RightArrow: 3008 pe = PE_ArrowRight; 3009 break; 3010 case Qt::UpArrow: 3011 pe = PE_ArrowUp; 3012 break; 3013 default: 3014 case Qt::DownArrow: 3015 pe = PE_ArrowDown; 3016 break; 3017 } 3018 3019 drawPrimitive (pe, p, rect, cg, flags, opt); 2988 3020 } 2989 3021 else 2990 3022 { 2991 QToolButton const *toolbutton = (QToolButton const *) widget; 2992 QRect rect = r; 2993 Qt::ArrowType arrowType = opt.isDefault() ? 2994 Qt::DownArrow : opt.arrowType(); 2995 2996 if (flags & (Style_Down | Style_On)) 2997 rect.moveBy (pixelMetric(PM_ButtonShiftHorizontal, widget), 2998 pixelMetric(PM_ButtonShiftVertical, widget)); 2999 3000 if (!opt.isDefault()) 3023 QColor btext = toolbutton->paletteForegroundColor(); 3024 3025 if (toolbutton->iconSet().isNull() && 3026 !toolbutton->text().isNull() && 3027 !toolbutton->usesTextLabel()) 3001 3028 { 3002 PrimitiveElement pe; 3003 switch (arrowType) 3004 { 3005 case Qt::LeftArrow: 3006 pe = PE_ArrowLeft; 3007 break; 3008 case Qt::RightArrow: 3009 pe = PE_ArrowRight; 3010 break; 3011 case Qt::UpArrow: 3012 pe = PE_ArrowUp; 3013 break; 3014 default: 3015 case Qt::DownArrow: 3016 pe = PE_ArrowDown; 3017 break; 3018 } 3019 3020 drawPrimitive (pe, p, rect, cg, flags, opt); 3029 int alignment = AlignCenter | AlignVCenter | ShowPrefix; 3030 3031 if (!styleHint (SH_UnderlineAccelerator, widget, 3032 QStyleOption::Default, 0)) 3033 alignment |= NoAccel; 3034 3035 drawItem (p, rect, alignment, cg, 3036 flags & Style_Enabled, 0, toolbutton->text(), 3037 toolbutton->text().length(), &btext); 3021 3038 } 3022 3039 else 3023 3040 { 3024 QColor btext = toolbutton->paletteForegroundColor(); 3025 3026 if (toolbutton->iconSet().isNull() && 3027 !toolbutton->text().isNull() && 3028 !toolbutton->usesTextLabel()) 3041 QPixmap pm; 3042 3043 QIconSet::Size size = 3044 toolbutton->usesBigPixmap() ? QIconSet::Large : QIconSet::Small; 3045 3046 QIconSet::State state = 3047 toolbutton->isOn() ? QIconSet::On : QIconSet::Off; 3048 3049 QIconSet::Mode mode; 3050 if (!toolbutton->isEnabled()) 3051 mode = QIconSet::Disabled; 3052 else if (flags & (Style_Down | Style_On | Style_Raised)) 3053 mode = QIconSet::Active; 3054 else 3055 mode = QIconSet::Normal; 3056 3057 pm = toolbutton->iconSet().pixmap(size, mode, state); 3058 3059 if (toolbutton->usesTextLabel()) 3029 3060 { 3030 int alignment = AlignCenter | AlignVCenter | ShowPrefix; 3031 3032 if (!styleHint (SH_UnderlineAccelerator, widget, 3033 QStyleOption::Default, 0)) 3034 alignment |= NoAccel; 3035 3036 drawItem (p, rect, alignment, cg, 3037 flags & Style_Enabled, 0, toolbutton->text(), 3038 toolbutton->text().length(), &btext); 3061 if (toolbutton->textPosition() == QToolButton::Under) 3062 { 3063 p->setFont(toolbutton->font()); 3064 3065 QRect pr = rect, tr = rect; 3066 int fh = p->fontMetrics().height(); 3067 pr.addCoords (0, 1, 0, -fh - 3); 3068 tr.addCoords (0, pr.bottom(), 0, -3); 3069 drawItem (p, pr, AlignCenter, cg, TRUE, &pm, QString::null); 3070 int alignment = AlignCenter | ShowPrefix; 3071 3072 if (!styleHint (SH_UnderlineAccelerator, widget, QStyleOption::Default, 0)) 3073 alignment |= NoAccel; 3074 3075 drawItem (p, tr, alignment, cg, 3076 flags & Style_Enabled, 0, toolbutton->textLabel(), 3077 toolbutton->textLabel().length(), &btext); 3078 } 3079 else 3080 { 3081 p->setFont (toolbutton->font()); 3082 3083 QRect pr = rect, tr = rect; 3084 pr.setWidth (pm.width() + 8); 3085 tr.addCoords (pr.right(), 0, 0, 0); 3086 drawItem (p, pr, AlignCenter, cg, TRUE, &pm, QString::null); 3087 int alignment = AlignLeft | AlignVCenter | ShowPrefix; 3088 3089 if (!styleHint(SH_UnderlineAccelerator, widget, QStyleOption::Default, 0)) 3090 alignment |= NoAccel; 3091 3092 drawItem (p, tr, alignment, cg, 3093 flags & Style_Enabled, 0, toolbutton->textLabel(), 3094 toolbutton->textLabel().length(), &btext); 3095 } 3039 3096 } 3040 3097 else 3041 3098 { 3042 QPixmap pm; 3043 3044 QIconSet::Size size = 3045 toolbutton->usesBigPixmap() ? QIconSet::Large : QIconSet::Small; 3046 3047 QIconSet::State state = 3048 toolbutton->isOn() ? QIconSet::On : QIconSet::Off; 3049 3050 QIconSet::Mode mode; 3051 if (!toolbutton->isEnabled()) 3052 mode = QIconSet::Disabled; 3053 else if (flags & (Style_Down | Style_On | Style_Raised)) 3054 mode = QIconSet::Active; 3055 else 3056 mode = QIconSet::Normal; 3057 3058 pm = toolbutton->iconSet().pixmap(size, mode, state); 3059 3060 if (toolbutton->usesTextLabel()) 3061 { 3062 if (toolbutton->textPosition() == QToolButton::Under) 3063 { 3064 p->setFont(toolbutton->font()); 3065 3066 QRect pr = rect, tr = rect; 3067 int fh = p->fontMetrics().height(); 3068 pr.addCoords (0, 1, 0, -fh - 3); 3069 tr.addCoords (0, pr.bottom(), 0, -3); 3070 drawItem (p, pr, AlignCenter, cg, TRUE, &pm, QString::null); 3071 int alignment = AlignCenter | ShowPrefix; 3072 3073 if (!styleHint (SH_UnderlineAccelerator, widget, QStyleOption::Default, 0)) 3074 alignment |= NoAccel; 3075 3076 drawItem (p, tr, alignment, cg, 3077 flags & Style_Enabled, 0, toolbutton->textLabel(), 3078 toolbutton->textLabel().length(), &btext); 3079 } 3080 else 3081 { 3082 p->setFont (toolbutton->font()); 3083 3084 QRect pr = rect, tr = rect; 3085 pr.setWidth (pm.width() + 8); 3086 tr.addCoords (pr.right(), 0, 0, 0); 3087 drawItem (p, pr, AlignCenter, cg, TRUE, &pm, QString::null); 3088 int alignment = AlignLeft | AlignVCenter | ShowPrefix; 3089 3090 if (!styleHint(SH_UnderlineAccelerator, widget, QStyleOption::Default, 0)) 3091 alignment |= NoAccel; 3092 3093 drawItem (p, tr, alignment, cg, 3094 flags & Style_Enabled, 0, toolbutton->textLabel(), 3095 toolbutton->textLabel().length(), &btext); 3096 } 3097 } 3098 else 3099 { 3100 drawItem (p, rect, AlignCenter, cg, TRUE, &pm, QString::null); 3101 } 3099 drawItem (p, rect, AlignCenter, cg, TRUE, &pm, QString::null); 3102 3100 } 3103 3101 } 3104 3102 } 3105 3106 break; 3107 } 3103 } 3104 3105 break; 3106 } 3108 3107 #endif // QT_NO_TOOLBUTTON 3109 3108
Note:
See TracChangeset
for help on using the changeset viewer.