| 1 |
/* |
| 2 |
* Copyright (C) 2020 ~ 2021 Uniontech Software Technology Co., Ltd. |
| 3 |
* |
| 4 |
* Author: ZhangYong <[email protected]> |
| 5 |
* |
| 6 |
* Maintainer: ZhangYong <[email protected]> |
| 7 |
* |
| 8 |
* This program is free software: you can redistribute it and/or modify |
| 9 |
* it under the terms of the GNU General Public License as published by |
| 10 |
* the Free Software Foundation, either version 3 of the License, or |
| 11 |
* any later version. |
| 12 |
* |
| 13 |
* This program is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU General Public License |
| 19 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
#ifndef THUMBNAILLISTVIEW_H |
| 22 |
#define THUMBNAILLISTVIEW_H |
| 23 |
|
| 24 |
#include "thumbnaildelegate.h" |
| 25 |
#include "controller/configsetter.h" |
| 26 |
#include "dbmanager/dbmanager.h" |
| 27 |
#include "widgets/printhelper.h" |
| 28 |
#include "imageengine/imageengineobject.h" |
| 29 |
#include "albumgloabl.h" |
| 30 |
|
| 31 |
#include <QListWidget> |
| 32 |
#include <QListWidgetItem> |
| 33 |
#include <QListView> |
| 34 |
#include <QList> |
| 35 |
#include <QWidgetAction> |
| 36 |
#include <QPixmap> |
| 37 |
#include <QIcon> |
| 38 |
#include <QFileInfo> |
| 39 |
#include <QSize> |
| 40 |
#include <QStandardItemModel> |
| 41 |
#include <QBuffer> |
| 42 |
#include <QMouseEvent> |
| 43 |
#include <QPointer> |
| 44 |
#include <QPropertyAnimation> |
| 45 |
|
| 46 |
#include <DPushButton> |
| 47 |
#include <DImageButton> |
| 48 |
#include <DIconButton> |
| 49 |
#include <DListView> |
| 50 |
#include <DLabel> |
| 51 |
#include <DMenu> |
| 52 |
#include <DApplicationHelper> |
| 53 |
|
| 54 |
|
| 55 |
DWIDGET_USE_NAMESPACE |
| 56 |
|
| 57 |
class BatchOperateWidget; |
| 58 |
class ThumbnailListView : public DListView |
| 59 |
{ |
| 60 |
Q_OBJECT |
| 61 |
|
| 62 |
public: |
| 63 |
enum ListViewUseFor { |
| 64 |
Normal,// |
| 65 |
Mount,//phone |
| 66 |
}; |
| 67 |
enum MenuItemId { |
| 68 |
IdView, |
| 69 |
IdFullScreen, |
| 70 |
IdPrint, |
| 71 |
IdStartSlideShow, |
| 72 |
IdAddToAlbum, |
| 73 |
IdExport, |
| 74 |
IdCopy, |
| 75 |
IdCopyToClipboard, |
| 76 |
IdMoveToTrash, |
| 77 |
IdRemoveFromAlbum, |
| 78 |
IdEdit, |
| 79 |
IdAddToFavorites, |
| 80 |
IdRemoveFromFavorites, |
| 81 |
IdRotateClockwise, |
| 82 |
IdRotateCounterclockwise, |
| 83 |
IdLabel, |
| 84 |
IdSetAsWallpaper, |
| 85 |
IdDisplayInFileManager, |
| 86 |
IdImageInfo, |
| 87 |
IdVideoInfo, //视频信息 |
| 88 |
IdSubMenu, |
| 89 |
IdSeparator, |
| 90 |
IdTrashRecovery, |
| 91 |
IdDrawingBoard//lmh0407画板 |
| 92 |
}; |
| 93 |
|
| 94 |
explicit ThumbnailListView(ThumbnailDelegate::DelegateType type = ThumbnailDelegate::NullType, const QString &imgtype = "All Photos", QWidget *parent = nullptr); |
| 95 |
~ThumbnailListView() override; |
| 96 |
|
| 97 |
void insertThumbnail(const DBImgInfo &dBImgInfo);//1050 |
| 98 |
//为true则清除模型中的数据 |
| 99 |
void stopLoadAndClear(bool bClearModel = false); |
| 100 |
//根据列表显示不同,返回不同数据 |
| 101 |
QStringList getFileList(int row = -1); |
| 102 |
//获取所有文件信息 |
| 103 |
QList<DBImgInfo> getAllFileInfo(int row = -1); |
| 104 |
//根据路径返回所在行号 |
| 105 |
int getRow(const QString &path); |
| 106 |
//筛选出所有选中缩略图 |
| 107 |
QStringList selectedPaths(); |
| 108 |
//获取拖拽的item |
| 109 |
QStringList getDagItemPath(); |
| 110 |
//右键菜单 |
| 111 |
void menuItemDeal(QStringList paths, QAction *action); |
| 112 |
int getListViewHeight(); |
| 113 |
int getRow(QPoint point); |
| 114 |
void setListViewUseFor(ListViewUseFor usefor); |
| 115 |
//选中重复照片 |
| 116 |
void selectDuplicatePhotos(QStringList paths); |
| 117 |
void updateModelRoleData(QString albumName, int actionType); |
| 118 |
void selectFirstPhoto(); |
| 119 |
bool isFirstPhotoSelected(); |
| 120 |
bool isNoPhotosSelected(); |
| 121 |
void clearAll(); |
| 122 |
|
| 123 |
/********* 插入一个空白项,ItemTypeBlank *********/ |
| 124 |
/********* 插入时间线标题,ItemTypeTimeLineTitle *********/ |
| 125 |
/********* 插入已导入时间线标题,ItemTypeImportTimeLineTitle*********/ |
| 126 |
void insertBlankOrTitleItem(ItemType type, const QString &date = "", const QString &num = "", int height = 0);//zynew |
| 127 |
//更新空白栏高度 |
| 128 |
void resetBlankItemHeight(int height);//zynew |
| 129 |
//根据DBImgInfoList插入listview |
| 130 |
void insertThumbnailByImgInfos(DBImgInfoList infoList);//zynew |
| 131 |
|
| 132 |
//判断是否全部选中 |
| 133 |
bool isAllSelected(ItemType type = ItemTypeNull); //zynew |
| 134 |
//判断选中图片是否都可旋转 |
| 135 |
bool isAllSelectedSupportRotate();//zynew |
| 136 |
//删除选中项到相册已删除 |
| 137 |
void removeSelectToTrash(QStringList paths);//zynew |
| 138 |
//更新时间线界面内各个按钮的text状态,单选/框选 |
| 139 |
void updatetimeLimeBtnText();//1050 |
| 140 |
//过滤显示选中类型 |
| 141 |
void showAppointTypeItem(ItemType type);//zynew |
| 142 |
//显示类型数量 |
| 143 |
int getAppointTypeItemCount(ItemType type);//zynew |
| 144 |
//显示指定类型选中项数量 |
| 145 |
int getAppointTypeSelectItemCount(ItemType type);//zynew |
| 146 |
//按类型选择 |
| 147 |
void selectAllByItemType(ItemType type);//zynew |
| 148 |
//时间线所有选择按钮响应ctrl+all快捷键,切换按钮状态 |
| 149 |
void TimeLineSelectAllBtn(); |
| 150 |
//设置批量操作菜单 |
| 151 |
void setBatchOperateWidget(BatchOperateWidget *widget); |
| 152 |
|
| 153 |
signals: |
| 154 |
//打开图片,该项在当前列表行数,以及该项所含信息路径 |
| 155 |
void openImage(int row, QString path, bool bFullScreen); |
| 156 |
//幻灯片播放 |
| 157 |
void sigSlideShow(QString path); |
| 158 |
void exportImage(QString, QStringList); |
| 159 |
void showExtensionPanel(); |
| 160 |
void trashRecovery(); |
| 161 |
|
| 162 |
void sigMouseRelease(); |
| 163 |
void sigSelectAll(); |
| 164 |
void sigMouseMove(); |
| 165 |
//数据库图片加载完毕 |
| 166 |
bool sigDBImageLoaded(); |
| 167 |
|
| 168 |
//加载完成后刷新状态栏数量 |
| 169 |
void sigUpdatePicNum(); |
| 170 |
//时间线需要用到显示后的宽度 |
| 171 |
void sigShowEvent(); |
| 172 |
//最上方时间与图片数量 |
| 173 |
void sigTimeLineDataAndNum(QString data, QString num, QString text); |
| 174 |
|
| 175 |
void sigMoveToTrash(); |
| 176 |
|
| 177 |
//筛选显示图片或者视频,无结果时 |
| 178 |
void sigNoPicOrNoVideo(bool isNoResult);//1050 |
| 179 |
protected: |
| 180 |
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; |
| 181 |
void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; |
| 182 |
void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; |
| 183 |
void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE; |
| 184 |
void dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE; |
| 185 |
void dragMoveEvent(QDragMoveEvent *event) Q_DECL_OVERRIDE; |
| 186 |
void dragLeaveEvent(QDragLeaveEvent *event) Q_DECL_OVERRIDE; |
| 187 |
void dropEvent(QDropEvent *event) Q_DECL_OVERRIDE; |
| 188 |
void startDrag(Qt::DropActions supportedActions) Q_DECL_OVERRIDE; |
| 189 |
void showEvent(QShowEvent *event) Q_DECL_OVERRIDE; |
| 190 |
void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE; |
| 191 |
//重写该函数是为了获取当前视图中最大的model index,该函数和paint同步 |
| 192 |
QRect visualRect(const QModelIndex &index) const override; |
| 193 |
|
| 194 |
private slots: |
| 195 |
void sltReloadAfterFilterEnd(); |
| 196 |
//子线程加载缩略图后刷新列表 |
| 197 |
void onUpdateListview(); |
| 198 |
void onLoadTimerTimeout(); |
| 199 |
void onMenuItemClicked(QAction *action); |
| 200 |
void onShowMenu(const QPoint &pos); |
| 201 |
void onPixMapScale(int value); |
| 202 |
void onCancelFavorite(const QModelIndex &index); |
| 203 |
void resizeEventF(); |
| 204 |
//删除图片之后更新listview中数据 |
| 205 |
void updateThumbnailViewAfterDelete(const DBImgInfoList &infos); |
| 206 |
//时间线界面,选择当前时间内照片 |
| 207 |
void slotSelectCurrentDatePic(bool isSelect, QStandardItem *item); |
| 208 |
public slots: |
| 209 |
//加载当前页面前后各两百张图片 |
| 210 |
void reloadImage(); |
| 211 |
//所有照片界面 |
| 212 |
void slotLoadFirstPageThumbnailsFinish(); |
| 213 |
|
| 214 |
//时间线界面 |
| 215 |
//有新的图片加载上来 |
| 216 |
void slotOneImgReady(const QString &path, QPixmap pix); |
| 217 |
//滚动条定时器 |
| 218 |
void onScrollTimerOut(); |
| 219 |
|
| 220 |
void onSyncListviewModelData(QStringList paths, QString albumName, int actionType); |
| 221 |
//处理时间线悬浮按钮与其他时间在滑动时的状态同步 |
| 222 |
void onScrollbarValueChanged(int value); |
| 223 |
|
| 224 |
void onDoubleClicked(const QModelIndex &index); |
| 225 |
void onClicked(const QModelIndex &index); |
| 226 |
//设置所有选择按钮是否可见 |
| 227 |
void slotChangeAllSelectBtnVisible(bool visible);//1050 |
| 228 |
public: |
| 229 |
// zy 新算法 |
| 230 |
void cutPixmap(DBImgInfo &DBImgInfo); |
| 231 |
// 响应时间线悬浮栏的按钮选中操作 |
| 232 |
void timeLimeFloatBtnClicked(const QString &date, bool isSelect); |
| 233 |
|
| 234 |
private: |
| 235 |
void initConnections(); |
| 236 |
void updateMenuContents(); |
| 237 |
void appendAction(int id, const QString &text, const QString &shortcut); |
| 238 |
void initMenuAction(); |
| 239 |
DMenu *createAlbumMenu(); |
| 240 |
void resizeEvent(QResizeEvent *e) override; |
| 241 |
bool eventFilter(QObject *obj, QEvent *e) override; |
| 242 |
//获取当前index所属时间线的时间和数量 |
| 243 |
QStringList getCurrentIndexTime(const QModelIndex &index); |
| 244 |
//获取当前时间线内的图片选中状态 |
| 245 |
bool getCurrentIndexSelectStatus(const QModelIndex &index, bool isPic); |
| 246 |
//判断是都全是选中类型 |
| 247 |
bool isAllAppointType(ItemType type);//1050 |
| 248 |
//隐藏指定选中类型 |
| 249 |
void hideAllAppointType(ItemType type);//1050 |
| 250 |
|
| 251 |
int m_iBaseHeight = 0; |
| 252 |
|
| 253 |
ThumbnailDelegate *m_delegate = nullptr; |
| 254 |
|
| 255 |
DMenu *m_pMenu = nullptr; |
| 256 |
QMap<QString, QAction *> m_MenuActionMap; |
| 257 |
DMenu *m_albumMenu = nullptr; |
| 258 |
|
| 259 |
QStringList m_dragItemPath; |
| 260 |
ThumbnailDelegate::DelegateType m_delegatetype = ThumbnailDelegate::NullType; |
| 261 |
|
| 262 |
QStringList m_allfileslist; |
| 263 |
bool m_bfirstload = true; |
| 264 |
bool bneedcache = true; |
| 265 |
QListWidgetItem *m_item = nullptr; |
| 266 |
|
| 267 |
//---触屏判断-------- |
| 268 |
// 用于实现触屏滚动视图和框选文件不冲突,手指在屏幕上按下短时间内就开始移动 |
| 269 |
// 会被认为触发滚动视图,否则为触发文件选择(时间默认为300毫秒) |
| 270 |
QPointer<QTimer> updateEnableSelectionByMouseTimer; |
| 271 |
|
| 272 |
// 记录触摸按下事件,在mouse move事件中使用,用于判断手指移动的距离,当大于 |
| 273 |
// QPlatformTheme::TouchDoubleTapDistance 的值时认为触发触屏滚动 |
| 274 |
QPoint lastTouchBeginPos; |
| 275 |
|
| 276 |
//触屏状态指示:0,等待模式;1,滑动模式;2,框选模式 |
| 277 |
int touchStatus = 0; |
| 278 |
|
| 279 |
//是否激活click:当处于滑动模式的时候,本轮不执行click |
| 280 |
bool activeClick = true; |
| 281 |
QTimer *m_loadTimer = nullptr; |
| 282 |
//记录当前显示类型 |
| 283 |
ItemType m_currentShowItemType = ItemType::ItemTypeNull; |
| 284 |
BatchOperateWidget *m_batchOperateWidget = nullptr; |
| 285 |
public: |
| 286 |
ListViewUseFor m_useFor = Normal; |
| 287 |
QString m_imageType; |
| 288 |
QStandardItemModel *m_model = nullptr; |
| 289 |
|
| 290 |
int m_rowSizeHint = 0; |
| 291 |
int m_blankItemHeight = 0;//上方空白项高度 |
| 292 |
bool m_animationEnable = false;//标题上滑动画是否可执行 |
| 293 |
QPropertyAnimation *m_animation = nullptr; |
| 294 |
QTimer *m_scrollTimer = nullptr; |
| 295 |
int m_height = 0; |
| 296 |
int m_onePicWidth = 0; |
| 297 |
bool m_isSelectAllBtn = false; //平板下,是否选中所有,默认未选定 |
| 298 |
}; |
| 299 |
|
| 300 |
#endif // THUMBNAILLISTVIEW_H |