add heuristic to identify theme roundness automatic

pull/5/head
Michail Vourlakos 6 years ago
parent 1a17ffb683
commit b6c272d6a9

@ -64,7 +64,8 @@ Theme::Theme(KSharedConfig::Ptr config, QObject *parent) :
void Theme::load() void Theme::load()
{ {
loadThemePaths(); loadThemePaths();
loadRoundness(); // loadRoundness();
loadRoundnessFromSvgs();
} }
Theme::~Theme() Theme::~Theme()
@ -97,22 +98,22 @@ bool Theme::themeHasExtendedInfo() const
int Theme::bottomEdgeRoundness() const int Theme::bottomEdgeRoundness() const
{ {
return ((themeHasExtendedInfo() && m_userRoundness == -1) ? m_bottomEdgeRoundness : qMax(0, m_userRoundness)); return m_bottomEdgeRoundness;
} }
int Theme::leftEdgeRoundness() const int Theme::leftEdgeRoundness() const
{ {
return ((themeHasExtendedInfo() && m_userRoundness == -1) ? m_leftEdgeRoundness : qMax(0, m_userRoundness)); return m_leftEdgeRoundness;
} }
int Theme::topEdgeRoundness() const int Theme::topEdgeRoundness() const
{ {
return ((themeHasExtendedInfo() && m_userRoundness == -1) ? m_topEdgeRoundness : qMax(0, m_userRoundness)); return m_topEdgeRoundness;
} }
int Theme::rightEdgeRoundness() const int Theme::rightEdgeRoundness() const
{ {
return ((themeHasExtendedInfo() && m_userRoundness == -1) ? m_rightEdgeRoundness : qMax(0, m_userRoundness)); return m_rightEdgeRoundness;
} }
int Theme::outlineWidth() const int Theme::outlineWidth() const
@ -263,7 +264,7 @@ void Theme::updateReversedSchemeValues()
KConfigGroup reversedGroup(reversedPtr, groupName); KConfigGroup reversedGroup(reversedPtr, groupName);
if (reversedGroup.keyList().contains("BackgroundNormal") if (reversedGroup.keyList().contains("BackgroundNormal")
&& reversedGroup.keyList().contains("ForegroundNormal")) { && reversedGroup.keyList().contains("ForegroundNormal")) {
//! reverse usual text/background values //! reverse usual text/background values
KConfigGroup originalGroup(originalPtr, groupName); KConfigGroup originalGroup(originalPtr, groupName);
@ -280,9 +281,9 @@ void Theme::updateReversedSchemeValues()
KConfigGroup originalViewGroup(originalPtr, "Colors:View"); KConfigGroup originalViewGroup(originalPtr, "Colors:View");
if (reversedWMGroup.keyList().contains("activeBackground") if (reversedWMGroup.keyList().contains("activeBackground")
&& reversedWMGroup.keyList().contains("activeForeground") && reversedWMGroup.keyList().contains("activeForeground")
&& reversedWMGroup.keyList().contains("inactiveBackground") && reversedWMGroup.keyList().contains("inactiveBackground")
&& reversedWMGroup.keyList().contains("inactiveForeground")) { && reversedWMGroup.keyList().contains("inactiveForeground")) {
//! reverse usual wm titlebar values //! reverse usual wm titlebar values
KConfigGroup originalGroup(originalPtr, "WM"); KConfigGroup originalGroup(originalPtr, "WM");
reversedWMGroup.writeEntry("activeBackground", originalViewGroup.readEntry("ForegroundNormal", QColor())); reversedWMGroup.writeEntry("activeBackground", originalViewGroup.readEntry("ForegroundNormal", QColor()));
@ -293,7 +294,7 @@ void Theme::updateReversedSchemeValues()
} }
if (reversedWMGroup.keyList().contains("activeBlend") if (reversedWMGroup.keyList().contains("activeBlend")
&& reversedWMGroup.keyList().contains("inactiveBlend")) { && reversedWMGroup.keyList().contains("inactiveBlend")) {
KConfigGroup originalGroup(originalPtr, "WM"); KConfigGroup originalGroup(originalPtr, "WM");
reversedWMGroup.writeEntry("activeBlend", originalGroup.readEntry("inactiveBlend", QColor())); reversedWMGroup.writeEntry("activeBlend", originalGroup.readEntry("inactiveBlend", QColor()));
reversedWMGroup.writeEntry("inactiveBlend", originalGroup.readEntry("activeBlend", QColor())); reversedWMGroup.writeEntry("inactiveBlend", originalGroup.readEntry("activeBlend", QColor()));
@ -308,6 +309,87 @@ void Theme::updateReversedSchemeValues()
} }
} }
int Theme::roundness(Plasma::FrameSvg *svg, Plasma::Types::Location edge)
{
int discovY{edge == Plasma::Types::TopEdge ? svg->mask().boundingRect().bottom() : svg->mask().boundingRect().top()};
int discovX{edge == Plasma::Types::LeftEdge ? svg->mask().boundingRect().right() : svg->mask().boundingRect().left()};
int round{0};
if (edge == Plasma::Types::BottomEdge || edge == Plasma::Types::RightEdge || edge == Plasma::Types::TopEdge) {
//! TOPLEFT corner
//! first LEFT pixel found
for (int x=0; x<50; ++x) {
if (!svg->mask().contains(QPoint(x, discovY))) {
discovX++;
round++;
} else {
break;
}
}
} else if (edge == Plasma::Types::LeftEdge) {
//! it should be TOPRIGHT corner in that case
//! first RIGHT pixel found
for (int x=svg->mask().boundingRect().right(); x>50; --x) {
if (!svg->mask().contains(QPoint(x, discovY))) {
discovX--;
round++;
} else {
break;
}
}
}
return round;
}
void Theme::loadRoundnessFromSvgs()
{
Plasma::FrameSvg *svg = new Plasma::FrameSvg(this);
svg->setImagePath(QStringLiteral("widgets/panel-background"));
svg->setEnabledBorders(Plasma::FrameSvg::AllBorders);
//! bottom roundness
if (svg->hasElementPrefix("south")) {
svg->setElementPrefix("south");
}
svg->resizeFrame(QSize(100,00));
m_bottomEdgeRoundness = roundness(svg, Plasma::Types::BottomEdge);
//! left roundness
if (svg->hasElementPrefix("west")) {
svg->setElementPrefix("west");
} else {
svg->setElementPrefix("");
}
svg->resizeFrame(QSize(100,00));
m_leftEdgeRoundness = roundness(svg, Plasma::Types::LeftEdge);
//! top roundness
if (svg->hasElementPrefix("north")) {
svg->setElementPrefix("north");
} else {
svg->setElementPrefix("");
}
svg->resizeFrame(QSize(100,00));
m_topEdgeRoundness = roundness(svg, Plasma::Types::TopEdge);
//! right roundness
if (svg->hasElementPrefix("east")) {
svg->setElementPrefix("east");
} else {
svg->setElementPrefix("");
}
svg->resizeFrame(QSize(100,00));
m_rightEdgeRoundness = roundness(svg, Plasma::Types::RightEdge);
qDebug() << " MASK ::: " << svg->mask();
qDebug() << " BOUNDING RECT ::: " << svg->mask().boundingRect();
qDebug() << " ROUNDNESS ::: " << m_bottomEdgeRoundness << " _ " << m_leftEdgeRoundness << " _ " << m_topEdgeRoundness << " _ " << m_rightEdgeRoundness;
svg->deleteLater();
emit roundnessChanged();
}
void Theme::loadRoundness() void Theme::loadRoundness()
{ {
@ -445,38 +527,38 @@ void Theme::parseThemeSvgFiles()
QString styleSvgStr; QString styleSvgStr;
if (svgFile.open(QIODevice::ReadOnly)) { if (svgFile.open(QIODevice::ReadOnly)) {
QTextStream in(&svgFile); QTextStream in(&svgFile);
bool centerIdFound{false}; bool centerIdFound{false};
bool styleFound{false}; bool styleFound{false};
while (!in.atEnd() && !styleFound) { while (!in.atEnd() && !styleFound) {
QString line = in.readLine(); QString line = in.readLine();
//! each time a rect starts then style can be reset //! each time a rect starts then style can be reset
if (line.contains("<rect")) { if (line.contains("<rect")) {
styleSvgStr = ""; styleSvgStr = "";
} }
//! identify the id "center //! identify the id "center
if (line.contains("id=\"center\"")) { if (line.contains("id=\"center\"")) {
centerIdFound = true; centerIdFound = true;
} }
//! if valid style for center exists we can break //! if valid style for center exists we can break
if (centerIdFound && !styleSvgStr.isEmpty()) { if (centerIdFound && !styleSvgStr.isEmpty()) {
break; break;
} }
if (centerIdFound && line.contains("style=\"") ) { if (centerIdFound && line.contains("style=\"") ) {
styleSvgStr = line; styleSvgStr = line;
} }
//! when end of "center" you can break //! when end of "center" you can break
if (centerIdFound && line.contains("/rect>")) { if (centerIdFound && line.contains("/rect>")) {
break; break;
} }
} }
svgFile.close(); svgFile.close();
} }
if (!styleSvgStr.isEmpty()) { if (!styleSvgStr.isEmpty()) {

@ -36,6 +36,7 @@
#include <KSharedConfig> #include <KSharedConfig>
// Plasma // Plasma
#include <Plasma/FrameSvg>
#include <Plasma/Theme> #include <Plasma/Theme>
namespace Latte { namespace Latte {
@ -108,6 +109,7 @@ private slots:
private: private:
void loadThemePaths(); void loadThemePaths();
void loadRoundness(); void loadRoundness();
void loadRoundnessFromSvgs();
void setOriginalSchemeFile(const QString &file); void setOriginalSchemeFile(const QString &file);
void parseThemeSvgFiles(); void parseThemeSvgFiles();
@ -118,6 +120,7 @@ private:
bool themeHasExtendedInfo() const; bool themeHasExtendedInfo() const;
int roundness(Plasma::FrameSvg *svg, Plasma::Types::Location edge);
private: private:
bool m_isLightTheme{false}; bool m_isLightTheme{false};
bool m_themeHasExtendedInfo{false}; bool m_themeHasExtendedInfo{false};

Loading…
Cancel
Save