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
|
#include <kapp.h>
#include <qmenubar.h>
#include <qmessagebox.h>
#include <qpopupmenu.h>
#include <qprocess.h>
#include <qpushbutton.h>
#include <qvbox.h>
#include <qxembed.h>
#include "qt-embedder.h"
XEmbedQtEmbedder::XEmbedQtEmbedder ()
{
// Create menu
QPopupMenu *file_menu = new QPopupMenu (this);
menuBar()->insertItem ("&File", file_menu);
file_menu->insertItem( "&Quit", this, SLOT( maybeQuit() ), CTRL+Key_Q );
vbox_ = new QVBox (this);
setCentralWidget (vbox_);
QPushButton *button;
button = new QPushButton ("Add Active GTK+ Child", vbox_);
QObject::connect (button, SIGNAL(clicked()), this, SLOT(addActiveGtkChild()));
button = new QPushButton ("Add Passive GTK+ Child", vbox_);
QObject::connect (button, SIGNAL(clicked()), this, SLOT(addPassiveGtkChild()));
button = new QPushButton ("Add Active Qt Child", vbox_);
QObject::connect (button, SIGNAL(clicked()), this, SLOT(addActiveQtChild()));
button = new QPushButton ("Add Passive Qt Child", vbox_);
QObject::connect (button, SIGNAL(clicked()), this, SLOT(addPassiveQtChild()));
button = new QPushButton ("Remove Last Child", vbox_);
QObject::connect (button, SIGNAL(clicked()), this, SLOT(removeChild()));
}
void
XEmbedQtEmbedder::addChild (bool active, bool isQt)
{
QXEmbed *embedder = new QXEmbed (vbox_);
embedder->show ();
embedders_.append (embedder);
QProcess *proc = new QProcess (this);
proc->setCommunication (QProcess::Stdout);
if (isQt)
proc->addArgument ("./qt-client");
else
proc->addArgument ("./gtk-client");
if (!active)
proc->addArgument (QString::number (embedder->winId ()));
proc->start ();
if (active)
{
QString pid_str = proc->readLineStdout ();
embedder->embed (pid_str.toLong ());
}
}
void
XEmbedQtEmbedder::addActiveGtkChild ()
{
addChild (TRUE, FALSE);
}
void
XEmbedQtEmbedder::addPassiveGtkChild ()
{
addChild (TRUE, FALSE);
}
void
XEmbedQtEmbedder::addActiveQtChild ()
{
addChild (TRUE, TRUE);
}
void
XEmbedQtEmbedder::addPassiveQtChild ()
{
addChild (FALSE, TRUE);
}
void
XEmbedQtEmbedder::removeChild ()
{
if (!embedders_.isEmpty ())
{
embedders_.getLast()->close();
embedders_.removeLast();
}
}
void
XEmbedQtEmbedder::maybeQuit ()
{
QMessageBox mb( "qt-embedder", "Really Quit?",
QMessageBox::Information,
QMessageBox::Yes | QMessageBox::Default,
QMessageBox::Cancel | QMessageBox::Escape,
0, this );
mb.setButtonText( QMessageBox::Yes, "&Quit" );
mb.setButtonText( QMessageBox::No, "Cancel");
if (mb.exec() == QMessageBox::Yes)
{
qApp->closeAllWindows ();
}
}
int main( int argc, char **argv )
{
KApplication a( argc, argv, "qt-embedder" );
XEmbedQtEmbedder *embedder = new XEmbedQtEmbedder ();
a.setMainWidget( embedder );
embedder->show();
return a.exec();
}
|