feat: tab menu search bar
This commit is contained in:
@@ -43,6 +43,7 @@ set(GUI_SOURCES
|
|||||||
src/Gui/Network/FloatingEdgeGraphic.cpp
|
src/Gui/Network/FloatingEdgeGraphic.cpp
|
||||||
src/Gui/Network/DisplayFlagButton.cpp
|
src/Gui/Network/DisplayFlagButton.cpp
|
||||||
src/Gui/Network/NodeIconGraphic.cpp
|
src/Gui/Network/NodeIconGraphic.cpp
|
||||||
|
src/Gui/Network/TabMenu.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
# qt
|
# qt
|
||||||
|
|||||||
55
src/Gui/Network/TabMenu.cpp
Normal file
55
src/Gui/Network/TabMenu.cpp
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
#include "Gui/Network/TabMenu.h"
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <iostream>
|
||||||
|
#include <qapplication.h>
|
||||||
|
#include <qlineedit.h>
|
||||||
|
#include <qwidget.h>
|
||||||
|
#include <QEvent>
|
||||||
|
|
||||||
|
enzo::ui::TabMenu::TabMenu(QWidget *parent, Qt::WindowFlags f)
|
||||||
|
: QWidget(parent, f)
|
||||||
|
{
|
||||||
|
setFocusPolicy(Qt::StrongFocus);
|
||||||
|
searchBar_ = new QLineEdit("hello world");
|
||||||
|
auto box = new QVBoxLayout(this);
|
||||||
|
box->addWidget(searchBar_);
|
||||||
|
}
|
||||||
|
|
||||||
|
void enzo::ui::TabMenu::showOnMouse(float dx, float dy)
|
||||||
|
{
|
||||||
|
QPoint cursorPos = mapFromGlobal(QCursor::pos());
|
||||||
|
std::cout << "inside" << cursorPos.x() << " " << cursorPos.y() << "\n";
|
||||||
|
move(cursorPos + QPoint(dx, dy));
|
||||||
|
show();
|
||||||
|
setFocus();
|
||||||
|
}
|
||||||
|
|
||||||
|
void enzo::ui::TabMenu::focusOutEvent(QFocusEvent *event)
|
||||||
|
{
|
||||||
|
std::cout << "focus lost\n";
|
||||||
|
QWidget::focusOutEvent(event);
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool enzo::ui::TabMenu::event(QEvent *event)
|
||||||
|
{
|
||||||
|
if(
|
||||||
|
event->type() == QEvent::KeyPress ||
|
||||||
|
event->type() == QEvent::KeyRelease
|
||||||
|
)
|
||||||
|
{
|
||||||
|
QApplication::postEvent(searchBar_, event->clone());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return QWidget::event(event);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// void enzo::ui::TabMenu::keyPressEvent(QKeyEvent *event)
|
||||||
|
// {
|
||||||
|
// searchBar_->keyPressEvent(event);
|
||||||
|
// }
|
||||||
|
// void enzo::ui::TabMenu::keyReleaseEvent(QKeyEvent *event)
|
||||||
|
// {
|
||||||
|
// }
|
||||||
24
src/Gui/Network/TabMenu.h
Normal file
24
src/Gui/Network/TabMenu.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <qlineedit.h>
|
||||||
|
#include <qwidget.h>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
|
namespace enzo::ui
|
||||||
|
{
|
||||||
|
class TabMenu
|
||||||
|
: public QWidget
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TabMenu(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
|
||||||
|
void showOnMouse(float dx=0, float dy=0);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QLineEdit* searchBar_;
|
||||||
|
protected:
|
||||||
|
void focusOutEvent(QFocusEvent *event) override;
|
||||||
|
bool event(QEvent *event) override;
|
||||||
|
// void keyPressEvent(QKeyEvent *event) override;
|
||||||
|
// void keyReleaseEvent(QKeyEvent *event) override;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -5,6 +5,9 @@
|
|||||||
#include <boost/dll/import.hpp>
|
#include <boost/dll/import.hpp>
|
||||||
|
|
||||||
#include "Interface.h"
|
#include "Interface.h"
|
||||||
|
#include "Gui/Network/TabMenu.h"
|
||||||
|
#include <iostream>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
@@ -26,8 +29,19 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
QApplication app (argc, argv);
|
QApplication app (argc, argv);
|
||||||
|
|
||||||
|
QPoint cursorPos = QCursor::pos();
|
||||||
|
|
||||||
EnzoUI interface;
|
EnzoUI interface;
|
||||||
interface.show();
|
interface.show();
|
||||||
|
|
||||||
|
enzo::ui::TabMenu tabMenu(&interface);
|
||||||
|
QTimer::singleShot(1000, [&]{
|
||||||
|
QPoint cursorPos = QCursor::pos();
|
||||||
|
std::cout << cursorPos.x() << " " << cursorPos.y() << "\n";
|
||||||
|
tabMenu.showOnMouse();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user