]>
cloud.milkyroute.net Git - dolphin.git/blob - src/views/tooltips/filemetadatatooltip.cpp
1 /***************************************************************************
2 * Copyright (C) 2010 by Peter Penz <peter.penz19@gmail.com> *
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>
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);
43 m_preview
->setAlignment(Qt::AlignTop
);
45 // Create widget for file name
46 m_name
= new QLabel(this);
47 QFont font
= m_name
->font();
49 m_name
->setFont(font
);
51 // Create widget for the meta data
52 m_fileMetaDataWidget
= new KFileMetaDataWidget();
53 m_fileMetaDataWidget
->setForegroundRole(QPalette::ToolTipText
);
54 m_fileMetaDataWidget
->setReadOnly(true);
55 connect(m_fileMetaDataWidget
, SIGNAL(metaDataRequestFinished(KFileItemList
)),
56 this, SIGNAL(metaDataRequestFinished(KFileItemList
)));
58 QVBoxLayout
* textLayout
= new QVBoxLayout();
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
);
64 // Assure that the text-layout gets top-aligned by adding a stretch.
65 // Don't use textLayout->setAlignment(Qt::AlignTop) instead, as this does
66 // not work with the heightForWidth()-size-hint of m_fileMetaDataWidget
68 textLayout
->addStretch();
70 QHBoxLayout
* tipLayout
= new QHBoxLayout(this);
71 tipLayout
->addWidget(m_preview
);
72 tipLayout
->addSpacing(tipLayout
->margin());
73 tipLayout
->addLayout(textLayout
);
76 FileMetaDataToolTip::~FileMetaDataToolTip()
80 void FileMetaDataToolTip::setPreview(const QPixmap
& pixmap
)
82 m_preview
->setPixmap(pixmap
);
85 QPixmap
FileMetaDataToolTip::preview() const
87 if (m_preview
->pixmap() != 0) {
88 return *m_preview
->pixmap();
93 void FileMetaDataToolTip::setName(const QString
& name
)
95 m_name
->setText(name
);
98 QString
FileMetaDataToolTip::name() const
100 return m_name
->text();
103 void FileMetaDataToolTip::setItems(const KFileItemList
& items
)
105 m_fileMetaDataWidget
->setItems(items
);
108 KFileItemList
FileMetaDataToolTip::items() const
110 return m_fileMetaDataWidget
->items();
113 void FileMetaDataToolTip::paintEvent(QPaintEvent
* event
)
117 QPainter
painter(this);
119 QColor toColor
= palette().brush(QPalette::ToolTipBase
).color();
120 QColor fromColor
= KColorScheme::shade(toColor
, KColorScheme::LightShade
, 0.2);
122 const bool haveAlphaChannel
= KWindowSystem::compositingActive();
123 if (haveAlphaChannel
) {
124 painter
.setRenderHint(QPainter::Antialiasing
);
125 painter
.translate(0.5, 0.5);
126 toColor
.setAlpha(220);
127 fromColor
.setAlpha(220);
130 QLinearGradient
gradient(QPointF(0.0, 0.0), QPointF(0.0, height()));
131 gradient
.setColorAt(0.0, fromColor
);
132 gradient
.setColorAt(1.0, toColor
);
133 painter
.setPen(Qt::NoPen
);
134 painter
.setBrush(gradient
);
136 const QRect
rect(0, 0, width(), height());
137 if (haveAlphaChannel
) {
138 const qreal radius
= 5.0;
141 path
.moveTo(rect
.left(), rect
.top() + radius
);
142 arc(path
, rect
.left() + radius
, rect
.top() + radius
, radius
, 180, -90);
143 arc(path
, rect
.right() - radius
, rect
.top() + radius
, radius
, 90, -90);
144 arc(path
, rect
.right() - radius
, rect
.bottom() - radius
, radius
, 0, -90);
145 arc(path
, rect
.left() + radius
, rect
.bottom() - radius
, radius
, 270, -90);
148 painter
.drawPath(path
);
150 painter
.drawRect(rect
);
154 void FileMetaDataToolTip::arc(QPainterPath
& path
,
156 qreal radius
, qreal angle
,
159 path
.arcTo(cx
-radius
, cy
-radius
, radius
* 2, radius
* 2, angle
, sweepLength
);
162 #include "filemetadatatooltip.moc"