67 lines
1.3 KiB
C++
67 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include <QWidget>
|
|
#include <QPushButton>
|
|
#include <QStackedWidget>
|
|
#include <QVBoxLayout>
|
|
#include <QHBoxLayout>
|
|
#include <QButtonGroup>
|
|
#include <QTimer>
|
|
#include <QMenu>
|
|
|
|
class MyCarousel : public QWidget
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
explicit MyCarousel(QWidget* parent = nullptr);
|
|
|
|
void addWidget(QWidget* w);
|
|
void play();
|
|
void gotoWidget(int index);
|
|
|
|
protected:
|
|
void contextMenuEvent(QContextMenuEvent* event) override;
|
|
void resizeEvent(QResizeEvent* event) override;
|
|
|
|
private slots:
|
|
void slideLeft();
|
|
void slideRight();
|
|
void onButtonClicked(int index);
|
|
|
|
private:
|
|
// UI
|
|
QStackedWidget* m_stackedWidget;
|
|
QWidget* m_bottomButtonOverlay;
|
|
QHBoxLayout* m_bottomButtonLayout;
|
|
QButtonGroup* m_bottomButtonGroup;
|
|
|
|
QVector<QWidget*> m_widgets;
|
|
QVector<QPushButton*> m_bottomButtons;
|
|
QString m_nomalQSS;
|
|
QString m_lockedQSS;
|
|
|
|
// ״ֵ̬
|
|
int m_currentIndex;
|
|
bool m_isPlaying;
|
|
bool m_isLocked;
|
|
int m_lockedIndex;
|
|
|
|
// ²ÎÊý
|
|
int m_playInterval;
|
|
int m_intervalButtonSize;
|
|
|
|
QTimer* m_autoPlayerTimer;
|
|
|
|
private:
|
|
void updateStackedWidgetVisibility();
|
|
void updateButtonState(int index);
|
|
|
|
void setButtonLocked(int index);
|
|
void restoreButtonStyle(int index);
|
|
|
|
void showContextMenu(const QPoint& pos);
|
|
|
|
void startAutoPlay();
|
|
void stopAutoPlay();
|
|
};
|