#include "mainwindow.h"
#ifdef CONFIG_WIN32
-#include "windows.h"
-
+#include <windows.h>
#else
#include <X11/Xlib.h>
#include <X11/Xatom.h>
-
#endif
-
-ContextMenu::ContextMenu(QWidget *parent) :
- QMenu(parent)
+ContextMenu::ContextMenu(QWidget *parent) : QMenu(parent)
{
- infoDialog = NULL;
- aboutDialog = NULL;
- vmName = ((MainWindow *)parent)->uiInfo->vmName + " : "
+ this->parent = (MainWindow *)parent;
+ this->infoDialog = NULL;
+ this->aboutDialog = NULL;
+ this->vmName = ((MainWindow *)parent)->uiInfo->vmName + " : "
+ QString::number(get_device_serial_number());
+ actionDetailedInfo = NULL;
+ actionTopMost = NULL;
+ actionShell = NULL;
+ actionControlPanel = NULL;
+ actionAbout = NULL;
+ actionForceClose = NULL;
+ actionClose = NULL;
+
+ longPressTimer = new QTimer(this);
+
createItems();
installEventFilter(this);
}
void ContextMenu::createItems() {
- MainWindow *win = (MainWindow *)this->parent();
+ MainWindow *win = parent;
+ QAction *action = NULL;
/* Detailed Info menu */
- QAction *action = addAction(vmName);
- action->setIcon(QIcon(QPixmap(":/icons/detailed_info.png")));
- connect(action, SIGNAL(triggered()), this, SLOT(slotDetailedInfo()));
+ actionDetailedInfo = addAction(vmName);
+ actionDetailedInfo->setIcon(QIcon(QPixmap(":/icons/detailed_info.png")));
+ connect(actionDetailedInfo, SIGNAL(triggered()), this, SLOT(slotDetailedInfo()));
addSeparator();
/* Always On Top menu */
- action = addAction("&Always on Top");
- action->setCheckable(true);
- connect(action, SIGNAL(triggered(bool)), this, SLOT(slotTopMost(bool)));
+ actionTopMost = addAction("&Always on Top");
+ actionTopMost->setCheckable(true);
+ connect(actionTopMost, SIGNAL(triggered(bool)), this, SLOT(slotTopMost(bool)));
/* = Rotate menu = */
if (win->uiInfo->mainFormList.count() > 1) {
advancedMenu->addSeparator();
/* Advanced > About menu */
- action = advancedMenu->addAction("&About");
- action->setIcon(QIcon(QPixmap(":/icons/about.png")));
- connect(action, SIGNAL(triggered()), this, SLOT(slotAbout()));
+ actionAbout = advancedMenu->addAction("&About");
+ actionAbout->setIcon(QIcon(QPixmap(":/icons/about.png")));
+ connect(actionAbout, SIGNAL(triggered()), this, SLOT(slotAbout()));
/* Advanced > Force Close menu */
- action = advancedMenu->addAction("&Force Close");
- action->setIcon(QIcon(QPixmap(":/icons/force_close.png")));
- connect(action, SIGNAL(triggered()), this, SLOT(slotForceClose()));
+ actionForceClose = advancedMenu->addAction("&Force Close");
+ actionForceClose->setIcon(QIcon(QPixmap(":/icons/force_close.png")));
+ connect(actionForceClose, SIGNAL(triggered()), this, SLOT(slotForceClose()));
/* ================= */
/* Shell menu */
- action = addAction("S&hell");
- action->setIcon(QIcon(QPixmap(":/icons/shell.png")));
- connect(action, SIGNAL(triggered()), this, SLOT(slotShell()));
+ actionShell = addAction("S&hell");
+ actionShell->setIcon(QIcon(QPixmap(":/icons/shell.png")));
+ connect(actionShell, SIGNAL(triggered()), this, SLOT(slotShell()));
/* Control Panel menu */
- action = addAction("Control &Panel");
- action->setIcon(QIcon(QPixmap(":/icons/control_panel.png")));
- connect(action, SIGNAL(triggered()), this, SLOT(slotControlPanel()));
+ actionControlPanel = addAction("Control &Panel");
+ actionControlPanel->setIcon(QIcon(QPixmap(":/icons/control_panel.png")));
+ connect(actionControlPanel, SIGNAL(triggered()), this, SLOT(slotControlPanel()));
addSeparator();
/* Close menu */
- longPressTimer = new QTimer(this);
- action = addAction("&Close");
- action->setIcon(QIcon(QPixmap(":/icons/close.png")));
- connect(action, SIGNAL(triggered()), this, SLOT(slotClose()));
+ actionClose = addAction("&Close");
+ actionClose->setIcon(QIcon(QPixmap(":/icons/close.png")));
+ connect(actionClose, SIGNAL(triggered()), this, SLOT(slotClose()));
}
bool ContextMenu::eventFilter(QObject *obj, QEvent *event)
qDebug("VM info");
if (infoDialog == NULL) {
- infoDialog = new DetailedInfoDialog((QWidget *)this->parent());
+ infoDialog = new DetailedInfoDialog((QWidget *)parent);
}
infoDialog->show();
{
qDebug("stays on top : %s", on? "on" : "off");
- QWidget *win = (QWidget *)this->parent();
-
#ifdef CONFIG_WIN32
- /*
- if (on == true) {
- win->setWindowFlags(win->windowFlags() | Qt::WindowStaysOnTopHint);
- } else {
- win->setWindowFlags(win->windowFlags() & ~(Qt::WindowStaysOnTopHint));
- }
-
- win->show();
- */
- HWND hWnd = (HWND)win->winId();
- HWND hWndInsertAfter = ( (on == true) ? HWND_TOPMOST : HWND_NOTOPMOST);
- SetWindowPos(hWnd, hWndInsertAfter, win->pos().x(), win->pos().y(), 0, 0, SWP_NOSIZE);
- win->show();
-
+ HWND hWnd = (HWND)parent->winId();
+ HWND hWndInsertAfter = ((on == true) ? HWND_TOPMOST : HWND_NOTOPMOST);
+ SetWindowPos(hWnd, hWndInsertAfter, parent->pos().x(), parent->pos().y(), 0, 0, SWP_NOSIZE);
#else
- Display* display = XOpenDisplay (NULL);
+ Display* display = XOpenDisplay(NULL);
if (display == NULL) {
qDebug("Error: XOpenDisplay() Failed. Always on top failed.");
return;
}
+
XClientMessageEvent event;
- memset(&event,0,sizeof(event));
+ memset(&event, 0, sizeof(event));
event.type = ClientMessage;
- event.window = win->winId();
- event.message_type = XInternAtom (display, "_NET_WM_STATE", False);
+ event.window = parent->winId();
+ event.message_type = XInternAtom(display, "_NET_WM_STATE", False);
event.format = 32;
- event.data.l[0] = on ? 1 : 0; // 1:_NET_WM_STATE_ADD , 0:_NET_WM_STATE_REMOVE
- event.data.l[1] = XInternAtom (display, "_NET_WM_STATE_ABOVE", False);
- event.data.l[2] = 0; //unused.
+ event.data.l[0] = on ? 1 : 0; /* 1:_NET_WM_STATE_ADD, 0:_NET_WM_STATE_REMOVE */
+ event.data.l[1] = XInternAtom(display, "_NET_WM_STATE_ABOVE", False);
+ event.data.l[2] = 0; /* unused */
event.data.l[3] = 0;
event.data.l[4] = 0;
- XSendEvent (display, DefaultRootWindow(display), False, SubstructureRedirectMask|SubstructureNotifyMask, (XEvent*)&event);
+
+ XSendEvent(display, DefaultRootWindow(display), False,
+ SubstructureRedirectMask | SubstructureNotifyMask, (XEvent *)&event);
XFlush(display);
+
XCloseDisplay(display);
#endif
-
+ actionTopMost->setChecked(on);
+ parent->getUIState()->setOnTop(on);
}
void ContextMenu::slotRotate(int angle)
{
qDebug("rotate : %d", angle);
- ((MainWindow *)this->parent())->rotate(angle);
+ parent->rotate(angle);
}
void ContextMenu::slotScale(int scale)
{
qDebug("scale : %d", scale);
- ((MainWindow *)this->parent())->scale(scale);
+ parent->scale(scale);
}
void ContextMenu::slotController(int index)
{
qDebug("controller : %d", index);
- MainWindow *win = ((MainWindow *)this->parent());
- win->openController(index, win->getUIState()->conState.recentlyDockPos);
+ parent->openController(index,
+ parent->getUIState()->conState.recentlyDockPos);
}
void ContextMenu::slotShell()
qDebug() << msg;
QMessageBox *msgBox = new QMessageBox(QMessageBox::Information,
- "Emulator", msg, QMessageBox::Ok, (QWidget*)this->parent());
+ "Emulator", msg, QMessageBox::Ok, (QWidget*)parent);
msgBox->setAttribute(Qt::WA_DeleteOnClose);
msgBox->setModal(false);
msgBox->show();
qWarning() << msg;
QMessageBox *msgBox = new QMessageBox(QMessageBox::Warning,
- "Emulator", msg, QMessageBox::Ok, (QWidget*)this->parent());
+ "Emulator", msg, QMessageBox::Ok, (QWidget*)parent);
msgBox->setAttribute(Qt::WA_DeleteOnClose);
msgBox->setModal(false);
msgBox->show();
qDebug() << msg;
QMessageBox *msgBox = new QMessageBox(QMessageBox::Warning,
- "Emulator", msg, QMessageBox::Ok ,(QWidget*)this->parent());
+ "Emulator", msg, QMessageBox::Ok ,(QWidget*)parent);
msgBox->setAttribute(Qt::WA_DeleteOnClose);
msgBox->setModal(false);
msgBox->show();
{
qDebug("Control Panel");
- MainWindow *win = (MainWindow *)this->parent();
+ MainWindow *win = (MainWindow *)parent;
QString basePortOpt = "base.port=" + QString::number(win->uiInfo->basePort);
QString vmNameOpt = "vmname=" + win->uiInfo->vmName;
qWarning() << msg;
QMessageBox *msgBox = new QMessageBox(QMessageBox::Warning,
- "Emulator", msg, QMessageBox::Ok, (QWidget*)this->parent());
+ "Emulator", msg, QMessageBox::Ok, (QWidget*)parent);
msgBox->setAttribute(Qt::WA_DeleteOnClose);
msgBox->setModal(false);
msgBox->show();
qDebug() << msg;
QMessageBox *msgBox = new QMessageBox(QMessageBox::Warning,
- "Emulator", msg, QMessageBox::Ok, (QWidget*)this->parent());
+ "Emulator", msg, QMessageBox::Ok, (QWidget*)parent);
msgBox->setAttribute(Qt::WA_DeleteOnClose);
msgBox->setModal(false);
msgBox->show();
qDebug("about");
if (aboutDialog == NULL) {
- aboutDialog = new AboutDialog((QWidget *)this->parent());
+ aboutDialog = new AboutDialog((QWidget *)parent);
}
aboutDialog->show();
{
qDebug("force close");
- QMessageBox *msg = new QMessageBox((QWidget*)this->parent());
+ QMessageBox *msg = new QMessageBox((QWidget*)parent);
msg->setAttribute(Qt::WA_DeleteOnClose);
msg->setWindowTitle("Emulator");
msg->setText("If you force stop an emulator, it may cause some problems.\n"
qDebug("close");
do_hw_key_event(KEY_PRESSED, HARD_KEY_POWER);
- this->longPressTimer->setInterval(CLOSE_POWER_KEY_INTERVAL);
- this->longPressTimer->setSingleShot(true);
+ longPressTimer->setInterval(CLOSE_POWER_KEY_INTERVAL);
+ longPressTimer->setSingleShot(true);
connect(longPressTimer, SIGNAL(timeout()), this, SLOT(slotPwkeyRelease()));
- this->longPressTimer->start();
+ longPressTimer->start();
}
QSignalMapper *ContextMenu::getRotateMapper()
ContextMenu::~ContextMenu()
{
qDebug("destroy menu");
+
+ longPressTimer->stop();
}