From 1caf4a8e2d146ff69e6c8753dde39abb4951f006 Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Wed, 4 Apr 2018 00:20:59 +0300 Subject: [PATCH] Color property reafctored --- .../objectinspector/editors/lrcoloreditor.cpp | 22 ++++++++++----- .../propertyItems/lrcolorpropitem.cpp | 28 +++++++++---------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/limereport/objectinspector/editors/lrcoloreditor.cpp b/limereport/objectinspector/editors/lrcoloreditor.cpp index b0f4c19..09c22d6 100644 --- a/limereport/objectinspector/editors/lrcoloreditor.cpp +++ b/limereport/objectinspector/editors/lrcoloreditor.cpp @@ -28,11 +28,14 @@ * GNU General Public License for more details. * ****************************************************************************/ #include "lrcoloreditor.h" +#include "lrglobal.h" #include #include #include #include +#include +#include namespace LimeReport{ @@ -94,18 +97,23 @@ void ColorEditor::slotClicked() emit(editingFinished()); } - void ColorIndicator::paintEvent(QPaintEvent* event) { QPainter painter(this); + + QStyle* style = QApplication::style(); painter.save(); painter.setBrush(m_color); - painter.setPen(Qt::transparent); - QRect rect = event->rect().adjusted(3,3,-4,-4); - rect.setWidth(rect.height()); - painter.setRenderHint(QPainter::Antialiasing); -// painter.drawEllipse(rect); - painter.drawRoundedRect(rect,2,2); + QColor penColor = isColorDark(m_color) ? Qt::transparent : Qt::darkGray; + + painter.setPen(penColor); + int border = (event->rect().height() - style->pixelMetric(QStyle::PM_IndicatorWidth))/2; + + QRect rect(event->rect().x()+border, event->rect().y()+border, + style->pixelMetric(QStyle::PM_IndicatorWidth), + style->pixelMetric(QStyle::PM_IndicatorWidth));// = option.rect.adjusted(4,4,-4,-6); + + painter.drawRect(rect); painter.restore(); } diff --git a/limereport/objectinspector/propertyItems/lrcolorpropitem.cpp b/limereport/objectinspector/propertyItems/lrcolorpropitem.cpp index 4eed649..a47f77c 100644 --- a/limereport/objectinspector/propertyItems/lrcolorpropitem.cpp +++ b/limereport/objectinspector/propertyItems/lrcolorpropitem.cpp @@ -28,8 +28,10 @@ * GNU General Public License for more details. * ****************************************************************************/ #include "lrcolorpropitem.h" +#include "lrglobal.h" #include "editors/lrcoloreditor.h" #include +#include namespace{ LimeReport::ObjectPropItem * createColorPropItem( @@ -58,24 +60,20 @@ bool ColorPropItem::paint(QPainter *painter, const StyleOptionViewItem &option, { if (index.column()==1){ painter->save(); + + QStyle* style = option.widget ? option.widget->style() : QApplication::style(); QPen pen; - -// if (option.state & QStyle::State_Selected){ -// pen.setWidth(1); -// pen.setColor(option.palette.brightText().color()); -// }else { -// pen.setColor(Qt::darkGray); -// } - - pen.setColor(Qt::transparent); + QColor penColor = isColorDark(propertyValue().value()) ? Qt::transparent : Qt::darkGray; + pen.setColor(penColor); painter->setPen(pen); - painter->setBrush(propertyValue().value()); - QRect rect = option.rect.adjusted(4,4,-4,-6); - rect.setWidth(rect.height()); - painter->setRenderHint(QPainter::Antialiasing); - painter->drawRoundedRect(rect,2,2); -// painter->drawEllipse(rect); + int border = (option.rect.height() - style->pixelMetric(QStyle::PM_IndicatorWidth))/2; + + QRect rect(option.rect.x()+border,option.rect.y()+border, + style->pixelMetric(QStyle::PM_IndicatorWidth), + style->pixelMetric(QStyle::PM_IndicatorWidth)); + painter->drawRect(rect); + painter->restore(); return true; } else return false;