1
/* This file is part of the KDE projects
2
Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
3
Copyright (C) 2000, 2001, 2002 David Faure <david@mandrakesoft.com>
4
Copyright (C) 2004 Martin Koller <m.koller@surfeu.at>
6
This program is free software; you can redistribute it and/or
7
modify it under the terms of the GNU General Public
8
License as published by the Free Software Foundation; either
9
version 2 of the License, or (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 GNU
14
General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; see the file COPYING. If not, write to
18
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
Boston, MA 02110-1301, USA.
22
#include <konq_filetip.h>
24
#include <kfileitem.h>
25
#include <kglobalsettings.h>
26
#include <kstandarddirs.h>
27
#include <kapplication.h>
33
#include <qscrollview.h>
37
//--------------------------------------------------------------------------------
39
KonqFileTip::KonqFileTip( QScrollView* parent )
40
: QFrame( 0, 0, WStyle_Customize | WStyle_NoBorder | WStyle_Tool | WStyle_StaysOnTop | WX11BypassWM ),
50
m_iconLabel = new QLabel(this);
51
m_textLabel = new QLabel(this);
52
m_textLabel->setAlignment(Qt::AlignAuto | Qt::AlignTop);
54
QGridLayout* layout = new QGridLayout(this, 1, 2, 8, 0);
55
layout->addWidget(m_iconLabel, 0, 0);
56
layout->addWidget(m_textLabel, 0, 1);
57
layout->setResizeMode(QLayout::Fixed);
59
setPalette( QToolTip::palette() );
61
setFrameStyle( QFrame::Plain | QFrame::Box );
63
m_timer = new QTimer(this);
68
KonqFileTip::~KonqFileTip()
76
void KonqFileTip::setPreview(bool on)
85
void KonqFileTip::setOptions( bool on, bool preview, int num )
92
void KonqFileTip::setItem( KFileItem *item, const QRect &rect, const QPixmap *pixmap )
109
m_iconLabel->setPixmap( *pixmap );
111
m_iconLabel->setPixmap( QPixmap() );
114
// Don't start immediately, because the user could move the mouse over another item
115
// This avoids a quick sequence of started preview-jobs
116
m_timer->disconnect( this );
117
connect(m_timer, SIGNAL(timeout()), this, SLOT(startDelayed()));
118
m_timer->start( 300, true );
122
void KonqFileTip::reposition()
124
if ( m_rect.isEmpty() || !m_view || !m_view->viewport() ) return;
127
QPoint off = m_view->viewport()->mapToGlobal( m_view->contentsToViewport( rect.topRight() ) );
128
rect.moveTopRight( off );
130
QPoint pos = rect.center();
138
// should the tooltip be shown to the left or to the right of the ivi ?
139
QRect desk = KGlobalSettings::desktopGeometry(rect.center());
140
if (rect.center().x() + width() > desk.right())
143
if (pos.x() - width() < 0) {
147
pos.setX( pos.x() - width() );
151
// should the tooltip be shown above or below the ivi ?
152
if (rect.bottom() + height() > desk.bottom())
155
pos.setY( rect.top() - height() );
158
else pos.setY( rect.bottom() + 1 );
164
void KonqFileTip::gotPreview( const KFileItem* item, const QPixmap& pixmap )
167
if (item != m_item) return;
169
m_iconLabel -> setPixmap(pixmap);
172
void KonqFileTip::gotPreviewResult()
177
void KonqFileTip::drawContents( QPainter *p )
179
static const char * const names[] = {
186
if (m_corner >= 4) { // 4 is empty, so don't draw anything
187
QFrame::drawContents( p );
191
if ( m_corners[m_corner].isNull())
192
m_corners[m_corner].load( locate( "data", QString::fromLatin1( "konqueror/pics/%1.png" ).arg( names[m_corner] ) ) );
194
QPixmap &pix = m_corners[m_corner];
199
p->drawPixmap( 3, 3, pix );
202
p->drawPixmap( width() - pix.width() - 3, 3, pix );
205
p->drawPixmap( 3, height() - pix.height() - 3, pix );
208
p->drawPixmap( width() - pix.width() - 3, height() - pix.height() - 3, pix );
212
QFrame::drawContents( p );
215
void KonqFileTip::setFilter( bool enable )
217
if ( enable == m_filter ) return;
220
kapp->installEventFilter( this );
221
QApplication::setGlobalMouseTracking( true );
224
QApplication::setGlobalMouseTracking( false );
225
kapp->removeEventFilter( this );
230
void KonqFileTip::showTip()
232
QString text = m_item->getToolTipText(m_num);
234
if ( text.isEmpty() ) return;
236
m_timer->disconnect( this );
237
connect(m_timer, SIGNAL(timeout()), this, SLOT(hideTip()));
238
m_timer->start( 15000, true );
240
m_textLabel->setText( text );
248
void KonqFileTip::hideTip()
252
if ( isShown() && m_view && m_view->viewport() &&
253
(m_view->horizontalScrollBar()->isShown() || m_view->verticalScrollBar()->isShown()) )
254
m_view->viewport()->update();
257
void KonqFileTip::startDelayed()
260
KFileItemList oneItem;
261
oneItem.append( m_item );
263
m_previewJob = KIO::filePreview( oneItem, 256, 256, 64, 70, true, true, 0);
264
connect( m_previewJob, SIGNAL( gotPreview( const KFileItem *, const QPixmap & ) ),
265
this, SLOT( gotPreview( const KFileItem *, const QPixmap & ) ) );
266
connect( m_previewJob, SIGNAL( result( KIO::Job * ) ),
267
this, SLOT( gotPreviewResult() ) );
270
m_timer->disconnect( this );
271
connect(m_timer, SIGNAL(timeout()), this, SLOT(showTip()));
272
m_timer->start( 400, true );
275
void KonqFileTip::resizeEvent( QResizeEvent* event )
277
QFrame::resizeEvent(event);
281
bool KonqFileTip::eventFilter( QObject *, QEvent *e )
286
case QEvent::MouseButtonPress:
287
case QEvent::MouseButtonRelease:
288
case QEvent::KeyPress:
289
case QEvent::KeyRelease:
290
case QEvent::FocusIn:
291
case QEvent::FocusOut:
300
#include "konq_filetip.moc"