~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kinfocenter/ToolTips/ktooltipwindow.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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(0.0, 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
    if (haveAlphaChannel) {
 
76
        const qreal radius = 5.0;
 
77
 
 
78
        QPainterPath path;
 
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);
 
84
        path.closeSubpath();
 
85
 
 
86
        painter.drawPath(path);
 
87
    } else {
 
88
        painter.drawRect(rect);
 
89
    }
 
90
}
 
91
 
 
92
void KToolTipWindow::arc(QPainterPath& path, qreal cx, qreal cy, qreal radius, qreal angle, qreal sweeplength)
 
93
{
 
94
    path.arcTo(cx-radius, cy-radius, radius * 2, radius * 2, angle, sweeplength);
 
95
}
 
96