]>
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> *
4 * Copyright (C) 2012 by Mark Gaiser <markg85@gmail.com> *
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. *
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. *
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 ***************************************************************************/
22 #include "filemetadatatooltip.h"
24 #include <KColorScheme>
25 #include <kfilemetadatawidget.h>
27 #include <KWindowSystem>
30 #include <QStyleOptionFrame>
31 #include <QStylePainter>
32 #include <QVBoxLayout>
34 // For the blurred tooltip background
35 #include <plasma/windoweffects.h>
37 FileMetaDataToolTip::FileMetaDataToolTip(QWidget
* parent
) :
41 m_fileMetaDataWidget(0)
43 setAttribute(Qt::WA_TranslucentBackground
);
44 setWindowFlags(Qt::ToolTip
| Qt::FramelessWindowHint
);
46 // Create widget for file preview
47 m_preview
= new QLabel(this);
48 m_preview
->setAlignment(Qt::AlignTop
);
50 // Create widget for file name
51 m_name
= new QLabel(this);
52 m_name
->setForegroundRole(QPalette::ToolTipText
);
53 QFont font
= m_name
->font();
55 m_name
->setFont(font
);
57 // Create widget for the meta data
58 m_fileMetaDataWidget
= new KFileMetaDataWidget(this);
59 m_fileMetaDataWidget
->setForegroundRole(QPalette::ToolTipText
);
60 m_fileMetaDataWidget
->setReadOnly(true);
61 connect(m_fileMetaDataWidget
, SIGNAL(metaDataRequestFinished(KFileItemList
)),
62 this, SIGNAL(metaDataRequestFinished(KFileItemList
)));
64 QVBoxLayout
* textLayout
= new QVBoxLayout();
65 textLayout
->addWidget(m_name
);
66 textLayout
->addWidget(new KSeparator());
67 textLayout
->addWidget(m_fileMetaDataWidget
);
68 textLayout
->setAlignment(m_name
, Qt::AlignCenter
);
69 textLayout
->setAlignment(m_fileMetaDataWidget
, Qt::AlignLeft
);
70 // Assure that the text-layout gets top-aligned by adding a stretch.
71 // Don't use textLayout->setAlignment(Qt::AlignTop) instead, as this does
72 // not work with the heightForWidth()-size-hint of m_fileMetaDataWidget
74 textLayout
->addStretch();
76 QHBoxLayout
* tipLayout
= new QHBoxLayout(this);
77 tipLayout
->addWidget(m_preview
);
78 tipLayout
->addSpacing(tipLayout
->margin());
79 tipLayout
->addLayout(textLayout
);
82 FileMetaDataToolTip::~FileMetaDataToolTip()
86 void FileMetaDataToolTip::setPreview(const QPixmap
& pixmap
)
88 m_preview
->setPixmap(pixmap
);
91 QPixmap
FileMetaDataToolTip::preview() const
93 if (m_preview
->pixmap()) {
94 return *m_preview
->pixmap();
99 void FileMetaDataToolTip::setName(const QString
& name
)
101 m_name
->setText(name
);
104 QString
FileMetaDataToolTip::name() const
106 return m_name
->text();
109 void FileMetaDataToolTip::setItems(const KFileItemList
& items
)
111 m_fileMetaDataWidget
->setItems(items
);
114 KFileItemList
FileMetaDataToolTip::items() const
116 return m_fileMetaDataWidget
->items();
119 void FileMetaDataToolTip::paintEvent(QPaintEvent
* event
)
121 QStylePainter
painter(this);
122 QStyleOptionFrame option
;
124 painter
.drawPrimitive(QStyle::PE_PanelTipLabel
, option
);
127 QWidget::paintEvent(event
);
130 void FileMetaDataToolTip::showEvent(QShowEvent
*)
132 Plasma::WindowEffects::overrideShadow(winId(), true);
133 Plasma::WindowEffects::enableBlurBehind(winId(), true, mask());
136 #include "filemetadatatooltip.moc"