From 106b57ba3ca877aa8233edd22f8edbdd91607aad Mon Sep 17 00:00:00 2001 From: scorpio810 Date: Thu, 26 Dec 2013 17:59:58 +0000 Subject: [PATCH] Added Abhishek Bansal patch: Diagram::background_color is now selectable and make component color reverse color for contrast, thanks Abhishek git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2670 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- sources/borderpropertieswidget.cpp | 32 +++++++++++++++++-- sources/borderpropertieswidget.h | 6 ++++ sources/diagram.cpp | 11 +++++-- sources/diagram.h | 3 +- sources/diagramview.cpp | 6 +++- sources/qetgraphicsitem/customelement.cpp | 34 +++++++++++++++++++++ sources/qetgraphicsitem/diagramtextitem.cpp | 5 +++ 7 files changed, 91 insertions(+), 6 deletions(-) diff --git a/sources/borderpropertieswidget.cpp b/sources/borderpropertieswidget.cpp index d5010576c..9aaa70b72 100644 --- a/sources/borderpropertieswidget.cpp +++ b/sources/borderpropertieswidget.cpp @@ -19,7 +19,10 @@ #include #include "qetapp.h" #include "bordertitleblock.h" - +// added to incorporate QColor functionality and so that +// variable Diagram::background_color is recognized in this file +#include +#include "diagram.h" /** Constructeur Construit un widget editant les proprietes d'une bordure @@ -126,6 +129,11 @@ void BorderPropertiesWidget::build() { rows_height -> setSuffix(tr("px", "unit for rows height")); display_rows = new QCheckBox(tr("Afficher les en-t\352tes"), diagram_size_box); + + widget_layout -> addWidget(diagram_size_box); + // add background color field + QLabel *ds3 = new QLabel(tr("Couleur de fond :")); + pb_background_color = new QPushButton(diagram_size_box); // layout diagram_size_box_layout -> addWidget(ds1, 0, 0); @@ -137,6 +145,26 @@ void BorderPropertiesWidget::build() { diagram_size_box_layout -> addWidget(rows_height, 1, 2); diagram_size_box_layout -> addWidget(display_rows, 1, 3); - widget_layout -> addWidget(diagram_size_box); + diagram_size_box_layout -> addWidget(ds3, 2, 0, 1, 2); + diagram_size_box_layout -> addWidget(pb_background_color, 2, 2, 1, 2); + // make color of pushbutton same as the present background color chosen + QPalette palette; + palette.setColor(QPalette::Button, Diagram::background_color); + pb_background_color -> setPalette(palette); + + //build button connection + connect(pb_background_color, SIGNAL(clicked()), this, SLOT(chooseColor())); setLayout(widget_layout); +} + /** + Background color choose QColorDialog. Makes Diagram::background_color equal to new chosen color. + */ +void BorderPropertiesWidget::chooseColor() { + QColor user_chosen_color = QColorDialog::getColor(Diagram::background_color); + if (user_chosen_color.isValid()) { + Diagram::background_color = user_chosen_color; + QPalette palette; + palette.setColor(QPalette::Button, Diagram::background_color); + pb_background_color -> setPalette(palette); + } } diff --git a/sources/borderpropertieswidget.h b/sources/borderpropertieswidget.h index d5836e1fb..029d996c2 100644 --- a/sources/borderpropertieswidget.h +++ b/sources/borderpropertieswidget.h @@ -21,6 +21,7 @@ #include "borderproperties.h" class QCheckBox; class QSpinBox; +class QPushButton; /** This class provides a widget to edit dimensions and display properties of a diagram, title block excluded. @@ -42,6 +43,10 @@ class BorderPropertiesWidget : public QWidget { bool isReadOnly() const; void setReadOnly(bool); void setEditedBorder(const BorderProperties &); + + public slots: + // to choose the back_ground color of diagram. + void chooseColor(); private: void build(); @@ -55,5 +60,6 @@ class BorderPropertiesWidget : public QWidget { QSpinBox *rows_count; ///< Widget to edit the rows count QSpinBox *rows_height; ///< Widget to edit the rows height QCheckBox *display_rows; ///< Checkbox stating whether to display row headers + QPushButton *pb_background_color; ///< Push button for selecting diagram background color }; #endif diff --git a/sources/diagram.cpp b/sources/diagram.cpp index c516f9e2e..4c400f4bd 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -37,6 +37,8 @@ const int Diagram::xGrid = 10; const int Diagram::yGrid = 10; const qreal Diagram::margin = 5.0; +// static variable to keep track of present background color of the diagram. +QColor Diagram::background_color = Qt::white; /** Constructeur @param parent Le QObject parent du schema @@ -121,12 +123,17 @@ void Diagram::drawBackground(QPainter *p, const QRectF &r) { // dessine un fond blanc p -> setPen(Qt::NoPen); - p -> setBrush(Qt::white); + //set brush color to present background color. + p -> setBrush(Diagram::background_color); p -> drawRect(r); if (draw_grid_) { // dessine les points de la grille - p -> setPen(Qt::black); + // if background color is black, then grid spots shall be white, else they shall be black in color. + if (Diagram::background_color == Qt::black) + p -> setPen(Qt::white); + else + p -> setPen(Qt::black); p -> setBrush(Qt::NoBrush); qreal limite_x = r.x() + r.width(); qreal limite_y = r.y() + r.height(); diff --git a/sources/diagram.h b/sources/diagram.h index 5f29c491b..65a4a6dfa 100644 --- a/sources/diagram.h +++ b/sources/diagram.h @@ -77,7 +77,8 @@ class Diagram : public QGraphicsScene { static const int yGrid; /// margin around the diagram static const qreal margin; - + /// background color of diagram + static QColor background_color; private: QGraphicsLineItem *conductor_setter_; ElementsMover *elements_mover_; diff --git a/sources/diagramview.cpp b/sources/diagramview.cpp index c2fda0e94..9c66585b1 100644 --- a/sources/diagramview.cpp +++ b/sources/diagramview.cpp @@ -652,7 +652,11 @@ void DiagramView::editDiagramProperties() { /// TODO implement an undo command to allow the user to undo/redo this action scene -> defaultConductorProperties = new_conductors; } - if (adjust_scene) adjustSceneRect(); + // adjustSceneRect shall be called whenever the user accepts the dialog + // even if no changes have been made. + // Added so that diagram refreshes after back-ground color change. + //if (adjust_scene) + adjustSceneRect(); } } diff --git a/sources/qetgraphicsitem/customelement.cpp b/sources/qetgraphicsitem/customelement.cpp index 122af8607..9b24c0f1a 100644 --- a/sources/qetgraphicsitem/customelement.cpp +++ b/sources/qetgraphicsitem/customelement.cpp @@ -148,6 +148,12 @@ bool CustomElement::buildFromXml(const QDomElement &xml_def_elmt, int *state) { low_zoom_qp.begin(&low_zoom_drawing); QPen tmp; tmp.setWidthF(1.0); // ligne vaudou pour prise en compte du setCosmetic - ne pas enlever + // make component color reverse of back_ground color for contrast + QColor color(Diagram::background_color); + color.setBlue(255 - color.blue()); + color.setGreen(255 - color.green()); + color.setRed(255 - color.red()); + tmp.setColor(color); tmp.setCosmetic(true); low_zoom_qp.setPen(tmp); @@ -293,6 +299,12 @@ bool CustomElement::parseLine(QDomElement &e, QPainter &qp) { setPainterStyle(e, qp); QPen t = qp.pen(); t.setJoinStyle(Qt::MiterJoin); + // make component color reverse of back_ground color for contrast + QColor color(Diagram::background_color); + color.setBlue(255 - color.blue()); + color.setGreen(255 - color.green()); + color.setRed(255 - color.red()); + t.setColor(color); qp.setPen(t); QLineF line(x1, y1, x2, y2); @@ -397,6 +409,12 @@ bool CustomElement::parseRect(QDomElement &e, QPainter &qp) { // force le type de jointures pour les rectangles QPen p = qp.pen(); p.setJoinStyle(Qt::MiterJoin); + // make component color reverse of back_ground color for contrast + QColor color(Diagram::background_color); + color.setBlue(255 - color.blue()); + color.setGreen(255 - color.green()); + color.setRed(255 - color.red()); + p.setColor(color); qp.setPen(p); qp.drawRect(QRectF(rect_x, rect_y, rect_w, rect_h)); @@ -549,6 +567,13 @@ bool CustomElement::parseText(QDomElement &e, QPainter &qp) { QFont used_font = QETApp::diagramTextsFont(size); QFontMetrics qfm(used_font); QColor text_color = (e.attribute("color") != "white"? Qt::black : Qt::white); + + // make component color reverse of back_ground color for contrast + QColor color(Diagram::background_color); + color.setBlue(255 - color.blue()); + color.setGreen(255 - color.green()); + color.setRed(255 - color.red()); + text_color = color; // instancie un QTextDocument (comme la classe QGraphicsTextItem) pour // generer le rendu graphique du texte @@ -743,6 +768,13 @@ void CustomElement::setPainterStyle(QDomElement &e, QPainter &qp) { pen.setJoinStyle(Qt::BevelJoin); pen.setCapStyle(Qt::SquareCap); + // make component color reverse of back_ground color for contrast + QColor color(Diagram::background_color); + color.setBlue(255 - color.blue()); + color.setGreen(255 - color.green()); + color.setRed(255 - color.red()); + pen.setColor(color); + // recupere la liste des couples style / valeur QStringList styles = e.attribute("style").split(";", QString::SkipEmptyParts); @@ -796,6 +828,8 @@ void CustomElement::setPainterStyle(QDomElement &e, QPainter &qp) { pen.setColor(Qt::green); } } + // make component color reverse of back_ground color for contrast + pen.setColor(color); } } diff --git a/sources/qetgraphicsitem/diagramtextitem.cpp b/sources/qetgraphicsitem/diagramtextitem.cpp index 77e35fdc2..35d2ff6a2 100644 --- a/sources/qetgraphicsitem/diagramtextitem.cpp +++ b/sources/qetgraphicsitem/diagramtextitem.cpp @@ -198,6 +198,11 @@ void DiagramTextItem::setFontSize(int &s) { */ void DiagramTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { painter -> setRenderHint(QPainter::Antialiasing, false); + QColor color(Diagram::background_color); + color.setBlue(255 - color.blue()); + color.setGreen(255 - color.green()); + color.setRed(255 - color.red()); + setDefaultTextColor(color); QGraphicsTextItem::paint(painter, option, widget); }