Improve KMessageWidget visuals

This commit is contained in:
Janek Bevendorff 2018-01-19 20:05:37 +01:00
parent f520a0f272
commit 30f77b07bb
No known key found for this signature in database
GPG key ID: 2FDEB0D40BCA5E11
4 changed files with 45 additions and 50 deletions

View file

@ -34,7 +34,6 @@ BrowserOptionDialog::BrowserOptionDialog(QWidget* parent) :
connect(m_ui->removeStoredPermissions, SIGNAL(clicked()), this, SIGNAL(removeStoredPermissions())); connect(m_ui->removeStoredPermissions, SIGNAL(clicked()), this, SIGNAL(removeStoredPermissions()));
m_ui->warningWidget->showMessage(tr("The following options can be dangerous!\nChange them only if you know what you are doing."), MessageWidget::Warning); m_ui->warningWidget->showMessage(tr("The following options can be dangerous!\nChange them only if you know what you are doing."), MessageWidget::Warning);
m_ui->warningWidget->setIcon(FilePath::instance()->icon("status", "dialog-warning"));
m_ui->warningWidget->setCloseButtonVisible(false); m_ui->warningWidget->setCloseButtonVisible(false);
m_ui->warningWidget->setAutoHideTimeout(-1); m_ui->warningWidget->setAutoHideTimeout(-1);

View file

