mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-09-27 12:34:14 +02:00
Compare commits
7 Commits
031441884a
...
acf2320f68
| Author | SHA1 | Date | |
|---|---|---|---|
| acf2320f68 | |||
| 6cdf60e2e7 | |||
| 98c56fcc7b | |||
| 55886e5e8a | |||
| c772e1d3ea | |||
| 9637f0ff9e | |||
| 5275fb44fe |
@@ -248,6 +248,8 @@ set(QET_SRC_FILES
|
||||
${QET_DIR}/sources/qtextorientationwidget.h
|
||||
${QET_DIR}/sources/recentfiles.cpp
|
||||
${QET_DIR}/sources/recentfiles.h
|
||||
${QET_DIR}/sources/shortcutmanager.cpp
|
||||
${QET_DIR}/sources/shortcutmanager.h
|
||||
${QET_DIR}/sources/titleblockcell.cpp
|
||||
${QET_DIR}/sources/titleblockcell.h
|
||||
${QET_DIR}/sources/titleblockproperties.cpp
|
||||
@@ -732,9 +734,13 @@ set(QET_SRC_FILES
|
||||
${QET_DIR}/sources/ui/configpage/projectconfigpages.h
|
||||
${QET_DIR}/sources/ui/configpage/guidespropertieswidget.cpp
|
||||
${QET_DIR}/sources/ui/configpage/guidespropertieswidget.h
|
||||
${QET_DIR}/sources/ui/configpage/shortcutsconfigpage.cpp
|
||||
${QET_DIR}/sources/ui/configpage/shortcutsconfigpage.h
|
||||
|
||||
${QET_DIR}/sources/undocommand/addelementtextcommand.cpp
|
||||
${QET_DIR}/sources/undocommand/addelementtextcommand.h
|
||||
${QET_DIR}/sources/undocommand/adddiagramcommand.cpp
|
||||
${QET_DIR}/sources/undocommand/adddiagramcommand.h
|
||||
${QET_DIR}/sources/undocommand/addgraphicsobjectcommand.cpp
|
||||
${QET_DIR}/sources/undocommand/addgraphicsobjectcommand.h
|
||||
${QET_DIR}/sources/undocommand/changeelementdatacommand.cpp
|
||||
@@ -749,6 +755,10 @@ set(QET_SRC_FILES
|
||||
${QET_DIR}/sources/undocommand/itemmodelcommand.h
|
||||
${QET_DIR}/sources/undocommand/linkelementcommand.cpp
|
||||
${QET_DIR}/sources/undocommand/linkelementcommand.h
|
||||
${QET_DIR}/sources/undocommand/movediagramcommand.cpp
|
||||
${QET_DIR}/sources/undocommand/movediagramcommand.h
|
||||
${QET_DIR}/sources/undocommand/removediagramcommand.cpp
|
||||
${QET_DIR}/sources/undocommand/removediagramcommand.h
|
||||
${QET_DIR}/sources/undocommand/rotateselectioncommand.cpp
|
||||
${QET_DIR}/sources/undocommand/rotateselectioncommand.h
|
||||
${QET_DIR}/sources/undocommand/rotatetextscommand.cpp
|
||||
|
||||
+775
-563
File diff suppressed because it is too large
Load Diff
+775
-563
File diff suppressed because it is too large
Load Diff
+775
-563
File diff suppressed because it is too large
Load Diff
+775
-563
File diff suppressed because it is too large
Load Diff
+772
-560
File diff suppressed because it is too large
Load Diff
+775
-563
File diff suppressed because it is too large
Load Diff
Binary file not shown.
+775
-563
File diff suppressed because it is too large
Load Diff
+775
-563
File diff suppressed because it is too large
Load Diff
Binary file not shown.
+791
-579
File diff suppressed because it is too large
Load Diff
+770
-558
File diff suppressed because it is too large
Load Diff
+771
-559
File diff suppressed because it is too large
Load Diff
+774
-562
File diff suppressed because it is too large
Load Diff
+770
-558
File diff suppressed because it is too large
Load Diff
+775
-563
File diff suppressed because it is too large
Load Diff
+771
-559
File diff suppressed because it is too large
Load Diff
+771
-559
File diff suppressed because it is too large
Load Diff
+775
-563
File diff suppressed because it is too large
Load Diff
+778
-566
File diff suppressed because it is too large
Load Diff
+775
-563
File diff suppressed because it is too large
Load Diff
+774
-562
File diff suppressed because it is too large
Load Diff
+772
-560
File diff suppressed because it is too large
Load Diff
+774
-562
File diff suppressed because it is too large
Load Diff
+778
-566
File diff suppressed because it is too large
Load Diff
+775
-563
File diff suppressed because it is too large
Load Diff
+779
-567
File diff suppressed because it is too large
Load Diff
+778
-566
File diff suppressed because it is too large
Load Diff
+778
-566
File diff suppressed because it is too large
Load Diff
+770
-558
File diff suppressed because it is too large
Load Diff
+772
-560
File diff suppressed because it is too large
Load Diff
+770
-558
File diff suppressed because it is too large
Load Diff
+772
-560
File diff suppressed because it is too large
Load Diff
@@ -20,6 +20,7 @@
|
||||
#include "../../diagram.h"
|
||||
#include "../../diagramview.h"
|
||||
#include "../../qetapp.h"
|
||||
#include "../../shortcutmanager.h"
|
||||
#include "../../titleblockproperties.h"
|
||||
#include "../../ui/projectpropertiesdialog.h"
|
||||
#include "../numerotationcontext.h"
|
||||
@@ -151,7 +152,8 @@ void AutoNumberingDockWidget::setProject(QETProject *project,
|
||||
//Set Combobox Context
|
||||
setContext();
|
||||
|
||||
ui->m_configure_pb->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_P);
|
||||
ShortcutManager::instance().registerAction(ui->m_configure_pb, "autonum.configure",
|
||||
tr("Autonumérotation"), Qt::CTRL | Qt::SHIFT | Qt::Key_P);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -124,6 +124,7 @@ void ElementScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e)
|
||||
{
|
||||
if (m_event_interface) {
|
||||
if (m_event_interface -> mouseMoveEvent(e)) {
|
||||
emit mouseMoved(e -> scenePos());
|
||||
if (m_event_interface->isFinish()) {
|
||||
delete m_event_interface;
|
||||
m_event_interface = nullptr;
|
||||
@@ -136,6 +137,8 @@ void ElementScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e)
|
||||
if (!(e -> modifiers() & Qt::ControlModifier))
|
||||
event_pos = snapToGrid(event_pos);
|
||||
|
||||
emit mouseMoved(event_pos);
|
||||
|
||||
if (m_behavior == PasteArea) {
|
||||
QRectF current_rect(m_paste_area -> rect());
|
||||
current_rect.moveCenter(event_pos);
|
||||
|
||||
@@ -179,6 +179,8 @@ class ElementScene : public QGraphicsScene
|
||||
void elementInfoChanged();
|
||||
/// Signal emitted when the element type changes
|
||||
void elementTypeChanged();
|
||||
/// Signal emitted with the current cursor position (scene coordinates) on every mouse move
|
||||
void mouseMoved(const QPointF &pos);
|
||||
};
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(ElementScene::ItemOptions)
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "ui_qetelementeditor.h"
|
||||
#include "../elementscene.h"
|
||||
#include "../../qeticons.h"
|
||||
#include "../../shortcutmanager.h"
|
||||
#include "../elementview.h"
|
||||
#include "../../qetmessagebox.h"
|
||||
#include "../../qetapp.h"
|
||||
@@ -978,32 +979,32 @@ void QETElementEditor::setupActions()
|
||||
m_redo_action = m_elmt_scene -> undoStack().createRedoAction(this, tr("Refaire"));
|
||||
m_undo_action -> setIcon(QET::Icons::EditUndo);
|
||||
m_redo_action -> setIcon(QET::Icons::EditRedo);
|
||||
m_undo_action -> setShortcuts(QKeySequence::Undo);
|
||||
m_redo_action -> setShortcuts(QKeySequence::Redo);
|
||||
ShortcutManager::instance().registerAction(m_undo_action, "elementeditor.undo", tr("Éditeur d'élément"), QKeySequence::Undo);
|
||||
ShortcutManager::instance().registerAction(m_redo_action, "elementeditor.redo", tr("Éditeur d'élément"), QKeySequence::Redo);
|
||||
ui->m_undo_toolbar->addAction(m_undo_action);
|
||||
ui->m_undo_toolbar->addAction(m_redo_action);
|
||||
|
||||
ui->m_new_action -> setShortcut(QKeySequence::New);
|
||||
ui->m_open_action -> setShortcut(QKeySequence::Open);
|
||||
ui->m_open_from_file_action -> setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_O);
|
||||
ui->m_save_action -> setShortcut(QKeySequence::Save);
|
||||
ui->m_save_as_file_action -> setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_S);
|
||||
ui->m_select_all_act -> setShortcut(QKeySequence::SelectAll);
|
||||
ui->m_deselect_all_action -> setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_A);
|
||||
ui->m_revert_selection_action -> setShortcut(Qt::CTRL | Qt::Key_I);
|
||||
ui->m_cut_action -> setShortcut(QKeySequence::Cut);
|
||||
ui->m_copy_action -> setShortcut(QKeySequence::Copy);
|
||||
ui->m_paste_action -> setShortcut(QKeySequence::Paste);
|
||||
ui->m_paste_in_area_action -> setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_V);
|
||||
ui->m_edit_names_action -> setShortcut(Qt::CTRL | Qt::Key_E);
|
||||
ui->m_edit_author_action -> setShortcut(Qt::CTRL | Qt::Key_Y);
|
||||
ShortcutManager::instance().registerAction(ui->m_new_action, "elementeditor.new", tr("Éditeur d'élément"), QKeySequence::New);
|
||||
ShortcutManager::instance().registerAction(ui->m_open_action, "elementeditor.open", tr("Éditeur d'élément"), QKeySequence::Open);
|
||||
ShortcutManager::instance().registerAction(ui->m_open_from_file_action, "elementeditor.open_from_file", tr("Éditeur d'élément"), Qt::CTRL | Qt::SHIFT | Qt::Key_O);
|
||||
ShortcutManager::instance().registerAction(ui->m_save_action, "elementeditor.save", tr("Éditeur d'élément"), QKeySequence::Save);
|
||||
ShortcutManager::instance().registerAction(ui->m_save_as_file_action, "elementeditor.save_as_file", tr("Éditeur d'élément"), Qt::CTRL | Qt::SHIFT | Qt::Key_S);
|
||||
ShortcutManager::instance().registerAction(ui->m_select_all_act, "elementeditor.select_all", tr("Éditeur d'élément"), QKeySequence::SelectAll);
|
||||
ShortcutManager::instance().registerAction(ui->m_deselect_all_action, "elementeditor.deselect_all", tr("Éditeur d'élément"), Qt::CTRL | Qt::SHIFT | Qt::Key_A);
|
||||
ShortcutManager::instance().registerAction(ui->m_revert_selection_action, "elementeditor.revert_selection", tr("Éditeur d'élément"), Qt::CTRL | Qt::Key_I);
|
||||
ShortcutManager::instance().registerAction(ui->m_cut_action, "elementeditor.cut", tr("Éditeur d'élément"), QKeySequence::Cut);
|
||||
ShortcutManager::instance().registerAction(ui->m_copy_action, "elementeditor.copy", tr("Éditeur d'élément"), QKeySequence::Copy);
|
||||
ShortcutManager::instance().registerAction(ui->m_paste_action, "elementeditor.paste", tr("Éditeur d'élément"), QKeySequence::Paste);
|
||||
ShortcutManager::instance().registerAction(ui->m_paste_in_area_action, "elementeditor.paste_in_area", tr("Éditeur d'élément"), Qt::CTRL | Qt::SHIFT | Qt::Key_V);
|
||||
ShortcutManager::instance().registerAction(ui->m_edit_names_action, "elementeditor.edit_names", tr("Éditeur d'élément"), Qt::CTRL | Qt::Key_E);
|
||||
ShortcutManager::instance().registerAction(ui->m_edit_author_action, "elementeditor.edit_author", tr("Éditeur d'élément"), Qt::CTRL | Qt::Key_Y);
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
ui->m_delete_action -> setShortcut(Qt::Key_Backspace);
|
||||
ui->m_quit_action -> setShortcut(Qt::CTRL | Qt::Key_W);
|
||||
ShortcutManager::instance().registerAction(ui->m_delete_action, "elementeditor.delete", tr("Éditeur d'élément"), Qt::Key_Backspace);
|
||||
ShortcutManager::instance().registerAction(ui->m_quit_action, "elementeditor.quit", tr("Éditeur d'élément"), Qt::CTRL | Qt::Key_W);
|
||||
#else
|
||||
ui->m_delete_action -> setShortcut(Qt::Key_Delete);
|
||||
ui->m_quit_action -> setShortcut(Qt::CTRL | Qt::Key_Q);
|
||||
ShortcutManager::instance().registerAction(ui->m_delete_action, "elementeditor.delete", tr("Éditeur d'élément"), Qt::Key_Delete);
|
||||
ShortcutManager::instance().registerAction(ui->m_quit_action, "elementeditor.quit", tr("Éditeur d'élément"), Qt::CTRL | Qt::Key_Q);
|
||||
#endif
|
||||
|
||||
//Depth action
|
||||
@@ -1019,27 +1020,27 @@ void QETElementEditor::setupActions()
|
||||
addToolBar(Qt::TopToolBarArea, depth_toolbar);
|
||||
|
||||
//Rotate action
|
||||
ui->m_rotate_action -> setShortcut(Qt::Key_Space);
|
||||
ShortcutManager::instance().registerAction(ui->m_rotate_action, "elementeditor.rotate", tr("Éditeur d'élément"), Qt::Key_Space);
|
||||
connect(ui->m_rotate_action, &QAction::triggered, [this]() {this -> elementScene() -> undoStack().push(new RotateElementsCommand(this->elementScene()));});
|
||||
|
||||
//Rotate Fine action = rotate with smaller inkrement
|
||||
ui->m_rotateFine_action -> setShortcut(Qt::CTRL | Qt::Key_Space);
|
||||
ShortcutManager::instance().registerAction(ui->m_rotateFine_action, "elementeditor.rotate_fine", tr("Éditeur d'élément"), Qt::CTRL | Qt::Key_Space);
|
||||
connect(ui->m_rotateFine_action, &QAction::triggered, [this]() {this -> elementScene() -> undoStack().push(new RotateFineElementsCommand(this->elementScene()));});
|
||||
|
||||
//Flip action
|
||||
ui->m_flip_action -> setShortcut(Qt::Key_F);
|
||||
ShortcutManager::instance().registerAction(ui->m_flip_action, "elementeditor.flip", tr("Éditeur d'élément"), Qt::Key_F);
|
||||
connect(ui->m_flip_action, &QAction::triggered, [this]() {this -> elementScene() -> undoStack().push(new FlipElementsCommand(this->elementScene()));});
|
||||
|
||||
//Mirror action
|
||||
ui->m_mirror_action -> setShortcut(Qt::Key_M);
|
||||
ShortcutManager::instance().registerAction(ui->m_mirror_action, "elementeditor.mirror", tr("Éditeur d'élément"), Qt::Key_M);
|
||||
connect(ui->m_mirror_action, &QAction::triggered, [this]() {this -> elementScene() -> undoStack().push(new MirrorElementsCommand(this->elementScene()));});
|
||||
|
||||
|
||||
//Zoom action
|
||||
ui->m_zoom_in_action -> setShortcut(QKeySequence::ZoomIn);
|
||||
ui->m_zoom_out_action -> setShortcut(QKeySequence::ZoomOut);
|
||||
ui->m_zoom_fit_best_action -> setShortcut(Qt::CTRL | Qt::Key_9);
|
||||
ui->m_zoom_original_action -> setShortcut(Qt::CTRL | Qt::Key_0);
|
||||
ShortcutManager::instance().registerAction(ui->m_zoom_in_action, "elementeditor.zoom_in", tr("Éditeur d'élément"), QKeySequence::ZoomIn);
|
||||
ShortcutManager::instance().registerAction(ui->m_zoom_out_action, "elementeditor.zoom_out", tr("Éditeur d'élément"), QKeySequence::ZoomOut);
|
||||
ShortcutManager::instance().registerAction(ui->m_zoom_fit_best_action, "elementeditor.zoom_fit_best", tr("Éditeur d'élément"), Qt::CTRL | Qt::Key_9);
|
||||
ShortcutManager::instance().registerAction(ui->m_zoom_original_action, "elementeditor.zoom_original", tr("Éditeur d'élément"), Qt::CTRL | Qt::Key_0);
|
||||
|
||||
//Add primitive actions
|
||||
m_add_part_action_grp = new QActionGroup(this);
|
||||
@@ -1194,6 +1195,16 @@ void QETElementEditor::initGui()
|
||||
if (te) te->refreshMasterLabelVisibility();
|
||||
});
|
||||
|
||||
//Live cursor position readout, in the same scene coordinates as the parts' X/Y properties
|
||||
m_position_label = new QLabel(this);
|
||||
m_position_label->setMinimumWidth(120);
|
||||
statusBar()->addPermanentWidget(m_position_label);
|
||||
connect(m_elmt_scene, &ElementScene::mouseMoved, this, [this](const QPointF &pos) {
|
||||
m_position_label->setText(tr("X: %1 Y: %2")
|
||||
.arg(pos.x(), 0, 'f', 1)
|
||||
.arg(pos.y(), 0, 'f', 1));
|
||||
});
|
||||
|
||||
statusBar()->showMessage(tr("Éditeur d'éléments", "status bar message"));
|
||||
}
|
||||
|
||||
|
||||
@@ -161,6 +161,8 @@ class QETElementEditor : public QMainWindow
|
||||
|
||||
QLabel *m_default_informations = nullptr;
|
||||
|
||||
QLabel *m_position_label = nullptr;
|
||||
|
||||
};
|
||||
|
||||
#endif // QETELEMENTEDITOR_H
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "qetapp.h"
|
||||
#include "qeticons.h"
|
||||
#include "qetproject.h"
|
||||
#include "shortcutmanager.h"
|
||||
#include "titleblock/templatedeleter.h"
|
||||
#include <QFileInfo>
|
||||
#include <QMessageBox>
|
||||
@@ -74,14 +75,14 @@ ElementsPanelWidget::ElementsPanelWidget(QWidget *parent) : QWidget(parent) {
|
||||
tbt_remove = new QAction(QET::Icons::TitleBlock, tr("Supprimer ce modèle"), this);
|
||||
|
||||
|
||||
prj_del_diagram -> setShortcut(QKeySequence(Qt::Key_Delete));
|
||||
prj_move_diagram_up -> setShortcut(QKeySequence(Qt::Key_F3));
|
||||
prj_move_diagram_down -> setShortcut(QKeySequence(Qt::Key_F4));
|
||||
prj_move_diagram_top -> setShortcut(QKeySequence(Qt::Key_F5));
|
||||
prj_move_diagram_downx10 -> setShortcut(QKeySequence(Qt::Key_F6));
|
||||
prj_move_diagram_downx100 -> setShortcut(QKeySequence(Qt::Key_F7));
|
||||
prj_move_diagram_upx10 -> setShortcut(QKeySequence(Qt::Key_F8));
|
||||
prj_move_diagram_upx100 -> setShortcut(QKeySequence(Qt::Key_F9));
|
||||
ShortcutManager::instance().registerAction(prj_del_diagram, "panel.delete_diagram", tr("Panneau des éléments"), QKeySequence(Qt::Key_Delete));
|
||||
ShortcutManager::instance().registerAction(prj_move_diagram_up, "panel.move_diagram_up", tr("Panneau des éléments"), QKeySequence(Qt::Key_F3));
|
||||
ShortcutManager::instance().registerAction(prj_move_diagram_down, "panel.move_diagram_down", tr("Panneau des éléments"), QKeySequence(Qt::Key_F4));
|
||||
ShortcutManager::instance().registerAction(prj_move_diagram_top, "panel.move_diagram_top", tr("Panneau des éléments"), QKeySequence(Qt::Key_F5));
|
||||
ShortcutManager::instance().registerAction(prj_move_diagram_downx10, "panel.move_diagram_downx10", tr("Panneau des éléments"), QKeySequence(Qt::Key_F6));
|
||||
ShortcutManager::instance().registerAction(prj_move_diagram_downx100, "panel.move_diagram_downx100", tr("Panneau des éléments"), QKeySequence(Qt::Key_F7));
|
||||
ShortcutManager::instance().registerAction(prj_move_diagram_upx10, "panel.move_diagram_upx10", tr("Panneau des éléments"), QKeySequence(Qt::Key_F8));
|
||||
ShortcutManager::instance().registerAction(prj_move_diagram_upx100, "panel.move_diagram_upx100", tr("Panneau des éléments"), QKeySequence(Qt::Key_F9));
|
||||
|
||||
|
||||
|
||||
|
||||
+82
-13
@@ -33,6 +33,8 @@
|
||||
#include "ui/dialogwaiting.h"
|
||||
#include "ui/projectpropertiesdialog.h"
|
||||
#include "ui/titleblockpropertieswidget.h"
|
||||
#include "undocommand/movediagramcommand.h"
|
||||
#include "undocommand/removediagramcommand.h"
|
||||
|
||||
/**
|
||||
Constructeur
|
||||
@@ -87,6 +89,10 @@ void ProjectView::setProject(QETProject *project)
|
||||
Q_UNUSED(project)
|
||||
this->diagramAdded(diagram);
|
||||
});
|
||||
connect(m_project, &QETProject::diagramRemoved, [this](QETProject *project, Diagram *diagram) {
|
||||
Q_UNUSED(project)
|
||||
this->diagramRemoved(diagram);
|
||||
});
|
||||
|
||||
adjustReadOnlyState();
|
||||
loadDiagrams();
|
||||
@@ -383,7 +389,7 @@ void ProjectView::removeDiagram(DiagramView *diagram_view, bool silent)
|
||||
int answer = QET::QetMessageBox::question(
|
||||
this,
|
||||
tr("Supprimer le folio ?", "message box title"),
|
||||
tr("Êtes-vous sûr de vouloir supprimer ce folio du projet ? Ce changement est irréversible.", "message box content"),
|
||||
tr("Êtes-vous sûr de vouloir supprimer ce folio du projet ?", "message box content"),
|
||||
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
|
||||
QMessageBox::No
|
||||
);
|
||||
@@ -392,16 +398,33 @@ void ProjectView::removeDiagram(DiagramView *diagram_view, bool silent)
|
||||
}
|
||||
}
|
||||
|
||||
//Remove the diagram view of the tabs widget
|
||||
m_project->undoStack()->push(new RemoveDiagramCommand(m_project, diagram_view->diagram()));
|
||||
}
|
||||
|
||||
/**
|
||||
@brief ProjectView::diagramRemoved
|
||||
Slot called when the project emits diagramRemoved (either from a direct,
|
||||
non-undoable QETProject::removeDiagram() call, or -- the normal UI path
|
||||
-- from a RemoveDiagramCommand's redo()/undo()). Tears down the tab and
|
||||
DiagramView for the given diagram; the diagram itself is left untouched,
|
||||
since by this point it has already been detached (and possibly parked
|
||||
for undo) by the caller.
|
||||
@param diagram
|
||||
*/
|
||||
void ProjectView::diagramRemoved(Diagram *diagram)
|
||||
{
|
||||
DiagramView *diagram_view = findDiagram(diagram);
|
||||
if (!diagram_view)
|
||||
return;
|
||||
|
||||
int index_to_remove = m_diagram_ids.key(diagram_view);
|
||||
m_tab->removeTab(index_to_remove);
|
||||
m_diagram_view_list.removeAll(diagram_view);
|
||||
rebuildDiagramsMap();
|
||||
|
||||
m_project -> removeDiagram(diagram_view -> diagram());
|
||||
emit(diagramRemoved(diagram_view));
|
||||
delete diagram_view;
|
||||
|
||||
emit(diagramRemoved(diagram_view));
|
||||
updateAllTabsTitle();
|
||||
m_project -> setModified(true);
|
||||
}
|
||||
@@ -485,7 +508,7 @@ void ProjectView::moveDiagramUp(DiagramView *diagram_view) {
|
||||
// le schema est le premier du projet
|
||||
return;
|
||||
}
|
||||
m_tab -> tabBar() -> moveTab(diagram_view_position, diagram_view_position - 1);
|
||||
m_project->undoStack()->push(new MoveDiagramCommand(this, diagram_view->diagram(), diagram_view_position - 1));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -506,7 +529,7 @@ void ProjectView::moveDiagramDown(DiagramView *diagram_view) {
|
||||
// le schema est le dernier du projet
|
||||
return;
|
||||
}
|
||||
m_tab -> tabBar() -> moveTab(diagram_view_position, diagram_view_position + 1);
|
||||
m_project->undoStack()->push(new MoveDiagramCommand(this, diagram_view->diagram(), diagram_view_position + 1));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -528,7 +551,7 @@ void ProjectView::moveDiagramUpTop(DiagramView *diagram_view)
|
||||
// le schema est le premier du projet
|
||||
return;
|
||||
}
|
||||
m_tab->tabBar()->moveTab(diagram_view_position, 0);
|
||||
m_project->undoStack()->push(new MoveDiagramCommand(this, diagram_view->diagram(), 0));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -550,7 +573,7 @@ void ProjectView::moveDiagramUpx10(DiagramView *diagram_view) {
|
||||
// le schema est le premier du projet
|
||||
return;
|
||||
}
|
||||
m_tab -> tabBar() -> moveTab(diagram_view_position, diagram_view_position - 10);
|
||||
m_project->undoStack()->push(new MoveDiagramCommand(this, diagram_view->diagram(), diagram_view_position - 10));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -573,7 +596,7 @@ void ProjectView::moveDiagramUpx100(DiagramView *diagram_view) {
|
||||
// The diagram is the first of the project
|
||||
return;
|
||||
}
|
||||
m_tab->tabBar()->moveTab(diagram_view_position, diagram_view_position - 100);
|
||||
m_project->undoStack()->push(new MoveDiagramCommand(this, diagram_view->diagram(), diagram_view_position - 100));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -598,7 +621,7 @@ void ProjectView::moveDiagramDownx100(DiagramView *diagram_view) {
|
||||
// The diagram is the last of the project
|
||||
return;
|
||||
}
|
||||
m_tab->tabBar()->moveTab(diagram_view_position, diagram_view_position + 100);
|
||||
m_project->undoStack()->push(new MoveDiagramCommand(this, diagram_view->diagram(), diagram_view_position + 100));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -621,7 +644,7 @@ void ProjectView::moveDiagramDownx10(DiagramView *diagram_view) {
|
||||
// le schema est le dernier du projet
|
||||
return;
|
||||
}
|
||||
m_tab -> tabBar() -> moveTab(diagram_view_position, diagram_view_position + 10);
|
||||
m_project->undoStack()->push(new MoveDiagramCommand(this, diagram_view->diagram(), diagram_view_position + 10));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1052,10 +1075,10 @@ void ProjectView::tabMoved(int from, int to)
|
||||
{
|
||||
if (!m_project)
|
||||
return;
|
||||
|
||||
|
||||
m_project->diagramOrderChanged(from, to);
|
||||
rebuildDiagramsMap();
|
||||
|
||||
|
||||
//Rebuild the title of each diagram in range from - to
|
||||
for (int i= qMin(from,to) ; i< qMax(from,to)+1 ; ++i)
|
||||
{
|
||||
@@ -1064,6 +1087,52 @@ void ProjectView::tabMoved(int from, int to)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief ProjectView::setDiagramPosition
|
||||
Move \p diagram's tab to \p new_position (out-of-range values are
|
||||
clamped by the underlying tab bar, same as a direct QTabBar::moveTab()
|
||||
call). Used by MoveDiagramCommand for both redo and undo.
|
||||
|
||||
tabMoved() -- the slot that normally keeps the project's diagram list in
|
||||
sync with the tab bar -- is connected with Qt::QueuedConnection (needed
|
||||
so interactive drag-and-drop reordering settles before the model
|
||||
updates). That queued call would run a second, redundant
|
||||
diagramOrderChanged() after this method already performed it
|
||||
synchronously, so that one connection is temporarily dropped around the
|
||||
move (blocking all of the tab bar's signals instead would also suppress
|
||||
QTabWidget's own internal tabMoved connection, which is what keeps its
|
||||
page stack in the same order as the tab bar -- breaking the move
|
||||
visually).
|
||||
@param diagram
|
||||
@param new_position
|
||||
*/
|
||||
void ProjectView::setDiagramPosition(Diagram *diagram, int new_position)
|
||||
{
|
||||
if (!m_project)
|
||||
return;
|
||||
|
||||
DiagramView *diagram_view = findDiagram(diagram);
|
||||
if (!diagram_view)
|
||||
return;
|
||||
|
||||
int current_position = m_diagram_ids.key(diagram_view, -1);
|
||||
if (current_position < 0)
|
||||
return;
|
||||
|
||||
disconnect(m_tab->tabBar(), SIGNAL(tabMoved(int,int)), this, SLOT(tabMoved(int,int)));
|
||||
m_tab->tabBar()->moveTab(current_position, new_position);
|
||||
connect(m_tab->tabBar(), SIGNAL(tabMoved(int,int)), this, SLOT(tabMoved(int,int)), Qt::QueuedConnection);
|
||||
|
||||
rebuildDiagramsMap();
|
||||
|
||||
int actual_new_position = m_tab->indexOf(diagram_view);
|
||||
if (actual_new_position != current_position)
|
||||
m_project->diagramOrderChanged(current_position, actual_new_position);
|
||||
|
||||
for (int i = qMin(current_position, actual_new_position); i <= qMax(current_position, actual_new_position); ++i)
|
||||
updateTabTitle(m_diagram_ids.value(i));
|
||||
}
|
||||
|
||||
/**
|
||||
@param diagram Schema a trouver
|
||||
@return le DiagramView correspondant au schema passe en parametre, ou 0 si
|
||||
|
||||
@@ -102,6 +102,7 @@ class ProjectView : public QWidget
|
||||
void changeTabDown();
|
||||
void changeFirstTab();
|
||||
void changeLastTab();
|
||||
void setDiagramPosition(Diagram *diagram, int new_position);
|
||||
|
||||
public slots:
|
||||
void removeDiagram(DiagramView *diagram_view, bool silent = false);
|
||||
@@ -168,6 +169,7 @@ class ProjectView : public QWidget
|
||||
void setDisplayFallbackWidget(bool);
|
||||
void adjustReadOnlyState();
|
||||
void diagramAdded(Diagram *diagram);
|
||||
void diagramRemoved(Diagram *diagram);
|
||||
|
||||
// attributes
|
||||
private:
|
||||
|
||||
+5
-4
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
#include "qet.h"
|
||||
#include "qeticons.h"
|
||||
#include "shortcutmanager.h"
|
||||
|
||||
#include <limits>
|
||||
#include <QGraphicsSceneContextMenuEvent>
|
||||
@@ -785,10 +786,10 @@ QActionGroup *QET::depthActionGroup(QObject *parent)
|
||||
edit_lower ->setStatusTip(QObject::tr("Éloigne la ou les sélections"));
|
||||
edit_backward->setStatusTip(QObject::tr("Envoie en arrière plan la ou les sélections"));
|
||||
|
||||
edit_raise ->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_Up);
|
||||
edit_lower ->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_Down);
|
||||
edit_backward->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_End);
|
||||
edit_forward ->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_Home);
|
||||
ShortcutManager::instance().registerAction(edit_raise, "depth.raise", QObject::tr("Profondeur"), Qt::CTRL | Qt::SHIFT | Qt::Key_Up);
|
||||
ShortcutManager::instance().registerAction(edit_lower, "depth.lower", QObject::tr("Profondeur"), Qt::CTRL | Qt::SHIFT | Qt::Key_Down);
|
||||
ShortcutManager::instance().registerAction(edit_backward, "depth.backward", QObject::tr("Profondeur"), Qt::CTRL | Qt::SHIFT | Qt::Key_End);
|
||||
ShortcutManager::instance().registerAction(edit_forward, "depth.forward", QObject::tr("Profondeur"), Qt::CTRL | Qt::SHIFT | Qt::Key_Home);
|
||||
|
||||
edit_forward ->setData(QET::BringForward);
|
||||
edit_raise ->setData(QET::Raise);
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "titleblocktemplate.h"
|
||||
#include "ui/aboutqetdialog.h"
|
||||
#include "ui/configpage/generalconfigurationpage.h"
|
||||
#include "ui/configpage/shortcutsconfigpage.h"
|
||||
#include "machine_info.h"
|
||||
#include "TerminalStrip/ui/terminalstripeditorwindow.h"
|
||||
#include "qetversion.h"
|
||||
@@ -2051,6 +2052,7 @@ void QETApp::configureQET()
|
||||
cd.addPage(new NewDiagramPage());
|
||||
cd.addPage(new ExportConfigPage());
|
||||
cd.addPage(new PrintConfigPage());
|
||||
cd.addPage(new ShortcutsConfigPage());
|
||||
|
||||
// associates the dialog with a possible parent widget
|
||||
// associe le dialogue a un eventuel widget parent
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include "qeticons.h"
|
||||
#include "qetmessagebox.h"
|
||||
#include "recentfiles.h"
|
||||
#include "shortcutmanager.h"
|
||||
#include "ui/bomexportdialog.h"
|
||||
#include "ui/diagrampropertieseditordockwidget.h"
|
||||
#include "ui/backupdialog.h"
|
||||
@@ -275,7 +276,7 @@ void QETDiagramEditor::setUpActions()
|
||||
{
|
||||
//Export to another file type (jpeg, dxf etc...)
|
||||
m_export_to_images = new QAction(QET::Icons::DocumentExport, tr("E&xporter"), this);
|
||||
m_export_to_images->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_X);
|
||||
ShortcutManager::instance().registerAction(m_export_to_images, "diagrameditor.export_to_images", tr("Éditeur de schémas"), Qt::CTRL | Qt::SHIFT | Qt::Key_X);
|
||||
m_export_to_images->setStatusTip(tr("Exporte le folio courant dans un autre format", "status bar tip"));
|
||||
connect(m_export_to_images, &QAction::triggered, [this]() {
|
||||
ProjectView *current_project = currentProjectView();
|
||||
@@ -286,7 +287,7 @@ void QETDiagramEditor::setUpActions()
|
||||
|
||||
//Print
|
||||
m_print = new QAction(QET::Icons::DocumentPrint, tr("Imprimer"), this);
|
||||
m_print->setShortcut(QKeySequence::Print);
|
||||
ShortcutManager::instance().registerAction(m_print, "diagrameditor.print", tr("Éditeur de schémas"), QKeySequence::Print);
|
||||
m_print->setStatusTip(tr("Imprime un ou plusieurs folios du projet courant", "status bar tip"));
|
||||
connect(m_print, &QAction::triggered, [this]() {
|
||||
auto project = currentProject();
|
||||
@@ -307,19 +308,19 @@ void QETDiagramEditor::setUpActions()
|
||||
|
||||
//Quit editor
|
||||
m_quit_editor = new QAction(QET::Icons::ApplicationExit, tr("&Quitter"), this);
|
||||
m_quit_editor->setShortcut(Qt::CTRL | Qt::Key_Q);
|
||||
ShortcutManager::instance().registerAction(m_quit_editor, "diagrameditor.quit", tr("Éditeur de schémas"), Qt::CTRL | Qt::Key_Q);
|
||||
m_quit_editor->setStatusTip(tr("Ferme l'application QElectroTech", "status bar tip"));
|
||||
connect(m_quit_editor, &QAction::triggered, this, &QETDiagramEditor::close);
|
||||
|
||||
//Undo
|
||||
undo = undo_group.createUndoAction(this, tr("Annuler"));
|
||||
undo->setIcon(QET::Icons::EditUndo);
|
||||
undo->setShortcut(QKeySequence::Undo);
|
||||
ShortcutManager::instance().registerAction(undo, "diagrameditor.undo", tr("Éditeur de schémas"), QKeySequence::Undo);
|
||||
undo->setStatusTip(tr("Annule l'action précédente", "status bar tip"));
|
||||
//Redo
|
||||
redo = undo_group.createRedoAction(this, tr("Refaire"));
|
||||
redo->setIcon(QET::Icons::EditRedo);
|
||||
redo->setShortcut(QKeySequence::Redo);
|
||||
ShortcutManager::instance().registerAction(redo, "diagrameditor.redo", tr("Éditeur de schémas"), QKeySequence::Redo);
|
||||
redo->setStatusTip(tr("Restaure l'action annulée", "status bar tip"));
|
||||
|
||||
//cut copy past
|
||||
@@ -327,9 +328,9 @@ void QETDiagramEditor::setUpActions()
|
||||
m_copy = new QAction(QET::Icons::EditCopy, tr("Cop&ier"), this);
|
||||
m_paste = new QAction(QET::Icons::EditPaste, tr("C&oller"), this);
|
||||
|
||||
m_cut -> setShortcut(QKeySequence::Cut);
|
||||
m_copy -> setShortcut(QKeySequence::Copy);
|
||||
m_paste -> setShortcut(QKeySequence::Paste);
|
||||
ShortcutManager::instance().registerAction(m_cut, "diagrameditor.cut", tr("Éditeur de schémas"), QKeySequence::Cut);
|
||||
ShortcutManager::instance().registerAction(m_copy, "diagrameditor.copy", tr("Éditeur de schémas"), QKeySequence::Copy);
|
||||
ShortcutManager::instance().registerAction(m_paste, "diagrameditor.paste", tr("Éditeur de schémas"), QKeySequence::Paste);
|
||||
|
||||
m_cut -> setStatusTip(tr("Transfère les éléments sélectionnés dans le presse-papier", "status bar tip"));
|
||||
m_copy -> setStatusTip(tr("Copie les éléments sélectionnés dans le presse-papier", "status bar tip"));
|
||||
@@ -350,7 +351,7 @@ void QETDiagramEditor::setUpActions()
|
||||
|
||||
//Reset conductor path
|
||||
m_conductor_reset = new QAction(QET::Icons::ConductorSettings, tr("Réinitialiser les conducteurs"), this);
|
||||
m_conductor_reset->setShortcut(Qt::CTRL | Qt::Key_K);
|
||||
ShortcutManager::instance().registerAction(m_conductor_reset, "diagrameditor.conductor_reset", tr("Éditeur de schémas"), Qt::CTRL | Qt::Key_K);
|
||||
m_conductor_reset->setStatusTip(tr("Recalcule les chemins des conducteurs sans tenir compte des modifications", "status bar tip"));
|
||||
connect(m_conductor_reset, &QAction::triggered, [this]() {
|
||||
if (DiagramView *dv = currentDiagramView())
|
||||
@@ -404,7 +405,7 @@ void QETDiagramEditor::setUpActions()
|
||||
|
||||
//Edit current diagram properties
|
||||
m_edit_diagram_properties = new QAction(QET::Icons::DialogInformation, tr("Propriétés du folio"), this);
|
||||
m_edit_diagram_properties->setShortcut(Qt::CTRL | Qt::Key_L);
|
||||
ShortcutManager::instance().registerAction(m_edit_diagram_properties, "diagrameditor.edit_diagram_properties", tr("Éditeur de schémas"), Qt::CTRL | Qt::Key_L);
|
||||
m_edit_diagram_properties -> setStatusTip(tr("Édite les propriétés du folio (dimensions, informations du cartouche, propriétés des conducteurs...)", "status bar tip"));
|
||||
connect(m_edit_diagram_properties, &QAction::triggered, [this]() {
|
||||
if (ProjectView *project_view = currentProjectView())
|
||||
@@ -422,7 +423,7 @@ void QETDiagramEditor::setUpActions()
|
||||
|
||||
//Add new folio to current project
|
||||
m_project_add_diagram = new QAction(QET::Icons::DiagramAdd, tr("Ajouter un folio"), this);
|
||||
m_project_add_diagram->setShortcut(Qt::CTRL | Qt::Key_T);
|
||||
ShortcutManager::instance().registerAction(m_project_add_diagram, "diagrameditor.project_add_diagram", tr("Éditeur de schémas"), Qt::CTRL | Qt::Key_T);
|
||||
connect(m_project_add_diagram, &QAction::triggered, [this]() {
|
||||
if (ProjectView *current_project = currentProjectView()) {
|
||||
current_project->project()->addNewDiagram();
|
||||
@@ -566,12 +567,12 @@ void QETDiagramEditor::setUpActions()
|
||||
|
||||
//Navigate next/previous project
|
||||
m_next_window = new QAction(tr("Projet suivant"), this);
|
||||
m_next_window->setShortcut(QKeySequence::NextChild);
|
||||
ShortcutManager::instance().registerAction(m_next_window, "diagrameditor.next_window", tr("Éditeur de schémas"), QKeySequence::NextChild);
|
||||
m_next_window->setStatusTip(tr("Active le projet suivant", "status bar tip"));
|
||||
connect(m_next_window, &QAction::triggered, &m_workspace, &QMdiArea::activateNextSubWindow);
|
||||
|
||||
m_previous_window = new QAction(tr("Projet précédent"), this);
|
||||
m_previous_window->setShortcut(QKeySequence::PreviousChild);
|
||||
ShortcutManager::instance().registerAction(m_previous_window, "diagrameditor.previous_window", tr("Éditeur de schémas"), QKeySequence::PreviousChild);
|
||||
m_previous_window->setStatusTip(tr("Active le projet précédent", "status bar tip"));
|
||||
connect(m_previous_window, &QAction::triggered, &m_workspace, &QMdiArea::activatePreviousSubWindow);
|
||||
|
||||
@@ -582,11 +583,11 @@ void QETDiagramEditor::setUpActions()
|
||||
m_save_file_as = m_file_actions_group.addAction(QET::Icons::DocumentSaveAs, tr("Enregistrer sous"));
|
||||
m_close_file = m_file_actions_group.addAction(QET::Icons::ProjectClose, tr("&Fermer"));
|
||||
|
||||
new_file ->setShortcut(QKeySequence::New);
|
||||
open_file ->setShortcut(QKeySequence::Open);
|
||||
m_close_file ->setShortcut(QKeySequence::Close);
|
||||
m_save_file ->setShortcut(QKeySequence::Save);
|
||||
m_save_file_as ->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_S);
|
||||
ShortcutManager::instance().registerAction(new_file, "diagrameditor.new_file", tr("Éditeur de schémas"), QKeySequence::New);
|
||||
ShortcutManager::instance().registerAction(open_file, "diagrameditor.open_file", tr("Éditeur de schémas"), QKeySequence::Open);
|
||||
ShortcutManager::instance().registerAction(m_close_file, "diagrameditor.close_file", tr("Éditeur de schémas"), QKeySequence::Close);
|
||||
ShortcutManager::instance().registerAction(m_save_file, "diagrameditor.save_file", tr("Éditeur de schémas"), QKeySequence::Save);
|
||||
ShortcutManager::instance().registerAction(m_save_file_as, "diagrameditor.save_file_as", tr("Éditeur de schémas"), Qt::CTRL | Qt::SHIFT | Qt::Key_S);
|
||||
|
||||
new_file ->setStatusTip( tr("Crée un nouveau projet", "status bar tip") );
|
||||
open_file ->setStatusTip( tr("Ouvre un projet existant", "status bar tip") );
|
||||
@@ -630,10 +631,10 @@ void QETDiagramEditor::setUpActions()
|
||||
m_edit_selection = m_selection_actions_group.addAction( QET::Icons::ElementEdit, tr("Éditer l'item sélectionné") );
|
||||
m_group_selected_texts = m_selection_actions_group.addAction( QET::Icons::textGroup, tr("Grouper les textes sélectionnés"));
|
||||
|
||||
m_delete_selection->setShortcut(Qt::Key_Delete);
|
||||
m_rotate_selection->setShortcut(Qt::Key_Space);
|
||||
m_rotate_texts ->setShortcut(Qt::CTRL | Qt::Key_Space);
|
||||
m_edit_selection ->setShortcut(Qt::CTRL | Qt::Key_E);
|
||||
ShortcutManager::instance().registerAction(m_delete_selection, "diagrameditor.delete_selection", tr("Éditeur de schémas"), Qt::Key_Delete);
|
||||
ShortcutManager::instance().registerAction(m_rotate_selection, "diagrameditor.rotate_selection", tr("Éditeur de schémas"), Qt::Key_Space);
|
||||
ShortcutManager::instance().registerAction(m_rotate_texts, "diagrameditor.rotate_texts", tr("Éditeur de schémas"), Qt::CTRL | Qt::Key_Space);
|
||||
ShortcutManager::instance().registerAction(m_edit_selection, "diagrameditor.edit_selection", tr("Éditeur de schémas"), Qt::CTRL | Qt::Key_E);
|
||||
|
||||
m_delete_selection->setStatusTip( tr("Enlève les éléments sélectionnés du folio", "status bar tip"));
|
||||
m_rotate_selection->setStatusTip( tr("Pivote les éléments et textes sélectionnés", "status bar tip"));
|
||||
@@ -654,9 +655,9 @@ void QETDiagramEditor::setUpActions()
|
||||
QAction *select_nothing = m_select_actions_group.addAction( QET::Icons::EditSelectNone, tr("Désélectionner tout") );
|
||||
QAction *select_invert = m_select_actions_group.addAction( QET::Icons::EditSelectInvert, tr("Inverser la sélection") );
|
||||
|
||||
select_all ->setShortcut(QKeySequence::SelectAll);
|
||||
select_nothing->setShortcut(QKeySequence::Deselect);
|
||||
select_invert ->setShortcut(Qt::CTRL | Qt::Key_I);
|
||||
ShortcutManager::instance().registerAction(select_all, "diagrameditor.select_all", tr("Éditeur de schémas"), QKeySequence::SelectAll);
|
||||
ShortcutManager::instance().registerAction(select_nothing, "diagrameditor.select_nothing", tr("Éditeur de schémas"), QKeySequence::Deselect);
|
||||
ShortcutManager::instance().registerAction(select_invert, "diagrameditor.select_invert", tr("Éditeur de schémas"), Qt::CTRL | Qt::Key_I);
|
||||
|
||||
select_all ->setStatusTip( tr("Sélectionne tous les éléments du folio", "status bar tip") );
|
||||
select_nothing->setStatusTip( tr("Désélectionne tous les éléments du folio", "status bar tip") );
|
||||
@@ -676,11 +677,11 @@ void QETDiagramEditor::setUpActions()
|
||||
QAction *zoom_reset = m_zoom_actions_group.addAction( QET::Icons::ZoomOriginal, tr("Pas de zoom"));
|
||||
m_zoom_action_toolBar << zoom_content << zoom_fit << zoom_reset;
|
||||
|
||||
zoom_in ->setShortcut(QKeySequence::ZoomIn);
|
||||
zoom_out ->setShortcut(QKeySequence::ZoomOut);
|
||||
zoom_content->setShortcut(Qt::CTRL | Qt::Key_8);
|
||||
zoom_fit ->setShortcut(Qt::CTRL | Qt::Key_9);
|
||||
zoom_reset ->setShortcut(Qt::CTRL | Qt::Key_0);
|
||||
ShortcutManager::instance().registerAction(zoom_in, "diagrameditor.zoom_in", tr("Éditeur de schémas"), QKeySequence::ZoomIn);
|
||||
ShortcutManager::instance().registerAction(zoom_out, "diagrameditor.zoom_out", tr("Éditeur de schémas"), QKeySequence::ZoomOut);
|
||||
ShortcutManager::instance().registerAction(zoom_content, "diagrameditor.zoom_content", tr("Éditeur de schémas"), Qt::CTRL | Qt::Key_8);
|
||||
ShortcutManager::instance().registerAction(zoom_fit, "diagrameditor.zoom_fit", tr("Éditeur de schémas"), Qt::CTRL | Qt::Key_9);
|
||||
ShortcutManager::instance().registerAction(zoom_reset, "diagrameditor.zoom_reset", tr("Éditeur de schémas"), Qt::CTRL | Qt::Key_0);
|
||||
|
||||
zoom_in ->setStatusTip(tr("Agrandit le folio", "status bar tip"));
|
||||
zoom_out ->setStatusTip(tr("Rétrécit le folio", "status bar tip"));
|
||||
@@ -738,7 +739,7 @@ void QETDiagramEditor::setUpActions()
|
||||
});
|
||||
|
||||
m_find = new QAction(tr("Chercher/remplacer"), this);
|
||||
m_find->setShortcut(QKeySequence::Find);
|
||||
ShortcutManager::instance().registerAction(m_find, "diagrameditor.find", tr("Éditeur de schémas"), QKeySequence::Find);
|
||||
connect(m_find, &QAction::triggered, [this]()
|
||||
{
|
||||
if (auto animator = m_search_and_replace_widget.findChild<QWidgetAnimation *>("search and replace animator")) {
|
||||
@@ -2249,17 +2250,26 @@ void QETDiagramEditor::removeDiagrams(const QList<Diagram *> &diagrams)
|
||||
}
|
||||
|
||||
ProjectView *project_view = nullptr;
|
||||
if (QETProject *diagram_project = diagrams.first()->project()) {
|
||||
project_view = findProject(diagram_project);
|
||||
QETProject *project = diagrams.first()->project();
|
||||
if (project) {
|
||||
project_view = findProject(project);
|
||||
}
|
||||
|
||||
if (project_view) project_view->setUpdatesEnabled(false);
|
||||
if (pa) pa->setUpdatesEnabled(false);
|
||||
|
||||
if (project) {
|
||||
project->undoStack()->beginMacro(diagrams.count() == 1
|
||||
? tr("Supprimer le folio")
|
||||
: tr("Supprimer %1 folios").arg(diagrams.count()));
|
||||
}
|
||||
|
||||
foreach (Diagram *diagram, diagrams) {
|
||||
removeDiagramSilent(diagram);
|
||||
}
|
||||
|
||||
if (project) project->undoStack()->endMacro();
|
||||
|
||||
if (pa) pa->setUpdatesEnabled(true);
|
||||
if (project_view) project_view->setUpdatesEnabled(true);
|
||||
|
||||
@@ -2289,10 +2299,12 @@ void QETDiagramEditor::moveDiagramUp(const QList<Diagram *> &diagrams) {
|
||||
if (!diagram_project->isReadOnly()) {
|
||||
if (ProjectView *project_view = findProject(diagram_project)) {
|
||||
// Forward loop for moving up
|
||||
diagram_project->undoStack()->beginMacro(tr("Déplacer les folios"));
|
||||
for (int i = 0; i < safeDiagrams.size(); ++i) {
|
||||
project_view->moveDiagramUp(safeDiagrams.at(i));
|
||||
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
|
||||
}
|
||||
diagram_project->undoStack()->endMacro();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2305,10 +2317,12 @@ void QETDiagramEditor::moveDiagramDown(const QList<Diagram *> &diagrams) {
|
||||
if (!diagram_project->isReadOnly()) {
|
||||
if (ProjectView *project_view = findProject(diagram_project)) {
|
||||
// Backward loop for moving down
|
||||
diagram_project->undoStack()->beginMacro(tr("Déplacer les folios"));
|
||||
for (int i = safeDiagrams.size() - 1; i >= 0; --i) {
|
||||
project_view->moveDiagramDown(safeDiagrams.at(i));
|
||||
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
|
||||
}
|
||||
diagram_project->undoStack()->endMacro();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2321,10 +2335,12 @@ void QETDiagramEditor::moveDiagramUpTop(const QList<Diagram *> &diagrams) {
|
||||
if (!diagram_project->isReadOnly()) {
|
||||
if (ProjectView *project_view = findProject(diagram_project)) {
|
||||
// Backward loop to preserve relative order of the selected items when moving to top
|
||||
diagram_project->undoStack()->beginMacro(tr("Déplacer les folios"));
|
||||
for (int i = safeDiagrams.size() - 1; i >= 0; --i) {
|
||||
project_view->moveDiagramUpTop(safeDiagrams.at(i));
|
||||
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
|
||||
}
|
||||
diagram_project->undoStack()->endMacro();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2337,10 +2353,12 @@ void QETDiagramEditor::moveDiagramUpx10(const QList<Diagram *> &diagrams) {
|
||||
if (!diagram_project->isReadOnly()) {
|
||||
if (ProjectView *project_view = findProject(diagram_project)) {
|
||||
// Forward loop for moving up
|
||||
diagram_project->undoStack()->beginMacro(tr("Déplacer les folios"));
|
||||
for (int i = 0; i < safeDiagrams.size(); ++i) {
|
||||
project_view->moveDiagramUpx10(safeDiagrams.at(i));
|
||||
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
|
||||
}
|
||||
diagram_project->undoStack()->endMacro();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2353,10 +2371,12 @@ void QETDiagramEditor::moveDiagramDownx10(const QList<Diagram *> &diagrams) {
|
||||
if (!diagram_project->isReadOnly()) {
|
||||
if (ProjectView *project_view = findProject(diagram_project)) {
|
||||
// Backward loop for moving down
|
||||
diagram_project->undoStack()->beginMacro(tr("Déplacer les folios"));
|
||||
for (int i = safeDiagrams.size() - 1; i >= 0; --i) {
|
||||
project_view->moveDiagramDownx10(safeDiagrams.at(i));
|
||||
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
|
||||
}
|
||||
diagram_project->undoStack()->endMacro();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2369,10 +2389,12 @@ void QETDiagramEditor::moveDiagramUpx100(const QList<Diagram *> &diagrams) {
|
||||
if (!diagram_project->isReadOnly()) {
|
||||
if (ProjectView *project_view = findProject(diagram_project)) {
|
||||
// Forward loop for moving up
|
||||
diagram_project->undoStack()->beginMacro(tr("Déplacer les folios"));
|
||||
for (int i = 0; i < safeDiagrams.size(); ++i) {
|
||||
project_view->moveDiagramUpx100(safeDiagrams.at(i));
|
||||
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
|
||||
}
|
||||
diagram_project->undoStack()->endMacro();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2385,10 +2407,12 @@ void QETDiagramEditor::moveDiagramDownx100(const QList<Diagram *> &diagrams) {
|
||||
if (!diagram_project->isReadOnly()) {
|
||||
if (ProjectView *project_view = findProject(diagram_project)) {
|
||||
// Backward loop for moving down
|
||||
diagram_project->undoStack()->beginMacro(tr("Déplacer les folios"));
|
||||
for (int i = safeDiagrams.size() - 1; i >= 0; --i) {
|
||||
project_view->moveDiagramDownx100(safeDiagrams.at(i));
|
||||
QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
|
||||
}
|
||||
diagram_project->undoStack()->endMacro();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include "qetmainwindow.h"
|
||||
#include "qeticons.h"
|
||||
#include "shortcutmanager.h"
|
||||
#include "qetapp.h"
|
||||
#include "qetdiagrameditor.h"
|
||||
#include "projectview.h"
|
||||
@@ -98,7 +99,7 @@ void QETMainWindow::initCommonActions()
|
||||
QDesktopServices::openUrl(QUrl(link));
|
||||
});
|
||||
|
||||
manual_online_ -> setShortcut(Qt::Key_F1);
|
||||
ShortcutManager::instance().registerAction(manual_online_, "mainwindow.manual_online", tr("Général"), Qt::Key_F1);
|
||||
|
||||
youtube_ = new QAction(QET::Icons::QETVideo, tr("Chaine Youtube"), this);
|
||||
youtube_ -> setStatusTip(tr("Lance le navigateur par défaut vers la chaine Youtube de QElectroTech", "status bar tip"));
|
||||
@@ -220,7 +221,7 @@ void QETMainWindow::updateFullScreenAction()
|
||||
fullscreen_action_ -> setIcon(QET::Icons::FullScreenEnter);
|
||||
fullscreen_action_ -> setStatusTip(tr("Affiche QElectroTech en mode plein écran", "status bar tip"));
|
||||
}
|
||||
fullscreen_action_ -> setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_F);
|
||||
ShortcutManager::instance().registerAction(fullscreen_action_, "mainwindow.fullscreen", tr("Général"), Qt::CTRL | Qt::SHIFT | Qt::Key_F);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+36
-10
@@ -34,6 +34,7 @@
|
||||
#include "TerminalStrip/terminalstrip.h"
|
||||
#include "qetxml.h"
|
||||
#include "qetversion.h"
|
||||
#include "undocommand/adddiagramcommand.h"
|
||||
|
||||
#include <QElapsedTimer>
|
||||
#include <QHash>
|
||||
@@ -1348,6 +1349,8 @@ bool QETProject::usesTitleBlockTemplate(const TitleBlockTemplateLocation &locati
|
||||
/**
|
||||
@brief QETProject::addNewDiagram
|
||||
Add a new diagram in project at position pos.
|
||||
This is pushed as an undoable AddDiagramCommand: use undoStack()->undo()
|
||||
to remove it again.
|
||||
@param pos
|
||||
@return the new created diagram
|
||||
*/
|
||||
@@ -1363,14 +1366,15 @@ Diagram *QETProject::addNewDiagram(int pos)
|
||||
diagram->border_and_titleblock.importTitleBlock(defaultTitleBlockProperties());
|
||||
diagram->defaultConductorProperties = defaultConductorProperties();
|
||||
|
||||
addDiagram(diagram, pos);
|
||||
emit diagramAdded(this, diagram);
|
||||
m_undo_stack->push(new AddDiagramCommand(this, diagram, pos));
|
||||
return(diagram);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QETProject::removeDiagram
|
||||
Remove diagram from project
|
||||
Remove diagram from project immediately (not undoable). UI code should
|
||||
generally go through ProjectView::removeDiagram() instead, which pushes
|
||||
an undoable RemoveDiagramCommand.
|
||||
@param diagram
|
||||
*/
|
||||
void QETProject::removeDiagram(Diagram *diagram)
|
||||
@@ -1380,13 +1384,8 @@ void QETProject::removeDiagram(Diagram *diagram)
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_diagrams_list.removeAll(diagram))
|
||||
{
|
||||
emit diagramRemoved(this, diagram);
|
||||
diagram->deleteLater();
|
||||
}
|
||||
|
||||
updateDiagramsFolioData();
|
||||
detachDiagram(diagram);
|
||||
diagram->deleteLater();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1930,6 +1929,33 @@ void QETProject::addDiagram(Diagram *diagram, int pos)
|
||||
}
|
||||
|
||||
updateDiagramsFolioData();
|
||||
emit diagramAdded(this, diagram);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief QETProject::detachDiagram
|
||||
Inverse of addDiagram(): removes \p diagram from this project's diagram
|
||||
list and disconnects the signals set up by addDiagram(), without
|
||||
destroying it. Used by RemoveDiagramCommand (and removeDiagram()) so a
|
||||
removed diagram can be parked and later reinserted by undo.
|
||||
@param diagram
|
||||
*/
|
||||
void QETProject::detachDiagram(Diagram *diagram)
|
||||
{
|
||||
if (!diagram || !m_diagrams_list.contains(diagram)) {
|
||||
return;
|
||||
}
|
||||
|
||||
disconnect(&diagram->border_and_titleblock,
|
||||
&BorderTitleBlock::needFolioData,
|
||||
this,
|
||||
&QETProject::updateDiagramsFolioData);
|
||||
disconnect(diagram, &Diagram::usedTitleBlockTemplateChanged,
|
||||
this, &QETProject::usedTitleBlockTemplateChanged);
|
||||
|
||||
m_diagrams_list.removeAll(diagram);
|
||||
updateDiagramsFolioData();
|
||||
emit diagramRemoved(this, diagram);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -75,6 +75,8 @@ struct GuideProperties {
|
||||
*/
|
||||
class QETProject : public QObject
|
||||
{
|
||||
friend class AddDiagramCommand;
|
||||
friend class RemoveDiagramCommand;
|
||||
Q_OBJECT
|
||||
public :
|
||||
//This enum lists possible states for a particular project.
|
||||
@@ -257,6 +259,7 @@ class QETProject : public QObject
|
||||
void writeDefaultPropertiesXml(QDomElement &);
|
||||
void writeUsageXml(QDomElement &);
|
||||
void addDiagram(Diagram *diagram, int pos = -1);
|
||||
void detachDiagram(Diagram *diagram);
|
||||
void writeBackup();
|
||||
void init();
|
||||
ProjectState openFile(QFile *file);
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
|
||||
#include "richtexteditor_p.h"
|
||||
#include "ui_addlinkdialog.h"
|
||||
#include "../shortcutmanager.h"
|
||||
|
||||
//#include <QtDesigner/QDesignerFormEditorInterface>
|
||||
|
||||
@@ -461,19 +462,19 @@ RichTextEditorToolBar::RichTextEditorToolBar(RichTextEditor *editor,
|
||||
m_bold_action = createCheckableAction(
|
||||
QIcon(":/ico/32x32/format-text-bold.png"),
|
||||
tr("Texte en gras"), editor, SLOT(setFontBold(bool)), this);
|
||||
m_bold_action->setShortcut(Qt::CTRL | Qt::Key_B);
|
||||
ShortcutManager::instance().registerAction(m_bold_action, "richtext.bold", tr("Éditeur de texte"), Qt::CTRL | Qt::Key_B);
|
||||
addAction(m_bold_action);
|
||||
|
||||
m_italic_action = createCheckableAction(
|
||||
QIcon(":/ico/32x32/format-text-italic.png"),
|
||||
tr("Texte en italique"), editor, SLOT(setFontItalic(bool)), this);
|
||||
m_italic_action->setShortcut(Qt::CTRL | Qt::Key_I);
|
||||
ShortcutManager::instance().registerAction(m_italic_action, "richtext.italic", tr("Éditeur de texte"), Qt::CTRL | Qt::Key_I);
|
||||
addAction(m_italic_action);
|
||||
|
||||
m_underline_action = createCheckableAction(
|
||||
QIcon(":/ico/32x32/format-text-underline.png"),
|
||||
tr("Texte souligé"), editor, SLOT(setFontUnderline(bool)), this);
|
||||
m_underline_action->setShortcut(Qt::CTRL | Qt::Key_U);
|
||||
ShortcutManager::instance().registerAction(m_underline_action, "richtext.underline", tr("Éditeur de texte"), Qt::CTRL | Qt::Key_U);
|
||||
addAction(m_underline_action);
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
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 "shortcutmanager.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QSettings>
|
||||
#include <QVariant>
|
||||
#include <algorithm>
|
||||
|
||||
namespace {
|
||||
const QString SETTINGS_GROUP = QStringLiteral("shortcuts/");
|
||||
}
|
||||
|
||||
ShortcutManager &ShortcutManager::instance()
|
||||
{
|
||||
static ShortcutManager manager;
|
||||
return manager;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief ShortcutManager::savedSequence
|
||||
@param id
|
||||
@param default_sequence
|
||||
@return the user-overridden sequence stored for \a id, or \a default_sequence
|
||||
if the user never overrode it. A stored-but-empty sequence (the user
|
||||
cleared the shortcut) is returned as an empty QKeySequence, not the default.
|
||||
*/
|
||||
QKeySequence ShortcutManager::savedSequence(const QString &id, const QKeySequence &default_sequence) const
|
||||
{
|
||||
QSettings settings;
|
||||
const QString key = SETTINGS_GROUP + id;
|
||||
if (!settings.contains(key)) {
|
||||
return default_sequence;
|
||||
}
|
||||
return QKeySequence::fromString(settings.value(key).toString());
|
||||
}
|
||||
|
||||
/**
|
||||
@brief ShortcutManager::registerAction
|
||||
Register \a target under \a id, applying the user's saved override (if
|
||||
any) or \a default_sequence otherwise. \a target must be a QAction or a
|
||||
QAbstractButton -- both declare a "shortcut" QKeySequence property, which
|
||||
is what's actually read/written here, so this works for either without a
|
||||
separate code path. Safe to call once per instance that shares this id
|
||||
(e.g. once per open window of the same kind) -- the first call to reach a
|
||||
given id fixes its category, description (taken from the target's current
|
||||
"text" property) and default sequence for the lifetime of the
|
||||
application; later calls just register another live target to update.
|
||||
*/
|
||||
void ShortcutManager::registerAction(QObject *target, const QString &id,
|
||||
const QString &category,
|
||||
const QKeySequence &default_sequence)
|
||||
{
|
||||
if (!target) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto it = m_entries.find(id);
|
||||
if (it == m_entries.end()) {
|
||||
Entry entry;
|
||||
entry.category = category;
|
||||
entry.description = target->property("text").toString();
|
||||
entry.description.remove(QLatin1Char('&'));
|
||||
entry.default_sequence = default_sequence;
|
||||
it = m_entries.insert(id, entry);
|
||||
m_order << id;
|
||||
}
|
||||
|
||||
QList<QPointer<QObject>> &targets = it->targets;
|
||||
targets.erase(std::remove_if(targets.begin(), targets.end(),
|
||||
[](const QPointer<QObject> &t) { return t.isNull(); }),
|
||||
targets.end());
|
||||
if (!targets.contains(target)) {
|
||||
targets << target;
|
||||
}
|
||||
|
||||
target->setProperty("shortcut", QVariant::fromValue(savedSequence(id, it->default_sequence)));
|
||||
}
|
||||
|
||||
/**
|
||||
@return every registered shortcut, in registration order, along with its
|
||||
currently effective sequence -- for display in the Shortcuts config page.
|
||||
*/
|
||||
QList<ShortcutManager::ShortcutInfo> ShortcutManager::allShortcuts() const
|
||||
{
|
||||
QList<ShortcutInfo> list;
|
||||
for (const QString &id : m_order) {
|
||||
const Entry &entry = m_entries.value(id);
|
||||
ShortcutInfo info;
|
||||
info.id = id;
|
||||
info.category = entry.category;
|
||||
info.description = entry.description;
|
||||
info.default_sequence = entry.default_sequence;
|
||||
info.current_sequence = savedSequence(id, entry.default_sequence);
|
||||
list << info;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
QKeySequence ShortcutManager::currentSequence(const QString &id) const
|
||||
{
|
||||
auto it = m_entries.find(id);
|
||||
if (it == m_entries.end()) {
|
||||
return QKeySequence();
|
||||
}
|
||||
return savedSequence(id, it->default_sequence);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief ShortcutManager::setSequence
|
||||
Persist \a sequence as the binding for \a id and apply it immediately to
|
||||
every currently live QAction registered under that id. Persisted as "no
|
||||
override" when \a sequence matches the id's default, so a future QET
|
||||
version raising that default takes effect for users who never customized it.
|
||||
*/
|
||||
void ShortcutManager::setSequence(const QString &id, const QKeySequence &sequence)
|
||||
{
|
||||
auto it = m_entries.find(id);
|
||||
if (it == m_entries.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QSettings settings;
|
||||
const QString key = SETTINGS_GROUP + id;
|
||||
if (sequence == it->default_sequence) {
|
||||
settings.remove(key);
|
||||
} else {
|
||||
settings.setValue(key, sequence.toString());
|
||||
}
|
||||
|
||||
for (const QPointer<QObject> &target : qAsConst(it->targets)) {
|
||||
if (target) {
|
||||
target->setProperty("shortcut", QVariant::fromValue(sequence));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ShortcutManager::resetToDefault(const QString &id)
|
||||
{
|
||||
auto it = m_entries.find(id);
|
||||
if (it == m_entries.end()) {
|
||||
return;
|
||||
}
|
||||
setSequence(id, it->default_sequence);
|
||||
}
|
||||
|
||||
void ShortcutManager::resetAllToDefaults()
|
||||
{
|
||||
for (const QString &id : m_order) {
|
||||
resetToDefault(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
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 SHORTCUTMANAGER_H
|
||||
#define SHORTCUTMANAGER_H
|
||||
|
||||
#include <QHash>
|
||||
#include <QKeySequence>
|
||||
#include <QList>
|
||||
#include <QPointer>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
class QObject;
|
||||
|
||||
/**
|
||||
@brief The ShortcutManager class
|
||||
App-wide registry of every rebindable shortcut, carried by either a
|
||||
QAction or a QAbstractButton -- both declare an identical "shortcut"
|
||||
Q_PROPERTY of type QKeySequence, which this class targets generically via
|
||||
QObject so it doesn't need a separate code path for the handful of
|
||||
QAbstractButton-based shortcuts (e.g. a QPushButton acting as a shortcut-
|
||||
only trigger).
|
||||
|
||||
Every place in the code that used to call setShortcut() directly now
|
||||
calls registerAction() instead, giving each shortcut a stable string id, a
|
||||
category (for grouping in the UI) and a hardcoded default sequence.
|
||||
registerAction() applies the user's saved override for that id (if any),
|
||||
falling back to the default, and remembers the target so the Shortcuts
|
||||
configuration page can list, edit and persist it.
|
||||
|
||||
Several targets can share the same id at once, since QET allows several
|
||||
windows of the same kind (diagram editor, element editor...) to be open
|
||||
simultaneously, each with its own QAction. setSequence() updates every
|
||||
live target for a given id in one call.
|
||||
*/
|
||||
class ShortcutManager
|
||||
{
|
||||
public:
|
||||
static ShortcutManager &instance();
|
||||
|
||||
struct ShortcutInfo {
|
||||
QString id;
|
||||
QString category;
|
||||
QString description;
|
||||
QKeySequence default_sequence;
|
||||
QKeySequence current_sequence;
|
||||
};
|
||||
|
||||
void registerAction(QObject *target, const QString &id,
|
||||
const QString &category,
|
||||
const QKeySequence &default_sequence);
|
||||
|
||||
QList<ShortcutInfo> allShortcuts() const;
|
||||
QKeySequence currentSequence(const QString &id) const;
|
||||
void setSequence(const QString &id, const QKeySequence &sequence);
|
||||
void resetToDefault(const QString &id);
|
||||
void resetAllToDefaults();
|
||||
|
||||
private:
|
||||
ShortcutManager() = default;
|
||||
ShortcutManager(const ShortcutManager &) = delete;
|
||||
void operator=(const ShortcutManager &) = delete;
|
||||
|
||||
struct Entry {
|
||||
QString category;
|
||||
QString description;
|
||||
QKeySequence default_sequence;
|
||||
QList<QPointer<QObject>> targets;
|
||||
};
|
||||
|
||||
QKeySequence savedSequence(const QString &id, const QKeySequence &default_sequence) const;
|
||||
|
||||
QHash<QString, Entry> m_entries;
|
||||
QStringList m_order;
|
||||
};
|
||||
|
||||
#endif // SHORTCUTMANAGER_H
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "../qetapp.h"
|
||||
#include "../qeticons.h"
|
||||
#include "../shortcutmanager.h"
|
||||
#include "../qetmessagebox.h"
|
||||
#include "../qetproject.h"
|
||||
#include "templatecellwidget.h"
|
||||
@@ -390,25 +391,25 @@ void QETTitleBlockTemplateEditor::initActions()
|
||||
undo_ -> setIcon(QET::Icons::EditUndo);
|
||||
redo_ -> setIcon(QET::Icons::EditRedo);
|
||||
|
||||
new_ -> setShortcut(QKeySequence::New);
|
||||
open_ -> setShortcut(QKeySequence::Open);
|
||||
open_from_file_ -> setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_O);
|
||||
save_ -> setShortcut(QKeySequence::Save);
|
||||
save_as_file_ -> setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_S);
|
||||
quit_ -> setShortcut(Qt::CTRL | Qt::Key_Q);
|
||||
undo_ -> setShortcut(QKeySequence::Undo);
|
||||
redo_ -> setShortcut(QKeySequence::Redo);
|
||||
cut_ -> setShortcut(QKeySequence::Cut);
|
||||
copy_ -> setShortcut(QKeySequence::Copy);
|
||||
paste_ -> setShortcut(QKeySequence::Paste);
|
||||
edit_logos_ -> setShortcut(Qt::CTRL | Qt::Key_T);
|
||||
edit_info_ -> setShortcut(Qt::CTRL | Qt::Key_Y);
|
||||
merge_cells_ -> setShortcut(Qt::CTRL | Qt::Key_J);
|
||||
split_cell_ -> setShortcut(Qt::CTRL | Qt::Key_K);
|
||||
zoom_in_ -> setShortcut(QKeySequence::ZoomIn);
|
||||
zoom_out_ -> setShortcut(QKeySequence::ZoomOut);
|
||||
zoom_fit_ -> setShortcut(Qt::CTRL | Qt::Key_9);
|
||||
zoom_reset_ -> setShortcut(Qt::CTRL | Qt::Key_0);
|
||||
ShortcutManager::instance().registerAction(new_, "titleblockeditor.new", tr("Éditeur de cartouche"), QKeySequence::New);
|
||||
ShortcutManager::instance().registerAction(open_, "titleblockeditor.open", tr("Éditeur de cartouche"), QKeySequence::Open);
|
||||
ShortcutManager::instance().registerAction(open_from_file_, "titleblockeditor.open_from_file", tr("Éditeur de cartouche"), Qt::CTRL | Qt::SHIFT | Qt::Key_O);
|
||||
ShortcutManager::instance().registerAction(save_, "titleblockeditor.save", tr("Éditeur de cartouche"), QKeySequence::Save);
|
||||
ShortcutManager::instance().registerAction(save_as_file_, "titleblockeditor.save_as_file", tr("Éditeur de cartouche"), Qt::CTRL | Qt::SHIFT | Qt::Key_S);
|
||||
ShortcutManager::instance().registerAction(quit_, "titleblockeditor.quit", tr("Éditeur de cartouche"), Qt::CTRL | Qt::Key_Q);
|
||||
ShortcutManager::instance().registerAction(undo_, "titleblockeditor.undo", tr("Éditeur de cartouche"), QKeySequence::Undo);
|
||||
ShortcutManager::instance().registerAction(redo_, "titleblockeditor.redo", tr("Éditeur de cartouche"), QKeySequence::Redo);
|
||||
ShortcutManager::instance().registerAction(cut_, "titleblockeditor.cut", tr("Éditeur de cartouche"), QKeySequence::Cut);
|
||||
ShortcutManager::instance().registerAction(copy_, "titleblockeditor.copy", tr("Éditeur de cartouche"), QKeySequence::Copy);
|
||||
ShortcutManager::instance().registerAction(paste_, "titleblockeditor.paste", tr("Éditeur de cartouche"), QKeySequence::Paste);
|
||||
ShortcutManager::instance().registerAction(edit_logos_, "titleblockeditor.edit_logos", tr("Éditeur de cartouche"), Qt::CTRL | Qt::Key_T);
|
||||
ShortcutManager::instance().registerAction(edit_info_, "titleblockeditor.edit_info", tr("Éditeur de cartouche"), Qt::CTRL | Qt::Key_Y);
|
||||
ShortcutManager::instance().registerAction(merge_cells_, "titleblockeditor.merge_cells", tr("Éditeur de cartouche"), Qt::CTRL | Qt::Key_J);
|
||||
ShortcutManager::instance().registerAction(split_cell_, "titleblockeditor.split_cell", tr("Éditeur de cartouche"), Qt::CTRL | Qt::Key_K);
|
||||
ShortcutManager::instance().registerAction(zoom_in_, "titleblockeditor.zoom_in", tr("Éditeur de cartouche"), QKeySequence::ZoomIn);
|
||||
ShortcutManager::instance().registerAction(zoom_out_, "titleblockeditor.zoom_out", tr("Éditeur de cartouche"), QKeySequence::ZoomOut);
|
||||
ShortcutManager::instance().registerAction(zoom_fit_, "titleblockeditor.zoom_fit", tr("Éditeur de cartouche"), Qt::CTRL | Qt::Key_9);
|
||||
ShortcutManager::instance().registerAction(zoom_reset_, "titleblockeditor.zoom_reset", tr("Éditeur de cartouche"), Qt::CTRL | Qt::Key_0);
|
||||
|
||||
connect(new_, SIGNAL(triggered()), this, SLOT(newTemplate()));
|
||||
connect(open_, SIGNAL(triggered()), this, SLOT(open()));
|
||||
|
||||
@@ -0,0 +1,227 @@
|
||||
/*
|
||||
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 "shortcutsconfigpage.h"
|
||||
|
||||
#include "../../qeticons.h"
|
||||
#include "../../shortcutmanager.h"
|
||||
|
||||
#include <QFrame>
|
||||
#include <QHBoxLayout>
|
||||
#include <QHeaderView>
|
||||
#include <QKeySequenceEdit>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QTableWidget>
|
||||
#include <QToolButton>
|
||||
#include <QVBoxLayout>
|
||||
#include <algorithm>
|
||||
|
||||
/**
|
||||
@brief ShortcutsConfigPage::ShortcutsConfigPage
|
||||
@param parent
|
||||
*/
|
||||
ShortcutsConfigPage::ShortcutsConfigPage(QWidget *parent) :
|
||||
ConfigPage(parent)
|
||||
{
|
||||
auto *vlayout = new QVBoxLayout();
|
||||
|
||||
QLabel *title_label = new QLabel(this->title());
|
||||
vlayout->addWidget(title_label);
|
||||
|
||||
QFrame *horiz_line = new QFrame();
|
||||
horiz_line->setFrameShape(QFrame::HLine);
|
||||
vlayout->addWidget(horiz_line);
|
||||
|
||||
m_filter_edit = new QLineEdit(this);
|
||||
m_filter_edit->setPlaceholderText(tr("Filtrer les raccourcis…"));
|
||||
connect(m_filter_edit, &QLineEdit::textChanged, this, &ShortcutsConfigPage::filterRows);
|
||||
vlayout->addWidget(m_filter_edit);
|
||||
|
||||
m_table = new QTableWidget(0, 4, this);
|
||||
m_table->setHorizontalHeaderLabels({tr("Catégorie"), tr("Action"), tr("Raccourci"), QString()});
|
||||
m_table->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
|
||||
m_table->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
|
||||
m_table->horizontalHeader()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
|
||||
m_table->horizontalHeader()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
|
||||
m_table->verticalHeader()->setVisible(false);
|
||||
m_table->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||
m_table->setSelectionMode(QAbstractItemView::NoSelection);
|
||||
vlayout->addWidget(m_table);
|
||||
|
||||
auto *reset_all_button = new QPushButton(tr("Tout réinitialiser"), this);
|
||||
connect(reset_all_button, &QPushButton::clicked, this, &ShortcutsConfigPage::resetAllRows);
|
||||
|
||||
auto *bottom_layout = new QHBoxLayout();
|
||||
bottom_layout->addStretch();
|
||||
bottom_layout->addWidget(reset_all_button);
|
||||
vlayout->addLayout(bottom_layout);
|
||||
|
||||
setLayout(vlayout);
|
||||
|
||||
populateTable();
|
||||
}
|
||||
|
||||
ShortcutsConfigPage::~ShortcutsConfigPage()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
@brief ShortcutsConfigPage::populateTable
|
||||
Fill the table with one row per shortcut known to ShortcutManager, sorted
|
||||
by category then action name.
|
||||
*/
|
||||
void ShortcutsConfigPage::populateTable()
|
||||
{
|
||||
QList<ShortcutManager::ShortcutInfo> shortcuts = ShortcutManager::instance().allShortcuts();
|
||||
std::sort(shortcuts.begin(), shortcuts.end(),
|
||||
[](const ShortcutManager::ShortcutInfo &a, const ShortcutManager::ShortcutInfo &b) {
|
||||
if (a.category != b.category) {
|
||||
return a.category < b.category;
|
||||
}
|
||||
return a.description < b.description;
|
||||
});
|
||||
|
||||
m_table->setRowCount(shortcuts.size());
|
||||
m_rows.clear();
|
||||
m_rows.reserve(shortcuts.size());
|
||||
|
||||
for (int row = 0; row < shortcuts.size(); ++row) {
|
||||
const ShortcutManager::ShortcutInfo &info = shortcuts.at(row);
|
||||
|
||||
auto *category_item = new QTableWidgetItem(info.category);
|
||||
category_item->setFlags(category_item->flags() & ~Qt::ItemIsEditable);
|
||||
m_table->setItem(row, 0, category_item);
|
||||
|
||||
auto *description_item = new QTableWidgetItem(info.description);
|
||||
description_item->setFlags(description_item->flags() & ~Qt::ItemIsEditable);
|
||||
m_table->setItem(row, 1, description_item);
|
||||
|
||||
auto *edit = new QKeySequenceEdit(info.current_sequence, m_table);
|
||||
connect(edit, &QKeySequenceEdit::editingFinished, this, &ShortcutsConfigPage::checkConflicts);
|
||||
m_table->setCellWidget(row, 2, edit);
|
||||
|
||||
auto *reset_button = new QToolButton(m_table);
|
||||
reset_button->setIcon(QET::Icons::EditUndo);
|
||||
reset_button->setToolTip(tr("Réinitialiser ce raccourci"));
|
||||
reset_button->setAutoRaise(true);
|
||||
connect(reset_button, &QToolButton::clicked, this, [this, row]() { resetRow(row); });
|
||||
m_table->setCellWidget(row, 3, reset_button);
|
||||
|
||||
m_rows << Row{info.id, info.default_sequence, edit};
|
||||
}
|
||||
|
||||
checkConflicts();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief ShortcutsConfigPage::filterRows
|
||||
Hide every row whose category or action name doesn't contain \a filter_text.
|
||||
*/
|
||||
void ShortcutsConfigPage::filterRows(const QString &filter_text)
|
||||
{
|
||||
const QString needle = filter_text.trimmed();
|
||||
for (int row = 0; row < m_table->rowCount(); ++row) {
|
||||
const bool matches = needle.isEmpty()
|
||||
|| m_table->item(row, 0)->text().contains(needle, Qt::CaseInsensitive)
|
||||
|| m_table->item(row, 1)->text().contains(needle, Qt::CaseInsensitive);
|
||||
m_table->setRowHidden(row, !matches);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief ShortcutsConfigPage::checkConflicts
|
||||
Highlight every row whose currently-edited sequence is shared, non-empty,
|
||||
with another row, and explain the conflict in the shortcut editor's tooltip.
|
||||
*/
|
||||
void ShortcutsConfigPage::checkConflicts()
|
||||
{
|
||||
QHash<QString, QList<int>> sequence_to_rows;
|
||||
for (int row = 0; row < m_rows.size(); ++row) {
|
||||
const QString sequence_text = m_rows.at(row).edit->keySequence().toString();
|
||||
if (!sequence_text.isEmpty()) {
|
||||
sequence_to_rows[sequence_text] << row;
|
||||
}
|
||||
}
|
||||
|
||||
for (int row = 0; row < m_rows.size(); ++row) {
|
||||
const Row ¤t_row = m_rows.at(row);
|
||||
const QString sequence_text = current_row.edit->keySequence().toString();
|
||||
const QList<int> &conflicting_rows = sequence_to_rows.value(sequence_text);
|
||||
const bool conflicted = !sequence_text.isEmpty() && conflicting_rows.size() > 1;
|
||||
|
||||
QTableWidgetItem *description_item = m_table->item(row, 1);
|
||||
if (conflicted) {
|
||||
QStringList other_descriptions;
|
||||
for (int other_row : conflicting_rows) {
|
||||
if (other_row != row) {
|
||||
other_descriptions << m_table->item(other_row, 1)->text();
|
||||
}
|
||||
}
|
||||
description_item->setBackground(QColor(255, 205, 205));
|
||||
current_row.edit->setToolTip(
|
||||
tr("Ce raccourci est aussi utilisé par : %1").arg(other_descriptions.join(QStringLiteral(", "))));
|
||||
} else {
|
||||
description_item->setBackground(Qt::NoBrush);
|
||||
current_row.edit->setToolTip(QString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief ShortcutsConfigPage::resetRow
|
||||
Reset the shortcut editor at \a row_index to its default sequence.
|
||||
*/
|
||||
void ShortcutsConfigPage::resetRow(int row_index)
|
||||
{
|
||||
if (row_index < 0 || row_index >= m_rows.size()) {
|
||||
return;
|
||||
}
|
||||
m_rows.at(row_index).edit->setKeySequence(m_rows.at(row_index).default_sequence);
|
||||
checkConflicts();
|
||||
}
|
||||
|
||||
void ShortcutsConfigPage::resetAllRows()
|
||||
{
|
||||
for (const Row &row : qAsConst(m_rows)) {
|
||||
row.edit->setKeySequence(row.default_sequence);
|
||||
}
|
||||
checkConflicts();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief ShortcutsConfigPage::applyConf
|
||||
Persist every row's shortcut edit through ShortcutManager, which also
|
||||
applies it immediately to every currently live QAction sharing that id.
|
||||
*/
|
||||
void ShortcutsConfigPage::applyConf()
|
||||
{
|
||||
for (const Row &row : qAsConst(m_rows)) {
|
||||
ShortcutManager::instance().setSequence(row.id, row.edit->keySequence());
|
||||
}
|
||||
}
|
||||
|
||||
QString ShortcutsConfigPage::title() const
|
||||
{
|
||||
return tr("Raccourcis", "configuration page title");
|
||||
}
|
||||
|
||||
QIcon ShortcutsConfigPage::icon() const
|
||||
{
|
||||
return QET::Icons::ConfigureToolbars;
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
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 SHORTCUTSCONFIGPAGE_H
|
||||
#define SHORTCUTSCONFIGPAGE_H
|
||||
|
||||
#include "configpage.h"
|
||||
|
||||
#include <QKeySequence>
|
||||
|
||||
class QKeySequenceEdit;
|
||||
class QLineEdit;
|
||||
class QTableWidget;
|
||||
|
||||
/**
|
||||
@brief The ShortcutsConfigPage class
|
||||
Configuration page listing every shortcut registered with ShortcutManager,
|
||||
letting the user rebind, reset and search them. Bindings are only
|
||||
persisted (via ShortcutManager::setSequence()) when applyConf() runs, i.e.
|
||||
when the user validates the surrounding ConfigDialog.
|
||||
*/
|
||||
class ShortcutsConfigPage : public ConfigPage
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ShortcutsConfigPage(QWidget *parent = nullptr);
|
||||
~ShortcutsConfigPage() override;
|
||||
|
||||
void applyConf() override;
|
||||
QString title() const override;
|
||||
QIcon icon() const override;
|
||||
|
||||
private slots:
|
||||
void filterRows(const QString &filter_text);
|
||||
void checkConflicts();
|
||||
void resetAllRows();
|
||||
|
||||
private:
|
||||
struct Row {
|
||||
QString id;
|
||||
QKeySequence default_sequence;
|
||||
QKeySequenceEdit *edit;
|
||||
};
|
||||
|
||||
void populateTable();
|
||||
void resetRow(int row_index);
|
||||
|
||||
QLineEdit *m_filter_edit;
|
||||
QTableWidget *m_table;
|
||||
QList<Row> m_rows;
|
||||
};
|
||||
|
||||
#endif // SHORTCUTSCONFIGPAGE_H
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
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 "adddiagramcommand.h"
|
||||
|
||||
#include "../qetproject.h"
|
||||
#include "../diagram.h"
|
||||
|
||||
/**
|
||||
@brief AddDiagramCommand::AddDiagramCommand
|
||||
@param project : project the diagram is added to
|
||||
@param diagram : the already constructed diagram to add (not yet part of any project's diagram list)
|
||||
@param pos : position to insert the diagram at, -1 to append at the end
|
||||
@param parent
|
||||
*/
|
||||
AddDiagramCommand::AddDiagramCommand(QETProject *project, Diagram *diagram, int pos, QUndoCommand *parent) :
|
||||
QUndoCommand(parent),
|
||||
m_project(project),
|
||||
m_diagram(diagram),
|
||||
m_position(pos)
|
||||
{
|
||||
setText(QObject::tr("Ajouter un folio", "undo command text"));
|
||||
}
|
||||
|
||||
/**
|
||||
@brief AddDiagramCommand::~AddDiagramCommand
|
||||
Destroy the diagram only if it is currently detached from the project
|
||||
(i.e. this add was undone) -- otherwise the project owns it and will
|
||||
destroy it itself.
|
||||
*/
|
||||
AddDiagramCommand::~AddDiagramCommand()
|
||||
{
|
||||
if (m_owns_diagram && m_diagram) {
|
||||
m_diagram->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
void AddDiagramCommand::redo()
|
||||
{
|
||||
if (!m_project || !m_diagram) {
|
||||
return;
|
||||
}
|
||||
m_project->addDiagram(m_diagram, m_position);
|
||||
m_owns_diagram = false;
|
||||
}
|
||||
|
||||
void AddDiagramCommand::undo()
|
||||
{
|
||||
if (!m_project || !m_diagram) {
|
||||
return;
|
||||
}
|
||||
m_project->detachDiagram(m_diagram);
|
||||
m_owns_diagram = true;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
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 ADDDIAGRAMCOMMAND_H
|
||||
#define ADDDIAGRAMCOMMAND_H
|
||||
|
||||
#include <QUndoCommand>
|
||||
#include <QPointer>
|
||||
|
||||
class QETProject;
|
||||
class Diagram;
|
||||
|
||||
/**
|
||||
@brief The AddDiagramCommand class
|
||||
Undo/redo support for adding a new folio (diagram) to a project.
|
||||
Takes ownership of the (already constructed, not yet inserted) diagram:
|
||||
redo() inserts it into the project, undo() detaches it again without
|
||||
destroying it. The diagram is only actually destroyed when this command
|
||||
itself is destroyed while the diagram is detached (i.e. while undone).
|
||||
*/
|
||||
class AddDiagramCommand : public QUndoCommand
|
||||
{
|
||||
public:
|
||||
AddDiagramCommand(QETProject *project, Diagram *diagram, int pos = -1, QUndoCommand *parent = nullptr);
|
||||
~AddDiagramCommand() override;
|
||||
|
||||
void undo() override;
|
||||
void redo() override;
|
||||
|
||||
private:
|
||||
QPointer<QETProject> m_project;
|
||||
Diagram *m_diagram;
|
||||
int m_position;
|
||||
/// true while the diagram is detached from the project (not currently in its diagram list)
|
||||
bool m_owns_diagram = true;
|
||||
};
|
||||
|
||||
#endif // ADDDIAGRAMCOMMAND_H
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
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 "movediagramcommand.h"
|
||||
|
||||
#include "../projectview.h"
|
||||
#include "../qetproject.h"
|
||||
|
||||
/**
|
||||
@brief MoveDiagramCommand::MoveDiagramCommand
|
||||
@param project_view : project view the diagram's tab belongs to
|
||||
@param diagram : the diagram to move
|
||||
@param new_position : target position (may be out of range, e.g. for a
|
||||
x10/x100 move near either end -- ProjectView::setDiagramPosition() clamps
|
||||
it the same way the underlying tab bar always has)
|
||||
@param parent
|
||||
*/
|
||||
MoveDiagramCommand::MoveDiagramCommand(ProjectView *project_view, Diagram *diagram, int new_position, QUndoCommand *parent) :
|
||||
QUndoCommand(parent),
|
||||
m_project_view(project_view),
|
||||
m_diagram(diagram),
|
||||
m_old_position(project_view ? project_view->project()->folioIndex(diagram) : -1),
|
||||
m_new_position(new_position)
|
||||
{
|
||||
setText(QObject::tr("Déplacer un folio", "undo command text"));
|
||||
}
|
||||
|
||||
void MoveDiagramCommand::redo()
|
||||
{
|
||||
if (!m_project_view) {
|
||||
return;
|
||||
}
|
||||
m_project_view->setDiagramPosition(m_diagram, m_new_position);
|
||||
}
|
||||
|
||||
void MoveDiagramCommand::undo()
|
||||
{
|
||||
if (!m_project_view) {
|
||||
return;
|
||||
}
|
||||
m_project_view->setDiagramPosition(m_diagram, m_old_position);
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
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 MOVEDIAGRAMCOMMAND_H
|
||||
#define MOVEDIAGRAMCOMMAND_H
|
||||
|
||||
#include <QUndoCommand>
|
||||
#include <QPointer>
|
||||
|
||||
class ProjectView;
|
||||
class Diagram;
|
||||
|
||||
/**
|
||||
@brief The MoveDiagramCommand class
|
||||
Undo/redo support for reordering a folio (diagram) within a project's
|
||||
tabs. Wraps ProjectView::setDiagramPosition(), which performs the tab
|
||||
move and the matching (synchronous) project diagram-list reorder in one
|
||||
step.
|
||||
*/
|
||||
class MoveDiagramCommand : public QUndoCommand
|
||||
{
|
||||
public:
|
||||
MoveDiagramCommand(ProjectView *project_view, Diagram *diagram, int new_position, QUndoCommand *parent = nullptr);
|
||||
|
||||
void undo() override;
|
||||
void redo() override;
|
||||
|
||||
private:
|
||||
QPointer<ProjectView> m_project_view;
|
||||
Diagram *m_diagram;
|
||||
int m_old_position;
|
||||
int m_new_position;
|
||||
};
|
||||
|
||||
#endif // MOVEDIAGRAMCOMMAND_H
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
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 "removediagramcommand.h"
|
||||
|
||||
#include "../qetproject.h"
|
||||
#include "../diagram.h"
|
||||
|
||||
/**
|
||||
@brief RemoveDiagramCommand::RemoveDiagramCommand
|
||||
@param project : project the diagram is removed from
|
||||
@param diagram : the diagram to remove, currently part of \p project
|
||||
@param parent
|
||||
*/
|
||||
RemoveDiagramCommand::RemoveDiagramCommand(QETProject *project, Diagram *diagram, QUndoCommand *parent) :
|
||||
QUndoCommand(parent),
|
||||
m_project(project),
|
||||
m_diagram(diagram),
|
||||
m_position(project ? project->folioIndex(diagram) : -1)
|
||||
{
|
||||
setText(QObject::tr("Supprimer un folio", "undo command text"));
|
||||
}
|
||||
|
||||
/**
|
||||
@brief RemoveDiagramCommand::~RemoveDiagramCommand
|
||||
Destroy the diagram only if it is currently detached from the project
|
||||
(i.e. the removal is currently in effect) -- otherwise the project owns
|
||||
it and will destroy it itself.
|
||||
*/
|
||||
RemoveDiagramCommand::~RemoveDiagramCommand()
|
||||
{
|
||||
if (m_owns_diagram && m_diagram) {
|
||||
m_diagram->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
void RemoveDiagramCommand::redo()
|
||||
{
|
||||
if (!m_project || !m_diagram) {
|
||||
return;
|
||||
}
|
||||
m_project->detachDiagram(m_diagram);
|
||||
m_owns_diagram = true;
|
||||
}
|
||||
|
||||
void RemoveDiagramCommand::undo()
|
||||
{
|
||||
if (!m_project || !m_diagram) {
|
||||
return;
|
||||
}
|
||||
m_project->addDiagram(m_diagram, m_position);
|
||||
m_owns_diagram = false;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
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 REMOVEDIAGRAMCOMMAND_H
|
||||
#define REMOVEDIAGRAMCOMMAND_H
|
||||
|
||||
#include <QUndoCommand>
|
||||
#include <QPointer>
|
||||
|
||||
class QETProject;
|
||||
class Diagram;
|
||||
|
||||
/**
|
||||
@brief The RemoveDiagramCommand class
|
||||
Undo/redo support for removing a folio (diagram) from a project.
|
||||
redo() detaches the diagram from the project (and, reactively, its
|
||||
ProjectView tab) without destroying it; undo() reinserts it at its
|
||||
original position. The diagram is only actually destroyed when this
|
||||
command itself is destroyed while the diagram is detached (i.e. while
|
||||
the removal is still in effect).
|
||||
*/
|
||||
class RemoveDiagramCommand : public QUndoCommand
|
||||
{
|
||||
public:
|
||||
RemoveDiagramCommand(QETProject *project, Diagram *diagram, QUndoCommand *parent = nullptr);
|
||||
~RemoveDiagramCommand() override;
|
||||
|
||||
void undo() override;
|
||||
void redo() override;
|
||||
|
||||
private:
|
||||
QPointer<QETProject> m_project;
|
||||
Diagram *m_diagram;
|
||||
int m_position;
|
||||
/// true while the diagram is detached from the project (i.e. the removal is in effect)
|
||||
bool m_owns_diagram = false;
|
||||
};
|
||||
|
||||
#endif // REMOVEDIAGRAMCOMMAND_H
|
||||
Reference in New Issue
Block a user