summaryrefslogtreecommitdiffstats
path: root/xembed/tests/qt-client.cpp
blob: ef4073987f1c4897bd576e3c8e260d48d0ac336a (plain)
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
#include <kapp.h>
#include <qhbox.h>
#include <qlabel.h>
#include <qlineedit.h>
#include <qlayout.h>
#include <qpushbutton.h>
#include <qtimer.h>

#include <qxembed.h>

#include "qt-client.h"
#include "qt-common.h"

XEmbedQtButtonBox::XEmbedQtButtonBox (QWidget *parent, XEmbedQtClient *client)
  : QWidget (parent)
{
  QHBoxLayout *layout = new QHBoxLayout (this);
  layout->setAutoAdd (TRUE);
  
  QPushButton *button;

  button = new QPushButton( "&Add", this );
  QObject::connect (button, SIGNAL(clicked()), client, SLOT(addButtons()));
  
  button = new QPushButton( "&Remove", this );
  QObject::connect (button, SIGNAL(clicked()), this, SLOT(close()));
}


XEmbedQtClient::XEmbedQtClient ()
{
  setFrameStyle (QFrame::Box | QFrame::Sunken);
  
  QVBoxLayout *vlayout = new QVBoxLayout (this);

  vlayout->setAutoAdd (TRUE);
  vlayout->setMargin (5);
  
  hbox_ = new QHBox (this);

  new QLabel ("Qt", hbox_);
  
  new QLineEdit (hbox_);
  
  QPushButton *button;

  button = new QPushButton( "&Close", hbox_ );
  QObject::connect (button, SIGNAL(clicked()), this, SLOT(close()));

  button = new QPushButton( "&Blink", hbox_ );
  QObject::connect (button, SIGNAL(clicked()), this, SLOT(blink()));

  button = new QPushButton( "Add &GTK+", hbox_ );
  QObject::connect (button, SIGNAL(clicked()), this, SLOT(addGtkChild()));

  button = new QPushButton( "Add &Qt", hbox_ );
  QObject::connect (button, SIGNAL(clicked()), this, SLOT(addQtChild()));

  addButtons();
}

void
XEmbedQtClient::blink()
{
  hide ();

  QTimer *timer = new QTimer ( this );
  QObject::connect (timer, SIGNAL(timeout()), this, SLOT(show()));
  timer->start (1000, TRUE);
}

void
XEmbedQtClient::addGtkChild()
{
  new XEmbedQtChildSite (this, FALSE, FALSE);
}

void
XEmbedQtClient::addQtChild()
{
  new XEmbedQtChildSite (this, FALSE, TRUE);
}

void
XEmbedQtClient::addButtons ()
{
  XEmbedQtButtonBox *box = new XEmbedQtButtonBox (hbox_, this);
  box->show();
}

int main( int argc, char **argv )
{
  KApplication a( argc, argv, "qt-client" );
  WId embedder_xid, client_xid;
  XEmbedQtClient *client;
  
  if (argc != 1 && argc != 2)
    {
      fprintf (stderr, "Usage: qt-client [WINDOW_ID]\n");
      exit (1);
    }
  
  QXEmbed::initialize ();
  
  if (argc == 2)
    {
      embedder_xid = strtol (argv[1], NULL, 0);
      if (embedder_xid == 0)
	{
	  fprintf (stderr, "Invalid window id '%s'\n", argv[1]);
	  exit (1);
	}
      
      client = new XEmbedQtClient ();
      QXEmbed::embedClientIntoWindow (client, embedder_xid);
    }
  else
    {
      client = new XEmbedQtClient ();
      printf ("%d\n", client->winId());
      fflush (stdout);
    }
  
  a.setMainWidget( client );
   
  return a.exec();
}