chore: 格式化ElaWidgetTools代码

This commit is contained in:
sleepwithoutbz
2025-09-20 01:39:00 +08:00
parent d2fded145d
commit 4ab391f8a1
394 changed files with 10913 additions and 15860 deletions

View File

@@ -21,93 +21,67 @@
#include <QEvent>
#include <QLayout>
#include <QPropertyAnimation>
ElaNavigationBarPrivate::ElaNavigationBarPrivate(QObject* parent)
: QObject{parent}
{
}
ElaNavigationBarPrivate::ElaNavigationBarPrivate(QObject *parent) : QObject{parent} {}
ElaNavigationBarPrivate::~ElaNavigationBarPrivate()
{
}
ElaNavigationBarPrivate::~ElaNavigationBarPrivate() {}
void ElaNavigationBarPrivate::onNavigationButtonClicked()
{
void ElaNavigationBarPrivate::onNavigationButtonClicked() {
Q_Q(ElaNavigationBar);
if (_currentDisplayMode == ElaNavigationType::Compact)
{
if (_currentDisplayMode == ElaNavigationType::Compact) {
q->setDisplayMode(ElaNavigationType::Maximal);
}
else
{
} else {
q->setDisplayMode(ElaNavigationType::Compact);
}
}
void ElaNavigationBarPrivate::onNavigationOpenNewWindow(QString nodeKey)
{
void ElaNavigationBarPrivate::onNavigationOpenNewWindow(QString nodeKey) {
Q_Q(ElaNavigationBar);
const QMetaObject* meta = _pageMetaMap.value(nodeKey);
if (!meta)
{
const QMetaObject *meta = _pageMetaMap.value(nodeKey);
if (!meta) {
return;
}
QWidget* widget = static_cast<QWidget*>(meta->newInstance());
if (widget)
{
QWidget *widget = static_cast<QWidget *>(meta->newInstance());
if (widget) {
widget->setProperty("ElaPageKey", nodeKey);
widget->setProperty("ElaFloatParentWidget", QVariant::fromValue(q));
widget->installEventFilter(this);
ElaCustomTabWidget* floatWidget = new ElaCustomTabWidget(q);
ElaCustomTabWidget *floatWidget = new ElaCustomTabWidget(q);
floatWidget->addTab(widget, widget->windowIcon(), widget->windowTitle());
floatWidget->show();
Q_EMIT q->pageOpenInNewWindow(nodeKey);
}
}
void ElaNavigationBarPrivate::onNavigationRouteBack(QVariantMap routeData)
{
void ElaNavigationBarPrivate::onNavigationRouteBack(QVariantMap routeData) {
Q_Q(ElaNavigationBar);
QString pageKey = routeData.value("ElaPageKey").toString();
q->navigation(pageKey, false, true);
}
void ElaNavigationBarPrivate::onTreeViewClicked(const QModelIndex& index, bool isLogRoute, bool isRouteBack)
{
void ElaNavigationBarPrivate::onTreeViewClicked(const QModelIndex &index, bool isLogRoute, bool isRouteBack) {
Q_Q(ElaNavigationBar);
if (index.isValid())
{
ElaNavigationNode* node = static_cast<ElaNavigationNode*>(index.internalPointer());
if (!node)
{
if (index.isValid()) {
ElaNavigationNode *node = static_cast<ElaNavigationNode *>(index.internalPointer());
if (!node) {
return;
}
if (node->getIsExpanderNode())
{
if (node->getIsExpanderNode()) {
_expandOrCollpaseExpanderNode(node, !_navigationView->isExpanded(index));
}
else
{
if (node->getKeyPoints())
{
} else {
if (node->getKeyPoints()) {
node->setKeyPoints(0);
_navigationView->update();
}
ElaNavigationNode* selectedNode = _navigationModel->getSelectedNode();
if (selectedNode != node)
{
ElaNavigationNode *selectedNode = _navigationModel->getSelectedNode();
if (selectedNode != node) {
// 记录跳转
if (isLogRoute)
{
if (isLogRoute) {
QVariantMap routeData = QVariantMap();
QString pageKey;
if (selectedNode)
{
QString pageKey;
if (selectedNode) {
pageKey.append(selectedNode->getNodeKey());
}
else
{
if (_footerModel->getSelectedNode())
{
} else {
if (_footerModel->getSelectedNode()) {
pageKey.append(_footerModel->getSelectedNode()->getNodeKey());
}
}
@@ -116,8 +90,7 @@ void ElaNavigationBarPrivate::onTreeViewClicked(const QModelIndex& index, bool i
}
Q_EMIT q->navigationNodeClicked(ElaNavigationType::PageNode, node->getNodeKey(), isRouteBack);
if (_footerModel->getSelectedNode())
{
if (_footerModel->getSelectedNode()) {
_footerView->clearSelection();
QVariantMap footerPostData = QVariantMap();
footerPostData.insert("SelectMarkChanged", true);
@@ -128,25 +101,17 @@ void ElaNavigationBarPrivate::onTreeViewClicked(const QModelIndex& index, bool i
}
QVariantMap postData = QVariantMap();
postData.insert("SelectMarkChanged", true);
if (_navigationModel->getSelectedExpandedNode())
{
if (_navigationModel->getSelectedExpandedNode()) {
postData.insert("LastSelectedNode", QVariant::fromValue(_navigationModel->getSelectedExpandedNode()));
}
else
{
} else {
postData.insert("LastSelectedNode", QVariant::fromValue(_navigationModel->getSelectedNode()));
}
if (_currentDisplayMode == ElaNavigationType::Compact)
{
ElaNavigationNode* originNode = node->getOriginalNode();
if (originNode == node)
{
if (_currentDisplayMode == ElaNavigationType::Compact) {
ElaNavigationNode *originNode = node->getOriginalNode();
if (originNode == node) {
postData.insert("SelectedNode", QVariant::fromValue(node));
}
else
{
if (originNode == _navigationModel->getSelectedExpandedNode())
{
} else {
if (originNode == _navigationModel->getSelectedExpandedNode()) {
_navigationModel->setSelectedNode(node);
_resetNodeSelected();
return;
@@ -154,15 +119,12 @@ void ElaNavigationBarPrivate::onTreeViewClicked(const QModelIndex& index, bool i
_navigationModel->setSelectedExpandedNode(originNode);
postData.insert("SelectedNode", QVariant::fromValue(originNode));
}
}
else
{
} else {
postData.insert("SelectedNode", QVariant::fromValue(node));
}
_navigationModel->setSelectedNode(node);
_navigationView->navigationNodeStateChange(postData);
if (!node->getIsVisible() && _currentDisplayMode != ElaNavigationType::Compact)
{
if (!node->getIsVisible() && _currentDisplayMode != ElaNavigationType::Compact) {
_expandSelectedNodeParent();
}
}
@@ -171,32 +133,24 @@ void ElaNavigationBarPrivate::onTreeViewClicked(const QModelIndex& index, bool i
}
}
void ElaNavigationBarPrivate::onFooterViewClicked(const QModelIndex& index, bool isLogRoute, bool isRouteBack)
{
void ElaNavigationBarPrivate::onFooterViewClicked(const QModelIndex &index, bool isLogRoute, bool isRouteBack) {
Q_Q(ElaNavigationBar);
ElaNavigationNode* node = index.data(Qt::UserRole).value<ElaNavigationNode*>();
if (node->getKeyPoints())
{
ElaNavigationNode *node = index.data(Qt::UserRole).value<ElaNavigationNode *>();
if (node->getKeyPoints()) {
node->setKeyPoints(0);
_navigationView->update();
}
ElaNavigationNode* selectedNode = _footerModel->getSelectedNode();
ElaNavigationNode *selectedNode = _footerModel->getSelectedNode();
if (selectedNode != node)
{
if (selectedNode != node) {
// 记录跳转
if (isLogRoute && node->getIsHasFooterPage())
{
if (isLogRoute && node->getIsHasFooterPage()) {
QVariantMap routeData = QVariantMap();
QString pageKey;
if (selectedNode)
{
QString pageKey;
if (selectedNode) {
pageKey.append(selectedNode->getNodeKey());
}
else
{
if (_navigationModel->getSelectedNode())
{
} else {
if (_navigationModel->getSelectedNode()) {
pageKey.append(_navigationModel->getSelectedNode()->getNodeKey());
}
}
@@ -205,13 +159,13 @@ void ElaNavigationBarPrivate::onFooterViewClicked(const QModelIndex& index, bool
}
Q_EMIT q->navigationNodeClicked(ElaNavigationType::FooterNode, node->getNodeKey(), isRouteBack);
if (node->getIsHasFooterPage())
{
if (_navigationModel->getSelectedNode() || _navigationModel->getSelectedExpandedNode())
{
if (node->getIsHasFooterPage()) {
if (_navigationModel->getSelectedNode() || _navigationModel->getSelectedExpandedNode()) {
QVariantMap mainPostData = QVariantMap();
mainPostData.insert("SelectMarkChanged", true);
mainPostData.insert("LastSelectedNode", QVariant::fromValue(_navigationModel->getSelectedExpandedNode() ? _navigationModel->getSelectedExpandedNode() : _navigationModel->getSelectedNode()));
mainPostData.insert("LastSelectedNode",
QVariant::fromValue(_navigationModel->getSelectedExpandedNode() ? _navigationModel->getSelectedExpandedNode()
: _navigationModel->getSelectedNode()));
mainPostData.insert("SelectedNode", QVariant::fromValue(nullptr));
_navigationView->clearSelection();
_navigationView->navigationNodeStateChange(mainPostData);
@@ -230,64 +184,50 @@ void ElaNavigationBarPrivate::onFooterViewClicked(const QModelIndex& index, bool
}
}
bool ElaNavigationBarPrivate::eventFilter(QObject* watched, QEvent* event)
{
switch (event->type())
{
case QEvent::Show:
{
bool ElaNavigationBarPrivate::eventFilter(QObject *watched, QEvent *event) {
switch (event->type()) {
case QEvent::Show: {
QString nodeKey = watched->property("ElaPageKey").toString();
if (!nodeKey.isNull())
{
if (!nodeKey.isNull()) {
_pageNewWindowCountMap[nodeKey] += 1;
}
break;
}
case QEvent::HideToParent:
{
case QEvent::HideToParent: {
QString nodeKey = watched->property("ElaPageKey").toString();
if (!nodeKey.isNull())
{
if (!nodeKey.isNull()) {
_pageNewWindowCountMap[nodeKey] -= 1;
}
break;
}
default:
{
default: {
break;
}
}
return QObject::eventFilter(watched, event);
}
void ElaNavigationBarPrivate::_initNodeModelIndex(const QModelIndex& parentIndex)
{
void ElaNavigationBarPrivate::_initNodeModelIndex(const QModelIndex &parentIndex) {
int rowCount = _navigationModel->rowCount(parentIndex);
for (int row = 0; row < rowCount; ++row)
{
QModelIndex index = _navigationModel->index(row, 0, parentIndex);
ElaNavigationNode* childNode = static_cast<ElaNavigationNode*>(index.internalPointer());
for (int row = 0; row < rowCount; ++row) {
QModelIndex index = _navigationModel->index(row, 0, parentIndex);
ElaNavigationNode *childNode = static_cast<ElaNavigationNode *>(index.internalPointer());
childNode->setModelIndex(index);
if (_navigationModel->hasChildren(index))
{
if (_navigationModel->hasChildren(index)) {
_initNodeModelIndex(index);
}
}
}
void ElaNavigationBarPrivate::_resetNodeSelected()
{
void ElaNavigationBarPrivate::_resetNodeSelected() {
_navigationView->clearSelection();
ElaNavigationNode* selectedNode = _navigationModel->getSelectedNode();
if (!selectedNode || !selectedNode->getModelIndex().isValid())
{
ElaNavigationNode *selectedNode = _navigationModel->getSelectedNode();
if (!selectedNode || !selectedNode->getModelIndex().isValid()) {
return;
}
if (selectedNode->getParentNode()->getIsRootNode() || selectedNode->getIsVisible())
{
if (selectedNode->getParentNode()->getIsRootNode() || selectedNode->getIsVisible()) {
_navigationView->selectionModel()->select(selectedNode->getModelIndex(), QItemSelectionModel::Select);
if (_navigationModel->getSelectedExpandedNode())
{
if (_navigationModel->getSelectedExpandedNode()) {
QVariantMap postData = QVariantMap();
postData.insert("SelectMarkChanged", true);
postData.insert("LastSelectedNode", QVariant::fromValue(_navigationModel->getSelectedExpandedNode()));
@@ -295,35 +235,26 @@ void ElaNavigationBarPrivate::_resetNodeSelected()
_navigationView->navigationNodeStateChange(postData);
}
_navigationModel->setSelectedExpandedNode(nullptr);
}
else
{
ElaNavigationNode* parentNode = selectedNode->getParentNode();
while (parentNode && !parentNode->getParentNode()->getIsRootNode() && !parentNode->getIsVisible())
{
} else {
ElaNavigationNode *parentNode = selectedNode->getParentNode();
while (parentNode && !parentNode->getParentNode()->getIsRootNode() && !parentNode->getIsVisible()) {
parentNode = parentNode->getParentNode();
}
if (!parentNode)
{
if (!parentNode) {
return;
}
// 单级节点展开/收起时Mark变化
if (!_navigationModel->getSelectedExpandedNode())
{
if (!_navigationModel->getSelectedExpandedNode()) {
QVariantMap postData = QVariantMap();
postData.insert("SelectMarkChanged", true);
postData.insert("LastSelectedNode", QVariant::fromValue(_navigationModel->getSelectedNode()));
postData.insert("SelectedNode", QVariant::fromValue(parentNode));
_navigationView->navigationNodeStateChange(postData);
}
else
{
} else {
// 多级节点
if (_navigationModel->getSelectedExpandedNode() != parentNode)
{
if (_navigationModel->getSelectedExpandedNode() != parentNode) {
// 同一起源节点展开/收起时的Mark变化
if (_navigationModel->getSelectedExpandedNode()->getOriginalNode() == parentNode->getOriginalNode())
{
if (_navigationModel->getSelectedExpandedNode()->getOriginalNode() == parentNode->getOriginalNode()) {
QVariantMap postData = QVariantMap();
postData.insert("SelectMarkChanged", true);
postData.insert("LastSelectedNode", QVariant::fromValue(_navigationModel->getSelectedExpandedNode()));
@@ -337,11 +268,9 @@ void ElaNavigationBarPrivate::_resetNodeSelected()
}
}
void ElaNavigationBarPrivate::_expandSelectedNodeParent()
{
ElaNavigationNode* parentNode = _navigationModel->getSelectedNode()->getParentNode();
while (parentNode && !parentNode->getIsRootNode())
{
void ElaNavigationBarPrivate::_expandSelectedNodeParent() {
ElaNavigationNode *parentNode = _navigationModel->getSelectedNode()->getParentNode();
while (parentNode && !parentNode->getIsRootNode()) {
QVariantMap data;
data.insert("Expand", QVariant::fromValue(parentNode));
_navigationView->navigationNodeStateChange(data);
@@ -351,38 +280,28 @@ void ElaNavigationBarPrivate::_expandSelectedNodeParent()
}
}
void ElaNavigationBarPrivate::_expandOrCollpaseExpanderNode(ElaNavigationNode* node, bool isExpand)
{
if (_currentDisplayMode == ElaNavigationType::Compact)
{
if (node->getIsHasPageChild())
{
//展开菜单
ElaMenu* menu = _compactMenuMap.value(node);
if (menu)
{
void ElaNavigationBarPrivate::_expandOrCollpaseExpanderNode(ElaNavigationNode *node, bool isExpand) {
if (_currentDisplayMode == ElaNavigationType::Compact) {
if (node->getIsHasPageChild()) {
// 展开菜单
ElaMenu *menu = _compactMenuMap.value(node);
if (menu) {
QPoint nodeTopRight = _navigationView->mapToGlobal(_navigationView->visualRect(node->getModelIndex()).topRight());
menu->popup(QPoint(nodeTopRight.x() + 10, nodeTopRight.y()));
}
}
}
else
{
QModelIndex index = node->getModelIndex();
bool isExpanded = _navigationView->isExpanded(index);
if (node->getIsHasChild() && isExpand != isExpanded)
{
} else {
QModelIndex index = node->getModelIndex();
bool isExpanded = _navigationView->isExpanded(index);
if (node->getIsHasChild() && isExpand != isExpanded) {
QVariantMap data;
if (isExpanded)
{
if (isExpanded) {
// 收起
data.insert("Collapse", QVariant::fromValue(node));
node->setIsExpanded(isExpand);
_navigationView->navigationNodeStateChange(data);
_navigationView->collapse(index);
}
else
{
} else {
// 展开
data.insert("Expand", QVariant::fromValue(node));
node->setIsExpanded(true);
@@ -393,56 +312,47 @@ void ElaNavigationBarPrivate::_expandOrCollpaseExpanderNode(ElaNavigationNode* n
}
}
void ElaNavigationBarPrivate::_addStackedPage(QWidget* page, QString pageKey)
{
void ElaNavigationBarPrivate::_addStackedPage(QWidget *page, QString pageKey) {
Q_Q(ElaNavigationBar);
page->setProperty("ElaPageKey", pageKey);
Q_EMIT q->navigationNodeAdded(ElaNavigationType::PageNode, pageKey, page);
ElaNavigationNode* node = _navigationModel->getNavigationNode(pageKey);
QVariantMap suggestData;
ElaNavigationNode *node = _navigationModel->getNavigationNode(pageKey);
QVariantMap suggestData;
suggestData.insert("ElaNodeType", "Stacked");
suggestData.insert("ElaPageKey", pageKey);
QString suggestKey = _navigationSuggestBox->addSuggestion(node->getAwesome(), node->getNodeTitle(), suggestData);
_suggestKeyMap.insert(pageKey, suggestKey);
}
void ElaNavigationBarPrivate::_addFooterPage(QWidget* page, QString footKey)
{
void ElaNavigationBarPrivate::_addFooterPage(QWidget *page, QString footKey) {
Q_Q(ElaNavigationBar);
Q_EMIT q->navigationNodeAdded(ElaNavigationType::FooterNode, footKey, page);
if (page)
{
if (page) {
page->setProperty("ElaPageKey", footKey);
}
_footerView->setFixedHeight(40 * _footerModel->getFooterNodeCount());
ElaNavigationNode* node = _footerModel->getNavigationNode(footKey);
QVariantMap suggestData;
ElaNavigationNode *node = _footerModel->getNavigationNode(footKey);
QVariantMap suggestData;
suggestData.insert("ElaNodeType", "Footer");
suggestData.insert("ElaPageKey", footKey);
QString suggestKey = _navigationSuggestBox->addSuggestion(node->getAwesome(), node->getNodeTitle(), suggestData);
_suggestKeyMap.insert(footKey, suggestKey);
}
void ElaNavigationBarPrivate::_raiseNavigationBar()
{
void ElaNavigationBarPrivate::_raiseNavigationBar() {
Q_Q(ElaNavigationBar);
q->raise();
}
void ElaNavigationBarPrivate::_doComponentAnimation(ElaNavigationType::NavigationDisplayMode displayMode, bool isAnimation)
{
switch (displayMode)
{
case ElaNavigationType::Minimal:
{
void ElaNavigationBarPrivate::_doComponentAnimation(ElaNavigationType::NavigationDisplayMode displayMode, bool isAnimation) {
switch (displayMode) {
case ElaNavigationType::Minimal: {
_doNavigationBarWidthAnimation(displayMode, isAnimation);
if (_currentDisplayMode == ElaNavigationType::Maximal)
{
if (_currentDisplayMode == ElaNavigationType::Maximal) {
_searchButton->setVisible(true);
_userCard->setVisible(false);
_navigationSuggestBox->setVisible(false);
if (_isShowUserCard)
{
if (_isShowUserCard) {
_userButton->setVisible(true);
}
_handleNavigationExpandState(true);
@@ -450,12 +360,10 @@ void ElaNavigationBarPrivate::_doComponentAnimation(ElaNavigationType::Navigatio
_currentDisplayMode = displayMode;
break;
}
case ElaNavigationType::Compact:
{
case ElaNavigationType::Compact: {
_doNavigationBarWidthAnimation(displayMode, isAnimation);
_doNavigationViewWidthAnimation(isAnimation);
if (_currentDisplayMode != ElaNavigationType::Minimal)
{
if (_currentDisplayMode != ElaNavigationType::Minimal) {
_handleMaximalToCompactLayout();
_doNavigationButtonAnimation(true, isAnimation);
_doSearchButtonAnimation(true, isAnimation);
@@ -466,8 +374,7 @@ void ElaNavigationBarPrivate::_doComponentAnimation(ElaNavigationType::Navigatio
_currentDisplayMode = displayMode;
break;
}
case ElaNavigationType::Maximal:
{
case ElaNavigationType::Maximal: {
_resetLayout();
_handleCompactToMaximalLayout();
_doNavigationBarWidthAnimation(displayMode, isAnimation);
@@ -479,154 +386,120 @@ void ElaNavigationBarPrivate::_doComponentAnimation(ElaNavigationType::Navigatio
_handleNavigationExpandState(false);
break;
}
default:
{
default: {
break;
}
}
}
void ElaNavigationBarPrivate::_handleNavigationExpandState(bool isSave)
{
if (isSave)
{
void ElaNavigationBarPrivate::_handleNavigationExpandState(bool isSave) {
if (isSave) {
// 保存展开状态 收起根节点所有子树
_lastExpandedNodesList = _navigationModel->getRootExpandedNodes();
for (auto node: _lastExpandedNodesList)
{
for (auto node : _lastExpandedNodesList) {
onTreeViewClicked(node->getModelIndex(), false);
}
}
else
{
} else {
// 修正动画覆盖
_navigationView->resize(_pNavigationBarWidth - 5, _navigationView->height());
for (auto node: _lastExpandedNodesList)
{
for (auto node : _lastExpandedNodesList) {
onTreeViewClicked(node->getModelIndex(), false);
}
}
}
void ElaNavigationBarPrivate::_handleMaximalToCompactLayout()
{
void ElaNavigationBarPrivate::_handleMaximalToCompactLayout() {
// 动画过程布局
while (_navigationButtonLayout->count())
{
while (_navigationButtonLayout->count()) {
_navigationButtonLayout->takeAt(0);
}
if (_isShowUserCard)
{
if (_isShowUserCard) {
_navigationButtonLayout->addSpacing(76);
}
else
{
} else {
_navigationButtonLayout->addSpacing(40);
}
_navigationSuggestLayout->addStretch();
while (_userButtonLayout->count())
{
while (_userButtonLayout->count()) {
_userButtonLayout->takeAt(0);
}
_userButtonLayout->addSpacing(36);
}
void ElaNavigationBarPrivate::_handleCompactToMaximalLayout()
{
void ElaNavigationBarPrivate::_handleCompactToMaximalLayout() {
// 动画过程布局
while (_navigationButtonLayout->count())
{
while (_navigationButtonLayout->count()) {
_navigationButtonLayout->takeAt(0);
}
_navigationButtonLayout->addSpacing(38);
_navigationSuggestLayout->insertSpacing(0, 46);
while (_userButtonLayout->count())
{
while (_userButtonLayout->count()) {
_userButtonLayout->takeAt(0);
}
if (_isShowUserCard)
{
if (_isShowUserCard) {
_userButtonLayout->addSpacing(74);
}
}
void ElaNavigationBarPrivate::_resetLayout()
{
void ElaNavigationBarPrivate::_resetLayout() {
// 恢复初始布局
while (_navigationButtonLayout->count())
{
while (_navigationButtonLayout->count()) {
_navigationButtonLayout->takeAt(0);
}
_navigationButtonLayout->addWidget(_navigationButton);
_navigationButtonLayout->addWidget(_searchButton);
while (_navigationSuggestLayout->count())
{
while (_navigationSuggestLayout->count()) {
_navigationSuggestLayout->takeAt(0);
}
_navigationSuggestLayout->addLayout(_navigationButtonLayout);
_navigationSuggestLayout->addWidget(_navigationSuggestBox);
while (_userButtonLayout->count())
{
while (_userButtonLayout->count()) {
_userButtonLayout->takeAt(0);
}
_userButtonLayout->addWidget(_userButton);
}
void ElaNavigationBarPrivate::_doNavigationBarWidthAnimation(ElaNavigationType::NavigationDisplayMode displayMode, bool isAnimation)
{
void ElaNavigationBarPrivate::_doNavigationBarWidthAnimation(ElaNavigationType::NavigationDisplayMode displayMode, bool isAnimation) {
Q_Q(ElaNavigationBar);
QPropertyAnimation* navigationBarWidthAnimation = new QPropertyAnimation(q, "maximumWidth");
QPropertyAnimation *navigationBarWidthAnimation = new QPropertyAnimation(q, "maximumWidth");
navigationBarWidthAnimation->setEasingCurve(QEasingCurve::OutCubic);
navigationBarWidthAnimation->setStartValue(q->width());
navigationBarWidthAnimation->setDuration(isAnimation ? 285 : 0);
switch (displayMode)
{
case ElaNavigationType::Minimal:
{
connect(navigationBarWidthAnimation, &QPropertyAnimation::valueChanged, this, [=](const QVariant& value) {
q->setFixedWidth(value.toUInt());
});
switch (displayMode) {
case ElaNavigationType::Minimal: {
connect(navigationBarWidthAnimation, &QPropertyAnimation::valueChanged, this,
[=](const QVariant &value) { q->setFixedWidth(value.toUInt()); });
navigationBarWidthAnimation->setEndValue(0);
break;
}
case ElaNavigationType::Compact:
{
connect(navigationBarWidthAnimation, &QPropertyAnimation::valueChanged, this, [=](const QVariant& value) {
q->setFixedWidth(value.toUInt());
});
case ElaNavigationType::Compact: {
connect(navigationBarWidthAnimation, &QPropertyAnimation::valueChanged, this,
[=](const QVariant &value) { q->setFixedWidth(value.toUInt()); });
navigationBarWidthAnimation->setEndValue(47);
break;
}
case ElaNavigationType::Maximal:
{
connect(navigationBarWidthAnimation, &QPropertyAnimation::finished, this, [=]() {
_resetLayout();
});
connect(navigationBarWidthAnimation, &QPropertyAnimation::valueChanged, this, [=](const QVariant& value) {
q->setFixedWidth(value.toUInt());
});
case ElaNavigationType::Maximal: {
connect(navigationBarWidthAnimation, &QPropertyAnimation::finished, this, [=]() { _resetLayout(); });
connect(navigationBarWidthAnimation, &QPropertyAnimation::valueChanged, this,
[=](const QVariant &value) { q->setFixedWidth(value.toUInt()); });
navigationBarWidthAnimation->setEndValue(_pNavigationBarWidth);
break;
}
default:
{
default: {
break;
}
}
navigationBarWidthAnimation->start(QAbstractAnimation::DeleteWhenStopped);
}
void ElaNavigationBarPrivate::_doNavigationViewWidthAnimation(bool isAnimation)
{
QPropertyAnimation* navigationViewWidthAnimation = new QPropertyAnimation(this, "pNavigationViewWidth");
connect(navigationViewWidthAnimation, &QPropertyAnimation::valueChanged, this, [=](const QVariant& value) {
_navigationView->setColumnWidth(0, value.toUInt());
});
void ElaNavigationBarPrivate::_doNavigationViewWidthAnimation(bool isAnimation) {
QPropertyAnimation *navigationViewWidthAnimation = new QPropertyAnimation(this, "pNavigationViewWidth");
connect(navigationViewWidthAnimation, &QPropertyAnimation::valueChanged, this,
[=](const QVariant &value) { _navigationView->setColumnWidth(0, value.toUInt()); });
navigationViewWidthAnimation->setEasingCurve(QEasingCurve::OutCubic);
navigationViewWidthAnimation->setStartValue(_navigationView->columnWidth(0));
navigationViewWidthAnimation->setEndValue(40);
@@ -634,40 +507,28 @@ void ElaNavigationBarPrivate::_doNavigationViewWidthAnimation(bool isAnimation)
navigationViewWidthAnimation->start(QAbstractAnimation::DeleteWhenStopped);
}
void ElaNavigationBarPrivate::_doNavigationButtonAnimation(bool isCompact, bool isAnimation)
{
if (isCompact)
{
void ElaNavigationBarPrivate::_doNavigationButtonAnimation(bool isCompact, bool isAnimation) {
if (isCompact) {
// 导航按钮
QPropertyAnimation* navigationButtonAnimation = new QPropertyAnimation(_navigationButton, "pos");
connect(navigationButtonAnimation, &QPropertyAnimation::finished, this, [=]() {
_resetLayout();
});
QPropertyAnimation *navigationButtonAnimation = new QPropertyAnimation(_navigationButton, "pos");
connect(navigationButtonAnimation, &QPropertyAnimation::finished, this, [=]() { _resetLayout(); });
QPoint navigationButtonPos = _navigationButton->pos();
navigationButtonAnimation->setStartValue(navigationButtonPos);
if (_isShowUserCard)
{
if (_isShowUserCard) {
navigationButtonAnimation->setEndValue(QPoint(0, 56));
}
else
{
} else {
navigationButtonAnimation->setEndValue(navigationButtonPos);
}
navigationButtonAnimation->setEasingCurve(QEasingCurve::OutCubic);
navigationButtonAnimation->setDuration(isAnimation ? 285 : 0);
navigationButtonAnimation->start(QAbstractAnimation::DeleteWhenStopped);
}
else
{
QPropertyAnimation* navigationButtonAnimation = new QPropertyAnimation(_navigationButton, "pos");
QPoint navigationButtonPos = _navigationButton->pos();
} else {
QPropertyAnimation *navigationButtonAnimation = new QPropertyAnimation(_navigationButton, "pos");
QPoint navigationButtonPos = _navigationButton->pos();
navigationButtonAnimation->setStartValue(navigationButtonPos);
if (_isShowUserCard)
{
if (_isShowUserCard) {
navigationButtonAnimation->setEndValue(QPoint(0, 94));
}
else
{
} else {
navigationButtonAnimation->setEndValue(navigationButtonPos);
}
navigationButtonAnimation->setEasingCurve(QEasingCurve::InOutSine);
@@ -676,20 +537,15 @@ void ElaNavigationBarPrivate::_doNavigationButtonAnimation(bool isCompact, bool
}
}
void ElaNavigationBarPrivate::_doSearchButtonAnimation(bool isCompact, bool isAnimation)
{
if (isCompact)
{
void ElaNavigationBarPrivate::_doSearchButtonAnimation(bool isCompact, bool isAnimation) {
if (isCompact) {
QPoint navigationButtonPos = _navigationButton->pos();
// 搜索按钮
QPropertyAnimation* searchButtonAnimation = new QPropertyAnimation(_searchButton, "pos");
if (_isShowUserCard)
{
QPropertyAnimation *searchButtonAnimation = new QPropertyAnimation(_searchButton, "pos");
if (_isShowUserCard) {
searchButtonAnimation->setStartValue(QPoint(200, navigationButtonPos.y()));
searchButtonAnimation->setEndValue(QPoint(0, navigationButtonPos.y()));
}
else
{
} else {
searchButtonAnimation->setStartValue(QPoint(200, navigationButtonPos.y() + 38));
searchButtonAnimation->setEndValue(QPoint(0, navigationButtonPos.y() + 38));
}
@@ -697,47 +553,37 @@ void ElaNavigationBarPrivate::_doSearchButtonAnimation(bool isCompact, bool isAn
searchButtonAnimation->setDuration(isAnimation ? 285 : 0);
searchButtonAnimation->start(QAbstractAnimation::DeleteWhenStopped);
_searchButton->setVisible(true);
}
else
{
} else {
_searchButton->setVisible(false);
}
}
void ElaNavigationBarPrivate::_doUserButtonAnimation(bool isCompact, bool isAnimation)
{
if (isCompact)
{
void ElaNavigationBarPrivate::_doUserButtonAnimation(bool isCompact, bool isAnimation) {
if (isCompact) {
_userCard->setVisible(false);
if (_isShowUserCard)
{
if (_isShowUserCard) {
_userButton->setVisible(true);
}
QPropertyAnimation* userButtonAnimation = new QPropertyAnimation(_userButton, "geometry");
connect(userButtonAnimation, &QPropertyAnimation::valueChanged, this, [=](const QVariant& value) {
_userButton->setFixedSize(value.toRect().size());
});
QPropertyAnimation *userButtonAnimation = new QPropertyAnimation(_userButton, "geometry");
connect(userButtonAnimation, &QPropertyAnimation::valueChanged, this,
[=](const QVariant &value) { _userButton->setFixedSize(value.toRect().size()); });
userButtonAnimation->setEasingCurve(QEasingCurve::OutCubic);
userButtonAnimation->setStartValue(QRect(13, 18, 64, 64));
userButtonAnimation->setEndValue(QRect(3, 10, 36, 36));
userButtonAnimation->setDuration(isAnimation ? 285 : 0);
userButtonAnimation->start(QAbstractAnimation::DeleteWhenStopped);
}
else
{
QPropertyAnimation* userButtonAnimation = new QPropertyAnimation(_userButton, "geometry");
} else {
QPropertyAnimation *userButtonAnimation = new QPropertyAnimation(_userButton, "geometry");
connect(userButtonAnimation, &QPropertyAnimation::finished, this, [=]() {
if (_isShowUserCard)
{
if (_isShowUserCard) {
_userCard->setVisible(true);
}
_userButton->setFixedSize(36, 36);
_userButton->setGeometry(QRect(3, 10, 36, 36));
_userButton->setVisible(false);
});
connect(userButtonAnimation, &QPropertyAnimation::valueChanged, this, [=](const QVariant& value) {
_userButton->setFixedSize(value.toRect().size());
});
connect(userButtonAnimation, &QPropertyAnimation::valueChanged, this,
[=](const QVariant &value) { _userButton->setFixedSize(value.toRect().size()); });
userButtonAnimation->setEasingCurve(QEasingCurve::InOutSine);
userButtonAnimation->setStartValue(QRect(3, 10, 36, 36));
userButtonAnimation->setEndValue(QRect(13, 18, 64, 64));