conView->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
}
+ControllerForm *DockingController::getConForm()
+{
+ return conForm;
+}
+
DockingConView *DockingController::getConView()
{
return conView;
QAction *menu, int dockPos, QWidget *parent = 0);
~DockingController();
+ ControllerForm *getConForm();
DockingConView *getConView();
int getDockPos();
void updateGeometry();
layout->addWidget(conView);
}
+ControllerForm *FloatingController::getConForm()
+{
+ return conForm;
+}
+
FloatingConView *FloatingController::getConView()
{
return conView;
explicit FloatingController(ControllerForm *conForm, QAction *menu, QWidget *parent = 0);
~FloatingController();
+ ControllerForm *getConForm();
FloatingConView *getConView();
protected:
keyButton = new HWKeyButton(buttonGroup, hwKey,
QSize(GPC_KEYBUTTON_WIDTH, GPC_KEYBUTTON_HEIGHT));
- if (!hwKey->getKeySequence().isEmpty()) {
- keyButton->setToolTip(hwKey->getKeySequence());
+ if (hwKey->getKeySequence().isEmpty() == false) {
+ keyButton->setToolTip(hwKey->getKeySequence().toString());
}
layout->addWidget(keyButton);
void HWKeyButton::mousePressEvent(QMouseEvent *event)
{
- const int keycode = hwKey->getKeycodeType()->getShortPressKeycode();
+ const int keycode = hwKey->getKeycode();
qDebug() << hwKey->getName() << "key button pressed:" << keycode;
do_hw_key_event(KEY_PRESSED, keycode);
void HWKeyButton::mouseReleaseEvent(QMouseEvent *event)
{
- const int keycode = hwKey->getKeycodeType()->getShortPressKeycode();
+ const int keycode = hwKey->getKeycode();
qDebug() << hwKey->getName() << "key button released:" << keycode;
do_hw_key_event(KEY_RELEASED, keycode);
KeyboardShortcut::KeyboardShortcut(QWidget *parent) : QWidget(parent)
{
- this->parent = (MainWindow *)parent;
- this->hide();
-}
+ this->win = (MainWindow *)parent;
-void KeyboardShortcut::removeControllerShortcut()
-{
- for (int index = 0; index < controllerShortcutList.count(); index++) {
- delete controllerShortcutList.at(index);
- }
+ mapper = new QSignalMapper(this);
+ connect(mapper, SIGNAL(mapped(int)), this, SLOT(slotHwKeyShortcut(int)));
- controllerShortcutList.clear();
- controllerShortcutMap.clear();
+ hide();
- qDebug() << "Removed controller shortcuts";
+ registerHwKeyShortcuts(win->uiInfo->getMainForm()->keyList);
}
-void KeyboardShortcut::removeHwKeyShortcut()
+QMap<HardwareKey *, QShortcut *> KeyboardShortcut::getHwKeyShortcutMap()
{
- for (int index = 0; index < hwKeyShortcutList.count(); index++) {
- delete hwKeyShortcutList.at(index);
- }
-
- hwKeyShortcutList.clear();
- hwKeyShortcutMap.clear();
-
- qDebug() << "Removed hwKey shortcuts";
+ return hwKeyShortcutMap;
}
-void KeyboardShortcut::registShortcutKey(QShortcut *shortcut, QString item)
+void KeyboardShortcut::registerHwKeyShortcuts(QList<HardwareKey *> list)
{
- QSignalMapper *mapper = new QSignalMapper(this);
- if (!mapper || !shortcut) {
- qDebug() << "regist HwKey shortcut failed.";
- return;
- }
+ for (int index = 0; index < list.count(); index++) {
+ HardwareKey *hwKey = list.at(index);
+ if (hwKey && hwKey->getKeySequence().isEmpty() == false) {
+ QShortcut *shortcut = new QShortcut(hwKey->getKeySequence(), win);
- connect(shortcut, SIGNAL(activated()), mapper, SLOT(map()));
- mapper->setMapping(shortcut, item);
- connect(mapper, SIGNAL(mapped(const QString &)), this, SLOT(slotShortcutHwKey(const QString &)));
-}
+ connect(shortcut, SIGNAL(activated()), mapper, SLOT(map()));
+ mapper->setMapping(shortcut, hwKey->getKeycode());
-void KeyboardShortcut::setKeyboardShortcutController()
-{
- DockingController *dct = parent->getDockingCon();
- FloatingController *fct = parent->getFloatingCon();
-
- if (dct) {
- controllerKeyList = dct->getConView()->getKeyList();
- } else if (fct) {
- controllerKeyList = fct->getConView()->getKeyList();
- } else {
- qDebug() << "controllerKeyList is not exist!";
- return;
- }
-
- qDebug() << "Set keyboard shortcut ControllerKeys.";
- for (int index = 0; index < controllerKeyList.count(); index++) {
- HardwareKey *controllerKey = controllerKeyList.at(index);
- if (controllerKey) {
- if (!controllerKey->getKeySequence().isEmpty()) {
- QShortcut *shortcut = new QShortcut(
- QKeySequence::fromString(controllerKey->getKeySequence()), parent);
- registShortcutKey(shortcut, controllerKey->getName());
-
- controllerShortcutList.append(shortcut);
- controllerShortcutMap.insert(
- controllerKey->getName(), controllerKey->getKeySequence());
- }
- } else {
- qDebug() << "controllerKeyList.at(" << index << ") is NULL";
+ hwKeyShortcutMap.insert(hwKey, shortcut);
}
}
+
+ qDebug() << hwKeyShortcutMap.count() << "shortcuts have been registered";
}
-void KeyboardShortcut::setKeyboardShortcutHwKey()
+void KeyboardShortcut::cancelHwKeyShortcuts(QList<HardwareKey *> list)
{
- UIInformation *uiInfo = parent->uiInfo;
-
- if (uiInfo) {
- if (uiInfo->getMainForm() != NULL) {
- if (uiInfo->getMainForm()->keyList.count() > 0) {
- hwKeyList = uiInfo->getMainForm()->keyList;
- } else if (uiInfo->getMainForm()->keyList.count() == 0) {
- qWarning() << "hwKey is not exist";
- return;
- } else {
- qWarning() << "hwKeyList is not exist";
- return;
- }
- } else {
- qWarning() << "uiInfo->getMainForm() is NULL";
- }
- } else {
- qWarning() << "uiInfo is NULL";
- return;
+ for (int index = 0; index < list.count(); index++) {
+ delete hwKeyShortcutMap.value(list.at(index));
+ hwKeyShortcutMap.remove(list.at(index));
}
- qDebug() << "Set keyboard shortcut HwKeys.";
- for (int index = 0; index < hwKeyList.count(); index++) {
- HardwareKey *hwKey = hwKeyList.at(index);
- if (hwKey) {
- if (!hwKey->getKeySequence().isEmpty()) {
- QShortcut *shortcut = new QShortcut(
- QKeySequence::fromString(hwKey->getKeySequence()), parent);
- registShortcutKey(shortcut, hwKey->getName());
-
- hwKeyShortcutList.append(shortcut);
- hwKeyShortcutMap.insert(hwKey->getName(), hwKey->getKeySequence());
- }
- } else {
- qDebug() << "hwKeyList.at(" << index << ") is NULL";
- }
- }
+ qDebug() << hwKeyShortcutMap.count() << "shortcuts have been registered";
}
+// TODO: move to context menu class
void KeyboardShortcut::slotShortcutHostKeyboard()
{
- QAction *action = parent->getPopupMenu()->keyboardGroup->checkedAction();
- QList<QAction *> keyboardStatusList = parent->getPopupMenu()->keyboardGroup->actions();
+ QAction *action = win->getPopupMenu()->keyboardGroup->checkedAction();
+ QList<QAction *> keyboardStatusList = win->getPopupMenu()->keyboardGroup->actions();
if (!action) {
qWarning() << "HostKeyboard enable/disable failed";
keyboardStatusList.at(index)->setChecked(true);
}
-int KeyboardShortcut::getHwKeyCode(QString item)
-{
- int index = 0, keyCode = 0;
-
- for (index = 0; index < hwKeyList.count(); index++) {
- if (hwKeyList.at(index)->getName().compare(item) == 0) {
- keyCode = hwKeyList.at(index)->
- getKeycodeType()->getShortPressKeycode();
- break;
- }
- }
-
- if (index == hwKeyList.count()) {
- for (index = 0; index < controllerKeyList.count(); index++) {
- if (controllerKeyList.at(index)->getName().compare(item) == 0) {
- keyCode = controllerKeyList.at(index)->
- getKeycodeType()->getShortPressKeycode();
- break;
- }
- }
-
- if (index == controllerKeyList.count()) {
- qWarning() << item << "is not exist in KeyList";
- }
- }
-
- return keyCode;
-}
-
-void KeyboardShortcut::doHwKeyEvent(int keyCode)
+void KeyboardShortcut::slotHwKeyShortcut(int keycode)
{
- do_hw_key_event(KEY_PRESSED, keyCode);
- do_hw_key_event(KEY_RELEASED, keyCode);
-}
+ qDebug() << "shortcut: \"HW key\"" << keycode;
-void KeyboardShortcut::slotShortcutHwKey(const QString &name)
-{
- int keyCode = getHwKeyCode(name);
- doHwKeyEvent(keyCode);
-}
-
-QList<QShortcut *> KeyboardShortcut::getControllerShortcutList()
-{
- return controllerShortcutList;
-}
-
-QList<QShortcut *> KeyboardShortcut::getHwKeyShortcutList()
-{
- return hwKeyShortcutList;
-}
-
-QMap<QString, QString> KeyboardShortcut::getHwKeyShortcutMap()
-{
- return hwKeyShortcutMap;
-}
-
-QMap<QString, QString> KeyboardShortcut::getControllerShortcutMap()
-{
- return controllerShortcutMap;
+ do_hw_key_event(KEY_PRESSED, keycode);
+ do_hw_key_event(KEY_RELEASED, keycode);
}
KeyboardShortcut::~KeyboardShortcut()
{
- removeHwKeyShortcut();
- removeControllerShortcut();
-
qDebug("destroy keyboard shortcut");
+
+ hwKeyShortcutMap.clear();
}
#ifndef KEYBOARDSHORTCUT_H
#define KEYBOARDSHORTCUT_H
-#include <QObject>
-#include <QShortcut>
-#include <QMap>
+#include <QtWidgets>
#include "layout/hardwarekey.h"
KeyboardShortcut(QWidget *parent = 0);
~KeyboardShortcut();
- void setKeyboardShortcutHwKey();
- void setKeyboardShortcutController();
- void removeControllerShortcut();
- void removeHwKeyShortcut();
-
- QList<QShortcut *> getControllerShortcutList();
- QList<QShortcut *> getHwKeyShortcutList();
- QMap<QString, QString> getHwKeyShortcutMap();
- QMap<QString, QString> getControllerShortcutMap();
+ void registerHwKeyShortcuts(QList<HardwareKey *> list);
+ void cancelHwKeyShortcuts(QList<HardwareKey *> list);
+ QMap<HardwareKey *, QShortcut *> getHwKeyShortcutMap();
public slots:
- void slotShortcutHwKey(const QString &name);
+ void slotHwKeyShortcut(int keycode);
void slotShortcutHostKeyboard();
private:
- void registShortcutKey(QShortcut *shortcut, QString item);
- int getHwKeyCode(QString item);
- void doHwKeyEvent(int keyCode);
+ MainWindow *win;
+ QSignalMapper *mapper;
- MainWindow *parent;
- QList<HardwareKey *> hwKeyList;
- QList<HardwareKey *> controllerKeyList;
- QList<QShortcut *> controllerShortcutList;
- QList<QShortcut *> hwKeyShortcutList;
- QMap<QString, QString> hwKeyShortcutMap;
- QMap<QString, QString> controllerShortcutMap;
+ QMap<HardwareKey *, QShortcut *> hwKeyShortcutMap;
};
#endif // KEYBOARDSHORTCUT_H
#include "hardwarekey.h"
HardwareKey::HardwareKey(QString name, KeycodeType *keycodeType,
- QRect region, QString tooltip, QString keySequence)
+ QRect region, QString tooltip, QKeySequence keySequence)
{
this->name = name;
this->keycodeType = keycodeType;
return keycodeType;
}
+int HardwareKey::getKeycode()
+{
+ return getKeycodeType()->getShortPressKeycode();
+}
+
bool HardwareKey::hasLongPressKeycode()
{
return (keycodeType->getLongPressKeycode() > 0);
return tooltip;
}
-QString HardwareKey::getKeySequence()
+QKeySequence HardwareKey::getKeySequence()
{
return keySequence;
}
{
public:
HardwareKey(QString name, KeycodeType *keycodeType,
- QRect region, QString tooltip, QString keySequence);
+ QRect region, QString tooltip, QKeySequence keySequence);
~HardwareKey();
QString getName();
KeycodeType *getKeycodeType();
+ int getKeycode();
bool hasLongPressKeycode();
QRect getRegion();
QString getTooltip();
- QString getKeySequence();
+ QKeySequence getKeySequence();
private:
QString name;
KeycodeType *keycodeType;
QRect region;
QString tooltip;
- QString keySequence;
+ QKeySequence keySequence;
};
#endif // HARDWAREKEY_H
/* set HW Key shortcut */
keyboardShortcut = new KeyboardShortcut(this);
- keyboardShortcut->setKeyboardShortcutHwKey();
/* popup menu */
popupMenu = new ContextMenu(this);
return;
}
+ getUIState()->conState.conFormIndex = index;
+
QAction *action = NULL;
if (popupMenu != NULL && popupMenu->getControllerMapper() != NULL) {
action = (QAction *)popupMenu->getControllerMapper()->mapping(index);
+ qDebug() << "open controller:" << action->text();
}
- getUIState()->conState.conFormIndex = index;
-
/* create */
if (dockPos == -1) {
getUIState()->conState.floatingCon =
#endif
}
+ /* register controller's HW key shortcuts */
+ keyboardShortcut->registerHwKeyShortcuts(conForm->keyList);
+
/* update layout */
resize(uiInfo->getUiSize());
* So, we need an additional updating for display. */
display->update();
- /* set controller shortcut */
- keyboardShortcut->setKeyboardShortcutController();
-
#ifdef CONFIG_LINUX
popupMenu->slotTopMost(getUIState()->isOnTop());
#endif
if (getDockingCon() != NULL) {
qDebug("close docking controller");
+ /* cancel controller's HW key shortcuts */
+ keyboardShortcut->cancelHwKeyShortcuts(
+ getDockingCon()->getConForm()->keyList);
getDockingCon()->close();
getUIState()->conState.dockingCon = NULL;
qDebug("close floating controller");
getUIState()->conState.recentlyFloatPos = getFloatingCon()->pos();
+
+ /* cancel controller's HW key shortcuts */
+ keyboardShortcut->cancelHwKeyShortcuts(
+ getFloatingCon()->getConForm()->keyList);
getFloatingCon()->close();
getUIState()->conState.floatingCon = NULL;
/* Some part of QGLWidget's surface might be lost on Windows when view changing.
* So, we need an additional updating for display. */
display->update();
-
- /* remove controller shortcut */
- keyboardShortcut->removeControllerShortcut();
}
/* override */
void MainWindow::switchForm(int index)
{
- qDebug("window switch : %d", index);
+ qDebug("window switch: %d", index);
+
+ /* cancel HW key shortcuts */
+ keyboardShortcut->cancelHwKeyShortcuts(uiInfo->getMainForm()->keyList);
/* layout switching */
getUIState()->mainFormIndex = index;
+ /* register new HW key shortcuts */
+ keyboardShortcut->registerHwKeyShortcuts(uiInfo->getMainForm()->keyList);
+
updateDisplayMatrix();
if (getDockingCon() != NULL) {
void MainWindow::scaleForm(int scale)
{
- qDebug("window scale : %d", scale);
+ qDebug("window scale: %d", scale);
/* scale changing */
getUIState()->mainFormScale = scale;
} else {
qDebug() << "Display is not ready.";
}
-
- /* reset HwKey shortcut */
- KeyboardShortcut *keyboardShortcut = parent->getKeyboardShortcut();
- keyboardShortcut->removeHwKeyShortcut();
- keyboardShortcut->setKeyboardShortcutHwKey();
}
void ContextMenu::slotSwitchShortcutPrev()
}
QAction *nextAction = conActions.at(index);
+ qDebug() << "shortcut next:" << controllerMenu->title() <<
+ '<' << nextAction->text();
+
nextAction->setChecked(true);
nextAction->trigger();
-
- qDebug() << "shortcut: next" << controllerMenu->title() << nextAction->text();
}
void ContextMenu::slotShell()
/* insert menu shortcut info */
insertMenuShortcutInfo(win->uiInfo->menuList);
- setShortcutInfoTable(keyboardShortcut->getHwKeyShortcutMap(),
- keyboardShortcut->getHwKeyShortcutList());
- setShortcutInfoTable(keyboardShortcut->getControllerShortcutMap(),
- keyboardShortcut->getControllerShortcutList());
+ // TODO: consider getHwKeyShortcutMap()
+ /* insert HW key shortcut info */
+ insertHwKeyShortcutInfo(win->uiInfo->getMainForm()->keyList);
+
+ /* insert Controller's HW key shortcut info */
+ ControllerForm *conForm = win->uiInfo->getConForm();
+ if (conForm != NULL) {
+ insertHwKeyShortcutInfo(win->uiInfo->getConForm()->keyList,
+ QString(" (controller)"));
+ }
qDebug() << shortcutInfoTable->rowCount() << "shortcut items have been inserted";
}
void DetailedInfoDialog::insertMenuShortcutInfo(QList<MenuItem *> list)
{
+ MenuItem *item = NULL;
+
for (int i = 0; i < list.count(); i++) {
- MenuItem *item = list.at(i);
+ item = list.at(i);
if (item != NULL) {
if (item->getType() == MenuItemType::separator) {
/* do nothing */
}
}
-void DetailedInfoDialog::setShortcutInfoTable(
- const QMap<QString, QString>& map, const QList<QShortcut *>& list)
+void DetailedInfoDialog::insertHwKeyShortcutInfo(
+ QList<HardwareKey *> list, QString source)
{
- QMap<QString, QString>::const_iterator mapIter = map.constBegin();
+ HardwareKey *hwKey = NULL;
- for (int index = 0; index < list.count(); index++) {
- while (mapIter != map.constEnd()) {
- if (mapIter.value() == list.at(index)->key().toString()) {
-#ifdef CONFIG_DARWIN
- QString value = mapIter.value();
- value.replace("Ctrl", "Cmd");
- insertTableRow(shortcutInfoTable, mapIter.key(), value);
-#else
- insertTableRow(shortcutInfoTable, mapIter.key(), mapIter.value());
-#endif
- break;
- }
- ++mapIter;
+ for (int i = 0; i < list.count(); i++) {
+ hwKey = list.at(i);
+ if (hwKey && hwKey->getKeySequence().isEmpty() == false &&
+ hwKey->getName().isEmpty() == false) {
+ insertTableRow(shortcutInfoTable,
+ hwKey->getName() + source, hwKey->getKeySequence().toString());
}
- mapIter = map.constBegin();
}
}
resize(tWidth, tHeight);
- shortcutInfoTable->resizeColumnsToContents();
- vmInfoTable->resizeColumnsToContents();
+ table->resizeColumnsToContents();
}
void DetailedInfoDialog::insertTableRow(QTableWidget *table,
~DetailedInfoDialog();
void updateShortcutTableItems();
- void insertMenuShortcutInfo(QList<MenuItem *> list);
-
- void setShortcutInfoTable(const QMap<QString, QString>& map,
- const QList<QShortcut *>& list);
- void insertTableRow(QTableWidget *table, const QString& key,
- const QString& value, const QString& tooltip);
- void insertTableRow(QTableWidget *table, const QString& key,
- const QString& value);
- void removeTableRows(QTableWidget *table, int startIndex, int lastIndex);
public slots:
void slotCellOpen(int nRow, int nCol);
QTableWidget *createShortcutInfoTable();
void resizeTableToContents(QTableWidget *table);
+ void insertTableRow(QTableWidget *table, const QString& key,
+ const QString& value, const QString& tooltip);
+ void insertTableRow(QTableWidget *table, const QString& key,
+ const QString& value);
+ void removeTableRows(QTableWidget *table, int startIndex, int lastIndex);
+
+ void insertMenuShortcutInfo(QList<MenuItem *> list);
+ void insertHwKeyShortcutInfo(QList<HardwareKey *> list, QString source = "");
+
MainWindow *win;
QVBoxLayout *baseLayout;
QHBoxLayout *upsideLayout;
return;
}
- const int keycode = hwKey->getKeycodeType()->getShortPressKeycode();
+ const int keycode = hwKey->getKeycode();
qDebug() << hwKey->getName() << "key pressed:" << keycode;
do_hw_key_event(KEY_PRESSED, keycode);
{
bezelParent->setHWKeyHandling(isPressed = false);
- int keycode = hwKey->getKeycodeType()->getShortPressKeycode();
+ int keycode = hwKey->getKeycode();
if (hwKey->hasLongPressKeycode() == true) {
if (longPressTimer->remainingTime() <= 0) {
if (index > (mainFormList.count() - 1) || index < 0) {
qWarning("invalid form found");
- uiState.mainFormIndex = 0;
+ index = uiState.mainFormIndex = 0;
}
return mainFormList.at(index);
if (index > (conFormList.count() - 1) || index < 0) {
qWarning("invalid form found");
- uiState.conState.conFormIndex = 0;
+ return NULL;
}
return conFormList.at(index);
QRect keyRegion;
KeycodeType *keycodeType = NULL;
QString keyTooptip;
- QString keySequence;
+ QKeySequence keySequence;
/* attribute */
QString keyName = xml.attributes().value(NAME_ATTR_KEYWORD).toString();
keyTooptip = xml.readElementText();
} else if (xml.name() == SHORTCUT_KEYWORD) {
/* shortcut */
- keySequence = xml.readElementText();
+ keySequence = QKeySequence::fromString(xml.readElementText());
}
}
return map.count();
}
-int XmlLayoutParser::parseShortcut(
+int XmlLayoutParser::parseShortcuts(
QXmlStreamReader &xml, QMap<QString, QKeySequence> &map)
{
QString key = xml.attributes().value(PROP_ATTR_KEYWORD).toString();
{
if (token == QXmlStreamReader::StartElement) {
if (xml.name() == SHORTCUT_KEYWORD) {
- parseShortcut(xml, item->getShortcutMap());
+ parseShortcuts(xml, item->getShortcutMap());
} else if (xml.name() == MENULIST_KEYWORD) {
int cnt = parseMenuList(xml, item->getMenuList());
qDebug("- advanced menuList : %d", cnt);
{
if (token == QXmlStreamReader::StartElement) {
if (xml.name() == SHORTCUT_KEYWORD) {
- parseShortcut(xml, item->getShortcutMap());
+ parseShortcuts(xml, item->getShortcutMap());
} else if (xml.name() == FACTORLIST_KEYWORD) {
int defaultFactor = 0;
int cnt = parseFactorList(xml, item->getFactorMap(), &defaultFactor);
{
if (token == QXmlStreamReader::StartElement) {
if (xml.name() == SHORTCUT_KEYWORD) {
- parseShortcut(xml, item->getShortcutMap());
+ parseShortcuts(xml, item->getShortcutMap());
}
}
int parseMainFormList(QXmlStreamReader &xml, QList<MainForm *> &list);
int parseFactorList(QXmlStreamReader &xml, QMap<int, QString> &map, int *defaultFactor);
- int parseShortcut(QXmlStreamReader &xml, QMap<QString, QKeySequence> &map);
+ int parseShortcuts(QXmlStreamReader &xml, QMap<QString, QKeySequence> &map);
AdvancedMenuItem *parseAdvancedMenuItem(QXmlStreamReader &xml);
ScaleMenuItem *parseScaleMenuItem(QXmlStreamReader &xml);
MenuItem *parseGeneralMenuItem(QXmlStreamReader &xml, int menuType);