]>
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>
26 #include <KWindowSystem>
29 #include <QStyleOptionFrame>
30 #include <QStylePainter>
31 #include <QVBoxLayout>
34 #include <KFileMetaDataWidget>
36 #include <nepomuk2/filemetadatawidget.h>
39 // For the blurred tooltip background
40 #include <plasma/windoweffects.h>
42 FileMetaDataToolTip::FileMetaDataToolTip(QWidget
* parent
) :
46 m_fileMetaDataWidget(0)
48 setAttribute(Qt::WA_TranslucentBackground
);
49 setWindowFlags(Qt::ToolTip
| Qt::FramelessWindowHint
);
51 // Create widget for file preview
52 m_preview
= new QLabel(this);
53 m_preview
->setAlignment(Qt::AlignTop
);
55 // Create widget for file name
56 m_name
= new QLabel(this);
57 m_name
->setForegroundRole(QPalette::ToolTipText
);
58 m_name
->setTextFormat(Qt::PlainText
);
59 QFont font
= m_name
->font();
61 m_name
->setFont(font
);
63 // Create widget for the meta data
65 m_fileMetaDataWidget
= new KFileMetaDataWidget(this);
67 m_fileMetaDataWidget
= new Nepomuk2::FileMetaDataWidget(this);
69 m_fileMetaDataWidget
->setForegroundRole(QPalette::ToolTipText
);
70 m_fileMetaDataWidget
->setReadOnly(true);
71 connect(m_fileMetaDataWidget
, SIGNAL(metaDataRequestFinished(KFileItemList
)),
72 this, SIGNAL(metaDataRequestFinished(KFileItemList
)));
74 QVBoxLayout
* textLayout
= new QVBoxLayout();
75 textLayout
->addWidget(m_name
);
76 textLayout
->addWidget(new KSeparator());
77 textLayout
->addWidget(m_fileMetaDataWidget
);
78 textLayout
->setAlignment(m_name
, Qt::AlignCenter
);
79 textLayout
->setAlignment(m_fileMetaDataWidget
, Qt::AlignLeft
);
80 // Assure that the text-layout gets top-aligned by adding a stretch.
81 // Don't use textLayout->setAlignment(Qt::AlignTop) instead, as this does
82 // not work with the heightForWidth()-size-hint of m_fileMetaDataWidget
84 textLayout
->addStretch();
86 QHBoxLayout
* tipLayout
= new QHBoxLayout(this);
87 tipLayout
->addWidget(m_preview
);
88 tipLayout
->addSpacing(tipLayout
->margin());
89 tipLayout
->addLayout(textLayout
);
92 FileMetaDataToolTip::~FileMetaDataToolTip()
96 void FileMetaDataToolTip::setPreview(const QPixmap
& pixmap
)
98 m_preview
->setPixmap(pixmap
);
101 QPixmap
FileMetaDataToolTip::preview() const
103 if (m_preview
->pixmap()) {
104 return *m_preview
->pixmap();
109 void FileMetaDataToolTip::setName(const QString
& name
)
111 m_name
->setText(name
);
114 QString
FileMetaDataToolTip::name() const
116 return m_name
->text();
119 void FileMetaDataToolTip::setItems(const KFileItemList
& items
)
121 m_fileMetaDataWidget
->setItems(items
);
124 KFileItemList
FileMetaDataToolTip::items() const
126 return m_fileMetaDataWidget
->items();
129 void FileMetaDataToolTip::paintEvent(QPaintEvent
* event
)
131 QStylePainter
painter(this);
132 QStyleOptionFrame option
;
134 painter
.drawPrimitive(QStyle::PE_PanelTipLabel
, option
);
137 QWidget::paintEvent(event
);
140 void FileMetaDataToolTip::showEvent(QShowEvent
*)
142 Plasma::WindowEffects::overrideShadow(winId(), true);
143 Plasma::WindowEffects::enableBlurBehind(winId(), true, mask());
146 #include "filemetadatatooltip.moc"