ui: Added singleton QtContextMenu with global back and forward actions
* QtContextMenu holds default actions for back and forward * additional actions can be passed to extend the default menu * currently used in QtMainWindow and QtCodeArea * fixed crash on undo when only view actions happened since project load bug id = 108
This commit is contained in:
@@ -52,6 +52,8 @@ add_files(
|
||||
qt/network/QtTcpWrapper.cpp
|
||||
qt/network/QtTcpWrapper.h
|
||||
|
||||
qt/utility/QtContextMenu.cpp
|
||||
qt/utility/QtContextMenu.h
|
||||
qt/utility/QtDeviceScaledPixmap.cpp
|
||||
qt/utility/QtDeviceScaledPixmap.h
|
||||
qt/utility/QtHighlighter.cpp
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "data/location/TokenLocationFile.h"
|
||||
#include "qt/element/QtCodeFile.h"
|
||||
#include "qt/element/QtCodeSnippet.h"
|
||||
#include "qt/utility/QtContextMenu.h"
|
||||
#include "qt/utility/QtHighlighter.h"
|
||||
#include "settings/ApplicationSettings.h"
|
||||
#include "settings/ColorScheme.h"
|
||||
@@ -498,10 +499,7 @@ void QtCodeArea::contextMenuEvent(QContextMenuEvent* event)
|
||||
if (m_setIDECursorPositionAction != nullptr)
|
||||
{
|
||||
m_eventPosition = event->pos();
|
||||
|
||||
QMenu menu(this);
|
||||
menu.addAction(m_setIDECursorPositionAction);
|
||||
menu.exec(event->globalPos());
|
||||
QtContextMenu::getInstance()->showExtended(event, this, std::vector<QAction*>(1, m_setIDECursorPositionAction));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
#include "qt/utility/QtContextMenu.h"
|
||||
|
||||
#include <QMenu>
|
||||
#include <QContextMenuEvent>
|
||||
|
||||
#include "utility/messaging/type/MessageRedo.h"
|
||||
#include "utility/messaging/type/MessageUndo.h"
|
||||
|
||||
std::shared_ptr<QtContextMenu> QtContextMenu::s_instance;
|
||||
|
||||
QtContextMenu* QtContextMenu::getInstance()
|
||||
{
|
||||
if (!s_instance)
|
||||
{
|
||||
s_instance = std::make_shared<QtContextMenu>();
|
||||
}
|
||||
|
||||
return s_instance.get();
|
||||
}
|
||||
|
||||
QtContextMenu::QtContextMenu()
|
||||
{
|
||||
m_undoAction = new QAction(tr("Back"), this);
|
||||
m_undoAction->setStatusTip(tr("Go back to last active symbol"));
|
||||
m_undoAction->setToolTip(tr("Go back to last active symbol"));
|
||||
connect(m_undoAction, SIGNAL(triggered()), this, SLOT(undoActionTriggered()));
|
||||
|
||||
m_redoAction = new QAction(tr("Forward"), this);
|
||||
m_redoAction->setStatusTip(tr("Go forward to next active symbol"));
|
||||
m_redoAction->setToolTip(tr("Go forward to next active symbol"));
|
||||
connect(m_redoAction, SIGNAL(triggered()), this, SLOT(redoActionTriggered()));
|
||||
}
|
||||
|
||||
void QtContextMenu::showDefault(QContextMenuEvent* event, QWidget* origin)
|
||||
{
|
||||
showExtended(event, origin, std::vector<QAction*>());
|
||||
}
|
||||
|
||||
void QtContextMenu::showExtended(QContextMenuEvent* event, QWidget* origin, const std::vector<QAction*>& actions)
|
||||
{
|
||||
QMenu menu(origin);
|
||||
|
||||
menu.addAction(m_undoAction);
|
||||
menu.addAction(m_redoAction);
|
||||
|
||||
if (actions.size())
|
||||
{
|
||||
menu.addSeparator();
|
||||
|
||||
for (QAction* action : actions)
|
||||
{
|
||||
menu.addAction(action);
|
||||
}
|
||||
}
|
||||
|
||||
menu.exec(event->globalPos());
|
||||
}
|
||||
|
||||
void QtContextMenu::undoActionTriggered()
|
||||
{
|
||||
MessageUndo().dispatch();
|
||||
}
|
||||
|
||||
void QtContextMenu::redoActionTriggered()
|
||||
{
|
||||
MessageRedo().dispatch();
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#ifndef QT_CONTEXT_MENU_H
|
||||
#define QT_CONTEXT_MENU_H
|
||||
|
||||
#include <QAction>
|
||||
#include <QObject>
|
||||
|
||||
class QtContextMenu
|
||||
: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static QtContextMenu* getInstance();
|
||||
|
||||
QtContextMenu();
|
||||
|
||||
void showDefault(QContextMenuEvent* event, QWidget* origin);
|
||||
void showExtended(QContextMenuEvent* event, QWidget* origin, const std::vector<QAction*>& actions);
|
||||
|
||||
private slots:
|
||||
void undoActionTriggered();
|
||||
void redoActionTriggered();
|
||||
|
||||
private:
|
||||
static std::shared_ptr<QtContextMenu> s_instance;
|
||||
|
||||
QAction* m_undoAction;
|
||||
QAction* m_redoAction;
|
||||
};
|
||||
|
||||
#endif // QT_CONTEXT_MENU_H
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "component/view/View.h"
|
||||
#include "component/view/CompositeView.h"
|
||||
#include "qt/utility/QtContextMenu.h"
|
||||
#include "qt/utility/utilityQt.h"
|
||||
#include "qt/view/QtViewWidgetWrapper.h"
|
||||
#include "qt/window/project_wizzard/QtProjectWizzard.h"
|
||||
@@ -139,8 +140,6 @@ QtMainWindow::QtMainWindow()
|
||||
setWindowIcon(QIcon((ResourcePaths::getGuiPath() + "icon/logo_1024_1024.png").c_str()));
|
||||
setWindowFlags(Qt::Widget);
|
||||
|
||||
// QApplication::setOverrideCursor(Qt::ArrowCursor);
|
||||
|
||||
QApplication* app = dynamic_cast<QApplication*>(QCoreApplication::instance());
|
||||
app->installEventFilter(new MouseReleaseFilter(this));
|
||||
app->installEventFilter(new MouseWheelFilter(this));
|
||||
@@ -314,6 +313,11 @@ void QtMainWindow::keyPressEvent(QKeyEvent* event)
|
||||
}
|
||||
}
|
||||
|
||||
void QtMainWindow::contextMenuEvent(QContextMenuEvent* event)
|
||||
{
|
||||
QtContextMenu::getInstance()->showDefault(event, this);
|
||||
}
|
||||
|
||||
void QtMainWindow::activateWindow()
|
||||
{
|
||||
this->setEnabled(true);
|
||||
|
||||
@@ -89,6 +89,7 @@ public:
|
||||
protected:
|
||||
bool event(QEvent* event);
|
||||
void keyPressEvent(QKeyEvent* event);
|
||||
void contextMenuEvent(QContextMenuEvent* event);
|
||||
|
||||
public slots:
|
||||
void activateWindow();
|
||||
@@ -157,6 +158,7 @@ private:
|
||||
QAction* m_viewSeparator;
|
||||
QAction** m_recentProjectAction;
|
||||
QAction* m_showTitleBarsAction;
|
||||
|
||||
bool m_showDockWidgetTitleBars;
|
||||
|
||||
QtWindowStack m_windowStack;
|
||||
|
||||
Reference in New Issue
Block a user