diff --git a/sources/elementspanel.cpp b/sources/elementspanel.cpp index d3c948c56..2ce21f83e 100644 --- a/sources/elementspanel.cpp +++ b/sources/elementspanel.cpp @@ -67,7 +67,10 @@ ElementsPanel::ElementsPanel(QWidget *parent) : connect(this, &ElementsPanel::itemDoubleClicked, this, &ElementsPanel::slot_doubleClick); connect(this, &GenericPanel::firstActivated, [this]() {QTimer::singleShot(250, this, SLOT(reload()));}); connect(this, &ElementsPanel::panelContentChanged, this, &ElementsPanel::panelContentChange); - + + // manage signal itemClicked + connect(this, &ElementsPanel::itemClicked, this, &ElementsPanel::slot_clicked); + //Emit a signal instead au manage is own context menu setContextMenuPolicy(Qt::CustomContextMenu); } @@ -269,21 +272,28 @@ void ElementsPanel::reload() } /** - Gere le double-clic sur un element. - Si un double-clic sur un projet est effectue, le signal requestForProject - est emis. - Si un double-clic sur un schema est effectue, le signal requestForDiagram - est emis. + @brief ElementsPanel::slot_clicked + handle click on qtwi + @param qtwi item that was clickerd on +*/ +void ElementsPanel::slot_clicked(QTreeWidgetItem *clickedItem, int) { + + requestForItem(clickedItem); +} + +/** + @brief ElementsPanel::slot_doubleClick + handle double click on qtwi @param qtwi */ void ElementsPanel::slot_doubleClick(QTreeWidgetItem *qtwi, int) { int qtwi_type = qtwi -> type(); if (qtwi_type == QET::Project) { - QETProject *project = valueForItem(qtwi); - emit(requestForProject(project)); + // open project properties + emit(requestForProjectPropertiesEdition()); } else if (qtwi_type == QET::Diagram) { - Diagram *diagram = valueForItem(qtwi); - diagram->showMe(); + // open diagram properties + emit(requestForDiagramPropertiesEdition()); } else if (qtwi_type == QET::TitleBlockTemplate) { TitleBlockTemplateLocation tbt = valueForItem(qtwi); emit(requestForTitleBlockTemplate(tbt)); @@ -455,3 +465,64 @@ void ElementsPanel::ensureHierarchyIsVisible(const QList &ite if (parent_qtwi -> isHidden()) parent_qtwi -> setHidden(false); } } + +/** + * @brief ElementsPanel::syncTabBars + * set the project- or diagram Tab corresponding to + * the selection in the treeView + */ +void ElementsPanel::requestForItem(QTreeWidgetItem *clickedItem) +{ + // activate diagram + if(clickedItem->type() == QET::Diagram){ + Diagram *diagram = valueForItem(clickedItem); + // if we click on diagramItem in annother project we need the other project + emit(requestForProject(projectForItem(clickedItem->parent()))); + // required for keyPressEvent + // after emit the focus is on the diagram editor, we put it back to elementsPanel + this->setFocus(); + // activate diagram + diagram->showMe(); + } + // activate project + else if(clickedItem->type() == QET::Project) { + QETProject *project = projectForItem(clickedItem); + emit(requestForProject(project)); + this->setFocus(); + } +} + +/** + * @brief ElementsPanel::keyPressEvent + * @param event + */ +void ElementsPanel::keyPressEvent(QKeyEvent *event) +{ + switch (event->key()) + { + case Qt::Key_Up:{ + // check if there is another item abbove + if(!itemAbove(currentItem())) + break; + + setCurrentItem(itemAbove(currentItem())); + if (currentItem()->type()==QET::Diagram || currentItem()->type()==QET::Project){ + requestForItem(currentItem()); + } + break; + } + case Qt::Key_Down:{ + // check if there is another item below + if(!itemBelow(currentItem())) + break; + + setCurrentItem(itemBelow(currentItem())); + if (currentItem()->type()==QET::Diagram || currentItem()->type()==QET::Project){ + requestForItem(currentItem()); + } + break; + } + default: + QTreeView::keyPressEvent(event); + } +} diff --git a/sources/elementspanel.h b/sources/elementspanel.h index a82daa160..7aa1143e5 100644 --- a/sources/elementspanel.h +++ b/sources/elementspanel.h @@ -53,8 +53,13 @@ class ElementsPanel : public GenericPanel { signals: void requestForProject(QETProject *); void requestForTitleBlockTemplate(const TitleBlockTemplateLocation &); - + // Signal to open the project properties + void requestForProjectPropertiesEdition(); + // Signal to open the diagram properties + void requestForDiagramPropertiesEdition(); + public slots: + void slot_clicked(QTreeWidgetItem *, int); void slot_doubleClick(QTreeWidgetItem *, int); void reload(); void filter(const QString &, QET::Filtering = QET::RegularFilter); @@ -63,7 +68,9 @@ class ElementsPanel : public GenericPanel { void buildFilterList(); void applyCurrentFilter(const QList &); void ensureHierarchyIsVisible(const QList &); - + void requestForItem(QTreeWidgetItem *); + void keyPressEvent(QKeyEvent *event)override; + protected: void startDrag(Qt::DropActions) override; void startTitleBlockTemplateDrag(const TitleBlockTemplateLocation &); diff --git a/sources/elementspanelwidget.cpp b/sources/elementspanelwidget.cpp index 43b4b6958..464fb89d0 100644 --- a/sources/elementspanelwidget.cpp +++ b/sources/elementspanelwidget.cpp @@ -120,6 +120,12 @@ ElementsPanelWidget::ElementsPanelWidget(QWidget *parent) : QWidget(parent) { SLOT(openTitleBlockTemplate(const TitleBlockTemplateLocation &)) ); + // manage double click on TreeWidgetItem + connect(elements_panel, SIGNAL(requestForProjectPropertiesEdition()), this, SLOT(editProjectProperties()) ); + connect(elements_panel, SIGNAL(requestForDiagramPropertiesEdition()), this, SLOT(editDiagramProperties()) ); + // manage project activation + connect(elements_panel, SIGNAL(requestForProject(QETProject*)), this, SIGNAL(requestForProject(QETProject*))); + // disposition verticale QVBoxLayout *vlayout = new QVBoxLayout(this); vlayout -> setContentsMargins(0,0,0,0);