]>
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>
27 #include <QVBoxLayout>
33 KToolTipWindow::KToolTipWindow(QWidget
* content
) :
36 setAttribute(Qt::WA_TranslucentBackground
);
37 setWindowFlags(Qt::ToolTip
| Qt::FramelessWindowHint
);
39 QVBoxLayout
* layout
= new QVBoxLayout(this);
40 layout
->addWidget(content
);
43 KToolTipWindow::~KToolTipWindow()
47 void KToolTipWindow::paintEvent(QPaintEvent
* event
)
51 QPainter
painter(this);
53 QColor toColor
= palette().brush(QPalette::ToolTipBase
).color();
54 QColor fromColor
= KColorScheme::shade(toColor
, KColorScheme::LightShade
, 0.2);
57 const bool haveAlphaChannel
= QX11Info::isCompositingManagerRunning();
59 const bool haveAlphaChannel
= false;
61 if (haveAlphaChannel
) {
62 painter
.setRenderHint(QPainter::Antialiasing
);
63 painter
.translate(0.5, 0.5);
64 toColor
.setAlpha(220);
65 fromColor
.setAlpha(220);
68 QLinearGradient
gradient(QPointF(0.0, 0.0), QPointF(0.0, height()));
69 gradient
.setColorAt(0.0, fromColor
);
70 gradient
.setColorAt(1.0, toColor
);
71 painter
.setPen(Qt::NoPen
);
72 painter
.setBrush(gradient
);
74 const QRect
rect(0, 0, width(), height());
75 if (haveAlphaChannel
) {
76 const qreal radius
= 5.0;
79 path
.moveTo(rect
.left(), rect
.top() + radius
);
80 arc(path
, rect
.left() + radius
, rect
.top() + radius
, radius
, 180, -90);
81 arc(path
, rect
.right() - radius
, rect
.top() + radius
, radius
, 90, -90);
82 arc(path
, rect
.right() - radius
, rect
.bottom() - radius
, radius
, 0, -90);
83 arc(path
, rect
.left() + radius
, rect
.bottom() - radius
, radius
, 270, -90);
86 painter
.drawPath(path
);
88 painter
.drawRect(rect
);
92 void KToolTipWindow::arc(QPainterPath
& path
, qreal cx
, qreal cy
, qreal radius
, qreal angle
, qreal sweeplength
)
94 path
.arcTo(cx
-radius
, cy
-radius
, radius
* 2, radius
* 2, angle
, sweeplength
);
97 #include "ktooltipwindow_p.moc"