@ -33,6 +33,7 @@
#include <QTimeLine> #include <QTimeLine>
#include <QToolButton> #include <QToolButton>
#include <QStyle> #include <QStyle>
#include <QtGui/QBitmap>
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// KMessageWidgetPrivate // KMessageWidgetPrivate
@ -49,6 +50,7 @@ public:
QToolButton *closeButton; QToolButton *closeButton;
QTimeLine *timeLine; QTimeLine *timeLine;
QIcon icon; QIcon icon;
QPixmap closeButtonPixmap;
KMessageWidget::MessageType messageType; KMessageWidget::MessageType messageType;
bool wordWrap; bool wordWrap;
@ -99,6 +101,7 @@ void KMessageWidgetPrivate::init(KMessageWidget *q_ptr)
closeButton = new QToolButton(content); closeButton = new QToolButton(content);
closeButton->setAutoRaise(true); closeButton->setAutoRaise(true);
closeButton->setDefaultAction(closeAction); closeButton->setDefaultAction(closeAction);
closeButtonPixmap = QPixmap(closeButton->icon().pixmap(closeButton->icon().actualSize(QSize(16, 16))));
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
closeButton->setStyleSheet("QToolButton { background: transparent;" closeButton->setStyleSheet("QToolButton { background: transparent;"
"border-radius: 2px; padding: 3px; }" "border-radius: 2px; padding: 3px; }"
@ -256,49 +259,42 @@ KMessageWidget::MessageType KMessageWidget::messageType() const
return d->messageType; return d->messageType;
} }
static QColor darkShade(QColor c)
{
qreal contrast = 0.7; // taken from kcolorscheme for the dark shade
qreal darkAmount;
if (c.lightnessF() < 0.006) { /* too dark */
darkAmount = 0.02 + 0.40 * contrast;
} else if (c.lightnessF() > 0.93) { /* too bright */
darkAmount = -0.06 - 0.60 * contrast;
} else {
darkAmount = (-c.lightnessF()) * (0.55 + contrast * 0.35);
}
qreal v = c.lightnessF() + darkAmount;
v = v > 0.0 ? (v < 1.0 ? v : 1.0) : 0.0;
c.setHsvF(c.hslHueF(), c.hslSaturationF(), v);
return c;
}
void KMessageWidget::setMessageType(KMessageWidget::MessageType type) void KMessageWidget::setMessageType(KMessageWidget::MessageType type)
{ {
d->messageType = type; d->messageType = type;
QColor bg0, bg1, bg2, border, fg; QColor bg0, bg1, bg2, border;
QColor fg = palette().light().color();
switch (type) { switch (type) {
case Positive: case Positive:
bg1.setRgb(0, 110, 40); // values taken from kcolorscheme.cpp (Positive) bg1.setRgb(37, 163, 83);
break; break;
case Information: case Information:
bg1 = palette().highlight().color(); bg1.setRgb(24, 187, 242);
break; break;
case Warning: case Warning:
bg1.setRgb(191, 126, 7); // values taken from kcolorscheme.cpp (Neutral) bg1.setRgb(252, 193, 57);
fg = palette().foreground().color();
break; break;
case Error: case Error:
bg1.setRgb(191, 3, 3); // values taken from kcolorscheme.cpp (Negative) bg1.setRgb(198, 69, 21);
break; break;
} }
// Colors // Colors
fg = palette().light().color(); bg0 = bg1.lighter(105);
bg0 = bg1.lighter(110); bg2 = bg1.darker(105);
bg2 = bg1.darker(110); border = bg1.darker(115);
border = darkShade(bg1);
// Tint close icon
auto closeButtonPixmap = d->closeButtonPixmap;
QPixmap mask(closeButtonPixmap);
QPainter painter;
painter.begin(&closeButtonPixmap);
painter.setRenderHints(QPainter::HighQualityAntialiasing);
painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
painter.fillRect(QRect(0, 0, 16, 16), fg);
painter.end();
d->closeButton->setIcon(closeButtonPixmap);
d->content->setStyleSheet( d->content->setStyleSheet(
QString(QLatin1String(".QFrame {" QString(QLatin1String(".QFrame {"
@ -306,7 +302,7 @@ void KMessageWidget::setMessageType(KMessageWidget::MessageType type)
" stop: 0 %1," " stop: 0 %1,"
" stop: 0.1 %2," " stop: 0.1 %2,"
" stop: 1.0 %3);" " stop: 1.0 %3);"
"border-radius: 5px;" " border-radius: 2px;"
" border: 1px solid %4;" " border: 1px solid %4;"
" margin: %5px;" " margin: %5px;"
" padding: 5px;" " padding: 5px;"
@ -317,8 +313,9 @@ void KMessageWidget::setMessageType(KMessageWidget::MessageType type)
.arg(bg1.name()) .arg(bg1.name())
.arg(bg2.name()) .arg(bg2.name())
.arg(border.name()) .arg(border.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 // DefaultFrameWidth returns the size of the external margin + border width. We know our border is 1px,
.arg(style()->pixelMetric(QStyle::PM_DefaultFrameWidth, 0, this) - 1) // so we subtract this from the frame normal QStyle FrameWidth to get our margin
.arg(style()->pixelMetric(QStyle::PM_DefaultFrameWidth, nullptr, this) - 1)
.arg(fg.name()) .arg(fg.name())
); );
} }

View file

@ -425,14 +425,14 @@ MainWindow::~MainWindow()
void MainWindow::showKeePassHTTPDeprecationNotice() void MainWindow::showKeePassHTTPDeprecationNotice()
{ {
displayGlobalMessage(tr("<p>It looks like you are using KeePassHTTP for browser integration.<br>" displayGlobalMessage(tr("<p>It looks like you are using KeePassHTTP for browser integration. "
"This feature has been deprecated and will be removed in the future.<br>" "This feature has been deprecated and will be removed in the future.<br>"
"Please switch to keepassxc-browser instead! For help with migration,<br>" "Please switch to keepassxc-browser instead! For help with migration, "
"visit our <a href=\"https://keepassxc.org/docs/keepassxc-browser-migration\">" "visit our <a class=\"link\" href=\"https://keepassxc.org/docs/keepassxc-browser-migration\">"
"keepassxc-browser migration guide</a>.</p>"), "keepassxc-browser migration guide</a>.</p>"),
MessageWidget::Warning, true, -1); MessageWidget::Warning, true, -1);
config()->set("Http/DeprecationNoticeShown", true); // config()->set("Http/DeprecationNoticeShown", true);
disconnect(m_ui->tabWidget, SIGNAL(messageDismissGlobal()), this, SLOT(showKeePassHTTPDeprecationNotice())); disconnect(m_ui->tabWidget, SIGNAL(messageDismissGlobal()), this, SLOT(showKeePassHTTPDeprecationNotice()));
} }

View file

@ -33,7 +33,6 @@ OptionDialog::OptionDialog(QWidget *parent) :
connect(m_ui->removeStoredPermissions, SIGNAL(clicked()), this, SIGNAL(removeStoredPermissions())); connect(m_ui->removeStoredPermissions, SIGNAL(clicked()), this, SIGNAL(removeStoredPermissions()));
m_ui->warningWidget->showMessage(tr("The following options can be dangerous!\nChange them only if you know what you are doing."), MessageWidget::Warning); m_ui->warningWidget->showMessage(tr("The following options can be dangerous!\nChange them only if you know what you are doing."), MessageWidget::Warning);
m_ui->warningWidget->setIcon(FilePath::instance()->icon("status", "dialog-warning"));
m_ui->warningWidget->setCloseButtonVisible(false); m_ui->warningWidget->setCloseButtonVisible(false);
m_ui->warningWidget->setAutoHideTimeout(MessageWidget::DisableAutoHide); m_ui->warningWidget->setAutoHideTimeout(MessageWidget::DisableAutoHide);