Merge pull request #199 from mammonsama666/0415-dev

Fix: Font-size & row height will not refresh in search list.
This commit is contained in:
iaom 2021-04-16 09:45:46 +08:00 committed by GitHub
commit d4b6336400
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 62 additions and 3 deletions

View File

@ -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());
}
}

View File

@ -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"

View File

@ -25,6 +25,7 @@
#include <QDebug>
#include <QTextDocument>
#include <QAbstractTextDocumentLayout>
#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字体中的位置

View File

@ -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;}");

View File

@ -56,6 +56,7 @@ private:
QLabel * m_namelabel = nullptr;
double m_transparency = 0;
QString m_path;
int m_type = 0;
};
#endif // HOMEPAGEITEM_H

View File

@ -21,9 +21,13 @@
#include "search-list-view.h"
#include <QDebug>
#include <QFileInfo>
#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);

18
src/custom-style.cpp Normal file
View File

@ -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);
}

14
src/custom-style.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef CUSTOMSTYLE_H
#define CUSTOMSTYLE_H
#include <QProxyStyle>
#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

View File

@ -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 \