// Eventfilter: Only needed under Windows.
// Without this, files dropped in the line edit have URL-encoding.
// This eventfilter decodes the filenames as needed by KDiff3.
bool OpenDialog::eventFilter(QObject* o, QEvent* e)
{
   if ( e->type()==QEvent::DragEnter )
   {
      QDragEnterEvent* d = static_cast<QDragEnterEvent*>(e);
      d->setAccepted( d->mimeData()->hasUrls() );
      return true;
   }
   if (e->type()==QEvent::Drop)
   {
      QDropEvent* d = static_cast<QDropEvent*>(e);

      if ( !d->mimeData()->hasUrls() )
         return false;

      QList<QUrl> lst = d->mimeData()->urls();

      if ( lst.count() > 0 )
      {
         static_cast<QLineEdit*>(o)->setText( QDir::toNativeSeparators( lst[0].toLocalFile() ) );
         static_cast<QLineEdit*>(o)->setFocus();
      }
       
      return true;
   }
   return false;
}
Example #2
0
bool RegisterP12::eventFilter( QObject *o, QEvent *e )
{
	if( o == d->p12Cert && e->type() == QEvent::Drop )
	{
		QDropEvent *drop = static_cast<QDropEvent*>(e);
		if( drop->mimeData()->hasUrls() )
		{
			d->p12Cert->setText( drop->mimeData()->urls().value( 0 ).toLocalFile() );
			return true;
		}
	}
	return QWidget::eventFilter( o, e );
}
Example #3
0
bool SettingsDialog::eventFilter( QObject *o, QEvent *e )
{
	if( o == d->p12Cert && e->type() == QEvent::Drop )
	{
		QDropEvent *d = static_cast<QDropEvent*>(e);
		if( d->mimeData()->hasUrls() )
		{
			setP12Cert( d->mimeData()->urls().value( 0 ).toLocalFile() );
			return true;
		}
	}
	return QWidget::eventFilter( o, e );
}
Example #4
0
bool DockedMdiArea::event(QEvent *event)
{
    // Listen for desktop file manager drop and emit a signal once a file is
    // dropped.
    switch (event->type()) {
    case QEvent::DragEnter: {
        QDragEnterEvent *e = static_cast<QDragEnterEvent*>(event);
        if (!uiFiles(e->mimeData()).empty()) {
            e->acceptProposedAction();
            return true;
        }
    }
        break;
    case QEvent::Drop: {
        QDropEvent *e = static_cast<QDropEvent*>(event);
        const QStringList files = uiFiles(e->mimeData());
        const QStringList::const_iterator cend = files.constEnd();
        for (QStringList::const_iterator it = files.constBegin(); it != cend; ++it) {
            emit fileDropped(*it);
        }
        e->acceptProposedAction();
        return true;
    }
        break;
    default:
        break;
    }
    return QMdiArea::event(event);
}
Example #5
0
/** Redefined to forward events to children. */
bool TabPlaylist::eventFilter(QObject *obj, QEvent *event)
{
	if (event->type() == QEvent::DragEnter) {
		event->accept();
		return true;
	} else if (event->type() == QEvent::Drop) {
		QDropEvent *de = static_cast<QDropEvent*>(event);
		if (de->source() == NULL) {
			// Drag & Drop comes from another application but has landed in the playlist area
			de->ignore();
			QDropEvent *d = new QDropEvent(de->pos(), de->possibleActions(), de->mimeData(), de->mouseButtons(), de->keyboardModifiers());
			_mainWindow->dispatchDrop(d);
			return true;
		} else {
			if (obj == cornerWidget()) {
				auto p = this->addPlaylist();
				p->forceDrop(de);
			} else {
				currentPlayList()->forceDrop(de);
			}
			return true;
		}
	}
	return QTabWidget::eventFilter(obj, event);
}
Example #6
0
bool FormFile::eventFilter(QObject *watched, QEvent *event)
{
    if(watched == ui->lvServer)
    {
        if(event->type() == QEvent::DragEnter)
        {
            QDragEnterEvent* dee = dynamic_cast<QDragEnterEvent*>(event);
            dee->acceptProposedAction();
            return true;
        }
        else if(event->type() == QEvent::Drop)
        {
            QDropEvent* de = dynamic_cast<QDropEvent*>(event);
            QList<QUrl>urls = de->mimeData()->urls();
            if(urls.isEmpty())
            {
                return true;
            }
            QString path = urls.first().toLocalFile();
            //上传文件
            updateFile(path, path.split("/").last());
            return true;
        }
    }

    return QWidget::eventFilter(watched, event);
}
 bool DropFilter::eventFilter(QObject *obj, QEvent *event)
 {
     if( event->type() == QEvent::DragEnter)
     {
         QDragEnterEvent *dragEvent=dynamic_cast< QDragEnterEvent* >(event);
         if (dragEvent->mimeData()->hasFormat("text/plain"))
         {
             QString data = dragEvent->mimeData()->text();
             dragEvent->acceptProposedAction();
         }
     }
     else if (event->type() == QEvent::Drop )
     {
         QDropEvent* dropEvent = dynamic_cast< QDropEvent* >(event);
         QString data = dropEvent->mimeData()->text();
         ::fwServices::ObjectMsg::sptr message = ::fwServices::ObjectMsg::New();
         message->addEvent("DROPPED_UUID", ::fwData::String::New(data.toStdString()));
         ::fwServices::IService::sptr service = m_service.lock();
         ::fwServices::IEditionService::notify( service, service->getObject< ::fwData::Object >(), message );
     } else {
         // standard event processing
         return QObject::eventFilter(obj, event);
     }
     return true;
 }
Example #8
0
bool AlgorithmRunner::eventFilter(QObject *obj, QEvent *ev) {
  bool draggableObject = obj == _ui->favoritesBox->widget() ||
                         _favorites.contains(dynamic_cast<AlgorithmRunnerItem *>(obj));

  if (ev->type() == QEvent::Paint) {
    if (obj == _ui->favoritesBox->widget() && _favorites.empty()) {
      QPainter painter(_ui->favoritesBox->widget());
      QPixmap px((_ui->favoritesBox->_droppingFavorite
                      ? ":/tulip/graphperspective/icons/32/favorite.png"
                      : ":/tulip/graphperspective/icons/32/favorite-empty.png"));
      painter.drawPixmap(_ui->favoritesBox->widget()->width() - px.width() - 8, 8, px);
      QFont f;
      f.setItalic(true);
      painter.setFont(f);
      painter.setBrush(QColor(107, 107, 107));
      painter.setPen(QColor(107, 107, 107));
      painter.drawText(0, 8 + (px.height() - 12) / 2, _ui->favoritesBox->widget()->width(), 65535,
                       /*Qt::AlignHCenter | Qt::AlignTop |*/ Qt::TextWordWrap,
                       "Put your favorite algorithms here");
    }
  } else if ((ev->type() == QEvent::DragEnter || ev->type() == QEvent::DragMove) &&
             draggableObject) {
    QDropEvent *dropEv = static_cast<QDropEvent *>(ev);

    if (dynamic_cast<const AlgorithmMimeType *>(dropEv->mimeData()) != nullptr) {
      _ui->favoritesBox->_droppingFavorite = true;
      ev->accept();
      _ui->favoritesBox->repaint();
    }

    return true;
  } else if (ev->type() == QEvent::DragLeave && draggableObject) {
    _ui->favoritesBox->_droppingFavorite = false;
    _ui->favoritesBox->repaint();
  } else if (ev->type() == QEvent::Drop && draggableObject) {
    QDropEvent *dropEv = static_cast<QDropEvent *>(ev);
    const AlgorithmMimeType *mime = dynamic_cast<const AlgorithmMimeType *>(dropEv->mimeData());

    if (mime != nullptr)
      addFavorite(mime->algorithm(), mime->params());

    _ui->favoritesBox->_droppingFavorite = false;
    _ui->favoritesBox->repaint();
  }

  return false;
}
Example #9
0
/****************************************************************************
**
** Copyright (C) 2015
**
** This file is generated by the Magus toolkit
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
****************************************************************************/

