[qet] [2670] Added Abhishek Bansal patch: |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 2670
Author: scorpio810
Date: 2013-12-26 18:59:58 +0100 (Thu, 26 Dec 2013)
Log Message:
-----------
Added Abhishek Bansal patch:
Diagram::background_color is now selectable
and make component color reverse color for contrast, thanks Abhishek
Modified Paths:
--------------
trunk/sources/borderpropertieswidget.cpp
trunk/sources/borderpropertieswidget.h
trunk/sources/diagram.cpp
trunk/sources/diagram.h
trunk/sources/diagramview.cpp
trunk/sources/qetgraphicsitem/customelement.cpp
trunk/sources/qetgraphicsitem/diagramtextitem.cpp
Modified: trunk/sources/borderpropertieswidget.cpp
===================================================================
--- trunk/sources/borderpropertieswidget.cpp 2013-12-26 14:08:35 UTC (rev 2669)
+++ trunk/sources/borderpropertieswidget.cpp 2013-12-26 17:59:58 UTC (rev 2670)
@@ -19,7 +19,10 @@
#include <QtGui>
#include "qetapp.h"
#include "bordertitleblock.h"
-
+// added to incorporate QColor functionality and so that
+// variable Diagram::background_color is recognized in this file
+#include <QColor>
+#include "diagram.h"
/**
Constructeur
Construit un widget editant les proprietes d'une bordure
@@ -126,6 +129,11 @@
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 @@
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);
+ }
+}
Modified: trunk/sources/borderpropertieswidget.h
===================================================================
--- trunk/sources/borderpropertieswidget.h 2013-12-26 14:08:35 UTC (rev 2669)
+++ trunk/sources/borderpropertieswidget.h 2013-12-26 17:59:58 UTC (rev 2670)
@@ -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 @@
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 @@
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
Modified: trunk/sources/diagram.cpp
===================================================================
--- trunk/sources/diagram.cpp 2013-12-26 14:08:35 UTC (rev 2669)
+++ trunk/sources/diagram.cpp 2013-12-26 17:59:58 UTC (rev 2670)
@@ -37,6 +37,8 @@
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 @@
// 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();
Modified: trunk/sources/diagram.h
===================================================================
--- trunk/sources/diagram.h 2013-12-26 14:08:35 UTC (rev 2669)
+++ trunk/sources/diagram.h 2013-12-26 17:59:58 UTC (rev 2670)
@@ -77,7 +77,8 @@
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_;
Modified: trunk/sources/diagramview.cpp
===================================================================
--- trunk/sources/diagramview.cpp 2013-12-26 14:08:35 UTC (rev 2669)
+++ trunk/sources/diagramview.cpp 2013-12-26 17:59:58 UTC (rev 2670)
@@ -652,7 +652,11 @@
/// 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();
}
}
Modified: trunk/sources/qetgraphicsitem/customelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/customelement.cpp 2013-12-26 14:08:35 UTC (rev 2669)
+++ trunk/sources/qetgraphicsitem/customelement.cpp 2013-12-26 17:59:58 UTC (rev 2670)
@@ -148,6 +148,12 @@
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 @@
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 @@
// 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 @@
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 @@
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 @@
pen.setColor(Qt::green);
}
}
+ // make component color reverse of back_ground color for contrast
+ pen.setColor(color);
}
}
Modified: trunk/sources/qetgraphicsitem/diagramtextitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/diagramtextitem.cpp 2013-12-26 14:08:35 UTC (rev 2669)
+++ trunk/sources/qetgraphicsitem/diagramtextitem.cpp 2013-12-26 17:59:58 UTC (rev 2670)
@@ -198,6 +198,11 @@
*/
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);
}