ui: basic search view
- Added a basic SearchView (+ controller and qt implementation) - SearchView can set the active element of other views by dispatching a message. - SearchView adjusts its text when the active element is changed by other views. - Added wrappers for Button and EditBox that allow the usage of simple callback functions.
This commit is contained in:
@@ -3,8 +3,12 @@ add_files(
|
||||
|
||||
qt/element/QtCodeFile.cpp
|
||||
qt/element/QtCodeFile.h
|
||||
qt/element/QtButton.cpp
|
||||
qt/element/QtButton.h
|
||||
qt/element/QtCodeSnippet.cpp
|
||||
qt/element/QtCodeSnippet.h
|
||||
qt/element/QtEditBox.cpp
|
||||
qt/element/QtEditBox.h
|
||||
qt/element/QtMainWindow.cpp
|
||||
qt/element/QtMainWindow.h
|
||||
|
||||
@@ -23,6 +27,8 @@ add_files(
|
||||
qt/view/QtGraphView.h
|
||||
qt/view/QtMainView.cpp
|
||||
qt/view/QtMainView.h
|
||||
qt/view/QtSearchView.cpp
|
||||
qt/view/QtSearchView.h
|
||||
|
||||
qt/QtGuiFactory.cpp
|
||||
qt/QtGuiFactory.h
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "qt/view/QtCodeView.h"
|
||||
#include "qt/view/QtGraphView.h"
|
||||
#include "qt/view/QtMainView.h"
|
||||
#include "qt/view/QtSearchView.h"
|
||||
|
||||
QtGuiFactory::QtGuiFactory()
|
||||
{
|
||||
@@ -26,3 +27,8 @@ std::shared_ptr<GraphView> QtGuiFactory::createGraphView(ViewLayout* viewLayout)
|
||||
{
|
||||
return View::create<QtGraphView>(viewLayout);
|
||||
}
|
||||
|
||||
std::shared_ptr<SearchView> QtGuiFactory::createSearchView(ViewLayout* viewLayout) const
|
||||
{
|
||||
return View::create<QtSearchView>(viewLayout);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ public:
|
||||
virtual std::shared_ptr<MainView> createMainView() const;
|
||||
virtual std::shared_ptr<CodeView> createCodeView(ViewLayout* viewLayout) const;
|
||||
virtual std::shared_ptr<GraphView> createGraphView(ViewLayout* viewLayout) const;
|
||||
virtual std::shared_ptr<SearchView> createSearchView(ViewLayout* viewLayout) const;
|
||||
};
|
||||
|
||||
#endif // QT_GUI_FACTORY_H
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
#include "qt/element/QtButton.h"
|
||||
|
||||
QtButton::QtButton(QWidget *parent)
|
||||
: QPushButton(parent)
|
||||
, m_onClick(nullptr)
|
||||
{
|
||||
connect(this, SIGNAL(clicked()), this, SLOT(slotOnClick()));
|
||||
}
|
||||
|
||||
QtButton::~QtButton()
|
||||
{
|
||||
}
|
||||
|
||||
void QtButton::setCallbackOnClick(std::function<void(void)> callback)
|
||||
{
|
||||
m_onClick = callback;
|
||||
}
|
||||
|
||||
void QtButton::slotOnClick()
|
||||
{
|
||||
if (m_onClick)
|
||||
m_onClick();
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef QT_BUTTON_H
|
||||
#define QT_BUTTON_H
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include <QPushButton>
|
||||
|
||||
class QtButton: public QPushButton
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QtButton(QWidget *parent);
|
||||
~QtButton();
|
||||
|
||||
void setCallbackOnClick(std::function<void(void)> callback);
|
||||
|
||||
private slots:
|
||||
void slotOnClick();
|
||||
|
||||
private:
|
||||
std::function<void(void)> m_onClick;
|
||||
};
|
||||
|
||||
#endif // QT_BUTTON_H
|
||||
@@ -0,0 +1,23 @@
|
||||
#include "qt/element/QtEditBox.h"
|
||||
|
||||
QtEditBox::QtEditBox(QWidget *parent)
|
||||
: QLineEdit(parent)
|
||||
, m_onReturnPressed(nullptr)
|
||||
{
|
||||
connect(this, SIGNAL(returnPressed()), this, SLOT(slotOnReturnPressed()));
|
||||
}
|
||||
|
||||
QtEditBox::~QtEditBox()
|
||||
{
|
||||
}
|
||||
|
||||
void QtEditBox::setCallbackOnReturnPressed(std::function<void(void)> callback)
|
||||
{
|
||||
m_onReturnPressed = callback;
|
||||
}
|
||||
|
||||
void QtEditBox::slotOnReturnPressed()
|
||||
{
|
||||
if (m_onReturnPressed)
|
||||
m_onReturnPressed();
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef QT_EDIT_BOX_H
|
||||
#define QT_EDIT_BOX_H
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include <QLineEdit>
|
||||
|
||||
class QtEditBox: public QLineEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QtEditBox(QWidget *parent);
|
||||
~QtEditBox();
|
||||
|
||||
void setCallbackOnReturnPressed(std::function<void(void)> callback);
|
||||
|
||||
private slots:
|
||||
void slotOnReturnPressed();
|
||||
|
||||
private:
|
||||
std::function<void(void)> m_onReturnPressed;
|
||||
};
|
||||
|
||||
#endif // QT_EDIT_BOX_H
|
||||
@@ -0,0 +1,58 @@
|
||||
#include "qt/view/QtSearchView.h"
|
||||
|
||||
#include <QtWidgets>
|
||||
|
||||
#include "qt/element/QtButton.h"
|
||||
#include "qt/element/QtEditBox.h"
|
||||
#include "qt/QtWidgetWrapper.h"
|
||||
#include "qt/utility/utilityQt.h"
|
||||
#include "component/controller/SearchController.h"
|
||||
|
||||
QtSearchView::QtSearchView(ViewLayout* viewLayout)
|
||||
: SearchView(viewLayout)
|
||||
{
|
||||
}
|
||||
|
||||
QtSearchView::~QtSearchView()
|
||||
{
|
||||
}
|
||||
|
||||
void QtSearchView::createWidgetWrapper()
|
||||
{
|
||||
setWidgetWrapper(std::make_shared<QtWidgetWrapper>(std::make_shared<QFrame>()));
|
||||
}
|
||||
|
||||
void QtSearchView::initGui()
|
||||
{
|
||||
QWidget* widget = QtWidgetWrapper::getWidgetOfView(this);
|
||||
utility::setWidgetBackgroundColor(widget, Colori(190, 190, 190, 255));
|
||||
|
||||
QBoxLayout* layout = new QBoxLayout(QBoxLayout::LeftToRight);
|
||||
layout->setSpacing(3);
|
||||
layout->setContentsMargins(3, 3, 3, 3);
|
||||
widget->setLayout(layout);
|
||||
|
||||
m_searchBox = new QtEditBox(widget);
|
||||
m_searchBox->setPlaceholderText("Please enter your search string.");
|
||||
m_searchBox->setCallbackOnReturnPressed(std::bind(&QtSearchView::onSeachButtonClick, this));
|
||||
|
||||
m_searchButton = new QtButton(widget);
|
||||
m_searchButton->setText("Search");
|
||||
m_searchButton->setCallbackOnClick(std::bind(&QtSearchView::onSeachButtonClick, this));
|
||||
|
||||
widget->layout()->addWidget(m_searchBox);
|
||||
widget->layout()->addWidget(m_searchButton);
|
||||
}
|
||||
|
||||
void QtSearchView::setText(const std::string& s) const
|
||||
{
|
||||
if (m_searchBox->text() != s.c_str())
|
||||
{
|
||||
m_searchBox->setText(s.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void QtSearchView::onSeachButtonClick()
|
||||
{
|
||||
getController()->search(m_searchBox->text().toStdString());
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef QT_SEARCH_VIEW_H
|
||||
#define QT_SEARCH_VIEW_H
|
||||
|
||||
#include "component/view/SearchView.h"
|
||||
|
||||
class QtEditBox;
|
||||
class QtButton;
|
||||
|
||||
class QtSearchView: public SearchView
|
||||
{
|
||||
public:
|
||||
QtSearchView(ViewLayout* viewLayout);
|
||||
~QtSearchView();
|
||||
|
||||
// View implementation
|
||||
virtual void createWidgetWrapper();
|
||||
virtual void initGui();
|
||||
|
||||
// SearchView implementation
|
||||
virtual void setText(const std::string& s) const;
|
||||
|
||||
private:
|
||||
void onSeachButtonClick();
|
||||
|
||||
QtEditBox* m_searchBox;
|
||||
QtButton* m_searchButton;
|
||||
};
|
||||
|
||||
# endif // QT_SEARCH_VIEW_H
|
||||
Reference in New Issue
Block a user