]>
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> *
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. *
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. *
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 ***************************************************************************/
21 #include "filemetadatatooltip.h"
23 #include <KColorScheme>
24 #include <kfilemetadatawidget.h>
26 #include <KWindowSystem>
29 #include <QStyleOptionFrame>
30 #include <QStylePainter>
31 #include <QVBoxLayout>
33 FileMetaDataToolTip::FileMetaDataToolTip(QWidget
* parent
) :
37 m_fileMetaDataWidget(0)
39 setAttribute(Qt::WA_TranslucentBackground
);
40 setWindowFlags(Qt::ToolTip
| Qt::FramelessWindowHint
);
42 // Create widget for file preview
43 m_preview
= new QLabel(this);
44 m_preview
->setAlignment(Qt::AlignTop
);
46 // Create widget for file name
47 m_name
= new QLabel(this);
48 QFont font
= m_name
->font();
50 m_name
->setFont(font
);
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
)));
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
69 textLayout
->addStretch();
71 QHBoxLayout
* tipLayout
= new QHBoxLayout(this);
72 tipLayout
->addWidget(m_preview
);
73 tipLayout
->addSpacing(tipLayout
->margin());
74 tipLayout
->addLayout(textLayout
);
77 FileMetaDataToolTip::~FileMetaDataToolTip()
81 void FileMetaDataToolTip::setPreview(const QPixmap
& pixmap
)
83 m_preview
->setPixmap(pixmap
);
86 QPixmap
FileMetaDataToolTip::preview() const
88 if (m_preview
->pixmap()) {
89 return *m_preview
->pixmap();
94 void FileMetaDataToolTip::setName(const QString
& name
)
96 m_name
->setText(name
);
99 QString
FileMetaDataToolTip::name() const
101 return m_name
->text();
104 void FileMetaDataToolTip::setItems(const KFileItemList
& items
)
106 m_fileMetaDataWidget
->setItems(items
);
109 KFileItemList
FileMetaDataToolTip::items() const
111 return m_fileMetaDataWidget
->items();
114 void FileMetaDataToolTip::paintEvent(QPaintEvent
* event
)
116 QStylePainter
painter(this);
117 QStyleOptionFrame option
;
119 painter
.drawPrimitive(QStyle::PE_PanelTipLabel
, option
);
122 QWidget::paintEvent(event
);
125 #include "filemetadatatooltip.moc"