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.
150 lines
3.2 KiB
150 lines
3.2 KiB
15 years ago
|
/*
|
||
|
* khexedit - Versatile hex editor
|
||
|
* Copyright (C) 1999-2000 Espen Sand, espensa@online.no
|
||
|
*
|
||
|
* 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; if not, write to the Free Software
|
||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
#include <stdlib.h>
|
||
|
|
||
14 years ago
|
#include <tqbitmap.h>
|
||
|
#include <tqpainter.h>
|
||
15 years ago
|
|
||
|
#include <kurldrag.h>
|
||
|
|
||
|
#include "draglabel.h"
|
||
|
|
||
|
|
||
13 years ago
|
CDragLabel::CDragLabel( TQWidget *parent )
|
||
10 years ago
|
: TQLabel( "draglabel", parent, "tde toolbar widget" )
|
||
15 years ago
|
{
|
||
|
mValid = true;
|
||
|
mDragPending = false;
|
||
14 years ago
|
setBackgroundMode( TQt::PaletteButton );
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
|
CDragLabel::~CDragLabel( void )
|
||
|
{
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void CDragLabel::mousePressEvent( TQMouseEvent *e )
|
||
15 years ago
|
{
|
||
14 years ago
|
if( mValid == false || e->button() != Qt::LeftButton || mUrl.isEmpty() == true )
|
||
15 years ago
|
{
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
mDragOrigin = e->pos();
|
||
|
mDragPending = true;
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void CDragLabel::mouseMoveEvent( TQMouseEvent *e )
|
||
15 years ago
|
{
|
||
|
if( mDragPending == true )
|
||
|
{
|
||
|
if( abs(e->x() - mDragOrigin.x()) + abs(e->y() - mDragOrigin.y()) > 5 )
|
||
|
{
|
||
|
mDragPending = false;
|
||
|
|
||
|
//
|
||
|
// Make drag object, assign pixmap and grab keyboard. The grabbing
|
||
|
// will allow ESC to abort the drag
|
||
|
//
|
||
|
KURL::List uris;
|
||
|
uris.append(KURL(mUrl));
|
||
|
KURLDrag *uriDrag = new KURLDrag( uris, this );
|
||
|
if( uriDrag == 0 ) { return; }
|
||
|
prepPixmap( *uriDrag );
|
||
|
grabKeyboard();
|
||
|
uriDrag->drag();
|
||
|
releaseKeyboard();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
void CDragLabel::mouseReleaseEvent( TQMouseEvent * )
|
||
15 years ago
|
{
|
||
|
mDragPending = false;
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void CDragLabel::setUrl( const TQString &url )
|
||
15 years ago
|
{
|
||
|
mUrl = url;
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void CDragLabel::setDragMask( const TQPixmap pix )
|
||
15 years ago
|
{
|
||
|
mDragMask = pix;
|
||
|
}
|
||
|
|
||
|
|
||
|
void CDragLabel::prepPixmap( KURLDrag &uriDrag )
|
||
|
{
|
||
|
if( pixmap() == 0 )
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString text;
|
||
13 years ago
|
int index = mUrl.findRev( '/', mUrl.length() );
|
||
15 years ago
|
if( index < 0 )
|
||
|
{
|
||
|
text = mUrl;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
text = mUrl.right( mUrl.length() - index - 1 );
|
||
|
}
|
||
|
|
||
|
int sep = 2;
|
||
14 years ago
|
TQRect rect = fontMetrics().boundingRect(text);
|
||
15 years ago
|
int w = pixmap()->width() + rect.width() + sep + 2;
|
||
|
int h = fontMetrics().lineSpacing();
|
||
|
if( pixmap()->height() > h ) { h = pixmap()->height(); }
|
||
|
|
||
13 years ago
|
TQBitmap mask( w, h, TRUE );
|
||
14 years ago
|
TQPixmap dragPixmap( w, h );
|
||
15 years ago
|
dragPixmap.fill( black );
|
||
|
|
||
14 years ago
|
TQPainter p;
|
||
13 years ago
|
p.begin( &mask );
|
||
15 years ago
|
p.setPen( white );
|
||
|
p.drawPixmap( 0, 0, mDragMask );
|
||
|
p.drawText( pixmap()->width()+sep, 0, w-pixmap()->width()+sep,
|
||
|
h, AlignVCenter|AlignLeft, text );
|
||
|
p.end();
|
||
|
|
||
|
p.begin( &dragPixmap );
|
||
|
p.drawPixmap( 0, 0, *pixmap() );
|
||
|
p.end();
|
||
|
|
||
13 years ago
|
dragPixmap.setMask( mask );
|
||
15 years ago
|
|
||
14 years ago
|
TQPoint hotspot( pixmap()->width(), pixmap()->height()/2 );
|
||
15 years ago
|
uriDrag.setPixmap( dragPixmap, hotspot );
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
#include "draglabel.moc"
|