diff options
Diffstat (limited to 'src/gui/guikernel')
-rw-r--r-- | src/gui/guikernel/guikernel.pri | 13 | ||||
-rw-r--r-- | src/gui/guikernel/qdnd.cpp | 491 | ||||
-rw-r--r-- | src/gui/guikernel/qdnd_p.h | 336 | ||||
-rw-r--r-- | src/gui/guikernel/qdnd_qpa.cpp | 426 | ||||
-rw-r--r-- | src/gui/guikernel/qdrag.cpp | 359 | ||||
-rw-r--r-- | src/gui/guikernel/qdrag.h | 105 | ||||
-rw-r--r-- | src/gui/guikernel/qkeymapper.cpp | 121 | ||||
-rw-r--r-- | src/gui/guikernel/qkeymapper_p.h | 224 | ||||
-rw-r--r-- | src/gui/guikernel/qkeymapper_qpa.cpp | 77 | ||||
-rw-r--r-- | src/gui/guikernel/qshortcut.cpp | 407 | ||||
-rw-r--r-- | src/gui/guikernel/qshortcut.h | 107 | ||||
-rw-r--r-- | src/gui/guikernel/qshortcutmap.cpp | 897 | ||||
-rw-r--r-- | src/gui/guikernel/qshortcutmap_p.h | 123 |
13 files changed, 1 insertions, 3685 deletions
diff --git a/src/gui/guikernel/guikernel.pri b/src/gui/guikernel/guikernel.pri index 23cb385f9e..7f24adf56c 100644 --- a/src/gui/guikernel/guikernel.pri +++ b/src/gui/guikernel/guikernel.pri @@ -8,30 +8,21 @@ KERNEL_P= guikernel HEADERS += \ guikernel/qclipboard.h \ guikernel/qcursor.h \ - guikernel/qdrag.h \ - guikernel/qdnd_p.h \ guikernel/qevent.h \ guikernel/qevent_p.h \ guikernel/qkeysequence.h \ + guikernel/qkeysequence_p.h \ guikernel/qmime.h \ guikernel/qsessionmanager.h \ - guikernel/qshortcut.h \ - guikernel/qshortcutmap_p.h \ guikernel/qwindowdefs.h \ - guikernel/qkeymapper_p.h SOURCES += \ guikernel/qclipboard.cpp \ guikernel/qcursor.cpp \ - guikernel/qdrag.cpp \ - guikernel/qdnd.cpp \ guikernel/qevent.cpp \ guikernel/qkeysequence.cpp \ guikernel/qmime.cpp \ - guikernel/qshortcut.cpp \ - guikernel/qshortcutmap.cpp \ guikernel/qguivariant.cpp \ - guikernel/qkeymapper.cpp \ qpa { HEADERS += \ @@ -60,10 +51,8 @@ qpa { SOURCES += \ guikernel/qclipboard_qpa.cpp \ guikernel/qcursor_qpa.cpp \ - guikernel/qdnd_qpa.cpp \ guikernel/qgenericpluginfactory_qpa.cpp \ guikernel/qgenericplugin_qpa.cpp \ - guikernel/qkeymapper_qpa.cpp \ guikernel/qeventdispatcher_qpa.cpp \ guikernel/qwindowsysteminterface_qpa.cpp \ guikernel/qplatformintegration_qpa.cpp \ diff --git a/src/gui/guikernel/qdnd.cpp b/src/gui/guikernel/qdnd.cpp deleted file mode 100644 index db79b9042d..0000000000 --- a/src/gui/guikernel/qdnd.cpp +++ /dev/null @@ -1,491 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qplatformdefs.h" - -#include "qbitmap.h" -#include "qdrag.h" -#include "qpixmap.h" -#include "qevent.h" -#include "qfile.h" -#include "qtextcodec.h" -#include "qguiapplication.h" -#include "qpoint.h" -#include "qwidget.h" -#include "qbuffer.h" -#include "qimage.h" -#include "qregexp.h" -#include "qdir.h" -#include "qdnd_p.h" -#include "qimagereader.h" -#include "qimagewriter.h" -#include "qdebug.h" -#include <ctype.h> - -#include <private/qguiapplication_p.h> - -#ifndef QT_NO_DRAGANDDROP - -QT_BEGIN_NAMESPACE - -#ifndef QT_NO_DRAGANDDROP - -//#define QDND_DEBUG - -#ifdef QDND_DEBUG -QString dragActionsToString(Qt::DropActions actions) -{ - QString str; - if (actions == Qt::IgnoreAction) { - if (!str.isEmpty()) - str += " | "; - str += "IgnoreAction"; - } - if (actions & Qt::LinkAction) { - if (!str.isEmpty()) - str += " | "; - str += "LinkAction"; - } - if (actions & Qt::CopyAction) { - if (!str.isEmpty()) - str += " | "; - str += "CopyAction"; - } - if (actions & Qt::MoveAction) { - if (!str.isEmpty()) - str += " | "; - str += "MoveAction"; - } - if ((actions & Qt::TargetMoveAction) == Qt::TargetMoveAction ) { - if (!str.isEmpty()) - str += " | "; - str += "TargetMoveAction"; - } - return str; -} - -QString KeyboardModifiersToString(Qt::KeyboardModifiers moderfies) -{ - QString str; - if (moderfies & Qt::ControlModifier) { - if (!str.isEmpty()) - str += " | "; - str += Qt::ControlModifier; - } - if (moderfies & Qt::AltModifier) { - if (!str.isEmpty()) - str += " | "; - str += Qt::AltModifier; - } - if (moderfies & Qt::ShiftModifier) { - if (!str.isEmpty()) - str += " | "; - str += Qt::ShiftModifier; - } - return str; -} -#endif - - -// the universe's only drag manager -QDragManager *QDragManager::instance = 0; - - -QDragManager::QDragManager() - : QObject(qApp) -{ - Q_ASSERT(!instance); - -#ifdef Q_WS_QWS - currentActionForOverrideCursor = Qt::IgnoreAction; -#endif - object = 0; - beingCancelled = false; - restoreCursor = false; - willDrop = false; - eventLoop = 0; - dropData = new QDropData(); - currentDropTarget = 0; -#ifdef Q_WS_X11 - xdndMimeTransferedPixmapIndex = 0; -#endif -} - - -QDragManager::~QDragManager() -{ -#ifndef QT_NO_CURSOR - if (restoreCursor) - QGuiApplication::restoreOverrideCursor(); -#endif - instance = 0; - delete dropData; -} - -QDragManager *QDragManager::self() -{ - if (!instance && !QApplication::closingDown()) - instance = new QDragManager; - return instance; -} - -QPixmap QDragManager::dragCursor(Qt::DropAction action) const -{ - QDragPrivate * d = dragPrivate(); - if (d && d->customCursors.contains(action)) - return d->customCursors[action]; - else if (action == Qt::MoveAction) - return QGuiApplicationPrivate::instance()->getPixmapCursor(Qt::DragMoveCursor); - else if (action == Qt::CopyAction) - return QGuiApplicationPrivate::instance()->getPixmapCursor(Qt::DragCopyCursor); - else if (action == Qt::LinkAction) - return QGuiApplicationPrivate::instance()->getPixmapCursor(Qt::DragLinkCursor); -#ifdef Q_WS_WIN - else if (action == Qt::IgnoreAction) - return QGuiApplicationPrivate::instance()->getPixmapCursor(Qt::ForbiddenCursor); -#endif - return QPixmap(); -} - -bool QDragManager::hasCustomDragCursors() const -{ - QDragPrivate * d = dragPrivate(); - return d && !d->customCursors.isEmpty(); -} - -Qt::DropAction QDragManager::defaultAction(Qt::DropActions possibleActions, - Qt::KeyboardModifiers modifiers) const -{ -#ifdef QDND_DEBUG - qDebug("QDragManager::defaultAction(Qt::DropActions possibleActions)"); - qDebug("keyboard modifiers : %s", KeyboardModifiersToString(modifiers).latin1()); -#endif - - QDragPrivate *d = dragPrivate(); - Qt::DropAction defaultAction = d ? d->defaultDropAction : Qt::IgnoreAction; - - if (defaultAction == Qt::IgnoreAction) { - //This means that the drag was initiated by QDrag::start and we need to - //preserve the old behavior -#ifdef Q_WS_MAC - defaultAction = Qt::MoveAction; -#else - defaultAction = Qt::CopyAction; -#endif - } - -#ifdef Q_WS_MAC - if (modifiers & Qt::ControlModifier && modifiers & Qt::AltModifier) - defaultAction = Qt::LinkAction; - else if (modifiers & Qt::AltModifier) - defaultAction = Qt::CopyAction; - else if (modifiers & Qt::ControlModifier) - defaultAction = Qt::MoveAction; -#else - if (modifiers & Qt::ControlModifier && modifiers & Qt::ShiftModifier) - defaultAction = Qt::LinkAction; - else if (modifiers & Qt::ControlModifier) - defaultAction = Qt::CopyAction; - else if (modifiers & Qt::ShiftModifier) - defaultAction = Qt::MoveAction; - else if (modifiers & Qt::AltModifier) - defaultAction = Qt::LinkAction; -#endif - - // if the object is set take the list of possibles from it - if (object) - possibleActions = object->d_func()->possible_actions; - -#ifdef QDND_DEBUG - qDebug("possible actions : %s", dragActionsToString(possibleActions).latin1()); -#endif - - // Check if the action determined is allowed - if (!(possibleActions & defaultAction)) { - if (possibleActions & Qt::CopyAction) - defaultAction = Qt::CopyAction; - else if (possibleActions & Qt::MoveAction) - defaultAction = Qt::MoveAction; - else if (possibleActions & Qt::LinkAction) - defaultAction = Qt::LinkAction; - else - defaultAction = Qt::IgnoreAction; - } - -#ifdef QDND_DEBUG - qDebug("default action : %s", dragActionsToString(defaultAction).latin1()); -#endif - - return defaultAction; -} - -void QDragManager::setCurrentTarget(QWidget *target, bool dropped) -{ - if (currentDropTarget == target) - return; - - currentDropTarget = target; - if (!dropped && object) { - object->d_func()->target = target; - emit object->targetChanged(target); - } - -} - -QWidget *QDragManager::currentTarget() -{ - return currentDropTarget; -} - -#endif - -QDropData::QDropData() - : QInternalMimeData() -{ -} - -QDropData::~QDropData() -{ -} -#endif // QT_NO_DRAGANDDROP - -#if !(defined(QT_NO_DRAGANDDROP) && defined(QT_NO_CLIPBOARD)) - -static QStringList imageReadMimeFormats() -{ - QStringList formats; - QList<QByteArray> imageFormats = QImageReader::supportedImageFormats(); - for (int i = 0; i < imageFormats.size(); ++i) { - QString format = QLatin1String("image/"); - format += QString::fromLatin1(imageFormats.at(i).toLower()); - formats.append(format); - } - - //put png at the front because it is best - int pngIndex = formats.indexOf(QLatin1String("image/png")); - if (pngIndex != -1 && pngIndex != 0) - formats.move(pngIndex, 0); - - return formats; -} - - -static QStringList imageWriteMimeFormats() -{ - QStringList formats; - QList<QByteArray> imageFormats = QImageWriter::supportedImageFormats(); - for (int i = 0; i < imageFormats.size(); ++i) { - QString format = QLatin1String("image/"); - format += QString::fromLatin1(imageFormats.at(i).toLower()); - formats.append(format); - } - - //put png at the front because it is best - int pngIndex = formats.indexOf(QLatin1String("image/png")); - if (pngIndex != -1 && pngIndex != 0) - formats.move(pngIndex, 0); - - return formats; -} - -QInternalMimeData::QInternalMimeData() - : QMimeData() -{ -} - -QInternalMimeData::~QInternalMimeData() -{ -} - -bool QInternalMimeData::hasFormat(const QString &mimeType) const -{ - bool foundFormat = hasFormat_sys(mimeType); - if (!foundFormat && mimeType == QLatin1String("application/x-qt-image")) { - QStringList imageFormats = imageReadMimeFormats(); - for (int i = 0; i < imageFormats.size(); ++i) { - if ((foundFormat = hasFormat_sys(imageFormats.at(i)))) - break; - } - } - return foundFormat; -} - -QStringList QInternalMimeData::formats() const -{ - QStringList realFormats = formats_sys(); - if (!realFormats.contains(QLatin1String("application/x-qt-image"))) { - QStringList imageFormats = imageReadMimeFormats(); - for (int i = 0; i < imageFormats.size(); ++i) { - if (realFormats.contains(imageFormats.at(i))) { - realFormats += QLatin1String("application/x-qt-image"); - break; - } - } - } - return realFormats; -} - -QVariant QInternalMimeData::retrieveData(const QString &mimeType, QVariant::Type type) const -{ - QVariant data = retrieveData_sys(mimeType, type); - if (mimeType == QLatin1String("application/x-qt-image")) { - if (data.isNull() || (data.type() == QVariant::ByteArray && data.toByteArray().isEmpty())) { - // try to find an image - QStringList imageFormats = imageReadMimeFormats(); - for (int i = 0; i < imageFormats.size(); ++i) { - data = retrieveData_sys(imageFormats.at(i), type); - if (data.isNull() || (data.type() == QVariant::ByteArray && data.toByteArray().isEmpty())) - continue; - break; - } - } - // we wanted some image type, but all we got was a byte array. Convert it to an image. - if (data.type() == QVariant::ByteArray - && (type == QVariant::Image || type == QVariant::Pixmap || type == QVariant::Bitmap)) - data = QImage::fromData(data.toByteArray()); - - } else if (mimeType == QLatin1String("application/x-color") && data.type() == QVariant::ByteArray) { - QColor c; - QByteArray ba = data.toByteArray(); - if (ba.size() == 8) { - ushort * colBuf = (ushort *)ba.data(); - c.setRgbF(qreal(colBuf[0]) / qreal(0xFFFF), - qreal(colBuf[1]) / qreal(0xFFFF), - qreal(colBuf[2]) / qreal(0xFFFF), - qreal(colBuf[3]) / qreal(0xFFFF)); - data = c; - } else { - qWarning("Qt: Invalid color format"); - } - } else if (data.type() != type && data.type() == QVariant::ByteArray) { - // try to use mime data's internal conversion stuf. - QInternalMimeData *that = const_cast<QInternalMimeData *>(this); - that->setData(mimeType, data.toByteArray()); - data = QMimeData::retrieveData(mimeType, type); - that->clear(); - } - return data; -} - -bool QInternalMimeData::canReadData(const QString &mimeType) -{ - return imageReadMimeFormats().contains(mimeType); -} - -// helper functions for rendering mimedata to the system, this is needed because QMimeData is in core. -QStringList QInternalMimeData::formatsHelper(const QMimeData *data) -{ - QStringList realFormats = data->formats(); - if (realFormats.contains(QLatin1String("application/x-qt-image"))) { - // add all supported image formats - QStringList imageFormats = imageWriteMimeFormats(); - for (int i = 0; i < imageFormats.size(); ++i) { - if (!realFormats.contains(imageFormats.at(i))) - realFormats.append(imageFormats.at(i)); - } - } - return realFormats; -} - -bool QInternalMimeData::hasFormatHelper(const QString &mimeType, const QMimeData *data) -{ - - bool foundFormat = data->hasFormat(mimeType); - if (!foundFormat) { - if (mimeType == QLatin1String("application/x-qt-image")) { - // check all supported image formats - QStringList imageFormats = imageWriteMimeFormats(); - for (int i = 0; i < imageFormats.size(); ++i) { - if ((foundFormat = data->hasFormat(imageFormats.at(i)))) - break; - } - } else if (mimeType.startsWith(QLatin1String("image/"))) { - return data->hasImage() && imageWriteMimeFormats().contains(mimeType); - } - } - return foundFormat; -} - -QByteArray QInternalMimeData::renderDataHelper(const QString &mimeType, const QMimeData *data) -{ - QByteArray ba; - if (mimeType == QLatin1String("application/x-color")) { - /* QMimeData can only provide colors as QColor or the name - of a color as a QByteArray or a QString. So we need to do - the conversion to application/x-color here. - The application/x-color format is : - type: application/x-color - format: 16 - data[0]: red - data[1]: green - data[2]: blue - data[3]: opacity - */ - ba.resize(8); - ushort * colBuf = (ushort *)ba.data(); - QColor c = qvariant_cast<QColor>(data->colorData()); - colBuf[0] = ushort(c.redF() * 0xFFFF); - colBuf[1] = ushort(c.greenF() * 0xFFFF); - colBuf[2] = ushort(c.blueF() * 0xFFFF); - colBuf[3] = ushort(c.alphaF() * 0xFFFF); - } else { - ba = data->data(mimeType); - if (ba.isEmpty()) { - if (mimeType == QLatin1String("application/x-qt-image") && data->hasImage()) { - QImage image = qvariant_cast<QImage>(data->imageData()); - QBuffer buf(&ba); - buf.open(QBuffer::WriteOnly); - // would there not be PNG ?? - image.save(&buf, "PNG"); - } else if (mimeType.startsWith(QLatin1String("image/")) && data->hasImage()) { - QImage image = qvariant_cast<QImage>(data->imageData()); - QBuffer buf(&ba); - buf.open(QBuffer::WriteOnly); - image.save(&buf, mimeType.mid(mimeType.indexOf(QLatin1Char('/')) + 1).toLatin1().toUpper()); - } - } - } - return ba; -} - -#endif // QT_NO_DRAGANDDROP && QT_NO_CLIPBOARD - -QT_END_NAMESPACE diff --git a/src/gui/guikernel/qdnd_p.h b/src/gui/guikernel/qdnd_p.h deleted file mode 100644 index 754366637c..0000000000 --- a/src/gui/guikernel/qdnd_p.h +++ /dev/null @@ -1,336 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QDND_P_H -#define QDND_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of other Qt classes. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "QtCore/qobject.h" -#include "QtCore/qmap.h" -#include "QtGui/qmime.h" -#include "QtGui/qdrag.h" -#include "QtGui/qpixmap.h" -#include "QtGui/qcursor.h" -#include "QtCore/qpoint.h" -#include "private/qobject_p.h" -#ifdef Q_WS_MAC -# include "private/qt_mac_p.h" -#endif - -#if defined(Q_WS_WIN) -# include <qt_windows.h> -# include <objidl.h> -#endif - -QT_BEGIN_NAMESPACE - -class QEventLoop; - -#if !(defined(QT_NO_DRAGANDDROP) && defined(QT_NO_CLIPBOARD)) - -class Q_GUI_EXPORT QInternalMimeData : public QMimeData -{ - Q_OBJECT -public: - QInternalMimeData(); - ~QInternalMimeData(); - - bool hasFormat(const QString &mimeType) const; - QStringList formats() const; - static bool canReadData(const QString &mimeType); - - - static QStringList formatsHelper(const QMimeData *data); - static bool hasFormatHelper(const QString &mimeType, const QMimeData *data); - static QByteArray renderDataHelper(const QString &mimeType, const QMimeData *data); - -protected: - QVariant retrieveData(const QString &mimeType, QVariant::Type type) const; - - virtual bool hasFormat_sys(const QString &mimeType) const = 0; - virtual QStringList formats_sys() const = 0; - virtual QVariant retrieveData_sys(const QString &mimeType, QVariant::Type type) const = 0; -}; - -#ifdef Q_WS_WIN -class QOleDataObject : public IDataObject -{ -public: - explicit QOleDataObject(QMimeData *mimeData); - virtual ~QOleDataObject(); - - void releaseQt(); - const QMimeData *mimeData() const; - DWORD reportedPerformedEffect() const; - - // IUnknown methods - STDMETHOD(QueryInterface)(REFIID riid, void FAR* FAR* ppvObj); - STDMETHOD_(ULONG,AddRef)(void); - STDMETHOD_(ULONG,Release)(void); - - // IDataObject methods - STDMETHOD(GetData)(LPFORMATETC pformatetcIn, LPSTGMEDIUM pmedium); - STDMETHOD(GetDataHere)(LPFORMATETC pformatetc, LPSTGMEDIUM pmedium); - STDMETHOD(QueryGetData)(LPFORMATETC pformatetc); - STDMETHOD(GetCanonicalFormatEtc)(LPFORMATETC pformatetc, LPFORMATETC pformatetcOut); - STDMETHOD(SetData)(LPFORMATETC pformatetc, STGMEDIUM FAR * pmedium, - BOOL fRelease); - STDMETHOD(EnumFormatEtc)(DWORD dwDirection, LPENUMFORMATETC FAR* ppenumFormatEtc); - STDMETHOD(DAdvise)(FORMATETC FAR* pFormatetc, DWORD advf, - LPADVISESINK pAdvSink, DWORD FAR* pdwConnection); - STDMETHOD(DUnadvise)(DWORD dwConnection); - STDMETHOD(EnumDAdvise)(LPENUMSTATDATA FAR* ppenumAdvise); - -private: - ULONG m_refs; - QPointer<QMimeData> data; - int CF_PERFORMEDDROPEFFECT; - DWORD performedEffect; -}; - -class QOleEnumFmtEtc : public IEnumFORMATETC -{ -public: - explicit QOleEnumFmtEtc(const QVector<FORMATETC> &fmtetcs); - explicit QOleEnumFmtEtc(const QVector<LPFORMATETC> &lpfmtetcs); - virtual ~QOleEnumFmtEtc(); - - bool isNull() const; - - // IUnknown methods - STDMETHOD(QueryInterface)(REFIID riid, void FAR* FAR* ppvObj); - STDMETHOD_(ULONG,AddRef)(void); - STDMETHOD_(ULONG,Release)(void); - - // IEnumFORMATETC methods - STDMETHOD(Next)(ULONG celt, LPFORMATETC rgelt, ULONG FAR* pceltFetched); - STDMETHOD(Skip)(ULONG celt); - STDMETHOD(Reset)(void); - STDMETHOD(Clone)(LPENUMFORMATETC FAR* newEnum); - -private: - bool copyFormatEtc(LPFORMATETC dest, LPFORMATETC src) const; - - ULONG m_dwRefs; - ULONG m_nIndex; - QVector<LPFORMATETC> m_lpfmtetcs; - bool m_isNull; -}; - -#endif - -#endif //QT_NO_DRAGANDDROP && QT_NO_CLIPBOARD - -#ifndef QT_NO_DRAGANDDROP - -class QDragPrivate : public QObjectPrivate -{ -public: - QWidget *source; - QWidget *target; - QMimeData *data; - QPixmap pixmap; - QPoint hotspot; - Qt::DropActions possible_actions; - Qt::DropAction executed_action; - QMap<Qt::DropAction, QPixmap> customCursors; - Qt::DropAction defaultDropAction; -}; - -class QDropData : public QInternalMimeData -{ - Q_OBJECT -public: - QDropData(); - ~QDropData(); - -protected: - bool hasFormat_sys(const QString &mimeType) const; - QStringList formats_sys() const; - QVariant retrieveData_sys(const QString &mimeType, QVariant::Type type) const; - -#if defined(Q_WS_WIN) -public: - LPDATAOBJECT currentDataObject; -#endif -}; - -class QDragManager: public QObject { - Q_OBJECT - - QDragManager(); - ~QDragManager(); - // only friend classes can use QDragManager. - friend class QDrag; - friend class QDragMoveEvent; - friend class QDropEvent; - friend class QApplication; -#ifdef Q_WS_MAC - friend class QWidgetPrivate; //dnd is implemented here -#endif - - bool eventFilter(QObject *, QEvent *); - void timerEvent(QTimerEvent*); - -public: - Qt::DropAction drag(QDrag *); - - void cancel(bool deleteSource = true); - void move(const QPoint &); - void drop(); - void updatePixmap(); - QWidget *source() const { return object ? object->d_func()->source : 0; } - QDragPrivate *dragPrivate() const { return object ? object->d_func() : 0; } - static QDragPrivate *dragPrivate(QDrag *drag) { return drag ? drag->d_func() : 0; } - - static QDragManager *self(); - Qt::DropAction defaultAction(Qt::DropActions possibleActions, - Qt::KeyboardModifiers modifiers) const; - - QDrag *object; - - void updateCursor(); - - bool beingCancelled; - bool restoreCursor; - bool willDrop; - QEventLoop *eventLoop; - - QPixmap dragCursor(Qt::DropAction action) const; - - bool hasCustomDragCursors() const; - - QDropData *dropData; - - void emitActionChanged(Qt::DropAction newAction) { if (object) emit object->actionChanged(newAction); } - - void setCurrentTarget(QWidget *target, bool dropped = false); - QWidget *currentTarget(); - -#ifdef Q_WS_X11 - QPixmap xdndMimeTransferedPixmap[2]; - int xdndMimeTransferedPixmapIndex; -#endif - -private: -#if defined(Q_WS_QWS) || defined(Q_WS_QPA) - Qt::DropAction currentActionForOverrideCursor; -#endif -#ifdef Q_OS_SYMBIAN -#ifndef QT_NO_CURSOR - QCursor overrideCursor; -#endif -#endif - QWidget *currentDropTarget; - - static QDragManager *instance; - Q_DISABLE_COPY(QDragManager) -}; - - -#if defined(Q_WS_WIN) - -class QOleDropTarget : public IDropTarget -{ -public: - QOleDropTarget(QWidget* w); - virtual ~QOleDropTarget() {} - - void releaseQt(); - - // IUnknown methods - STDMETHOD(QueryInterface)(REFIID riid, void FAR* FAR* ppvObj); - STDMETHOD_(ULONG, AddRef)(void); - STDMETHOD_(ULONG, Release)(void); - - // IDropTarget methods - STDMETHOD(DragEnter)(LPDATAOBJECT pDataObj, DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect); - STDMETHOD(DragOver)(DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect); - STDMETHOD(DragLeave)(); - STDMETHOD(Drop)(LPDATAOBJECT pDataObj, DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect); - -private: - ULONG m_refs; - QWidget* widget; - QPointer<QWidget> currentWidget; - QRect answerRect; - QPoint lastPoint; - DWORD chosenEffect; - DWORD lastKeyState; - - void sendDragEnterEvent(QWidget *to, DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect); -}; - -#endif - -#if defined (Q_WS_MAC) -class QCocoaDropData : public QInternalMimeData -{ - Q_OBJECT -public: - QCocoaDropData(CFStringRef pasteboard); - ~QCocoaDropData(); - -protected: - bool hasFormat_sys(const QString &mimeType) const; - QStringList formats_sys() const; - QVariant retrieveData_sys(const QString &mimeType, QVariant::Type type) const; -public: - CFStringRef dropPasteboard; -}; -#endif - -#endif // !QT_NO_DRAGANDDROP - - -QT_END_NAMESPACE - -#endif // QDND_P_H diff --git a/src/gui/guikernel/qdnd_qpa.cpp b/src/gui/guikernel/qdnd_qpa.cpp deleted file mode 100644 index 82e8d580ae..0000000000 --- a/src/gui/guikernel/qdnd_qpa.cpp +++ /dev/null @@ -1,426 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qguiapplication.h" - -#ifndef QT_NO_DRAGANDDROP - -#include "qwidget.h" -#include "qdatetime.h" -#include "qbitmap.h" -#include "qcursor.h" -#include "qevent.h" -#include "qpainter.h" -#include "qdnd_p.h" - -QT_BEGIN_NAMESPACE - -QT_USE_NAMESPACE - -static QPixmap *defaultPm = 0; -static const int default_pm_hotx = -2; -static const int default_pm_hoty = -16; -static const char *const default_pm[] = { -"13 9 3 1", -". c None", -" c #000000", -"X c #FFFFFF", -"X X X X X X X", -" X X X X X X ", -"X ......... X", -" X.........X ", -"X ......... X", -" X.........X ", -"X ......... X", -" X X X X X X ", -"X X X X X X X", -}; - -// Shift/Ctrl handling, and final drop status -static Qt::DropAction global_accepted_action = Qt::CopyAction; -static Qt::DropActions possible_actions = Qt::IgnoreAction; - - -// static variables in place of a proper cross-process solution -static QDrag *drag_object; -static bool qt_qws_dnd_dragging = false; - - -static Qt::KeyboardModifiers oldstate; - -class QShapedPixmapWidget : public QWidget { - QPixmap pixmap; -public: - QShapedPixmapWidget() : - QWidget(0, Qt::Tool | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint) - { - // ### Temporary workaround for 4.2-rc1!!! To prevent flickering when - // using drag'n drop in a client application. (task 126956) - // setAttribute() should be done unconditionally! - // if (QApplication::type() == QApplication::GuiServer) - setAttribute(Qt::WA_TransparentForMouseEvents); - } - - void setPixmap(QPixmap pm) - { - pixmap = pm; - if (!pixmap.mask().isNull()) { - setMask(pixmap.mask()); - } else { - clearMask(); - } - resize(pm.width(),pm.height()); - } - - void paintEvent(QPaintEvent*) - { - QPainter p(this); - p.drawPixmap(0,0,pixmap); - } -}; - - -static QShapedPixmapWidget *qt_qws_dnd_deco = 0; - - -void QDragManager::updatePixmap() -{ - if (qt_qws_dnd_deco) { - QPixmap pm; - QPoint pm_hot(default_pm_hotx,default_pm_hoty); - if (drag_object) { - pm = drag_object->pixmap(); - if (!pm.isNull()) - pm_hot = drag_object->hotSpot(); - } - if (pm.isNull()) { - if (!defaultPm) - defaultPm = new QPixmap(default_pm); - pm = *defaultPm; - } - qt_qws_dnd_deco->setPixmap(pm); - qt_qws_dnd_deco->move(QCursor::pos()-pm_hot); - if (willDrop) { - qt_qws_dnd_deco->show(); - } else { - qt_qws_dnd_deco->hide(); - } - } -} - -void QDragManager::timerEvent(QTimerEvent *) { } - -void QDragManager::move(const QPoint &) { } - -void QDragManager::updateCursor() -{ -#ifndef QT_NO_CURSOR - if (willDrop) { - if (qt_qws_dnd_deco) - qt_qws_dnd_deco->show(); - if (currentActionForOverrideCursor != global_accepted_action) { - QGuiApplication::changeOverrideCursor(QCursor(dragCursor(global_accepted_action), 0, 0)); - currentActionForOverrideCursor = global_accepted_action; - } - } else { - QCursor *overrideCursor = QGuiApplication::overrideCursor(); - if (!overrideCursor || overrideCursor->shape() != Qt::ForbiddenCursor) { - QGuiApplication::changeOverrideCursor(QCursor(Qt::ForbiddenCursor)); - currentActionForOverrideCursor = Qt::IgnoreAction; - } - if (qt_qws_dnd_deco) - qt_qws_dnd_deco->hide(); - } -#endif -} - - -bool QDragManager::eventFilter(QObject *o, QEvent *e) -{ - if (beingCancelled) { - if (e->type() == QEvent::KeyRelease && static_cast<QKeyEvent*>(e)->key() == Qt::Key_Escape) { - qApp->removeEventFilter(this); - Q_ASSERT(object == 0); - beingCancelled = false; - eventLoop->exit(); - return true; // block the key release - } - return false; - } - - - - if (!o->isWidgetType()) - return false; - - switch(e->type()) { - case QEvent::ShortcutOverride: - // prevent accelerators from firing while dragging - e->accept(); - return true; - - case QEvent::KeyPress: - case QEvent::KeyRelease: - { - QKeyEvent *ke = ((QKeyEvent*)e); - if (ke->key() == Qt::Key_Escape && e->type() == QEvent::KeyPress) { - cancel(); - qApp->removeEventFilter(this); - beingCancelled = false; - eventLoop->exit(); - } else { - updateCursor(); - } - return true; // Eat all key events - } - - case QEvent::MouseButtonPress: - case QEvent::MouseMove: - { - if (!object) { //#### this should not happen - qWarning("QDragManager::eventFilter: No object"); - return true; - } - - QDragManager *manager = QDragManager::self(); - QMimeData *dropData = manager->object ? manager->dragPrivate()->data : manager->dropData; - if (manager->object) - possible_actions = manager->dragPrivate()->possible_actions; - else - possible_actions = Qt::IgnoreAction; - - QMouseEvent *me = (QMouseEvent *)e; - if (me->buttons()) { - Qt::DropAction prevAction = global_accepted_action; - QWidget *cw = QApplication::widgetAt(me->globalPos()); - - // Fix for when we move mouse on to the deco widget - if (qt_qws_dnd_deco && cw == qt_qws_dnd_deco) - cw = object->target(); - - while (cw && !cw->acceptDrops() && !cw->isWindow()) - cw = cw->parentWidget(); - - if (object->target() != cw) { - if (object->target()) { - QDragLeaveEvent dle; - QCoreApplication::sendEvent(object->target(), &dle); - willDrop = false; - global_accepted_action = Qt::IgnoreAction; - updateCursor(); - restoreCursor = true; - object->d_func()->target = 0; - } - if (cw && cw->acceptDrops()) { - object->d_func()->target = cw; - QDragEnterEvent dee(cw->mapFromGlobal(me->globalPos()), possible_actions, dropData, - me->buttons(), me->modifiers()); - QCoreApplication::sendEvent(object->target(), &dee); - willDrop = dee.isAccepted() && dee.dropAction() != Qt::IgnoreAction; - global_accepted_action = willDrop ? dee.dropAction() : Qt::IgnoreAction; - updateCursor(); - restoreCursor = true; - } - } else if (cw) { - QDragMoveEvent dme(cw->mapFromGlobal(me->globalPos()), possible_actions, dropData, - me->buttons(), me->modifiers()); - if (global_accepted_action != Qt::IgnoreAction) { - dme.setDropAction(global_accepted_action); - dme.accept(); - } - QCoreApplication::sendEvent(cw, &dme); - willDrop = dme.isAccepted(); - global_accepted_action = willDrop ? dme.dropAction() : Qt::IgnoreAction; - updatePixmap(); - updateCursor(); - } - if (global_accepted_action != prevAction) - emitActionChanged(global_accepted_action); - } - return true; // Eat all mouse events - } - - case QEvent::MouseButtonRelease: - { - qApp->removeEventFilter(this); - if (restoreCursor) { - willDrop = false; -#ifndef QT_NO_CURSOR - QGuiApplication::restoreOverrideCursor(); -#endif - restoreCursor = false; - } - if (object && object->target()) { - QMouseEvent *me = (QMouseEvent *)e; - - QDragManager *manager = QDragManager::self(); - QMimeData *dropData = manager->object ? manager->dragPrivate()->data : manager->dropData; - - QDropEvent de(object->target()->mapFromGlobal(me->globalPos()), possible_actions, dropData, - me->buttons(), me->modifiers()); - QCoreApplication::sendEvent(object->target(), &de); - if (de.isAccepted()) - global_accepted_action = de.dropAction(); - else - global_accepted_action = Qt::IgnoreAction; - - if (object) - object->deleteLater(); - drag_object = object = 0; - } - eventLoop->exit(); - return true; // Eat all mouse events - } - - default: - break; - } - - return false; -} - -Qt::DropAction QDragManager::drag(QDrag *o) -{ - if (object == o || !o || !o->source()) - return Qt::IgnoreAction; - - if (object) { - cancel(); - qApp->removeEventFilter(this); - beingCancelled = false; - } - - object = drag_object = o; - qt_qws_dnd_deco = new QShapedPixmapWidget(); - oldstate = Qt::NoModifier; // #### Should use state that caused the drag -// drag_mode = mode; - - willDrop = false; - updatePixmap(); - updateCursor(); - restoreCursor = true; - object->d_func()->target = 0; - qApp->installEventFilter(this); - - global_accepted_action = Qt::CopyAction; -#ifndef QT_NO_CURSOR - qApp->setOverrideCursor(Qt::ArrowCursor); - restoreCursor = true; - updateCursor(); -#endif - - qt_qws_dnd_dragging = true; - - eventLoop = new QEventLoop; - (void) eventLoop->exec(); - delete eventLoop; - eventLoop = 0; - - delete qt_qws_dnd_deco; - qt_qws_dnd_deco = 0; - qt_qws_dnd_dragging = false; - - - return global_accepted_action; -} - - -void QDragManager::cancel(bool deleteSource) -{ -// qDebug("QDragManager::cancel"); - beingCancelled = true; - - if (object->target()) { - QDragLeaveEvent dle; - QCoreApplication::sendEvent(object->target(), &dle); - } - -#ifndef QT_NO_CURSOR - if (restoreCursor) { - QGuiApplication::restoreOverrideCursor(); - restoreCursor = false; - } -#endif - - if (drag_object) { - if (deleteSource) - object->deleteLater(); - drag_object = object = 0; - } - - delete qt_qws_dnd_deco; - qt_qws_dnd_deco = 0; - - global_accepted_action = Qt::IgnoreAction; -} - - -void QDragManager::drop() -{ -} - -QVariant QDropData::retrieveData_sys(const QString &mimetype, QVariant::Type type) const -{ - if (!drag_object) - return QVariant(); - QByteArray data = drag_object->mimeData()->data(mimetype); - if (type == QVariant::String) - return QString::fromUtf8(data); - return data; -} - -bool QDropData::hasFormat_sys(const QString &format) const -{ - return formats().contains(format); -} - -QStringList QDropData::formats_sys() const -{ - if (drag_object) - return drag_object->mimeData()->formats(); - return QStringList(); -} - - -#endif // QT_NO_DRAGANDDROP - - -QT_END_NAMESPACE diff --git a/src/gui/guikernel/qdrag.cpp b/src/gui/guikernel/qdrag.cpp deleted file mode 100644 index d8d14cb45c..0000000000 --- a/src/gui/guikernel/qdrag.cpp +++ /dev/null @@ -1,359 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <qwidget.h> -#include <qdrag.h> -#include <qpixmap.h> -#include <qpoint.h> -#include "qdnd_p.h" - -#ifndef QT_NO_DRAGANDDROP - -QT_BEGIN_NAMESPACE - -/*! - \class QDrag - \brief The QDrag class provides support for MIME-based drag and drop data - transfer. - - Drag and drop is an intuitive way for users to copy or move data around in an - application, and is used in many desktop environments as a mechanism for copying - data between applications. Drag and drop support in Qt is centered around the - QDrag class that handles most of the details of a drag and drop operation. - - The data to be transferred by the drag and drop operation is contained in a - QMimeData object. This is specified with the setMimeData() function in the - following way: - - \snippet doc/src/snippets/dragging/mainwindow.cpp 1 - - Note that setMimeData() assigns ownership of the QMimeData object to the - QDrag object. The QDrag must be constructed on the heap with a parent QWidget - to ensure that Qt can clean up after the drag and drop operation has been - completed. - - A pixmap can be used to represent the data while the drag is in - progress, and will move with the cursor to the drop target. This - pixmap typically shows an icon that represents the MIME type of - the data being transferred, but any pixmap can be set with - setPixmap(). The cursor's hot spot can be given a position - relative to the top-left corner of the pixmap with the - setHotSpot() function. The following code positions the pixmap so - that the cursor's hot spot points to the center of its bottom - edge: - - \snippet doc/src/snippets/separations/finalwidget.cpp 2 - - \note On X11, the pixmap may not be able to keep up with the mouse - movements if the hot spot causes the pixmap to be displayed - directly under the cursor. - - The source and target widgets can be found with source() and target(). - These functions are often used to determine whether drag and drop operations - started and finished at the same widget, so that special behavior can be - implemented. - - QDrag only deals with the drag and drop operation itself. It is up to the - developer to decide when a drag operation begins, and how a QDrag object should - be constructed and used. For a given widget, it is often necessary to - reimplement \l{QWidget::mousePressEvent()}{mousePressEvent()} to determine - whether the user has pressed a mouse button, and reimplement - \l{QWidget::mouseMoveEvent()}{mouseMoveEvent()} to check whether a QDrag is - required. - - \sa {Drag and Drop}, QClipboard, QMimeData, QWindowsMime, QMacPasteboardMime, - {Draggable Icons Example}, {Draggable Text Example}, {Drop Site Example}, - {Fridge Magnets Example} -*/ - -/*! - Constructs a new drag object for the widget specified by \a dragSource. -*/ -QDrag::QDrag(QWidget *dragSource) - : QObject(*new QDragPrivate, dragSource) -{ - Q_D(QDrag); - d->source = dragSource; - d->target = 0; - d->data = 0; - d->hotspot = QPoint(-10, -10); - d->possible_actions = Qt::CopyAction; - d->executed_action = Qt::IgnoreAction; - d->defaultDropAction = Qt::IgnoreAction; -} - -/*! - Destroys the drag object. -*/ -QDrag::~QDrag() -{ - Q_D(QDrag); - delete d->data; - QDragManager *manager = QDragManager::self(); - if (manager && manager->object == this) - manager->cancel(false); -} - -/*! - Sets the data to be sent to the given MIME \a data. Ownership of the data is - transferred to the QDrag object. -*/ -void QDrag::setMimeData(QMimeData *data) -{ - Q_D(QDrag); - if (d->data == data) - return; - if (d->data != 0) - delete d->data; - d->data = data; -} - -/*! - Returns the MIME data that is encapsulated by the drag object. -*/ -QMimeData *QDrag::mimeData() const -{ - Q_D(const QDrag); - return d->data; -} - -/*! - Sets \a pixmap as the pixmap used to represent the data in a drag - and drop operation. You can only set a pixmap before the drag is - started. -*/ -void QDrag::setPixmap(const QPixmap &pixmap) -{ - Q_D(QDrag); - d->pixmap = pixmap; -} - -/*! - Returns the pixmap used to represent the data in a drag and drop operation. -*/ -QPixmap QDrag::pixmap() const -{ - Q_D(const QDrag); - return d->pixmap; -} - -/*! - Sets the position of the hot spot relative to the top-left corner of the - pixmap used to the point specified by \a hotspot. - - \bold{Note:} on X11, the pixmap may not be able to keep up with the mouse - movements if the hot spot causes the pixmap to be displayed - directly under the cursor. -*/ -void QDrag::setHotSpot(const QPoint& hotspot) -{ - Q_D(QDrag); - d->hotspot = hotspot; -} - -/*! - Returns the position of the hot spot relative to the top-left corner of the - cursor. -*/ -QPoint QDrag::hotSpot() const -{ - Q_D(const QDrag); - return d->hotspot; -} - -/*! - Returns the source of the drag object. This is the widget where the drag - and drop operation originated. -*/ -QWidget *QDrag::source() const -{ - Q_D(const QDrag); - return d->source; -} - -/*! - Returns the target of the drag and drop operation. This is the widget where - the drag object was dropped. -*/ -QWidget *QDrag::target() const -{ - Q_D(const QDrag); - return d->target; -} - -/*! - \since 4.3 - - Starts the drag and drop operation and returns a value indicating the requested - drop action when it is completed. The drop actions that the user can choose - from are specified in \a supportedActions. The default proposed action will be selected - among the allowed actions in the following order: Move, Copy and Link. - - \bold{Note:} On Linux and Mac OS X, the drag and drop operation - can take some time, but this function does not block the event - loop. Other events are still delivered to the application while - the operation is performed. On Windows, the Qt event loop is - blocked while during the operation. -*/ - -Qt::DropAction QDrag::exec(Qt::DropActions supportedActions) -{ - return exec(supportedActions, Qt::IgnoreAction); -} - -/*! - \since 4.3 - - Starts the drag and drop operation and returns a value indicating the requested - drop action when it is completed. The drop actions that the user can choose - from are specified in \a supportedActions. - - The \a defaultDropAction determines which action will be proposed when the user performs a - drag without using modifier keys. - - \bold{Note:} On Linux and Mac OS X, the drag and drop operation - can take some time, but this function does not block the event - loop. Other events are still delivered to the application while - the operation is performed. On Windows, the Qt event loop is - blocked during the operation. However, QDrag::exec() on - Windows causes processEvents() to be called frequently to keep the GUI responsive. - If any loops or operations are called while a drag operation is active, it will block the drag operation. -*/ - -Qt::DropAction QDrag::exec(Qt::DropActions supportedActions, Qt::DropAction defaultDropAction) -{ - Q_D(QDrag); - if (!d->data) { - qWarning("QDrag: No mimedata set before starting the drag"); - return d->executed_action; - } - QDragManager *manager = QDragManager::self(); - d->defaultDropAction = Qt::IgnoreAction; - d->possible_actions = supportedActions; - - if (manager) { - if (defaultDropAction == Qt::IgnoreAction) { - if (supportedActions & Qt::MoveAction) { - d->defaultDropAction = Qt::MoveAction; - } else if (supportedActions & Qt::CopyAction) { - d->defaultDropAction = Qt::CopyAction; - } else if (supportedActions & Qt::LinkAction) { - d->defaultDropAction = Qt::LinkAction; - } - } else { - d->defaultDropAction = defaultDropAction; - } - d->executed_action = manager->drag(this); - } - - return d->executed_action; -} - -/*! - \obsolete - - \bold{Note:} It is recommended to use exec() instead of this function. - - Starts the drag and drop operation and returns a value indicating the requested - drop action when it is completed. The drop actions that the user can choose - from are specified in \a request. Qt::CopyAction is always allowed. - - \bold{Note:} Although the drag and drop operation can take some time, this function - does not block the event loop. Other events are still delivered to the application - while the operation is performed. - - \sa exec() -*/ -Qt::DropAction QDrag::start(Qt::DropActions request) -{ - Q_D(QDrag); - if (!d->data) { - qWarning("QDrag: No mimedata set before starting the drag"); - return d->executed_action; - } - QDragManager *manager = QDragManager::self(); - d->defaultDropAction = Qt::IgnoreAction; - d->possible_actions = request | Qt::CopyAction; - if (manager) - d->executed_action = manager->drag(this); - return d->executed_action; -} - -/*! - Sets the drag \a cursor for the \a action. This allows you - to override the default native cursors. To revert to using the - native cursor for \a action pass in a null QPixmap as \a cursor. - - The \a action can only be CopyAction, MoveAction or LinkAction. - All other values of DropAction are ignored. -*/ -void QDrag::setDragCursor(const QPixmap &cursor, Qt::DropAction action) -{ - Q_D(QDrag); - if (action != Qt::CopyAction && action != Qt::MoveAction && action != Qt::LinkAction) - return; - if (cursor.isNull()) - d->customCursors.remove(action); - else - d->customCursors[action] = cursor; -} - -/*! - \fn void QDrag::actionChanged(Qt::DropAction action) - - This signal is emitted when the \a action associated with the - drag changes. - - \sa targetChanged() -*/ - -/*! - \fn void QDrag::targetChanged(QWidget *newTarget) - - This signal is emitted when the target of the drag and drop - operation changes, with \a newTarget the new target. - - \sa target(), actionChanged() -*/ - -QT_END_NAMESPACE - -#endif // QT_NO_DRAGANDDROP diff --git a/src/gui/guikernel/qdrag.h b/src/gui/guikernel/qdrag.h deleted file mode 100644 index da847898b2..0000000000 --- a/src/gui/guikernel/qdrag.h +++ /dev/null @@ -1,105 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QDRAG_H -#define QDRAG_H - -#include <QtCore/qobject.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -#ifndef QT_NO_DRAGANDDROP -class QMimeData; -class QDragPrivate; -class QWidget; -class QPixmap; -class QPoint; -class QDragManager; - -class Q_GUI_EXPORT QDrag : public QObject -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QDrag) -public: - explicit QDrag(QWidget *dragSource); - ~QDrag(); - - void setMimeData(QMimeData *data); - QMimeData *mimeData() const; - - void setPixmap(const QPixmap &); - QPixmap pixmap() const; - - void setHotSpot(const QPoint &hotspot); - QPoint hotSpot() const; - - QWidget *source() const; - QWidget *target() const; - - Qt::DropAction start(Qt::DropActions supportedActions = Qt::CopyAction); - Qt::DropAction exec(Qt::DropActions supportedActions = Qt::MoveAction); - Qt::DropAction exec(Qt::DropActions supportedActions, Qt::DropAction defaultAction); - - void setDragCursor(const QPixmap &cursor, Qt::DropAction action); - -Q_SIGNALS: - void actionChanged(Qt::DropAction action); - void targetChanged(QWidget *newTarget); - -private: -#ifdef Q_WS_MAC - friend class QWidgetPrivate; -#endif - friend class QDragManager; - Q_DISABLE_COPY(QDrag) -}; - -#endif // QT_NO_DRAGANDDROP - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QDRAG_H diff --git a/src/gui/guikernel/qkeymapper.cpp b/src/gui/guikernel/qkeymapper.cpp deleted file mode 100644 index e38a905ca5..0000000000 --- a/src/gui/guikernel/qkeymapper.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include "qapplication.h" - -#include <private/qobject_p.h> -#include "qkeymapper_p.h" -#include <qwidget.h> - -QT_BEGIN_NAMESPACE - -/*! - \class QKeyMapper - \since 4.2 - \internal - - \sa QObject -*/ - -/*! - Constructs a new key mapper. -*/ -QKeyMapper::QKeyMapper() - : QObject(*new QKeyMapperPrivate, 0) -{ -} - -/*! - Destroys the key mapper. -*/ -QKeyMapper::~QKeyMapper() -{ -} - -QList<int> QKeyMapper::possibleKeys(QKeyEvent *e) -{ - QList<int> result; - - if (!e->nativeScanCode()) { - if (e->key() && (e->key() != Qt::Key_unknown)) - result << int(e->key() + e->modifiers()); - else if (!e->text().isEmpty()) - result << int(e->text().at(0).unicode() + e->modifiers()); - return result; - } - - return instance()->d_func()->possibleKeys(e); -} - -extern bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event); // in qapplication_*.cpp -void QKeyMapper::changeKeyboard() -{ - instance()->d_func()->clearMappings(); - - // ## TODO: Support KeyboardLayoutChange on QPA -#if 0 - // inform all toplevel widgets of the change - QEvent e(QEvent::KeyboardLayoutChange); - QWidgetList list = QApplication::topLevelWidgets(); - for (int i = 0; i < list.size(); ++i) { - QWidget *w = list.at(i); - qt_sendSpontaneousEvent(w, &e); - } -#endif -} - -Q_GLOBAL_STATIC(QKeyMapper, keymapper) -/*! - Returns the pointer to the single instance of QKeyMapper in the application. - If none yet exists, the function ensures that one is created. -*/ -QKeyMapper *QKeyMapper::instance() -{ - return keymapper(); -} - -QKeyMapperPrivate *qt_keymapper_private() -{ - return QKeyMapper::instance()->d_func(); -} - -QT_END_NAMESPACE diff --git a/src/gui/guikernel/qkeymapper_p.h b/src/gui/guikernel/qkeymapper_p.h deleted file mode 100644 index ec2d8492fe..0000000000 --- a/src/gui/guikernel/qkeymapper_p.h +++ /dev/null @@ -1,224 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef QKEYMAPPER_P_H -#define QKEYMAPPER_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <qobject.h> -#include <private/qobject_p.h> -#include <qkeysequence.h> -#include <qlist.h> -#include <qlocale.h> -#include <qevent.h> -#include <qhash.h> - -#if defined (Q_WS_MAC64) -# include <private/qt_mac_p.h> -#endif - -QT_BEGIN_NAMESPACE - -class QKeyMapperPrivate; -class QKeyMapper : public QObject -{ - Q_OBJECT -public: - explicit QKeyMapper(); - ~QKeyMapper(); - - static QKeyMapper *instance(); - static void changeKeyboard(); - static bool sendKeyEvent(QWidget *widget, bool grab, - QEvent::Type type, int code, Qt::KeyboardModifiers modifiers, - const QString &text, bool autorepeat, int count, - quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers, - bool *unusedExceptForCocoa = 0); - static QList<int> possibleKeys(QKeyEvent *e); - -private: - friend QKeyMapperPrivate *qt_keymapper_private(); - Q_DECLARE_PRIVATE(QKeyMapper) - Q_DISABLE_COPY(QKeyMapper) -}; - - - -#if defined(Q_OS_WIN) -enum WindowsNativeModifiers { - ShiftLeft = 0x00000001, - ControlLeft = 0x00000002, - AltLeft = 0x00000004, - MetaLeft = 0x00000008, - ShiftRight = 0x00000010, - ControlRight = 0x00000020, - AltRight = 0x00000040, - MetaRight = 0x00000080, - CapsLock = 0x00000100, - NumLock = 0x00000200, - ScrollLock = 0x00000400, - ExtendedKey = 0x01000000, - - // Convenience mappings - ShiftAny = 0x00000011, - ControlAny = 0x00000022, - AltAny = 0x00000044, - MetaAny = 0x00000088, - LockAny = 0x00000700 -}; -# if !defined(tagMSG) - typedef struct tagMSG MSG; -# endif -#elif defined(Q_WS_MAC) -QT_BEGIN_INCLUDE_NAMESPACE -# include <private/qt_mac_p.h> -QT_END_INCLUDE_NAMESPACE -#elif defined(Q_WS_X11) - -QT_BEGIN_INCLUDE_NAMESPACE -typedef ulong XID; -typedef XID KeySym; -QT_END_INCLUDE_NAMESPACE - -struct QXCoreDesc { - int min_keycode; - int max_keycode; - int keysyms_per_keycode; - KeySym *keysyms; - uchar mode_switch; - uchar num_lock; - KeySym lock_meaning; -}; - -#endif - -struct KeyboardLayoutItem; -typedef struct __TISInputSource * TISInputSourceRef; -class QKeyEvent; -class QKeyMapperPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QKeyMapper) -public: - QKeyMapperPrivate(); - ~QKeyMapperPrivate(); - - void clearMappings(); - QList<int> possibleKeys(QKeyEvent *e); - - QLocale keyboardInputLocale; - Qt::LayoutDirection keyboardInputDirection; - -#if defined(Q_OS_WIN) - void clearRecordedKeys(); - void updateKeyMap(const MSG &msg); - bool translateKeyEvent(QWidget *receiver, const MSG &msg, bool grab); - void updatePossibleKeyCodes(unsigned char *kbdBuffer, quint32 scancode, quint32 vk_key); - bool isADeadKey(unsigned int vk_key, unsigned int modifiers); - void deleteLayouts(); - - KeyboardLayoutItem *keyLayout[256]; - -#elif defined(Q_WS_X11) - - QList<int> possibleKeysXKB(QKeyEvent *event); - QList<int> possibleKeysCore(QKeyEvent *event); - - bool translateKeyEventInternal(QWidget *keywidget, - const XEvent *, - KeySym &keysym, - int& count, - QString& text, - Qt::KeyboardModifiers& modifiers, - int &code, - QEvent::Type &type, - bool statefulTranslation = true); - bool translateKeyEvent(QWidget *keywidget, - const XEvent *, - bool grab); - - int xkb_currentGroup; - QXCoreDesc coreDesc; - -#elif defined(Q_WS_MAC) - bool updateKeyboard(); - void updateKeyMap(EventHandlerCallRef, EventRef, void *); - bool translateKeyEvent(QWidget *, EventHandlerCallRef, EventRef, void *, bool); - void deleteLayouts(); - - enum { NullMode, UnicodeMode, OtherMode } keyboard_mode; - union { - const UCKeyboardLayout *unicode; - void *other; - } keyboard_layout_format; -#ifdef Q_WS_MAC64 - QCFType<TISInputSourceRef> currentInputSource; -#else - KeyboardLayoutRef currentKeyboardLayout; -#endif - KeyboardLayoutKind keyboard_kind; - UInt32 keyboard_dead; - KeyboardLayoutItem *keyLayout[256]; -#elif defined(Q_WS_QWS) -#elif defined(Q_OS_SYMBIAN) -public: - QString translateKeyEvent(int keySym, Qt::KeyboardModifiers modifiers); - int mapS60KeyToQt(TUint s60key); - int mapS60ScanCodesToQt(TUint s60key); - int mapQtToS60Key(int qtKey); - int mapQtToS60ScanCodes(int qtKey); - void updateInputLanguage(); -#endif -}; - -QKeyMapperPrivate *qt_keymapper_private(); // from qkeymapper.cpp - -QT_END_NAMESPACE - -#endif // QKEYMAPPER_P_H diff --git a/src/gui/guikernel/qkeymapper_qpa.cpp b/src/gui/guikernel/qkeymapper_qpa.cpp deleted file mode 100644 index 7e4114057f..0000000000 --- a/src/gui/guikernel/qkeymapper_qpa.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qkeymapper_p.h" -#include <qdebug.h> -#include <private/qevent_p.h> -#include <private/qlocale_p.h> - -QT_BEGIN_NAMESPACE - -QT_USE_NAMESPACE - - -QKeyMapperPrivate::QKeyMapperPrivate() -{ - keyboardInputLocale = QLocale::system(); - keyboardInputDirection = keyboardInputLocale.textDirection(); -} - -QKeyMapperPrivate::~QKeyMapperPrivate() -{ - // clearMappings(); -} - -void QKeyMapperPrivate::clearMappings() -{ -} - -QList<int> QKeyMapperPrivate::possibleKeys(QKeyEvent *e) -{ - QList<int> result; - if (e->key() && (e->key() != Qt::Key_unknown)) - result << int(e->key() + e->modifiers()); - else if (!e->text().isEmpty()) - result << int(e->text().at(0).unicode() + e->modifiers()); - return result; -} - -QT_END_NAMESPACE diff --git a/src/gui/guikernel/qshortcut.cpp b/src/gui/guikernel/qshortcut.cpp deleted file mode 100644 index 978ef0c240..0000000000 --- a/src/gui/guikernel/qshortcut.cpp +++ /dev/null @@ -1,407 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qshortcut.h" -#include "private/qwidget_p.h" - -#ifndef QT_NO_SHORTCUT -#include <qevent.h> -#include <qwhatsthis.h> -#include <qmenu.h> -#include <qapplication.h> -#include <private/qapplication_p.h> -#include <private/qshortcutmap_p.h> - -QT_BEGIN_NAMESPACE - -#define QAPP_CHECK(functionName) \ - if (!qApp) { \ - qWarning("QShortcut: Initialize QApplication before calling '" functionName "'."); \ - return; \ - } - -/*! - \class QShortcut - \brief The QShortcut class is used to create keyboard shortcuts. - - \ingroup events - - - The QShortcut class provides a way of connecting keyboard - shortcuts to Qt's \l{signals and slots} mechanism, so that - objects can be informed when a shortcut is executed. The shortcut - can be set up to contain all the key presses necessary to - describe a keyboard shortcut, including the states of modifier - keys such as \gui Shift, \gui Ctrl, and \gui Alt. - - \target mnemonic - - On certain widgets, using '&' in front of a character will - automatically create a mnemonic (a shortcut) for that character, - e.g. "E&xit" will create the shortcut \gui Alt+X (use '&&' to - display an actual ampersand). The widget might consume and perform - an action on a given shortcut. On X11 the ampersand will not be - shown and the character will be underlined. On Windows, shortcuts - are normally not displayed until the user presses the \gui Alt - key, but this is a setting the user can change. On Mac, shortcuts - are disabled by default. Call qt_set_sequence_auto_mnemonic() to - enable them. However, because mnemonic shortcuts do not fit in - with Aqua's guidelines, Qt will not show the shortcut character - underlined. - - For applications that use menus, it may be more convenient to - use the convenience functions provided in the QMenu class to - assign keyboard shortcuts to menu items as they are created. - Alternatively, shortcuts may be associated with other types of - actions in the QAction class. - - The simplest way to create a shortcut for a particular widget is - to construct the shortcut with a key sequence. For example: - - \snippet doc/src/snippets/code/src_gui_kernel_qshortcut.cpp 0 - - When the user types the \l{QKeySequence}{key sequence} - for a given shortcut, the shortcut's activated() signal is - emitted. (In the case of ambiguity, the activatedAmbiguously() - signal is emitted.) A shortcut is "listened for" by Qt's event - loop when the shortcut's parent widget is receiving events. - - A shortcut's key sequence can be set with setKey() and retrieved - with key(). A shortcut can be enabled or disabled with - setEnabled(), and can have "What's This?" help text set with - setWhatsThis(). - - \sa QShortcutEvent, QKeySequence, QAction -*/ - -/*! - \fn QWidget *QShortcut::parentWidget() const - - Returns the shortcut's parent widget. -*/ - -/*! - \fn void QShortcut::activated() - - This signal is emitted when the user types the shortcut's key - sequence. - - \sa activatedAmbiguously() -*/ - -/*! - \fn void QShortcut::activatedAmbiguously() - - When a key sequence is being typed at the keyboard, it is said to - be ambiguous as long as it matches the start of more than one - shortcut. - - When a shortcut's key sequence is completed, - activatedAmbiguously() is emitted if the key sequence is still - ambiguous (i.e., it is the start of one or more other shortcuts). - The activated() signal is not emitted in this case. - - \sa activated() -*/ - -/* - \internal - Private data accessed through d-pointer. -*/ -class QShortcutPrivate : public QObjectPrivate -{ - Q_DECLARE_PUBLIC(QShortcut) -public: - QShortcutPrivate() : sc_context(Qt::WindowShortcut), sc_enabled(true), sc_autorepeat(true), sc_id(0) {} - QKeySequence sc_sequence; - Qt::ShortcutContext sc_context; - bool sc_enabled; - bool sc_autorepeat; - int sc_id; - QString sc_whatsthis; - void redoGrab(QShortcutMap &map); -}; - -void QShortcutPrivate::redoGrab(QShortcutMap &map) -{ - Q_Q(QShortcut); - if (!parent) { - qWarning("QShortcut: No widget parent defined"); - return; - } - - if (sc_id) - map.removeShortcut(sc_id, q); - if (sc_sequence.isEmpty()) - return; - sc_id = map.addShortcut(q, sc_sequence, sc_context); - if (!sc_enabled) - map.setShortcutEnabled(false, sc_id, q); - if (!sc_autorepeat) - map.setShortcutAutoRepeat(false, sc_id, q); -} - -/*! - Constructs a QShortcut object for the \a parent widget. Since no - shortcut key sequence is specified, the shortcut will not emit any - signals. - - \sa setKey() -*/ -QShortcut::QShortcut(QWidget *parent) - : QObject(*new QShortcutPrivate, parent) -{ - Q_ASSERT(parent != 0); -} - -/*! - Constructs a QShortcut object for the \a parent widget. The shortcut - operates on its parent, listening for \l{QShortcutEvent}s that - match the \a key sequence. Depending on the ambiguity of the - event, the shortcut will call the \a member function, or the \a - ambiguousMember function, if the key press was in the shortcut's - \a context. -*/ -QShortcut::QShortcut(const QKeySequence &key, QWidget *parent, - const char *member, const char *ambiguousMember, - Qt::ShortcutContext context) - : QObject(*new QShortcutPrivate, parent) -{ - QAPP_CHECK("QShortcut"); - - Q_D(QShortcut); - Q_ASSERT(parent != 0); - d->sc_context = context; - d->sc_sequence = key; - d->redoGrab(qApp->d_func()->shortcutMap); - if (member) - connect(this, SIGNAL(activated()), parent, member); - if (ambiguousMember) - connect(this, SIGNAL(activatedAmbiguously()), parent, ambiguousMember); -} - -/*! - Destroys the shortcut. -*/ -QShortcut::~QShortcut() -{ - Q_D(QShortcut); - if (qApp) - qApp->d_func()->shortcutMap.removeShortcut(d->sc_id, this); -} - -/*! - \property QShortcut::key - \brief the shortcut's key sequence - - This is a key sequence with an optional combination of Shift, Ctrl, - and Alt. The key sequence may be supplied in a number of ways: - - \snippet doc/src/snippets/code/src_gui_kernel_qshortcut.cpp 1 - - By default, this property contains an empty key sequence. -*/ -void QShortcut::setKey(const QKeySequence &key) -{ - Q_D(QShortcut); - if (d->sc_sequence == key) - return; - QAPP_CHECK("setKey"); - d->sc_sequence = key; - d->redoGrab(qApp->d_func()->shortcutMap); -} - -QKeySequence QShortcut::key() const -{ - Q_D(const QShortcut); - return d->sc_sequence; -} - -/*! - \property QShortcut::enabled - \brief whether the shortcut is enabled - - An enabled shortcut emits the activated() or activatedAmbiguously() - signal when a QShortcutEvent occurs that matches the shortcut's - key() sequence. - - If the application is in \c WhatsThis mode the shortcut will not emit - the signals, but will show the "What's This?" text instead. - - By default, this property is true. - - \sa whatsThis -*/ -void QShortcut::setEnabled(bool enable) -{ - Q_D(QShortcut); - if (d->sc_enabled == enable) - return; - QAPP_CHECK("setEnabled"); - d->sc_enabled = enable; - qApp->d_func()->shortcutMap.setShortcutEnabled(enable, d->sc_id, this); -} - -bool QShortcut::isEnabled() const -{ - Q_D(const QShortcut); - return d->sc_enabled; -} - -/*! - \property QShortcut::context - \brief the context in which the shortcut is valid - - A shortcut's context decides in which circumstances a shortcut is - allowed to be triggered. The normal context is Qt::WindowShortcut, - which allows the shortcut to trigger if the parent (the widget - containing the shortcut) is a subwidget of the active top-level - window. - - By default, this property is set to Qt::WindowShortcut. -*/ -void QShortcut::setContext(Qt::ShortcutContext context) -{ - Q_D(QShortcut); - if(d->sc_context == context) - return; - QAPP_CHECK("setContext"); - d->sc_context = context; - d->redoGrab(qApp->d_func()->shortcutMap); -} - -Qt::ShortcutContext QShortcut::context() -{ - Q_D(QShortcut); - return d->sc_context; -} - -/*! - \property QShortcut::whatsThis - \brief the shortcut's "What's This?" help text - - The text will be shown when the application is in "What's - This?" mode and the user types the shortcut key() sequence. - - To set "What's This?" help on a menu item (with or without a - shortcut key), set the help on the item's action. - - By default, this property contains an empty string. - - \sa QWhatsThis::inWhatsThisMode(), QAction::setWhatsThis() -*/ -void QShortcut::setWhatsThis(const QString &text) -{ - Q_D(QShortcut); - d->sc_whatsthis = text; -} - -QString QShortcut::whatsThis() const -{ - Q_D(const QShortcut); - return d->sc_whatsthis; -} - -/*! - \property QShortcut::autoRepeat - \brief whether the shortcut can auto repeat - \since 4.2 - - If true, the shortcut will auto repeat when the keyboard shortcut - combination is held down, provided that keyboard auto repeat is - enabled on the system. - The default value is true. -*/ -void QShortcut::setAutoRepeat(bool on) -{ - Q_D(QShortcut); - if (d->sc_autorepeat == on) - return; - QAPP_CHECK("setAutoRepeat"); - d->sc_autorepeat = on; - qApp->d_func()->shortcutMap.setShortcutAutoRepeat(on, d->sc_id, this); -} - -bool QShortcut::autoRepeat() const -{ - Q_D(const QShortcut); - return d->sc_autorepeat; -} - -/*! - Returns the shortcut's ID. - - \sa QShortcutEvent::shortcutId() -*/ -int QShortcut::id() const -{ - Q_D(const QShortcut); - return d->sc_id; -} - -/*! - \internal -*/ -bool QShortcut::event(QEvent *e) -{ - Q_D(QShortcut); - bool handled = false; - if (d->sc_enabled && e->type() == QEvent::Shortcut) { - QShortcutEvent *se = static_cast<QShortcutEvent *>(e); - if (se->shortcutId() == d->sc_id && se->key() == d->sc_sequence){ -#ifndef QT_NO_WHATSTHIS - if (QWhatsThis::inWhatsThisMode()) { - QWhatsThis::showText(QCursor::pos(), d->sc_whatsthis); - handled = true; - } else -#endif - if (se->isAmbiguous()) - emit activatedAmbiguously(); - else - emit activated(); - handled = true; - } - } - return handled; -} -#endif // QT_NO_SHORTCUT - -QT_END_NAMESPACE diff --git a/src/gui/guikernel/qshortcut.h b/src/gui/guikernel/qshortcut.h deleted file mode 100644 index f432d9ad97..0000000000 --- a/src/gui/guikernel/qshortcut.h +++ /dev/null @@ -1,107 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSHORTCUT_H -#define QSHORTCUT_H - -#include <QtGui/qwidget.h> -#include <QtGui/qkeysequence.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Gui) - -#ifndef QT_NO_SHORTCUT - -class QShortcutPrivate; -class Q_GUI_EXPORT QShortcut : public QObject -{ - Q_OBJECT - Q_DECLARE_PRIVATE(QShortcut) - Q_PROPERTY(QKeySequence key READ key WRITE setKey) - Q_PROPERTY(QString whatsThis READ whatsThis WRITE setWhatsThis) - Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled) - Q_PROPERTY(bool autoRepeat READ autoRepeat WRITE setAutoRepeat) - Q_PROPERTY(Qt::ShortcutContext context READ context WRITE setContext) -public: - explicit QShortcut(QWidget *parent); - QShortcut(const QKeySequence& key, QWidget *parent, - const char *member = 0, const char *ambiguousMember = 0, - Qt::ShortcutContext context = Qt::WindowShortcut); - ~QShortcut(); - - void setKey(const QKeySequence& key); - QKeySequence key() const; - - void setEnabled(bool enable); - bool isEnabled() const; - - void setContext(Qt::ShortcutContext context); - Qt::ShortcutContext context(); - - void setWhatsThis(const QString &text); - QString whatsThis() const; - - void setAutoRepeat(bool on); - bool autoRepeat() const; - - int id() const; - - inline QWidget *parentWidget() const - { return static_cast<QWidget *>(QObject::parent()); } - -Q_SIGNALS: - void activated(); - void activatedAmbiguously(); - -protected: - bool event(QEvent *e); -}; - -#endif // QT_NO_SHORTCUT - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QSHORTCUT_H diff --git a/src/gui/guikernel/qshortcutmap.cpp b/src/gui/guikernel/qshortcutmap.cpp deleted file mode 100644 index d6baa1331e..0000000000 --- a/src/gui/guikernel/qshortcutmap.cpp +++ /dev/null @@ -1,897 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qshortcutmap_p.h" -#include "private/qobject_p.h" -#include "qkeysequence.h" -#include "qgraphicsscene.h" -#include "qgraphicsview.h" -#include "qdebug.h" -#include "qevent.h" -#include "qwidget.h" -#include "qapplication.h" -#include "qvector.h" -#include "qmenu.h" -#include "qmenubar.h" -#include "qshortcut.h" -#include "private/qapplication_p.h" -#include <private/qaction_p.h> -#include <private/qkeymapper_p.h> -#include <private/qwidget_p.h> - -#ifndef QT_NO_SHORTCUT - -QT_BEGIN_NAMESPACE - -// To enable verbose output uncomment below -//#define DEBUG_QSHORTCUTMAP - -/* \internal - Entry data for QShortcutMap - Contains: - Keysequence for entry - Pointer to parent owning the sequence -*/ -struct QShortcutEntry -{ - QShortcutEntry() - : keyseq(0), context(Qt::WindowShortcut), enabled(false), autorepeat(1), id(0), owner(0) - {} - - QShortcutEntry(const QKeySequence &k) - : keyseq(k), context(Qt::WindowShortcut), enabled(false), autorepeat(1), id(0), owner(0) - {} - - QShortcutEntry(QObject *o, const QKeySequence &k, Qt::ShortcutContext c, int i) - : keyseq(k), context(c), enabled(true), autorepeat(1), id(i), owner(o) - {} - - QShortcutEntry(QObject *o, const QKeySequence &k, Qt::ShortcutContext c, int i, bool a) - : keyseq(k), context(c), enabled(true), autorepeat(a), id(i), owner(o) - {} - - bool operator<(const QShortcutEntry &f) const - { return keyseq < f.keyseq; } - - QKeySequence keyseq; - Qt::ShortcutContext context; - bool enabled : 1; - bool autorepeat : 1; - signed int id; - QObject *owner; -}; - -#if 0 //ndef QT_NO_DEBUG_STREAM -/*! \internal - QDebug operator<< for easy debug output of the shortcut entries. -*/ -static QDebug &operator<<(QDebug &dbg, const QShortcutEntry *se) { - if (!se) - return dbg << "QShortcutEntry(0x0)"; - dbg.nospace() - << "QShortcutEntry(" << se->keyseq - << "), id(" << se->id << "), enabled(" << se->enabled << "), autorepeat(" << se->autorepeat - << "), owner(" << se->owner << ')'; - return dbg.space(); -} -#endif // QT_NO_DEBUGSTREAM - -/* \internal - Private data for QShortcutMap -*/ -class QShortcutMapPrivate -{ - Q_DECLARE_PUBLIC(QShortcutMap) - -public: - QShortcutMapPrivate(QShortcutMap* parent) - : q_ptr(parent), currentId(0), ambigCount(0), currentState(QKeySequence::NoMatch) - { - identicals.reserve(10); - currentSequences.reserve(10); - } - QShortcutMap *q_ptr; // Private's parent - - QList<QShortcutEntry> sequences; // All sequences! - - int currentId; // Global shortcut ID number - int ambigCount; // Index of last enabled ambiguous dispatch - QKeySequence::SequenceMatch currentState; - QVector<QKeySequence> currentSequences; // Sequence for the current state - QVector<QKeySequence> newEntries; - QKeySequence prevSequence; // Sequence for the previous identical match - QVector<const QShortcutEntry*> identicals; // Last identical matches -}; - - -/*! \internal - QShortcutMap constructor. -*/ -QShortcutMap::QShortcutMap() - : d_ptr(new QShortcutMapPrivate(this)) -{ - resetState(); -} - -/*! \internal - QShortcutMap destructor. -*/ -QShortcutMap::~QShortcutMap() -{ -} - -/*! \internal - Adds a shortcut to the global map. - Returns the id of the newly added shortcut. -*/ -int QShortcutMap::addShortcut(QObject *owner, const QKeySequence &key, Qt::ShortcutContext context) -{ - Q_ASSERT_X(owner, "QShortcutMap::addShortcut", "All shortcuts need an owner"); - Q_ASSERT_X(!key.isEmpty(), "QShortcutMap::addShortcut", "Cannot add keyless shortcuts to map"); - Q_D(QShortcutMap); - - QShortcutEntry newEntry(owner, key, context, --(d->currentId), true); - QList<QShortcutEntry>::iterator it = qUpperBound(d->sequences.begin(), d->sequences.end(), newEntry); - d->sequences.insert(it, newEntry); // Insert sorted -#if defined(DEBUG_QSHORTCUTMAP) - qDebug().nospace() - << "QShortcutMap::addShortcut(" << owner << ", " - << key << ", " << context << ") = " << d->currentId; -#endif - return d->currentId; -} - -/*! \internal - Removes a shortcut from the global map. - If \a owner is 0, all entries in the map with the key sequence specified - is removed. If \a key is null, all sequences for \a owner is removed from - the map. If \a id is 0, any identical \a key sequences owned by \a owner - are removed. - Returns the number of sequences removed from the map. -*/ - -int QShortcutMap::removeShortcut(int id, QObject *owner, const QKeySequence &key) -{ - Q_D(QShortcutMap); - int itemsRemoved = 0; - bool allOwners = (owner == 0); - bool allKeys = key.isEmpty(); - bool allIds = id == 0; - - // Special case, remove everything - if (allOwners && allKeys && id == 0) { - itemsRemoved = d->sequences.size(); - d->sequences.clear(); - return itemsRemoved; - } - - int i = d->sequences.size()-1; - while (i>=0) - { - const QShortcutEntry &entry = d->sequences.at(i); - int entryId = entry.id; - if ((allOwners || entry.owner == owner) - && (allIds || entry.id == id) - && (allKeys || entry.keyseq == key)) { - d->sequences.removeAt(i); - ++itemsRemoved; - } - if (id == entryId) - return itemsRemoved; - --i; - } -#if defined(DEBUG_QSHORTCUTMAP) - qDebug().nospace() - << "QShortcutMap::removeShortcut(" << id << ", " << owner << ", " - << key << ") = " << itemsRemoved; -#endif - return itemsRemoved; -} - -/*! \internal - Changes the enable state of a shortcut to \a enable. - If \a owner is 0, all entries in the map with the key sequence specified - is removed. If \a key is null, all sequences for \a owner is removed from - the map. If \a id is 0, any identical \a key sequences owned by \a owner - are changed. - Returns the number of sequences which are matched in the map. -*/ -int QShortcutMap::setShortcutEnabled(bool enable, int id, QObject *owner, const QKeySequence &key) -{ - Q_D(QShortcutMap); - int itemsChanged = 0; - bool allOwners = (owner == 0); - bool allKeys = key.isEmpty(); - bool allIds = id == 0; - - int i = d->sequences.size()-1; - while (i>=0) - { - QShortcutEntry entry = d->sequences.at(i); - if ((allOwners || entry.owner == owner) - && (allIds || entry.id == id) - && (allKeys || entry.keyseq == key)) { - d->sequences[i].enabled = enable; - ++itemsChanged; - } - if (id == entry.id) - return itemsChanged; - --i; - } -#if defined(DEBUG_QSHORTCUTMAP) - qDebug().nospace() - << "QShortcutMap::setShortcutEnabled(" << enable << ", " << id << ", " - << owner << ", " << key << ") = " << itemsChanged; -#endif - return itemsChanged; -} - -/*! \internal - Changes the auto repeat state of a shortcut to \a enable. - If \a owner is 0, all entries in the map with the key sequence specified - is removed. If \a key is null, all sequences for \a owner is removed from - the map. If \a id is 0, any identical \a key sequences owned by \a owner - are changed. - Returns the number of sequences which are matched in the map. -*/ -int QShortcutMap::setShortcutAutoRepeat(bool on, int id, QObject *owner, const QKeySequence &key) -{ - Q_D(QShortcutMap); - int itemsChanged = 0; - bool allOwners = (owner == 0); - bool allKeys = key.isEmpty(); - bool allIds = id == 0; - - int i = d->sequences.size()-1; - while (i>=0) - { - QShortcutEntry entry = d->sequences.at(i); - if ((allOwners || entry.owner == owner) - && (allIds || entry.id == id) - && (allKeys || entry.keyseq == key)) { - d->sequences[i].autorepeat = on; - ++itemsChanged; - } - if (id == entry.id) - return itemsChanged; - --i; - } -#if defined(DEBUG_QSHORTCUTMAP) - qDebug().nospace() - << "QShortcutMap::setShortcutAutoRepeat(" << on << ", " << id << ", " - << owner << ", " << key << ") = " << itemsChanged; -#endif - return itemsChanged; -} - -/*! \internal - Resets the state of the statemachine to NoMatch -*/ -void QShortcutMap::resetState() -{ - Q_D(QShortcutMap); - d->currentState = QKeySequence::NoMatch; - clearSequence(d->currentSequences); -} - -/*! \internal - Returns the current state of the statemachine -*/ -QKeySequence::SequenceMatch QShortcutMap::state() -{ - Q_D(QShortcutMap); - return d->currentState; -} - -/*! \internal - Uses ShortcutOverride event to see if any widgets want to override - the event. If not, uses nextState(QKeyEvent) to check for a grabbed - Shortcut, and dispatchEvent() is found an identical. - \sa nextState dispatchEvent -*/ -bool QShortcutMap::tryShortcutEvent(QObject *o, QKeyEvent *e) -{ - Q_D(QShortcutMap); - - bool wasAccepted = e->isAccepted(); - bool wasSpontaneous = e->spont; - if (d->currentState == QKeySequence::NoMatch) { - ushort orgType = e->t; - e->t = QEvent::ShortcutOverride; - e->ignore(); - QCoreApplication::sendEvent(o, e); - e->t = orgType; - e->spont = wasSpontaneous; - if (e->isAccepted()) { - if (!wasAccepted) - e->ignore(); - return false; - } - } - - QKeySequence::SequenceMatch result = nextState(e); - bool stateWasAccepted = e->isAccepted(); - if (wasAccepted) - e->accept(); - else - e->ignore(); - - int identicalMatches = d->identicals.count(); - - switch(result) { - case QKeySequence::NoMatch: - return stateWasAccepted; - case QKeySequence::ExactMatch: - resetState(); - dispatchEvent(e); - default: - break; - } - // If nextState is QKeySequence::ExactMatch && identicals.count == 0 - // we've only found disabled shortcuts - return identicalMatches > 0 || result == QKeySequence::PartialMatch; -} - -/*! \internal - Returns the next state of the statemachine - If return value is SequenceMatch::ExactMatch, then a call to matches() - will return a QObjects* list of all matching objects for the last matching - sequence. -*/ -QKeySequence::SequenceMatch QShortcutMap::nextState(QKeyEvent *e) -{ - Q_D(QShortcutMap); - // Modifiers can NOT be shortcuts... - if (e->key() >= Qt::Key_Shift && - e->key() <= Qt::Key_Alt) - return d->currentState; - - QKeySequence::SequenceMatch result = QKeySequence::NoMatch; - - // We start fresh each time.. - d->identicals.resize(0); - - result = find(e); - if (result == QKeySequence::NoMatch && e->modifiers() & Qt::ShiftModifier) { - // If Shift + Key_Backtab, also try Shift + Qt::Key_Tab - if (e->key() == Qt::Key_Backtab) { - QKeyEvent pe = QKeyEvent(e->type(), Qt::Key_Tab, e->modifiers(), e->text()); - result = find(&pe); - } - } - - // Should we eat this key press? - if (d->currentState == QKeySequence::PartialMatch - || (d->currentState == QKeySequence::ExactMatch && d->identicals.count())) - e->accept(); - // Does the new state require us to clean up? - if (result == QKeySequence::NoMatch) - clearSequence(d->currentSequences); - d->currentState = result; - -#if defined(DEBUG_QSHORTCUTMAP) - qDebug().nospace() << "QShortcutMap::nextState(" << e << ") = " << result; -#endif - return result; -} - - -/*! \internal - Determines if an enabled shortcut has a matcing key sequence. -*/ -bool QShortcutMap::hasShortcutForKeySequence(const QKeySequence &seq) const -{ - Q_D(const QShortcutMap); - QShortcutEntry entry(seq); // needed for searching - QList<QShortcutEntry>::ConstIterator itEnd = d->sequences.constEnd(); - QList<QShortcutEntry>::ConstIterator it = qLowerBound(d->sequences.constBegin(), itEnd, entry); - - for (;it != itEnd; ++it) { - if (matches(entry.keyseq, (*it).keyseq) == QKeySequence::ExactMatch && correctContext(*it) && (*it).enabled) { - return true; - } - } - - //end of the loop: we didn't find anything - return false; -} - -/*! \internal - Returns the next state of the statemachine, based - on the new key event \a e. - Matches are appended to the vector of identicals, - which can be access through matches(). - \sa matches -*/ -QKeySequence::SequenceMatch QShortcutMap::find(QKeyEvent *e) -{ - Q_D(QShortcutMap); - if (!d->sequences.count()) - return QKeySequence::NoMatch; - - createNewSequences(e, d->newEntries); -#if defined(DEBUG_QSHORTCUTMAP) - qDebug() << "Possible shortcut key sequences:" << d->newEntries; -#endif - - // Should never happen - if (d->newEntries == d->currentSequences) { - Q_ASSERT_X(e->key() != Qt::Key_unknown || e->text().length(), - "QShortcutMap::find", "New sequence to find identical to previous"); - return QKeySequence::NoMatch; - } - - // Looking for new identicals, scrap old - d->identicals.resize(0); - - bool partialFound = false; - bool identicalDisabledFound = false; - QVector<QKeySequence> okEntries; - int result = QKeySequence::NoMatch; - for (int i = d->newEntries.count()-1; i >= 0 ; --i) { - QShortcutEntry entry(d->newEntries.at(i)); // needed for searching - QList<QShortcutEntry>::ConstIterator itEnd = d->sequences.constEnd(); - QList<QShortcutEntry>::ConstIterator it = - qLowerBound(d->sequences.constBegin(), itEnd, entry); - - int oneKSResult = QKeySequence::NoMatch; - int tempRes = QKeySequence::NoMatch; - do { - if (it == itEnd) - break; - tempRes = matches(entry.keyseq, (*it).keyseq); - oneKSResult = qMax(oneKSResult, tempRes); - if (tempRes != QKeySequence::NoMatch && correctContext(*it)) { - if (tempRes == QKeySequence::ExactMatch) { - if ((*it).enabled) - d->identicals.append(&*it); - else - identicalDisabledFound = true; - } else if (tempRes == QKeySequence::PartialMatch) { - // We don't need partials, if we have identicals - if (d->identicals.size()) - break; - // We only care about enabled partials, so we don't consume - // key events when all partials are disabled! - partialFound |= (*it).enabled; - } - } - ++it; - // If we got a valid match on this run, there might still be more keys to check against, - // so we'll loop once more. If we get NoMatch, there's guaranteed no more possible - // matches in the shortcutmap. - } while (tempRes != QKeySequence::NoMatch); - - // If the type of match improves (ergo, NoMatch->Partial, or Partial->Exact), clear the - // previous list. If this match is equal or better than the last match, append to the list - if (oneKSResult > result) { - okEntries.clear(); -#if defined(DEBUG_QSHORTCUTMAP) - qDebug() << "Found better match (" << d->newEntries << "), clearing key sequence list"; -#endif - } - if (oneKSResult && oneKSResult >= result) { - okEntries << d->newEntries.at(i); -#if defined(DEBUG_QSHORTCUTMAP) - qDebug() << "Added ok key sequence" << d->newEntries; -#endif - } - } - - if (d->identicals.size()) { - result = QKeySequence::ExactMatch; - } else if (partialFound) { - result = QKeySequence::PartialMatch; - } else if (identicalDisabledFound) { - result = QKeySequence::ExactMatch; - } else { - clearSequence(d->currentSequences); - result = QKeySequence::NoMatch; - } - if (result != QKeySequence::NoMatch) - d->currentSequences = okEntries; -#if defined(DEBUG_QSHORTCUTMAP) - qDebug() << "Returning shortcut match == " << result; -#endif - return QKeySequence::SequenceMatch(result); -} - -/*! \internal - Clears \a seq to an empty QKeySequence. - Same as doing (the slower) - \snippet doc/src/snippets/code/src_gui_kernel_qshortcutmap.cpp 0 -*/ -void QShortcutMap::clearSequence(QVector<QKeySequence> &ksl) -{ - ksl.clear(); - d_func()->newEntries.clear(); -} - -/*! \internal - Alters \a seq to the new sequence state, based on the - current sequence state, and the new key event \a e. -*/ -void QShortcutMap::createNewSequences(QKeyEvent *e, QVector<QKeySequence> &ksl) -{ - Q_D(QShortcutMap); - QList<int> possibleKeys = QKeyMapper::possibleKeys(e); - int pkTotal = possibleKeys.count(); - if (!pkTotal) - return; - - int ssActual = d->currentSequences.count(); - int ssTotal = qMax(1, ssActual); - // Resize to possible permutations of the current sequence(s). - ksl.resize(pkTotal * ssTotal); - - int index = ssActual ? d->currentSequences.at(0).count() : 0; - for (int pkNum = 0; pkNum < pkTotal; ++pkNum) { - for (int ssNum = 0; ssNum < ssTotal; ++ssNum) { - int i = (pkNum * ssTotal) + ssNum; - QKeySequence &curKsl = ksl[i]; - if (ssActual) { - const QKeySequence &curSeq = d->currentSequences.at(ssNum); - curKsl.setKey(curSeq[0], 0); - curKsl.setKey(curSeq[1], 1); - curKsl.setKey(curSeq[2], 2); - curKsl.setKey(curSeq[3], 3); - } else { - curKsl.setKey(0, 0); - curKsl.setKey(0, 1); - curKsl.setKey(0, 2); - curKsl.setKey(0, 3); - } - // Filtering keycode here with 0xdfffffff to ignore the Keypad modifier - curKsl.setKey(possibleKeys.at(pkNum) & 0xdfffffff, index); - } - } -} - -/*! \internal - Basically the same function as QKeySequence::matches(const QKeySequence &seq) const - only that is specially handles Key_hyphen as Key_Minus, as people mix these up all the time and - they conceptually the same. -*/ -QKeySequence::SequenceMatch QShortcutMap::matches(const QKeySequence &seq1, - const QKeySequence &seq2) const -{ - uint userN = seq1.count(), - seqN = seq2.count(); - - if (userN > seqN) - return QKeySequence::NoMatch; - - // If equal in length, we have a potential ExactMatch sequence, - // else we already know it can only be partial. - QKeySequence::SequenceMatch match = (userN == seqN - ? QKeySequence::ExactMatch - : QKeySequence::PartialMatch); - - for (uint i = 0; i < userN; ++i) { - int userKey = seq1[i], - sequenceKey = seq2[i]; - if ((userKey & Qt::Key_unknown) == Qt::Key_hyphen) - userKey = (userKey & Qt::KeyboardModifierMask) | Qt::Key_Minus; - if ((sequenceKey & Qt::Key_unknown) == Qt::Key_hyphen) - sequenceKey = (sequenceKey & Qt::KeyboardModifierMask) | Qt::Key_Minus; - if (userKey != sequenceKey) - return QKeySequence::NoMatch; - } - return match; -} - -/*! \internal - Returns true if the widget \a w is a logical sub window of the current - top-level widget. -*/ -bool QShortcutMap::correctContext(const QShortcutEntry &item) const { - Q_ASSERT_X(item.owner, "QShortcutMap", "Shortcut has no owner. Illegal map state!"); - - QWidget *active_window = QApplication::activeWindow(); - - // popups do not become the active window, - // so we fake it here to get the correct context - // for the shortcut system. - if (QApplication::activePopupWidget()) - active_window = QApplication::activePopupWidget(); - - if (!active_window) - return false; -#ifndef QT_NO_ACTION - if (QAction *a = qobject_cast<QAction *>(item.owner)) - return correctContext(item.context, a, active_window); -#endif -#ifndef QT_NO_GRAPHICSVIEW - if (QGraphicsWidget *gw = qobject_cast<QGraphicsWidget *>(item.owner)) - return correctGraphicsWidgetContext(item.context, gw, active_window); -#endif - QWidget *w = qobject_cast<QWidget *>(item.owner); - if (!w) { - QShortcut *s = qobject_cast<QShortcut *>(item.owner); - w = s->parentWidget(); - } - return correctWidgetContext(item.context, w, active_window); -} - -bool QShortcutMap::correctWidgetContext(Qt::ShortcutContext context, QWidget *w, QWidget *active_window) const -{ - bool visible = w->isVisible(); -#ifdef Q_WS_MAC - if (!qApp->testAttribute(Qt::AA_DontUseNativeMenuBar) && qobject_cast<QMenuBar *>(w)) - visible = true; -#endif - - if (!visible || !w->isEnabled()) - return false; - - if (context == Qt::ApplicationShortcut) - return QApplicationPrivate::tryModalHelper(w, 0); // true, unless w is shadowed by a modal dialog - - if (context == Qt::WidgetShortcut) - return w == QApplication::focusWidget(); - - if (context == Qt::WidgetWithChildrenShortcut) { - const QWidget *tw = QApplication::focusWidget(); - while (tw && tw != w && (tw->windowType() == Qt::Widget || tw->windowType() == Qt::Popup)) - tw = tw->parentWidget(); - return tw == w; - } - - // Below is Qt::WindowShortcut context - QWidget *tlw = w->window(); -#ifndef QT_NO_GRAPHICSVIEW - if (QWExtra *topData = tlw->d_func()->extra) { - if (topData->proxyWidget) { - bool res = correctGraphicsWidgetContext(context, (QGraphicsWidget *)topData->proxyWidget, active_window); - return res; - } - } -#endif - - /* if a floating tool window is active, keep shortcuts on the - * parent working */ - if (active_window != tlw && active_window && active_window->windowType() == Qt::Tool && active_window->parentWidget()) { - active_window = active_window->parentWidget()->window(); - } - - if (active_window != tlw) - return false; - - /* if we live in a MDI subwindow, ignore the event if we are - not the active document window */ - const QWidget* sw = w; - while (sw && !(sw->windowType() == Qt::SubWindow) && !sw->isWindow()) - sw = sw->parentWidget(); - if (sw && (sw->windowType() == Qt::SubWindow)) { - QWidget *focus_widget = QApplication::focusWidget(); - while (focus_widget && focus_widget != sw) - focus_widget = focus_widget->parentWidget(); - return sw == focus_widget; - } - -#if defined(DEBUG_QSHORTCUTMAP) - qDebug().nospace() << "..true [Pass-through]"; -#endif - return true; -} - -#ifndef QT_NO_GRAPHICSVIEW -bool QShortcutMap::correctGraphicsWidgetContext(Qt::ShortcutContext context, QGraphicsWidget *w, QWidget *active_window) const -{ - bool visible = w->isVisible(); -#ifdef Q_WS_MAC - if (!qApp->testAttribute(Qt::AA_DontUseNativeMenuBar) && qobject_cast<QMenuBar *>(w)) - visible = true; -#endif - - if (!visible || !w->isEnabled() || !w->scene()) - return false; - - if (context == Qt::ApplicationShortcut) { - // Applicationwide shortcuts are always reachable unless their owner - // is shadowed by modality. In QGV there's no modality concept, but we - // must still check if all views are shadowed. - QList<QGraphicsView *> views = w->scene()->views(); - for (int i = 0; i < views.size(); ++i) { - if (QApplicationPrivate::tryModalHelper(views.at(i), 0)) - return true; - } - return false; - } - - if (context == Qt::WidgetShortcut) - return static_cast<QGraphicsItem *>(w) == w->scene()->focusItem(); - - if (context == Qt::WidgetWithChildrenShortcut) { - const QGraphicsItem *ti = w->scene()->focusItem(); - if (ti && ti->isWidget()) { - const QGraphicsWidget *tw = static_cast<const QGraphicsWidget *>(ti); - while (tw && tw != w && (tw->windowType() == Qt::Widget || tw->windowType() == Qt::Popup)) - tw = tw->parentWidget(); - return tw == w; - } - return false; - } - - // Below is Qt::WindowShortcut context - - // Find the active view (if any). - QList<QGraphicsView *> views = w->scene()->views(); - QGraphicsView *activeView = 0; - for (int i = 0; i < views.size(); ++i) { - QGraphicsView *view = views.at(i); - if (view->window() == active_window) { - activeView = view; - break; - } - } - if (!activeView) - return false; - - // The shortcut is reachable if owned by a windowless widget, or if the - // widget's window is the same as the focus item's window. - QGraphicsWidget *a = w->scene()->activeWindow(); - return !w->window() || a == w->window(); -} -#endif - -#ifndef QT_NO_ACTION -bool QShortcutMap::correctContext(Qt::ShortcutContext context, QAction *a, QWidget *active_window) const -{ - const QList<QWidget *> &widgets = a->d_func()->widgets; -#if defined(DEBUG_QSHORTCUTMAP) - if (widgets.isEmpty()) - qDebug() << a << "not connected to any widgets; won't trigger"; -#endif - for (int i = 0; i < widgets.size(); ++i) { - QWidget *w = widgets.at(i); -#ifndef QT_NO_MENU - if (QMenu *menu = qobject_cast<QMenu *>(w)) { - QAction *a = menu->menuAction(); - if (correctContext(context, a, active_window)) - return true; - } else -#endif - if (correctWidgetContext(context, w, active_window)) - return true; - } - -#ifndef QT_NO_GRAPHICSVIEW - const QList<QGraphicsWidget *> &graphicsWidgets = a->d_func()->graphicsWidgets; -#if defined(DEBUG_QSHORTCUTMAP) - if (graphicsWidgets.isEmpty()) - qDebug() << a << "not connected to any widgets; won't trigger"; -#endif - for (int i = 0; i < graphicsWidgets.size(); ++i) { - QGraphicsWidget *w = graphicsWidgets.at(i); - if (correctGraphicsWidgetContext(context, w, active_window)) - return true; - } -#endif - return false; -} -#endif // QT_NO_ACTION - -/*! \internal - Converts keyboard button states into modifier states -*/ -int QShortcutMap::translateModifiers(Qt::KeyboardModifiers modifiers) -{ - int result = 0; - if (modifiers & Qt::ShiftModifier) - result |= Qt::SHIFT; - if (modifiers & Qt::ControlModifier) - result |= Qt::CTRL; - if (modifiers & Qt::MetaModifier) - result |= Qt::META; - if (modifiers & Qt::AltModifier) - result |= Qt::ALT; - return result; -} - -/*! \internal - Returns the vector of QShortcutEntry's matching the last Identical state. -*/ -QVector<const QShortcutEntry*> QShortcutMap::matches() const -{ - Q_D(const QShortcutMap); - return d->identicals; -} - -/*! \internal - Dispatches QShortcutEvents to widgets who grabbed the matched key sequence. -*/ -void QShortcutMap::dispatchEvent(QKeyEvent *e) -{ - Q_D(QShortcutMap); - if (!d->identicals.size()) - return; - - const QKeySequence &curKey = d->identicals.at(0)->keyseq; - if (d->prevSequence != curKey) { - d->ambigCount = 0; - d->prevSequence = curKey; - } - // Find next - const QShortcutEntry *current = 0, *next = 0; - int i = 0, enabledShortcuts = 0; - while(i < d->identicals.size()) { - current = d->identicals.at(i); - if (current->enabled || !next){ - ++enabledShortcuts; - if (enabledShortcuts > d->ambigCount + 1) - break; - next = current; - } - ++i; - } - d->ambigCount = (d->identicals.size() == i ? 0 : d->ambigCount + 1); - // Don't trigger shortcut if we're autorepeating and the shortcut is - // grabbed with not accepting autorepeats. - if (!next || (e->isAutoRepeat() && !next->autorepeat)) - return; - // Dispatch next enabled -#if defined(DEBUG_QSHORTCUTMAP) - qDebug().nospace() - << "QShortcutMap::dispatchEvent(): Sending QShortcutEvent(\"" - << (QString)next->keyseq << "\", " << next->id << ", " - << (bool)(enabledShortcuts>1) << ") to object(" << next->owner << ')'; -#endif - QShortcutEvent se(next->keyseq, next->id, enabledShortcuts>1); - QCoreApplication::sendEvent(const_cast<QObject *>(next->owner), &se); -} - -/* \internal - QShortcutMap dump function, only available when DEBUG_QSHORTCUTMAP is - defined. -*/ -#if defined(Dump_QShortcutMap) -void QShortcutMap::dumpMap() const -{ - Q_D(const QShortcutMap); - for (int i = 0; i < d->sequences.size(); ++i) - qDebug().nospace() << &(d->sequences.at(i)); -} -#endif - -QT_END_NAMESPACE - -#endif // QT_NO_SHORTCUT diff --git a/src/gui/guikernel/qshortcutmap_p.h b/src/gui/guikernel/qshortcutmap_p.h deleted file mode 100644 index bc530b00b4..0000000000 --- a/src/gui/guikernel/qshortcutmap_p.h +++ /dev/null @@ -1,123 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSHORTCUTMAP_P_H -#define QSHORTCUTMAP_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include "QtGui/qkeysequence.h" -#include "QtCore/qvector.h" -#include "QtCore/qscopedpointer.h" - -QT_BEGIN_NAMESPACE - -#ifndef QT_NO_SHORTCUT - -// To enable dump output uncomment below -//#define Dump_QShortcutMap - -class QKeyEvent; -struct QShortcutEntry; -class QShortcutMapPrivate; -class QGraphicsWidget; -class QWidget; -class QAction; -class QObject; - -class QShortcutMap -{ - Q_DECLARE_PRIVATE(QShortcutMap) -public: - QShortcutMap(); - ~QShortcutMap(); - - int addShortcut(QObject *owner, const QKeySequence &key, Qt::ShortcutContext context); - int removeShortcut(int id, QObject *owner, const QKeySequence &key = QKeySequence()); - int setShortcutEnabled(bool enable, int id, QObject *owner, const QKeySequence &key = QKeySequence()); - int setShortcutAutoRepeat(bool on, int id, QObject *owner, const QKeySequence &key = QKeySequence()); - - void resetState(); - QKeySequence::SequenceMatch nextState(QKeyEvent *e); - QKeySequence::SequenceMatch state(); - void dispatchEvent(QKeyEvent *e); - bool tryShortcutEvent(QObject *o, QKeyEvent *e); - -#ifdef Dump_QShortcutMap - void dumpMap() const; -#endif - - bool hasShortcutForKeySequence(const QKeySequence &seq) const; - - -private: - bool correctWidgetContext(Qt::ShortcutContext context, QWidget *w, QWidget *active_window) const; -#ifndef QT_NO_GRAPHICSVIEW - bool correctGraphicsWidgetContext(Qt::ShortcutContext context, QGraphicsWidget *w, QWidget *active_window) const; -#endif -#ifndef QT_NO_ACTION - bool correctContext(Qt::ShortcutContext context,QAction *a, QWidget *active_window) const; -#endif - QScopedPointer<QShortcutMapPrivate> d_ptr; - - QKeySequence::SequenceMatch find(QKeyEvent *e); - QKeySequence::SequenceMatch matches(const QKeySequence &seq1, const QKeySequence &seq2) const; - QVector<const QShortcutEntry *> matches() const; - void createNewSequences(QKeyEvent *e, QVector<QKeySequence> &ksl); - void clearSequence(QVector<QKeySequence> &ksl); - bool correctContext(const QShortcutEntry &item) const; - int translateModifiers(Qt::KeyboardModifiers modifiers); -}; - -#endif // QT_NO_SHORTCUT - -QT_END_NAMESPACE - -#endif // QSHORTCUTMAP_P_H |