| 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 "viewpanel.h" |
| 22 |
#include "application.h" |
| 23 |
#include "navigationwidget.h" |
| 24 |
#include "controller/signalmanager.h" |
| 25 |
#include "controller/configsetter.h" |
| 26 |
#include "contents/ttbcontent.h" |
| 27 |
#include "scen/imageview.h" |
| 28 |
#include "utils/imageutils.h" |
| 29 |
#include "utils/baseutils.h" |
| 30 |
#include "widgets/imagebutton.h" |
| 31 |
#include "widgets/printhelper.h" |
| 32 |
#include "widgets/dialogs/imgdeletedialog.h" |
| 33 |
#include "imageengine/imageengineapi.h" |
| 34 |
#include "ac-desktop-define.h" |
| 35 |
|
| 36 |
#include <QApplication> |
| 37 |
#include <QDebug> |
| 38 |
#include <QFileInfo> |
| 39 |
#include <QProxyStyle> |
| 40 |
#include <QFileSystemWatcher> |
| 41 |
#include <QHBoxLayout> |
| 42 |
#include <QKeySequence> |
| 43 |
#include <QPixmapCache> |
| 44 |
#include <QProcess> |
| 45 |
#include <QResizeEvent> |
| 46 |
#include <QStackedWidget> |
| 47 |
#include <QtConcurrent> |
| 48 |
#include <QFileDialog> |
| 49 |
#include <QPainter> |
| 50 |
#include <QMovie> |
| 51 |
#include <QDesktopWidget> |
| 52 |
#include <QPropertyAnimation> |
| 53 |
|
| 54 |
#include <DRecentManager> |
| 55 |
#include <DWidgetUtil> |
| 56 |
|
| 57 |
#include "imagedataservice.h" |
| 58 |
|
| 59 |
using namespace Dtk::Core; |
| 60 |
using namespace Dtk::Widget; |
| 61 |
|
| 62 |
namespace { |
| 63 |
|
| 64 |
const int DELAY_HIDE_CURSOR_INTERVAL = 3000; |
| 65 |
|
| 66 |
} // namespace |
| 67 |
|
| 68 |
ViewPanel::ViewPanel(QWidget *parent) |
| 69 |
: ModulePanel(parent) |
| 70 |
, m_hideCursorTid(0) |
| 71 |
, m_iSlideShowTimerId(0) |
| 72 |
, m_isInfoShowed(false) |
| 73 |
, m_viewB(nullptr) |
| 74 |
, m_stack(nullptr) |
| 75 |
, m_deletetimer(nullptr) |
| 76 |
, m_bFirstFullScreen(false) |
| 77 |
{ |
| 78 |
// onThemeChanged(dApp->viewerTheme->getCurrentTheme()); |
| 79 |
initShortcut(); |
| 80 |
initStack(); |
| 81 |
initFloatingComponent(); |
| 82 |
|
| 83 |
initConnect(); |
| 84 |
|
| 85 |
initPopupMenu(); |
| 86 |
|
| 87 |
setAcceptDrops(true); |
| 88 |
setContextMenuPolicy(Qt::CustomContextMenu); |
| 89 |
installEventFilter(this); |
| 90 |
AC_SET_ACCESSIBLE_NAME(this, VIEW_PANEL_WIDGET); |
| 91 |
AC_SET_OBJECT_NAME(this, VIEW_PANEL_WIDGET); |
| 92 |
|
| 93 |
AC_SET_ACCESSIBLE_NAME(m_stack, VIEW_PANEL_STACK); |
| 94 |
AC_SET_OBJECT_NAME(m_stack, VIEW_PANEL_STACK); |
| 95 |
} |
| 96 |
|
| 97 |
ViewPanel::~ViewPanel() |
| 98 |
{ |
| 99 |
|
| 100 |
} |
| 101 |
|
| 102 |
QString ViewPanel::moduleName() |
| 103 |
{ |
| 104 |
return "ViewPanel"; |
| 105 |
} |
| 106 |
|
| 107 |
void ViewPanel::loadFilesFromLocal(QStringList files) |
| 108 |
{ |
| 109 |
imageLocalLoaded(files); |
| 110 |
} |
| 111 |
|
| 112 |
bool ViewPanel::imageLocalLoaded(QStringList &filelist) |
| 113 |
{ |
| 114 |
onViewImage(filelist); |
| 115 |
return true; |
| 116 |
} |
| 117 |
|
| 118 |
void ViewPanel::initConnect() |
| 119 |
{ |
| 120 |
connect(dApp->signalM, &SignalManager::deleteByMenu, this, &ViewPanel::onDeleteByMenu); |
| 121 |
connect(dApp->signalM, &SignalManager::gotoPanel, this, &ViewPanel::onGotoPanel); |
| 122 |
connect(dApp->signalM, &SignalManager::showExtensionPanel, this, &ViewPanel::onShowExtensionPanel); |
| 123 |
connect(dApp->signalM, &SignalManager::hideExtensionPanel, this, &ViewPanel::onHideExtensionPanel); |
| 124 |
connect(dApp->signalM, &SignalManager::hideImageView, this, &ViewPanel::onHideImageView); |
| 125 |
qRegisterMetaType<SignalManager::ViewInfo>("SignalManager::ViewInfo"); |
| 126 |
// connect(dApp->signalM, &SignalManager::viewImageNoNeedReload, this, &ViewPanel::onViewImageNoNeedReload); |
| 127 |
connect(dApp->signalM, &SignalManager::viewImage, this, &ViewPanel::onSigViewImage); |
| 128 |
connect(m_viewB, &ImageView::mouseHoverMoved, this, &ViewPanel::onMouseHoverMoved); |
| 129 |
qRegisterMetaType<DBImgInfoList>("DBImgInfoList &"); |
| 130 |
// connect(dApp->signalM, &SignalManager::imagesInserted, this, &ViewPanel::onImagesInserted); |
| 131 |
connect(dApp->signalM, &SignalManager::sigESCKeyActivated, this, &ViewPanel::onESCKeyActivated); |
| 132 |
} |
| 133 |
|
| 134 |
void ViewPanel::mousePressEvent(QMouseEvent *e) |
| 135 |
{ |
| 136 |
emit dApp->signalM->hideExtensionPanel(); |
| 137 |
if (e->button() == Qt::BackButton) { |
| 138 |
if (window()->isFullScreen()) { |
| 139 |
showNormal(); |
| 140 |
} else { |
| 141 |
backToLastPanel(); |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
if (0 != m_iSlideShowTimerId) { |
| 146 |
killTimer(m_iSlideShowTimerId); |
| 147 |
m_iSlideShowTimerId = 0; |
| 148 |
} |
| 149 |
|
| 150 |
ModulePanel::mousePressEvent(e); |
| 151 |
} |
| 152 |
|
| 153 |
//void ViewPanel::onThemeChanged(ViewerThemeManager::AppTheme theme) |
| 154 |
//{ |
| 155 |
// Q_UNUSED(theme); |
| 156 |
//} |
| 157 |
|
| 158 |
void ViewPanel::feedBackCurrentIndex(int index, const QString &path) |
| 159 |
{ |
| 160 |
Q_UNUSED(index) |
| 161 |
openImage(path, false); |
| 162 |
} |
| 163 |
|
| 164 |
void ViewPanel::showNormal() |
| 165 |
{ |
| 166 |
if (m_isMaximized) { |
| 167 |
window()->showNormal(); |
| 168 |
window()->showMaximized(); |
| 169 |
} else { |
| 170 |
window()->showNormal(); |
| 171 |
} |
| 172 |
|
| 173 |
emit dApp->signalM->showTopToolbar(); |
| 174 |
} |
| 175 |
|
| 176 |
|
| 177 |
void ViewPanel::showFullScreen() |
| 178 |
{ |
| 179 |
m_isMaximized = window()->isMaximized(); |
| 180 |
//加入显示动画效果,以透明度0-1显示,动态加载,视觉效果掩盖左上角展开 |
| 181 |
#ifndef tablet_PC |
| 182 |
QPropertyAnimation *animation = new QPropertyAnimation(window(), "windowOpacity"); |
| 183 |
animation->setDuration(50); |
| 184 |
animation->setEasingCurve(QEasingCurve::Linear); |
| 185 |
animation->setStartValue(0); |
| 186 |
animation->setEndValue(1); |
| 187 |
animation->start(QAbstractAnimation::DeleteWhenStopped); |
| 188 |
#endif |
| 189 |
window()->showFullScreen(); |
| 190 |
m_hideCursorTid = startTimer(DELAY_HIDE_CURSOR_INTERVAL); |
| 191 |
emit dApp->signalM->sigShowFullScreen(); |
| 192 |
} |
| 193 |
|
| 194 |
//QWidget *ViewPanel::toolbarBottomContent() |
| 195 |
//{ |
| 196 |
// return nullptr; |
| 197 |
//} |
| 198 |
|
| 199 |
//QWidget *ViewPanel::toolbarTopLeftContent() |
| 200 |
//{ |
| 201 |
// return nullptr; |
| 202 |
//} |
| 203 |
|
| 204 |
void ViewPanel::bottomTopLeftContent() |
| 205 |
{ |
| 206 |
emit dApp->signalM->sigPauseOrStart(true); |
| 207 |
m_ttbc = new TTBContent(m_vinfo.inDatabase, this); |
| 208 |
m_ttbc->setObjectName("TTBContent"); |
| 209 |
|
| 210 |
connect(m_ttbc, &TTBContent::feedBackCurrentIndex, this, &ViewPanel::feedBackCurrentIndex); |
| 211 |
//测试使用 |
| 212 |
connect(this, &ViewPanel::ttbcDeleteImage, m_ttbc, &TTBContent::deleteImage); |
| 213 |
// connect(this, &ViewPanel::viewImageFrom, m_ttbc, [ = ](const QString & dir) { |
| 214 |
// m_ttbc->setCurrentDir(dir); |
| 215 |
// }); |
| 216 |
connect(this, &ViewPanel::imageChanged, m_ttbc, &TTBContent::setImage); |
| 217 |
connect(m_ttbc, &TTBContent::rotateClockwise, this, &ViewPanel::onRotateClockwise); |
| 218 |
connect(m_ttbc, &TTBContent::rotateCounterClockwise, this, &ViewPanel::onRotateCounterClockwise); |
| 219 |
connect(m_ttbc, &TTBContent::removed, this, &ViewPanel::onRemoved); |
| 220 |
connect(m_ttbc, &TTBContent::resetTransform, this, &ViewPanel::onResetTransform); |
| 221 |
connect(m_viewB, &ImageView::disCheckAdaptImageBtn, m_ttbc, &TTBContent::disCheckAdaptImageBtn); |
| 222 |
connect(m_viewB, &ImageView::disCheckAdaptScreenBtn, m_ttbc, &TTBContent::disCheckAdaptScreenBtn); |
| 223 |
connect(m_viewB, &ImageView::checkAdaptImageBtn, m_ttbc, &TTBContent::checkAdaptImageBtn); |
| 224 |
connect(m_viewB, &ImageView::checkAdaptScreenBtn, m_ttbc, &TTBContent::checkAdaptScreenBtn); |
| 225 |
connect(dApp->signalM, &SignalManager::insertedIntoAlbum, m_ttbc, &TTBContent::updateCollectButton); |
| 226 |
connect(dApp->signalM, &SignalManager::removedFromAlbum, m_ttbc, &TTBContent::updateCollectButton); |
| 227 |
|
| 228 |
connect(m_viewB, &ImageView::previousRequested, m_ttbc, &TTBContent::onPreButton); |
| 229 |
connect(m_viewB, &ImageView::nextRequested, m_ttbc, &TTBContent::onNextButton); |
| 230 |
#ifdef tablet_PC |
| 231 |
//退出时,重置ttb显隐状态 |
| 232 |
connect(m_ttbc, &TTBContent::resetShoworHide, this, [ = ] { |
| 233 |
m_showorhide = true; |
| 234 |
}); |
| 235 |
#endif |
| 236 |
|
| 237 |
m_ttbc->setAllFileInfo(m_vinfo); |
| 238 |
m_ttbc->m_imageType = m_vinfo.viewType; |
| 239 |
} |
| 240 |
//QWidget *ViewPanel::toolbarTopMiddleContent() |
| 241 |
//{ |
| 242 |
// QWidget *w = new QWidget(); |
| 243 |
// return w; |
| 244 |
//} |
| 245 |
|
| 246 |
//ImageView *ViewPanel::getImageView() |
| 247 |
//{ |
| 248 |
// return m_viewB; |
| 249 |
//} |
| 250 |
|
| 251 |
void ViewPanel::onDeleteByMenu() |
| 252 |
{ |
| 253 |
if (m_deletetimer->isActive()) { |
| 254 |
return; |
| 255 |
} |
| 256 |
m_deletetimer->start(); |
| 257 |
if (m_ttbc) { |
| 258 |
m_ttbc->deleteImage(); |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
void ViewPanel::onGotoPanel(ModulePanel *p) |
| 263 |
{ |
| 264 |
if (p != this) { |
| 265 |
emit dApp->signalM->showTopToolbar(); |
| 266 |
} else { |
| 267 |
emit dApp->signalM->showTopToolbar(); |
| 268 |
emit dApp->signalM->showBottomToolbar(); |
| 269 |
} |
| 270 |
} |
| 271 |
|
| 272 |
void ViewPanel::onShowExtensionPanel() |
| 273 |
{ |
| 274 |
m_isInfoShowed = true; |
| 275 |
} |
| 276 |
|
| 277 |
void ViewPanel::onHideExtensionPanel() |
| 278 |
{ |
| 279 |
m_isInfoShowed = false; |
| 280 |
} |
| 281 |
|
| 282 |
void ViewPanel::onHideImageView() |
| 283 |
{ |
| 284 |
if (m_vinfo.fullScreen) { //全屏退出 |
| 285 |
toggleFullScreen(); |
| 286 |
} |
| 287 |
m_viewB->clear(); |
| 288 |
} |
| 289 |
|
| 290 |
bool ViewPanel::onSigViewImage(const SignalManager::ViewInfo &info) |
| 291 |
{ |
| 292 |
//除去info的const,并对m_vinfo赋值 |
| 293 |
m_vinfo = *(const_cast<SignalManager::ViewInfo *>(&info)); |
| 294 |
m_filepathlist = m_vinfo.paths; |
| 295 |
if (m_ttbc == nullptr) { |
| 296 |
bottomTopLeftContent(); |
| 297 |
emit dApp->signalM->updateBottomToolbarContent(m_ttbc, true); |
| 298 |
} |
| 299 |
m_bFirstFullScreen = m_vinfo.fullScreen; |
| 300 |
QList<QByteArray> fList = QMovie::supportedFormats(); //"gif","mng","webp" |
| 301 |
QString strfixL = QFileInfo(m_vinfo.path).suffix().toLower(); |
| 302 |
if (fList.contains(strfixL.toUtf8().data()) || m_vinfo.fullScreen) { |
| 303 |
m_currentpath = m_vinfo.path; |
| 304 |
if (m_vinfo.paths.size() < 1) { |
| 305 |
m_vinfo.paths << m_vinfo.path; |
| 306 |
} |
| 307 |
loadFilesFromLocal(m_vinfo.paths); |
| 308 |
emit dApp->signalM->showImageView(m_vinfo.viewMainWindowID); |
| 309 |
if (nullptr == m_vinfo.lastPanel) { |
| 310 |
return false; |
| 311 |
} else if (m_vinfo.lastPanel->moduleName() == "AlbumPanel" || |
| 312 |
m_vinfo.lastPanel->moduleName() == "ViewPanel") { |
| 313 |
m_currentImageLastDir = m_vinfo.album; |
| 314 |
emit viewImageFrom(m_vinfo.album); |
| 315 |
} else if (m_vinfo.lastPanel->moduleName() == "TimelinePanel") { |
| 316 |
m_currentImageLastDir = "Timeline"; |
| 317 |
emit viewImageFrom("Timeline"); |
| 318 |
} |
| 319 |
return false; |
| 320 |
//TODO: there will be some others panel |
| 321 |
} else { |
| 322 |
m_currentpath = m_vinfo.path; |
| 323 |
if (m_vinfo.paths.size() < 1) { |
| 324 |
m_vinfo.paths << m_vinfo.path; |
| 325 |
} |
| 326 |
loadFilesFromLocal(m_vinfo.paths); |
| 327 |
if (nullptr == m_vinfo.lastPanel) { |
| 328 |
return false; |
| 329 |
} else if (m_vinfo.lastPanel->moduleName() == "AlbumPanel" || |
| 330 |
m_vinfo.lastPanel->moduleName() == "ViewPanel") { |
| 331 |
m_currentImageLastDir = m_vinfo.album; |
| 332 |
emit viewImageFrom(m_vinfo.album); |
| 333 |
} else if (m_vinfo.lastPanel->moduleName() == "TimelinePanel") { |
| 334 |
m_currentImageLastDir = "Timeline"; |
| 335 |
emit viewImageFrom("Timeline"); |
| 336 |
} |
| 337 |
return false; |
| 338 |
} |
| 339 |
|
| 340 |
//TODO: there will be some others panel |
| 341 |
} |
| 342 |
|
| 343 |
void ViewPanel::onMouseHoverMoved() |
| 344 |
{ |
| 345 |
emit mouseMoved(); |
| 346 |
} |
| 347 |
|
| 348 |
void ViewPanel::onESCKeyActivated() |
| 349 |
{ |
| 350 |
#if 1 |
| 351 |
if (isVisible()) { |
| 352 |
if (0 != m_iSlideShowTimerId) { |
| 353 |
killTimer(m_iSlideShowTimerId); |
| 354 |
m_iSlideShowTimerId = 0; |
| 355 |
} |
| 356 |
if (m_bFirstFullScreen) |
| 357 |
emit dApp->signalM->hideImageView(); |
| 358 |
else { |
| 359 |
toggleFullScreen(); |
| 360 |
} |
| 361 |
} |
| 362 |
m_vinfo.fullScreen = false; |
| 363 |
emit dApp->signalM->showBottomToolbar(); |
| 364 |
#ifdef tablet_PC |
| 365 |
m_showorhide = true;//重置显隐状态 |
| 366 |
#endif |
| 367 |
#endif |
| 368 |
} |
| 369 |
|
| 370 |
//void ViewPanel::onImagesInserted() |
| 371 |
//{ |
| 372 |
// if (!m_ttbc) { |
| 373 |
// return; |
| 374 |
// } |
| 375 |
// int size = m_ttbc->itemLoadedSize(); |
| 376 |
//} |
| 377 |
|
| 378 |
//void ViewPanel::onViewImageNoNeedReload(int &fileindex) |
| 379 |
//{ |
| 380 |
// //todo |
| 381 |
//} |
| 382 |
|
| 383 |
void ViewPanel::onRotateClockwise() |
| 384 |
{ |
| 385 |
rotateImage(true); |
| 386 |
} |
| 387 |
|
| 388 |
void ViewPanel::onRotateCounterClockwise() |
| 389 |
{ |
| 390 |
rotateImage(false); |
| 391 |
} |
| 392 |
|
| 393 |
void ViewPanel::onRemoved() |
| 394 |
{ |
| 395 |
if (COMMON_STR_TRASH == m_vinfo.viewType) { |
| 396 |
int imgCount = 0; |
| 397 |
int videoCount = 0; |
| 398 |
DBImgInfo info; |
| 399 |
ImageEngineApi::instance()->getImageData(m_currentpath, info); |
| 400 |
if (info.itemType == ItemTypePic) { |
| 401 |
imgCount++; |
| 402 |
} else if (info.itemType == ItemTypeVideo) { |
| 403 |
videoCount++; |
| 404 |
} |
| 405 |
ImgDeleteDialog *dialog = new ImgDeleteDialog(this, imgCount, videoCount); |
| 406 |
dialog->setObjectName("deteledialog"); |
| 407 |
if (dialog->exec() > 0) { |
| 408 |
DBManager::instance()->removeTrashImgInfos(QStringList(m_currentpath)); |
| 409 |
removeCurrentImage(); |
| 410 |
DDesktopServices::trash(m_currentpath); |
| 411 |
} |
| 412 |
} else { |
| 413 |
DBImgInfoList infos; |
| 414 |
DBImgInfo info; |
| 415 |
info = DBManager::instance()->getInfoByPath(m_currentpath); |
| 416 |
info.importTime = QDateTime::currentDateTime(); |
| 417 |
infos << info; |
| 418 |
DBManager::instance()->insertTrashImgInfos(infos); |
| 419 |
DBManager::instance()->removeImgInfos(QStringList(m_currentpath)); |
| 420 |
removeCurrentImage(); |
| 421 |
} |
| 422 |
} |
| 423 |
|
| 424 |
void ViewPanel::onResetTransform(bool fitWindow) |
| 425 |
{ |
| 426 |
if (fitWindow) { |
| 427 |
m_viewB->fitWindow(); |
| 428 |
} else { |
| 429 |
m_viewB->fitImage(); |
| 430 |
} |
| 431 |
} |
| 432 |
|
| 433 |
void ViewPanel::onDoubleClicked() |
| 434 |
{ |
| 435 |
if (m_bFirstFullScreen) |
| 436 |
emit dApp->signalM->hideImageView(); |
| 437 |
else { |
| 438 |
toggleFullScreen(); |
| 439 |
} |
| 440 |
} |
| 441 |
|
| 442 |
void ViewPanel::onViewBClicked() |
| 443 |
{ |
| 444 |
dApp->signalM->hideExtensionPanel(); |
| 445 |
#ifdef tablet_PC |
| 446 |
if (!window()->isFullScreen()) { |
| 447 |
toggleFullScreen(); |
| 448 |
} else { |
| 449 |
//BUG#82053,隔壁部门要求添加DBUS调用,以实现单指点击循环显示和隐藏工具栏 |
| 450 |
auto &statusBarDbus = ComDeepinDueStatusbarInterface::instance(); |
| 451 |
statusBarDbus.setVisible(!statusBarDbus.visible()); |
| 452 |
//BUG#82053 end |
| 453 |
|
| 454 |
emit dApp->signalM->sigMouseMove(m_showorhide); |
| 455 |
m_showorhide = m_showorhide ? false : true; |
| 456 |
} |
| 457 |
#endif |
| 458 |
} |
| 459 |
|
| 460 |
void ViewPanel::onViewBImageChanged(const QString &path) |
| 461 |
{ |
| 462 |
emit imageChanged(path); |
| 463 |
// Pixmap is cache in thread, make sure the size would correct after |
| 464 |
// cache is finish |
| 465 |
//m_viewB->autoFit(); 放出来会导致切换图片时偶发引起1:1图标闪烁 |
| 466 |
} |
| 467 |
|
| 468 |
void ViewPanel::onFileDelete() |
| 469 |
{ |
| 470 |
m_viewB->setImage(m_currentpath); //设置当前显示图片 |
| 471 |
if (!QFileInfo(m_currentpath).exists()) { |
| 472 |
QImage img = ImageDataService::instance()->getThumnailImageByPath(m_currentpath); |
| 473 |
m_emptyWidget->setThumbnailImage(QPixmap::fromImage(img)); |
| 474 |
m_stack->setCurrentIndex(1); |
| 475 |
} |
| 476 |
} |
| 477 |
|
| 478 |
bool ViewPanel::eventFilter(QObject *obj, QEvent *e) |
| 479 |
{ |
| 480 |
Q_UNUSED(obj) |
| 481 |
if (e->type() == QEvent::HideToParent) { |
| 482 |
m_viewB->clear(); |
| 483 |
} |
| 484 |
if (e->type() == QEvent::Resize && this->isVisible()) { |
| 485 |
emit sigResize(); |
| 486 |
} |
| 487 |
|
| 488 |
if (e->type() == QEvent::ShortcutOverride) { |
| 489 |
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(e); |
| 490 |
|
| 491 |
if (keyEvent->key() == Qt::Key_Delete) { |
| 492 |
emit SignalManager::instance()->deleteByMenu(); |
| 493 |
} |
| 494 |
} |
| 495 |
|
| 496 |
return false; |
| 497 |
} |
| 498 |
|
| 499 |
void ViewPanel::resizeEvent(QResizeEvent *e) |
| 500 |
{ |
| 501 |
ModulePanel::resizeEvent(e); |
| 502 |
// There will be several times the size change during switch to full process |
| 503 |
// So correct it every times |
| 504 |
if (window()->isFullScreen()) { |
| 505 |
Q_EMIT dApp->signalM->hideExtensionPanel(true); |
| 506 |
Q_EMIT dApp->signalM->hideTopToolbar(true); |
| 507 |
} |
| 508 |
if (!window()->isFullScreen()) { |
| 509 |
m_isMaximized = window()->isMaximized(); |
| 510 |
} |
| 511 |
|
| 512 |
if (m_viewB->isFitImage()) { |
| 513 |
m_viewB->fitImage(); |
| 514 |
} else if (m_viewB->isFitWindow()) { |
| 515 |
m_viewB->fitWindow(); |
| 516 |
} |
| 517 |
} |
| 518 |
|
| 519 |
void ViewPanel::timerEvent(QTimerEvent *e) |
| 520 |
{ |
| 521 |
if (e->timerId() == m_hideCursorTid && |
| 522 |
!m_menu->isVisible() && !m_printDialogVisible && qApp->modalWindow() == nullptr) { |
| 523 |
m_viewB->viewport()->setCursor(Qt::BlankCursor); |
| 524 |
} |
| 525 |
|
| 526 |
if (e->timerId() == m_iSlideShowTimerId) { |
| 527 |
m_ttbc->onNextButton(); |
| 528 |
} |
| 529 |
|
| 530 |
ModulePanel::timerEvent(e); |
| 531 |
} |
| 532 |
|
| 533 |
void ViewPanel::wheelEvent(QWheelEvent *e) |
| 534 |
{ |
| 535 |
if (m_viewB && !m_viewB->path().isEmpty()) |
| 536 |
qApp->sendEvent(m_viewB->viewport(), e); |
| 537 |
} |
| 538 |
|
| 539 |
void ViewPanel::onViewImage(const QStringList &vinfo) |
| 540 |
{ |
| 541 |
using namespace utils::base; |
| 542 |
this->setCursor(Qt::ArrowCursor); |
| 543 |
if (m_vinfo.fullScreen) { |
| 544 |
showFullScreen(); |
| 545 |
} |
| 546 |
if (m_vinfo.slideShow) { |
| 547 |
m_iSlideShowTimerId = startTimer(3000); |
| 548 |
} else { |
| 549 |
if (0 != m_iSlideShowTimerId) { |
| 550 |
killTimer(m_iSlideShowTimerId); |
| 551 |
m_iSlideShowTimerId = 0; |
| 552 |
} |
| 553 |
} |
| 554 |
emit dApp->signalM->gotoPanel(this); |
| 555 |
|
| 556 |
|
| 557 |
if (vinfo.size() == 1) { |
| 558 |
m_imageDirIterator.reset(new QDirIterator(QFileInfo(vinfo.first()).absolutePath(), |
| 559 |
utils::image::supportedImageFormats(), QDir::Files | QDir::Readable)); |
| 560 |
} else { |
| 561 |
m_imageDirIterator.reset(); |
| 562 |
} |
| 563 |
|
| 564 |
bottomTopLeftContent(); |
| 565 |
emit dApp->signalM->updateBottomToolbarContent(m_ttbc, (vinfo.size() >= 1)); |
| 566 |
} |
| 567 |
|
| 568 |
|
| 569 |
void ViewPanel::toggleFullScreen() |
| 570 |
{ |
| 571 |
if (window()->isFullScreen()) { |
| 572 |
showNormal(); |
| 573 |
killTimer(m_hideCursorTid); |
| 574 |
m_hideCursorTid = 0; |
| 575 |
m_vinfo.fullScreen = false; |
| 576 |
emit dApp->signalM->showBottomToolbar(); |
| 577 |
m_viewB->viewport()->setCursor(Qt::ArrowCursor); |
| 578 |
} else { |
| 579 |
// window()->setWindowFlags (Qt::Window); |
| 580 |
showFullScreen(); |
| 581 |
m_vinfo.fullScreen = true; |
| 582 |
if (!m_menu->isVisible() && qApp->modalWindow() != nullptr) { |
| 583 |
m_viewB->viewport()->setCursor(Qt::BlankCursor); |
| 584 |
} |
| 585 |
m_hideCursorTid = startTimer(DELAY_HIDE_CURSOR_INTERVAL); |
| 586 |
} |
| 587 |
} |
| 588 |
|
| 589 |
void ViewPanel::removeCurrentImage() |
| 590 |
{ |
| 591 |
// m_infos.removeAt(m_current); |
| 592 |
// if (m_infos.isEmpty()) { |
| 593 |
if (m_ttbc == nullptr) { |
| 594 |
return; |
| 595 |
} |
| 596 |
if (m_ttbc->getAllFileCount() <= 0) { |
| 597 |
qDebug() << "No images to show!"; |
| 598 |
// if (window()->isFullScreen()) |
| 599 |
// showNormal(); |
| 600 |
if (m_bFirstFullScreen) |
| 601 |
emit dApp->signalM->hideImageView(); |
| 602 |
else { |
| 603 |
toggleFullScreen(); |
| 604 |
} |
| 605 |
|
| 606 |
emit imageChanged(""); |
| 607 |
|
| 608 |
m_emptyWidget->setThumbnailImage(QPixmap()); |
| 609 |
m_stack->setCurrentIndex(1); |
| 610 |
emit dApp->signalM->hideImageView(); |
| 611 |
|
| 612 |
bottomTopLeftContent(); |
| 613 |
emit dApp->signalM->updateBottomToolbarContent(m_ttbc, (m_filepathlist.size() > 1)); |
| 614 |
} else { |
| 615 |
emit dApp->signalM->updateBottomToolbar(m_ttbc->getAllFileCount() > 1); |
| 616 |
} |
| 617 |
} |
| 618 |
|
| 619 |
void ViewPanel::initStack() |
| 620 |
{ |
| 621 |
m_stack = new QStackedWidget; |
| 622 |
m_stack->setMouseTracking(true); |
| 623 |
m_stack->setContentsMargins(0, 0, 0, 0); |
| 624 |
|
| 625 |
// View frame |
| 626 |
initViewContent(); |
| 627 |
QVBoxLayout *vl = new QVBoxLayout(this); |
| 628 |
connect(dApp->signalM, &SignalManager::showTopToolbar, this, [ = ] { |
| 629 |
vl->setContentsMargins(0, 0, 0, 0); |
| 630 |
}); |
| 631 |
connect(dApp->signalM, &SignalManager::hideTopToolbar, this, [ = ] { |
| 632 |
vl->setContentsMargins(0, 0, 0, 0); |
| 633 |
}); |
| 634 |
vl->addWidget(m_stack); |
| 635 |
|
| 636 |
// Empty frame |
| 637 |
m_emptyWidget = new ThumbnailWidget("", ""); |
| 638 |
|
| 639 |
|
| 640 |
m_stack->addWidget(m_viewB); |
| 641 |
m_stack->addWidget(m_emptyWidget); |
| 642 |
//Lock frame: if the deepin-image-viewer |
| 643 |
//can't access to read the image |
| 644 |
m_lockWidget = new LockWidget("", ""); |
| 645 |
m_stack->addWidget(m_lockWidget); |
| 646 |
} |
| 647 |
|
| 648 |
void ViewPanel::backToLastPanel() |
| 649 |
{ |
| 650 |
if (window()->isFullScreen()) { |
| 651 |
showNormal(); |
| 652 |
} |
| 653 |
if (m_vinfo.lastPanel) { |
| 654 |
emit dApp->signalM->gotoPanel(m_vinfo.lastPanel); |
| 655 |
emit dApp->signalM->hideExtensionPanel(true); |
| 656 |
emit dApp->signalM->showBottomToolbar(); |
| 657 |
} else { |
| 658 |
} |
| 659 |
} |
| 660 |
|
| 661 |
void ViewPanel::rotateImage(bool clockWise) |
| 662 |
{ |
| 663 |
if (clockWise) { |
| 664 |
m_viewB->rotateClockWise(); |
| 665 |
} else { |
| 666 |
m_viewB->rotateCounterclockwise(); |
| 667 |
} |
| 668 |
} |
| 669 |
|
| 670 |
void ViewPanel::initViewContent() |
| 671 |
{ |
| 672 |
m_viewB = new ImageView(this); |
| 673 |
connect(m_viewB, &ImageView::doubleClicked, this, &ViewPanel::onDoubleClicked); |
| 674 |
connect(m_viewB, &ImageView::clicked, this, &ViewPanel::onViewBClicked); |
| 675 |
connect(m_viewB, &ImageView::imageChanged, this, &ViewPanel::onViewBImageChanged); |
| 676 |
connect(m_viewB, &ImageView::sigFileDelete, this, &ViewPanel::onFileDelete); |
| 677 |
} |
| 678 |
|
| 679 |
void ViewPanel::openImage(const QString &path, bool bjudge) |
| 680 |
{ |
| 681 |
qDebug() << "---" << __FUNCTION__ << "---"; |
| 682 |
if (bjudge && m_currentpath == path) |
| 683 |
return; |
| 684 |
m_currentpath = path; |
| 685 |
m_viewB->setImage(path); //设置当前显示图片 |
| 686 |
//m_ttbc->setButtonDisabled(!QFileInfo(path).exists()); |
| 687 |
updateMenuContent(); |
| 688 |
if (!QFileInfo(path).exists()) { |
| 689 |
QImage img = ImageDataService::instance()->getThumnailImageByPath(path); |
| 690 |
m_emptyWidget->setThumbnailImage(QPixmap::fromImage(img)); |
| 691 |
m_stack->setCurrentIndex(1); |
| 692 |
} else if (!QFileInfo(path).isReadable()) { |
| 693 |
m_stack->setCurrentIndex(2); |
| 694 |
} else if (QFileInfo(path).isReadable() && !QFileInfo(path).isWritable()) { |
| 695 |
m_stack->setCurrentIndex(0); |
| 696 |
} else { |
| 697 |
m_stack->setCurrentIndex(0); |
| 698 |
|
| 699 |
// open success. |
| 700 |
DRecentData data; |
| 701 |
data.appName = "Deepin Image Viewer"; |
| 702 |
data.appExec = "deepin-image-viewer"; |
| 703 |
DRecentManager::addItem(path, data); |
| 704 |
} |
| 705 |
} |