| 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 "ttbcontent.h" |
| 22 |
#include "application.h" |
| 23 |
#include "utils/baseutils.h" |
| 24 |
#include "utils/imageutils.h" |
| 25 |
#include "utils/unionimage.h" |
| 26 |
|
| 27 |
#include "dbmanager/dbmanager.h" |
| 28 |
#include "controller/configsetter.h" |
| 29 |
#include "widgets/elidedlabel.h" |
| 30 |
#include "controller/signalmanager.h" |
| 31 |
#include "imageengine/imageengineapi.h" |
| 32 |
#include "ac-desktop-define.h" |
| 33 |
#include "imagedataservice.h" |
| 34 |
|
| 35 |
#include <QTimer> |
| 36 |
#include <QFileInfo> |
| 37 |
#include <QHBoxLayout> |
| 38 |
#include <QDebug> |
| 39 |
#include <QPainterPath> |
| 40 |
#include <DLabel> |
| 41 |
#include <QAbstractItemModel> |
| 42 |
#include <DImageButton> |
| 43 |
#include <DThumbnailProvider> |
| 44 |
#include <DApplicationHelper> |
| 45 |
#include <DSpinner> |
| 46 |
#include <QtMath> |
| 47 |
|
| 48 |
#include "imgviewlistview.h" |
| 49 |
#include "imgviewwidget.h" |
| 50 |
#include "mainwindow.h" |
| 51 |
DWIDGET_USE_NAMESPACE |
| 52 |
namespace { |
| 53 |
const int LEFT_MARGIN = 10; |
| 54 |
const QSize ICON_SIZE = QSize(50, 50); |
| 55 |
const int ICON_SPACING = 10; |
| 56 |
const int FILENAME_MAX_LENGTH = 600; |
| 57 |
const int RIGHT_TITLEBAR_WIDTH = 100; |
| 58 |
const QString LOCMAP_SELECTED_DARK = ":/resources/dark/images/58 drak.svg"; |
| 59 |
const QString LOCMAP_NOT_SELECTED_DARK = ":/resources/dark/images/imagewithbg-dark.svg"; |
| 60 |
const QString LOCMAP_SELECTED_LIGHT = ":/resources/light/images/58.svg"; |
| 61 |
const QString LOCMAP_NOT_SELECTED_LIGHT = ":/resources/light/images/imagewithbg.svg"; |
| 62 |
|
| 63 |
const int TOOLBAR_MINIMUN_WIDTH = 782; |
| 64 |
const int TOOLBAR_JUSTONE_WIDTH = 532; |
| 65 |
const int RT_SPACING = 20; |
| 66 |
const int TOOLBAR_HEIGHT = 60; |
| 67 |
|
| 68 |
const int TOOLBAR_DVALUE = 114 + 8; |
| 69 |
|
| 70 |
const int THUMBNAIL_WIDTH = 32; |
| 71 |
const int THUMBNAIL_ADD_WIDTH = 32; |
| 72 |
const int THUMBNAIL_LIST_ADJUST = 9; |
| 73 |
const int THUMBNAIL_VIEW_DVALUE = 668; |
| 74 |
|
| 75 |
const int LOAD_LEFT_RIGHT = 25; //前后加载图片数(动态) |
| 76 |
|
| 77 |
} // namespace |
| 78 |
|
| 79 |
TTBContent::TTBContent(bool inDB, QWidget *parent) : QLabel(parent) |
| 80 |
{ |
| 81 |
m_windowWidth = std::max(this->window()->width(), |
| 82 |
ConfigSetter::instance()->value("MAINWINDOW", "WindowWidth").toInt()); |
| 83 |
|
| 84 |
QHBoxLayout *hb = new QHBoxLayout(this); |
| 85 |
hb->setContentsMargins(LEFT_MARGIN, 0, LEFT_MARGIN, 3); |
| 86 |
hb->setSpacing(0); |
| 87 |
m_inDB = inDB; |
| 88 |
#ifndef LITE_DIV |
| 89 |
m_returnBtn = new ReturnButton(); |
| 90 |
m_returnBtn->setMaxWidth(RETURN_BTN_MAX); |
| 91 |
m_returnBtn->setMaximumWidth(RETURN_BTN_MAX); |
| 92 |
m_returnBtn->setObjectName("ReturnBtn"); |
| 93 |
m_returnBtn->setToolTip(tr("Back")); |
| 94 |
|
| 95 |
m_folderBtn = new PushButton(); |
| 96 |
m_folderBtn->setFixedSize(QSize(24, 24)); |
| 97 |
m_folderBtn->setObjectName("FolderBtn"); |
| 98 |
//AC_SET_OBJECT_NAME(m_folderBtn, Ttbcontent_Back_Button); |
| 99 |
//AC_SET_ACCESSIBLE_NAME(m_folderBtn, Ttbcontent_Back_Button); |
| 100 |
m_folderBtn->setToolTip("Image management"); |
| 101 |
if (m_inDB) { |
| 102 |
hb->addWidget(m_returnBtn); |
| 103 |
} else { |
| 104 |
hb->addWidget(m_folderBtn); |
| 105 |
} |
| 106 |
hb->addSpacing(20); |
| 107 |
|
| 108 |
connect(m_returnBtn, &ReturnButton::clicked, this, [ = ] { |
| 109 |
emit clicked(); |
| 110 |
}); |
| 111 |
connect(m_folderBtn, &PushButton::clicked, this, [ = ] { |
| 112 |
emit clicked(); |
| 113 |
}); |
| 114 |
connect(m_returnBtn, &ReturnButton::returnBtnWidthChanged, this, [ = ] { |
| 115 |
updateFilenameLayout(); |
| 116 |
}); |
| 117 |
#endif |
| 118 |
// Adapt buttons//////////////////////////////////////////////////////////// |
| 119 |
m_backButton = new DIconButton(this); |
| 120 |
m_backButton->setFixedSize(ICON_SIZE); |
| 121 |
AC_SET_OBJECT_NAME(m_backButton, Ttbcontent_Back_Button); |
| 122 |
AC_SET_ACCESSIBLE_NAME(m_backButton, Ttbcontent_Back_Button); |
| 123 |
m_backButton->setIcon(QIcon::fromTheme("dcc_back")); |
| 124 |
m_backButton->setIconSize(QSize(36, 36)); |
| 125 |
m_backButton->setToolTip(tr("Back")); |
| 126 |
|
| 127 |
hb->addWidget(m_backButton); |
| 128 |
hb->addStretch(); |
| 129 |
//hb->addSpacing(ICON_SPACING * 5); |
| 130 |
connect(m_backButton, &DIconButton::clicked, this, &TTBContent::onBackButtonClicked); |
| 131 |
|
| 132 |
// preButton |
| 133 |
m_preButton = new DIconButton(this); |
| 134 |
AC_SET_OBJECT_NAME(m_preButton, Ttbcontent_Pre_Button); |
| 135 |
AC_SET_ACCESSIBLE_NAME(m_preButton, Ttbcontent_Pre_Button); |
| 136 |
m_preButton->setFixedSize(ICON_SIZE); |
| 137 |
m_preButton->setIcon(QIcon::fromTheme("dcc_previous")); |
| 138 |
m_preButton->setIconSize(QSize(36, 36)); |
| 139 |
m_preButton->setToolTip(tr("Previous")); |
| 140 |
|
| 141 |
m_preButton->hide(); |
| 142 |
|
| 143 |
connect(m_preButton, &DIconButton::clicked, this, &TTBContent::onPreButton); |
| 144 |
// nextButton |
| 145 |
m_nextButton = new DIconButton(this); |
| 146 |
AC_SET_OBJECT_NAME(m_nextButton, Ttbcontent_Next_Button); |
| 147 |
AC_SET_ACCESSIBLE_NAME(m_nextButton, Ttbcontent_Next_Button); |
| 148 |
m_nextButton->setFixedSize(ICON_SIZE); |
| 149 |
m_nextButton->setIcon(QIcon::fromTheme("dcc_next")); |
| 150 |
m_nextButton->setIconSize(QSize(36, 36)); |
| 151 |
m_nextButton->setToolTip(tr("Next")); |
| 152 |
|
| 153 |
m_nextButton->hide(); |
| 154 |
|
| 155 |
connect(parent, SIGNAL(sigResize()), this, SLOT(onResize())); |
| 156 |
connect(m_nextButton, &DIconButton::clicked, this, &TTBContent::onNextButton); |
| 157 |
|
| 158 |
hb->addWidget(m_preButton); |
| 159 |
hb->addSpacing(ICON_SPACING); |
| 160 |
hb->addWidget(m_nextButton); |
| 161 |
hb->addSpacing(ICON_SPACING); |
| 162 |
|
| 163 |
// adaptImageBtn |
| 164 |
m_adaptImageBtn = new DIconButton(this); |
| 165 |
AC_SET_OBJECT_NAME(m_adaptImageBtn, Ttbcontent_AdaptImg_Button); |
| 166 |
AC_SET_ACCESSIBLE_NAME(m_adaptImageBtn, Ttbcontent_AdaptImg_Button); |
| 167 |
m_adaptImageBtn->setFixedSize(ICON_SIZE); |
| 168 |
m_adaptImageBtn->setIcon(QIcon::fromTheme("dcc_11")); |
| 169 |
m_adaptImageBtn->setIconSize(QSize(36, 36)); |
| 170 |
m_adaptImageBtn->setToolTip(tr("1:1 Size")); |
| 171 |
m_adaptImageBtn->setCheckable(true); |
| 172 |
|
| 173 |
|
| 174 |
hb->addWidget(m_adaptImageBtn); |
| 175 |
hb->addSpacing(ICON_SPACING); |
| 176 |
connect(m_adaptImageBtn, &DIconButton::clicked, this, &TTBContent::onAdaptImageBtnClicked); |
| 177 |
|
| 178 |
|
| 179 |
// adaptScreenBtn |
| 180 |
m_adaptScreenBtn = new DIconButton(this); |
| 181 |
m_adaptScreenBtn->setFixedSize(ICON_SIZE); |
| 182 |
AC_SET_OBJECT_NAME(m_adaptScreenBtn, Ttbcontent_AdaptScreen_Button); |
| 183 |
AC_SET_ACCESSIBLE_NAME(m_adaptScreenBtn, Ttbcontent_AdaptScreen_Button); |
| 184 |
m_adaptScreenBtn->setIcon(QIcon::fromTheme("dcc_fit")); |
| 185 |
m_adaptScreenBtn->setIconSize(QSize(36, 36)); |
| 186 |
m_adaptScreenBtn->setToolTip(tr("Fit to window")); |
| 187 |
// m_adaptScreenBtn->setCheckable(true); |
| 188 |
|
| 189 |
|
| 190 |
hb->addWidget(m_adaptScreenBtn); |
| 191 |
hb->addSpacing(ICON_SPACING); |
| 192 |
connect(m_adaptScreenBtn, &DIconButton::clicked, this, &TTBContent::onAdaptScreenBtnClicked); |
| 193 |
|
| 194 |
// Collection button |
| 195 |
m_clBT = new DIconButton(this); |
| 196 |
m_clBT->setFixedSize(ICON_SIZE); |
| 197 |
m_clBT->setToolTip(tr("Favorite")); |
| 198 |
m_clBT->setIcon(QIcon::fromTheme("dcc_collection_normal")); |
| 199 |
m_clBT->setIconSize(QSize(36, 36)); |
| 200 |
AC_SET_OBJECT_NAME(m_clBT, Ttbcontent_Collect_Button); |
| 201 |
AC_SET_ACCESSIBLE_NAME(m_clBT, Ttbcontent_Collect_Button); |
| 202 |
|
| 203 |
connect(m_clBT, &DIconButton::clicked, this, &TTBContent::onclBTClicked); |
| 204 |
|
| 205 |
hb->addWidget(m_clBT); |
| 206 |
hb->addSpacing(ICON_SPACING); |
| 207 |
|
| 208 |
// rotateLBtn |
| 209 |
m_rotateLBtn = new DIconButton(this); |
| 210 |
AC_SET_OBJECT_NAME(m_rotateLBtn, Ttbcontent_Rotate_Left_Button); |
| 211 |
AC_SET_ACCESSIBLE_NAME(m_rotateLBtn, Ttbcontent_Rotate_Left_Button); |
| 212 |
m_rotateLBtn->setFixedSize(ICON_SIZE); |
| 213 |
m_rotateLBtn->setIcon(QIcon::fromTheme("dcc_left")); |
| 214 |
m_rotateLBtn->setIconSize(QSize(36, 36)); |
| 215 |
m_rotateLBtn->setToolTip(tr("Rotate counterclockwise")); |
| 216 |
hb->addWidget(m_rotateLBtn); |
| 217 |
hb->addSpacing(ICON_SPACING); |
| 218 |
connect(m_rotateLBtn, &DIconButton::clicked, this, &TTBContent::onRotateLBtnClicked); |
| 219 |
|
| 220 |
// rotateRBtn |
| 221 |
m_rotateRBtn = new DIconButton(this); |
| 222 |
AC_SET_OBJECT_NAME(m_rotateRBtn, Ttbcontent_Rotate_Right_Button); |
| 223 |
AC_SET_ACCESSIBLE_NAME(m_rotateRBtn, Ttbcontent_Rotate_Right_Button); |
| 224 |
m_rotateRBtn->setFixedSize(ICON_SIZE); |
| 225 |
m_rotateRBtn->setIcon(QIcon::fromTheme("dcc_right")); |
| 226 |
m_rotateRBtn->setIconSize(QSize(36, 36)); |
| 227 |
m_rotateRBtn->setToolTip(tr("Rotate clockwise")); |
| 228 |
|
| 229 |
hb->addWidget(m_rotateRBtn); |
| 230 |
hb->addSpacing(ICON_SPACING + 8); |
| 231 |
connect(m_rotateRBtn, &DIconButton::clicked, this, &TTBContent::onRotateRBtnClicked); |
| 232 |
|
| 233 |
// imgListView |
| 234 |
m_imgListWidget = new MyImageListWidget(this); |
| 235 |
connect(m_imgListWidget, &MyImageListWidget::openImg, this, &TTBContent::feedBackCurrentIndex, Qt::QueuedConnection); |
| 236 |
// connect(m_imgListView, &MyImageListWidget::mouseLeftReleased, this, &TTBContent::updateScreen); |
| 237 |
|
| 238 |
//图片少的时候设置列表大小 |
| 239 |
//todo设置大小 |
| 240 |
// if (m_allfileslist.size() <= 3) { |
| 241 |
// m_imgListView->setFixedSize(QSize(TOOLBAR_DVALUE, TOOLBAR_HEIGHT)); |
| 242 |
// } else { |
| 243 |
// m_imgListView->setFixedSize(QSize(qMin((TOOLBAR_MINIMUN_WIDTH + THUMBNAIL_ADD_WIDTH * (m_allfileslist.size() - 3)), qMax(m_windowWidth - RT_SPACING, TOOLBAR_MINIMUN_WIDTH)) - THUMBNAIL_VIEW_DVALUE + THUMBNAIL_LIST_ADJUST, TOOLBAR_HEIGHT)); |
| 244 |
// } |
| 245 |
|
| 246 |
hb->addWidget(m_imgListWidget); |
| 247 |
hb->addSpacing(ICON_SPACING + 14); |
| 248 |
|
| 249 |
m_trashBtn = new DIconButton(this); |
| 250 |
m_trashBtn->setFixedSize(ICON_SIZE); |
| 251 |
AC_SET_OBJECT_NAME(m_trashBtn, Ttbcontent_Trash_Button); |
| 252 |
AC_SET_ACCESSIBLE_NAME(m_trashBtn, Ttbcontent_Trash_Button); |
| 253 |
m_trashBtn->setIcon(QIcon::fromTheme("dcc_delete")); |
| 254 |
m_trashBtn->setIconSize(QSize(36, 36)); |
| 255 |
m_trashBtn->setToolTip(tr("Delete")); |
| 256 |
|
| 257 |
hb->addWidget(m_trashBtn); |
| 258 |
hb->addSpacing(10); |
| 259 |
m_fileNameLabel = new ElidedLabel(); |
| 260 |
|
| 261 |
connect(m_trashBtn, &DIconButton::clicked, this, &TTBContent::onTrashBtnClicked); |
| 262 |
} |
| 263 |
|
| 264 |
void TTBContent::setAllFileInfo(const SignalManager::ViewInfo &info) |
| 265 |
{ |
| 266 |
qDebug() << "---" << __FUNCTION__ << "---"; |
| 267 |
if (info.paths.size() <= 1) { |
| 268 |
m_contentWidth = TOOLBAR_JUSTONE_WIDTH; |
| 269 |
} else if (info.paths.size() <= 3) { |
| 270 |
m_contentWidth = TOOLBAR_MINIMUN_WIDTH; |
| 271 |
m_preButton->setVisible(true); |
| 272 |
m_nextButton->setVisible(true); |
| 273 |
} else { |
| 274 |
m_preButton->setVisible(true); |
| 275 |
m_nextButton->setVisible(true); |
| 276 |
m_contentWidth = qMin((TOOLBAR_MINIMUN_WIDTH + THUMBNAIL_ADD_WIDTH * (info.paths.size() - 3)), qMax(m_windowWidth - RT_SPACING, TOOLBAR_MINIMUN_WIDTH)) + THUMBNAIL_LIST_ADJUST; |
| 277 |
} |
| 278 |
|
| 279 |
setFixedWidth(m_contentWidth); |
| 280 |
setFixedHeight(72); |
| 281 |
|
| 282 |
m_imgListWidget->setAllFile(info, info.path); |
| 283 |
} |
| 284 |
|
| 285 |
int TTBContent::getAllFileCount() |
| 286 |
{ |
| 287 |
int count = -1; |
| 288 |
if (m_imgListWidget) { |
| 289 |
count = m_imgListWidget->getImgCount(); |
| 290 |
} |
| 291 |
return count; |
| 292 |
} |
| 293 |
|
| 294 |
int TTBContent::itemLoadedSize() |
| 295 |
{ |
| 296 |
return m_imgListWidget->getImgCount(); |
| 297 |
} |
| 298 |
|
| 299 |
void TTBContent::updateScreen() |
| 300 |
{ |
| 301 |
//todo,不知道干啥的 |
| 302 |
} |
| 303 |
|
| 304 |
void TTBContent::disCheckAdaptImageBtn() |
| 305 |
{ |
| 306 |
qDebug() << "---" << __FUNCTION__ << "---"; |
| 307 |
m_adaptImageBtn->setChecked(false); |
| 308 |
badaptImageBtnChecked = false; |
| 309 |
} |
| 310 |
void TTBContent::disCheckAdaptScreenBtn() |
| 311 |
{ |
| 312 |
m_adaptScreenBtn->setChecked(false); |
| 313 |
badaptScreenBtnChecked = false; |
| 314 |
} |
| 315 |
|
| 316 |
void TTBContent::checkAdaptImageBtn() |
| 317 |
{ |
| 318 |
qDebug() << "---" << __FUNCTION__ << "---"; |
| 319 |
m_adaptImageBtn->setChecked(true); |
| 320 |
badaptImageBtnChecked = true; |
| 321 |
} |
| 322 |
void TTBContent::checkAdaptScreenBtn() |
| 323 |
{ |
| 324 |
m_adaptScreenBtn->setChecked(true); |
| 325 |
badaptScreenBtnChecked = true; |
| 326 |
} |
| 327 |
|
| 328 |
void TTBContent::deleteImage() |
| 329 |
{ |
| 330 |
if (m_imgListWidget && m_imgListWidget->getImgCount() >= 0) { |
| 331 |
//移除正在展示照片 |
| 332 |
m_imgListWidget->removeCurrent(); |
| 333 |
|
| 334 |
emit removed(); //删除数据库图片 |
| 335 |
onResize(); |
| 336 |
} |
| 337 |
} |
| 338 |
|
| 339 |
void TTBContent::updateFilenameLayout() |
| 340 |
{ |
| 341 |
using namespace utils::base; |
| 342 |
DFontSizeManager::instance()->bind(m_fileNameLabel, DFontSizeManager::T8); |
| 343 |
QFontMetrics fm(DFontSizeManager::instance()->get(DFontSizeManager::T8)); |
| 344 |
QString filename = QFileInfo(m_currentpath).fileName(); |
| 345 |
QString name; |
| 346 |
|
| 347 |
int strWidth = fm.boundingRect(filename).width(); |
| 348 |
int leftMargin = 0; |
| 349 |
int m_leftContentWidth = 0; |
| 350 |
#ifndef LITE_DIV |
| 351 |
if (m_inDB) |
| 352 |
m_leftContentWidth = m_returnBtn->buttonWidth() + 6 |
| 353 |
+ (ICON_SIZE.width() + 2) * 6 + LEFT_SPACE; |
| 354 |
else { |
| 355 |
m_leftContentWidth = m_folderBtn->width() + 8 |
| 356 |
+ (ICON_SIZE.width() + 2) * 5 + LEFT_SPACE; |
| 357 |
} |
| 358 |
#else |
| 359 |
// 39 为logo以及它的左右margin |
| 360 |
m_leftContentWidth = 5 + (ICON_SIZE.width() + 2) * 5 + 39; |
| 361 |
#endif |
| 362 |
|
| 363 |
int ww = dApp->setter->value("MAINWINDOW", "WindowWidth").toInt(); |
| 364 |
m_windowWidth = std::max(std::max(this->window()->geometry().width(), this->width()), ww); |
| 365 |
m_contentWidth = std::max(m_windowWidth - RIGHT_TITLEBAR_WIDTH + 2, 1); |
| 366 |
setFixedWidth(m_contentWidth); |
| 367 |
// setFixedWidth(dApp->getMainWindow()->width() - 20); |
| 368 |
m_contentWidth = this->width() - m_leftContentWidth; |
| 369 |
|
| 370 |
if (strWidth > m_contentWidth || strWidth > FILENAME_MAX_LENGTH) { |
| 371 |
name = fm.elidedText(filename, Qt::ElideMiddle, std::min(m_contentWidth - 32, |
| 372 |
FILENAME_MAX_LENGTH)); |
| 373 |
strWidth = fm.boundingRect(name).width(); |
| 374 |
leftMargin = std::max(0, (m_windowWidth - strWidth) / 2 |
| 375 |
- m_leftContentWidth - LEFT_MARGIN - 2); |
| 376 |
} else { |
| 377 |
leftMargin = std::max(0, (m_windowWidth - strWidth) / 2 |
| 378 |
- m_leftContentWidth - 6); |
| 379 |
name = filename; |
| 380 |
} |
| 381 |
|
| 382 |
m_fileNameLabel->setText(name, leftMargin); |
| 383 |
} |
| 384 |
|
| 385 |
void TTBContent::onBackButtonClicked() |
| 386 |
{ |
| 387 |
//2020/6/9 DJH 优化退出全屏,不再闪出退出全屏的间隙 31331 |
| 388 |
this->setVisible(false); |
| 389 |
emit dApp->signalM->hideImageView(); |
| 390 |
this->setVisible(true); |
| 391 |
emit dApp->signalM->sigPauseOrStart(false); //唤醒后台外设线程 |
| 392 |
#ifdef tablet_PC |
| 393 |
emit resetShoworHide(); |
| 394 |
#endif |
| 395 |
} |
| 396 |
|
| 397 |
void TTBContent::onAdaptImageBtnClicked() |
| 398 |
{ |
| 399 |
m_adaptImageBtn->setChecked(true); |
| 400 |
if (!badaptImageBtnChecked) { |
| 401 |
badaptImageBtnChecked = true; |
| 402 |
emit resetTransform(false); |
| 403 |
} |
| 404 |
} |
| 405 |
|
| 406 |
void TTBContent::onAdaptScreenBtnClicked() |
| 407 |
{ |
| 408 |
m_adaptScreenBtn->setChecked(true); |
| 409 |
if (!badaptScreenBtnChecked) { |
| 410 |
badaptScreenBtnChecked = true; |
| 411 |
emit resetTransform(true); |
| 412 |
} |
| 413 |
} |
| 414 |
|
| 415 |
void TTBContent::onclBTClicked() |
| 416 |
{ |
| 417 |
if (true == m_bClBTChecked) { |
| 418 |
DBManager::instance()->removeFromAlbum(COMMON_STR_FAVORITES, QStringList(m_currentpath), AlbumDBType::Favourite); |
| 419 |
} else { |
| 420 |
DBManager::instance()->insertIntoAlbum(COMMON_STR_FAVORITES, QStringList(m_currentpath), AlbumDBType::Favourite); |
| 421 |
emit dApp->signalM->insertedIntoAlbum(COMMON_STR_FAVORITES, QStringList(m_currentpath)); |
| 422 |
} |
| 423 |
} |
| 424 |
|
| 425 |
void TTBContent::onRotateLBtnClicked() |
| 426 |
{ |
| 427 |
emit rotateCounterClockwise(); |
| 428 |
} |
| 429 |
|
| 430 |
void TTBContent::onRotateRBtnClicked() |
| 431 |
{ |
| 432 |
emit rotateClockwise(); |
| 433 |
} |
| 434 |
|
| 435 |
void TTBContent::onTrashBtnClicked() |
| 436 |
{ |
| 437 |
emit dApp->signalM->deleteByMenu(); |
| 438 |
} |
| 439 |
|
| 440 |
void TTBContent::onNextButton() |
| 441 |
{ |
| 442 |
if (m_imgListWidget) { |
| 443 |
m_imgListWidget->openNext(); |
| 444 |
m_preButton->setEnabled(true); |
| 445 |
m_nextButton->setEnabled(!m_imgListWidget->isLast()); |
| 446 |
} |
| 447 |
} |
| 448 |
|
| 449 |
void TTBContent::onPreButton() |
| 450 |
{ |
| 451 |
if (m_imgListWidget) { |
| 452 |
m_imgListWidget->openPre(); |
| 453 |
m_preButton->setEnabled(!m_imgListWidget->isFirst()); |
| 454 |
m_nextButton->setEnabled(true); |
| 455 |
} |
| 456 |
} |
| 457 |
|
| 458 |
void TTBContent::resizeEvent(QResizeEvent *event) |
| 459 |
{ |
| 460 |
Q_UNUSED(event); |
| 461 |
m_windowWidth = this->window()->geometry().width(); |
| 462 |
if (m_imgListWidget->getImgCount() <= 1) { |
| 463 |
m_contentWidth = TOOLBAR_JUSTONE_WIDTH; |
| 464 |
} else if (m_imgListWidget->getImgCount() <= 3) { |
| 465 |
m_contentWidth = TOOLBAR_MINIMUN_WIDTH; |
| 466 |
//todo设置大小 |
| 467 |
// m_imgListView->setFixedSize(QSize(TOOLBAR_DVALUE, TOOLBAR_HEIGHT)); |
| 468 |
m_imgListWidget->setFixedSize(QSize(TOOLBAR_DVALUE, TOOLBAR_HEIGHT)); |
| 469 |
} else { |
| 470 |
m_contentWidth = qMin((TOOLBAR_MINIMUN_WIDTH + THUMBNAIL_ADD_WIDTH * (m_imgListWidget->getImgCount() - 3)), qMax(m_windowWidth - RT_SPACING, TOOLBAR_MINIMUN_WIDTH)) + THUMBNAIL_LIST_ADJUST; |
| 471 |
m_imgListWidget->setFixedSize(QSize(qMin((TOOLBAR_MINIMUN_WIDTH + THUMBNAIL_ADD_WIDTH * (m_imgListWidget->getImgCount() - 3)), qMax(m_windowWidth - RT_SPACING, TOOLBAR_MINIMUN_WIDTH)) - THUMBNAIL_VIEW_DVALUE + THUMBNAIL_LIST_ADJUST, TOOLBAR_HEIGHT)); |
| 472 |
} |
| 473 |
setFixedWidth(m_contentWidth); |
| 474 |
} |
| 475 |
|
| 476 |
|
| 477 |
void TTBContent::setImage(const QString &path) |
| 478 |
{ |
| 479 |
qDebug() << "---" << __FUNCTION__ << "---"; |
| 480 |
if ((m_imgListWidget->getImgCount() > 0) && !QFileInfo(path).exists()) { |
| 481 |
emit dApp->signalM->picNotExists(true); |
| 482 |
m_currentpath = path; |
| 483 |
if (m_imgListWidget->getImgCount() == 1) |
| 484 |
return; |
| 485 |
} else { |
| 486 |
emit dApp->signalM->picNotExists(false); |
| 487 |
} |
| 488 |
m_currentpath = path; |
| 489 |
|
| 490 |
//>1的判断用来解决右键打开时按钮状态不正确问题,不是很好,后期替换公共能力的时候使用新的方法判断 |
| 491 |
if (!ImageDataService::instance()->imageIsLoaded(path) && (m_imgListWidget->getImgCount() > 1)) { |
| 492 |
m_adaptImageBtn->setDisabled(true); |
| 493 |
m_adaptScreenBtn->setDisabled(true); |
| 494 |
m_rotateLBtn->setDisabled(true); |
| 495 |
m_rotateRBtn->setDisabled(true); |
| 496 |
} else { |
| 497 |
setCurrentItem(); |
| 498 |
} |
| 499 |
} |
| 500 |
|
| 501 |
bool TTBContent::setCurrentItem() |
| 502 |
{ |
| 503 |
if (m_currentpath.isEmpty() || !QFileInfo(m_currentpath).exists()) { |
| 504 |
m_adaptImageBtn->setDisabled(true); |
| 505 |
m_adaptScreenBtn->setDisabled(true); |
| 506 |
m_rotateLBtn->setDisabled(true); |
| 507 |
m_rotateRBtn->setDisabled(true); |
| 508 |
m_trashBtn->setDisabled(true); |
| 509 |
m_clBT->setDisabled(true); |
| 510 |
} else { |
| 511 |
m_adaptImageBtn->setDisabled(false); |
| 512 |
m_adaptScreenBtn->setDisabled(false); |
| 513 |
|
| 514 |
updateScreen(); |
| 515 |
m_trashBtn->setDisabled(false); |
| 516 |
|
| 517 |
if (UnionImage_NameSpace::canSave(m_currentpath) && QFile::permissions(m_currentpath).testFlag(QFile::WriteUser)) { |
| 518 |
m_rotateLBtn->setDisabled(false); |
| 519 |
m_rotateRBtn->setDisabled(false); |
| 520 |
} else { |
| 521 |
m_rotateLBtn->setEnabled(false); |
| 522 |
m_rotateRBtn->setEnabled(false); |
| 523 |
} |
| 524 |
} |
| 525 |
QString fileName = ""; |
| 526 |
if (m_currentpath != "") { |
| 527 |
fileName = QFileInfo(m_currentpath).fileName(); |
| 528 |
} |
| 529 |
emit dApp->signalM->updateFileName(fileName); |
| 530 |
// updateFilenameLayout(); |
| 531 |
updateCollectButton(); |
| 532 |
return true; |
| 533 |
} |
| 534 |
|
| 535 |
void TTBContent::updateCollectButton() |
| 536 |
{ |
| 537 |
if (m_currentpath.isEmpty()) { |
| 538 |
return; |
| 539 |
} |
| 540 |
if (DBManager::instance()->isImgExistInAlbum(COMMON_STR_FAVORITES, m_currentpath, AlbumDBType::Favourite)) { |
| 541 |
m_clBT->setToolTip(tr("Unfavorite")); |
| 542 |
m_clBT->setIcon(QIcon::fromTheme("dcc_ccollection")); |
| 543 |
m_clBT->setIconSize(QSize(36, 36)); |
| 544 |
m_bClBTChecked = true; |
| 545 |
} else { |
| 546 |
m_clBT->setToolTip(tr("Favorite")); |
| 547 |
DGuiApplicationHelper::ColorType themeType = DGuiApplicationHelper::instance()->themeType(); |
| 548 |
Q_UNUSED(themeType); |
| 549 |
m_clBT->setIcon(QIcon::fromTheme("dcc_collection_normal")); |
| 550 |
m_clBT->setIconSize(QSize(36, 36)); |
| 551 |
m_bClBTChecked = false; |
| 552 |
} |
| 553 |
} |
| 554 |
|
| 555 |
void TTBContent::onResize() |
| 556 |
{ |
| 557 |
m_windowWidth = this->window()->geometry().width(); |
| 558 |
if (m_imgListWidget->getImgCount() <= 1) { |
| 559 |
m_preButton->setVisible(false); |
| 560 |
m_nextButton->setVisible(false); |
| 561 |
m_contentWidth = TOOLBAR_JUSTONE_WIDTH; |
| 562 |
} else if (m_imgListWidget->getImgCount() <= 3) { |
| 563 |
m_contentWidth = TOOLBAR_MINIMUN_WIDTH; |
| 564 |
//todo设置大小 |
| 565 |
// m_imgListView->setFixedSize(QSize(TOOLBAR_DVALUE, TOOLBAR_HEIGHT)); |
| 566 |
m_imgListWidget->setFixedSize(QSize(TOOLBAR_DVALUE, TOOLBAR_HEIGHT)); |
| 567 |
} else { |
| 568 |
m_contentWidth = qMin((TOOLBAR_MINIMUN_WIDTH + THUMBNAIL_ADD_WIDTH * (m_imgListWidget->getImgCount() - 3)), qMax(m_windowWidth - RT_SPACING, TOOLBAR_MINIMUN_WIDTH)) + THUMBNAIL_LIST_ADJUST; |
| 569 |
//todo设置大小 |
| 570 |
// m_imgListView->setFixedSize(QSize(qMin((TOOLBAR_MINIMUN_WIDTH + THUMBNAIL_ADD_WIDTH * (m_filelist_size - 3)), qMax(m_windowWidth - RT_SPACING, TOOLBAR_MINIMUN_WIDTH)) - THUMBNAIL_VIEW_DVALUE + THUMBNAIL_LIST_ADJUST, TOOLBAR_HEIGHT)); |
| 571 |
m_imgListWidget->setFixedSize(QSize(qMin((TOOLBAR_MINIMUN_WIDTH + THUMBNAIL_ADD_WIDTH * (m_imgListWidget->getImgCount() - 3)), qMax(m_windowWidth - RT_SPACING, TOOLBAR_MINIMUN_WIDTH)) - THUMBNAIL_VIEW_DVALUE + THUMBNAIL_LIST_ADJUST, TOOLBAR_HEIGHT)); |
| 572 |
} |
| 573 |
setFixedWidth(m_contentWidth); |
| 574 |
} |