You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
301 lines
7.7 KiB
301 lines
7.7 KiB
15 years ago
|
/* This file is part of the KDE projects
|
||
|
Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
|
||
|
Copyright (C) 2000, 2001, 2002 David Faure <david@mandrakesoft.com>
|
||
|
Copyright (C) 2004 Martin Koller <m.koller@surfeu.at>
|
||
|
|
||
|
This program is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This program is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU General Public License
|
||
|
along with this program; see the file COPYING. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include <konq_filetip.h>
|
||
|
|
||
12 years ago
|
#include <tdefileitem.h>
|
||
12 years ago
|
#include <tdeglobalsettings.h>
|
||
15 years ago
|
#include <kstandarddirs.h>
|
||
12 years ago
|
#include <tdeapplication.h>
|
||
15 years ago
|
|
||
15 years ago
|
#include <tqlabel.h>
|
||
|
#include <tqtooltip.h>
|
||
13 years ago
|
#include <tqlayout.h>
|
||
15 years ago
|
#include <tqpainter.h>
|
||
|
#include <tqscrollview.h>
|
||
|
#include <tqtimer.h>
|
||
15 years ago
|
|
||
|
#include <fixx11h.h>
|
||
|
//--------------------------------------------------------------------------------
|
||
|
|
||
15 years ago
|
KonqFileTip::KonqFileTip( TQScrollView* parent )
|
||
14 years ago
|
: TQFrame( 0, 0, (WFlags)(WStyle_Customize | WStyle_NoBorder | WStyle_Tool | WStyle_StaysOnTop | WX11BypassWM) ),
|
||
15 years ago
|
m_on( false ),
|
||
|
m_preview( false ),
|
||
|
m_filter( false ),
|
||
|
m_corner( 0 ),
|
||
|
m_num( 0 ),
|
||
|
m_view( parent ),
|
||
|
m_item( 0 ),
|
||
|
m_previewJob( 0 )
|
||
|
{
|
||
15 years ago
|
m_iconLabel = new TQLabel(this);
|
||
|
m_textLabel = new TQLabel(this);
|
||
13 years ago
|
m_textLabel->setAlignment(TQt::AlignAuto | TQt::AlignTop);
|
||
15 years ago
|
|
||
14 years ago
|
TQGridLayout* layout = new TQGridLayout(this, 1, 2, 8, 0);
|
||
|
layout->addWidget(m_iconLabel, 0, 0);
|
||
|
layout->addWidget(m_textLabel, 0, 1);
|
||
|
layout->setResizeMode(TQLayout::Fixed);
|
||
15 years ago
|
|
||
15 years ago
|
setPalette( TQToolTip::palette() );
|
||
15 years ago
|
setMargin( 1 );
|
||
15 years ago
|
setFrameStyle( TQFrame::Plain | TQFrame::Box );
|
||
15 years ago
|
|
||
15 years ago
|
m_timer = new TQTimer(this);
|
||
15 years ago
|
|
||
|
hide();
|
||
|
}
|
||
|
|
||
|
KonqFileTip::~KonqFileTip()
|
||
|
{
|
||
|
if ( m_previewJob ) {
|
||
|
m_previewJob->kill();
|
||
|
m_previewJob = 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KonqFileTip::setPreview(bool on)
|
||
|
{
|
||
|
m_preview = on;
|
||
|
if(on)
|
||
|
m_iconLabel->show();
|
||
|
else
|
||
|
m_iconLabel->hide();
|
||
|
}
|
||
|
|
||
|
void KonqFileTip::setOptions( bool on, bool preview, int num )
|
||
|
{
|
||
|
setPreview(preview);
|
||
|
m_on = on;
|
||
|
m_num = num;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KonqFileTip::setItem( KFileItem *item, const TQRect &rect, const TQPixmap *pixmap )
|
||
15 years ago
|
{
|
||
|
hideTip();
|
||
|
|
||
|
if (!m_on) return;
|
||
|
|
||
|
if ( m_previewJob ) {
|
||
|
m_previewJob->kill();
|
||
|
m_previewJob = 0;
|
||
|
}
|
||
|
|
||
|
m_rect = rect;
|
||
|
m_item = item;
|
||
|
|
||
|
if ( m_item ) {
|
||
|
if (m_preview) {
|
||
|
if ( pixmap )
|
||
|
m_iconLabel->setPixmap( *pixmap );
|
||
|
else
|
||
15 years ago
|
m_iconLabel->setPixmap( TQPixmap() );
|
||
15 years ago
|
}
|
||
|
|
||
|
// Don't start immediately, because the user could move the mouse over another item
|
||
|
// This avoids a quick sequence of started preview-jobs
|
||
|
m_timer->disconnect( this );
|
||
15 years ago
|
connect(m_timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(startDelayed()));
|
||
15 years ago
|
m_timer->start( 300, true );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KonqFileTip::reposition()
|
||
|
{
|
||
|
if ( m_rect.isEmpty() || !m_view || !m_view->viewport() ) return;
|
||
|
|
||
15 years ago
|
TQRect rect = m_rect;
|
||
|
TQPoint off = m_view->viewport()->mapToGlobal( m_view->contentsToViewport( rect.topRight() ) );
|
||
15 years ago
|
rect.moveTopRight( off );
|
||
|
|
||
15 years ago
|
TQPoint pos = rect.center();
|
||
15 years ago
|
// m_corner:
|
||
|
// 0: upperleft
|
||
|
// 1: upperright
|
||
|
// 2: lowerleft
|
||
|
// 3: lowerright
|
||
|
// 4+: none
|
||
|
m_corner = 0;
|
||
|
// should the tooltip be shown to the left or to the right of the ivi ?
|
||
12 years ago
|
TQRect desk = TDEGlobalSettings::desktopGeometry(rect.center());
|
||
15 years ago
|
if (rect.center().x() + width() > desk.right())
|
||
|
{
|
||
|
// to the left
|
||
|
if (pos.x() - width() < 0) {
|
||
|
pos.setX(0);
|
||
|
m_corner = 4;
|
||
|
} else {
|
||
|
pos.setX( pos.x() - width() );
|
||
|
m_corner = 1;
|
||
|
}
|
||
|
}
|
||
|
// should the tooltip be shown above or below the ivi ?
|
||
|
if (rect.bottom() + height() > desk.bottom())
|
||
|
{
|
||
|
// above
|
||
|
pos.setY( rect.top() - height() );
|
||
|
m_corner += 2;
|
||
|
}
|
||
|
else pos.setY( rect.bottom() + 1 );
|
||
|
|
||
|
move( pos );
|
||
|
update();
|
||
|
}
|
||
|
|
||
15 years ago
|
void KonqFileTip::gotPreview( const KFileItem* item, const TQPixmap& pixmap )
|
||
15 years ago
|
{
|
||
|
m_previewJob = 0;
|
||
|
if (item != m_item) return;
|
||
|
|
||
|
m_iconLabel -> setPixmap(pixmap);
|
||
|
}
|
||
|
|
||
|
void KonqFileTip::gotPreviewResult()
|
||
|
{
|
||
|
m_previewJob = 0;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KonqFileTip::drawContents( TQPainter *p )
|
||
15 years ago
|
{
|
||
|
static const char * const names[] = {
|
||
|
"arrow_topleft",
|
||
|
"arrow_topright",
|
||
|
"arrow_bottomleft",
|
||
|
"arrow_bottomright"
|
||
|
};
|
||
|
|
||
|
if (m_corner >= 4) { // 4 is empty, so don't draw anything
|
||
15 years ago
|
TQFrame::drawContents( p );
|
||
15 years ago
|
return;
|
||
|
}
|
||
|
|
||
|
if ( m_corners[m_corner].isNull())
|
||
13 years ago
|
m_corners[m_corner].load( locate( "data", TQString::fromLatin1( "konqueror/pics/%1.png" ).arg( names[m_corner] ) ) );
|
||
15 years ago
|
|
||
15 years ago
|
TQPixmap &pix = m_corners[m_corner];
|
||
15 years ago
|
|
||
|
switch ( m_corner )
|
||
|
{
|
||
|
case 0:
|
||
|
p->drawPixmap( 3, 3, pix );
|
||
|
break;
|
||
|
case 1:
|
||
|
p->drawPixmap( width() - pix.width() - 3, 3, pix );
|
||
|
break;
|
||
|
case 2:
|
||
|
p->drawPixmap( 3, height() - pix.height() - 3, pix );
|
||
|
break;
|
||
|
case 3:
|
||
|
p->drawPixmap( width() - pix.width() - 3, height() - pix.height() - 3, pix );
|
||
|
break;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQFrame::drawContents( p );
|
||
15 years ago
|
}
|
||
|
|
||
|
void KonqFileTip::setFilter( bool enable )
|
||
|
{
|
||
|
if ( enable == m_filter ) return;
|
||
|
|
||
|
if ( enable ) {
|
||
|
kapp->installEventFilter( this );
|
||
15 years ago
|
TQApplication::setGlobalMouseTracking( true );
|
||
15 years ago
|
}
|
||
|
else {
|
||
15 years ago
|
TQApplication::setGlobalMouseTracking( false );
|
||
15 years ago
|
kapp->removeEventFilter( this );
|
||
|
}
|
||
|
m_filter = enable;
|
||
|
}
|
||
|
|
||
|
void KonqFileTip::showTip()
|
||
|
{
|
||
15 years ago
|
TQString text = m_item->getToolTipText(m_num);
|
||
15 years ago
|
|
||
|
if ( text.isEmpty() ) return;
|
||
|
|
||
|
m_timer->disconnect( this );
|
||
15 years ago
|
connect(m_timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(hideTip()));
|
||
15 years ago
|
m_timer->start( 15000, true );
|
||
|
|
||
|
m_textLabel->setText( text );
|
||
|
|
||
|
setFilter( true );
|
||
|
|
||
|
reposition();
|
||
|
show();
|
||
|
}
|
||
|
|
||
|
void KonqFileTip::hideTip()
|
||
|
{
|
||
|
m_timer->stop();
|
||
|
setFilter( false );
|
||
|
if ( isShown() && m_view && m_view->viewport() &&
|
||
|
(m_view->horizontalScrollBar()->isShown() || m_view->verticalScrollBar()->isShown()) )
|
||
|
m_view->viewport()->update();
|
||
|
hide();
|
||
|
}
|
||
|
void KonqFileTip::startDelayed()
|
||
|
{
|
||
|
if ( m_preview ) {
|
||
|
KFileItemList oneItem;
|
||
|
oneItem.append( m_item );
|
||
|
|
||
12 years ago
|
m_previewJob = TDEIO::filePreview( oneItem, 256, 256, 64, 70, true, true, 0);
|
||
15 years ago
|
connect( m_previewJob, TQT_SIGNAL( gotPreview( const KFileItem *, const TQPixmap & ) ),
|
||
|
this, TQT_SLOT( gotPreview( const KFileItem *, const TQPixmap & ) ) );
|
||
12 years ago
|
connect( m_previewJob, TQT_SIGNAL( result( TDEIO::Job * ) ),
|
||
15 years ago
|
this, TQT_SLOT( gotPreviewResult() ) );
|
||
15 years ago
|
}
|
||
|
|
||
|
m_timer->disconnect( this );
|
||
15 years ago
|
connect(m_timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(showTip()));
|
||
15 years ago
|
m_timer->start( 400, true );
|
||
|
}
|
||
|
|
||
15 years ago
|
void KonqFileTip::resizeEvent( TQResizeEvent* event )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQFrame::resizeEvent(event);
|
||
15 years ago
|
reposition();
|
||
|
}
|
||
|
|
||
15 years ago
|
bool KonqFileTip::eventFilter( TQObject *, TQEvent *e )
|
||
15 years ago
|
{
|
||
|
switch ( e->type() )
|
||
|
{
|
||
15 years ago
|
case TQEvent::Leave:
|
||
|
case TQEvent::MouseButtonPress:
|
||
|
case TQEvent::MouseButtonRelease:
|
||
|
case TQEvent::KeyPress:
|
||
|
case TQEvent::KeyRelease:
|
||
|
case TQEvent::FocusIn:
|
||
|
case TQEvent::FocusOut:
|
||
|
case TQEvent::Wheel:
|
||
15 years ago
|
hideTip();
|
||
|
default: break;
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
#include "konq_filetip.moc"
|