]>
cloud.milkyroute.net Git - dolphin.git/blob - src/views/tooltips/filemetadatatooltip.cpp
1 /***************************************************************************
2 * Copyright (C) 2010 by Peter Penz <peter.penz@gmx.at> *
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.h>
24 #include <kfilemetadatawidget.h>
25 #include <kseparator.h>
26 #include <kwindowsystem.h>
30 #include <QVBoxLayout>
32 FileMetaDataToolTip::FileMetaDataToolTip(QWidget
* parent
) :
36 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);
45 // Create widget for file name
46 m_name
= new QLabel(this);
47 QFont font
= m_name
->font();
49 m_name
->setFont(font
);
50 m_name
->setAlignment(Qt::AlignHCenter
);
52 // Create widget for the meta data
53 m_fileMetaDataWidget
= new KFileMetaDataWidget();
54 m_fileMetaDataWidget
->setForegroundRole(QPalette::ToolTipText
);
55 m_fileMetaDataWidget
->setReadOnly(true);
57 // The stretchwidget allows the metadata widget to be top aligned and fills
58 // the remaining vertical space
59 QWidget
* stretchWidget
= new QWidget(this);
60 stretchWidget
->setSizePolicy(QSizePolicy::Preferred
, QSizePolicy::MinimumExpanding
);
62 QWidget
* textContainer
= new QWidget(this);
63 QVBoxLayout
* textLayout
= new QVBoxLayout(textContainer
);
64 textLayout
->addWidget(m_name
);
65 textLayout
->addWidget(new KSeparator());
66 textLayout
->addWidget(m_fileMetaDataWidget
);
67 textLayout
->addWidget(stretchWidget
);
69 QHBoxLayout
* tipLayout
= new QHBoxLayout(this);
70 tipLayout
->addWidget(m_preview
);
71 tipLayout
->addWidget(textContainer
);
73 tipLayout
->setSizeConstraint(QLayout::SetFixedSize
);
76 FileMetaDataToolTip::~FileMetaDataToolTip()
80 void FileMetaDataToolTip::setPreview(const QPixmap
& pixmap
)
82 m_preview
->setPixmap(pixmap
);
85 const QPixmap
* FileMetaDataToolTip::preview() const
87 return m_preview
->pixmap();
90 void FileMetaDataToolTip::setName(const QString
& name
)
92 m_name
->setText(name
);
95 QString
FileMetaDataToolTip::name() const
97 return m_name
->text();
100 void FileMetaDataToolTip::setItems(const KFileItemList
& items
)
102 m_fileMetaDataWidget
->setItems(items
);
105 KFileItemList
FileMetaDataToolTip::items() const
107 return m_fileMetaDataWidget
->items();
110 void FileMetaDataToolTip::paintEvent(QPaintEvent
* event
)
114 QPainter
painter(this);
116 QColor toColor
= palette().brush(QPalette::ToolTipBase
).color();
117 QColor fromColor
= KColorScheme::shade(toColor
, KColorScheme::LightShade
, 0.2);
119 const bool haveAlphaChannel
= KWindowSystem::compositingActive();
120 if (haveAlphaChannel
) {
121 painter
.setRenderHint(QPainter::Antialiasing
);
122 painter
.translate(0.5, 0.5);
123 toColor
.setAlpha(220);
124 fromColor
.setAlpha(220);
127 QLinearGradient
gradient(QPointF(0.0, 0.0), QPointF(0.0, height()));
128 gradient
.setColorAt(0.0, fromColor
);
129 gradient
.setColorAt(1.0, toColor
);
130 painter
.setPen(Qt::NoPen
);
131 painter
.setBrush(gradient
);
133 const QRect
rect(0, 0, width(), height());
134 if (haveAlphaChannel
) {
135 const qreal radius
= 5.0;
138 path
.moveTo(rect
.left(), rect
.top() + radius
);
139 arc(path
, rect
.left() + radius
, rect
.top() + radius
, radius
, 180, -90);
140 arc(path
, rect
.right() - radius
, rect
.top() + radius
, radius
, 90, -90);
141 arc(path
, rect
.right() - radius
, rect
.bottom() - radius
, radius
, 0, -90);
142 arc(path
, rect
.left() + radius
, rect
.bottom() - radius
, radius
, 270, -90);
145 painter
.drawPath(path
);
147 painter
.drawRect(rect
);
151 void FileMetaDataToolTip::arc(QPainterPath
& path
,
153 qreal radius
, qreal angle
,
156 path
.arcTo(cx
-radius
, cy
-radius
, radius
* 2, radius
* 2, angle
, sweepLength
);
159 #include "filemetadatatooltip.moc"