summaryrefslogtreecommitdiffstats
path: root/kword/KWMailMergeLabelAction.cpp
blob: facb6e9d8c1b8f0ddee21e5416e69607c0bf6da7 (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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/* This file is part of the KDE project

   Copyright (C) 2002 Joseph Wenninger <jowenn@kde.org>

   Large parts are taken from tdebase/konqueror/konq_actions.*
   Copyright (C) 2000 Simon Hausmann <hausmann@kde.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   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 "KWMailMergeLabelAction.h"
#include "KWMailMergeLabelAction.moc"
#include <KoMainWindow.h>
#include <kstyle.h>
#include <kpopupmenu.h>

class MailMergeDraggableLabel : public TQToolButton
{
public:
    MailMergeDraggableLabel( KoMainWindow * mw, const TQString & text, TQWidget * parent = 0, const char * name = 0 )
        : TQToolButton( parent, name ), m_mw(mw)
    {
        setText(text);
        setAcceptDrops(true);
        validDrag = false;
    }
protected:
    void mousePressEvent( TQMouseEvent * ev )
    {
        validDrag = true;
        startDragPos = ev->pos();
    }
    void mouseMoveEvent( TQMouseEvent * ev )
    {
        if ((startDragPos - ev->pos()).manhattanLength() > TQApplication::startDragDistance())
        {
            validDrag = false;

#if 0             // what was the goal here?
        KWTextDrag *drag=new KWTextDrag(m_mw);
//      drag->setKWord(" <!DOCTYPE PARAGRAPHS> <PARAGRAPHS> <PARAGRAPH>  <TEXT>fsfsd</TEXT>  <LAYOUT>   <NAME value=\"Standard\" />   <FLOW align=\"left\" />   <FORMAT id=\"1\" pos=\"0\" len=\"5\" >    <WEIGHT value=\"50\" />    <FONT name=\"helvetica\" />    <SIZE value=\"12\" />    <ITALIC value=\"0\" />    <UNDERLINE value=\"0\" />    <STRIKEOUT value=\"0\" />    <VERTALIGN value=\"0\" />   </FORMAT>  </LAYOUT> </PARAGRAPH></PARAGRAPHS>");
        drag->setKWord(" <!DOCTYPE PARAGRAPHS> <PARAGRAPHS> <PARAGRAPH>  <TEXT>fsfsd</TEXT> </PARAGRAPH> </PARAGRAPHS>");
//      drag->setKWord("<TEXT>fsfsd</TEXT>");

        drag->dragCopy();
#endif
        }
    }
    void mouseReleaseEvent( TQMouseEvent * )
    {
        validDrag = false;
    }
    TQSize sizeHint() const
    {
        int w = fontMetrics().width( text() );
        int h = fontMetrics().height();
        return TQSize( w, h );
    }
    void drawButton( TQPainter * p )
    {
        // Draw the background
        tqstyle().drawComplexControl( TQStyle::CC_ToolButton, p, this, rect(), colorGroup(),
                                    TQStyle::Style_Enabled, TQStyle::SC_ToolButton );
        // Draw the label
        tqstyle().drawControl( TQStyle::CE_ToolButtonLabel, p, this, rect(), colorGroup(),
                             TQStyle::Style_Enabled );
    }
    void enterEvent( TQEvent* ) {};
    void leaveEvent( TQEvent* ) {};
#if 0
    void dragEnterEvent( TQDragEnterEvent *ev ) {
        if ( KURLDrag::canDecode( ev ) )
            ev->acceptAction();
    }
    void dropEvent( TQDropEvent* ev ) {
        KURL::List lst;
        if ( KURLDrag::decode( ev, lst ) ) {
            m_mw->openURL( 0L, lst.first() );
        }
    }
#endif
private:
    TQPoint startDragPos;
    bool validDrag;
    KoMainWindow * m_mw;
};





KWMailMergeLabelAction::KWMailMergeLabelAction( const TQString &text, int accel,
                    TQObject* receiver, const char* slot, TQObject *parent, const char *name )
    : KAction( text, accel, receiver, slot, parent, name ), m_label( 0L )
{
}

int KWMailMergeLabelAction::plug( TQWidget *widget, int index )
{
  //do not call the previous implementation here

  if ( widget->inherits( "KToolBar" ) )
  {
    KToolBar *tb = (KToolBar *)widget;

    int id = KAction::getToolButtonID();

    m_label = new MailMergeDraggableLabel( static_cast<KoMainWindow*>(tb->mainWindow()), text(), widget );
    tb->insertWidget( id, m_label->width(), m_label, index );

    addContainer( tb, id );

    connect( tb, TQT_SIGNAL( destroyed() ), this, TQT_SLOT( slotDestroyed() ) );

    return containerCount() - 1;
  }

  return -1;
}

void KWMailMergeLabelAction::unplug( TQWidget *widget )
{
  if ( widget->inherits( "KToolBar" ) )
  {
    KToolBar *bar = (KToolBar *)widget;

    int idx = findContainer( bar );

    if ( idx != -1 )
    {
      bar->removeItem( itemId( idx ) );
      removeContainer( idx );
    }

    m_label = 0;
    return;
  }
}