Skip to content

Commit

Permalink
[ImageCarousel 功能重构]: 图片轮播组件功能升级与界面调整
Browse files Browse the repository at this point in the history
- 图片轮播组件 `ImageCarousel` 进行了功能重构,引入了新的 `ImageViewer` 类,提供了更加丰富的图片展示和交互方式。
- 移除了原有的 `ImageCarousel` 类定义和实现文件,包括 `imagecarousel.cc` 和 `imagecarousel.hpp`,以及相关的图片轮播控件 `ImageCarouselWidget` 的定义和实现文件。
- 新增 `graphicspixmapitem.cc` 和 `graphicspixmapitem.hpp` 文件,定义了一个扩展自 `QGraphicsPixmapItem` 的 `GraphicsPixmapItem` 类,增加了点击信号和自定义的图片尺寸调整功能。
- 新增 `imageviewer.cc` 和 `imageviewer.hpp` 文件,定义了 `ImageViewer` 类,该类支持图片的左右切换、点击响应以及动画效果展示。
- 对 `main.cc` 和 `mainwindow.cc` 进行了修改,以适应新的 `ImageViewer` 组件,移除了与旧 `ImageCarouselWidget` 相关的代码,并简化了主窗口的 UI 设计。
- 更新了 `README.md` 文件,调整了图片轮播组件的描述和展示图片。
  • Loading branch information
RealChuan committed Aug 29, 2024
1 parent 07df2b8 commit 136c663
Show file tree
Hide file tree
Showing 15 changed files with 302 additions and 437 deletions.
8 changes: 4 additions & 4 deletions ImageCarousel/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
set(PROJECT_SOURCES
imagecarousel.cc
imagecarousel.hpp
imagecarouselwidget.hpp
imagecarouselwidget.cc
graphicspixmapitem.cc
graphicspixmapitem.hpp
imageviewer.cc
imageviewer.hpp
main.cc
mainwindow.cc
mainwindow.hpp)
Expand Down
8 changes: 4 additions & 4 deletions ImageCarousel/ImageCarousel.pro
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ CONFIG += c++17
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
imagecarousel.cc \
imagecarouselwidget.cc \
graphicspixmapitem.cc \
imageviewer.cc \
main.cc \
mainwindow.cc

HEADERS += \
imagecarousel.hpp \
imagecarouselwidget.hpp \
graphicspixmapitem.hpp \
imageviewer.hpp \
mainwindow.hpp

# Default rules for deployment.
Expand Down
29 changes: 29 additions & 0 deletions ImageCarousel/graphicspixmapitem.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "graphicspixmapitem.hpp"

#include <QGraphicsSceneMouseEvent>

void GraphicsPixmapItem::setCustomPixmap(const QPixmap &pixmap)
{
m_pixmap = pixmap;
}

QPixmap GraphicsPixmapItem::customPixmap() const
{
return m_pixmap;
}

void GraphicsPixmapItem::setSize(const QSize &size)
{
setPixmap(m_pixmap.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation));
}

QSize GraphicsPixmapItem::size() const
{
return pixmap().size();
}

void GraphicsPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
// QGraphicsPixmapItem::mousePressEvent(event);
emit clicked();
}
25 changes: 25 additions & 0 deletions ImageCarousel/graphicspixmapitem.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#include <QGraphicsPixmapItem>

class GraphicsPixmapItem : public QObject, public QGraphicsPixmapItem
{
Q_OBJECT
Q_PROPERTY(QPointF pos READ pos WRITE setPos)
Q_PROPERTY(QSize size READ size WRITE setSize)
public:
void setCustomPixmap(const QPixmap &pixmap);
QPixmap customPixmap() const;

void setSize(const QSize &size);
QSize size() const;

signals:
void clicked();

protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;

private:
QPixmap m_pixmap;
};
137 changes: 0 additions & 137 deletions ImageCarousel/imagecarousel.cc

This file was deleted.

43 changes: 0 additions & 43 deletions ImageCarousel/imagecarousel.hpp

This file was deleted.

120 changes: 0 additions & 120 deletions ImageCarousel/imagecarouselwidget.cc

This file was deleted.

Loading

0 comments on commit 136c663

Please sign in to comment.