Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [ui] fix ui bug 108 #539

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/configs/settings/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ bool Settings::setValueNoNotify(const QString &group, const QString &key, const

changed = true;
} else {
changed = this->value(group, key, value) != value;
changed = this->value(group, key) != value;
}

d->writableData.setValue(group, key, value);
Expand Down
7 changes: 7 additions & 0 deletions src/plugins/cooperation/core/gui/dialogs/transferdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include <QMovie>

#include <maincontroller/maincontroller.h>

using namespace cooperation_core;
#ifdef linux
static constexpr char Ktransfer_success[] = "transfer_success";
Expand Down Expand Up @@ -134,6 +136,11 @@ void TransferDialog::createProgressPage()
vLayout->addWidget(progressMsgLael);
}

bool TransferDialog::isInProgress() const
{
return stackedLayout->currentIndex() == 2;
}

void TransferDialog::switchWaitConfirmPage()
{
stackedLayout->setCurrentIndex(0);
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/cooperation/core/gui/dialogs/transferdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class TransferDialog : public CooperationDialog
void switchResultPage(bool success, const QString &msg);
void switchProgressPage(const QString &title);

bool isInProgress() const;

public Q_SLOTS:
void updateProgress(int value, const QString &remainTime);

Expand Down
72 changes: 53 additions & 19 deletions src/plugins/cooperation/core/gui/widgets/cooperationstatewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void NoNetworkWidget::initUI()
QVBoxLayout *vLayout = new QVBoxLayout;
vLayout->setContentsMargins(0, 0, 0, 0);
vLayout->setSpacing(0);
vLayout->addSpacing(116);
vLayout->addStretch();
vLayout->addWidget(iconLabel, 0, Qt::AlignCenter);
vLayout->addSpacing(14);
vLayout->addWidget(tipsLabel, 0, Qt::AlignCenter);
Expand Down Expand Up @@ -242,12 +242,34 @@ void NoResultTipWidget::initUI()
#endif
}

void NoResultTipWidget::paintEvent(QPaintEvent *event)
{
if (useTipMode) {
QWidget::paintEvent(event);
return;
}
QPainter painter(this);
QColor color;

if (CooperationGuiHelper::isDarkTheme())
color.setRgb(255, 255, 255, static_cast<int>(255 * 0.05));
else
color.setRgb(0, 0, 0, static_cast<int>(255 * 0.05));
painter.fillRect(rect(), color);
QWidget::paintEvent(event);
}

NoResultWidget::NoResultWidget(QWidget *parent)
: QWidget(parent)
{
initUI();
}

void NoResultWidget::mousePressEvent(QMouseEvent *event)
{
Q_UNUSED(event);
}

void NoResultWidget::initUI()
{
setFocusPolicy(Qt::ClickFocus);
Expand All @@ -265,42 +287,42 @@ void NoResultWidget::initUI()
font.setWeight(QFont::Medium);
tipsLabel->setFont(font);

BackgroundWidget *contentBackgroundWidget = new BackgroundWidget(this);
contentBackgroundWidget->setBackground(17, BackgroundWidget::ItemBackground,
BackgroundWidget::TopAndBottom);
BackgroundWidget *backgroundWidget = new BackgroundWidget(this);
QScrollArea *scrollArea = new QScrollArea();
backgroundWidget->setBackground(17, BackgroundWidget::ItemBackground,
BackgroundWidget::TopAndBottom);

QVBoxLayout *contentLayout = new QVBoxLayout;
NoResultTipWidget *noResultTipWidget = new NoResultTipWidget();
noResultTipWidget->setTitleVisible(false);
contentLayout->addWidget(noResultTipWidget);
contentBackgroundWidget->setLayout(contentLayout);
backgroundWidget->setLayout(contentLayout);

QVBoxLayout *vLayout = new QVBoxLayout;
vLayout->setContentsMargins(0, 0, 0, 0);

QSpacerItem *sp_1 = new QSpacerItem(20, 88, QSizePolicy::Minimum, QSizePolicy::Expanding);
QSpacerItem *sp_2 = new QSpacerItem(20, 14, QSizePolicy::Minimum, QSizePolicy::Expanding);
QSpacerItem *sp_3 = new QSpacerItem(20, 22, QSizePolicy::Minimum, QSizePolicy::Expanding);
QSpacerItem *sp_1 = new QSpacerItem(20, 70, QSizePolicy::Minimum, QSizePolicy::Expanding);

vLayout->addItem(sp_1);
vLayout->addWidget(iconLabel, 0, Qt::AlignCenter);
vLayout->addItem(sp_2);
vLayout->addSpacing(10);
vLayout->addWidget(tipsLabel, 0, Qt::AlignCenter);
vLayout->addItem(sp_3);
QScrollArea *scrollArea = new QScrollArea();
vLayout->addSpacing(10);

scrollArea->setWidgetResizable(true);
scrollArea->setWidget(contentBackgroundWidget);
contentLayout->addWidget(scrollArea);
contentLayout->setSpacing(0);
scrollArea->setWidget(noResultTipWidget);

#ifndef __linux__
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
#endif
scrollArea->setWidget(contentBackgroundWidget);
scrollArea->show();
scrollArea->setFrameStyle(QFrame::NoFrame);
vLayout->addWidget(scrollArea);
vLayout->addWidget(backgroundWidget);

vLayout->addSpacerItem(new QSpacerItem(10, 10, QSizePolicy::Minimum, QSizePolicy::Expanding));
setLayout(vLayout);
backgroundWidget->setMaximumHeight(129);
}

BottomLabel::BottomLabel(QWidget *parent)
Expand Down Expand Up @@ -340,8 +362,7 @@ void BottomLabel::initUI()
{
QString ip = QString(tr("Local IP: %1").arg(CooperationUtil::localIPAddress()));
ipLabel = new QLabel(ip);
ipLabel->setAlignment(Qt::AlignHCenter);
ipLabel->setFixedHeight(30);
ipLabel->setAlignment(Qt::AlignCenter);
connect(MainController::instance(), &MainController::onlineStateChanged, this, [this](bool isOnline) {
if (!isOnline)
return;
Expand All @@ -354,6 +375,7 @@ void BottomLabel::initUI()
QScrollArea *scrollArea = new QScrollArea(dialog);
tipLabel = new QLabel(qobject_cast<QWidget *>(this->parent()));
tipLabel->installEventFilter(this);
ipLabel->setFixedSize(500, 33);

#ifdef linux
updateSizeMode();
Expand All @@ -373,7 +395,7 @@ void BottomLabel::initUI()
scrollArea->setStyleSheet("QScrollArea { border: none; background-color: transparent; }");
#endif

dialog->setFixedSize(260, 208);
dialog->setFixedSize(260, 210);
scrollArea->setWidgetResizable(true);
QWidget *contentWidget = new QWidget;

Expand All @@ -383,10 +405,21 @@ void BottomLabel::initUI()
NoResultTipWidget *tipWidgt = new NoResultTipWidget(scrollArea, true);
layout->addWidget(tipWidgt);
scrollArea->setWidget(contentWidget);
scrollArea->setFrameStyle(QFrame::NoFrame);

QWidget *topSpace = new QWidget();
topSpace->setFixedHeight(5);
topSpace->setAutoFillBackground(true);
QWidget *bottomSpace = new QWidget();
bottomSpace->setFixedHeight(5);
bottomSpace->setAutoFillBackground(true);

QVBoxLayout *contentLayout = new QVBoxLayout;
contentLayout->setContentsMargins(0, 0, 0, 0);
contentLayout->setSpacing(0);
contentLayout->addWidget(topSpace);
contentLayout->addWidget(scrollArea);
contentLayout->addWidget(bottomSpace);
contentLayout->setAlignment(Qt::AlignCenter);

dialog->setLayout(contentLayout);
Expand All @@ -397,7 +430,8 @@ void BottomLabel::initUI()

QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(ipLabel);
mainLayout->setAlignment(Qt::AlignHCenter);
mainLayout->setAlignment(Qt::AlignCenter);
mainLayout->setContentsMargins(0, 0, 0, 0);
setLayout(mainLayout);

timer = new QTimer(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class NoResultTipWidget : public QWidget
void onLinkActivated(const QString &link);
void setTitleVisible(bool visible);

protected:
void paintEvent(QPaintEvent *event) override;
private:
void initUI();
CooperationLabel *titleLabel { nullptr };
Expand All @@ -63,6 +65,8 @@ class NoResultWidget : public QWidget
Q_OBJECT
public:
explicit NoResultWidget(QWidget *parent = nullptr);
void mousePressEvent(QMouseEvent *event) override;


private:
void initUI();
Expand Down
29 changes: 21 additions & 8 deletions src/plugins/cooperation/core/gui/widgets/firsttipwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ FirstTipWidget::FirstTipWidget(QWidget *parent)
void FirstTipWidget::themeTypeChanged()
{
if (CooperationGuiHelper::instance()->isDarkTheme()) {
shadowEffect->setColor(QColor(122, 192, 255, 128));
shadowEffect->setColor(QColor(10, 57, 99, 128));
bannerLabel->setPixmap(QIcon::fromTheme(":/icons/deepin/builtin/dark/icons/banner_128px.png").pixmap(234, 158));

} else {
shadowEffect->setColor(QColor(10, 57, 99, 128));
shadowEffect->setColor(QColor(122, 192, 255, 128));
bannerLabel->setPixmap(QIcon::fromTheme(":/icons/deepin/builtin/light/icons/banner_128px.png").pixmap(234, 158));
}
if (!qApp->property("onlyTransfer").toBool())
Expand All @@ -46,7 +45,7 @@ void FirstTipWidget::showEvent(QShowEvent *event)
{
auto ge = lineBalls.last()->geometry();

line->setGeometry(32, 26, qApp->devicePixelRatio(), ge.y() - 26);
line->setGeometry(32, 32, qApp->devicePixelRatio(), ge.y() - 32);
QWidget::showEvent(event);
}

Expand Down Expand Up @@ -81,7 +80,7 @@ void FirstTipWidget::initbackgroundFrame()
QString backdarkStyle = ".QFrame { background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(132, 141, 179, 0.24), stop:1 rgba(224, 225, 255, 0.12)); "
"border-radius: 10px;"
"color: rgba(0, 0, 0, 0.6);"
"border: 1px solid rgba(0, 0, 0, 0.05); } ";
"border: 1px solid rgba(255, 255, 255, 0.05); } ";
CooperationGuiHelper::initThemeTypeConnect(backgroundFrame, backlightStyle, backdarkStyle);
backgroundFrame->setFixedWidth(480);

Expand Down Expand Up @@ -116,12 +115,14 @@ void FirstTipWidget::initbackgroundFrame()

QLabel *lineball = new QLabel(this);
lineBalls.append(lineball);
lineball->setFixedSize(12, 12);
lineball->setFixedSize(12, 14);
QString balllightStyle = "background-color: rgb(33, 138, 244); "
"border-radius: 6px;"
"margin-top: 2px;"
"border: 1px solid white;";
QString balldarkStyle = "background-color: rgb(0, 89, 210); "
"border-radius: 6px;"
"margin-top: 2px;" //用style画圆形背景会出现顶部被切割,规避一下
"border: 1px solid white; ";
CooperationGuiHelper::initThemeTypeConnect(lineball, balllightStyle, balldarkStyle);
lineball->setGraphicsEffect(shadowEffect);
Expand Down Expand Up @@ -204,8 +205,13 @@ void FirstTipWidget::inittipBtn()
flag.close();
setVisible(false);
});
tipBtn->setStyleSheet("QToolButton { background-color: rgba(0, 0, 0, 0.1); border-radius: 9px; }"
"QToolButton::hover { background-color: rgba(0, 0, 0, 0.2); border-radius: 9px; }");

tipBtn->setFixedSize(18, 20);
QString lightStyle = "QToolButton { background-color: rgba(0, 0, 0, 0.1); margin-top: 2px; border-radius: 9px; }"
"QToolButton::hover { background-color: rgba(0, 0, 0, 0.15); margin-top: 2px; border-radius: 9px; }";
QString darkStyle = "QToolButton { background-color: rgba(255, 255, 255, 0.1); margin-top: 2px; border-radius: 9px; }"
"QToolButton::hover { background-color: rgba(255, 255, 255, 0.2); margin-top: 2px; border-radius: 9px; }";
CooperationGuiHelper::initThemeTypeConnect(tipBtn, lightStyle, darkStyle);
}

void FirstTipWidget::setVisible(bool visible)
Expand Down Expand Up @@ -244,7 +250,14 @@ void LineWidget::paintEvent(QPaintEvent *event)
int x = width() / 2;
int y = 0;
int dashLength = 4; // 每段虚线的长度
int mid = 0;
while (y < height()) {
//中间一段不画,不然就画到圆圈上了
if (mid < 1 && y > height() / 2 - 8) {
mid++;
y += 4 * dashLength;
continue;
}
painter.drawLine(x, y, x, qMin(y + dashLength, height()));
y += 2 * dashLength; // 虚线间距
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ void WorkspaceWidgetPrivate::initUI()
stackedLayout->addWidget(nnWidget);
stackedLayout->addWidget(nrWidget);
stackedLayout->addWidget(dlWidget);
stackedLayout->setAlignment(Qt::AlignCenter);
stackedLayout->setCurrentIndex(0);

QVBoxLayout *mainLayout = new QVBoxLayout;
Expand Down
7 changes: 7 additions & 0 deletions src/plugins/cooperation/core/transfer/transferhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

# include <QDBusInterface>
# include <QDBusReply>

# include <maincontroller/maincontroller.h>
#endif

using ButtonStateCallback = std::function<bool(const QString &, const DeviceInfoPointer)>;
Expand Down Expand Up @@ -226,6 +228,11 @@ TransferHelper::TransferHelper(QObject *parent)
: QObject(parent),
d(new TransferHelperPrivate(this))
{
connect(MainController::instance(), &MainController::onlineStateChanged, this, [this](bool isOnline) {
if (isOnline || !d->transDialog()->isVisible() || !d->transDialog()->isInProgress())
return;
d->transferResult(false, tr("Network not connected, file delivery failed this time. Please connect to the network and try again!"));
});
}

TransferHelper::~TransferHelper()
Expand Down
1 change: 1 addition & 0 deletions src/plugins/cooperation/core/transfer/transferhelper_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public Q_SLOTS:
QTimer confirmTimer;
bool isTransTimeout = false;
QString recvFilesSavePath;
int jobId = 0;
};

} // namespace cooperation_core
Expand Down
Loading