add a F2 shortcut for the widget "Edit the color of the given conductor"

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@1313 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
scorpio810
2011-08-22 11:17:10 +00:00
parent 0b97e6ad99
commit b1c0d8eea1
2 changed files with 53 additions and 0 deletions

View File

@@ -73,6 +73,8 @@ DiagramView::DiagramView(Diagram *diagram, QWidget *parent) : QGraphicsView(pare
connect(&(scene -> undoStack()), SIGNAL(cleanChanged(bool)), this, SLOT(updateWindowTitle()));
connect(this, SIGNAL(aboutToAddElement()), this, SLOT(addDroppedElement()), Qt::QueuedConnection);
QShortcut *edit_conductor_color_shortcut = new QShortcut(QKeySequence(Qt::Key_F2), this);
connect(edit_conductor_color_shortcut, SIGNAL(activated()), this, SLOT(editSelectedConductorColor()));
}
/**
@@ -736,6 +738,20 @@ void DiagramView::editSelectionProperties() {
);
}
/**
Edit the color of the selected conductor; does nothing if multiple conductors are selected
*/
void DiagramView::editSelectedConductorColor() {
// retrieve selected content
DiagramContent selection = scene -> selectedContent();
// we'll focus on the selected conductor (we do not handle multiple conductors edition)
QList<Conductor *> selected_conductors = selection.conductors(DiagramContent::AnyConductor | DiagramContent::SelectedOnly);
if (selected_conductors.count() == 1) {
editConductorColor(selected_conductors.at(0));
}
}
/**
Affiche des informations sur un element
@param element Element a afficher
@@ -857,6 +873,41 @@ void DiagramView::editConductor(Conductor *edited_conductor) {
}
}
/**
Edit the color of the given conductor
@param edited_conductor Conductor we want to change the color
*/
void DiagramView::editConductorColor(Conductor *edited_conductor) {
if (scene -> isReadOnly()) return;
if (!edited_conductor) return;
// store the initial properties of the provided conductor
ConductorProperties initial_properties = edited_conductor -> properties();
// prepare a color dialog showing the initial conductor color
QColorDialog *color_dialog = new QColorDialog(this);
color_dialog -> setWindowTitle(tr("Choisir la nouvelle couleur de ce conducteur"));
#ifdef Q_WS_MAC
color_dialog.setWindowFlags(Qt::Sheet);
#endif
color_dialog -> setCurrentColor(initial_properties.color);
// asks the user what color he wishes to apply
if (color_dialog -> exec() == QDialog::Accepted) {
QColor new_color = color_dialog -> selectedColor();
if (new_color != initial_properties.color) {
// the user chose a different color
ConductorProperties new_properties = initial_properties;
new_properties.color = new_color;
ChangeConductorPropertiesCommand *ccpc = new ChangeConductorPropertiesCommand(edited_conductor);
ccpc -> setOldSettings(initial_properties);
ccpc -> setNewSettings(new_properties);
diagram() -> undoStack().push(ccpc);
}
}
}
/**
Reinitialise le profil des conducteurs selectionnes
*/

View File

@@ -118,9 +118,11 @@ class DiagramView : public QGraphicsView {
void adjustSceneRect();
void updateWindowTitle();
void editSelectionProperties();
void editSelectedConductorColor();
void editElement(Element *);
void editConductor();
void editConductor(Conductor *);
void editConductorColor(Conductor *);
void resetConductors();
private slots: