From 6a2563d4dc2b4ae51169a34db8407b7f867fc167 Mon Sep 17 00:00:00 2001 From: zhangjiaping Date: Sat, 16 Jan 2021 15:24:28 +0800 Subject: [PATCH 1/3] feat(frontend): Add animation into inputbox. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Description: 在输入框添加动画效果 Log: 在输入框添加动画效果 --- src/input-box.cpp | 117 +++++++++++++++++++++++++++++++--------------- src/input-box.h | 13 ++++-- 2 files changed, 89 insertions(+), 41 deletions(-) diff --git a/src/input-box.cpp b/src/input-box.cpp index 654ad68..47ff2a2 100644 --- a/src/input-box.cpp +++ b/src/input-box.cpp @@ -5,26 +5,10 @@ */ UKuiSeachBarWidget::UKuiSeachBarWidget() { -// this->setFixedSize(Style::defaultMainViewWidWidth,Style::defaultTopWidHeight); - } UKuiSeachBarWidget::~UKuiSeachBarWidget() { - -} - -void UKuiSeachBarWidget::paintEvent(QPaintEvent *e) -{ - QPainter p(this); - QRect rect = this->rect(); - p.setRenderHint(QPainter::Antialiasing); // 反锯齿; - p.setBrush(this->palette().color(QPalette::Base)); -// p.setBrush(QBrush(QColor(255,255,255))); - p.setOpacity(1); - p.setPen(Qt::NoPen); - p.drawRoundedRect(rect,12,12); - QWidget::paintEvent(e); } /** @@ -41,12 +25,10 @@ UkuiSearchBarWidgetLayout::UkuiSearchBarWidgetLayout() UkuiSearchBarWidgetLayout::~UkuiSearchBarWidgetLayout() { - } UKuiSeachBar::~UKuiSeachBar() { - } /** @@ -55,15 +37,7 @@ UKuiSeachBar::~UKuiSeachBar() UkuiSearchBarHLayout::UkuiSearchBarHLayout() { initUI(); -// retouchLineEdit(); - m_queryLineEdit=new UKuiSearchLineEdit; - - this->setContentsMargins(0,0,0,0); - this->setAlignment(m_queryLineEdit,Qt::AlignCenter); - this->addWidget(m_queryLineEdit); - -// connect(m_queryLineEdit, SIGNAL(textChanged(QString)), SIGNAL(textChanged(QString))); m_timer = new QTimer; connect(m_timer, &QTimer::timeout, this, [ = ](){ m_timer->stop(); @@ -80,7 +54,6 @@ UkuiSearchBarHLayout::UkuiSearchBarHLayout() Q_EMIT this->textChanged(m_queryLineEdit->text()); return; } -// Q_EMIT this->textChanged(m_queryLineEdit->text()); m_timer->stop(); m_timer->start(0.1 * 1000); } @@ -100,12 +73,50 @@ UkuiSearchBarHLayout::~UkuiSearchBarHLayout() */ void UkuiSearchBarHLayout::initUI() { - setContentsMargins(5,3,0,2); - setSpacing(5); -} + m_queryLineEdit = new UKuiSearchLineEdit; + m_queryLineEdit->installEventFilter(this); + m_queryLineEdit->setTextMargins(30,1,0,1); + this->setContentsMargins(0,0,0,0); + this->setAlignment(m_queryLineEdit,Qt::AlignCenter); + this->addWidget(m_queryLineEdit); + m_queryWidget = new QWidget(m_queryLineEdit); + m_queryWidget->setFocusPolicy(Qt::NoFocus); + m_queryWidget->setStyleSheet("border:0px;background:transparent"); -void UkuiSearchBarHLayout::searchContent(QString searchcontent){ - m_queryLineEdit->setText(searchcontent); + QHBoxLayout* queryWidLayout= new QHBoxLayout; + queryWidLayout->setContentsMargins(4,0,0,0); + queryWidLayout->setAlignment(Qt::AlignJustify); + queryWidLayout->setSpacing(5); + m_queryWidget->setLayout(queryWidLayout); + + + QPixmap pixmap(QString(":/res/icons/edit-find-symbolic.svg")); + m_queryIcon = new QLabel; + m_queryIcon->setStyleSheet("background:transparent"); + m_queryIcon->setFixedSize(pixmap.size()); + m_queryIcon->setPixmap(pixmap); + + m_queryText = new QLabel; + m_queryText->setText(tr("Search")); + m_queryText->setStyleSheet("background:transparent;color:#626c6e;"); + m_queryText->setContentsMargins(0,0,0,4); + m_queryText->adjustSize(); + + queryWidLayout->addWidget(m_queryIcon); + queryWidLayout->addWidget(m_queryText); + m_queryWidget->setGeometry(QRect((m_queryLineEdit->width() - (m_queryIcon->width() + m_queryText->width() + 15)) / 2 - 10, 0, + m_queryIcon->width() + m_queryText->width() + 10, 35)); //设置图标初始位置 + + m_animation= new QPropertyAnimation(m_queryWidget,"geometry"); + m_animation->setDuration(100); //动画时长 + connect(m_animation,&QPropertyAnimation::finished,this, [ = ]() { + if (m_isSearching) { + m_queryWidget->layout()->removeWidget(m_queryText); + m_queryText->setParent(nullptr); + } else { + m_queryWidget->layout()->addWidget(m_queryText); + } + }); } void UkuiSearchBarHLayout::clearText() { @@ -116,6 +127,37 @@ QString UkuiSearchBarHLayout::text() { return m_queryLineEdit->text(); } +bool UkuiSearchBarHLayout::eventFilter(QObject *watched, QEvent *event) +{ + if (watched == m_queryLineEdit) { + if (event->type()==QEvent::FocusIn) { + if (m_queryLineEdit->text().isEmpty()) { + m_animation->stop(); + m_animation->setStartValue(QRect((m_queryLineEdit->width() - (m_queryIcon->width() + m_queryText->width() + 10)) / 2, 0, + m_queryIcon->width() + m_queryText->width() + 10, 35)); + m_animation->setEndValue(QRect(0, 0, m_queryIcon->width() + 5, 35)); + m_animation->setEasingCurve(QEasingCurve::OutQuad); + m_animation->start(); + } + m_isSearching=true; + } else if (event->type()==QEvent::FocusOut) { + if (m_queryLineEdit->text().isEmpty()) { + if (m_isSearching) { + m_animation->stop(); + m_queryText->adjustSize(); + m_animation->setStartValue(QRect(0, 0, m_queryIcon->width() + 5, 35)); + m_animation->setEndValue(QRect((m_queryLineEdit->width() - (m_queryIcon->width() + m_queryText->width() + 10)) / 2, 0, + m_queryIcon->width() + m_queryText->width() + 10, 35)); + m_animation->setEasingCurve(QEasingCurve::InQuad); + m_animation->start(); + } + } + m_isSearching=false; + } + } + return QObject::eventFilter(watched, event); +} + /** * @brief UKuiSearchLineEdit 全局搜索的输入框 */ @@ -127,11 +169,10 @@ UKuiSearchLineEdit::UKuiSearchLineEdit() this->setMaxLength(100); - QAction *searchAction = new QAction(this); - searchAction->setIcon(QIcon(":/res/icons/edit-find-symbolic.svg")); - this->addAction(searchAction,QLineEdit::LeadingPosition); - - + //这是搜索框图标,要改 +// QAction *searchAction = new QAction(this); +// searchAction->setIcon(QIcon(":/res/icons/edit-find-symbolic.svg")); +// this->addAction(searchAction,QLineEdit::LeadingPosition); /*发送输入框文字改变的dbus*/ QDBusConnection::sessionBus().unregisterService("org.ukui.search.service"); @@ -156,7 +197,7 @@ UKuiSearchLineEdit::~UKuiSearchLineEdit() */ void UKuiSearchLineEdit::lineEditTextChanged(QString arg) { - QDBusMessage message =QDBusMessage::createSignal("/lineEdit/textChanged", "org.ukui.search.inputbox", "InputBoxTextChanged"); + QDBusMessage message = QDBusMessage::createSignal("/lineEdit/textChanged", "org.ukui.search.inputbox", "InputBoxTextChanged"); message< Date: Sat, 16 Jan 2021 16:16:26 +0800 Subject: [PATCH 2/3] feat(frontend): Set fixed height for titlelabel. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Description: 给列表标题设置固定高度以防滚动区域高度计算错误 Log: 给列表标题设置固定高度以防滚动区域高度计算错误 --- src/content-widget.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/content-widget.cpp b/src/content-widget.cpp index 629731a..e3f334c 100644 --- a/src/content-widget.cpp +++ b/src/content-widget.cpp @@ -92,26 +92,32 @@ void ContentWidget::initListView() m_fileTitleLabel = new QLabel(m_resultList); m_fileTitleLabel->setContentsMargins(8, 0, 0, 0); + m_fileTitleLabel->setFixedHeight(24); m_fileTitleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}"); m_fileTitleLabel->setText(getTitleName(SearchItem::SearchType::Files)); m_dirTitleLabel = new QLabel(m_resultList); m_dirTitleLabel->setContentsMargins(8, 0, 0, 0); + m_dirTitleLabel->setFixedHeight(24); m_dirTitleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}"); m_dirTitleLabel->setText(getTitleName(SearchItem::SearchType::Dirs)); m_contentTitleLabel = new QLabel(m_resultList); m_contentTitleLabel->setContentsMargins(8, 0, 0, 0); + m_contentTitleLabel->setFixedHeight(24); m_contentTitleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}"); m_contentTitleLabel->setText(getTitleName(SearchItem::SearchType::Contents)); m_appTitleLabel = new QLabel(m_resultList); m_appTitleLabel->setContentsMargins(8, 0, 0, 0); + m_appTitleLabel->setFixedHeight(24); m_appTitleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}"); m_appTitleLabel->setText(getTitleName(SearchItem::SearchType::Apps)); m_settingTitleLabel = new QLabel(m_resultList); m_settingTitleLabel->setContentsMargins(8, 0, 0, 0); + m_settingTitleLabel->setFixedHeight(24); m_settingTitleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}"); m_settingTitleLabel->setText(getTitleName(SearchItem::SearchType::Settings)); m_bestTitleLabel = new QLabel(m_resultList); m_bestTitleLabel->setContentsMargins(8, 0, 0, 0); + m_bestTitleLabel->setFixedHeight(24); m_bestTitleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}"); m_bestTitleLabel->setText(getTitleName(SearchItem::SearchType::Best)); From 0301d5f854bbef3bffac8a4b18ee8249c6e616b6 Mon Sep 17 00:00:00 2001 From: zhangjiaping Date: Mon, 18 Jan 2021 09:34:47 +0800 Subject: [PATCH 3/3] fix(frontend): Break line by adding '\n' into path string,. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Description: 在文件路径添加换行符以实现无视分隔符换行 Log: 在文件路径添加换行符以实现无视分隔符换行 Bug: http://172.17.66.192/biz/bug-view-33378.html --- src/control/search-detail-view.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/control/search-detail-view.cpp b/src/control/search-detail-view.cpp index 4b1be5d..069bd2d 100644 --- a/src/control/search-detail-view.cpp +++ b/src/control/search-detail-view.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include "config-file.h" SearchDetailView::SearchDetailView(QWidget *parent) : QWidget(parent) @@ -138,7 +139,26 @@ void SearchDetailView::setupWidget(const int& type, const QString& path) { m_timeFrame->show(); m_pathLabel_1->show(); m_pathLabel_2->show(); - m_pathLabel_2->setText(path); +// m_pathLabel_2->setText(path); + QString showPath = path; + QFontMetrics fontMetrics = m_pathLabel_2->fontMetrics(); + if (fontMetrics.width(path) > m_pathLabel_2->width()) { + //路径长度超过240,手动添加换行符以实现折叠 + int lastIndex = 0; + for (int i = lastIndex; i < path.length(); i++) { + if (fontMetrics.width(path.mid(lastIndex, i - lastIndex)) == m_pathLabel_2->width()) { + lastIndex = i; + showPath.insert(i, '\n'); + } else if (fontMetrics.width(path.mid(lastIndex, i - lastIndex)) > m_pathLabel_2->width()) { + lastIndex = i; + showPath.insert(i - 1, '\n'); + } else { + continue; + } + } + } + m_pathLabel_2->setText(showPath); + m_timeLabel_1->show(); m_timeLabel_2->show(); QFileInfo fileInfo(path); @@ -326,7 +346,7 @@ void SearchDetailView::initUI() m_pathLabel_2 = new QLabel(m_pathFrame); m_pathLabel_1->setText(tr("Path")); m_pathLabel_2->setFixedWidth(240); - m_pathLabel_2->setWordWrap(true); +// m_pathLabel_2->setWordWrap(true); m_pathLyt->addWidget(m_pathLabel_1); m_pathLyt->addStretch(); m_pathLyt->addWidget(m_pathLabel_2);