]>
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 m_name
->setForegroundRole(QPalette::ToolTipText
);
49 QFont font
= m_name
->font();
51 m_name
->setFont(font
);
53 // Create widget for the meta data
54 m_fileMetaDataWidget
= new KFileMetaDataWidget(this);
55 m_fileMetaDataWidget
->setForegroundRole(QPalette::ToolTipText
);
56 m_fileMetaDataWidget
->setReadOnly(true);
57 connect(m_fileMetaDataWidget
, SIGNAL(metaDataRequestFinished(KFileItemList
)),
58 this, SIGNAL(metaDataRequestFinished(KFileItemList
)));
60 QVBoxLayout
* textLayout
= new QVBoxLayout();
61 textLayout
->addWidget(m_name
);
62 textLayout
->addWidget(new KSeparator());
63 textLayout
->addWidget(m_fileMetaDataWidget
);
64 textLayout
->setAlignment(m_name
, Qt::AlignCenter
);
65 textLayout
->setAlignment(m_fileMetaDataWidget
, Qt::AlignLeft
);
66 // Assure that the text-layout gets top-aligned by adding a stretch.
67 // Don't use textLayout->setAlignment(Qt::AlignTop) instead, as this does
68 // not work with the heightForWidth()-size-hint of m_fileMetaDataWidget
70 textLayout
->addStretch();
72 QHBoxLayout
* tipLayout
= new QHBoxLayout(this);
73 tipLayout
->addWidget(m_preview
);
74 tipLayout
->addSpacing(tipLayout
->margin());
75 tipLayout
->addLayout(textLayout
);
78 FileMetaDataToolTip::~FileMetaDataToolTip()
82 void FileMetaDataToolTip::setPreview(const QPixmap
& pixmap
)
84 m_preview
->setPixmap(pixmap
);
87 QPixmap
FileMetaDataToolTip::preview() const
89 if (m_preview
->pixmap()) {
90 return *m_preview
->pixmap();
95 void FileMetaDataToolTip::setName(const QString
& name
)
97 m_name
->setText(name
);
100 QString
FileMetaDataToolTip::name() const
102 return m_name
->text();
105 void FileMetaDataToolTip::setItems(const KFileItemList
& items
)
107 m_fileMetaDataWidget
->setItems(items
);
110 KFileItemList
FileMetaDataToolTip::items() const
112 return m_fileMetaDataWidget
->items();
115 void FileMetaDataToolTip::paintEvent(QPaintEvent
* event
)
117 QStylePainter
painter(this);
118 QStyleOptionFrame option
;
120 painter
.drawPrimitive(QStyle::PE_PanelTipLabel
, option
);
123 QWidget::paintEvent(event
);
126 #include "filemetadatatooltip.moc"