87 lines
3.5 KiB
C++
87 lines
3.5 KiB
C++
#include "panels/columns/ColumnDrawer.hpp"
|
||
#include "panels/columns/Column2DDataset.hpp"
|
||
#include "panels/columns/CategoryAnalysisTab.hpp"
|
||
#include <algorithm>
|
||
|
||
#include "Glyphs.hpp"
|
||
#include "Theme.hpp"
|
||
#include <QHBoxLayout>
|
||
#include <QPushButton>
|
||
#include <QResizeEvent>
|
||
#include <QTabBar>
|
||
#include <QTabWidget>
|
||
|
||
namespace geopro::app {
|
||
|
||
ColumnDrawer::ColumnDrawer(QWidget* parent, geopro::data::DatasetFieldDictionary* dict)
|
||
: QWidget(parent)
|
||
{
|
||
col2D_ = new Column2DDataset(this);
|
||
analysisTab_ = new CategoryAnalysisTab(dict, this);
|
||
|
||
// Tab 容器(body_):两 tab(三维分析[分段] / 二维分析)。
|
||
auto* tabs = new QTabWidget(this);
|
||
body_ = tabs;
|
||
tabs->addTab(analysisTab_, QStringLiteral("三维分析"));
|
||
tabs->addTab(col2D_, QStringLiteral("二维分析"));
|
||
|
||
// 折叠按钮:固定宽 18px,垂直拉伸。
|
||
// 用 SVG 图标(makeGlyph)而非 ◀/▶ 文字——三角符(U+25C0/25B6)不在 YaHei,作按钮文字会触发
|
||
// Qt 字体回退,本机 DirectWrite 在回退枚举时崩(0xc0000005)。SVG 图标走 QIcon 不做字体整形,规避之。
|
||
toggleBtn_ = new QPushButton(this);
|
||
toggleBtn_->setIcon(geopro::app::makeGlyph(Glyph::ChevronLeft,
|
||
geopro::app::tokenColor("text/secondary"), 14));
|
||
toggleBtn_->setFixedWidth(18);
|
||
toggleBtn_->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
||
toggleBtn_->setCursor(Qt::PointingHandCursor);
|
||
toggleBtn_->setToolTip(QStringLiteral("折叠 / 展开"));
|
||
geopro::app::applyTokenizedStyleSheet(toggleBtn_,
|
||
QStringLiteral("QPushButton{background:{{bg/panel-subtle}};color:{{text/secondary}};"
|
||
"border:none;border-left:1px solid {{border/default}};font-size:12px;}"
|
||
"QPushButton:hover{background:{{bg/hover}};color:{{accent/primary}};}"));
|
||
connect(toggleBtn_, &QPushButton::clicked, this, &ColumnDrawer::toggleCollapsed);
|
||
|
||
// 根布局:[body_ | toggleBtn_],无边距
|
||
auto* root = new QHBoxLayout(this);
|
||
root->setContentsMargins(0, 0, 0, 0);
|
||
root->setSpacing(0);
|
||
root->addWidget(body_, 1);
|
||
root->addWidget(toggleBtn_, 0);
|
||
|
||
// 可调宽:min 180 / max 560(外层 QSplitter 拖动改宽)。
|
||
setMinimumWidth(180);
|
||
setMaximumWidth(560);
|
||
}
|
||
|
||
void ColumnDrawer::resizeEvent(QResizeEvent* e)
|
||
{
|
||
QWidget::resizeEvent(e);
|
||
// 两 tab 平分抽屉宽度填满(带样式表的 tab 不响应 setExpanding,须按 barWidth/n 显式给宽)。
|
||
// 消除旧 3 栏布局遗留的右侧空白——重构成 2 栏后不再三分、留空第三位。
|
||
if (auto* tabs = qobject_cast<QTabWidget*>(body_)) {
|
||
const int n = tabs->count();
|
||
if (n > 0 && tabs->width() > 0) {
|
||
const int w = std::max(40, tabs->width() / n - 6); // 减 margin-right(4)余量
|
||
tabs->tabBar()->setStyleSheet(QStringLiteral("QTabBar::tab{width:%1px;}").arg(w));
|
||
}
|
||
}
|
||
}
|
||
|
||
void ColumnDrawer::toggleCollapsed()
|
||
{
|
||
collapsed_ = !collapsed_;
|
||
body_->setVisible(!collapsed_);
|
||
toggleBtn_->setIcon(geopro::app::makeGlyph(collapsed_ ? Glyph::ChevronRight : Glyph::ChevronLeft,
|
||
geopro::app::tokenColor("text/secondary"), 14));
|
||
// 折叠后只保留按钮宽度;展开恢复可调范围
|
||
setMinimumWidth(collapsed_ ? 0 : 180);
|
||
setMaximumWidth(collapsed_ ? 18 : 560);
|
||
}
|
||
|
||
void ColumnDrawer::expand()
|
||
{
|
||
if (collapsed_) toggleCollapsed(); // 仅在折叠时展开
|
||
}
|
||
|
||
} // namespace geopro::app
|