4 # include <QtGui/QX11Info>
6 # include <X11/Xatom.h>
9 #include "adopterwindow.h"
13 # define ICON_PREFIX ":/icons/mac/"
15 # define ICON_PREFIX ":/icons/"
18 AdopterWindow::AdopterWindow(QWidget *parent):
19 QMainWindow(parent), grabbingZoomKeys(false), mainChild(0)
21 Trace t("AdopterWindow::AdopterWindow");
24 setAttribute(Qt::WA_Maemo5StackedWindow, true);
25 #endif // Q_WS_MAEMO_5
27 QFrame *frame = new QFrame(this);
28 QVBoxLayout *layout = new QVBoxLayout(frame);
30 frame->setLayout(layout);
31 setCentralWidget(frame);
34 QAction *closeAction = new QAction(parent? tr("Back"): tr("Exit"), this);
35 closeAction->setSoftKeyRole(QAction::NegativeSoftKey);
36 connect(closeAction, SIGNAL(triggered()), this, SLOT(close()));
37 QMainWindow::addAction(closeAction);
40 setUnifiedTitleAndToolBarOnMac(true);
41 toolBar = addToolBar("controls");
42 toolBar->setMovable(false);
43 toolBar->setFloatable(false);
44 toolBar->toggleViewAction()->setVisible(false);
45 #if defined(Q_WS_X11) && !defined(Q_WS_MAEMO_5)
46 toolBar->setIconSize(QSize(42, 42));
48 #endif // Q_OS_SYMBIAN
51 void AdopterWindow::takeChildren(QWidget *main, const QList<QWidget *> &others)
53 Trace t("AdopterWindow::takeChildren");
57 mainChild->setParent(centralWidget());
58 centralWidget()->layout()->addWidget(mainChild);
61 foreach (QWidget *child, others) {
63 child->setParent(this);
68 void AdopterWindow::leaveChildren()
70 Trace t("AdopterWindow::leaveChildren");
72 centralWidget()->layout()->removeWidget(mainChild);
77 void AdopterWindow::grabZoomKeys(bool grab)
79 Trace t("AdopterWindow::grabZoomKeys");
80 grabbingZoomKeys = grab;
84 void AdopterWindow::showEvent(QShowEvent *e)
86 Trace t("AdopterWindow::showEvent");
87 doGrabZoomKeys(grabbingZoomKeys);
88 QMainWindow::showEvent(e);
91 void AdopterWindow::doGrabZoomKeys(bool grab)
93 Trace t("AdopterWindow::doGrabZoomKeys");
96 qDebug() << "Not visible - skipping";
99 qDebug() << "Could not get window ID - skipping";
102 unsigned long val = grab? 1: 0;
103 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
105 qCritical() << "Unable to obtain _HILDON_ZOOM_KEY_ATOM";
108 XChangeProperty(QX11Info::display(),
114 reinterpret_cast<unsigned char *>(&val),
118 #endif // Q_WS_MAEMO_5
121 void AdopterWindow::show()
124 foreach (QWidget *w, QApplication::allWidgets()) {
125 w->setContextMenuPolicy(Qt::NoContextMenu);
133 QAction *AdopterWindow::addToolBarAction(QObject *receiver,
135 const QString &iconName,
138 Trace t("AdopterWindow::addToolBarAction");
139 qDebug() << "icon" << iconName << "text" << text;
141 return toolBar->addAction(QIcon(ICON_PREFIX + iconName + ".png"), text,
145 QAction *action = new QAction(text, this);
146 menuBar()->addAction(action);
147 connect(action, SIGNAL(triggered()), receiver, member);
152 void AdopterWindow::addToolBarSpace()
155 QFrame *frame = new QFrame(toolBar);
156 frame->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
157 toolBar->addWidget(frame);