feat(tab menu): add nodes section

This commit is contained in:
parker
2025-07-15 20:29:53 +01:00
parent 7be504cc62
commit 6d00c92f0f
3 changed files with 61 additions and 24 deletions

View File

@@ -6,25 +6,63 @@
#include <qevent.h>
#include <qlineedit.h>
#include <qnamespace.h>
#include <qpushbutton.h>
#include <qscrollarea.h>
#include <qwidget.h>
#include <QEvent>
#include <QPainterPath>
#include <QPushButton>
#include <string>
enzo::ui::TabMenu::TabMenu(QWidget *parent, Qt::WindowFlags f)
: QWidget(parent, f)
{
std::cout << "ctor\n";
searchBar_ = new QLineEdit();
auto box = new QVBoxLayout(this);
box->addWidget(searchBar_);
setAttribute(Qt::WA_TranslucentBackground);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
mainLayout_ = new QVBoxLayout(this);
setLayout(mainLayout_);
searchBar_ = new QLineEdit();
nodeHolder_ = new QWidget();
nodeScrollArea_ = new QScrollArea();
nodeScrollArea_->setWidget(nodeHolder_);
nodeScrollArea_->setWidgetResizable(true);
mainLayout_->addWidget(searchBar_);
mainLayout_->addWidget(nodeScrollArea_);
nodeHolderLayout_ = new QVBoxLayout();
nodeHolder_->setLayout(nodeHolderLayout_);
for(int i=0; i<10; ++i)
{
auto button = new QPushButton(std::string("Node " + std::to_string(i)).c_str());
button->setStyleSheet(R"(
QPushButton {
background-color: #181c1d;
border: none;
padding: 0px;
border-radius: 4px;
}
QPushButton:hover {
background-color: #d0d0d0;
color: black;
}
QPushButton:pressed {
background-color: #b0b0b0;
}
)");
nodeHolderLayout_->addWidget(button);
}
// searchBar_->setFocusPolicy(Qt::NoFocus);
setDisabled(true);
}
void enzo::ui::TabMenu::showOnMouse(float dx, float dy)
{
// searchBar_->setFocusPolicy(Qt::StrongFocus);
setDisabled(false);
std::cout << "showing\n";
QPoint cursorPos = mapToParent(mapFromGlobal(QCursor::pos()));
@@ -32,6 +70,7 @@ void enzo::ui::TabMenu::showOnMouse(float dx, float dy)
searchBar_->clear();
move(cursorPos + QPoint(dx, dy));
show();
adjustSize();
setFocus();
raise();
}
@@ -41,7 +80,6 @@ void enzo::ui::TabMenu::focusOutEvent(QFocusEvent *event)
std::cout << "focus lost\n";
QWidget::focusOutEvent(event);
setDisabled(true);
// searchBar_->setFocusPolicy(Qt::NoFocus);
hide();
}
@@ -57,7 +95,8 @@ bool enzo::ui::TabMenu::event(QEvent *event)
if(event->type() == QEvent::KeyPress)
{
if(static_cast<QKeyEvent*>(event)->key()==Qt::Key_Tab)
auto key = static_cast<QKeyEvent*>(event)->key();
if(key==Qt::Key_Tab || key==Qt::Key_Escape)
{
focusOutEvent(static_cast<QFocusEvent*>(event));
@@ -76,11 +115,11 @@ bool enzo::ui::TabMenu::event(QEvent *event)
}
void enzo::ui::TabMenu::resizeEvent(QResizeEvent *event)
{
QPainterPath path;
constexpr float radius = 10;
path.addRoundedRect(contentsRect(), radius, radius);
QRegion region = QRegion(path.toFillPolygon().toPolygon());
this->setMask(region);
}
// void enzo::ui::TabMenu::resizeEvent(QResizeEvent *event)
// {
// QPainterPath path;
// constexpr float radius = 10;
// path.addRoundedRect(contentsRect(), radius, radius);
// QRegion region = QRegion(path.toFillPolygon().toPolygon());
// this->setMask(region);
// }