Skip to content

Commit

Permalink
Gui: improve Std_SelUp command
Browse files Browse the repository at this point in the history
  • Loading branch information
realthunder committed Jul 9, 2020
1 parent 61f836a commit 73f279b
Show file tree
Hide file tree
Showing 8 changed files with 256 additions and 36 deletions.
10 changes: 6 additions & 4 deletions src/Gui/Action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#endif

#include <Base/Tools.h>
#include <App/DocumentObserver.h>
#include "Action.h"
#include "Application.h"
#include "Command.h"
Expand All @@ -51,6 +52,7 @@
#include "WorkbenchManager.h"
#include "View3DInventor.h"
#include "Document.h"
#include "SelectionView.h"

#include <Base/Exception.h>
#include <App/Application.h>
Expand Down Expand Up @@ -1108,15 +1110,15 @@ SelUpAction::SelUpAction ( Command* pcCmd, QObject * parent )

SelUpAction::~SelUpAction()
{
delete _menu;
}

void SelUpAction::addTo ( QWidget * w )
{
if (!_menu) {
_menu = new QMenu();
_menu = new SelUpMenu(nullptr);
_action->setMenu(_menu);
connect(_menu, SIGNAL(aboutToShow()), this, SLOT(onShowMenu()));
connect(_menu, SIGNAL(triggered(QAction*)), this, SLOT(onTriggered(QAction*)));
}
w->addAction(_action);
}
Expand All @@ -1127,9 +1129,9 @@ void SelUpAction::onShowMenu()
TreeWidget::populateSelUpMenu(_menu);
}

void SelUpAction::onTriggered(QAction *action)
void SelUpAction::popup(const QPoint &pt)
{
TreeWidget::selectUp(action);
_menu->exec(pt);
}

#include "moc_Action.cpp"
5 changes: 2 additions & 3 deletions src/Gui/Action.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#define GUI_ACTION_H

#include <QAction>
#include <QMenu>
#include <QComboBox>
#include <QKeySequence>

Expand Down Expand Up @@ -338,8 +339,6 @@ protected Q_SLOTS:
QMenu* _menu;
};

// --------------------------------------------------------------------

/**
* Special action for Std_SelUp command.
*/
Expand All @@ -351,10 +350,10 @@ class GuiExport SelUpAction : public Action
SelUpAction (Command* pcCmd, QObject * parent = 0);
virtual ~SelUpAction();
void addTo (QWidget * w);
void popup(const QPoint &pt);

protected Q_SLOTS:
void onShowMenu();
void onTriggered(QAction *);

private:
QMenu* _menu;
Expand Down
5 changes: 3 additions & 2 deletions src/Gui/CommandView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3343,13 +3343,14 @@ StdCmdSelUp::StdCmdSelUp()

bool StdCmdSelUp::isActive(void)
{
return Selection().size() == 1;
return App::GetApplication().getActiveDocument() && Selection().size() <= 1;
}

void StdCmdSelUp::activated(int iMsg)
{
Q_UNUSED(iMsg);
TreeWidget::selectUp();
if (_pcAction)
static_cast<SelUpAction*>(_pcAction)->popup(QCursor::pos());
}

Action * StdCmdSelUp::createAction(void)
Expand Down
60 changes: 52 additions & 8 deletions src/Gui/SelectionView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,10 +538,8 @@ static QLatin1String _DefaultStyle(
static QLatin1String _DefaultStyle("QMenu {menu-scrollable:1}");
#endif

SelectionMenu::SelectionMenu(QWidget *parent)
:QMenu(parent),pSelList(0)
static void setupMenuStyle(QMenu *menu)
{
connect(this, SIGNAL(aboutToShow()), this, SLOT(beforeShow()));
#if QT_VERSION >= 0x050000
auto hGrp = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/MainWindow");
Expand Down Expand Up @@ -569,15 +567,22 @@ SelectionMenu::SelectionMenu(QWidget *parent)
}
if(_Stylesheet.isEmpty())
_Stylesheet = _DefaultStyle;
setStyleSheet(_Stylesheet);
setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
setAttribute(Qt::WA_NoSystemBackground, true);
setAttribute(Qt::WA_TranslucentBackground, true);
menu->setStyleSheet(_Stylesheet);
menu->setWindowFlags(menu->windowFlags() | Qt::FramelessWindowHint);
menu->setAttribute(Qt::WA_NoSystemBackground, true);
menu->setAttribute(Qt::WA_TranslucentBackground, true);
#else
setStyleSheet(QLatin1String(_DefaultStyle));
menu->setStyleSheet(QLatin1String(_DefaultStyle));
#endif
}

SelectionMenu::SelectionMenu(QWidget *parent)
:QMenu(parent),pSelList(0)
{
connect(this, SIGNAL(aboutToShow()), this, SLOT(beforeShow()));
setupMenuStyle(this);
}

void SelectionMenu::beforeShow()
{
#if QT_VERSION >= 0x050000
Expand Down Expand Up @@ -803,4 +808,43 @@ void SelectionMenu::onSubMenu() {
tooltipIndex = -idx;
}

// --------------------------------------------------------------------

SelUpMenu::SelUpMenu(QWidget *parent)
:QMenu(parent)
{
connect(this, SIGNAL(triggered(QAction*)), this, SLOT(onTriggered(QAction *)));
connect(this, SIGNAL(hovered(QAction*)), this, SLOT(onHovered(QAction *)));
setupMenuStyle(this);
#if QT_VERSION >= 0x050100
setToolTipsVisible(true);
#endif
}

void SelUpMenu::mouseReleaseEvent(QMouseEvent *e)
{
if (e->button() == Qt::RightButton) {
QAction *action = actionAt(e->pos());
if (action) {
TreeWidget::selectUp(action, this);
return;
}
}
QMenu::mouseReleaseEvent(e);
}

void SelUpMenu::onTriggered(QAction *action)
{
TreeWidget::selectUp(action);
}

void SelUpMenu::onHovered(QAction *action)
{
App::SubObjectT objT = qvariant_cast<App::SubObjectT>(action->data());
if (!objT.getSubObject())
return;
Selection().setPreselect(objT.getDocumentName().c_str(),
objT.getObjectName().c_str(), objT.getSubName().c_str(), 0,0,0,2);
}

#include "moc_SelectionView.cpp"
15 changes: 15 additions & 0 deletions src/Gui/SelectionView.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,21 @@ public Q_SLOTS:
int tooltipIndex;
};


class GuiExport SelUpMenu : public QMenu
{
Q_OBJECT
public:
SelUpMenu(QWidget *parent);

protected:
void mouseReleaseEvent(QMouseEvent *e);

protected Q_SLOTS:
void onTriggered(QAction *action);
void onHovered(QAction *action);
};

} // namespace Gui

#endif // GUI_DOCKWND_SELECTIONVIEW_H
Loading

0 comments on commit 73f279b

Please sign in to comment.