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 -> 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
|
||||
qp -> setBrush(conductor_brush);
|
||||
qp -> setPen(conductor_pen);
|
||||
if (isSelected()) {
|
||||
QPen tmp = qp -> pen();
|
||||
tmp.setColor(Qt::red);
|
||||
qp -> setPen(tmp);
|
||||
}
|
||||
QPen final_conductor_pen = conductor_pen;
|
||||
|
||||
// modification du QPen generique pour lui affecter la couleur adequate
|
||||
final_conductor_pen.setColor(final_conductor_color);
|
||||
|
||||
// utilisation d'un trait "cosmetique" en-dessous d'un certain zoom
|
||||
if (options && options -> levelOfDetail < 1.0) {
|
||||
QPen tmp = qp -> pen();
|
||||
tmp.setCosmetic(true);
|
||||
qp -> setPen(tmp);
|
||||
final_conductor_pen.setCosmetic(true);
|
||||
}
|
||||
|
||||
qp -> setPen(final_conductor_pen);
|
||||
|
||||
// dessin du conducteur
|
||||
qp -> drawPath(path());
|
||||
if (properties_.type == ConductorProperties::Single) {
|
||||
if (isSelected()) qp -> setBrush(Qt::red);
|
||||
qp -> setBrush(final_conductor_color);
|
||||
properties_.singleLineProperties.draw(
|
||||
qp,
|
||||
middleSegment() -> isHorizontal() ? QET::Horizontal : QET::Vertical,
|
||||
@@ -509,7 +510,7 @@ void Conductor::paint(QPainter *qp, const QStyleOptionGraphicsItem *options, QWi
|
||||
QList<QPointF> junctions_list = junctions();
|
||||
if (!junctions_list.isEmpty()) {
|
||||
QBrush junction_brush(Qt::SolidPattern);
|
||||
junction_brush.setColor(isSelected() ? Qt::red : Qt::black);
|
||||
junction_brush.setColor(final_conductor_color);
|
||||
qp -> setBrush(junction_brush);
|
||||
qp -> setRenderHint(QPainter::Antialiasing, true);
|
||||
foreach(QPointF point, junctions_list) {
|
||||
@@ -1100,6 +1101,7 @@ ConductorProperties Conductor::properties() const {
|
||||
Relit les proprietes et les applique
|
||||
*/
|
||||
void Conductor::readProperties() {
|
||||
// la couleur n'est vraiment applicable que lors du rendu du conducteur
|
||||
setText(properties_.text);
|
||||
text_item -> setVisible(properties_.type == ConductorProperties::Multi);
|
||||
}
|
||||
|
||||
@@ -180,6 +180,23 @@ void SingleLineProperties::fromXml(QDomElement &e) {
|
||||
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
|
||||
ajoutes a l'element e.
|
||||
@@ -187,6 +204,7 @@ void SingleLineProperties::fromXml(QDomElement &e) {
|
||||
*/
|
||||
void ConductorProperties::toXml(QDomElement &e) const {
|
||||
e.setAttribute("type", typeToString(type));
|
||||
e.setAttribute("color", color.name());
|
||||
if (type == Single) {
|
||||
singleLineProperties.toXml(e);
|
||||
} else if (type == Multi) {
|
||||
@@ -200,6 +218,14 @@ void ConductorProperties::toXml(QDomElement &e) const {
|
||||
@param e Element XML dont les attributs seront lus
|
||||
*/
|
||||
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)) {
|
||||
// recupere les parametres specifiques a un conducteur unifilaire
|
||||
singleLineProperties.fromXml(e);
|
||||
@@ -218,6 +244,7 @@ void ConductorProperties::fromXml(QDomElement &e) {
|
||||
@param prefix prefixe a ajouter devant les noms des parametres
|
||||
*/
|
||||
void ConductorProperties::toSettings(QSettings &settings, const QString &prefix) const {
|
||||
settings.setValue(prefix + "color", color.name());
|
||||
settings.setValue(prefix + "type", typeToString(type));
|
||||
settings.setValue(prefix + "text", text);
|
||||
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
|
||||
*/
|
||||
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();
|
||||
if (setting_type == typeToString(Single)) {
|
||||
type = Single;
|
||||
@@ -259,6 +294,7 @@ QString ConductorProperties::typeToString(ConductorType t) {
|
||||
int ConductorProperties::operator==(const ConductorProperties &other) {
|
||||
return(
|
||||
other.type == type &&\
|
||||
other.color == color &&\
|
||||
other.text == text &&\
|
||||
other.singleLineProperties == singleLineProperties
|
||||
);
|
||||
@@ -271,6 +307,7 @@ int ConductorProperties::operator==(const ConductorProperties &other) {
|
||||
int ConductorProperties::operator!=(const ConductorProperties &other) {
|
||||
return(
|
||||
other.type != type ||\
|
||||
other.color != color ||\
|
||||
other.text != text ||\
|
||||
other.singleLineProperties != singleLineProperties
|
||||
);
|
||||
|
||||
@@ -57,16 +57,8 @@ class SingleLineProperties {
|
||||
class ConductorProperties {
|
||||
// constructeurs, destructeur
|
||||
public:
|
||||
/**
|
||||
Constructeur : par defaut, les proprietes font un conducteur
|
||||
multifilaire dont le texte est "_"
|
||||
*/
|
||||
ConductorProperties() : type(Multi), text("_") {
|
||||
}
|
||||
|
||||
/// Destructeur
|
||||
virtual ~ConductorProperties() {
|
||||
}
|
||||
ConductorProperties();
|
||||
virtual ~ConductorProperties();
|
||||
|
||||
/**
|
||||
Represente le type d'un conducteur :
|
||||
@@ -79,7 +71,8 @@ class ConductorProperties {
|
||||
// attributs
|
||||
/// type du conducteur
|
||||
ConductorType type;
|
||||
|
||||
/// couleur du conducteur
|
||||
QColor color;
|
||||
/// texte affiche si le conducteur est multifilaire
|
||||
QString text;
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ ConductorPropertiesWidget::ConductorPropertiesWidget(const ConductorProperties &
|
||||
/// construit l'interface du widget
|
||||
void ConductorPropertiesWidget::buildInterface() {
|
||||
|
||||
setMinimumSize(380, 280);
|
||||
setMinimumSize(380, 320);
|
||||
|
||||
QVBoxLayout *main_layout = new QVBoxLayout(this);
|
||||
main_layout -> setContentsMargins(0, 0, 0, 0);
|
||||
@@ -93,12 +93,28 @@ void ConductorPropertiesWidget::buildInterface() {
|
||||
singleline_layout1 -> addWidget(preview);
|
||||
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(multiline);
|
||||
groupbox_layout -> addLayout(multiline_layout);
|
||||
groupbox_layout -> addWidget(singleline);
|
||||
groupbox_layout -> addLayout(singleline_layout1);
|
||||
|
||||
groupbox2_layout -> addLayout(color_layout);
|
||||
|
||||
radio_buttons = new QButtonGroup(this);
|
||||
radio_buttons -> addButton(simple, ConductorProperties::Simple);
|
||||
radio_buttons -> addButton(multiline, ConductorProperties::Multi);
|
||||
@@ -118,6 +134,36 @@ void ConductorPropertiesWidget::buildConnections() {
|
||||
connect(phase_slider, SIGNAL(valueChanged(int)), this, SLOT(updateConfig()));
|
||||
connect(radio_buttons, SIGNAL(buttonClicked(int)), 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
|
||||
@@ -130,6 +176,7 @@ void ConductorPropertiesWidget::destroyConnections() {
|
||||
disconnect(phase_slider, SIGNAL(valueChanged(int)), this, SLOT(updateConfig()));
|
||||
disconnect(radio_buttons, SIGNAL(buttonClicked(int)), this, SLOT(updateConfig()));
|
||||
disconnect(text_field, SIGNAL(textChanged(const QString &)), this, SLOT(updateConfig()));
|
||||
disconnect(color_button, SIGNAL(clicked()), this, SLOT(chooseColor()));
|
||||
}
|
||||
|
||||
/// Destructeur
|
||||
@@ -139,6 +186,7 @@ ConductorPropertiesWidget::~ConductorPropertiesWidget() {
|
||||
/// Met a jour les proprietes
|
||||
void ConductorPropertiesWidget::updateConfig() {
|
||||
properties_.type = static_cast<ConductorProperties::ConductorType>(radio_buttons -> checkedId());
|
||||
properties_.color = colorButton();
|
||||
properties_.text = text_field -> text();
|
||||
properties_.singleLineProperties.hasGround = ground_checkbox -> isChecked();
|
||||
properties_.singleLineProperties.hasNeutral = neutral_checkbox -> isChecked();
|
||||
@@ -152,6 +200,7 @@ void ConductorPropertiesWidget::updateDisplay() {
|
||||
destroyConnections();
|
||||
|
||||
setConductorType(properties_.type);
|
||||
setColorButton(properties_.color);
|
||||
text_field -> setText(properties_.text);
|
||||
ground_checkbox -> setChecked(properties_.singleLineProperties.hasGround);
|
||||
neutral_checkbox -> setChecked(properties_.singleLineProperties.hasNeutral);
|
||||
|
||||
@@ -43,11 +43,14 @@ class ConductorPropertiesWidget : public QWidget {
|
||||
|
||||
private:
|
||||
void setConductorType(ConductorProperties::ConductorType);
|
||||
void setColorButton(const QColor &);
|
||||
QColor colorButton() const;
|
||||
|
||||
public slots:
|
||||
void updatePreview();
|
||||
void updateConfig();
|
||||
void updateDisplay();
|
||||
void chooseColor();
|
||||
|
||||
// attributs prives
|
||||
private:
|
||||
@@ -62,6 +65,7 @@ class ConductorPropertiesWidget : public QWidget {
|
||||
QCheckBox *ground_checkbox;
|
||||
QCheckBox *neutral_checkbox;
|
||||
QLabel *preview;
|
||||
QPushButton *color_button;
|
||||
|
||||
ConductorProperties properties_;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user