]> cloud.milkyroute.net Git - dolphin.git/blob - src/tooltips/ktooltipwindow.cpp
Always apply the editable state of the current URL navigator to the URL navigator...
[dolphin.git] / src / tooltips / ktooltipwindow.cpp
1 /*******************************************************************************
2 * Copyright (C) 2008 by Fredrik Höglund <fredrik@kde.org> *
3 * Copyright (C) 2008 by Konstantin Heil <konst.heil@stud.uni-heidelberg.de> *
4 * Copyright (C) 2009 by Peter Penz <peter.penz@gmx.at> *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 *******************************************************************************/
21
22 #include "ktooltipwindow_p.h"
23
24 #include <kcolorscheme.h>
25 #include <kwindowsystem.h>
26
27 #include <QPainter>
28 #include <QVBoxLayout>
29
30 KToolTipWindow::KToolTipWindow(QWidget* content) :
31 QWidget(0)
32 {
33 setAttribute(Qt::WA_TranslucentBackground);
34 setWindowFlags(Qt::ToolTip | Qt::FramelessWindowHint);
35
36 QVBoxLayout* layout = new QVBoxLayout(this);
37 layout->addWidget(content);
38 }
39
40 KToolTipWindow::~KToolTipWindow()
41 {
42 }
43
44 void KToolTipWindow::paintEvent(QPaintEvent* event)
45 {
46 Q_UNUSED(event);
47
48 QPainter painter(this);
49
50 QColor toColor = palette().brush(QPalette::ToolTipBase).color();
51 QColor fromColor = KColorScheme::shade(toColor, KColorScheme::LightShade, 0.2);
52
53 const bool haveAlphaChannel = KWindowSystem::compositingActive();
54 if (haveAlphaChannel) {
55 painter.setRenderHint(QPainter::Antialiasing);
56 painter.translate(0.5, 0.5);
57 toColor.setAlpha(220);
58 fromColor.setAlpha(220);
59 }
60
61 QLinearGradient gradient(QPointF(0.0, 0.0), QPointF(0.0, height()));
62 gradient.setColorAt(0.0, fromColor);
63 gradient.setColorAt(1.0, toColor);
64 painter.setPen(Qt::NoPen);
65 painter.setBrush(gradient);
66
67 const QRect rect(0, 0, width(), height());
68 if (haveAlphaChannel) {
69 const qreal radius = 5.0;
70
71 QPainterPath path;
72 path.moveTo(rect.left(), rect.top() + radius);
73 arc(path, rect.left() + radius, rect.top() + radius, radius, 180, -90);
74 arc(path, rect.right() - radius, rect.top() + radius, radius, 90, -90);
75 arc(path, rect.right() - radius, rect.bottom() - radius, radius, 0, -90);
76 arc(path, rect.left() + radius, rect.bottom() - radius, radius, 270, -90);
77 path.closeSubpath();
78
79 painter.drawPath(path);
80 } else {
81 painter.drawRect(rect);
82 }
83 }
84
85 void KToolTipWindow::arc(QPainterPath& path, qreal cx, qreal cy, qreal radius, qreal angle, qreal sweeplength)
86 {
87 path.arcTo(cx-radius, cy-radius, radius * 2, radius * 2, angle, sweeplength);
88 }
89
90 #include "ktooltipwindow_p.moc"