mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-22 17:50:52 +01:00
Il est desormais possible de choisir la couleur de chaque conducteur.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@755 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -451,26 +451,27 @@ void Conductor::paint(QPainter *qp, const QStyleOptionGraphicsItem *options, QWi
|
|||||||
qp -> save();
|
qp -> save();
|
||||||
qp -> setRenderHint(QPainter::Antialiasing, false);
|
qp -> setRenderHint(QPainter::Antialiasing, false);
|
||||||
|
|
||||||
|
// determine la couleur du conducteur
|
||||||
|
QColor final_conductor_color = isSelected() ? Qt::red : properties_.color;
|
||||||
|
|
||||||
// affectation du QPen et de la QBrush modifies au QPainter
|
// affectation du QPen et de la QBrush modifies au QPainter
|
||||||
qp -> setBrush(conductor_brush);
|
qp -> setBrush(conductor_brush);
|
||||||
qp -> setPen(conductor_pen);
|
QPen final_conductor_pen = conductor_pen;
|
||||||
if (isSelected()) {
|
|
||||||
QPen tmp = qp -> pen();
|
// modification du QPen generique pour lui affecter la couleur adequate
|
||||||
tmp.setColor(Qt::red);
|
final_conductor_pen.setColor(final_conductor_color);
|
||||||
qp -> setPen(tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
// utilisation d'un trait "cosmetique" en-dessous d'un certain zoom
|
// utilisation d'un trait "cosmetique" en-dessous d'un certain zoom
|
||||||
if (options && options -> levelOfDetail < 1.0) {
|
if (options && options -> levelOfDetail < 1.0) {
|
||||||
QPen tmp = qp -> pen();
|
final_conductor_pen.setCosmetic(true);
|
||||||
tmp.setCosmetic(true);
|
|
||||||
qp -> setPen(tmp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qp -> setPen(final_conductor_pen);
|
||||||
|
|
||||||
// dessin du conducteur
|
// dessin du conducteur
|
||||||
qp -> drawPath(path());
|
qp -> drawPath(path());
|
||||||
if (properties_.type == ConductorProperties::Single) {
|
if (properties_.type == ConductorProperties::Single) {
|
||||||
if (isSelected()) qp -> setBrush(Qt::red);
|
qp -> setBrush(final_conductor_color);
|
||||||
properties_.singleLineProperties.draw(
|
properties_.singleLineProperties.draw(
|
||||||
qp,
|
qp,
|
||||||
middleSegment() -> isHorizontal() ? QET::Horizontal : QET::Vertical,
|
middleSegment() -> isHorizontal() ? QET::Horizontal : QET::Vertical,
|
||||||
@@ -509,7 +510,7 @@ void Conductor::paint(QPainter *qp, const QStyleOptionGraphicsItem *options, QWi
|
|||||||
QList<QPointF> junctions_list = junctions();
|
QList<QPointF> junctions_list = junctions();
|
||||||
if (!junctions_list.isEmpty()) {
|
if (!junctions_list.isEmpty()) {
|
||||||
QBrush junction_brush(Qt::SolidPattern);
|
QBrush junction_brush(Qt::SolidPattern);
|
||||||
junction_brush.setColor(isSelected() ? Qt::red : Qt::black);
|
junction_brush.setColor(final_conductor_color);
|
||||||
qp -> setBrush(junction_brush);
|
qp -> setBrush(junction_brush);
|
||||||
qp -> setRenderHint(QPainter::Antialiasing, true);
|
qp -> setRenderHint(QPainter::Antialiasing, true);
|
||||||
foreach(QPointF point, junctions_list) {
|
foreach(QPointF point, junctions_list) {
|
||||||
@@ -1100,6 +1101,7 @@ ConductorProperties Conductor::properties() const {
|
|||||||
Relit les proprietes et les applique
|
Relit les proprietes et les applique
|
||||||
*/
|
*/
|
||||||
void Conductor::readProperties() {
|
void Conductor::readProperties() {
|
||||||
|
// la couleur n'est vraiment applicable que lors du rendu du conducteur
|
||||||
setText(properties_.text);
|
setText(properties_.text);
|
||||||
text_item -> setVisible(properties_.type == ConductorProperties::Multi);
|
text_item -> setVisible(properties_.type == ConductorProperties::Multi);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -180,6 +180,23 @@ void SingleLineProperties::fromXml(QDomElement &e) {
|
|||||||
setPhasesCount(e.attribute("phase").toInt());
|
setPhasesCount(e.attribute("phase").toInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Constructeur : par defaut, les proprietes font un conducteur
|
||||||
|
multifilaire noir dont le texte est "_"
|
||||||
|
*/
|
||||||
|
ConductorProperties::ConductorProperties() :
|
||||||
|
type(Multi),
|
||||||
|
color(Qt::black),
|
||||||
|
text("_")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Destructeur
|
||||||
|
*/
|
||||||
|
ConductorProperties::~ConductorProperties() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Exporte les parametres du conducteur sous formes d'attributs XML
|
Exporte les parametres du conducteur sous formes d'attributs XML
|
||||||
ajoutes a l'element e.
|
ajoutes a l'element e.
|
||||||
@@ -187,6 +204,7 @@ void SingleLineProperties::fromXml(QDomElement &e) {
|
|||||||
*/
|
*/
|
||||||
void ConductorProperties::toXml(QDomElement &e) const {
|
void ConductorProperties::toXml(QDomElement &e) const {
|
||||||
e.setAttribute("type", typeToString(type));
|
e.setAttribute("type", typeToString(type));
|
||||||
|
e.setAttribute("color", color.name());
|
||||||
if (type == Single) {
|
if (type == Single) {
|
||||||
singleLineProperties.toXml(e);
|
singleLineProperties.toXml(e);
|
||||||
} else if (type == Multi) {
|
} else if (type == Multi) {
|
||||||
@@ -200,6 +218,14 @@ void ConductorProperties::toXml(QDomElement &e) const {
|
|||||||
@param e Element XML dont les attributs seront lus
|
@param e Element XML dont les attributs seront lus
|
||||||
*/
|
*/
|
||||||
void ConductorProperties::fromXml(QDomElement &e) {
|
void ConductorProperties::fromXml(QDomElement &e) {
|
||||||
|
// recupere la couleur du conducteur
|
||||||
|
QColor xml_color= QColor(e.attribute("color"));
|
||||||
|
if (xml_color.isValid()) {
|
||||||
|
color = xml_color;
|
||||||
|
} else {
|
||||||
|
color = QColor(Qt::black);
|
||||||
|
}
|
||||||
|
|
||||||
if (e.attribute("type") == typeToString(Single)) {
|
if (e.attribute("type") == typeToString(Single)) {
|
||||||
// recupere les parametres specifiques a un conducteur unifilaire
|
// recupere les parametres specifiques a un conducteur unifilaire
|
||||||
singleLineProperties.fromXml(e);
|
singleLineProperties.fromXml(e);
|
||||||
@@ -218,6 +244,7 @@ void ConductorProperties::fromXml(QDomElement &e) {
|
|||||||
@param prefix prefixe a ajouter devant les noms des parametres
|
@param prefix prefixe a ajouter devant les noms des parametres
|
||||||
*/
|
*/
|
||||||
void ConductorProperties::toSettings(QSettings &settings, const QString &prefix) const {
|
void ConductorProperties::toSettings(QSettings &settings, const QString &prefix) const {
|
||||||
|
settings.setValue(prefix + "color", color.name());
|
||||||
settings.setValue(prefix + "type", typeToString(type));
|
settings.setValue(prefix + "type", typeToString(type));
|
||||||
settings.setValue(prefix + "text", text);
|
settings.setValue(prefix + "text", text);
|
||||||
singleLineProperties.toSettings(settings, prefix);
|
singleLineProperties.toSettings(settings, prefix);
|
||||||
@@ -228,6 +255,14 @@ void ConductorProperties::toSettings(QSettings &settings, const QString &prefix)
|
|||||||
@param prefix prefixe a ajouter devant les noms des parametres
|
@param prefix prefixe a ajouter devant les noms des parametres
|
||||||
*/
|
*/
|
||||||
void ConductorProperties::fromSettings(QSettings &settings, const QString &prefix) {
|
void ConductorProperties::fromSettings(QSettings &settings, const QString &prefix) {
|
||||||
|
// recupere la couleur dans les parametres
|
||||||
|
QColor settings_color = QColor(settings.value(prefix + "color").toString());
|
||||||
|
if (settings_color.isValid()) {
|
||||||
|
color = settings_color;
|
||||||
|
} else {
|
||||||
|
color = QColor(Qt::black);
|
||||||
|
}
|
||||||
|
|
||||||
QString setting_type = settings.value(prefix + "type", typeToString(Multi)).toString();
|
QString setting_type = settings.value(prefix + "type", typeToString(Multi)).toString();
|
||||||
if (setting_type == typeToString(Single)) {
|
if (setting_type == typeToString(Single)) {
|
||||||
type = Single;
|
type = Single;
|
||||||
@@ -259,6 +294,7 @@ QString ConductorProperties::typeToString(ConductorType t) {
|
|||||||
int ConductorProperties::operator==(const ConductorProperties &other) {
|
int ConductorProperties::operator==(const ConductorProperties &other) {
|
||||||
return(
|
return(
|
||||||
other.type == type &&\
|
other.type == type &&\
|
||||||
|
other.color == color &&\
|
||||||
other.text == text &&\
|
other.text == text &&\
|
||||||
other.singleLineProperties == singleLineProperties
|
other.singleLineProperties == singleLineProperties
|
||||||
);
|
);
|
||||||
@@ -271,6 +307,7 @@ int ConductorProperties::operator==(const ConductorProperties &other) {
|
|||||||
int ConductorProperties::operator!=(const ConductorProperties &other) {
|
int ConductorProperties::operator!=(const ConductorProperties &other) {
|
||||||
return(
|
return(
|
||||||
other.type != type ||\
|
other.type != type ||\
|
||||||
|
other.color != color ||\
|
||||||
other.text != text ||\
|
other.text != text ||\
|
||||||
other.singleLineProperties != singleLineProperties
|
other.singleLineProperties != singleLineProperties
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -57,16 +57,8 @@ class SingleLineProperties {
|
|||||||
class ConductorProperties {
|
class ConductorProperties {
|
||||||
// constructeurs, destructeur
|
// constructeurs, destructeur
|
||||||
public:
|
public:
|
||||||
/**
|
ConductorProperties();
|
||||||
Constructeur : par defaut, les proprietes font un conducteur
|
virtual ~ConductorProperties();
|
||||||
multifilaire dont le texte est "_"
|
|
||||||
*/
|
|
||||||
ConductorProperties() : type(Multi), text("_") {
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Destructeur
|
|
||||||
virtual ~ConductorProperties() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Represente le type d'un conducteur :
|
Represente le type d'un conducteur :
|
||||||
@@ -79,7 +71,8 @@ class ConductorProperties {
|
|||||||
// attributs
|
// attributs
|
||||||
/// type du conducteur
|
/// type du conducteur
|
||||||
ConductorType type;
|
ConductorType type;
|
||||||
|
/// couleur du conducteur
|
||||||
|
QColor color;
|
||||||
/// texte affiche si le conducteur est multifilaire
|
/// texte affiche si le conducteur est multifilaire
|
||||||
QString text;
|
QString text;
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ ConductorPropertiesWidget::ConductorPropertiesWidget(const ConductorProperties &
|
|||||||
/// construit l'interface du widget
|
/// construit l'interface du widget
|
||||||
void ConductorPropertiesWidget::buildInterface() {
|
void ConductorPropertiesWidget::buildInterface() {
|
||||||
|
|
||||||
setMinimumSize(380, 280);
|
setMinimumSize(380, 320);
|
||||||
|
|
||||||
QVBoxLayout *main_layout = new QVBoxLayout(this);
|
QVBoxLayout *main_layout = new QVBoxLayout(this);
|
||||||
main_layout -> setContentsMargins(0, 0, 0, 0);
|
main_layout -> setContentsMargins(0, 0, 0, 0);
|
||||||
@@ -93,12 +93,28 @@ void ConductorPropertiesWidget::buildInterface() {
|
|||||||
singleline_layout1 -> addWidget(preview);
|
singleline_layout1 -> addWidget(preview);
|
||||||
singleline_layout1 -> addLayout(singleline_layout2);
|
singleline_layout1 -> addLayout(singleline_layout2);
|
||||||
|
|
||||||
|
QGroupBox *groupbox2 = new QGroupBox(tr("Apparence du conducteur"));
|
||||||
|
main_layout -> addWidget(groupbox2);
|
||||||
|
|
||||||
|
QVBoxLayout *groupbox2_layout = new QVBoxLayout();
|
||||||
|
groupbox2 -> setLayout(groupbox2_layout);
|
||||||
|
|
||||||
|
QHBoxLayout *color_layout = new QHBoxLayout();
|
||||||
|
QLabel *text1 = new QLabel(tr("Couleur :"));
|
||||||
|
color_button = new QPushButton("");
|
||||||
|
|
||||||
|
color_layout -> addWidget(text1);
|
||||||
|
color_layout -> addWidget(color_button);
|
||||||
|
setColorButton(properties_.color);
|
||||||
|
|
||||||
groupbox_layout -> addWidget(simple);
|
groupbox_layout -> addWidget(simple);
|
||||||
groupbox_layout -> addWidget(multiline);
|
groupbox_layout -> addWidget(multiline);
|
||||||
groupbox_layout -> addLayout(multiline_layout);
|
groupbox_layout -> addLayout(multiline_layout);
|
||||||
groupbox_layout -> addWidget(singleline);
|
groupbox_layout -> addWidget(singleline);
|
||||||
groupbox_layout -> addLayout(singleline_layout1);
|
groupbox_layout -> addLayout(singleline_layout1);
|
||||||
|
|
||||||
|
groupbox2_layout -> addLayout(color_layout);
|
||||||
|
|
||||||
radio_buttons = new QButtonGroup(this);
|
radio_buttons = new QButtonGroup(this);
|
||||||
radio_buttons -> addButton(simple, ConductorProperties::Simple);
|
radio_buttons -> addButton(simple, ConductorProperties::Simple);
|
||||||
radio_buttons -> addButton(multiline, ConductorProperties::Multi);
|
radio_buttons -> addButton(multiline, ConductorProperties::Multi);
|
||||||
@@ -118,6 +134,36 @@ void ConductorPropertiesWidget::buildConnections() {
|
|||||||
connect(phase_slider, SIGNAL(valueChanged(int)), this, SLOT(updateConfig()));
|
connect(phase_slider, SIGNAL(valueChanged(int)), this, SLOT(updateConfig()));
|
||||||
connect(radio_buttons, SIGNAL(buttonClicked(int)), this, SLOT(updateConfig()));
|
connect(radio_buttons, SIGNAL(buttonClicked(int)), this, SLOT(updateConfig()));
|
||||||
connect(text_field, SIGNAL(textChanged(const QString &)), this, SLOT(updateConfig()));
|
connect(text_field, SIGNAL(textChanged(const QString &)), this, SLOT(updateConfig()));
|
||||||
|
connect(color_button, SIGNAL(clicked()), this, SLOT(chooseColor()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Demande a l'utilisateur de choisir une couleur via un dialogue approprie.
|
||||||
|
*/
|
||||||
|
void ConductorPropertiesWidget::chooseColor() {
|
||||||
|
QColor user_chosen_color = QColorDialog::getColor(properties_.color);
|
||||||
|
if (user_chosen_color.isValid()) {
|
||||||
|
setColorButton(user_chosen_color);
|
||||||
|
updateConfig();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@return la couleur actuelle du bouton permettant de choisir la couleur du
|
||||||
|
conducteur
|
||||||
|
*/
|
||||||
|
QColor ConductorPropertiesWidget::colorButton() const {
|
||||||
|
return(color_button -> palette().color(QPalette::Button));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Change la couleur du bouton permettant de choisir la couleur du conducteur
|
||||||
|
@param color Nouvelle couleur a afficher
|
||||||
|
*/
|
||||||
|
void ConductorPropertiesWidget::setColorButton(const QColor &color) {
|
||||||
|
QPalette palette;
|
||||||
|
palette.setColor(QPalette::Button, color);
|
||||||
|
color_button -> setPalette(palette);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Enleve les connexions signaux/slots
|
/// Enleve les connexions signaux/slots
|
||||||
@@ -130,6 +176,7 @@ void ConductorPropertiesWidget::destroyConnections() {
|
|||||||
disconnect(phase_slider, SIGNAL(valueChanged(int)), this, SLOT(updateConfig()));
|
disconnect(phase_slider, SIGNAL(valueChanged(int)), this, SLOT(updateConfig()));
|
||||||
disconnect(radio_buttons, SIGNAL(buttonClicked(int)), this, SLOT(updateConfig()));
|
disconnect(radio_buttons, SIGNAL(buttonClicked(int)), this, SLOT(updateConfig()));
|
||||||
disconnect(text_field, SIGNAL(textChanged(const QString &)), this, SLOT(updateConfig()));
|
disconnect(text_field, SIGNAL(textChanged(const QString &)), this, SLOT(updateConfig()));
|
||||||
|
disconnect(color_button, SIGNAL(clicked()), this, SLOT(chooseColor()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Destructeur
|
/// Destructeur
|
||||||
@@ -139,6 +186,7 @@ ConductorPropertiesWidget::~ConductorPropertiesWidget() {
|
|||||||
/// Met a jour les proprietes
|
/// Met a jour les proprietes
|
||||||
void ConductorPropertiesWidget::updateConfig() {
|
void ConductorPropertiesWidget::updateConfig() {
|
||||||
properties_.type = static_cast<ConductorProperties::ConductorType>(radio_buttons -> checkedId());
|
properties_.type = static_cast<ConductorProperties::ConductorType>(radio_buttons -> checkedId());
|
||||||
|
properties_.color = colorButton();
|
||||||
properties_.text = text_field -> text();
|
properties_.text = text_field -> text();
|
||||||
properties_.singleLineProperties.hasGround = ground_checkbox -> isChecked();
|
properties_.singleLineProperties.hasGround = ground_checkbox -> isChecked();
|
||||||
properties_.singleLineProperties.hasNeutral = neutral_checkbox -> isChecked();
|
properties_.singleLineProperties.hasNeutral = neutral_checkbox -> isChecked();
|
||||||
@@ -152,6 +200,7 @@ void ConductorPropertiesWidget::updateDisplay() {
|
|||||||
destroyConnections();
|
destroyConnections();
|
||||||
|
|
||||||
setConductorType(properties_.type);
|
setConductorType(properties_.type);
|
||||||
|
setColorButton(properties_.color);
|
||||||
text_field -> setText(properties_.text);
|
text_field -> setText(properties_.text);
|
||||||
ground_checkbox -> setChecked(properties_.singleLineProperties.hasGround);
|
ground_checkbox -> setChecked(properties_.singleLineProperties.hasGround);
|
||||||
neutral_checkbox -> setChecked(properties_.singleLineProperties.hasNeutral);
|
neutral_checkbox -> setChecked(properties_.singleLineProperties.hasNeutral);
|
||||||
|
|||||||
@@ -43,11 +43,14 @@ class ConductorPropertiesWidget : public QWidget {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void setConductorType(ConductorProperties::ConductorType);
|
void setConductorType(ConductorProperties::ConductorType);
|
||||||
|
void setColorButton(const QColor &);
|
||||||
|
QColor colorButton() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updatePreview();
|
void updatePreview();
|
||||||
void updateConfig();
|
void updateConfig();
|
||||||
void updateDisplay();
|
void updateDisplay();
|
||||||
|
void chooseColor();
|
||||||
|
|
||||||
// attributs prives
|
// attributs prives
|
||||||
private:
|
private:
|
||||||
@@ -62,6 +65,7 @@ class ConductorPropertiesWidget : public QWidget {
|
|||||||
QCheckBox *ground_checkbox;
|
QCheckBox *ground_checkbox;
|
||||||
QCheckBox *neutral_checkbox;
|
QCheckBox *neutral_checkbox;
|
||||||
QLabel *preview;
|
QLabel *preview;
|
||||||
|
QPushButton *color_button;
|
||||||
|
|
||||||
ConductorProperties properties_;
|
ConductorProperties properties_;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user