ui: added find shortcut to set focus in search view
The shortcut is added to the new Find menubar item and dispatches a MessageFind, which is handled by the SearchController. QtSearchView assures via the ViewLayout that the view is visible when setting focus on the search box.
This commit is contained in:
@@ -9,6 +9,8 @@
|
||||
|
||||
#include "component/view/View.h"
|
||||
#include "qt/QtWidgetWrapper.h"
|
||||
#include "utility/logging/logging.h"
|
||||
#include "utility/messaging/type/MessageFind.h"
|
||||
#include "utility/messaging/type/MessageLoadProject.h"
|
||||
#include "utility/messaging/type/MessageLoadSource.h"
|
||||
|
||||
@@ -18,6 +20,7 @@ QtMainWindow::QtMainWindow()
|
||||
setCentralWidget(nullptr);
|
||||
|
||||
setupProjectMenu();
|
||||
setupFindMenu();
|
||||
setupHelpMenu();
|
||||
}
|
||||
|
||||
@@ -66,6 +69,11 @@ void QtMainWindow::openProject(const QString &path)
|
||||
}
|
||||
}
|
||||
|
||||
void QtMainWindow::find()
|
||||
{
|
||||
MessageFind().dispatch();
|
||||
}
|
||||
|
||||
void QtMainWindow::addView(View* view)
|
||||
{
|
||||
QDockWidget* dock = new QDockWidget(tr(view->getName().c_str()), this);
|
||||
@@ -87,6 +95,16 @@ void QtMainWindow::removeView(View* view)
|
||||
}
|
||||
}
|
||||
|
||||
void QtMainWindow::showView(View* view)
|
||||
{
|
||||
getDockWidgetForView(view)->setHidden(false);
|
||||
}
|
||||
|
||||
void QtMainWindow::hideView(View* view)
|
||||
{
|
||||
getDockWidgetForView(view)->setHidden(true);
|
||||
}
|
||||
|
||||
void QtMainWindow::loadLayout()
|
||||
{
|
||||
QSettings settings("data/window_settings.ini", QSettings::IniFormat);
|
||||
@@ -151,6 +169,14 @@ void QtMainWindow::setupProjectMenu()
|
||||
menu->addAction(tr("E&xit"), QCoreApplication::instance(), SLOT(quit()), QKeySequence::Quit);
|
||||
}
|
||||
|
||||
void QtMainWindow::setupFindMenu()
|
||||
{
|
||||
QMenu *menu = new QMenu(tr("&Find"), this);
|
||||
menuBar()->addMenu(menu);
|
||||
|
||||
menu->addAction(tr("&Find"), this, SLOT(find()), QKeySequence::Find);
|
||||
}
|
||||
|
||||
void QtMainWindow::setupHelpMenu()
|
||||
{
|
||||
QMenu *menu = new QMenu(tr("&Help"), this);
|
||||
@@ -159,3 +185,17 @@ void QtMainWindow::setupHelpMenu()
|
||||
menu->addAction(tr("&About"), this, SLOT(about()));
|
||||
menu->addAction(tr("About &Qt"), QCoreApplication::instance(), SLOT(aboutQt()));
|
||||
}
|
||||
|
||||
QDockWidget* QtMainWindow::getDockWidgetForView(View* view) const
|
||||
{
|
||||
for (size_t i = 0; i < m_dockWidgets.size(); i++)
|
||||
{
|
||||
if (m_dockWidgets[i].first == view)
|
||||
{
|
||||
return m_dockWidgets[i].second;
|
||||
}
|
||||
}
|
||||
|
||||
LOG_ERROR("DockWidget was not found for view.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -20,17 +20,24 @@ public:
|
||||
void addView(View* view);
|
||||
void removeView(View* view);
|
||||
|
||||
void showView(View* view);
|
||||
void hideView(View* view);
|
||||
|
||||
void loadLayout();
|
||||
void saveLayout();
|
||||
|
||||
public slots:
|
||||
void about();
|
||||
void newProject();
|
||||
void openProject(const QString &path = QString());
|
||||
void about();
|
||||
void newProject();
|
||||
void openProject(const QString &path = QString());
|
||||
void find();
|
||||
|
||||
private:
|
||||
void setupProjectMenu();
|
||||
void setupHelpMenu();
|
||||
void setupProjectMenu();
|
||||
void setupFindMenu();
|
||||
void setupHelpMenu();
|
||||
|
||||
QDockWidget* getDockWidgetForView(View* view) const;
|
||||
|
||||
std::vector<std::pair<View*, QDockWidget*> > m_dockWidgets;
|
||||
};
|
||||
|
||||
@@ -32,6 +32,16 @@ void QtMainView::removeView(View* view)
|
||||
m_views.erase(it);
|
||||
}
|
||||
|
||||
void QtMainView::showView(View* view)
|
||||
{
|
||||
m_window->showView(view);
|
||||
}
|
||||
|
||||
void QtMainView::hideView(View* view)
|
||||
{
|
||||
m_window->hideView(view);
|
||||
}
|
||||
|
||||
void QtMainView::loadLayout()
|
||||
{
|
||||
m_window->loadLayout();
|
||||
|
||||
@@ -16,8 +16,11 @@ public:
|
||||
virtual ~QtMainView();
|
||||
|
||||
// ViewLayout implementation
|
||||
void addView(View* view);
|
||||
void removeView(View* view);
|
||||
virtual void addView(View* view);
|
||||
virtual void removeView(View* view);
|
||||
|
||||
virtual void showView(View* view);
|
||||
virtual void hideView(View* view);
|
||||
|
||||
virtual void loadLayout();
|
||||
virtual void saveLayout();
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
QtSearchView::QtSearchView(ViewLayout* viewLayout)
|
||||
: SearchView(viewLayout)
|
||||
, m_setTextFunctor(std::bind(&QtSearchView::doSetText, this, std::placeholders::_1))
|
||||
, m_setFocusFunctor(std::bind(&QtSearchView::doSetFocus, this))
|
||||
, m_setAutocompletionListFunctor(std::bind(&QtSearchView::doSetAutocompletionList, this, std::placeholders::_1))
|
||||
{
|
||||
}
|
||||
@@ -59,6 +60,11 @@ void QtSearchView::setText(const std::string& s)
|
||||
m_setTextFunctor(s);
|
||||
}
|
||||
|
||||
void QtSearchView::setFocus()
|
||||
{
|
||||
m_setFocusFunctor();
|
||||
}
|
||||
|
||||
void QtSearchView::setAutocompletionList(const std::vector<std::string>& autocompletionList)
|
||||
{
|
||||
m_setAutocompletionListFunctor(autocompletionList);
|
||||
@@ -81,6 +87,12 @@ void QtSearchView::doSetText(const std::string& s)
|
||||
}
|
||||
}
|
||||
|
||||
void QtSearchView::doSetFocus()
|
||||
{
|
||||
getViewLayout()->showView(this);
|
||||
m_searchBox->setFocus(Qt::ShortcutFocusReason);
|
||||
}
|
||||
|
||||
void QtSearchView::doSetAutocompletionList(const std::vector<std::string>& autocompletionList)
|
||||
{
|
||||
QStringList wordList;
|
||||
|
||||
@@ -21,18 +21,21 @@ public:
|
||||
|
||||
// SearchView implementation
|
||||
virtual void setText(const std::string& s);
|
||||
virtual void setFocus();
|
||||
virtual void setAutocompletionList(const std::vector<std::string>& autocompletionList);
|
||||
|
||||
private:
|
||||
void onSearchButtonClick();
|
||||
|
||||
void doSetText(const std::string& s);
|
||||
void doSetFocus();
|
||||
void doSetAutocompletionList(const std::vector<std::string>& autocompletionList);
|
||||
|
||||
QtEditBox* m_searchBox;
|
||||
QtButton* m_searchButton;
|
||||
QtButton* m_caseSensitiveButton;
|
||||
QtThreadedFunctor<const std::string&> m_setTextFunctor;
|
||||
QtThreadedFunctor<> m_setFocusFunctor;
|
||||
QtThreadedFunctor<const std::vector<std::string>&> m_setAutocompletionListFunctor;
|
||||
};
|
||||
|
||||
|
||||
@@ -150,8 +150,10 @@ add_files(
|
||||
utility/math/VectorBase.h
|
||||
|
||||
utility/messaging/type/MessageActivateToken.h
|
||||
utility/messaging/type/MessageFind.h
|
||||
utility/messaging/type/MessageFinishedParsing.h
|
||||
utility/messaging/type/MessageLoadProject.h
|
||||
utility/messaging/type/MessageLoadSource.h
|
||||
|
||||
utility/messaging/Message.h
|
||||
utility/messaging/MessageBase.h
|
||||
|
||||
@@ -33,6 +33,11 @@ void SearchController::handleMessage(MessageActivateToken* message)
|
||||
getView()->setText(m_graphAccess->getNameForNodeWithId(message->tokenId));
|
||||
}
|
||||
|
||||
void SearchController::handleMessage(MessageFind* message)
|
||||
{
|
||||
getView()->setFocus();
|
||||
}
|
||||
|
||||
void SearchController::handleMessage(MessageFinishedParsing* message)
|
||||
{
|
||||
getView()->setAutocompletionList(m_graphAccess->getNamesForNodesWithNamePrefix(""));
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "component/controller/Controller.h"
|
||||
#include "utility/messaging/MessageListener.h"
|
||||
#include "utility/messaging/type/MessageActivateToken.h"
|
||||
#include "utility/messaging/type/MessageFind.h"
|
||||
#include "utility/messaging/type/MessageFinishedParsing.h"
|
||||
|
||||
class GraphAccess;
|
||||
@@ -14,6 +15,7 @@ class SearchView;
|
||||
class SearchController
|
||||
: public Controller
|
||||
, public MessageListener<MessageActivateToken>
|
||||
, public MessageListener<MessageFind>
|
||||
, public MessageListener<MessageFinishedParsing>
|
||||
{
|
||||
public:
|
||||
@@ -25,6 +27,7 @@ public:
|
||||
|
||||
private:
|
||||
virtual void handleMessage(MessageActivateToken* message);
|
||||
virtual void handleMessage(MessageFind* message);
|
||||
virtual void handleMessage(MessageFinishedParsing* message);
|
||||
SearchView* getView();
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ public:
|
||||
virtual std::string getName() const;
|
||||
|
||||
virtual void setText(const std::string& s) = 0;
|
||||
virtual void setFocus() = 0;
|
||||
virtual void setAutocompletionList(const std::vector<std::string>& autocompletionList) = 0;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
#include "component/view/View.h"
|
||||
|
||||
#include "component/view/ViewLayout.h"
|
||||
#include "gui/GuiWidgetWrapper.h"
|
||||
|
||||
View::View(ViewLayout* viewLayout, const Vec2i& minSize)
|
||||
: m_viewLayout(viewLayout)
|
||||
, m_widgetWrapper(nullptr)
|
||||
, m_minSize(minSize)
|
||||
{
|
||||
}
|
||||
|
||||
View::~View()
|
||||
{
|
||||
m_viewLayout->removeView(this);
|
||||
@@ -38,9 +44,7 @@ Vec2i View::getMinSize() const
|
||||
return m_minSize;
|
||||
}
|
||||
|
||||
View::View(ViewLayout* viewLayout, const Vec2i& minSize)
|
||||
: m_viewLayout(viewLayout)
|
||||
, m_widgetWrapper(nullptr)
|
||||
, m_minSize(minSize)
|
||||
ViewLayout* View::getViewLayout() const
|
||||
{
|
||||
return m_viewLayout;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include "utility/math/Vector2.h"
|
||||
|
||||
class GuiWidgetWrapper;
|
||||
class ViewLayout;
|
||||
|
||||
class View
|
||||
{
|
||||
@@ -17,6 +16,7 @@ public:
|
||||
template<typename T>
|
||||
static std::shared_ptr<T> create(ViewLayout* viewLayout);
|
||||
|
||||
View(ViewLayout* viewLayout, const Vec2i& minSize);
|
||||
virtual ~View();
|
||||
|
||||
virtual std::string getName() const = 0;
|
||||
@@ -34,11 +34,11 @@ public:
|
||||
Vec2i getMinSize() const;
|
||||
|
||||
protected:
|
||||
View(ViewLayout* viewLayout, const Vec2i& minSize); // make public
|
||||
|
||||
template <typename ControllerType>
|
||||
ControllerType* getController();
|
||||
|
||||
ViewLayout* getViewLayout() const;
|
||||
|
||||
private:
|
||||
Component* m_component;
|
||||
ViewLayout* const m_viewLayout;
|
||||
|
||||
@@ -12,6 +12,9 @@ public:
|
||||
virtual void addView(View* view) = 0;
|
||||
virtual void removeView(View* view) = 0;
|
||||
|
||||
virtual void showView(View* view) = 0;
|
||||
virtual void hideView(View* view) = 0;
|
||||
|
||||
virtual void loadLayout() = 0;
|
||||
virtual void saveLayout() = 0;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef MESSAGE_FIND_H
|
||||
#define MESSAGE_FIND_H
|
||||
|
||||
#include "utility/messaging/Message.h"
|
||||
#include "utility/types.h"
|
||||
|
||||
class MessageFind: public Message<MessageFind>
|
||||
{
|
||||
public:
|
||||
MessageFind()
|
||||
{
|
||||
}
|
||||
|
||||
static const std::string getStaticType()
|
||||
{
|
||||
return "MessageFind";
|
||||
}
|
||||
};
|
||||
|
||||
#endif // MESSAGE_FIND_H
|
||||
Reference in New Issue
Block a user