mirror of
https://github.com/KDE/latte-dock.git
synced 2025-01-10 21:18:19 +03:00
smart way to identify plasma theme hasShadows
--many plasma themes disable their shadows with settings their opacity to zero instead of removing their shadow elements. In such case the new approach sets the hasShadow flag to zero
This commit is contained in:
parent
059b78ebc0
commit
0f2562aa5e
@ -20,6 +20,9 @@
|
||||
|
||||
#include "panelbackground.h"
|
||||
|
||||
// local
|
||||
#include "theme.h"
|
||||
|
||||
// Qt
|
||||
#include <QDebug>
|
||||
#include <QImage>
|
||||
@ -31,9 +34,10 @@
|
||||
namespace Latte {
|
||||
namespace PlasmaExtended {
|
||||
|
||||
PanelBackground::PanelBackground(Plasma::Types::Location edge, QObject *parent)
|
||||
PanelBackground::PanelBackground(Plasma::Types::Location edge, Theme *parent)
|
||||
: QObject(parent),
|
||||
m_location(edge)
|
||||
m_location(edge),
|
||||
m_parentTheme(parent)
|
||||
{
|
||||
}
|
||||
|
||||
@ -143,35 +147,6 @@ void PanelBackground::updatePaddings(Plasma::Svg *svg)
|
||||
emit paddingsChanged();
|
||||
}
|
||||
|
||||
bool PanelBackground::hasVisibleShadow(Plasma::Svg *svg) const
|
||||
{
|
||||
if (!svg || !svg->hasElement("shadow-topleft")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QString cornerId = "shadow-topleft";
|
||||
QImage corner = svg->image(svg->elementSize(cornerId), cornerId);
|
||||
|
||||
int fullTransparentPixels = 0;
|
||||
|
||||
for(int c=0; c<corner.width(); ++c) {
|
||||
for(int r=0; r<corner.height(); ++r) {
|
||||
QRgb *line = (QRgb *)corner.scanLine(r);
|
||||
QRgb point = line[c];
|
||||
|
||||
if (qAlpha(point) == 0) {
|
||||
fullTransparentPixels++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int pixels = (corner.width() * corner.height());
|
||||
|
||||
qDebug() << " PLASMA THEME TOPLEFT SHADOW :: pixels : " << pixels << " transparent pixels" << fullTransparentPixels;
|
||||
|
||||
return (fullTransparentPixels != pixels );
|
||||
}
|
||||
|
||||
void PanelBackground::updateRoundnessFromShadows(Plasma::Svg *svg)
|
||||
{
|
||||
if (!svg) {
|
||||
@ -353,7 +328,7 @@ void PanelBackground::updateRoundness(Plasma::Svg *svg)
|
||||
return;
|
||||
}
|
||||
|
||||
if (hasVisibleShadow(svg)) {
|
||||
if (m_parentTheme->hasShadow()) {
|
||||
qDebug() << "PLASMA THEME, calculating roundness from shadows...";
|
||||
updateRoundnessFromShadows(svg);
|
||||
} else {
|
||||
|
@ -28,6 +28,12 @@
|
||||
#include <Plasma>
|
||||
#include <Plasma/FrameSvg>
|
||||
|
||||
namespace Latte {
|
||||
namespace PlasmaExtended {
|
||||
class Theme;
|
||||
}
|
||||
}
|
||||
|
||||
namespace Latte {
|
||||
namespace PlasmaExtended {
|
||||
|
||||
@ -44,7 +50,7 @@ class PanelBackground: public QObject
|
||||
Q_PROPERTY(float maxOpacity READ maxOpacity NOTIFY maxOpacityChanged)
|
||||
|
||||
public:
|
||||
PanelBackground(Plasma::Types::Location edge, QObject *parent);
|
||||
PanelBackground(Plasma::Types::Location edge, Theme *parent);
|
||||
~PanelBackground();
|
||||
|
||||
int paddingTop() const;
|
||||
@ -65,8 +71,6 @@ signals:
|
||||
void maxOpacityChanged();
|
||||
|
||||
private:
|
||||
bool hasVisibleShadow(Plasma::Svg *svg) const;
|
||||
|
||||
QString prefixed(const QString &id);
|
||||
QString element(Plasma::Svg *svg, const QString &id);
|
||||
|
||||
@ -89,6 +93,7 @@ private:
|
||||
|
||||
Plasma::Types::Location m_location{Plasma::Types::BottomEdge};
|
||||
|
||||
Theme *m_parentTheme{nullptr};
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -82,7 +82,6 @@ Theme::Theme(KSharedConfig::Ptr config, QObject *parent) :
|
||||
connect(this, &Theme::compositingChanged, this, &Theme::updateBackgrounds);
|
||||
connect(this, &Theme::outlineWidthChanged, this, &Theme::saveConfig);
|
||||
|
||||
connect(&m_theme, &Plasma::Theme::themeChanged, this, &Theme::hasShadowChanged);
|
||||
connect(&m_theme, &Plasma::Theme::themeChanged, this, &Theme::load);
|
||||
connect(&m_theme, &Plasma::Theme::themeChanged, this, &Theme::themeChanged);
|
||||
}
|
||||
@ -103,7 +102,7 @@ Theme::~Theme()
|
||||
|
||||
bool Theme::hasShadow() const
|
||||
{
|
||||
return PanelShadows::self()->hasShadows();
|
||||
return m_hasShadow;
|
||||
}
|
||||
|
||||
bool Theme::isLightTheme() const
|
||||
@ -310,12 +309,46 @@ void Theme::updateReversedSchemeValues()
|
||||
|
||||
void Theme::updateBackgrounds()
|
||||
{
|
||||
updateHasShadow();
|
||||
|
||||
m_backgroundTopEdge->update();
|
||||
m_backgroundLeftEdge->update();
|
||||
m_backgroundBottomEdge->update();
|
||||
m_backgroundRightEdge->update();
|
||||
}
|
||||
|
||||
void Theme::updateHasShadow()
|
||||
{
|
||||
Plasma::Svg *svg = new Plasma::Svg(this);
|
||||
svg->setImagePath(QStringLiteral("widgets/panel-background"));
|
||||
svg->resize();
|
||||
|
||||
QString cornerId = "shadow-topleft";
|
||||
QImage corner = svg->image(svg->elementSize(cornerId), cornerId);
|
||||
|
||||
int fullTransparentPixels = 0;
|
||||
|
||||
for(int c=0; c<corner.width(); ++c) {
|
||||
for(int r=0; r<corner.height(); ++r) {
|
||||
QRgb *line = (QRgb *)corner.scanLine(r);
|
||||
QRgb point = line[c];
|
||||
|
||||
if (qAlpha(point) == 0) {
|
||||
fullTransparentPixels++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int pixels = (corner.width() * corner.height());
|
||||
|
||||
m_hasShadow = (fullTransparentPixels != pixels );
|
||||
emit hasShadowChanged();
|
||||
|
||||
qDebug() << " PLASMA THEME TOPLEFT SHADOW :: pixels : " << pixels << " transparent pixels" << fullTransparentPixels << " | HAS SHADOWS :" << m_hasShadow;
|
||||
|
||||
svg->deleteLater();
|
||||
}
|
||||
|
||||
void Theme::loadThemePaths()
|
||||
{
|
||||
m_themePath = Layouts::Importer::standardPath("plasma/desktoptheme/" + m_theme.themeName());
|
||||
|
@ -110,6 +110,7 @@ private:
|
||||
void updateBackgrounds();
|
||||
|
||||
void setOriginalSchemeFile(const QString &file);
|
||||
void updateHasShadow();
|
||||
void updateDefaultScheme();
|
||||
void updateDefaultSchemeValues();
|
||||
void updateReversedScheme();
|
||||
@ -118,6 +119,7 @@ private:
|
||||
void qmlRegisterTypes();
|
||||
|
||||
private:
|
||||
bool m_hasShadow{false};
|
||||
bool m_isLightTheme{false};
|
||||
bool m_compositing{true};
|
||||
|
||||
|
@ -1035,7 +1035,7 @@ PlasmaComponents.Page {
|
||||
text: i18n("Shadows")
|
||||
checked: plasmoid.configuration.panelShadows
|
||||
checkable: true
|
||||
enabled: showBackground.checked && LatteCore.WindowSystem.compositingActive
|
||||
enabled: showBackground.checked && LatteCore.WindowSystem.compositingActive && themeExtended.hasShadow
|
||||
tooltip: i18n("Background shows its shadows")
|
||||
|
||||
onClicked: {
|
||||
|
Loading…
Reference in New Issue
Block a user