]> cloud.milkyroute.net Git - dolphin.git/blob - src/views/tooltips/filemetadatatooltip.cpp
Details view: Fix jumping column-widths
[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 QFont font = m_name->font();
49 font.setBold(true);
50 m_name->setFont(font);
51
52 // Create widget for the meta data
53 m_fileMetaDataWidget = new KFileMetaDataWidget(this);
54 m_fileMetaDataWidget->setForegroundRole(QPalette::ToolTipText);
55 m_fileMetaDataWidget->setReadOnly(true);
56 connect(m_fileMetaDataWidget, SIGNAL(metaDataRequestFinished(KFileItemList)),
57 this, SIGNAL(metaDataRequestFinished(KFileItemList)));
58
59 QVBoxLayout* textLayout = new QVBoxLayout();
60 textLayout->addWidget(m_name);
61 textLayout->addWidget(new KSeparator());
62 textLayout->addWidget(m_fileMetaDataWidget);
63 textLayout->setAlignment(m_name, Qt::AlignCenter);
64 textLayout->setAlignment(m_fileMetaDataWidget, Qt::AlignLeft);
65 // Assure that the text-layout gets top-aligned by adding a stretch.
66 // Don't use textLayout->setAlignment(Qt::AlignTop) instead, as this does
67 // not work with the heightForWidth()-size-hint of m_fileMetaDataWidget
68 // (see bug #241608)
69 textLayout->addStretch();
70
71 QHBoxLayout* tipLayout = new QHBoxLayout(this);
72 tipLayout->addWidget(m_preview);
73 tipLayout->addSpacing(tipLayout->margin());
74 tipLayout->addLayout(textLayout);
75 }
76
77 FileMetaDataToolTip::~FileMetaDataToolTip()
78 {
79 }
80
81 void FileMetaDataToolTip::setPreview(const QPixmap& pixmap)
82 {
83 m_preview->setPixmap(pixmap);
84 }
85
86 QPixmap FileMetaDataToolTip::preview() const
87 {
88 if (m_preview->pixmap()) {
89 return *m_preview->pixmap();
90 }
91 return QPixmap();
92 }
93
94 void FileMetaDataToolTip::setName(const QString& name)
95 {
96 m_name->setText(name);
97 }
98
99 QString FileMetaDataToolTip::name() const
100 {
101 return m_name->text();
102 }
103
104 void FileMetaDataToolTip::setItems(const KFileItemList& items)
105 {
106 m_fileMetaDataWidget->setItems(items);
107 }
108
109 KFileItemList FileMetaDataToolTip::items() const
110 {
111 return m_fileMetaDataWidget->items();
112 }
113
114 void FileMetaDataToolTip::paintEvent(QPaintEvent* event)
115 {
116 QStylePainter painter(this);
117 QStyleOptionFrame option;
118 option.init(this);
119 painter.drawPrimitive(QStyle::PE_PanelTipLabel, option);
120 painter.end();
121
122 QWidget::paintEvent(event);
123 }
124
125 #include "filemetadatatooltip.moc"