• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • libkonq
 

libkonq

  • libkonq
konq_filetip.cpp
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>
5 
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.
10 
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.
15 
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.
20 */
21 
22 #include <konq_filetip.h>
23 
24 #include <tdefileitem.h>
25 #include <tdeglobalsettings.h>
26 #include <kstandarddirs.h>
27 #include <tdeapplication.h>
28 
29 #include <tqlabel.h>
30 #include <tqtooltip.h>
31 #include <tqlayout.h>
32 #include <tqpainter.h>
33 #include <tqscrollview.h>
34 #include <tqtimer.h>
35 
36 #include <fixx11h.h>
37 //--------------------------------------------------------------------------------
38 
39 KonqFileTip::KonqFileTip( TQScrollView* parent )
40  : TQFrame( 0, 0, (WFlags)(WStyle_Customize | WStyle_NoBorder | WStyle_Tool | WStyle_StaysOnTop | WX11BypassWM) ),
41  m_on( false ),
42  m_preview( false ),
43  m_filter( false ),
44  m_corner( 0 ),
45  m_num( 0 ),
46  m_view( parent ),
47  m_item( 0 ),
48  m_previewJob( 0 )
49 {
50  m_iconLabel = new TQLabel(this);
51  m_textLabel = new TQLabel(this);
52  m_textLabel->setAlignment(TQt::AlignAuto | TQt::AlignTop);
53 
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);
58 
59  setPalette( TQToolTip::palette() );
60  setMargin( 1 );
61  setFrameStyle( TQFrame::Plain | TQFrame::Box );
62 
63  m_timer = new TQTimer(this);
64 
65  hide();
66 }
67 
68 KonqFileTip::~KonqFileTip()
69 {
70  if ( m_previewJob ) {
71  m_previewJob->kill();
72  m_previewJob = 0;
73  }
74 }
75 
76 void KonqFileTip::setPreview(bool on)
77 {
78  m_preview = on;
79  if(on)
80  m_iconLabel->show();
81  else
82  m_iconLabel->hide();
83 }
84 
85 void KonqFileTip::setOptions( bool on, bool preview, int num )
86 {
87  setPreview(preview);
88  m_on = on;
89  m_num = num;
90 }
91 
92 void KonqFileTip::setItem( KFileItem *item, const TQRect &rect, const TQPixmap *pixmap )
93 {
94  hideTip();
95 
96  if (!m_on) return;
97 
98  if ( m_previewJob ) {
99  m_previewJob->kill();
100  m_previewJob = 0;
101  }
102 
103  m_rect = rect;
104  m_item = item;
105 
106  if ( m_item ) {
107  if (m_preview) {
108  if ( pixmap )
109  m_iconLabel->setPixmap( *pixmap );
110  else
111  m_iconLabel->setPixmap( TQPixmap() );
112  }
113 
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, TQ_SIGNAL(timeout()), this, TQ_SLOT(startDelayed()));
118  m_timer->start( 300, true );
119  }
120 }
121 
122 void KonqFileTip::reposition()
123 {
124  if ( m_rect.isEmpty() || !m_view || !m_view->viewport() ) return;
125 
126  TQRect rect = m_rect;
127  TQPoint off = m_view->viewport()->mapToGlobal( m_view->contentsToViewport( rect.topRight() ) );
128  rect.moveTopRight( off );
129 
130  TQPoint pos = rect.center();
131  // m_corner:
132  // 0: upperleft
133  // 1: upperright
134  // 2: lowerleft
135  // 3: lowerright
136  // 4+: none
137  m_corner = 0;
138  // should the tooltip be shown to the left or to the right of the ivi ?
139  TQRect desk = TDEGlobalSettings::desktopGeometry(rect.center());
140  if (rect.center().x() + width() > desk.right())
141  {
142  // to the left
143  if (pos.x() - width() < 0) {
144  pos.setX(0);
145  m_corner = 4;
146  } else {
147  pos.setX( pos.x() - width() );
148  m_corner = 1;
149  }
150  }
151  // should the tooltip be shown above or below the ivi ?
152  if (rect.bottom() + height() > desk.bottom())
153  {
154  // above
155  pos.setY( rect.top() - height() );
156  m_corner += 2;
157  }
158  else pos.setY( rect.bottom() + 1 );
159 
160  move( pos );
161  update();
162 }
163 
164 void KonqFileTip::gotPreview( const KFileItem* item, const TQPixmap& pixmap )
165 {
166  m_previewJob = 0;
167  if (item != m_item) return;
168 
169  m_iconLabel -> setPixmap(pixmap);
170 }
171 
172 void KonqFileTip::gotPreviewResult()
173 {
174  m_previewJob = 0;
175 }
176 
177 void KonqFileTip::drawContents( TQPainter *p )
178 {
179  static const char * const names[] = {
180  "arrow_topleft",
181  "arrow_topright",
182  "arrow_bottomleft",
183  "arrow_bottomright"
184  };
185 
186  if (m_corner >= 4) { // 4 is empty, so don't draw anything
187  TQFrame::drawContents( p );
188  return;
189  }
190 
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] ) ) );
193 
194  TQPixmap &pix = m_corners[m_corner];
195 
196  switch ( m_corner )
197  {
198  case 0:
199  p->drawPixmap( 3, 3, pix );
200  break;
201  case 1:
202  p->drawPixmap( width() - pix.width() - 3, 3, pix );
203  break;
204  case 2:
205  p->drawPixmap( 3, height() - pix.height() - 3, pix );
206  break;
207  case 3:
208  p->drawPixmap( width() - pix.width() - 3, height() - pix.height() - 3, pix );
209  break;
210  }
211 
212  TQFrame::drawContents( p );
213 }
214 
215 void KonqFileTip::setFilter( bool enable )
216 {
217  if ( enable == m_filter ) return;
218 
219  if ( enable ) {
220  kapp->installEventFilter( this );
221  TQApplication::setGlobalMouseTracking( true );
222  }
223  else {
224  TQApplication::setGlobalMouseTracking( false );
225  kapp->removeEventFilter( this );
226  }
227  m_filter = enable;
228 }
229 
230 void KonqFileTip::showTip()
231 {
232  TQString text = m_item->getToolTipText(m_num);
233 
234  if ( text.isEmpty() ) return;
235 
236  m_timer->disconnect( this );
237  connect(m_timer, TQ_SIGNAL(timeout()), this, TQ_SLOT(hideTip()));
238  m_timer->start( 15000, true );
239 
240  m_textLabel->setText( text );
241 
242  setFilter( true );
243 
244  reposition();
245  show();
246 }
247 
248 void KonqFileTip::hideTip()
249 {
250  m_timer->stop();
251  setFilter( false );
252  if ( isShown() && m_view && m_view->viewport() &&
253  (m_view->horizontalScrollBar()->isShown() || m_view->verticalScrollBar()->isShown()) )
254  m_view->viewport()->update();
255  hide();
256 }
257 void KonqFileTip::startDelayed()
258 {
259  if ( m_preview ) {
260  KFileItemList oneItem;
261  oneItem.append( m_item );
262 
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() ) );
268  }
269 
270  m_timer->disconnect( this );
271  connect(m_timer, TQ_SIGNAL(timeout()), this, TQ_SLOT(showTip()));
272  m_timer->start( 400, true );
273 }
274 
275 void KonqFileTip::resizeEvent( TQResizeEvent* event )
276 {
277  TQFrame::resizeEvent(event);
278  reposition();
279 }
280 
281 bool KonqFileTip::eventFilter( TQObject *, TQEvent *e )
282 {
283  switch ( e->type() )
284  {
285  case TQEvent::Leave:
286  case TQEvent::MouseButtonPress:
287  case TQEvent::MouseButtonRelease:
288  case TQEvent::KeyPress:
289  case TQEvent::KeyRelease:
290  case TQEvent::FocusIn:
291  case TQEvent::FocusOut:
292  case TQEvent::Wheel:
293  hideTip();
294  default: break;
295  }
296 
297  return false;
298 }
299 
300 #include "konq_filetip.moc"

libkonq

Skip menu "libkonq"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

libkonq

Skip menu "libkonq"
  • kate
  • libkonq
  • twin
  •   lib
Generated for libkonq by doxygen 1.9.1
This website is maintained by Timothy Pearson.