diff --git a/libsearch/global-settings.cpp b/libsearch/global-settings.cpp index a70199d..34b7176 100644 --- a/libsearch/global-settings.cpp +++ b/libsearch/global-settings.cpp @@ -77,8 +77,18 @@ GlobalSettings::GlobalSettings(QObject *parent) : QObject(parent) if (key == STYLE_NAME_KEY) { //当前主题改变时也发出paletteChanged信号,通知主界面刷新 qApp->paletteChanged(qApp->palette()); + m_cache.remove(STYLE_NAME_KEY); + m_cache.insert(STYLE_NAME_KEY, m_theme_gsettings->get(STYLE_NAME_KEY).toString()); + } else if (key == FONT_SIZE_KEY) { + qApp->paletteChanged(qApp->palette()); + m_cache.remove(FONT_SIZE_KEY); + m_cache.insert(FONT_SIZE_KEY, m_theme_gsettings->get(FONT_SIZE_KEY).toDouble()); } }); + m_cache.remove(STYLE_NAME_KEY); + m_cache.insert(STYLE_NAME_KEY, m_theme_gsettings->get(STYLE_NAME_KEY).toString()); + m_cache.remove(FONT_SIZE_KEY); + m_cache.insert(FONT_SIZE_KEY, m_theme_gsettings->get(FONT_SIZE_KEY).toDouble()); } } diff --git a/libsearch/global-settings.h b/libsearch/global-settings.h index 858185c..87b9a61 100644 --- a/libsearch/global-settings.h +++ b/libsearch/global-settings.h @@ -39,6 +39,7 @@ #define TRANSPARENCY_KEY "transparency" #define THEME_GSETTINGS_ID "org.ukui.style" #define STYLE_NAME_KEY "styleName" +#define FONT_SIZE_KEY "systemFontSize" #define INDEX_DATABASE_STATE "index_database_state" #define CONTENT_INDEX_DATABASE_STATE "content_index_database_state" #define INDEX_GENERATOR_NORMAL_EXIT "index_generator_normal_exit" diff --git a/src/control/highlight-item-delegate.cpp b/src/control/highlight-item-delegate.cpp index 9aae3d8..334a8bc 100644 --- a/src/control/highlight-item-delegate.cpp +++ b/src/control/highlight-item-delegate.cpp @@ -25,6 +25,7 @@ #include #include #include +#include "global-settings.h" HighlightItemDelegate::HighlightItemDelegate(QObject *parent) : QStyledItemDelegate (parent) { @@ -83,8 +84,11 @@ 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() + 10); //当字体超过Item的长度时显示为省略号 + 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() + 10); //当字体超过Item的长度时显示为省略号 +// QFontMetrics m_QFontMetrics = painter->fontMetrics(); +// 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/home-page-item.cpp b/src/control/home-page-item.cpp index 7ee8c35..d98bbc2 100644 --- a/src/control/home-page-item.cpp +++ b/src/control/home-page-item.cpp @@ -35,7 +35,11 @@ HomePageItem::HomePageItem(QWidget *parent, const int& type, const QString& path connect(qApp, &QApplication::paletteChanged, this, [ = ]() { if (m_namelabel) { QString name = this->toolTip(); - m_namelabel->setText(m_namelabel->fontMetrics().elidedText(name, Qt::ElideRight, 108)); + if (m_type == ItemType::Recent) { + m_namelabel->setText(m_namelabel->fontMetrics().elidedText(name, Qt::ElideRight, 250)); + } else { + m_namelabel->setText(m_namelabel->fontMetrics().elidedText(name, Qt::ElideRight, 108)); + } } }); } @@ -51,6 +55,7 @@ HomePageItem::~HomePageItem() */ void HomePageItem::setupUi(const int& type, const QString& path) { m_path = path; + m_type = type; m_widget = new QWidget(this); m_widget->setObjectName("MainWidget"); // m_widget->setStyleSheet("QWidget#MainWidget{background: rgba(0, 0, 0, 0.05); border-radius: 4px;}"); diff --git a/src/control/home-page-item.h b/src/control/home-page-item.h index 1c8fa61..58acdac 100644 --- a/src/control/home-page-item.h +++ b/src/control/home-page-item.h @@ -56,6 +56,7 @@ private: QLabel * m_namelabel = nullptr; double m_transparency = 0; QString m_path; + int m_type = 0; }; #endif // HOMEPAGEITEM_H diff --git a/src/control/search-list-view.cpp b/src/control/search-list-view.cpp index 5fcca26..a4ddca6 100644 --- a/src/control/search-list-view.cpp +++ b/src/control/search-list-view.cpp @@ -21,9 +21,13 @@ #include "search-list-view.h" #include #include +#include "custom-style.h" SearchListView::SearchListView(QWidget * parent, const QStringList& list, const int& type) : QTreeView(parent) { + CustomStyle * style = new CustomStyle(GlobalSettings::getInstance()->getValue(STYLE_NAME_KEY).toString()); + this->setStyle(style); + this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setSelectionBehavior(QAbstractItemView::SelectRows); setSelectionMode(QAbstractItemView::SingleSelection); diff --git a/src/custom-style.cpp b/src/custom-style.cpp new file mode 100644 index 0000000..2e82aa8 --- /dev/null +++ b/src/custom-style.cpp @@ -0,0 +1,18 @@ +#include "custom-style.h" + +CustomStyle::CustomStyle(const QString &proxyStyleName, QObject *parent) : QProxyStyle(proxyStyleName) +{ + +} + +QSize CustomStyle::sizeFromContents(QStyle::ContentsType type, const QStyleOption *option, const QSize &contentsSize, const QWidget *widget) const +{ + switch (type) { + case CT_ItemViewItem: { + QSize size(0, GlobalSettings::getInstance()->getValue(FONT_SIZE_KEY).toDouble() * 2); + return size; + } break; + default: break; + } + return QProxyStyle::sizeFromContents(type, option, contentsSize, widget); +} diff --git a/src/custom-style.h b/src/custom-style.h new file mode 100644 index 0000000..c220bc5 --- /dev/null +++ b/src/custom-style.h @@ -0,0 +1,14 @@ +#ifndef CUSTOMSTYLE_H +#define CUSTOMSTYLE_H +#include +#include "global-settings.h" + +class CustomStyle : public QProxyStyle +{ + Q_OBJECT +public: + explicit CustomStyle(const QString &proxyStyleName = "windows",QObject *parent = nullptr); + virtual QSize sizeFromContents(QStyle::ContentsType type, const QStyleOption *option, const QSize &contentsSize, const QWidget *widget = nullptr) const; +}; + +#endif // CUSTOMSTYLE_H diff --git a/src/src.pro b/src/src.pro index 9b1133f..31dc032 100644 --- a/src/src.pro +++ b/src/src.pro @@ -26,6 +26,7 @@ include(singleapplication/qt-single-application.pri) SOURCES += \ content-widget.cpp \ + custom-style.cpp \ input-box.cpp \ main.cpp \ mainwindow.cpp \ @@ -37,6 +38,7 @@ SOURCES += \ HEADERS += \ content-widget.h \ + custom-style.h \ input-box.h \ mainwindow.h \ search-app-thread.h \