1 /***************************************************************************
6 * begin : Tue Jan 29 2002
7 * copyright : (C) 2002 by Patrick Charbonnier
8 * : Based On Caitoo v.0.7.3 (c) 1998 - 2000, Matej Koss
9 * email : pch@freeshell.org
11 ****************************************************************************/
13 /***************************************************************************
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 ***************************************************************************/
30 #include <kapplication.h>
32 #include <kiconloader.h>
33 #include <kglobalsettings.h>
34 #include <kmainwindow.h>
37 #include <kpopupmenu.h>
40 #include "kmainwidget.h"
44 #include <X11/Xutil.h>
46 #include <X11/extensions/shape.h>
51 #include "droptarget.h"
53 DropTarget::DropTarget(KMainWindow
* mainWin
):QWidget()
55 int x
= ksettings
.dropPosition
.x();
56 int y
= ksettings
.dropPosition
.y();
58 QRect desk
= KGlobalSettings::desktopGeometry(this);
59 QPixmap bgnd
= UserIcon( "target" );
62 x
>= desk
.left() && y
>= desk
.top() &&
63 (x
+ bgnd
.width()) <= desk
.right() &&
64 (y
+ bgnd
.height()) <= desk
.bottom() )
66 move(ksettings
.dropPosition
);
67 resize(bgnd
.width(), bgnd
.height());
68 KWin::setState(winId(), ksettings
.dropState
);
72 setGeometry(desk
.x()+200, desk
.y()+200, bgnd
.width(), bgnd
.height());
73 KWin::setState(winId(), NET::SkipTaskbar
| NET::StaysOnTop
);
76 b_sticky
= ksettings
.dropState
& NET::Sticky
;
81 kdError(5001) << "Drop target pixmap has no mask!\n";
85 setBackgroundPixmap( bgnd
);
87 // popup menu for right mouse button
88 popupMenu
= new KPopupMenu();
89 popupMenu
->insertTitle(kapp
->caption());
90 popupMenu
->setCheckable(true);
92 pop_Max
= popupMenu
->insertItem(i18n("Maximize"), this, SLOT(toggleMinimizeRestore()));
93 pop_Min
= popupMenu
->insertItem(i18n("Minimize"), this, SLOT(toggleMinimizeRestore()));
95 pop_sticky
= popupMenu
->insertItem(i18n("Sticky"), this, SLOT(toggleSticky()));
96 popupMenu
->insertSeparator();
97 mainWin
->action("drop_target")->plug(popupMenu
);
98 popupMenu
->insertSeparator();
100 popupMenu
->setItemChecked(pop_sticky
, b_sticky
);
101 kmain
->m_paPreferences
->plug(popupMenu
);
102 popupMenu
->insertSeparator();
103 kmain
->m_paQuit
->plug(popupMenu
);
108 setAcceptDrops(true);
112 DropTarget::~DropTarget()
119 DropTarget::mousePressEvent(QMouseEvent
* e
)
121 if (e
->button() == LeftButton
)
123 // toggleMinimizeRestore ();
127 dx
= QCursor::pos().x() - pos().x();
128 dy
= QCursor::pos().y() - pos().y();
130 else if (e
->button() == RightButton
)
132 popupMenu
->setItemEnabled(pop_Min
, kmain
->isVisible());
133 popupMenu
->setItemEnabled(pop_Max
, kmain
->isHidden());
135 popupMenu
->popup(QCursor::pos());
137 else if (e
->button() == MidButton
)
139 kmain
->slotPasteTransfer();
144 void DropTarget::resizeEvent(QResizeEvent
*)
147 XShapeCombineMask(x11Display(), winId(), ShapeBounding
, 0, 0, mask
.handle(), ShapeSet
);
152 void DropTarget::dragEnterEvent(QDragEnterEvent
* event
)
154 event
->accept(KURLDrag::canDecode(event
)
155 || QTextDrag::canDecode(event
));
159 void DropTarget::dropEvent(QDropEvent
* event
)
164 if (KURLDrag::decode(event
, list
))
166 kmain
->addTransfers(list
);
168 else if (QTextDrag::decode(event
, str
))
170 kmain
->addTransfer(str
);
175 void DropTarget::toggleSticky()
177 b_sticky
= !b_sticky
;
178 popupMenu
->setItemChecked(pop_sticky
, b_sticky
);
182 void DropTarget::updateStickyState()
186 KWin::setState(winId(), NET::SkipTaskbar
| NET::StaysOnTop
| NET::Sticky
);
190 KWin::clearState(winId(), NET::Sticky
);
194 void DropTarget::toggleMinimizeRestore()
196 if (kmain
->isVisible())
202 /** No descriptions */
203 void DropTarget::mouseMoveEvent(QMouseEvent
* e
)
214 move( QCursor::pos().x() - dx
, QCursor::pos().y() - dy
);
216 // move(x() + (e->x() - oldX), y() + (e->y() - oldY)); // <<--
219 void DropTarget::mouseReleaseEvent(QMouseEvent
*)
224 /** No descriptions */
225 void DropTarget::mouseDoubleClickEvent(QMouseEvent
* e
)
227 if (e
->button() == LeftButton
)
228 toggleMinimizeRestore();
231 #include "droptarget.moc"