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()));
39 setUnifiedTitleAndToolBarOnMac(true);
40 toolBar = addToolBar("controls");
41 toolBar->setMovable(false);
42 toolBar->setFloatable(false);
43 toolBar->toggleViewAction()->setVisible(false);
44 #if defined(Q_WS_X11) && !defined(Q_WS_MAEMO_5)
45 toolBar->setIconSize(QSize(42, 42));
47 #endif // Q_OS_SYMBIAN
50 void AdopterWindow::takeChildren(QWidget *main, const QList<QWidget *> &others)
52 Trace t("AdopterWindow::takeChildren");
56 mainChild->setParent(centralWidget());
57 centralWidget()->layout()->addWidget(mainChild);
60 foreach (QWidget *child, others) {
62 child->setParent(this);
67 void AdopterWindow::leaveChildren()
69 Trace t("AdopterWindow::leaveChildren");
71 centralWidget()->layout()->removeWidget(mainChild);
76 void AdopterWindow::grabZoomKeys(bool grab)
78 Trace t("AdopterWindow::grabZoomKeys");
79 grabbingZoomKeys = grab;
83 void AdopterWindow::showEvent(QShowEvent *e)
85 Trace t("AdopterWindow::showEvent");
86 doGrabZoomKeys(grabbingZoomKeys);
87 QMainWindow::showEvent(e);
90 void AdopterWindow::doGrabZoomKeys(bool grab)
92 Trace t("AdopterWindow::doGrabZoomKeys");
95 qDebug() << "Not visible - skipping";
98 qDebug() << "Could not get window ID - skipping";
101 unsigned long val = grab? 1: 0;
102 Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
104 qCritical() << "Unable to obtain _HILDON_ZOOM_KEY_ATOM";
107 XChangeProperty(QX11Info::display(),
113 reinterpret_cast<unsigned char *>(&val),
117 #endif // Q_WS_MAEMO_5
120 void AdopterWindow::show()
129 QAction *AdopterWindow::addToolBarAction(QObject *receiver,
131 const QString &iconName,
134 Trace t("AdopterWindow::addToolBarAction");
135 qDebug() << "icon" << iconName << "text" << text;
137 return toolBar->addAction(QIcon(ICON_PREFIX + iconName + ".png"), text,
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);