]>
cloud.milkyroute.net Git - dolphin.git/blob - src/views/tooltips/filemetadatatooltip.cpp
1 /***************************************************************************
2 * Copyright (C) 2010 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2008 by Fredrik Höglund <fredrik@kde.org> *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
21 #include "filemetadatatooltip.h"
23 #include <KColorScheme>
24 #include <kfilemetadatawidget.h>
26 #include <KWindowSystem>
30 #include <QVBoxLayout>
32 FileMetaDataToolTip::FileMetaDataToolTip(QWidget
* parent
) :
36 m_fileMetaDataWidget(0)
38 setAttribute(Qt::WA_TranslucentBackground
);
39 setWindowFlags(Qt::ToolTip
| Qt::FramelessWindowHint
);
41 // Create widget for file preview
42 m_preview
= new QLabel(this);
44 // Create widget for file name
45 m_name
= new QLabel(this);
46 QFont font
= m_name
->font();
48 m_name
->setFont(font
);
50 // Create widget for the meta data
51 m_fileMetaDataWidget
= new KFileMetaDataWidget();
52 m_fileMetaDataWidget
->setForegroundRole(QPalette::ToolTipText
);
53 m_fileMetaDataWidget
->setReadOnly(true);
54 connect(m_fileMetaDataWidget
, SIGNAL(metaDataRequestFinished()),
55 this, SIGNAL(metaDataRequestFinished()));
57 QVBoxLayout
* textLayout
= new QVBoxLayout();
58 textLayout
->setAlignment(Qt::AlignTop
);
59 textLayout
->addWidget(m_name
);
60 textLayout
->addWidget(new KSeparator());
61 textLayout
->addWidget(m_fileMetaDataWidget
);
62 textLayout
->setAlignment(m_name
, Qt::AlignCenter
);
63 textLayout
->setAlignment(m_fileMetaDataWidget
, Qt::AlignLeft
);
65 QHBoxLayout
* tipLayout
= new QHBoxLayout(this);
66 tipLayout
->addWidget(m_preview
);
67 tipLayout
->addLayout(textLayout
);
70 FileMetaDataToolTip::~FileMetaDataToolTip()
74 void FileMetaDataToolTip::setPreview(const QPixmap
& pixmap
)
76 m_preview
->setPixmap(pixmap
);
79 QPixmap
FileMetaDataToolTip::preview() const
81 if (m_preview
->pixmap() != 0) {
82 return *m_preview
->pixmap();
87 void FileMetaDataToolTip::setName(const QString
& name
)
89 m_name
->setText(name
);
92 QString
FileMetaDataToolTip::name() const
94 return m_name
->text();
97 void FileMetaDataToolTip::setItems(const KFileItemList
& items
)
99 m_fileMetaDataWidget
->setItems(items
);
102 KFileItemList
FileMetaDataToolTip::items() const
104 return m_fileMetaDataWidget
->items();
107 void FileMetaDataToolTip::paintEvent(QPaintEvent
* event
)
111 QPainter
painter(this);
113 QColor toColor
= palette().brush(QPalette::ToolTipBase
).color();
114 QColor fromColor
= KColorScheme::shade(toColor
, KColorScheme::LightShade
, 0.2);
116 const bool haveAlphaChannel
= KWindowSystem::compositingActive();
117 if (haveAlphaChannel
) {
118 painter
.setRenderHint(QPainter::Antialiasing
);
119 painter
.translate(0.5, 0.5);
120 toColor
.setAlpha(220);
121 fromColor
.setAlpha(220);
124 QLinearGradient
gradient(QPointF(0.0, 0.0), QPointF(0.0, height()));
125 gradient
.setColorAt(0.0, fromColor
);
126 gradient
.setColorAt(1.0, toColor
);
127 painter
.setPen(Qt::NoPen
);
128 painter
.setBrush(gradient
);
130 const QRect
rect(0, 0, width(), height());
131 if (haveAlphaChannel
) {
132 const qreal radius
= 5.0;
135 path
.moveTo(rect
.left(), rect
.top() + radius
);
136 arc(path
, rect
.left() + radius
, rect
.top() + radius
, radius
, 180, -90);
137 arc(path
, rect
.right() - radius
, rect
.top() + radius
, radius
, 90, -90);
138 arc(path
, rect
.right() - radius
, rect
.bottom() - radius
, radius
, 0, -90);
139 arc(path
, rect
.left() + radius
, rect
.bottom() - radius
, radius
, 270, -90);
142 painter
.drawPath(path
);
144 painter
.drawRect(rect
);
148 void FileMetaDataToolTip::arc(QPainterPath
& path
,
150 qreal radius
, qreal angle
,
153 path
.arcTo(cx
-radius
, cy
-radius
, radius
* 2, radius
* 2, angle
, sweepLength
);
156 #include "filemetadatatooltip.moc"