Skip to content

Commit

Permalink
feat: 添加照片分类视图页
Browse files Browse the repository at this point in the history
  添加照片分类视图页

Log: 添加照片分类视图页
  • Loading branch information
starhcq committed Nov 28, 2023
1 parent efad889 commit 6e5b814
Show file tree
Hide file tree
Showing 18 changed files with 264 additions and 22 deletions.
16 changes: 16 additions & 0 deletions src/album/albumgloabl.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,22 @@ struct DBImgInfo {
typedef QList<DBImgInfo> DBImgInfoList;
typedef QList<DBImgInfo*> DBImgInfoListPtr;

#define CLASS_PLANT "Plants"
#define CLASS_Scenery "Scenery"
#define CLASS_FOOD "Food"
#define CLASS_SCENE "Scene"
#define CLASS_ANIMALS "Animals"
#define CLASS_HUMANS "Humans"
#define CLASS_ITEMS "Items"
#define CLASS_OTHER "Other"

struct ClassifyDBImgInfo {
QString className;
QList<DBImgInfo> infos;
};

typedef QList<ClassifyDBImgInfo> ClassifyDBImgInfoList;

enum OpenImgViewType {
VIEW_MAINWINDOW_ALLPIC = 0,
VIEW_MAINWINDOW_TIMELINE = 1,
Expand Down
52 changes: 44 additions & 8 deletions src/album/albumview/albumview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ void AlbumView::initClassWidget()
p_Class->setContentsMargins(8, 0, 0, 0);
m_pClassWidget->setLayout(p_Class);

m_classThumbnailList = new ThumbnailListView(ThumbnailDelegate::AlbumViewClassType, -1, COMMON_STR_FAVORITES);
m_classThumbnailList = new ThumbnailListView(ThumbnailDelegate::AlbumViewClassType, -1, COMMON_STR_CLASS);
//筛选显示,当先列表中内容为无结果
connect(m_classThumbnailList, &ThumbnailListView::sigNoPicOrNoVideo, this, &AlbumView::slotNoPicOrNoVideo);
m_classThumbnailList->setFrameShape(DTableView::NoFrame);
Expand Down Expand Up @@ -1118,18 +1118,51 @@ void AlbumView::updateRightClassView()
return;
}

// 按类型对图片数据归类
QStringList classList;
classList << CLASS_Scenery << CLASS_FOOD << CLASS_HUMANS << CLASS_ANIMALS << CLASS_SCENE << CLASS_PLANT << CLASS_ITEMS;
ClassifyDBImgInfoList classifys;
for (auto str : classList) {
ClassifyDBImgInfo info;
info.className = str;
classifys.push_back(info);
}
for (auto info: infos) {
if (classList.indexOf(info.className) == -1)
continue;

for (int i = 0; i < classifys.size(); i++) {
if (classifys[i].className == info.className) {
classifys[i].infos.push_back(info);
}
}
}

DBImgInfoList classDBInfos;
for (auto classify: classifys) {
if (!classify.infos.isEmpty()) {
DBImgInfo info = classify.infos.first();
info.num = QString::number(classify.infos.size());
classDBInfos.push_back(info);
}
}

m_pStatusBar->hide();
m_classBatchOperateWidget->hide();
m_pClassTitle->hide();

m_classThumbnailList->clearAll();
//插入上方空白项
m_classThumbnailList->insertBlankOrTitleItem(ItemTypeBlank, "", "", favorite_title_height);
m_classThumbnailList->insertThumbnailByImgInfos(infos);
m_classThumbnailList->insertThumbnailByImgInfos(classDBInfos);
// 添加底栏空白区域
m_classThumbnailList->insertBlankOrTitleItem(ItemTypeBlank, "", "", m_pStatusBar->height());
//重置数量显示
resetLabelCount(m_classThumbnailList->getAppointTypeItemCount(ItemTypePic)
, m_classThumbnailList->getAppointTypeItemCount(ItemTypeVideo), m_pClassPicTotal);
// //重置数量显示
// resetLabelCount(m_classThumbnailList->getAppointTypeItemCount(ItemTypePic)
// , m_classThumbnailList->getAppointTypeItemCount(ItemTypeVideo), m_pClassPicTotal);
m_pRightStackWidget->setCurrentIndex(RIGHT_VIEW_CLASS_LIST);
m_ClassTitleWidget->setVisible(infos.size() > 0);
m_pStatusBar->setVisible(true);

emit sigSearchEditIsDisplay(true);
setAcceptDrops(false);
}
Expand Down Expand Up @@ -2220,7 +2253,7 @@ void AlbumView::updatePicNum()

