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
This commit is contained in:
scorpio810
2013-12-26 17:59:58 +00:00
parent ef4bbdf0e3
commit 106b57ba3c
7 changed files with 91 additions and 6 deletions

View File

@@ -19,7 +19,10 @@
#include <QtGui> #include <QtGui>
#include "qetapp.h" #include "qetapp.h"
#include "bordertitleblock.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 Constructeur
Construit un widget editant les proprietes d'une bordure 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")); rows_height -> setSuffix(tr("px", "unit for rows height"));
display_rows = new QCheckBox(tr("Afficher les en-t\352tes"), diagram_size_box); 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 // layout
diagram_size_box_layout -> addWidget(ds1, 0, 0); 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(rows_height, 1, 2);
diagram_size_box_layout -> addWidget(display_rows, 1, 3); 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); 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);
}
} }

View File

@@ -21,6 +21,7 @@
#include "borderproperties.h" #include "borderproperties.h"
class QCheckBox; class QCheckBox;
class QSpinBox; class QSpinBox;
class QPushButton;
/** /**
This class provides a widget to edit dimensions and display properties of a This class provides a widget to edit dimensions and display properties of a
diagram, title block excluded. diagram, title block excluded.
@@ -42,6 +43,10 @@ class BorderPropertiesWidget : public QWidget {
bool isReadOnly() const; bool isReadOnly() const;
void setReadOnly(bool); void setReadOnly(bool);
void setEditedBorder(const BorderProperties &); void setEditedBorder(const BorderProperties &);
public slots:
// to choose the back_ground color of diagram.
void chooseColor();
private: private:
void build(); void build();
@@ -55,5 +60,6 @@ class BorderPropertiesWidget : public QWidget {
QSpinBox *rows_count; ///< Widget to edit the rows count QSpinBox *rows_count; ///< Widget to edit the rows count
QSpinBox *rows_height; ///< Widget to edit the rows height QSpinBox *rows_height; ///< Widget to edit the rows height
QCheckBox *display_rows; ///< Checkbox stating whether to display row headers QCheckBox *display_rows; ///< Checkbox stating whether to display row headers
QPushButton *pb_background_color; ///< Push button for selecting diagram background color
}; };
#endif #endif

View File

@@ -37,6 +37,8 @@ const int Diagram::xGrid = 10;
const int Diagram::yGrid = 10; const int Diagram::yGrid = 10;
const qreal Diagram::margin = 5.0; 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 Constructeur
@param parent Le QObject parent du schema @param parent Le QObject parent du schema
@@ -121,12 +123,17 @@ void Diagram::drawBackground(QPainter *p, const QRectF &r) {
// dessine un fond blanc // dessine un fond blanc
p -> setPen(Qt::NoPen); p -> setPen(Qt::NoPen);
p -> setBrush(Qt::white); //set brush color to present background color.
p -> setBrush(Diagram::background_color);
p -> drawRect(r); p -> drawRect(r);
if (draw_grid_) { if (draw_grid_) {
// dessine les points de la grille // 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); p -> setBrush(Qt::NoBrush);
qreal limite_x = r.x() + r.width(); qreal limite_x = r.x() + r.width();
qreal limite_y = r.y() + r.height(); qreal limite_y = r.y() + r.height();

View File

@@ -77,7 +77,8 @@ class Diagram : public QGraphicsScene {
static const int yGrid; static const int yGrid;
/// margin around the diagram /// margin around the diagram
static const qreal margin; static const qreal margin;
/// background color of diagram
static QColor background_color;
private: private:
QGraphicsLineItem *conductor_setter_; QGraphicsLineItem *conductor_setter_;
ElementsMover *elements_mover_; ElementsMover *elements_mover_;

View File

@@ -652,7 +652,11 @@ void DiagramView::editDiagramProperties() {
/// TODO implement an undo command to allow the user to undo/redo this action /// TODO implement an undo command to allow the user to undo/redo this action
scene -> defaultConductorProperties = new_conductors; 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();
} }
} }

View File

@@ -148,6 +148,12 @@ bool CustomElement::buildFromXml(const QDomElement &xml_def_elmt, int *state) {
low_zoom_qp.begin(&low_zoom_drawing); low_zoom_qp.begin(&low_zoom_drawing);
QPen tmp; QPen tmp;
tmp.setWidthF(1.0); // ligne vaudou pour prise en compte du setCosmetic - ne pas enlever 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); tmp.setCosmetic(true);
low_zoom_qp.setPen(tmp); low_zoom_qp.setPen(tmp);
@@ -293,6 +299,12 @@ bool CustomElement::parseLine(QDomElement &e, QPainter &qp) {
setPainterStyle(e, qp); setPainterStyle(e, qp);
QPen t = qp.pen(); QPen t = qp.pen();
t.setJoinStyle(Qt::MiterJoin); 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); qp.setPen(t);
QLineF line(x1, y1, x2, y2); 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 // force le type de jointures pour les rectangles
QPen p = qp.pen(); QPen p = qp.pen();
p.setJoinStyle(Qt::MiterJoin); 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.setPen(p);
qp.drawRect(QRectF(rect_x, rect_y, rect_w, rect_h)); 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); QFont used_font = QETApp::diagramTextsFont(size);
QFontMetrics qfm(used_font); QFontMetrics qfm(used_font);
QColor text_color = (e.attribute("color") != "white"? Qt::black : Qt::white); 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 // instancie un QTextDocument (comme la classe QGraphicsTextItem) pour
// generer le rendu graphique du texte // generer le rendu graphique du texte
@@ -743,6 +768,13 @@ void CustomElement::setPainterStyle(QDomElement &e, QPainter &qp) {
pen.setJoinStyle(Qt::BevelJoin); pen.setJoinStyle(Qt::BevelJoin);
pen.setCapStyle(Qt::SquareCap); 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 // recupere la liste des couples style / valeur
QStringList styles = e.attribute("style").split(";", QString::SkipEmptyParts); QStringList styles = e.attribute("style").split(";", QString::SkipEmptyParts);
@@ -796,6 +828,8 @@ void CustomElement::setPainterStyle(QDomElement &e, QPainter &qp) {
pen.setColor(Qt::green); pen.setColor(Qt::green);
} }
} }
// make component color reverse of back_ground color for contrast
pen.setColor(color);
} }
} }

View File

@@ -198,6 +198,11 @@ void DiagramTextItem::setFontSize(int &s) {
*/ */
void DiagramTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { void DiagramTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
painter -> setRenderHint(QPainter::Antialiasing, false); 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); QGraphicsTextItem::paint(painter, option, widget);
} }