添加模型分割
This commit is contained in:
55
client/gui/widgets/ToolOptionPopup.cpp
Normal file
55
client/gui/widgets/ToolOptionPopup.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#include "widgets/ToolOptionPopup.h"
|
||||
|
||||
#include <QBoxLayout>
|
||||
#include <QPushButton>
|
||||
#include <QToolButton>
|
||||
|
||||
ToolOptionPopup::ToolOptionPopup(QWidget* parent)
|
||||
: QFrame(parent) {
|
||||
setWindowFlags(Qt::Popup | Qt::FramelessWindowHint);
|
||||
setFrameShape(QFrame::StyledPanel);
|
||||
setObjectName(QStringLiteral("ToolOptionPopup"));
|
||||
setStyleSheet(QStringLiteral(
|
||||
"#ToolOptionPopup { background: palette(base); border: 1px solid palette(mid); border-radius: 10px; }"
|
||||
"#ToolOptionPopup QPushButton { border: 1px solid transparent; padding: 8px 10px; text-align: left; }"
|
||||
"#ToolOptionPopup QPushButton:hover { background: palette(midlight); }"));
|
||||
}
|
||||
|
||||
void ToolOptionPopup::setOptions(const QVector<Option>& opts) {
|
||||
m_options = opts;
|
||||
rebuildUi();
|
||||
}
|
||||
|
||||
void ToolOptionPopup::rebuildUi() {
|
||||
QLayout* old = layout();
|
||||
if (old) {
|
||||
delete old;
|
||||
}
|
||||
auto* root = new QVBoxLayout(this);
|
||||
root->setContentsMargins(8, 8, 8, 8);
|
||||
root->setSpacing(6);
|
||||
for (const auto& opt : m_options) {
|
||||
auto* b = new QPushButton(opt.text, this);
|
||||
b->setFlat(true);
|
||||
connect(b, &QPushButton::clicked, this, [this, id = opt.id]() {
|
||||
emit optionChosen(id);
|
||||
close();
|
||||
});
|
||||
root->addWidget(b);
|
||||
}
|
||||
}
|
||||
|
||||
void ToolOptionPopup::popupNearToolButton(QToolButton* btn) {
|
||||
if (!btn) {
|
||||
return;
|
||||
}
|
||||
if (!layout()) {
|
||||
rebuildUi();
|
||||
}
|
||||
adjustSize();
|
||||
const QPoint g = btn->mapToGlobal(QPoint(btn->width(), 0));
|
||||
move(g.x() + 6, g.y());
|
||||
show();
|
||||
raise();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user