void QgsFeatureListView::selectRow( const QModelIndex &index, bool anchor ) { QItemSelectionModel::SelectionFlags command = selectionCommand( index ); int row = index.row(); if ( anchor ) mRowAnchor = row; if ( selectionMode() != QListView::SingleSelection && command.testFlag( QItemSelectionModel::Toggle ) ) { if ( anchor ) mCtrlDragSelectionFlag = mFeatureSelectionModel->isSelected( index ) ? QItemSelectionModel::Deselect : QItemSelectionModel::Select; command &= ~QItemSelectionModel::Toggle; command |= mCtrlDragSelectionFlag; if ( !anchor ) command |= QItemSelectionModel::Current; } QModelIndex tl = model()->index( std::min( mRowAnchor, row ), 0 ); QModelIndex br = model()->index( std::max( mRowAnchor, row ), model()->columnCount() - 1 ); mFeatureSelectionModel->selectFeatures( QItemSelection( tl, br ), command ); }
void AMActionHistoryTreeView3::mousePressEvent(QMouseEvent *event){ // Ignore mouse clicks if the cursor shows forbidden if(shiftKeyDown_ && hasOverriddenShiftCursor_){ event->ignore(); } // Actually handling valid shift-clicks else if(shiftKeyDown_){ AMActionHistoryModel3 *historyModel = qobject_cast<AMActionHistoryModel3*>(model()); QModelIndex index = indexAt(event->pos()); // We can ignore: bad models, invalid indexes, not enabled indexes, and not selectable indexes if(!historyModel || !index.isValid() || !index.flags().testFlag(Qt::ItemIsEnabled) || !index.flags().testFlag(Qt::ItemIsSelectable)) event->ignore(); // Grab current selection from model and the indices between the shift click QItemSelection currentSelection = selectionModel()->selection(); QItemSelection newSelection = historyModel->indicesBetween(index, lastClickedIndex_); // Call the selectionCommand function and merge the current and new selections QItemSelectionModel::SelectionFlags command = selectionCommand(index, event); currentSelection.merge(newSelection, command); // Clear the selection and select the combined list selectionModel()->clearSelection(); selectionModel()->select(currentSelection, command); // Grab the list indices between the shift click so we can apply the right parentSelected states to them QModelIndexList interiorIndices = newSelection.indexes(); // We only care about lists that have interior elements, the indicesBetween call returns the ends as well if(interiorIndices.count() >= 2){ // Grab the clear flag for the signal emitted below bool clearFlag = command.testFlag(QItemSelectionModel::Clear); // Not sure if the indices are ordered correctly, so figure out the min and max to remove them (they should be the ends we don't care about) QModelIndex minRowIndex = interiorIndices.at(0); int minRowValue = minRowIndex.row(); QModelIndex maxRowIndex = interiorIndices.at(1); int maxRowValue = maxRowIndex.row(); for(int x = 0; x < interiorIndices.count(); x++){ if(interiorIndices.at(x).row() < minRowValue){ minRowIndex = interiorIndices.at(x); minRowValue = minRowIndex.row(); } if(interiorIndices.at(x).row() > maxRowValue){ maxRowIndex = interiorIndices.at(x); maxRowValue = maxRowIndex.row(); } } // Remove both ends interiorIndices.removeOne(maxRowIndex); interiorIndices.removeOne(minRowIndex); // For all interior indices emulate a click by emitting the actuallySelectedByClicking signal ... then the regular chain of events can happen to parentSelect the children for(int x = 0; x < interiorIndices.count(); x++) emit actuallySelectedByClicking(interiorIndices.at(x), clearFlag); } // Accept the event event->accept(); } // Ignore mouse clicks if the cursor shows forbidden else if(controlKeyDown_ && hasOverriddenControlCursor_){ event->ignore(); } // Falls through, call the parent class else QTreeView::mousePressEvent(event); }
void DownloadProgressView::MessageReceived(BMessage* message) { switch (message->what) { case B_DOWNLOAD_STARTED: { BString path; if (message->FindString("path", &path) != B_OK) break; fPath.SetTo(path); BEntry entry(fPath.Path()); fIconView->SetTo(entry); fStatusBar->Reset(fPath.Leaf()); _StartNodeMonitor(entry); // Immediately switch to speed display whenever a new download // starts. sShowSpeed = true; sLastEstimatedFinishSpeedToggleTime = fProcessStartTime = fLastSpeedReferenceTime = fEstimatedFinishReferenceTime = system_time(); break; } case B_DOWNLOAD_PROGRESS: { int64 currentSize; int64 expectedSize; if (message->FindInt64("current size", ¤tSize) == B_OK && message->FindInt64("expected size", &expectedSize) == B_OK) { _UpdateStatus(currentSize, expectedSize); } break; } case B_DOWNLOAD_REMOVED: // TODO: This is a bit asymetric. The removed notification // arrives here, but it would be nicer if it arrived // at the window... Window()->PostMessage(message); break; case OPEN_DOWNLOAD: { // TODO: In case of executable files, ask the user first! entry_ref ref; status_t status = get_ref_for_path(fPath.Path(), &ref); if (status == B_OK) status = be_roster->Launch(&ref); if (status != B_OK && status != B_ALREADY_RUNNING) { BAlert* alert = new BAlert("Open download error", "The download could not be opened.", "OK"); alert->Go(NULL); } break; } case RESTART_DOWNLOAD: BWebPage::RequestDownload(fURL); break; case CANCEL_DOWNLOAD: fDownload->Cancel(); DownloadCanceled(); break; case REMOVE_DOWNLOAD: { Window()->PostMessage(SAVE_SETTINGS); RemoveSelf(); delete this; // TOAST! return; } case B_NODE_MONITOR: { int32 opCode; if (message->FindInt32("opcode", &opCode) != B_OK) break; switch (opCode) { case B_ENTRY_REMOVED: fIconView->SetIconDimmed(true); DownloadCanceled(); break; case B_ENTRY_MOVED: { // Follow the entry to the new location dev_t device; ino_t directory; const char* name; if (message->FindInt32("device", reinterpret_cast<int32*>(&device)) != B_OK || message->FindInt64("to directory", reinterpret_cast<int64*>(&directory)) != B_OK || message->FindString("name", &name) != B_OK || strlen(name) == 0) { break; } // Construct the BEntry and update fPath entry_ref ref(device, directory, name); BEntry entry(&ref); if (entry.GetPath(&fPath) != B_OK) break; // Find out if the directory is the Trash for this // volume char trashPath[B_PATH_NAME_LENGTH]; if (find_directory(B_TRASH_DIRECTORY, device, false, trashPath, B_PATH_NAME_LENGTH) == B_OK) { BPath trashDirectory(trashPath); BPath parentDirectory; fPath.GetParent(&parentDirectory); if (parentDirectory == trashDirectory) { // The entry was moved into the Trash. // If the download is still in progress, // cancel it. if (fDownload) fDownload->Cancel(); fIconView->SetIconDimmed(true); DownloadCanceled(); break; } else if (fIconView->IsIconDimmed()) { // Maybe it was moved out of the trash. fIconView->SetIconDimmed(false); } } // Inform download of the new path if (fDownload) fDownload->HasMovedTo(fPath); float value = fStatusBar->CurrentValue(); fStatusBar->Reset(name); fStatusBar->SetTo(value); Window()->PostMessage(SAVE_SETTINGS); break; } case B_ATTR_CHANGED: { BEntry entry(fPath.Path()); fIconView->SetIconDimmed(false); fIconView->SetTo(entry); break; } } break; } // Context menu messages case COPY_URL_TO_CLIPBOARD: if (be_clipboard->Lock()) { BMessage* data = be_clipboard->Data(); if (data != NULL) { be_clipboard->Clear(); data->AddData("text/plain", B_MIME_TYPE, fURL.String(), fURL.Length()); } be_clipboard->Commit(); be_clipboard->Unlock(); } break; case OPEN_CONTAINING_FOLDER: if (fPath.InitCheck() == B_OK) { BPath containingFolder; if (fPath.GetParent(&containingFolder) != B_OK) break; BEntry entry(containingFolder.Path()); if (!entry.Exists()) break; entry_ref ref; if (entry.GetRef(&ref) != B_OK) break; be_roster->Launch(&ref); // Use Tracker scripting and select the download pose // in the window. // TODO: We should somehow get the window that just openend. // Using the name like this is broken when there are multiple // windows open with this name. Also Tracker does not scroll // to this entry. BString windowName = ref.name; BString fullWindowName = containingFolder.Path(); BMessenger trackerMessenger("application/x-vnd.Be-TRAK"); if (trackerMessenger.IsValid() && get_ref_for_path(fPath.Path(), &ref) == B_OK) { // We need to wait a bit until the folder is open. // TODO: This is also too fragile... we should be able // to wait for the roster message. snooze(250000); int32 tries = 2; while (tries > 0) { BMessage selectionCommand(B_SET_PROPERTY); selectionCommand.AddSpecifier("Selection"); selectionCommand.AddSpecifier("Poses"); selectionCommand.AddSpecifier("Window", windowName.String()); selectionCommand.AddRef("data", &ref); BMessage reply; trackerMessenger.SendMessage(&selectionCommand, &reply); int32 error; if (reply.FindInt32("error", &error) != B_OK || error == B_OK) { break; } windowName = fullWindowName; tries--; } } } break; default: BGroupView::MessageReceived(message); } }
inline QItemSelectionModel::SelectionFlags tst_selectionCommand(const QModelIndex &index, const QEvent *event = 0) const { return selectionCommand(index, event); }
void DownloadProgressView::MessageReceived(BMessage* message) { switch (message->what) { case B_DOWNLOAD_STARTED: { BString path; if (message->FindString("path", &path) != B_OK) break; fPath.SetTo(path); BEntry entry(fPath.Path()); fIconView->SetTo(entry); fStatusBar->Reset(fPath.Leaf()); _StartNodeMonitor(entry); // Immediately switch to speed display whenever a new download // starts. sShowSpeed = true; sLastEstimatedFinishSpeedToggleTime = fProcessStartTime = fLastSpeedReferenceTime = fEstimatedFinishReferenceTime = system_time(); break; } case B_DOWNLOAD_PROGRESS: { int64 currentSize; int64 expectedSize; if (message->FindInt64("current size", ¤tSize) == B_OK && message->FindInt64("expected size", &expectedSize) == B_OK) { _UpdateStatus(currentSize, expectedSize); } break; } case B_DOWNLOAD_REMOVED: // TODO: This is a bit asymetric. The removed notification // arrives here, but it would be nicer if it arrived // at the window... Window()->PostMessage(message); break; case OPEN_DOWNLOAD: { // TODO: In case of executable files, ask the user first! entry_ref ref; status_t status = get_ref_for_path(fPath.Path(), &ref); if (status == B_OK) status = be_roster->Launch(&ref); if (status != B_OK && status != B_ALREADY_RUNNING) { BAlert* alert = new BAlert(B_TRANSLATE("Open download error"), B_TRANSLATE("The download could not be opened."), B_TRANSLATE("OK")); alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); alert->Go(NULL); } break; } case RESTART_DOWNLOAD: { // We can't create a download without a full web context (mainly // because it needs to access the cookie jar), and when we get here // the original context is long gone (possibly the browser was // restarted). So we create a new window to restart the download // in a fresh context. // FIXME this has of course the huge downside of leaving the new // window open with a blank page. I can't think of a better // solution right now... BMessage* request = new BMessage(NEW_WINDOW); request->AddString("url", fURL); be_app->PostMessage(request); break; } case CANCEL_DOWNLOAD: CancelDownload(); break; case REMOVE_DOWNLOAD: { Window()->PostMessage(SAVE_SETTINGS); RemoveSelf(); delete this; // TOAST! return; } case B_NODE_MONITOR: { int32 opCode; if (message->FindInt32("opcode", &opCode) != B_OK) break; switch (opCode) { case B_ENTRY_REMOVED: fIconView->SetIconDimmed(true); CancelDownload(); break; case B_ENTRY_MOVED: { // Follow the entry to the new location dev_t device; ino_t directory; const char* name; if (message->FindInt32("device", reinterpret_cast<int32*>(&device)) != B_OK || message->FindInt64("to directory", reinterpret_cast<int64*>(&directory)) != B_OK || message->FindString("name", &name) != B_OK || strlen(name) == 0) { break; } // Construct the BEntry and update fPath entry_ref ref(device, directory, name); BEntry entry(&ref); if (entry.GetPath(&fPath) != B_OK) break; // Find out if the directory is the Trash for this // volume char trashPath[B_PATH_NAME_LENGTH]; if (find_directory(B_TRASH_DIRECTORY, device, false, trashPath, B_PATH_NAME_LENGTH) == B_OK) { BPath trashDirectory(trashPath); BPath parentDirectory; fPath.GetParent(&parentDirectory); if (parentDirectory == trashDirectory) { // The entry was moved into the Trash. // If the download is still in progress, // cancel it. fIconView->SetIconDimmed(true); CancelDownload(); break; } else if (fIconView->IsIconDimmed()) { // Maybe it was moved out of the trash. fIconView->SetIconDimmed(false); } } // Inform download of the new path if (fDownload) fDownload->HasMovedTo(fPath); float value = fStatusBar->CurrentValue(); fStatusBar->Reset(name); fStatusBar->SetTo(value); Window()->PostMessage(SAVE_SETTINGS); break; } case B_ATTR_CHANGED: { BEntry entry(fPath.Path()); fIconView->SetIconDimmed(false); fIconView->SetTo(entry); break; } } break; } // Context menu messages case COPY_URL_TO_CLIPBOARD: if (be_clipboard->Lock()) { BMessage* data = be_clipboard->Data(); if (data != NULL) { be_clipboard->Clear(); data->AddData("text/plain", B_MIME_TYPE, fURL.String(), fURL.Length()); } be_clipboard->Commit(); be_clipboard->Unlock(); } break; case OPEN_CONTAINING_FOLDER: if (fPath.InitCheck() == B_OK) { BEntry selected(fPath.Path()); if (!selected.Exists()) break; BPath containingFolder; if (fPath.GetParent(&containingFolder) != B_OK) break; entry_ref ref; if (get_ref_for_path(containingFolder.Path(), &ref) != B_OK) break; // Ask Tracker to open the containing folder and select the // file inside it. BMessenger trackerMessenger("application/x-vnd.Be-TRAK"); if (trackerMessenger.IsValid()) { BMessage selectionCommand(B_REFS_RECEIVED); selectionCommand.AddRef("refs", &ref); node_ref selectedRef; if (selected.GetNodeRef(&selectedRef) == B_OK) { selectionCommand.AddData("nodeRefToSelect", B_RAW_TYPE, (void*)&selectedRef, sizeof(node_ref)); } trackerMessenger.SendMessage(&selectionCommand); } } break; default: BGroupView::MessageReceived(message); } }