修改属性面板默认不折叠

This commit is contained in:
2026-04-11 10:40:15 +08:00
parent 0710090b4d
commit a78b290920
2 changed files with 89 additions and 9 deletions

View File

@@ -26,11 +26,14 @@
#include <QAbstractItemView>
#include <QAbstractSpinBox>
#include <QApplication>
#include <QGuiApplication>
#include <QScreen>
#include <QAction>
#include <QBoxLayout>
#include <QButtonGroup>
#include <QCheckBox>
#include <QComboBox>
#include <QCursor>
#include <QDockWidget>
#include <QDrag>
#include <QEvent>
@@ -40,6 +43,7 @@
#include <QInputDialog>
#include <QLabel>
#include <QPainter>
#include <QPointer>
#include <QBuffer>
#include <QIODevice>
#include <QMenu>
@@ -298,6 +302,83 @@ namespace {
constexpr const char* kMimeProjectNodeJson = "application/x-hfut-project-node+json";
static bool guiRunningOnWayland() {
return QGuiApplication::platformName().contains(QLatin1String("wayland"), Qt::CaseInsensitive);
}
// 全屏 + Tool 菜单(仅非 Wayland先按锚点对齐再按可用工作区夹紧。仅靠 move(锚点) 时菜单右缘常超出屏幕,
// 部分合成器会把窗口整体扔到屏幕最左侧。
static void placeContextMenuOnScreen(QMenu* menu, const QPoint& anchorGlobal, QScreen* screenHint) {
if (!menu) {
return;
}
menu->adjustSize();
const QSize sh = menu->size();
QScreen* scr = screenHint;
if (!scr) {
scr = QGuiApplication::screenAt(anchorGlobal);
}
if (!scr) {
scr = QGuiApplication::primaryScreen();
}
const QRect avail = scr ? scr->availableGeometry() : QRect();
if (!avail.isValid()) {
menu->move(anchorGlobal);
return;
}
int x = anchorGlobal.x();
int y = anchorGlobal.y();
const int w = sh.width();
const int h = sh.height();
if (x + w > avail.right()) {
x = anchorGlobal.x() - w;
}
if (x + w > avail.right()) {
x = avail.right() - w + 1;
}
if (x < avail.left()) {
x = avail.left();
}
if (y + h > avail.bottom()) {
y = anchorGlobal.y() - h;
}
if (y + h > avail.bottom()) {
y = avail.bottom() - h + 1;
}
if (y < avail.top()) {
y = avail.top();
}
menu->move(x, y);
}
// 主窗口全屏时(常见于 F11以 QMainWindow 为父级的 Popup 菜单可能被压在全屏层之下不可见。
// X11 等:用 Qt::Tool + 延迟 move 抬高叠放顺序WaylandKWin 等)下 Tool 顶层窗的客户端 setGeometry/move 常被忽略,
// 菜单会被摆在屏左,应交给 Qt 的 xdg_popup 与普通 exec(globalPos) 定位,故不在 Wayland 走 Tool 分支。
QAction* execPopupMenuAboveFullscreen(QMenu& menu, const QPoint& globalPos, QWidget* topLevelRef) {
QWidget* w = topLevelRef ? topLevelRef->window() : nullptr;
if (w && (w->windowState() & Qt::WindowFullScreen) && !guiRunningOnWayland()) {
menu.setWindowFlag(Qt::Tool, true);
QScreen* menuScreen = w->screen();
QPointer<QMenu> guard(&menu);
QObject::connect(
&menu,
&QMenu::aboutToShow,
&menu,
[guard, menuScreen]() {
if (!guard) {
return;
}
QTimer::singleShot(0, guard.data(), [guard, menuScreen]() {
if (guard) {
placeContextMenuOnScreen(guard.data(), QCursor::pos(), menuScreen);
}
});
},
Qt::SingleShotConnection);
}
return menu.exec(globalPos);
}
class ProjectTreeWidget final : public QTreeWidget {
public:
explicit ProjectTreeWidget(QWidget* parent = nullptr) : QTreeWidget(parent) {
@@ -641,7 +722,7 @@ void MainWindow::createTimelineDock() {
m_currentFrame = std::clamp(frame, 0, core::Project::kClipFixedFrames - 1);
if (m_editorCanvas) m_editorCanvas->setCurrentFrame(m_currentFrame);
QAction* chosen = menu.exec(globalPos);
QAction* chosen = execPopupMenuAboveFullscreen(menu, globalPos, this);
if (!chosen) {
return;
}
@@ -2383,7 +2464,7 @@ void MainWindow::showProjectRootContextMenu(const QPoint& globalPos) {
actPreview->setEnabled(canPreview);
actBack->setEnabled(m_previewRequested);
QAction* chosen = menu.exec(globalPos);
QAction* chosen = execPopupMenuAboveFullscreen(menu, globalPos, this);
if (!chosen) {
return;
}
@@ -2498,7 +2579,8 @@ void MainWindow::rebuildCentralPages() {
}
QMenu menu(this);
QAction* actRemove = menu.addAction(QStringLiteral("从列表中移除"));
QAction* chosen = menu.exec(m_welcomeRecentTree->viewport()->mapToGlobal(pos));
QAction* chosen =
execPopupMenuAboveFullscreen(menu, m_welcomeRecentTree->viewport()->mapToGlobal(pos), this);
if (chosen == actRemove) {
const QString path = item->data(0, Qt::UserRole).toString();
if (!path.isEmpty()) {
@@ -3509,7 +3591,7 @@ void MainWindow::showBackgroundContextMenu(const QPoint& globalPos) {
QAction* actComputeDepth = menu.addAction(QStringLiteral("计算深度"));
actComputeDepth->setEnabled(m_workspace.isOpen() && m_workspace.hasBackground());
QAction* chosen = menu.exec(globalPos);
QAction* chosen = execPopupMenuAboveFullscreen(menu, globalPos, this);
if (!chosen) {
return;
}
@@ -3549,7 +3631,7 @@ void MainWindow::showBlackholeContextMenu(const QPoint& globalPos, const QString
QMenu menu(this);
QAction* actResolve = menu.addAction(QStringLiteral("修复"));
QAction* chosen = menu.exec(globalPos);
QAction* chosen = execPopupMenuAboveFullscreen(menu, globalPos, this);
if (!chosen || chosen != actResolve) {
return;
}

View File

@@ -123,8 +123,6 @@ EntityPropertySection::EntityPropertySection(QWidget* parent)
lay->addWidget(m_introContent);
lay->addStretch(1);
m_introContent->setVisible(false);
m_introSaveTimer = new QTimer(this);
m_introSaveTimer->setSingleShot(true);
connect(m_introSaveTimer, &QTimer::timeout, this, [this]() {
@@ -136,6 +134,7 @@ EntityPropertySection::EntityPropertySection(QWidget* parent)
connect(m_introToggle, &QToolButton::clicked, this, [this]() {
setIntroSectionExpanded(!m_introContent->isVisible());
});
setIntroSectionExpanded(true);
connect(m_name, &QLineEdit::editingFinished, this, [this]() {
if (m_name) {
@@ -231,7 +230,7 @@ void EntityPropertySection::clearDisconnected() {
m_introVideo->blockSignals(false);
}
if (m_introImages) m_introImages->clear();
setIntroSectionExpanded(false);
setIntroSectionExpanded(true);
m_introBulkUpdate = false;
}
@@ -308,7 +307,6 @@ void EntityPropertySection::applyState(const EntityPropertyUiState& s) {
}
}
}
setIntroSectionExpanded(false);
m_introBulkUpdate = false;
}