-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy360button.cpp
500 lines (478 loc) · 15.4 KB
/
my360button.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
#include "my360button.h"
#include<QPainter>
#include<QDebug>
#include<QLabel>
#include<QHBoxLayout>
#include<QFontMetrics>
mainButton::mainButton(QString strpixnormal,QString strpixenter,QString strpixleave,QWidget*parent):QPushButton(parent)
{
QPixmap pixnormal(strpixnormal);
QPixmap pixenter(strpixenter);
QPixmap pixleave(strpixleave);
setCursor(Qt::PointingHandCursor);
m_leave=false;
m_enter=true;
m_leaveIndex=0;
m_enterIndex=0;
m_pixnormal=pixnormal;
for(int i=0;i<10;i++)//进入
{
m_enterlist<<pixenter.copy(i*(pixenter.width()/10),0,pixenter.width()/10,pixenter.height());
}
for(int j=0;j<8;j++)//离开
{
m_leavelist<<pixleave.copy(j*(pixleave.width()/8),0,pixleave.width()/8,pixleave.height());
}
m_enteranimation=new QPropertyAnimation(this,"");
m_enteranimation->setStartValue(0);
m_enteranimation->setEndValue(9);
m_enteranimation->setDuration(600);
connect(m_enteranimation,SIGNAL(valueChanged(QVariant)),this,SLOT(entervaluechange(QVariant)));
m_leaveanimation=new QPropertyAnimation(this,"");
m_leaveanimation->setStartValue(0);
m_leaveanimation->setEndValue(7);
m_leaveanimation->setDuration(600);
connect(m_leaveanimation,SIGNAL(valueChanged(QVariant)),this,SLOT(leavevaluechange(QVariant)));
}
mainButton::~mainButton()
{
delete m_leaveanimation;
delete m_enteranimation;
}
void mainButton::enterEvent(QEvent *)
{
m_enter=true;
m_leave=false;
m_enteranimation->start();
}
void mainButton::leaveEvent(QEvent *)
{
m_enter=false;
m_leave=true;
m_leaveanimation->start();
}
void mainButton::paintEvent(QPaintEvent *)
{
QPainter painter(this);
if(m_enter)
painter.drawPixmap(rect(),m_enterlist.at(m_enterIndex));
if(m_leave)
painter.drawPixmap(rect(),m_leavelist.at(m_leaveIndex));
}
///////////////////////////////////////////////////////////////////////////////////////////////第二组
main2Button::main2Button(QString pixnormal, QString text, QWidget *parent):QPushButton(parent)
{
this->setCursor(Qt::PointingHandCursor);
m_pix=QPixmap(pixnormal);
m_text=text;
m_enter=false;
QPixmap borpix(":/image/btnborder.png");
m_pixborder=borpix.copy(2*(borpix.width()/3),0,borpix.width()/3,borpix.height());//第二个
}
void main2Button::paintEvent(QPaintEvent *)
{
QPainter painter(this);
if(m_enter)
painter.drawPixmap(rect(),m_pixborder);
painter.drawPixmap(QRect((rect().width()-m_pix.width())/2,(rect().height()-m_pix.height())/3,m_pix.width(),m_pix.height()),m_pix);
QFont font;
QFontMetrics fontmetr(font);
int m_width= fontmetr.width(m_text);
painter.setPen(QColor(124, 124, 124));
painter.drawText(QPoint((rect().width()-m_width)/2,(rect().height()-m_pix.height())/3+m_pix.height()+20),m_text);
}
void main2Button::enterEvent(QEvent *)
{
m_enter=true;
update();
}
void main2Button::leaveEvent(QEvent *)
{
m_enter=false;
update();
}
///////////////////////////////////////////////////////////////////
main3Button::main3Button(QString pixnormal,QWidget *parent):QPushButton(parent)
{
this->setCursor(Qt::PointingHandCursor);
m_index=0;
m_enter=false;
QPixmap pix(pixnormal);
for(int i=0;i<4;i++)
m_pixlist<<pix.copy(i*(pix.width()/4),0,pix.width()/4,pix.height());
}
void main3Button::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.drawPixmap((width()-m_pixlist.at(m_index).width())/2,(height()-m_pixlist.at(m_index).height())/2
,m_pixlist.at(m_index).width()
,m_pixlist.at(m_index).height(),m_pixlist.at(m_index));//画图画到中间
}
void main3Button::enterEvent(QEvent *)
{
m_index=1;
m_enter=true;
update();
}
void main3Button::leaveEvent(QEvent *)
{
m_index=0;
m_enter=false;
update();
}
void main3Button::mousePressEvent(QMouseEvent *e)
{
if(e->button()==Qt::LeftButton)//如果是左键按下
{
m_index=2;
update();
QPushButton::mousePressEvent(e);//返回到上级
}
}
void main3Button::mouseReleaseEvent(QMouseEvent *e)
{
if(e->button()==Qt::LeftButton)//如果是左键放下
{
m_index=1;
update();
QPushButton::mouseReleaseEvent(e);//返回到上级 引出按钮clicked信号
}
}
/////////////////////////////////////////////////////////头像
headButton::headButton(QWidget*parent):QPushButton(parent)
{
setCursor(Qt::PointingHandCursor);
m_index=0;
QPixmap pixheadbor(":/image/head_bkg.png");
m_pixlist<<pixheadbor.copy(0,0,pixheadbor.width()/2,pixheadbor.height());
m_pixlist<<pixheadbor.copy(pixheadbor.width()/2,0,pixheadbor.width()/2,pixheadbor.height());
}
void headButton::paintEvent(QPaintEvent*)
{
QPainter painter(this);
painter.drawPixmap(rect(),m_pixlist.at(m_index));
QPixmap pixhead(":/image/head.png");
painter.drawPixmap((width()-pixhead.width())/2,(height()-pixhead.height())/2,pixhead.width(),pixhead.height(),pixhead);
}
void headButton::enterEvent(QEvent *)
{
m_index=1;
update();
}
void headButton::leaveEvent(QEvent *)
{
m_index=0;
update();
}
///////////////////////////////////////////////////////////////////
wordslineButton::wordslineButton(QString text,QWidget *parent):QPushButton(parent)
{
setCursor(Qt::PointingHandCursor);
m_text=text;
m_enter=false;
}
void wordslineButton::paintEvent(QPaintEvent *)
{
QPainter p(this);
QFont font;
QFontMetrics metric(font);
if(m_enter)
font.setUnderline(true);
p.setPen(Qt::white);
p.setFont(font);
p.drawText((width()-metric.width(m_text))/2,height()/2,m_text);
}
void wordslineButton::enterEvent(QEvent *)
{
m_enter=true;
update();
}
void wordslineButton::leaveEvent(QEvent *)
{
m_enter=false;
update();
}
////////////////////////////////////////////////////////////////////////////////////////////
checkButton::checkButton(QString pixcheckurl,QString pixuncheckurl, QWidget *parent):QPushButton(parent)
{
setCursor(Qt::PointingHandCursor);
setFixedSize(150,150);
m_checkindex=4;//checkbox的值
m_uncheckindex=0;//checkbox的值
m_checked=true;
m_enter=false;
m_pixcheck=QPixmap(pixcheckurl);
m_pixuncheck=QPixmap(pixuncheckurl);
QPixmap pixcheckbox(":/image/cat_checkbox.png");
for(int i=0;i<12;i++)
m_checklist<<pixcheckbox.copy(i*(pixcheckbox.width()/12),0,pixcheckbox.width(),pixcheckbox.height());
}
void checkButton::paintEvent(QPaintEvent *)
{
QPainter p(this);
QPainter p1(this);
QPixmap m_pixcheckhover(":/image/cat_hover.png");
QPixmap m_pixuncheckhover(":/image/cat_gray_hover.png");
if(m_checked)//如果选中了
{
if(m_enter)
{
p.drawPixmap(rect(),m_pixcheckhover);
p.drawPixmap(110,110,m_checklist.at(m_checkindex));
}
p1.drawPixmap(rect(),m_pixcheck);
p1.drawPixmap(110,110,m_checklist.at(m_checkindex));
}
else//如果没选中了
{
if(m_enter)
{
p.drawPixmap(rect(),m_pixuncheckhover);
p.drawPixmap(110,110,m_checklist.at(m_uncheckindex));
}
p1.drawPixmap(rect(),m_pixuncheck);
p1.drawPixmap(110,110,m_checklist.at(m_uncheckindex));
}
}
void checkButton::enterEvent(QEvent *)
{
m_checkindex=5;//选中的
m_uncheckindex=1;//黑色的
m_enter=true;
update();
}
void checkButton::mousePressEvent(QMouseEvent *e)
{
if(e->button()==Qt::LeftButton)
{
if(m_checked)
m_checked=false;
else
m_checked=true;
update();
QPushButton::mousePressEvent(e);
}
}
void checkButton::leaveEvent(QEvent *)
{
m_enter=false;
m_checkindex=4;//checkbox的值
m_uncheckindex=0;//checkbox的值
update();
}
////////////////////////////////////////////////////////////////
main4Button::main4Button(QString pixani,QString pixurl,QWidget*parent):QPushButton(parent)
{
QPixmap anipix(pixani);
QPixmap norpix(pixurl);
for(int i=0;i<4;i++)
m_normallist<<norpix.copy(i*(norpix.width()/4),0,norpix.width()/4,norpix.height());
for(int i=0;i<8;i++)
m_animalist<<anipix.copy(i*(anipix.width()/8),0,anipix.width()/8,anipix.height());
setCursor(Qt::PointingHandCursor);
animaindex=0;
m_animation=new QPropertyAnimation(this,"");
m_animation->setStartValue(0);
m_animation->setEndValue(7);
m_animation->setDuration(500);
connect(m_animation,SIGNAL(valueChanged(QVariant)),this,SLOT(slot_valuechange(QVariant)));
m_enter=false;
}
void main4Button::paintEvent(QPaintEvent *)
{
QPainter p(this);
if(m_enter)
{
p.drawPixmap(rect(),m_animalist.at(animaindex));
}
else
{
p.drawPixmap(rect(),m_normallist.at(0));
}
}
void main4Button::enterEvent(QEvent *)
{
m_enter=true;
m_animation->start();
}
void main4Button::leaveEvent(QEvent *)
{
m_enter=false;
update();
}
///////////////////////////////////////////////////////////////////////////////////////
cleanMainButton::cleanMainButton(QString normal,QString gray,QString aninormal,QString anigray,int number,QWidget *parent):QPushButton(parent)
{
m_pixnormal=QPixmap(normal);
m_pixgray=QPixmap(gray);
QPixmap pixani(aninormal);
QPixmap pixanigray(anigray);
count=number;
for(int i=0;i<count;i++)//正常
m_pixaninormallist<<pixani.copy(i*(pixani.width()/count),0,pixani.width()/count,pixani.height());
for(int i=0;i<count;i++)//gray
m_pixanigraylist<<pixanigray.copy(i*(pixanigray.width()/count),0,pixanigray.width()/count,pixanigray.height());
setCursor(Qt::PointingHandCursor);
m_enter=false;
m_ischeck=true;
m_normalindex=0;
m_aninormal=new QPropertyAnimation(this,"");
m_aninormal->setStartValue(0);
m_aninormal->setEndValue(count-1);
m_aninormal->setDuration(1200);
connect(m_aninormal,SIGNAL(valueChanged(QVariant)),this,SLOT(slot_normalaimachange(QVariant)));
}
void cleanMainButton::paintEvent(QPaintEvent *)
{
QPixmap pixcheck(":/image/clean/group_check.png");
QPixmap pixuncheck(":/image/clean/group_uncheck.png");
QPixmap pixcheck_hoverborder(":/image/clean/select_hover.png");
QPixmap pixcheckborder(":/image/clean/select_normal.png");
QPixmap pixuncheck_hoverborder(":/image/clean/notselect_hover.png");
QPixmap pixuncheckborder(":/image/clean/notselect_normal.png");
QPainter p(this);
QPainter p2(this);
if(m_enter)//如果进入就启动动画
{
if(m_ischeck)//选中动画
{
p.drawPixmap((width()-pixcheckborder.width())/2,(height()-pixcheckborder.height())/2,pixcheckborder);
p2.drawPixmap((width()-pixcheck_hoverborder.width())/2,(height()-pixcheck_hoverborder.height())/2,pixcheck_hoverborder);
p.drawPixmap((width()-m_pixaninormallist.at(m_normalindex).width())/2,(height()-m_pixaninormallist.at(m_normalindex).height())/2
,m_pixaninormallist.at(m_normalindex));
p.drawPixmap(width()-pixcheck.width(),height()-1.5*(pixcheck.height()),pixcheck);
}
else//非选中动画
{
p.drawPixmap((width()-pixuncheckborder.width())/2,(height()-pixuncheckborder.height())/2,pixuncheckborder);
p2.drawPixmap(rect(),pixuncheck_hoverborder);
p.drawPixmap((width()-m_pixanigraylist.at(m_normalindex).width())/2,(height()-m_pixanigraylist.at(m_normalindex).height())/2
,m_pixanigraylist.at(m_normalindex));
p.drawPixmap(width()-pixuncheck.width(),height()-1.5*(pixuncheck.height()),pixuncheck);
}
}
else//如果不进入
{
if(m_ischeck)//如果是选中就做选中动画//起始位置
{
p.drawPixmap((width()-m_pixnormal.width())/2,(height()-m_pixnormal.height())/2,m_pixnormal);
p.drawPixmap(width()-pixcheck.width(),height()-1.5*(pixcheck.height()),pixcheck);
}
else
{
p.drawPixmap((width()-m_pixgray.width())/2,(height()-m_pixgray.height())/2,m_pixgray);
p.drawPixmap(width()-pixuncheck.width(),height()-1.5*(pixuncheck.height()),pixuncheck);
}
}
}
void cleanMainButton::enterEvent(QEvent *)
{
m_enter=true;
m_aninormal->start();
}
void cleanMainButton::mousePressEvent(QMouseEvent *e)
{
if(e->button()==Qt::LeftButton)
{
if(m_ischeck)
m_ischeck=false;
else
m_ischeck=true;
m_aninormal->start();
QPushButton::mousePressEvent(e);
}
}
void cleanMainButton::leaveEvent(QEvent *)//如果离开
{
m_enter=false;
m_aninormal->stop();
m_normalindex=0;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
main5Button::main5Button(QString pixnormal,QString text,QWidget *parent):QPushButton(parent)
{
this->setCursor(Qt::PointingHandCursor);
m_index=0;
m_enter=false;
QPixmap pix(pixnormal);
for(int i=0;i<4;i++)
m_pixlist<<pix.copy(i*(pix.width()/4),0,pix.width()/4,pix.height());
m_text=text;
setStyleSheet("main5Button{color:rgb(36,147,229)}"
"main5Button::hover{color:rgb(36,147,229,180)}");
}
void main5Button::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.drawPixmap((width()-m_pixlist.at(m_index).width())/2,(height()-m_pixlist.at(m_index).height())/2
,m_pixlist.at(m_index).width()
,m_pixlist.at(m_index).height(),m_pixlist.at(m_index));//画图画到中间
QFont font;
QFontMetrics metri(font);
painter.setPen(QColor(36,147,229));
int w= metri.width(m_text);
painter.drawText((width()-w)/2+5,16,m_text);
}
void main5Button::enterEvent(QEvent *)
{
m_index=1;
update();
}
void main5Button::leaveEvent(QEvent *)
{
m_index=0;
m_enter=false;
update();
}
void main5Button::mousePressEvent(QMouseEvent *e)
{
if(e->button()==Qt::LeftButton)//如果是左键按下
{
m_index=2;
update();
QPushButton::mousePressEvent(e);
}
}
void main5Button::mouseReleaseEvent(QMouseEvent *e)
{
if(e->button()==Qt::LeftButton)//如果是左键放下
{
m_index=1;
update();
QPushButton::mouseReleaseEvent(e);
}
}
////////////////////////////////////////////////////////////////////////////
main6Button::main6Button(QString pixurl,QString text,QWidget*parent):QPushButton(parent)//一个图片with 下文字
{
setStyleSheet("background:transparent");
m_pix=QPixmap(pixurl);
m_text=text;
m_enter=false;
}
void main6Button::paintEvent(QPaintEvent *e)
{
QPainter p(this);
if(m_enter)
{
p.setBrush(QColor(242,242,242));
p.drawRect(-1,-1,width()+1,height()+1);
}
p.drawPixmap((width()-m_pix.width())/2,15,m_pix);
p.setPen(QColor(88,88,88));
QFont font;
QFontMetrics metric(font);
int w= metric.width(m_text);
p.drawText((width()-w)/2,70,m_text);
QPushButton::paintEvent(e);
}
void main6Button::enterEvent(QEvent *)
{
m_enter=true;
update();
}
void main6Button::leaveEvent(QEvent *)
{
m_enter=false;
update();
}