| 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 |
#include "thumbnaillistview.h" |
| 22 |
#include "application.h" |
| 23 |
|
| 24 |
#include <QDebug> |
| 25 |
#include <QDrag> |
| 26 |
#include <QFileInfo> |
| 27 |
#include <QImageReader> |
| 28 |
#include <QMimeData> |
| 29 |
#include <QScrollBar> |
| 30 |
#include <QMutex> |
| 31 |
#include <QScroller> |
| 32 |
#include <QPropertyAnimation> |
| 33 |
#include <QDesktopServices> |
| 34 |
#include <QProcess> |
| 35 |
|
| 36 |
#include "controller/signalmanager.h" |
| 37 |
#include "controller/wallpapersetter.h" |
| 38 |
#include "widgets/dialogs/imgdeletedialog.h" |
| 39 |
#include "utils/baseutils.h" |
| 40 |
#include "utils/imageutils.h" |
| 41 |
#include "utils/unionimage.h" |
| 42 |
#include "imageengine/imageengineapi.h" |
| 43 |
#include "imageengine/imageenginethread.h" |
| 44 |
#include "ac-desktop-define.h" |
| 45 |
#include "timelinedatewidget.h" |
| 46 |
#include "allpicview/allpicview.h" |
| 47 |
#include "imagedataservice.h" |
| 48 |
#include "batchoperatewidget.h" |
| 49 |
|
| 50 |
namespace { |
| 51 |
const int ITEM_SPACING = 4; |
| 52 |
const int BASE_HEIGHT = 100; |
| 53 |
|
| 54 |
// const QString IMAGE_DEFAULTTYPE = "All pics"; |
| 55 |
const QString IMAGE_DEFAULTTYPE = "All Photos"; |
| 56 |
const QString SHORTCUTVIEW_GROUP = "SHORTCUTVIEW"; |
| 57 |
|
| 58 |
using namespace utils::common; |
| 59 |
|
| 60 |
QString ss(const QString &text) |
| 61 |
{ |
| 62 |
QString str = dApp->setter->value(SHORTCUTVIEW_GROUP, text).toString(); |
| 63 |
str.replace(" ", ""); |
| 64 |
|
| 65 |
return str; |
| 66 |
} |
| 67 |
} // namespace |
| 68 |
|
| 69 |
ThumbnailListView::ThumbnailListView(ThumbnailDelegate::DelegateType type, const QString &imgtype, QWidget *parent) |
| 70 |
: DListView(parent), m_delegatetype(type), m_allfileslist(), updateEnableSelectionByMouseTimer(nullptr) |
| 71 |
{ |
| 72 |
m_model = new QStandardItemModel(this); |
| 73 |
m_imageType = imgtype; |
| 74 |
m_iBaseHeight = BASE_HEIGHT; |
| 75 |
m_albumMenu = nullptr; |
| 76 |
setResizeMode(QListView::Adjust); |
| 77 |
setViewMode(QListView::IconMode); |
| 78 |
setSpacing(ITEM_SPACING); |
| 79 |
setDragEnabled(false); |
| 80 |
//按照像素滚动,步进20 |
| 81 |
setVerticalScrollMode(QListView::ScrollPerPixel); |
| 82 |
verticalScrollBar()->setSingleStep(20); |
| 83 |
|
| 84 |
setContextMenuPolicy(Qt::CustomContextMenu); |
| 85 |
setEditTriggers(QAbstractItemView::NoEditTriggers); |
| 86 |
setSelectionMode(QAbstractItemView::ExtendedSelection); |
| 87 |
setMinimumWidth(500); |
| 88 |
m_delegate = new ThumbnailDelegate(type, this); //绑在this上面,用于自动销毁 |
| 89 |
m_delegate->m_imageTypeStr = m_imageType; |
| 90 |
setItemDelegate(m_delegate); |
| 91 |
setModel(m_model); |
| 92 |
m_pMenu = new DMenu(); |
| 93 |
// setViewportMargins(0, 0, 0, 0); |
| 94 |
initMenuAction(); |
| 95 |
initConnections(); |
| 96 |
installEventFilter(this); |
| 97 |
verticalScrollBar()->installEventFilter(this); |
| 98 |
|
| 99 |
updateEnableSelectionByMouseTimer = new QTimer(this); |
| 100 |
updateEnableSelectionByMouseTimer->setInterval(500); |
| 101 |
connect(updateEnableSelectionByMouseTimer, &QTimer::timeout, [ = ]() { |
| 102 |
if (touchStatus == 0) { //时间到了还在等待模式,则进入框选模式 |
| 103 |
touchStatus = 2; |
| 104 |
} |
| 105 |
updateEnableSelectionByMouseTimer->stop(); |
| 106 |
}); |
| 107 |
|
| 108 |
m_scrollTimer = new QTimer(this); |
| 109 |
m_scrollTimer->setInterval(100); |
| 110 |
m_scrollTimer->setSingleShot(true); |
| 111 |
connect(m_scrollTimer, &QTimer::timeout, this, &ThumbnailListView::onScrollTimerOut); |
| 112 |
} |
| 113 |
|
| 114 |
ThumbnailListView::~ThumbnailListView() |
| 115 |
{ |
| 116 |
if (m_loadTimer) { |
| 117 |
if (m_loadTimer->isActive()) |
| 118 |
m_loadTimer->stop(); |
| 119 |
m_loadTimer->deleteLater(); |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
static QString myMimeType() |
| 124 |
{ |
| 125 |
return QStringLiteral("TestListView/text-icon-icon_hover"); |
| 126 |
} |
| 127 |
|
| 128 |
void ThumbnailListView::mousePressEvent(QMouseEvent *event) |
| 129 |
{ |
| 130 |
//点击时将焦点设置到当前 |
| 131 |
setFocus(); |
| 132 |
//复位激活click |
| 133 |
activeClick = true; |
| 134 |
// 当事件source为MouseEventSynthesizedByQt,认为此事件为TouchBegin转换而来 |
| 135 |
if (event->source() == Qt::MouseEventSynthesizedByQt) { |
| 136 |
lastTouchBeginPos = event->pos(); |
| 137 |
|
| 138 |
// 清空触屏滚动操作,因为在鼠标按下时还不知道即将进行的是触屏滚动还是文件框选 |
| 139 |
if (QScroller::hasScroller(this)) { |
| 140 |
// 不可使用 ungrab,会导致应用崩溃,或许是Qt的bug |
| 141 |
QScroller::scroller(this)->deleteLater(); |
| 142 |
} |
| 143 |
|
| 144 |
updateEnableSelectionByMouseTimer->start(); |
| 145 |
} |
| 146 |
|
| 147 |
if ((QApplication::keyboardModifiers() == Qt::ShiftModifier && event->button() == Qt::LeftButton)) { |
| 148 |
// 最近删除界面单指循环选中、取消选中 |
| 149 |
if (selectionModel()->selectedIndexes().contains(this->indexAt(event->pos())) |
| 150 |
&& selectionModel()->selectedIndexes().size() == 1 && m_imageType == COMMON_STR_TRASH) { |
| 151 |
if (event->button() != Qt::MouseButton::RightButton) { // 优化最近删除界面,长按时不清除选中 |
| 152 |
clearSelection(); |
| 153 |
} |
| 154 |
} |
| 155 |
#ifdef tablet_PC |
| 156 |
else if (m_isSelectAllBtn && (m_imageType == COMMON_STR_VIEW_TIMELINE || m_imageType == COMMON_STR_RECENT_IMPORTED)) { |
| 157 |
QModelIndexList list = selectionModel()->selectedIndexes(); |
| 158 |
DListView::mousePressEvent(event); |
| 159 |
for (auto item : list) { |
| 160 |
selectionModel()->select(item, QItemSelectionModel::Select); |
| 161 |
} |
| 162 |
if (list.contains(this->indexAt(event->pos())) && event->button() != Qt::RightButton) { |
| 163 |
selectionModel()->select(this->indexAt(event->pos()), QItemSelectionModel::Deselect); |
| 164 |
} else { |
| 165 |
selectionModel()->select(this->indexAt(event->pos()), QItemSelectionModel::Select); |
| 166 |
} |
| 167 |
} |
| 168 |
#endif |
| 169 |
} |
| 170 |
QModelIndex index = this->indexAt(event->pos()); |
| 171 |
DBImgInfo info = index.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 172 |
if ((m_imageType != COMMON_STR_VIEW_TIMELINE) |
| 173 |
&& (m_delegatetype != ThumbnailDelegate::AllPicViewType) |
| 174 |
&& (m_imageType != COMMON_STR_TRASH) |
| 175 |
&& (m_imageType != ALBUM_PATHTYPE_BY_PHONE)) { |
| 176 |
if (info.itemType == ItemTypeImportTimeLineTitle) { |
| 177 |
//已导入时间线标题不可拖动 |
| 178 |
setDragEnabled(false); |
| 179 |
} else if (dragDropMode() != NoDragDrop) { |
| 180 |
setDragDropMode(DragDrop); |
| 181 |
} |
| 182 |
} else { |
| 183 |
setDragEnabled(false); |
| 184 |
} |
| 185 |
|
| 186 |
DListView::mousePressEvent(event); |
| 187 |
} |
| 188 |
|
| 189 |
void ThumbnailListView::mouseMoveEvent(QMouseEvent *event) |
| 190 |
{ |
| 191 |
if (touchStatus == 0) { |
| 192 |
QRectF rect(QPointF((lastTouchBeginPos.x() - 30), (lastTouchBeginPos.y() - 30)), |
| 193 |
QPointF((lastTouchBeginPos.x() + 30), (lastTouchBeginPos.y() + 30))); |
| 194 |
if (rect.contains(event->pos())) { |
| 195 |
return; |
| 196 |
} else { |
| 197 |
touchStatus = 1; |
| 198 |
activeClick = false; |
| 199 |
} |
| 200 |
} |
| 201 |
|
| 202 |
if (touchStatus == 1) { |
| 203 |
if (event->source() == Qt::MouseEventSynthesizedByQt) { |
| 204 |
//todo |
| 205 |
// emit sigNeedMoveScorll(-(event->pos() - lastTouchBeginPos).y()); |
| 206 |
} |
| 207 |
} |
| 208 |
|
| 209 |
emit sigMouseMove(); |
| 210 |
DListView::mouseMoveEvent(event); |
| 211 |
} |
| 212 |
|
| 213 |
void ThumbnailListView::startDrag(Qt::DropActions supportedActions) |
| 214 |
{ |
| 215 |
Q_UNUSED(supportedActions); |
| 216 |
QString text = "xxxxxxxxxxxxxx"; |
| 217 |
QIcon icon = QIcon(":/resources/images/other/deepin-album.svg"); |
| 218 |
QIcon icon_hover = QIcon(":/resources/images/other/deepin-album.svg"); |
| 219 |
QByteArray itemData; |
| 220 |
QDataStream dataStream(&itemData, QIODevice::WriteOnly); |
| 221 |
dataStream << text << icon << icon_hover; |
| 222 |
QMimeData *mimeData = new QMimeData; |
| 223 |
mimeData->setData(myMimeType(), itemData); |
| 224 |
QDrag *pDrag = new QDrag(this); |
| 225 |
QPixmap p = QPixmap(":/resources/images/other/deepin-album.svg"); |
| 226 |
pDrag->setMimeData(mimeData); |
| 227 |
pDrag->setPixmap(p); |
| 228 |
pDrag->exec(Qt::MoveAction); |
| 229 |
} |
| 230 |
|
| 231 |
void ThumbnailListView::showEvent(QShowEvent *event) |
| 232 |
{ |
| 233 |
qDebug() << __FUNCTION__ << "---"; |
| 234 |
Q_UNUSED(event); |
| 235 |
//时间线使用 |
| 236 |
emit sigShowEvent(); |
| 237 |
int i_totalwidth = width() - 30; |
| 238 |
//计算一行的个数 |
| 239 |
m_rowSizeHint = i_totalwidth / (m_iBaseHeight + ITEM_SPACING); |
| 240 |
m_onePicWidth = (i_totalwidth - ITEM_SPACING * (m_rowSizeHint - 1)) / m_rowSizeHint;//一张图的宽度 |
| 241 |
} |
| 242 |
|
| 243 |
void ThumbnailListView::wheelEvent(QWheelEvent *event) |
| 244 |
{ |
| 245 |
if (event->delta() < 0) { |
| 246 |
//向下滑时才可执行 |
| 247 |
m_animationEnable = false; |
| 248 |
} else { |
| 249 |
m_animationEnable = true; |
| 250 |
} |
| 251 |
DListView::wheelEvent(event); |
| 252 |
} |
| 253 |
|
| 254 |
QRect ThumbnailListView::visualRect(const QModelIndex &index) const |
| 255 |
{ |
| 256 |
//获取当前视图中的item项,找到视图中的index,注意:获取到的index可能不是最大值,但已经足够了 |
| 257 |
ImageDataService::instance()->setVisualIndex(index.row()); |
| 258 |
return QListView::visualRect(index); |
| 259 |
} |
| 260 |
|
| 261 |
void ThumbnailListView::sltReloadAfterFilterEnd() |
| 262 |
{ |
| 263 |
if (m_delegatetype != ThumbnailDelegate::AllPicViewType) { |
| 264 |
return; |
| 265 |
} |
| 266 |
for (int i = (m_model->rowCount() - 1); i >= 0; i--) { |
| 267 |
QModelIndex index = m_model->index(i, 0); |
| 268 |
DBImgInfo data = index.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 269 |
if (!ImageEngineApi::instance()->isItemLoadedFromDB(data.filePath) |
| 270 |
&& (data.itemType == ItemTypePic || data.itemType == ItemTypeVideo)) { |
| 271 |
m_model->removeRow(index.row()); |
| 272 |
} |
| 273 |
} |
| 274 |
//m_model->rowCount()减一是为了减去顶部空白栏占用的一个ModelIndex |
| 275 |
for (int j = (m_model->rowCount() - 1); j < ImageEngineApi::instance()->m_AllImageDataVector.size(); j++) { |
| 276 |
insertThumbnail(ImageEngineApi::instance()->m_AllImageDataVector.at(j)); |
| 277 |
} |
| 278 |
//加载完后通知所有图片页刷新状态栏显示数量 |
| 279 |
emit sigUpdatePicNum(); |
| 280 |
} |
| 281 |
|
| 282 |
void ThumbnailListView::onUpdateListview() |
| 283 |
{ |
| 284 |
if (this->isVisible()) { |
| 285 |
this->update(); |
| 286 |
} |
| 287 |
} |
| 288 |
|
| 289 |
void ThumbnailListView::onLoadTimerTimeout() |
| 290 |
{ |
| 291 |
// qDebug() << __FUNCTION__ << "---allImageCount = " << ImageDataService::instance()->getCount(); |
| 292 |
//获取一个有效的model index; |
| 293 |
// QModelIndex load; |
| 294 |
// int row = ImageDataService::instance()->getVisualIndex(); |
| 295 |
// if (row <= m_model->rowCount()) |
| 296 |
// { |
| 297 |
// load = m_model->index(row, 0); |
| 298 |
// } |
| 299 |
if (!this->isVisible()) { |
| 300 |
return; |
| 301 |
} |
| 302 |
QModelIndex load = indexAt(QPoint(100, 100)); |
| 303 |
if (!load.isValid()) { |
| 304 |
load = indexAt(QPoint(120, 130)); |
| 305 |
} |
| 306 |
if (!load.isValid()) { |
| 307 |
return; |
| 308 |
} |
| 309 |
|
| 310 |
QStringList pathlist; |
| 311 |
int count = 0; |
| 312 |
for (int i = load.row(); i >= 0; i--) { |
| 313 |
QModelIndex index = m_model->index(i, 0); |
| 314 |
DBImgInfo data = index.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 315 |
pathlist << data.filePath; |
| 316 |
count++; |
| 317 |
if (count >= 300) { |
| 318 |
break; |
| 319 |
} |
| 320 |
} |
| 321 |
count = 0; |
| 322 |
for (int i = load.row(); i < m_model->rowCount(); i++) { |
| 323 |
QModelIndex index = m_model->index(i, 0); |
| 324 |
DBImgInfo data = index.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 325 |
pathlist << data.filePath; |
| 326 |
count++; |
| 327 |
if (count >= 300) { |
| 328 |
break; |
| 329 |
} |
| 330 |
} |
| 331 |
ImageDataService::instance()->readThumbnailByPaths(pathlist, true); |
| 332 |
this->update(); |
| 333 |
} |
| 334 |
|
| 335 |
void ThumbnailListView::mouseReleaseEvent(QMouseEvent *event) |
| 336 |
{ |
| 337 |
//触屏状态复位 |
| 338 |
touchStatus = 0; |
| 339 |
updateEnableSelectionByMouseTimer->stop(); |
| 340 |
m_animationEnable = false; |
| 341 |
|
| 342 |
if (COMMON_STR_RECENT_IMPORTED == m_imageType) { |
| 343 |
if (QApplication::keyboardModifiers() == Qt::NoModifier) { |
| 344 |
emit sigMouseRelease(); |
| 345 |
} |
| 346 |
} else { |
| 347 |
emit sigMouseRelease(); |
| 348 |
} |
| 349 |
|
| 350 |
DListView::mouseReleaseEvent(event); |
| 351 |
updatetimeLimeBtnText(); |
| 352 |
} |
| 353 |
|
| 354 |
void ThumbnailListView::keyPressEvent(QKeyEvent *event) |
| 355 |
{ |
| 356 |
DListView::keyPressEvent(event); |
| 357 |
if ((event->modifiers() == Qt::ControlModifier) && (event->key() == Qt::Key_A)) { |
| 358 |
TimeLineSelectAllBtn(); |
| 359 |
emit sigSelectAll(); |
| 360 |
} |
| 361 |
m_dragItemPath = selectedPaths(); |
| 362 |
if (event->key() == Qt::Key_Period) { |
| 363 |
if (m_dragItemPath.empty()) { |
| 364 |
return; |
| 365 |
} |
| 366 |
if (!DBManager::instance()->isImgExistInAlbum(COMMON_STR_FAVORITES, m_dragItemPath.first(), AlbumDBType::Favourite)) { |
| 367 |
DBManager::instance()->insertIntoAlbum(COMMON_STR_FAVORITES, QStringList(m_dragItemPath.first()), AlbumDBType::Favourite); |
| 368 |
emit dApp->signalM->insertedIntoAlbum(COMMON_STR_FAVORITES, QStringList(m_dragItemPath.first())); |
| 369 |
} else { |
| 370 |
DBManager::instance()->removeFromAlbum(COMMON_STR_FAVORITES, QStringList(m_dragItemPath.first()), AlbumDBType::Favourite); |
| 371 |
} |
| 372 |
} |
| 373 |
} |
| 374 |
|
| 375 |
void ThumbnailListView::dragEnterEvent(QDragEnterEvent *event) |
| 376 |
{ |
| 377 |
if (event->mimeData()->hasFormat(myMimeType())) { |
| 378 |
if (event->source() == this) { |
| 379 |
event->setDropAction(Qt::MoveAction); |
| 380 |
event->accept(); |
| 381 |
} else { |
| 382 |
if (!utils::base::checkMimeUrls(event->mimeData()->urls())) { |
| 383 |
return; |
| 384 |
} |
| 385 |
event->acceptProposedAction(); |
| 386 |
} |
| 387 |
} else { |
| 388 |
event->ignore(); |
| 389 |
} |
| 390 |
} |
| 391 |
|
| 392 |
void ThumbnailListView::dragMoveEvent(QDragMoveEvent *event) |
| 393 |
{ |
| 394 |
if (event->mimeData()->hasFormat(myMimeType())) { |
| 395 |
if (event->source() == this) { |
| 396 |
event->setDropAction(Qt::MoveAction); |
| 397 |
event->accept(); |
| 398 |
} else { |
| 399 |
if (!utils::base::checkMimeUrls(event->mimeData()->urls())) { |
| 400 |
return; |
| 401 |
} |
| 402 |
event->acceptProposedAction(); |
| 403 |
} |
| 404 |
} else { |
| 405 |
event->ignore(); |
| 406 |
} |
| 407 |
} |
| 408 |
|
| 409 |
void ThumbnailListView::dragLeaveEvent(QDragLeaveEvent *event) |
| 410 |
{ |
| 411 |
m_dragItemPath = selectedPaths(); |
| 412 |
DListView::dragLeaveEvent(event); |
| 413 |
} |
| 414 |
|
| 415 |
void ThumbnailListView::dropEvent(QDropEvent *event) |
| 416 |
{ |
| 417 |
if (event->mimeData()->hasFormat("TestListView/text-icon-icon_hover")) |
| 418 |
return; |
| 419 |
DListView::dropEvent(event); |
| 420 |
} |
| 421 |
|
| 422 |
void ThumbnailListView::initConnections() |
| 423 |
{ |
| 424 |
connect(ImageEngineApi::instance(), &ImageEngineApi::sigLoadCompleted, this, &ThumbnailListView::reloadImage); |
| 425 |
connect(ImageDataService::instance(), &ImageDataService::sigeUpdateListview, this, &ThumbnailListView::onUpdateListview); |
| 426 |
connect(dApp->signalM, &SignalManager::sigSyncListviewModelData, this, &ThumbnailListView::onSyncListviewModelData); |
| 427 |
//有图片删除后,刷新列表 |
| 428 |
connect(dApp->signalM, &SignalManager::imagesRemovedPar, this, &ThumbnailListView::updateThumbnailViewAfterDelete); |
| 429 |
connect(this->verticalScrollBar(), &QScrollBar::valueChanged, this, &ThumbnailListView::onScrollbarValueChanged); |
| 430 |
connect(this, &QListView::customContextMenuRequested, this, &ThumbnailListView::onShowMenu); |
| 431 |
connect(m_pMenu, &DMenu::triggered, this, &ThumbnailListView::onMenuItemClicked); |
| 432 |
connect(this, &ThumbnailListView::doubleClicked, this, &ThumbnailListView::onDoubleClicked); |
| 433 |
connect(this, &ThumbnailListView::clicked, this, &ThumbnailListView::onClicked); |
| 434 |
connect(dApp->signalM, &SignalManager::sigMainwindowSliderValueChg, this, &ThumbnailListView::onPixMapScale); |
| 435 |
connect(m_delegate, &ThumbnailDelegate::sigCancelFavorite, this, &ThumbnailListView::onCancelFavorite); |
| 436 |
|
| 437 |
connect(ImageEngineApi::instance(), &ImageEngineApi::sigOneImgReady, this, &ThumbnailListView::slotOneImgReady); |
| 438 |
connect(ImageEngineApi::instance(), &ImageEngineApi::sigReloadAfterFilterEnd, |
| 439 |
this, &ThumbnailListView::sltReloadAfterFilterEnd); |
| 440 |
} |
| 441 |
|
| 442 |
void ThumbnailListView::insertThumbnail(const DBImgInfo &dBImgInfo) |
| 443 |
{ |
| 444 |
DBImgInfo info = dBImgInfo; |
| 445 |
cutPixmap(info); |
| 446 |
|
| 447 |
QStandardItem *item = new QStandardItem; |
| 448 |
QVariant infoVariant; |
| 449 |
int height = info.imgHeight; |
| 450 |
if (info.itemType == ItemType::ItemTypeBlank |
| 451 |
|| info.itemType == ItemType::ItemTypeTimeLineTitle |
| 452 |
|| info.itemType == ItemType::ItemTypeImportTimeLineTitle) { |
| 453 |
info.imgWidth = this->width() - 5; |
| 454 |
} |
| 455 |
infoVariant.setValue(info); |
| 456 |
item->setData(infoVariant, Qt::DisplayRole); |
| 457 |
QStringList albumNames = ImageEngineApi::instance()->getImgPathAndAlbumNames().values(info.filePath); |
| 458 |
item->setData(QVariant(albumNames), Qt::UserRole + 2); |
| 459 |
item->setData(QVariant(QSize(info.imgWidth, /*gridItem[i][j].height*/height)), |
| 460 |
Qt::SizeHintRole); |
| 461 |
m_model->appendRow(item); |
| 462 |
if (info.itemType == ItemTypeTimeLineTitle) { |
| 463 |
QModelIndex index = m_model->indexFromItem(item); |
| 464 |
TimeLineDateWidget *pCurrentDateWidget = new TimeLineDateWidget(item, info.date, info.num); |
| 465 |
connect(pCurrentDateWidget, &TimeLineDateWidget::sigIsSelectCurrentDatePic, this, &ThumbnailListView::slotSelectCurrentDatePic); |
| 466 |
this->setIndexWidget(index, pCurrentDateWidget); |
| 467 |
} else if (info.itemType == ItemTypeImportTimeLineTitle) { |
| 468 |
QModelIndex index = m_model->indexFromItem(item); |
| 469 |
importTimeLineDateWidget *pCurrentDateWidget = new importTimeLineDateWidget(item, info.date, info.num); |
| 470 |
connect(pCurrentDateWidget, &importTimeLineDateWidget::sigIsSelectCurrentDatePic, this, &ThumbnailListView::slotSelectCurrentDatePic); |
| 471 |
this->setIndexWidget(index, pCurrentDateWidget); |
| 472 |
} |
| 473 |
} |
| 474 |
|
| 475 |
void ThumbnailListView::stopLoadAndClear(bool bClearModel) |
| 476 |
{ |
| 477 |
if (bClearModel) |
| 478 |
m_model->clear(); //清除模型中的数据 |
| 479 |
m_allfileslist.clear(); |
| 480 |
} |
| 481 |
//根据显示类型,返回不同列表,如所有照片返回所有,时间线返回当前时间下内容 |
| 482 |
QStringList ThumbnailListView::getFileList(int row) |
| 483 |
{ |
| 484 |
m_allfileslist.clear(); |
| 485 |
if (m_delegatetype == ThumbnailDelegate::AllPicViewType |
| 486 |
|| m_delegatetype == ThumbnailDelegate::AlbumViewCustomType |
| 487 |
|| m_delegatetype == ThumbnailDelegate::AlbumViewFavoriteType |
| 488 |
|| m_delegatetype == ThumbnailDelegate::SearchViewType |
| 489 |
|| m_delegatetype == ThumbnailDelegate::AlbumViewPhoneType) { |
| 490 |
//遍历所有数据 |
| 491 |
for (int i = 0; i < m_model->rowCount(); i++) { |
| 492 |
QModelIndex index = m_model->index(i, 0); |
| 493 |
DBImgInfo data = index.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 494 |
if (data.itemType == ItemType::ItemTypePic || data.itemType == ItemType::ItemTypeVideo) { |
| 495 |
m_allfileslist.append(data.filePath); |
| 496 |
} |
| 497 |
} |
| 498 |
} else if (m_delegatetype == ThumbnailDelegate::TimeLineViewType |
| 499 |
|| m_delegatetype == ThumbnailDelegate::AlbumViewImportTimeLineViewType) { |
| 500 |
//找到当前项前面最近的一个标题 |
| 501 |
QModelIndex titleIndex; |
| 502 |
for (int i = row; i >= 0; i--) { |
| 503 |
QModelIndex itemIndex = m_model->index(i, 0); |
| 504 |
DBImgInfo data = itemIndex.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 505 |
if (data.itemType == ItemTypeTimeLineTitle |
| 506 |
|| data.itemType == ItemTypeImportTimeLineTitle |
| 507 |
|| data.itemType == ItemTypeBlank) { |
| 508 |
titleIndex = itemIndex; |
| 509 |
break; |
| 510 |
} |
| 511 |
} |
| 512 |
int index = titleIndex.row() + 1; |
| 513 |
//根据找到的标题,遍历当前时间下所有数据 |
| 514 |
for (; index < m_model->rowCount(); index++) { |
| 515 |
QModelIndex itemIndex = m_model->index(index, 0); |
| 516 |
DBImgInfo data = itemIndex.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 517 |
if (data.itemType == ItemTypeTimeLineTitle |
| 518 |
|| data.itemType == ItemTypeImportTimeLineTitle) { |
| 519 |
break; |
| 520 |
} else { |
| 521 |
if (!data.filePath.isEmpty()) { |
| 522 |
m_allfileslist.append(data.filePath); |
| 523 |
} |
| 524 |
} |
| 525 |
} |
| 526 |
} |
| 527 |
return m_allfileslist; |
| 528 |
} |
| 529 |
|
| 530 |
QList<DBImgInfo> ThumbnailListView::getAllFileInfo(int row) |
| 531 |
{ |
| 532 |
QList<DBImgInfo> DBImgInfos; |
| 533 |
if (m_delegatetype == ThumbnailDelegate::AllPicViewType |
| 534 |
|| m_delegatetype == ThumbnailDelegate::AlbumViewCustomType |
| 535 |
|| m_delegatetype == ThumbnailDelegate::AlbumViewFavoriteType |
| 536 |
|| m_delegatetype == ThumbnailDelegate::SearchViewType) { |
| 537 |
for (int i = 0; i < m_model->rowCount(); i++) { |
| 538 |
QModelIndex index = m_model->index(i, 0); |
| 539 |
DBImgInfo data = index.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 540 |
if (data.itemType == ItemType::ItemTypePic) { |
| 541 |
DBImgInfos.append(data); |
| 542 |
} |
| 543 |
} |
| 544 |
} else if (m_delegatetype == ThumbnailDelegate::TimeLineViewType |
| 545 |
|| m_delegatetype == ThumbnailDelegate::AlbumViewImportTimeLineViewType) { |
| 546 |
//找到当前项前面最近的一个标题 |
| 547 |
QModelIndex titleIndex; |
| 548 |
for (int i = row; i >= 0; i--) { |
| 549 |
QModelIndex itemIndex = m_model->index(i, 0); |
| 550 |
DBImgInfo data = itemIndex.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 551 |
if (data.itemType == ItemTypeTimeLineTitle |
| 552 |
|| data.itemType == ItemTypeImportTimeLineTitle |
| 553 |
|| data.itemType == ItemTypeBlank) { |
| 554 |
titleIndex = itemIndex; |
| 555 |
break; |
| 556 |
} |
| 557 |
} |
| 558 |
int index = titleIndex.row() + 1; |
| 559 |
//根据找到的标题,遍历当前时间下所有数据 |
| 560 |
for (; index < m_model->rowCount(); index++) { |
| 561 |
QModelIndex itemIndex = m_model->index(index, 0); |
| 562 |
DBImgInfo data = itemIndex.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 563 |
if (data.itemType == ItemTypeTimeLineTitle |
| 564 |
|| data.itemType == ItemTypeImportTimeLineTitle) { |
| 565 |
break; |
| 566 |
} else { |
| 567 |
DBImgInfos.append(data); |
| 568 |
} |
| 569 |
} |
| 570 |
} |
| 571 |
return DBImgInfos; |
| 572 |
} |
| 573 |
|
| 574 |
int ThumbnailListView::getRow(const QString &path) |
| 575 |
{ |
| 576 |
int row = -1; |
| 577 |
for (int i = 0; i < m_model->rowCount(); i++) { |
| 578 |
QModelIndex index = m_model->index(i, 0); |
| 579 |
DBImgInfo data = index.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 580 |
if (data.itemType == ItemType::ItemTypePic) { |
| 581 |
if (data.filePath == path) { |
| 582 |
row = i; |
| 583 |
} |
| 584 |
} |
| 585 |
} |
| 586 |
return row; |
| 587 |
} |
| 588 |
|
| 589 |
void ThumbnailListView::onShowMenu(const QPoint &pos) |
| 590 |
{ |
| 591 |
//外接设备显示照片时,禁用鼠标右键菜单 |
| 592 |
QModelIndex index = this->indexAt(pos); |
| 593 |
if (!index.isValid() || ALBUM_PATHTYPE_BY_PHONE == m_imageType) { |
| 594 |
return; |
| 595 |
} |
| 596 |
//标题项和空白项不显示右键菜单 |
| 597 |
DBImgInfo info = index.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 598 |
if (info.itemType == ItemTypeBlank |
| 599 |
|| info.itemType == ItemTypeTimeLineTitle |
| 600 |
|| info.itemType == ItemTypeImportTimeLineTitle) { |
| 601 |
return; |
| 602 |
} |
| 603 |
#ifdef tablet_PC |
| 604 |
//区分最近删除界面和其他界面 |
| 605 |
if (this->m_imageType == COMMON_STR_TRASH) { |
| 606 |
return; |
| 607 |
} else { |
| 608 |
emit sigMouseRelease(); |
| 609 |
updateMenuContents(); |
| 610 |
m_pMenu->popup(QCursor::pos()); |
| 611 |
} |
| 612 |
#else |
| 613 |
emit sigMouseRelease(); |
| 614 |
updateMenuContents(); |
| 615 |
m_pMenu->popup(QCursor::pos()); |
| 616 |
#endif |
| 617 |
} |
| 618 |
|
| 619 |
void ThumbnailListView::updateMenuContents() |
| 620 |
{ |
| 621 |
QStringList paths = selectedPaths(); |
| 622 |
if (paths.empty()) { |
| 623 |
return; |
| 624 |
} |
| 625 |
#ifndef tablet_PC |
| 626 |
if (m_imageType.compare(COMMON_STR_TRASH) == 0) { |
| 627 |
if (1 == paths.length()) { |
| 628 |
DBImgInfo data = selectedIndexes().at(0).data(Qt::DisplayRole).value<DBImgInfo>(); |
| 629 |
if (data.itemType == ItemTypePic) { |
| 630 |
m_MenuActionMap.value(tr("Photo info"))->setVisible(true); |
| 631 |
m_MenuActionMap.value(tr("Video info"))->setVisible(false); |
| 632 |
} else { |
| 633 |
m_MenuActionMap.value(tr("Photo info"))->setVisible(false); |
| 634 |
m_MenuActionMap.value(tr("Video info"))->setVisible(true); |
| 635 |
} |
| 636 |
} else { |
| 637 |
m_MenuActionMap.value(tr("Photo info"))->setVisible(false); |
| 638 |
m_MenuActionMap.value(tr("Video info"))->setVisible(false); |
| 639 |
} |
| 640 |
return; |
| 641 |
} |
| 642 |
#endif |
| 643 |
for (QAction *action : m_MenuActionMap.values()) { |
| 644 |
action->setVisible(true); |
| 645 |
action->setEnabled(true); |
| 646 |
} |
| 647 |
//源文件不存在时的菜单 |
| 648 |
if ((1 == paths.length()) && (!QFileInfo(paths[0]).exists()) && (COMMON_STR_TRASH != m_imageType)) { |
| 649 |
#ifndef tablet_PC |
| 650 |
m_MenuActionMap.value(tr("View"))->setEnabled(true); |
| 651 |
m_MenuActionMap.value(tr("Fullscreen"))->setEnabled(false); |
| 652 |
m_MenuActionMap.value(tr("Slide show"))->setEnabled(false); |
| 653 |
m_MenuActionMap.value(tr("Export"))->setEnabled(false); |
| 654 |
m_albumMenu->deleteLater(); |
| 655 |
m_albumMenu = createAlbumMenu(); |
| 656 |
if (m_albumMenu) { |
| 657 |
QAction *action = m_MenuActionMap.value(tr("Export")); |
| 658 |
action->setEnabled(false); |
| 659 |
m_albumMenu->setEnabled(false); |
| 660 |
m_pMenu->insertMenu(action, m_albumMenu); |
| 661 |
} |
| 662 |
m_MenuActionMap.value(tr("Copy"))->setEnabled(false); |
| 663 |
#endif |
| 664 |
m_MenuActionMap.value(tr("Delete"))->setEnabled(true); |
| 665 |
m_MenuActionMap.value(tr("Remove from album"))->setVisible(false); |
| 666 |
#ifndef tablet_PC |
| 667 |
m_MenuActionMap.value(tr("Print"))->setVisible(false); |
| 668 |
#endif |
| 669 |
if (DBManager::instance()->isImgExistInAlbum(COMMON_STR_FAVORITES, paths[0], AlbumDBType::Favourite)) { |
| 670 |
m_MenuActionMap.value(tr("Favorite"))->setVisible(false); |
| 671 |
m_MenuActionMap.value(tr("Unfavorite"))->setEnabled(false); |
| 672 |
} else { |
| 673 |
m_MenuActionMap.value(tr("Unfavorite"))->setVisible(false); |
| 674 |
m_MenuActionMap.value(tr("Favorite"))->setEnabled(false); |
| 675 |
} |
| 676 |
#ifndef tablet_PC |
| 677 |
m_MenuActionMap.value(tr("Rotate clockwise"))->setEnabled(false); |
| 678 |
m_MenuActionMap.value(tr("Rotate counterclockwise"))->setEnabled(false); |
| 679 |
m_MenuActionMap.value(tr("Display in file manager"))->setEnabled(false); |
| 680 |
m_MenuActionMap.value(tr("Photo info"))->setEnabled(false); |
| 681 |
m_MenuActionMap.value(tr("Video info"))->setVisible(false); |
| 682 |
m_MenuActionMap.value(tr("Set as wallpaper"))->setEnabled(false); |
| 683 |
#endif |
| 684 |
return; |
| 685 |
} |
| 686 |
#ifndef tablet_PC |
| 687 |
if (1 != paths.length()) { |
| 688 |
m_MenuActionMap.value(tr("View"))->setVisible(false); |
| 689 |
m_MenuActionMap.value(tr("Fullscreen"))->setVisible(false); |
| 690 |
} |
| 691 |
#endif |
| 692 |
if (COMMON_STR_TRASH == m_imageType) { |
| 693 |
m_MenuActionMap.value(tr("Delete"))->setVisible(false); |
| 694 |
} else { |
| 695 |
if (m_albumMenu) |
| 696 |
m_albumMenu->deleteLater(); |
| 697 |
m_albumMenu = createAlbumMenu(); |
| 698 |
if (m_albumMenu) { |
| 699 |
#ifndef tablet_PC |
| 700 |
QAction *action = m_MenuActionMap.value(tr("Export")); |
| 701 |
#else |
| 702 |
QAction *action = m_MenuActionMap.value(tr("Delete")); |
| 703 |
#endif |
| 704 |
m_pMenu->insertMenu(action, m_albumMenu); |
| 705 |
} |
| 706 |
} |
| 707 |
//非最近删除的单选 |
| 708 |
if (1 == paths.length() && COMMON_STR_TRASH != m_imageType) { |
| 709 |
if (DBManager::instance()->isImgExistInAlbum(COMMON_STR_FAVORITES, paths[0], AlbumDBType::Favourite)) { |
| 710 |
m_MenuActionMap.value(tr("Favorite"))->setVisible(false); |
| 711 |
} else { |
| 712 |
m_MenuActionMap.value(tr("Unfavorite"))->setVisible(false); |
| 713 |
} |
| 714 |
m_pMenu->addSeparator(); |
| 715 |
} else { |
| 716 |
m_MenuActionMap.value(tr("Unfavorite"))->setVisible(false); |
| 717 |
m_MenuActionMap.value(tr("Favorite"))->setVisible(false); |
| 718 |
} |
| 719 |
//非自定义相册,隐藏从相册中移除菜单 |
| 720 |
if (m_delegatetype != ThumbnailDelegate::AlbumViewCustomType) { |
| 721 |
m_MenuActionMap.value(tr("Remove from album"))->setVisible(false); |
| 722 |
} |
| 723 |
#ifndef tablet_PC |
| 724 |
bool bflag_imageSupportSave = false; //图片是否可以保存标志 |
| 725 |
if (1 == paths.length()) { //单张照片 |
| 726 |
if (UnionImage_NameSpace::isImageSupportRotate(paths[0])) |
| 727 |
bflag_imageSupportSave = true; |
| 728 |
} |
| 729 |
if (bflag_imageSupportSave) { |
| 730 |
int flag_isRW = 0; |
| 731 |
if (1 == paths.length()) { |
| 732 |
if (QFileInfo(paths[0]).isReadable() && !QFileInfo(paths[0]).isWritable()) { |
| 733 |
flag_isRW = 1; |
| 734 |
} |
| 735 |
} |
| 736 |
if (flag_isRW == 1) { |
| 737 |
m_MenuActionMap.value(tr("Rotate clockwise"))->setDisabled(true); |
| 738 |
m_MenuActionMap.value(tr("Rotate counterclockwise"))->setDisabled(true); |
| 739 |
} else { |
| 740 |
m_MenuActionMap.value(tr("Rotate clockwise"))->setDisabled(false); |
| 741 |
m_MenuActionMap.value(tr("Rotate counterclockwise"))->setDisabled(false); |
| 742 |
} |
| 743 |
} else { |
| 744 |
m_MenuActionMap.value(tr("Rotate clockwise"))->setVisible(false); |
| 745 |
m_MenuActionMap.value(tr("Rotate counterclockwise"))->setVisible(false); |
| 746 |
} |
| 747 |
if (1 == paths.length()) { |
| 748 |
DBImgInfo data = selectedIndexes().at(0).data(Qt::DisplayRole).value<DBImgInfo>(); |
| 749 |
if (data.itemType == ItemTypePic) { |
| 750 |
m_MenuActionMap.value(tr("Photo info"))->setVisible(true); |
| 751 |
m_MenuActionMap.value(tr("Video info"))->setVisible(false); |
| 752 |
m_MenuActionMap.value(tr("Fullscreen"))->setVisible(true); |
| 753 |
m_MenuActionMap.value(tr("Rotate clockwise"))->setVisible(true); |
| 754 |
m_MenuActionMap.value(tr("Rotate counterclockwise"))->setVisible(true); |
| 755 |
} else { |
| 756 |
m_MenuActionMap.value(tr("Video info"))->setVisible(true); |
| 757 |
m_MenuActionMap.value(tr("Print"))->setVisible(false); |
| 758 |
m_MenuActionMap.value(tr("Slide show"))->setVisible(false); |
| 759 |
m_MenuActionMap.value(tr("Export"))->setVisible(false); |
| 760 |
m_MenuActionMap.value(tr("Photo info"))->setVisible(false); |
| 761 |
m_MenuActionMap.value(tr("Fullscreen"))->setVisible(false); |
| 762 |
m_MenuActionMap.value(tr("Rotate clockwise"))->setVisible(false); |
| 763 |
m_MenuActionMap.value(tr("Rotate counterclockwise"))->setVisible(false); |
| 764 |
m_MenuActionMap.value(tr("Set as wallpaper"))->setVisible(false); |
| 765 |
} |
| 766 |
} else { |
| 767 |
m_MenuActionMap.value(tr("Display in file manager"))->setVisible(false); |
| 768 |
m_MenuActionMap.value(tr("Photo info"))->setVisible(false); |
| 769 |
m_MenuActionMap.value(tr("Video info"))->setVisible(false); |
| 770 |
for (int i = 0; i < paths.length(); i++) { |
| 771 |
QString path = paths.at(i); |
| 772 |
if (utils::base::isVideo(path)) { |
| 773 |
m_MenuActionMap.value(tr("Print"))->setVisible(false); |
| 774 |
m_MenuActionMap.value(tr("Slide show"))->setVisible(false); |
| 775 |
m_MenuActionMap.value(tr("Export"))->setVisible(false); |
| 776 |
break; |
| 777 |
} |
| 778 |
} |
| 779 |
//有图片则可以显示幻灯片 |
| 780 |
for (int i = 0; i < paths.length(); i++) { |
| 781 |
QString path = paths.at(i); |
| 782 |
if (!utils::base::isVideo(path)) { |
| 783 |
m_MenuActionMap.value(tr("Slide show"))->setVisible(true); |
| 784 |
break; |
| 785 |
} |
| 786 |
} |
| 787 |
} |
| 788 |
|
| 789 |
if ((1 == paths.length() || QFileInfo(paths[0]).suffix().contains("gif"))) { |
| 790 |
DBImgInfo data = selectedIndexes().at(0).data(Qt::DisplayRole).value<DBImgInfo>(); |
| 791 |
if (data.itemType == ItemTypePic) { |
| 792 |
m_MenuActionMap.value(tr("Set as wallpaper"))->setVisible(true); |
| 793 |
} else { |
| 794 |
m_MenuActionMap.value(tr("Set as wallpaper"))->setVisible(false); |
| 795 |
} |
| 796 |
} else { |
| 797 |
m_MenuActionMap.value(tr("Set as wallpaper"))->setVisible(false); |
| 798 |
} |
| 799 |
#endif |
| 800 |
} |
| 801 |
|
| 802 |
void ThumbnailListView::appendAction(int id, const QString &text, const QString &shortcut) |
| 803 |
{ |
| 804 |
QAction *ac = new QAction(this); |
| 805 |
addAction(ac); |
| 806 |
ac->setText(text); |
| 807 |
ac->setProperty("MenuID", id); |
| 808 |
//如果是查看照片,需要响应Enter键,而Enter键有两个Key-Enter和Return |
| 809 |
if (text.compare(tr("View")) == 0) { |
| 810 |
QList<QKeySequence> shortcuts; |
| 811 |
shortcuts.append(QKeySequence(ENTER_SHORTCUT)); |
| 812 |
shortcuts.append(QKeySequence(RETURN_SHORTCUT)); |
| 813 |
ac->setShortcuts(shortcuts); |
| 814 |
} else { |
| 815 |
ac->setShortcut(QKeySequence(shortcut)); |
| 816 |
} |
| 817 |
ac->setShortcutContext(Qt::WidgetShortcut); |
| 818 |
m_MenuActionMap.insert(text, ac); |
| 819 |
m_pMenu->addAction(ac); |
| 820 |
} |
| 821 |
|
| 822 |
void ThumbnailListView::initMenuAction() |
| 823 |
{ |
| 824 |
m_pMenu->clear(); |
| 825 |
if (m_imageType.compare(COMMON_STR_TRASH) == 0) { |
| 826 |
appendAction(IdMoveToTrash, tr("Delete"), ss("")); |
| 827 |
appendAction(IdTrashRecovery, tr("Restore"), ss(BUTTON_RECOVERY)); |
| 828 |
appendAction(IdImageInfo, tr("Photo info"), ss(ImageInfo_CONTEXT_MENU)); |
| 829 |
appendAction(IdVideoInfo, tr("Video info"), ss(VideoInfo_CONTEXT_MENU)); |
| 830 |
return; |
| 831 |
} |
| 832 |
|
| 833 |
m_MenuActionMap.clear(); |
| 834 |
#ifndef tablet_PC |
| 835 |
appendAction(IdView, tr("View"), ss(VIEW_CONTEXT_MENU)); |
| 836 |
appendAction(IdFullScreen, tr("Fullscreen"), ss(FULLSCREEN_CONTEXT_MENU)); |
| 837 |
appendAction(IdPrint, tr("Print"), ss(PRINT_CONTEXT_MENU)); |
| 838 |
appendAction(IdStartSlideShow, tr("Slide show"), ss(SLIDESHOW_CONTEXT_MENU)); |
| 839 |
m_pMenu->addSeparator(); |
| 840 |
appendAction(IdExport, tr("Export"), ss(EXPORT_CONTEXT_MENU)); |
| 841 |
appendAction(IdCopyToClipboard, tr("Copy"), ss(COPYTOCLIPBOARD_CONTEXT_MENU)); |
| 842 |
#endif |
| 843 |
appendAction(IdMoveToTrash, tr("Delete"), ss("")); |
| 844 |
appendAction(IdRemoveFromAlbum, tr("Remove from album"), ss("")); |
| 845 |
|
| 846 |
m_pMenu->addSeparator(); |
| 847 |
appendAction(IdAddToFavorites, tr("Favorite"), ""); |
| 848 |
appendAction(IdRemoveFromFavorites, tr("Unfavorite"), ""); |
| 849 |
#ifndef tablet_PC |
| 850 |
m_pMenu->addSeparator(); |
| 851 |
appendAction(IdRotateClockwise, tr("Rotate clockwise"), ss(ROTATECLOCKWISE_CONTEXT_MENU)); |
| 852 |
appendAction(IdRotateCounterclockwise, tr("Rotate counterclockwise"), |
| 853 |
ss(ROTATECOUNTERCLOCKWISE_CONTEXT_MENU)); |
| 854 |
m_pMenu->addSeparator(); |
| 855 |
appendAction(IdSetAsWallpaper, tr("Set as wallpaper"), ss(SETASWALLPAPER_CONTEXT_MENU)); |
| 856 |
appendAction(IdDisplayInFileManager, tr("Display in file manager"), ss(DISPLAYINFILEMANAGER_CONTEXT_MENU)); |
| 857 |
appendAction(IdImageInfo, tr("Photo info"), ss(ImageInfo_CONTEXT_MENU)); |
| 858 |
appendAction(IdVideoInfo, tr("Video info"), ss(VideoInfo_CONTEXT_MENU)); |
| 859 |
#endif |
| 860 |
} |
| 861 |
|
| 862 |
DMenu *ThumbnailListView::createAlbumMenu() |
| 863 |
{ |
| 864 |
DMenu *am = new DMenu(tr("Add to album")); |
| 865 |
QStringList albums = DBManager::instance()->getAllAlbumNames(); |
| 866 |
QAction *ac1 = new QAction(am); |
| 867 |
ac1->setProperty("MenuID", IdAddToAlbum); |
| 868 |
ac1->setText(tr("New album")); |
| 869 |
ac1->setData("Add to new album"); |
| 870 |
am->addAction(ac1); |
| 871 |
am->addSeparator(); |
| 872 |
QModelIndexList indexList = selectionModel()->selectedIndexes(); |
| 873 |
QStringList albumNames; |
| 874 |
// 单选 |
| 875 |
if (indexList.count() == 1) { |
| 876 |
albumNames = indexList.first().model()->data(indexList.first(), Qt::UserRole + 2).toStringList(); |
| 877 |
} |
| 878 |
// 多选,以第一个作标准 |
| 879 |
else if (indexList.count() > 1) { |
| 880 |
albumNames = indexList.first().model()->data(indexList.first(), Qt::UserRole + 2).toStringList(); |
| 881 |
for (int idx = 1; idx < indexList.count(); idx++) { |
| 882 |
QStringList tempList = indexList.at(idx).model()->data(indexList.at(idx), Qt::UserRole + 2).toStringList(); |
| 883 |
for (int i = 0; i < albumNames.count(); i++) { |
| 884 |
// 不存在相册名 |
| 885 |
if (!tempList.contains(albumNames.at(i))) { |
| 886 |
albumNames.removeAll(albumNames.at(i)); |
| 887 |
break; |
| 888 |
} |
| 889 |
} |
| 890 |
} |
| 891 |
} |
| 892 |
for (QString album : albums) { |
| 893 |
QAction *ac = new QAction(am); |
| 894 |
ac->setProperty("MenuID", IdAddToAlbum); |
| 895 |
ac->setText( |
| 896 |
fontMetrics().elidedText(QString(album).replace("&", "&&"), Qt::ElideMiddle, 200)); |
| 897 |
ac->setData(album); |
| 898 |
am->addAction(ac); |
| 899 |
if (albumNames.contains(album)) { |
| 900 |
ac->setEnabled(false); |
| 901 |
} |
| 902 |
} |
| 903 |
return am; |
| 904 |
} |
| 905 |
|
| 906 |
void ThumbnailListView::onMenuItemClicked(QAction *action) |
| 907 |
{ |
| 908 |
QStringList paths = selectedPaths(); |
| 909 |
menuItemDeal(paths, action); |
| 910 |
} |
| 911 |
//获取选中路径 |
| 912 |
QStringList ThumbnailListView::selectedPaths() |
| 913 |
{ |
| 914 |
QStringList paths; |
| 915 |
for (QModelIndex index : selectionModel()->selectedIndexes()) { |
| 916 |
if (isRowHidden(index.row())) { |
| 917 |
continue; |
| 918 |
} |
| 919 |
DBImgInfo info = index.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 920 |
if ((info.itemType != ItemTypeBlank |
| 921 |
|| info.itemType != ItemTypeTimeLineTitle |
| 922 |
|| info.itemType != ItemTypeImportTimeLineTitle) |
| 923 |
&& !info.filePath.isEmpty()) { |
| 924 |
paths << info.filePath; |
| 925 |
} |
| 926 |
} |
| 927 |
return paths; |
| 928 |
} |
| 929 |
|
| 930 |
QStringList ThumbnailListView::getDagItemPath() |
| 931 |
{ |
| 932 |
return m_dragItemPath; |
| 933 |
} |
| 934 |
|
| 935 |
void ThumbnailListView::menuItemDeal(QStringList paths, QAction *action) |
| 936 |
{ |
| 937 |
paths.removeAll(QString("")); |
| 938 |
if (paths.isEmpty()) { |
| 939 |
return; |
| 940 |
} |
| 941 |
|
| 942 |
const QString path = paths.first(); |
| 943 |
const int id = action->property("MenuID").toInt(); |
| 944 |
switch (MenuItemId(id)) { |
| 945 |
case IdView: { |
| 946 |
//双击打开信号,enter打开信号 |
| 947 |
if (paths.size() > 1) { |
| 948 |
for (auto tmpPath : paths) { |
| 949 |
if (utils::base::isVideo(tmpPath)) { |
| 950 |
return;//选中数量大于1,只要包含视频即为混选或者多选视频,不作响应 |
| 951 |
} |
| 952 |
} |
| 953 |
} |
| 954 |
|
| 955 |
if (utils::base::isVideo(path)) { |
| 956 |
//更改打开方式,先默认影院,失败再选择 |
| 957 |
QProcess *process = new QProcess(this); |
| 958 |
QStringList arguments; |
| 959 |
arguments << path; |
| 960 |
bool isopen = process->startDetached("deepin-movie", arguments); |
| 961 |
if (!isopen) { |
| 962 |
arguments.clear(); |
| 963 |
arguments << "-o" << path; |
| 964 |
process->startDetached("dde-file-manager", arguments); |
| 965 |
} |
| 966 |
} else { |
| 967 |
emit openImage(this->currentIndex().row(), path, false); |
| 968 |
} |
| 969 |
} |
| 970 |
break; |
| 971 |
case IdFullScreen: |
| 972 |
emit openImage(this->currentIndex().row(), path, true); |
| 973 |
break; |
| 974 |
case IdPrint: |
| 975 |
PrintHelper::getIntance()->showPrintDialog(paths, this); |
| 976 |
break; |
| 977 |
case IdStartSlideShow: |
| 978 |
emit sigSlideShow(path); |
| 979 |
break; |
| 980 |
case IdAddToAlbum: { |
| 981 |
const QString album = action->data().toString(); |
| 982 |
if (album != "Add to new album") { |
| 983 |
if (1 == paths.count()) { |
| 984 |
if (!DBManager::instance()->isImgExistInAlbum(album, paths[0])) { |
| 985 |
emit dApp->signalM->sigAddToAlbToast(album); |
| 986 |
} |
| 987 |
} else { |
| 988 |
emit dApp->signalM->sigAddToAlbToast(album); |
| 989 |
} |
| 990 |
DBManager::instance()->insertIntoAlbum(album, paths); |
| 991 |
emit dApp->signalM->insertedIntoAlbum(album, paths); |
| 992 |
// 相册照片更新时的.更新路径相册名缓存,用于listview的setdata userrole + 2 |
| 993 |
ImageEngineApi::instance()->setImgPathAndAlbumNames(DBManager::instance()->getAllPathAlbumNames()); |
| 994 |
// 只更新部分,即将照片添加或者删除相册时 |
| 995 |
updateModelRoleData(album, IdAddToAlbum); |
| 996 |
|
| 997 |
} else { |
| 998 |
emit dApp->signalM->createAlbum(paths); |
| 999 |
} |
| 1000 |
break; |
| 1001 |
} |
| 1002 |
case IdCopyToClipboard: |
| 1003 |
utils::base::copyImageToClipboard(paths); |
| 1004 |
break; |
| 1005 |
case IdMoveToTrash: { |
| 1006 |
qDebug() << "---" << __FUNCTION__ << "---" << "IdMoveToTrash"; |
| 1007 |
this->removeSelectToTrash(paths); |
| 1008 |
} |
| 1009 |
break; |
| 1010 |
case IdAddToFavorites: |
| 1011 |
DBManager::instance()->insertIntoAlbum(COMMON_STR_FAVORITES, paths, AlbumDBType::Favourite); |
| 1012 |
//todo 下面的信号应该放在dbmanager里删除成功后发送 |
| 1013 |
emit dApp->signalM->insertedIntoAlbum(COMMON_STR_FAVORITES, paths); |
| 1014 |
if (m_batchOperateWidget) { |
| 1015 |
m_batchOperateWidget->refreshCollectBtn(); |
| 1016 |
} |
| 1017 |
break; |
| 1018 |
case IdRemoveFromFavorites: |
| 1019 |
DBManager::instance()->removeFromAlbum(COMMON_STR_FAVORITES, paths, AlbumDBType::Favourite); |
| 1020 |
if (m_batchOperateWidget) { |
| 1021 |
m_batchOperateWidget->refreshCollectBtn(); |
| 1022 |
} |
| 1023 |
break; |
| 1024 |
case IdRemoveFromAlbum: { |
| 1025 |
if (IMAGE_DEFAULTTYPE != m_imageType && COMMON_STR_VIEW_TIMELINE != m_imageType && |
| 1026 |
COMMON_STR_RECENT_IMPORTED != m_imageType && COMMON_STR_TRASH != m_imageType) { |
| 1027 |
// 只更新部分,从相册移出时 |
| 1028 |
updateModelRoleData(m_imageType, IdRemoveFromAlbum); |
| 1029 |
DBManager::instance()->removeFromAlbum(m_imageType, paths); |
| 1030 |
// 相册照片更新时的.更新路径相册名缓存,用于listview的setdata userrole + 2 |
| 1031 |
ImageEngineApi::instance()->setImgPathAndAlbumNames(DBManager::instance()->getAllPathAlbumNames()); |
| 1032 |
} |
| 1033 |
} |
| 1034 |
break; |
| 1035 |
case IdRotateClockwise: { |
| 1036 |
//发送给子线程旋转图片 |
| 1037 |
emit ImageEngineApi::instance()->sigRotateImageFile(90, path); |
| 1038 |
dApp->m_imageloader->updateImageLoader(paths); |
| 1039 |
} |
| 1040 |
break; |
| 1041 |
case IdRotateCounterclockwise: { |
| 1042 |
//发送给子线程旋转图片 |
| 1043 |
emit ImageEngineApi::instance()->sigRotateImageFile(-90, path); |
| 1044 |
dApp->m_imageloader->updateImageLoader(paths); |
| 1045 |
} |
| 1046 |
break; |
| 1047 |
case IdSetAsWallpaper: |
| 1048 |
dApp->wpSetter->setBackground(path); |
| 1049 |
break; |
| 1050 |
case IdDisplayInFileManager: |
| 1051 |
utils::base::showInFileManager(path); |
| 1052 |
break; |
| 1053 |
case IdImageInfo: |
| 1054 |
dApp->signalM->showInfoDlg(path); |
| 1055 |
break; |
| 1056 |
case IdVideoInfo: { |
| 1057 |
DBImgInfo data = selectedIndexes().at(0).data(Qt::DisplayRole).value<DBImgInfo>(); |
| 1058 |
dApp->signalM->showInfoDlg(path, data.itemType); |
| 1059 |
} |
| 1060 |
break; |
| 1061 |
case IdExport: |
| 1062 |
emit dApp->signalM->exportImage(paths); |
| 1063 |
break; |
| 1064 |
case IdTrashRecovery: |
| 1065 |
emit trashRecovery(); |
| 1066 |
break; |
| 1067 |
default: |
| 1068 |
break; |
| 1069 |
} |
| 1070 |
} |
| 1071 |
|
| 1072 |
void ThumbnailListView::onPixMapScale(int value) |
| 1073 |
{ |
| 1074 |
// if (!this->isVisible()) |
| 1075 |
// return; |
| 1076 |
switch (value) { |
| 1077 |
case 0: |
| 1078 |
m_iBaseHeight = 80; |
| 1079 |
break; |
| 1080 |
case 1: |
| 1081 |
m_iBaseHeight = 90; |
| 1082 |
break; |
| 1083 |
case 2: |
| 1084 |
m_iBaseHeight = 100; |
| 1085 |
break; |
| 1086 |
case 3: |
| 1087 |
m_iBaseHeight = 110; |
| 1088 |
break; |
| 1089 |
case 4: |
| 1090 |
m_iBaseHeight = 120; |
| 1091 |
break; |
| 1092 |
case 5: |
| 1093 |
m_iBaseHeight = 130; |
| 1094 |
break; |
| 1095 |
case 6: |
| 1096 |
m_iBaseHeight = 140; |
| 1097 |
break; |
| 1098 |
case 7: |
| 1099 |
m_iBaseHeight = 150; |
| 1100 |
break; |
| 1101 |
case 8: |
| 1102 |
m_iBaseHeight = 160; |
| 1103 |
break; |
| 1104 |
case 9: |
| 1105 |
m_iBaseHeight = 170; |
| 1106 |
break; |
| 1107 |
default: |
| 1108 |
m_iBaseHeight = 80; |
| 1109 |
break; |
| 1110 |
} |
| 1111 |
resizeEventF(); |
| 1112 |
} |
| 1113 |
|
| 1114 |
void ThumbnailListView::onCancelFavorite(const QModelIndex &index) |
| 1115 |
{ |
| 1116 |
QStringList str; |
| 1117 |
DBImgInfo info = index.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 1118 |
str << info.filePath; |
| 1119 |
//通知其它界面更新取消收藏 |
| 1120 |
DBManager::instance()->removeFromAlbum(COMMON_STR_FAVORITES, str, AlbumDBType::Favourite); |
| 1121 |
} |
| 1122 |
|
| 1123 |
void ThumbnailListView::resizeEvent(QResizeEvent *e) |
| 1124 |
{ |
| 1125 |
Q_UNUSED(e) |
| 1126 |
//改变第一个空白项和标题项的宽度 |
| 1127 |
for (int i = 0; i < m_model->rowCount(); i++) { |
| 1128 |
QModelIndex index = m_model->index(i, 0); |
| 1129 |
DBImgInfo data = index.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 1130 |
if (data.itemType == ItemType::ItemTypeBlank |
| 1131 |
|| data.itemType == ItemType::ItemTypeTimeLineTitle |
| 1132 |
|| data.itemType == ItemType::ItemTypeImportTimeLineTitle) { |
| 1133 |
data.imgWidth = this->width() - 5; |
| 1134 |
QVariant meta; |
| 1135 |
meta.setValue(data); |
| 1136 |
m_model->setData(index, meta, Qt::DisplayRole); |
| 1137 |
m_model->setData(index, QVariant(QSize(data.imgWidth, data.imgWidth)), Qt::SizeHintRole); |
| 1138 |
} |
| 1139 |
} |
| 1140 |
|
| 1141 |
resizeEventF(); |
| 1142 |
|
| 1143 |
// if (m_model->rowCount() > 0) { |
| 1144 |
// for (int i = 0; i < m_model->rowCount(); i++) { |
| 1145 |
// QModelIndex index = m_model->index(i, 0); |
| 1146 |
// QRect rect = this->visualRect(index); |
| 1147 |
// qDebug() << "------" << __FUNCTION__ << "---row = " << i << "---rect = " << rect; |
| 1148 |
// } |
| 1149 |
// qDebug() << "------" << __FUNCTION__ << "--------rect = " << this->rect(); |
| 1150 |
// } |
| 1151 |
} |
| 1152 |
|
| 1153 |
bool ThumbnailListView::eventFilter(QObject *obj, QEvent *e) |
| 1154 |
{ |
| 1155 |
if (obj == verticalScrollBar()) { |
| 1156 |
if (e->type() == QEvent::MouseButtonPress) { |
| 1157 |
//刷新鼠标在滚动条上按下标志位 |
| 1158 |
QRect scrollGlobaRect(verticalScrollBar()->mapToGlobal(QPoint(0, 0)), |
| 1159 |
QSize(verticalScrollBar()->geometry().width(), verticalScrollBar()->geometry().height())); |
| 1160 |
if (scrollGlobaRect.contains(QCursor::pos())) { |
| 1161 |
m_animationEnable = true; |
| 1162 |
} |
| 1163 |
} else if (e->type() == QEvent::MouseButtonRelease) { |
| 1164 |
//刷新鼠标在滚动条上释放标志位 |
| 1165 |
m_animationEnable = false; |
| 1166 |
} |
| 1167 |
} |
| 1168 |
|
| 1169 |
if (e->type() == QEvent::Wheel && QApplication::keyboardModifiers() == Qt::ControlModifier) { |
| 1170 |
return true; |
| 1171 |
} else if (e->type() == QEvent::KeyPress) { |
| 1172 |
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(e); |
| 1173 |
if (keyEvent->key() == Qt::Key_PageDown) { |
| 1174 |
DScrollBar *vb = this->verticalScrollBar(); |
| 1175 |
int posValue = vb->value(); |
| 1176 |
posValue += this->height(); |
| 1177 |
vb->setValue(posValue); |
| 1178 |
return true; |
| 1179 |
} else if (keyEvent->key() == Qt::Key_PageUp) { |
| 1180 |
DScrollBar *vb = this->verticalScrollBar(); |
| 1181 |
int posValue = vb->value(); |
| 1182 |
posValue -= this->height(); |
| 1183 |
vb->setValue(posValue); |
| 1184 |
return true; |
| 1185 |
} |
| 1186 |
} |
| 1187 |
return false; |
| 1188 |
} |
| 1189 |
|
| 1190 |
QStringList ThumbnailListView::getCurrentIndexTime(const QModelIndex &index) |
| 1191 |
{ |
| 1192 |
// index对应的是图片,获取所属时间线的时间和数量 |
| 1193 |
QStringList list; |
| 1194 |
if (index.isValid()) { |
| 1195 |
for (int i = index.row(); i >= 0; i--) { |
| 1196 |
QModelIndex idx = m_model->index(i, 0); |
| 1197 |
DBImgInfo tempdata = idx.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 1198 |
if (tempdata.itemType == ItemTypeBlank || tempdata.itemType == ItemTypeTimeLineTitle |
| 1199 |
|| tempdata.itemType == ItemTypeImportTimeLineTitle) { |
| 1200 |
list.append(tempdata.date); |
| 1201 |
list.append(tempdata.num); |
| 1202 |
break; |
| 1203 |
} |
| 1204 |
} |
| 1205 |
} |
| 1206 |
return list; |
| 1207 |
} |
| 1208 |
|
| 1209 |
bool ThumbnailListView::getCurrentIndexSelectStatus(const QModelIndex &index, bool isPic) |
| 1210 |
{ |
| 1211 |
if (!index.isValid()) { |
| 1212 |
return false; |
| 1213 |
} |
| 1214 |
QModelIndexList list = selectionModel()->selectedIndexes(); |
| 1215 |
if (isPic) { |
| 1216 |
//图片,向前循环判断选中状态 |
| 1217 |
for (int i = index.row(); i > 0; i--) { |
| 1218 |
QModelIndex idx = m_model->index(i, 0); |
| 1219 |
DBImgInfo tempdata = idx.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 1220 |
if (tempdata.itemType == ItemTypeBlank || tempdata.itemType == ItemTypeTimeLineTitle |
| 1221 |
|| tempdata.itemType == ItemTypeImportTimeLineTitle) { |
| 1222 |
break; |
| 1223 |
} |
| 1224 |
if (!list.contains(idx)) { |
| 1225 |
return false; |
| 1226 |
} |
| 1227 |
} |
| 1228 |
//图片,向后循环判断选中状态 |
| 1229 |
for (int j = index.row(); j < m_model->rowCount(); j++) { |
| 1230 |
QModelIndex idx = m_model->index(j, 0); |
| 1231 |
DBImgInfo tempdata = idx.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 1232 |
if (tempdata.itemType == ItemTypeBlank || tempdata.itemType == ItemTypeTimeLineTitle |
| 1233 |
|| tempdata.itemType == ItemTypeImportTimeLineTitle) { |
| 1234 |
break; |
| 1235 |
} |
| 1236 |
if (!list.contains(idx)) { |
| 1237 |
return false; |
| 1238 |
} |
| 1239 |
} |
| 1240 |
} else {//标题,+1进入第一张 |
| 1241 |
for (int j = index.row() + 1; j < m_model->rowCount(); j++) { |
| 1242 |
QModelIndex idx = m_model->index(j, 0); |
| 1243 |
DBImgInfo tempdata = idx.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 1244 |
if (tempdata.itemType == ItemTypeBlank || tempdata.itemType == ItemTypeTimeLineTitle |
| 1245 |
|| tempdata.itemType == ItemTypeImportTimeLineTitle) { |
| 1246 |
break; |
| 1247 |
} |
| 1248 |
if (!list.contains(idx)) { |
| 1249 |
return false; |
| 1250 |
} |
| 1251 |
} |
| 1252 |
} |
| 1253 |
return true; |
| 1254 |
} |
| 1255 |
|
| 1256 |
bool ThumbnailListView::isAllAppointType(ItemType type) |
| 1257 |
{ |
| 1258 |
bool isAllAppointType = true; |
| 1259 |
for (int i = 0; i < m_model->rowCount(); i++) { |
| 1260 |
QModelIndex index = m_model->index(i, 0); |
| 1261 |
DBImgInfo info = index.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 1262 |
if (type == ItemTypePic) { |
| 1263 |
if (info.itemType == ItemTypeVideo) { |
| 1264 |
isAllAppointType = false; |
| 1265 |
break; |
| 1266 |
} |
| 1267 |
} else if (type == ItemTypeVideo) { |
| 1268 |
if (info.itemType == ItemTypePic) { |
| 1269 |
isAllAppointType = false; |
| 1270 |
break; |
| 1271 |
} |
| 1272 |
} |
| 1273 |
} |
| 1274 |
qDebug() << __FUNCTION__ << "---isAllAppointType = " << isAllAppointType; |
| 1275 |
return isAllAppointType; |
| 1276 |
} |
| 1277 |
|
| 1278 |
void ThumbnailListView::hideAllAppointType(ItemType type) |
| 1279 |
{ |
| 1280 |
for (int i = 0; i < m_model->rowCount(); i++) { |
| 1281 |
QModelIndex index = m_model->index(i, 0); |
| 1282 |
DBImgInfo info = index.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 1283 |
if (info.itemType == type) { |
| 1284 |
setRowHidden(i, true); |
| 1285 |
} else { |
| 1286 |
setRowHidden(i, false); |
| 1287 |
} |
| 1288 |
} |
| 1289 |
//有可能出现图片或者视频删除好,时间线页面两个标题在一起的情况 |
| 1290 |
for (int i = 0; i < m_model->rowCount(); i++) { |
| 1291 |
QModelIndex index = m_model->index(i, 0); |
| 1292 |
DBImgInfo info = index.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 1293 |
//空白栏下第一个未隐藏的是标题,隐藏标题,同时将标题中的时间和数量传递给空白栏 |
| 1294 |
if (info.itemType == ItemTypeBlank) { |
| 1295 |
bool nextVisibleIsTitle = false; |
| 1296 |
for (int j = i + 1; j < m_model->rowCount(); j++) { |
| 1297 |
QModelIndex nextIndex = m_model->index(j, 0); |
| 1298 |
DBImgInfo nextInfo = nextIndex.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 1299 |
if (!isRowHidden(j) && (nextInfo.itemType == ItemTypePic || nextInfo.itemType == ItemTypeVideo)) { |
| 1300 |
break; |
| 1301 |
} |
| 1302 |
if (!isRowHidden(j)) { |
| 1303 |
if (nextInfo.itemType == ItemTypeTimeLineTitle || nextInfo.itemType == ItemTypeImportTimeLineTitle) { |
| 1304 |
setRowHidden(j, true); |
| 1305 |
bool isSelect = getCurrentIndexSelectStatus(nextIndex, false); |
| 1306 |
emit sigTimeLineDataAndNum(nextInfo.date, nextInfo.num, isSelect ? QObject::tr("Unselect") : QObject::tr("Select")); |
| 1307 |
nextVisibleIsTitle = true; |
| 1308 |
break; |
| 1309 |
} |
| 1310 |
} |
| 1311 |
} |
| 1312 |
if (nextVisibleIsTitle) { |
| 1313 |
i--; |
| 1314 |
continue; |
| 1315 |
} |
| 1316 |
} else if (info.itemType == ItemTypeTimeLineTitle |
| 1317 |
|| info.itemType == ItemTypeImportTimeLineTitle) { |
| 1318 |
//当前是标题,下一个未隐藏的也是标题时,隐藏当前标题 |
| 1319 |
for (int j = i + 1; j < m_model->rowCount(); j++) { |
| 1320 |
QModelIndex nextIndex = m_model->index(j, 0); |
| 1321 |
DBImgInfo nextInfo = nextIndex.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 1322 |
if (!isRowHidden(j) && (nextInfo.itemType == ItemTypePic || nextInfo.itemType == ItemTypeVideo)) { |
| 1323 |
break; |
| 1324 |
} |
| 1325 |
if (!isRowHidden(j)) { |
| 1326 |
if (nextInfo.itemType == ItemTypeTimeLineTitle || nextInfo.itemType == ItemTypeImportTimeLineTitle) { |
| 1327 |
setRowHidden(i, true); |
| 1328 |
break; |
| 1329 |
} |
| 1330 |
} |
| 1331 |
//当前是最后一个标题 |
| 1332 |
if (isRowHidden(j) && (j == (m_model->rowCount() - 1))) { |
| 1333 |
setRowHidden(i, true); |
| 1334 |
} |
| 1335 |
} |
| 1336 |
} |
| 1337 |
} |
| 1338 |
} |
| 1339 |
|
| 1340 |
int ThumbnailListView::getRow(QPoint point) |
| 1341 |
{ |
| 1342 |
return indexAt(point).row(); |
| 1343 |
} |
| 1344 |
|
| 1345 |
void ThumbnailListView::setListViewUseFor(ThumbnailListView::ListViewUseFor usefor) |
| 1346 |
{ |
| 1347 |
m_useFor = usefor; |
| 1348 |
} |
| 1349 |
|
| 1350 |
//add start 3975 |
| 1351 |
int ThumbnailListView::getListViewHeight() |
| 1352 |
{ |
| 1353 |
return m_height; |
| 1354 |
} |
| 1355 |
//add end 3975 |
| 1356 |
//有文件删除,刷新所有列表 |
| 1357 |
void ThumbnailListView::updateThumbnailViewAfterDelete(const DBImgInfoList &infos) |
| 1358 |
{ |
| 1359 |
//列表上移除所有图片项 |
| 1360 |
if (m_delegatetype == ThumbnailDelegate::AllPicViewType |
| 1361 |
|| m_delegatetype == ThumbnailDelegate::AlbumViewCustomType |
| 1362 |
|| m_delegatetype == ThumbnailDelegate::AlbumViewFavoriteType |
| 1363 |
|| m_delegatetype == ThumbnailDelegate::TimeLineViewType |
| 1364 |
|| m_delegatetype == ThumbnailDelegate::AlbumViewImportTimeLineViewType) { |
| 1365 |
foreach (auto info, infos) { |
| 1366 |
for (int i = (m_model->rowCount() - 1); i >= 0; i--) { |
| 1367 |
QModelIndex index = m_model->index(i, 0); |
| 1368 |
DBImgInfo data = index.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 1369 |
if (info.filePath == data.filePath) { |
| 1370 |
m_model->removeRow(i); |
| 1371 |
break; |
| 1372 |
} |
| 1373 |
} |
| 1374 |
} |
| 1375 |
} |
| 1376 |
if (m_delegatetype == ThumbnailDelegate::TimeLineViewType |
| 1377 |
|| m_delegatetype == ThumbnailDelegate::AlbumViewImportTimeLineViewType) { |
| 1378 |
//给需要移除的项添加标志 |
| 1379 |
for (int i = 0; i < m_model->rowCount(); i++) { |
| 1380 |
QModelIndex index = m_model->index(i, 0); |
| 1381 |
DBImgInfo data = index.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 1382 |
if (i < (m_model->rowCount() - 1)) { |
| 1383 |
QModelIndex indexNext = m_model->index((i + 1), 0); |
| 1384 |
DBImgInfo dataNext = indexNext.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 1385 |
//当前项和下一项都是标题,则当前项标记为需要删除 |
| 1386 |
if ((data.itemType == ItemTypeTimeLineTitle && dataNext.itemType == ItemTypeTimeLineTitle) |
| 1387 |
|| (data.itemType == ItemTypeImportTimeLineTitle && dataNext.itemType == ItemTypeImportTimeLineTitle)) { |
| 1388 |
data.bNeedDelete = true; |
| 1389 |
QVariant meta; |
| 1390 |
meta.setValue(data); |
| 1391 |
m_model->setData(index, meta, Qt::DisplayRole); |
| 1392 |
} |
| 1393 |
} else if (i == (m_model->rowCount() - 1)) { |
| 1394 |
//最后一项是标题,标记需要删除 |
| 1395 |
if (data.itemType == ItemTypeTimeLineTitle || data.itemType == ItemTypeImportTimeLineTitle) { |
| 1396 |
data.bNeedDelete = true; |
| 1397 |
QVariant meta; |
| 1398 |
meta.setValue(data); |
| 1399 |
m_model->setData(index, meta, Qt::DisplayRole); |
| 1400 |
} |
| 1401 |
} |
| 1402 |
if (i == 1) { |
| 1403 |
//第二项是标题,标记需要删除 |
| 1404 |
if (data.itemType == ItemTypeTimeLineTitle || data.itemType == ItemTypeImportTimeLineTitle) { |
| 1405 |
data.bNeedDelete = true; |
| 1406 |
QVariant meta; |
| 1407 |
meta.setValue(data); |
| 1408 |
m_model->setData(index, meta, Qt::DisplayRole); |
| 1409 |
} |
| 1410 |
} |
| 1411 |
} |
| 1412 |
//移除添加了标志的项 |
| 1413 |
for (int i = 0; i < m_model->rowCount(); i++) { |
| 1414 |
QModelIndex index = m_model->index(i, 0); |
| 1415 |
DBImgInfo data = index.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 1416 |
if (data.bNeedDelete) { |
| 1417 |
m_model->removeRow(i); |
| 1418 |
//移除后先减1,后面加1的时候才不会遗漏 |
| 1419 |
i--; |
| 1420 |
} |
| 1421 |
} |
| 1422 |
} |
| 1423 |
} |
| 1424 |
|
| 1425 |
void ThumbnailListView::slotSelectCurrentDatePic(bool isSelect, QStandardItem *item) |
| 1426 |
{ |
| 1427 |
if (item == nullptr || !m_model->indexFromItem(item).isValid()) { |
| 1428 |
return; |
| 1429 |
} |
| 1430 |
int index = m_model->indexFromItem(item).row() + 1; |
| 1431 |
for (; index < m_model->rowCount(); index++) { |
| 1432 |
QModelIndex itemIndex = m_model->index(index, 0); |
| 1433 |
DBImgInfo data = itemIndex.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 1434 |
if (data.itemType == ItemTypeTimeLineTitle || data.itemType == ItemTypeImportTimeLineTitle) { |
| 1435 |
break; |
| 1436 |
} else { |
| 1437 |
if (isSelect) { |
| 1438 |
selectionModel()->select(itemIndex, QItemSelectionModel::Select); |
| 1439 |
} else { |
| 1440 |
selectionModel()->select(itemIndex, QItemSelectionModel::Deselect); |
| 1441 |
} |
| 1442 |
} |
| 1443 |
} |
| 1444 |
} |
| 1445 |
//刷新所有标题中选择按钮的状态 |
| 1446 |
void ThumbnailListView::slotChangeAllSelectBtnVisible(bool visible) |
| 1447 |
{ |
| 1448 |
if (m_delegatetype == ThumbnailDelegate::TimeLineViewType) { |
| 1449 |
TimeLineDateWidget *w = nullptr; |
| 1450 |
for (int i = 0; i < m_model->rowCount(); i++) { |
| 1451 |
QModelIndex idx = m_model->index(i, 0); |
| 1452 |
DBImgInfo data = idx.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 1453 |
if (data.itemType == ItemTypeTimeLineTitle) { |
| 1454 |
w = static_cast<TimeLineDateWidget *>(this->indexWidget(idx)); |
| 1455 |
if (w != nullptr) { |
| 1456 |
w->onChangeChooseBtnVisible(visible); |
| 1457 |
} |
| 1458 |
} |
| 1459 |
} |
| 1460 |
} else if (m_delegatetype == ThumbnailDelegate::AlbumViewImportTimeLineViewType) { |
| 1461 |
importTimeLineDateWidget *w = nullptr; |
| 1462 |
for (int i = 0; i < m_model->rowCount(); i++) { |
| 1463 |
QModelIndex idx = m_model->index(i, 0); |
| 1464 |
DBImgInfo data = idx.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 1465 |
if (data.itemType == ItemTypeImportTimeLineTitle) { |
| 1466 |
w = static_cast<importTimeLineDateWidget *>(this->indexWidget(idx)); |
| 1467 |
if (w != nullptr) { |
| 1468 |
w->onChangeChooseBtnVisible(visible); |
| 1469 |
} |
| 1470 |
} |
| 1471 |
} |
| 1472 |
} |
| 1473 |
} |
| 1474 |
|
| 1475 |
// 选中重复导入的图片 |
| 1476 |
void ThumbnailListView::selectDuplicatePhotos(QStringList paths) |
| 1477 |
{ |
| 1478 |
QModelIndex firstIndex; |
| 1479 |
if (paths.count() > 0) { |
| 1480 |
this->clearSelection(); |
| 1481 |
for (int i = 0; i < m_model->rowCount(); i++) { |
| 1482 |
QModelIndex index = m_model->index(i, 0); |
| 1483 |
DBImgInfo info = index.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 1484 |
for (int j = 0; j < paths.count(); j++) { |
| 1485 |
if (info.filePath == paths.at(j)) { |
| 1486 |
// 选中 |
| 1487 |
selectionModel()->select(index, QItemSelectionModel::Select); |
| 1488 |
if (!firstIndex.isValid()) { |
| 1489 |
firstIndex = index; |
| 1490 |
} |
| 1491 |
} |
| 1492 |
} |
| 1493 |
} |
| 1494 |
} |
| 1495 |
// 定位第一个重复导入的照片 |
| 1496 |
if (firstIndex.isValid()) { |
| 1497 |
this->scrollTo(firstIndex, ScrollHint::PositionAtCenter); |
| 1498 |
} |
| 1499 |
} |
| 1500 |
|
| 1501 |
void ThumbnailListView::updateModelRoleData(QString albumName, int actionType) |
| 1502 |
{ |
| 1503 |
// listview存在多个,状态model不同,所以先处理已知的,再通知其他model |
| 1504 |
// 本listview对象不再处理其他listviw对象model的同步问题! |
| 1505 |
if (actionType == IdRemoveFromAlbum) { |
| 1506 |
// remove from album |
| 1507 |
for (QModelIndex index : selectedIndexes()) { |
| 1508 |
QStringList datas = index.model()->data(index, Qt::UserRole + 2).toStringList(); |
| 1509 |
datas.removeAll(albumName); |
| 1510 |
QMap<int, QVariant> tempData; |
| 1511 |
tempData.insert(Qt::UserRole + 2, datas); |
| 1512 |
m_model->setItemData(index, tempData); |
| 1513 |
} |
| 1514 |
} else if (actionType == IdAddToAlbum) { |
| 1515 |
// add to album |
| 1516 |
for (QModelIndex index : selectedIndexes()) { |
| 1517 |
QStringList datas = index.model()->data(index, Qt::UserRole + 2).toStringList(); |
| 1518 |
datas.append(albumName); |
| 1519 |
QMap<int, QVariant> tempData; |
| 1520 |
tempData.insert(Qt::UserRole + 2, datas); |
| 1521 |
m_model->setItemData(index, tempData); |
| 1522 |
} |
| 1523 |
} else if (actionType == IdMoveToTrash) { |
| 1524 |
// delete photos |
| 1525 |
// for (QModelIndex index : selectedIndexes()) { |
| 1526 |
// QStringList datas; |
| 1527 |
// datas.clear(); |
| 1528 |
// QMap<int, QVariant> tempData; |
| 1529 |
// tempData.insert(Qt::UserRole + 2, datas); |
| 1530 |
// m_model->setItemData(index, tempData); |
| 1531 |
// } |
| 1532 |
} |
| 1533 |
QStringList paths; |
| 1534 |
paths.clear(); |
| 1535 |
for (QModelIndex index : selectedIndexes()) { |
| 1536 |
paths.append(index.data(Qt::DisplayRole).value<DBImgInfo>().filePath); |
| 1537 |
} |
| 1538 |
emit SignalManager::instance()->sigSyncListviewModelData(paths, albumName, actionType); |
| 1539 |
} |
| 1540 |
|
| 1541 |
void ThumbnailListView::selectFirstPhoto() |
| 1542 |
{ |
| 1543 |
if (m_model->rowCount() < 1) |
| 1544 |
return; |
| 1545 |
QModelIndex idx = m_model->index(0, 0); |
| 1546 |
selectionModel()->setCurrentIndex(idx, QItemSelectionModel::Select); |
| 1547 |
selectionModel()->select(idx, QItemSelectionModel::Select); |
| 1548 |
} |
| 1549 |
|
| 1550 |
bool ThumbnailListView::isFirstPhotoSelected() |
| 1551 |
{ |
| 1552 |
QModelIndexList idx = selectionModel()->selectedIndexes(); |
| 1553 |
for (QModelIndex index : selectionModel()->selectedIndexes()) { |
| 1554 |
if (index.row() == 0) { |
| 1555 |
return true; |
| 1556 |
} |
| 1557 |
} |
| 1558 |
return false; |
| 1559 |
} |
| 1560 |
|
| 1561 |
bool ThumbnailListView::isNoPhotosSelected() |
| 1562 |
{ |
| 1563 |
QModelIndexList indexList = selectionModel()->selectedIndexes(); |
| 1564 |
if (indexList.count() > 0) |
| 1565 |
return false; |
| 1566 |
else |
| 1567 |
return true; |
| 1568 |
} |
| 1569 |
|
| 1570 |
void ThumbnailListView::clearAll() |
| 1571 |
{ |
| 1572 |
m_model->clear(); |
| 1573 |
} |
| 1574 |
//插入一个空白项,ItemTypeBlank |
| 1575 |
//插入时间线标题,ItemTypeTimeLineTitle |
| 1576 |
//插入已导入时间线标题,ItemTypeImportTimeLineTitle |
| 1577 |
void ThumbnailListView::insertBlankOrTitleItem(ItemType type, const QString &date, const QString &num, int height) |
| 1578 |
{ |
| 1579 |
DBImgInfo info; |
| 1580 |
info.itemType = type; |
| 1581 |
info.imgWidth = this->width(); |
| 1582 |
if (type == ItemTypeBlank) { |
| 1583 |
m_blankItemHeight = height; |
| 1584 |
} |
| 1585 |
info.imgHeight = height; |
| 1586 |
info.date = date; |
| 1587 |
info.num = num; |
| 1588 |
insertThumbnail(info); |
| 1589 |
} |
| 1590 |
//更新空白栏高度 |
| 1591 |
void ThumbnailListView::resetBlankItemHeight(int height) |
| 1592 |
{ |
| 1593 |
|
| 1594 |
for (int i = 0; i < m_model->rowCount(); i++) { |
| 1595 |
QModelIndex idx = m_model->index(i, 0); |
| 1596 |
DBImgInfo data = idx.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 1597 |
if (data.itemType == ItemTypeBlank) { |
| 1598 |
m_blankItemHeight = height; |
| 1599 |
data.imgHeight = height; |
| 1600 |
|
| 1601 |
QVariant infoVariant; |
| 1602 |
infoVariant.setValue(data); |
| 1603 |
m_model->setData(idx, infoVariant, Qt::DisplayRole); |
| 1604 |
break; |
| 1605 |
} |
| 1606 |
} |
| 1607 |
doItemsLayout(); |
| 1608 |
} |
| 1609 |
|
| 1610 |
void ThumbnailListView::insertThumbnailByImgInfos(DBImgInfoList infoList) |
| 1611 |
{ |
| 1612 |
QDateTime currentTime = QDateTime::currentDateTime(); |
| 1613 |
for (int i = 0; i < infoList.size(); ++i) { |
| 1614 |
DBImgInfo imgData = infoList.at(i); |
| 1615 |
DBImgInfo info = imgData; |
| 1616 |
info.imgWidth = m_onePicWidth; |
| 1617 |
info.imgHeight = m_onePicWidth; |
| 1618 |
if (m_delegatetype == ThumbnailDelegate::AlbumViewTrashType) { |
| 1619 |
info.remainDays = QString::number(30 - utils::base::daysDifferenceBetweenTime(info.importTime, currentTime)) + tr("days"); |
| 1620 |
} |
| 1621 |
insertThumbnail(info); |
| 1622 |
} |
| 1623 |
//如果不是显示全部,则重新过滤显示 |
| 1624 |
if (m_currentShowItemType != ItemTypeNull) { |
| 1625 |
this->showAppointTypeItem(m_currentShowItemType); |
| 1626 |
} |
| 1627 |
} |
| 1628 |
//判断所有图片是否全选中 |
| 1629 |
bool ThumbnailListView::isAllSelected(ItemType type) |
| 1630 |
{ |
| 1631 |
bool isAllSelected = true; |
| 1632 |
qDebug() << __FUNCTION__ << "---type = " << type; |
| 1633 |
|
| 1634 |
if (this->selectionModel()->selection().size() == 0) { |
| 1635 |
return false; |
| 1636 |
} |
| 1637 |
for (int i = 0; i < m_model->rowCount(); i++) { |
| 1638 |
QModelIndex idx = m_model->index(i, 0); |
| 1639 |
DBImgInfo data = idx.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 1640 |
//全选 |
| 1641 |
if (type == ItemType::ItemTypeNull) { |
| 1642 |
if ((data.itemType == ItemTypeVideo || data.itemType == ItemTypePic) |
| 1643 |
&& !this->selectionModel()->selection().contains(idx)) { |
| 1644 |
isAllSelected = false; |
| 1645 |
break; |
| 1646 |
} |
| 1647 |
} else if (type == ItemTypePic) { |
| 1648 |
if (data.itemType == ItemTypePic && !this->selectionModel()->selection().contains(idx)) { |
| 1649 |
isAllSelected = false; |
| 1650 |
break; |
| 1651 |
} |
| 1652 |
} else if (type == ItemTypeVideo) { |
| 1653 |
if (data.itemType == ItemTypeVideo && !this->selectionModel()->selection().contains(idx)) { |
| 1654 |
isAllSelected = false; |
| 1655 |
break; |
| 1656 |
} |
| 1657 |
} |
| 1658 |
} |
| 1659 |
return isAllSelected; |
| 1660 |
} |
| 1661 |
//判断选中图片是否都可旋转 |
| 1662 |
bool ThumbnailListView::isAllSelectedSupportRotate() |
| 1663 |
{ |
| 1664 |
QStringList list = selectedPaths(); |
| 1665 |
int count = list.size(); |
| 1666 |
bool isAllSelectedSupportRotate = true; |
| 1667 |
if (count <= 0) { |
| 1668 |
isAllSelectedSupportRotate = false; |
| 1669 |
} |
| 1670 |
for (int i = 0; i < count; i++) { |
| 1671 |
QString path = list.at(i); |
| 1672 |
if (!UnionImage_NameSpace::isImageSupportRotate(path)) { |
| 1673 |
isAllSelectedSupportRotate = false; |
| 1674 |
break; |
| 1675 |
} |
| 1676 |
} |
| 1677 |
return isAllSelectedSupportRotate; |
| 1678 |
} |
| 1679 |
|
| 1680 |
//删除到相册已删除 |
| 1681 |
void ThumbnailListView::removeSelectToTrash(QStringList paths) |
| 1682 |
{ |
| 1683 |
int imgCount = 0; |
| 1684 |
int videoCount = 0; |
| 1685 |
DBImgInfoList infos; |
| 1686 |
DBImgInfo info; |
| 1687 |
for (int i = 0; i < paths.size(); i++) { |
| 1688 |
QString path = paths.at(i); |
| 1689 |
bool succes = ImageEngineApi::instance()->getImageData(path, info); |
| 1690 |
if (!succes) { |
| 1691 |
if (infos.size() == 0) { |
| 1692 |
infos = DBManager::instance()->getAllTrashInfos(); |
| 1693 |
} |
| 1694 |
for (int j = 0; j < infos.size(); j++) { |
| 1695 |
if (infos.at(j).filePath == path) { |
| 1696 |
info.itemType = infos.at(j).itemType; |
| 1697 |
break; |
| 1698 |
} |
| 1699 |
} |
| 1700 |
} |
| 1701 |
if (info.itemType == ItemTypePic) { |
| 1702 |
imgCount++; |
| 1703 |
} else if (info.itemType == ItemTypeVideo) { |
| 1704 |
videoCount++; |
| 1705 |
} |
| 1706 |
} |
| 1707 |
ImgDeleteDialog *dialog = new ImgDeleteDialog(this, imgCount, videoCount); |
| 1708 |
dialog->setObjectName("deteledialog"); |
| 1709 |
if (dialog->exec() > 0) { |
| 1710 |
// 只更新部分,删除 |
| 1711 |
updateModelRoleData("", IdMoveToTrash); |
| 1712 |
if (COMMON_STR_VIEW_TIMELINE == m_imageType || COMMON_STR_RECENT_IMPORTED == m_imageType) { |
| 1713 |
emit sigMoveToTrash(); |
| 1714 |
} |
| 1715 |
(COMMON_STR_TRASH == m_imageType) ? ImageEngineApi::instance()->moveImagesToTrash(paths, true, false) |
| 1716 |
: ImageEngineApi::instance()->moveImagesToTrash(paths); |
| 1717 |
} |
| 1718 |
} |
| 1719 |
//更新时间线界面内各个按钮的text状态,单选/框选 |
| 1720 |
void ThumbnailListView::updatetimeLimeBtnText() |
| 1721 |
{ |
| 1722 |
QModelIndexList indexs = selectionModel()->selectedIndexes(); |
| 1723 |
bool isSelectAll = true; |
| 1724 |
if (m_delegatetype == ThumbnailDelegate::TimeLineViewType) { |
| 1725 |
TimeLineDateWidget *w = nullptr; |
| 1726 |
for (int i = 0; i < m_model->rowCount(); i++) { |
| 1727 |
QModelIndex idx = m_model->index(i, 0); |
| 1728 |
DBImgInfo data = idx.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 1729 |
if (data.itemType == ItemTypeBlank) { |
| 1730 |
continue; |
| 1731 |
} |
| 1732 |
if (data.itemType == ItemTypeTimeLineTitle) { |
| 1733 |
if (w == nullptr) { //说明是第一个时间线 |
| 1734 |
// 悬浮时间线标题内的按钮状态同步 |
| 1735 |
emit sigTimeLineDataAndNum("", "", isSelectAll ? QObject::tr("Unselect") : QObject::tr("Select")); |
| 1736 |
} else { |
| 1737 |
w->onTimeLinePicSelectAll(isSelectAll); |
| 1738 |
} |
| 1739 |
w = static_cast<TimeLineDateWidget *>(this->indexWidget(idx)); |
| 1740 |
isSelectAll = true; |
| 1741 |
continue; |
| 1742 |
} |
| 1743 |
if (!indexs.contains(idx)) { |
| 1744 |
isSelectAll = false; |
| 1745 |
} |
| 1746 |
} |
| 1747 |
//最后一个时间线的相关逻辑 |
| 1748 |
if (w) { |
| 1749 |
w->onTimeLinePicSelectAll(isSelectAll); |
| 1750 |
} else { //有且只有一个时间线时的逻辑 |
| 1751 |
emit sigTimeLineDataAndNum("", "", isSelectAll ? QObject::tr("Unselect") : QObject::tr("Select")); |
| 1752 |
} |
| 1753 |
} else if (m_delegatetype == ThumbnailDelegate::AlbumViewImportTimeLineViewType) { |
| 1754 |
importTimeLineDateWidget *iw = nullptr; |
| 1755 |
isSelectAll = true; |
| 1756 |
for (int i = 0; i < m_model->rowCount(); i++) { |
| 1757 |
QModelIndex idx = m_model->index(i, 0); |
| 1758 |
DBImgInfo data = idx.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 1759 |
if (data.itemType == ItemTypeBlank) { |
| 1760 |
continue; |
| 1761 |
} |
| 1762 |
if (data.itemType == ItemTypeImportTimeLineTitle) { |
| 1763 |
if (iw == nullptr) { //说明是第一个时间线 |
| 1764 |
// 悬浮时间线标题内的按钮状态同步 |
| 1765 |
emit sigTimeLineDataAndNum("", "", isSelectAll ? QObject::tr("Unselect") : QObject::tr("Select")); |
| 1766 |
} else { |
| 1767 |
iw->onTimeLinePicSelectAll(isSelectAll); |
| 1768 |
} |
| 1769 |
iw = static_cast<importTimeLineDateWidget *>(this->indexWidget(idx)); |
| 1770 |
isSelectAll = true; |
| 1771 |
continue; |
| 1772 |
} |
| 1773 |
if (!indexs.contains(idx)) { |
| 1774 |
isSelectAll = false; |
| 1775 |
} |
| 1776 |
} |
| 1777 |
//最后一个时间线的相关逻辑 |
| 1778 |
if (iw) { |
| 1779 |
iw->onTimeLinePicSelectAll(isSelectAll); |
| 1780 |
} else { //有且只有一个时间线时的逻辑 |
| 1781 |
emit sigTimeLineDataAndNum("", "", isSelectAll ? QObject::tr("Unselect") : QObject::tr("Select")); |
| 1782 |
} |
| 1783 |
} |
| 1784 |
} |
| 1785 |
|
| 1786 |
void ThumbnailListView::showAppointTypeItem(ItemType type) |
| 1787 |
{ |
| 1788 |
//记录当前显示类型 |
| 1789 |
m_currentShowItemType = type; |
| 1790 |
//切换显示之前先清除选中 |
| 1791 |
this->clearSelection(); |
| 1792 |
qDebug() << __FUNCTION__ << "---"; |
| 1793 |
if (type == ItemTypePic) { |
| 1794 |
//显示所有图片 |
| 1795 |
if (isAllAppointType(ItemTypeVideo)) { |
| 1796 |
//如果全是视频,显示无结果 |
| 1797 |
//todo |
| 1798 |
emit sigNoPicOrNoVideo(true); |
| 1799 |
} else { |
| 1800 |
//隐藏视频项 |
| 1801 |
hideAllAppointType(ItemTypeVideo); |
| 1802 |
emit sigNoPicOrNoVideo(false); |
| 1803 |
} |
| 1804 |
} else if (type == ItemTypeVideo) { |
| 1805 |
//显示所有视频 |
| 1806 |
if (isAllAppointType(ItemTypePic)) { |
| 1807 |
//如果全是图片,显示无结果 |
| 1808 |
//todo |
| 1809 |
emit sigNoPicOrNoVideo(true); |
| 1810 |
} else { |
| 1811 |
//隐藏图片项 |
| 1812 |
hideAllAppointType(ItemTypePic); |
| 1813 |
emit sigNoPicOrNoVideo(false); |
| 1814 |
} |
| 1815 |
} else if (type == ItemTypeNull) { |
| 1816 |
//恢复显示所有 |
| 1817 |
hideAllAppointType(ItemTypeNull); |
| 1818 |
emit sigNoPicOrNoVideo(false); |
| 1819 |
} |
| 1820 |
} |
| 1821 |
//显示类型数量 |
| 1822 |
int ThumbnailListView::getAppointTypeItemCount(ItemType type) |
| 1823 |
{ |
| 1824 |
int count = 0; |
| 1825 |
for (int i = 0; i < m_model->rowCount(); i++) { |
| 1826 |
if (isRowHidden(i)) { |
| 1827 |
continue; |
| 1828 |
} |
| 1829 |
QModelIndex index = m_model->index(i, 0); |
| 1830 |
DBImgInfo pdata = index.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 1831 |
//全选 |
| 1832 |
if (type == ItemType::ItemTypeNull) { |
| 1833 |
if (pdata.itemType == ItemTypeVideo || pdata.itemType == ItemTypePic) { |
| 1834 |
count++; |
| 1835 |
} |
| 1836 |
} else if (type == pdata.itemType) { |
| 1837 |
count++; |
| 1838 |
} |
| 1839 |
} |
| 1840 |
return count; |
| 1841 |
} |
| 1842 |
//显示指定类型选中项数量 |
| 1843 |
int ThumbnailListView::getAppointTypeSelectItemCount(ItemType type) |
| 1844 |
{ |
| 1845 |
int count = 0; |
| 1846 |
QModelIndexList list = selectedIndexes(); |
| 1847 |
int size = list.size(); |
| 1848 |
for (int i = 0; i < size; i++) { |
| 1849 |
QModelIndex index = list.at(i); |
| 1850 |
if (isRowHidden(index.row())) { |
| 1851 |
continue; |
| 1852 |
} |
| 1853 |
DBImgInfo pdata = index.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 1854 |
//全选 |
| 1855 |
if (type == ItemType::ItemTypeNull) { |
| 1856 |
if (pdata.itemType == ItemTypeVideo || pdata.itemType == ItemTypePic) { |
| 1857 |
count++; |
| 1858 |
} |
| 1859 |
} else if (type == pdata.itemType) { |
| 1860 |
count++; |
| 1861 |
} |
| 1862 |
} |
| 1863 |
return count; |
| 1864 |
} |
| 1865 |
//按类型选择 |
| 1866 |
void ThumbnailListView::selectAllByItemType(ItemType type) |
| 1867 |
{ |
| 1868 |
qDebug() << __FUNCTION__ << "---type = " << type; |
| 1869 |
this->selectAll(); |
| 1870 |
emit sigSelectAll(); |
| 1871 |
//因为性能问题,未根据类型选择,这里做全选处理,全选后,在获取选中项处过滤隐藏项 |
| 1872 |
// if (type == ItemTypeNull) { |
| 1873 |
// this->selectAll(); |
| 1874 |
// } else { |
| 1875 |
// for (int i = 0; i < m_model->rowCount(); i++) { |
| 1876 |
// QModelIndex index = m_model->index(i, 0); |
| 1877 |
// DBImgInfo pdata = index.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 1878 |
// if (pdata.itemType == type) { |
| 1879 |
// selectionModel()->select(index, QItemSelectionModel::Select); |
| 1880 |
// } |
| 1881 |
// } |
| 1882 |
// } |
| 1883 |
} |
| 1884 |
|
| 1885 |
void ThumbnailListView::TimeLineSelectAllBtn() |
| 1886 |
{ |
| 1887 |
if (m_delegatetype == ThumbnailDelegate::TimeLineViewType || m_delegatetype == ThumbnailDelegate:: AlbumViewImportTimeLineViewType) { |
| 1888 |
for (int i = 0; i < m_model->rowCount(); i++) { |
| 1889 |
QModelIndex idx = m_model->index(i, 0); |
| 1890 |
DBImgInfo data = idx.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 1891 |
if (data.itemType == ItemTypeTimeLineTitle) { |
| 1892 |
TimeLineDateWidget *w = static_cast<TimeLineDateWidget *>(this->indexWidget(idx)); |
| 1893 |
if (w) { |
| 1894 |
w->onTimeLinePicSelectAll(true); |
| 1895 |
} |
| 1896 |
} else if (data.itemType == ItemTypeImportTimeLineTitle) { |
| 1897 |
importTimeLineDateWidget *w = static_cast<importTimeLineDateWidget *>(this->indexWidget(idx)); |
| 1898 |
if (w) { |
| 1899 |
w->onTimeLinePicSelectAll(true); |
| 1900 |
} |
| 1901 |
} |
| 1902 |
} |
| 1903 |
} |
| 1904 |
} |
| 1905 |
|
| 1906 |
void ThumbnailListView::setBatchOperateWidget(BatchOperateWidget *widget) |
| 1907 |
{ |
| 1908 |
m_batchOperateWidget = widget; |
| 1909 |
} |
| 1910 |
|
| 1911 |
void ThumbnailListView::reloadImage() |
| 1912 |
{ |
| 1913 |
if (!this->isVisible()) { |
| 1914 |
return; |
| 1915 |
} |
| 1916 |
//加载上下两百张 |
| 1917 |
if (m_loadTimer == nullptr) { |
| 1918 |
m_loadTimer = new QTimer(); |
| 1919 |
m_loadTimer->setInterval(50); |
| 1920 |
m_loadTimer->setSingleShot(true); |
| 1921 |
connect(m_loadTimer, &QTimer::timeout, this, &ThumbnailListView::onLoadTimerTimeout); |
| 1922 |
} |
| 1923 |
if (m_loadTimer->isActive()) { |
| 1924 |
m_loadTimer->stop(); |
| 1925 |
} |
| 1926 |
m_loadTimer->start(); |
| 1927 |
} |
| 1928 |
|
| 1929 |
void ThumbnailListView::slotLoadFirstPageThumbnailsFinish() |
| 1930 |
{ |
| 1931 |
// 将缩略图信息插入到listview中 |
| 1932 |
int size = ImageEngineApi::instance()->m_AllImageDataVector.size(); |
| 1933 |
qDebug() << __FUNCTION__ << "---size = " << size; |
| 1934 |
if (size <= 0) { |
| 1935 |
//通知所有照片界面刷新,如果没有图片则显示导入界面 |
| 1936 |
emit sigDBImageLoaded(); |
| 1937 |
} |
| 1938 |
//加空白栏 |
| 1939 |
if (m_delegatetype == ThumbnailDelegate::AllPicViewType) { |
| 1940 |
insertBlankOrTitleItem(ItemTypeBlank, "", "", AllPicView::SUSPENSION_WIDGET_HEIGHT); |
| 1941 |
} |
| 1942 |
for (int i = 0; i < ImageEngineApi::instance()->m_FirstPageScreen && i < size; i++) { |
| 1943 |
DBImgInfo info = ImageEngineApi::instance()->m_AllImageDataVector[i]; |
| 1944 |
info.imgWidth = m_onePicWidth; |
| 1945 |
info.imgHeight = m_onePicWidth; |
| 1946 |
insertThumbnail(info); |
| 1947 |
} |
| 1948 |
|
| 1949 |
//过滤不存在图片后重新加载 |
| 1950 |
ImageEngineApi::instance()->reloadAfterFilterUnExistImage(); |
| 1951 |
} |
| 1952 |
|
| 1953 |
void ThumbnailListView::slotOneImgReady(const QString &path, QPixmap pix) |
| 1954 |
{ |
| 1955 |
for (int i = 0; i < m_model->rowCount(); i++) { |
| 1956 |
QModelIndex index = m_model->index(i, 0); |
| 1957 |
DBImgInfo data = index.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 1958 |
if (data.filePath == path) { |
| 1959 |
data.image = pix; |
| 1960 |
cutPixmap(data); |
| 1961 |
QVariant meta; |
| 1962 |
meta.setValue(data); |
| 1963 |
// ImageEngineApi::instance()->m_AllImageData[data.filePath].imgpixmap = pix; |
| 1964 |
ImageDataService::instance()->addImage(data.filePath, data.image.toImage()); |
| 1965 |
m_model->setData(index, meta, Qt::DisplayRole); |
| 1966 |
break; |
| 1967 |
} |
| 1968 |
} |
| 1969 |
} |
| 1970 |
|
| 1971 |
void ThumbnailListView::onScrollTimerOut() |
| 1972 |
{ |
| 1973 |
// disconnect(this->verticalScrollBar(), &QScrollBar::valueChanged, this, &ThumbnailListView::onScrollbarValueChanged); |
| 1974 |
// QPropertyAnimation *animation = new QPropertyAnimation(verticalScrollBar(), "value"); |
| 1975 |
// int value = verticalScrollBar()->value(); |
| 1976 |
// animation->setDuration(ANIMATION_DRLAY); |
| 1977 |
// animation->setEasingCurve(QEasingCurve::InOutQuad);//OutCubic InOutQuad |
| 1978 |
// animation->setStartValue(value); |
| 1979 |
// animation->setEndValue(value + 10); |
| 1980 |
// connect(animation, &QPropertyAnimation::finished, |
| 1981 |
// animation, &QPropertyAnimation::deleteLater); |
| 1982 |
// connect(animation, &QPropertyAnimation::finished, this, [ = ]() { |
| 1983 |
// connect(this->verticalScrollBar(), &QScrollBar::valueChanged, this, &ThumbnailListView::onScrollbarValueChanged); |
| 1984 |
// }); |
| 1985 |
// animation->start(); |
| 1986 |
|
| 1987 |
disconnect(this->verticalScrollBar(), &QScrollBar::valueChanged, this, &ThumbnailListView::onScrollbarValueChanged); |
| 1988 |
m_animation->start(); |
| 1989 |
connect(m_animation, &QPropertyAnimation::finished, this, [ = ]() { |
| 1990 |
connect(this->verticalScrollBar(), &QScrollBar::valueChanged, this, &ThumbnailListView::onScrollbarValueChanged); |
| 1991 |
}); |
| 1992 |
|
| 1993 |
|
| 1994 |
} |
| 1995 |
|
| 1996 |
void ThumbnailListView::onSyncListviewModelData(QStringList paths, QString albumName, int actionType) |
| 1997 |
{ |
| 1998 |
if (paths.count() < 1) |
| 1999 |
return ; |
| 2000 |
if (sender() != this) { |
| 2001 |
// listview存在多个,状态model不同,所以先处理已知的,再通知其他model |
| 2002 |
// 本listview对象不再处理其他listviw对象model的同步问题! |
| 2003 |
if (actionType == IdRemoveFromAlbum) { |
| 2004 |
// remove from album |
| 2005 |
if (paths.count() == 1 && !this->getFileList().contains(paths.at(0))) |
| 2006 |
return; |
| 2007 |
for (int i = 0; i < m_model->rowCount(); i++) { |
| 2008 |
QModelIndex idx = m_model->index(i, 0); |
| 2009 |
DBImgInfo info = idx.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 2010 |
for (int j = 0; j < paths.count(); j++) { |
| 2011 |
if (info.filePath == paths.at(j)) { |
| 2012 |
QStringList datas = idx.model()->data(idx, Qt::UserRole + 2).toStringList(); |
| 2013 |
datas.removeAll(albumName); |
| 2014 |
QMap<int, QVariant> tempData; |
| 2015 |
tempData.insert(Qt::UserRole + 2, datas); |
| 2016 |
m_model->setItemData(idx, tempData); |
| 2017 |
} |
| 2018 |
} |
| 2019 |
} |
| 2020 |
} else if (actionType == IdAddToAlbum) { |
| 2021 |
// add to album |
| 2022 |
if (paths.count() == 1 && !this->getFileList().contains(paths.at(0))) |
| 2023 |
return; |
| 2024 |
for (int i = 0; i < m_model->rowCount(); i++) { |
| 2025 |
QModelIndex idx = m_model->index(i, 0); |
| 2026 |
DBImgInfo info = idx.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 2027 |
for (int j = 0; j < paths.count(); j++) { |
| 2028 |
if (info.filePath == paths.at(j)) { |
| 2029 |
QStringList datas = idx.model()->data(idx, Qt::UserRole + 2).toStringList(); |
| 2030 |
datas.append(albumName); |
| 2031 |
QMap<int, QVariant> tempData; |
| 2032 |
tempData.insert(Qt::UserRole + 2, datas); |
| 2033 |
m_model->setItemData(idx, tempData); |
| 2034 |
} |
| 2035 |
} |
| 2036 |
} |
| 2037 |
} else if (actionType == IdMoveToTrash) { |
| 2038 |
// delete photos |
| 2039 |
// if (paths.count() == 1 && !this->getAllFileList().contains(paths.at(0))) |
| 2040 |
// return; |
| 2041 |
// for (int i = 0; i < m_model->rowCount(); i++) { |
| 2042 |
// QModelIndex idx = m_model->index(i, 0); |
| 2043 |
// DBImgInfo info = idx.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 2044 |
// for (int j = 0; j < paths.count(); j++) { |
| 2045 |
// if (info.path == paths.at(j)) { |
| 2046 |
// QStringList datas; |
| 2047 |
// datas.clear(); |
| 2048 |
// QMap<int, QVariant> tempData; |
| 2049 |
// tempData.insert(Qt::UserRole + 2, datas); |
| 2050 |
// m_model->setItemData(idx, tempData); |
| 2051 |
// } |
| 2052 |
// } |
| 2053 |
// } |
| 2054 |
} |
| 2055 |
} |
| 2056 |
} |
| 2057 |
|
| 2058 |
void ThumbnailListView::onScrollbarValueChanged(int value) |
| 2059 |
{ |
| 2060 |
Q_UNUSED(value) |
| 2061 |
//加载上下两百张 |
| 2062 |
reloadImage(); |
| 2063 |
//滚动条向下滑动 |
| 2064 |
if (m_animation && m_animation->state() == QPropertyAnimation::Running) { |
| 2065 |
m_animation->stop(); |
| 2066 |
} |
| 2067 |
if (m_scrollTimer->isActive()) { |
| 2068 |
m_scrollTimer->stop(); |
| 2069 |
} |
| 2070 |
|
| 2071 |
QModelIndex index = this->indexAt(QPoint(80, m_blankItemHeight)); |
| 2072 |
DBImgInfo data = index.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 2073 |
|
| 2074 |
//无选中照片,直接返回 |
| 2075 |
QModelIndexList list = selectionModel()->selectedIndexes(); |
| 2076 |
if (list.isEmpty()) { |
| 2077 |
emit sigTimeLineDataAndNum(data.date, data.num, QObject::tr("Select")); |
| 2078 |
return; |
| 2079 |
} |
| 2080 |
|
| 2081 |
//先判断当前的类型,是标题则获取是否全选;是图片,则找到它所在时间线的数量和时间以及是否全选 |
| 2082 |
if (data.itemType == ItemTypeBlank || data.itemType == ItemTypeTimeLineTitle |
| 2083 |
|| data.itemType == ItemTypeImportTimeLineTitle) { |
| 2084 |
bool isSelect = getCurrentIndexSelectStatus(index, false); |
| 2085 |
emit sigTimeLineDataAndNum(data.date, data.num, isSelect ? QObject::tr("Unselect") : QObject::tr("Select")); |
| 2086 |
} else { |
| 2087 |
bool isSelect = getCurrentIndexSelectStatus(index, true); |
| 2088 |
QStringList currentIndexTimeList = getCurrentIndexTime(index); |
| 2089 |
if (currentIndexTimeList.size() == 2) { |
| 2090 |
emit sigTimeLineDataAndNum(currentIndexTimeList.at(0), currentIndexTimeList.at(1), isSelect ? QObject::tr("Unselect") : QObject::tr("Select")); |
| 2091 |
} |
| 2092 |
} |
| 2093 |
//TODO 时间上滑动画 |
| 2094 |
// if (data.itemType == ItemTypeTimeLineTitle || data.itemType == ItemTypeBlank || data.itemType == ItemTypeImportTimeLineTitle) { |
| 2095 |
// if (!m_animationEnable) { |
| 2096 |
// //计算滚动距离,使用动画滑动 |
| 2097 |
// QRect rect = rectForIndex(index); |
| 2098 |
// if (m_animation == nullptr) { |
| 2099 |
// m_animation = new QPropertyAnimation(verticalScrollBar(), "value", this); |
| 2100 |
// m_animation->setDuration(ANIMATION_DRLAY); |
| 2101 |
// m_animation->setEasingCurve(QEasingCurve::InOutQuad); |
| 2102 |
// } |
| 2103 |
// m_animation->setStartValue(verticalScrollBar()->value()); |
| 2104 |
// m_animation->setEndValue(rect.top()); |
| 2105 |
|
| 2106 |
// disconnect(this->verticalScrollBar(), &QScrollBar::valueChanged, this, &ThumbnailListView::onScrollbarValueChanged); |
| 2107 |
// m_animation->start(); |
| 2108 |
// connect(m_animation, &QPropertyAnimation::finished, this, [ = ]() { |
| 2109 |
// connect(this->verticalScrollBar(), &QScrollBar::valueChanged, this, &ThumbnailListView::onScrollbarValueChanged); |
| 2110 |
// }); |
| 2111 |
// } |
| 2112 |
// } |
| 2113 |
} |
| 2114 |
|
| 2115 |
void ThumbnailListView::onDoubleClicked(const QModelIndex &index) |
| 2116 |
{ |
| 2117 |
if (m_isSelectAllBtn) { |
| 2118 |
return; |
| 2119 |
} |
| 2120 |
if (ALBUM_PATHTYPE_BY_PHONE != m_imageType && m_imageType.compare(COMMON_STR_TRASH) != 0) { |
| 2121 |
DBImgInfo data = index.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 2122 |
if (data.itemType == ItemTypeBlank |
| 2123 |
|| data.itemType == ItemTypeTimeLineTitle |
| 2124 |
|| data.itemType == ItemTypeImportTimeLineTitle) { |
| 2125 |
return; |
| 2126 |
} |
| 2127 |
//如果是视频,则使用系统默认播放器打开视频进行播放 |
| 2128 |
if (data.itemType == ItemTypeVideo) { |
| 2129 |
//更改打开方式,先默认影院,失败再选择 |
| 2130 |
QProcess *process = new QProcess(this); |
| 2131 |
QStringList arguments; |
| 2132 |
arguments << data.filePath; |
| 2133 |
bool isopen = process->startDetached("deepin-movie", arguments); |
| 2134 |
if (!isopen) { |
| 2135 |
arguments.clear(); |
| 2136 |
arguments << "-o" << data.filePath; |
| 2137 |
process->startDetached("dde-file-manager", arguments); |
| 2138 |
} |
| 2139 |
} else { |
| 2140 |
emit openImage(index.row(), data.filePath, false); |
| 2141 |
} |
| 2142 |
} |
| 2143 |
} |
| 2144 |
|
| 2145 |
void ThumbnailListView::onClicked(const QModelIndex &index) |
| 2146 |
{ |
| 2147 |
if (m_isSelectAllBtn) { |
| 2148 |
return; |
| 2149 |
} |
| 2150 |
DBImgInfo data = index.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 2151 |
qDebug() << __FUNCTION__ << "---" << data.filePath; |
| 2152 |
qDebug() << __FUNCTION__ << "---" << ImageDataService::instance()->imageIsLoaded(data.filePath); |
| 2153 |
qDebug() << __FUNCTION__ << "---" << ImageDataService::instance()->getMovieDurationStrByPath(data.filePath); |
| 2154 |
#ifdef tablet_PC |
| 2155 |
if (activeClick && ALBUM_PATHTYPE_BY_PHONE != m_imageType) { |
| 2156 |
if (m_imageType.compare(COMMON_STR_TRASH) != 0) { |
| 2157 |
emit openImage(index.row()); |
| 2158 |
} |
| 2159 |
} |
| 2160 |
#endif |
| 2161 |
Q_UNUSED(index) |
| 2162 |
} |
| 2163 |
|
| 2164 |
//裁剪图片尺寸 |
| 2165 |
void ThumbnailListView::cutPixmap(DBImgInfo &DBImgInfo) |
| 2166 |
{ |
| 2167 |
int width = DBImgInfo.image.width(); |
| 2168 |
if (width == 0) |
| 2169 |
width = m_iBaseHeight; |
| 2170 |
int height = DBImgInfo.image.height(); |
| 2171 |
if (abs((width - height) * 10 / width) >= 1) { |
| 2172 |
QRect rect = DBImgInfo.image.rect(); |
| 2173 |
int x = rect.x() + width / 2; |
| 2174 |
int y = rect.y() + height / 2; |
| 2175 |
if (width > height) { |
| 2176 |
x = x - height / 2; |
| 2177 |
y = 0; |
| 2178 |
DBImgInfo.image = DBImgInfo.image.copy(x, y, height, height); |
| 2179 |
} else { |
| 2180 |
y = y - width / 2; |
| 2181 |
x = 0; |
| 2182 |
DBImgInfo.image = DBImgInfo.image.copy(x, y, width, width); |
| 2183 |
} |
| 2184 |
} |
| 2185 |
} |
| 2186 |
|
| 2187 |
void ThumbnailListView::timeLimeFloatBtnClicked(const QString &date, bool isSelect) |
| 2188 |
{ |
| 2189 |
QString tmpdate = date; |
| 2190 |
for (int i = 0; i < m_model->rowCount(); i++) { |
| 2191 |
QModelIndex index = m_model->index(i, 0); |
| 2192 |
DBImgInfo data = index.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 2193 |
//循环找到时间 |
| 2194 |
if (data.itemType == ItemTypePic || data.itemType == ItemTypeVideo || data.itemType == ItemTypeMountImg) { |
| 2195 |
continue; |
| 2196 |
} |
| 2197 |
//时间线 |
| 2198 |
if (m_delegatetype == ThumbnailDelegate::TimeLineViewType && (data.itemType == ItemTypeTimeLineTitle || data.itemType == ItemTypeBlank) |
| 2199 |
&& data.date == tmpdate) { |
| 2200 |
//先同步设置本时间线选择按钮状态 |
| 2201 |
TimeLineDateWidget *w = static_cast<TimeLineDateWidget *>(this->indexWidget(index)); |
| 2202 |
if (w) { |
| 2203 |
w->onTimeLinePicSelectAll(isSelect); |
| 2204 |
} |
| 2205 |
//取选中范围 |
| 2206 |
bool bFirstSelect = true; |
| 2207 |
QModelIndex first_idx, end_idx; |
| 2208 |
for (int j = i + 1; j < m_model->rowCount(); j++) { |
| 2209 |
index = m_model->index(j, 0); |
| 2210 |
DBImgInfo pdata = index.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 2211 |
if (pdata.itemType == ItemTypeTimeLineTitle) { |
| 2212 |
break;//到达下一个时间线,跳出 |
| 2213 |
} |
| 2214 |
if (pdata.itemType == ItemTypePic || pdata.itemType == ItemTypeVideo) { |
| 2215 |
if (bFirstSelect) { |
| 2216 |
first_idx = index; |
| 2217 |
bFirstSelect = false; |
| 2218 |
} |
| 2219 |
end_idx = index; |
| 2220 |
} |
| 2221 |
} |
| 2222 |
QItemSelection selection(first_idx, end_idx); |
| 2223 |
if (isSelect) {//设置选中还是取消选中 |
| 2224 |
selectionModel()->select(selection, QItemSelectionModel::Select); |
| 2225 |
} else { |
| 2226 |
selectionModel()->select(selection, QItemSelectionModel::Deselect); |
| 2227 |
} |
| 2228 |
break; |
| 2229 |
} else if (m_delegatetype == ThumbnailDelegate::AlbumViewImportTimeLineViewType && (data.itemType == ItemTypeImportTimeLineTitle || data.itemType == ItemTypeBlank) |
| 2230 |
&& data.date == tmpdate) { //已导入时间线 |
| 2231 |
//先同步设置本时间线选择按钮状态 |
| 2232 |
importTimeLineDateWidget *w = static_cast<importTimeLineDateWidget *>(this->indexWidget(index)); |
| 2233 |
if (w) { |
| 2234 |
w->onTimeLinePicSelectAll(isSelect); |
| 2235 |
} |
| 2236 |
//取选中范围 |
| 2237 |
bool bFirstSelect = true; |
| 2238 |
QModelIndex first_idx, end_idx; |
| 2239 |
for (int j = i + 1; j < m_model->rowCount(); j++) { |
| 2240 |
index = m_model->index(j, 0); |
| 2241 |
DBImgInfo pdata = index.data(Qt::DisplayRole).value<DBImgInfo>(); |
| 2242 |
if (pdata.itemType == ItemTypeImportTimeLineTitle) { |
| 2243 |
break;//到达下一个时间线,跳出 |
| 2244 |
} else if (pdata.itemType == ItemTypePic || pdata.itemType == ItemTypeVideo) { |
| 2245 |
if (bFirstSelect) { |
| 2246 |
first_idx = index; |
| 2247 |
bFirstSelect = false; |
| 2248 |
} |
| 2249 |
end_idx = index; |
| 2250 |
} |
| 2251 |
} |
| 2252 |
QItemSelection selection(first_idx, end_idx); |
| 2253 |
if (isSelect) {//设置选中还是取消选中 |
| 2254 |
selectionModel()->select(selection, QItemSelectionModel::Select); |
| 2255 |
} else { |
| 2256 |
selectionModel()->select(selection, QItemSelectionModel::Deselect); |
| 2257 |
} |
| 2258 |
break;//已完成,跳出循环,后面index的不需要处理 |
| 2259 |
} |
| 2260 |
} |
| 2261 |
} |
| 2262 |
|
| 2263 |
void ThumbnailListView::resizeEventF() |
| 2264 |
{ |
| 2265 |
int i_totalwidth = width() - 30; |
| 2266 |
//计算一行的个数 |
| 2267 |
m_rowSizeHint = i_totalwidth / (m_iBaseHeight + ITEM_SPACING); |
| 2268 |
int currentwidth = (i_totalwidth - ITEM_SPACING * (m_rowSizeHint - 1)) / m_rowSizeHint;//一张图的宽度 |
| 2269 |
m_onePicWidth = currentwidth; |
| 2270 |
|
| 2271 |
if (nullptr != m_item) { |
| 2272 |
m_item->setSizeHint(QSize(this->width(), getListViewHeight() + 8 + 27)/*this->size()*/); |
| 2273 |
this->resize(QSize(this->width(), m_height + 27 + 8)/*this->size()*/); |
| 2274 |
} |
| 2275 |
if (m_delegate) { |
| 2276 |
m_delegate->setItemSize(QSize(m_onePicWidth, m_onePicWidth)); |
| 2277 |
} |
| 2278 |
this->setSpacing(ITEM_SPACING); |
| 2279 |
|
| 2280 |
//resize以后加载图片 |
| 2281 |
reloadImage(); |
| 2282 |
} |