-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathCButtonBasedEditor.cpp
58 lines (42 loc) · 1.14 KB
/
CButtonBasedEditor.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
#include "CButtonBasedEditor.h"
#include <QHBoxLayout>
#include <QEvent>
CButtonBasedEditor::CButtonBasedEditor(QWidget *hostedEditor, QWidget *parent) :
QWidget(parent),
m_hostedEditor(hostedEditor)
{
QHBoxLayout* hbl = new QHBoxLayout();
hbl->setContentsMargins(0,0,0,0);
hbl->setSpacing(0);
setLayout(hbl);
hbl->addWidget(m_hostedEditor);
m_button = new QToolButton(this);
m_button->setText("...");
hbl->addWidget(m_button);
connect(m_button, SIGNAL(clicked()), this, SLOT(onEditButtonActivated()));
}
CButtonBasedEditor::~CButtonBasedEditor()
{
layout()->removeWidget(m_hostedEditor);
m_hostedEditor->setParent(NULL);
m_hostedEditor->hide();
}
void CButtonBasedEditor::enableButton(bool on)
{
m_button->setVisible(on);
}
bool CButtonBasedEditor::event(QEvent *e)
{
if (e->type() == QEvent::FocusIn)
{
m_hostedEditor->setFocus();
e->accept();
return true;
}
return QWidget::event(e);
}
void CButtonBasedEditor::showEvent(QShowEvent *e)
{
QWidget::showEvent(e);
m_hostedEditor->show();
}