This commit is contained in:
zhaominyong 2022-04-12 11:27:37 +08:00
parent 16327ed35e
commit 43d2122939
12 changed files with 174 additions and 112 deletions

View File

@ -34,21 +34,22 @@ BackupPointListDialog::BackupPointListDialog(QWidget *parent, bool isOnlyShowLoc
m_tableWidget = new QTableWidget;
m_tableWidget->setColumnCount(headerLabels.size());
m_tableWidget->setHorizontalHeaderLabels(headerLabels);
m_tableWidget->horizontalHeader()->setDefaultAlignment(Qt::AlignCenter);
m_tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
// m_tableWidget->horizontalHeader()->resizeSection(Column_Index::Backup_Name, 200);
// m_tableWidget->horizontalHeader()->resizeSection(Column_Index::UUID, 310);
// m_tableWidget->horizontalHeader()->resizeSection(Column_Index::Backup_Time, 150);
// m_tableWidget->horizontalHeader()->resizeSection(Column_Index::Backup_Size, 120);
// m_tableWidget->horizontalHeader()->setSectionResizeMode(Column_Index::Backup_Device, QHeaderView::Stretch);
// m_tableWidget->horizontalHeader()->resizeSection(Column_Index::Backup_State, 150);
m_tableWidget->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
// m_tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
m_tableWidget->horizontalHeader()->resizeSection(Column_Index::Backup_Name, 200);
// m_tableWidget->horizontalHeader()->resizeSection(Column_Index::UUID, 310);
m_tableWidget->horizontalHeader()->resizeSection(Column_Index::Backup_Time, 150);
m_tableWidget->horizontalHeader()->resizeSection(Column_Index::Backup_Size, 120);
m_tableWidget->horizontalHeader()->setSectionResizeMode(Column_Index::Backup_Device, QHeaderView::Stretch);
m_tableWidget->horizontalHeader()->resizeSection(Column_Index::Backup_State, 150);
m_tableWidget->horizontalHeader()->setTextElideMode( Qt::ElideRight);
m_tableWidget->horizontalHeader()->setFixedHeight(30);
m_tableWidget->horizontalHeader()->setFixedHeight(36);
m_tableWidget->verticalHeader()->setHidden(true); // 好像隐藏不掉
m_tableWidget->verticalHeader()->setVisible(false); //左侧标题不可见
m_tableWidget->verticalHeader()->setDefaultSectionSize(30); // 设置行高
m_tableWidget->verticalHeader()->setDefaultSectionSize(36); // 设置行高
m_tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
m_tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
m_tableWidget->hideColumn(Column_Index::UUID);
m_tableWidget->hideColumn(Column_Index::Prefix_Path);
m_tableWidget->setSortingEnabled(false); // 等录入完数据后再排序
m_tableWidget->setAlternatingRowColors(true);
@ -63,10 +64,8 @@ BackupPointListDialog::BackupPointListDialog(QWidget *parent, bool isOnlyShowLoc
// 添加本地默认路径、移动设备目录
connect(m_udector, &UdiskDetector::udiskListChanged, this, [=](QList<QStorageInfo> diskList) {
this->m_udiskPaths.clear();
// 如果有备份分区,则将本地默认分区备份路径放在第一个
if (GlobelBackupInfo::inst().hasBackupPartition()) {
this->m_udiskPaths << Utils::getSysRootPath();
}
// 将本地默认备份路径放在第一个
this->m_udiskPaths << Utils::getSysRootPath();
if (this->m_onlyShowLocal)
return;

View File

@ -45,7 +45,7 @@ signals:
protected:
void keyPressEvent(QKeyEvent* event);
void setItem(int row, int column, const QString& text, int alignFlag = Qt::AlignCenter);
void setItem(int row, int column, const QString& text, int alignFlag = Qt::AlignLeft | Qt::AlignVCenter);
QString text(int row, int column);
QTableWidget *m_tableWidget;

View File

@ -4,14 +4,78 @@
#include <QPushButton>
#include <QMimeData>
#include <QFileInfo>
#include "mylabel.h"
#include <QScrollBar>
#include "../messageboxutils.h"
#include "../gsettingswrapper.h"
#include "../globalbackupinfo.h"
#define WIDTH_ITEM 36
MyItemWidget::MyItemWidget(QWidget* parent) :
QWidget(parent)
{}
{
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
QHBoxLayout *hlayout = new QHBoxLayout;
hlayout->setContentsMargins(5, 2, 2, 2);
hlayout->setSpacing(5);
m_label = new MyLabel;
m_label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
m_label->setIsOriginal(true);
QPushButton *buttonDelete = new QPushButton;
// buttonDelete->setProperty("isWindowButton", 0x2);
// buttonDelete->setProperty("useIconHighlightEffect", 0x8);
buttonDelete->setFlat(true);
buttonDelete->setFixedSize(20, 20);
buttonDelete->setIcon(QIcon::fromTheme("window-close-symbolic"));
buttonDelete->setVisible(false);
hlayout->addWidget(m_label);
hlayout->addWidget(buttonDelete);
hlayout->setAlignment(Qt::AlignLeft);
connect(this, &MyItemWidget::setScrollWidth, this, [=](int width) {
int labelWidth = this->m_label->width();
this->m_label->setFixedWidth(labelWidth + (m_scrollWidth - width));
this->m_label->setElidedText(this->m_text, Qt::ElideLeft);
m_scrollWidth = width;
});
connect(GlobelBackupInfo::inst().getGlobalSignals(), &GlobalSignals::fontChanged, this, [=](int fontSize) {
QFont font = this->m_label->font();
font.setPointSize(fontSize);
this->m_label->setFont(font);
// 字体家族、大小变化需重绘,并且字体大小变化也可能会造成显示不全问题
this->m_label->setElidedText(this->m_text, Qt::ElideLeft);
});
connect(this, &MyItemWidget::selected, buttonDelete, [=](bool checked) {
if (checked) {
buttonDelete->setVisible(true);
this->m_label->setFixedWidth(this->width() - 12 - 20 - this->m_scrollWidth);
this->m_label->setElidedText(this->m_text, Qt::ElideLeft);
} else {
buttonDelete->setVisible(false);
this->m_label->setFixedWidth(this->width() - 7 - this->m_scrollWidth);
this->m_label->setElidedText(this->m_text, Qt::ElideLeft);
}
});
connect(buttonDelete, &QPushButton::clicked, this, &MyItemWidget::deleteItem);
this->setLayout(hlayout);
}
void MyItemWidget::setText(const QString& text)
{
m_text = text;
m_label->setFixedWidth(this->width() - 7 - this->m_scrollWidth);
m_label->setElidedText(m_text, Qt::ElideLeft);
m_label->setToolTip(m_text);
}
MyItemWidget::~MyItemWidget()
{}
@ -22,12 +86,14 @@ BackupListWidget::BackupListWidget(QWidget *parent /*= nullptr*/) :
setSortingEnabled(false);
setAcceptDrops(true);
setAlternatingRowColors(true);
// setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
// 设置为无边框默认时为StyledPanel
// setFrameShape(QListWidget::NoFrame);
// 列表为空时,展示一个“+”号图标和拖拽文件提示
m_plusLogo = new QLabel;
m_plusLogo->setFixedHeight(36);
m_plusLogo->setFixedHeight(WIDTH_ITEM);
QIcon icon = QIcon::fromTheme("list-add-symbolic", QIcon(":/symbos/list-add-symbolic.png"));
m_plusLogo->setPixmap(icon.pixmap(icon.actualSize(QSize(16, 16))));
m_plusLogo->setEnabled(false);
@ -86,63 +152,26 @@ bool BackupListWidget::appendItem(const QString &text)
++count;
QListWidgetItem *item = new QListWidgetItem(this, m_type);
item->setSizeHint(QSize(this->width() - 5, 36));
MyItemWidget *widget = new MyItemWidget(this);
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->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);
buttonDelete->setFlat(true);
buttonDelete->setFixedSize(20, 20);
buttonDelete->setIcon(QIcon::fromTheme("window-close-symbolic"));
buttonDelete->setVisible(false);
hlayout->setSpacing(5);
hlayout->addWidget(buttonDelete);
hlayout->setAlignment(buttonDelete, Qt::AlignRight);
widget->setLayout(hlayout);
item->setSizeHint(QSize(this->width() - 5, WIDTH_ITEM));
MyItemWidget *widget = new MyItemWidget;
this->setItemWidget(item, widget);
this->setCurrentRow(-1);
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(this, &BackupListWidget::setScrollWidth, widget, &MyItemWidget::setScrollWidth);
// 滚动条是否展示
if (count * WIDTH_ITEM > this->height()) {
QScrollBar *vertScroll = verticalScrollBar();
if (vertScroll)
emit this->setScrollWidth(vertScroll->size().width());
}
connect(buttonDelete, &QPushButton::clicked, this, [=]() {
this->m_List.removeOne(label->getOriginalText());
QRect rect = this->visualItemRect(item);
widget->setBaseSize(rect.width(), rect.height());
widget->setText(text);
m_List << text;
connect(widget, &MyItemWidget::deleteItem, this, [=]() {
this->m_List.removeOne(widget->text());
this->removeItemWidget(item);
this->takeItem(this->row(item));
delete item;
@ -150,12 +179,17 @@ bool BackupListWidget::appendItem(const QString &text)
this->m_plusLogo->setVisible(true);
this->m_plusText->setVisible(true);
emit this->deleteEmpty();
} else {
if (this->count() * WIDTH_ITEM <= this->height())
emit this->setScrollWidth(0);
}
});
m_plusLogo->setVisible(false);
m_plusText->setVisible(false);
emit this->addedItem();
this->scrollToBottom();
return true;
}

View File

@ -5,6 +5,7 @@
#include <QStringList>
#include <QDropEvent>
#include <QLabel>
#include "mylabel.h"
class MyItemWidget : public QWidget
{
@ -13,8 +14,23 @@ public:
explicit MyItemWidget(QWidget* parent = nullptr);
virtual ~MyItemWidget();
void setSize(int width, int height);
void setText(const QString& text);
QString text() {
return m_text;
}
signals:
void selected(bool checked);
void deleteItem();
void setScrollWidth(int width);
private:
QString m_text;
MyLabel *m_label;
int m_scrollWidth = 0;
};
class BackupListWidget : public QListWidget
@ -49,6 +65,7 @@ protected:
signals:
void deleteEmpty();
void addedItem();
void setScrollWidth(int width);
private:
bool checkPathLimit(const QString &path);

View File

@ -37,7 +37,7 @@ MyIconButton::MyIconButton(QWidget *parent) :
m_textLabel->setSizePolicy(textLabelPolicy);
QHBoxLayout *hLayout = new QHBoxLayout(this);
hLayout->setContentsMargins(5, 0, 5, 0);
hLayout->setContentsMargins(10, 0, 5, 0);
hLayout->setSpacing(5);
hLayout->addWidget(m_iconButton);
hLayout->addWidget(m_textLabel);

View File

@ -16,6 +16,9 @@ public:
void setThemeIcon(const QString &themeIconName, const QString &defaultIconName = "", int size = 16);
void setDesplayText(const QString &text);
void flashText() {
setDesplayText(m_originalText);
}
QString pluginBtnHoverColor(bool hoverFlag);

View File

@ -15,9 +15,27 @@ LeftsiderbarWidget::LeftsiderbarWidget(QWidget *parent, StartMode mode)
: QWidget(parent)
{
m_parent = parent;
m_mode = mode;
m_personalQgsettings = nullptr;
if (QGSettings::isSchemaInstalled(PERSONALSIE_SCHEMA)) {
m_personalQgsettings = new QGSettings(PERSONALSIE_SCHEMA, QByteArray(), this);
m_transparency = m_personalQgsettings->get(PERSONALSIE_TRAN_KEY).toDouble();
connect(m_personalQgsettings,&QGSettings::changed,this,[=](QString changedKey) { //监听透明度变化
if (changedKey == CONTAIN_PERSONALSIE_TRAN_KEY) {
m_transparency = m_personalQgsettings->get(PERSONALSIE_TRAN_KEY).toDouble();
// this->setWindowOpacity(m_transparency);
this->repaint();
}
});
}
}
void LeftsiderbarWidget::initUi()
{
m_leftSideBarVLayout = new QVBoxLayout;
m_leftSideBarVLayout->setObjectName("m_leftSideBarVLayout");
m_leftSideBarVLayout->setContentsMargins(5,0,0,0);
m_leftSideBarVLayout->setContentsMargins(0,0,0,0);
m_leftSideBarVLayout->setSpacing(5);
setLayout(m_leftSideBarVLayout);
@ -31,7 +49,7 @@ LeftsiderbarWidget::LeftsiderbarWidget(QWidget *parent, StartMode mode)
m_titleLabel = new MyLabel;
m_titleLabel->setDeplayText(tr("Backup & Restore"));
m_titleLabel->setToolTip(tr("Backup & Restore"));
m_titleLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
m_titleLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
titleWidget->setLayout(titleLayout);
titleLayout->addWidget(m_mTitleIcon);
titleLayout->addWidget(m_titleLabel);
@ -39,9 +57,9 @@ LeftsiderbarWidget::LeftsiderbarWidget(QWidget *parent, StartMode mode)
// 功能列表
int funcNum = FuncTypeConverter::FunType::TOTALMODULES;
if (StartMode::livecd == mode) {
if (StartMode::livecd == m_mode) {
m_deplayFuncs << "BACKUP_SYSTEM" << "RESTORE_SYSTEM";
} else if (StartMode::std_user == mode) {
} else if (StartMode::std_user == m_mode) {
m_deplayFuncs << "BACKUP_DATA" << "RESTORE_DATA" << "OPERATION_LOG";
} else {
m_deplayFuncs << "BACKUP_SYSTEM" << "RESTORE_SYSTEM" << "BACKUP_DATA" << "RESTORE_DATA" << "OPERATION_LOG" << "GHOST_IMAGE";
@ -60,8 +78,10 @@ LeftsiderbarWidget::LeftsiderbarWidget(QWidget *parent, StartMode mode)
MyIconButton *funcButton = new MyIconButton(this);
QString btnName = mnameString;
funcButton->setObjectName(btnName);
funcButton->setFixedSize(180, 40);
funcButton->setFixedSize(this->width() - 20, 36);
funcButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
funcButton->setDesplayText(mnamei18nString);
funcButton->setFlat(true);
QString defaultIconName(":/symbos/");
defaultIconName += themeIconName;
defaultIconName += ".png";
@ -73,10 +93,11 @@ LeftsiderbarWidget::LeftsiderbarWidget(QWidget *parent, StartMode mode)
emit this->selected(type);
});
// 設置無邊框,跟隨背景色
funcButton->setFlat(true);
m_funcGroup->addButton(funcButton, type);
m_leftSideBarVLayout->addWidget(funcButton);
QHBoxLayout * hLayout = new QHBoxLayout;
hLayout->setContentsMargins(10, 0, 10, 0);
hLayout->addWidget(funcButton);
m_leftSideBarVLayout->addLayout(hLayout);
}
connect(GlobelBackupInfo::inst().getGlobalSignals(), &GlobalSignals::busy, this, [=](bool isBusy) {
@ -89,19 +110,6 @@ LeftsiderbarWidget::LeftsiderbarWidget(QWidget *parent, StartMode mode)
m_leftSideBarVLayout->addSpacing(8);
m_leftSideBarVLayout->addStretch();
m_personalQgsettings = nullptr;
if (QGSettings::isSchemaInstalled(PERSONALSIE_SCHEMA)) {
m_personalQgsettings = new QGSettings(PERSONALSIE_SCHEMA, QByteArray(), this);
m_transparency = m_personalQgsettings->get(PERSONALSIE_TRAN_KEY).toDouble();
connect(m_personalQgsettings,&QGSettings::changed,this,[=](QString changedKey) { //监听透明度变化
if (changedKey == CONTAIN_PERSONALSIE_TRAN_KEY) {
m_transparency = m_personalQgsettings->get(PERSONALSIE_TRAN_KEY).toDouble();
// this->setWindowOpacity(m_transparency);
this->repaint();
}
});
}
}
LeftsiderbarWidget::~LeftsiderbarWidget()

View File

@ -25,6 +25,8 @@ public:
LeftsiderbarWidget(QWidget *parent = nullptr, StartMode mode = StartMode::normal);
~LeftsiderbarWidget();
void initUi();
void paintEvent(QPaintEvent *event);
void setCheckedFunc(int func_type);
@ -35,6 +37,7 @@ private:
QGSettings *m_personalQgsettings;
qreal m_transparency = 0.8;
QWidget *m_parent;
StartMode m_mode;
QVBoxLayout *m_leftSideBarVLayout = nullptr;
PixmapLabel *m_mTitleIcon = nullptr;

View File

@ -75,6 +75,7 @@ void MainDialog::initUI()
m_leftSiderBarWidget = new LeftsiderbarWidget(ui->centralwidget, LeftsiderbarWidget::StartMode::std_user);
m_leftSiderBarWidget->setObjectName(QString::fromUtf8("m_leftSiderBarWidget"));
m_leftSiderBarWidget->setFixedSize(200, 640);
m_leftSiderBarWidget->initUi();
m_totalHLayout->addWidget(m_leftSiderBarWidget);

View File

@ -155,7 +155,7 @@ void DataBackup::initFirstWidget()
incrementBackup->setFixedWidth(180);
incrementBackup->setEnabled(true);
incrementBackup->setAutoRepeat(true);
incrementBackup->setProperty("isImportant", true);
// incrementBackup->setProperty("isImportant", true);
font.setPixelSize(24);
incrementBackup->setFont(font);
connect(incrementBackup, &MyPushButton::clicked, this, [=](bool checked) {

View File

@ -27,8 +27,8 @@ void OperationLog::initFirstWidget()
QWidget *first = new QWidget;
QVBoxLayout *vlayout = new QVBoxLayout;
vlayout->setContentsMargins(30, 10, 30, 20);
vlayout->addStretch();
vlayout->setContentsMargins(30, 10, 30, 30);
vlayout->setAlignment(Qt::AlignCenter);
// 列表为空时展示图片
QHBoxLayout *hlayoutLine1 = new QHBoxLayout;
@ -52,34 +52,31 @@ void OperationLog::initFirstWidget()
QStringList headerLabels;
headerLabels << tr("Backup Name") << tr("UUID") << tr("Operation") << tr("Operation Time");
m_tableWidget = new QTableWidget;
m_tableWidget->setFixedSize(680, 560);
m_tableWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
m_tableWidget->setMinimumSize(680, 550);
m_tableWidget->setColumnCount(headerLabels.size());
m_tableWidget->setHorizontalHeaderLabels(headerLabels);
m_tableWidget->horizontalHeader()->setDefaultAlignment(Qt::AlignCenter);
m_tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
// m_tableWidget->horizontalHeader()->resizeSection(Column_Index::Backup_Name, 200);
// m_tableWidget->horizontalHeader()->setSectionResizeMode(Column_Index::Backup_Name, QHeaderView::ResizeToContents);
// m_tableWidget->horizontalHeader()->resizeSection(Column_Index::UUID, 310);
// m_tableWidget->horizontalHeader()->resizeSection(Column_Index::Operation, 150);
// m_tableWidget->horizontalHeader()->resizeSection(Column_Index::Operation_Time, 150);
m_tableWidget->horizontalHeader()->setStretchLastSection(true);
m_tableWidget->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
// m_tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
m_tableWidget->horizontalHeader()->resizeSection(Column_Index::Backup_Name, 300);
m_tableWidget->horizontalHeader()->setSectionResizeMode(Column_Index::Backup_Name, QHeaderView::Stretch);
// m_tableWidget->horizontalHeader()->resizeSection(Column_Index::UUID, 310);
m_tableWidget->horizontalHeader()->resizeSection(Column_Index::Operation, 190);
m_tableWidget->horizontalHeader()->resizeSection(Column_Index::Operation_Time, 190);
m_tableWidget->horizontalHeader()->setTextElideMode(Qt::ElideRight);
m_tableWidget->horizontalHeader()->setFixedHeight(30);
m_tableWidget->horizontalHeader()->setFixedHeight(36);
m_tableWidget->verticalHeader()->setHidden(true); // 好像隐藏不掉
m_tableWidget->verticalHeader()->setVisible(false); //左侧标题不可见
m_tableWidget->verticalHeader()->setDefaultSectionSize(30); // 设置行高
m_tableWidget->verticalHeader()->setDefaultSectionSize(36); // 设置行高
m_tableWidget->setSelectionMode(QAbstractItemView::NoSelection);
m_tableWidget->setSortingEnabled(false); // 等录入完数据后再排序
m_tableWidget->setAlternatingRowColors(true);
m_tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
m_tableWidget->setShowGrid(false);
// m_tableWidget->hideColumn(1); // 隐藏uuid
hlayoutLine3->addStretch();
m_tableWidget->hideColumn(1); // 隐藏uuid
hlayoutLine3->addWidget(m_tableWidget);
hlayoutLine3->addStretch();
vlayout->addLayout(hlayoutLine3);
vlayout->addStretch();
first->setLayout(vlayout);
QList<BackupWrapper> list = Utils::getBackupLogList();

View File

@ -21,7 +21,7 @@ public:
private:
void initFirstWidget();
void initOperationLogs(const QList<BackupWrapper>& list);
void setItem(int row, int column, const QString& text, int alignFlag = Qt::AlignCenter/*Qt::AlignLeft | Qt::AlignVCenter*/);
void setItem(int row, int column, const QString& text, int alignFlag = Qt::AlignLeft | Qt::AlignVCenter);
QString castTypeToString(int type);
QTableWidget *m_tableWidget;