Commit 87a2b284 authored by Denis Kuplyakov's avatar Denis Kuplyakov
Browse files

Added universal ColorScheme class to get colors from KColorScheme.

-- Works only with Q_GADGET patch to kdelibs --
parent bed08d31
......@@ -22,30 +22,90 @@
********************************************************************/
#include <colorscheme.h>
#include <KColorScheme>
ColorScheme::ColorScheme(QDeclarativeItem *parent) :
QDeclarativeItem(parent)
{
}
KColorScheme::ColorSet ColorScheme::getColorSet() const
{
return m_colorSet;
}
void ColorScheme::setColorSet(KColorScheme::ColorSet colorSet)
{
m_colorSet = colorSet;
emit onBackgroundChange();
emit onForegroundChange();
emit onDecorationChange();
}
KColorScheme::BackgroundRole ColorScheme::getBackgroundRole() const
{
return m_backgroundRole;
}
void ColorScheme::setBackgroundRole(KColorScheme::BackgroundRole role)
{
m_backgroundRole = role;
emit onBackgroundChange();
}
KColorScheme::ForegroundRole ColorScheme::getForegroundRole() const
{
return m_foregroundRole;
}
void ColorScheme::setForegroundRole(KColorScheme::ForegroundRole role)
{
m_foregroundRole = role;
emit onForegroundChange();
}
KColorScheme::DecorationRole ColorScheme::getDecorationRole() const
{
return m_decorationRole;
}
void ColorScheme::setDecorationRole(KColorScheme::DecorationRole role)
{
m_decorationRole = role;
emit onDecorationChange();
}
KColorScheme::ShadeRole ColorScheme::getShadeRole() const
{
return m_shadeRole;
}
void ColorScheme::setShadeRole(KColorScheme::ShadeRole role)
{
m_shadeRole = role;
emit onShadeChange();
}
QColor ColorScheme::background() const
{
return KStatefulBrush(KColorScheme::Tooltip,
KColorScheme::NormalBackground)
.brush(QPalette::Active).color();
return KStatefulBrush(m_colorSet,
m_backgroundRole)
.brush(QPalette::Active).color();
}
QColor ColorScheme::foreground() const
{
return KStatefulBrush(KColorScheme::Tooltip,
KColorScheme::NormalText)
.brush(QPalette::Active).color();
return KStatefulBrush(m_colorSet,
m_foregroundRole)
.brush(QPalette::Active).color();
}
QColor ColorScheme::decoration() const
{
return KStatefulBrush(m_colorSet,
m_decorationRole)
.brush(QPalette::Active).color();
}
QColor ColorScheme::border() const
QColor ColorScheme::shade() const
{
return KStatefulBrush(KColorScheme::View,
KColorScheme::NormalText)
.brush(QPalette::Active).color();
return KColorScheme(QPalette::Active).shade(m_shadeRole);
}
......@@ -26,20 +26,61 @@
#include <QDeclarativeItem>
#include <QColor>
#include <KColorScheme>
class ColorScheme : public QDeclarativeItem
{
Q_OBJECT
Q_PROPERTY(QColor background READ background)
Q_PROPERTY(QColor foreground READ foreground)
Q_PROPERTY(QColor border READ border)
Q_PROPERTY(KColorScheme::ColorSet colorSet
READ getColorSet WRITE setColorSet)
Q_PROPERTY(KColorScheme::BackgroundRole backgroundRole
READ getBackgroundRole WRITE setBackgroundRole)
Q_PROPERTY(KColorScheme::ForegroundRole foregroundRole
READ getForegroundRole WRITE setForegroundRole)
Q_PROPERTY(KColorScheme::DecorationRole decorationRole
READ getDecorationRole WRITE setDecorationRole)
Q_PROPERTY(KColorScheme::ShadeRole shadeRole
READ getShadeRole WRITE setShadeRole)
Q_PROPERTY(QColor background READ background NOTIFY onBackgroundChange)
Q_PROPERTY(QColor foreground READ foreground NOTIFY onForegroundChange)
Q_PROPERTY(QColor decoration READ decoration NOTIFY onDecorationChange)
Q_PROPERTY(QColor shade READ shade NOTIFY onShadeChange)
public:
explicit ColorScheme(QDeclarativeItem *parent = 0);
KColorScheme::ColorSet getColorSet() const;
void setColorSet(KColorScheme::ColorSet colorSet);
KColorScheme::BackgroundRole getBackgroundRole() const;
void setBackgroundRole(KColorScheme::BackgroundRole role);
KColorScheme::ForegroundRole getForegroundRole() const;
void setForegroundRole(KColorScheme::ForegroundRole role);
KColorScheme::DecorationRole getDecorationRole() const;
void setDecorationRole(KColorScheme::DecorationRole role);
KColorScheme::ShadeRole getShadeRole() const;
void setShadeRole(KColorScheme::ShadeRole role);
QColor background() const;
QColor foreground() const;
QColor border() const;
QColor decoration() const;
QColor shade() const;
signals:
void onBackgroundChange();
void onForegroundChange();
void onDecorationChange();
void onShadeChange();
private:
KColorScheme::ColorSet m_colorSet;
KColorScheme::BackgroundRole m_backgroundRole;
KColorScheme::ForegroundRole m_foregroundRole;
KColorScheme::DecorationRole m_decorationRole;
KColorScheme::ShadeRole m_shadeRole;
};
#endif // COLORSCHEME_H
......@@ -32,6 +32,8 @@ KReversiView::KReversiView(KReversiGame* game, QWidget *parent, KgThemeProvider
m_provider->setDeclarativeEngine("themeProvider", engine());
qmlRegisterType<ColorScheme>("ColorScheme", 1, 0, "ColorScheme");
qmlRegisterUncreatableType<KColorScheme>("KColorScheme", 1, 0, "KColorScheme",
"KColorScheme class is uncreatable. Use for enums only");
QString path =
KStandardDirs::locate("appdata", QLatin1String("qml/Table.qml"));
......
......@@ -18,6 +18,7 @@
import QtQuick 1.1
import ColorScheme 1.0
import KColorScheme 1.0
Rectangle {
id: popup
......@@ -47,8 +48,8 @@ Rectangle {
height: row.height + 2 * marginOnSides
width: row.width + 2 * marginOnSides
color: colorScheme.background
border.color: useCustomBorderColor ? borderColor : colorScheme.border
color: backgroundTokken.background
border.color: useCustomBorderColor ? borderColor : borderTokken.foreground
border.width: borderWidth
function show(message, showing_state) {
......@@ -60,7 +61,21 @@ Rectangle {
}
ColorScheme {
id: colorScheme
id: borderTokken
colorSet: KColorScheme.View
foregroundRole: KColorScheme.NormalText
}
ColorScheme {
id: backgroundTokken
colorSet: KColorScheme.Tooltip
backgroundRole: KColorScheme.NormalBackground
}
ColorScheme {
id: textColorTokken
colorSet: KColorScheme.Tooltip
foregroundRole: KColorScheme.NormalText
}
Timer {
......@@ -91,7 +106,7 @@ Rectangle {
Text {
id: text
anchors.verticalCenter: parent.verticalCenter
color: colorScheme.foreground
color: textColorTokken.foreground
wrapMode: Text.WordWrap
onLinkActivated: popup.linkActivated(link);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment