]>
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>
33 #include <nepomuk2/filemetadatawidget.h>
35 // For the blurred tooltip background
36 #include <plasma/windoweffects.h>
38 FileMetaDataToolTip::FileMetaDataToolTip(QWidget
* parent
) :
42 m_fileMetaDataWidget(0)
44 setAttribute(Qt::WA_TranslucentBackground
);
45 setWindowFlags(Qt::ToolTip
| Qt::FramelessWindowHint
);
47 // Create widget for file preview
48 m_preview
= new QLabel(this);
49 m_preview
->setAlignment(Qt::AlignTop
);
51 // Create widget for file name
52 m_name
= new QLabel(this);
53 m_name
->setForegroundRole(QPalette::ToolTipText
);
54 QFont font
= m_name
->font();
56 m_name
->setFont(font
);
58 // Create widget for the meta data
59 m_fileMetaDataWidget
= new Nepomuk2::FileMetaDataWidget(this);
60 m_fileMetaDataWidget
->setForegroundRole(QPalette::ToolTipText
);
61 m_fileMetaDataWidget
->setReadOnly(true);
62 connect(m_fileMetaDataWidget
, SIGNAL(metaDataRequestFinished(KFileItemList
)),
63 this, SIGNAL(metaDataRequestFinished(KFileItemList
)));
65 QVBoxLayout
* textLayout
= new QVBoxLayout();
66 textLayout
->addWidget(m_name
);
67 textLayout
->addWidget(new KSeparator());
68 textLayout
->addWidget(m_fileMetaDataWidget
);
69 textLayout
->setAlignment(m_name
, Qt::AlignCenter
);
70 textLayout
->setAlignment(m_fileMetaDataWidget
, Qt::AlignLeft
);
71 // Assure that the text-layout gets top-aligned by adding a stretch.
72 // Don't use textLayout->setAlignment(Qt::AlignTop) instead, as this does
73 // not work with the heightForWidth()-size-hint of m_fileMetaDataWidget
75 textLayout
->addStretch();
77 QHBoxLayout
* tipLayout
= new QHBoxLayout(this);
78 tipLayout
->addWidget(m_preview
);
79 tipLayout
->addSpacing(tipLayout
->margin());
80 tipLayout
->addLayout(textLayout
);
83 FileMetaDataToolTip::~FileMetaDataToolTip()
87 void FileMetaDataToolTip::setPreview(const QPixmap
& pixmap
)
89 m_preview
->setPixmap(pixmap
);
92 QPixmap
FileMetaDataToolTip::preview() const
94 if (m_preview
->pixmap()) {
95 return *m_preview
->pixmap();
100 void FileMetaDataToolTip::setName(const QString
& name
)
102 m_name
->setText(name
);
105 QString
FileMetaDataToolTip::name() const
107 return m_name
->text();
110 void FileMetaDataToolTip::setItems(const KFileItemList
& items
)
112 m_fileMetaDataWidget
->setItems(items
);
115 KFileItemList
FileMetaDataToolTip::items() const
117 return m_fileMetaDataWidget
->items();
120 void FileMetaDataToolTip::paintEvent(QPaintEvent
* event
)
122 QStylePainter
painter(this);
123 QStyleOptionFrame option
;
125 painter
.drawPrimitive(QStyle::PE_PanelTipLabel
, option
);
128 QWidget::paintEvent(event
);
131 void FileMetaDataToolTip::showEvent(QShowEvent
*)
133 Plasma::WindowEffects::overrideShadow(winId(), true);
134 Plasma::WindowEffects::enableBlurBehind(winId(), true, mask());
137 #include "filemetadatatooltip.moc"