From 4aed2c8219774f5d797760606b8489a92ddc5163 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kicker/applets/media/mediumbutton.cpp | 202 ++++++++++++++++++++++++++++++++++ 1 file changed, 202 insertions(+) create mode 100644 kicker/applets/media/mediumbutton.cpp (limited to 'kicker/applets/media/mediumbutton.cpp') diff --git a/kicker/applets/media/mediumbutton.cpp b/kicker/applets/media/mediumbutton.cpp new file mode 100644 index 000000000..2c96601ea --- /dev/null +++ b/kicker/applets/media/mediumbutton.cpp @@ -0,0 +1,202 @@ +/* This file is part of the KDE project + Copyright (c) 2004 Kevin Ottens + + 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 "mediumbutton.h" + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +MediumButton::MediumButton(QWidget *parent, const KFileItem &fileItem) + : PanelPopupButton(parent), mActions(this, this), mFileItem(fileItem) +{ + KAction *a = KStdAction::paste(this, SLOT(slotPaste()), + &mActions, "pasteto"); + a->setShortcut(0); + a = KStdAction::copy(this, SLOT(slotCopy()), &mActions, "copy"); + a->setShortcut(0); + + setBackgroundOrigin(AncestorOrigin); + + resize(20, 20); + + setAcceptDrops(mFileItem.isWritable()); + + setTitle(mFileItem.text()); + + refreshType(); + + connect(&mOpenTimer, SIGNAL(timeout()), SLOT(slotDragOpen())); + + // Activate this code only if we find a way to have both an + // action and a popup menu for the same kicker button + //connect(this, SIGNAL(clicked()), this, SLOT(slotClicked())); + + setPopup(new QPopupMenu()); +} + +MediumButton::~MediumButton() +{ + QPopupMenu *menu = popup(); + setPopup(0); + delete menu; +} + +const KFileItem &MediumButton::fileItem() const +{ + return mFileItem; +} + +void MediumButton::setFileItem(const KFileItem &fileItem) +{ + mFileItem.assign(fileItem); + setAcceptDrops(mFileItem.isWritable()); + setTitle(mFileItem.text()); + refreshType(); +} + +void MediumButton::initPopup() +{ + QPopupMenu *old_popup = popup(); + + KFileItemList items; + items.append(&mFileItem); + + KonqPopupMenu::KonqPopupFlags kpf = + KonqPopupMenu::ShowProperties + | KonqPopupMenu::ShowNewWindow; + + KParts::BrowserExtension::PopupFlags bef = + KParts::BrowserExtension::DefaultPopupItems; + + KonqPopupMenu *new_popup = new KonqPopupMenu(0L, items, + KURL("media:/"), mActions, 0L, + this, kpf, bef); + KPopupTitle *title = new KPopupTitle(new_popup); + title->setTitle(mFileItem.text()); + + new_popup->insertItem(title, -1, 0); + + setPopup(new_popup); + + if (old_popup!=0L) delete old_popup; +} + +void MediumButton::refreshType() +{ + KMimeType::Ptr mime = mFileItem.determineMimeType(); + QToolTip::add(this, mime->comment()); + setIcon(mime->icon(QString::null, false)); +} + +// Activate this code only if we find a way to have both an +// action and a popup menu for the same kicker button +/* +void MediumButton::slotClicked() +{ + mFileItem.run(); +} +*/ + +void MediumButton::slotPaste() +{ + KonqOperations::doPaste(this, mFileItem.url()); +} + +void MediumButton::slotCopy() +{ + KonqDrag * obj = KonqDrag::newDrag(mFileItem.url(), false); + + QApplication::clipboard()->setData( obj ); +} + +void MediumButton::dragEnterEvent(QDragEnterEvent* e) +{ + if (mFileItem.isWritable()) + { + mOpenTimer.start(1000, true); + e->accept(true); + } +} + +void MediumButton::dragLeaveEvent(QDragLeaveEvent* e) +{ + mOpenTimer.stop(); + + PanelPopupButton::dragLeaveEvent( e ); +} + +void MediumButton::dropEvent(QDropEvent *e) +{ + mOpenTimer.stop(); + + KonqOperations::doDrop(&mFileItem, mFileItem.url(), e, this); +} + +void MediumButton::slotDragOpen() +{ + mFileItem.run(); +} + +QString MediumButton::tileName() +{ + return mFileItem.text(); +} + +void MediumButton::setPanelPosition(KPanelApplet::Position position) +{ + switch(position) + { + case KPanelApplet::pBottom: + setPopupDirection(KPanelApplet::Up); + break; + case KPanelApplet::pTop: + setPopupDirection(KPanelApplet::Down); + break; + case KPanelApplet::pRight: + setPopupDirection(KPanelApplet::Left); + break; + case KPanelApplet::pLeft: + setPopupDirection(KPanelApplet::Right); + break; + } +} + +#include "mediumbutton.moc" -- cgit v1.2.1