From 243f56eb7e6448d4775e9ab7ac035a83b54f11bd Mon Sep 17 00:00:00 2001 From: zhangjiaping Date: Wed, 27 Jan 2021 16:25:10 +0800 Subject: [PATCH] fix(frontend): Adjust ui according to blueprint. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Description: 根据设计稿调整UI细节,添加弹窗 Log: 根据设计稿调整UI细节,添加弹窗 --- src/control/highlight-item-delegate.cpp | 4 +- src/control/search-detail-view.cpp | 4 +- src/input-box.cpp | 12 ++-- src/mainwindow.cpp | 1 + src/settings-widget.cpp | 63 +++++++++++++------ src/settings-widget.h | 6 +- translations/ukui-search/bo.ts | 84 ++++++++++++++----------- translations/ukui-search/tr.ts | 84 ++++++++++++++----------- translations/ukui-search/zh_CN.ts | 76 +++++++++++----------- 9 files changed, 192 insertions(+), 142 deletions(-) diff --git a/src/control/highlight-item-delegate.cpp b/src/control/highlight-item-delegate.cpp index 3f354ac..c2b679b 100644 --- a/src/control/highlight-item-delegate.cpp +++ b/src/control/highlight-item-delegate.cpp @@ -35,7 +35,7 @@ void HighlightItemDelegate::paint(QPainter * painter, const QStyleOptionViewItem ctx.palette.setColor(QPalette::Text, optionV4.palette.color(QPalette::Active, QPalette::HighlightedText)); QRect textRect = style->subElementRect(QStyle::SE_ItemViewItemText, &optionV4); - textRect.adjust(0, -3, 0, 0); + textRect.adjust(-20, -5, 0, 0); painter->save(); painter->translate(textRect.topLeft()); painter->setClipRect(textRect.translated(-textRect.topLeft())); @@ -64,7 +64,7 @@ QString HighlightItemDelegate::getHtmlText(QPainter *painter, const QStyleOption int indexFindLeft = 0; QString indexString = index.model()->data(index,Qt::DisplayRole).toString(); QFontMetrics m_QFontMetrics = painter->fontMetrics(); - QString indexColString = m_QFontMetrics.elidedText(indexString, Qt::ElideRight, itemOption.rect.width() - 2); //当字体超过Item的长度时显示为省略号 + QString indexColString = m_QFontMetrics.elidedText(indexString, Qt::ElideRight, itemOption.rect.width() + 10); //当字体超过Item的长度时显示为省略号 QString htmlString; if ((indexColString.toUpper()).contains((m_regFindKeyWords.toUpper()))) { indexFindLeft = indexColString.toUpper().indexOf(m_regFindKeyWords.toUpper()); //得到查找字体在当前整个Item字体中的位置 diff --git a/src/control/search-detail-view.cpp b/src/control/search-detail-view.cpp index 017e0ee..9ea7ee1 100644 --- a/src/control/search-detail-view.cpp +++ b/src/control/search-detail-view.cpp @@ -260,7 +260,9 @@ bool SearchDetailView::openAction(const int& type, const QString& path) { case SearchListView::ResType::Setting: { //打开控制面板对应页面 QProcess process; - process.startDetached(QString("ukui-control-center --%1").arg(path.left(path.indexOf("/")).toLower())); + if (path.left(path.indexOf("/")).toLower() == "wallpaper") + process.startDetached(QString("ukui-control-center --background")); + else process.startDetached(QString("ukui-control-center --%1").arg(path.left(path.indexOf("/")).toLower())); return true; break; } diff --git a/src/input-box.cpp b/src/input-box.cpp index 2e9184d..9c232b1 100644 --- a/src/input-box.cpp +++ b/src/input-box.cpp @@ -84,7 +84,7 @@ void SearchBarHLayout::initUI() m_queryWidget->setStyleSheet("border:0px;background:transparent"); QHBoxLayout* queryWidLayout= new QHBoxLayout; - queryWidLayout->setContentsMargins(4,0,0,0); + queryWidLayout->setContentsMargins(8,4,0,0); queryWidLayout->setAlignment(Qt::AlignJustify); queryWidLayout->setSpacing(5); m_queryWidget->setLayout(queryWidLayout); @@ -99,13 +99,13 @@ void SearchBarHLayout::initUI() 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->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_queryIcon->width() + m_queryText->width() + 20, 35)); //设置图标初始位置 m_animation= new QPropertyAnimation(m_queryWidget,"geometry"); m_animation->setDuration(100); //动画时长 @@ -130,7 +130,7 @@ void SearchBarHLayout::focusOut() { m_queryText->adjustSize(); } 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_queryIcon->width() + m_queryText->width() + 20, 35)); //使图标回到初始位置 } void SearchBarHLayout::clearText() { @@ -148,7 +148,7 @@ bool SearchBarHLayout::eventFilter(QObject *watched, QEvent *event) if (m_queryLineEdit->text().isEmpty()) { m_animation->stop(); m_animation->setStartValue(m_queryWidget->geometry()); - m_animation->setEndValue(QRect(0, 0, m_queryIcon->width() + 5, 35)); + m_animation->setEndValue(QRect(0, 0, m_queryIcon->width() + 10, 35)); m_animation->setEasingCurve(QEasingCurve::OutQuad); m_animation->start(); } @@ -160,7 +160,7 @@ bool SearchBarHLayout::eventFilter(QObject *watched, QEvent *event) 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_queryIcon->width() + m_queryText->width() + 20, 35)); m_animation->setEasingCurve(QEasingCurve::InQuad); m_animation->start(); } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 91a1837..3618513 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -202,6 +202,7 @@ void MainWindow::initUi() mainlayout->addWidget(m_titleFrame); mainlayout->addWidget(m_contentFrame); mainlayout->addWidget(m_searchWidget); + mainlayout->setContentsMargins(16, 0, 16, 10); connect(QApplication::primaryScreen(), &QScreen::geometryChanged, this, &MainWindow::monitorResolutionChange); diff --git a/src/settings-widget.cpp b/src/settings-widget.cpp index 70e60ab..909eaf8 100644 --- a/src/settings-widget.cpp +++ b/src/settings-widget.cpp @@ -4,14 +4,16 @@ #include #include #include +#include #include "folder-list-item.h" #include "global-settings.h" #include "file-utils.h" #include "index/file-searcher.h" extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed); -SettingsWidget::SettingsWidget(QWidget *parent) : QWidget(parent) +SettingsWidget::SettingsWidget(QWidget *parent) : QDialog(parent) { + this->setWindowIcon(QIcon::fromTheme("kylin-search")); this->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint); this->setAttribute(Qt::WA_TranslucentBackground); initUi(); @@ -27,13 +29,12 @@ SettingsWidget::~SettingsWidget() * @brief SettingsWidget::initUi 初始化界面UI */ void SettingsWidget::initUi() { - this->setFixedWidth(528); - this->setMinimumHeight(460); - this->setMaximumHeight(680); +// this->setFixedWidth(528); +// this->setMinimumHeight(460); +// this->setMaximumHeight(680); m_mainLyt = new QVBoxLayout(this); - m_mainLyt->setContentsMargins(24, 9, 16, 24); + m_mainLyt->setContentsMargins(24, 9, 24, 24); this->setLayout(m_mainLyt); - this->setStyleSheet("QLabel{color: palette(text);}"); //标题栏 m_titleFrame = new QFrame(this); @@ -47,7 +48,7 @@ void SettingsWidget::initUi() { m_titleLabel->setText(tr("Search")); m_closeBtn = new QPushButton(m_titleFrame); m_closeBtn->setFixedSize(24, 24); - m_closeBtn->setIcon(QIcon(":/res/icons/close.svg")); +// m_closeBtn->setIcon(QIcon(":/res/icons/close.svg")); // m_closeBtn->setStyleSheet("QPushButton{background: transparent;}" // "QPushButton:hover:!pressed{background: transparent;}"); m_closeBtn->setIcon(QIcon::fromTheme("window-close-symbolic")); @@ -67,14 +68,12 @@ void SettingsWidget::initUi() { //设置 m_settingLabel = new QLabel(this); - m_settingLabel->setText(tr("Settings")); - m_settingLabel->setStyleSheet("QLabel{font-size: 24px; color: palette(text);}"); + m_settingLabel->setText(tr("

Settings

")); m_mainLyt->addWidget(m_settingLabel); //文件索引 m_indexTitleLabel = new QLabel(this); - m_indexTitleLabel->setText(tr("Index State")); - m_indexTitleLabel->setStyleSheet("QLabel{font-size: 16px; font-weight:bold; color: palette(text);}"); + m_indexTitleLabel->setText(tr("

Index State

")); m_indexStateLabel = new QLabel(this); m_indexStateLabel->setText(tr("...")); m_indexNumLabel = new QLabel(this); @@ -86,8 +85,7 @@ void SettingsWidget::initUi() { //文件索引设置(黑名单) m_indexSettingLabel = new QLabel(this); - m_indexSettingLabel->setText(tr("File Index Settings")); - m_indexSettingLabel->setStyleSheet("QLabel{font-size: 16px; font-weight:bold; color: palette(text);}"); + m_indexSettingLabel->setText(tr("

File Index Settings

")); m_indexDescLabel = new QLabel(this); m_indexDescLabel->setText(tr("Following folders will not be searched. You can set it by adding and removing folders.")); m_indexDescLabel->setWordWrap(true); @@ -119,8 +117,7 @@ void SettingsWidget::initUi() { //搜索引擎设置 m_searchEngineLabel = new QLabel(this); - m_searchEngineLabel->setText(tr("Search Engine Settings")); - m_searchEngineLabel->setStyleSheet("QLabel{font-size: 16px; font-weight:bold; color: palette(text);}"); + m_searchEngineLabel->setText(tr("

Search Engine Settings

")); m_engineDescLabel = new QLabel(this); m_engineDescLabel->setText(tr("Please select search engine you preferred.")); m_engineDescLabel->setWordWrap(true); @@ -183,13 +180,17 @@ void SettingsWidget::initUi() { */ void SettingsWidget::setupBlackList(const QStringList& list) { clearLayout(m_dirListLyt); + m_blockdirs = 0; Q_FOREACH(QString path, list) { FolderListItem * item = new FolderListItem(m_dirListWidget, path); m_dirListLyt->addWidget(item); - item->setMaximumWidth(470); + item->setMaximumWidth(this->width() - 52); connect(item, SIGNAL(onDelBtnClicked(const QString&)), this, SLOT(onBtnDelClicked(const QString&))); + m_blockdirs ++; } - m_dirListLyt->addStretch(); + this->resize(); + m_dirListWidget->setFixedWidth(this->width() - 52); +// m_dirListLyt->addStretch(); } /** @@ -239,6 +240,12 @@ void SettingsWidget::refreshIndexState() * @param path 文件夹路径 */ void SettingsWidget::onBtnDelClicked(const QString& path) { + QMessageBox message(QMessageBox::Question, tr("Search"), tr("Whether to delete this directory?"), QMessageBox::No | QMessageBox::Yes, this); + message.exec(); + if (message.clickedButton() != message.button(QMessageBox::Yes)) { + return; + } + QString returnMessage; if (GlobalSettings::getInstance()->setBlockDirs(path, returnMessage, true)) { qDebug()<<"Remove block dir in onBtnDelClicked() successed."; @@ -246,13 +253,17 @@ void SettingsWidget::onBtnDelClicked(const QString& path) { if (item->getPath() == path) { item->deleteLater(); item = NULL; + m_blockdirs --; + this->resize(); return; } } - } else { qWarning()<settings-widget.cpp #238"; +// QMessageBox::warning(this, tr("Search"), returnMessage); + + QMessageBox message(QMessageBox::Warning, tr("Search"), returnMessage, QMessageBox::Ok, this); + message.exec(); } } @@ -386,3 +401,15 @@ void SettingsWidget::paintEvent(QPaintEvent *event) { p.restore(); } + +/** + * @brief SettingsWidget::resize 重新计算窗口应有大小 + */ +void SettingsWidget::resize() +{ + if (m_blockdirs <= 1) { + this->setFixedSize(528, 455); + } else { + this->setFixedSize(528, 425 + 30 * m_blockdirs); + } +} diff --git a/src/settings-widget.h b/src/settings-widget.h index 0cfef85..00db04a 100644 --- a/src/settings-widget.h +++ b/src/settings-widget.h @@ -2,6 +2,7 @@ #define SETTINGSWIDGET_H #include +#include #include #include #include @@ -12,7 +13,7 @@ #include #include -class SettingsWidget : public QWidget +class SettingsWidget : public QDialog { Q_OBJECT public: @@ -29,6 +30,7 @@ private: void clearLayout(QLayout *); void refreshIndexState(); void paintEvent(QPaintEvent *); + void resize(); //标题栏 QVBoxLayout * m_mainLyt = nullptr; QFrame * m_titleFrame = nullptr; @@ -74,6 +76,8 @@ private: QTimer * m_timer; + int m_blockdirs = 0; //黑名单文件夹数量 + Q_SIGNALS: void settingWidgetClosed(); diff --git a/translations/ukui-search/bo.ts b/translations/ukui-search/bo.ts index 0419082..d83283b 100644 --- a/translations/ukui-search/bo.ts +++ b/translations/ukui-search/bo.ts @@ -145,113 +145,121 @@ SettingsWidget - + + + + Search - - Settings - - - - - Index State - - - - - + + ... - - File Index Settings - - - - + Following folders will not be searched. You can set it by adding and removing folders. - + Add ignored folders - Search Engine Settings - - - - Please select search engine you preferred. - + baidu - + sougou - + 360 - + Cancel - + Creating ... - + + <h2>Settings</h2> + + + + + <h3>Index State</h3> + + + + + <h3>File Index Settings</h3> + + + + + <h3>Search Engine Settings</h3> + + + + + Whether to delete this directory? + + + + Done - + Index Entry: %1 - + Directories - + select blocked folder - + Select - + Position: - + FileName: - + FileType: diff --git a/translations/ukui-search/tr.ts b/translations/ukui-search/tr.ts index 0419082..d83283b 100644 --- a/translations/ukui-search/tr.ts +++ b/translations/ukui-search/tr.ts @@ -145,113 +145,121 @@ SettingsWidget - + + + + Search - - Settings - - - - - Index State - - - - - + + ... - - File Index Settings - - - - + Following folders will not be searched. You can set it by adding and removing folders. - + Add ignored folders - Search Engine Settings - - - - Please select search engine you preferred. - + baidu - + sougou - + 360 - + Cancel - + Creating ... - + + <h2>Settings</h2> + + + + + <h3>Index State</h3> + + + + + <h3>File Index Settings</h3> + + + + + <h3>Search Engine Settings</h3> + + + + + Whether to delete this directory? + + + + Done - + Index Entry: %1 - + Directories - + select blocked folder - + Select - + Position: - + FileName: - + FileType: diff --git a/translations/ukui-search/zh_CN.ts b/translations/ukui-search/zh_CN.ts index dba6d32..4708052 100644 --- a/translations/ukui-search/zh_CN.ts +++ b/translations/ukui-search/zh_CN.ts @@ -145,121 +145,121 @@ SettingsWidget - + + + + Search 搜索 - - Settings - 配置项 + + <h2>Settings</h2> + <h2>设置</h2> - Index State - 索引状态 + <h3>Index State</h3> + <h3>索引状态</h3> - - + + ... - - File Index Settings - 文件索引设置 + + <h3>File Index Settings</h3> + <h3>文件索引设置</h3> - + Following folders will not be searched. You can set it by adding and removing folders. 搜索将不再查看以下文件夹。通过增加和删除文件夹可进行文件索引设置。 - + Add ignored folders 添加文件夹至黑名单 - - Search Engine Settings - 搜索引擎设置 + + <h3>Search Engine Settings</h3> + <h3>搜索引擎设置</h3> - + Please select search engine you preferred. 设置互联网搜索引擎 - + baidu 百度 - + sougou 搜狗 - + 360 360 - + + Whether to delete this directory? + 是否要删除此目录 + + + Cancel 取消 - Parent folder has been blocked! - 12345 - - - Confirm - 确认 - - - + Creating ... 正在索引 - + Done 索引完成 - + Index Entry: %1 索引项: %1 - + Directories 文件夹 - + select blocked folder 选择屏蔽文件夹 - + Select 选择 - + Position: 位置: - + FileName: 名称: - + FileType: 类型: