feat(tab menu): add nodes section
This commit is contained in:
@@ -111,7 +111,6 @@ private:
|
||||
if(filteredItems.size()==0) return nullptr;
|
||||
if(filteredItems.size()==1) return filteredItems.at(0);
|
||||
|
||||
std::cout << "\n\n new item " << filteredItems.size() << "\n";
|
||||
QGraphicsItem* closestItem=filteredItems.at(0);
|
||||
float closestDist;
|
||||
{
|
||||
@@ -126,7 +125,6 @@ private:
|
||||
}
|
||||
closestDist = QLineF(itemPos, centerPos).length();
|
||||
}
|
||||
std::cout << "currentDist: " << closestDist << "\n";
|
||||
|
||||
for(size_t i=1; i<filteredItems.size(); ++i)
|
||||
{
|
||||
@@ -142,7 +140,6 @@ private:
|
||||
itemPos = item->scenePos();
|
||||
}
|
||||
auto currentDist = QLineF(itemPos, centerPos).length();
|
||||
std::cout << "currentDist: " << currentDist << "\n";
|
||||
if(currentDist < closestDist)
|
||||
{
|
||||
closestItem = item;
|
||||
|
||||
@@ -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);
|
||||
// }
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <qlineedit.h>
|
||||
#include <QLabel>
|
||||
#include <qscrollarea.h>
|
||||
#include <qwidget.h>
|
||||
#include <QVBoxLayout>
|
||||
#include <iostream>
|
||||
@@ -13,17 +14,17 @@ class TabMenu
|
||||
{
|
||||
public:
|
||||
TabMenu(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
|
||||
~TabMenu()
|
||||
{
|
||||
std::cout << "dtor\n";
|
||||
}
|
||||
void showOnMouse(float dx=0, float dy=0);
|
||||
|
||||
private:
|
||||
QVBoxLayout* mainLayout_;
|
||||
QLineEdit* searchBar_;
|
||||
QScrollArea* nodeScrollArea_;
|
||||
QWidget* nodeHolder_;
|
||||
QVBoxLayout* nodeHolderLayout_;
|
||||
protected:
|
||||
void focusOutEvent(QFocusEvent *event) override;
|
||||
bool event(QEvent *event) override;
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
// void resizeEvent(QResizeEvent *event) override;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user