]>
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 QFont font
= m_name
->font();
60 m_name
->setFont(font
);
62 // Create widget for the meta data
64 m_fileMetaDataWidget
= new KFileMetaDataWidget(this);
66 m_fileMetaDataWidget
= new Nepomuk2::FileMetaDataWidget(this);
68 m_fileMetaDataWidget
->setForegroundRole(QPalette::ToolTipText
);
69 m_fileMetaDataWidget
->setReadOnly(true);
70 connect(m_fileMetaDataWidget
, SIGNAL(metaDataRequestFinished(KFileItemList
)),
71 this, SIGNAL(metaDataRequestFinished(KFileItemList
)));
73 QVBoxLayout
* textLayout
= new QVBoxLayout();
74 textLayout
->addWidget(m_name
);
75 textLayout
->addWidget(new KSeparator());
76 textLayout
->addWidget(m_fileMetaDataWidget
);
77 textLayout
->setAlignment(m_name
, Qt::AlignCenter
);
78 textLayout
->setAlignment(m_fileMetaDataWidget
, Qt::AlignLeft
);
79 // Assure that the text-layout gets top-aligned by adding a stretch.
80 // Don't use textLayout->setAlignment(Qt::AlignTop) instead, as this does
81 // not work with the heightForWidth()-size-hint of m_fileMetaDataWidget
83 textLayout
->addStretch();
85 QHBoxLayout
* tipLayout
= new QHBoxLayout(this);
86 tipLayout
->addWidget(m_preview
);
87 tipLayout
->addSpacing(tipLayout
->margin());
88 tipLayout
->addLayout(textLayout
);
91 FileMetaDataToolTip::~FileMetaDataToolTip()
95 void FileMetaDataToolTip::setPreview(const QPixmap
& pixmap
)
97 m_preview
->setPixmap(pixmap
);
100 QPixmap
FileMetaDataToolTip::preview() const
102 if (m_preview
->pixmap()) {
103 return *m_preview
->pixmap();
108 void FileMetaDataToolTip::setName(const QString
& name
)
110 m_name
->setText(name
);
113 QString
FileMetaDataToolTip::name() const
115 return m_name
->text();
118 void FileMetaDataToolTip::setItems(const KFileItemList
& items
)
120 m_fileMetaDataWidget
->setItems(items
);
123 KFileItemList
FileMetaDataToolTip::items() const
125 return m_fileMetaDataWidget
->items();
128 void FileMetaDataToolTip::paintEvent(QPaintEvent
* event
)
130 QStylePainter
painter(this);
131 QStyleOptionFrame option
;
133 painter
.drawPrimitive(QStyle::PE_PanelTipLabel
, option
);
136 QWidget::paintEvent(event
);
139 void FileMetaDataToolTip::showEvent(QShowEvent
*)
141 Plasma::WindowEffects::overrideShadow(winId(), true);
142 Plasma::WindowEffects::enableBlurBehind(winId(), true, mask());
145 #include "filemetadatatooltip.moc"