697 |
697 |
698 QPoint offset; |
698 QPoint offset; |
699 if (sourceIsPixmap()) { |
699 if (sourceIsPixmap()) { |
700 // No point in drawing in device coordinates (pixmap will be scaled anyways). |
700 // No point in drawing in device coordinates (pixmap will be scaled anyways). |
701 const QPixmap pixmap = sourcePixmap(Qt::LogicalCoordinates, &offset, NoPad); |
701 const QPixmap pixmap = sourcePixmap(Qt::LogicalCoordinates, &offset, NoPad); |
702 d->filter->draw(painter, offset, pixmap); |
702 if (!pixmap.isNull()) |
|
703 d->filter->draw(painter, offset, pixmap); |
|
704 |
703 return; |
705 return; |
704 } |
706 } |
705 |
707 |
706 // Draw pixmap in deviceCoordinates to avoid pixmap scaling. |
708 // Draw pixmap in deviceCoordinates to avoid pixmap scaling. |
707 const QPixmap pixmap = sourcePixmap(Qt::DeviceCoordinates, &offset); |
709 const QPixmap pixmap = sourcePixmap(Qt::DeviceCoordinates, &offset); |
|
710 if (pixmap.isNull()) |
|
711 return; |
|
712 |
708 QTransform restoreTransform = painter->worldTransform(); |
713 QTransform restoreTransform = painter->worldTransform(); |
709 painter->setWorldTransform(QTransform()); |
714 painter->setWorldTransform(QTransform()); |
710 d->filter->draw(painter, offset, pixmap); |
715 d->filter->draw(painter, offset, pixmap); |
711 painter->setWorldTransform(restoreTransform); |
716 painter->setWorldTransform(restoreTransform); |
712 } |
717 } |
719 A blur effect blurs the source. This effect is useful for reducing details, |
724 A blur effect blurs the source. This effect is useful for reducing details, |
720 such as when the source loses focus and you want to draw attention to other |
725 such as when the source loses focus and you want to draw attention to other |
721 elements. The level of detail can be modified using the setBlurRadius() |
726 elements. The level of detail can be modified using the setBlurRadius() |
722 function. Use setBlurHints() to choose the blur hints. |
727 function. Use setBlurHints() to choose the blur hints. |
723 |
728 |
724 By default, the blur radius is 5 pixels. |
729 By default, the blur radius is 5 pixels. The blur radius is specified in |
|
730 device coordinates. |
725 |
731 |
726 \img graphicseffect-blur.png |
732 \img graphicseffect-blur.png |
727 |
733 |
728 \sa QGraphicsDropShadowEffect, QGraphicsColorizeEffect, QGraphicsOpacityEffect |
734 \sa QGraphicsDropShadowEffect, QGraphicsColorizeEffect, QGraphicsOpacityEffect |
729 */ |
735 */ |
774 |
780 |
775 Using a smaller radius results in a sharper appearance, whereas a bigger |
781 Using a smaller radius results in a sharper appearance, whereas a bigger |
776 radius results in a more blurred appearance. |
782 radius results in a more blurred appearance. |
777 |
783 |
778 By default, the blur radius is 5 pixels. |
784 By default, the blur radius is 5 pixels. |
|
785 |
|
786 The radius is given in device coordinates, meaning it is |
|
787 unaffected by scale. |
779 */ |
788 */ |
780 qreal QGraphicsBlurEffect::blurRadius() const |
789 qreal QGraphicsBlurEffect::blurRadius() const |
781 { |
790 { |
782 Q_D(const QGraphicsBlurEffect); |
791 Q_D(const QGraphicsBlurEffect); |
783 return d->filter->radius(); |
792 return d->filter->radius(); |
856 |
865 |
857 PixmapPadMode mode = PadToEffectiveBoundingRect; |
866 PixmapPadMode mode = PadToEffectiveBoundingRect; |
858 if (painter->paintEngine()->type() == QPaintEngine::OpenGL2) |
867 if (painter->paintEngine()->type() == QPaintEngine::OpenGL2) |
859 mode = NoPad; |
868 mode = NoPad; |
860 |
869 |
861 // Draw pixmap in device coordinates to avoid pixmap scaling. |
|
862 QPoint offset; |
870 QPoint offset; |
863 QPixmap pixmap = sourcePixmap(Qt::LogicalCoordinates, &offset, mode); |
871 QPixmap pixmap = sourcePixmap(Qt::LogicalCoordinates, &offset, mode); |
|
872 if (pixmap.isNull()) |
|
873 return; |
|
874 |
864 d->filter->draw(painter, offset, pixmap); |
875 d->filter->draw(painter, offset, pixmap); |
865 } |
876 } |
866 |
877 |
867 /*! |
878 /*! |
868 \class QGraphicsDropShadowEffect |
879 \class QGraphicsDropShadowEffect |
875 radius of the drop shadow can be changed with the setBlurRadius() |
886 radius of the drop shadow can be changed with the setBlurRadius() |
876 function. |
887 function. |
877 |
888 |
878 By default, the drop shadow is a semi-transparent dark gray |
889 By default, the drop shadow is a semi-transparent dark gray |
879 (QColor(63, 63, 63, 180)) shadow, blurred with a radius of 1 at an offset |
890 (QColor(63, 63, 63, 180)) shadow, blurred with a radius of 1 at an offset |
880 of 8 pixels towards the lower right. |
891 of 8 pixels towards the lower right. The drop shadow offset is specified |
|
892 in device coordinates. |
881 |
893 |
882 \img graphicseffect-drop-shadow.png |
894 \img graphicseffect-drop-shadow.png |
883 |
895 |
884 \sa QGraphicsBlurEffect, QGraphicsColorizeEffect, QGraphicsOpacityEffect |
896 \sa QGraphicsBlurEffect, QGraphicsColorizeEffect, QGraphicsOpacityEffect |
885 */ |
897 */ |
903 /*! |
915 /*! |
904 \property QGraphicsDropShadowEffect::offset |
916 \property QGraphicsDropShadowEffect::offset |
905 \brief the shadow offset in pixels. |
917 \brief the shadow offset in pixels. |
906 |
918 |
907 By default, the offset is 8 pixels towards the lower right. |
919 By default, the offset is 8 pixels towards the lower right. |
|
920 |
|
921 The offset is given in device coordinates, which means it is |
|
922 unaffected by scale. |
908 |
923 |
909 \sa xOffset(), yOffset(), blurRadius(), color() |
924 \sa xOffset(), yOffset(), blurRadius(), color() |
910 */ |
925 */ |
911 QPointF QGraphicsDropShadowEffect::offset() const |
926 QPointF QGraphicsDropShadowEffect::offset() const |
912 { |
927 { |
1045 mode = NoPad; |
1060 mode = NoPad; |
1046 |
1061 |
1047 // Draw pixmap in device coordinates to avoid pixmap scaling. |
1062 // Draw pixmap in device coordinates to avoid pixmap scaling. |
1048 QPoint offset; |
1063 QPoint offset; |
1049 const QPixmap pixmap = sourcePixmap(Qt::DeviceCoordinates, &offset, mode); |
1064 const QPixmap pixmap = sourcePixmap(Qt::DeviceCoordinates, &offset, mode); |
|
1065 if (pixmap.isNull()) |
|
1066 return; |
|
1067 |
1050 QTransform restoreTransform = painter->worldTransform(); |
1068 QTransform restoreTransform = painter->worldTransform(); |
1051 painter->setWorldTransform(QTransform()); |
1069 painter->setWorldTransform(QTransform()); |
1052 d->filter->draw(painter, offset, pixmap); |
1070 d->filter->draw(painter, offset, pixmap); |
1053 painter->setWorldTransform(restoreTransform); |
1071 painter->setWorldTransform(restoreTransform); |
1054 } |
1072 } |