备份列表优化
This commit is contained in:
parent
cde6b9d95f
commit
a99dda1eab
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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"/>
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue