Skip to content

Commit

Permalink
Merge #95 nmc/2003-E2E_Settings_Dialog - Master
Browse files Browse the repository at this point in the history
  • Loading branch information
eugenMCloud committed Feb 5, 2024
2 parents 03340ff + dbb1e91 commit eadab06
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 21 deletions.
96 changes: 77 additions & 19 deletions src/3rdparty/kmessagewidget/kmessagewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class KMessageWidgetPrivate
QFrame *content = nullptr;
QLabel *iconLabel = nullptr;
QLabel *textLabel = nullptr;
QLabel *titleLabel = nullptr;
QLabel *titelIcon = nullptr;
QToolButton *closeButton = nullptr;
QTimeLine *timeLine = nullptr;
QIcon icon;
Expand All @@ -62,6 +64,9 @@ class KMessageWidgetPrivate
void slotTimeLineFinished();

[[nodiscard]] int bestContentHeight() const;

private:
void applyNMCStylesheets() const;
};

void KMessageWidgetPrivate::init(KMessageWidget *q_ptr)
Expand All @@ -86,11 +91,21 @@ void KMessageWidgetPrivate::init(KMessageWidget *q_ptr)
iconLabel->hide();

textLabel = new QLabel(content);
textLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
textLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
textLabel->setFixedWidth(500);
textLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
QObject::connect(textLabel, &QLabel::linkActivated, q, &KMessageWidget::linkActivated);
QObject::connect(textLabel, &QLabel::linkHovered, q, &KMessageWidget::linkHovered);

titleLabel = new QLabel(content);
titleLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
titleLabel->setText(KMessageWidget::tr("E2E_ENCRYPTION"));
titleLabel->setStyleSheet("font-size: 13px; font-weight: 600;");

titelIcon = new QLabel(content);
titelIcon->setFixedSize(24,24);
titelIcon->setPixmap(QIcon(QLatin1String(":/client/theme/NMCIcons/cloud-security.svg")).pixmap(24,24));

auto *closeAction = new QAction(q);
closeAction->setText(KMessageWidget::tr("&Close"));
closeAction->setToolTip(KMessageWidget::tr("Close message"));
Expand All @@ -99,8 +114,8 @@ void KMessageWidgetPrivate::init(KMessageWidget *q_ptr)
QObject::connect(closeAction, &QAction::triggered, q, &KMessageWidget::animatedHide);

closeButton = new QToolButton(content);
closeButton->setAutoRaise(true);
closeButton->setDefaultAction(closeAction);
//closeButton->setAutoRaise(true);
//closeButton->setDefaultAction(closeAction);

q->setMessageType(KMessageWidget::Information);
}
Expand All @@ -117,37 +132,53 @@ void KMessageWidgetPrivate::createLayout()
Q_FOREACH (QAction *action, q->actions()) {
auto *button = new QToolButton(content);
button->setDefaultAction(action);
button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
button->setToolButtonStyle(Qt::ToolButtonTextOnly);
buttons.append(button);
}

// AutoRaise reduces visual clutter, but we don't want to turn it on if
// there are other buttons, otherwise the close button will look different
// from the others.
closeButton->setAutoRaise(buttons.isEmpty());
//closeButton->setAutoRaise(buttons.isEmpty());

if (wordWrap) {
//NMC customization, make sure, we always enter the first case
if (true) {
auto *layout = new QGridLayout(content);

layout->setContentsMargins(8,8,0,8);
content->setFixedHeight(84);

auto *titleLayout = new QHBoxLayout(content);
titleLayout->setSpacing(8);
titleLayout->setContentsMargins(0,0,0,0);
titleLayout->addWidget(titleLabel);
titleLayout->addWidget(titelIcon);

layout->addLayout(titleLayout, 0, 0, 1, 1, Qt::AlignLeft | Qt::AlignCenter);

// Set alignment to make sure icon does not move down if text wraps
layout->addWidget(iconLabel, 0, 0, 1, 1, Qt::AlignHCenter | Qt::AlignTop);
layout->addWidget(textLabel, 0, 1);
//layout->addWidget(iconLabel, 0, 0, 1, 1, Qt::AlignHCenter | Qt::AlignTop);
layout->addWidget(textLabel, 1, 0);

if (buttons.isEmpty()) {
// Use top-vertical alignment like the icon does.
layout->addWidget(closeButton, 0, 2, 1, 1, Qt::AlignHCenter | Qt::AlignTop);
//layout->addWidget(closeButton, 0, 2, 1, 1, Qt::AlignHCenter | Qt::AlignTop);
} else {
// Use an additional layout in row 1 for the buttons.
auto *buttonLayout = new QHBoxLayout;
buttonLayout->addStretch();
auto *buttonLayout = new QVBoxLayout;
buttonLayout->setContentsMargins(0,0,0,0);
buttonLayout->setSpacing(4);
//buttonLayout->addStretch();
Q_FOREACH (QToolButton *button, buttons) {
// For some reason, calling show() is necessary if wordwrap is true,
// otherwise the buttons do not show up. It is not needed if
// wordwrap is false.
button->show();
buttonLayout->addWidget(button);
}
buttonLayout->addWidget(closeButton);
layout->addItem(buttonLayout, 1, 0, 1, 2);
//buttonLayout->addWidget(closeButton);
layout->addItem(buttonLayout, 0, 1, 2, 1, Qt::AlignCenter);
applyNMCStylesheets();
}
} else {
auto *layout = new QHBoxLayout(content);
Expand All @@ -158,7 +189,7 @@ void KMessageWidgetPrivate::createLayout()
layout->addWidget(button);
}

layout->addWidget(closeButton);
//layout->addWidget(closeButton);
};

if (q->isVisible()) {
Expand All @@ -176,10 +207,10 @@ void KMessageWidgetPrivate::applyStyleSheet()
// The following RGB color values come from the "default" scheme in kcolorscheme.cpp
switch (messageType) {
case KMessageWidget::Positive:
bgBaseColor.setRgb(39, 174, 96); // Window: ForegroundPositive
bgBaseColor.setRgb(204, 250, 225); // Window: ForegroundPositive
break;
case KMessageWidget::Information:
bgBaseColor.setRgb(61, 174, 233); // Window: ForegroundActive
bgBaseColor.setRgb(211, 215, 249); // Window: ForegroundActive
break;
case KMessageWidget::Warning:
bgBaseColor.setRgb(246, 116, 0); // Window: ForegroundNeutral
Expand All @@ -188,7 +219,7 @@ void KMessageWidgetPrivate::applyStyleSheet()
bgBaseColor.setRgb(218, 68, 83); // Window: ForegroundNegative
break;
}
const qreal bgBaseColorAlpha = 0.2;
const qreal bgBaseColorAlpha = 1.0;
bgBaseColor.setAlphaF(bgBaseColorAlpha);

const QPalette palette = QGuiApplication::palette();
Expand All @@ -213,11 +244,13 @@ void KMessageWidgetPrivate::applyStyleSheet()
".QLabel { color: %4; }"
)
.arg(bgFinalColor.name())
.arg(border.name())
.arg(bgFinalColor.name())
// DefaultFrameWidth returns the size of the external margin + border width. We know our border is 1px, so we subtract this from the frame normal QStyle FrameWidth to get our margin
.arg(q->style()->pixelMetric(QStyle::PM_DefaultFrameWidth, nullptr, q) - 1)
.arg(textColor.name())
);

applyNMCStylesheets();
}

void KMessageWidgetPrivate::updateLayout()
Expand Down Expand Up @@ -271,6 +304,30 @@ int KMessageWidgetPrivate::bestContentHeight() const
return height;
}

void KMessageWidgetPrivate::applyNMCStylesheets() const
{
//Set button color and size
if(!buttons.empty()){
QString stylesheet = QString("QToolButton{width: 180px; height: 32px; border-radius: 4px; font-size: %1px; color: %2; background-color: %3;} QToolButton:hover { background-color: %4;}");
switch (messageType) {
case KMessageWidget::Positive:
Q_FOREACH (QToolButton *button, buttons) {
button->setStyleSheet(stylesheet.arg("13", "white", "#00b367", "#00a461"));
}
break;
case KMessageWidget::Information:
Q_FOREACH (QToolButton *button, buttons) {
button->setStyleSheet(stylesheet.arg("13", "white", "#216bff", "#0819bd"));
}
break;
case KMessageWidget::Warning:
break;
case KMessageWidget::Error:
break;
}
}
}

//---------------------------------------------------------------------
// KMessageWidget
//---------------------------------------------------------------------
Expand Down Expand Up @@ -396,7 +453,8 @@ bool KMessageWidget::isCloseButtonVisible() const

void KMessageWidget::setCloseButtonVisible(bool show)
{
d->closeButton->setVisible(show);
Q_UNUSED(show)
d->closeButton->setVisible(false);
updateGeometry();
}

Expand Down
4 changes: 2 additions & 2 deletions src/gui/accountsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ void AccountSettings::slotE2eEncryptionMnemonicReady()

_ui->encryptionMessage->setMessageType(KMessageWidget::Positive);
_ui->encryptionMessage->setText(tr("End-to-end encryption has been enabled for this account"));
_ui->encryptionMessage->setIcon(Theme::createColorAwareIcon(QStringLiteral(":/client/theme/lock.svg")));
//_ui->encryptionMessage->setIcon(Theme::createColorAwareIcon(QStringLiteral(":/client/theme/lock.svg")));
_ui->encryptionMessage->show();
}

Expand Down Expand Up @@ -1683,7 +1683,7 @@ void AccountSettings::initializeE2eEncryptionSettingsMessage()
{
_ui->encryptionMessage->setMessageType(KMessageWidget::Information);
_ui->encryptionMessage->setText(tr("This account supports end-to-end encryption"));
_ui->encryptionMessage->setIcon(Theme::createColorAwareIcon(QStringLiteral(":/client/theme/black/state-info.svg")));
//_ui->encryptionMessage->setIcon(Theme::createColorAwareIcon(QStringLiteral(":/client/theme/black/state-info.svg")));
_ui->encryptionMessage->hide();

auto *const actionEnableE2e = addActionToEncryptionMessage(tr("Set up encryption"), e2EeUiActionEnableEncryptionId);
Expand Down

0 comments on commit eadab06

Please sign in to comment.