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

@@ -14,9 +14,7 @@
#include "ElaNavigationStyle.h"
#include "ElaScrollBar.h"
#include "ElaToolTip.h"
ElaNavigationView::ElaNavigationView(QWidget* parent)
: QTreeView(parent)
{
ElaNavigationView::ElaNavigationView(QWidget *parent) : QTreeView(parent) {
setObjectName("ElaNavigationView");
setStyleSheet("#ElaNavigationView{background-color:transparent;}");
setAnimated(true);
@@ -30,14 +28,12 @@ ElaNavigationView::ElaNavigationView(QWidget* parent)
// 滚动条设置
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
ElaScrollBar* vScrollBar = new ElaScrollBar(this);
connect(vScrollBar, &ElaScrollBar::rangeAnimationFinished, this, [=]() {
doItemsLayout();
});
ElaScrollBar *vScrollBar = new ElaScrollBar(this);
connect(vScrollBar, &ElaScrollBar::rangeAnimationFinished, this, [=]() { doItemsLayout(); });
setVerticalScrollBar(vScrollBar);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
ElaScrollBar* floatVScrollBar = new ElaScrollBar(vScrollBar, this);
ElaScrollBar *floatVScrollBar = new ElaScrollBar(vScrollBar, this);
floatVScrollBar->setIsAnimation(true);
floatVScrollBar->installEventFilter(this);
@@ -46,7 +42,7 @@ ElaNavigationView::ElaNavigationView(QWidget* parent)
setStyle(_navigationStyle);
QScroller::grabGesture(this->viewport(), QScroller::LeftMouseButtonGesture);
QScroller* scroller = QScroller::scroller(this->viewport());
QScroller *scroller = QScroller::scroller(this->viewport());
QScrollerProperties properties = scroller->scrollerProperties();
properties.setScrollMetric(QScrollerProperties::MousePressEventDelay, 0);
properties.setScrollMetric(QScrollerProperties::HorizontalOvershootPolicy, QScrollerProperties::OvershootAlwaysOff);
@@ -57,13 +53,10 @@ ElaNavigationView::ElaNavigationView(QWidget* parent)
scroller->setScrollerProperties(properties);
connect(scroller, &QScroller::stateChanged, this, [=](QScroller::State newstate) {
if (newstate == QScroller::Pressed)
{
if (newstate == QScroller::Pressed) {
_navigationStyle->setPressIndex(indexAt(mapFromGlobal(QCursor::pos())));
viewport()->update();
}
else if (newstate == QScroller::Scrolling || newstate == QScroller::Inactive)
{
} else if (newstate == QScroller::Scrolling || newstate == QScroller::Inactive) {
_navigationStyle->setPressIndex(QModelIndex());
}
});
@@ -74,110 +67,82 @@ ElaNavigationView::ElaNavigationView(QWidget* parent)
_compactToolTip = new ElaToolTip(this);
}
ElaNavigationView::~ElaNavigationView()
{
}
ElaNavigationView::~ElaNavigationView() {}
void ElaNavigationView::navigationNodeStateChange(QVariantMap data)
{
this->_navigationStyle->navigationNodeStateChange(data);
}
void ElaNavigationView::navigationNodeStateChange(QVariantMap data) { this->_navigationStyle->navigationNodeStateChange(data); }
void ElaNavigationView::onCustomContextMenuRequested(const QPoint& pos)
{
if (!_pNavigationBarPrivate->_pIsAllowPageOpenInNewWindow)
{
void ElaNavigationView::onCustomContextMenuRequested(const QPoint &pos) {
if (!_pNavigationBarPrivate->_pIsAllowPageOpenInNewWindow) {
return;
}
QModelIndex posIndex = indexAt(pos);
if (!posIndex.isValid())
{
if (!posIndex.isValid()) {
return;
}
ElaNavigationNode* posNode = static_cast<ElaNavigationNode*>(posIndex.internalPointer());
if (!posNode->getIsExpanderNode())
{
ElaNavigationNode *posNode = static_cast<ElaNavigationNode *>(posIndex.internalPointer());
if (!posNode->getIsExpanderNode()) {
ElaMenu menu;
menu.setMenuItemHeight(27);
QAction* openAction = menu.addElaIconAction(ElaIconType::ObjectGroup, "在新窗口中打开");
connect(openAction, &QAction::triggered, this, [=]() {
Q_EMIT navigationOpenNewWindow(posNode->getNodeKey());
});
QAction *openAction = menu.addElaIconAction(ElaIconType::ObjectGroup, "在新窗口中打开");
connect(openAction, &QAction::triggered, this, [=]() { Q_EMIT navigationOpenNewWindow(posNode->getNodeKey()); });
menu.exec(mapToGlobal(pos));
}
}
void ElaNavigationView::mouseMoveEvent(QMouseEvent* event)
{
if (_pNavigationBarPrivate->_currentDisplayMode == ElaNavigationType::NavigationDisplayMode::Compact)
{
void ElaNavigationView::mouseMoveEvent(QMouseEvent *event) {
if (_pNavigationBarPrivate->_currentDisplayMode == ElaNavigationType::NavigationDisplayMode::Compact) {
QModelIndex posIndex = indexAt(event->pos());
if (!posIndex.isValid())
{
if (!posIndex.isValid()) {
_compactToolTip->hide();
return;
}
ElaNavigationNode* posNode = static_cast<ElaNavigationNode*>(posIndex.internalPointer());
ElaNavigationNode *posNode = static_cast<ElaNavigationNode *>(posIndex.internalPointer());
_compactToolTip->setToolTip(posNode->getNodeTitle());
_compactToolTip->updatePos();
_compactToolTip->show();
}
else
{
} else {
_compactToolTip->hide();
}
QTreeView::mouseMoveEvent(event);
}
void ElaNavigationView::mouseDoubleClickEvent(QMouseEvent* event)
{
void ElaNavigationView::mouseDoubleClickEvent(QMouseEvent *event) {
_navigationStyle->setPressIndex(indexAt(event->pos()));
viewport()->update();
QTreeView::mouseDoubleClickEvent(event);
}
void ElaNavigationView::mouseReleaseEvent(QMouseEvent* event)
{
void ElaNavigationView::mouseReleaseEvent(QMouseEvent *event) {
QTreeView::mouseReleaseEvent(event);
if (event->button() == Qt::LeftButton)
{
if (event->button() == Qt::LeftButton) {
QModelIndex index = indexAt(event->pos());
if (index.isValid())
{
if (index.isValid()) {
Q_EMIT navigationClicked(index);
}
_navigationStyle->setPressIndex(QModelIndex());
}
}
bool ElaNavigationView::eventFilter(QObject* watched, QEvent* event)
{
switch (event->type())
{
bool ElaNavigationView::eventFilter(QObject *watched, QEvent *event) {
switch (event->type()) {
case QEvent::MouseMove:
case QEvent::HoverMove:
{
if (_pNavigationBarPrivate->_currentDisplayMode == ElaNavigationType::NavigationDisplayMode::Compact)
{
case QEvent::HoverMove: {
if (_pNavigationBarPrivate->_currentDisplayMode == ElaNavigationType::NavigationDisplayMode::Compact) {
QModelIndex posIndex = indexAt(mapFromGlobal(QCursor::pos()));
if (!posIndex.isValid())
{
if (!posIndex.isValid()) {
_compactToolTip->hide();
break;
}
ElaNavigationNode* posNode = static_cast<ElaNavigationNode*>(posIndex.internalPointer());
ElaNavigationNode *posNode = static_cast<ElaNavigationNode *>(posIndex.internalPointer());
_compactToolTip->setToolTip(posNode->getNodeTitle());
_compactToolTip->updatePos();
_compactToolTip->show();
}
else
{
} else {
_compactToolTip->hide();
}
break;
}
default:
{
default: {
break;
}
}