mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-09-20 15:24:14 +02:00
Compare commits
6 Commits
2da516667e
...
8bbc2da5c7
| Author | SHA1 | Date | |
|---|---|---|---|
| 8bbc2da5c7 | |||
| 4b8db6be0e | |||
| a6b4c3c673 | |||
| 8f0ee06a4f | |||
| 70599c4ae1 | |||
| e42ebdc861 |
@@ -699,6 +699,8 @@ set(QET_SRC_FILES
|
|||||||
${QET_DIR}/sources/ui/contactgroupselectiondialog.h
|
${QET_DIR}/sources/ui/contactgroupselectiondialog.h
|
||||||
${QET_DIR}/sources/ui/conductorpropertiesdialog.cpp
|
${QET_DIR}/sources/ui/conductorpropertiesdialog.cpp
|
||||||
${QET_DIR}/sources/ui/conductorpropertiesdialog.h
|
${QET_DIR}/sources/ui/conductorpropertiesdialog.h
|
||||||
|
${QET_DIR}/sources/ui/conductorcolortoolbutton.cpp
|
||||||
|
${QET_DIR}/sources/ui/conductorcolortoolbutton.h
|
||||||
${QET_DIR}/sources/ui/conductorpropertieswidget.cpp
|
${QET_DIR}/sources/ui/conductorpropertieswidget.cpp
|
||||||
${QET_DIR}/sources/ui/conductorpropertieswidget.h
|
${QET_DIR}/sources/ui/conductorpropertieswidget.h
|
||||||
${QET_DIR}/sources/ui/configsaveloaderwidget.cpp
|
${QET_DIR}/sources/ui/configsaveloaderwidget.cpp
|
||||||
|
|||||||
+195
-190
File diff suppressed because it is too large
Load Diff
@@ -50,6 +50,7 @@
|
|||||||
#include "recentfiles.h"
|
#include "recentfiles.h"
|
||||||
#include "shortcutmanager.h"
|
#include "shortcutmanager.h"
|
||||||
#include "ui/bomexportdialog.h"
|
#include "ui/bomexportdialog.h"
|
||||||
|
#include "ui/conductorcolortoolbutton.h"
|
||||||
#include "ui/jumptoelementdialog.h"
|
#include "ui/jumptoelementdialog.h"
|
||||||
#include "ui/diagrampropertieseditordockwidget.h"
|
#include "ui/diagrampropertieseditordockwidget.h"
|
||||||
#include "ui/backupdialog.h"
|
#include "ui/backupdialog.h"
|
||||||
@@ -389,6 +390,13 @@ void QETDiagramEditor::setUpActions()
|
|||||||
if (ProjectView *pv = currentProjectView())
|
if (ProjectView *pv = currentProjectView())
|
||||||
pv->project()->setAutoConductor(ac);
|
pv->project()->setAutoConductor(ac);
|
||||||
});
|
});
|
||||||
|
//Registered with no default sequence on purpose. This is a
|
||||||
|
//setting some people toggle constantly and others never touch,
|
||||||
|
//so it earns a place in the Shortcuts page rather than a key of
|
||||||
|
//its own taken from the ones still free. Asked for on the forum
|
||||||
|
//(viewtopic.php?pid=23296): "est il possible dans les raccourcis
|
||||||
|
//d'ajouter un pour création automatique de conducteur ?"
|
||||||
|
ShortcutManager::instance().registerAction(m_auto_conductor, "diagrameditor.auto_conductor", tr("Éditeur de schémas"), QKeySequence());
|
||||||
|
|
||||||
//AutoBreakConductor
|
//AutoBreakConductor
|
||||||
m_auto_break_conductor = new QAction (QET::Icons::Conductor, tr("Coupure automatique de conducteur(s)","Tool tip of auto break conductor"), this);
|
m_auto_break_conductor = new QAction (QET::Icons::Conductor, tr("Coupure automatique de conducteur(s)","Tool tip of auto break conductor"), this);
|
||||||
@@ -912,6 +920,10 @@ void QETDiagramEditor::setUpToolBar()
|
|||||||
diagram_tool_bar -> addAction (m_conductor_reset);
|
diagram_tool_bar -> addAction (m_conductor_reset);
|
||||||
diagram_tool_bar -> addAction (m_auto_conductor);
|
diagram_tool_bar -> addAction (m_auto_conductor);
|
||||||
diagram_tool_bar -> addAction (m_auto_break_conductor);
|
diagram_tool_bar -> addAction (m_auto_break_conductor);
|
||||||
|
//Sits with the conductor actions it works alongside: it colours
|
||||||
|
//the selected conductors and sets the colour of the next one drawn.
|
||||||
|
m_conductor_color_button = new ConductorColorToolButton(this, this);
|
||||||
|
diagram_tool_bar -> addWidget (m_conductor_color_button);
|
||||||
|
|
||||||
m_add_item_tool_bar = new QToolBar(tr("Ajouter"), this);
|
m_add_item_tool_bar = new QToolBar(tr("Ajouter"), this);
|
||||||
m_add_item_tool_bar->setObjectName("adding");
|
m_add_item_tool_bar->setObjectName("adding");
|
||||||
@@ -2110,6 +2122,10 @@ void QETDiagramEditor::slot_updateModeActions()
|
|||||||
m_auto_conductor -> setDisabled(true);
|
m_auto_conductor -> setDisabled(true);
|
||||||
m_auto_break_conductor -> setDisabled(true);
|
m_auto_break_conductor -> setDisabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_conductor_color_button) {
|
||||||
|
m_conductor_color_button->updateEnabledState();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ class QMdiSubWindow;
|
|||||||
class QETProject;
|
class QETProject;
|
||||||
class QETResult;
|
class QETResult;
|
||||||
class ProjectView;
|
class ProjectView;
|
||||||
|
class ConductorColorToolButton;
|
||||||
class CustomElement;
|
class CustomElement;
|
||||||
class Diagram;
|
class Diagram;
|
||||||
class DiagramView;
|
class DiagramView;
|
||||||
@@ -237,6 +238,9 @@ class QETDiagramEditor : public QETMainWindow
|
|||||||
*m_find = nullptr,
|
*m_find = nullptr,
|
||||||
*m_jump_to_element = nullptr; ///< Open the "jump to element" quick-open popup
|
*m_jump_to_element = nullptr; ///< Open the "jump to element" quick-open popup
|
||||||
|
|
||||||
|
///< One-click conductor colour, in the "Schéma" toolbar
|
||||||
|
ConductorColorToolButton *m_conductor_color_button = nullptr;
|
||||||
|
|
||||||
QList <QAction *> m_zoom_action_toolBar; ///Only zoom action must displayed in the toolbar
|
QList <QAction *> m_zoom_action_toolBar; ///Only zoom action must displayed in the toolbar
|
||||||
|
|
||||||
void removeDiagramSilent(Diagram *diagram);
|
void removeDiagramSilent(Diagram *diagram);
|
||||||
|
|||||||
@@ -0,0 +1,265 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2006-2026 The QElectroTech Team
|
||||||
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
QElectroTech is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include "conductorcolortoolbutton.h"
|
||||||
|
|
||||||
|
#include "../QPropertyUndoCommand/qpropertyundocommand.h"
|
||||||
|
#include "../diagram.h"
|
||||||
|
#include "../diagramcontent.h"
|
||||||
|
#include "../diagramview.h"
|
||||||
|
#include "../lastusedstyle.h"
|
||||||
|
#include "../qetdiagrameditor.h"
|
||||||
|
#include "../projectview.h"
|
||||||
|
#include "../qetgraphicsitem/conductor.h"
|
||||||
|
#include "../conductorproperties.h"
|
||||||
|
|
||||||
|
#include <QColorDialog>
|
||||||
|
#include <QMenu>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QPixmap>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
/**
|
||||||
|
The colours an electrician reaches for, in the order the trade
|
||||||
|
names them: the three phases, neutral, earth, then the ones used
|
||||||
|
for control and extra-low-voltage circuits. Not a standard in
|
||||||
|
itself -- IEC 60445 only fixes blue for neutral and green/yellow
|
||||||
|
for protective earth -- but it covers the wiring a schematic
|
||||||
|
actually shows, which is what makes the toolbar worth a click.
|
||||||
|
*/
|
||||||
|
struct NamedColor { const char *context_name; QColor color; };
|
||||||
|
|
||||||
|
QList<NamedColor> standardColors()
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
{QT_TRANSLATE_NOOP("ConductorColorToolButton", "Noir"), QColor(0x00, 0x00, 0x00)},
|
||||||
|
{QT_TRANSLATE_NOOP("ConductorColorToolButton", "Marron"), QColor(0x7B, 0x3F, 0x00)},
|
||||||
|
{QT_TRANSLATE_NOOP("ConductorColorToolButton", "Gris"), QColor(0x80, 0x80, 0x80)},
|
||||||
|
{QT_TRANSLATE_NOOP("ConductorColorToolButton", "Bleu"), QColor(0x00, 0x00, 0xFF)},
|
||||||
|
{QT_TRANSLATE_NOOP("ConductorColorToolButton", "Vert"), QColor(0x00, 0x80, 0x00)},
|
||||||
|
{QT_TRANSLATE_NOOP("ConductorColorToolButton", "Rouge"), QColor(0xFF, 0x00, 0x00)},
|
||||||
|
{QT_TRANSLATE_NOOP("ConductorColorToolButton", "Orange"), QColor(0xFF, 0x80, 0x00)},
|
||||||
|
{QT_TRANSLATE_NOOP("ConductorColorToolButton", "Violet"), QColor(0x80, 0x00, 0x80)},
|
||||||
|
{QT_TRANSLATE_NOOP("ConductorColorToolButton", "Blanc"), QColor(0xFF, 0xFF, 0xFF)},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const int MAX_RECENT = 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief ConductorColorToolButton::ConductorColorToolButton
|
||||||
|
@param editor : the diagram editor this button acts on
|
||||||
|
@param parent
|
||||||
|
*/
|
||||||
|
ConductorColorToolButton::ConductorColorToolButton(QETDiagramEditor *editor, QWidget *parent) :
|
||||||
|
QToolButton(parent),
|
||||||
|
m_editor(editor)
|
||||||
|
{
|
||||||
|
setPopupMode(QToolButton::InstantPopup);
|
||||||
|
setToolTip(tr("Couleur de conducteur"));
|
||||||
|
setStatusTip(tr("Applique une couleur aux conducteurs sélectionnés, et l'utilise pour les prochains conducteurs tracés",
|
||||||
|
"status bar tip"));
|
||||||
|
|
||||||
|
m_current = LastUsedStyle::hasConductorColor() ? LastUsedStyle::conductorColor()
|
||||||
|
: QColor(Qt::black);
|
||||||
|
setMenu(new QMenu(this));
|
||||||
|
rebuildMenu();
|
||||||
|
setSwatch(m_current);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief ConductorColorToolButton::currentView
|
||||||
|
@return the folio being edited, or nullptr when no project is open.
|
||||||
|
Goes through the project view because QETDiagramEditor keeps its own
|
||||||
|
currentDiagramView() private.
|
||||||
|
*/
|
||||||
|
DiagramView *ConductorColorToolButton::currentView() const
|
||||||
|
{
|
||||||
|
ProjectView *pv = m_editor ? m_editor->currentProjectView() : nullptr;
|
||||||
|
return pv ? pv->currentDiagram() : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief ConductorColorToolButton::updateEnabledState
|
||||||
|
Greyed out when there is no folio to act on, or when the project is
|
||||||
|
read-only -- the same rule the other conductor actions follow.
|
||||||
|
*/
|
||||||
|
void ConductorColorToolButton::updateEnabledState()
|
||||||
|
{
|
||||||
|
DiagramView *dv = currentView();
|
||||||
|
setEnabled(dv && dv->diagram() && !dv->diagram()->isReadOnly());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief ConductorColorToolButton::rebuildMenu
|
||||||
|
The standard colours never change; the recent ones do, so the menu is
|
||||||
|
rebuilt rather than kept in sync entry by entry.
|
||||||
|
*/
|
||||||
|
void ConductorColorToolButton::rebuildMenu()
|
||||||
|
{
|
||||||
|
QMenu *m = menu();
|
||||||
|
m->clear();
|
||||||
|
|
||||||
|
for (const auto &nc : standardColors())
|
||||||
|
{
|
||||||
|
const QColor c = nc.color;
|
||||||
|
QAction *a = m->addAction(swatchIcon(c),
|
||||||
|
tr(nc.context_name));
|
||||||
|
connect(a, &QAction::triggered, this, [this, c]() { applyColor(c); });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_recent.isEmpty())
|
||||||
|
{
|
||||||
|
m->addSeparator();
|
||||||
|
QAction *title = m->addAction(tr("Récemment utilisées"));
|
||||||
|
title->setEnabled(false);
|
||||||
|
for (const QColor &c : std::as_const(m_recent))
|
||||||
|
{
|
||||||
|
QAction *a = m->addAction(swatchIcon(c), c.name());
|
||||||
|
connect(a, &QAction::triggered, this, [this, c]() { applyColor(c); });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m->addSeparator();
|
||||||
|
QAction *other = m->addAction(tr("Autre couleur…"));
|
||||||
|
connect(other, &QAction::triggered, this, &ConductorColorToolButton::chooseOtherColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief ConductorColorToolButton::applyColor
|
||||||
|
Recolour the selected conductors, and remember the colour for the next
|
||||||
|
one drawn.
|
||||||
|
@param color
|
||||||
|
*/
|
||||||
|
void ConductorColorToolButton::applyColor(const QColor &color)
|
||||||
|
{
|
||||||
|
if (!color.isValid()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Always: this is the half that works with nothing selected.
|
||||||
|
LastUsedStyle::setConductorColor(color);
|
||||||
|
rememberRecent(color);
|
||||||
|
setSwatch(color);
|
||||||
|
|
||||||
|
DiagramView *dv = currentView();
|
||||||
|
if (!dv) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Diagram *diagram = dv->diagram();
|
||||||
|
if (!diagram || diagram->isReadOnly()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DiagramContent dc(diagram);
|
||||||
|
const auto conductors = dc.conductors(DiagramContent::AnyConductor);
|
||||||
|
if (conductors.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QUndoCommand *undo = new QUndoCommand(tr("Modifier la couleur de %n conducteur(s)",
|
||||||
|
"undo caption", conductors.count()));
|
||||||
|
int changed = 0;
|
||||||
|
for (Conductor *conductor : conductors)
|
||||||
|
{
|
||||||
|
ConductorProperties before = conductor->properties();
|
||||||
|
if (before.color == color) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ConductorProperties after = before;
|
||||||
|
after.color = color;
|
||||||
|
|
||||||
|
QVariant old_value, new_value;
|
||||||
|
old_value.setValue(before);
|
||||||
|
new_value.setValue(after);
|
||||||
|
new QPropertyUndoCommand(conductor, "properties", old_value, new_value, undo);
|
||||||
|
++changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Every selected conductor was already this colour: pushing an
|
||||||
|
//empty command would put a no-op step in the undo stack.
|
||||||
|
if (changed) {
|
||||||
|
diagram->undoStack().push(undo);
|
||||||
|
} else {
|
||||||
|
delete undo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief ConductorColorToolButton::chooseOtherColor
|
||||||
|
*/
|
||||||
|
void ConductorColorToolButton::chooseOtherColor()
|
||||||
|
{
|
||||||
|
const QColor c = QColorDialog::getColor(m_current, this,
|
||||||
|
tr("Choisir une couleur de conducteur"));
|
||||||
|
if (c.isValid()) {
|
||||||
|
applyColor(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief ConductorColorToolButton::rememberRecent
|
||||||
|
Most recent first, no duplicates, capped.
|
||||||
|
@param color
|
||||||
|
*/
|
||||||
|
void ConductorColorToolButton::rememberRecent(const QColor &color)
|
||||||
|
{
|
||||||
|
//A colour that is already one row up in the standard list would
|
||||||
|
//only appear twice, under a hex name it does not need.
|
||||||
|
for (const auto &nc : standardColors()) {
|
||||||
|
if (nc.color == color) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_recent.removeAll(color);
|
||||||
|
m_recent.prepend(color);
|
||||||
|
while (m_recent.size() > MAX_RECENT) {
|
||||||
|
m_recent.removeLast();
|
||||||
|
}
|
||||||
|
rebuildMenu();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief ConductorColorToolButton::setSwatch
|
||||||
|
@param color
|
||||||
|
*/
|
||||||
|
void ConductorColorToolButton::setSwatch(const QColor &color)
|
||||||
|
{
|
||||||
|
m_current = color;
|
||||||
|
setIcon(swatchIcon(color));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief ConductorColorToolButton::swatchIcon
|
||||||
|
@param color
|
||||||
|
@return a plain square of that colour, outlined so that white and very
|
||||||
|
light colours are still visible against the toolbar.
|
||||||
|
*/
|
||||||
|
QIcon ConductorColorToolButton::swatchIcon(const QColor &color)
|
||||||
|
{
|
||||||
|
QPixmap pix(16, 16);
|
||||||
|
pix.fill(Qt::transparent);
|
||||||
|
QPainter p(&pix);
|
||||||
|
p.setRenderHint(QPainter::Antialiasing, false);
|
||||||
|
p.setBrush(color);
|
||||||
|
p.setPen(QPen(QColor(0x40, 0x40, 0x40), 1));
|
||||||
|
p.drawRect(0, 0, 15, 15);
|
||||||
|
p.end();
|
||||||
|
return QIcon(pix);
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2006-2026 The QElectroTech Team
|
||||||
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
QElectroTech is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#ifndef CONDUCTORCOLORTOOLBUTTON_H
|
||||||
|
#define CONDUCTORCOLORTOOLBUTTON_H
|
||||||
|
|
||||||
|
#include <QColor>
|
||||||
|
#include <QList>
|
||||||
|
#include <QToolButton>
|
||||||
|
|
||||||
|
class QETDiagramEditor;
|
||||||
|
class DiagramView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief The ConductorColorToolButton class
|
||||||
|
One-click conductor colour, from the "Schéma" toolbar.
|
||||||
|
|
||||||
|
Picking a colour does two things: it recolours every conductor
|
||||||
|
currently selected (one undo command for the lot), and it becomes the
|
||||||
|
colour of the next conductor drawn this session, through the existing
|
||||||
|
LastUsedStyle mechanism. Either half is useful on its own -- with
|
||||||
|
nothing selected it only sets the pen for what comes next.
|
||||||
|
|
||||||
|
This deliberately stores nothing in the project and nothing in
|
||||||
|
QSettings. It is the same session-scoped "what did I just use" idea
|
||||||
|
LastUsedStyle already implements; named presets that persist per
|
||||||
|
project are a separate, larger feature (upstream issue #461) that
|
||||||
|
needs a maintainer decision first.
|
||||||
|
*/
|
||||||
|
class ConductorColorToolButton : public QToolButton
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ConductorColorToolButton(QETDiagramEditor *editor,
|
||||||
|
QWidget *parent = nullptr);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void updateEnabledState();
|
||||||
|
|
||||||
|
private:
|
||||||
|
DiagramView *currentView() const;
|
||||||
|
void rebuildMenu();
|
||||||
|
void applyColor(const QColor &color);
|
||||||
|
void chooseOtherColor();
|
||||||
|
void rememberRecent(const QColor &color);
|
||||||
|
void setSwatch(const QColor &color);
|
||||||
|
static QIcon swatchIcon(const QColor &color);
|
||||||
|
|
||||||
|
QETDiagramEditor *m_editor = nullptr;
|
||||||
|
QList<QColor> m_recent;
|
||||||
|
QColor m_current;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CONDUCTORCOLORTOOLBUTTON_H
|
||||||
Reference in New Issue
Block a user