]> cloud.milkyroute.net Git - dolphin.git/blob - src/views/tooltips/filemetadatatooltip.cpp
Merge branch 'KDE/4.10'
[dolphin.git] / 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> *
4 * Copyright (C) 2012 by Mark Gaiser <markg85@gmail.com> *
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 "filemetadatatooltip.h"
23
24 #include <KColorScheme>
25 #include <KSeparator>
26 #include <KWindowSystem>
27
28 #include <QLabel>
29 #include <QStyleOptionFrame>
30 #include <QStylePainter>
31 #include <QVBoxLayout>
32
33 #include <nepomuk2/filemetadatawidget.h>
34
35 // For the blurred tooltip background
36 #include <plasma/windoweffects.h>
37
38 FileMetaDataToolTip::FileMetaDataToolTip(QWidget* parent) :
39 QWidget(parent),
40 m_preview(0),
41 m_name(0),
42 m_fileMetaDataWidget(0)
43 {
44 setAttribute(Qt::WA_TranslucentBackground);
45 setWindowFlags(Qt::ToolTip | Qt::FramelessWindowHint);
46
47 // Create widget for file preview
48 m_preview = new QLabel(this);
49 m_preview->setAlignment(Qt::AlignTop);
50
51 // Create widget for file name
52 m_name = new QLabel(this);
53 m_name->setForegroundRole(QPalette::ToolTipText);
54 QFont font = m_name->font();
55 font.setBold(true);
56 m_name->setFont(font);
57
58 // Create widget for the meta data
59 m_fileMetaDataWidget = new Nepomuk2::FileMetaDataWidget(this);
60 m_fileMetaDataWidget->setForegroundRole(QPalette::ToolTipText);
61 m_fileMetaDataWidget->setReadOnly(true);
62 connect(m_fileMetaDataWidget, SIGNAL(metaDataRequestFinished(KFileItemList)),
63 this, SIGNAL(metaDataRequestFinished(KFileItemList)));
64
65 QVBoxLayout* textLayout = new QVBoxLayout();
66 textLayout->addWidget(m_name);
67 textLayout->addWidget(new KSeparator());
68 textLayout->addWidget(m_fileMetaDataWidget);
69 textLayout->setAlignment(m_name, Qt::AlignCenter);
70 textLayout->setAlignment(m_fileMetaDataWidget, Qt::AlignLeft);
71 // Assure that the text-layout gets top-aligned by adding a stretch.
72 // Don't use textLayout->setAlignment(Qt::AlignTop) instead, as this does
73 // not work with the heightForWidth()-size-hint of m_fileMetaDataWidget
74 // (see bug #241608)
75 textLayout->addStretch();
76
77 QHBoxLayout* tipLayout = new QHBoxLayout(this);
78 tipLayout->addWidget(m_preview);
79 tipLayout->addSpacing(tipLayout->margin());
80 tipLayout->addLayout(textLayout);
81 }
82
83 FileMetaDataToolTip::~FileMetaDataToolTip()
84 {
85 }
86
87 void FileMetaDataToolTip::setPreview(const QPixmap& pixmap)
88 {
89 m_preview->setPixmap(pixmap);
90 }
91
92 QPixmap FileMetaDataToolTip::preview() const
93 {
94 if (m_preview->pixmap()) {
95 return *m_preview->pixmap();
96 }
97 return QPixmap();
98 }
99
100 void FileMetaDataToolTip::setName(const QString& name)
101 {
102 m_name->setText(name);
103 }
104
105 QString FileMetaDataToolTip::name() const
106 {
107 return m_name->text();
108 }
109
110 void FileMetaDataToolTip::setItems(const KFileItemList& items)
111 {
112 m_fileMetaDataWidget->setItems(items);
113 }
114
115 KFileItemList FileMetaDataToolTip::items() const
116 {
117 return m_fileMetaDataWidget->items();
118 }
119
120 void FileMetaDataToolTip::paintEvent(QPaintEvent* event)
121 {
122 QStylePainter painter(this);
123 QStyleOptionFrame option;
124 option.init(this);
125 painter.drawPrimitive(QStyle::PE_PanelTipLabel, option);
126 painter.end();
127
128 QWidget::paintEvent(event);
129 }
130
131 void FileMetaDataToolTip::showEvent(QShowEvent *)
132 {
133 Plasma::WindowEffects::overrideShadow(winId(), true);
134 Plasma::WindowEffects::enableBlurBehind(winId(), true, mask());
135 }
136
137 #include "filemetadatatooltip.moc"