4 # include <QtGui/QX11Info>
6 # include <X11/Xatom.h>
9 #include "adopterwindow.h"
13 AdopterWindow::AdopterWindow(QWidget *parent):
14 QMainWindow(parent), grabbingZoomKeys(false), mainChild(0)
19 setAttribute(Qt::WA_Maemo5StackedWindow, true);
20 #endif // Q_WS_MAEMO_5
22 QFrame *frame = new QFrame(this);
23 QVBoxLayout *layout = new QVBoxLayout(frame);
25 frame->setLayout(layout);
26 setCentralWidget(frame);
29 QAction *closeAction = new QAction(parent? tr("Back"): tr("Exit"), this);
30 closeAction->setSoftKeyRole(QAction::NegativeSoftKey);
31 connect(closeAction, SIGNAL(triggered()), this, SLOT(close()));
32 QMainWindow::addAction(closeAction);
35 setUnifiedTitleAndToolBarOnMac(true);
36 toolBar = addToolBar("controls");
37 toolBar->setMovable(false);
38 toolBar->setFloatable(false);
39 toolBar->toggleViewAction()->setVisible(false);
40 #if defined(Q_WS_X11) && !defined(Q_WS_MAEMO_5)
41 toolBar->setIconSize(QSize(42, 42));
43 #endif // Q_OS_SYMBIAN
46 void AdopterWindow::takeChildren(QWidget *main, const QList<QWidget *> &others)
52 mainChild->setParent(centralWidget());
53 centralWidget()->layout()->addWidget(mainChild);
56 foreach (QWidget *child, others) {
58 child->setParent(this);
63 void AdopterWindow::leaveChildren()
67 centralWidget()->layout()->removeWidget(mainChild);
72 void AdopterWindow::grabZoomKeys(bool grab)
75 grabbingZoomKeys = grab;
79 void AdopterWindow::showEvent(QShowEvent *e)
82 doGrabZoomKeys(grabbingZoomKeys);
83 QMainWindow::showEvent(e);
86 void AdopterWindow::doGrabZoomKeys(bool grab)
91 qDebug() << "Not visible - skipping";
94 qDebug() << "Could not get window ID - skipping";
97 unsigned long val = grab? 1: 0;
98 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
100 qCritical() << "Unable to obtain _HILDON_ZOOM_KEY_ATOM";
103 XChangeProperty(QX11Info::display(),
109 reinterpret_cast<unsigned char *>(&val),
113 #endif // Q_WS_MAEMO_5
116 void AdopterWindow::show()
119 foreach (QWidget *w, QApplication::allWidgets()) {
120 w->setContextMenuPolicy(Qt::NoContextMenu);
129 QAction *AdopterWindow::addToolBarAction(QObject *receiver,
131 const QString &iconName,
135 qDebug() << "icon" << iconName << "text" << text;
137 return toolBar->addAction(QIcon(Platform::icon(iconName)),
138 text, receiver, member);
141 QAction *action = new QAction(text, this);
142 menuBar()->addAction(action);
143 connect(action, SIGNAL(triggered()), receiver, member);
148 void AdopterWindow::addToolBarSpace()
151 QFrame *frame = new QFrame(toolBar);
152 frame->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
153 toolBar->addWidget(frame);