// Include
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QMessageBox>
#include <QHeaderView>
#include <QEvent>
#include <QPixmap>
#include <QImage>
#include <QMimeData>
#include <QTableWidgetItem>
#include <QTreeWidgetItem>
#include "tool_layerwidget.h"

namespace Magus
{
    //****************************************************************************/
    QtLayerWidget::QtLayerWidget(const QString& iconDir, QtSceneViewWidget* sceneViewWidget, QWidget* parent) : QWidget(parent)
    {
        setWindowTitle(QString("Layers"));
        QHBoxLayout* mainLayout = new QHBoxLayout;
        QVBoxLayout* tableLayout = new QVBoxLayout;
        mIconDir = iconDir;
        mLayerIdCounter = 1;
        mSceneViewWidget = sceneViewWidget;
        mListenToSceneViewWidget = 0;
        mListenToSceneId = 0;
        mListenToDropEvents = true;
        mListenToDeleteEvents = true;

        // Create table
        mTable = new QTableWidget(0, 3, this);
        mTable->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        mTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
        mTable->setAcceptDrops(true);
        mTable->setShowGrid(false);
        mTable->viewport()->installEventFilter(this);
        mTable->setColumnWidth(TOOL_LAYER_COLUMN_ICON, 2 * TOOL_LAYER_ICON_WIDTH);
        mTable->setColumnWidth(TOOL_LAYER_COLUMN_NAME, TOOL_LAYER_NAME_WIDTH);
        mTable->setColumnWidth(TOOL_LAYER_COLUMN_VISIBILITY, 2 * TOOL_LAYER_ICON_WIDTH);
        mTable->setSelectionBehavior(QAbstractItemView::SelectRows);
        setStyleSheet("QLineEdit{padding: 0 0px; margin-left: 0px; margin-right: 0px; max-height: 28px; height: 28px;}");
        connect(mTable, SIGNAL(clicked(QModelIndex)), this, SLOT(tableClicked(QModelIndex)));

        // Set headers
        QStringList headers;
        headers << tr("Layer") << tr("") << tr("Visibility");
        mTable->setHorizontalHeaderLabels(headers);
        QFont font;
        font.setBold(true);
        mTable->horizontalHeader()->setFont(font);

        // Contextmenu
        setContextMenuPolicy(Qt::CustomContextMenu);
        mContextMenu = new QMenu(mTable);
        mContextMenu->addAction(new QAction(TOOL_LAYER_ACTION_CREATE_LAYER, mTable));
        mContextMenu->addAction(new QAction(TOOL_LAYER_ACTION_DELETE_LAYER, mTable));
        mContextMenu->addAction(new QAction(TOOL_LAYER_ACTION_RENAME_LAYER, mTable));
        mContextMenu->addAction(new QAction(TOOL_LAYER_ACTION_ALL_VISIBLE, mTable));
        //mContextMenu->addAction(new QAction(QString("TEST"), mTable));
        connect(mContextMenu, SIGNAL(triggered(QAction*)), this, SLOT(contextMenuItemSelected(QAction*)));

        // Layout
        tableLayout->addWidget(mTable);
        mainLayout->addLayout(tableLayout);
        setLayout(mainLayout);
    }

    //****************************************************************************/
    QtLayerWidget::~QtLayerWidget(void)
    {
        QVector<QtLayer*>::iterator it;
        for (it = mLayerVec.begin(); it != mLayerVec.end(); ++it)
            delete *it;

        mLayerVec.clear(); // The table is automatically deleted when this widget is deleted
    }

    //****************************************************************************/
    bool QtLayerWidget::eventFilter(QObject* object, QEvent* event)
    {
        QMouseEvent* mouseEvent = (QMouseEvent*) event;
        switch ((int) event->type())
        {
            case QEvent::MouseButtonPress:
                mouseClickHandler(mouseEvent);
            break;

            case QEvent::MouseButtonDblClick:
                mouseDblClickHandler(mouseEvent);
            break;

            case QEvent::Drop:
                dropHandler(object, event);
            break;
        }
        return QObject::eventFilter(object, event);
    }

    //****************************************************************************/
    void QtLayerWidget::tableClicked(QModelIndex index)
    {
        // Toggle visibility
        int row = index.row();
        int col = index.column();
        QtLayer* layer = mLayerVec.at(row);
        if (col == TOOL_LAYER_COLUMN_VISIBILITY)
        {
            if (layer->visible == true)
                updateVisibilityIcon(row, false);
            else
                updateVisibilityIcon(row, true);
        }

        // Set associated sceneview to visible (if mSceneView available)
        if (mSceneViewWidget)
            mSceneViewWidget->setSceneViewVisible(layer->layerId);

        // Signal that layer is selected
        emit layerSelected(layer->layerId, layer->name);
}

    //****************************************************************************/
    void QtLayerWidget::mouseClickHandler(QMouseEvent* event)
    {
        switch ((int) event->button())
        {
            case Qt::LeftButton:
            {
                // TODO
            }
            break;

            case Qt::RightButton:
            {
                QPoint pos;
                pos.setX(event->screenPos().x());
                pos.setY(event->screenPos().y());
                mContextMenu->popup(pos);
            }
            break;
        }
    }

    //****************************************************************************/
    void QtLayerWidget::mouseDblClickHandler(QMouseEvent* event)
    {
        switch ((int) event->button())
        {
            case Qt::LeftButton:
            {
                if (mTable->currentColumn() == TOOL_LAYER_COLUMN_NAME)
                {
                    QTableWidgetItem* item = mTable->currentItem();
                    if (item->column() == TOOL_LAYER_COLUMN_NAME)
                    {
                        // Its the name; edit it
                        mTable->editItem(item);
                    }
                }
            }
            break;
        }
    }

