]>
cloud.milkyroute.net Git - dolphin.git/blob - 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> *
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. *
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. *
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 *******************************************************************************/
22 #include "ktooltipwindow_p.h"
24 #include <kcolorscheme.h>
25 #include <kwindowsystem.h>
28 #include <QVBoxLayout>
30 KToolTipWindow::KToolTipWindow(QWidget
* content
) :
33 setAttribute(Qt::WA_TranslucentBackground
);
34 setWindowFlags(Qt::ToolTip
| Qt::FramelessWindowHint
);
36 QVBoxLayout
* layout
= new QVBoxLayout(this);
37 layout
->addWidget(content
);
40 KToolTipWindow::~KToolTipWindow()
44 void KToolTipWindow::paintEvent(QPaintEvent
* event
)
48 QPainter
painter(this);
50 QColor toColor
= palette().brush(QPalette::ToolTipBase
).color();
51 QColor fromColor
= KColorScheme::shade(toColor
, KColorScheme::LightShade
, 0.2);
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);
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
);
67 const QRect
rect(0, 0, width(), height());
68 if (haveAlphaChannel
) {
69 const qreal radius
= 5.0;
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);
79 painter
.drawPath(path
);
81 painter
.drawRect(rect
);
85 void KToolTipWindow::arc(QPainterPath
& path
, qreal cx
, qreal cy
, qreal radius
, qreal angle
, qreal sweeplength
)
87 path
.arcTo(cx
-radius
, cy
-radius
, radius
* 2, radius
* 2, angle
, sweeplength
);
90 #include "ktooltipwindow_p.moc"