]>
cloud.milkyroute.net Git - dolphin.git/blob - src/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 m_name
->setWordWrap(true);
48 QFont font
= m_name
->font();
50 m_name
->setFont(font
);
51 m_name
->setAlignment(Qt::AlignHCenter
);
52 m_name
->setSizePolicy(QSizePolicy::Expanding
, QSizePolicy::Fixed
);
54 // Create widget for the meta data
55 m_fileMetaDataWidget
= new KFileMetaDataWidget();
56 m_fileMetaDataWidget
->setForegroundRole(QPalette::ToolTipText
);
57 m_fileMetaDataWidget
->setSizePolicy(QSizePolicy::Fixed
, QSizePolicy::Fixed
);
58 m_fileMetaDataWidget
->setReadOnly(true);
60 // The stretchwidget allows the metadata widget to be top aligned and fills
61 // the remaining vertical space
62 QWidget
* stretchWidget
= new QWidget(this);
63 stretchWidget
->setSizePolicy(QSizePolicy::Preferred
, QSizePolicy::MinimumExpanding
);
65 QWidget
* textContainer
= new QWidget(this);
66 QVBoxLayout
* textLayout
= new QVBoxLayout(textContainer
);
67 textLayout
->addWidget(m_name
);
68 textLayout
->addWidget(new KSeparator());
69 textLayout
->addWidget(m_fileMetaDataWidget
);
70 textLayout
->addWidget(stretchWidget
);
72 QHBoxLayout
* tipLayout
= new QHBoxLayout(this);
73 tipLayout
->addWidget(m_preview
);
74 tipLayout
->addWidget(textContainer
);
77 FileMetaDataToolTip::~FileMetaDataToolTip()
81 void FileMetaDataToolTip::setPreview(const QPixmap
& pixmap
)
83 m_preview
->setPixmap(pixmap
);
84 m_preview
->setFixedSize(pixmap
.size());
87 const QPixmap
* FileMetaDataToolTip::preview() const
89 return m_preview
->pixmap();
92 void FileMetaDataToolTip::setName(const QString
& name
)
94 m_name
->setText(name
);
97 QString
FileMetaDataToolTip::name() const
99 return m_name
->text();
102 void FileMetaDataToolTip::setItems(const KFileItemList
& items
)
104 m_fileMetaDataWidget
->setItems(items
);
107 KFileItemList
FileMetaDataToolTip::items() const
109 return m_fileMetaDataWidget
->items();
112 void FileMetaDataToolTip::paintEvent(QPaintEvent
* event
)
116 QPainter
painter(this);
118 QColor toColor
= palette().brush(QPalette::ToolTipBase
).color();
119 QColor fromColor
= KColorScheme::shade(toColor
, KColorScheme::LightShade
, 0.2);
121 const bool haveAlphaChannel
= KWindowSystem::compositingActive();
122 if (haveAlphaChannel
) {
123 painter
.setRenderHint(QPainter::Antialiasing
);
124 painter
.translate(0.5, 0.5);
125 toColor
.setAlpha(220);
126 fromColor
.setAlpha(220);
129 QLinearGradient
gradient(QPointF(0.0, 0.0), QPointF(0.0, height()));
130 gradient
.setColorAt(0.0, fromColor
);
131 gradient
.setColorAt(1.0, toColor
);
132 painter
.setPen(Qt::NoPen
);
133 painter
.setBrush(gradient
);
135 const QRect
rect(0, 0, width(), height());
136 if (haveAlphaChannel
) {
137 const qreal radius
= 5.0;
140 path
.moveTo(rect
.left(), rect
.top() + radius
);
141 arc(path
, rect
.left() + radius
, rect
.top() + radius
, radius
, 180, -90);
142 arc(path
, rect
.right() - radius
, rect
.top() + radius
, radius
, 90, -90);
143 arc(path
, rect
.right() - radius
, rect
.bottom() - radius
, radius
, 0, -90);
144 arc(path
, rect
.left() + radius
, rect
.bottom() - radius
, radius
, 270, -90);
147 painter
.drawPath(path
);
149 painter
.drawRect(rect
);
153 void FileMetaDataToolTip::arc(QPainterPath
& path
,
155 qreal radius
, qreal angle
,
158 path
.arcTo(cx
-radius
, cy
-radius
, radius
* 2, radius
* 2, angle
, sweepLength
);
161 #include "filemetadatatooltip.moc"