void SelectElement::updateListBoxSelection(SelectElementData& data, Element* element, bool deselectOtherOptions) { ASSERT(element->renderer() && element->renderer()->isListBox()); ASSERT(data.activeSelectionAnchorIndex() >= 0); unsigned start = min(data.activeSelectionAnchorIndex(), data.activeSelectionEndIndex()); unsigned end = max(data.activeSelectionAnchorIndex(), data.activeSelectionEndIndex()); Vector<bool>& cachedStateForActiveSelection = data.cachedStateForActiveSelection(); const Vector<Element*>& items = data.listItems(element); for (unsigned i = 0; i < items.size(); ++i) { OptionElement* optionElement = toOptionElement(items[i]); if (!optionElement || items[i]->disabled()) continue; if (i >= start && i <= end) optionElement->setSelectedState(data.activeSelectionState()); else if (deselectOtherOptions || i >= cachedStateForActiveSelection.size()) optionElement->setSelectedState(false); else optionElement->setSelectedState(cachedStateForActiveSelection[i]); } scrollToSelection(data, element); }
void SelectElement::accessKeySetSelectedIndex(SelectElementData& data, Element* element, int index) { // first bring into focus the list box if (!element->focused()) element->accessKeyAction(false); // if this index is already selected, unselect. otherwise update the selected index const Vector<Element*>& items = data.listItems(element); int listIndex = optionToListIndex(data, element, index); if (OptionElement* optionElement = (listIndex >= 0 ? toOptionElement(items[listIndex]) : 0)) { if (optionElement->selected()) optionElement->setSelectedState(false); else setSelectedIndex(data, element, index, false, true); } listBoxOnChange(data, element); scrollToSelection(data, element); }
void SelectElement::setSelectedIndex(SelectElementData& data, Element* element, int optionIndex, bool deselect, bool fireOnChangeNow, bool userDrivenChange) { const Vector<Element*>& items = data.listItems(element); int listIndex = optionToListIndex(data, element, optionIndex); if (!data.multiple()) deselect = true; Element* excludeElement = 0; if (OptionElement* optionElement = (listIndex >= 0 ? toOptionElement(items[listIndex]) : 0)) { excludeElement = items[listIndex]; if (data.activeSelectionAnchorIndex() < 0 || deselect) setActiveSelectionAnchorIndex(data, element, listIndex); if (data.activeSelectionEndIndex() < 0 || deselect) setActiveSelectionEndIndex(data, listIndex); optionElement->setSelectedState(true); } if (deselect) deselectItems(data, element, excludeElement); // For the menu list case, this is what makes the selected element appear. if (RenderObject* renderer = element->renderer()) renderer->updateFromElement(); scrollToSelection(data, element); // This only gets called with fireOnChangeNow for menu lists. if (data.usesMenuList()) { data.setUserDrivenChange(userDrivenChange); if (fireOnChangeNow) menuListOnChange(data, element); } if (Frame* frame = element->document()->frame()) frame->page()->chrome()->client()->formStateDidChange(element); }
QObject* FileSystemTab::component(Jerboa::Plugin::ComponentType type, QObject* parent) { switch(type) { case Jerboa::Plugin::WidgetUsedWithPlaylist: { QFileSystemModel* model = new FileSystemModelWithToolTip(parent); model->setRootPath("/"); model->setFilter(QDir::AllEntries | QDir::NoDotAndDotDot | QDir::AllDirs); model->setNameFilterDisables(false); QStringList musicGlobs; musicGlobs << "*.aac" << "*.aiff" << "*.ape" << "*.au" << "*.cdda" << "*.flac" << "*.m4a" << "*.mp3" << "*.oga" << "*.ogg" << "*.ogm" << "*.wav" << "*.wma" ; model->setNameFilters(musicGlobs); QTreeView* view = new QTreeView(qobject_cast<QWidget*>(parent)); view->setWindowTitle("Files"); view->setModel(model); view->setHeaderHidden(true); for(int i = 1; i < model->columnCount(); ++i) { view->setColumnHidden(i, true); } QString path = QDesktopServices::storageLocation(QDesktopServices::MusicLocation); if(path.isEmpty() || !QDir(path).exists()) { path = QDesktopServices::storageLocation(QDesktopServices::HomeLocation); } const QModelIndex index(model->index(QSettings().value("collection/directory", path).toString())); for(QModelIndex iterator(index); iterator.isValid(); iterator = iterator.parent()) { view->setExpanded(iterator, true); } view->setDragDropMode(QAbstractItemView::DragOnly); view->selectionModel()->select(index, QItemSelectionModel::ClearAndSelect); view->setSelectionMode(QAbstractItemView::ExtendedSelection); connect( view, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(addPathToPlaylist(QModelIndex)) ); QTimer* timer = new QTimer(this); connect( timer, SIGNAL(timeout()), this, SLOT(scrollToSelection()) ); timer->setSingleShot(true); timer->start(1000); m_view = view; return view; } default: return Jerboa::Plugin::component(type, parent); } }