summaryrefslogtreecommitdiffstats
path: root/src/kerrylabel.cpp
blob: 9c850252e96aa43232134cede724c917a88cd163 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* This file is part of the KDE libraries
   Copyright (C) 1998 Kurt Granroth <granroth@kde.org>
   Copyright (C) 2000 Peter Putzer <putzer@kde.org>
   Copyright (C) 2005 Jaroslaw Staniek <js@iidea.pl>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2 as published by the Free Software Foundation.

   This library 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
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#include "kerrylabel.h"
#include "hitwidget.h"

#include <ntqdragobject.h>
#include <kglobalsettings.h>
#include <kurl.h>
#include <krun.h>
/*
#include <konq_popupmenu.h>
#include <konqbookmarkmanager.h>
#include <knewmenu.h>
*/

KerryLabel::KerryLabel (TQWidget* parent, const char* name)
  : KURLLabel (parent, name)
{
  dragInfo.state = diNone;
}

void KerryLabel::mousePressEvent(TQMouseEvent* ev)
{
  if (!url().isEmpty())
  {
    if ( ev->button() == LeftButton)
    {
      dragInfo.state = diPending;
      dragInfo.start = ev->pos();
    }
    else if (ev->button() == RightButton)
    {
        ev->accept();
        //popupMenu( mapToGlobal(ev->pos()) );
        return;
    }
  }
  KURLLabel::mousePressEvent(ev);
}

void KerryLabel::mouseMoveEvent(TQMouseEvent* ev)
{
  if (dragInfo.state == diPending) {
      int distance = KGlobalSettings::dndEventDelay();
      if ( ev->x() > dragInfo.start.x() + distance || ev->x() < dragInfo.start.x() - distance ||
           ev->y() > dragInfo.start.y() + distance || ev->y() < dragInfo.start.y() - distance) {
          doDrag();
      }
      return;
  }
  KURLLabel::mouseMoveEvent(ev);
}

void KerryLabel::mouseReleaseEvent(TQMouseEvent* ev)
{
  if ( ev->button() == LeftButton)
  {
      dragInfo.state = diNone;
  }
  KURLLabel::mouseReleaseEvent(ev);
}

void KerryLabel::doDrag()
{
  dragInfo.state = diDragging;
  const KURL kuri = KURL(url());
  dragInfo.dragObject = new TQTextDrag("'"+kuri.url().replace("file://",TQString::null)+"'", this);
  dragInfo.dragObject->dragCopy();
  // Don't delete the TQTextDrag object.  TQt will delete it when it's done with it.
}

// void KerryLabel::popupMenu( const TQPoint &_global )
// {
//     KFileItem item( ((HitWidget*)parent())->uri(),((HitWidget*)parent())->mimetype(),KFileItem::Unknown);
//     KFileItemList _items;
//     _items.append( &item );
// 
//     const KURL kurl(url());
//     KActionCollection act(this);
// 
//     KonqPopupMenu * popupMenu = new KonqPopupMenu( KonqBookmarkManager::self(), _items,
//                                                    kurl, act, (KNewMenu*)NULL, this,
//                                                    item.isLocalFile() ? KonqPopupMenu::ShowProperties : KonqPopupMenu::NoFlags,
//                                                    KParts::BrowserExtension::DefaultPopupItems );
// 
//     if (popupMenu->count())
//       popupMenu->exec( _global );
//     delete popupMenu;
// }

#include "kerrylabel.moc"