22 #include <konq_filetip.h>
24 #include <tdefileitem.h>
25 #include <tdeglobalsettings.h>
26 #include <kstandarddirs.h>
27 #include <tdeapplication.h>
30 #include <tqtooltip.h>
32 #include <tqpainter.h>
33 #include <tqscrollview.h>
39 KonqFileTip::KonqFileTip( TQScrollView* parent )
40 : TQFrame( 0, 0, (WFlags)(WStyle_Customize | WStyle_NoBorder | WStyle_Tool | WStyle_StaysOnTop | WX11BypassWM) ),
50 m_iconLabel =
new TQLabel(
this);
51 m_textLabel =
new TQLabel(
this);
52 m_textLabel->setAlignment(TQt::AlignAuto | TQt::AlignTop);
54 TQGridLayout* layout =
new TQGridLayout(
this, 1, 2, 8, 0);
55 layout->addWidget(m_iconLabel, 0, 0);
56 layout->addWidget(m_textLabel, 0, 1);
57 layout->setResizeMode(TQLayout::Fixed);
59 setPalette( TQToolTip::palette() );
61 setFrameStyle( TQFrame::Plain | TQFrame::Box );
63 m_timer =
new TQTimer(
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 TQRect &rect,
const TQPixmap *pixmap )
109 m_iconLabel->setPixmap( *pixmap );
111 m_iconLabel->setPixmap( TQPixmap() );
116 m_timer->disconnect(
this );
117 connect(m_timer, TQ_SIGNAL(timeout()),
this, TQ_SLOT(startDelayed()));
118 m_timer->start( 300,
true );
122 void KonqFileTip::reposition()
124 if ( m_rect.isEmpty() || !m_view || !m_view->viewport() )
return;
126 TQRect rect = m_rect;
127 TQPoint off = m_view->viewport()->mapToGlobal( m_view->contentsToViewport( rect.topRight() ) );
128 rect.moveTopRight( off );
130 TQPoint pos = rect.center();
139 TQRect desk = TDEGlobalSettings::desktopGeometry(rect.center());
140 if (rect.center().x() + width() > desk.right())
143 if (pos.x() - width() < 0) {
147 pos.setX( pos.x() - width() );
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 TQPixmap& pixmap )
167 if (item != m_item)
return;
169 m_iconLabel -> setPixmap(pixmap);
172 void KonqFileTip::gotPreviewResult()
177 void KonqFileTip::drawContents( TQPainter *p )
179 static const char *
const names[] = {
187 TQFrame::drawContents( p );
191 if ( m_corners[m_corner].isNull())
192 m_corners[m_corner].load( locate(
"data", TQString::fromLatin1(
"konqueror/pics/%1.png" ).arg( names[m_corner] ) ) );
194 TQPixmap &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 TQFrame::drawContents( p );
215 void KonqFileTip::setFilter(
bool enable )
217 if ( enable == m_filter )
return;
220 kapp->installEventFilter(
this );
221 TQApplication::setGlobalMouseTracking(
true );
224 TQApplication::setGlobalMouseTracking(
false );
225 kapp->removeEventFilter(
this );
230 void KonqFileTip::showTip()
232 TQString text = m_item->getToolTipText(m_num);
234 if ( text.isEmpty() )
return;
236 m_timer->disconnect(
this );
237 connect(m_timer, TQ_SIGNAL(timeout()),
this, TQ_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 = TDEIO::filePreview( oneItem, 256, 256, 64, 70,
true,
true, 0);
264 connect( m_previewJob, TQ_SIGNAL( gotPreview(
const KFileItem *,
const TQPixmap & ) ),
265 this, TQ_SLOT( gotPreview(
const KFileItem *,
const TQPixmap & ) ) );
266 connect( m_previewJob, TQ_SIGNAL( result( TDEIO::Job * ) ),
267 this, TQ_SLOT( gotPreviewResult() ) );
270 m_timer->disconnect(
this );
271 connect(m_timer, TQ_SIGNAL(timeout()),
this, TQ_SLOT(showTip()));
272 m_timer->start( 400,
true );
275 void KonqFileTip::resizeEvent( TQResizeEvent* event )
277 TQFrame::resizeEvent(event);
281 bool KonqFileTip::eventFilter( TQObject *, TQEvent *e )
286 case TQEvent::MouseButtonPress:
287 case TQEvent::MouseButtonRelease:
288 case TQEvent::KeyPress:
289 case TQEvent::KeyRelease:
290 case TQEvent::FocusIn:
291 case TQEvent::FocusOut:
300 #include "konq_filetip.moc"