| 1 |
/* |
| 2 |
* libkysdk-qtwidgets's Library |
| 3 |
* |
| 4 |
* Copyright (C) 2024, KylinSoft Co., Ltd. |
| 5 |
* |
| 6 |
* This library is free software; you can redistribute it and/or |
| 7 |
* modify it under the terms of the GNU Lesser General Public |
| 8 |
* License as published by the Free Software Foundation; either |
| 9 |
* version 3 of the License, or (at your option) any later version. |
| 10 |
* |
| 11 |
* This library is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
* Lesser General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this library. If not, see <https://www.gnu.org/licenses/>. |
| 18 |
* |
| 19 |
* Authors: Zhenyu Wang <[email protected]> |
| 20 |
* |
| 21 |
*/ |
| 22 |
|
| 23 |
#ifndef KDRAGWIDGET_H |
| 24 |
#define KDRAGWIDGET_H |
| 25 |
|
| 26 |
#include "gui_g.h" |
| 27 |
#include "kpushbutton.h" |
| 28 |
#include <QDragEnterEvent> |
| 29 |
#include <QDropEvent> |
| 30 |
#include <QFileDialog> |
| 31 |
#include <QLabel> |
| 32 |
|
| 33 |
namespace kdk |
| 34 |
{ |
| 35 |
|
| 36 |
/** |
| 37 |
* @defgroup DragModule |
| 38 |
* { |
| 39 |
*/ |
| 40 |
class KDragWidgetPrivate; |
| 41 |
|
| 42 |
/** |
| 43 |
* @brief 拖动文件或文件夹,可识别并获取文件或文件夹路径 |
| 44 |
* @since 2.3.1.0 |
| 45 |
*/ |
| 46 |
class GUI_EXPORT KDragWidget : public QWidget |
| 47 |
{ |
| 48 |
Q_OBJECT |
| 49 |
|
| 50 |
public: |
| 51 |
KDragWidget(QWidget *parent = nullptr); |
| 52 |
|
| 53 |
/** |
| 54 |
* @brief iconButton |
| 55 |
* @return 返回iconbutton |
| 56 |
*/ |
| 57 |
KPushButton *iconButton(); |
| 58 |
|
| 59 |
/** |
| 60 |
* @brief textLabel |
| 61 |
* @return 返回textlabel |
| 62 |
*/ |
| 63 |
QLabel *textLabel(); |
| 64 |
|
| 65 |
/** |
| 66 |
* @brief fileDialog |
| 67 |
* @return 返回QFiledialog |
| 68 |
*/ |
| 69 |
QFileDialog *fileDialog(); |
| 70 |
|
| 71 |
/** |
| 72 |
* @brief 将文件对话框中使用的过滤器设置为给定的过滤器。 |
| 73 |
* @param filter |
| 74 |
*/ |
| 75 |
void setNameFilter(const QString &filter); |
| 76 |
|
| 77 |
/** |
| 78 |
* @brief 设置文件对话框中使用的过滤器。 |
| 79 |
* @param filters |
| 80 |
*/ |
| 81 |
void setNameFilters(const QStringList &filters); |
| 82 |
|
| 83 |
protected: |
| 84 |
void mouseMoveEvent(QMouseEvent *event); |
| 85 |
void mousePressEvent(QMouseEvent *event); |
| 86 |
void mouseReleaseEvent(QMouseEvent *event); |
| 87 |
void keyPressEvent(QKeyEvent *event); |
| 88 |
void keyReleaseEvent(QKeyEvent *event); |
| 89 |
void paintEvent(QPaintEvent *event); |
| 90 |
bool eventFilter(QObject *watched, QEvent *event); |
| 91 |
void dragEnterEvent(QDragEnterEvent *event); |
| 92 |
void dragLeaveEvent(QDragLeaveEvent *event); |
| 93 |
void dragMoveEvent(QDragMoveEvent *event); |
| 94 |
void dropEvent(QDropEvent *event); |
| 95 |
|
| 96 |
Q_SIGNALS: |
| 97 |
void getPath(QString); |
| 98 |
|
| 99 |
/** |
| 100 |
* @brief 获取列表信号 |
| 101 |
* @since 2.5.1.2-0k1.0 |
| 102 |
*/ |
| 103 |
void getPathList(QStringList); |
| 104 |
|
| 105 |
private: |
| 106 |
Q_DECLARE_PRIVATE(KDragWidget) |
| 107 |
KDragWidgetPrivate *const d_ptr; |
| 108 |
}; |
| 109 |
|
| 110 |
} |
| 111 |
#endif // KDRAGWIDGET_H |