TEST_F(ListControlItemSelectionManagerTest, RevertSelection) { auto test = [this]( std::size_t revert_index, std::size_t check_index, std::size_t check_count, const std::set<std::size_t>& expected_selected_indexes) { item_selection_manager_->RevertSelection(revert_index); CheckSelection(check_index, check_count, expected_selected_indexes); }; test(0, 0, 10, { 0 }); test(0, 0, 10, { }); test(0, 0, 10, { 0 }); test(0, 0, 10, { }); test(33, 30, 35, { 33 }); test(34, 30, 35, { 33, 34 }); test(3, 0, 40, { 3, 33, 34 }); //Revert in selection range item_selection_manager_->ReplaceSelection(7, 2); test(7, 0, 10, { 8 }); test(8, 0, 10, { }); }
void EditTOC::MoveRight() { QModelIndex index = CheckSelection(0); if (!index.isValid()) { return; } QStandardItem *item = m_TableOfContents->itemFromIndex(index); int item_row = item->row(); // Can't indent if row above is already parent if (item_row == 0) { return; } QStandardItem *parent_item = item->parent(); if (!parent_item) { parent_item = m_TableOfContents->invisibleRootItem(); } // Make the item above the parent of this item QList<QStandardItem *> row_items = parent_item->takeRow(item_row); QStandardItem *new_parent = parent_item->child(item_row - 1, 0); new_parent->insertRow(new_parent->rowCount(), row_items); QStandardItem *new_item = new_parent->child(new_parent->rowCount() - 1, 0); // Reselect the item ui.TOCTree->selectionModel()->clear(); ui.TOCTree->setCurrentIndex(item->index()); ui.TOCTree->selectionModel()->select(item->index(), QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); ExpandChildren(new_item); }
TEST_F(ListControlItemSelectionManagerTest, ReplaceSelection) { auto test = [this]( std::size_t replace_index, std::size_t replace_count, std::size_t check_index, std::size_t check_count, const std::set<std::size_t>& expected_selected_indexes) { item_selection_manager_->ReplaceSelection(replace_index, replace_count); CheckSelection(check_index, check_count, expected_selected_indexes); }; //Empty range. test(0, 0, 0, 10, { }); test(3, 0, 0, 10, { }); //Single selection test(0, 1, 0, 10, { 0 }); test(2, 1, 0, 10, { 2 }); //Multiple selection test(0, 5, 0, 10, { 0, 1, 2, 3, 4 }); test(3, 5, 0, 10, { 3, 4, 5, 6, 7 }); test(11, 3, 0, 20, { 11, 12, 13 }); }
void EditTOC::MoveDown() { QModelIndex index = CheckSelection(0); if (!index.isValid()) { return; } QStandardItem *item = m_TableOfContents->itemFromIndex(index); QStandardItem *parent_item = item->parent(); if (!parent_item) { parent_item = m_TableOfContents->invisibleRootItem(); } int item_row = item->row(); // Can't move down if this row is already the last one of its parent if (item_row == parent_item->rowCount() - 1) { return; } QList<QStandardItem *> row_items = parent_item->takeRow(item_row); parent_item->insertRow(item_row + 1, row_items); // Reselect the item ui.TOCTree->selectionModel()->clear(); ui.TOCTree->setCurrentIndex(item->index()); ui.TOCTree->selectionModel()->select(item->index(), QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); ExpandChildren(item); }
void EditTOC::AddEntry(bool above) { QModelIndex index = CheckSelection(0); if (!index.isValid()) { return; } QStandardItem *item = m_TableOfContents->itemFromIndex(index); QStandardItem *parent_item = item->parent(); if (!parent_item) { parent_item = m_TableOfContents->invisibleRootItem(); } // Add a new empty row of items QStandardItem *entry_item = new QStandardItem(); QStandardItem *target_item = new QStandardItem(); QList<QStandardItem *> row_items; row_items << entry_item << target_item ; int location = 1; if (above) { location = 0; } parent_item->insertRow(item->row() + location,row_items); // Select the new row ui.TOCTree->selectionModel()->clear(); ui.TOCTree->setCurrentIndex(entry_item->index()); ui.TOCTree->selectionModel()->select(entry_item->index(), QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); }
void CFriendListCtrl::OnRightClick(wxMouseEvent& event) { int cursel = CheckSelection(event); CFriend* cur_friend = NULL; wxMenu* menu = new wxMenu(_("Friends")); if ( cursel != -1 ) { cur_friend = (CFriend*)GetItemData(cursel); menu->Append(MP_DETAIL, _("Show &Details")); menu->Enable(MP_DETAIL, cur_friend->GetLinkedClient().IsLinked()); } menu->Append(MP_ADDFRIEND, _("Add a friend")); if (cursel != (-1)) { menu->Append(MP_REMOVEFRIEND, _("Remove Friend")); menu->Append(MP_MESSAGE, _("Send &Message")); menu->Append(MP_SHOWLIST, _("View Files")); menu->AppendCheckItem(MP_FRIENDSLOT, _("Establish Friend Slot")); if (cur_friend->GetLinkedClient().IsLinked()) { menu->Enable(MP_FRIENDSLOT, true); menu->Check(MP_FRIENDSLOT, cur_friend->HasFriendSlot()); } else { menu->Enable(MP_FRIENDSLOT, false); } } PopupMenu(menu, event.GetPosition()); delete menu; }
void TControl::OnMouseMove(QMouseEvent event) { if (State == CS_PlanetSelection) { World->UpdateSelection(SelectionFrom, event.pos()); CheckSelection(SelectionFrom, event.pos()); } else if (State == CS_TargetSelection) { CheckTargetSelection(event.pos()); } }
long CMuleListCtrl::CheckSelection(wxMouseEvent& event) { int flags = 0; wxListEvent evt; evt.m_itemIndex = HitTest(event.GetPosition(), flags); return CheckSelection(evt); }
void TControl::OnMouseEvent(QMouseEvent event, bool pressed) { if (pressed) { SelectionFrom = event.pos(); MousePressed = true; CheckSelection(SelectionFrom, event.pos()); TargetSelection = !World->SelectedPlanets.empty(); } else { MousePressed = false; CheckSelection(SelectionFrom, event.pos()); World->Selection.reset(); if (World->SelectedTarget.is_initialized()) { SpawnShips(); World->SelectedTarget.reset(); } if (TargetSelection) { World->SelectedPlanets.clear(); } } }
void TControl::OnMouseMove(QMouseEvent event) { if (MousePressed) { if (!TargetSelection) { World->UpdateSelection(SelectionFrom, event.pos()); CheckSelection(SelectionFrom, event.pos()); } else { CheckTargetSelection(event.pos()); } } }
void TControl::OnMouseEvent(QMouseEvent event, bool mouseDown) { if (State == CS_None) { CheckSelection(event.pos(), event.pos()); if (!World->SelectedPlanets.empty()) { State = CS_TargetSelection; } else if (mouseDown) { State = CS_PlanetSelection; SelectionFrom = event.pos(); } } else if (State == CS_PlanetSelection && !mouseDown) { if (!World->SelectedPlanets.empty()) { State = CS_TargetSelection; World->Selection.reset(); } else { State = CS_None; World->SelectedPlanets.clear(); World->Selection.reset(); World->SelectedTarget.reset(); } } else if (State == CS_TargetSelection && !mouseDown) { CheckTargetSelection(event.pos()); if (World->SelectedTarget.is_initialized()) { if (World->SelectedPlanets.size() == 1 && *World->SelectedPlanets.begin() == *World->SelectedTarget) { CheckSelection(event.pos(), event.pos()); } else { SpawnShips(); State = CS_None; World->SelectedPlanets.clear(); World->Selection.reset(); World->SelectedTarget.reset(); } } else { State = CS_None; World->SelectedPlanets.clear(); World->Selection.reset(); World->SelectedTarget.reset(); } } }
TEST_F(ListControlItemSelectionManagerTest, RemoveSelection) { auto test = [this]( std::size_t remove_index, std::size_t remove_count, std::size_t check_index, std::size_t check_count, const std::set<std::size_t>& expected_selected_indexes) { item_selection_manager_->RemoveSelection(remove_index, remove_count); CheckSelection(check_index, check_count, expected_selected_indexes); }; //Remove from empty selection. item_selection_manager_->ReplaceSelection(0, 0); test(0, 10, 0, 10, { }); //Remove empty selection. item_selection_manager_->ReplaceSelection(0, 5); test(0, 0, 0, 10, { 0, 1, 2, 3, 4 }); //Remove before selection. item_selection_manager_->ReplaceSelection(5, 2); test(0, 5, 0, 10, { 5, 6 }); //Remove after selection. item_selection_manager_->ReplaceSelection(5, 2); test(7, 5, 0, 10, { 5, 6 }); //Remove selection. item_selection_manager_->ReplaceSelection(10, 10); test(0, 12, 0, 30, { 12, 13, 14, 15, 16, 17, 18, 19 }); test(18, 5, 0, 30, { 12, 13, 14, 15, 16, 17 }); test(14, 2, 0, 30, { 12, 13, 16, 17 }); //Remove whole selection. item_selection_manager_->ReplaceSelection(10, 2); test(10, 2, 0, 20, { }); test(8, 4, 0, 20, { }); test(10, 4, 0, 20, { }); test(8, 8, 0, 20, { }); //Remove selection across multi selection. item_selection_manager_->ReplaceSelection(4, 2); item_selection_manager_->AddSelection(8, 2); test(0, 10, 0, 10, { }); item_selection_manager_->ReplaceSelection(4, 2); item_selection_manager_->AddSelection(8, 2); test(5, 4, 0, 10, { 4, 9 }); }
TEST_F(ListControlItemSelectionManagerTest, AddSelection) { auto test = [this]( std::size_t add_index, std::size_t add_count, std::size_t check_index, std::size_t check_count, const std::set<std::size_t>& expected_selected_indexes) { item_selection_manager_->AddSelection(add_index, add_count); CheckSelection(check_index, check_count, expected_selected_indexes); }; //Add to empty selection item_selection_manager_->ReplaceSelection(0, 0); test(0, 1, 0, 10, { 0 }); test(0, 4, 0, 10, { 0, 1, 2, 3 }); //Add empty selection item_selection_manager_->ReplaceSelection(0, 0); test(0, 0, 0, 10, { }); //Add selection that doesn't intersect with other. item_selection_manager_->ReplaceSelection(10, 2); test(0, 2, 0, 20, { 0, 1, 10, 11 }); test(9, 1, 0, 20, { 0, 1, 9, 10, 11 }); test(12, 1, 0, 20, { 0, 1, 9, 10, 11, 12 }); test(15, 3, 0, 20, { 0, 1, 9, 10, 11, 12, 15, 16, 17 }); //Add selection intersects with other. item_selection_manager_->ReplaceSelection(10, 2); test(8, 3, 0, 20, { 8, 9, 10, 11 }); test(10, 4, 0, 20, { 8, 9, 10, 11, 12, 13 }); test(6, 10, 0, 20, { 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }); test(9, 3, 0, 20, { 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }); //Add selection across other selections. item_selection_manager_->ReplaceSelection(5, 2); item_selection_manager_->RevertSelection(9); item_selection_manager_->RevertSelection(10); test(4, 8, 0, 20, { 4, 5, 6, 7, 8, 9, 10, 11 }); item_selection_manager_->RevertSelection(5); test(0, 0, 0, 20, { 4, 6, 7, 8, 9, 10, 11 }); item_selection_manager_->RevertSelection(6); test(0, 0, 0, 20, { 4, 7, 8, 9, 10, 11 }); item_selection_manager_->RevertSelection(9); test(0, 0, 0, 20, { 4, 7, 8, 10, 11 }); item_selection_manager_->RevertSelection(10); test(0, 0, 0, 20, { 4, 7, 8, 11 }); }
void EditTOC::SelectTarget() { QModelIndex index = CheckSelection(1); if (!index.isValid()) { return; } QStandardItem *item = m_TableOfContents->itemFromIndex(index); SelectHyperlink select_target(item->text(), NULL, m_Resources, m_Book, this); if (select_target.exec() == QDialog::Accepted) { item->setText(select_target.GetTarget()); } }
TEST_F(ListControlItemSelectionManagerTest, AdjustSelectionByAddingIndexes) { auto test = [this]( std::size_t add_index, std::size_t add_count, std::size_t check_index, std::size_t check_count, const std::set<std::size_t>& expected_selected_indexes) { item_selection_manager_->AdjustSelectionByAddingIndexes(add_index, add_count); CheckSelection(check_index, check_count, expected_selected_indexes); }; //Add indexes to empty selection. item_selection_manager_->ReplaceSelection(0, 0); test(0, 0, 0, 10, { }); test(0, 1, 0, 10, { }); test(3, 0, 0, 10, { }); test(3, 2, 0, 10, { }); //Add indexes before selection. item_selection_manager_->RevertSelection(0); item_selection_manager_->RevertSelection(5); test(0, 0, 0, 10, { 0, 5 }); test(0, 1, 0, 10, { 1, 6 }); test(1, 1, 0, 10, { 2, 7 }); test(0, 4, 0, 20, { 6, 11 }); //Add indexes to the middle of selection. item_selection_manager_->ReplaceSelection(0, 0); item_selection_manager_->RevertSelection(0); item_selection_manager_->RevertSelection(5); item_selection_manager_->RevertSelection(6); item_selection_manager_->RevertSelection(10); test(6, 2, 0, 20, { 0, 5, 8, 12 }); //Insert indexes into selection. item_selection_manager_->ReplaceSelection(0, 10); test(3, 2, 0, 20, { 0, 1, 2, 5, 6, 7, 8, 9, 10, 11 }); ASSERT_EQ(0, item_selection_manager_->GetFirstSelectedIndex()); //Add indexes after selection. item_selection_manager_->ReplaceSelection(0, 0); item_selection_manager_->RevertSelection(0); item_selection_manager_->RevertSelection(5); test(1, 1, 0, 10, { 0, 6 }); test(1, 3, 0, 10, { 0, 9 }); }
void EditTOC::DeleteEntry() { QModelIndex index = CheckSelection(0); if (!index.isValid()) { return; } QStandardItem *item = m_TableOfContents->itemFromIndex(index); QStandardItem *parent_item = item->parent(); if (!parent_item) { parent_item = m_TableOfContents->invisibleRootItem(); } parent_item->takeRow(item->row()); }
TEST_F(ListControlItemSelectionManagerTest, AdjustSelectionByRemovingIndexes) { auto test = [this]( std::size_t remove_index, std::size_t remove_count, std::size_t check_index, std::size_t check_count, const std::set<std::size_t>& expected_selected_indexes) { item_selection_manager_->AdjustSelectionByRemovingIndexes(remove_index, remove_count); CheckSelection(check_index, check_count, expected_selected_indexes); }; //Remove from empty selection. item_selection_manager_->ReplaceSelection(0, 0); test(0, 0, 0, 10, { }); test(0, 3, 0, 10, { }); //Remove indexes before selection. item_selection_manager_->ReplaceSelection(0, 0); item_selection_manager_->RevertSelection(1); item_selection_manager_->RevertSelection(4); test(0, 1, 0, 10, { 0, 3 }); test(1, 2, 0, 10, { 0, 1 }); //Remove indexes at the middle of selection. item_selection_manager_->ReplaceSelection(5, 5); test(0, 11, 0, 20, { }); item_selection_manager_->ReplaceSelection(5, 5); test(0, 7, 0, 20, { 0, 1, 2 }); item_selection_manager_->ReplaceSelection(5, 5); test(5, 2, 0, 20, { 5, 6, 7 }); item_selection_manager_->ReplaceSelection(5, 5); test(6, 3, 0, 20, { 5, 6 }); item_selection_manager_->ReplaceSelection(5, 5); test(7, 3, 0, 20, { 5, 6 }); item_selection_manager_->ReplaceSelection(5, 5); test(7, 10, 0, 20, { 5, 6 }); //Remove indexes after selection. item_selection_manager_->ReplaceSelection(0, 0); item_selection_manager_->RevertSelection(0); item_selection_manager_->RevertSelection(5); test(6, 1, 0, 10, { 0, 5 }); test(3, 2, 0, 10, { 0, 3 }); }
void EditTOC::MoveLeft() { QModelIndex index = CheckSelection(0); if (!index.isValid()) { return; } QStandardItem *item = m_TableOfContents->itemFromIndex(index); QStandardItem *parent_item = item->parent(); // Can't indent above top level if (!parent_item) { return; } QStandardItem *grandparent_item = parent_item->parent(); if (!grandparent_item) { grandparent_item = m_TableOfContents->invisibleRootItem(); } // Make siblings following the entry into children int row = item->row() ; while (row + 1 < parent_item->rowCount()) { QList<QStandardItem *> row_items = parent_item->takeRow(row + 1); int row_count = item->rowCount(); item->setChild(row_count, 0, row_items[0]); item->setChild(row_count, 1, row_items[1]); } // Make item child of grandparent int parent_row = parent_item->row(); QList<QStandardItem *> row_items = parent_item->takeRow(row); grandparent_item->insertRow(parent_row + 1, row_items); // Reselect the item QModelIndex item_index = grandparent_item->child(parent_row + 1)->index(); ui.TOCTree->selectionModel()->clear(); ui.TOCTree->setCurrentIndex(item_index); ui.TOCTree->selectionModel()->select(item_index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); ExpandChildren(grandparent_item->child(parent_row + 1)); }
void CSharedFilesCtrl::OnRightClick(wxListEvent& event) { long item_hit = CheckSelection(event); if ( (m_menu == NULL) && (item_hit != -1)) { m_menu = new wxMenu(_("Shared Files")); wxMenu* prioMenu = new wxMenu(); prioMenu->AppendCheckItem(MP_PRIOVERYLOW, _("Very low")); prioMenu->AppendCheckItem(MP_PRIOLOW, _("Low")); prioMenu->AppendCheckItem(MP_PRIONORMAL, _("Normal")); prioMenu->AppendCheckItem(MP_PRIOHIGH, _("High")); prioMenu->AppendCheckItem(MP_PRIOVERYHIGH, _("Very High")); prioMenu->AppendCheckItem(MP_POWERSHARE, _("Release")); prioMenu->AppendCheckItem(MP_PRIOAUTO, _("Auto")); m_menu->Append(0,_("Priority"),prioMenu); m_menu->AppendSeparator(); CKnownFile* file = (CKnownFile*)GetItemData(item_hit); if (file->GetFileComment().IsEmpty() && !file->GetFileRating()) { m_menu->Append(MP_CMT, _("Add Comment/Rating")); } else { m_menu->Append(MP_CMT, _("Edit Comment/Rating")); } m_menu->AppendSeparator(); m_menu->Append(MP_RENAME, _("Rename")); m_menu->AppendSeparator(); if (file->GetFileName().GetExt() == wxT("emulecollection")) { m_menu->Append( MP_ADDCOLLECTION, _("Add files in collection to transfer list")); m_menu->AppendSeparator(); } m_menu->Append(MP_GETMAGNETLINK,_("Copy magnet &URI to clipboard")); m_menu->Append(MP_GETED2KLINK,_("Copy eD2k &link to clipboard")); m_menu->Append(MP_GETSOURCEED2KLINK,_("Copy eD2k link to clipboard (&Source)")); m_menu->Append(MP_GETCRYPTSOURCEDED2KLINK,_("Copy eD2k link to clipboard (Source) (&With Crypt options)")); m_menu->Append(MP_GETHOSTNAMESOURCEED2KLINK,_("Copy eD2k link to clipboard (&Hostname)")); m_menu->Append(MP_GETHOSTNAMECRYPTSOURCEED2KLINK,_("Copy eD2k link to clipboard (Hostname) (With &Crypt options)")); m_menu->Append(MP_GETAICHED2KLINK,_("Copy eD2k link to clipboard (&AICH info)")); m_menu->Append(MP_WS,_("Copy feedback to clipboard")); m_menu->Enable(MP_GETAICHED2KLINK, file->HasProperAICHHashSet()); m_menu->Enable(MP_GETHOSTNAMESOURCEED2KLINK, !thePrefs::GetYourHostname().IsEmpty()); m_menu->Enable(MP_GETHOSTNAMECRYPTSOURCEED2KLINK, !thePrefs::GetYourHostname().IsEmpty()); int priority = file->IsAutoUpPriority() ? PR_AUTO : file->GetUpPriority(); prioMenu->Check(MP_PRIOVERYLOW, priority == PR_VERYLOW); prioMenu->Check(MP_PRIOLOW, priority == PR_LOW); prioMenu->Check(MP_PRIONORMAL, priority == PR_NORMAL); prioMenu->Check(MP_PRIOHIGH, priority == PR_HIGH); prioMenu->Check(MP_PRIOVERYHIGH,priority == PR_VERYHIGH); prioMenu->Check(MP_POWERSHARE, priority == PR_POWERSHARE); prioMenu->Check(MP_PRIOAUTO, priority == PR_AUTO); PopupMenu( m_menu, event.GetPoint() ); delete m_menu; m_menu = NULL; } }
VOID* ViewUnitEditor::onMouseUp(INT32 button, INT32 x, INT32 y) { ::ReleaseCapture(); if (!_lmdown && !_rmdown) { return NULL; } switch(button) { case MOUSE_LEFT: _lmdown = false; this->onRender(); //for remove selection rectangle break; case MOUSE_RIGHT: _rmdown = false; break; } // 마우스 왼쪽버튼을 떼었을 때, Action을 정의해서 저장 if(button == MOUSE_LEFT) { FLOAT rect[4]; POINT now; now.x = x; now.y = y; _pViewUnitPainter->dp2lp(_ldown, &rect[0], &rect[1]); // mouse down position _pViewUnitPainter->dp2lp(now, &rect[2], &rect[3]); // current cursor position Action* act = ActionFactory::createSelection(_layers.shapes(), rect); act->excute(); //_actions.insert(act); CheckSelection(); } // if(button == MOUSE_LEFT) // 마우스 오른쪽 버튼을 떼었을 때, Action을 정의해서 저장 if(button == MOUSE_RIGHT) { INT dx = x - _current.x; INT dy = _current.y - y; Action* act = ActionFactory::createCamMoveDone(_pPainter, dx, dy); _actions.insert(act); //// 마우스 우클릭 메뉴 추가 141007 smcho //if (_startRdown.x == x && _startRdown.y == y) //{ // if (_fView != NULL) // { // if (_fView->PopupMenu != NULL) // { // _fView->PopupMenu->Popup(_fView->ClientOrigin.X + x, _fView->ClientOrigin.Y + y); // } // } //} } // if(button == MOUSE_RIGHT) this->onRender(); // for draw selected shapes return NULL; }