155 lines
6.8 KiB
C++
155 lines
6.8 KiB
C++
#ifndef Navigate_Bar_H
|
|
#define Navigate_Bar_H
|
|
#include "function/function.export.h"
|
|
#include "global.h"
|
|
class Delegate_导航 : public QStyledItemDelegate {
|
|
public:
|
|
using QStyledItemDelegate::QStyledItemDelegate;
|
|
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override {
|
|
painter->save();
|
|
auto dd = index.data(Qt::DisplayRole).value<导航_Dat>();
|
|
if (std::holds_alternative<导航_Dat1>(dd.data))
|
|
{
|
|
bool selected = option.state & QStyle::State_Selected;
|
|
if (selected)
|
|
{
|
|
painter->setPen(Qt::NoPen);
|
|
// painter->setBrush(QColor("#ADD8E6"));
|
|
painter->setBrush(base);
|
|
painter->drawRoundedRect(option.rect, 4, 4);
|
|
}
|
|
auto& d = std::get<导航_Dat1>(dd.data);
|
|
QColor cc = selected ? Qt::white : d.icon.get_color();
|
|
int height = 20;
|
|
int y = (option.rect.height() - height) / 2;
|
|
QRect iconRect = QRect(option.rect.left() + 8, option.rect.y() + y, height, height);
|
|
d.icon.render(painter, iconRect, cc);
|
|
QRect textRect = option.rect;
|
|
textRect.setLeft(iconRect.right() + 8);
|
|
painter->setPen(QPen(cc));
|
|
painter->drawText(textRect, Qt::AlignVCenter, d.text);
|
|
}
|
|
if (std::holds_alternative<导航_Dat2>(dd.data))
|
|
{
|
|
auto& d = std::get<导航_Dat2>(dd.data);
|
|
QRect textRect = option.rect;
|
|
// painter->drawRect(textRect);
|
|
painter->setPen(QPen(Qt::darkGray));
|
|
painter->setFont(get_font());
|
|
painter->drawText(textRect, Qt::AlignVCenter, d.text);
|
|
painter->drawLine(textRect.bottomLeft(), textRect.bottomRight());
|
|
}
|
|
painter->restore();
|
|
}
|
|
QFont get_font() const {
|
|
QFont f;
|
|
f.setPixelSize(18);
|
|
return f;
|
|
}
|
|
QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override {
|
|
auto dd = index.data(Qt::DisplayRole).value<导航_Dat>();
|
|
if (std::holds_alternative<导航_Dat1>(dd.data))
|
|
{
|
|
auto& d = std::get<导航_Dat1>(dd.data);
|
|
QString text = d.text;
|
|
int width = option.rect.width(); // 视图宽度
|
|
QFontMetrics fm(option.font); // 获取字体度量
|
|
int textHeight =
|
|
fm.boundingRect(QRect(0, 0, width, 0), Qt::TextWordWrap, text).height(); // 计算多行文本的高度
|
|
int extraPadding = 10; // 额外的间距
|
|
return QSize(width, textHeight + extraPadding); // 返回计算后的尺寸
|
|
}
|
|
if (std::holds_alternative<导航_Dat2>(dd.data))
|
|
{
|
|
auto& d = std::get<导航_Dat2>(dd.data);
|
|
QString text = d.text;
|
|
QFontMetrics fm(get_font());
|
|
int extraPadding = 20; // 额外的间距
|
|
return QSize(fm.horizontalAdvance(text), fm.height() + extraPadding); // 返回计算后的
|
|
}
|
|
return {0, 20};
|
|
}
|
|
};
|
|
class View_导航 : public QListView {
|
|
public:
|
|
explicit View_导航(QWidget* parent = nullptr) : QListView(parent) {
|
|
setFrameShape(QFrame::NoFrame);
|
|
model = new Model_导航<导航_Dat>(this);
|
|
QAbstractItemView::setModel(model);
|
|
setItemDelegate(new Delegate_导航(this));
|
|
QObject::connect(this, &QListView::clicked, [&](const QModelIndex& index) {
|
|
导航_Dat it = model->data(index, Qt::DisplayRole).value<导航_Dat>();
|
|
if (click) click(&it);
|
|
});
|
|
setStyleSheet("background: rgba(0, 0, 0, 0);");
|
|
setSpacing(2);
|
|
}
|
|
protected:
|
|
void paintEvent(QPaintEvent* e) override {
|
|
QPainter painter(viewport()); // 在视图区域绘制
|
|
QListView::paintEvent(e);
|
|
}
|
|
public:
|
|
std::function<void(导航_Dat*)> click = nullptr;
|
|
QVector<导航_Dat> items;
|
|
void update_model() { model->setDataList(items); }
|
|
private:
|
|
Model_导航<导航_Dat>* model;
|
|
};
|
|
class Navigate_Bar : public QWidget {
|
|
public:
|
|
View_导航* w;
|
|
QVBoxLayout* layout;
|
|
void set_click(const std::function<void(导航_Dat*)>& click) { w->click = click; }
|
|
采集预处理* m采集预处理;
|
|
信号侦察* m信号侦察;
|
|
信号处理* m信号处理;
|
|
信号生成* m信号生成;
|
|
信号对消* m信号对消;
|
|
存储列表* m存储列表;
|
|
protected:
|
|
void paintEvent(QPaintEvent* event) override {
|
|
QPainter painter(this);
|
|
painter.setRenderHints(QPainter::Antialiasing);
|
|
painter.setPen(Qt::NoPen);
|
|
painter.setBrush(Qt::white);
|
|
painter.drawRoundedRect(rect(), 8, 8);
|
|
painter.end();
|
|
}
|
|
public:
|
|
Navigate_Bar() {
|
|
layout = new QVBoxLayout(this);
|
|
w = new View_导航;
|
|
m采集预处理 = new 采集预处理;
|
|
m信号侦察 = new 信号侦察;
|
|
m信号处理 = new 信号处理;
|
|
m信号生成 = new 信号生成;
|
|
m信号对消 = new 信号对消;
|
|
m存储列表 = new 存储列表;
|
|
QColor c = Qt::darkGray;
|
|
w->items.push_back(导航_Dat(导航_Dat2{"功能模块"}));
|
|
w->items.push_back(
|
|
导航_Dat(导航_Dat1{"采集预处理\n\t\t999.999MHZ", "采集预处理", "F信号 载频、能量、用户聚类",
|
|
SVGImage_Render().set_path(":/filter_1.svg").set_color(c).create(), m采集预处理}));
|
|
w->items.push_back(
|
|
导航_Dat(导航_Dat1{"信号侦察\n\tF信号侦察\n\t\t\t\t6/44", "信号侦察", "F信号 载频、能量、用户聚类",
|
|
SVGImage_Render().set_path(":/filter_2.svg").set_color(c).create(), m信号侦察}));
|
|
w->items.push_back(
|
|
导航_Dat(导航_Dat1{"信号处理", "信号处理", "F信号 载频、能量、用户聚类",
|
|
SVGImage_Render().set_path(":/filter_3.svg").set_color(c).create(), m信号处理}));
|
|
w->items.push_back(
|
|
导航_Dat(导航_Dat1{"信号生成", "信号生成", "F信号 载频、能量、用户聚类",
|
|
SVGImage_Render().set_path(":/filter_4.svg").set_color(c).create(), m信号生成}));
|
|
w->items.push_back(
|
|
导航_Dat(导航_Dat1{"信号对消", "信号对消", "F信号 载频、能量、用户聚类",
|
|
SVGImage_Render().set_path(":/filter_5.svg").set_color(c).create(), m信号对消}));
|
|
w->items.push_back(导航_Dat(导航_Dat2{"数据存储"}));
|
|
w->items.push_back(
|
|
导航_Dat(导航_Dat1{"存储列表\n\t\t1/60", "存储列表", "F信号 载频、能量、用户聚类",
|
|
SVGImage_Render().set_path(":/filter_1.svg").set_color(c).create(), m存储列表}));
|
|
w->update_model();
|
|
layout->addWidget(w);
|
|
}
|
|
};
|
|
#endif // FUNCTION_BAR_H
|