添加一个dragdrop例程
BIN
test/testdroptoimageeffect/AppRoot/logo.png
Normal file
After Width: | Height: | Size: 6.8 KiB |
24
test/testdroptoimageeffect/AppRoot/skin/default.qss
Normal file
@ -0,0 +1,24 @@
|
||||
/*spinbox 抬起样式*/
|
||||
QTimeEdit::up-button,QDoubleSpinBox::up-button,QSpinBox::up-button {
|
||||
subcontrol-origin:border;
|
||||
subcontrol-position:right;
|
||||
width: 12px;
|
||||
}
|
||||
|
||||
QTimeEdit::down-button,QDoubleSpinBox::down-button,QSpinBox::down-button {
|
||||
subcontrol-origin:border;
|
||||
subcontrol-position:left;
|
||||
width: 12px;
|
||||
}
|
||||
|
||||
/*按钮按下样式*/
|
||||
QTimeEdit::up-button:pressed,QDoubleSpinBox::up-button:pressed,QSpinBox::up-button:pressed{
|
||||
subcontrol-origin:border;
|
||||
subcontrol-position:right;
|
||||
width: 12px;
|
||||
}
|
||||
|
||||
QTimeEdit::down-button:pressed,QDoubleSpinBox::down-button:pressed,QSpinBox::down-button:pressed,QSpinBox::down-button:pressed{
|
||||
subcontrol-position:left;
|
||||
width: 12px;
|
||||
}
|
89
test/testdroptoimageeffect/android/AndroidManifest.xml
Normal file
@ -0,0 +1,89 @@
|
||||
<?xml version="1.0"?>
|
||||
<manifest package="org.qtproject.example.testdroptoimageeffect" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.0" android:versionCode="1" android:installLocation="auto">
|
||||
<application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="testdroptoimageeffect" android:icon="@drawable/icon">
|
||||
<activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="org.qtproject.qt5.android.bindings.QtActivity" android:label="testdroptoimageeffect" android:screenOrientation="unspecified" android:launchMode="singleTop">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
|
||||
<!-- Application arguments -->
|
||||
<!-- meta-data android:name="android.app.arguments" android:value="arg1 arg2 arg3"/ -->
|
||||
<!-- Application arguments -->
|
||||
|
||||
<meta-data android:name="android.app.lib_name" android:value="testdroptoimageeffect"/>
|
||||
<meta-data android:name="android.app.qt_sources_resource_id" android:resource="@array/qt_sources"/>
|
||||
<meta-data android:name="android.app.repository" android:value="default"/>
|
||||
<meta-data android:name="android.app.qt_libs_resource_id" android:resource="@array/qt_libs"/>
|
||||
<meta-data android:name="android.app.bundled_libs_resource_id" android:resource="@array/bundled_libs"/>
|
||||
<!-- Deploy Qt libs as part of package -->
|
||||
<meta-data android:name="android.app.bundle_local_qt_libs" android:value="1"/>
|
||||
<meta-data android:name="android.app.bundled_in_lib_resource_id" android:resource="@array/bundled_in_lib"/>
|
||||
<meta-data android:name="android.app.bundled_in_assets_resource_id" android:resource="@array/bundled_in_assets"/>
|
||||
<!-- Run with local libs -->
|
||||
<meta-data android:name="android.app.use_local_qt_libs" android:value="1"/>
|
||||
<meta-data android:name="android.app.libs_prefix" android:value="/data/local/tmp/qt/"/>
|
||||
<meta-data android:name="android.app.load_local_libs" android:value="plugins/platforms/android/libqtforandroid.so"/>
|
||||
<meta-data android:name="android.app.load_local_jars" android:value="jar/QtAndroid.jar:jar/QtAndroid-bundled.jar"/>
|
||||
<meta-data android:name="android.app.static_init_classes" android:value=""/>
|
||||
<!-- Messages maps -->
|
||||
<meta-data android:value="@string/ministro_not_found_msg" android:name="android.app.ministro_not_found_msg"/>
|
||||
<meta-data android:value="@string/ministro_needed_msg" android:name="android.app.ministro_needed_msg"/>
|
||||
<meta-data android:value="@string/fatal_error_msg" android:name="android.app.fatal_error_msg"/>
|
||||
<!-- Messages maps -->
|
||||
|
||||
<!-- Splash screen -->
|
||||
<!-- meta-data android:name="android.app.splash_screen_drawable" android:resource="@drawable/logo"/ -->
|
||||
<!-- meta-data android:name="android.app.splash_screen_sticky" android:value="true"/ -->
|
||||
<!-- Splash screen -->
|
||||
|
||||
<!-- Background running -->
|
||||
<!-- Warning: changing this value to true may cause unexpected crashes if the
|
||||
application still try to draw after
|
||||
"applicationStateChanged(Qt::ApplicationSuspended)"
|
||||
signal is sent! -->
|
||||
<meta-data android:name="android.app.background_running" android:value="false"/>
|
||||
<!-- Background running -->
|
||||
|
||||
<!-- auto screen scale factor -->
|
||||
<meta-data android:name="android.app.auto_screen_scale_factor" android:value="false"/>
|
||||
<!-- auto screen scale factor -->
|
||||
|
||||
<!-- extract android style -->
|
||||
<!-- available android:values :
|
||||
* full - useful QWidget & Quick Controls 1 apps
|
||||
* minimal - useful for Quick Controls 2 apps, it is much faster than "full"
|
||||
* none - useful for apps that don't use any of the above Qt modules
|
||||
-->
|
||||
<meta-data android:name="android.app.extract_android_style" android:value="full"/>
|
||||
<!-- extract android style -->
|
||||
</activity>
|
||||
|
||||
<!-- For adding service(s) please check: https://wiki.qt.io/AndroidServices -->
|
||||
|
||||
</application>
|
||||
|
||||
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="16"/>
|
||||
<supports-screens android:largeScreens="true" android:normalScreens="true" android:anyDensity="true" android:smallScreens="true"/>
|
||||
|
||||
<!-- The following comment will be replaced upon deployment with default permissions based on the dependencies of the application.
|
||||
Remove the comment if you do not require these default permissions. -->
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- The following comment will be replaced upon deployment with default features based on the dependencies of the application.
|
||||
Remove the comment if you do not require these default features. -->
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
<!-- %%INSERT_PERMISSIONS -->
|
||||
<!-- %%INSERT_FEATURES -->
|
||||
<uses-permission android:name="android.permission.ACCESS_CHECKIN_PROPERTIES"/>
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
|
||||
</manifest>
|
After Width: | Height: | Size: 13 KiB |
BIN
test/testdroptoimageeffect/android/res/drawable-hdpi/icon.png
Normal file
After Width: | Height: | Size: 82 KiB |
After Width: | Height: | Size: 3.5 KiB |
BIN
test/testdroptoimageeffect/android/res/drawable-ldpi/icon.png
Normal file
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 6.0 KiB |
BIN
test/testdroptoimageeffect/android/res/drawable-mdpi/icon.png
Normal file
After Width: | Height: | Size: 48 KiB |
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 48 KiB |
After Width: | Height: | Size: 82 KiB |
11
test/testdroptoimageeffect/main.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
#include "mainwindow.h"
|
||||
#include <QQtApplication>
|
||||
|
||||
int main ( int argc, char* argv[] )
|
||||
{
|
||||
QQtApplication a ( argc, argv );
|
||||
MainWindow w;
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
}
|
25
test/testdroptoimageeffect/mainwindow.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
#include <qqtbodydroptoimageeffect.h>
|
||||
#include <qqtframe.h>
|
||||
|
||||
MainWindow::MainWindow ( QWidget* parent ) :
|
||||
QMainWindow ( parent ),
|
||||
ui ( new Ui::MainWindow )
|
||||
{
|
||||
ui->setupUi ( this );
|
||||
|
||||
ui->widget->setPixmap ( conf_root ( "logo.png" ) );
|
||||
ui->widget->setAcceptDrops ( true );
|
||||
ui->widget_2->setAcceptDrops ( true );
|
||||
|
||||
QQtBodyDropImageEffect* effect = new QQtBodyDropImageEffect ( this );
|
||||
ui->widget->installEventFilter ( effect );
|
||||
ui->widget_2->installEventFilter ( effect );
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
}
|
22
test/testdroptoimageeffect/mainwindow.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = 0);
|
||||
~MainWindow();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
69
test/testdroptoimageeffect/mainwindow.ui
Normal file
@ -0,0 +1,69 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>632</width>
|
||||
<height>387</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>testdroptoimageeffect</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget">
|
||||
<widget class="QQtWidget" name="widget" native="true">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>70</x>
|
||||
<y>70</y>
|
||||
<width>120</width>
|
||||
<height>80</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QQtWidget" name="widget_2" native="true">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>280</x>
|
||||
<y>70</y>
|
||||
<width>120</width>
|
||||
<height>80</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menuBar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>632</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QToolBar" name="mainToolBar">
|
||||
<attribute name="toolBarArea">
|
||||
<enum>TopToolBarArea</enum>
|
||||
</attribute>
|
||||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusBar"/>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>QQtWidget</class>
|
||||
<extends>QWidget</extends>
|
||||
<header location="global">qqtwidget.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
140
test/testdroptoimageeffect/qqtbodydroptoimageeffect.cpp
Normal file
@ -0,0 +1,140 @@
|
||||
#include <qqtbodydroptoimageeffect.h>
|
||||
|
||||
#include <QEvent>
|
||||
#include <QPainter>
|
||||
#include <QWidget>
|
||||
|
||||
#include <qqtcore.h>
|
||||
|
||||
QQtBodyDropImageEffect::QQtBodyDropImageEffect ( QObject* parent ) : QObject ( parent )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QQtBodyDropImageEffect::~QQtBodyDropImageEffect() {}
|
||||
|
||||
|
||||
bool QQtBodyDropImageEffect::eventFilter ( QObject* watched, QEvent* event )
|
||||
{
|
||||
if ( !watched->inherits ( "QWidget" ) )
|
||||
return QObject::eventFilter ( watched, event );
|
||||
|
||||
//修复鼠标穿透。鼠标穿透没有效果
|
||||
bool atti = ( qobject_cast<QWidget*> ( watched ) )->testAttribute ( Qt::WA_TransparentForMouseEvents );
|
||||
if ( atti )
|
||||
return QObject::eventFilter ( watched, event );
|
||||
|
||||
if ( event->type() == QEvent::Paint )
|
||||
return QObject::eventFilter ( watched, event );
|
||||
|
||||
if ( event->type() == QEvent::MouseMove )
|
||||
return QObject::eventFilter ( watched, event );
|
||||
|
||||
static int i = 0;
|
||||
p2line() << i++ << watched->objectName() << event->type() ;
|
||||
|
||||
switch ( event->type() )
|
||||
{
|
||||
case QEvent::DragEnter:
|
||||
{
|
||||
QWidget* target = qobject_cast<QWidget*> ( watched );
|
||||
QWidget& w = *target;
|
||||
|
||||
QRect rectMustIn = QRect ( w.mapToGlobal ( w.rect().topLeft() ), w.mapToGlobal ( w.rect().bottomRight() ) );//srcR0
|
||||
QMargins m_margins = w.contentsMargins();
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
||||
QRect rectMustNotIn = rectMustIn.adjusted ( m_margins.left(), m_margins.top(), m_margins.right(), m_margins.bottom() );
|
||||
#else
|
||||
QRect rectMustNotIn = rectMustIn.marginsRemoved ( m_margins );
|
||||
#endif
|
||||
QPoint cursorPos = QCursor::pos();//globalPos
|
||||
|
||||
//在content里面才能响应 [比较的时候不放大坐标,调试出来的]
|
||||
if ( rectMustIn.contains ( cursorPos ) && rectMustNotIn.contains ( cursorPos ) )
|
||||
{
|
||||
QDragEnterEvent* e = ( QDragEnterEvent* ) event;
|
||||
p2line() << e->answerRect();
|
||||
//p2line() << e->dropAction();
|
||||
p2line() << e->spontaneous();
|
||||
p2line() << e->source()->objectName();
|
||||
p2line() << e->mimeData()->formats() << e->mimeData()->urls();
|
||||
p2line() << e->possibleActions() << e->proposedAction();
|
||||
}
|
||||
|
||||
event->accept();
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case QEvent::DragLeave:
|
||||
{
|
||||
QWidget* target = qobject_cast<QWidget*> ( watched );
|
||||
QWidget& w = *target;
|
||||
|
||||
if ( !target->isActiveWindow() )
|
||||
{
|
||||
event->ignore();
|
||||
return false;
|
||||
}
|
||||
|
||||
QRect rectMustIn = QRect ( w.mapToGlobal ( w.rect().topLeft() ), w.mapToGlobal ( w.rect().bottomRight() ) );//srcR0
|
||||
QMargins m_margins = w.contentsMargins();
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
||||
QRect rectMustNotIn = rectMustIn.adjusted ( m_margins.left(), m_margins.top(), m_margins.right(), m_margins.bottom() );
|
||||
#else
|
||||
QRect rectMustNotIn = rectMustIn.marginsRemoved ( m_margins );
|
||||
#endif
|
||||
QPoint cursorPos = QCursor::pos();//globalPos
|
||||
|
||||
//在content里面才能响应 [比较的时候不放大坐标,调试出来的]
|
||||
if ( rectMustIn.contains ( cursorPos ) && rectMustNotIn.contains ( cursorPos ) )
|
||||
{
|
||||
QDragLeaveEvent* e = ( QDragLeaveEvent* ) event;
|
||||
p2line() << e->spontaneous();
|
||||
}
|
||||
|
||||
event->accept();
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case QEvent::Drop:
|
||||
{
|
||||
QWidget* target = qobject_cast<QWidget*> ( watched );
|
||||
QWidget& w = *target;
|
||||
|
||||
if ( !target->isActiveWindow() )
|
||||
{
|
||||
event->ignore();
|
||||
return false;
|
||||
}
|
||||
|
||||
QRect rectMustIn = QRect ( w.mapToGlobal ( w.rect().topLeft() ), w.mapToGlobal ( w.rect().bottomRight() ) );//srcR0
|
||||
QMargins m_margins = w.contentsMargins();
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
||||
QRect rectMustNotIn = rectMustIn.adjusted ( m_margins.left(), m_margins.top(), m_margins.right(), m_margins.bottom() );
|
||||
#else
|
||||
QRect rectMustNotIn = rectMustIn.marginsRemoved ( m_margins );
|
||||
#endif
|
||||
QPoint cursorPos = QCursor::pos();//globalPos
|
||||
|
||||
//在content里面才能响应 [比较的时候不放大坐标,调试出来的]
|
||||
if ( rectMustIn.contains ( cursorPos ) && rectMustNotIn.contains ( cursorPos ) )
|
||||
{
|
||||
QDropEvent* e = ( QDropEvent* ) event;
|
||||
p2line();
|
||||
//p2line() << e->dropAction();
|
||||
p2line() << e->spontaneous();
|
||||
p2line() << e->source()->objectName();
|
||||
p2line() << e->mimeData()->formats() << e->mimeData()->urls();
|
||||
p2line() << e->possibleActions() << e->proposedAction();
|
||||
}
|
||||
|
||||
event->accept();
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return QObject::eventFilter ( watched, event );
|
||||
}
|
18
test/testdroptoimageeffect/qqtbodydroptoimageeffect.h
Normal file
@ -0,0 +1,18 @@
|
||||
#ifndef QQTBODYDROPIMAGEEFFECT_H
|
||||
#define QQTBODYDROPIMAGEEFFECT_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class QQtBodyDropImageEffect : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QQtBodyDropImageEffect ( QObject* parent = 0 );
|
||||
virtual ~QQtBodyDropImageEffect();
|
||||
|
||||
// QObject interface
|
||||
public:
|
||||
virtual bool eventFilter ( QObject* watched, QEvent* event ) override;
|
||||
};
|
||||
|
||||
#endif // QQTBODYDROPIMAGEEFFECT_H
|
69
test/testdroptoimageeffect/testdroptoimageeffect.pro
Normal file
@ -0,0 +1,69 @@
|
||||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2018-10-06T08:16:10
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core gui
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
|
||||
TARGET = testdroptoimageeffect
|
||||
TEMPLATE = app
|
||||
|
||||
# The following define makes your compiler emit warnings if you use
|
||||
# any feature of Qt which has been marked as deprecated (the exact warnings
|
||||
# depend on your compiler). Please consult the documentation of the
|
||||
# deprecated API in order to know how to port your code away from it.
|
||||
DEFINES += QT_DEPRECATED_WARNINGS
|
||||
|
||||
# You can also make your code fail to compile if you use deprecated APIs.
|
||||
# In order to do so, uncomment the following line.
|
||||
# You can also select to disable deprecated APIs only up to a certain version of Qt.
|
||||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||
include($${PWD}/../../multi-link/add_base_manager.pri)
|
||||
|
||||
SOURCES += \
|
||||
main.cpp \
|
||||
mainwindow.cpp
|
||||
|
||||
HEADERS += \
|
||||
mainwindow.h
|
||||
|
||||
FORMS += \
|
||||
mainwindow.ui
|
||||
|
||||
add_file(qqtbodydroptoimageeffect.h)
|
||||
add_file(qqtbodydroptoimageeffect.cpp)
|
||||
HEADERS += qqtbodydroptoimageeffect.h
|
||||
SOURCES += qqtbodydroptoimageeffect.cpp
|
||||
|
||||
#-------------------------------------------------
|
||||
#用户工程配置
|
||||
#-------------------------------------------------
|
||||
add_version(1,0,0,0)
|
||||
add_deploy()
|
||||
add_deploy_config($${PWD}/AppRoot)
|
||||
add_dependent_manager(QQt)
|
||||
system(touch main.cpp)
|
||||
|
||||
#-------------------------------------------------
|
||||
#用户工程配置
|
||||
#-------------------------------------------------
|
||||
equals(QSYS_PRIVATE, macOS) {
|
||||
CONFIG += app_bundle
|
||||
}
|
||||
|
||||
contains(QSYS_PRIVATE, Android|AndroidX86) {
|
||||
CONFIG += mobility
|
||||
MOBILITY =
|
||||
DISTFILES += \
|
||||
android/AndroidManifest.xml
|
||||
|
||||
ANDROID_PACKAGE_SOURCE_DIR = $${PWD}/android
|
||||
}
|
||||
|
||||
message ($${TARGET} config $${CONFIG})
|
||||
message ($${TARGET} DEFINE $${DEFINES})
|
||||
message ($${TARGET} prelink $${QMAKE_PRE_LINK})
|
||||
message ($${TARGET} postlink $${QMAKE_POST_LINK})
|