summaryrefslogtreecommitdiffstats
path: root/xembed/tests/qt-embedder.cpp
blob: e004204e67e138b56f121bd96aa57b05f8636308 (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
#include <kapp.h>
#include <qmenubar.h>
#include <qmessagebox.h>
#include <qpopupmenu.h>
#include <qpushbutton.h>
#include <qvbox.h>

#include "qt-common.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)
{
  XEmbedQtChildSite *site = new XEmbedQtChildSite (vbox_, active, isQt);

  embedders_.append (site);
}

void
XEmbedQtEmbedder::addActiveGtkChild ()
{
  addChild (TRUE, FALSE);
}

void
XEmbedQtEmbedder::addPassiveGtkChild ()
{
  addChild (FALSE, 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();
}