0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-25 00:54:39 +03:00

Color property reafctored

This commit is contained in:
Arin Alexander 2018-04-04 00:20:59 +03:00
parent dd94689f41
commit 1caf4a8e2d
2 changed files with 28 additions and 22 deletions

View File

@ -28,11 +28,14 @@
* GNU General Public License for more details. * * GNU General Public License for more details. *
****************************************************************************/ ****************************************************************************/
#include "lrcoloreditor.h" #include "lrcoloreditor.h"
#include "lrglobal.h"
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QColorDialog> #include <QColorDialog>
#include <QPaintEvent> #include <QPaintEvent>
#include <QPainter> #include <QPainter>
#include <QApplication>
#include <QStyle>
namespace LimeReport{ namespace LimeReport{
@ -94,18 +97,23 @@ void ColorEditor::slotClicked()
emit(editingFinished()); emit(editingFinished());
} }
void ColorIndicator::paintEvent(QPaintEvent* event) void ColorIndicator::paintEvent(QPaintEvent* event)
{ {
QPainter painter(this); QPainter painter(this);
QStyle* style = QApplication::style();
painter.save(); painter.save();
painter.setBrush(m_color); painter.setBrush(m_color);
painter.setPen(Qt::transparent); QColor penColor = isColorDark(m_color) ? Qt::transparent : Qt::darkGray;
QRect rect = event->rect().adjusted(3,3,-4,-4);
rect.setWidth(rect.height()); painter.setPen(penColor);
painter.setRenderHint(QPainter::Antialiasing); int border = (event->rect().height() - style->pixelMetric(QStyle::PM_IndicatorWidth))/2;
// painter.drawEllipse(rect);
painter.drawRoundedRect(rect,2,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(); painter.restore();
} }

View File

@ -28,8 +28,10 @@
* GNU General Public License for more details. * * GNU General Public License for more details. *
****************************************************************************/ ****************************************************************************/
#include "lrcolorpropitem.h" #include "lrcolorpropitem.h"
#include "lrglobal.h"
#include "editors/lrcoloreditor.h" #include "editors/lrcoloreditor.h"
#include <QPainter> #include <QPainter>
#include <QApplication>
namespace{ namespace{
LimeReport::ObjectPropItem * createColorPropItem( LimeReport::ObjectPropItem * createColorPropItem(
@ -58,24 +60,20 @@ bool ColorPropItem::paint(QPainter *painter, const StyleOptionViewItem &option,
{ {
if (index.column()==1){ if (index.column()==1){
painter->save(); painter->save();
QStyle* style = option.widget ? option.widget->style() : QApplication::style();
QPen pen; QPen pen;
QColor penColor = isColorDark(propertyValue().value<QColor>()) ? Qt::transparent : Qt::darkGray;
// if (option.state & QStyle::State_Selected){ pen.setColor(penColor);
// pen.setWidth(1);
// pen.setColor(option.palette.brightText().color());
// }else {
// pen.setColor(Qt::darkGray);
// }
pen.setColor(Qt::transparent);
painter->setPen(pen); painter->setPen(pen);
painter->setBrush(propertyValue().value<QColor>()); painter->setBrush(propertyValue().value<QColor>());
QRect rect = option.rect.adjusted(4,4,-4,-6); int border = (option.rect.height() - style->pixelMetric(QStyle::PM_IndicatorWidth))/2;
rect.setWidth(rect.height());
painter->setRenderHint(QPainter::Antialiasing); QRect rect(option.rect.x()+border,option.rect.y()+border,
painter->drawRoundedRect(rect,2,2); style->pixelMetric(QStyle::PM_IndicatorWidth),
// painter->drawEllipse(rect); style->pixelMetric(QStyle::PM_IndicatorWidth));
painter->drawRect(rect);
painter->restore(); painter->restore();
return true; return true;
} else return false; } else return false;