// copyright (c) 2021 hors // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. // #include "xshortcuts.h" XShortcuts::XShortcuts(QObject *pParent) : QObject(pParent) { g_bIsNative=false; } void XShortcuts::setName(QString sValue) { this->g_sName=sValue; } void XShortcuts::setNative(bool bValue) { g_bIsNative=bValue; } void XShortcuts::addGroup(GROUPID groupId) { qint32 nEnd=getGroupEnd(groupId); for(qint32 nId=(groupId<>GROUP_SH)); for(qint32 nId=id+1;nId listValueIDs) { this->g_listValueIDs=listValueIDs; } QList XShortcuts::getShortcutsIDs() { return g_listValueIDs; } void XShortcuts::load() { QSettings *pSettings=nullptr; if(g_bIsNative) { pSettings=new QSettings; } else if(g_sName!="") { pSettings=new QSettings(qApp->applicationDirPath()+QDir::separator()+QString("%1").arg(g_sName),QSettings::IniFormat); // TODO more options } #ifdef QT_DEBUG if(pSettings) { qDebug("XShortcuts load %s",pSettings->fileName().toLatin1().data()); } #endif int nNumberOfIDs=g_listValueIDs.count(); for(int i=0;ivalue(sName,ksDefault.toString()).toString())); } else { g_mapValues.insert(id,ksDefault); } } if(pSettings) { delete pSettings; } } void XShortcuts::save() { QSettings *pSettings=nullptr; if(g_bIsNative) { pSettings=new QSettings; } else if(g_sName!="") { pSettings=new QSettings(qApp->applicationDirPath()+QDir::separator()+QString("%1").arg(g_sName),QSettings::IniFormat); // TODO more options } #ifdef QT_DEBUG if(pSettings) { qDebug("XShortcuts save %s",pSettings->fileName().toLatin1().data()); } #endif if(pSettings) { int nNumberOfIDs=g_listValueIDs.count(); for(int i=0;isetValue(sName,g_mapValues.value(id).toString()); } } if(pSettings) { delete pSettings; } } QKeySequence XShortcuts::getShortcut(XShortcuts::ID id) { #ifdef QT_DEBUG if(!g_mapValues.contains(id)) { QString sErrorString=idToSettingsString(id); qDebug(sErrorString.toLatin1().data()); } #endif return g_mapValues.value(id); } void XShortcuts::setShortcut(XShortcuts::ID id, QKeySequence keyValue) { g_mapValues.insert(id,keyValue); } bool XShortcuts::checkShortcut(XShortcuts::ID id, QKeySequence keyValue) { bool bResult=true; if(keyValue!=QKeySequence()) { GROUPID idGroup=getGroupId(id); for(qint32 nId=(idGroup<>=24; return (GROUPID)nResult; } XShortcuts::GROUPID XShortcuts::getSubgroupId(ID id) { GROUPID result=GROUPID_UNKNOWN; switch(id) { case ID_DEBUGGER_FILE_ATTACH: case ID_DEBUGGER_FILE_CLOSE: case ID_DEBUGGER_FILE_DETACH: case ID_DEBUGGER_FILE_EXIT: case ID_DEBUGGER_FILE_OPEN: result=GROUPID_FILE; break; default: result=GROUPID_UNKNOWN; } return result; }