前文链接:Qt实现思维导图功能(四)
思维导图纵向分布模式:模式一
百度网盘体验地址:
链接:https://pan.baidu.com/s/1YNSBiFOUwnSSKvHsBvOT3g
提取码:ifyc
动态演示效果
静态展示图片
前文BUG维护
序号 | 问题 |
---|---|
1 | 修复侧滑菜单栏首次收缩卡顿问题 |
2 | 修复侧滑功能窗口未能置顶问题 |
3 | 修复侧滑功能窗口状态未与思维导图状态统一问题 |
4 | 优化侧滑功能窗口图片,由svg格式文件转换 |
5 | 升级侧滑功能窗口,增加功能标题和功能备注,增加鼠标进出动态效果 |
新增功能如下
序号 | 简述 | 具体功能 |
---|---|---|
1 | 布局转换 | 思维导图横向模式与纵向模式间任意切换 |
新升级的侧滑窗口鼠标进出动效代码
#pragma once/** 思维导图-侧滑窗体-阴影图画按钮* 按钮文本:标题|说明(文本用“|”分割)*/#include <QPushButton>
#include <QPaintEvent>class QPropertyAnimation;class ShadowButton : public QPushButton
{Q_OBJECTQ_PROPERTY(int offsetY READ offsetY WRITE setOffsetY)public:ShadowButton(QWidget *parent = nullptr);~ShadowButton();// 设置图片void setPixmap(const QPixmap &pixmap);protected:void paintEvent(QPaintEvent *event);void enterEvent(QEvent *event);void leaveEvent(QEvent *event);private:void setOffsetY(int offsetY);int offsetY();private:qreal m_opacity; // 透明度QColor m_coverColor; // 遮罩颜色QPixmap m_pixmap; // 图片int m_coverHieght; // 遮罩高度int m_offsetY; // 遮罩偏移QPropertyAnimation *m_animation;
};
#include "ShadowButton.h"
#include <QPainter>
#include <QPropertyAnimation>ShadowButton::ShadowButton(QWidget *parent /*= nullptr*/)
{m_opacity = 0.75;m_coverColor = QColor(0, 0, 0);m_coverHieght = 100;m_offsetY = m_coverHieght / 2;setCheckable(true);m_animation = new QPropertyAnimation(this, "offsetY", this);m_animation->setEasingCurve(QEasingCurve::Linear);m_animation->setDuration(300);
}ShadowButton::~ShadowButton()
{}void ShadowButton::setPixmap(const QPixmap &pixmap)
{m_pixmap = pixmap;
}void ShadowButton::paintEvent(QPaintEvent *event)
{Q_UNUSED(event)QPainter painter(this);painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);// 设置剪切路径QPainterPath path;int radius = 10;path.addRoundedRect(rect(), radius, radius);painter.setClipPath(path);// 绘制图片painter.drawPixmap(rect(), m_pixmap);// 绘制遮罩painter.setPen(Qt::NoPen);painter.setBrush(m_coverColor);painter.setOpacity(m_opacity);QPainterPath coverPath1;coverPath1.addRect(rect());QPainterPath coverPath2;coverPath2.addRect(rect().adjusted(0, height() - m_offsetY, 0, 0));QPainterPath coverPath = coverPath1.intersected(coverPath2);painter.drawPath(coverPath);// 绘制标题painter.setPen(Qt::white);QStringList texts = text().split("|");if (2 == texts.size())painter.drawText(QRect(0, height() - m_offsetY + m_coverHieght / 2, width(), m_coverHieght / 2), Qt::AlignCenter, texts.at(1));if (1 <= texts.size()){if (isChecked())painter.setPen(QPen(QColor(119, 169, 253)));QFont font = painter.font();font.setPixelSize(20);painter.setFont(font);painter.drawText(QRect(0, height() - m_offsetY, width(), m_coverHieght / 2), Qt::AlignCenter, texts.at(0));}
}void ShadowButton::enterEvent(QEvent *event)
{Q_UNUSED(event)if (m_animation->state() != QAbstractAnimation::Stopped)m_animation->stop();m_animation->setStartValue(m_offsetY);m_animation->setEndValue(m_coverHieght);m_animation->start();update();
}void ShadowButton::leaveEvent(QEvent *event)
{Q_UNUSED(event)if (m_animation->state() != QAbstractAnimation::Stopped)m_animation->stop();m_animation->setStartValue(m_offsetY);m_animation->setEndValue(m_coverHieght / 2);m_animation->start();update();
}void ShadowButton::setOffsetY(int offsetY)
{m_offsetY = offsetY;update();
}int ShadowButton::offsetY()
{return m_offsetY;
}