[qet] [2646] make new element properties dialog (first step for the new dialog) |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 2646
Author: blacksun
Date: 2013-11-29 15:42:03 +0100 (Fri, 29 Nov 2013)
Log Message:
-----------
make new element properties dialog (first step for the new dialog)
Modified Paths:
--------------
trunk/sources/diagram.h
trunk/sources/diagramview.cpp
trunk/sources/diagramview.h
trunk/sources/qetgraphicsitem/element.cpp
trunk/sources/qetgraphicsitem/element.h
Added Paths:
-----------
trunk/sources/ui/elementpropertieswidget.cpp
trunk/sources/ui/elementpropertieswidget.h
Modified: trunk/sources/diagram.h
===================================================================
--- trunk/sources/diagram.h 2013-11-28 21:25:20 UTC (rev 2645)
+++ trunk/sources/diagram.h 2013-11-29 14:42:03 UTC (rev 2646)
@@ -199,6 +199,10 @@
void readOnlyChanged(bool);
void usedTitleBlockTemplateChanged(const QString &);
void diagramTitleChanged(Diagram *, const QString &);
+ /// Signal emitted when users wish to locate an element from the diagram within elements collection
+ void findElementRequired(const ElementsLocation &);
+ /// Signal emitted when users wish to edit an element from the diagram
+ void editElementRequired(const ElementsLocation &);
};
Q_DECLARE_METATYPE(Diagram *)
Modified: trunk/sources/diagramview.cpp
===================================================================
--- trunk/sources/diagramview.cpp 2013-11-28 21:25:20 UTC (rev 2645)
+++ trunk/sources/diagramview.cpp 2013-11-29 14:42:03 UTC (rev 2646)
@@ -39,7 +39,7 @@
#include "qetmessagebox.h"
#include "qtextorientationspinboxwidget.h"
#include <QGraphicsObject>
-
+#include <ui/elementpropertieswidget.h>
#include <QGraphicsPixmapItem>
#include <QGraphicsSceneMouseEvent>
@@ -88,6 +88,8 @@
connect(&(scene -> border_and_titleblock), SIGNAL(displayChanged()), this, SLOT(adjustSceneRect()));
connect(&(scene -> border_and_titleblock), SIGNAL(diagramTitleChanged(const QString &)), this, SLOT(updateWindowTitle()));
connect(&(scene -> undoStack()), SIGNAL(cleanChanged(bool)), this, SLOT(updateWindowTitle()));
+ connect(diagram, SIGNAL(editElementRequired(ElementsLocation)), this, SIGNAL(editElementRequired(ElementsLocation)));
+ connect(diagram, SIGNAL(findElementRequired(ElementsLocation)), this, SIGNAL(findElementRequired(ElementsLocation)));
connect(this, SIGNAL(aboutToAddElement()), this, SLOT(addDroppedElement()), Qt::QueuedConnection);
connect(
@@ -881,42 +883,37 @@
Edite les proprietes des objets selectionnes
*/
void DiagramView::editSelectionProperties() {
- // recupere la selection
+ // get selection
DiagramContent selection = scene -> selectedContent();
- // s'il n'y a rien de selectionne, cette methode ne fait rien
+ // if selection contains nothing return
int selected_items_count = selection.count(DiagramContent::All | DiagramContent::SelectedOnly);
if (!selected_items_count) return;
- // si la selection ne comprend qu'un seul objet, on l'edite via un dialogue approprie
- if (selected_items_count == 1) {
- // cas d'un conducteur selectionne
- QList<Conductor *> selected_conductors = selection.conductors(DiagramContent::AnyConductor | DiagramContent::SelectedOnly);
- if (selected_conductors.count() == 1) {
- editConductor(selected_conductors.at(0));
- return;
- }
-
- // cas d'un element selectionne
- if (selection.elements.count() == 1) {
- editElement(selection.elements.toList().at(0));
- return;
- }
-
- // cas d'un champ de texte selectionne : pour le moment, on traite comme une selection multiple
+ // if selection contains one item and this item can be editable, edit this item with an appropriate dialog
+ if (selected_items_count == 1 && selection.items(DiagramContent::Elements |
+ DiagramContent::AnyConductor |
+ DiagramContent::SelectedOnly).size()) {
+ // edit conductor
+ if (selection.conductors(DiagramContent::AnyConductor | DiagramContent::SelectedOnly).size())
+ editConductor(selection.conductors().first());
+ // edit element
+ else if (selection.elements.size())
+ selection.elements.toList().first() -> editProperty();
}
- // sinon on affiche un simple listing des elements selectionnes
- QET::MessageBox::information(
- this,
- tr("Propri\351t\351s de la s\351lection"),
- QString(
- tr(
- "La s\351lection contient %1.",
- "%1 is a sentence listing the selected objects"
- )
- ).arg(selection.sentence(DiagramContent::All | DiagramContent::SelectedOnly))
- );
+ else {
+ QET::MessageBox::information(
+ this,
+ tr("Propri\351t\351s de la s\351lection"),
+ QString(
+ tr(
+ "La s\351lection contient %1.",
+ "%1 is a sentence listing the selected objects"
+ )
+ ).arg(selection.sentence(DiagramContent::All | DiagramContent::SelectedOnly))
+ );
+ }
}
/**
@@ -934,75 +931,6 @@
}
/**
- Affiche des informations sur un element
- @param element Element a afficher
-*/
-void DiagramView::editElement(Element *element) {
- if (!element) return;
-
- CustomElement *custom_element = qobject_cast<CustomElement *>(element);
- GhostElement *ghost_element = qobject_cast<GhostElement *>(element);
-
- // type de l'element
- QString description_string;
- if (ghost_element) {
- description_string += tr("\311l\351ment manquant");
- } else {
- description_string += tr("\311l\351ment");
- }
- description_string += "\n";
-
- // nom, nombre de bornes, dimensions
- description_string += QString(tr("Nom\240: %1\n")).arg(element -> name());
- int folio_index = scene -> folioIndex();
- if (folio_index != -1) {
- description_string += QString(tr("Folio\240: %1\n")).arg(folio_index + 1);
- }
- description_string += QString(tr("Position\240: %1\n")).arg(scene -> convertPosition(element -> scenePos()).toString());
- description_string += QString(tr("Dimensions\240: %1\327%2\n")).arg(element -> size().width()).arg(element -> size().height());
- description_string += QString(tr("Bornes\240: %1\n")).arg(element -> terminals().count());
- description_string += QString(tr("Connexions internes\240: %1\n")).arg(element -> internalConnections() ? tr("Autoris\351es") : tr("Interdites"));
- description_string += QString(tr("Champs de texte\240: %1\n")).arg(element -> texts().count());
-
- if (custom_element) {
- description_string += QString(tr("Emplacement\240: %1\n")).arg(custom_element -> location().toString());
- }
-
- // titre et boutons du dialogue
- QString description_title = tr("Propri\351t\351s de l'\351l\351ment s\351lectionn\351");
- QPushButton *find_in_panel = new QPushButton(tr("Retrouver dans le panel"));
- QPushButton *edit_element = new QPushButton(tr("\311diter l'\351l\351ment"));
- edit_element->setIcon(QET::Icons::ElementEdit);
-
- // dialogue en lui-meme
- QMessageBox edit_element_dialog(diagramEditor());
-#ifdef Q_WS_MAC
- edit_element_dialog.setWindowFlags(Qt::Sheet);
-#endif
- edit_element_dialog.setIcon(QMessageBox::Information);
- edit_element_dialog.setWindowTitle(description_title);
- edit_element_dialog.setText(description_title);
- edit_element_dialog.setInformativeText(description_string);
- edit_element_dialog.addButton(find_in_panel, QMessageBox::ApplyRole);
- edit_element_dialog.addButton(edit_element, QMessageBox::ApplyRole);
- edit_element_dialog.addButton(QMessageBox::Ok);
- edit_element_dialog.setDefaultButton(QMessageBox::Ok);
- edit_element_dialog.setEscapeButton(QMessageBox::Ok);
- edit_element_dialog.exec();
-
- // Permet de trouver l'element dans la collection
- if (edit_element_dialog.clickedButton() == find_in_panel) {
- emit(findElementRequired(custom_element -> location()));
- }
-
- // Trouve l'element dans la collection et l'edite
- if (edit_element_dialog.clickedButton() == edit_element) {
- emit(findElementRequired(custom_element -> location()));
- emit(editElementRequired(custom_element -> location()));
- }
-}
-
-/**
Affiche un dialogue permettant d'editer le conducteur selectionne.
Ne fait rien s'il y a 0 ou plusieurs conducteurs selectionnes.
*/
@@ -1036,8 +964,8 @@
QVBoxLayout *dialog_layout = new QVBoxLayout(&conductor_dialog);
dialog_layout -> addWidget(cpw);
QCheckBox *cb_apply_all = new QCheckBox(tr("Appliquer les propri\351t\351s \340 l'ensemble des conducteurs de ce potentiel"), &conductor_dialog);
- dialog_layout -> addWidget(cb_apply_all);
dialog_layout -> addStretch();
+ dialog_layout -> addWidget(cb_apply_all);
QDialogButtonBox *dbb = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
dbb -> setParent(&conductor_dialog);
dialog_layout -> addWidget(dbb);
@@ -1427,8 +1355,6 @@
if (QGraphicsItem *qgi = itemAt(e -> pos())) {
if (Conductor *c = qgraphicsitem_cast<Conductor *>(qgi)) {
editConductor(c);
- } else if (Element *element = qgraphicsitem_cast<Element *>(qgi)) {
- editElement(element);
} else {
QGraphicsView::mouseDoubleClickEvent(e);
}
Modified: trunk/sources/diagramview.h
===================================================================
--- trunk/sources/diagramview.h 2013-11-28 21:25:20 UTC (rev 2645)
+++ trunk/sources/diagramview.h 2013-11-29 14:42:03 UTC (rev 2646)
@@ -154,7 +154,6 @@
void updateWindowTitle();
void editSelectionProperties();
void editSelectedConductorColor();
- void editElement(Element *);
void editConductor();
void editConductor(Conductor *);
void editConductorColor(Conductor *);
Modified: trunk/sources/qetgraphicsitem/element.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/element.cpp 2013-11-28 21:25:20 UTC (rev 2645)
+++ trunk/sources/qetgraphicsitem/element.cpp 2013-11-29 14:42:03 UTC (rev 2646)
@@ -22,6 +22,7 @@
#include "elementtextitem.h"
#include "diagramcommands.h"
#include <QtDebug>
+#include <ui/elementpropertieswidget.h>
/**
Constructeur pour un element sans scene ni parent
@@ -40,6 +41,16 @@
Element::~Element() {
}
+void Element::editProperty() {
+ if (diagram())
+ if(!diagram()->isReadOnly()){
+ elementpropertieswidget epw (this, diagram()->views().first());
+ connect(&epw, SIGNAL(editElementRequired(ElementsLocation)), diagram(), SIGNAL(editElementRequired(ElementsLocation)));
+ connect(&epw, SIGNAL(findElementRequired(ElementsLocation)), diagram(), SIGNAL(findElementRequired(ElementsLocation)));
+ epw.exec();
+ }
+}
+
/**
@return true si l'element est mis en evidence
*/
Modified: trunk/sources/qetgraphicsitem/element.h
===================================================================
--- trunk/sources/qetgraphicsitem/element.h 2013-11-28 21:25:20 UTC (rev 2645)
+++ trunk/sources/qetgraphicsitem/element.h 2013-11-29 14:42:03 UTC (rev 2646)
@@ -99,6 +99,7 @@
bool internalConnections();
void setInternalConnections(bool);
virtual void rotateBy(const qreal &);
+ virtual void editProperty();
// methods related to XML import/export
static bool valideXml(QDomElement &);
Added: trunk/sources/ui/elementpropertieswidget.cpp
===================================================================
--- trunk/sources/ui/elementpropertieswidget.cpp (rev 0)
+++ trunk/sources/ui/elementpropertieswidget.cpp 2013-11-29 14:42:03 UTC (rev 2646)
@@ -0,0 +1,134 @@
+#include "elementpropertieswidget.h"
+#include <qetgraphicsitem/ghostelement.h>
+#include <qeticons.h>
+#include <diagramposition.h>
+
+/**
+ * @brief elementpropertieswidget::elementpropertieswidget
+ * default constructor
+ * @param elmt
+ * @param parent
+ */
+elementpropertieswidget::elementpropertieswidget(Element *elmt, QWidget *parent) :
+ QDialog(parent),
+ element_ (elmt),
+ diagram_ (elmt->diagram())
+{
+ setWindowTitle(tr("Propri\351t\351s de l'\351l\351ment"));
+
+ tab_ = new QTabWidget(this);
+ tab_ -> addTab(generalWidget(), tr("G\351n\351ral"));
+
+ dbb = new QDialogButtonBox(QDialogButtonBox::Apply | QDialogButtonBox::Cancel | QDialogButtonBox::Reset,
+ Qt::Horizontal, this);
+ connect(dbb, SIGNAL(clicked(QAbstractButton*)), this, SLOT(standardButtonClicked(QAbstractButton*)));
+
+ QVBoxLayout *main_layout = new QVBoxLayout(this);
+ main_layout -> addWidget(tab_);
+ main_layout -> addWidget(dbb);
+ setLayout(main_layout);
+}
+
+/**
+ * @brief elementpropertieswidget::generalWidget
+ * build the widget for the tab général
+ * @return
+ */
+QWidget* elementpropertieswidget::generalWidget() {
+ CustomElement *custom_element = qobject_cast<CustomElement *>(element_);
+ GhostElement *ghost_element = qobject_cast<GhostElement *>(element_);
+
+ // type de l'element
+ QString description_string;
+ if (ghost_element) {
+ description_string += tr("\311l\351ment manquant");
+ } else {
+ description_string += tr("\311l\351ment");
+ }
+ description_string += "\n";
+
+ // some element characteristic
+ description_string += QString(tr("Nom\240: %1\n")).arg(element_ -> name());
+ int folio_index = diagram_ -> folioIndex();
+ if (folio_index != -1) {
+ description_string += QString(tr("Folio\240: %1\n")).arg(folio_index + 1);
+ }
+ description_string += QString(tr("Position\240: %1\n")).arg(diagram_ -> convertPosition(element_ -> scenePos()).toString());
+ description_string += QString(tr("Dimensions\240: %1\327%2\n")).arg(element_ -> size().width()).arg(element_ -> size().height());
+ description_string += QString(tr("Bornes\240: %1\n")).arg(element_ -> terminals().count());
+ description_string += QString(tr("Champs de texte\240: %1\n")).arg(element_ -> texts().count());
+
+ if (custom_element) {
+ description_string += QString(tr("Emplacement\240: %1\n")).arg(custom_element -> location().toString());
+ }
+
+ // widget himself
+ QWidget *general_widget = new QWidget (tab_);
+ QVBoxLayout *vlayout_ = new QVBoxLayout (general_widget);
+ general_widget -> setLayout(vlayout_);
+
+ //widget for the text
+ vlayout_->addWidget(new QLabel (description_string, general_widget));
+
+ //widget for the pixmap
+ QLabel *pix = new QLabel(general_widget);
+ pix->setPixmap(element_->pixmap());
+ vlayout_->addWidget(pix, 0, Qt::AlignHCenter);
+ vlayout_ -> addStretch();
+
+ //button widget
+ find_in_panel = new QPushButton(QET::Icons::ZoomDraw, tr("Retrouver dans le panel"), general_widget);
+ connect(find_in_panel, SIGNAL(clicked()), this, SLOT(findInPanel()));
+ edit_element = new QPushButton(QET::Icons::ElementEdit, tr("\311diter l'\351l\351ment"), general_widget);
+ connect(edit_element, SIGNAL(clicked()), this, SLOT(editElement()));
+ QHBoxLayout *hlayout_ = new QHBoxLayout;
+ hlayout_->addWidget(find_in_panel);
+ hlayout_->addWidget(edit_element);
+
+ vlayout_->addLayout(hlayout_);
+ return general_widget;
+}
+
+/**
+ * @brief elementpropertieswidget::standardButtonClicked
+ * apply action when click in the dialog standard button box
+ * @param button
+ * the cliked button
+ */
+void elementpropertieswidget::standardButtonClicked(QAbstractButton *button) {
+ int answer = dbb -> buttonRole(button);
+
+ switch (answer) {
+ case QDialogButtonBox::ResetRole:
+ break;
+ case QDialogButtonBox::ApplyRole:
+ this->accept();
+ case QDialogButtonBox::RejectRole:
+ this->reject();
+ default:
+ this->reject();
+ }
+}
+
+/**
+ * @brief elementpropertieswidget::findInPanel
+ * Slot
+ */
+void elementpropertieswidget::findInPanel() {
+ if (CustomElement *custom_element = qobject_cast<CustomElement *>(element_)) {
+ emit findElementRequired(custom_element->location());
+ }
+ reject();
+}
+
+/**
+ * @brief elementpropertieswidget::editElement
+ * Slot
+ */
+void elementpropertieswidget::editElement() {
+ if (CustomElement *custom_element = qobject_cast<CustomElement *>(element_)) {
+ emit findElementRequired(custom_element->location());
+ emit editElementRequired(custom_element->location());
+ }
+ reject();
+}
Added: trunk/sources/ui/elementpropertieswidget.h
===================================================================
--- trunk/sources/ui/elementpropertieswidget.h (rev 0)
+++ trunk/sources/ui/elementpropertieswidget.h 2013-11-29 14:42:03 UTC (rev 2646)
@@ -0,0 +1,37 @@
+#ifndef ELEMENTPROPERTIESWIDGET_H
+#define ELEMENTPROPERTIESWIDGET_H
+
+#include <QtGui>
+#include <qetgraphicsitem/element.h>
+#include <diagram.h>
+
+class elementpropertieswidget : public QDialog
+{
+ Q_OBJECT
+ public:
+ explicit elementpropertieswidget(Element *elmt, QWidget *parent = 0);
+
+ private:
+ QWidget* generalWidget();
+
+ signals:
+ /// Signal emitted when users wish to locate an element from the diagram within elements collection
+ void findElementRequired(const ElementsLocation &);
+ /// Signal emitted when users wish to edit an element from the diagram
+ void editElementRequired(const ElementsLocation &);
+
+ public slots:
+ void standardButtonClicked (QAbstractButton *);
+ void findInPanel ();
+ void editElement ();
+
+ private:
+ QDialogButtonBox *dbb;
+ Element *element_;
+ Diagram *diagram_;
+ QTabWidget *tab_;
+ QPushButton *find_in_panel, *edit_element;
+
+};
+
+#endif // ELEMENTPROPERTIESWIDGET_H