    //****************************************************************************/
    void QtLayerWidget::dropHandler(QObject* object, QEvent* event)
    {
        event->accept();

        if (!mListenToDropEvents)
            return;

        if (!mListenToSceneViewWidget)
            return;

        // Determine whether the data was from an abstractitem modellist
        QDropEvent* dropEvent = static_cast<QDropEvent*>(event);
        const QMimeData* mimeData = dropEvent->mimeData();
        QString mimeType("application/x-qabstractitemmodeldatalist");
        if (!mimeData->hasFormat(mimeType))
            return;

        // Do not use the mimeData to retrieve the sceneview tree item, because a standard model is used,
        // which does not return the data that is needed.
        // Use the data of the selected item in the sceneview (mListenToSceneId) as an alternative.
        if (mTable->rowCount() > 0 && mSceneViewWidget)
        {
            // Get the dropped item (this is the currently selected item of mListenToSceneId in widget mListenToSceneViewWidget)
            QTreeWidgetItem* item = mListenToSceneViewWidget->getCurrentItem(mListenToSceneId);
            if (item)
            {
                // The layerId of the selected layer = the sceneId of the visible sceneview tree in mSceneViewWidget
                // The currently selected group in the mListenToSceneViewWidget = the destination group of mSceneViewWidget
                int layerId = getCurrentLayerId();
                int groupId = mListenToSceneViewWidget->getCurrentGroupId(item);

                // 1. Add the group; this is ignored if the group is already available
                QtAssetGroup assetGroupInfo = mListenToSceneViewWidget->getGroupInfo(groupId);
                mSceneViewWidget->addGroupToSceneView(layerId,
                                                      assetGroupInfo.groupIcon,
                                                      groupId,
                                                      assetGroupInfo.groupName,
                                                      false);

                // 2. Determine the item type and add either the asset or all assets in a group
                if (mListenToSceneViewWidget->itemIsGroup(item))
                {
                    // The dropped item is a GROUP
                    // Add all the items of the source group to the destination group
                    QVector<QTreeWidgetItem*> assetVec = mListenToSceneViewWidget->getAssetItemsOfGroup(mListenToSceneId, groupId);
                    foreach (QTreeWidgetItem* assetItem, assetVec)
                    {
                        mSceneViewWidget->addAssetToSceneView(layerId,
                                                              groupId,
                                                              mSceneViewWidget->getAssetIdOfAssetItem(assetItem),
                                                              assetItem->text(0));
                    }
                }
bool CloudView::eventFilter(QObject *obj, QEvent *event)
{
    if (obj == mHeader) {
        static QPoint oldPos;
        if (event->type() == QEvent::MouseButtonPress) {
            QMouseEvent *ev = (QMouseEvent *)event;
            oldPos = ev->globalPos();

            return true;

        } else if (event->type() == QEvent::MouseMove) {
            QMouseEvent *ev = (QMouseEvent *)event;
            const QPoint delta = ev->globalPos() - oldPos;

            MainWindow *win = seafApplet->mainWindow();
            win->move(win->x() + delta.x(), win->y() + delta.y());

            oldPos = ev->globalPos();
            return true;
        }

    } else if (obj == mDropArea) {
        if (event->type() == QEvent::DragEnter) {
            QDragEnterEvent *ev = (QDragEnterEvent *)event;
            if (ev->mimeData()->hasUrls() && ev->mimeData()->urls().size() == 1) {
                const QUrl url = ev->mimeData()->urls().at(0);
                if (url.scheme() == "file") {
                    QString path = url.toLocalFile();
#if defined(Q_OS_MAC) && (QT_VERSION <= QT_VERSION_CHECK(5, 4, 0))
                    path = utils::mac::fix_file_id_url(path);
#endif
                    if (QFileInfo(path).isDir()) {
                        ev->acceptProposedAction();
                    }
                }
            }
            return true;
        } else if (event->type() == QEvent::Drop) {
            QDropEvent *ev = (QDropEvent *)event;
            const QUrl url = ev->mimeData()->urls().at(0);
            QString path = url.toLocalFile();
#if defined(Q_OS_MAC) && (QT_VERSION <= QT_VERSION_CHECK(5, 4, 0))
            path = utils::mac::fix_file_id_url(path);
#endif
            ev->setDropAction(Qt::CopyAction);
            ev->accept();
            showCreateRepoDialog(path);
            return true;
        }
    }

    return QWidget::eventFilter(obj, event);
}
Example #11
0
bool CloudView::eventFilter(QObject *obj, QEvent *event)
{
    if (obj == mHeader) {
        static QPoint oldPos;
        if (event->type() == QEvent::MouseButtonPress) {
            QMouseEvent *ev = (QMouseEvent *)event;
            oldPos = ev->globalPos();

            return true;

        } else if (event->type() == QEvent::MouseMove) {
            QMouseEvent *ev = (QMouseEvent *)event;
            const QPoint delta = ev->globalPos() - oldPos;

            MainWindow *win = seafApplet->mainWindow();
            win->move(win->x() + delta.x(), win->y() + delta.y());

            oldPos = ev->globalPos();
            return true;
        }

    } else if (obj == mDropArea) {
        if (event->type() == QEvent::DragEnter) {
            QDragEnterEvent *ev = (QDragEnterEvent *)event;
            if (ev->mimeData()->hasUrls() && ev->mimeData()->urls().size() == 1) {
                const QUrl url = ev->mimeData()->urls().at(0);
                if (url.isLocalFile()) {
                    QString path = url.toLocalFile();
                    if (QFileInfo(path).isDir()) {
                        ev->acceptProposedAction();
                    }
                }
            }
            return true;
        } else if (event->type() == QEvent::Drop) {
            QDropEvent *ev = (QDropEvent *)event;
            const QUrl url = ev->mimeData()->urls().at(0);
            QString path = url.toLocalFile();
            showCreateRepoDialog(path);
            return true;
        }
    }

    return QWidget::eventFilter(obj, event);
}
Example #12
0
bool SessionListWidget::event(QEvent *event)
{
#ifndef QUTIM_MOBILE_UI
	if (event->type() == QEvent::ToolTip) {
		if (QHelpEvent *help = static_cast<QHelpEvent*>(event)) {
			int index = indexAt(help->pos()).row();
			if (index != -1) {
				ChatUnit *unit = session(index)->getUnit();
				ToolTip::instance()->showText(help->globalPos(), unit, this);
				return true;
			}
		}
	} else if (event->type() == QEvent::DragEnter) {
		QDragEnterEvent *dragEvent = static_cast<QDragEnterEvent*>(event);
		if (const MimeObjectData *data = qobject_cast<const MimeObjectData*>(dragEvent->mimeData())) {
			ChatUnit *u = qobject_cast<ChatUnit*>(data->object());
			if (u)
				dragEvent->acceptProposedAction();
		}
		return true;
	} else if (event->type() == QEvent::Drop) {
		QDropEvent *dropEvent = static_cast<QDropEvent*>(event);
		if (const MimeObjectData *mimeData
				= qobject_cast<const MimeObjectData*>(dropEvent->mimeData())) {
			if (ChatUnit *u = qobject_cast<ChatUnit*>(mimeData->object())) {
				ChatLayerImpl::get(u,true)->activate();
				dropEvent->setDropAction(Qt::CopyAction);
				dropEvent->accept();
				return true;
			}
		}
	} else 
#endif
	if (event->type() == QEvent::ContextMenu) {
		QContextMenuEvent *ev = static_cast<QContextMenuEvent*>(event);
		ChatSessionImpl *s = session(row(itemAt(ev->pos())));
		if(s) {
			s->unit()->showMenu(ev->globalPos());
			return true;
		}

	}
	return QListWidget::event(event);
}
Example #13
0
bool AssemblyBrowser::eventFilter(QObject* o, QEvent* e) {
    if(o == ui) {
        if (e->type() == QEvent::DragEnter || e->type() == QEvent::Drop) {
            QDropEvent* de = (QDropEvent*)e;
            const QMimeData* md = de->mimeData();
            const GObjectMimeData* gomd = qobject_cast<const GObjectMimeData*>(md);
            if (gomd != NULL) {
                if (e->type() == QEvent::DragEnter) {
                    de->acceptProposedAction();
                } else {
                    QApplication::changeOverrideCursor(Qt::ArrowCursor);//setting arrow cursor on Linux
                    QString err = tryAddObject(gomd->objPtr.data());
                    if(!err.isEmpty()) {
                        QMessageBox::critical(ui, tr("Error!"), err);
                    }
                }
            }
        }
    }
    return false;
}
    bool ArticleViewPrivate::eventFilter(QObject * obj, QEvent * event)
    {
        //qDebug() << "eventFilter" << obj << event;

        const AbstractBibliographicModel * model = qobject_cast< const AbstractBibliographicModel * >(view ? origin(view->model()) : 0);

        // Only filter the view's events
        if (model && obj == view->viewport()) {
            switch (event->type()) {
            case QEvent::DragMove:
            case QEvent::DragEnter: {
                QDropEvent * e = static_cast< QDropEvent * >(event);
                if ((dropping = model->acceptsDrop(e->mimeData()))) {
                    view->viewport()->update();
                    e->accept();
                } else {
                    e->ignore();
                }
                //qDebug() << "---" << dropping;
                return true;
                break;
            }
            case QEvent::DragLeave:
                dropping = false;
                view->viewport()->update();
                break;
            case QEvent::Drop:
                dropping = false;
                view->viewport()->update();
                break;
            default:
                break;
            }
        }

        return QObject::eventFilter(obj, event);
    }
Example #15
0
bool EventFilter::eventFilter(QObject *watched, QEvent *event)
{
    Q_UNUSED(watched);
    AVPlayer *player = static_cast<AVPlayer*>(parent());
    if (!player || !player->renderer() || !player->renderer()->widget())
        return false;
    if (qobject_cast<QWidget*>(watched) != player->renderer()->widget()) {
        return false;
    }
#ifndef QT_NO_DYNAMIC_CAST //dynamic_cast is defined as a macro to force a compile error
    if (player->renderer() != dynamic_cast<VideoRenderer*>(watched)) {
       // return false;
    }
#endif
    QEvent::Type type = event->type();
    switch (type) {
    case QEvent::KeyPress: {
        QKeyEvent *key_event = static_cast<QKeyEvent*>(event);
        int key = key_event->key();
        Qt::KeyboardModifiers modifiers = key_event->modifiers();
        switch (key) {
        case Qt::Key_C: //capture
            player->captureVideo();
            break;
        case Qt::Key_N: //check playing?
            player->playNextFrame();
            break;
        case Qt::Key_P:
            player->play();
            break;
        case Qt::Key_Q:
        case Qt::Key_Escape:
            qApp->quit();
            break;
        case Qt::Key_S:
            player->stop(); //check playing?
            break;
        case Qt::Key_Space: //check playing?
            qDebug("isPaused = %d", player->isPaused());
            player->pause(!player->isPaused());
            break;
        case Qt::Key_F: { //TODO: move to gui
            QWidget *w = qApp->activeWindow();
            if (!w)
                return false;
            if (w->isFullScreen())
                w->showNormal();
            else
                w->showFullScreen();
        }
            break;
        case Qt::Key_Up: {
            AudioOutput *ao = player->audio();
            if (modifiers == Qt::ControlModifier) {
                qreal s = player->speed();
                if (s < 1.4)
                    s += 0.02;
                else
                    s += 0.05;
                if (qAbs<qreal>(s-1.0) <= 0.01)
                    s = 1.0;
                player->setSpeed(s);
                return true;
            }
            if (ao && ao->isAvailable()) {
                qreal v = player->audio()->volume();
                if (v > 0.5)
                    v += 0.1;
                else if (v > 0.1)
                    v += 0.05;
                else
                    v += 0.025;
                player->audio()->setVolume(v);
                qDebug("vol = %.3f", player->audio()->volume());
            }
        }
            break;
        case Qt::Key_Down: {
            AudioOutput *ao = player->audio();
            if (modifiers == Qt::ControlModifier) {
                qreal s = player->speed();
                if (s < 1.4)
                    s -= 0.02;
                else
                    s -= 0.05;
                if (qAbs<qreal>(s-1.0) <= 0.01)
                    s = 1.0;
                s = qMax<qreal>(s, 0.0);
                player->setSpeed(s);
                return true;
            }
            if (ao && ao->isAvailable()) {
                qreal v = player->audio()->volume();
                if (v > 0.5)
                    v -= 0.1;
                else if (v > 0.1)
                    v -= 0.05;
                else
                    v -= 0.025;
                player->audio()->setVolume(v);
                qDebug("vol = %.3f", player->audio()->volume());
            }
        }
            break;
        case Qt::Key_O: {
            if (modifiers == Qt::ControlModifier) {
                //TODO: emit a signal so we can use custome dialogs?
                openLocalFile();
            } else/* if (m == Qt::NoModifier) */{
                emit showNextOSD();
            }
        }
            break;
        case Qt::Key_Left:
            qDebug("<-");
            player->seekBackward();
            break;
        case Qt::Key_Right:
            qDebug("->");
            player->seekForward();
            break;
        case Qt::Key_M:
            if (player->audio()) {
                player->audio()->setMute(!player->audio()->isMute());
            }
            break;
        case Qt::Key_R: {
            VideoRenderer* renderer = player->renderer();
            VideoRenderer::OutAspectRatioMode r = renderer->outAspectRatioMode();
            renderer->setOutAspectRatioMode(VideoRenderer::OutAspectRatioMode(((int)r+1)%2));
        }
            break;
        case Qt::Key_T: {
            QWidget *w = qApp->activeWindow();
            if (!w)
                return false;
            Qt::WindowFlags wf = w->windowFlags();
            if (wf & Qt::WindowStaysOnTopHint) {
                qDebug("Window not stays on top");
                w->setWindowFlags(wf & ~Qt::WindowStaysOnTopHint);
            } else {
                qDebug("Window stays on top");
                w->setWindowFlags(wf | Qt::WindowStaysOnTopHint);
            }
            //call setParent() when changing the flags, causing the widget to be hidden
            w->show();
        }
            break;
        case Qt::Key_F1:
            help();
            break;
        default:
            return false;
        }
        break;
    }
    case QEvent::DragEnter:
    case QEvent::DragMove: {
        QDropEvent *e = static_cast<QDropEvent*>(event);
        e->acceptProposedAction();
    }
        break;
    case QEvent::Drop: {
        QDropEvent *e = static_cast<QDropEvent*>(event);
        QString path = e->mimeData()->urls().first().toLocalFile();
        player->stop();
        player->load(path);
        player->play();
        e->acceptProposedAction();
    }
        break;
    case QEvent::GraphicsSceneContextMenu: {
        QGraphicsSceneContextMenuEvent *e = static_cast<QGraphicsSceneContextMenuEvent*>(event);
        showMenu(e->screenPos());
    }
        break;
    case QEvent::ContextMenu: {
        QContextMenuEvent *e = static_cast<QContextMenuEvent*>(event);
        showMenu(e->globalPos());
    }
        break;
    default:
        return false;
    }
    return true; //false: for text input
}
// TODO    *** drop improvements ***
// open submenus on drop interactions
bool KBookmarkBar::eventFilter( QObject *, QEvent *e )
{
    if (d->m_filteredToolbar)
        return false; // todo: make this limit the actions

    if ( e->type() == QEvent::DragLeave )
    {
        removeTempSep();
    }
    else if ( e->type() == QEvent::Drop )
    {
        removeTempSep();

        QDropEvent *dev = static_cast<QDropEvent*>( e );
        QDomDocument doc;
        QList<KBookmark> list = KBookmark::List::fromMimeData( dev->mimeData(), doc );
        if ( list.isEmpty() )
            return false;
        if (list.count() > 1)
            kWarning(7043) << "Sorry, currently you can only drop one address "
                "onto the bookmark bar!";
        KBookmark toInsert = list.first();

        KBookmarkGroup parentBookmark = getToolbar();

        if(d->m_sepIndex == 0)
        {
            KBookmark newBookmark = parentBookmark.addBookmark(toInsert.fullText(), toInsert.url() );

            parentBookmark.moveBookmark( newBookmark, KBookmark() );
            m_pManager->emitChanged( parentBookmark );
            return true;
        }
        else
        {
            KBookmark after = parentBookmark.first();

            for(int i=0; i < d->m_sepIndex - 1 ; ++i)
                after = parentBookmark.next(after);
            KBookmark newBookmark = parentBookmark.addBookmark(toInsert.fullText(), toInsert.url() );

            parentBookmark.moveBookmark( newBookmark, after );
            m_pManager->emitChanged( parentBookmark );
            return true;
        }
    }
    else if ( e->type() == QEvent::DragMove || e->type() == QEvent::DragEnter )
    {
        QDragMoveEvent *dme = static_cast<QDragMoveEvent*>( e );
        if (!KBookmark::List::canDecode( dme->mimeData() ))
            return false;

        //cache text, save positions (inserting the temporary widget changes the positions)
        if(e->type() == QEvent::DragEnter)
        {
            QDomDocument doc;
            const QList<KBookmark> list = KBookmark::List::fromMimeData( dme->mimeData(), doc );
            if ( list.isEmpty() )
                return false;
            d->tempLabel  = list.first().url().pathOrUrl();

            d->widgetPositions.clear();

            for (int i = 0; i < m_toolBar->actions().count(); ++i)
                if (QWidget* button = m_toolBar->widgetForAction(m_toolBar->actions()[i])) {
                    if(m_toolBar->orientation() == Qt::Horizontal) {
                        if(QApplication::isLeftToRight()) {
                            d->widgetPositions.push_back(button->geometry().right());
                        } else {
                            d->widgetPositions.push_back(button->geometry().left());
                        }
                    } else {
                        d->widgetPositions.push_back(button->geometry().bottom());
                    }
                }
        }

        bool accept = handleToolbarDragMoveEvent(dme->pos(), d->m_actions, d->tempLabel);
        if (accept)
        {
            dme->accept();
            return true; //Really?
        }
    }
    return false;
}
bool ClassSpaceChecker::eventFilter(QObject *object, QEvent *evt)
{
	if(evt->type() == QEvent::FocusOut) 
	{
		if(object == ui.tableWidgetResult)
		{
			ui.lineEdit_Result->setText(prevTotalResultStr_);
		}
		return QMainWindow::eventFilter(object, evt);
	}

	if(object == ui.comboBox_JarFile 
		|| object == ui.lineEdit_MapFile
		) 
	{
		if(evt->type() == QEvent::DragEnter)
		{
			QDragEnterEvent *e = (QDragEnterEvent*)evt;
			const QMimeData *mimeData = e->mimeData();
			if (mimeData->hasUrls())
			{
				int cnt = 0;
				QList<QUrl> urlList = mimeData->urls();
				for (int i = 0; i < urlList.size(); ++i)
				{
					QString path = urlList.at(i).toLocalFile();
					if( !QFileInfo(path).isFile() )
						continue;

					if(path.indexOf(".jar", 0, Qt::CaseInsensitive) < 0 
						&& path.indexOf(".zip", 0, Qt::CaseInsensitive) < 0
						&& path.indexOf(".txt", 0, Qt::CaseInsensitive) < 0
						)
						continue;

					if(urlList.size() == 1) 
					{
						if(object == ui.comboBox_JarFile)
						{
							if(path.indexOf(".jar", 0, Qt::CaseInsensitive) < 0 
								&& path.indexOf(".zip", 0, Qt::CaseInsensitive) < 0
								)
								continue;
						}
						else if(object == ui.lineEdit_MapFile)
						{
							if(path.indexOf(".txt", 0, Qt::CaseInsensitive) < 0)
								continue;
						}
					}

					cnt++;
				}
				if( cnt > 0 )
					e->acceptProposedAction();
			}
			qDebug() << evt << mimeData->text();
		}
		else if(evt->type() == QEvent::DragLeave)
		{
			QDragLeaveEvent *e = (QDragLeaveEvent*)evt;
			e->accept();
		}
		else if(evt->type() == QEvent::DragMove)
		{
			QDragMoveEvent *e = (QDragMoveEvent*)evt;
			e->acceptProposedAction();
		}
		else if(evt->type() == QEvent::Drop)
		{
			QDropEvent *e = (QDropEvent*)evt;
			const QMimeData* mimeData = e->mimeData();

			if (mimeData->hasUrls())
			{
				QList<QUrl> urlList = mimeData->urls();

				for (int i = 0; i < urlList.size(); ++i)
				{
					QString path = urlList.at(i).toLocalFile();

					if(path.indexOf(".txt", 0, Qt::CaseInsensitive) >= 0)
						ui.lineEdit_MapFile->setText(path);
					if(path.indexOf(".jar", 0, Qt::CaseInsensitive) >= 0 || path.indexOf(".zip", 0, Qt::CaseInsensitive) >= 0)
					{
						checkAndJarFilePreset(path);
					}
				}
			}
		}
	}
	return QMainWindow::eventFilter(object, evt);
}
bool
PlayerWidget::eventFilter(QObject *object, QEvent *event)
{
	if(object == m_layeredWidget) {
		if(event->type() == QEvent::DragEnter) {
			QDragEnterEvent *dragEnterEvent = static_cast<QDragEnterEvent *>(event);
			KUrl::List urls = KUrl::List::fromMimeData(dragEnterEvent->mimeData());
			if(!urls.isEmpty())
				dragEnterEvent->accept();
			else
				dragEnterEvent->ignore();
			return true;
		} else if(event->type() == QEvent::DragMove) {
			return true;            // eat event
		} else if(event->type() == QEvent::Drop) {
			QDropEvent *dropEvent = static_cast<QDropEvent *>(event);

			KUrl::List urls = KUrl::List::fromMimeData(dropEvent->mimeData());
			if(!urls.isEmpty()) {
				for(KUrl::List::ConstIterator it = urls.begin(), end = urls.end(); it != end; ++it) {
					const KUrl &url = *it;

					if(url.protocol() != "file")
						continue;

					app()->openVideo(url);
					break;
				}
			}

			return true;            // eat event
		} else if(event->type() == QEvent::KeyPress) {
			// NOTE: when on full screen mode, the keyboard input is received but
			// for some reason it doesn't trigger the correct actions automatically
			// so we process the event and handle the issue ourselves.

			QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
			return app()->triggerAction(QKeySequence((keyEvent->modifiers() & ~Qt::KeypadModifier) + keyEvent->key()));
		} else if(event->type() == QEvent::MouseMove) {
			QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
			if(mouseEvent->globalPos() != m_currentCursorPos) {
				m_currentCursorPos = mouseEvent->globalPos();
				if(m_layeredWidget->cursor().shape() == Qt::BlankCursor)
					m_layeredWidget->unsetCursor();
				if(m_fullScreenControls->isAttached())
					m_fullScreenControls->toggleVisible(true);
			}
		}
	} else if(object == m_infoControlsGroupBox || object->parent() == m_infoControlsGroupBox) {
		if(event->type() != QEvent::MouseButtonRelease)
			return QWidget::eventFilter(object, event);

		QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);

		if(mouseEvent->button() != Qt::RightButton)
			return QWidget::eventFilter(object, event);

		KMenu menu;
		QAction *action = menu.addAction(i18n("Show editable position control"));
		action->setCheckable(true);
		action->setChecked(app()->playerConfig()->showPositionTimeEdit());

		if(menu.exec(mouseEvent->globalPos()) == action)
			app()->playerConfig()->toggleShowPositionTimeEdit();

		return true;                    // eat event
	}

	return QWidget::eventFilter(object, event);
}
Example #19
0
bool canDropToTab(const QDropEvent &event)
{
    const auto &data = *event.mimeData();
    return data.hasFormat(mimeItems) || data.hasText() || data.hasImage() || data.hasUrls();
}
Example #20
0
bool HashBox::eventFilter(QObject* object, QEvent* event)
{
	if (object == dropWidget) {
		if (event->type() == QEvent::DragEnter) {
			QDragEnterEvent* dragEnterEvent = static_cast<QDragEnterEvent*>(event);
			if (dragEnterEvent) {
				/* print out mimeType */
				showFormats("HashBox::dragEnterEvent", dragEnterEvent->mimeData()->formats());

				if (dragEnterEvent->mimeData()->hasUrls()) {
					std::cerr << "HashBox::dragEnterEvent() Accepting Urls" << std::endl;
					dragEnterEvent->acceptProposedAction();
				} else {
					std::cerr << "HashBox::dragEnterEvent() No Urls" << std::endl;
				}
			}
		} else if (event->type() == QEvent::Drop) {
			QDropEvent* dropEvent = static_cast<QDropEvent*>(event);
			if (dropEvent) {
				if (Qt::CopyAction & dropEvent->possibleActions()) {
					/* print out mimeType */
					showFormats("HashBox::dropEvent", dropEvent->mimeData()->formats());

					QStringList files;

					if (dropEvent->mimeData()->hasUrls()) {
						std::cerr << "HashBox::dropEvent() Urls:" << std::endl;

						QList<QUrl> urls = dropEvent->mimeData()->urls();
						QList<QUrl>::iterator uit;
						for (uit = urls.begin(); uit != urls.end(); ++uit) {
							QString localpath = uit->toLocalFile();
							std::cerr << "Whole URL: " << uit->toString().toStdString() << std::endl;
							std::cerr << "or As Local File: " << localpath.toStdString() << std::endl;

							if (localpath.isEmpty() == false) {
								//Check that the file does exist and is not a directory
								QDir dir(localpath);
								if (dir.exists()) {
									std::cerr << "HashBox::dropEvent() directory not accepted." << std::endl;
									QMessageBox mb(tr("Drop file error."), tr("Directory can't be dropped, only files are accepted."), QMessageBox::Information, QMessageBox::Ok, 0, 0, this);
									mb.exec();
								} else if (QFile::exists(localpath)) {
									files.push_back(localpath);
								} else {
									std::cerr << "HashBox::dropEvent() file does not exists."<< std::endl;
									QMessageBox mb(tr("Drop file error."), tr("File not found or file name not accepted."), QMessageBox::Information, QMessageBox::Ok, 0, 0, this);
									mb.exec();
								}
							}
						}
					}

					addAttachments(files,mDefaultTransferFlags);

					dropEvent->setDropAction(Qt::CopyAction);
					dropEvent->accept();
				} else {
					std::cerr << "HashBox::dropEvent() Rejecting uncopyable DropAction" << std::endl;
				}
			}
		}
	}
	// pass the event on to the parent class
	return QScrollArea::eventFilter(object, event);
}
bool FileDialogEventCatcher::eventFilter(QObject *o, QEvent *e)
{
	if (e->type() == QEvent::KeyPress)
	{
		QKeyEvent *keyEvent = static_cast<QKeyEvent *>(e);
		switch (keyEvent->key())
		{
			case Qt::Key_Escape:
				emit escapePressed();
				return true;
			case Qt::Key_D:
				if (keyEvent->modifiers() & Qt::ControlModifier)
				{
					emit desktopPressed();
					return true;
				}
				break;
			case Qt::Key_H:
				if (keyEvent->modifiers() & (Qt::ControlModifier|Qt::ShiftModifier))
				{
					emit homePressed();
					return true;
				}
				break;
			case Qt::Key_Up:
				if (keyEvent->modifiers() & Qt::ControlModifier)
				{
					emit parentPressed();
					return true;
				}
				break;
			case Qt::Key_Down:
				if (keyEvent->modifiers() & Qt::ControlModifier)
				{
					emit enterSelectedPressed();
					return true;
				}
				break;
		}
	}
	else
	if (e->type() == QEvent::DragEnter)
	{
		e->accept();
		return true;
	}
	else
	if (e->type() == QEvent::Drop)
	{
		QDropEvent *dropEvent = static_cast<QDropEvent *>(e);
		if (dropEvent)
		{
			if ( dropEvent->mimeData()->hasFormat("text/uri-list"))
			{
				QString fileUrl;
				QList<QUrl> fileUrls = dropEvent->mimeData()->urls();
				if (fileUrls.count()>0)
				{
					fileUrl = fileUrls[0].toLocalFile();
					if (fileUrls[0].isLocalFile())
					{
						emit dropLocation(fileUrl);
					}
				}
			}
		}
		e->accept();
		return true;
	}
	return QObject::eventFilter(o, e);
}
Example #22
0
bool BookmarkToolBar::eventFilter(QObject *watched, QEvent *event)
{
    if (m_currentMenu && m_currentMenu->isVisible()
            && !m_currentMenu->rect().contains(m_currentMenu->mapFromGlobal(QCursor::pos())))
    {
        // To switch root folders as in a menubar

        KBookmarkActionMenu* act = dynamic_cast<KBookmarkActionMenu *>(actionAt(mapFromGlobal(QCursor::pos())));

        if (event->type() == QEvent::MouseMove && act && act->menu() != m_currentMenu)
        {
            m_currentMenu->hide();
            QPoint pos = mapToGlobal(widgetForAction(act)->pos());
            act->menu()->popup(QPoint(pos.x(), pos.y() + widgetForAction(act)->height()));
        }
        else if (event->type() == QEvent::MouseButtonPress && act)
        {
            m_currentMenu->hide();
        }

        return QObject::eventFilter(watched, event);
    }

    switch (event->type())
    {
    case QEvent::Show:
    {
        if (!m_filled)
        {
            BookmarkManager::self()->fillBookmarkBar(this);
            m_filled = true;
        }
    }
    break;

    case QEvent::ActionRemoved:
    {
        QActionEvent *actionEvent = static_cast<QActionEvent*>(event);
        if (actionEvent && actionEvent->action() != m_dropAction)
        {
            QWidget *widget = widgetForAction(actionEvent->action());
            if (widget)
            {
                widget->removeEventFilter(this);
            }
        }
    }
    break;

    case QEvent::ParentChange:
    {
        QActionEvent *actionEvent = static_cast<QActionEvent*>(event);
        if (actionEvent && actionEvent->action() != m_dropAction)
        {
            QWidget *widget = widgetForAction(actionEvent->action());
            if (widget)
            {
                widget->removeEventFilter(this);
            }
        }
    }
    break;

    case QEvent::DragEnter:
    {
        QDragEnterEvent *dragEvent = static_cast<QDragEnterEvent*>(event);
        if (dragEvent->mimeData()->hasFormat(BookmarkManager::bookmark_mime_type())
                || dragEvent->mimeData()->hasFormat("text/uri-list")
                || dragEvent->mimeData()->hasFormat("text/plain"))
        {
            QFrame* dropIndicatorWidget = new QFrame(this);
            dropIndicatorWidget->setFrameShape(QFrame::VLine);
            m_dropAction = insertWidget(actionAt(dragEvent->pos()), dropIndicatorWidget);

            dragEvent->accept();
        }
    }
    break;

    case QEvent::DragLeave:
    {
        QDragLeaveEvent *dragEvent = static_cast<QDragLeaveEvent*>(event);

        if (m_checkedAction)
        {
            m_checkedAction->setCheckable(false);
            m_checkedAction->setChecked(false);
        }

        delete m_dropAction;
        m_dropAction = 0;
        dragEvent->accept();
    }
    break;

    case QEvent::DragMove:
    {
        QDragMoveEvent *dragEvent = static_cast<QDragMoveEvent*>(event);
        if (dragEvent->mimeData()->hasFormat(BookmarkManager::bookmark_mime_type())
                || dragEvent->mimeData()->hasFormat("text/uri-list")
                || dragEvent->mimeData()->hasFormat("text/plain"))
        {
            QAction *overAction = actionAt(dragEvent->pos());
            KBookmarkActionInterface *overActionBK = dynamic_cast<KBookmarkActionInterface*>(overAction);
            QWidget *widgetAction = widgetForAction(overAction);

            if (overAction != m_dropAction && overActionBK && widgetAction && m_dropAction)
            {
                removeAction(m_dropAction);
                if (m_checkedAction)
                {
                    m_checkedAction->setCheckable(false);
                    m_checkedAction->setChecked(false);
                }

                if (!overActionBK->bookmark().isGroup())
                {
                    if ((dragEvent->pos().x() - widgetAction->pos().x()) > (widgetAction->width() / 2))
                    {
                        if (actions().count() >  actions().indexOf(overAction) + 1)
                        {
                            insertAction(actions().at(actions().indexOf(overAction) + 1), m_dropAction);
                        }
                        else
                        {
                            addAction(m_dropAction);
                        }
                    }
                    else
                    {
                        insertAction(overAction, m_dropAction);
                    }
                }
                else
                {
                    if ((dragEvent->pos().x() - widgetAction->pos().x()) >= (widgetAction->width() * 0.75))
                    {
                        if (actions().count() >  actions().indexOf(overAction) + 1)
                        {
                            insertAction(actions().at(actions().indexOf(overAction) + 1), m_dropAction);
                        }
                        else
                        {
                            addAction(m_dropAction);
                        }
                    }
                    else if ((dragEvent->pos().x() - widgetAction->pos().x()) <= (widgetAction->width() * 0.25))
                    {
                        insertAction(overAction, m_dropAction);
                    }
                    else
                    {
                        overAction->setCheckable(true);
                        overAction->setChecked(true);
                        m_checkedAction = overAction;
                    }
                }

                dragEvent->accept();
            }
        }
    }
    break;


    case QEvent::Drop:
    {
        QDropEvent *dropEvent = static_cast<QDropEvent*>(event);
        KBookmark bookmark;
        KBookmarkGroup root = BookmarkManager::self()->manager()->toolbar();

        if (m_checkedAction)
        {
            m_checkedAction->setCheckable(false);
            m_checkedAction->setChecked(false);
        }

        if (dropEvent->mimeData()->hasFormat(BookmarkManager::bookmark_mime_type()))
        {
            QByteArray addresses = dropEvent->mimeData()->data(BookmarkManager::bookmark_mime_type());
            bookmark =  BookmarkManager::self()->findByAddress(QString::fromLatin1(addresses.data()));
            if (bookmark.isNull())
                return false;
        }
        else if (dropEvent->mimeData()->hasFormat("text/uri-list"))
        {
            // DROP is URL
            QString url = dropEvent->mimeData()->urls().at(0).toString();
            WebWindow *w = qobject_cast<WebWindow *>(parent());
            QString title = url.contains(w->url().url())
                            ? w->title()
                            : url;
            bookmark = root.addBookmark(title, url);
        }
        else if (dropEvent->mimeData()->hasFormat("text/plain"))
        {
            // DROP is TEXT
            QString url = dropEvent->mimeData()->text();
            KUrl u(url);
            if (u.isValid())
            {
                WebWindow *w = qobject_cast<WebWindow *>(parent());
                QString title = url.contains(w->url().url())
                                ? w->title()
                                : url;
                bookmark = root.addBookmark(title, url);
            }
        }
        else
        {
            return false;
        }

        QAction *destAction = actionAt(dropEvent->pos());
        if (destAction && destAction == m_dropAction)
        {
            if (actions().indexOf(m_dropAction) > 0)
            {
                destAction = actions().at(actions().indexOf(m_dropAction) - 1);
            }
            else
            {
                destAction = actions().at(1);
            }
        }

        if (destAction)
        {
            KBookmarkActionInterface *destBookmarkAction = dynamic_cast<KBookmarkActionInterface *>(destAction);
            QWidget *widgetAction = widgetForAction(destAction);

            if (destBookmarkAction && !destBookmarkAction->bookmark().isNull() && widgetAction
                    && bookmark.address() != destBookmarkAction->bookmark().address())
            {
                KBookmark destBookmark = destBookmarkAction->bookmark();

                if (!destBookmark.isGroup())
                {
                    if ((dropEvent->pos().x() - widgetAction->pos().x()) >= (widgetAction->width() / 2))
                    {
                        root.moveBookmark(bookmark, destBookmark);
                    }
                    else
                    {
                        root.moveBookmark(bookmark, destBookmark.parentGroup().previous(destBookmark));
                    }
                }
                else
                {
                    if ((dropEvent->pos().x() - widgetAction->pos().x()) >= (widgetAction->width() * 0.75))
                    {
                        root.moveBookmark(bookmark, destBookmark);
                    }
                    else if ((dropEvent->pos().x() - widgetAction->pos().x()) <= (widgetAction->width() * 0.25))
                    {
                        root.moveBookmark(bookmark, destBookmark.parentGroup().previous(destBookmark));
                    }
                    else
                    {
                        destBookmark.toGroup().addBookmark(bookmark);
                    }
                }


                BookmarkManager::self()->emitChanged();
            }
        }
        else
        {
            root.deleteBookmark(bookmark);
            bookmark = root.addBookmark(bookmark);
            if (dropEvent->pos().x() < widgetForAction(actions().first())->pos().x())
            {
                root.moveBookmark(bookmark, KBookmark());
            }

            BookmarkManager::self()->emitChanged();
        }
        dropEvent->accept();
    }
    break;

    default:
        break;
    }

    QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);

    // These events need to be handled only for Bookmark actions and not the bar
    if (watched != this && mouseEvent)
    {
        switch (event->type())
        {
        case QEvent::MouseButtonPress: // drag handling
        {
            QPoint pos = mapFromGlobal(QCursor::pos());
            KBookmarkActionInterface *action = dynamic_cast<KBookmarkActionInterface *>(actionAt(pos));

            if (action && mouseEvent->button() != Qt::MiddleButton)
            {
                m_dragAction = actionAt(pos);
                m_startDragPos = pos;

                // The menu is displayed only when the mouse button is released
                if (action->bookmark().isGroup())
                    return true;
            }
        }
        break;

        case QEvent::MouseMove:
        {
            int distance = (mapFromGlobal(QCursor::pos()) - m_startDragPos).manhattanLength();
            if (!m_currentMenu && distance >= QApplication::startDragDistance())
            {
                startDrag();
            }
        }
        break;

        case QEvent::MouseButtonRelease:
        {
            QPoint destPos = mapFromGlobal(QCursor::pos());
            int distance = (destPos - m_startDragPos).manhattanLength();
            KBookmarkActionInterface *action = dynamic_cast<KBookmarkActionInterface *>(actionAt(destPos));

            if (action)
            {
                if (action->bookmark().isGroup())
                {
                    if (mouseEvent->button() == Qt::MiddleButton)
                    {
                        BookmarkManager::self()->owner()->loadBookmarkFolder(action->bookmark());
                    }
                    else if (distance < QApplication::startDragDistance())
                    {
                        KBookmarkActionMenu *menu = dynamic_cast<KBookmarkActionMenu *>(actionAt(m_startDragPos));
                        QPoint actionPos = mapToGlobal(widgetForAction(menu)->pos());
                        menu->menu()->popup(QPoint(actionPos.x(), actionPos.y() + widgetForAction(menu)->height()));
                    }
                }
                else
                {
                    if (!action->bookmark().isNull() && !action->bookmark().isSeparator())
                    {
                        if (mouseEvent->button() == Qt::MiddleButton)
                        {
                            BookmarkManager::self()->owner()->loadBookmarkInNewTab(action->bookmark());
                        }
                    }
                }
            }
        }
        break;

        default:
            break;
        }
    }

    return QObject::eventFilter(watched, event);
}
Example #23
0
bool BE::Contacts::eventFilter(QObject *o, QEvent *e)
{
    if (o == m_ui->filter) {
        if (e->type() == QEvent::KeyPress)
        if (static_cast<QKeyEvent*>(e)->key() == Qt::Key_Down)
            m_ui->contacts->setFocus();
        return false;
    }

    if (o == m_ui->contacts) {
        if (e->type() == QEvent::KeyPress) {
            QKeyEvent *ke = static_cast<QKeyEvent*>(e);
            if (ke->key() == Qt::Key_Up && !m_ui->contacts->currentIndex().row()) {
            m_ui->filter->setFocus();
            return true;
            } else if (ke->key() == Qt::Key_Delete) {
                removeCurrentContact();
                return true;
            }
        }
        return false;
    }

    if (!m_currentContact)
        return false;
    switch (e->type()) {
    case QEvent::DragEnter:
    case QEvent::DragMove:
    case QEvent::Drop: {
        if (o != m_ui2->photo)
            return false;
        QDropEvent *de = static_cast<QDropEvent*>(e);
        if (!de->mimeData())
            return false;
        QList<QUrl> urls = de->mimeData()->urls();
        if (urls.isEmpty())
            return false;
        QUrl url = urls.first();
        if (
#if QT_VERSION >= QT_VERSION_CHECK(4, 8, 0)
                url.isLocalFile()
#else
                (url.scheme() == QLatin1String("file"))
#endif
                && QImageReader(url.path()).canRead()) {
            if (e->type() == QEvent::Drop)
                importPhoto(url.path());
            else
                de->acceptProposedAction();
        }
        return false;
    }
    case QEvent::KeyPress: {
        const int key = static_cast<QKeyEvent*>(e)->key();
        if (key == Qt::Key_Delete && o == m_ui2->photo) { // reset photo
            if (m_currentContact)
                m_currentContact->setData(QString(), Gui::AbookAddressbook::Photo);
            m_ui2->photo->setPixmap(m_incognitoPic);
        }
        else if (key == Qt::Key_Escape && o != m_ui2->photo)
        if (QLabel *l = qobject_cast<QLabel*>(o)) {
            setText(l, l->text());
            return true; // prevent closing the dialog!
        }
    }
    default:
        return false;
    }
    return false;
}
Example #24
0
bool MainWindow::eventFilter(QObject *watched, QEvent *event)
{
    switch (event->type())
    {
        case QEvent::KeyRelease:
        {
            QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
            //int mask = Qt::ControlModifier | Qt::ShiftModifier | Qt::AltModifier;

            //if(keyEvent->modifiers() == mask)
            //{
            //}

            break;
        }
        case QEvent::DragEnter:
        {


            QDragEnterEvent *dragEnterEvent = static_cast<QDragEnterEvent*>(event);
            const QMimeData* mimeData = dragEnterEvent->mimeData();

            // check for our needed mime type, here a file or a list of files
            if (!mimeData->hasUrls())
                break;

            QList<QUrl> urlList = mimeData->urls();

            for (int i = 0; i < urlList.size(); ++i)
            {
                qDebug() << urlList.at(i).toString();
                if (urlList.at(i).toString().endsWith(".torrent"))
                {
                    dragEnterEvent->acceptProposedAction();
                    return true;
                }
            }

            break;
        }
        case QEvent::Drop:
        {
            QDropEvent *dropEvent = static_cast<QDropEvent*>(event);
            const QMimeData* mimeData = dropEvent->mimeData();

            // check for our needed mime type, here a file or a list of files
            if (!mimeData->hasUrls())
                break;

            QStringList pathList;
            QList<QUrl> urlList = mimeData->urls();

            // extract the local paths of the files
            for (int i = 0; i < urlList.size(); ++i)
            {
                pathList.append(urlList.at(i).toLocalFile());
            }

            //addTorrents(pathList);
            return true;
        }
        default:
            break;
    }

    return QObject::eventFilter(watched, event);
}
Example #25
0
bool MainWindow::eventFilter(QObject *watched, QEvent *event) {
    if (watched == ui->iconLabel) {
        QFileInfo file("icon_create.py");
        if(!file.exists())
        {
            trcDebug("icon_create.py does not exist!");
            return false;
        }
        if (event->type() == QEvent::DragEnter) {
            // [[2]]: 当拖放时鼠标进入label时, label接受拖放的动作
            QDragEnterEvent *dee = dynamic_cast<QDragEnterEvent *>(event);
            dee->acceptProposedAction();
            return true;
        } else if (event->type() == QEvent::Drop) {
            // [[3]]: 当放操作发生后, 取得拖放的数据
            QDropEvent *de = dynamic_cast<QDropEvent *>(event);
            QList<QUrl> urls = de->mimeData()->urls();

            if (urls.isEmpty()) { return true; }
            QString path = urls.first().toLocalFile();

            // [[4]]: 在label上显示拖放的图片
            QImage image(path); // QImage对I/O优化过, QPixmap对显示优化
            if (!image.isNull()) {
                ui->iconLabel->setPixmap(QPixmap::fromImage(image));
                QStringList arguments;
                QFileInfo file(path);
                arguments<<"icon_create.py"<<file.absolutePath()<<file.fileName();
                cmd.start("python",arguments);//非阻塞
                int flag = cmd.execute("python",arguments);//阻塞
                switch (flag) {
                case -1:
                   ui->statusBar->showMessage("The process crashes");
                    break;
                case -2:
                    ui->statusBar->showMessage("The process cannot be started");
                default:
                    ui->statusBar->showMessage("Icon to create success");
                    break;
                }
            }

            return true;
        }
    }else if(watched == ui->screenshotLabel){
        QFileInfo file("screenshot_create.py");
        if(!file.exists())
        {
            trcDebug("screenshot_create.py does not exist!");
            return false;
        }
        if (event->type() == QEvent::DragEnter) {
            // [[2]]: 当拖放时鼠标进入label时, label接受拖放的动作
            QDragEnterEvent *dee = dynamic_cast<QDragEnterEvent *>(event);
            dee->acceptProposedAction();
            return true;
        } else if (event->type() == QEvent::Drop) {
            // [[3]]: 当放操作发生后, 取得拖放的数据
            QDropEvent *de = dynamic_cast<QDropEvent *>(event);
            QList<QUrl> urls = de->mimeData()->urls();

            if (urls.isEmpty()) { return true; }
            foreach (QUrl file, urls) {
                QString path = file.toLocalFile();

                // [[4]]: 在label上显示拖放的图片
                QImage image(path); // QImage对I/O优化过, QPixmap对显示优化
                if (!image.isNull()) {
                    ui->screenshotLabel->setPixmap(QPixmap::fromImage(image));

                    QStringList arguments;
                    QFileInfo file(path);
                    arguments<<"screenshot_create.py"<<file.absolutePath()<<file.fileName();
                    cmd.execute("python",arguments);//非阻塞
                    int flag = cmd.execute("python",arguments);//阻塞
                    switch (flag) {
                    case -1:
                       ui->statusBar->showMessage("The process crashes");
                        break;
                    case -2:
                        ui->statusBar->showMessage("The process cannot be started");
                    default:
                        ui->statusBar->showMessage("Icon to create success");
                        break;
                    }
                }

            }