forked from openkylin/ukui-search
!4 修复部分UI问题
* Add a mainWindow switch dbus interface. * Fix#125632 action label's color doesn't change whth the heightlight color. * Fix#127327 adjust the heightlight effect of ukcc plugin's switchbutton * 处理富文本超长问题 * 解决结果列表点击收起按钮时位置错误的问题 * 优化关键词高亮方案,结果项显示效果适配主题框架。 * 修复标题栏展开置顶后,点击收回位置错误问题
This commit is contained in:
parent
68ab5f4dd4
commit
1fa78d4080
|
@ -458,12 +458,13 @@ void ResultArea::initConnections()
|
|||
connect(this->m_titleLabel, &TitleLabel::retractClicked, this, [=] () {
|
||||
Q_FOREACH(auto widget, m_widget_list) {
|
||||
if (widget->pluginName() == m_titleLabel->text()) {
|
||||
widget->reduceListSlot();
|
||||
widget->resetTitleLabel();
|
||||
if (!m_titleLabel->isHidden()) {
|
||||
m_titleLabel->hide();
|
||||
this->setViewportMargins(0,0,0,0);
|
||||
}
|
||||
widget->reduceListSlot();
|
||||
this->verticalScrollBar()->setValue(widget->pos().ry());
|
||||
widget->resetTitleLabel();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -510,8 +511,8 @@ void ResultArea::setupConnectionsForWidget(ResultWidget *widget)
|
|||
});
|
||||
connect(widget, &ResultWidget::retractClicked, this, [=] () {//点击收起搜索结果后
|
||||
if (!m_titleLabel->isHidden()) {
|
||||
m_titleLabel->hide();
|
||||
this->setViewportMargins(0,0,0,0);
|
||||
m_titleLabel->hide();
|
||||
}
|
||||
});
|
||||
connect(widget, &ResultWidget::sendBestListData, m_bestListWidget, &BestListWidget::sendBestListData);
|
||||
|
|
|
@ -327,6 +327,11 @@ void MainWindow::resizeHeight(int height)
|
|||
this->setFixedHeight(height);
|
||||
}
|
||||
|
||||
void MainWindow::tryHide()
|
||||
{
|
||||
this->tryHideMainwindow();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief monitorResolutionChange 监听屏幕改变
|
||||
* @param rect
|
||||
|
|
|
@ -110,6 +110,7 @@ public Q_SLOTS:
|
|||
void settingsBtnClickedSlot();
|
||||
void searchKeywordSlot(const QString&);
|
||||
void resizeHeight(int height);
|
||||
void tryHide();
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
@ -12,6 +12,15 @@ void UkuiSearchDbusServices::searchKeyword(QString keyword)
|
|||
m_mainWindow->setText(keyword);
|
||||
}
|
||||
|
||||
void UkuiSearchDbusServices::mainWindowSwitch()
|
||||
{
|
||||
if (m_mainWindow->isActiveWindow()) {
|
||||
m_mainWindow->tryHide();
|
||||
} else {
|
||||
m_mainWindow->bootOptionsFilter("-s");
|
||||
}
|
||||
}
|
||||
|
||||
UkuiSearchDbusServices::UkuiSearchDbusServices(MainWindow *m)
|
||||
{
|
||||
m_mainWindow = m;
|
||||
|
|
|
@ -20,9 +20,10 @@ public:
|
|||
public Q_SLOTS:
|
||||
void showWindow();
|
||||
void searchKeyword(QString keyword);
|
||||
void mainWindowSwitch();
|
||||
|
||||
private:
|
||||
MainWindow *m_mainWindow;
|
||||
MainWindow *m_mainWindow = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -3,15 +3,15 @@
|
|||
using namespace UkuiSearch;
|
||||
static ResultItemStyle *global_instance_of_item_style = nullptr;
|
||||
|
||||
ResultViewDelegate::ResultViewDelegate(QObject *parent) : QStyledItemDelegate(parent)
|
||||
ResultViewDelegate::ResultViewDelegate(QObject *parent) : QStyledItemDelegate(parent),
|
||||
m_textDoc(new QTextDocument(this)),
|
||||
m_hightLightEffectHelper(new HightLightEffectHelper(this))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ResultViewDelegate::setSearchKeyword(const QString ®FindKeyWords)
|
||||
{
|
||||
m_regFindKeyWords.clear();
|
||||
m_regFindKeyWords = regFindKeyWords;
|
||||
m_hightLightEffectHelper->setExpression(regFindKeyWords);
|
||||
}
|
||||
|
||||
QSize ResultViewDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
|
@ -21,90 +21,36 @@ QSize ResultViewDelegate::sizeHint(const QStyleOptionViewItem &option, const QMo
|
|||
return size;
|
||||
}
|
||||
|
||||
void ResultViewDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const {
|
||||
void ResultViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
QStyleOptionViewItem opt = option;
|
||||
initStyleOption(&opt, index);
|
||||
QStyle *style = opt.widget->style();
|
||||
opt.displayAlignment = Qt::Alignment(Qt::AlignLeft|Qt::AlignVCenter);
|
||||
|
||||
QString text = opt.text;
|
||||
if(text.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
opt.text = QString();
|
||||
|
||||
QStyle *style = opt.widget->style();
|
||||
style->proxy()->drawControl(QStyle::CE_ItemViewItem, &opt, painter, opt.widget); //绘制非文本区域内容
|
||||
|
||||
opt.text = text;
|
||||
QTextDocument doc;
|
||||
doc.setHtml(getHtmlText(painter, opt, index)); //提取富文本
|
||||
QAbstractTextDocumentLayout* layout = doc.documentLayout();
|
||||
const double height = layout->documentSize().height();
|
||||
|
||||
|
||||
QRect textRect = style->subElementRect(QStyle::SE_ItemViewItemText, &opt, opt.widget);
|
||||
//使图标和文本间隔与原来保持一致,故文本区域右移4
|
||||
// textRect.adjust(4, 0, 0, 0);
|
||||
double y = textRect.y();
|
||||
y += (textRect.height() - height) / 2;
|
||||
QFontMetrics fontMetrics(opt.font);
|
||||
text = fontMetrics.elidedText(text, Qt::ElideRight, textRect.width() - 5); //富余5px的宽度
|
||||
opt.text = text;
|
||||
|
||||
QAbstractTextDocumentLayout::PaintContext context;
|
||||
|
||||
QPalette::ColorGroup cg = opt.state & QStyle::State_Enabled
|
||||
? QPalette::Normal : QPalette::Disabled;
|
||||
if (cg == QPalette::Normal && !(opt.state & QStyle::State_Active))
|
||||
cg = QPalette::Inactive;
|
||||
|
||||
if(opt.state & QStyle::State_Selected) {
|
||||
painter->setPen(opt.palette.color(cg, QPalette::HighlightedText));
|
||||
} else {
|
||||
painter->setPen(opt.palette.color(cg, QPalette::Text));
|
||||
}
|
||||
painter->save();
|
||||
painter->translate(QPointF(textRect.x(), y));
|
||||
layout->draw(painter, context); //绘制文本区域内容
|
||||
painter->restore();
|
||||
|
||||
}
|
||||
|
||||
QString ResultViewDelegate::getHtmlText(QPainter *painter, const QStyleOptionViewItem &itemOption, const QModelIndex &index) const
|
||||
{
|
||||
int indexFindLeft = 0;
|
||||
QString indexString = index.model()->data(index, Qt::DisplayRole).toString();
|
||||
QFont ft(painter->font().family(), GlobalSettings::getInstance()->getValue(FONT_SIZE_KEY).toInt());
|
||||
QFontMetrics fm(ft);
|
||||
QString indexColString = fm.elidedText(indexString, Qt::ElideRight, itemOption.rect.width() - 30 - 10); //当字体超过Item的长度时显示为省略号
|
||||
QString htmlString;
|
||||
if((indexColString.toUpper()).contains((m_regFindKeyWords.toUpper()))) {
|
||||
indexFindLeft = indexColString.toUpper().indexOf(m_regFindKeyWords.toUpper()); //得到查找字体在当前整个Item字体中的位置
|
||||
htmlString = escapeHtml(indexColString.left(indexFindLeft)) + "<b>" + escapeHtml(indexColString.mid(indexFindLeft, m_regFindKeyWords.length())) + "</b>" + escapeHtml(indexColString.right(indexColString.length() - indexFindLeft - m_regFindKeyWords.length()));
|
||||
if(opt.state & QStyle::State_Selected) {
|
||||
m_hightLightEffectHelper->setTextColor(QBrush(opt.palette.highlightedText().color()));
|
||||
} else {
|
||||
bool boldOpenned = false;
|
||||
for(int i = 0; i < indexColString.length(); i++) {
|
||||
if((m_regFindKeyWords.toUpper()).contains(QString(indexColString.at(i)).toUpper())) {
|
||||
if(! boldOpenned) {
|
||||
boldOpenned = true;
|
||||
htmlString.append(QString("<b>"));
|
||||
}
|
||||
htmlString.append(escapeHtml(QString(indexColString.at(i))));
|
||||
} else {
|
||||
if(boldOpenned) {
|
||||
boldOpenned = false;
|
||||
htmlString.append(QString("</b>"));
|
||||
}
|
||||
htmlString.append(escapeHtml(QString(indexColString.at(i))));
|
||||
|
||||
}
|
||||
}
|
||||
m_hightLightEffectHelper->setTextColor(QBrush(opt.palette.text().color()));
|
||||
}
|
||||
// qDebug()<<indexColString<<"---->"<<htmlString;
|
||||
return "<pre>" + htmlString + "</pre>";
|
||||
}
|
||||
painter->translate(textRect.topLeft());
|
||||
|
||||
QString ResultViewDelegate::escapeHtml(const QString &str) const
|
||||
{
|
||||
QString temp = str;
|
||||
temp.replace("<", "<");
|
||||
temp.replace(">", ">");
|
||||
return temp;
|
||||
m_textDoc->setPlainText(text);
|
||||
m_hightLightEffectHelper->setDocument(m_textDoc);
|
||||
m_hightLightEffectHelper->rehighlight();
|
||||
m_textDoc->drawContents(painter);
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
ResultItemStyle *ResultItemStyle::getStyle()
|
||||
|
@ -259,3 +205,32 @@ void ResultItemStyle::drawControl(QStyle::ControlElement element, const QStyleOp
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
HightLightEffectHelper::HightLightEffectHelper(QObject *parent) : QSyntaxHighlighter(parent)
|
||||
{
|
||||
m_expression.setCaseSensitivity(Qt::CaseInsensitive);
|
||||
}
|
||||
|
||||
void HightLightEffectHelper::setExpression(const QString &text)
|
||||
{
|
||||
m_expression.setPattern(text);
|
||||
}
|
||||
|
||||
void HightLightEffectHelper::setTextColor(const QBrush &brush)
|
||||
{
|
||||
m_textCharFormat.setForeground(brush);
|
||||
}
|
||||
|
||||
void HightLightEffectHelper::highlightBlock(const QString &text)
|
||||
{
|
||||
setFormat(0, text.length(), m_textCharFormat);
|
||||
|
||||
m_textCharFormat.setFontWeight(QFont::Bold);
|
||||
int index = text.indexOf(m_expression);
|
||||
while(index >= 0){
|
||||
int length = m_expression.matchedLength();
|
||||
setFormat(index, length, m_textCharFormat);
|
||||
index = text.indexOf(m_expression, index+length);
|
||||
}
|
||||
m_textCharFormat.setFontWeight(QFont::Normal);
|
||||
}
|
||||
|
|
|
@ -27,10 +27,29 @@
|
|||
#include <QTextDocument>
|
||||
#include <QAbstractTextDocumentLayout>
|
||||
#include <QProxyStyle>
|
||||
#include <QSyntaxHighlighter>
|
||||
#include <QTextCharFormat>
|
||||
#include <QRegExp>
|
||||
#include "global-settings.h"
|
||||
|
||||
namespace UkuiSearch {
|
||||
class ResultViewDelegate : public QStyledItemDelegate {
|
||||
class HightLightEffectHelper : public QSyntaxHighlighter
|
||||
{
|
||||
public:
|
||||
explicit HightLightEffectHelper(QObject *parent = nullptr);
|
||||
void setExpression(const QString &text);
|
||||
void setTextColor(const QBrush &brush);
|
||||
|
||||
protected:
|
||||
void highlightBlock(const QString &text);
|
||||
|
||||
private:
|
||||
QRegExp m_expression;
|
||||
QTextCharFormat m_textCharFormat;
|
||||
};
|
||||
|
||||
class ResultViewDelegate : public QStyledItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ResultViewDelegate(QObject *parent = nullptr);
|
||||
|
@ -38,11 +57,12 @@ public:
|
|||
void setSearchKeyword(const QString &);
|
||||
protected:
|
||||
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
private:
|
||||
QString m_regFindKeyWords = 0;
|
||||
void paint(QPainter *, const QStyleOptionViewItem &, const QModelIndex &) const override;
|
||||
QString getHtmlText(QPainter *, const QStyleOptionViewItem &, const QModelIndex &) const;
|
||||
QString escapeHtml(const QString&) const;
|
||||
|
||||
private:
|
||||
QTextDocument *m_textDoc = nullptr;
|
||||
HightLightEffectHelper *m_hightLightEffectHelper = nullptr;
|
||||
|
||||
};
|
||||
|
||||
class ResultItemStyle : public QProxyStyle
|
||||
|
|
|
@ -7,7 +7,7 @@ TEMPLATE = lib
|
|||
DEFINES += LIBSEARCH_LIBRARY
|
||||
CONFIG += create_pc create_prl no_install_prl
|
||||
|
||||
PKGCONFIG += gio-2.0 glib-2.0 gio-unix-2.0 gsettings-qt poppler-qt5
|
||||
PKGCONFIG += gio-2.0 glib-2.0 gio-unix-2.0 gsettings-qt poppler-qt5 kysdk-qtwidgets
|
||||
|
||||
CONFIG += c++11 link_pkgconfig no_keywords lrelease
|
||||
QMAKE_CXXFLAGS += -Werror=return-type -Werror=return-local-addr -Werror=uninitialized
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#define ACTION_HOVER_COLOR QColor(64, 169, 251, 255)
|
||||
#define ACTION_PRESS_COLOR QColor(41, 108, 217, 255)
|
||||
using namespace UkuiSearch;
|
||||
ActionLabel::ActionLabel(const QString &action, const QString &key, QWidget *parent) : QLabel(parent)
|
||||
ActionLabel::ActionLabel(const QString &action, const QString &key, QWidget *parent) : KBorderlessButton(parent)
|
||||
{
|
||||
m_action = action;
|
||||
m_key = key;
|
||||
|
@ -33,32 +33,40 @@ ActionLabel::ActionLabel(const QString &action, const QString &key, QWidget *par
|
|||
void ActionLabel::initUi()
|
||||
{
|
||||
this->setText(m_action);
|
||||
QPalette pal = palette();
|
||||
pal.setColor(QPalette::WindowText, ACTION_NORMAL_COLOR);
|
||||
pal.setColor(QPalette::Light, ACTION_HOVER_COLOR);
|
||||
pal.setColor(QPalette::Dark, ACTION_PRESS_COLOR);
|
||||
this->setPalette(pal);
|
||||
this->setForegroundRole(QPalette::WindowText);
|
||||
// QPalette pal = palette();
|
||||
// pal.setColor(QPalette::WindowText, ACTION_NORMAL_COLOR);
|
||||
// pal.setColor(QPalette::Light, ACTION_HOVER_COLOR);
|
||||
// pal.setColor(QPalette::Dark, ACTION_PRESS_COLOR);
|
||||
// this->setPalette(pal);
|
||||
// this->setForegroundRole(QPalette::WindowText);
|
||||
this->setCursor(QCursor(Qt::PointingHandCursor));
|
||||
}
|
||||
|
||||
bool ActionLabel::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
if (watched == this) {
|
||||
if(event->type() == QEvent::MouseButtonPress) {
|
||||
this->setForegroundRole(QPalette::Dark);
|
||||
return true;
|
||||
} else if(event->type() == QEvent::MouseButtonRelease) {
|
||||
if (event->type() == QEvent::MouseButtonRelease) {
|
||||
Q_EMIT this->actionTriggered(m_action);
|
||||
this->setForegroundRole(QPalette::Light);
|
||||
return true;
|
||||
} else if(event->type() == QEvent::Enter) {
|
||||
this->setForegroundRole(QPalette::Light);
|
||||
return true;
|
||||
} else if(event->type() == QEvent::Leave) {
|
||||
this->setForegroundRole(QPalette::WindowText);
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
|
||||
// if (watched == this) {
|
||||
// if(event->type() == QEvent::MouseButtonPress) {
|
||||
// this->setForegroundRole(QPalette::Dark);
|
||||
// return true;
|
||||
// } else if(event->type() == QEvent::MouseButtonRelease) {
|
||||
// Q_EMIT this->actionTriggered(m_action);
|
||||
// this->setForegroundRole(QPalette::Light);
|
||||
// return true;
|
||||
// } else if(event->type() == QEvent::Enter) {
|
||||
// this->setForegroundRole(QPalette::Light);
|
||||
// return true;
|
||||
// } else if(event->type() == QEvent::Leave) {
|
||||
// this->setForegroundRole(QPalette::WindowText);
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
return KBorderlessButton::eventFilter(watched, event);
|
||||
}
|
||||
|
|
|
@ -23,8 +23,9 @@
|
|||
#include <QObject>
|
||||
#include <QLabel>
|
||||
#include <QEvent>
|
||||
#include <kborderlessbutton.h>
|
||||
namespace UkuiSearch {
|
||||
class ActionLabel : public QLabel
|
||||
class ActionLabel : public kdk::KBorderlessButton
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
|
|
@ -6,7 +6,7 @@ target.path = $$[QT_INSTALL_LIBS]/ukui-control-center/
|
|||
|
||||
CONFIG += plugin link_pkgconfig c++11 lrelease
|
||||
|
||||
PKGCONFIG += gio-2.0 gio-unix-2.0 gsettings-qt
|
||||
PKGCONFIG += gio-2.0 gio-unix-2.0 gsettings-qt kysdk-qtwidgets
|
||||
|
||||
LIBS += -L$$[QT_INSTALL_LIBS] -lgsettings-qt
|
||||
LIBS += -lukcc
|
||||
|
|
|
@ -65,7 +65,7 @@ QWidget *Search::pluginUi()
|
|||
m_webEngineFrame->mCombox->blockSignals(false);
|
||||
}
|
||||
});
|
||||
connect(m_searchMethodBtn, &SwitchButton::checkedChanged, this, [ = ](bool checked) {
|
||||
connect(m_searchMethodBtn, &kdk::KSwitchButton::stateChanged, this, [ = ](bool checked) {
|
||||
if (m_gsettings && m_gsettings->keys().contains(SEARCH_METHOD_KEY)) {
|
||||
m_gsettings->set(SEARCH_METHOD_KEY, checked);
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ void Search::initUi()
|
|||
m_descLabel2->setEnabled(false);
|
||||
m_descFrameLyt->addWidget(m_descLabel1);
|
||||
m_descFrameLyt->addWidget(m_descLabel2);
|
||||
m_searchMethodBtn = new SwitchButton(m_searchMethodFrame);
|
||||
m_searchMethodBtn = new kdk::KSwitchButton(m_searchMethodFrame);
|
||||
m_searchMethodLyt->addWidget(m_descFrame);
|
||||
m_searchMethodLyt->addStretch();
|
||||
m_searchMethodLyt->addWidget(m_searchMethodBtn);
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
#include <QPushButton>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include <kswitchbutton.h>
|
||||
|
||||
#include <ukcc/interface/interface.h>
|
||||
#include <ukcc/widgets/comboboxitem.h>
|
||||
#include <ukcc/widgets/switchbutton.h>
|
||||
|
@ -75,7 +77,7 @@ private:
|
|||
QFrame *m_searchMethodFrame = nullptr;
|
||||
QHBoxLayout *m_searchMethodLyt = nullptr;
|
||||
// QLabel *m_searchMethodLabel = nullptr;
|
||||
SwitchButton * m_searchMethodBtn = nullptr;
|
||||
kdk::KSwitchButton *m_searchMethodBtn = nullptr;
|
||||
//设置搜索引擎
|
||||
TitleLabel * m_webEngineLabel = nullptr;
|
||||
ComboxFrame * m_webEngineFrame = nullptr;
|
||||
|
|
Loading…
Reference in New Issue