-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaunchbutton.h
More file actions
148 lines (120 loc) · 3.38 KB
/
Copy pathlaunchbutton.h
File metadata and controls
148 lines (120 loc) · 3.38 KB
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
#ifndef LAUNCHBUTTON_H
#define LAUNCHBUTTON_H
#include <QPushButton>
#include <QProcess>
#include <QDebug>
#include <QStyleOptionViewItem>
#include <QStyledItemDelegate>
#include <QStylePainter>
#include <QKeyEvent>
#include <QMenu>
class launchButton : public QPushButton
{
Q_OBJECT
private:
QString cmdName;
public:
explicit launchButton(QWidget *parent = 0);
launchButton(QIcon ico):
QPushButton(ico,NULL)
{
// setStyleSheet("border-style: outset; border-width: 0px;");
QPalette* palette3 = new QPalette();
palette3->setColor(QPalette::Button,Qt::transparent);
setPalette(*palette3);
}
void launch(){
QProcess p;
p.startDetached(cmdName);
}
void setCmdName(QString cmd){cmdName = cmd;}
QString getCmdName(){ return cmdName;}
void focusInEvent ( QFocusEvent * e )
{
// QPushButton::focusInEvent(e);
// qDebug()<<(QPushButton*)this<<__func__;
setPalette( QPalette( Qt::darkGray ) );
setAutoFillBackground(true);
setAutoDefault(true);
update();
}
void focusOutEvent ( QFocusEvent * e )
{
//QPushButton::focusOutEvent(e);
// qDebug()<<(QPushButton*)this<<__func__;
setPalette( QPalette( Qt::black) );
setAutoFillBackground(true);
update();
}
void mousePressEvent(QMouseEvent* e)
{
QPushButton::mousePressEvent(e);
switch(e->button())
{
// case Qt::Key_Down:
// {
// QKeyEvent k( QEvent::KeyPress,Qt::Key_Tab,Qt::NoModifier);
// keyPressEvent(&k);
// qDebug()<<"down pressed";
// break;
// }
case Qt::RightButton:
{
qDebug()<<"mouse dx on "<<this;
QMenu *m = new QMenu;
QAction* a = new QAction("Edit",this);
connect(a,SIGNAL(triggered()),this,SLOT(menuActionEdit()));
m->addAction(a);
a = new QAction("Remove",this);
connect(a,SIGNAL(triggered()),this,SLOT(menuActionRemove()));
m->addAction(a);
m->popup(this->pos()+e->pos());
break;
}
}
}
void mouseReleaseEvent(QMouseEvent* e)
{
qDebug()<<__func__<<e;
QPushButton::mouseReleaseEvent(e);
switch(e->type())
{
case QEvent::MouseButtonRelease:
{
setPalette( QPalette( Qt::black) );
setAutoFillBackground(true);
update();
break;
}
}
}
protected:
void paintEvent(QPaintEvent *e)
{
QStyleOptionButton option;
option.initFrom(this);
option.icon = icon();
option.text = text();
option.iconSize = iconSize();
option.features = QStyleOptionButton::Flat;
if (option.state & QStyle::State_HasFocus)
option.state = option.state ^ QStyle::State_HasFocus;
QStylePainter painter(this);
style()->drawControl(QStyle::CE_PushButton,&option,&painter,this);
}
signals:
void remove(QWidget*);
void edit(QWidget*);
public slots:
void menuActionEdit()
{
qDebug()<<__func__;
emit edit(this);
}
void menuActionRemove()
{
qDebug()<<__func__;
emit remove(this);
}
};
#endif // LAUNCHBUTTON_H