chore: 格式化ElaWidgetTools代码
This commit is contained in:
@@ -9,113 +9,83 @@
|
||||
#include <QPropertyAnimation>
|
||||
#include <QUuid>
|
||||
|
||||
ElaSuggestion::ElaSuggestion(QObject* parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
_pElaIcon = ElaIconType::None;
|
||||
ElaSuggestion::ElaSuggestion(QObject *parent) : QObject(parent) {
|
||||
_pElaIcon = ElaIconType::None;
|
||||
_pSuggestText = "";
|
||||
_pSuggestKey = QUuid::createUuid().toString().remove("{").remove("}").remove("-");
|
||||
_pSuggestKey = QUuid::createUuid().toString().remove("{").remove("}").remove("-");
|
||||
_pSuggestData = QVariantMap();
|
||||
}
|
||||
|
||||
ElaSuggestion::~ElaSuggestion()
|
||||
{
|
||||
}
|
||||
ElaSuggestion::~ElaSuggestion() {}
|
||||
|
||||
ElaSuggestBoxPrivate::ElaSuggestBoxPrivate(QObject* parent)
|
||||
: QObject{parent}
|
||||
{
|
||||
}
|
||||
ElaSuggestBoxPrivate::ElaSuggestBoxPrivate(QObject *parent) : QObject{parent} {}
|
||||
|
||||
ElaSuggestBoxPrivate::~ElaSuggestBoxPrivate()
|
||||
{
|
||||
}
|
||||
ElaSuggestBoxPrivate::~ElaSuggestBoxPrivate() {}
|
||||
|
||||
void ElaSuggestBoxPrivate::onThemeModeChanged(ElaThemeType::ThemeMode themeMode)
|
||||
{
|
||||
void ElaSuggestBoxPrivate::onThemeModeChanged(ElaThemeType::ThemeMode themeMode) {
|
||||
_themeMode = themeMode;
|
||||
_searchEdit->removeAction(_themeMode == ElaThemeType::Light ? _darkSearchAction : _lightSearchAction);
|
||||
_searchEdit->addAction(_themeMode == ElaThemeType::Light ? _lightSearchAction : _darkSearchAction, QLineEdit::TrailingPosition);
|
||||
_searchEdit->update();
|
||||
}
|
||||
|
||||
void ElaSuggestBoxPrivate::onSearchEditTextEdit(const QString& searchText)
|
||||
{
|
||||
void ElaSuggestBoxPrivate::onSearchEditTextEdit(const QString &searchText) {
|
||||
Q_Q(ElaSuggestBox);
|
||||
if (searchText.isEmpty())
|
||||
{
|
||||
if (searchText.isEmpty()) {
|
||||
_startCloseAnimation();
|
||||
return;
|
||||
}
|
||||
QVector<ElaSuggestion*> suggestionVector;
|
||||
for (const auto& suggest: _suggestionVector)
|
||||
{
|
||||
if (suggest->getSuggestText().contains(searchText, _pCaseSensitivity))
|
||||
{
|
||||
QVector<ElaSuggestion *> suggestionVector;
|
||||
for (const auto &suggest : _suggestionVector) {
|
||||
if (suggest->getSuggestText().contains(searchText, _pCaseSensitivity)) {
|
||||
suggestionVector.append(suggest);
|
||||
}
|
||||
}
|
||||
if (!suggestionVector.isEmpty())
|
||||
{
|
||||
if (!suggestionVector.isEmpty()) {
|
||||
_searchModel->setSearchSuggestion(suggestionVector);
|
||||
int rowCount = suggestionVector.count();
|
||||
if (rowCount > 4)
|
||||
{
|
||||
if (rowCount > 4) {
|
||||
rowCount = 4;
|
||||
}
|
||||
if (!_searchViewBaseWidget->isVisible())
|
||||
{
|
||||
if (!_searchViewBaseWidget->isVisible()) {
|
||||
q->raise();
|
||||
_searchViewBaseWidget->show();
|
||||
_searchViewBaseWidget->raise();
|
||||
QPoint cyclePoint = _searchViewBaseWidget->mapFromGlobal(q->mapToGlobal(QPoint(-5, q->height())));
|
||||
if (cyclePoint != QPoint(0, 0))
|
||||
{
|
||||
if (cyclePoint != QPoint(0, 0)) {
|
||||
_searchViewBaseWidget->move(cyclePoint);
|
||||
}
|
||||
_startSizeAnimation(QSize(q->width() + 10, 0), QSize(q->width() + 10, 40 * rowCount + 16));
|
||||
_searchView->move(_searchView->x(), -(40 * rowCount + 16));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
_startSizeAnimation(_searchViewBaseWidget->size(), QSize(q->width() + 12, 40 * rowCount + 16));
|
||||
}
|
||||
_startExpandAnimation();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
_startCloseAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
void ElaSuggestBoxPrivate::onSearchViewClicked(const QModelIndex& index)
|
||||
{
|
||||
void ElaSuggestBoxPrivate::onSearchViewClicked(const QModelIndex &index) {
|
||||
Q_Q(ElaSuggestBox);
|
||||
_searchEdit->clear();
|
||||
_searchView->clearSelection();
|
||||
if (!index.isValid())
|
||||
{
|
||||
if (!index.isValid()) {
|
||||
return;
|
||||
}
|
||||
ElaSuggestion* suggest = _searchModel->getSearchSuggestion(index.row());
|
||||
ElaSuggestion *suggest = _searchModel->getSearchSuggestion(index.row());
|
||||
Q_EMIT q->suggestionClicked(suggest->getSuggestText(), suggest->getSuggestData());
|
||||
_startCloseAnimation();
|
||||
}
|
||||
|
||||
void ElaSuggestBoxPrivate::_startSizeAnimation(QSize oldSize, QSize newSize)
|
||||
{
|
||||
if (_lastSize.isValid() && _lastSize == newSize)
|
||||
{
|
||||
void ElaSuggestBoxPrivate::_startSizeAnimation(QSize oldSize, QSize newSize) {
|
||||
if (_lastSize.isValid() && _lastSize == newSize) {
|
||||
return;
|
||||
}
|
||||
_shadowLayout->removeWidget(_searchView);
|
||||
QPropertyAnimation* expandAnimation = new QPropertyAnimation(_searchViewBaseWidget, "size");
|
||||
connect(expandAnimation, &QPropertyAnimation::valueChanged, this, [=]() {
|
||||
_searchView->resize(_searchViewBaseWidget->size());
|
||||
});
|
||||
connect(expandAnimation, &QPropertyAnimation::finished, this, [=]() {
|
||||
_shadowLayout->addWidget(_searchView);
|
||||
});
|
||||
QPropertyAnimation *expandAnimation = new QPropertyAnimation(_searchViewBaseWidget, "size");
|
||||
connect(expandAnimation, &QPropertyAnimation::valueChanged, this, [=]() { _searchView->resize(_searchViewBaseWidget->size()); });
|
||||
connect(expandAnimation, &QPropertyAnimation::finished, this, [=]() { _shadowLayout->addWidget(_searchView); });
|
||||
expandAnimation->setDuration(300);
|
||||
expandAnimation->setEasingCurve(QEasingCurve::InOutSine);
|
||||
expandAnimation->setStartValue(oldSize);
|
||||
@@ -124,15 +94,13 @@ void ElaSuggestBoxPrivate::_startSizeAnimation(QSize oldSize, QSize newSize)
|
||||
_lastSize = newSize;
|
||||
}
|
||||
|
||||
void ElaSuggestBoxPrivate::_startExpandAnimation()
|
||||
{
|
||||
if (!_isExpandAnimationFinished)
|
||||
{
|
||||
void ElaSuggestBoxPrivate::_startExpandAnimation() {
|
||||
if (!_isExpandAnimationFinished) {
|
||||
return;
|
||||
}
|
||||
_isCloseAnimationFinished = true;
|
||||
_isExpandAnimationFinished = false;
|
||||
QPropertyAnimation* expandAnimation = new QPropertyAnimation(_searchView, "pos");
|
||||
_isCloseAnimationFinished = true;
|
||||
_isExpandAnimationFinished = false;
|
||||
QPropertyAnimation *expandAnimation = new QPropertyAnimation(_searchView, "pos");
|
||||
connect(expandAnimation, &QPropertyAnimation::finished, this, [=]() {
|
||||
_isExpandAnimationFinished = true;
|
||||
_searchView->clearSelection();
|
||||
@@ -144,21 +112,19 @@ void ElaSuggestBoxPrivate::_startExpandAnimation()
|
||||
expandAnimation->start(QAbstractAnimation::DeleteWhenStopped);
|
||||
}
|
||||
|
||||
void ElaSuggestBoxPrivate::_startCloseAnimation()
|
||||
{
|
||||
if (!_isCloseAnimationFinished)
|
||||
{
|
||||
void ElaSuggestBoxPrivate::_startCloseAnimation() {
|
||||
if (!_isCloseAnimationFinished) {
|
||||
return;
|
||||
}
|
||||
_isExpandAnimationFinished = true;
|
||||
_isCloseAnimationFinished = false;
|
||||
QPropertyAnimation* baseWidgetsAnimation = new QPropertyAnimation(_searchViewBaseWidget, "size");
|
||||
_isExpandAnimationFinished = true;
|
||||
_isCloseAnimationFinished = false;
|
||||
QPropertyAnimation *baseWidgetsAnimation = new QPropertyAnimation(_searchViewBaseWidget, "size");
|
||||
baseWidgetsAnimation->setDuration(300);
|
||||
baseWidgetsAnimation->setEasingCurve(QEasingCurve::InOutSine);
|
||||
baseWidgetsAnimation->setStartValue(_searchViewBaseWidget->size());
|
||||
baseWidgetsAnimation->setEndValue(QSize(_searchViewBaseWidget->width(), 0));
|
||||
baseWidgetsAnimation->start(QAbstractAnimation::DeleteWhenStopped);
|
||||
QPropertyAnimation* closeAnimation = new QPropertyAnimation(_searchView, "pos");
|
||||
QPropertyAnimation *closeAnimation = new QPropertyAnimation(_searchView, "pos");
|
||||
connect(closeAnimation, &QPropertyAnimation::finished, this, [=]() {
|
||||
_isCloseAnimationFinished = true;
|
||||
_searchModel->clearSearchNode();
|
||||
|
||||
Reference in New Issue
Block a user