1 | /* |
2 | This file is part of the KDE project. |
3 | |
4 | Copyright (c) 2011 Lionel Chauvin <megabigbug@yahoo.fr> |
5 | Copyright (c) 2011,2012 Cédric Bellegarde <gnumdk@gmail.com> |
6 | |
7 | Permission is hereby granted, free of charge, to any person obtaining a |
8 | copy of this software and associated documentation files (the "Software"), |
9 | to deal in the Software without restriction, including without limitation |
10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, |
11 | and/or sell copies of the Software, and to permit persons to whom the |
12 | Software is furnished to do so, subject to the following conditions: |
13 | |
14 | The above copyright notice and this permission notice shall be included in |
15 | all copies or substantial portions of the Software. |
16 | |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
23 | DEALINGS IN THE SOFTWARE. |
24 | */ |
25 | |
26 | #include "glowbar.h" |
27 | |
28 | #include <X11/extensions/shape.h> |
29 | #include <fixx11h.h> |
30 | |
31 | #include <Plasma/Svg> |
32 | #include <KWindowSystem> |
33 | #include <KDebug> |
34 | |
35 | #include <QTimer> |
36 | #include <QDebug> |
37 | #include <QPainter> |
38 | #include <QX11Info> |
39 | |
40 | |
41 | GlowBar::GlowBar() |
42 | : QWidget(0), |
43 | m_svg(new Plasma::Svg(this)) |
44 | { |
45 | m_svg->setImagePath("widgets/glowbar" ); |
46 | |
47 | setWindowFlags(Qt::Tool | Qt::X11BypassWindowManagerHint | Qt::WindowStaysOnTopHint); |
48 | setAttribute(Qt::WA_TranslucentBackground); |
49 | setAutoFillBackground(false); |
50 | KWindowSystem::setType(winId(), NET::Dock); |
51 | |
52 | QPalette pal = palette(); |
53 | pal.setColor(backgroundRole(), Qt::transparent); |
54 | setPalette(pal); |
55 | |
56 | setInputMask(); |
57 | } |
58 | |
59 | GlowBar::~GlowBar() |
60 | { |
61 | } |
62 | |
63 | void GlowBar::paintEvent(QPaintEvent*) |
64 | { |
65 | QPixmap l, r, c; |
66 | QPoint pixmapPosition(0, 0); |
67 | |
68 | m_buffer.fill(QColor(0, 0, 0, int(qreal(255)*0.3))); |
69 | QPainter p(&m_buffer); |
70 | p.setCompositionMode(QPainter::CompositionMode_SourceIn); |
71 | l = m_svg->pixmap("bottomleft" ); |
72 | r = m_svg->pixmap("bottomright" ); |
73 | c = m_svg->pixmap("bottom" ); |
74 | p.drawPixmap(pixmapPosition, l); |
75 | p.drawTiledPixmap(QRect(l.width(), pixmapPosition.y(), width() - l.width() - r.width(), c.height()), c); |
76 | p.drawPixmap(QPoint(width() - r.width(), pixmapPosition.y()), r); |
77 | p.end(); |
78 | p.begin(this); |
79 | p.drawPixmap(QPoint(0, 0), m_buffer); |
80 | } |
81 | |
82 | void GlowBar::setPixmap(const QPoint pos, uint width) |
83 | { |
84 | QRect zone = QRect(pos, QSize(width, 10)); |
85 | setGeometry(zone); |
86 | m_buffer = QPixmap(zone.size()); |
87 | } |
88 | |
89 | void GlowBar::setInputMask() |
90 | { |
91 | // Create an empty input mask to achieve click-through effect |
92 | // Thanks to MacSlow for this! |
93 | Pixmap mask; |
94 | |
95 | mask = XCreatePixmap(QX11Info::display(), |
96 | winId(), |
97 | 1, /* width */ |
98 | 1, /* height */ |
99 | 1 /* depth */); |
100 | XShapeCombineMask(QX11Info::display(), |
101 | winId(), |
102 | ShapeInput, |
103 | 0, /* x-offset */ |
104 | 0, /* y-offset */ |
105 | mask, |
106 | ShapeSet); |
107 | XFreePixmap(QX11Info::display(), mask); |
108 | } |
109 | #include "glowbar.moc" |
110 | |