Commit b4f8143e authored by Radosław Wicik's avatar Radosław Wicik Committed by Jarosław Staniek

Fix background opacity handling and new background/foreground defaults

(in Kexi Report elements)

REVIEW:120290
parent 28d3e11f
......@@ -75,8 +75,8 @@ void KoReportItemCheck::createProperties()
m_controlSource = new KoProperty::Property("item-data-source", QStringList(), QStringList(), QString(), i18n("Data Source"));
m_controlSource->setOption("extraValueAllowed", "true");
m_foregroundColor = new KoProperty::Property("foreground-color", Qt::black, i18n("Foreground Color"));
m_foregroundColor = new KoProperty::Property("foreground-color", QPalette().color(QPalette::Foreground), i18n("Foreground Color"));
m_lineWeight = new KoProperty::Property("line-weight", 1, i18n("Line Weight"));
m_lineColor = new KoProperty::Property("line-color", Qt::black, i18n("Line Color"));
......
......@@ -102,11 +102,11 @@ void KoReportDesignerItemField::paint(QPainter* painter, const QStyleOptionGraph
QPen p = painter->pen();
painter->setFont(font());
painter->setBackgroundMode(Qt::TransparentMode);
QColor bg = m_backgroundColor->value().value<QColor>();
bg.setAlpha((m_backgroundOpacity->value().toInt() / 100) * 255);
bg.setAlphaF(m_backgroundOpacity->value().toReal() *0.01);
painter->setBackground(bg);
painter->setPen(m_foregroundColor->value().value<QColor>());
painter->fillRect(QGraphicsRectItem::rect(), bg);
......@@ -121,7 +121,6 @@ void KoReportDesignerItemField::paint(QPainter* painter, const QStyleOptionGraph
painter->drawRect(rect());
painter->setBackgroundMode(Qt::TransparentMode);
drawHandles(painter);
......
......@@ -96,10 +96,11 @@ void KoReportItemField::createProperties()
m_font = new KoProperty::Property("Font", KGlobalSettings::generalFont(), "Font", i18n("Font"));
m_backgroundColor = new KoProperty::Property("background-color", Qt::white, i18n("Background Color"));
m_foregroundColor = new KoProperty::Property("foregroud-color", Qt::black, i18n("Foreground Color"));
m_foregroundColor = new KoProperty::Property("foreground-color", QPalette().color(QPalette::Foreground), i18n("Foreground Color"));
m_backgroundOpacity = new KoProperty::Property("background-opacity", 100, i18n("Background Opacity"));
m_backgroundOpacity = new KoProperty::Property("background-opacity", QVariant(0), i18n("Background Opacity"));
m_backgroundOpacity->setOption("max", 100);
m_backgroundOpacity->setOption("min", 0);
m_backgroundOpacity->setOption("unit", "%");
......
......@@ -98,13 +98,13 @@ void KoReportDesignerItemLabel::paint(QPainter* painter, const QStyleOptionGraph
// store any values we plan on changing so we can restore them
QFont f = painter->font();
QPen p = painter->pen();
painter->setFont(font());
painter->setBackgroundMode(Qt::TransparentMode);
QColor bg = m_backgroundColor->value().value<QColor>();
bg.setAlpha((m_backgroundOpacity->value().toInt() / 100) * 255);
bg.setAlphaF(m_backgroundOpacity->value().toReal() * 0.01);
painter->setBackground(bg);
painter->setPen(m_foregroundColor->value().value<QColor>());
painter->fillRect(QGraphicsRectItem::rect(), bg);
......@@ -118,7 +118,7 @@ void KoReportDesignerItemLabel::paint(QPainter* painter, const QStyleOptionGraph
painter->drawRect(QGraphicsRectItem::rect());
painter->setBackgroundMode(Qt::TransparentMode);
painter->setPen(m_foregroundColor->value().value<QColor>());
drawHandles(painter);
......
......@@ -100,8 +100,9 @@ void KoReportItemLabel::createProperties()
m_font = new KoProperty::Property("Font", KGlobalSettings::generalFont(), i18n("Font"), i18n("Font"));
m_backgroundColor = new KoProperty::Property("background-color", Qt::white, i18n("Background Color"));
m_foregroundColor = new KoProperty::Property("foreground-color", Qt::black, i18n("Foreground Color"));
m_backgroundOpacity = new KoProperty::Property("background-opacity", 100, i18n("Background Opacity"));
m_foregroundColor = new KoProperty::Property("foreground-color", QPalette().color(QPalette::Foreground), i18n("Foreground Color"));
m_backgroundOpacity = new KoProperty::Property("background-opacity", QVariant(0), i18n("Background Opacity"));
m_backgroundOpacity->setOption("max", 100);
m_backgroundOpacity->setOption("min", 0);
m_backgroundOpacity->setOption("unit", "%");
......
......@@ -105,14 +105,14 @@ void KoReportDesignerItemText::paint(QPainter* painter, const QStyleOptionGraphi
QPen p = painter->pen();
painter->setFont(font());
painter->setBackgroundMode(Qt::TransparentMode);
QColor bg = m_backgroundColor->value().value<QColor>();
bg.setAlpha((m_backgroundOpacity->value().toInt() / 100) * 255);
bg.setAlphaF(m_backgroundOpacity->value().toReal()*0.01);
painter->setBackground(bg);
painter->setPen(m_foregroundColor->value().value<QColor>());
painter->fillRect(rect(), m_backgroundColor->value().value<QColor>());
painter->fillRect(rect(), bg);
painter->drawText(rect(), textFlags(), dataSourceAndObjectTypeName(itemDataSource(), "textarea"));
if ((Qt::PenStyle)m_lineStyle->value().toInt() == Qt::NoPen || m_lineWeight->value().toInt() <= 0) {
......@@ -122,7 +122,6 @@ void KoReportDesignerItemText::paint(QPainter* painter, const QStyleOptionGraphi
}
painter->drawRect(rect());
painter->setBackgroundMode(Qt::TransparentMode);
painter->setPen(m_foregroundColor->value().value<QColor>());
drawHandles(painter);
......
......@@ -121,12 +121,12 @@ void KoReportItemText::createProperties()
m_font = new KoProperty::Property("Font", KGlobalSettings::generalFont(), "Font", i18n("Font"));
m_backgroundColor = new KoProperty::Property("background-color", Qt::white, i18n("Background Color"));
m_foregroundColor = new KoProperty::Property("foreground-color", Qt::black, i18n("Foreground Color"));
m_foregroundColor = new KoProperty::Property("foreground-color", QPalette().color(QPalette::Foreground), i18n("Foreground Color"));
m_lineWeight = new KoProperty::Property("line-weight", 1, i18n("Line Weight"));
m_lineColor = new KoProperty::Property("line-color", Qt::black, i18n("Line Color"));
m_lineStyle = new KoProperty::Property("line-style", Qt::NoPen, i18n("Line Style"), i18n("Line Style"), KoProperty::LineStyle);
m_backgroundOpacity = new KoProperty::Property("background-opacity", 100, i18n("Background Opacity"));
m_backgroundOpacity = new KoProperty::Property("background-opacity", QVariant(0), i18n("Background Opacity"));
m_backgroundOpacity->setOption("max", 100);
m_backgroundOpacity->setOption("min", 0);
m_backgroundOpacity->setOption("unit", "%");
......
......@@ -129,13 +129,20 @@ QString KoReportHTMLCSSRenderer::renderCSS(ORODocument *document)
//kDebug() << "Got object type" << prim->type();
if (prim->type() == OROTextBox::TextBox) {
OROTextBox * tb = (OROTextBox*) prim;
QColor bg = tb->textStyle().backgroundColor;
style = "position: absolute; "
"background-color: " + (tb->textStyle().backgroundOpacity == 0 ? "transparent" : tb->textStyle().backgroundColor.name()) + "; "
"background-color: " + QString("rgba(%1,%2,%3,%4)")
.arg(bg.red())
.arg(bg.green())
.arg(bg.blue())
.arg(0.01 * tb->textStyle().backgroundOpacity) + "; "
"top: " + QString::number(tb->position().y()) + "pt; "
"left: " + QString::number(tb->position().x()) + "pt; "
"font-size: " + QString::number(tb->textStyle().font.pointSize()) + "pt; "
"color: " + tb->textStyle().foregroundColor.name() + "; ";
"color: " + tb->textStyle().foregroundColor.name() + "; "
"width: " + QString::number(tb->size().width()) + "px;"
"height: " + QString::number(tb->size().height()) + "px;" ;
//TODO opaque text + translucent background
//it looks a pain to implement
//http://developer.mozilla.org/en/docs/Useful_CSS_tips:Color_and_Background
......
......@@ -99,10 +99,9 @@ bool KoReportPrintRenderer::render(const KoReportRendererContext &context, ORODo
//Background
QColor bg = tb->textStyle().backgroundColor;
bg.setAlpha(tb->textStyle().backgroundOpacity);
bg.setAlphaF(0.01 * tb->textStyle().backgroundOpacity);
//_painter->setBackgroundMode(Qt::OpaqueMode);
context.painter->setBackground(bg);
context.painter->fillRect(rc, bg);
//Text
......
......@@ -61,14 +61,14 @@ bool KoReportScreenRenderer::render(const KoReportRendererContext& context, OROD
context.painter->save();
//Background
context.painter->setBackgroundMode(Qt::TransparentMode);
QColor bg = tb->textStyle().backgroundColor;
bg.setAlpha((tb->textStyle().backgroundOpacity / 100) * 255);
bg.setAlphaF(0.01 * tb->textStyle().backgroundOpacity);
context.painter->setBackground(bg);
context.painter->fillRect(rc, bg);
//Text
context.painter->setBackgroundMode(Qt::TransparentMode);
context.painter->setFont(tb->textStyle().font);
context.painter->setPen(tb->textStyle().foregroundColor);
context.painter->drawText(rc.adjusted(2, 2, 0, 0), tb->flags(), tb->text());
......
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