备份列表优化

This commit is contained in:
zhaominyong 2022-03-21 11:02:27 +08:00
parent cde6b9d95f
commit a99dda1eab
5 changed files with 42 additions and 9 deletions

View File

@ -6,6 +6,8 @@
#include <QFileInfo>
#include "mylabel.h"
#include "../messageboxutils.h"
#include "../gsettingswrapper.h"
#include "../globalbackupinfo.h"
MyItemWidget::MyItemWidget(QWidget* parent) :
QWidget(parent)
@ -58,8 +60,6 @@ BackupListWidget::BackupListWidget(QWidget *parent /*= nullptr*/) :
if (widget)
emit widget->selected(false);
}
// repaint();
});
}
@ -88,21 +88,30 @@ bool BackupListWidget::appendItem(const QString &text)
QListWidgetItem *item = new QListWidgetItem(this, m_type);
item->setSizeHint(QSize(this->width() - 5, 36));
MyItemWidget *widget = new MyItemWidget(this);
widget->setMaximumWidth(this->width() - 5);
widget->setMinimumWidth(this->width() - 5);
widget->setFixedHeight(36);
widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
QHBoxLayout *hlayout = new QHBoxLayout;
hlayout->setContentsMargins(5, 2, 2, 2);
MyLabel *label = new MyLabel;
label->setDeplayText(text);
label->setToolTip(text);
label->setMinimumWidth(this->width() - 12);
label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
label->setIsOriginal(true);
label->setElidedText(text, Qt::ElideLeft);
label->setToolTip(text);
hlayout->addWidget(label);
hlayout->setAlignment(label, Qt::AlignLeft);
m_List << text;
connect(GlobelBackupInfo::inst().getGlobalSignals(), &GlobalSignals::fontChanged, this, [=](int fontSize) {
QFont font = label->font();
font.setPointSize(fontSize);
label->setFont(font);
// 字体家族、大小变化需重绘,并且字体大小变化也可能会造成显示不全问题
label->setElidedText(text, Qt::ElideLeft);
});
QPushButton *buttonDelete = new QPushButton;
// buttonDelete->setProperty("isWindowButton", 0x2);
// buttonDelete->setProperty("useIconHighlightEffect", 0x8);
@ -110,8 +119,8 @@ bool BackupListWidget::appendItem(const QString &text)
buttonDelete->setFixedSize(20, 20);
buttonDelete->setIcon(QIcon::fromTheme("window-close-symbolic"));
buttonDelete->setVisible(false);
hlayout->addWidget(buttonDelete);
hlayout->setSpacing(5);
hlayout->addWidget(buttonDelete);
hlayout->setAlignment(buttonDelete, Qt::AlignRight);
widget->setLayout(hlayout);
@ -122,13 +131,18 @@ bool BackupListWidget::appendItem(const QString &text)
connect(widget, &MyItemWidget::selected, buttonDelete, [=](bool checked) {
if (checked) {
buttonDelete->setVisible(true);
// label->setMinimumWidth(this->width() - 12 - 30);
label->setFixedWidth(this->width() - 12 - 20);
label->setElidedText(text, Qt::ElideLeft);
} else {
buttonDelete->setVisible(false);
label->setFixedWidth(this->width() - 12);
label->setElidedText(text, Qt::ElideLeft);
}
});
connect(buttonDelete, &QPushButton::clicked, this, [=]() {
this->m_List.removeOne(label->text());
this->m_List.removeOne(label->getOriginalText());
this->removeItemWidget(item);
this->takeItem(this->row(item));
delete item;

View File

@ -88,6 +88,23 @@ MyLabel::MyLabel(const QString& text, QWidget* parent /*= nullptr*/, Qt::Alignme
MyLabel::~MyLabel()
{}
/**
* @brief
* @param text
* @note label固定大小或最小及其大小策略
*/
void MyLabel::setElidedText(const QString& text, Qt::TextElideMode mode/* = Qt::ElideRight*/)
{
m_text = text;
QFontMetrics fontMetrics(this->font());
int fontSize = fontMetrics.width(m_text);
if (fontSize > this->width()) {
this->setText(fontMetrics.elidedText(m_text, mode, this->width()));
} else {
this->setText(m_text);
}
}
/**
* @brief 使Qt::black这种模式的
* @param color

View File

@ -12,7 +12,9 @@ public:
MyLabel(const QString& text, QWidget* parent = nullptr, Qt::Alignment align = Qt::AlignCenter);
virtual ~MyLabel();
const QString & getOriginalText() const { return m_text; }
void setDeplayText(const QString& text) { m_text = text; this->setText(text);}
void setElidedText(const QString& text, Qt::TextElideMode mode = Qt::ElideRight);
void setFontColor(QColor color);
void setFontSize(int size);
void setFontWordWrap(bool on);

View File

@ -39,7 +39,7 @@
<message>
<location filename="component/backuplistwidget.cpp" line="34"/>
<source>File drag and drop area</source>
<translation></translation>
<translation></translation>
</message>
</context>
<context>
@ -185,7 +185,7 @@
<location filename="module/databackup.cpp" line="337"/>
<location filename="module/databackup.cpp" line="578"/>
<source>Clear</source>
<translation></translation>
<translation></translation>
</message>
<message>
<location filename="module/databackup.cpp" line="404"/>