delete imports now provided by kdeclarative repo
This commit is contained in:
parent
213584e987
commit
e64ab583c5
@ -1,10 +1,6 @@
|
|||||||
add_subdirectory(accessdenied)
|
add_subdirectory(accessdenied)
|
||||||
add_subdirectory(core)
|
add_subdirectory(core)
|
||||||
add_subdirectory(dirmodel)
|
|
||||||
add_subdirectory(draganddrop)
|
|
||||||
add_subdirectory(qtextracomponents)
|
|
||||||
add_subdirectory(plasmacomponents)
|
add_subdirectory(plasmacomponents)
|
||||||
add_subdirectory(plasmaextracomponents)
|
add_subdirectory(plasmaextracomponents)
|
||||||
add_subdirectory(platformcomponents)
|
add_subdirectory(platformcomponents)
|
||||||
add_subdirectory(calendar)
|
add_subdirectory(calendar)
|
||||||
add_subdirectory(kquickcontrols)
|
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
project(dirmodel)
|
|
||||||
|
|
||||||
set(dirmodel_SRCS
|
|
||||||
dirmodel.cpp
|
|
||||||
dirmodelplugin.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
add_library(dirmodelplugin SHARED ${dirmodel_SRCS})
|
|
||||||
target_link_libraries(dirmodelplugin
|
|
||||||
Qt5::Core
|
|
||||||
Qt5::Qml
|
|
||||||
KF5::KIOCore
|
|
||||||
KF5::KIOWidgets
|
|
||||||
KF5::GuiAddons
|
|
||||||
)
|
|
||||||
|
|
||||||
install(TARGETS dirmodelplugin DESTINATION ${QML_INSTALL_DIR}/org/kde/dirmodel)
|
|
||||||
install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/dirmodel)
|
|
||||||
|
|
||||||
#add_subdirectory(test)
|
|
@ -1,203 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012 by Marco Martin <mart@kde.org>
|
|
||||||
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Library General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Library General Public License for more details
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Library General Public
|
|
||||||
* License along with this program; if not, write to the
|
|
||||||
* Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "dirmodel.h"
|
|
||||||
|
|
||||||
#include <QImage>
|
|
||||||
#include <QPixmap>
|
|
||||||
#include <QTimer>
|
|
||||||
|
|
||||||
#include <kdirlister.h>
|
|
||||||
#include <QDebug>
|
|
||||||
#include <kio/previewjob.h>
|
|
||||||
#include <kimagecache.h>
|
|
||||||
#include <QMimeDatabase>
|
|
||||||
|
|
||||||
|
|
||||||
DirModel::DirModel(QObject *parent)
|
|
||||||
: KDirModel(parent),
|
|
||||||
m_screenshotSize(180, 120)
|
|
||||||
{
|
|
||||||
QMimeDatabase db;
|
|
||||||
QList<QMimeType> mimeList = db.allMimeTypes();
|
|
||||||
|
|
||||||
m_mimeTypes << "inode/directory";
|
|
||||||
foreach (const QMimeType &mime, mimeList) {
|
|
||||||
if (mime.name().startsWith(QStringLiteral("image/"))) {
|
|
||||||
m_mimeTypes << mime.name();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: configurable mime filter
|
|
||||||
//dirLister()->setMimeFilter(m_mimeTypes);
|
|
||||||
|
|
||||||
QHash<int, QByteArray>roleNames;
|
|
||||||
roleNames[Qt::DisplayRole] = "display";
|
|
||||||
roleNames[Qt::DecorationRole] = "decoration";
|
|
||||||
roleNames[UrlRole] = "url";
|
|
||||||
roleNames[MimeTypeRole] = "mimeType";
|
|
||||||
roleNames[Thumbnail] = "thumbnail";
|
|
||||||
setRoleNames(roleNames);
|
|
||||||
|
|
||||||
m_previewTimer = new QTimer(this);
|
|
||||||
m_previewTimer->setSingleShot(true);
|
|
||||||
connect(m_previewTimer, SIGNAL(timeout()),
|
|
||||||
this, SLOT(delayedPreview()));
|
|
||||||
|
|
||||||
//using the same cache of the engine, they index both by url
|
|
||||||
m_imageCache = new KImageCache("org.kde.dirmodel-qml", 10485760);
|
|
||||||
|
|
||||||
connect(this, SIGNAL(rowsInserted(QModelIndex,int,int)),
|
|
||||||
this, SIGNAL(countChanged()));
|
|
||||||
connect(this, SIGNAL(rowsRemoved(QModelIndex,int,int)),
|
|
||||||
this, SIGNAL(countChanged()));
|
|
||||||
connect(this, SIGNAL(modelReset()),
|
|
||||||
this, SIGNAL(countChanged()));
|
|
||||||
}
|
|
||||||
|
|
||||||
DirModel::~DirModel()
|
|
||||||
{
|
|
||||||
delete m_imageCache;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString DirModel::url() const
|
|
||||||
{
|
|
||||||
return dirLister()->url().toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DirModel::setUrl(const QString& url)
|
|
||||||
{
|
|
||||||
if (url.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (dirLister()->url().path() == url) {
|
|
||||||
dirLister()->updateDirectory(QUrl(url));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
beginResetModel();
|
|
||||||
dirLister()->openUrl(QUrl(url));
|
|
||||||
endResetModel();
|
|
||||||
emit urlChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
int DirModel::indexForUrl(const QString &url) const
|
|
||||||
{
|
|
||||||
QModelIndex index = KDirModel::indexForUrl(QUrl(url));
|
|
||||||
return index.row();
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariantMap DirModel::get(int i) const
|
|
||||||
{
|
|
||||||
QModelIndex modelIndex = index(i, 0);
|
|
||||||
|
|
||||||
KFileItem item = itemForIndex(modelIndex);
|
|
||||||
QString url = item.url().toString();
|
|
||||||
QString mimeType = item.mimetype();
|
|
||||||
|
|
||||||
QVariantMap ret;
|
|
||||||
ret.insert("url", QVariant(url));
|
|
||||||
ret.insert("mimeType", QVariant(mimeType));
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariant DirModel::data(const QModelIndex &index, int role) const
|
|
||||||
{
|
|
||||||
if (!index.isValid()) {
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (role) {
|
|
||||||
case UrlRole: {
|
|
||||||
KFileItem item = itemForIndex(index);
|
|
||||||
return item.url().toString();
|
|
||||||
}
|
|
||||||
case MimeTypeRole: {
|
|
||||||
KFileItem item = itemForIndex(index);
|
|
||||||
return item.mimetype();
|
|
||||||
}
|
|
||||||
case Thumbnail: {
|
|
||||||
KFileItem item = itemForIndex(index);
|
|
||||||
QImage preview = QImage(m_screenshotSize, QImage::Format_ARGB32_Premultiplied);
|
|
||||||
|
|
||||||
if (m_imageCache->findImage(item.url().toString(), &preview)) {
|
|
||||||
return preview;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_previewTimer->start(100);
|
|
||||||
const_cast<DirModel *>(this)->m_filesToPreview[item.url()] = QPersistentModelIndex(index);
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return KDirModel::data(index, role);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DirModel::delayedPreview()
|
|
||||||
{
|
|
||||||
QHash<QUrl, QPersistentModelIndex>::const_iterator i = m_filesToPreview.constBegin();
|
|
||||||
|
|
||||||
KFileItemList list;
|
|
||||||
|
|
||||||
while (i != m_filesToPreview.constEnd()) {
|
|
||||||
QUrl file = i.key();
|
|
||||||
QPersistentModelIndex index = i.value();
|
|
||||||
|
|
||||||
|
|
||||||
if (!m_previewJobs.contains(file) && file.isValid()) {
|
|
||||||
list.append(KFileItem(file, QString(), 0));
|
|
||||||
m_previewJobs.insert(file, QPersistentModelIndex(index));
|
|
||||||
}
|
|
||||||
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (list.size() > 0) {
|
|
||||||
KIO::PreviewJob* job = KIO::filePreview(list, m_screenshotSize);
|
|
||||||
job->setIgnoreMaximumSize(true);
|
|
||||||
// qDebug() << "Created job" << job;
|
|
||||||
connect(job, SIGNAL(gotPreview(KFileItem,QPixmap)),
|
|
||||||
this, SLOT(showPreview(KFileItem,QPixmap)));
|
|
||||||
connect(job, SIGNAL(failed(KFileItem)),
|
|
||||||
this, SLOT(previewFailed(KFileItem)));
|
|
||||||
}
|
|
||||||
|
|
||||||
m_filesToPreview.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DirModel::showPreview(const KFileItem &item, const QPixmap &preview)
|
|
||||||
{
|
|
||||||
QPersistentModelIndex index = m_previewJobs.value(item.url());
|
|
||||||
m_previewJobs.remove(item.url());
|
|
||||||
|
|
||||||
if (!index.isValid()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_imageCache->insertImage(item.url().toString(), preview.toImage());
|
|
||||||
//qDebug() << "preview size:" << preview.size();
|
|
||||||
emit dataChanged(index, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DirModel::previewFailed(const KFileItem &item)
|
|
||||||
{
|
|
||||||
m_previewJobs.remove(item.url());
|
|
||||||
}
|
|
||||||
|
|
||||||
#include "moc_dirmodel.cpp"
|
|
@ -1,91 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012 by Marco Martin <mart@kde.org>
|
|
||||||
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Library General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Library General Public License for more details
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Library General Public
|
|
||||||
* License along with this program; if not, write to the
|
|
||||||
* Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef DIRMODEL_H
|
|
||||||
#define DIRMODEL_H
|
|
||||||
|
|
||||||
#include <QSize>
|
|
||||||
#include <kdirmodel.h>
|
|
||||||
#include <QVariant>
|
|
||||||
#include <kimagecache.h>
|
|
||||||
#include <kshareddatacache.h>
|
|
||||||
|
|
||||||
class QTimer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class provides a QML binding to KDirModel
|
|
||||||
* Provides an easy way to navigate a filesystem from within QML
|
|
||||||
*
|
|
||||||
* @author Marco Martin <mart@kde.org>
|
|
||||||
*/
|
|
||||||
class DirModel : public KDirModel
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @property string The url we want to browse. it may be an absolute path or a correct url of any protocol KIO supports
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString url READ url WRITE setUrl NOTIFY urlChanged)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @property count Total number of rows
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(int count READ count NOTIFY countChanged)
|
|
||||||
|
|
||||||
public:
|
|
||||||
enum Roles {
|
|
||||||
UrlRole = Qt::UserRole + 1,
|
|
||||||
MimeTypeRole = Qt::UserRole + 2,
|
|
||||||
Thumbnail = Qt::UserRole + 3
|
|
||||||
};
|
|
||||||
|
|
||||||
DirModel(QObject* parent=0);
|
|
||||||
virtual ~DirModel();
|
|
||||||
|
|
||||||
void setUrl(const QString& url);
|
|
||||||
QString url() const;
|
|
||||||
|
|
||||||
QVariant data(const QModelIndex &index, int role) const;
|
|
||||||
int count() const {return rowCount();}
|
|
||||||
|
|
||||||
Q_INVOKABLE int indexForUrl(const QString &url) const;
|
|
||||||
|
|
||||||
Q_INVOKABLE QVariantMap get(int index) const;
|
|
||||||
|
|
||||||
protected Q_SLOTS:
|
|
||||||
void showPreview(const KFileItem &item, const QPixmap &preview);
|
|
||||||
void previewFailed(const KFileItem &item);
|
|
||||||
void delayedPreview();
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
void countChanged();
|
|
||||||
void urlChanged();
|
|
||||||
|
|
||||||
private:
|
|
||||||
QStringList m_mimeTypes;
|
|
||||||
|
|
||||||
//previews
|
|
||||||
QTimer *m_previewTimer;
|
|
||||||
QHash<QUrl, QPersistentModelIndex> m_filesToPreview;
|
|
||||||
QSize m_screenshotSize;
|
|
||||||
QHash<QUrl, QPersistentModelIndex> m_previewJobs;
|
|
||||||
KImageCache* m_imageCache;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // DIRMODEL_H
|
|
@ -1,33 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012 by Marco Martin <mart@kde.org>
|
|
||||||
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Library General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Library General Public License for more details
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Library General Public
|
|
||||||
* License along with this program; if not, write to the
|
|
||||||
* Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "dirmodelplugin.h"
|
|
||||||
#include "dirmodel.h"
|
|
||||||
|
|
||||||
#include <QtQml>
|
|
||||||
|
|
||||||
|
|
||||||
void DirModelPlugin::registerTypes(const char *uri)
|
|
||||||
{
|
|
||||||
Q_ASSERT(uri == QLatin1String("org.kde.dirmodel"));
|
|
||||||
qmlRegisterType<DirModel>(uri, 2,0, "DirModel");
|
|
||||||
}
|
|
||||||
|
|
||||||
#include "moc_dirmodelplugin.cpp"
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012 by Marco Martin <mart@kde.org>
|
|
||||||
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Library General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Library General Public License for more details
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Library General Public
|
|
||||||
* License along with this program; if not, write to the
|
|
||||||
* Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef DIRMODELPLUGIN_H
|
|
||||||
#define DIRMODELPLUGIN_H
|
|
||||||
|
|
||||||
#include <QQmlExtensionPlugin>
|
|
||||||
|
|
||||||
|
|
||||||
class DirModelPlugin : public QQmlExtensionPlugin
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
|
|
||||||
|
|
||||||
public:
|
|
||||||
void registerTypes(const char *uri);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,3 +0,0 @@
|
|||||||
module org.kde.dirmodel
|
|
||||||
plugin dirmodelplugin
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
|||||||
project(draganddrop)
|
|
||||||
|
|
||||||
set(declarativedragdrop_SRCS
|
|
||||||
draganddropplugin.cpp
|
|
||||||
DeclarativeDragArea.cpp
|
|
||||||
DeclarativeDragDropEvent.cpp
|
|
||||||
DeclarativeDropArea.cpp
|
|
||||||
DeclarativeMimeData.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
add_library(draganddropplugin SHARED ${declarativedragdrop_SRCS})
|
|
||||||
target_link_libraries(draganddropplugin
|
|
||||||
Qt5::Core
|
|
||||||
Qt5::Quick
|
|
||||||
Qt5::Qml
|
|
||||||
Qt5::Gui
|
|
||||||
Qt5::Widgets
|
|
||||||
)
|
|
||||||
|
|
||||||
install(TARGETS draganddropplugin DESTINATION ${QML_INSTALL_DIR}/org/kde/draganddrop)
|
|
||||||
|
|
||||||
install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/draganddrop)
|
|
@ -1,336 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (C) 2010 by BetterInbox <contact@betterinbox.com>
|
|
||||||
Original author: Gregory Schlomoff <greg@betterinbox.com>
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "DeclarativeDragArea.h"
|
|
||||||
#include "DeclarativeMimeData.h"
|
|
||||||
|
|
||||||
#include <QDrag>
|
|
||||||
#include <QIcon>
|
|
||||||
#include <QMimeData>
|
|
||||||
#include <QMouseEvent>
|
|
||||||
#include <QPainter>
|
|
||||||
#include <QApplication>
|
|
||||||
#include <QQmlContext>
|
|
||||||
#include <QQuickWindow>
|
|
||||||
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
/*!
|
|
||||||
A DragArea is used to make an item draggable.
|
|
||||||
*/
|
|
||||||
|
|
||||||
DeclarativeDragArea::DeclarativeDragArea(QQuickItem *parent)
|
|
||||||
: QQuickItem(parent),
|
|
||||||
m_delegate(0),
|
|
||||||
m_source(parent),
|
|
||||||
m_target(0),
|
|
||||||
m_enabled(true),
|
|
||||||
m_draggingJustStarted(false),
|
|
||||||
m_supportedActions(Qt::MoveAction),
|
|
||||||
m_defaultAction(Qt::MoveAction),
|
|
||||||
m_data(new DeclarativeMimeData()) // m_data is owned by us, and we shouldn't pass it to Qt directly as it will automatically delete it after the drag and drop.
|
|
||||||
{
|
|
||||||
m_startDragDistance = QApplication::startDragDistance();
|
|
||||||
setAcceptedMouseButtons(Qt::LeftButton);
|
|
||||||
// setFiltersChildEvents(true);
|
|
||||||
setFlag(ItemAcceptsDrops, m_enabled);
|
|
||||||
setAcceptHoverEvents(true);
|
|
||||||
setFiltersChildMouseEvents(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
DeclarativeDragArea::~DeclarativeDragArea()
|
|
||||||
{
|
|
||||||
if (m_data) {
|
|
||||||
delete m_data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
The delegate is the item that will be displayed next to the mouse cursor during the drag and drop operation.
|
|
||||||
It usually consists of a large, semi-transparent icon representing the data being dragged.
|
|
||||||
*/
|
|
||||||
QQuickItem* DeclarativeDragArea::delegate() const
|
|
||||||
{
|
|
||||||
return m_delegate;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeclarativeDragArea::setDelegate(QQuickItem *delegate)
|
|
||||||
{
|
|
||||||
if (m_delegate != delegate) {
|
|
||||||
//qDebug() << " ______________________________________________ " << delegate;
|
|
||||||
m_delegate = delegate;
|
|
||||||
emit delegateChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void DeclarativeDragArea::resetDelegate()
|
|
||||||
{
|
|
||||||
setDelegate(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
The QML element that is the source of this drag and drop operation. This can be defined to any item, and will
|
|
||||||
be available to the DropArea as event.data.source
|
|
||||||
*/
|
|
||||||
QQuickItem* DeclarativeDragArea::source() const
|
|
||||||
{
|
|
||||||
return m_source;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeclarativeDragArea::setSource(QQuickItem* source)
|
|
||||||
{
|
|
||||||
if (m_source != source) {
|
|
||||||
m_source = source;
|
|
||||||
emit sourceChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeclarativeDragArea::resetSource()
|
|
||||||
{
|
|
||||||
setSource(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// target
|
|
||||||
QQuickItem* DeclarativeDragArea::target() const
|
|
||||||
{
|
|
||||||
//TODO: implement me
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// data
|
|
||||||
DeclarativeMimeData* DeclarativeDragArea::mimeData() const
|
|
||||||
{
|
|
||||||
return m_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
// startDragDistance
|
|
||||||
int DeclarativeDragArea::startDragDistance() const
|
|
||||||
{
|
|
||||||
return m_startDragDistance;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeclarativeDragArea::setStartDragDistance(int distance)
|
|
||||||
{
|
|
||||||
if (distance == m_startDragDistance) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_startDragDistance = distance;
|
|
||||||
emit startDragDistanceChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
// delegateImage
|
|
||||||
QVariant DeclarativeDragArea::delegateImage() const
|
|
||||||
{
|
|
||||||
return m_delegateImage;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeclarativeDragArea::setDelegateImage(const QVariant &image)
|
|
||||||
{
|
|
||||||
if (image.canConvert<QImage>() && image.value<QImage>() == m_delegateImage) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (image.canConvert<QImage>()) {
|
|
||||||
m_delegateImage = image.value<QImage>();
|
|
||||||
} else {
|
|
||||||
m_delegateImage = image.value<QIcon>().pixmap(QSize(48, 48)).toImage();
|
|
||||||
}
|
|
||||||
|
|
||||||
emit delegateImageChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
// enabled
|
|
||||||
bool DeclarativeDragArea::isEnabled() const
|
|
||||||
{
|
|
||||||
return m_enabled;
|
|
||||||
}
|
|
||||||
void DeclarativeDragArea::setEnabled(bool enabled)
|
|
||||||
{
|
|
||||||
if (enabled != m_enabled) {
|
|
||||||
m_enabled = enabled;
|
|
||||||
emit enabledChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// supported actions
|
|
||||||
Qt::DropActions DeclarativeDragArea::supportedActions() const
|
|
||||||
{
|
|
||||||
return m_supportedActions;
|
|
||||||
}
|
|
||||||
void DeclarativeDragArea::setSupportedActions(Qt::DropActions actions)
|
|
||||||
{
|
|
||||||
if (actions != m_supportedActions) {
|
|
||||||
m_supportedActions = actions;
|
|
||||||
emit supportedActionsChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// default action
|
|
||||||
Qt::DropAction DeclarativeDragArea::defaultAction() const
|
|
||||||
{
|
|
||||||
return m_defaultAction;
|
|
||||||
}
|
|
||||||
void DeclarativeDragArea::setDefaultAction(Qt::DropAction action)
|
|
||||||
{
|
|
||||||
if (action != m_defaultAction) {
|
|
||||||
m_defaultAction = action;
|
|
||||||
emit defaultActionChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeclarativeDragArea::mousePressEvent(QMouseEvent* event)
|
|
||||||
{
|
|
||||||
m_buttonDownPos = event->screenPos();
|
|
||||||
m_draggingJustStarted = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeclarativeDragArea::mouseReleaseEvent(QMouseEvent* event)
|
|
||||||
{
|
|
||||||
m_draggingJustStarted = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeclarativeDragArea::mouseMoveEvent(QMouseEvent *event)
|
|
||||||
{
|
|
||||||
if ( !m_enabled
|
|
||||||
|| QLineF(event->screenPos(), m_buttonDownPos).length()
|
|
||||||
< m_startDragDistance) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_draggingJustStarted) {
|
|
||||||
m_draggingJustStarted = false;
|
|
||||||
//qDebug() << "************ DDDD new QDrag" << objectName();
|
|
||||||
QDrag *drag = new QDrag(parent());
|
|
||||||
DeclarativeMimeData* dataCopy = new DeclarativeMimeData(m_data); //Qt will take ownership of this copy and delete it.
|
|
||||||
dataCopy->setText(objectName());
|
|
||||||
drag->setMimeData(dataCopy);
|
|
||||||
//qDebug() << "-----> data: dragarea: " << this << x() << y() << " mimedata: " << m_data << (dataCopy->hasColor() ? dataCopy->color().name() : " no color") ;
|
|
||||||
|
|
||||||
const QSize _s(48,48); // FIXME: smarter, please
|
|
||||||
|
|
||||||
if (!m_delegateImage.isNull()) {
|
|
||||||
drag->setPixmap(QPixmap::fromImage(m_delegateImage));
|
|
||||||
// qDebug() << "++++++delegateImage";
|
|
||||||
} else {
|
|
||||||
// qDebug() << "DDD NO Delegte image";
|
|
||||||
if (m_delegate) {
|
|
||||||
// This is just highly unreliable, let's completely skip this
|
|
||||||
// until we have a non-digusting way of "attaching an item to
|
|
||||||
// the cursor
|
|
||||||
// QRectF rf;
|
|
||||||
// qDebug() << "DDD +++ delegate" << m_delegate;
|
|
||||||
// rf = QRectF(0, 0, m_delegate->width(), m_delegate->height());
|
|
||||||
// rf = m_delegate->mapRectToScene(rf);
|
|
||||||
// QImage grabbed = window()->grabWindow();
|
|
||||||
// //rf = rf.intersected(QRectF(0, 0, grabbed.width(), grabbed.height()));
|
|
||||||
// grabbed = grabbed.copy(rf.toAlignedRect());
|
|
||||||
// // qDebug() << " +++++++++++++++++++++++ dim: " << rf;
|
|
||||||
// grabbed.save("file:///tmp/grabbed.png");
|
|
||||||
// QPixmap pm = QPixmap::fromImage(grabbed);
|
|
||||||
// qDebug() << " set new pixmap" << grabbed.size();
|
|
||||||
// drag->setPixmap(pm);
|
|
||||||
|
|
||||||
} else if (mimeData()->hasImage()) {
|
|
||||||
// qDebug() << "++++++hasImage";
|
|
||||||
QImage im = qvariant_cast<QImage>(mimeData()->imageData());
|
|
||||||
drag->setPixmap(QPixmap::fromImage(im));
|
|
||||||
} else if (mimeData()->hasColor()) {
|
|
||||||
// qDebug() << "++++++color";
|
|
||||||
QPixmap px(_s);
|
|
||||||
px.fill(mimeData()->color());
|
|
||||||
drag->setPixmap(px);
|
|
||||||
} else {
|
|
||||||
// icons otherwise
|
|
||||||
QStringList icons;
|
|
||||||
// qDebug() << "DDD adding icons dan maar";
|
|
||||||
if (mimeData()->hasText()) {
|
|
||||||
icons << "text-plain";
|
|
||||||
}
|
|
||||||
if (mimeData()->hasHtml()) {
|
|
||||||
icons << "text-html";
|
|
||||||
}
|
|
||||||
if (mimeData()->hasUrls()) {
|
|
||||||
foreach (const QVariant &u, mimeData()->urls()) {
|
|
||||||
Q_UNUSED(u);
|
|
||||||
icons << "text-html";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (icons.count()) {
|
|
||||||
const int _w = 48;
|
|
||||||
QPixmap pm(_w*icons.count(), _w);
|
|
||||||
pm.fill(Qt::transparent);
|
|
||||||
QPainter p(&pm);
|
|
||||||
int i = 0;
|
|
||||||
foreach (const QString &ic, icons) {
|
|
||||||
p.drawPixmap(QPoint(i*_w, 0), QIcon::fromTheme(ic).pixmap(_w, _w));
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
p.end();
|
|
||||||
drag->setPixmap(pm);
|
|
||||||
}
|
|
||||||
//qDebug() << "DD pixmaps set for icons: " << icons;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//drag->setHotSpot(QPoint(drag->pixmap().width()/2, drag->pixmap().height()/2)); // TODO: Make a property for that
|
|
||||||
//setCursor(Qt::OpenHandCursor); //TODO? Make a property for the cursor
|
|
||||||
|
|
||||||
emit dragStarted();
|
|
||||||
|
|
||||||
Qt::DropAction action = drag->exec(m_supportedActions, m_defaultAction);
|
|
||||||
emit drop(action);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DeclarativeDragArea::childMouseEventFilter(QQuickItem *item, QEvent *event)
|
|
||||||
{
|
|
||||||
if (!isEnabled()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (event->type()) {
|
|
||||||
case QEvent::MouseButtonPress: {
|
|
||||||
QMouseEvent *me = static_cast<QMouseEvent *>(event);
|
|
||||||
//qDebug() << "press in dragarea";
|
|
||||||
mousePressEvent(me);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case QEvent::MouseMove: {
|
|
||||||
QMouseEvent *me = static_cast<QMouseEvent *>(event);
|
|
||||||
//qDebug() << "move in dragarea";
|
|
||||||
mouseMoveEvent(me);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case QEvent::MouseButtonRelease: {
|
|
||||||
QMouseEvent *me = static_cast<QMouseEvent *>(event);
|
|
||||||
//qDebug() << "release in dragarea";
|
|
||||||
mouseReleaseEvent(me);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return QQuickItem::childMouseEventFilter(item, event);
|
|
||||||
}
|
|
@ -1,153 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (C) 2010 by BetterInbox <contact@betterinbox.com>
|
|
||||||
Original author: Gregory Schlomoff <greg@betterinbox.com>
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef DECLARATIVEDRAGAREA_H
|
|
||||||
#define DECLARATIVEDRAGAREA_H
|
|
||||||
|
|
||||||
#include <QQuickItem>
|
|
||||||
#include <QImage>
|
|
||||||
|
|
||||||
class QQmlComponent;
|
|
||||||
class DeclarativeMimeData;
|
|
||||||
|
|
||||||
class DeclarativeDragArea : public QQuickItem
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The delegate is the item that will be displayed next to the mouse cursor during the drag and drop operation.
|
|
||||||
* It usually consists of a large, semi-transparent icon representing the data being dragged.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QQuickItem* delegate READ delegate WRITE setDelegate NOTIFY delegateChanged RESET resetDelegate)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The QML element that is the source of the resulting drag and drop operation. This can be defined to any item, and will
|
|
||||||
* be available to the DropArea as event.data.source
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QQuickItem* source READ source WRITE setSource NOTIFY sourceChanged RESET resetSource)
|
|
||||||
|
|
||||||
//TODO: to be implemented
|
|
||||||
Q_PROPERTY(QQuickItem* target READ source NOTIFY targetChanged)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* the mime data of the drag operation
|
|
||||||
* @see DeclarativeMimeData
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(DeclarativeMimeData* mimeData READ mimeData CONSTANT)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If false no drag operation will be generate
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) //TODO: Should call setAcceptDrops()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Supported operations, a combination of
|
|
||||||
* Qt.CopyAction
|
|
||||||
* Qt.MoveAction
|
|
||||||
* Qt.LinkAction
|
|
||||||
* Qt.ActionMask
|
|
||||||
* Qt.IgnoreAction
|
|
||||||
* Qt.TargetMoveAction
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(Qt::DropActions supportedActions READ supportedActions WRITE setSupportedActions NOTIFY supportedActionsChanged)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The default action will be performed during a drag when no modificators are pressed.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(Qt::DropAction defaultAction READ defaultAction WRITE setDefaultAction NOTIFY defaultActionChanged)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* distance in pixel after which a drag event will get started
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(int startDragDistance READ startDragDistance WRITE setStartDragDistance NOTIFY startDragDistanceChanged)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* an image to be used as delegate. if present overrides the delegate property. in can be either a QImage or a QIcon
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QVariant delegateImage READ delegateImage WRITE setDelegateImage NOTIFY delegateImageChanged)
|
|
||||||
|
|
||||||
public:
|
|
||||||
DeclarativeDragArea(QQuickItem *parent=0);
|
|
||||||
~DeclarativeDragArea();
|
|
||||||
|
|
||||||
QQuickItem *delegate() const;
|
|
||||||
void setDelegate(QQuickItem* delegate);
|
|
||||||
void resetDelegate();
|
|
||||||
|
|
||||||
QVariant delegateImage() const;
|
|
||||||
void setDelegateImage(const QVariant &image);
|
|
||||||
QQuickItem* target() const;
|
|
||||||
QQuickItem* source() const;
|
|
||||||
void setSource(QQuickItem* source);
|
|
||||||
void resetSource();
|
|
||||||
|
|
||||||
bool isEnabled() const;
|
|
||||||
void setEnabled(bool enabled);
|
|
||||||
|
|
||||||
int startDragDistance() const;
|
|
||||||
void setStartDragDistance(int distance);
|
|
||||||
|
|
||||||
//supported actions
|
|
||||||
Qt::DropActions supportedActions() const;
|
|
||||||
void setSupportedActions(Qt::DropActions actions);
|
|
||||||
|
|
||||||
//default action
|
|
||||||
Qt::DropAction defaultAction() const;
|
|
||||||
void setDefaultAction(Qt::DropAction action);
|
|
||||||
|
|
||||||
DeclarativeMimeData* mimeData() const;
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
void dragStarted();
|
|
||||||
void delegateChanged();
|
|
||||||
void sourceChanged();
|
|
||||||
void targetChanged();
|
|
||||||
void dataChanged();
|
|
||||||
void enabledChanged();
|
|
||||||
void drop(int action);
|
|
||||||
void supportedActionsChanged();
|
|
||||||
void defaultActionChanged();
|
|
||||||
void startDragDistanceChanged();
|
|
||||||
void delegateImageChanged();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void mouseMoveEvent(QMouseEvent *event);
|
|
||||||
void mousePressEvent(QMouseEvent *event);
|
|
||||||
void mouseReleaseEvent(QMouseEvent *);
|
|
||||||
bool childMouseEventFilter(QQuickItem *item, QEvent *event);
|
|
||||||
|
|
||||||
private:
|
|
||||||
QQuickItem* m_delegate;
|
|
||||||
QQuickItem* m_source;
|
|
||||||
QQuickItem* m_target;
|
|
||||||
bool m_enabled;
|
|
||||||
bool m_draggingJustStarted;
|
|
||||||
Qt::DropActions m_supportedActions;
|
|
||||||
Qt::DropAction m_defaultAction;
|
|
||||||
DeclarativeMimeData* const m_data;
|
|
||||||
QImage m_delegateImage;
|
|
||||||
int m_startDragDistance;
|
|
||||||
QPointF m_buttonDownPos;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // DECLARATIVEDRAGAREA_H
|
|
@ -1,62 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (C) 2010 by BetterInbox <contact@betterinbox.com>
|
|
||||||
Copyright 2013 by Sebastian Kügler <sebas@kde.org>
|
|
||||||
Original author: Gregory Schlomoff <greg@betterinbox.com>
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "DeclarativeDragDropEvent.h"
|
|
||||||
|
|
||||||
DeclarativeDragDropEvent::DeclarativeDragDropEvent(QDropEvent* e, DeclarativeDropArea* parent) :
|
|
||||||
QObject(parent),
|
|
||||||
m_x(e->pos().x()),
|
|
||||||
m_y(e->pos().y()),
|
|
||||||
m_buttons(e->mouseButtons()),
|
|
||||||
m_modifiers(e->keyboardModifiers()),
|
|
||||||
m_data(e->mimeData()),
|
|
||||||
m_event(e)
|
|
||||||
{
|
|
||||||
QPointF pos;
|
|
||||||
|
|
||||||
if (parent) {
|
|
||||||
pos = parent->mapFromScene(e->pos());
|
|
||||||
m_x = pos.x();
|
|
||||||
m_y = pos.y();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DeclarativeDragDropEvent::DeclarativeDragDropEvent(QDragLeaveEvent* e, DeclarativeDropArea* parent) :
|
|
||||||
QObject(parent),
|
|
||||||
m_x(0),
|
|
||||||
m_y(0),
|
|
||||||
m_buttons(Qt::NoButton),
|
|
||||||
m_modifiers(Qt::NoModifier),
|
|
||||||
//m_data(e->mimeData()),
|
|
||||||
m_event(0)
|
|
||||||
{
|
|
||||||
Q_UNUSED(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeclarativeDragDropEvent::accept(int action)
|
|
||||||
{
|
|
||||||
m_event->setDropAction( (Qt::DropAction) action );
|
|
||||||
qDebug() << "-----> Accepting event: " << this << m_data.urls() << m_data.text() << m_data.html() << ( m_data.hasColor() ? m_data.color().name() : " no color");
|
|
||||||
m_event->accept();
|
|
||||||
}
|
|
@ -1,120 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (C) 2010 by BetterInbox <contact@betterinbox.com>
|
|
||||||
Original author: Gregory Schlomoff <greg@betterinbox.com>
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef DECLARATIVEDRAGDROPEVENT_H
|
|
||||||
#define DECLARATIVEDRAGDROPEVENT_H
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include "DeclarativeMimeData.h"
|
|
||||||
#include "DeclarativeDropArea.h"
|
|
||||||
|
|
||||||
class DeclarativeDragDropEvent : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The mouse X position of the event relative to the DropArea that is receiving the event.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(int x READ x)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The mouse Y position of the event relative to the DropArea that is receiving the event.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(int y READ y)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The pressed mouse buttons.
|
|
||||||
* A combination of:
|
|
||||||
* Qt.NoButton The button state does not refer to any button (see QMouseEvent::button()).
|
|
||||||
* Qt.LeftButton The left button is pressed, or an event refers to the left button. (The left button may be the right button on left-handed mice.)
|
|
||||||
* Qt.RightButton The right button.
|
|
||||||
* Qt.MidButton The middle button.
|
|
||||||
* Qt.MiddleButton MidButton The middle button.
|
|
||||||
* Qt.XButton1 The first X button.
|
|
||||||
* Qt.XButton2 The second X button.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(int buttons READ buttons)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Pressed keyboard modifiers, a combination of:
|
|
||||||
* Qt.NoModifier No modifier key is pressed.
|
|
||||||
* Qt.ShiftModifier A Shift key on the keyboard is pressed.
|
|
||||||
* Qt.ControlModifier A Ctrl key on the keyboard is pressed.
|
|
||||||
* Qt.AltModifier An Alt key on the keyboard is pressed.
|
|
||||||
* Qt.MetaModifier A Meta key on the keyboard is pressed.
|
|
||||||
* Qt.KeypadModifier A keypad button is pressed.
|
|
||||||
* Qt.GroupSwitchModifier X11 only. A Mode_switch key on the keyboard is pressed.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(int modifiers READ modifiers)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The mime data of this operation
|
|
||||||
* @see DeclarativeMimeData
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(DeclarativeMimeData* mimeData READ mimeData)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The possible different kind of action that can be done in the drop, is a combination of:
|
|
||||||
* Qt.CopyAction 0x1 Copy the data to the target.
|
|
||||||
* Qt.MoveAction 0x2 Move the data from the source to the target.
|
|
||||||
* Qt.LinkAction 0x4 Create a link from the source to the target.
|
|
||||||
* Qt.ActionMask 0xff
|
|
||||||
* Qt.IgnoreAction 0x0 Ignore the action (do nothing with the data).
|
|
||||||
* Qt.TargetMoveAction 0x8002 On Windows, this value is used when the ownership of the D&D data should be taken over by the target application, i.e., the source application should not delete the data.
|
|
||||||
* On X11 this value is used to do a move.
|
|
||||||
* TargetMoveAction is not used on the Mac.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(Qt::DropActions possibleActions READ possibleActions)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default action
|
|
||||||
* @see possibleActions
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(Qt::DropAction proposedAction READ proposedAction)
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
DeclarativeDragDropEvent(QDropEvent* e, DeclarativeDropArea* parent = 0);
|
|
||||||
DeclarativeDragDropEvent(QDragLeaveEvent* e, DeclarativeDropArea* parent = 0);
|
|
||||||
|
|
||||||
int x() const { return m_x; }
|
|
||||||
int y() const { return m_y; }
|
|
||||||
int buttons() const { return m_buttons; }
|
|
||||||
int modifiers() const { return m_modifiers; }
|
|
||||||
DeclarativeMimeData* mimeData() { return &m_data; }
|
|
||||||
Qt::DropAction proposedAction() const { return m_event->proposedAction(); }
|
|
||||||
Qt::DropActions possibleActions() const { return m_event->possibleActions(); }
|
|
||||||
|
|
||||||
public Q_SLOTS:
|
|
||||||
void accept(int action);
|
|
||||||
|
|
||||||
private:
|
|
||||||
int m_x;
|
|
||||||
int m_y;
|
|
||||||
Qt::MouseButtons m_buttons;
|
|
||||||
Qt::KeyboardModifiers m_modifiers;
|
|
||||||
DeclarativeMimeData m_data;
|
|
||||||
QDropEvent* m_event;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // DECLARATIVEDRAGDROPEVENT_H
|
|
@ -1,86 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (C) 2010 by BetterInbox <contact@betterinbox.com>
|
|
||||||
Original author: Gregory Schlomoff <greg@betterinbox.com>
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "DeclarativeDropArea.h"
|
|
||||||
#include "DeclarativeDragDropEvent.h"
|
|
||||||
|
|
||||||
#include <QMimeData>
|
|
||||||
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
DeclarativeDropArea::DeclarativeDropArea(QQuickItem *parent)
|
|
||||||
: QQuickItem(parent),
|
|
||||||
m_enabled(true)
|
|
||||||
{
|
|
||||||
setFlag(ItemAcceptsDrops, m_enabled);
|
|
||||||
setFlag(ItemHasContents, m_enabled);
|
|
||||||
setAcceptHoverEvents(m_enabled);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeclarativeDropArea::dragEnterEvent(QDragEnterEvent *event)
|
|
||||||
{
|
|
||||||
DeclarativeDragDropEvent dde(event, this);
|
|
||||||
qDebug() << "enter.";
|
|
||||||
event->accept();
|
|
||||||
emit dragEnter(&dde);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeclarativeDropArea::dragLeaveEvent(QDragLeaveEvent *event)
|
|
||||||
{
|
|
||||||
DeclarativeDragDropEvent dde(event, this);
|
|
||||||
qDebug() << "leave.";
|
|
||||||
emit dragLeave(&dde);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeclarativeDropArea::dragMoveEvent(QDragMoveEvent *event)
|
|
||||||
{
|
|
||||||
DeclarativeDragDropEvent dde(event, this);
|
|
||||||
//qDebug() << "move.";
|
|
||||||
event->accept();
|
|
||||||
emit dragMove(&dde);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeclarativeDropArea::dropEvent(QDropEvent *event)
|
|
||||||
{
|
|
||||||
DeclarativeDragDropEvent dde(event, this);
|
|
||||||
qDebug() << "Drop.";
|
|
||||||
emit drop(&dde);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DeclarativeDropArea::isEnabled() const
|
|
||||||
{
|
|
||||||
return m_enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeclarativeDropArea::setEnabled(bool enabled)
|
|
||||||
{
|
|
||||||
if (enabled == m_enabled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_enabled = enabled;
|
|
||||||
setAcceptHoverEvents(m_enabled);
|
|
||||||
setFlag(ItemAcceptsDrops, m_enabled);
|
|
||||||
emit enabledChanged();
|
|
||||||
}
|
|
@ -1,87 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (C) 2010 by BetterInbox <contact@betterinbox.com>
|
|
||||||
Original author: Gregory Schlomoff <greg@betterinbox.com>
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef DECLARATIVEDROPAREA_H
|
|
||||||
#define DECLARATIVEDROPAREA_H
|
|
||||||
|
|
||||||
#include <QQuickItem>
|
|
||||||
|
|
||||||
class DeclarativeDragDropEvent;
|
|
||||||
|
|
||||||
class DeclarativeDropArea : public QQuickItem
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If false the area will receive no drop events
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
|
|
||||||
|
|
||||||
public:
|
|
||||||
DeclarativeDropArea(QQuickItem *parent=0);
|
|
||||||
bool isEnabled() const;
|
|
||||||
void setEnabled(bool enabled);
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
/**
|
|
||||||
* Emitted when the mouse cursor dragging something enters in the drag area
|
|
||||||
* @arg DeclarativeDragDropEvent description of the dragged content
|
|
||||||
* @see DeclarativeDragDropEvent
|
|
||||||
*/
|
|
||||||
void dragEnter(DeclarativeDragDropEvent* event);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Emitted when the mouse cursor dragging something leaves the drag area
|
|
||||||
* @arg DeclarativeDragDropEvent description of the dragged content
|
|
||||||
* @see DeclarativeDragDropEvent
|
|
||||||
*/
|
|
||||||
void dragLeave(DeclarativeDragDropEvent* event);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Emitted when the mouse cursor dragging something moves over the drag area
|
|
||||||
* @arg DeclarativeDragDropEvent description of the dragged content
|
|
||||||
* @see DeclarativeDragDropEvent
|
|
||||||
*/
|
|
||||||
void dragMove(DeclarativeDragDropEvent *event);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Emitted when the user drops something in the area
|
|
||||||
* @arg DeclarativeDragDropEvent description of the dragged content
|
|
||||||
* @see DeclarativeDragDropEvent
|
|
||||||
*/
|
|
||||||
void drop(DeclarativeDragDropEvent* event);
|
|
||||||
|
|
||||||
void enabledChanged();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void dragEnterEvent(QDragEnterEvent *event);
|
|
||||||
void dragLeaveEvent(QDragLeaveEvent *event);
|
|
||||||
void dragMoveEvent(QDragMoveEvent *event);
|
|
||||||
void dropEvent(QDropEvent *event);
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool m_enabled;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,156 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (C) 2010 by BetterInbox <contact@betterinbox.com>
|
|
||||||
Original author: Gregory Schlomoff <greg@betterinbox.com>
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "DeclarativeMimeData.h"
|
|
||||||
|
|
||||||
/*!
|
|
||||||
\qmlclass MimeData DeclarativeMimeData
|
|
||||||
|
|
||||||
This is a wrapper class around QMimeData, with a few extensions to provide better support for in-qml drag & drops.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*!
|
|
||||||
\internal
|
|
||||||
\class DeclarativeMimeData
|
|
||||||
|
|
||||||
Creates a new DeclarativeMimeData by cloning the QMimeData passed as parameter.
|
|
||||||
This is useful for two reasons :
|
|
||||||
- In DragArea, we want to clone our "working copy" of the DeclarativeMimeData instance, as Qt will automatically
|
|
||||||
delete it after the drag and drop operation.
|
|
||||||
- In the drop events, the QMimeData is const, and we have troubles passing const to QML. So we clone it to
|
|
||||||
remove the "constness"
|
|
||||||
|
|
||||||
This method will try to cast the QMimeData to DeclarativeMimeData, and will clone our extensions to QMimeData as well
|
|
||||||
*/
|
|
||||||
DeclarativeMimeData::DeclarativeMimeData(const QMimeData* copy)
|
|
||||||
: QMimeData(),
|
|
||||||
m_source(0)
|
|
||||||
{
|
|
||||||
// Copy the standard MIME data
|
|
||||||
foreach(QString format, copy->formats()) {
|
|
||||||
QMimeData::setData(format, copy->data(format));
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the object we are copying actually is a DeclarativeMimeData, copy our extended properties as well
|
|
||||||
const DeclarativeMimeData* declarativeMimeData = qobject_cast<const DeclarativeMimeData*>(copy);
|
|
||||||
if (declarativeMimeData) {
|
|
||||||
this->setSource(declarativeMimeData->source());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*!
|
|
||||||
\qmlproperty url MimeData::url
|
|
||||||
|
|
||||||
Returns the first URL from the urls property of QMimeData
|
|
||||||
TODO: We should use QDeclarativeListProperty<QUrls> to return the whole list instead of only the first element.
|
|
||||||
*/
|
|
||||||
QUrl DeclarativeMimeData::url() const
|
|
||||||
{
|
|
||||||
if ( this->hasUrls() && !this->urls().isEmpty()) {
|
|
||||||
return QMimeData::urls().first();
|
|
||||||
}
|
|
||||||
return QUrl();
|
|
||||||
}
|
|
||||||
void DeclarativeMimeData::setUrl(const QUrl &url)
|
|
||||||
{
|
|
||||||
if (this->url() == url)
|
|
||||||
return;
|
|
||||||
|
|
||||||
QList<QUrl> urlList;
|
|
||||||
urlList.append(url);
|
|
||||||
QMimeData::setUrls(urlList);
|
|
||||||
emit urlChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariantList DeclarativeMimeData::urls() const
|
|
||||||
{
|
|
||||||
QVariantList varUrls;
|
|
||||||
foreach (const QUrl &url, QMimeData::urls()) {
|
|
||||||
varUrls << url;
|
|
||||||
}
|
|
||||||
return varUrls;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeclarativeMimeData::setUrls(const QVariantList &urls)
|
|
||||||
{
|
|
||||||
QList<QUrl> urlList;
|
|
||||||
foreach (const QVariant &varUrl, urls) {
|
|
||||||
urlList << varUrl.value<QUrl>();
|
|
||||||
}
|
|
||||||
QMimeData::setUrls(urlList);
|
|
||||||
emit urlsChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
// color
|
|
||||||
QColor DeclarativeMimeData::color() const
|
|
||||||
{
|
|
||||||
if (this->hasColor()) {
|
|
||||||
return qvariant_cast<QColor>(this->colorData());
|
|
||||||
}
|
|
||||||
return QColor();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DeclarativeMimeData::hasColor() const
|
|
||||||
{
|
|
||||||
//qDebug() << " hasColor " << (QMimeData::hasColor() ? color().name() : "false");
|
|
||||||
return QMimeData::hasColor();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeclarativeMimeData::setColor(const QColor &color)
|
|
||||||
{
|
|
||||||
if (this->color() != color) {
|
|
||||||
this->setColorData(color);
|
|
||||||
emit colorChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeclarativeMimeData::setData(const QString &mimeType, const QVariant &data)
|
|
||||||
{
|
|
||||||
if (data.type() == QVariant::ByteArray) {
|
|
||||||
QMimeData::setData(mimeType, data.toByteArray());
|
|
||||||
} else if (data.canConvert(QVariant::String)) {
|
|
||||||
QMimeData::setData(mimeType, data.toString().toLatin1());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
\qmlproperty item MimeData::source
|
|
||||||
|
|
||||||
Setting source to any existing qml item will enable the receiver of the drag and drop operation to know in which item
|
|
||||||
the operation originated.
|
|
||||||
|
|
||||||
In the case of inter-application drag and drop operations, the source will not be available, and will be 0.
|
|
||||||
Be sure to test it in your QML code, before using it, or it will generate errors in the console.
|
|
||||||
*/
|
|
||||||
QQuickItem* DeclarativeMimeData::source() const
|
|
||||||
{
|
|
||||||
return m_source;
|
|
||||||
}
|
|
||||||
void DeclarativeMimeData::setSource(QQuickItem* source)
|
|
||||||
{
|
|
||||||
if (m_source != source) {
|
|
||||||
m_source = source;
|
|
||||||
emit sourceChanged();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,107 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (C) 2010 by BetterInbox <contact@betterinbox.com>
|
|
||||||
Original author: Gregory Schlomoff <greg@betterinbox.com>
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef DECLARATIVEMIMEDATA_H
|
|
||||||
#define DECLARATIVEMIMEDATA_H
|
|
||||||
|
|
||||||
#include <QMimeData>
|
|
||||||
#include <QColor>
|
|
||||||
#include <QUrl>
|
|
||||||
#include <QQuickItem>
|
|
||||||
|
|
||||||
class DeclarativeMimeData : public QMimeData
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A plain text (MIME type text/plain) representation of the data.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A string if the data stored in the object is HTML (MIME type text/html); otherwise returns an empty string.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QString html READ html WRITE setHtml NOTIFY htmlChanged)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Url contained in the mimedata
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A list of URLs contained within the MIME data object.
|
|
||||||
* URLs correspond to the MIME type text/uri-list.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QVariantList urls READ urls WRITE setUrls NOTIFY urlsChanged)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A color if the data stored in the object represents a color (MIME type application/x-color); otherwise QColor().
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The graphical item on the scene that started the drag event. It may be null.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QQuickItem* source READ source WRITE setSource NOTIFY sourceChanged)
|
|
||||||
//TODO: Image property
|
|
||||||
|
|
||||||
public:
|
|
||||||
DeclarativeMimeData() : QMimeData() {}
|
|
||||||
DeclarativeMimeData(const QMimeData* copy);
|
|
||||||
|
|
||||||
QUrl url() const;
|
|
||||||
void setUrl(const QUrl &url);
|
|
||||||
|
|
||||||
QVariantList urls() const;
|
|
||||||
void setUrls(const QVariantList &urls);
|
|
||||||
|
|
||||||
QColor color() const;
|
|
||||||
void setColor(const QColor &color);
|
|
||||||
Q_INVOKABLE bool hasColor() const;
|
|
||||||
|
|
||||||
Q_INVOKABLE void setData(const QString &mimeType, const QVariant &data);
|
|
||||||
|
|
||||||
QQuickItem* source() const;
|
|
||||||
void setSource(QQuickItem* source);
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
QString text() const; //TODO: Reimplement this to issue the onChanged signals
|
|
||||||
void setText(const QString &text);
|
|
||||||
QString html() const;
|
|
||||||
void setHtml(const QString &html);
|
|
||||||
*/
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
void textChanged(); //FIXME not being used
|
|
||||||
void htmlChanged(); //FIXME not being used
|
|
||||||
void urlChanged();
|
|
||||||
void urlsChanged();
|
|
||||||
void colorChanged();
|
|
||||||
void sourceChanged();
|
|
||||||
|
|
||||||
private:
|
|
||||||
QQuickItem* m_source;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // DECLARATIVEMIMEDATA_H
|
|
@ -1,15 +0,0 @@
|
|||||||
/** @mainpage Drag and Drop
|
|
||||||
|
|
||||||
<h2>import org.kde.draganddrop</h2>
|
|
||||||
|
|
||||||
Use those elements if you want to add drag and drop support to your application
|
|
||||||
|
|
||||||
- DeclarativeDragArea
|
|
||||||
- DeclarativeDropArea
|
|
||||||
- DeclarativeDragDropEvent
|
|
||||||
- DeclarativeMimeData
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
// DOXYGEN_SET_PROJECT_NAME = DragAndDrop
|
|
||||||
// vim:ts=4:sw=4:expandtab:filetype=doxygen
|
|
@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2011 by Marco Martin <mart@kde.org>
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "draganddropplugin.h"
|
|
||||||
|
|
||||||
#include <QtQml>
|
|
||||||
|
|
||||||
#include "DeclarativeDragArea.h"
|
|
||||||
#include "DeclarativeDragDropEvent.h"
|
|
||||||
#include "DeclarativeDropArea.h"
|
|
||||||
#include "DeclarativeMimeData.h"
|
|
||||||
|
|
||||||
void DragAndDropPlugin::registerTypes(const char *uri)
|
|
||||||
{
|
|
||||||
Q_ASSERT(uri == QLatin1String("org.kde.draganddrop"));
|
|
||||||
|
|
||||||
qmlRegisterType<DeclarativeDropArea>(uri, 2, 0, "DropArea");
|
|
||||||
qmlRegisterType<DeclarativeDragArea>(uri, 2, 0, "DragArea");
|
|
||||||
qmlRegisterType<QMimeData>();
|
|
||||||
qmlRegisterUncreatableType<DeclarativeMimeData>(uri, 2, 0, "MimeData", "MimeData cannot be created from QML.");
|
|
||||||
qmlRegisterUncreatableType<DeclarativeDragDropEvent>(uri, 2, 0, "DragDropEvent", "DragDropEvent cannot be created from QML.");
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2011 by Marco Martin <mart@kde.org>
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef DRAGANDDROPPLUGIN_H
|
|
||||||
#define DRAGANDDROPPLUGIN_H
|
|
||||||
|
|
||||||
#include <QQmlExtensionPlugin>
|
|
||||||
|
|
||||||
class DragAndDropPlugin : public QQmlExtensionPlugin
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
|
|
||||||
|
|
||||||
public:
|
|
||||||
void registerTypes(const char *uri);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,3 +0,0 @@
|
|||||||
module org.kde.draganddrop
|
|
||||||
plugin draganddropplugin
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
|||||||
project(kquickcontrols)
|
|
||||||
|
|
||||||
install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/kquickcontrols)
|
|
||||||
install(FILES KeySequenceItem.qml DESTINATION ${QML_INSTALL_DIR}/org/kde/kquickcontrols)
|
|
||||||
|
|
||||||
add_subdirectory(private)
|
|
||||||
|
|
@ -1,65 +0,0 @@
|
|||||||
import QtQuick 2.0
|
|
||||||
import QtQuick.Controls 1.1
|
|
||||||
import QtQuick.Layouts 1.1
|
|
||||||
|
|
||||||
import org.kde.private.kquickcontrols 2.0 as KQuickControlsPrivate
|
|
||||||
|
|
||||||
RowLayout {
|
|
||||||
property alias showClearButton: clearButton.visible
|
|
||||||
property alias modifierlessAllowed: _helper.modifierlessAllowed
|
|
||||||
property alias multiKeyShortcutsAllowed: _helper.multiKeyShortcutsAllowed
|
|
||||||
property alias keySequence: _helper.keySequence
|
|
||||||
|
|
||||||
|
|
||||||
KQuickControlsPrivate.KeySequenceHelper {
|
|
||||||
id: _helper
|
|
||||||
|
|
||||||
onCaptureFinished: {
|
|
||||||
mainButton.checked = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Button
|
|
||||||
{
|
|
||||||
id: mainButton
|
|
||||||
|
|
||||||
iconName: "configure"
|
|
||||||
|
|
||||||
property string shortcut
|
|
||||||
checkable: true
|
|
||||||
focus: checked
|
|
||||||
|
|
||||||
text: _helper.shortcutDisplay
|
|
||||||
tooltip: i18n("Click on the button, then enter the shortcut like you would in the program.\nExample for Ctrl+A: hold the Ctrl key and press A.")
|
|
||||||
|
|
||||||
onCheckedChanged: {
|
|
||||||
if (checked) {
|
|
||||||
mainButton.forceActiveFocus()
|
|
||||||
_helper.captureKeySequence()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onFocusChanged: {
|
|
||||||
if (!focus) {
|
|
||||||
mainButton.checked = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Keys.onPressed: {
|
|
||||||
_helper.keyPressed(event.key, event.modifiers);
|
|
||||||
event.accepted = true;
|
|
||||||
}
|
|
||||||
Keys.onReleased: {
|
|
||||||
_helper.keyReleased(event.key, event.modifiers);
|
|
||||||
event.accepted = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Button {
|
|
||||||
id: clearButton
|
|
||||||
onClicked: _helper.clearKeySequence();
|
|
||||||
|
|
||||||
//icon name determines the direction of the arrow, NOT the direction of the app layout
|
|
||||||
iconName: Qt.application.layoutDirection == Qt.LeftToRight ? "edit-clear-locationbar-rtl" : "edit-clear-locationbar-ltr"
|
|
||||||
}
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
This import contains KDE extras that are visually similar to Qt Quick Controls.
|
|
@ -1,23 +0,0 @@
|
|||||||
project(kquickcontrolsprivate)
|
|
||||||
|
|
||||||
set(kquickcontrolsprivate_SRCS
|
|
||||||
kquickcontrolsprivateplugin.cpp
|
|
||||||
keysequencehelper.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
add_library(kquickcontrolsprivateplugin SHARED ${kquickcontrolsprivate_SRCS})
|
|
||||||
|
|
||||||
target_link_libraries(kquickcontrolsprivateplugin
|
|
||||||
Qt5::Core
|
|
||||||
Qt5::Quick
|
|
||||||
Qt5::Qml
|
|
||||||
KF5::I18n
|
|
||||||
KF5::ConfigGui
|
|
||||||
KF5::WidgetsAddons
|
|
||||||
KF5::WindowSystem
|
|
||||||
KF5::GlobalAccel
|
|
||||||
)
|
|
||||||
|
|
||||||
install(TARGETS kquickcontrolsprivateplugin DESTINATION ${QML_INSTALL_DIR}/org/kde/private/kquickcontrols)
|
|
||||||
|
|
||||||
install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/private/kquickcontrols)
|
|
@ -1,522 +0,0 @@
|
|||||||
/*
|
|
||||||
* <one line to give the library's name and an idea of what it does.>
|
|
||||||
* Copyright (C) 2014 David Edmundson <davidedmundson@kde.org>
|
|
||||||
* Copyright (C) 1998 Mark Donohoe <donohoe@kde.org>
|
|
||||||
* Copyright (C) 2001 Ellis Whitehead <ellis@kde.org>
|
|
||||||
* Copyright (C) 2007 Andreas Hartmetz <ahartmetz@gmail.com>
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 2.1 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This library is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this library; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "keysequencehelper.h"
|
|
||||||
|
|
||||||
#include <QAction>
|
|
||||||
#include <QKeyEvent>
|
|
||||||
#include <QTimer>
|
|
||||||
#include <QtCore/QHash>
|
|
||||||
#include <QToolButton>
|
|
||||||
#include <QApplication>
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
#include <KStandardShortcut>
|
|
||||||
#include <KLocalizedString>
|
|
||||||
#include <KMessageBox>
|
|
||||||
#include <KKeyServer>
|
|
||||||
#include <KGlobalAccel/KGlobalShortcutInfo>
|
|
||||||
#include <KGlobalAccel/KGlobalAccel>
|
|
||||||
|
|
||||||
uint qHash(const QKeySequence &seq)
|
|
||||||
{
|
|
||||||
return qHash(seq.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
class KeySequenceHelperPrivate
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
KeySequenceHelperPrivate(KeySequenceHelper *q);
|
|
||||||
|
|
||||||
void init();
|
|
||||||
|
|
||||||
static QKeySequence appendToSequence(const QKeySequence &seq, int keyQt);
|
|
||||||
static bool isOkWhenModifierless(int keyQt);
|
|
||||||
|
|
||||||
void updateShortcutDisplay();
|
|
||||||
void startRecording();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Conflicts the key sequence @a seq with a current standard
|
|
||||||
* shortcut?
|
|
||||||
*/
|
|
||||||
bool conflictWithStandardShortcuts(const QKeySequence &seq);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Conflicts the key sequence @a seq with a current global
|
|
||||||
* shortcut?
|
|
||||||
*/
|
|
||||||
bool conflictWithGlobalShortcuts(const QKeySequence &seq);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get permission to steal the shortcut @seq from the standard shortcut @a std.
|
|
||||||
*/
|
|
||||||
bool stealStandardShortcut(KStandardShortcut::StandardShortcut std, const QKeySequence &seq);
|
|
||||||
|
|
||||||
bool checkAgainstStandardShortcuts() const
|
|
||||||
{
|
|
||||||
return checkAgainstShortcutTypes & KeySequenceHelper::StandardShortcuts;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool checkAgainstGlobalShortcuts() const
|
|
||||||
{
|
|
||||||
return checkAgainstShortcutTypes & KeySequenceHelper::GlobalShortcuts;
|
|
||||||
}
|
|
||||||
|
|
||||||
void controlModifierlessTimout()
|
|
||||||
{
|
|
||||||
if (nKey != 0 && !modifierKeys) {
|
|
||||||
// No modifier key pressed currently. Start the timout
|
|
||||||
modifierlessTimeout.start(600);
|
|
||||||
} else {
|
|
||||||
// A modifier is pressed. Stop the timeout
|
|
||||||
modifierlessTimeout.stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void cancelRecording()
|
|
||||||
{
|
|
||||||
keySequence = oldKeySequence;
|
|
||||||
q->doneRecording();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//members
|
|
||||||
KeySequenceHelper *const q;
|
|
||||||
QToolButton *clearButton;
|
|
||||||
|
|
||||||
QKeySequence keySequence;
|
|
||||||
QKeySequence oldKeySequence;
|
|
||||||
QTimer modifierlessTimeout;
|
|
||||||
bool allowModifierless;
|
|
||||||
uint nKey;
|
|
||||||
uint modifierKeys;
|
|
||||||
bool isRecording;
|
|
||||||
bool multiKeyShortcutsAllowed;
|
|
||||||
QString componentName;
|
|
||||||
QString shortcutDisplay;
|
|
||||||
|
|
||||||
//! Check the key sequence against KStandardShortcut::find()
|
|
||||||
KeySequenceHelper::ShortcutTypes checkAgainstShortcutTypes;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The list of action to check against for conflict shortcut
|
|
||||||
*/
|
|
||||||
QList<QAction *> checkList; // deprecated
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The list of action collections to check against for conflict shortcut
|
|
||||||
*/
|
|
||||||
// QList<KActionCollection *> checkActionCollections;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The action to steal the shortcut from.
|
|
||||||
*/
|
|
||||||
QList<QAction *> stealActions;
|
|
||||||
|
|
||||||
bool stealShortcuts(const QList<QAction *> &actions, const QKeySequence &seq);
|
|
||||||
void wontStealShortcut(QAction *item, const QKeySequence &seq);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
KeySequenceHelperPrivate::KeySequenceHelperPrivate(KeySequenceHelper *q)
|
|
||||||
: q(q)
|
|
||||||
, allowModifierless(false)
|
|
||||||
, nKey(0)
|
|
||||||
, modifierKeys(0)
|
|
||||||
, isRecording(false)
|
|
||||||
, multiKeyShortcutsAllowed(true)
|
|
||||||
, componentName()
|
|
||||||
, checkAgainstShortcutTypes(KeySequenceHelper::StandardShortcuts | KeySequenceHelper::GlobalShortcuts)
|
|
||||||
, stealActions()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
KeySequenceHelper::KeySequenceHelper(QObject* parent):
|
|
||||||
QObject(),
|
|
||||||
d(new KeySequenceHelperPrivate(this))
|
|
||||||
{
|
|
||||||
connect(&d->modifierlessTimeout, SIGNAL(timeout()), this, SLOT(doneRecording()));
|
|
||||||
d->updateShortcutDisplay();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
KeySequenceHelper::~KeySequenceHelper()
|
|
||||||
{
|
|
||||||
delete d;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool KeySequenceHelper::multiKeyShortcutsAllowed() const
|
|
||||||
{
|
|
||||||
return d->multiKeyShortcutsAllowed;
|
|
||||||
}
|
|
||||||
|
|
||||||
void KeySequenceHelper::setMultiKeyShortcutsAllowed(bool allowed)
|
|
||||||
{
|
|
||||||
d->multiKeyShortcutsAllowed = allowed;
|
|
||||||
}
|
|
||||||
|
|
||||||
void KeySequenceHelper::setModifierlessAllowed(bool allow)
|
|
||||||
{
|
|
||||||
d->allowModifierless = allow;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool KeySequenceHelper::isModifierlessAllowed()
|
|
||||||
{
|
|
||||||
return d->allowModifierless;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool KeySequenceHelper::isKeySequenceAvailable(const QKeySequence& keySequence) const
|
|
||||||
{
|
|
||||||
if (keySequence.isEmpty()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return !(d->conflictWithGlobalShortcuts(keySequence)
|
|
||||||
|| d->conflictWithStandardShortcuts(keySequence));
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// void KeySequenceHelper::setCheckActionCollections(const QList<KActionCollection *> &actionCollections)
|
|
||||||
// {
|
|
||||||
// d->checkActionCollections = actionCollections;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
|
|
||||||
//slot
|
|
||||||
void KeySequenceHelper::captureKeySequence()
|
|
||||||
{
|
|
||||||
d->startRecording();
|
|
||||||
}
|
|
||||||
|
|
||||||
QKeySequence KeySequenceHelper::keySequence() const
|
|
||||||
{
|
|
||||||
return d->keySequence;
|
|
||||||
}
|
|
||||||
|
|
||||||
void KeySequenceHelper::setKeySequence(const QKeySequence& sequence)
|
|
||||||
{
|
|
||||||
if (!d->isRecording) {
|
|
||||||
d->oldKeySequence = d->keySequence;
|
|
||||||
}
|
|
||||||
d->keySequence = sequence;
|
|
||||||
d->updateShortcutDisplay();
|
|
||||||
emit keySequenceChanged(d->keySequence);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void KeySequenceHelper::clearKeySequence()
|
|
||||||
{
|
|
||||||
setKeySequence(QKeySequence());
|
|
||||||
}
|
|
||||||
|
|
||||||
void KeySequenceHelperPrivate::startRecording()
|
|
||||||
{
|
|
||||||
nKey = 0;
|
|
||||||
modifierKeys = 0;
|
|
||||||
oldKeySequence = keySequence;
|
|
||||||
keySequence = QKeySequence();
|
|
||||||
isRecording = true;
|
|
||||||
|
|
||||||
updateShortcutDisplay();
|
|
||||||
}
|
|
||||||
//
|
|
||||||
void KeySequenceHelper::doneRecording()
|
|
||||||
{
|
|
||||||
d->modifierlessTimeout.stop();
|
|
||||||
d->isRecording = false;
|
|
||||||
d->stealActions.clear();
|
|
||||||
|
|
||||||
if (d->keySequence == d->oldKeySequence) {
|
|
||||||
// The sequence hasn't changed
|
|
||||||
d->updateShortcutDisplay();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! isKeySequenceAvailable(d->keySequence)) {
|
|
||||||
// The sequence had conflicts and the user said no to stealing it
|
|
||||||
d->keySequence = d->oldKeySequence;
|
|
||||||
} else {
|
|
||||||
emit keySequenceChanged(d->keySequence);
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_EMIT captureFinished();
|
|
||||||
|
|
||||||
d->updateShortcutDisplay();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool KeySequenceHelperPrivate::conflictWithGlobalShortcuts(const QKeySequence &keySequence)
|
|
||||||
{
|
|
||||||
#ifdef Q_OS_WIN
|
|
||||||
//on windows F12 is reserved by the debugger at all times, so we can't use it for a global shortcut
|
|
||||||
if (KeySequenceHelper::GlobalShortcuts && keySequence.toString().contains("F12")) {
|
|
||||||
QString title = i18n("Reserved Shortcut");
|
|
||||||
QString message = i18n("The F12 key is reserved on Windows, so cannot be used for a global shortcut.\n"
|
|
||||||
"Please choose another one.");
|
|
||||||
|
|
||||||
KMessageBox::sorry(q, message, title);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!(checkAgainstShortcutTypes & KeySequenceHelper::GlobalShortcuts)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Global shortcuts are on key+modifier shortcuts. They can clash with
|
|
||||||
// each of the keys of a multi key shortcut.
|
|
||||||
QList<KGlobalShortcutInfo> others;
|
|
||||||
for (int i = 0; i < keySequence.count(); ++i) {
|
|
||||||
QKeySequence tmp(keySequence[i]);
|
|
||||||
|
|
||||||
if (!KGlobalAccel::isGlobalShortcutAvailable(tmp, componentName)) {
|
|
||||||
others << KGlobalAccel::getGlobalShortcutsByKey(tmp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!others.isEmpty()
|
|
||||||
&& !KGlobalAccel::promptStealShortcutSystemwide(0, others, keySequence)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// The user approved stealing the shortcut. We have to steal
|
|
||||||
// it immediately because KAction::setGlobalShortcut() refuses
|
|
||||||
// to set a global shortcut that is already used. There is no
|
|
||||||
// error it just silently fails. So be nice because this is
|
|
||||||
// most likely the first action that is done in the slot
|
|
||||||
// listening to keySequenceChanged().
|
|
||||||
for (int i = 0; i < keySequence.count(); ++i) {
|
|
||||||
KGlobalAccel::stealShortcutSystemwide(keySequence[i]);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool KeySequenceHelperPrivate::conflictWithStandardShortcuts(const QKeySequence &keySequence)
|
|
||||||
{
|
|
||||||
if (!checkAgainstStandardShortcuts()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
KStandardShortcut::StandardShortcut ssc = KStandardShortcut::find(keySequence);
|
|
||||||
if (ssc != KStandardShortcut::AccelNone && !stealStandardShortcut(ssc, keySequence)) {
|
|
||||||
qDebug() << "!!!!!!!!!!!!!!";
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool KeySequenceHelperPrivate::stealStandardShortcut(KStandardShortcut::StandardShortcut std, const QKeySequence &seq)
|
|
||||||
{
|
|
||||||
QString title = i18n("Conflict with Standard Application Shortcut");
|
|
||||||
QString message = i18n("The '%1' key combination is also used for the standard action "
|
|
||||||
"\"%2\" that some applications use.\n"
|
|
||||||
"Do you really want to use it as a global shortcut as well?",
|
|
||||||
seq.toString(QKeySequence::NativeText), KStandardShortcut::label(std));
|
|
||||||
|
|
||||||
if (KMessageBox::warningContinueCancel(0, message, title, KGuiItem(i18n("Reassign"))) != KMessageBox::Continue) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void KeySequenceHelperPrivate::updateShortcutDisplay()
|
|
||||||
{
|
|
||||||
//empty string if no non-modifier was pressed
|
|
||||||
QString s = keySequence.toString(QKeySequence::NativeText);
|
|
||||||
s.replace(QLatin1Char('&'), QStringLiteral("&&"));
|
|
||||||
|
|
||||||
if (isRecording) {
|
|
||||||
if (modifierKeys) {
|
|
||||||
if (!s.isEmpty()) {
|
|
||||||
s.append(QLatin1Char(','));
|
|
||||||
}
|
|
||||||
if (modifierKeys & Qt::META) {
|
|
||||||
s += KKeyServer::modToStringUser(Qt::META) + QLatin1Char('+');
|
|
||||||
}
|
|
||||||
#if defined(Q_OS_MAC)
|
|
||||||
if (modifierKeys & Qt::ALT) {
|
|
||||||
s += KKeyServer::modToStringUser(Qt::ALT) + QLatin1Char('+');
|
|
||||||
}
|
|
||||||
if (modifierKeys & Qt::CTRL) {
|
|
||||||
s += KKeyServer::modToStringUser(Qt::CTRL) + QLatin1Char('+');
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (modifierKeys & Qt::CTRL) {
|
|
||||||
s += KKeyServer::modToStringUser(Qt::CTRL) + QLatin1Char('+');
|
|
||||||
}
|
|
||||||
if (modifierKeys & Qt::ALT) {
|
|
||||||
s += KKeyServer::modToStringUser(Qt::ALT) + QLatin1Char('+');
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (modifierKeys & Qt::SHIFT) {
|
|
||||||
s += KKeyServer::modToStringUser(Qt::SHIFT) + QLatin1Char('+');
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (nKey == 0) {
|
|
||||||
s = i18nc("What the user inputs now will be taken as the new shortcut", "Input");
|
|
||||||
}
|
|
||||||
//make it clear that input is still going on
|
|
||||||
s.append(QStringLiteral(" ..."));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s.isEmpty()) {
|
|
||||||
s = i18nc("No shortcut defined", "None");
|
|
||||||
}
|
|
||||||
|
|
||||||
s.prepend(QLatin1Char(' '));
|
|
||||||
s.append(QLatin1Char(' '));
|
|
||||||
shortcutDisplay = s;
|
|
||||||
q->shortcutDisplayChanged(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString KeySequenceHelper::shortcutDisplay() const
|
|
||||||
{
|
|
||||||
return d->shortcutDisplay;
|
|
||||||
}
|
|
||||||
|
|
||||||
void KeySequenceHelper::keyPressed(int key, int modifiers)
|
|
||||||
{
|
|
||||||
if (key == -1) {
|
|
||||||
// Qt sometimes returns garbage keycodes, I observed -1, if it doesn't know a key.
|
|
||||||
// We cannot do anything useful with those (several keys have -1, indistinguishable)
|
|
||||||
// and QKeySequence.toString() will also yield a garbage string.
|
|
||||||
KMessageBox::sorry(0,
|
|
||||||
i18n("The key you just pressed is not supported by Qt."),
|
|
||||||
i18n("Unsupported Key"));
|
|
||||||
return d->cancelRecording();
|
|
||||||
}
|
|
||||||
|
|
||||||
//don't have the return or space key appear as first key of the sequence when they
|
|
||||||
//were pressed to start editing - catch and them and imitate their effect
|
|
||||||
if (!d->isRecording && ((key == Qt::Key_Return || key == Qt::Key_Space))) {
|
|
||||||
d->startRecording();
|
|
||||||
d->modifierKeys = modifiers;
|
|
||||||
d->updateShortcutDisplay();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
d->modifierKeys = modifiers;
|
|
||||||
|
|
||||||
switch (key) {
|
|
||||||
case Qt::Key_AltGr: //or else we get unicode salad
|
|
||||||
return;
|
|
||||||
case Qt::Key_Shift:
|
|
||||||
case Qt::Key_Control:
|
|
||||||
case Qt::Key_Alt:
|
|
||||||
case Qt::Key_Meta:
|
|
||||||
case Qt::Key_Menu: //unused (yes, but why?)
|
|
||||||
d->controlModifierlessTimout();
|
|
||||||
d->updateShortcutDisplay();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
|
|
||||||
if (d->nKey == 0 && !(d->modifierKeys & ~Qt::SHIFT)) {
|
|
||||||
// It's the first key and no modifier pressed. Check if this is
|
|
||||||
// allowed
|
|
||||||
if (!(KeySequenceHelperPrivate::isOkWhenModifierless(key)
|
|
||||||
|| d->allowModifierless)) {
|
|
||||||
// No it's not
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// We now have a valid key press.
|
|
||||||
if (key) {
|
|
||||||
if ((key == Qt::Key_Backtab) && (d->modifierKeys & Qt::SHIFT)) {
|
|
||||||
key = Qt::Key_Tab | d->modifierKeys;
|
|
||||||
} else {
|
|
||||||
key |= (d->modifierKeys);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (d->nKey == 0) {
|
|
||||||
d->keySequence = QKeySequence(key);
|
|
||||||
} else {
|
|
||||||
d->keySequence =
|
|
||||||
KeySequenceHelperPrivate::appendToSequence(d->keySequence, key);
|
|
||||||
}
|
|
||||||
|
|
||||||
d->nKey++;
|
|
||||||
if ((!d->multiKeyShortcutsAllowed) || (d->nKey >= 4)) {
|
|
||||||
doneRecording();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
d->controlModifierlessTimout();
|
|
||||||
d->updateShortcutDisplay();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//
|
|
||||||
void KeySequenceHelper::keyReleased(int key, int modifiers)
|
|
||||||
{
|
|
||||||
if (key == -1) {
|
|
||||||
// ignore garbage, see keyPressEvent()
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//if a modifier that belongs to the shortcut was released...
|
|
||||||
if ((modifiers & d->modifierKeys) < d->modifierKeys) {
|
|
||||||
d->modifierKeys = modifiers;
|
|
||||||
d->controlModifierlessTimout();
|
|
||||||
d->updateShortcutDisplay();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//
|
|
||||||
//static
|
|
||||||
QKeySequence KeySequenceHelperPrivate::appendToSequence(const QKeySequence &seq, int keyQt)
|
|
||||||
{
|
|
||||||
switch (seq.count()) {
|
|
||||||
case 0:
|
|
||||||
return QKeySequence(keyQt);
|
|
||||||
case 1:
|
|
||||||
return QKeySequence(seq[0], keyQt);
|
|
||||||
case 2:
|
|
||||||
return QKeySequence(seq[0], seq[1], keyQt);
|
|
||||||
case 3:
|
|
||||||
return QKeySequence(seq[0], seq[1], seq[2], keyQt);
|
|
||||||
default:
|
|
||||||
return seq;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//
|
|
||||||
//static
|
|
||||||
bool KeySequenceHelperPrivate::isOkWhenModifierless(int keyQt)
|
|
||||||
{
|
|
||||||
//this whole function is a hack, but especially the first line of code
|
|
||||||
if (QKeySequence(keyQt).toString().length() == 1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (keyQt) {
|
|
||||||
case Qt::Key_Return:
|
|
||||||
case Qt::Key_Space:
|
|
||||||
case Qt::Key_Tab:
|
|
||||||
case Qt::Key_Backtab: //does this ever happen?
|
|
||||||
case Qt::Key_Backspace:
|
|
||||||
case Qt::Key_Delete:
|
|
||||||
return false;
|
|
||||||
default:
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,148 +0,0 @@
|
|||||||
/*
|
|
||||||
* <one line to give the library's name and an idea of what it does.>
|
|
||||||
* Copyright (C) 2014 David Edmundson <davidedmundson@kde.org>
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 2.1 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This library is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this library; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef KEYSEQUENCEHELPER_H
|
|
||||||
#define KEYSEQUENCEHELPER_H
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QKeySequence>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class is a clone of Key from XMLGUI
|
|
||||||
* It performs only the logic of building shortcuts
|
|
||||||
* It is a private class to be used by KeySequenceItem
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
class KeySequenceHelperPrivate;
|
|
||||||
|
|
||||||
class KeySequenceHelper : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
Q_FLAGS(ShortcutTypes)
|
|
||||||
|
|
||||||
Q_PROPERTY(
|
|
||||||
QKeySequence keySequence
|
|
||||||
READ keySequence
|
|
||||||
WRITE setKeySequence
|
|
||||||
NOTIFY keySequenceChanged)
|
|
||||||
|
|
||||||
Q_PROPERTY(
|
|
||||||
bool multiKeyShortcutsAllowed
|
|
||||||
READ multiKeyShortcutsAllowed
|
|
||||||
WRITE setMultiKeyShortcutsAllowed)
|
|
||||||
|
|
||||||
Q_PROPERTY(
|
|
||||||
QString shortcutDisplay
|
|
||||||
READ shortcutDisplay
|
|
||||||
NOTIFY shortcutDisplayChanged)
|
|
||||||
|
|
||||||
Q_PROPERTY(
|
|
||||||
bool modifierlessAllowed
|
|
||||||
READ isModifierlessAllowed
|
|
||||||
WRITE setModifierlessAllowed)
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
enum ShortcutType {
|
|
||||||
None = 0x00, //!< No checking for conflicts
|
|
||||||
StandardShortcuts = 0x01, //!< Check against standard shortcuts. @see KStandardShortcut
|
|
||||||
GlobalShortcuts = 0x02 //!< Check against global shortcuts. @see KGlobalAccel
|
|
||||||
};
|
|
||||||
Q_DECLARE_FLAGS(ShortcutTypes, ShortcutType)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor.
|
|
||||||
*/
|
|
||||||
explicit KeySequenceHelper(QObject* parent = 0);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Destructs the widget.
|
|
||||||
*/
|
|
||||||
virtual ~KeySequenceHelper();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Allow multikey shortcuts?
|
|
||||||
*/
|
|
||||||
void setMultiKeyShortcutsAllowed(bool);
|
|
||||||
bool multiKeyShortcutsAllowed() const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This only applies to user input, not to setShortcut().
|
|
||||||
* Set whether to accept "plain" keys without modifiers (like Ctrl, Alt, Meta).
|
|
||||||
* Plain keys by our definition include letter and symbol keys and
|
|
||||||
* text editing keys (Return, Space, Tab, Backspace, Delete).
|
|
||||||
* "Special" keys like F1, Cursor keys, Insert, PageDown will always work.
|
|
||||||
*/
|
|
||||||
void setModifierlessAllowed(bool allow);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see setModifierlessAllowed()
|
|
||||||
*/
|
|
||||||
bool isModifierlessAllowed();
|
|
||||||
|
|
||||||
|
|
||||||
bool isRecording() const;
|
|
||||||
void setShortcut(bool recording);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the default key sequence from a string
|
|
||||||
*/
|
|
||||||
void setKeySequence(const QKeySequence &sequence);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the currently selected key sequence as a string
|
|
||||||
*/
|
|
||||||
QKeySequence keySequence() const;
|
|
||||||
QString shortcutDisplay() const;
|
|
||||||
|
|
||||||
bool isKeySequenceAvailable(const QKeySequence &keySequence) const;
|
|
||||||
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
void keySequenceChanged(const QKeySequence &seq);
|
|
||||||
void shortcutDisplayChanged(const QString &string);
|
|
||||||
void captureFinished();
|
|
||||||
|
|
||||||
public Q_SLOTS:
|
|
||||||
void captureKeySequence();
|
|
||||||
void keyPressed(int key, int modifiers);
|
|
||||||
void keyReleased(int key, int modifiers);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clear the key sequence.
|
|
||||||
*/
|
|
||||||
void clearKeySequence();
|
|
||||||
|
|
||||||
private Q_SLOTS:
|
|
||||||
void doneRecording();
|
|
||||||
|
|
||||||
private:
|
|
||||||
friend class KeySequenceHelperPrivate;
|
|
||||||
KeySequenceHelperPrivate *const d;
|
|
||||||
|
|
||||||
Q_DISABLE_COPY(KeySequenceHelper)
|
|
||||||
};
|
|
||||||
|
|
||||||
Q_DECLARE_OPERATORS_FOR_FLAGS(KeySequenceHelper::ShortcutTypes)
|
|
||||||
|
|
||||||
|
|
||||||
#endif // KEYSEQUENCEHELPER_H
|
|
@ -1,31 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2014 David Edmundson <davidedmundson@kde.org>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Library General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Library General Public
|
|
||||||
* License along with this program; if not, write to the
|
|
||||||
* Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "kquickcontrolsprivateplugin.h"
|
|
||||||
|
|
||||||
#include <QtQml>
|
|
||||||
|
|
||||||
#include "keysequencehelper.h"
|
|
||||||
|
|
||||||
void KQuickControlsPrivatePlugin::registerTypes(const char *uri)
|
|
||||||
{
|
|
||||||
Q_ASSERT(uri == QLatin1String("org.kde.private.kquickcontrols"));
|
|
||||||
qmlRegisterType<KeySequenceHelper>(uri, 2, 0, "KeySequenceHelper");
|
|
||||||
}
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2014 David Edmundson <davidedmundson@kde.org>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Library General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Library General Public
|
|
||||||
* License along with this program; if not, write to the
|
|
||||||
* Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef KQUICKCONTROLSPRIVATEPLUGIN_H
|
|
||||||
#define KQUICKCONTROLSPRIVATEPLUGIN_H
|
|
||||||
|
|
||||||
#include <QQmlExtensionPlugin>
|
|
||||||
|
|
||||||
class KQuickControlsPrivatePlugin : public QQmlExtensionPlugin
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
|
|
||||||
|
|
||||||
public:
|
|
||||||
void registerTypes(const char *uri);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,4 +0,0 @@
|
|||||||
module org.kde.private.kquickcontrols
|
|
||||||
plugin kquickcontrolsprivateplugin
|
|
||||||
|
|
||||||
ShortcutButton 2.0 ShortcutButton.qml
|
|
@ -1 +0,0 @@
|
|||||||
KeySequenceItem 2.0 KeySequenceItem.qml
|
|
@ -1,27 +0,0 @@
|
|||||||
project(qtextracomponents)
|
|
||||||
|
|
||||||
add_subdirectory(tests)
|
|
||||||
|
|
||||||
set(qtextracomponents_SRCS
|
|
||||||
qtextracomponentsplugin.cpp
|
|
||||||
qpixmapitem.cpp
|
|
||||||
qimageitem.cpp
|
|
||||||
qiconitem.cpp
|
|
||||||
mouseeventlistener.cpp
|
|
||||||
columnproxymodel.cpp
|
|
||||||
clipboard.cpp
|
|
||||||
mimedatabase.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
add_library(qtextracomponentsplugin SHARED ${qtextracomponents_SRCS})
|
|
||||||
|
|
||||||
target_link_libraries(qtextracomponentsplugin
|
|
||||||
Qt5::Core
|
|
||||||
Qt5::Quick
|
|
||||||
Qt5::Qml
|
|
||||||
Qt5::Gui
|
|
||||||
KF5::IconThemes)
|
|
||||||
|
|
||||||
install(TARGETS qtextracomponentsplugin DESTINATION ${QML_INSTALL_DIR}/org/kde/qtextracomponents)
|
|
||||||
|
|
||||||
install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/qtextracomponents)
|
|
@ -1,14 +0,0 @@
|
|||||||
/** @mainpage Qt Extra Components
|
|
||||||
|
|
||||||
<h2>import org.kde.qtextracomponents</h2>
|
|
||||||
|
|
||||||
- QPixmapItem
|
|
||||||
- QImageItem
|
|
||||||
- QIconItem
|
|
||||||
- MouseEventListener
|
|
||||||
- ColumnProxyModel
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
// DOXYGEN_SET_PROJECT_NAME = QtExtraComponents
|
|
||||||
// vim:ts=4:sw=4:expandtab:filetype=doxygen
|
|
@ -1,128 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2014 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Library General Public
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 2 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This library is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* Library General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Library General Public License
|
|
||||||
* along with this library; see the file COPYING.LIB. If not, write to
|
|
||||||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
||||||
* Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "clipboard.h"
|
|
||||||
#include <QGuiApplication>
|
|
||||||
#include <QMimeData>
|
|
||||||
#include <QUrl>
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
Clipboard::Clipboard(QObject* parent)
|
|
||||||
: QObject(parent)
|
|
||||||
, m_clipboard(QGuiApplication::clipboard())
|
|
||||||
, m_mode(QClipboard::Clipboard)
|
|
||||||
{
|
|
||||||
connect(m_clipboard, SIGNAL(changed(QClipboard::Mode)), SLOT(clipboardChanged(QClipboard::Mode)));
|
|
||||||
}
|
|
||||||
|
|
||||||
void Clipboard::setMode(QClipboard::Mode mode)
|
|
||||||
{
|
|
||||||
m_mode = mode;
|
|
||||||
emit modeChanged(m_mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Clipboard::clipboardChanged(QClipboard::Mode m)
|
|
||||||
{
|
|
||||||
if (m == m_mode) {
|
|
||||||
emit contentChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Clipboard::clear()
|
|
||||||
{
|
|
||||||
m_clipboard->clear(m_mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
QClipboard::Mode Clipboard::mode() const
|
|
||||||
{
|
|
||||||
return m_mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariant Clipboard::contentFormat(const QString &format) const
|
|
||||||
{
|
|
||||||
const QMimeData* data = m_clipboard->mimeData(m_mode);
|
|
||||||
QVariant ret;
|
|
||||||
if(format == QStringLiteral("text/uri-list")) {
|
|
||||||
QVariantList retList;
|
|
||||||
foreach(const QUrl& url, data->urls())
|
|
||||||
retList += url;
|
|
||||||
ret = retList;
|
|
||||||
} else if(format.startsWith(QStringLiteral("text/"))) {
|
|
||||||
ret = data->text();
|
|
||||||
} else if(format.startsWith(QStringLiteral("image/"))) {
|
|
||||||
ret = data->imageData();
|
|
||||||
} else
|
|
||||||
ret = data->data(format.isEmpty() ? data->formats().first(): format);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariant Clipboard::content() const
|
|
||||||
{
|
|
||||||
return contentFormat(m_clipboard->mimeData(m_mode)->formats().first());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Clipboard::setContent(const QVariant &content)
|
|
||||||
{
|
|
||||||
QMimeData* mimeData = new QMimeData;
|
|
||||||
switch(content.type())
|
|
||||||
{
|
|
||||||
case QVariant::String:
|
|
||||||
mimeData->setText(content.toString());
|
|
||||||
break;
|
|
||||||
case QVariant::Color:
|
|
||||||
mimeData->setColorData(content.toString());
|
|
||||||
break;
|
|
||||||
case QVariant::Pixmap:
|
|
||||||
case QVariant::Image:
|
|
||||||
mimeData->setImageData(content);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (content.type() == QVariant::List) {
|
|
||||||
QVariantList list = content.toList();
|
|
||||||
QList<QUrl> urls;
|
|
||||||
bool wasUrlList = true;
|
|
||||||
foreach (const QVariant& url, list) {
|
|
||||||
if (url.type() != QVariant::Url) {
|
|
||||||
wasUrlList = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
urls += url.toUrl();
|
|
||||||
}
|
|
||||||
if(wasUrlList) {
|
|
||||||
mimeData->setUrls(urls);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (content.canConvert(QVariant::String)) {
|
|
||||||
mimeData->setText(content.toString());
|
|
||||||
} else {
|
|
||||||
mimeData->setData("application/octet-stream", content.toByteArray());
|
|
||||||
qWarning() << "Couldn't figure out the content type, storing as application/octet-stream";
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
m_clipboard->setMimeData(mimeData, m_mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList Clipboard::formats() const
|
|
||||||
{
|
|
||||||
return m_clipboard->mimeData(m_mode)->formats();
|
|
||||||
}
|
|
@ -1,73 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2014 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Library General Public
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 2 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This library is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* Library General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Library General Public License
|
|
||||||
* along with this library; see the file COPYING.LIB. If not, write to
|
|
||||||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
||||||
* Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef CLIPBOARD_H
|
|
||||||
#define CLIPBOARD_H
|
|
||||||
|
|
||||||
#include <QClipboard>
|
|
||||||
#include <QVariant>
|
|
||||||
#include <QMimeData>
|
|
||||||
|
|
||||||
class ClipboardPrivate;
|
|
||||||
|
|
||||||
class Clipboard : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
/**
|
|
||||||
* Controls the state this object will be monitoring and extracting its contents from.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QClipboard::Mode mode READ mode WRITE setMode NOTIFY modeChanged);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides the contents currently in the clipboard and lets modify them.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QVariant content READ content WRITE setContent NOTIFY contentChanged);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Figure out the nature of the contents in the clipboard.
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(QStringList formats READ formats NOTIFY contentChanged);
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit Clipboard(QObject* parent = 0);
|
|
||||||
|
|
||||||
QClipboard::Mode mode() const;
|
|
||||||
void setMode(QClipboard::Mode mode);
|
|
||||||
|
|
||||||
Q_SCRIPTABLE QVariant contentFormat(const QString &format) const;
|
|
||||||
QVariant content() const;
|
|
||||||
void setContent(const QVariant &content);
|
|
||||||
|
|
||||||
QStringList formats() const;
|
|
||||||
|
|
||||||
Q_SCRIPTABLE void clear();
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
void modeChanged(QClipboard::Mode mode);
|
|
||||||
void contentChanged();
|
|
||||||
|
|
||||||
private Q_SLOTS:
|
|
||||||
void clipboardChanged(QClipboard::Mode m);
|
|
||||||
|
|
||||||
private:
|
|
||||||
QClipboard* m_clipboard;
|
|
||||||
QClipboard::Mode m_mode;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,235 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012 by Aleix Pol Gonzalez <aleixpol@blue-systems.com>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Library General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Library General Public
|
|
||||||
* License along with this program; if not, write to the
|
|
||||||
* Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "columnproxymodel.h"
|
|
||||||
|
|
||||||
ColumnProxyModel::ColumnProxyModel(QObject* parent)
|
|
||||||
: QAbstractListModel(parent)
|
|
||||||
, m_column(0)
|
|
||||||
, m_sourceModel(0)
|
|
||||||
{}
|
|
||||||
|
|
||||||
void ColumnProxyModel::setSourceModel(QAbstractItemModel* sourceModel)
|
|
||||||
{
|
|
||||||
if(sourceModel==m_sourceModel) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
beginResetModel();
|
|
||||||
if(m_sourceModel) {
|
|
||||||
disconnect(m_sourceModel, SIGNAL(destroyed(QObject*)),
|
|
||||||
this, SLOT(sourceDestroyed(QObject*)));
|
|
||||||
|
|
||||||
disconnect(m_sourceModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
|
|
||||||
this, SLOT(considerDataChanged(QModelIndex,QModelIndex)));
|
|
||||||
disconnect(m_sourceModel, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
|
|
||||||
this, SLOT(considerRowsAboutToBeInserted(QModelIndex,int,int)));
|
|
||||||
disconnect(m_sourceModel, SIGNAL(rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)),
|
|
||||||
this, SLOT(considerRowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)));
|
|
||||||
disconnect(m_sourceModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
|
|
||||||
this, SLOT(considerRowsAboutToBeRemoved(QModelIndex,int,int)));
|
|
||||||
disconnect(m_sourceModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
|
|
||||||
this, SLOT(considerRowsInserted(QModelIndex,int,int)));
|
|
||||||
disconnect(m_sourceModel, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)),
|
|
||||||
this, SLOT(considerRowsMoved(QModelIndex,int,int,QModelIndex,int)));
|
|
||||||
disconnect(m_sourceModel, SIGNAL(rowsRemoved(QModelIndex,int,int)),
|
|
||||||
this, SLOT(considerRowsRemoved(QModelIndex,int,int)));
|
|
||||||
|
|
||||||
disconnect(m_sourceModel, SIGNAL(modelAboutToBeReset()),
|
|
||||||
this, SIGNAL(modelAboutToBeReset()));
|
|
||||||
disconnect(m_sourceModel, SIGNAL(modelReset()),
|
|
||||||
this, SIGNAL(modelReset()));
|
|
||||||
disconnect(m_sourceModel, SIGNAL(headerDataChanged(Qt::Orientation,int,int)),
|
|
||||||
this, SIGNAL(headerDataChanged(Qt::Orientation,int,int)));
|
|
||||||
disconnect(m_sourceModel, SIGNAL(layoutAboutToBeChanged()),
|
|
||||||
this, SIGNAL(layoutAboutToBeChanged()));
|
|
||||||
disconnect(m_sourceModel, SIGNAL(layoutChanged()),
|
|
||||||
this, SIGNAL(layoutChanged()));
|
|
||||||
}
|
|
||||||
m_sourceModel = sourceModel;
|
|
||||||
if(m_sourceModel) {
|
|
||||||
setRoleNames(m_sourceModel->roleNames());
|
|
||||||
connect(m_sourceModel, SIGNAL(destroyed(QObject*)),
|
|
||||||
this, SLOT(sourceDestroyed(QObject*)));
|
|
||||||
|
|
||||||
connect(m_sourceModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
|
|
||||||
this, SLOT(considerDataChanged(QModelIndex,QModelIndex)));
|
|
||||||
connect(m_sourceModel, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
|
|
||||||
this, SLOT(considerRowsAboutToBeInserted(QModelIndex,int,int)));
|
|
||||||
connect(m_sourceModel, SIGNAL(rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)),
|
|
||||||
this, SLOT(considerRowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)));
|
|
||||||
connect(m_sourceModel, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
|
|
||||||
this, SLOT(considerRowsAboutToBeRemoved(QModelIndex,int,int)));
|
|
||||||
connect(m_sourceModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
|
|
||||||
this, SLOT(considerRowsInserted(QModelIndex,int,int)));
|
|
||||||
connect(m_sourceModel, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)),
|
|
||||||
this, SLOT(considerRowsMoved(QModelIndex,int,int,QModelIndex,int)));
|
|
||||||
connect(m_sourceModel, SIGNAL(rowsRemoved(QModelIndex,int,int)),
|
|
||||||
this, SLOT(considerRowsRemoved(QModelIndex,int,int)));
|
|
||||||
|
|
||||||
connect(m_sourceModel, SIGNAL(modelAboutToBeReset()),
|
|
||||||
this, SIGNAL(modelAboutToBeReset()));
|
|
||||||
connect(m_sourceModel, SIGNAL(modelReset()),
|
|
||||||
this, SIGNAL(modelReset()));
|
|
||||||
connect(m_sourceModel, SIGNAL(headerDataChanged(Qt::Orientation,int,int)),
|
|
||||||
this, SIGNAL(headerDataChanged(Qt::Orientation,int,int)));
|
|
||||||
connect(m_sourceModel, SIGNAL(layoutAboutToBeChanged()),
|
|
||||||
this, SIGNAL(layoutAboutToBeChanged()));
|
|
||||||
connect(m_sourceModel, SIGNAL(layoutChanged()),
|
|
||||||
this, SIGNAL(layoutChanged()));
|
|
||||||
}
|
|
||||||
endResetModel();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ColumnProxyModel::setColumn(int col)
|
|
||||||
{
|
|
||||||
beginResetModel();
|
|
||||||
m_column = col;
|
|
||||||
endResetModel();
|
|
||||||
}
|
|
||||||
|
|
||||||
int ColumnProxyModel::column() const
|
|
||||||
{
|
|
||||||
return m_column;
|
|
||||||
}
|
|
||||||
|
|
||||||
QModelIndex ColumnProxyModel::rootIndex() const
|
|
||||||
{
|
|
||||||
return m_index;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ColumnProxyModel::setRootIndex(const QModelIndex& index)
|
|
||||||
{
|
|
||||||
if(index.isValid()) {
|
|
||||||
setSourceModel(const_cast<QAbstractItemModel*>(index.model()));
|
|
||||||
}
|
|
||||||
beginResetModel();
|
|
||||||
m_index = index;
|
|
||||||
endResetModel();
|
|
||||||
|
|
||||||
emit rootIndexChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
QModelIndex ColumnProxyModel::indexFromModel(QAbstractItemModel* model, int row, int column, const QModelIndex& parent)
|
|
||||||
{
|
|
||||||
return model ? model->index(row, column, parent) : QModelIndex();
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariant ColumnProxyModel::data(const QModelIndex& index, int role) const
|
|
||||||
{
|
|
||||||
return m_sourceModel ? m_sourceModel->data(sourceIndex(index), role) : QVariant();
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariant ColumnProxyModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
||||||
{
|
|
||||||
return m_sourceModel ? m_sourceModel->headerData(section, orientation, role) : QVariant();
|
|
||||||
}
|
|
||||||
|
|
||||||
QModelIndex ColumnProxyModel::sourceIndex(const QModelIndex& proxyIndex) const
|
|
||||||
{
|
|
||||||
return m_sourceModel ? m_sourceModel->index(proxyIndex.row(), m_column, m_index) : QModelIndex();
|
|
||||||
}
|
|
||||||
|
|
||||||
int ColumnProxyModel::rowCount(const QModelIndex& parent) const
|
|
||||||
{
|
|
||||||
return (!m_sourceModel || parent.isValid()) ? 0 : m_sourceModel->rowCount(m_index);
|
|
||||||
}
|
|
||||||
|
|
||||||
QModelIndex ColumnProxyModel::proxyIndex(const QModelIndex& sourceIndex) const
|
|
||||||
{
|
|
||||||
if(sourceIndex.parent()==m_index)
|
|
||||||
return index(sourceIndex.row(), sourceIndex.column(), QModelIndex());
|
|
||||||
|
|
||||||
return QModelIndex();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ColumnProxyModel::sourceDestroyed(QObject* source)
|
|
||||||
{
|
|
||||||
Q_ASSERT(source==m_sourceModel);
|
|
||||||
|
|
||||||
beginResetModel();
|
|
||||||
m_sourceModel = 0;
|
|
||||||
endResetModel();
|
|
||||||
}
|
|
||||||
|
|
||||||
QModelIndex ColumnProxyModel::indexAt(int row, const QModelIndex& parent) const
|
|
||||||
{
|
|
||||||
return m_sourceModel ? m_sourceModel->index(row, m_column, parent) : QModelIndex();
|
|
||||||
}
|
|
||||||
|
|
||||||
/////////////////
|
|
||||||
|
|
||||||
void ColumnProxyModel::considerDataChanged(const QModelIndex& idxA, const QModelIndex& idxB)
|
|
||||||
{
|
|
||||||
if(idxA.parent()==m_index && idxB.parent()==m_index) {
|
|
||||||
emit dataChanged(proxyIndex(idxA), proxyIndex(idxB));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ColumnProxyModel::considerRowsAboutToBeInserted(const QModelIndex& parent, int rA, int rB)
|
|
||||||
{
|
|
||||||
if(parent==m_index) {
|
|
||||||
beginInsertRows(QModelIndex(), rA, rB);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ColumnProxyModel::considerRowsAboutToBeMoved(const QModelIndex &sourceParent, int rA, int rB, const QModelIndex& destParent, int rD)
|
|
||||||
{
|
|
||||||
if(sourceParent==m_index && destParent==m_index) {
|
|
||||||
beginMoveRows(QModelIndex(), rA, rB, QModelIndex(), rD);
|
|
||||||
} else if(sourceParent==m_index) {
|
|
||||||
beginRemoveRows(sourceParent, rA, rB);
|
|
||||||
} else if(destParent==m_index) {
|
|
||||||
beginInsertRows(destParent, rD, rD+(rB-rA));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ColumnProxyModel::considerRowsAboutToBeRemoved(const QModelIndex& parent, int rA, int rB)
|
|
||||||
{
|
|
||||||
if(parent==m_index) {
|
|
||||||
beginRemoveRows(QModelIndex(), rA, rB);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ColumnProxyModel::considerRowsInserted(const QModelIndex& parent, int , int )
|
|
||||||
{
|
|
||||||
if(parent==m_index) {
|
|
||||||
endInsertRows();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ColumnProxyModel::considerRowsMoved(const QModelIndex& sourceParent, int , int , const QModelIndex& destParent, int )
|
|
||||||
{
|
|
||||||
if(sourceParent==m_index && destParent==m_index) {
|
|
||||||
endMoveRows();
|
|
||||||
} else if(sourceParent==m_index) {
|
|
||||||
endRemoveRows();
|
|
||||||
} else if(destParent==m_index) {
|
|
||||||
endInsertRows();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ColumnProxyModel::considerRowsRemoved(const QModelIndex& parent, int , int )
|
|
||||||
{
|
|
||||||
if(parent==m_index) {
|
|
||||||
endInsertRows();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#include "columnproxymodel.moc"
|
|
@ -1,72 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012 by Aleix Pol Gonzalez <aleixpol@blue-systems.com>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Library General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Library General Public
|
|
||||||
* License along with this program; if not, write to the
|
|
||||||
* Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef COLUMNPROXYMODEL_H
|
|
||||||
#define COLUMNPROXYMODEL_H
|
|
||||||
|
|
||||||
#include <QAbstractListModel>
|
|
||||||
|
|
||||||
class ColumnProxyModel : public QAbstractListModel
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
Q_PROPERTY(QModelIndex rootIndex READ rootIndex WRITE setRootIndex NOTIFY rootIndexChanged)
|
|
||||||
// Q_PROPERTY(QAbstractItemModel* sourceModel READ sourceModel WRITE setSourceModel) //rootIndex sets the model
|
|
||||||
Q_PROPERTY(int column READ column WRITE setColumn)
|
|
||||||
public:
|
|
||||||
ColumnProxyModel(QObject* parent = 0);
|
|
||||||
|
|
||||||
void setRootIndex(const QModelIndex& idx);
|
|
||||||
QModelIndex rootIndex() const;
|
|
||||||
|
|
||||||
void setSourceModel(QAbstractItemModel* sourceModel);
|
|
||||||
QAbstractItemModel* sourceModel() const { return m_sourceModel; }
|
|
||||||
|
|
||||||
int column() const;
|
|
||||||
void setColumn(int col);
|
|
||||||
|
|
||||||
Q_SCRIPTABLE static QModelIndex indexFromModel(QAbstractItemModel* model, int row, int column=0, const QModelIndex& parent=QModelIndex());
|
|
||||||
Q_SCRIPTABLE QModelIndex indexAt(int row, const QModelIndex& parent = QModelIndex()) const;
|
|
||||||
|
|
||||||
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
|
|
||||||
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
|
|
||||||
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
void rootIndexChanged();
|
|
||||||
|
|
||||||
private:
|
|
||||||
QModelIndex proxyIndex(const QModelIndex& sourceIndex) const;
|
|
||||||
QModelIndex sourceIndex(const QModelIndex& proxyIndex) const;
|
|
||||||
|
|
||||||
int m_column;
|
|
||||||
QModelIndex m_index;
|
|
||||||
QAbstractItemModel* m_sourceModel;
|
|
||||||
|
|
||||||
private Q_SLOTS:
|
|
||||||
void considerRowsAboutToBeInserted(const QModelIndex&,int,int);
|
|
||||||
void considerRowsAboutToBeMoved(const QModelIndex& sourceParent, int rA, int rB, const QModelIndex& destParent, int rD);
|
|
||||||
void considerRowsAboutToBeRemoved(const QModelIndex&,int,int);
|
|
||||||
void considerRowsRemoved(const QModelIndex&,int,int);
|
|
||||||
void considerRowsMoved(const QModelIndex&,int,int,const QModelIndex&,int);
|
|
||||||
void considerRowsInserted(const QModelIndex&,int,int);
|
|
||||||
void considerDataChanged(const QModelIndex& idxA, const QModelIndex& idxB);
|
|
||||||
void sourceDestroyed(QObject* source);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,44 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2014 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Library General Public
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 2 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This library is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* Library General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Library General Public License
|
|
||||||
* along with this library; see the file COPYING.LIB. If not, write to
|
|
||||||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
||||||
* Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "mimedatabase.h"
|
|
||||||
#include <QVariantMap>
|
|
||||||
|
|
||||||
static QVariantMap mimetypeToVariant(const QMimeType& type)
|
|
||||||
{
|
|
||||||
QVariantMap ret;
|
|
||||||
ret["name"] = type.name();
|
|
||||||
ret["iconName"] = type.iconName();
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
MimeDatabase::MimeDatabase(QObject* parent)
|
|
||||||
: QObject(parent)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariantMap MimeDatabase::mimeTypeForUrl(const QUrl& url) const
|
|
||||||
{
|
|
||||||
return mimetypeToVariant(m_db.mimeTypeForUrl(url));
|
|
||||||
}
|
|
||||||
|
|
||||||
QVariantMap MimeDatabase::mimeTypeForName(const QString& name) const
|
|
||||||
{
|
|
||||||
return mimetypeToVariant(m_db.mimeTypeForName(name));
|
|
||||||
}
|
|
@ -1,39 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2014 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Library General Public
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 2 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This library is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* Library General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Library General Public License
|
|
||||||
* along with this library; see the file COPYING.LIB. If not, write to
|
|
||||||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
||||||
* Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef MIMEDATABASE_H
|
|
||||||
#define MIMEDATABASE_H
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QMimeDatabase>
|
|
||||||
|
|
||||||
class MimeDatabase : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
MimeDatabase(QObject* parent = 0);
|
|
||||||
|
|
||||||
Q_SCRIPTABLE QVariantMap mimeTypeForUrl(const QUrl & url) const;
|
|
||||||
Q_SCRIPTABLE QVariantMap mimeTypeForName(const QString & name) const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
QMimeDatabase m_db;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // MIMEDATABASE_H
|
|
@ -1,318 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2011 Marco Martin <notmart@gmail.com>
|
|
||||||
Copyright 2013 Sebastian Kügler <sebas@kde.org>
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Library General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
Library General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Library General Public License
|
|
||||||
along with this library; see the file COPYING.LIB. If not, write to
|
|
||||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
||||||
Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "mouseeventlistener.h"
|
|
||||||
|
|
||||||
#include <QApplication>
|
|
||||||
#include <QEvent>
|
|
||||||
#include <QMouseEvent>
|
|
||||||
#include <QTimer>
|
|
||||||
#include <QQuickWindow>
|
|
||||||
#include <QScreen>
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
static const int PressAndHoldDelay = 800;
|
|
||||||
|
|
||||||
MouseEventListener::MouseEventListener(QQuickItem *parent)
|
|
||||||
: QQuickItem(parent),
|
|
||||||
m_pressed(false),
|
|
||||||
m_pressAndHoldEvent(0),
|
|
||||||
m_lastEvent(0),
|
|
||||||
m_containsMouse(false),
|
|
||||||
m_acceptedButtons(Qt::LeftButton)
|
|
||||||
{
|
|
||||||
m_pressAndHoldTimer = new QTimer(this);
|
|
||||||
m_pressAndHoldTimer->setSingleShot(true);
|
|
||||||
connect(m_pressAndHoldTimer, SIGNAL(timeout()),
|
|
||||||
this, SLOT(handlePressAndHold()));
|
|
||||||
|
|
||||||
qmlRegisterType<KDeclarativeMouseEvent>();
|
|
||||||
qmlRegisterType<KDeclarativeWheelEvent>();
|
|
||||||
|
|
||||||
setFiltersChildMouseEvents(true);
|
|
||||||
setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton|Qt::MidButton|Qt::XButton1|Qt::XButton2);
|
|
||||||
}
|
|
||||||
|
|
||||||
MouseEventListener::~MouseEventListener()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Qt::MouseButtons MouseEventListener::acceptedButtons() const
|
|
||||||
{
|
|
||||||
return m_acceptedButtons;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MouseEventListener::setAcceptedButtons(Qt::MouseButtons buttons)
|
|
||||||
{
|
|
||||||
if (buttons == m_acceptedButtons) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_acceptedButtons = buttons;
|
|
||||||
emit acceptedButtonsChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MouseEventListener::setHoverEnabled(bool enable)
|
|
||||||
{
|
|
||||||
if (enable == acceptHoverEvents()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setAcceptHoverEvents(enable);
|
|
||||||
emit hoverEnabledChanged(enable);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MouseEventListener::hoverEnabled() const
|
|
||||||
{
|
|
||||||
return acceptHoverEvents();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MouseEventListener::hoverEnterEvent(QHoverEvent *event)
|
|
||||||
{
|
|
||||||
Q_UNUSED(event);
|
|
||||||
|
|
||||||
m_containsMouse = true;
|
|
||||||
emit containsMouseChanged(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MouseEventListener::hoverLeaveEvent(QHoverEvent *event)
|
|
||||||
{
|
|
||||||
Q_UNUSED(event);
|
|
||||||
|
|
||||||
m_containsMouse = false;
|
|
||||||
emit containsMouseChanged(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MouseEventListener::hoverMoveEvent(QHoverEvent * event)
|
|
||||||
{
|
|
||||||
if (m_lastEvent == event) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QQuickWindow *w = window();
|
|
||||||
QPoint screenPos;
|
|
||||||
if (w) {
|
|
||||||
screenPos = w->mapToGlobal(event->pos());
|
|
||||||
}
|
|
||||||
|
|
||||||
KDeclarativeMouseEvent dme(event->pos().x(), event->pos().y(), screenPos.x(), screenPos.y(), Qt::NoButton, Qt::NoButton, event->modifiers(), 0);
|
|
||||||
emit positionChanged(&dme);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MouseEventListener::containsMouse() const
|
|
||||||
{
|
|
||||||
return m_containsMouse;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MouseEventListener::mousePressEvent(QMouseEvent *me)
|
|
||||||
{
|
|
||||||
if (m_lastEvent == me || !(me->buttons() & m_acceptedButtons)) {
|
|
||||||
me->setAccepted(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//FIXME: when a popup window is visible: a click anywhere hides it: but the old qquickitem will continue to think it's under the mouse
|
|
||||||
//doesn't seem to be any good way to properly reset this.
|
|
||||||
//this msolution will still caused a missed click after the popup is gone, but gets the situation unblocked.
|
|
||||||
if (!isUnderMouse()) {
|
|
||||||
me->ignore();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m_buttonDownPos[me->button()] = me->pos();
|
|
||||||
|
|
||||||
KDeclarativeMouseEvent dme(me->pos().x(), me->pos().y(), me->screenPos().x(), me->screenPos().y(), me->button(), me->buttons(), me->modifiers(), screenForGlobalPos(me->globalPos()));
|
|
||||||
if (!m_pressAndHoldEvent) {
|
|
||||||
m_pressAndHoldEvent = new KDeclarativeMouseEvent(me->pos().x(), me->pos().y(), me->screenPos().x(), me->screenPos().y(), me->button(), me->buttons(), me->modifiers(), screenForGlobalPos(me->globalPos()));
|
|
||||||
}
|
|
||||||
emit pressed(&dme);
|
|
||||||
m_pressed = true;
|
|
||||||
|
|
||||||
m_pressAndHoldTimer->start(PressAndHoldDelay);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MouseEventListener::mouseMoveEvent(QMouseEvent *me)
|
|
||||||
{
|
|
||||||
if (m_lastEvent == me || !(me->buttons() & m_acceptedButtons)) {
|
|
||||||
me->setAccepted(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
KDeclarativeMouseEvent dme(me->pos().x(), me->pos().y(), me->screenPos().x(), me->screenPos().y(), me->button(), me->buttons(), me->modifiers(), screenForGlobalPos(me->globalPos()));
|
|
||||||
emit positionChanged(&dme);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MouseEventListener::mouseReleaseEvent(QMouseEvent *me)
|
|
||||||
{
|
|
||||||
if (m_lastEvent == me) {
|
|
||||||
me->setAccepted(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
KDeclarativeMouseEvent dme(me->pos().x(), me->pos().y(), me->screenPos().x(), me->screenPos().y(), me->button(), me->buttons(), me->modifiers(), screenForGlobalPos(me->globalPos()));
|
|
||||||
m_pressed = false;
|
|
||||||
emit released(&dme);
|
|
||||||
|
|
||||||
if (boundingRect().contains(me->pos()) && m_pressAndHoldTimer->isActive()) {
|
|
||||||
emit clicked(&dme);
|
|
||||||
m_pressAndHoldTimer->stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MouseEventListener::wheelEvent(QWheelEvent *we)
|
|
||||||
{
|
|
||||||
if (m_lastEvent == we) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
KDeclarativeWheelEvent dwe(we->pos(), we->globalPos(), we->delta(), we->buttons(), we->modifiers(), we->orientation());
|
|
||||||
emit wheelMoved(&dwe);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MouseEventListener::handlePressAndHold()
|
|
||||||
{
|
|
||||||
if (m_pressed) {
|
|
||||||
emit pressAndHold(m_pressAndHoldEvent);
|
|
||||||
|
|
||||||
delete m_pressAndHoldEvent;
|
|
||||||
m_pressAndHoldEvent = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QPointF MouseEventListener::buttonDownPos(int btn) const
|
|
||||||
{
|
|
||||||
if (m_buttonDownPos.keys().contains(btn)) {
|
|
||||||
return m_buttonDownPos.value(btn);
|
|
||||||
}
|
|
||||||
return QPointF(0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool MouseEventListener::childMouseEventFilter(QQuickItem *item, QEvent *event)
|
|
||||||
{
|
|
||||||
if (!isEnabled()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (event->type()) {
|
|
||||||
case QEvent::MouseButtonPress: {
|
|
||||||
m_lastEvent = event;
|
|
||||||
QMouseEvent *me = static_cast<QMouseEvent *>(event);
|
|
||||||
|
|
||||||
if (!(me->buttons() & m_acceptedButtons)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
//the parent will receive events in its own coordinates
|
|
||||||
const QPointF myPos = item->mapToItem(this, me->pos());
|
|
||||||
KDeclarativeMouseEvent dme(myPos.x(), myPos.y(), me->screenPos().x(), me->screenPos().y(), me->button(), me->buttons(), me->modifiers(), screenForGlobalPos(me->globalPos()));
|
|
||||||
if (!m_pressAndHoldEvent) {
|
|
||||||
m_pressAndHoldEvent = new KDeclarativeMouseEvent(myPos.x(), myPos.y(), me->screenPos().x(), me->screenPos().y(), me->button(), me->buttons(), me->modifiers(), screenForGlobalPos(me->globalPos()));
|
|
||||||
}
|
|
||||||
//qDebug() << "pressed in sceneEventFilter";
|
|
||||||
m_buttonDownPos[me->button()] = me->pos();
|
|
||||||
emit pressed(&dme);
|
|
||||||
m_pressed = true;
|
|
||||||
|
|
||||||
m_pressAndHoldTimer->start(PressAndHoldDelay);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case QEvent::HoverMove: {
|
|
||||||
if (!acceptHoverEvents()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
m_lastEvent = event;
|
|
||||||
QHoverEvent *he = static_cast<QHoverEvent *>(event);
|
|
||||||
const QPointF myPos = item->mapToItem(this, he->pos());
|
|
||||||
|
|
||||||
QQuickWindow *w = window();
|
|
||||||
QPoint screenPos;
|
|
||||||
if (w) {
|
|
||||||
screenPos = w->mapToGlobal(myPos.toPoint());
|
|
||||||
}
|
|
||||||
|
|
||||||
KDeclarativeMouseEvent dme(myPos.x(), myPos.y(), screenPos.x(), screenPos.y(), Qt::NoButton, Qt::NoButton, he->modifiers(), 0);
|
|
||||||
//qDebug() << "positionChanged..." << dme.x() << dme.y();
|
|
||||||
emit positionChanged(&dme);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case QEvent::MouseMove: {
|
|
||||||
m_lastEvent = event;
|
|
||||||
QMouseEvent *me = static_cast<QMouseEvent *>(event);
|
|
||||||
if (!(me->buttons() & m_acceptedButtons)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QPointF myPos = item->mapToItem(this, me->pos());
|
|
||||||
KDeclarativeMouseEvent dme(myPos.x(), myPos.y(), me->screenPos().x(), me->screenPos().y(), me->button(), me->buttons(), me->modifiers(), screenForGlobalPos(me->globalPos()));
|
|
||||||
//qDebug() << "positionChanged..." << dme.x() << dme.y();
|
|
||||||
|
|
||||||
//if the mouse moves and we are waiting to emit a press and hold event, update the co-ordinates
|
|
||||||
//as there is no update function, delete the old event and create a new one
|
|
||||||
if (m_pressAndHoldEvent) {
|
|
||||||
delete m_pressAndHoldEvent;
|
|
||||||
m_pressAndHoldEvent = new KDeclarativeMouseEvent(myPos.x(), myPos.y(), me->screenPos().x(), me->screenPos().y(), me->button(), me->buttons(), me->modifiers(), screenForGlobalPos(me->globalPos()));
|
|
||||||
}
|
|
||||||
emit positionChanged(&dme);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case QEvent::MouseButtonRelease: {
|
|
||||||
m_lastEvent = event;
|
|
||||||
QMouseEvent *me = static_cast<QMouseEvent *>(event);
|
|
||||||
|
|
||||||
const QPointF myPos = item->mapToItem(this, me->pos());
|
|
||||||
KDeclarativeMouseEvent dme(myPos.x(), myPos.y(), me->screenPos().x(), me->screenPos().y(), me->button(), me->buttons(), me->modifiers(), screenForGlobalPos(me->globalPos()));
|
|
||||||
m_pressed = false;
|
|
||||||
|
|
||||||
emit released(&dme);
|
|
||||||
|
|
||||||
if (QPointF(me->pos() - buttonDownPos(me->button())).manhattanLength() <= QApplication::startDragDistance() && m_pressAndHoldTimer->isActive()) {
|
|
||||||
emit clicked(&dme);
|
|
||||||
m_pressAndHoldTimer->stop();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case QEvent::Wheel: {
|
|
||||||
m_lastEvent = event;
|
|
||||||
QWheelEvent *we = static_cast<QWheelEvent *>(event);
|
|
||||||
KDeclarativeWheelEvent dwe(we->pos(), we->globalPos(), we->delta(), we->buttons(), we->modifiers(), we->orientation());
|
|
||||||
emit wheelMoved(&dwe);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return QQuickItem::childMouseEventFilter(item, event);
|
|
||||||
// return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
QScreen* MouseEventListener::screenForGlobalPos(const QPoint& globalPos)
|
|
||||||
{
|
|
||||||
foreach(QScreen *screen, QGuiApplication::screens()) {
|
|
||||||
if (screen->geometry().contains(globalPos)) {
|
|
||||||
return screen;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#include "mouseeventlistener.moc"
|
|
||||||
|
|
@ -1,203 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2011 Marco Martin <notmart@gmail.com>
|
|
||||||
Copyright 2013 Sebastian Kügler <sebas@kde.org>
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Library General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
Library General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Library General Public License
|
|
||||||
along with this library; see the file COPYING.LIB. If not, write to
|
|
||||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
||||||
Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef MOUSEEVENTLISTENER_H
|
|
||||||
#define MOUSEEVENTLISTENER_H
|
|
||||||
|
|
||||||
#include <QQuickItem>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This item spies on mouse events from all child objects including child MouseAreas regardless
|
|
||||||
* of whether the child MouseArea propegates events. It does not accept the event.
|
|
||||||
*
|
|
||||||
* In addition unlike MouseArea events include the mouse position in global co-ordinates and provides
|
|
||||||
* the sceen the mouse is in.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
class KDeclarativeMouseEvent : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
Q_PROPERTY(int x READ x)
|
|
||||||
Q_PROPERTY(int y READ y)
|
|
||||||
Q_PROPERTY(int screenX READ screenX)
|
|
||||||
Q_PROPERTY(int screenY READ screenY)
|
|
||||||
Q_PROPERTY(int button READ button)
|
|
||||||
Q_PROPERTY(Qt::MouseButtons buttons READ buttons)
|
|
||||||
Q_PROPERTY(Qt::KeyboardModifiers modifiers READ modifiers)
|
|
||||||
Q_PROPERTY(QScreen* screen READ screen CONSTANT)
|
|
||||||
|
|
||||||
public:
|
|
||||||
KDeclarativeMouseEvent(int x, int y, int screenX, int screenY,
|
|
||||||
Qt::MouseButton button,
|
|
||||||
Qt::MouseButtons buttons,
|
|
||||||
Qt::KeyboardModifiers modifiers,
|
|
||||||
QScreen* screen)
|
|
||||||
: m_x(x),
|
|
||||||
m_y(y),
|
|
||||||
m_screenX(screenX),
|
|
||||||
m_screenY(screenY),
|
|
||||||
m_button(button),
|
|
||||||
m_buttons(buttons),
|
|
||||||
m_modifiers(modifiers),
|
|
||||||
m_screen(screen)
|
|
||||||
{}
|
|
||||||
|
|
||||||
int x() const { return m_x; }
|
|
||||||
int y() const { return m_y; }
|
|
||||||
int screenX() const { return m_screenX; }
|
|
||||||
int screenY() const { return m_screenY; }
|
|
||||||
int button() const { return m_button; }
|
|
||||||
Qt::MouseButtons buttons() const { return m_buttons; }
|
|
||||||
Qt::KeyboardModifiers modifiers() const { return m_modifiers; }
|
|
||||||
QScreen* screen() const { return m_screen; }
|
|
||||||
|
|
||||||
// only for internal usage
|
|
||||||
void setX(int x) { m_x = x; }
|
|
||||||
void setY(int y) { m_y = y; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
int m_x;
|
|
||||||
int m_y;
|
|
||||||
int m_screenX;
|
|
||||||
int m_screenY;
|
|
||||||
Qt::MouseButton m_button;
|
|
||||||
Qt::MouseButtons m_buttons;
|
|
||||||
Qt::KeyboardModifiers m_modifiers;
|
|
||||||
QScreen *m_screen;
|
|
||||||
};
|
|
||||||
|
|
||||||
class KDeclarativeWheelEvent : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
Q_PROPERTY(int x READ x CONSTANT)
|
|
||||||
Q_PROPERTY(int y READ y CONSTANT)
|
|
||||||
Q_PROPERTY(int screenX READ screenX CONSTANT)
|
|
||||||
Q_PROPERTY(int screenY READ screenY CONSTANT)
|
|
||||||
Q_PROPERTY(int delta READ delta CONSTANT)
|
|
||||||
Q_PROPERTY(Qt::MouseButtons buttons READ buttons CONSTANT)
|
|
||||||
Q_PROPERTY(Qt::KeyboardModifiers modifiers READ modifiers CONSTANT)
|
|
||||||
Q_PROPERTY(Qt::Orientation orientation READ orientation CONSTANT)
|
|
||||||
|
|
||||||
public:
|
|
||||||
KDeclarativeWheelEvent(QPointF pos, QPoint screenPos, int delta,
|
|
||||||
Qt::MouseButtons buttons,
|
|
||||||
Qt::KeyboardModifiers modifiers,
|
|
||||||
Qt::Orientation orientation)
|
|
||||||
: m_x(pos.x()),
|
|
||||||
m_y(pos.y()),
|
|
||||||
m_screenX(screenPos.x()),
|
|
||||||
m_screenY(screenPos.y()),
|
|
||||||
m_delta(delta),
|
|
||||||
m_buttons(buttons),
|
|
||||||
m_modifiers(modifiers),
|
|
||||||
m_orientation(orientation)
|
|
||||||
{}
|
|
||||||
|
|
||||||
int x() const { return m_x; }
|
|
||||||
int y() const { return m_y; }
|
|
||||||
int screenX() const { return m_screenX; }
|
|
||||||
int screenY() const { return m_screenY; }
|
|
||||||
int delta() const { return m_delta; }
|
|
||||||
Qt::MouseButtons buttons() const { return m_buttons; }
|
|
||||||
Qt::KeyboardModifiers modifiers() const { return m_modifiers; }
|
|
||||||
Qt::Orientation orientation() { return m_orientation; }
|
|
||||||
|
|
||||||
// only for internal usage
|
|
||||||
void setX(int x) { m_x = x; }
|
|
||||||
void setY(int y) { m_y = y; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
int m_x;
|
|
||||||
int m_y;
|
|
||||||
int m_screenX;
|
|
||||||
int m_screenY;
|
|
||||||
int m_delta;
|
|
||||||
Qt::MouseButtons m_buttons;
|
|
||||||
Qt::KeyboardModifiers m_modifiers;
|
|
||||||
Qt::Orientation m_orientation;
|
|
||||||
};
|
|
||||||
|
|
||||||
class MouseEventListener : public QQuickItem
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
/**
|
|
||||||
* This property holds whether hover events are handled.
|
|
||||||
* By default hover events are disabled
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(bool hoverEnabled READ hoverEnabled WRITE setHoverEnabled NOTIFY hoverEnabledChanged)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* True if this MouseEventListener or any of its children contains the mouse cursor: this property will change only when the mouse button is pressed if hoverEnabled is false
|
|
||||||
*/
|
|
||||||
Q_PROPERTY(bool containsMouse READ containsMouse NOTIFY containsMouseChanged)
|
|
||||||
|
|
||||||
Q_PROPERTY(Qt::MouseButtons acceptedButtons READ acceptedButtons WRITE setAcceptedButtons NOTIFY acceptedButtonsChanged)
|
|
||||||
|
|
||||||
public:
|
|
||||||
MouseEventListener(QQuickItem *parent=0);
|
|
||||||
~MouseEventListener();
|
|
||||||
|
|
||||||
bool containsMouse() const;
|
|
||||||
void setHoverEnabled(bool enable);
|
|
||||||
bool hoverEnabled() const;
|
|
||||||
|
|
||||||
Qt::MouseButtons acceptedButtons() const;
|
|
||||||
void setAcceptedButtons(Qt::MouseButtons buttons);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void hoverEnterEvent(QHoverEvent *event);
|
|
||||||
void hoverLeaveEvent(QHoverEvent *event);
|
|
||||||
void hoverMoveEvent(QHoverEvent * event);
|
|
||||||
void mousePressEvent(QMouseEvent *event);
|
|
||||||
void mouseMoveEvent(QMouseEvent *event);
|
|
||||||
void mouseReleaseEvent(QMouseEvent *event);
|
|
||||||
void wheelEvent(QWheelEvent *event);
|
|
||||||
bool childMouseEventFilter(QQuickItem *item, QEvent *event);
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
void pressed(KDeclarativeMouseEvent *mouse);
|
|
||||||
void positionChanged(KDeclarativeMouseEvent *mouse);
|
|
||||||
void released(KDeclarativeMouseEvent *mouse);
|
|
||||||
void clicked(KDeclarativeMouseEvent *mouse);
|
|
||||||
void pressAndHold(KDeclarativeMouseEvent *mouse);
|
|
||||||
void wheelMoved(KDeclarativeWheelEvent *wheel);
|
|
||||||
void containsMouseChanged(bool containsMouseChanged);
|
|
||||||
void hoverEnabledChanged(bool hoverEnabled);
|
|
||||||
void acceptedButtonsChanged();
|
|
||||||
|
|
||||||
private Q_SLOTS:
|
|
||||||
void handlePressAndHold();
|
|
||||||
|
|
||||||
private:
|
|
||||||
static QScreen* screenForGlobalPos(const QPoint &globalPos);
|
|
||||||
|
|
||||||
QPointF buttonDownPos(int btn) const;
|
|
||||||
bool m_pressed;
|
|
||||||
KDeclarativeMouseEvent* m_pressAndHoldEvent;
|
|
||||||
QHash<int, QPointF> m_buttonDownPos;
|
|
||||||
//Important: used only for comparison. If you will ever need to access this pointer, make it a QWeakPointer
|
|
||||||
QEvent *m_lastEvent;
|
|
||||||
QTimer *m_pressAndHoldTimer;
|
|
||||||
bool m_containsMouse;
|
|
||||||
Qt::MouseButtons m_acceptedButtons;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,127 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2011 Marco Martin <mart@kde.org>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Library General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Library General Public
|
|
||||||
* License along with this program; if not, write to the
|
|
||||||
* Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "qiconitem.h"
|
|
||||||
|
|
||||||
#include <kiconloader.h>
|
|
||||||
#include <kiconeffect.h>
|
|
||||||
|
|
||||||
#include <QIcon>
|
|
||||||
#include <QPainter>
|
|
||||||
|
|
||||||
|
|
||||||
QIconItem::QIconItem(QQuickItem *parent)
|
|
||||||
: QQuickPaintedItem(parent),
|
|
||||||
m_smooth(false),
|
|
||||||
m_state(DefaultState)
|
|
||||||
{
|
|
||||||
setFlag(ItemHasContents, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QIconItem::~QIconItem()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void QIconItem::setIcon(const QVariant &icon)
|
|
||||||
{
|
|
||||||
if(icon.canConvert<QIcon>()) {
|
|
||||||
m_icon = icon.value<QIcon>();
|
|
||||||
} else if(icon.canConvert<QString>()) {
|
|
||||||
m_icon = QIcon::fromTheme(icon.toString());
|
|
||||||
} else {
|
|
||||||
m_icon = QIcon();
|
|
||||||
}
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
QIcon QIconItem::icon() const
|
|
||||||
{
|
|
||||||
return m_icon;
|
|
||||||
}
|
|
||||||
|
|
||||||
QIconItem::State QIconItem::state() const
|
|
||||||
{
|
|
||||||
return m_state;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QIconItem::setState(QIconItem::State state)
|
|
||||||
{
|
|
||||||
if (m_state == state) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_state = state;
|
|
||||||
emit stateChanged(state);
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
int QIconItem::implicitWidth() const
|
|
||||||
{
|
|
||||||
return KIconLoader::global()->currentSize(KIconLoader::Desktop);
|
|
||||||
}
|
|
||||||
|
|
||||||
int QIconItem::implicitHeight() const
|
|
||||||
{
|
|
||||||
return KIconLoader::global()->currentSize(KIconLoader::Desktop);
|
|
||||||
}
|
|
||||||
|
|
||||||
void QIconItem::setSmooth(const bool smooth)
|
|
||||||
{
|
|
||||||
if (smooth == m_smooth) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m_smooth = smooth;
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QIconItem::smooth() const
|
|
||||||
{
|
|
||||||
return m_smooth;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QIconItem::paint(QPainter *painter)
|
|
||||||
{
|
|
||||||
if (m_icon.isNull()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//do without painter save, faster and the support can be compiled out
|
|
||||||
const bool wasAntiAlias = painter->testRenderHint(QPainter::Antialiasing);
|
|
||||||
const bool wasSmoothTransform = painter->testRenderHint(QPainter::SmoothPixmapTransform);
|
|
||||||
painter->setRenderHint(QPainter::Antialiasing, m_smooth);
|
|
||||||
painter->setRenderHint(QPainter::SmoothPixmapTransform, m_smooth);
|
|
||||||
|
|
||||||
if (m_state == ActiveState) {
|
|
||||||
QPixmap result = m_icon.pixmap(boundingRect().size().toSize());
|
|
||||||
result = KIconLoader::global()->iconEffect()->apply(result, KIconLoader::Desktop, KIconLoader::ActiveState);
|
|
||||||
painter->drawPixmap(0, 0, result);
|
|
||||||
} else if (m_state == QIconItem::DisabledState) {
|
|
||||||
QPixmap result = m_icon.pixmap(boundingRect().size().toSize());
|
|
||||||
result = KIconLoader::global()->iconEffect()->apply(result, KIconLoader::Desktop, KIconLoader::DisabledState);
|
|
||||||
painter->drawPixmap(0, 0, result);
|
|
||||||
} else {
|
|
||||||
m_icon.paint(painter, boundingRect().toRect(), Qt::AlignCenter, QIcon::Normal);
|
|
||||||
}
|
|
||||||
|
|
||||||
painter->setRenderHint(QPainter::Antialiasing, wasAntiAlias);
|
|
||||||
painter->setRenderHint(QPainter::SmoothPixmapTransform, wasSmoothTransform);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#include "qiconitem.moc"
|
|
@ -1,73 +0,0 @@
|
|||||||
/***************************************************************************
|
|
||||||
* Copyright 2011 Marco Martin <mart@kde.org> *
|
|
||||||
* *
|
|
||||||
* This program is free software; you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU General Public License as published by *
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or *
|
|
||||||
* (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU General Public License *
|
|
||||||
* along with this program; if not, write to the *
|
|
||||||
* Free Software Foundation, Inc., *
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
|
|
||||||
***************************************************************************/
|
|
||||||
#ifndef QICONITEM_H
|
|
||||||
#define QICONITEM_H
|
|
||||||
|
|
||||||
#include <QIcon>
|
|
||||||
#include <QQuickPaintedItem>
|
|
||||||
#include <QPixmap>
|
|
||||||
#include <QVariant>
|
|
||||||
|
|
||||||
class QIconItem : public QQuickPaintedItem
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
Q_PROPERTY(QVariant icon READ icon WRITE setIcon)
|
|
||||||
Q_PROPERTY(bool smooth READ smooth WRITE setSmooth)
|
|
||||||
Q_PROPERTY(int implicitWidth READ implicitWidth CONSTANT)
|
|
||||||
Q_PROPERTY(int implicitHeight READ implicitHeight CONSTANT)
|
|
||||||
Q_PROPERTY(State state READ state WRITE setState NOTIFY stateChanged)
|
|
||||||
|
|
||||||
Q_ENUMS(State)
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
enum State {
|
|
||||||
DefaultState, ///The default state.
|
|
||||||
ActiveState, ///Icon is active.
|
|
||||||
DisabledState ///Icon is disabled.
|
|
||||||
};
|
|
||||||
|
|
||||||
QIconItem(QQuickItem *parent=0);
|
|
||||||
~QIconItem();
|
|
||||||
|
|
||||||
void setIcon(const QVariant &icon);
|
|
||||||
QIcon icon() const;
|
|
||||||
|
|
||||||
QIconItem::State state() const;
|
|
||||||
void setState(State state);
|
|
||||||
|
|
||||||
int implicitWidth() const;
|
|
||||||
int implicitHeight() const;
|
|
||||||
|
|
||||||
void setSmooth(const bool smooth);
|
|
||||||
bool smooth() const;
|
|
||||||
|
|
||||||
void paint(QPainter *painter);
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
void stateChanged(State state);
|
|
||||||
|
|
||||||
private:
|
|
||||||
QIcon m_icon;
|
|
||||||
bool m_smooth;
|
|
||||||
State m_state;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,154 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2011 Marco Martin <mart@kde.org>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Library General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Library General Public
|
|
||||||
* License along with this program; if not, write to the
|
|
||||||
* Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "qimageitem.h"
|
|
||||||
|
|
||||||
#include <QPainter>
|
|
||||||
|
|
||||||
|
|
||||||
QImageItem::QImageItem(QQuickItem *parent)
|
|
||||||
: QQuickPaintedItem(parent),
|
|
||||||
m_smooth(false),
|
|
||||||
m_fillMode(QImageItem::Stretch)
|
|
||||||
{
|
|
||||||
setFlag(ItemHasContents, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QImageItem::~QImageItem()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void QImageItem::setImage(const QImage &image)
|
|
||||||
{
|
|
||||||
bool oldImageNull = m_image.isNull();
|
|
||||||
m_image = image;
|
|
||||||
update();
|
|
||||||
emit nativeWidthChanged();
|
|
||||||
emit nativeHeightChanged();
|
|
||||||
emit imageChanged();
|
|
||||||
if (oldImageNull != m_image.isNull()) {
|
|
||||||
emit nullChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QImage QImageItem::image() const
|
|
||||||
{
|
|
||||||
return m_image;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QImageItem::setSmooth(const bool smooth)
|
|
||||||
{
|
|
||||||
if (smooth == m_smooth) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m_smooth = smooth;
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QImageItem::smooth() const
|
|
||||||
{
|
|
||||||
return m_smooth;
|
|
||||||
}
|
|
||||||
|
|
||||||
int QImageItem::nativeWidth() const
|
|
||||||
{
|
|
||||||
return m_image.size().width();
|
|
||||||
}
|
|
||||||
|
|
||||||
int QImageItem::nativeHeight() const
|
|
||||||
{
|
|
||||||
return m_image.size().height();
|
|
||||||
}
|
|
||||||
|
|
||||||
QImageItem::FillMode QImageItem::fillMode() const
|
|
||||||
{
|
|
||||||
return m_fillMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QImageItem::setFillMode(QImageItem::FillMode mode)
|
|
||||||
{
|
|
||||||
if (mode == m_fillMode) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_fillMode = mode;
|
|
||||||
update();
|
|
||||||
emit fillModeChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QImageItem::paint(QPainter *painter)
|
|
||||||
{
|
|
||||||
if (m_image.isNull()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
painter->save();
|
|
||||||
painter->setRenderHint(QPainter::Antialiasing, m_smooth);
|
|
||||||
painter->setRenderHint(QPainter::SmoothPixmapTransform, m_smooth);
|
|
||||||
|
|
||||||
QRect sourceRect = m_image.rect();
|
|
||||||
QRect destRect;
|
|
||||||
switch (m_fillMode) {
|
|
||||||
case PreserveAspectFit: {
|
|
||||||
QSize scaled = m_image.size();
|
|
||||||
|
|
||||||
scaled.scale(boundingRect().size().toSize(), Qt::KeepAspectRatio);
|
|
||||||
destRect = QRect(QPoint(0, 0), scaled);
|
|
||||||
destRect.moveCenter(boundingRect().center().toPoint());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case PreserveAspectCrop: {
|
|
||||||
destRect = boundingRect().toRect();
|
|
||||||
sourceRect = destRect;
|
|
||||||
sourceRect.moveCenter(m_image.rect().center());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case TileVertically: {
|
|
||||||
painter->scale(width()/(qreal)m_image.width(), 1);
|
|
||||||
destRect = boundingRect().toRect();
|
|
||||||
destRect.setWidth(destRect.width() / (width()/(qreal)m_image.width()));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case TileHorizontally: {
|
|
||||||
painter->scale(1, height()/(qreal)m_image.height());
|
|
||||||
destRect = boundingRect().toRect();
|
|
||||||
destRect.setHeight(destRect.height() / (height()/(qreal)m_image.height()));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Stretch:
|
|
||||||
case Tile:
|
|
||||||
default:
|
|
||||||
destRect = boundingRect().toRect();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_fillMode >= Tile) {
|
|
||||||
painter->drawTiledPixmap(destRect, QPixmap::fromImage(m_image));
|
|
||||||
} else {
|
|
||||||
painter->drawImage(destRect, m_image, sourceRect);
|
|
||||||
}
|
|
||||||
|
|
||||||
painter->restore();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QImageItem::isNull() const
|
|
||||||
{
|
|
||||||
return m_image.isNull();
|
|
||||||
}
|
|
||||||
|
|
||||||
#include "qimageitem.moc"
|
|
@ -1,79 +0,0 @@
|
|||||||
/***************************************************************************
|
|
||||||
* Copyright 2011 Marco Martin <mart@kde.org> *
|
|
||||||
* *
|
|
||||||
* This program is free software; you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU General Public License as published by *
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or *
|
|
||||||
* (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU General Public License *
|
|
||||||
* along with this program; if not, write to the *
|
|
||||||
* Free Software Foundation, Inc., *
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
|
|
||||||
***************************************************************************/
|
|
||||||
#ifndef QIMAGEITEM_H
|
|
||||||
#define QIMAGEITEM_H
|
|
||||||
|
|
||||||
#include <QQuickPaintedItem>
|
|
||||||
#include <QImage>
|
|
||||||
|
|
||||||
class QImageItem : public QQuickPaintedItem
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
Q_PROPERTY(QImage image READ image WRITE setImage NOTIFY imageChanged)
|
|
||||||
Q_PROPERTY(bool smooth READ smooth WRITE setSmooth)
|
|
||||||
Q_PROPERTY(int nativeWidth READ nativeWidth NOTIFY nativeWidthChanged)
|
|
||||||
Q_PROPERTY(int nativeHeight READ nativeHeight NOTIFY nativeHeightChanged)
|
|
||||||
Q_PROPERTY(FillMode fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged)
|
|
||||||
Q_PROPERTY(bool null READ isNull NOTIFY nullChanged)
|
|
||||||
Q_ENUMS(FillMode)
|
|
||||||
|
|
||||||
public:
|
|
||||||
enum FillMode {
|
|
||||||
Stretch, // the image is scaled to fit
|
|
||||||
PreserveAspectFit, // the image is scaled uniformly to fit without cropping
|
|
||||||
PreserveAspectCrop, // the image is scaled uniformly to fill, cropping if necessary
|
|
||||||
Tile, // the image is duplicated horizontally and vertically
|
|
||||||
TileVertically, // the image is stretched horizontally and tiled vertically
|
|
||||||
TileHorizontally //the image is stretched vertically and tiled horizontally
|
|
||||||
};
|
|
||||||
|
|
||||||
QImageItem(QQuickItem *parent=0);
|
|
||||||
~QImageItem();
|
|
||||||
|
|
||||||
void setImage(const QImage &image);
|
|
||||||
QImage image() const;
|
|
||||||
|
|
||||||
void setSmooth(const bool smooth);
|
|
||||||
bool smooth() const;
|
|
||||||
|
|
||||||
int nativeWidth() const;
|
|
||||||
int nativeHeight() const;
|
|
||||||
|
|
||||||
FillMode fillMode() const;
|
|
||||||
void setFillMode(FillMode mode);
|
|
||||||
|
|
||||||
void paint(QPainter *painter);
|
|
||||||
|
|
||||||
bool isNull() const;
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
void nativeWidthChanged();
|
|
||||||
void nativeHeightChanged();
|
|
||||||
void fillModeChanged();
|
|
||||||
void imageChanged();
|
|
||||||
void nullChanged();
|
|
||||||
|
|
||||||
private:
|
|
||||||
QImage m_image;
|
|
||||||
bool m_smooth;
|
|
||||||
FillMode m_fillMode;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,5 +0,0 @@
|
|||||||
module org.kde.qtextracomponents
|
|
||||||
plugin qtextracomponentsplugin
|
|
||||||
|
|
||||||
|
|
||||||
ShortcutButton 2.0 ShortcutButton.qml
|
|
@ -1,156 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2011 Marco Martin <mart@kde.org>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Library General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Library General Public
|
|
||||||
* License along with this program; if not, write to the
|
|
||||||
* Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "qpixmapitem.h"
|
|
||||||
|
|
||||||
#include <QPainter>
|
|
||||||
|
|
||||||
|
|
||||||
QPixmapItem::QPixmapItem(QQuickItem *parent)
|
|
||||||
: QQuickPaintedItem(parent),
|
|
||||||
m_smooth(false),
|
|
||||||
m_fillMode(QPixmapItem::Stretch)
|
|
||||||
{
|
|
||||||
setFlag(ItemHasContents, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QPixmapItem::~QPixmapItem()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void QPixmapItem::setPixmap(const QPixmap &pixmap)
|
|
||||||
{
|
|
||||||
bool oldPixmapNull = m_pixmap.isNull();
|
|
||||||
m_pixmap = pixmap;
|
|
||||||
update();
|
|
||||||
emit nativeWidthChanged();
|
|
||||||
emit nativeHeightChanged();
|
|
||||||
emit pixmapChanged();
|
|
||||||
if (oldPixmapNull != m_pixmap.isNull()) {
|
|
||||||
emit nullChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QPixmap QPixmapItem::pixmap() const
|
|
||||||
{
|
|
||||||
return m_pixmap;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QPixmapItem::setSmooth(const bool smooth)
|
|
||||||
{
|
|
||||||
if (smooth == m_smooth) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m_smooth = smooth;
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QPixmapItem::smooth() const
|
|
||||||
{
|
|
||||||
return m_smooth;
|
|
||||||
}
|
|
||||||
|
|
||||||
int QPixmapItem::nativeWidth() const
|
|
||||||
{
|
|
||||||
return m_pixmap.size().width();
|
|
||||||
}
|
|
||||||
|
|
||||||
int QPixmapItem::nativeHeight() const
|
|
||||||
{
|
|
||||||
return m_pixmap.size().height();
|
|
||||||
}
|
|
||||||
|
|
||||||
QPixmapItem::FillMode QPixmapItem::fillMode() const
|
|
||||||
{
|
|
||||||
return m_fillMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QPixmapItem::setFillMode(QPixmapItem::FillMode mode)
|
|
||||||
{
|
|
||||||
if (mode == m_fillMode) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_fillMode = mode;
|
|
||||||
update();
|
|
||||||
emit fillModeChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
void QPixmapItem::paint(QPainter *painter)
|
|
||||||
{
|
|
||||||
if (m_pixmap.isNull()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
painter->save();
|
|
||||||
painter->setRenderHint(QPainter::Antialiasing, m_smooth);
|
|
||||||
painter->setRenderHint(QPainter::SmoothPixmapTransform, m_smooth);
|
|
||||||
|
|
||||||
QRect sourceRect = m_pixmap.rect();
|
|
||||||
QRect destRect;
|
|
||||||
switch (m_fillMode) {
|
|
||||||
case PreserveAspectFit: {
|
|
||||||
QSize scaled = m_pixmap.size();
|
|
||||||
|
|
||||||
scaled.scale(boundingRect().size().toSize(), Qt::KeepAspectRatio);
|
|
||||||
destRect = QRect(QPoint(0, 0), scaled);
|
|
||||||
destRect.moveCenter(boundingRect().center().toPoint());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case PreserveAspectCrop: {
|
|
||||||
QSize scaled = m_pixmap.size();
|
|
||||||
|
|
||||||
scaled.scale(boundingRect().size().toSize(), Qt::KeepAspectRatioByExpanding);
|
|
||||||
destRect = QRect(QPoint(0, 0), scaled);
|
|
||||||
destRect.moveCenter(boundingRect().center().toPoint());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case TileVertically: {
|
|
||||||
painter->scale(width()/(qreal)m_pixmap.width(), 1);
|
|
||||||
destRect = boundingRect().toRect();
|
|
||||||
destRect.setWidth(destRect.width() / (width()/(qreal)m_pixmap.width()));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case TileHorizontally: {
|
|
||||||
painter->scale(1, height()/(qreal)m_pixmap.height());
|
|
||||||
destRect = boundingRect().toRect();
|
|
||||||
destRect.setHeight(destRect.height() / (height()/(qreal)m_pixmap.height()));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Stretch:
|
|
||||||
case Tile:
|
|
||||||
default:
|
|
||||||
destRect = boundingRect().toRect();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_fillMode >= Tile) {
|
|
||||||
painter->drawTiledPixmap(destRect, m_pixmap);
|
|
||||||
} else {
|
|
||||||
painter->drawPixmap(destRect, m_pixmap, m_pixmap.rect());
|
|
||||||
}
|
|
||||||
|
|
||||||
painter->restore();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool QPixmapItem::isNull() const
|
|
||||||
{
|
|
||||||
return m_pixmap.isNull();
|
|
||||||
}
|
|
||||||
|
|
||||||
#include "qpixmapitem.moc"
|
|
@ -1,79 +0,0 @@
|
|||||||
/***************************************************************************
|
|
||||||
* Copyright 2011 Marco Martin <mart@kde.org> *
|
|
||||||
* *
|
|
||||||
* This program is free software; you can redistribute it and/or modify *
|
|
||||||
* it under the terms of the GNU General Public License as published by *
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or *
|
|
||||||
* (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU General Public License *
|
|
||||||
* along with this program; if not, write to the *
|
|
||||||
* Free Software Foundation, Inc., *
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
|
|
||||||
***************************************************************************/
|
|
||||||
#ifndef QPIXMAPITEM_H
|
|
||||||
#define QPIXMAPITEM_H
|
|
||||||
|
|
||||||
#include <QQuickPaintedItem>
|
|
||||||
#include <QPixmap>
|
|
||||||
|
|
||||||
class QPixmapItem : public QQuickPaintedItem
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap NOTIFY pixmapChanged)
|
|
||||||
Q_PROPERTY(bool smooth READ smooth WRITE setSmooth)
|
|
||||||
Q_PROPERTY(int nativeWidth READ nativeWidth NOTIFY nativeWidthChanged)
|
|
||||||
Q_PROPERTY(int nativeHeight READ nativeHeight NOTIFY nativeHeightChanged)
|
|
||||||
Q_PROPERTY(FillMode fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged)
|
|
||||||
Q_PROPERTY(bool null READ isNull NOTIFY nullChanged)
|
|
||||||
Q_ENUMS(FillMode)
|
|
||||||
|
|
||||||
public:
|
|
||||||
enum FillMode {
|
|
||||||
Stretch, // the image is scaled to fit
|
|
||||||
PreserveAspectFit, // the image is scaled uniformly to fit without cropping
|
|
||||||
PreserveAspectCrop, // the image is scaled uniformly to fill, cropping if necessary
|
|
||||||
Tile, // the image is duplicated horizontally and vertically
|
|
||||||
TileVertically, // the image is stretched horizontally and tiled vertically
|
|
||||||
TileHorizontally //the image is stretched vertically and tiled horizontally
|
|
||||||
};
|
|
||||||
|
|
||||||
QPixmapItem(QQuickItem *parent=0);
|
|
||||||
~QPixmapItem();
|
|
||||||
|
|
||||||
void setPixmap(const QPixmap &pixmap);
|
|
||||||
QPixmap pixmap() const;
|
|
||||||
|
|
||||||
void setSmooth(const bool smooth);
|
|
||||||
bool smooth() const;
|
|
||||||
|
|
||||||
int nativeWidth() const;
|
|
||||||
int nativeHeight() const;
|
|
||||||
|
|
||||||
FillMode fillMode() const;
|
|
||||||
void setFillMode(FillMode mode);
|
|
||||||
|
|
||||||
void paint(QPainter *painter);
|
|
||||||
|
|
||||||
bool isNull() const;
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
|
||||||
void nativeWidthChanged();
|
|
||||||
void nativeHeightChanged();
|
|
||||||
void fillModeChanged();
|
|
||||||
void pixmapChanged();
|
|
||||||
void nullChanged();
|
|
||||||
|
|
||||||
private:
|
|
||||||
QPixmap m_pixmap;
|
|
||||||
bool m_smooth;
|
|
||||||
FillMode m_fillMode;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,53 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2009 by Alan Alpert <alan.alpert@nokia.com>
|
|
||||||
* Copyright 2010 by Ménard Alexis <menard@kde.org>
|
|
||||||
* Copyright 2010 by Marco Martin <mart@kde.org>
|
|
||||||
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Library General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Library General Public
|
|
||||||
* License along with this program; if not, write to the
|
|
||||||
* Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "qtextracomponentsplugin.h"
|
|
||||||
|
|
||||||
#include <QtQml>
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
#include "qpixmapitem.h"
|
|
||||||
#include "qimageitem.h"
|
|
||||||
#include "qiconitem.h"
|
|
||||||
#include "mouseeventlistener.h"
|
|
||||||
#include "columnproxymodel.h"
|
|
||||||
#include "clipboard.h"
|
|
||||||
#include "mimedatabase.h"
|
|
||||||
|
|
||||||
void QtExtraComponentsPlugin::registerTypes(const char *uri)
|
|
||||||
{
|
|
||||||
Q_ASSERT(uri == QLatin1String("org.kde.qtextracomponents"));
|
|
||||||
|
|
||||||
qmlRegisterType<QPixmapItem>(uri, 2, 0, "QPixmapItem");
|
|
||||||
qmlRegisterType<QImageItem>(uri, 2, 0, "QImageItem");
|
|
||||||
qmlRegisterType<QIconItem>(uri, 2, 0, "QIconItem");
|
|
||||||
qmlRegisterType<MouseEventListener>(uri, 2, 0, "MouseEventListener");
|
|
||||||
qmlRegisterType<ColumnProxyModel>(uri, 2, 0, "ColumnProxyModel");
|
|
||||||
qmlRegisterType<Clipboard>(uri, 2, 0, "Clipboard");
|
|
||||||
qmlRegisterType<MimeDatabase>(uri, 2, 0, "MimeDatabase");
|
|
||||||
|
|
||||||
qmlRegisterType<QAbstractItemModel>();
|
|
||||||
qRegisterMetaType<QModelIndex>("QModelIndex");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#include "qtextracomponentsplugin.moc"
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2009 by Alan Alpert <alan.alpert@nokia.com>
|
|
||||||
* Copyright 2010 by Ménard Alexis <menard@kde.org>
|
|
||||||
* Copyright 2011 by Marco Martin <mart@kde.org>
|
|
||||||
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Library General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Library General Public
|
|
||||||
* License along with this program; if not, write to the
|
|
||||||
* Free Software Foundation, Inc.,
|
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef QTEXTRACOMPONENTSPLUGIN_H
|
|
||||||
#define QTEXTRACOMPONENTSPLUGIN_H
|
|
||||||
|
|
||||||
#include <QQmlExtensionPlugin>
|
|
||||||
|
|
||||||
|
|
||||||
class QtExtraComponentsPlugin : public QQmlExtensionPlugin
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
|
|
||||||
|
|
||||||
public:
|
|
||||||
void registerTypes(const char *uri);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,12 +0,0 @@
|
|||||||
INCLUDE_DIRECTORIES("${CMAKE_CURRENT_SOURCE_DIR}/..")
|
|
||||||
|
|
||||||
include(ECMMarkAsTest)
|
|
||||||
|
|
||||||
add_executable(fullmodelaccesstest columnproxymodeltest.cpp ../columnproxymodel.cpp ../../core/tests/modeltest.cpp)
|
|
||||||
target_link_libraries(fullmodelaccesstest
|
|
||||||
Qt5::Gui
|
|
||||||
Qt5::Test
|
|
||||||
)
|
|
||||||
|
|
||||||
add_test(fullmodelaccesstest fullmodelaccesstest)
|
|
||||||
ecm_mark_as_test(fullmodelaccesstest)
|
|
@ -1,65 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 2.1 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This library is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this library; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
||||||
* 02110-1301 USA
|
|
||||||
*/
|
|
||||||
#include <../tests/columnproxymodeltest.h>
|
|
||||||
#include <columnproxymodel.h>
|
|
||||||
#include <../../core/tests/modeltest.h>
|
|
||||||
#include <qtest.h>
|
|
||||||
#include <QSignalSpy>
|
|
||||||
#include <QStandardItemModel>
|
|
||||||
|
|
||||||
QTEST_MAIN(ColumnProxyModelTest)
|
|
||||||
|
|
||||||
void ColumnProxyModelTest::testInit()
|
|
||||||
{
|
|
||||||
qRegisterMetaType<QModelIndex>("QModelIndex");
|
|
||||||
|
|
||||||
ColumnProxyModel* listify = new ColumnProxyModel;
|
|
||||||
QSignalSpy spy(listify, SIGNAL(rowsInserted(QModelIndex, int, int)));
|
|
||||||
|
|
||||||
new ModelTest(listify, listify);
|
|
||||||
QStandardItemModel* m = new QStandardItemModel(listify);
|
|
||||||
listify->setRootIndex(QModelIndex());
|
|
||||||
listify->setSourceModel(m);
|
|
||||||
m->appendRow(new QStandardItem("lalalal"));
|
|
||||||
m->appendRow(new QStandardItem("lalalal"));
|
|
||||||
m->appendRow(new QStandardItem("lalalal"));
|
|
||||||
m->appendRow(new QStandardItem("lalalal"));
|
|
||||||
QStandardItem* item = new QStandardItem("lalalal");
|
|
||||||
item->appendRow(new QStandardItem("lelele"));
|
|
||||||
item->appendRow(new QStandardItem("lelele"));
|
|
||||||
m->appendRow(item);
|
|
||||||
item->appendRow(new QStandardItem("lelele"));
|
|
||||||
|
|
||||||
QCOMPARE(listify->rowCount(), 5);
|
|
||||||
QCOMPARE(spy.count(), 5);
|
|
||||||
|
|
||||||
ColumnProxyModel* listifyB = new ColumnProxyModel;
|
|
||||||
new ModelTest(listifyB, listifyB);
|
|
||||||
listifyB->setSourceModel(m);
|
|
||||||
QCOMPARE(listifyB->rowCount(), 5);
|
|
||||||
|
|
||||||
ColumnProxyModel* listifyC = new ColumnProxyModel;
|
|
||||||
new ModelTest(listifyC, listifyC);
|
|
||||||
listifyC->setRootIndex(item->index());
|
|
||||||
QCOMPARE(listifyC->rowCount(), 3);
|
|
||||||
|
|
||||||
delete listify;
|
|
||||||
delete listifyB;
|
|
||||||
delete listifyC;
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012 Aleix Pol Gonzalez <aleixpol@kde.org>
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 2.1 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This library is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this library; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
||||||
* 02110-1301 USA
|
|
||||||
*/
|
|
||||||
#ifndef COLUMNPROXYMODELTEST_H
|
|
||||||
#define COLUMNPROXYMODELTEST_H
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
class ColumnProxyModelTest : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
private Q_SLOTS:
|
|
||||||
void testInit();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,95 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2014 David Edmundson <davidedmundson@kde.org>
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Library General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
Library General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Library General Public License
|
|
||||||
along with this library; see the file COPYING.LIB. If not, write to
|
|
||||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
||||||
Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import org.kde.qtextracomponents 2.0
|
|
||||||
import QtQuick 2.1
|
|
||||||
import QtQuick.Layouts 1.0
|
|
||||||
|
|
||||||
|
|
||||||
Item
|
|
||||||
{
|
|
||||||
width: 800
|
|
||||||
height: 400
|
|
||||||
Row {
|
|
||||||
anchors.fill: parent
|
|
||||||
MouseEventListener {
|
|
||||||
width: 400
|
|
||||||
height: 400
|
|
||||||
id: mouseListener
|
|
||||||
acceptedButtons: Qt.LeftButton
|
|
||||||
hoverEnabled: true
|
|
||||||
onPressed: {
|
|
||||||
updateDebug("Pressed", mouse);
|
|
||||||
}
|
|
||||||
onPressAndHold: {
|
|
||||||
updateDebug("Held", mouse);
|
|
||||||
}
|
|
||||||
onReleased: {
|
|
||||||
mouseState.text = "";
|
|
||||||
mousePos.text = "";
|
|
||||||
screenPos.text = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateDebug(state, mouse) {
|
|
||||||
mouseState.text = state
|
|
||||||
mousePos.text = mouse.x + "," + mouse.y
|
|
||||||
screenPos.text = mouse.screenX + "," + mouse.screenY
|
|
||||||
}
|
|
||||||
|
|
||||||
Rectangle {
|
|
||||||
color: "red"
|
|
||||||
anchors.fill: parent
|
|
||||||
|
|
||||||
//MouseEventListener should still get events, even though this has a mousearea
|
|
||||||
MouseArea {
|
|
||||||
anchors.fill: parent
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
GridLayout {
|
|
||||||
width: 400
|
|
||||||
columns: 2
|
|
||||||
Text {
|
|
||||||
text: "Mouse status:"
|
|
||||||
}
|
|
||||||
Text {
|
|
||||||
id: mouseState
|
|
||||||
}
|
|
||||||
Text {
|
|
||||||
text: "Contains Mouse: "
|
|
||||||
}
|
|
||||||
Text {
|
|
||||||
text: mouseListener.containsMouse
|
|
||||||
}
|
|
||||||
Text {
|
|
||||||
text: "Mouse Position: "
|
|
||||||
}
|
|
||||||
Text {
|
|
||||||
id: mousePos
|
|
||||||
}
|
|
||||||
Text {
|
|
||||||
text: "Screen Position: "
|
|
||||||
}
|
|
||||||
Text {
|
|
||||||
id: screenPos
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user