void AlbumView::updateTotalLabelNum()
{
if (COMMON_STR_CLASS == m_currentType) {
if (COMMON_STR_CLASSDETAIL == m_currentType) {
//重置数量显示
resetLabelCount(m_classThumbnailList->getAppointTypeItemCount(ItemTypePic)
, m_classThumbnailList->getAppointTypeItemCount(ItemTypeVideo), m_pClassPicTotal);
Expand All @@ -2237,6 +2270,9 @@ void AlbumView::updateTotalLabelNum()

void AlbumView::restorePicNum()
{
if (COMMON_STR_CLASS == m_currentType)
return;

int photoCount = 0;
int videoCount = 0;
if (4 == m_pRightStackWidget->currentIndex()) {
Expand Down Expand Up @@ -2704,7 +2740,7 @@ void AlbumView::restoreTitleDisplay()
m_customAlbumTitleLabel->raise();
}
if (m_classBatchOperateWidget && !m_classBatchOperateWidget->isVisible()) {//图片分类界面标题
m_pClassTitle->setText(tr("Favorites"));
m_pClassTitle->setText(tr("Image classification"));
m_pClassTitle->show();
m_pClassTitle->raise();
}
Expand Down
91 changes: 90 additions & 1 deletion src/album/thumbnail/thumbnaildelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "thumbnaildelegate.h"
#include "utils/imageutils.h"
#include "utils/baseutils.h"
#include "statusbar.h"
#include "application.h"
#include <QDateTime>

Expand Down Expand Up @@ -164,7 +165,7 @@ void ThumbnailDelegate::drawImgAndVideo(QPainter *painter, const QStyleOptionVie
}

//绘制选中图标
if (selected) {
if (selected && COMMON_STR_CLASS != m_imageTypeStr) {
QRect rc = option.rect;
rc.setSize({CheckIcon_Size, CheckIcon_Size});
rc.moveTopRight(QPoint(option.rect.right() - 6, option.rect.top() + 6));
Expand Down Expand Up @@ -215,6 +216,70 @@ void ThumbnailDelegate::drawImgAndVideo(QPainter *painter, const QStyleOptionVie
str = Text.elidedText(str, Qt::ElideRight, textwidth);
}
painter->drawText(posx + 3, backgroundRect.y() + backgroundRect.height() - 15, str);//在框中绘制文字,起点位置离最下方15像素
} else if (COMMON_STR_CLASS == m_imageTypeStr) {

// 绘制蒙皮
QBrush shadowbrush;
if (themeType == DGuiApplicationHelper::LightType) {
shadowbrush = QBrush(QColor(0, 0, 0, 120));
}
if (themeType == DGuiApplicationHelper::DarkType) {
shadowbrush = QBrush(QColor(255, 255, 255, 120));
}
painter->fillRect(backgroundRect, shadowbrush);

const int iconWidth = 15;
const int yOffset = 1;
int rectwidth = backgroundRect.width() - 8; //缩略图宽度:总宽度减去选中框宽度8

// 绘制图标
QPainterPath bp;
bp.addRoundedRect(backgroundRect, utils::common::BORDER_RADIUS, utils::common::BORDER_RADIUS);
painter->setClipPath(bp);

QPixmap classPixmap = utils::base::renderSVG(getClassPicPath(data.className), QSize(iconWidth, iconWidth));
int posx = backgroundRect.x() + rectwidth / 2 - iconWidth;
int posy = backgroundRect.y() + backgroundRect.height() / 2 - iconWidth - yOffset;
painter->drawPixmap(posx, posy, classPixmap);

// 绘制分类文字
QString str(QObject::tr(data.className.toStdString().c_str()));
int m_Width = painter->fontMetrics().width(str);
QFontMetrics Text(str);

int textwidth1 = m_Width;

Check warning on line 250 in src/album/thumbnail/thumbnaildelegate.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Condition 'm_Width-textwidth1>0' is always false

Check warning on line 250 in src/album/thumbnail/thumbnaildelegate.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Finding the same expression on both sides of an operator is suspicious and might indicate a cut and paste or logic error. Please examine this code carefully to determine if it is correct.
int textheight1 = painter->fontMetrics().height();
int posx1 = posx + iconWidth;
int posy1 = posy + iconWidth / 2 + 4;

painter->setFont(DFontSizeManager::instance()->get(DFontSizeManager::T7, QFont::Medium));
painter->setPen(QColor(255, 255, 255));
if (m_Width - textwidth1 > 0) {
str = Text.elidedText(str, Qt::ElideRight, textwidth1);
}
painter->drawText(posx1 + 3, posy1, str);

// 绘制总数文字
int photosCount = data.num.toInt();
if (photosCount == 1) {
str = StatusBar::tr("1 photo");
} else if (photosCount > 1) {
str = StatusBar::tr("%n photos", "", photosCount);
}
m_Width = painter->fontMetrics().width(str);
Text = QFontMetrics(str);

int textwidth2 = m_Width;

Check warning on line 272 in src/album/thumbnail/thumbnaildelegate.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Condition 'm_Width-textwidth2>0' is always false

Check warning on line 272 in src/album/thumbnail/thumbnaildelegate.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Finding the same expression on both sides of an operator is suspicious and might indicate a cut and paste or logic error. Please examine this code carefully to determine if it is correct.
int posx2 = posx;
int posy2 = posy1 + textheight1;

painter->setFont(DFontSizeManager::instance()->get(DFontSizeManager::T8, QFont::Medium));
painter->setPen(QColor(255, 255, 255, 120));
if (m_Width - textwidth2 > 0) {
str = Text.elidedText(str, Qt::ElideRight, textwidth2);
}
painter->drawText(posx2, posy2, str);

}
//绘制视频时间
if (data.itemType == ItemTypeVideo) {
Expand Down Expand Up @@ -309,6 +374,30 @@ DBImgInfo ThumbnailDelegate::itemData(const QModelIndex &index) const
return data;
}

QString ThumbnailDelegate::getClassPicPath(const QString &className) const
{
QString picName = "";
if (className == CLASS_Scenery) {
picName = "album_scenery.svg";
} else if (className == CLASS_FOOD) {
picName = "album_food.svg";
} else if (className == CLASS_HUMANS) {
picName = "album_human.svg";
} else if (className == CLASS_ANIMALS) {
picName = "album_animal.svg";
} else if (className == CLASS_SCENE) {
picName = "album_scene.svg";
} else if (className == CLASS_PLANT) {
picName = "album_plant.svg";
} else if (className == CLASS_ITEMS) {
picName = "album_items.svg";
} else if (className == CLASS_OTHER) {
picName = "album_other.svg";
}

return ":/icons/deepin/builtin/texts/" + picName;
}

bool ThumbnailDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)

Check warning on line 401 in src/album/thumbnail/thumbnaildelegate.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'editorEvent' is never used.
{
Q_UNUSED(model);
Expand Down
3 changes: 2 additions & 1 deletion src/album/thumbnail/thumbnaildelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class ThumbnailDelegate : public QStyledItemDelegate
AlbumViewTrashType,//相册-已删除
AlbumViewFavoriteType,//相册-收藏
AlbumViewClassType,//相册-图片分类
AlbumViewClassTypeDetail,//相册-图片分类详情页
AlbumViewCustomType,//相册-自定义
AlbumViewPhoneType//相册-设备
};
Expand Down Expand Up @@ -61,7 +62,7 @@ private slots:

private:
DBImgInfo itemData(const QModelIndex &index) const;

QString getClassPicPath(const QString &className) const;
public:
QString m_imageTypeStr;

Expand Down
10 changes: 10 additions & 0 deletions src/album/thumbnail/thumbnaillistview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ void ThumbnailListView::mouseMoveEvent(QMouseEvent *event)
return;
}

// 照片分类页面禁用框选
if (m_delegatetype == ThumbnailDelegate::AlbumViewClassType)
return;

if (touchStatus == 0) {
touchStatus = 1;
activeClick = false;
Expand Down Expand Up @@ -1098,6 +1102,12 @@ void ThumbnailListView::menuItemDeal(QStringList paths, QAction *action)

void ThumbnailListView::onPixMapScale(int value)
{
// 图片分类视图,封面大小固定为170像素
if (m_delegatetype == ThumbnailDelegate::AlbumViewClassType) {
m_iBaseHeight = 170;
resizeEventF();
return;
}
// if (!this->isVisible())
// return;
switch (value) {
Expand Down
3 changes: 2 additions & 1 deletion src/album/utils/baseutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
#define COMMON_STR_RECENT_IMPORTED "已导入"
#define COMMON_STR_TRASH "最近删除"
#define COMMON_STR_FAVORITES "我的收藏"
#define COMMON_STR_CLASS "图片分类"
#define COMMON_STR_CLASS "照片分类"
#define COMMON_STR_CLASSDETAIL "照片分类详情页"
#define COMMON_STR_SEARCH "搜索"
#define ALBUM_PATHNAME_BY_PHONE "DCIM"
#define ALBUM_PATHTYPE_BY_PHONE "External Devices"
Expand Down
2 changes: 1 addition & 1 deletion src/album/widgets/batchoperatewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ void BatchOperateWidget::initDropdown()
data.icon_r_light = QIcon::fromTheme("album_animal");
data.icon_r_dark = QIcon::fromTheme("album_animal");
data.icon_r_path = "album_animal";
data.text = QObject::tr("Animal");
data.text = QObject::tr("Animals");
data.type = ItemType::ItemTypePic;
data.className = CLASS_ANIMALS;
m_expansionMenu->addNewButton(data);
Expand Down
9 changes: 0 additions & 9 deletions src/album/widgets/expansionpanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,6 @@

#include "albumgloabl.h"

#define CLASS_PLANT "Plants"
#define CLASS_Scenery "Scenery"
#define CLASS_FOOD "Food"
#define CLASS_SCENE "Scene"
#define CLASS_ANIMALS "Animals"
#define CLASS_HUMANS "Humans"
#define CLASS_ITEMS "Items"
#define CLASS_OTHER "Other"

class ExpansionPanel : public DBlurEffectWidget
{
Q_OBJECT
Expand Down
9 changes: 9 additions & 0 deletions src/icons/icons.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,16 @@
<file>texts/album_scene_hover_16px.svg</file>
<file>texts/album_other_16px.svg</file>
<file>texts/album_other_hover_16px.svg</file>
<file>texts/album_animal.svg</file>
<file>texts/album_food.svg</file>
<file>texts/album_human.svg</file>
<file>texts/album_items.svg</file>
<file>texts/album_plant.svg</file>
<file>texts/album_other.svg</file>
<file>texts/album_scene.svg</file>
<file>texts/album_scenery.svg</file>
</qresource>
<qresource prefix="/icons/deepin/builtin/light"/>
<qresource prefix="/icons/deepin/builtin/dark"/>
<qresource prefix="/"/>
</RCC>
16 changes: 16 additions & 0 deletions src/icons/texts/album_animal.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions src/icons/texts/album_food.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 6e5b814

Please sign in to comment.