OpenCores
URL https://opencores.org/ocsvn/ezidebug/ezidebug/trunk

Subversion Repositories ezidebug

[/] [ezidebug/] [trunk/] [EziDebug_src/] [button.cpp] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 EziDebug
#include "button.h"
2
 
3
Button::Button(QWidget *parent) : QPushButton(parent)
4
{
5
        //保存图片成员初始化
6
        buttonPicture = new QPixmap();
7
        pressPicture = new QPixmap();
8
        releasePicture = new QPixmap();
9
 
10
        enterPicture = new QPixmap();
11
        leavePicture = new QPixmap();
12
 
13
        //关闭按钮的默认显示
14
        this -> setFlat(true);
15
        this->setFocusPolicy(Qt::NoFocus);
16
 
17
        //初始化flag
18
        flag=false;
19
 
20
 
21
}
22
 
23
Button::Button(QString str, QWidget *parent) : QPushButton(parent)
24
{
25
        //保存图片成员初始化
26
        buttonPicture = new QPixmap();
27
        pressPicture = new QPixmap();
28
        releasePicture = new QPixmap();
29
 
30
        enterPicture = new QPixmap();
31
        leavePicture = new QPixmap();
32
 
33
        //关闭按钮的默认显示
34
        this -> setFlat(true);
35
        this->setFocusPolicy(Qt::NoFocus);
36
 
37
        //获取图像
38
        QPixmap objPixmap(str);
39
        //得到图像宽和高
40
        int nPixWidth = objPixmap.width() / 4;
41
        int nPixHeight = objPixmap.height();
42
        this->setButtonPicture(objPixmap.copy(nPixWidth*0,0,nPixWidth,nPixHeight));
43
        this->setPressPicture(objPixmap.copy(nPixWidth*2,0,nPixWidth,nPixHeight));
44
        this->setReleasePicture(objPixmap.copy(nPixWidth*3,0,nPixWidth,nPixHeight));
45
        this->setEnterPicture(objPixmap.copy(nPixWidth*1,0,nPixWidth,nPixHeight));
46
        this->setLeavePicture(objPixmap.copy(nPixWidth*3,0,nPixWidth,nPixHeight));
47
 
48
        //初始化flag
49
        flag=false;
50
 
51
 
52
}
53
 
54
void Button::setButtonPicture(QPixmap pic)
55
{
56
        *buttonPicture = pic;
57
 
58
        this -> setIcon(QIcon(*buttonPicture));
59
}
60
 
61
void Button::setPressPicture(QPixmap pic)
62
{
63
        *pressPicture = pic;
64
}
65
 
66
void Button::setReleasePicture(QPixmap pic)
67
{
68
        *releasePicture = pic;
69
}
70
 
71
void Button::setEnterPicture(QPixmap pic)
72
{
73
    *enterPicture = pic;
74
}
75
 
76
void Button::setLeavePicture(QPixmap pic)
77
{
78
    *leavePicture = pic;
79
}
80
 
81
void Button::set_X_Y_width_height(int x, int y, int width, int height)
82
{
83
        this -> setIconSize(QSize(width, height));
84
        this -> setGeometry(x, y, width, height);
85
}
86
 
87
void Button::mouseDoubleClickEvent(QMouseEvent *event)
88
{
89
        //null
90
}
91
 
92
void Button::mousePressEvent (QMouseEvent *event)
93
{
94
        this -> setIcon (QIcon(*pressPicture));
95
}
96
 
97
void Button::mouseMoveEvent(QMouseEvent *event)
98
{
99
        //null
100
}
101
 
102
 
103
void Button::mouseReleaseEvent (QMouseEvent *event)
104
{
105
        this -> setIcon(QIcon(*releasePicture));
106
        emit clicked();
107
}
108
 
109
void Button::enterEvent(QEvent *)
110
{
111
    this->setIcon(QIcon(*enterPicture));
112
    flag=true;
113
    setCursor(Qt::PointingHandCursor);
114
  //  this->resizeit();
115
 
116
}
117
 
118
void Button::leaveEvent(QEvent *)
119
{
120
    this->setIcon(QIcon(*leavePicture));
121
    flag=false;
122
}
123
 
124
void Button::resizeit(int w , int h)
125
{
126
    this->raise();
127
    this->resize(w,h);
128
    this ->setIconSize(QSize(w, h));
129
 
130
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.