]> cloud.milkyroute.net Git - dolphin.git/blob - src/tooltips/ktooltipwindow.cpp
fancy date formatting
[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
26 #include <QPainter>
27 #include <QVBoxLayout>
28
29 #ifdef Q_WS_X11
30 #include <QX11Info>
31 #endif
32
33 KToolTipWindow::KToolTipWindow(QWidget* content) :
34 QWidget(0)
35 {
36 setAttribute(Qt::WA_TranslucentBackground);
37 setWindowFlags(Qt::ToolTip | Qt::FramelessWindowHint);
38
39 QVBoxLayout* layout = new QVBoxLayout(this);
40 layout->addWidget(content);
41 }
42
43 KToolTipWindow::~KToolTipWindow()
44 {
45 }
46
47 void KToolTipWindow::paintEvent(QPaintEvent* event)
48 {
49 Q_UNUSED(event);
50
51 QPainter painter(this);
52
53 QColor toColor = palette().brush(QPalette::ToolTipBase).color();
54 QColor fromColor = KColorScheme::shade(toColor, KColorScheme::LightShade, 0.2);
55
56 #ifdef Q_WS_X11
57 const bool haveAlphaChannel = QX11Info::isCompositingManagerRunning();
58 #else
59 const bool haveAlphaChannel = false;
60 #endif
61 if (haveAlphaChannel) {
62 painter.setRenderHint(QPainter::Antialiasing);
63 painter.translate(0.5, 0.5);
64 toColor.setAlpha(220);
65 fromColor.setAlpha(220);
66 }
67
68 QLinearGradient gradient(QPointF(0.0, 0.0), QPointF(width(), height()));
69 gradient.setColorAt(0.0, fromColor);
70 gradient.setColorAt(1.0, toColor);
71 painter.setPen(Qt::NoPen);
72 painter.setBrush(gradient);
73
74 const QRect rect(0, 0, width(), height());
75 const qreal radius = 5;
76
77 QPainterPath path;
78 path.moveTo(rect.left(), rect.top() + radius);
79 arc(path, rect.left() + radius, rect.top() + radius, radius, 180, -90);
80 arc(path, rect.right() - radius, rect.top() + radius, radius, 90, -90);
81 arc(path, rect.right() - radius, rect.bottom() - radius, radius, 0, -90);
82 arc(path, rect.left() + radius, rect.bottom() - radius, radius, 270, -90);
83 path.closeSubpath();
84
85 painter.drawPath(path);
86 }
87
88 void KToolTipWindow::arc(QPainterPath& path, qreal cx, qreal cy, qreal radius, qreal angle, qreal sweeplength)
89 {
90 path.arcTo(cx-radius, cy-radius, radius * 2, radius * 2, angle, sweeplength);
91 }
92
93 #include "ktooltipwindow_p.moc"