QRectF SlippyMapWidget::selectedArea() { if (p->CurrentSelectionCoord.isNull()) makeSelection(QRect(0,0,width(),height())); return p->CurrentSelectionCoord; }
bool CIMIXhView::onKeyEvent(const CKeyEvent& key) { unsigned changeMasks = 0; unsigned keycode = key.code; unsigned keyvalue = key.value; unsigned modifiers = key.modifiers; bool isKeyStroke = false; #ifdef DEBUG printf("Xh View got a key (0x%x-0x%x-0x%x)...\n", keycode, keyvalue, modifiers); if (((modifiers & IM_CTRL_MASK) != 0) && (keyvalue == 'P' || keyvalue == 'p')) m_pIC->printLattice(); #endif if (m_pHotkeyProfile && m_pHotkeyProfile->isModeSwitchKey(key)) { setStatusAttrValue(CIMIWinHandler::STATUS_ID_CN, (!m_bCN) ? 1 : 0); if (!m_pIC->isEmpty()) { changeMasks |= CANDIDATE_MASK | PREEDIT_MASK; clearIC(); } } else if (m_pHotkeyProfile && m_pHotkeyProfile->isPunctSwitchKey(key)) { // On CTRL+. switch Full/Half punc changeMasks |= KEYEVENT_USED; setStatusAttrValue(CIMIWinHandler::STATUS_ID_FULLPUNC, (!m_bFullPunct) ? 1 : 0); } else if (m_pHotkeyProfile && m_pHotkeyProfile->isSymbolSwitchKey(key)) { // On SHIFT+SPACE switch Full/Half symbol changeMasks |= KEYEVENT_USED; setStatusAttrValue(CIMIWinHandler::STATUS_ID_FULLSYMBOL, (!m_bFullSymbol) ? 1 : 0); } else if (modifiers == IM_CTRL_MASK && keycode == IM_VK_LEFT) { // move left if (!m_pIC->isEmpty()) { changeMasks |= KEYEVENT_USED; _moveLeft(changeMasks); } } else if (modifiers == IM_CTRL_MASK && keycode == IM_VK_RIGHT) { // move right if (!m_pIC->isEmpty()) { changeMasks |= KEYEVENT_USED; _moveRight(changeMasks); } } else if (((modifiers == 0 && keycode == IM_VK_PAGE_UP) || (m_pHotkeyProfile && m_pHotkeyProfile->isPageUpKey(key))) && !m_pIC->isEmpty()) { changeMasks |= KEYEVENT_USED; if (m_candiPageFirst > 0) { m_candiPageFirst -= m_candiWindowSize; if (m_candiPageFirst < 0) m_candiPageFirst = 0; changeMasks |= CANDIDATE_MASK; } } else if (((modifiers == 0 && keycode == IM_VK_PAGE_DOWN) || (m_pHotkeyProfile && m_pHotkeyProfile->isPageDownKey(key))) && !m_pIC->isEmpty()) { changeMasks |= KEYEVENT_USED; if (m_candiPageFirst + m_candiWindowSize < candidateListSize()) { m_candiPageFirst += m_candiWindowSize; changeMasks |= CANDIDATE_MASK; } } else if (m_pHotkeyProfile && m_pHotkeyProfile->isCandiDeleteKey(key, m_candiWindowSize) && !m_pIC->isEmpty()) { changeMasks |= KEYEVENT_USED; unsigned sel = (keyvalue == '0' ? 9 : keyvalue - '1'); deleteCandidate(sel, changeMasks); goto PROCESSED; } else if ((modifiers & (IM_CTRL_MASK | IM_ALT_MASK | IM_SUPER_MASK | IM_RELEASE_MASK)) == 0) { if (isKeyValueSelectNumber(keyvalue)) { // try to make selection if (!m_pIC->isEmpty()) { changeMasks |= KEYEVENT_USED; unsigned sel = getSelectionNumber(keyvalue); makeSelection(sel, changeMasks); } else if (m_smartPunct) { m_pIC->omitNextPunct(); } // using the same keys between selections isKeyStroke = true; goto PROCESSED; } if (keyvalue >= '1' && keyvalue <= '5') { changeMasks |= KEYEVENT_USED; _insert(keyvalue, changeMasks); isKeyStroke = true; } else if (keyvalue > 0x60 && keyvalue < 0x7b) { /* islower(keyvalue) */ changeMasks |= KEYEVENT_USED; _insert(keyvalue, changeMasks); isKeyStroke = true; } else if (keyvalue > 0x20 && keyvalue < 0x7f) { /* isprint(keyvalue) && !isspace(keyvalue) */ changeMasks |= KEYEVENT_USED; if (m_pIC->isEmpty()) { _insert(keyvalue, changeMasks); _doCommit(); clearIC(); } else { _insert(keyvalue, changeMasks); } isKeyStroke = true; } else if (keycode == IM_VK_BACK_SPACE || keycode == IM_VK_DELETE) { if (!m_pIC->isEmpty()) { changeMasks |= KEYEVENT_USED; _erase(keycode == IM_VK_BACK_SPACE, changeMasks); } isKeyStroke = true; } else if (keycode == IM_VK_SPACE) { if (!m_pIC->isEmpty()) { changeMasks |= KEYEVENT_USED; makeSelection(0, changeMasks); } else { wstring wstr = (CFullCharManager::fullPuncOp())(keyvalue); if (wstr.size()) { _commitString(wstr); changeMasks |= KEYEVENT_USED; } } } else if (keycode == IM_VK_ENTER) { if (!m_pIC->isEmpty()) { changeMasks |= KEYEVENT_USED | CANDIDATE_MASK | PREEDIT_MASK; _doCommit(false); clearIC(); } } else if (keycode == IM_VK_ESCAPE) { if (!m_pIC->isEmpty()) { changeMasks |= KEYEVENT_USED | CANDIDATE_MASK | PREEDIT_MASK; clearIC(); } } else if (keycode == IM_VK_LEFT) { // move left syllable if (!m_pIC->isEmpty()) { changeMasks |= KEYEVENT_USED; _moveLeftSyllable(changeMasks); } } else if (keycode == IM_VK_RIGHT) { // move right syllable if (!m_pIC->isEmpty()) { changeMasks |= KEYEVENT_USED; _moveRightSyllable(changeMasks); } } else if (keycode == IM_VK_HOME) { // move home if (!m_pIC->isEmpty()) { changeMasks |= KEYEVENT_USED; _moveHome(changeMasks); } } else if (keycode == IM_VK_END) { // move end if (!m_pIC->isEmpty()) { changeMasks |= KEYEVENT_USED; _moveEnd(changeMasks); } } } else { goto RETURN; } PROCESSED:; m_pHotkeyProfile->rememberLastKey(key); RETURN:; if (isKeyStroke) { setOpMode(XHVOM_INPUT); } else { setOpMode(XHVOM_SELECT); } #ifdef DEBUG printf(" |-->(Mask=0x%x)\n", changeMasks); #endif updateWindows(changeMasks); return changeMasks & KEYEVENT_USED; }
bool CIMIClassicView::onKeyEvent(const CKeyEvent& key) { unsigned changeMasks = 0; unsigned keycode = key.code; unsigned keyvalue = key.value; unsigned modifiers = key.modifiers; #ifdef DEBUG printf("Classic View got a key (0x%x-0x%x-0x%x)...", keycode, keyvalue, modifiers); if (((modifiers & IM_CTRL_MASK) != 0) && (keyvalue == 'P' || keyvalue == 'p')) m_pIC->printLattice(); #endif if (m_pHotkeyProfile && m_pHotkeyProfile->isModeSwitchKey(key)) { setStatusAttrValue(CIMIWinHandler::STATUS_ID_CN, (!m_bCN) ? 1 : 0); if (!m_pIC->isEmpty()) { changeMasks |= CANDIDATE_MASK | PREEDIT_MASK; clearIC(); } } else if (m_pHotkeyProfile && m_pHotkeyProfile->isPunctSwitchKey(key)) { // On CTRL+. switch Full/Half punc changeMasks |= KEYEVENT_USED; setStatusAttrValue(CIMIWinHandler::STATUS_ID_FULLPUNC, (!m_bFullPunct) ? 1 : 0); } else if (m_pHotkeyProfile && m_pHotkeyProfile->isSymbolSwitchKey(key)) { // On SHIFT+SPACE switch Full/Half symbol changeMasks |= KEYEVENT_USED; setStatusAttrValue(CIMIWinHandler::STATUS_ID_FULLSYMBOL, (!m_bFullSymbol) ? 1 : 0); } else if (modifiers == IM_CTRL_MASK && keycode == IM_VK_LEFT) { // move left if (!m_pIC->isEmpty()) { changeMasks |= KEYEVENT_USED; _moveLeft(changeMasks); } } else if (modifiers == IM_CTRL_MASK && keycode == IM_VK_RIGHT) { // move right if (!m_pIC->isEmpty()) { changeMasks |= KEYEVENT_USED; _moveRight(changeMasks); } } else if (((modifiers == 0 && keycode == IM_VK_PAGE_UP) || (m_pHotkeyProfile && m_pHotkeyProfile->isPageUpKey(key))) && !m_pIC->isEmpty()) { changeMasks |= KEYEVENT_USED; if (m_candiPageFirst > 0) { m_candiPageFirst -= m_candiWindowSize; if (m_candiPageFirst < 0) m_candiPageFirst = 0; changeMasks |= CANDIDATE_MASK; } } else if (((modifiers == 0 && keycode == IM_VK_PAGE_DOWN) || (m_pHotkeyProfile && m_pHotkeyProfile->isPageDownKey(key))) && !m_pIC->isEmpty()) { changeMasks |= KEYEVENT_USED; if (m_candiPageFirst + m_candiWindowSize < candidateListSize()) { m_candiPageFirst += m_candiWindowSize; changeMasks |= CANDIDATE_MASK; } } else if (m_pHotkeyProfile && m_pHotkeyProfile->isCandiDeleteKey(key, m_candiWindowSize) && !m_pIC->isEmpty()) { changeMasks |= KEYEVENT_USED; unsigned sel = (keyvalue == '0' ? 9 : keyvalue - '1'); deleteCandidate(sel, changeMasks); goto PROCESSED; } else if ((modifiers & (IM_CTRL_MASK | IM_ALT_MASK | IM_SUPER_MASK | IM_RELEASE_MASK)) == 0) { if ((keyvalue >= '0' && keyvalue <= '9') && (m_candiWindowSize >= 10 || keyvalue < ('1' + m_candiWindowSize))) { // try to make selection if (!m_pIC->isEmpty()) { changeMasks |= KEYEVENT_USED; unsigned sel = (keyvalue == '0' ? 9 : keyvalue - '1'); makeSelection(sel, changeMasks); } else if (m_smartPunct) { m_pIC->omitNextPunct(); } goto PROCESSED; } if (keyvalue > 0x60 && keyvalue < 0x7b) { /* islower(keyvalue) */ changeMasks |= KEYEVENT_USED; #if !defined(__APPLE__) _insert(keyvalue, changeMasks); #else _insert(keyvalue, changeMasks, ^{}); #endif } else if (keyvalue > 0x20 && keyvalue < 0x7f) {
TEST(LuaUIOperationsTest, Copy) { QApplication app(argc, argv); LuaInterface luaInterface; auto L = luaInterface.luaState(); luaInterface.hideUI(true); luaInterface.initLua(); auto mdiArea = LuaIntf::Lua::getGlobal<QMdiArea*>(L, "mdiArea"); if(mdiArea->subWindowList().count() == 0) { LuaIntf::LuaRef(L, "new_file")(); } mdiArea->setActiveSubWindow(mdiArea->subWindowList().at(0)); auto mdiChild = dynamic_cast<CadMdiChild*>(mdiArea->activeSubWindow()->widget()); auto storageManager = mdiChild->storageManager(); auto documentCanvas = mdiChild->viewer()->documentCanvas(); lc::entity::Line_CSPtr createdEntity; std::vector<lc::entity::CADEntity_CSPtr> entities; entities = storageManager->entityContainer().asVector(); for(auto entity : entities) { storageManager->removeEntity(entity); } EXPECT_EQ(0, storageManager->entityContainer().asVector().size()); LuaIntf::LuaRef(L, "create_line")(); LuaIntf::LuaRef(L, "event.trigger")("point", lc::geo::Coordinate(0, 0)); LuaIntf::LuaRef(L, "event.trigger")("point", lc::geo::Coordinate(100, 100)); EXPECT_EQ(1, storageManager->entityContainer().asVector().size()) << "Line was not created"; documentCanvas->makeSelection(0, 0, 100, 100, false, false); documentCanvas->closeSelection(); EXPECT_EQ(1, mdiChild->selection().size()) << "Entity not selected"; LuaIntf::LuaRef(L, "copy_selected_entities")(); LuaIntf::LuaRef(L, "event.trigger")("point", lc::geo::Coordinate(0, 0)); LuaIntf::LuaRef(L, "event.trigger")("point", lc::geo::Coordinate(100, 100)); entities = storageManager->entityContainer().asVector(); ASSERT_EQ(2, entities.size()); createdEntity = std::dynamic_pointer_cast<const lc::entity::Line>(entities.at(0)); EXPECT_EQ(lc::geo::Coordinate(0, 0), createdEntity->start()); EXPECT_EQ(lc::geo::Coordinate(100, 100), createdEntity->end()); createdEntity = std::dynamic_pointer_cast<const lc::entity::Line>(entities.at(1)); EXPECT_EQ(lc::geo::Coordinate(100, 100), createdEntity->start()); EXPECT_EQ(lc::geo::Coordinate(200, 200), createdEntity->end()); }