chore: 格式化ElaWidgetTools代码
This commit is contained in:
@@ -7,15 +7,13 @@
|
||||
#include "ElaPromotionCard.h"
|
||||
#include "ElaPromotionViewPrivate.h"
|
||||
#include "ElaTheme.h"
|
||||
ElaPromotionView::ElaPromotionView(QWidget* parent)
|
||||
: QWidget{parent}, d_ptr(new ElaPromotionViewPrivate())
|
||||
{
|
||||
ElaPromotionView::ElaPromotionView(QWidget *parent) : QWidget{parent}, d_ptr(new ElaPromotionViewPrivate()) {
|
||||
Q_D(ElaPromotionView);
|
||||
d->q_ptr = this;
|
||||
d->_pCurrentIndex = 0;
|
||||
d->_pCardExpandWidth = 600;
|
||||
d->_pCardCollapseWidth = 300;
|
||||
d->_pIsAutoScroll = false;
|
||||
d->q_ptr = this;
|
||||
d->_pCurrentIndex = 0;
|
||||
d->_pCardExpandWidth = 600;
|
||||
d->_pCardCollapseWidth = 300;
|
||||
d->_pIsAutoScroll = false;
|
||||
d->_pAutoScrollInterval = 5000;
|
||||
setFixedHeight(300);
|
||||
setObjectName("ElaPromotionView");
|
||||
@@ -23,8 +21,7 @@ ElaPromotionView::ElaPromotionView(QWidget* parent)
|
||||
|
||||
d->_autoScrollTimer = new QTimer(this);
|
||||
connect(d->_autoScrollTimer, &QTimer::timeout, this, [=]() {
|
||||
if (isVisible() && d->_promotionCardList.count() > 2)
|
||||
{
|
||||
if (isVisible() && d->_promotionCardList.count() > 2) {
|
||||
d->onPromotionCardClicked(d->_promotionCardList[d->_getAdjacentIndex(Qt::LeftToRight, d->_pCurrentIndex)]);
|
||||
}
|
||||
});
|
||||
@@ -33,162 +30,127 @@ ElaPromotionView::ElaPromotionView(QWidget* parent)
|
||||
connect(eTheme, &ElaTheme::themeModeChanged, this, [=](ElaThemeType::ThemeMode themeMode) { d->_themeMode = themeMode; });
|
||||
}
|
||||
|
||||
ElaPromotionView::~ElaPromotionView()
|
||||
{
|
||||
}
|
||||
ElaPromotionView::~ElaPromotionView() {}
|
||||
|
||||
void ElaPromotionView::setCardExpandWidth(int width)
|
||||
{
|
||||
void ElaPromotionView::setCardExpandWidth(int width) {
|
||||
Q_D(ElaPromotionView);
|
||||
if (width <= 0)
|
||||
{
|
||||
if (width <= 0) {
|
||||
return;
|
||||
}
|
||||
d->_pCardExpandWidth = width;
|
||||
d->_updatePromotionCardGeometry();
|
||||
}
|
||||
|
||||
int ElaPromotionView::getCardExpandWidth() const
|
||||
{
|
||||
int ElaPromotionView::getCardExpandWidth() const {
|
||||
Q_D(const ElaPromotionView);
|
||||
return d->_pCardExpandWidth;
|
||||
}
|
||||
|
||||
void ElaPromotionView::setCardCollapseWidth(int width)
|
||||
{
|
||||
void ElaPromotionView::setCardCollapseWidth(int width) {
|
||||
Q_D(ElaPromotionView);
|
||||
if (width <= 0)
|
||||
{
|
||||
if (width <= 0) {
|
||||
return;
|
||||
}
|
||||
d->_pCardCollapseWidth = width;
|
||||
d->_updatePromotionCardGeometry();
|
||||
}
|
||||
|
||||
int ElaPromotionView::getCardCollapseWidth() const
|
||||
{
|
||||
int ElaPromotionView::getCardCollapseWidth() const {
|
||||
Q_D(const ElaPromotionView);
|
||||
return d->_pCardCollapseWidth;
|
||||
}
|
||||
|
||||
void ElaPromotionView::setCurrentIndex(int index)
|
||||
{
|
||||
void ElaPromotionView::setCurrentIndex(int index) {
|
||||
Q_D(ElaPromotionView);
|
||||
if (index < 0 || index >= d->_promotionCardList.count())
|
||||
{
|
||||
if (index < 0 || index >= d->_promotionCardList.count()) {
|
||||
return;
|
||||
}
|
||||
d->onPromotionCardClicked(d->_promotionCardList[index]);
|
||||
}
|
||||
|
||||
int ElaPromotionView::getCurrentIndex() const
|
||||
{
|
||||
int ElaPromotionView::getCurrentIndex() const {
|
||||
Q_D(const ElaPromotionView);
|
||||
return d->_pCurrentIndex;
|
||||
}
|
||||
|
||||
void ElaPromotionView::setIsAutoScroll(bool isAutoScroll)
|
||||
{
|
||||
void ElaPromotionView::setIsAutoScroll(bool isAutoScroll) {
|
||||
Q_D(ElaPromotionView);
|
||||
if (isAutoScroll)
|
||||
{
|
||||
if (isAutoScroll) {
|
||||
d->_autoScrollTimer->start(d->_pAutoScrollInterval);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
d->_autoScrollTimer->stop();
|
||||
}
|
||||
d->_pIsAutoScroll = isAutoScroll;
|
||||
Q_EMIT pIsAutoScrollChanged();
|
||||
}
|
||||
|
||||
bool ElaPromotionView::getIsAutoScroll() const
|
||||
{
|
||||
bool ElaPromotionView::getIsAutoScroll() const {
|
||||
Q_D(const ElaPromotionView);
|
||||
return d->_pIsAutoScroll;
|
||||
}
|
||||
|
||||
void ElaPromotionView::setAutoScrollInterval(int autoScrollInterval)
|
||||
{
|
||||
void ElaPromotionView::setAutoScrollInterval(int autoScrollInterval) {
|
||||
Q_D(ElaPromotionView);
|
||||
if (autoScrollInterval < 400)
|
||||
{
|
||||
if (autoScrollInterval < 400) {
|
||||
return;
|
||||
}
|
||||
d->_pAutoScrollInterval = autoScrollInterval;
|
||||
Q_EMIT pAutoScrollIntervalChanged();
|
||||
}
|
||||
|
||||
int ElaPromotionView::getAutoScrollInterval() const
|
||||
{
|
||||
int ElaPromotionView::getAutoScrollInterval() const {
|
||||
Q_D(const ElaPromotionView);
|
||||
return d->_pAutoScrollInterval;
|
||||
}
|
||||
|
||||
void ElaPromotionView::appendPromotionCard(ElaPromotionCard* card)
|
||||
{
|
||||
void ElaPromotionView::appendPromotionCard(ElaPromotionCard *card) {
|
||||
Q_D(ElaPromotionView);
|
||||
if (!card || d->_promotionCardList.contains(card))
|
||||
{
|
||||
if (!card || d->_promotionCardList.contains(card)) {
|
||||
return;
|
||||
}
|
||||
card->setMinimumSize(0, 0);
|
||||
card->setMaximumSize(10000, 10000);
|
||||
card->setParent(this);
|
||||
d->_promotionCardList.append(card);
|
||||
connect(card, &ElaPromotionCard::promotionCardClicked, this, [=]() {
|
||||
d->onPromotionCardClicked(card);
|
||||
});
|
||||
connect(card, &ElaPromotionCard::promotionCardClicked, this, [=]() { d->onPromotionCardClicked(card); });
|
||||
d->_updatePromotionCardGeometry();
|
||||
}
|
||||
|
||||
void ElaPromotionView::wheelEvent(QWheelEvent* event)
|
||||
{
|
||||
void ElaPromotionView::wheelEvent(QWheelEvent *event) {
|
||||
Q_D(ElaPromotionView);
|
||||
if (d->_isAllowSwitch)
|
||||
{
|
||||
if (event->angleDelta().y() > 0)
|
||||
{
|
||||
//右滑
|
||||
if (d->_isAllowSwitch) {
|
||||
if (event->angleDelta().y() > 0) {
|
||||
// 右滑
|
||||
d->_isAllowSwitch = false;
|
||||
QTimer::singleShot(400, this, [=] {
|
||||
d->_isAllowSwitch = true;
|
||||
});
|
||||
QTimer::singleShot(400, this, [=] { d->_isAllowSwitch = true; });
|
||||
d->onPromotionCardClicked(d->_promotionCardList[d->_getAdjacentIndex(Qt::RightToLeft, d->_pCurrentIndex)]);
|
||||
}
|
||||
else
|
||||
{
|
||||
//左滑
|
||||
} else {
|
||||
// 左滑
|
||||
d->_isAllowSwitch = false;
|
||||
QTimer::singleShot(400, this, [=] {
|
||||
d->_isAllowSwitch = true;
|
||||
});
|
||||
QTimer::singleShot(400, this, [=] { d->_isAllowSwitch = true; });
|
||||
d->onPromotionCardClicked(d->_promotionCardList[d->_getAdjacentIndex(Qt::LeftToRight, d->_pCurrentIndex)]);
|
||||
}
|
||||
}
|
||||
event->accept();
|
||||
}
|
||||
|
||||
void ElaPromotionView::paintEvent(QPaintEvent* event)
|
||||
{
|
||||
void ElaPromotionView::paintEvent(QPaintEvent *event) {
|
||||
Q_D(ElaPromotionView);
|
||||
QPainter painter(this);
|
||||
painter.save();
|
||||
painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
|
||||
painter.setPen(Qt::NoPen);
|
||||
painter.setBrush(ElaThemeColor(d->_themeMode, BasicIndicator));
|
||||
//页标指示器绘制
|
||||
int promotionCardCount = d->_promotionCardList.count();
|
||||
bool isCountOdd = promotionCardCount % 2;
|
||||
QPoint startPoint = isCountOdd ? QPoint(width() / 2 - promotionCardCount / 2 * d->_indicatorSpacing, height() - d->_bottomMargin / 2) : QPoint(width() / 2 - promotionCardCount / 2 * d->_indicatorSpacing - d->_indicatorSpacing / 2, height() - d->_bottomMargin / 2);
|
||||
for (int i = 0; i < promotionCardCount; i++)
|
||||
{
|
||||
if (i == d->_pCurrentIndex)
|
||||
{
|
||||
// 页标指示器绘制
|
||||
int promotionCardCount = d->_promotionCardList.count();
|
||||
bool isCountOdd = promotionCardCount % 2;
|
||||
QPoint startPoint =
|
||||
isCountOdd ? QPoint(width() / 2 - promotionCardCount / 2 * d->_indicatorSpacing, height() - d->_bottomMargin / 2)
|
||||
: QPoint(width() / 2 - promotionCardCount / 2 * d->_indicatorSpacing - d->_indicatorSpacing / 2, height() - d->_bottomMargin / 2);
|
||||
for (int i = 0; i < promotionCardCount; i++) {
|
||||
if (i == d->_pCurrentIndex) {
|
||||
painter.drawEllipse(QPointF(startPoint.x() + i * d->_indicatorSpacing, startPoint.y()), 3.5, 3.5);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
painter.drawEllipse(QPointF(startPoint.x() + i * d->_indicatorSpacing, startPoint.y()), 2.5, 2.5);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user