[qet] [2508] add edit image to context menu |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 2508
Author: blacksun
Date: 2013-09-10 16:44:25 +0200 (Tue, 10 Sep 2013)
Log Message:
-----------
add edit image to context menu
Modified Paths:
--------------
trunk/sources/diagramimageitem.cpp
trunk/sources/diagramview.cpp
trunk/sources/diagramview.h
trunk/sources/qetdiagrameditor.cpp
trunk/sources/qetdiagrameditor.h
Modified: trunk/sources/diagramimageitem.cpp
===================================================================
--- trunk/sources/diagramimageitem.cpp 2013-09-10 12:33:24 UTC (rev 2507)
+++ trunk/sources/diagramimageitem.cpp 2013-09-10 14:44:25 UTC (rev 2508)
@@ -111,55 +111,7 @@
*/
void DiagramImageItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) {
Q_UNUSED (event);
- if (diagram() -> isReadOnly()) return;
- //the range for scale image and divisor factor
- int min_range = 1;
- int max_range = 200;
- int factor_range = 100;
-
- //the dialog
- QDialog property_dialog;
- property_dialog.setWindowTitle(tr("\311diter les propri\351t\351s d'une image", "window title"));
- //the main layout
- QVBoxLayout *dialog_layout = new QVBoxLayout(&property_dialog);
-
- //GroupBox for resizer image
- QGroupBox *resize_groupe = new QGroupBox(tr("Dimension de l'image", "image size"));
- dialog_layout -> addWidget(resize_groupe);
- QHBoxLayout *resize_layout = new QHBoxLayout(resize_groupe);
-
- //slider
- QSlider *slider = new QSlider(Qt::Horizontal, &property_dialog);
- slider->setRange(min_range, max_range);
- qreal scale_= scale();
- slider -> setValue(scale_*factor_range);
- //spinbox
- QSpinBox *spin_box = new QSpinBox(&property_dialog);
- spin_box -> setRange(min_range, max_range);
- spin_box -> setValue(scale_*factor_range);
- spin_box -> setSuffix(" %");
- //synchro slider with spinbox
- connect(slider, SIGNAL(valueChanged(int)), spin_box, SLOT(setValue(int)));
- connect(slider, SIGNAL(valueChanged(int)), this, SLOT(PreviewScale(int)));
- connect(spin_box, SIGNAL(valueChanged(int)), slider, SLOT(setValue(int)));
- //add slider and spinbox to layout
- resize_layout -> addWidget(slider);
- resize_layout -> addWidget(spin_box);
-
- //dialog button, box
- QDialogButtonBox *dbb = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
- dialog_layout -> addWidget(dbb);
- connect(dbb, SIGNAL(accepted()), &property_dialog, SLOT(accept()));
- connect(dbb, SIGNAL(rejected()), &property_dialog, SLOT(reject()));
- //dialog is accepted...
- if (property_dialog.exec() == QDialog::Accepted) {
- qreal new_scale = slider -> value();
- new_scale /= factor_range;
- if (scale_ != new_scale) diagram()->undoStack().push(new ImageResizerCommand(this, scale_, new_scale));
- }
- //...or not
- else setScale(scale_);
- return;
+ edit();
}
/**
@@ -266,7 +218,55 @@
* @brief Edit the image with ....
*/
void DiagramImageItem::edit() {
- // waiting
+ if (diagram() -> isReadOnly()) return;
+ //the range for scale image and divisor factor
+ int min_range = 1;
+ int max_range = 200;
+ int factor_range = 100;
+
+ //the dialog
+ QDialog property_dialog;
+ property_dialog.setWindowTitle(tr("\311diter les propri\351t\351s d'une image", "window title"));
+ //the main layout
+ QVBoxLayout *dialog_layout = new QVBoxLayout(&property_dialog);
+
+ //GroupBox for resizer image
+ QGroupBox *resize_groupe = new QGroupBox(tr("Dimension de l'image", "image size"));
+ dialog_layout -> addWidget(resize_groupe);
+ QHBoxLayout *resize_layout = new QHBoxLayout(resize_groupe);
+
+ //slider
+ QSlider *slider = new QSlider(Qt::Horizontal, &property_dialog);
+ slider->setRange(min_range, max_range);
+ qreal scale_= scale();
+ slider -> setValue(scale_*factor_range);
+ //spinbox
+ QSpinBox *spin_box = new QSpinBox(&property_dialog);
+ spin_box -> setRange(min_range, max_range);
+ spin_box -> setValue(scale_*factor_range);
+ spin_box -> setSuffix(" %");
+ //synchro slider with spinbox
+ connect(slider, SIGNAL(valueChanged(int)), spin_box, SLOT(setValue(int)));
+ connect(slider, SIGNAL(valueChanged(int)), this, SLOT(PreviewScale(int)));
+ connect(spin_box, SIGNAL(valueChanged(int)), slider, SLOT(setValue(int)));
+ //add slider and spinbox to layout
+ resize_layout -> addWidget(slider);
+ resize_layout -> addWidget(spin_box);
+
+ //dialog button, box
+ QDialogButtonBox *dbb = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
+ dialog_layout -> addWidget(dbb);
+ connect(dbb, SIGNAL(accepted()), &property_dialog, SLOT(accept()));
+ connect(dbb, SIGNAL(rejected()), &property_dialog, SLOT(reject()));
+ //dialog is accepted...
+ if (property_dialog.exec() == QDialog::Accepted) {
+ qreal new_scale = slider -> value();
+ new_scale /= factor_range;
+ if (scale_ != new_scale) diagram()->undoStack().push(new ImageResizerCommand(this, scale_, new_scale));
+ }
+ //...or not
+ else setScale(scale_);
+ return;
}
void DiagramImageItem::setPixmap(const QPixmap &pixmap) {
Modified: trunk/sources/diagramview.cpp
===================================================================
--- trunk/sources/diagramview.cpp 2013-09-10 12:33:24 UTC (rev 2507)
+++ trunk/sources/diagramview.cpp 2013-09-10 14:44:25 UTC (rev 2508)
@@ -1261,7 +1261,22 @@
}
current_behavior = addingImage;
}
+
/**
+ * @brief DiagramView::editImage
+ * open edit image dialog if only one image is selected
+ */
+void DiagramView::editImage() {
+ if (scene -> isReadOnly()) return;
+ QList <QGraphicsItem *> images = diagram() -> selectedContent().items(DiagramContent::Images);
+ if (images.count() != 1) return;
+ DiagramImageItem *image;
+ if ((image = qgraphicsitem_cast<DiagramImageItem *> (images.first()))) {
+ image -> edit();
+ }
+}
+
+/**
* @brief DiagramView::addDiagramImageAtPos
* @param pos
* @return
@@ -1338,9 +1353,8 @@
context_menu -> addAction(qde -> delete_selection);
context_menu -> addAction(qde -> rotate_selection);
context_menu -> addAction(qde -> rotate_texts);
- context_menu -> addAction(qde -> add_edittext);
+ context_menu -> addAction(qde -> edit_selection);
context_menu -> addAction(qde -> find_element);
- context_menu -> addAction(qde -> edit_element);
context_menu -> addAction(qde -> selection_prop);
}
Modified: trunk/sources/diagramview.h
===================================================================
--- trunk/sources/diagramview.h 2013-09-10 12:33:24 UTC (rev 2507)
+++ trunk/sources/diagramview.h 2013-09-10 14:44:25 UTC (rev 2508)
@@ -75,6 +75,7 @@
void addText();
void editText();
void addImage();
+ void editImage();
IndependentTextItem *addDiagramTextAtPos(const QPointF &);
DiagramImageItem *addDiagramImageAtPos(const QPointF &);
Modified: trunk/sources/qetdiagrameditor.cpp
===================================================================
--- trunk/sources/qetdiagrameditor.cpp 2013-09-10 12:33:24 UTC (rev 2507)
+++ trunk/sources/qetdiagrameditor.cpp 2013-09-10 14:44:25 UTC (rev 2508)
@@ -209,14 +209,13 @@
rotate_selection = new QAction(QET::Icons::ObjectRotateRight, tr("Pivoter"), this);
rotate_texts = new QAction(QET::Icons::ObjectRotateRight, tr("Orienter les textes"), this);
find_element = new QAction( tr("Retrouver dans le panel"), this);
- edit_element = new QAction(QET::Icons::ElementEdit, tr("\311diter l'\351l\351ment"), this);
+ edit_selection = new QAction(QET::Icons::ElementEdit, tr("\311diter l'item s\351lectionn\351"), this);
selection_prop = new QAction(QET::Icons::DialogInformation, tr("Propri\351t\351s de la s\351lection"), this);
conductor_reset = new QAction(QET::Icons::ConductorSettings, tr("R\351initialiser les conducteurs"), this);
infos_diagram = new QAction(QET::Icons::DialogInformation, tr("Propri\351t\351s du sch\351ma"), this);
add_text = new QAction(QET::Icons::PartTextField, tr("Ajouter un champ de texte"), this);
- add_edittext = new QAction(QET::Icons::EditText, tr("\311diter le champ de texte"), this);
add_column = new QAction(QET::Icons::EditTableInsertColumnRight, tr("Ajouter une colonne"), this);
- add_image = new QAction(QET::Icons::adding_image, tr("Ajouter une image"), this);
+ add_image = new QAction(QET::Icons::adding_image, tr("Ajouter une image"), this);
remove_column = new QAction(QET::Icons::EditTableDeleteColumn, tr("Enlever une colonne"), this);
add_row = new QAction(QET::Icons::EditTableInsertRowUnder, tr("Ajouter une ligne"), this);
remove_row = new QAction(QET::Icons::EditTableDeleteRow, tr("Enlever une ligne"), this);
@@ -274,6 +273,7 @@
selection_prop -> setShortcut(QKeySequence(tr("Ctrl+J")));
conductor_reset -> setShortcut(QKeySequence(tr("Ctrl+K")));
infos_diagram -> setShortcut(QKeySequence(tr("Ctrl+L")));
+ edit_selection -> setShortcut(QKeySequence(tr("Ctrl+E")));
prj_add_diagram -> setShortcut(QKeySequence(tr("Ctrl+T")));
@@ -310,7 +310,6 @@
rotate_selection -> setStatusTip(tr("Pivote les \351l\351ments et textes s\351lectionn\351s", "status bar tip"));
rotate_texts -> setStatusTip(tr("Pivote les textes s\351lectionn\351s \340 un angle pr\351cis", "status bar tip"));
find_element -> setStatusTip(tr("Retrouve l'\351l\351ment s\351lectionn\351 dans le panel", "status bar tip"));
- edit_element -> setStatusTip(tr("Retrouve l'\351l\351ment s\351lectionn\351 dans le panel avant de l'\351diter", "status bar tip"));
selection_prop -> setStatusTip(tr("\311dite les propri\351t\351s des objets s\351lectionn\351", "status bar tip"));
conductor_reset -> setStatusTip(tr("Recalcule les chemins des conducteurs sans tenir compte des modifications", "status bar tip"));
infos_diagram -> setStatusTip(tr("\311dite les informations affich\351es par le cartouche", "status bar tip"));
@@ -338,7 +337,7 @@
// traitements speciaux
add_text -> setCheckable(true);
- add_image -> setCheckable(true);
+ add_image -> setCheckable(true);
windowed_view_mode -> setCheckable(true);
tabbed_view_mode -> setCheckable(true);
mode_selection -> setCheckable(true);
@@ -364,8 +363,7 @@
connect(rotate_selection, SIGNAL(triggered()), this, SLOT(slot_rotate()) );
connect(rotate_texts, SIGNAL(triggered()), this, SLOT(slot_rotateTexts()) );
connect(find_element, SIGNAL(triggered()), this, SLOT(findSelectedElementInPanel()));
- connect(edit_element, SIGNAL(triggered()), this, SLOT(findSelectedElementInPanel()));
- connect(edit_element, SIGNAL(triggered()), this, SLOT(editSelectedElementInEditor()));
+ connect(edit_selection, SIGNAL(triggered()), this, SLOT(slot_editSelection()) );
connect(windowed_view_mode, SIGNAL(triggered()), this, SLOT(setWindowedMode()) );
connect(tabbed_view_mode, SIGNAL(triggered()), this, SLOT(setTabbedMode()) );
connect(mode_selection, SIGNAL(triggered()), this, SLOT(slot_setSelectionMode()) );
@@ -400,7 +398,6 @@
connect(conductor_reset, SIGNAL(triggered()), this, SLOT(slot_resetConductors()) );
connect(infos_diagram, SIGNAL(triggered()), this, SLOT(editCurrentDiagramProperties()));
connect(add_text, SIGNAL(triggered()), this, SLOT(slot_addText()) );
- connect(add_edittext, SIGNAL(triggered()), this, SLOT(slot_editText()) );
connect(add_image, SIGNAL(triggered()), this, SLOT(slot_addImage()) );
connect(add_column, SIGNAL(triggered()), this, SLOT(slot_addColumn()) );
connect(remove_column, SIGNAL(triggered()), this, SLOT(slot_removeColumn()) );
@@ -476,7 +473,7 @@
menu_edition -> addAction(delete_selection);
menu_edition -> addAction(rotate_selection);
menu_edition -> addAction(rotate_texts);
- menu_edition -> addAction(add_edittext);
+ menu_edition -> addAction(edit_selection);
menu_edition -> addAction(selection_prop);
menu_edition -> addSeparator();
menu_edition -> addAction(conductor_reset);
@@ -1193,7 +1190,6 @@
// number of selected elements
int selected_elements_count = dv ? dv -> diagram() -> selectedContent().count(DiagramContent::Elements) : 0;
find_element -> setEnabled(selected_elements_count == 1);
- edit_element -> setEnabled(selected_elements_count == 1);
// actions ayant aussi besoin d'items (elements, conducteurs, textes, ...) selectionnes
bool copiable_items = dv ? (dv -> hasCopiableItems()) : false;
@@ -1209,7 +1205,38 @@
int selected_texts = dv ? (dv -> diagram() -> selectedTexts().count()) : 0;
int selected_conductor_texts = dv ? (dv -> diagram() -> selectedConductorTexts().count()) : 0;
rotate_texts -> setEnabled(editable_diagram && selected_texts);
- add_edittext -> setEnabled(editable_diagram && selected_texts == 1 && !selected_conductor_texts);
+
+ // actions need only one editable item
+ int selected_image = dv ? dv -> diagram() -> selectedContent().count(DiagramContent::Images) : 0;
+ int selected_editable = selected_elements_count + (selected_texts - selected_conductor_texts) + selected_image;
+
+ if (selected_editable == 1) {
+ edit_selection -> setEnabled(true);
+ //edit element
+ if (selected_elements_count == 1) {
+ edit_selection -> setText(tr("\311diter l'\351lement", "edit element"));
+ edit_selection -> setIcon(QET::Icons::ElementEdit);
+ edit_selection -> setIconVisibleInMenu(true);
+ }
+ //edit text field
+ else if (selected_texts == 1) {
+ edit_selection -> setText(tr("\311diter le champ de texte", "edit text field"));
+ edit_selection -> setIcon(QET::Icons::EditText);
+ edit_selection -> setIconVisibleInMenu(true);
+ }
+ //edit image
+ else if (selected_image) {
+ edit_selection -> setText(tr("\311diter l'image", "edit image"));
+ edit_selection ->setIconVisibleInMenu(false);
+ }
+ }
+ //not an editable item
+ else {
+ edit_selection -> setText(tr("\311diter l'objet s\351lectionn\351", "edit selected item"));
+ edit_selection -> setIcon(QET::Icons::ElementEdit);
+ edit_selection -> setIconVisibleInMenu(true);
+ edit_selection -> setEnabled(false);
+ }
}
@@ -1501,12 +1528,22 @@
dv -> addImage();
}
}
+
/**
- to Edit en text through the html editor
-*/
-void QETDiagramEditor::slot_editText() {
+ * @brief QETDiagramEditor::slot_editSelection
+ * edit the selected item if he can be edited and if only one item is selected
+ */
+void QETDiagramEditor::slot_editSelection() {
if (DiagramView *dv = currentDiagram()) {
- dv -> editText();
+ DiagramContent dc = dv -> diagram() -> selectedContent();
+ if (dc.count() != 1) return;
+
+ if (dc.count(DiagramContent::Elements)) {
+ findSelectedElementInPanel();
+ editSelectedElementInEditor();
+ }
+ else if (dc.count(DiagramContent::TextFields)) dv -> editText();
+ else if (dc.count(DiagramContent::Images)) dv -> editImage();
}
}
@@ -1767,7 +1804,6 @@
connect(dv, SIGNAL(selectionChanged()), this, SLOT(slot_updateComplexActions()));
connect(dv, SIGNAL(modeChanged()), this, SLOT(slot_updateModeActions()));
connect(dv, SIGNAL(textAdded(bool)), add_text, SLOT(setChecked(bool)));
- connect(dv, SIGNAL(textAdded(bool)), add_edittext, SLOT(setChecked(bool)));
connect(dv, SIGNAL(ImageAdded(bool)), add_image, SLOT(setChecked(bool)));
connect(dv, SIGNAL(ImageAddedCanceled(bool)), add_image, SLOT(setChecked(bool)));
}
Modified: trunk/sources/qetdiagrameditor.h
===================================================================
--- trunk/sources/qetdiagrameditor.h 2013-09-10 12:33:24 UTC (rev 2507)
+++ trunk/sources/qetdiagrameditor.h 2013-09-10 14:44:25 UTC (rev 2508)
@@ -123,8 +123,8 @@
void slot_editConductor();
void slot_resetConductors();
void slot_addText();
- void slot_editText();
void slot_addImage();
+ void slot_editSelection();
void setWindowedMode();
void setTabbedMode();
void readSettings();
@@ -190,13 +190,11 @@
QAction *rotate_selection; ///< Rotate selected elements and text items by 90 degrees
QAction *rotate_texts; ///< Direct selected text items to a specific angle
QAction *find_element; ///< Find the selected element in the panel
- QAction *edit_element; ///< Edit the selected element
QAction *selection_prop; ///< Show a dialog describing the selection
QAction *conductor_reset; ///< Reset paths of selected conductors
QAction *conductor_default; ///< Show a dialog to edit default conductor properties
QAction *infos_diagram; ///< Show a dialog to edit diagram properties
QAction *add_text; ///< Tool to add an independent text item on diagrams
- QAction *add_edittext; ///< Tool to add an independent text item on diagrams
QAction *add_column; ///< Increase diagram width by adding an extra column
QAction *remove_column; ///< Decrease diagram width by removing the last column
QAction *add_row; ///< Increase diagram height by adding an extra row
@@ -216,7 +214,9 @@
QAction *cascade_window; ///< Show MDI subwindows as cascade
QAction *prev_window; ///< Switch to the previous document
QAction *next_window; ///< Switch to the next document
- QAction *add_image; ///< Tool to add an independent image item on diagrams
+ QAction *add_image; ///< Tool to add an independent image item on diagrams
+ QAction *edit_selection; ///< To edit selected item
+
private:
QMdiArea workspace;
QSignalMapper windowMapper;