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