Changeset View
Changeset View
Standalone View
Standalone View
kdecoration/breezedecoration.cpp
Show All 23 Lines | |||||
24 | #include "breeze.h" | 24 | #include "breeze.h" | ||
25 | #include "breezesettingsprovider.h" | 25 | #include "breezesettingsprovider.h" | ||
26 | #include "config-breeze.h" | 26 | #include "config-breeze.h" | ||
27 | #include "config/breezeconfigwidget.h" | 27 | #include "config/breezeconfigwidget.h" | ||
28 | 28 | | |||
29 | #include "breezebutton.h" | 29 | #include "breezebutton.h" | ||
30 | #include "breezesizegrip.h" | 30 | #include "breezesizegrip.h" | ||
31 | 31 | | |||
32 | #include "breezeboxshadowhelper.h" | 32 | #include "breezeboxshadowrenderer.h" | ||
33 | 33 | | |||
34 | #include <KDecoration2/DecoratedClient> | 34 | #include <KDecoration2/DecoratedClient> | ||
35 | #include <KDecoration2/DecorationButtonGroup> | 35 | #include <KDecoration2/DecorationButtonGroup> | ||
36 | #include <KDecoration2/DecorationSettings> | 36 | #include <KDecoration2/DecorationSettings> | ||
37 | #include <KDecoration2/DecorationShadow> | 37 | #include <KDecoration2/DecorationShadow> | ||
38 | 38 | | |||
39 | #include <KConfigGroup> | 39 | #include <KConfigGroup> | ||
40 | #include <KColorUtils> | 40 | #include <KColorUtils> | ||
▲ Show 20 Lines • Show All 683 Lines • ▼ Show 20 Line(s) | 714 | { | |||
724 | } | 724 | } | ||
725 | 725 | | |||
726 | auto withOpacity = [](const QColor &color, qreal opacity) -> QColor { | 726 | auto withOpacity = [](const QColor &color, qreal opacity) -> QColor { | ||
727 | QColor c(color); | 727 | QColor c(color); | ||
728 | c.setAlphaF(opacity); | 728 | c.setAlphaF(opacity); | ||
729 | return c; | 729 | return c; | ||
730 | }; | 730 | }; | ||
731 | 731 | | |||
732 | // In order to properly render a box shadow with a given radius `shadowSize`, | 732 | const QSize boxSize = BoxShadowRenderer::minimumRequiredBoxSize(params.shadow1.radius) | ||
733 | // the box size should be at least `2 * QSize(shadowSize, shadowSize)`. | 733 | .expandedTo(BoxShadowRenderer::minimumRequiredBoxSize(params.shadow2.radius)); | ||
734 | const int shadowSize = qMax(params.shadow1.radius, params.shadow2.radius); | | |||
735 | const QRect box(shadowSize, shadowSize, 2 * shadowSize + 1, 2 * shadowSize + 1); | | |||
736 | const QRect rect = box.adjusted(-shadowSize, -shadowSize, shadowSize, shadowSize); | | |||
737 | 734 | | |||
738 | QImage shadow(rect.size(), QImage::Format_ARGB32_Premultiplied); | 735 | BoxShadowRenderer shadowRenderer; | ||
739 | shadow.fill(Qt::transparent); | 736 | shadowRenderer.setBorderRadius(Metrics::Frame_FrameRadius + 0.5); | ||
740 | 737 | shadowRenderer.setBoxSize(boxSize); | |||
741 | QPainter painter(&shadow); | 738 | shadowRenderer.setDevicePixelRatio(1.0); // TODO: Create HiDPI shadows? | ||
742 | painter.setRenderHint(QPainter::Antialiasing); | | |||
743 | 739 | | |||
744 | const qreal strength = static_cast<qreal>(g_shadowStrength) / 255.0; | 740 | const qreal strength = static_cast<qreal>(g_shadowStrength) / 255.0; | ||
745 | 741 | shadowRenderer.addShadow(params.shadow1.offset, params.shadow1.radius, | |||
746 | // Draw the "shape" shadow. | | |||
747 | BoxShadowHelper::boxShadow( | | |||
748 | &painter, | | |||
749 | box, | | |||
750 | params.shadow1.offset, | | |||
751 | params.shadow1.radius, | | |||
752 | withOpacity(g_shadowColor, params.shadow1.opacity * strength)); | 742 | withOpacity(g_shadowColor, params.shadow1.opacity * strength)); | ||
753 | 743 | shadowRenderer.addShadow(params.shadow2.offset, params.shadow2.radius, | |||
754 | // Draw the "contrast" shadow. | | |||
755 | BoxShadowHelper::boxShadow( | | |||
756 | &painter, | | |||
757 | box, | | |||
758 | params.shadow2.offset, | | |||
759 | params.shadow2.radius, | | |||
760 | withOpacity(g_shadowColor, params.shadow2.opacity * strength)); | 744 | withOpacity(g_shadowColor, params.shadow2.opacity * strength)); | ||
761 | 745 | | |||
746 | QImage shadowTexture = shadowRenderer.render(); | ||||
747 | | ||||
748 | QPainter painter(&shadowTexture); | ||||
749 | painter.setRenderHint(QPainter::Antialiasing); | ||||
750 | | ||||
751 | const QRect outerRect = shadowTexture.rect(); | ||||
752 | | ||||
753 | QRect boxRect(QPoint(0, 0), boxSize); | ||||
754 | boxRect.moveCenter(outerRect.center()); | ||||
755 | | ||||
762 | // Mask out inner rect. | 756 | // Mask out inner rect. | ||
763 | const QMargins padding = QMargins( | 757 | const QMargins padding = QMargins( | ||
764 | shadowSize - Metrics::Shadow_Overlap - params.offset.x(), | 758 | boxRect.left() - outerRect.left() - Metrics::Shadow_Overlap - params.offset.x(), | ||
765 | shadowSize - Metrics::Shadow_Overlap - params.offset.y(), | 759 | boxRect.top() - outerRect.top() - Metrics::Shadow_Overlap - params.offset.y(), | ||
766 | shadowSize - Metrics::Shadow_Overlap + params.offset.x(), | 760 | outerRect.right() - boxRect.right() - Metrics::Shadow_Overlap + params.offset.x(), | ||
767 | shadowSize - Metrics::Shadow_Overlap + params.offset.y()); | 761 | outerRect.bottom() - boxRect.bottom() - Metrics::Shadow_Overlap + params.offset.y()); | ||
768 | const QRect innerRect = rect - padding; | 762 | const QRect innerRect = outerRect - padding; | ||
769 | 763 | | |||
770 | painter.setPen(Qt::NoPen); | 764 | painter.setPen(Qt::NoPen); | ||
771 | painter.setBrush(Qt::black); | 765 | painter.setBrush(Qt::black); | ||
772 | painter.setCompositionMode(QPainter::CompositionMode_DestinationOut); | 766 | painter.setCompositionMode(QPainter::CompositionMode_DestinationOut); | ||
773 | painter.drawRoundedRect( | 767 | painter.drawRoundedRect( | ||
774 | innerRect, | 768 | innerRect, | ||
775 | Metrics::Frame_FrameRadius + 0.5, | 769 | Metrics::Frame_FrameRadius + 0.5, | ||
776 | Metrics::Frame_FrameRadius + 0.5); | 770 | Metrics::Frame_FrameRadius + 0.5); | ||
777 | 771 | | |||
778 | // Draw outline. | 772 | // Draw outline. | ||
779 | painter.setPen(withOpacity(g_shadowColor, 0.2 * strength)); | 773 | painter.setPen(withOpacity(g_shadowColor, 0.2 * strength)); | ||
780 | painter.setBrush(Qt::NoBrush); | 774 | painter.setBrush(Qt::NoBrush); | ||
781 | painter.setCompositionMode(QPainter::CompositionMode_SourceOver); | 775 | painter.setCompositionMode(QPainter::CompositionMode_SourceOver); | ||
782 | painter.drawRoundedRect( | 776 | painter.drawRoundedRect( | ||
783 | innerRect, | 777 | innerRect, | ||
784 | Metrics::Frame_FrameRadius - 0.5, | 778 | Metrics::Frame_FrameRadius - 0.5, | ||
785 | Metrics::Frame_FrameRadius - 0.5); | 779 | Metrics::Frame_FrameRadius - 0.5); | ||
786 | 780 | | |||
787 | painter.end(); | 781 | painter.end(); | ||
788 | 782 | | |||
789 | g_sShadow = QSharedPointer<KDecoration2::DecorationShadow>::create(); | 783 | g_sShadow = QSharedPointer<KDecoration2::DecorationShadow>::create(); | ||
790 | g_sShadow->setPadding(padding); | 784 | g_sShadow->setPadding(padding); | ||
791 | g_sShadow->setInnerShadowRect(QRect(shadow.rect().center(), QSize(1, 1))); | 785 | g_sShadow->setInnerShadowRect(QRect(outerRect.center(), QSize(1, 1))); | ||
792 | g_sShadow->setShadow(shadow); | 786 | g_sShadow->setShadow(shadowTexture); | ||
793 | } | 787 | } | ||
794 | 788 | | |||
795 | setShadow(g_sShadow); | 789 | setShadow(g_sShadow); | ||
796 | } | 790 | } | ||
797 | 791 | | |||
798 | //_________________________________________________________________ | 792 | //_________________________________________________________________ | ||
799 | void Decoration::createSizeGrip() | 793 | void Decoration::createSizeGrip() | ||
800 | { | 794 | { | ||
Show All 36 Lines |