Merge pull request #90 from mammonsama666/0116-dev
feat(frontend): Add animation into inputbox.
This commit is contained in:
commit
fc0dc1ca45
|
@ -92,26 +92,32 @@ void ContentWidget::initListView()
|
||||||
|
|
||||||
m_fileTitleLabel = new QLabel(m_resultList);
|
m_fileTitleLabel = new QLabel(m_resultList);
|
||||||
m_fileTitleLabel->setContentsMargins(8, 0, 0, 0);
|
m_fileTitleLabel->setContentsMargins(8, 0, 0, 0);
|
||||||
|
m_fileTitleLabel->setFixedHeight(24);
|
||||||
m_fileTitleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}");
|
m_fileTitleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}");
|
||||||
m_fileTitleLabel->setText(getTitleName(SearchItem::SearchType::Files));
|
m_fileTitleLabel->setText(getTitleName(SearchItem::SearchType::Files));
|
||||||
m_dirTitleLabel = new QLabel(m_resultList);
|
m_dirTitleLabel = new QLabel(m_resultList);
|
||||||
m_dirTitleLabel->setContentsMargins(8, 0, 0, 0);
|
m_dirTitleLabel->setContentsMargins(8, 0, 0, 0);
|
||||||
|
m_dirTitleLabel->setFixedHeight(24);
|
||||||
m_dirTitleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}");
|
m_dirTitleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}");
|
||||||
m_dirTitleLabel->setText(getTitleName(SearchItem::SearchType::Dirs));
|
m_dirTitleLabel->setText(getTitleName(SearchItem::SearchType::Dirs));
|
||||||
m_contentTitleLabel = new QLabel(m_resultList);
|
m_contentTitleLabel = new QLabel(m_resultList);
|
||||||
m_contentTitleLabel->setContentsMargins(8, 0, 0, 0);
|
m_contentTitleLabel->setContentsMargins(8, 0, 0, 0);
|
||||||
|
m_contentTitleLabel->setFixedHeight(24);
|
||||||
m_contentTitleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}");
|
m_contentTitleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}");
|
||||||
m_contentTitleLabel->setText(getTitleName(SearchItem::SearchType::Contents));
|
m_contentTitleLabel->setText(getTitleName(SearchItem::SearchType::Contents));
|
||||||
m_appTitleLabel = new QLabel(m_resultList);
|
m_appTitleLabel = new QLabel(m_resultList);
|
||||||
m_appTitleLabel->setContentsMargins(8, 0, 0, 0);
|
m_appTitleLabel->setContentsMargins(8, 0, 0, 0);
|
||||||
|
m_appTitleLabel->setFixedHeight(24);
|
||||||
m_appTitleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}");
|
m_appTitleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}");
|
||||||
m_appTitleLabel->setText(getTitleName(SearchItem::SearchType::Apps));
|
m_appTitleLabel->setText(getTitleName(SearchItem::SearchType::Apps));
|
||||||
m_settingTitleLabel = new QLabel(m_resultList);
|
m_settingTitleLabel = new QLabel(m_resultList);
|
||||||
m_settingTitleLabel->setContentsMargins(8, 0, 0, 0);
|
m_settingTitleLabel->setContentsMargins(8, 0, 0, 0);
|
||||||
|
m_settingTitleLabel->setFixedHeight(24);
|
||||||
m_settingTitleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}");
|
m_settingTitleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}");
|
||||||
m_settingTitleLabel->setText(getTitleName(SearchItem::SearchType::Settings));
|
m_settingTitleLabel->setText(getTitleName(SearchItem::SearchType::Settings));
|
||||||
m_bestTitleLabel = new QLabel(m_resultList);
|
m_bestTitleLabel = new QLabel(m_resultList);
|
||||||
m_bestTitleLabel->setContentsMargins(8, 0, 0, 0);
|
m_bestTitleLabel->setContentsMargins(8, 0, 0, 0);
|
||||||
|
m_bestTitleLabel->setFixedHeight(24);
|
||||||
m_bestTitleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}");
|
m_bestTitleLabel->setStyleSheet("QLabel{background: rgba(0,0,0,0.1);}");
|
||||||
m_bestTitleLabel->setText(getTitleName(SearchItem::SearchType::Best));
|
m_bestTitleLabel->setText(getTitleName(SearchItem::SearchType::Best));
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QTextBrowser>
|
||||||
#include "config-file.h"
|
#include "config-file.h"
|
||||||
|
|
||||||
SearchDetailView::SearchDetailView(QWidget *parent) : QWidget(parent)
|
SearchDetailView::SearchDetailView(QWidget *parent) : QWidget(parent)
|
||||||
|
@ -138,7 +139,26 @@ void SearchDetailView::setupWidget(const int& type, const QString& path) {
|
||||||
m_timeFrame->show();
|
m_timeFrame->show();
|
||||||
m_pathLabel_1->show();
|
m_pathLabel_1->show();
|
||||||
m_pathLabel_2->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_1->show();
|
||||||
m_timeLabel_2->show();
|
m_timeLabel_2->show();
|
||||||
QFileInfo fileInfo(path);
|
QFileInfo fileInfo(path);
|
||||||
|
@ -326,7 +346,7 @@ void SearchDetailView::initUI()
|
||||||
m_pathLabel_2 = new QLabel(m_pathFrame);
|
m_pathLabel_2 = new QLabel(m_pathFrame);
|
||||||
m_pathLabel_1->setText(tr("Path"));
|
m_pathLabel_1->setText(tr("Path"));
|
||||||
m_pathLabel_2->setFixedWidth(240);
|
m_pathLabel_2->setFixedWidth(240);
|
||||||
m_pathLabel_2->setWordWrap(true);
|
// m_pathLabel_2->setWordWrap(true);
|
||||||
m_pathLyt->addWidget(m_pathLabel_1);
|
m_pathLyt->addWidget(m_pathLabel_1);
|
||||||
m_pathLyt->addStretch();
|
m_pathLyt->addStretch();
|
||||||
m_pathLyt->addWidget(m_pathLabel_2);
|
m_pathLyt->addWidget(m_pathLabel_2);
|
||||||
|
|
|
@ -5,26 +5,10 @@
|
||||||
*/
|
*/
|
||||||
UKuiSeachBarWidget::UKuiSeachBarWidget()
|
UKuiSeachBarWidget::UKuiSeachBarWidget()
|
||||||
{
|
{
|
||||||
// this->setFixedSize(Style::defaultMainViewWidWidth,Style::defaultTopWidHeight);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UKuiSeachBarWidget::~UKuiSeachBarWidget()
|
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()
|
UkuiSearchBarWidgetLayout::~UkuiSearchBarWidgetLayout()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UKuiSeachBar::~UKuiSeachBar()
|
UKuiSeachBar::~UKuiSeachBar()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,15 +37,7 @@ UKuiSeachBar::~UKuiSeachBar()
|
||||||
UkuiSearchBarHLayout::UkuiSearchBarHLayout()
|
UkuiSearchBarHLayout::UkuiSearchBarHLayout()
|
||||||
{
|
{
|
||||||
initUI();
|
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;
|
m_timer = new QTimer;
|
||||||
connect(m_timer, &QTimer::timeout, this, [ = ](){
|
connect(m_timer, &QTimer::timeout, this, [ = ](){
|
||||||
m_timer->stop();
|
m_timer->stop();
|
||||||
|
@ -80,7 +54,6 @@ UkuiSearchBarHLayout::UkuiSearchBarHLayout()
|
||||||
Q_EMIT this->textChanged(m_queryLineEdit->text());
|
Q_EMIT this->textChanged(m_queryLineEdit->text());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Q_EMIT this->textChanged(m_queryLineEdit->text());
|
|
||||||
m_timer->stop();
|
m_timer->stop();
|
||||||
m_timer->start(0.1 * 1000);
|
m_timer->start(0.1 * 1000);
|
||||||
}
|
}
|
||||||
|
@ -100,12 +73,50 @@ UkuiSearchBarHLayout::~UkuiSearchBarHLayout()
|
||||||
*/
|
*/
|
||||||
void UkuiSearchBarHLayout::initUI()
|
void UkuiSearchBarHLayout::initUI()
|
||||||
{
|
{
|
||||||
setContentsMargins(5,3,0,2);
|
m_queryLineEdit = new UKuiSearchLineEdit;
|
||||||
setSpacing(5);
|
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){
|
QHBoxLayout* queryWidLayout= new QHBoxLayout;
|
||||||
m_queryLineEdit->setText(searchcontent);
|
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() {
|
void UkuiSearchBarHLayout::clearText() {
|
||||||
|
@ -116,6 +127,37 @@ QString UkuiSearchBarHLayout::text() {
|
||||||
return m_queryLineEdit->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 全局搜索的输入框
|
* @brief UKuiSearchLineEdit 全局搜索的输入框
|
||||||
*/
|
*/
|
||||||
|
@ -127,11 +169,10 @@ UKuiSearchLineEdit::UKuiSearchLineEdit()
|
||||||
this->setMaxLength(100);
|
this->setMaxLength(100);
|
||||||
|
|
||||||
|
|
||||||
QAction *searchAction = new QAction(this);
|
//这是搜索框图标,要改
|
||||||
searchAction->setIcon(QIcon(":/res/icons/edit-find-symbolic.svg"));
|
// QAction *searchAction = new QAction(this);
|
||||||
this->addAction(searchAction,QLineEdit::LeadingPosition);
|
// searchAction->setIcon(QIcon(":/res/icons/edit-find-symbolic.svg"));
|
||||||
|
// this->addAction(searchAction,QLineEdit::LeadingPosition);
|
||||||
|
|
||||||
|
|
||||||
/*发送输入框文字改变的dbus*/
|
/*发送输入框文字改变的dbus*/
|
||||||
QDBusConnection::sessionBus().unregisterService("org.ukui.search.service");
|
QDBusConnection::sessionBus().unregisterService("org.ukui.search.service");
|
||||||
|
@ -156,7 +197,7 @@ UKuiSearchLineEdit::~UKuiSearchLineEdit()
|
||||||
*/
|
*/
|
||||||
void UKuiSearchLineEdit::lineEditTextChanged(QString arg)
|
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<<arg;
|
message<<arg;
|
||||||
QDBusConnection::sessionBus().send(message);
|
QDBusConnection::sessionBus().send(message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,6 @@ class UKuiSeachBarWidget:public QWidget
|
||||||
public:
|
public:
|
||||||
UKuiSeachBarWidget();
|
UKuiSeachBarWidget();
|
||||||
~UKuiSeachBarWidget();
|
~UKuiSeachBarWidget();
|
||||||
void paintEvent(QPaintEvent *e);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class UKuiSeachBar:public QWidget
|
class UKuiSeachBar:public QWidget
|
||||||
|
@ -33,15 +32,23 @@ class UkuiSearchBarHLayout : public QHBoxLayout
|
||||||
public:
|
public:
|
||||||
UkuiSearchBarHLayout();
|
UkuiSearchBarHLayout();
|
||||||
~UkuiSearchBarHLayout();
|
~UkuiSearchBarHLayout();
|
||||||
void searchContent(QString searchcontent);
|
|
||||||
void clearText();
|
void clearText();
|
||||||
QString text();
|
QString text();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool eventFilter(QObject *watched, QEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void initUI();
|
void initUI();
|
||||||
bool m_isEmpty = true;
|
bool m_isEmpty = true;
|
||||||
QTimer * m_timer = nullptr;
|
QTimer * m_timer = nullptr;
|
||||||
|
|
||||||
UKuiSearchLineEdit *m_queryLineEdit=nullptr;
|
UKuiSearchLineEdit * m_queryLineEdit = nullptr;
|
||||||
|
QPropertyAnimation * m_animation = nullptr;
|
||||||
|
QWidget * m_queryWidget = nullptr;
|
||||||
|
QLabel * m_queryIcon = nullptr;
|
||||||
|
QLabel * m_queryText = nullptr;
|
||||||
|
bool m_isSearching = false;
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void textChanged(QString text);
|
void textChanged(QString text);
|
||||||
|
|
Loading…
Reference in New Issue