| 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 "leftlistview.h" |
| 22 |
#include "widgets/albumlefttabitem.h" |
| 23 |
#include "dbmanager/dbmanager.h" |
| 24 |
#include "application.h" |
| 25 |
#include "controller/configsetter.h" |
| 26 |
#include "utils/baseutils.h" |
| 27 |
#include "dbmanager/dbmanager.h" |
| 28 |
#include "controller/exporter.h" |
| 29 |
#include "imageengine/imageengineapi.h" |
| 30 |
#include "dialogs/albumcreatedialog.h" |
| 31 |
#include "ac-desktop-define.h" |
| 32 |
#include <QVBoxLayout> |
| 33 |
#include <QHBoxLayout> |
| 34 |
#include <DFontSizeManager> |
| 35 |
#include <DStyledItemDelegate> |
| 36 |
|
| 37 |
namespace { |
| 38 |
const int OPE_MODE_ADDNEWALBUM = 0; |
| 39 |
const int OPE_MODE_RENAMEALBUM = 1; |
| 40 |
const int LEFT_VIEW_WIDTH_180 = 180; |
| 41 |
const int LEFT_VIEW_LISTITEM_WIDTH_160 = 160; |
| 42 |
const int LEFT_VIEW_LISTITEM_HEIGHT_40 = 40; |
| 43 |
const QString SHORTCUTVIEW_GROUP = "SHORTCUTVIEW"; |
| 44 |
|
| 45 |
QString ss(const QString &text) |
| 46 |
{ |
| 47 |
QString str = dApp->setter->value(SHORTCUTVIEW_GROUP, text).toString(); |
| 48 |
str.replace(" ", ""); |
| 49 |
return str; |
| 50 |
} |
| 51 |
}; |
| 52 |
|
| 53 |
LeftListView::LeftListView(QWidget *parent) |
| 54 |
: DScrollArea(parent), m_pPhotoLibLabel(nullptr), m_pPhotoLibListView(nullptr) |
| 55 |
, m_pCustomizeLabel(nullptr), m_pAddListBtn(nullptr), m_pCustomizeListView(nullptr) |
| 56 |
, m_pMountLabel(nullptr), m_pMountListWidget(nullptr), m_pMountWidget(nullptr) |
| 57 |
, m_ItemCurrentName(COMMON_STR_RECENT_IMPORTED) |
| 58 |
, m_ItemCurrentType(COMMON_STR_RECENT_IMPORTED) |
| 59 |
, m_pMenu(nullptr) |
| 60 |
{ |
| 61 |
m_ItemCurrentDataType = 0; |
| 62 |
initUI(); |
| 63 |
initMenu(); |
| 64 |
initConnections(); |
| 65 |
} |
| 66 |
|
| 67 |
void LeftListView::initConnections() |
| 68 |
{ |
| 69 |
connect(m_pPhotoLibListView, &DListWidget::pressed, this, &LeftListView::onPhotoLibListViewPressed); |
| 70 |
connect(m_pCustomizeListView, &DListWidget::pressed, this, &LeftListView::onCustomListViewPressed); |
| 71 |
connect(m_pMountListWidget, &DListWidget::pressed, this, &LeftListView::onMountListViewPressed); |
| 72 |
connect(m_pPhotoLibListView, &DListWidget::currentItemChanged, this, &LeftListView::onPhotoLibListViewCurrentItemChanged); |
| 73 |
connect(m_pCustomizeListView, &DListWidget::currentItemChanged, this, &LeftListView::onCustomizeListViewCurrentItemChanged); |
| 74 |
connect(m_pMountListWidget, &DListWidget::currentItemChanged, this, &LeftListView::onMountListWidgetCurrentItemChanged); |
| 75 |
connect(m_pCustomizeListView, &QListView::customContextMenuRequested, this, &LeftListView::showMenu); |
| 76 |
connect(m_pMenu, &DMenu::triggered, this, &LeftListView::onMenuClicked); |
| 77 |
connect(m_pAddListBtn, &DPushButton::clicked, this, &LeftListView::onAddListBtnClicked); |
| 78 |
connect(DApplicationHelper::instance(), &DApplicationHelper::themeTypeChanged, this, &LeftListView::onApplicationHelperThemeTypeChanged); |
| 79 |
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, &LeftListView::onGuiApplicationHelperThemeTypeChanged); |
| 80 |
connect(m_pMountListWidget, &LeftListWidget::sigMousePressIsNoValid, this, &LeftListView::onMousePressIsNoValid); |
| 81 |
} |
| 82 |
|
| 83 |
void LeftListView::initUI() |
| 84 |
{ |
| 85 |
|
| 86 |
setFrameShape(QFrame::NoFrame); |
| 87 |
setWidgetResizable(true); |
| 88 |
setFixedWidth(180); |
| 89 |
setBackgroundRole(DPalette::Base); |
| 90 |
setAutoFillBackground(true); |
| 91 |
|
| 92 |
QWidget *widget = new QWidget(this); |
| 93 |
setWidget(widget); |
| 94 |
widget->setFixedWidth(180); |
| 95 |
auto pMainLayout = new QVBoxLayout(widget); |
| 96 |
pMainLayout->setContentsMargins(0, 0, 0, 0); |
| 97 |
pMainLayout->setSpacing(0); |
| 98 |
|
| 99 |
// 照片库Title |
| 100 |
DWidget *photowidget = new DWidget; |
| 101 |
QHBoxLayout *pPhotoLibLayout = new QHBoxLayout(); |
| 102 |
pPhotoLibLayout->setContentsMargins(20, 0, 0, 0); |
| 103 |
photowidget->setLayout(pPhotoLibLayout); |
| 104 |
photowidget->setFixedHeight(40); |
| 105 |
|
| 106 |
m_pPhotoLibLabel = new DLabel(); |
| 107 |
DFontSizeManager::instance()->bind(m_pPhotoLibLabel, DFontSizeManager::T6, QFont::Medium); |
| 108 |
m_pPhotoLibLabel->setForegroundRole(DPalette::TextTips); |
| 109 |
m_pPhotoLibLabel->setText(tr("Gallery")); |
| 110 |
pPhotoLibLayout->addWidget(m_pPhotoLibLabel); |
| 111 |
pPhotoLibLayout->addStretch(); |
| 112 |
// 照片库列表 |
| 113 |
m_pPhotoLibListView = new LeftListWidget(); |
| 114 |
m_pPhotoLibListView->setFocusPolicy(Qt::NoFocus); |
| 115 |
DStyledItemDelegate *itemDelegate0 = new DStyledItemDelegate(m_pPhotoLibListView); |
| 116 |
itemDelegate0->setBackgroundType(DStyledItemDelegate::NoBackground); |
| 117 |
m_pPhotoLibListView->setItemDelegate(itemDelegate0); |
| 118 |
|
| 119 |
m_pPhotoLibListView->setFixedWidth(LEFT_VIEW_WIDTH_180); |
| 120 |
m_pPhotoLibListView->setFixedHeight(120); |
| 121 |
m_pPhotoLibListView->setSpacing(0); |
| 122 |
m_pPhotoLibListView->setFrameShape(DListWidget::NoFrame); |
| 123 |
m_pPhotoLibListView->setContextMenuPolicy(Qt::CustomContextMenu); |
| 124 |
|
| 125 |
// 已导入 |
| 126 |
QListWidgetItem *pListWidgetItem1 = new QListWidgetItem(m_pPhotoLibListView); |
| 127 |
pListWidgetItem1->setSizeHint(QSize(LEFT_VIEW_LISTITEM_WIDTH_160, LEFT_VIEW_LISTITEM_HEIGHT_40)); |
| 128 |
|
| 129 |
AlbumLeftTabItem *pAlbumLeftTabItem1 = new AlbumLeftTabItem(COMMON_STR_RECENT_IMPORTED); |
| 130 |
pAlbumLeftTabItem1->setFixedWidth(LEFT_VIEW_LISTITEM_WIDTH_160); |
| 131 |
pAlbumLeftTabItem1->setFixedHeight(LEFT_VIEW_LISTITEM_HEIGHT_40); |
| 132 |
|
| 133 |
pAlbumLeftTabItem1->setFocusPolicy(Qt::NoFocus); |
| 134 |
m_pPhotoLibListView->setItemWidget(pListWidgetItem1, pAlbumLeftTabItem1); |
| 135 |
|
| 136 |
// 最新删除 |
| 137 |
QListWidgetItem *pListWidgetItem2 = new QListWidgetItem(m_pPhotoLibListView); |
| 138 |
pListWidgetItem2->setSizeHint(QSize(LEFT_VIEW_LISTITEM_WIDTH_160, LEFT_VIEW_LISTITEM_HEIGHT_40)); |
| 139 |
AlbumLeftTabItem *pAlbumLeftTabItem2 = new AlbumLeftTabItem(COMMON_STR_TRASH); |
| 140 |
pAlbumLeftTabItem2->setFixedWidth(LEFT_VIEW_LISTITEM_WIDTH_160); |
| 141 |
pAlbumLeftTabItem2->setFixedHeight(LEFT_VIEW_LISTITEM_HEIGHT_40); |
| 142 |
m_pPhotoLibListView->setItemWidget(pListWidgetItem2, pAlbumLeftTabItem2); |
| 143 |
|
| 144 |
// 我的收藏 |
| 145 |
QListWidgetItem *pListWidgetItem3 = new QListWidgetItem(m_pPhotoLibListView); |
| 146 |
pListWidgetItem3->setSizeHint(QSize(LEFT_VIEW_LISTITEM_WIDTH_160, LEFT_VIEW_LISTITEM_HEIGHT_40)); |
| 147 |
AlbumLeftTabItem *pAlbumLeftTabItem3 = new AlbumLeftTabItem(COMMON_STR_FAVORITES); |
| 148 |
pAlbumLeftTabItem3->setFixedWidth(LEFT_VIEW_LISTITEM_WIDTH_160); |
| 149 |
pAlbumLeftTabItem3->setFixedHeight(LEFT_VIEW_LISTITEM_HEIGHT_40); |
| 150 |
m_pPhotoLibListView->setItemWidget(pListWidgetItem3, pAlbumLeftTabItem3); |
| 151 |
|
| 152 |
// 相册列表Title |
| 153 |
DWidget *lableCustomixeWidget = new DWidget(this); |
| 154 |
lableCustomixeWidget->setFixedHeight(40); |
| 155 |
QHBoxLayout *pCustomizeLayout = new QHBoxLayout(); |
| 156 |
pCustomizeLayout->setContentsMargins(20, 0, 14, 0); |
| 157 |
m_pCustomizeLabel = new DLabel(); |
| 158 |
DFontSizeManager::instance()->bind(m_pCustomizeLabel, DFontSizeManager::T6, QFont::Medium); |
| 159 |
m_pCustomizeLabel->setForegroundRole(DPalette::TextTips); |
| 160 |
m_pCustomizeLabel->setText(tr("Albums")); |
| 161 |
m_pAddListBtn = new AlbumImageButton(); |
| 162 |
AC_SET_OBJECT_NAME(m_pAddListBtn, Add_Album_Button); |
| 163 |
AC_SET_ACCESSIBLE_NAME(m_pAddListBtn, Add_Album_Button); |
| 164 |
DGuiApplicationHelper::ColorType themeType = DGuiApplicationHelper::instance()->themeType(); |
| 165 |
if (themeType == DGuiApplicationHelper::LightType) { |
| 166 |
m_pAddListBtn->setPropertyPic(":/resources/images/sidebar/normal/add_normal.svg", |
| 167 |
":/resources/images/sidebar/active/add_hover.svg", |
| 168 |
":/resources/images/sidebar/active/add_press.svg", |
| 169 |
":/resources/images/sidebar/active/add_focus.svg"); |
| 170 |
} |
| 171 |
if (themeType == DGuiApplicationHelper::DarkType) { |
| 172 |
m_pAddListBtn->setPropertyPic(":/resources/images/sidebar/active/add_normal_dark.svg", |
| 173 |
":/resources/images/sidebar/active/add_hover_dark.svg", |
| 174 |
":/resources/images/sidebar/active/add_press_dark.svg", |
| 175 |
":/resources/images/sidebar/active/add_focus_dark.svg"); |
| 176 |
} |
| 177 |
|
| 178 |
m_pAddListBtn->setFixedSize(34, 34); |
| 179 |
m_pAddListBtn->setFocusPolicy(Qt::NoFocus); |
| 180 |
pCustomizeLayout->addWidget(m_pCustomizeLabel, 100, Qt::AlignLeft); |
| 181 |
pCustomizeLayout->addWidget(m_pAddListBtn, 0, Qt::AlignRight | Qt::AlignVCenter); |
| 182 |
|
| 183 |
// 相册列表 |
| 184 |
m_pCustomizeListView = new LeftListWidget(); |
| 185 |
m_pCustomizeListView->setFocusPolicy(Qt::NoFocus); |
| 186 |
DStyledItemDelegate *itemDelegate1 = new DStyledItemDelegate(m_pCustomizeListView); |
| 187 |
itemDelegate1->setBackgroundType(DStyledItemDelegate::NoBackground); |
| 188 |
m_pCustomizeListView->setItemDelegate(itemDelegate1); |
| 189 |
m_pCustomizeListView->setSpacing(0); |
| 190 |
m_pCustomizeListView->setFrameShape(DListWidget::NoFrame); |
| 191 |
m_pCustomizeListView->setContextMenuPolicy(Qt::CustomContextMenu); |
| 192 |
|
| 193 |
QStringList allAlbumNames = DBManager::instance()->getAllAlbumNames(); |
| 194 |
for (auto albumName : allAlbumNames) { |
| 195 |
QListWidgetItem *pListWidgetItem = new QListWidgetItem(m_pCustomizeListView, 1); |
| 196 |
pListWidgetItem->setSizeHint(QSize(LEFT_VIEW_LISTITEM_WIDTH_160 /*+ 8*/, LEFT_VIEW_LISTITEM_HEIGHT_40)); |
| 197 |
|
| 198 |
AlbumLeftTabItem *pAlbumLeftTabItem = new AlbumLeftTabItem(albumName, COMMON_STR_CREATEALBUM); |
| 199 |
pAlbumLeftTabItem->setFixedWidth(LEFT_VIEW_LISTITEM_WIDTH_160 /*+ 8*/); |
| 200 |
pAlbumLeftTabItem->setFixedHeight(LEFT_VIEW_LISTITEM_HEIGHT_40); |
| 201 |
m_pCustomizeListView->setItemWidget(pListWidgetItem, pAlbumLeftTabItem); |
| 202 |
} |
| 203 |
// 设备Widget |
| 204 |
QVBoxLayout *pMountVLayout = new QVBoxLayout(this); |
| 205 |
pMountVLayout->setContentsMargins(0, 0, 0, 0); |
| 206 |
|
| 207 |
// 设备Title |
| 208 |
m_pMountWidget = new DWidget(this); |
| 209 |
m_pMountWidget->setVisible(false); |
| 210 |
m_pMountWidget->setFixedHeight(40); |
| 211 |
QHBoxLayout *pMountLayout = new QHBoxLayout(); |
| 212 |
pMountLayout->setContentsMargins(20, 0, 0, 0); |
| 213 |
m_pMountLabel = new DLabel(); |
| 214 |
DFontSizeManager::instance()->bind(m_pMountLabel, DFontSizeManager::T6, QFont::Medium); |
| 215 |
m_pMountLabel->setForegroundRole(DPalette::TextTips); |
| 216 |
m_pMountLabel->setText(tr("Device")); |
| 217 |
pMountLayout->addWidget(m_pMountLabel); |
| 218 |
pMountLayout->addStretch(); |
| 219 |
|
| 220 |
// 设备列表 |
| 221 |
m_pMountListWidget = new LeftListWidget(); |
| 222 |
m_pMountListWidget->setFocusPolicy(Qt::NoFocus); |
| 223 |
m_pMountListWidget->setVisible(false); |
| 224 |
DStyledItemDelegate *itemDelegate2 = new DStyledItemDelegate(m_pMountListWidget); |
| 225 |
itemDelegate2->setBackgroundType(DStyledItemDelegate::NoBackground); |
| 226 |
m_pMountListWidget->setItemDelegate(itemDelegate2); |
| 227 |
|
| 228 |
m_pMountListWidget->setSpacing(0); |
| 229 |
m_pMountListWidget->setFrameShape(DListWidget::NoFrame); |
| 230 |
|
| 231 |
pMainLayout->addWidget(photowidget); |
| 232 |
pMainLayout->addWidget(m_pPhotoLibListView); |
| 233 |
|
| 234 |
m_pMountWidget->setLayout(pMountLayout); |
| 235 |
pMainLayout->addWidget(m_pMountWidget); |
| 236 |
pMainLayout->addWidget(m_pMountListWidget); |
| 237 |
|
| 238 |
lableCustomixeWidget->setLayout(pCustomizeLayout); |
| 239 |
pMainLayout->addWidget(lableCustomixeWidget); |
| 240 |
pMainLayout->addWidget(m_pCustomizeListView); |
| 241 |
pMainLayout->addStretch(); |
| 242 |
onUpdateLeftListview(); |
| 243 |
} |
| 244 |
void LeftListView::updatePhotoListView() |
| 245 |
{ |
| 246 |
m_pPhotoLibListView->clear(); |
| 247 |
// 已导入 |
| 248 |
QListWidgetItem *pListWidgetItem1 = new QListWidgetItem(m_pPhotoLibListView); |
| 249 |
pListWidgetItem1->setSizeHint(QSize(LEFT_VIEW_LISTITEM_WIDTH_160, LEFT_VIEW_LISTITEM_HEIGHT_40)); |
| 250 |
|
| 251 |
AlbumLeftTabItem *pAlbumLeftTabItem1 = new AlbumLeftTabItem(COMMON_STR_RECENT_IMPORTED); |
| 252 |
pAlbumLeftTabItem1->setFixedWidth(LEFT_VIEW_LISTITEM_WIDTH_160); |
| 253 |
pAlbumLeftTabItem1->setFixedHeight(LEFT_VIEW_LISTITEM_HEIGHT_40); |
| 254 |
m_pPhotoLibListView->setItemWidget(pListWidgetItem1, pAlbumLeftTabItem1); |
| 255 |
|
| 256 |
// 最新删除 |
| 257 |
QListWidgetItem *pListWidgetItem2 = new QListWidgetItem(m_pPhotoLibListView); |
| 258 |
pListWidgetItem2->setSizeHint(QSize(LEFT_VIEW_LISTITEM_WIDTH_160, LEFT_VIEW_LISTITEM_HEIGHT_40)); |
| 259 |
|
| 260 |
AlbumLeftTabItem *pAlbumLeftTabItem2 = new AlbumLeftTabItem(COMMON_STR_TRASH); |
| 261 |
pAlbumLeftTabItem2->setFixedWidth(LEFT_VIEW_LISTITEM_WIDTH_160); |
| 262 |
pAlbumLeftTabItem2->setFixedHeight(LEFT_VIEW_LISTITEM_HEIGHT_40); |
| 263 |
m_pPhotoLibListView->setItemWidget(pListWidgetItem2, pAlbumLeftTabItem2); |
| 264 |
|
| 265 |
// 我的收藏 |
| 266 |
QListWidgetItem *pListWidgetItem3 = new QListWidgetItem(m_pPhotoLibListView); |
| 267 |
pListWidgetItem3->setSizeHint(QSize(LEFT_VIEW_LISTITEM_WIDTH_160, LEFT_VIEW_LISTITEM_HEIGHT_40)); |
| 268 |
|
| 269 |
AlbumLeftTabItem *pAlbumLeftTabItem3 = new AlbumLeftTabItem(COMMON_STR_FAVORITES); |
| 270 |
pAlbumLeftTabItem3->setFixedWidth(LEFT_VIEW_LISTITEM_WIDTH_160); |
| 271 |
pAlbumLeftTabItem3->setFixedHeight(LEFT_VIEW_LISTITEM_HEIGHT_40); |
| 272 |
m_pPhotoLibListView->setItemWidget(pListWidgetItem3, pAlbumLeftTabItem3); |
| 273 |
|
| 274 |
m_pPhotoLibListView->setCurrentRow(0); |
| 275 |
QModelIndex index; |
| 276 |
emit m_pPhotoLibListView->pressed(index); |
| 277 |
} |
| 278 |
|
| 279 |
void LeftListView::updateCustomizeListView() |
| 280 |
{ |
| 281 |
m_pCustomizeListView->clear(); |
| 282 |
QStringList allAlbumNames = DBManager::instance()->getAllAlbumNames(); |
| 283 |
for (auto albumName : allAlbumNames) { |
| 284 |
QListWidgetItem *pListWidgetItem = new QListWidgetItem(m_pCustomizeListView); |
| 285 |
pListWidgetItem->setSizeHint(QSize(LEFT_VIEW_LISTITEM_WIDTH_160, LEFT_VIEW_LISTITEM_HEIGHT_40)); |
| 286 |
|
| 287 |
AlbumLeftTabItem *pAlbumLeftTabItem = new AlbumLeftTabItem(albumName); |
| 288 |
pAlbumLeftTabItem->setFixedWidth(LEFT_VIEW_LISTITEM_WIDTH_160); |
| 289 |
pAlbumLeftTabItem->setFixedHeight(LEFT_VIEW_LISTITEM_HEIGHT_40); |
| 290 |
m_pCustomizeListView->setItemWidget(pListWidgetItem, pAlbumLeftTabItem); |
| 291 |
} |
| 292 |
} |
| 293 |
|
| 294 |
void LeftListView::initMenu() |
| 295 |
{ |
| 296 |
m_pMenu = new DMenu(this); |
| 297 |
m_MenuActionMap.clear(); |
| 298 |
appendAction(IdStartSlideShow, tr("Slide show"), ss("")); |
| 299 |
appendAction(IdCreateAlbum, tr("New album"), ss("")); |
| 300 |
appendAction(IdRenameAlbum, tr("Rename"), ss("")); |
| 301 |
m_pMenu->addSeparator(); |
| 302 |
appendAction(IdExport, tr("Export"), ss("")); |
| 303 |
appendAction(IdDeleteAlbum, tr("Delete"), ss("THROWTOTRASH_CONTEXT_MENU")); |
| 304 |
} |
| 305 |
|
| 306 |
void LeftListView::appendAction(int id, const QString &text, const QString &shortcut) |
| 307 |
{ |
| 308 |
QAction *ac = new QAction(m_pMenu); |
| 309 |
addAction(ac); |
| 310 |
ac->setText(text); |
| 311 |
ac->setProperty("MenuID", id); |
| 312 |
ac->setShortcut(QKeySequence(shortcut)); |
| 313 |
m_MenuActionMap.insert(text, ac); |
| 314 |
m_pMenu->addAction(ac); |
| 315 |
} |
| 316 |
|
| 317 |
void LeftListView::showMenu(const QPoint &pos) |
| 318 |
{ |
| 319 |
if (!m_pCustomizeListView->indexAt(pos).isValid()) { |
| 320 |
return; |
| 321 |
} |
| 322 |
m_pMenu->setVisible(true); |
| 323 |
foreach (QAction *action, m_MenuActionMap.values()) { |
| 324 |
action->setVisible(true); |
| 325 |
action->setEnabled(true); |
| 326 |
} |
| 327 |
|
| 328 |
if (0 < DBManager::instance()->getItemsCountByAlbum(m_ItemCurrentName, ItemTypeVideo)) { |
| 329 |
m_MenuActionMap.value(tr("Export"))->setVisible(false); |
| 330 |
} |
| 331 |
|
| 332 |
if (0 == DBManager::instance()->getItemsCountByAlbum(m_ItemCurrentName, ItemTypePic)) { |
| 333 |
m_MenuActionMap.value(tr("Slide show"))->setVisible(false); |
| 334 |
m_MenuActionMap.value(tr("Export"))->setVisible(false); |
| 335 |
} |
| 336 |
m_pMenu->popup(QCursor::pos()); |
| 337 |
} |
| 338 |
|
| 339 |
void LeftListView::onMenuClicked(QAction *action) |
| 340 |
{ |
| 341 |
const int id = action->property("MenuID").toInt(); |
| 342 |
switch (MenuItemId(id)) { |
| 343 |
case IdStartSlideShow: { |
| 344 |
auto imagelist = DBManager::instance()->getInfosByAlbum(m_ItemCurrentName); |
| 345 |
QStringList paths; |
| 346 |
for (auto image : imagelist) { |
| 347 |
paths << image.filePath; |
| 348 |
} |
| 349 |
if (paths.length() > 0) { |
| 350 |
const QString path = paths.first(); |
| 351 |
emit sigSlideShow(path); |
| 352 |
} |
| 353 |
break; |
| 354 |
} |
| 355 |
case IdCreateAlbum: { |
| 356 |
QListWidgetItem *pListWidgetItem = new QListWidgetItem(); |
| 357 |
pListWidgetItem->setSizeHint(QSize(LEFT_VIEW_LISTITEM_WIDTH_160, LEFT_VIEW_LISTITEM_HEIGHT_40)); |
| 358 |
m_pCustomizeListView->insertItem(m_pCustomizeListView->currentRow() + 1, pListWidgetItem); |
| 359 |
AlbumLeftTabItem *pAlbumLeftTabItem = new AlbumLeftTabItem(getNewAlbumName()); |
| 360 |
m_pCustomizeListView->setItemWidget(pListWidgetItem, pAlbumLeftTabItem); |
| 361 |
m_pCustomizeListView->setCurrentRow(m_pCustomizeListView->currentRow() + 1); |
| 362 |
AlbumLeftTabItem *item = dynamic_cast<AlbumLeftTabItem *>(m_pCustomizeListView->itemWidget(m_pCustomizeListView->currentItem())); |
| 363 |
item->m_opeMode = OPE_MODE_ADDNEWALBUM; |
| 364 |
item->editAlbumEdit(); |
| 365 |
onUpdateLeftListview(); |
| 366 |
break; |
| 367 |
} |
| 368 |
case IdRenameAlbum: { |
| 369 |
AlbumLeftTabItem *item = dynamic_cast<AlbumLeftTabItem *>(m_pCustomizeListView->itemWidget(m_pCustomizeListView->currentItem())); |
| 370 |
item->m_opeMode = OPE_MODE_RENAMEALBUM; |
| 371 |
item->editAlbumEdit(); |
| 372 |
break; |
| 373 |
} |
| 374 |
case IdExport: { |
| 375 |
Exporter::instance()->exportAlbum(DBManager::instance()->getPathsByAlbum(m_ItemCurrentName), m_ItemCurrentName); |
| 376 |
break; |
| 377 |
} |
| 378 |
case IdDeleteAlbum: { |
| 379 |
QListWidgetItem *item = m_pCustomizeListView->currentItem(); |
| 380 |
AlbumLeftTabItem *pTabItem = dynamic_cast<AlbumLeftTabItem *>(m_pCustomizeListView->itemWidget(item)); |
| 381 |
deletDialg = new AlbumDeleteDialog; |
| 382 |
connect(deletDialg, &AlbumDeleteDialog::deleteAlbum, this, [ = ]() { |
| 383 |
QString str = pTabItem->m_albumNameStr; |
| 384 |
QStringList paths = DBManager::instance()->getPathsByAlbum(pTabItem->m_albumNameStr); |
| 385 |
ImageEngineApi::instance()->moveImagesToTrash(paths); |
| 386 |
DBManager::instance()->removeAlbum(pTabItem->m_albumNameStr); |
| 387 |
|
| 388 |
if (1 < m_pCustomizeListView->count()) { |
| 389 |
delete item; |
| 390 |
emit updateCurrentItemType(1); |
| 391 |
} else { |
| 392 |
updateCustomizeListView(); |
| 393 |
updatePhotoListView(); |
| 394 |
emit updateCurrentItemType(0); |
| 395 |
} |
| 396 |
//移除item后更新右边视图 |
| 397 |
//updateRightView(); |
| 398 |
emit sigLeftTabClicked(); |
| 399 |
onUpdateLeftListview(); |
| 400 |
emit dApp->signalM->sigAlbDelToast(str); |
| 401 |
}); |
| 402 |
deletDialg->show(); |
| 403 |
break; |
| 404 |
} |
| 405 |
} |
| 406 |
} |
| 407 |
|
| 408 |
void LeftListView::onUpdateLeftListview() |
| 409 |
{ |
| 410 |
if (m_pCustomizeListView->count() > 0) { |
| 411 |
m_pCustomizeListView->setFixedHeight(m_pCustomizeListView->count() * LEFT_VIEW_LISTITEM_HEIGHT_40); |
| 412 |
} else { |
| 413 |
m_pCustomizeListView->setFixedHeight(LEFT_VIEW_LISTITEM_HEIGHT_40); |
| 414 |
} |
| 415 |
} |
| 416 |
|
| 417 |
void LeftListView::onPhotoLibListViewPressed(const QModelIndex &index) |
| 418 |
{ |
| 419 |
Q_UNUSED(index); |
| 420 |
qDebug() << "m_pPhotoLibListView, &DListWidget::pressed"; |
| 421 |
m_pCustomizeListView->clearSelection(); |
| 422 |
m_pMountListWidget->clearSelection(); |
| 423 |
updateAlbumItemsColor(); |
| 424 |
QListWidgetItem *pitem = m_pPhotoLibListView->currentItem(); |
| 425 |
if (pitem) { |
| 426 |
AlbumLeftTabItem *item = dynamic_cast<AlbumLeftTabItem *>(m_pPhotoLibListView->itemWidget(m_pPhotoLibListView->currentItem())); |
| 427 |
auto list = m_pPhotoLibListView->selectedItems(); //当前选中项 |
| 428 |
if (QGuiApplication::queryKeyboardModifiers() & Qt::ControlModifier && list.isEmpty()) { //ctrl取消选中 |
| 429 |
item->oriAlbumStatus(); |
| 430 |
} else { |
| 431 |
item->newAlbumStatus(); //选中状态 |
| 432 |
} |
| 433 |
if (COMMON_STR_RECENT_IMPORTED == item->m_albumNameStr) { |
| 434 |
m_ItemCurrentName = COMMON_STR_RECENT_IMPORTED; |
| 435 |
m_ItemCurrentType = COMMON_STR_RECENT_IMPORTED; |
| 436 |
} else if (COMMON_STR_TRASH == item->m_albumNameStr) { |
| 437 |
m_ItemCurrentName = COMMON_STR_TRASH; |
| 438 |
m_ItemCurrentType = COMMON_STR_TRASH; |
| 439 |
} else { |
| 440 |
m_ItemCurrentName = COMMON_STR_FAVORITES; |
| 441 |
m_ItemCurrentType = COMMON_STR_FAVORITES; |
| 442 |
} |
| 443 |
m_ItemCurrentDataType = pitem->type(); //default 0 |
| 444 |
} |
| 445 |
m_pCustomizeListView->setFocusPolicy(Qt::NoFocus); |
| 446 |
m_pMountListWidget->setFocusPolicy(Qt::NoFocus); |
| 447 |
m_pPhotoLibListView->setFocus(); |
| 448 |
emit itemClicked(); |
| 449 |
} |
| 450 |
|
| 451 |
void LeftListView::onCustomListViewPressed(const QModelIndex &index) |
| 452 |
{ |
| 453 |
Q_UNUSED(index); |
| 454 |
qDebug() << "m_pCustomizeListView, &DListWidget::pressed"; |
| 455 |
m_pPhotoLibListView->clearSelection(); |
| 456 |
m_pMountListWidget->clearSelection(); |
| 457 |
updateAlbumItemsColor(); |
| 458 |
QListWidgetItem *plitem = m_pCustomizeListView->currentItem(); |
| 459 |
if (plitem) { |
| 460 |
AlbumLeftTabItem *item = dynamic_cast<AlbumLeftTabItem *>(m_pCustomizeListView->itemWidget(m_pCustomizeListView->currentItem())); |
| 461 |
auto list = m_pCustomizeListView->selectedItems(); //当前选中项 |
| 462 |
if (QGuiApplication::queryKeyboardModifiers() & Qt::ControlModifier && list.isEmpty()) { //ctrl取消选中 |
| 463 |
item->oriAlbumStatus(); |
| 464 |
} else { |
| 465 |
item->newAlbumStatus(); |
| 466 |
} |
| 467 |
m_ItemCurrentName = item->m_albumNameStr; |
| 468 |
m_ItemCurrentDataType = plitem->type(); //default 0 |
| 469 |
} |
| 470 |
m_ItemCurrentType = COMMON_STR_CUSTOM; |
| 471 |
m_pPhotoLibListView->setFocusPolicy(Qt::NoFocus); |
| 472 |
m_pMountListWidget->setFocusPolicy(Qt::NoFocus); |
| 473 |
m_pCustomizeListView->setFocus(); |
| 474 |
emit itemClicked(); |
| 475 |
} |
| 476 |
|
| 477 |
void LeftListView::onMountListViewPressed(const QModelIndex &index) |
| 478 |
{ |
| 479 |
Q_UNUSED(index); |
| 480 |
qDebug() << "------" << __FUNCTION__ << "---size = " << m_pMountListWidget->count(); |
| 481 |
m_pPhotoLibListView->clearSelection(); |
| 482 |
m_pCustomizeListView->clearSelection(); |
| 483 |
updateAlbumItemsColor(); |
| 484 |
QListWidgetItem *plitem = m_pMountListWidget->currentItem(); |
| 485 |
if (plitem) { |
| 486 |
AlbumLeftTabItem *item = dynamic_cast<AlbumLeftTabItem *>(m_pMountListWidget->itemWidget(m_pMountListWidget->currentItem())); |
| 487 |
if (item) { |
| 488 |
auto list = m_pMountListWidget->selectedItems(); //当前选中项 |
| 489 |
if (QGuiApplication::queryKeyboardModifiers() & Qt::ControlModifier) { //ctrl取消选中 |
| 490 |
item->oriAlbumStatus(); |
| 491 |
} else { |
| 492 |
item->newAlbumStatus(); |
| 493 |
} |
| 494 |
m_ItemCurrentName = item->m_albumNameStr; |
| 495 |
m_ItemCurrentDataType = plitem->type(); //default 0 |
| 496 |
} |
| 497 |
} |
| 498 |
m_ItemCurrentType = ALBUM_PATHTYPE_BY_PHONE; |
| 499 |
m_pPhotoLibListView->setFocusPolicy(Qt::NoFocus); |
| 500 |
m_pCustomizeListView->setFocusPolicy(Qt::NoFocus); |
| 501 |
m_pMountListWidget->setFocus(); |
| 502 |
emit itemClicked(); |
| 503 |
} |
| 504 |
|
| 505 |
void LeftListView::onPhotoLibListViewCurrentItemChanged() |
| 506 |
{ |
| 507 |
m_pCustomizeListView->clearSelection(); |
| 508 |
m_pMountListWidget->clearSelection(); |
| 509 |
updateAlbumItemsColor(); |
| 510 |
if (m_pPhotoLibListView->currentItem()) { |
| 511 |
AlbumLeftTabItem *item = dynamic_cast<AlbumLeftTabItem *>(m_pPhotoLibListView->itemWidget(m_pPhotoLibListView->currentItem())); |
| 512 |
item->newAlbumStatus(); |
| 513 |
if (COMMON_STR_RECENT_IMPORTED == item->m_albumNameStr) { |
| 514 |
m_ItemCurrentName = COMMON_STR_RECENT_IMPORTED; |
| 515 |
m_ItemCurrentType = COMMON_STR_RECENT_IMPORTED; |
| 516 |
} else if (COMMON_STR_TRASH == item->m_albumNameStr) { |
| 517 |
m_ItemCurrentName = COMMON_STR_TRASH; |
| 518 |
m_ItemCurrentType = COMMON_STR_TRASH; |
| 519 |
} else { |
| 520 |
m_ItemCurrentName = COMMON_STR_FAVORITES; |
| 521 |
m_ItemCurrentType = COMMON_STR_FAVORITES; |
| 522 |
} |
| 523 |
} |
| 524 |
} |
| 525 |
|
| 526 |
void LeftListView::onCustomizeListViewCurrentItemChanged() |
| 527 |
{ |
| 528 |
if (0 < m_pCustomizeListView->count()) { |
| 529 |
m_pPhotoLibListView->clearSelection(); |
| 530 |
m_pMountListWidget->clearSelection(); |
| 531 |
updateAlbumItemsColor(); |
| 532 |
if (m_pCustomizeListView->currentItem()) { |
| 533 |
AlbumLeftTabItem *item = dynamic_cast<AlbumLeftTabItem *>(m_pCustomizeListView->itemWidget(m_pCustomizeListView->currentItem())); |
| 534 |
item->newAlbumStatus(); |
| 535 |
m_ItemCurrentName = item->m_albumNameStr; |
| 536 |
} |
| 537 |
m_ItemCurrentType = COMMON_STR_CUSTOM; |
| 538 |
} |
| 539 |
} |
| 540 |
|
| 541 |
void LeftListView::onMountListWidgetCurrentItemChanged() |
| 542 |
{ |
| 543 |
if (0 < m_pMountListWidget->count()) { |
| 544 |
m_pPhotoLibListView->clearSelection(); |
| 545 |
m_pCustomizeListView->clearSelection(); |
| 546 |
updateAlbumItemsColor(); |
| 547 |
if (m_pMountListWidget->currentItem()) { |
| 548 |
AlbumLeftTabItem *item = dynamic_cast<AlbumLeftTabItem *>(m_pMountListWidget->itemWidget(m_pMountListWidget->currentItem())); |
| 549 |
if (nullptr != item) { |
| 550 |
item->newAlbumStatus(); |
| 551 |
m_ItemCurrentName = item->m_albumNameStr; |
| 552 |
} |
| 553 |
} |
| 554 |
m_ItemCurrentType = ALBUM_PATHTYPE_BY_PHONE; |
| 555 |
} |
| 556 |
} |
| 557 |
|
| 558 |
void LeftListView::onAddListBtnClicked() |
| 559 |
{ |
| 560 |
emit dApp->signalM->createAlbum(QStringList(" ")); |
| 561 |
} |
| 562 |
|
| 563 |
void LeftListView::onApplicationHelperThemeTypeChanged() |
| 564 |
{ |
| 565 |
if (COMMON_STR_RECENT_IMPORTED == m_ItemCurrentType) { |
| 566 |
AlbumLeftTabItem *item = dynamic_cast<AlbumLeftTabItem *>(m_pPhotoLibListView->itemWidget(m_pPhotoLibListView->currentItem())); |
| 567 |
item->newAlbumStatus(); |
| 568 |
item->oriAlbumStatus(); |
| 569 |
} |
| 570 |
if (COMMON_STR_TRASH == m_ItemCurrentType) { |
| 571 |
AlbumLeftTabItem *item = dynamic_cast<AlbumLeftTabItem *>(m_pPhotoLibListView->itemWidget(m_pPhotoLibListView->currentItem())); |
| 572 |
item->newAlbumStatus(); |
| 573 |
item->oriAlbumStatus(); |
| 574 |
} |
| 575 |
if (COMMON_STR_FAVORITES == m_ItemCurrentType) { |
| 576 |
AlbumLeftTabItem *item = dynamic_cast<AlbumLeftTabItem *>(m_pPhotoLibListView->itemWidget(m_pPhotoLibListView->currentItem())); |
| 577 |
item->newAlbumStatus(); |
| 578 |
item->oriAlbumStatus(); |
| 579 |
} |
| 580 |
if (COMMON_STR_CUSTOM == m_ItemCurrentType) { |
| 581 |
AlbumLeftTabItem *item = dynamic_cast<AlbumLeftTabItem *>(m_pCustomizeListView->itemWidget(m_pCustomizeListView->currentItem())); |
| 582 |
item->newAlbumStatus(); |
| 583 |
item->oriAlbumStatus(); |
| 584 |
} |
| 585 |
if (ALBUM_PATHTYPE_BY_PHONE == m_ItemCurrentType) { |
| 586 |
AlbumLeftTabItem *item = dynamic_cast<AlbumLeftTabItem *>(m_pMountListWidget->itemWidget(m_pMountListWidget->currentItem())); |
| 587 |
item->newAlbumStatus(); |
| 588 |
item->oriAlbumStatus(); |
| 589 |
} |
| 590 |
} |
| 591 |
|
| 592 |
void LeftListView::onGuiApplicationHelperThemeTypeChanged() |
| 593 |
{ |
| 594 |
DGuiApplicationHelper::ColorType themeType = DGuiApplicationHelper::instance()->themeType(); |
| 595 |
if (themeType == DGuiApplicationHelper::LightType) { |
| 596 |
m_pAddListBtn->setPropertyPic(":/resources/images/sidebar/normal/add_normal.svg", |
| 597 |
":/resources/images/sidebar/active/add_hover.svg", |
| 598 |
":/resources/images/sidebar/active/add_press.svg", |
| 599 |
":/resources/images/sidebar/active/add_focus.svg"); |
| 600 |
} |
| 601 |
if (themeType == DGuiApplicationHelper::DarkType) { |
| 602 |
m_pAddListBtn->setPropertyPic(":/resources/images/sidebar/active/add_normal_dark.svg", |
| 603 |
":/resources/images/sidebar/active/add_hover_dark.svg", |
| 604 |
":/resources/images/sidebar/active/add_press_dark.svg", |
| 605 |
":/resources/images/sidebar/active/add_focus_dark.svg"); |
| 606 |
} |
| 607 |
} |
| 608 |
|
| 609 |
void LeftListView::onMousePressIsNoValid() |
| 610 |
{ |
| 611 |
setFocusPolicy(Qt::ClickFocus); |
| 612 |
} |
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
QString LeftListView::getNewAlbumName() |
| 617 |
{ |
| 618 |
return AlbumCreateDialog::getNewAlbumName(""); |
| 619 |
} |
| 620 |
|
| 621 |
QString LeftListView::getItemCurrentName() |
| 622 |
{ |
| 623 |
return m_ItemCurrentName; |
| 624 |
} |
| 625 |
|
| 626 |
QString LeftListView::getItemCurrentType() |
| 627 |
{ |
| 628 |
return m_ItemCurrentType; |
| 629 |
} |
| 630 |
|
| 631 |
int LeftListView::getItemDataType() |
| 632 |
{ |
| 633 |
return m_ItemCurrentDataType; |
| 634 |
} |
| 635 |
|
| 636 |
void LeftListView::updateAlbumItemsColor() |
| 637 |
{ |
| 638 |
for (int i = 0; i < m_pPhotoLibListView->count(); i++) { |
| 639 |
AlbumLeftTabItem *item = dynamic_cast<AlbumLeftTabItem *>(m_pPhotoLibListView->itemWidget(m_pPhotoLibListView->item(i))); |
| 640 |
if (item) { |
| 641 |
item->oriAlbumStatus(); |
| 642 |
} |
| 643 |
} |
| 644 |
|
| 645 |
if (0 < m_pCustomizeListView->count()) { |
| 646 |
for (int i = 0; i < m_pCustomizeListView->count(); i++) { |
| 647 |
AlbumLeftTabItem *item = dynamic_cast<AlbumLeftTabItem *>(m_pCustomizeListView->itemWidget(m_pCustomizeListView->item(i))); |
| 648 |
if (item) { |
| 649 |
item->oriAlbumStatus(); |
| 650 |
} |
| 651 |
} |
| 652 |
} |
| 653 |
|
| 654 |
if (0 < m_pMountListWidget->count()) { |
| 655 |
for (int i = 0; i < m_pMountListWidget->count(); i++) { |
| 656 |
AlbumLeftTabItem *item = dynamic_cast<AlbumLeftTabItem *>(m_pMountListWidget->itemWidget(m_pMountListWidget->item(i))); |
| 657 |
if (item) |
| 658 |
item->oriAlbumStatus(); |
| 659 |
} |
| 660 |
} |
| 661 |
} |
| 662 |
|
| 663 |
void LeftListView::resizeEvent(QResizeEvent *e) |
| 664 |
{ |
| 665 |
DWidget::resizeEvent(e); |
| 666 |
// 设备左边栏 |
| 667 |
int deviceHeight = m_pMountListWidget->count() * LEFT_VIEW_LISTITEM_HEIGHT_40; |
| 668 |
m_pMountListWidget->setFixedHeight(deviceHeight); |
| 669 |
} |