Fallback for the OSD on systems without transparant top level widgets
This commit is contained in:
parent
b492a63dfa
commit
3a726f71cd
@ -24,9 +24,14 @@
|
|||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QBitmap>
|
||||||
|
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
|
|
||||||
|
#ifdef Q_WS_X11
|
||||||
|
# include <QX11Info>
|
||||||
|
#endif
|
||||||
|
|
||||||
const char* OSDPretty::kSettingsGroup = "OSDPretty";
|
const char* OSDPretty::kSettingsGroup = "OSDPretty";
|
||||||
|
|
||||||
const int OSDPretty::kDropShadowSize = 13;
|
const int OSDPretty::kDropShadowSize = 13;
|
||||||
@ -36,6 +41,7 @@ const int OSDPretty::kMaxIconSize = 100;
|
|||||||
const QRgb OSDPretty::kPresetBlue = qRgb(102, 150, 227);
|
const QRgb OSDPretty::kPresetBlue = qRgb(102, 150, 227);
|
||||||
const QRgb OSDPretty::kPresetOrange = qRgb(254, 156, 67);
|
const QRgb OSDPretty::kPresetOrange = qRgb(254, 156, 67);
|
||||||
|
|
||||||
|
|
||||||
OSDPretty::OSDPretty(QWidget *parent)
|
OSDPretty::OSDPretty(QWidget *parent)
|
||||||
: QWidget(parent),
|
: QWidget(parent),
|
||||||
mode_(Mode_Popup),
|
mode_(Mode_Popup),
|
||||||
@ -74,6 +80,13 @@ OSDPretty::OSDPretty(QWidget *parent)
|
|||||||
Load();
|
Load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool OSDPretty::IsTransparencyAvailable() {
|
||||||
|
#ifdef Q_WS_X11
|
||||||
|
return QX11Info::isCompositingManagerRunning();
|
||||||
|
#endif
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void OSDPretty::Load() {
|
void OSDPretty::Load() {
|
||||||
QSettings s;
|
QSettings s;
|
||||||
s.beginGroup(kSettingsGroup);
|
s.beginGroup(kSettingsGroup);
|
||||||
@ -107,12 +120,17 @@ void OSDPretty::SetMode(Mode mode) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QRect OSDPretty::BoxBorder() const {
|
||||||
|
return rect().adjusted(kDropShadowSize, kDropShadowSize,
|
||||||
|
-kDropShadowSize, -kDropShadowSize);
|
||||||
|
}
|
||||||
|
|
||||||
void OSDPretty::paintEvent(QPaintEvent *) {
|
void OSDPretty::paintEvent(QPaintEvent *) {
|
||||||
QPainter p(this);
|
QPainter p(this);
|
||||||
p.setRenderHint(QPainter::Antialiasing);
|
p.setRenderHint(QPainter::Antialiasing);
|
||||||
p.setRenderHint(QPainter::HighQualityAntialiasing);
|
p.setRenderHint(QPainter::HighQualityAntialiasing);
|
||||||
|
|
||||||
QRect box(rect().adjusted(kDropShadowSize, kDropShadowSize, -kDropShadowSize, -kDropShadowSize));
|
QRect box(BoxBorder());
|
||||||
|
|
||||||
// Shadow corners
|
// Shadow corners
|
||||||
const int kShadowCornerSize = kDropShadowSize + kBorderRadius;
|
const int kShadowCornerSize = kDropShadowSize + kBorderRadius;
|
||||||
@ -201,6 +219,20 @@ void OSDPretty::Reposition() {
|
|||||||
|
|
||||||
move(qBound(0, x, geometry.right() - width()),
|
move(qBound(0, x, geometry.right() - width()),
|
||||||
qBound(0, y, geometry.bottom() - height()));
|
qBound(0, y, geometry.bottom() - height()));
|
||||||
|
|
||||||
|
if (IsTransparencyAvailable())
|
||||||
|
clearMask();
|
||||||
|
else {
|
||||||
|
QBitmap mask(size());
|
||||||
|
mask.clear();
|
||||||
|
|
||||||
|
QPainter p(&mask);
|
||||||
|
p.setBrush(Qt::color1);
|
||||||
|
p.drawRoundedRect(BoxBorder().adjusted(-1, -1, 0, 0), kBorderRadius, kBorderRadius);
|
||||||
|
p.end();
|
||||||
|
|
||||||
|
setMask(mask);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OSDPretty::enterEvent(QEvent *) {
|
void OSDPretty::enterEvent(QEvent *) {
|
||||||
|
@ -41,6 +41,8 @@ class OSDPretty : public QWidget {
|
|||||||
Mode_Draggable,
|
Mode_Draggable,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static bool IsTransparencyAvailable();
|
||||||
|
|
||||||
void SetMode(Mode mode);
|
void SetMode(Mode mode);
|
||||||
void SetMessage(const QString& summary,
|
void SetMessage(const QString& summary,
|
||||||
const QString& message,
|
const QString& message,
|
||||||
@ -78,6 +80,8 @@ class OSDPretty : public QWidget {
|
|||||||
void Reposition();
|
void Reposition();
|
||||||
void Load();
|
void Load();
|
||||||
|
|
||||||
|
QRect BoxBorder() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::OSDPretty ui_;
|
Ui::OSDPretty ui_;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user