#include "interactivebuttonbase.h"
#include<QPainterPath>
InteractiveButtonBase::InteractiveButtonBase(QWidget *parent)
: QPushButton(parent), icon(nullptr), text("按钮"), paint_addin(),
fore_paddings(4, 4, 4, 4),
self_enabled(true), parent_enabled(false), fore_enabled(true),
show_animation(false), show_foreground(true), show_ani_appearing(false), show_ani_disappearing(false),
show_duration(300), show_timestamp(0), hide_timestamp(0), show_ani_progress(0), show_ani_point(0, 0),
enter_pos(-1, -1), press_pos(-1, -1), release_pos(-1, -1), mouse_pos(-1, -1), anchor_pos(-1, -1),
offset_pos(0, 0), effect_pos(-1, -1), release_offset(0, 0),
hovering(false), pressing(false),
hover_timestamp(0), leave_timestamp(0), press_timestamp(0), release_timestamp(0),
hover_bg_duration(300), press_bg_duration(300), click_ani_duration(300),
move_speed(5),
icon_color(0, 0, 0), text_color(0, 0, 0),
//normal_bg(0xF2, 0xF2, 0xF2, 0), hover_bg(128, 128, 128, 32), press_bg(128, 128, 128, 64), border_bg(0, 0, 0, 0),
normal_bg(166, 211, 242,64), hover_bg(128, 128, 128, 32), press_bg(128, 128, 128, 64), border_bg(0, 0, 0, 0),
focus_bg(0, 0, 0, 0), focus_border(0, 0, 0, 0),
hover_speed(5), press_start(40), press_speed(5),
hover_progress(0), press_progress(0), icon_padding_proper(0.2), icon_text_padding(4), icon_text_size(16),
border_width(1), radius_x(10), radius_y(10),
font_size(12), fixed_fore_pos(false), fixed_fore_size(false), text_dynamic_size(true), auto_text_color(true), focusing(false),
click_ani_appearing(false), click_ani_disappearing(false), click_ani_progress(0),
mouse_press_event(nullptr), mouse_release_event(nullptr),
unified_geometry(false), _l(0), _t(0), _w(32), _h(32),
jitter_animation(false), elastic_coefficient(1.2), jitter_duration(300),
water_animation(true), water_press_duration(800), water_release_duration(400), water_finish_duration(300),
align(Qt::AlignCenter), _state(false), leave_after_clicked(false), _block_hover(false),
double_clicked(false), double_timer(nullptr), double_prevent(false)
{
setMouseTracking(true); // 鼠标没有按下时也能捕获移动事件
model = PaintModel::None;
anchor_timer = new QTimer(this);
anchor_timer->setInterval(10);
connect(anchor_timer, SIGNAL(timeout()), this, SLOT(anchorTimeOut()));
setWaterRipple();
connect(this, SIGNAL(clicked()), this, SLOT(slotClicked()));
setFocusPolicy(Qt::NoFocus); // 避免一个按钮还获取Tab键焦点
}
/**
* 文字类型的按钮
*/
InteractiveButtonBase::InteractiveButtonBase(QString text, QWidget *parent)
: InteractiveButtonBase(parent)
{
setText(text);
}
/**
* 图标类型的按钮
*/
InteractiveButtonBase::InteractiveButtonBase(QIcon icon, QWidget *parent)
: InteractiveButtonBase(parent)
{
setIcon(icon);
}
/**
* 变色图标类型的按钮
*/
InteractiveButtonBase::InteractiveButtonBase(QPixmap pixmap, QWidget *parent)
: InteractiveButtonBase(parent)
{
setPixmap(pixmap);
}
InteractiveButtonBase::InteractiveButtonBase(QIcon icon, QString text, QWidget *parent)
: InteractiveButtonBase(parent)
{
setIcon(icon);
setText(text);
}
InteractiveButtonBase::InteractiveButtonBase(QPixmap pixmap, QString text, QWidget *parent)
: InteractiveButtonBase(parent)
{
setPixmap(pixmap);
setText(text);
}
/**
* 设置按钮文字
* @param text 按钮文字
*/
void InteractiveButtonBase::setText(QString text)
{
this->text = text;
if (model == PaintModel::None)
{
model = PaintModel::Text;
setAlign(Qt::AlignCenter);
}
else if (model == PaintModel::PixmapMask)
{
if (pixmap.isNull())
model = PaintModel::Text;
else
model = PaintModel::PixmapText;
setAlign(Qt::AlignLeft | Qt::AlignVCenter);
QFontMetrics fm(this->font());
icon_text_size = fm.lineSpacing();
}
else if (model == PaintModel::Icon)
{
if (text.isEmpty())
{
model = PaintModel::Icon;
setAlign(Qt::AlignCenter);
}
else
{
if (icon.isNull())
model = PaintModel::Text;
else
model = PaintModel::IconText;
setAlign(Qt::AlignLeft | Qt::AlignVCenter);
QFontMetrics fm(this->font());
icon_text_size = fm.lineSpacing();
}
}
if (parent_enabled)
QPushButton::setText(text);
// 根据字体调整大小
if (text_dynamic_size)
{
adjustMinimumSize();
}
update();
}
/**
* 设置 icon 图标
* @param path 图标路径文本
*/
void InteractiveButtonBase::setIconPath(QString path)
{
setIcon(QIcon(path));
}
/**
* 设置 pixmap 图标
* @param path 图标路径文本
*/
void InteractiveButtonBase::setPixmapPath(QString path)
{
setPixmap(QPixmap(path));
}
/**
* 设置 icon
* @param icon 图标
*/
void InteractiveButtonBase::setIcon(QIcon icon)
{
if (model == PaintModel::None)
{
model = PaintModel::Icon;
setAlign(Qt::AlignCenter);
}
else if (model == PaintModel::Text)
{
if (text.isEmpty())
model = PaintModel::Icon;
else
model = PaintModel::IconText;
setAlign(Qt::AlignLeft | Qt::AlignVCenter);
QFontMetrics fm(this->font());
icon_text_size = fm.lineSpacing();
}
else if (model == PaintModel::PixmapMask)
{
pixmap = QPixmap();
model = PaintModel::Icon;
}
else if (model == PaintModel::PixmapText)
{
pixmap = QPixmap();
if (text.isEmpty())
model = PaintModel::Icon;
else
model = PaintModel::IconText;
setAlign(Qt::AlignLeft | Qt::AlignVCenter);
QFontMetrics fm(this->font());
icon_text_size = fm.lineSpacing();
}
else if (model == PaintModel::IconText && text.isEmpty())
{
model = PaintModel::Icon;
setAlign(Qt::AlignCenter);
}
this->icon = icon;
if (parent_enabled)
QPushButton::setIcon(icon);
update();
}
/**
* 设置 Pixmap
* @param pixmap [description]
*/
void InteractiveButtonBase::setPixmap(QPixmap pixmap)
{
if (model == PaintModel::None)
model = PaintModel::PixmapMask;
else if (model == PaintModel::Text)
{
if (text.isEmpty())
model = PaintModel::PixmapMask;
else
model = PaintModel::PixmapText;
setAlign(Qt::AlignLeft | Qt::AlignVCenter);
QFontMetrics fm(this->font());
icon_text_size = fm.lineSpacing();
}
else if (model == PaintModel::Icon)
{
icon = QIcon();
model = PaintModel::PixmapMask;
}
else if (model == PaintModel::IconText)
{
icon = QIcon();
if (text.isEmpty())
model = PaintModel::PixmapMask;
else
model = PaintModel::PixmapText;
setAlign(Qt::AlignLeft | Qt::AlignVCenter);
QFontMetrics fm(this->font());
icon_text_size = fm.lineSpacing();
}
this->pixmap = getMaskPixmap(pixmap, isEnabled() ? icon_color : getOpacityColor(icon_color));
if (parent_enabled)
QPushButton::setIcon(QIcon(pixmap));
update();
}
/**
* 设置额外的图标,例如角标
* @param pixmap 图标
* @param align 对齐方式
* @param size 图标尺寸
*/
void InteractiveButtonBase::setPaintAddin(QPixmap pixmap, Qt::Alignment align, QSize size)
{
QBitmap mask = pixmap.mask();
pixmap.fill(icon_color);
pixmap.setMask(mask);
paint_addin = PaintAddin(pixmap, align, size);
update();
}
/**
* 设置子类功能是否开启
* 如果关闭,则相当于默认的 QPushButton
* @param e 开关
*/
void InteractiveButtonBase::setSelfEnabled(bool e)
{
self_enabled = e;
}
/**
* 设置父类(QPushButton)功能是否开启
没有合适的资源?快使用搜索试试~ 我知道了~
基于C++&Qt和MySQL的图书管理系统.zip
共56个文件
cpp:21个
h:20个
ui:9个
需积分: 1 3 下载量 33 浏览量
2023-09-06
22:07:14
上传
评论 2
收藏 3.86MB ZIP 举报
温馨提示
基于C++&Qt和MySQL的图书管理系统.zip
资源推荐
资源详情
资源评论
收起资源包目录
基于C++&Qt和MySQL的图书管理系统.zip (56个子文件)
projectok_x
deleteinfo.cpp 1KB
pic
janko-ferlic-sfL_QOnmy00-unsplash.jpg 686KB
wallhaven-j8mqyp_1920x1080.png 3.13MB
batchimport.h 308B
changepassdialog.cpp 5KB
compensatedialog.ui 4KB
login.cpp 3KB
insertinfo.ui 8KB
book.h 2KB
readerui.cpp 10KB
book.cpp 9KB
readonlydelegate.cpp 256B
smtp
smtp.h 814B
smtp.cpp 3KB
changepassdialog.h 941B
admin.h 477B
toast
toast.cpp 3KB
toast.h 2KB
br_re_cp.h 679B
deleteinfo.ui 4KB
admin.cpp 1KB
login.ui 11KB
insertinfo.cpp 10KB
br_re_cp.ui 2KB
batchimport.cpp 4KB
main.cpp 170B
captchabox
captchabox.h 2KB
captchabox.cpp 8KB
readerui.h 981B
compensatedialog.cpp 2KB
changepassdialog.ui 5KB
interactive_buttons
interactivebuttonbase.h 17KB
interactivebuttonbase.cpp 60KB
adminui.h 1KB
LMIS.pro.user 31KB
encryptpass.cpp 214B
LMIS.pro 2KB
encryptpass.h 158B
LMIS.user 19KB
res.qrc 206B
br_re_cp.cpp 3KB
adminui.ui 27KB
reader.h 2KB
labeled_edit
bottomlineedit.cpp 710B
bottomlineedit.h 800B
labelededit.h 5KB
labelededit.cpp 33KB
mainwindow.ui.bak.ui 4KB
compensatedialog.h 696B
adminui.cpp 11KB
insertinfo.h 991B
readonlydelegate.h 412B
deleteinfo.h 534B
readerui.ui 13KB
reader.cpp 6KB
login.h 794B
共 56 条
- 1
资源评论
程皮
- 粉丝: 256
- 资源: 2485
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功