| 45 | }; |
| 46 | |
| 47 | QuickOpenWidget::QuickOpenWidget(QuickOpenModel* model, const QStringList& initialItems, const QStringList& initialScopes, bool listOnly, bool noSearchField) |
| 48 | : m_model(model) |
| 49 | , m_expandedTemporary(false) |
| 50 | , m_hadNoCommandSinceAlt(true) |
| 51 | { |
| 52 | m_filterTimer.setSingleShot(true); |
| 53 | connect(&m_filterTimer, &QTimer::timeout, this, &QuickOpenWidget::applyFilter); |
| 54 | |
| 55 | ui.setupUi(this); |
| 56 | ui.list->header()->hide(); |
| 57 | ui.list->setRootIsDecorated(false); |
| 58 | ui.list->setVerticalScrollMode(QAbstractItemView::ScrollPerItem); |
| 59 | |
| 60 | connect(ui.list->verticalScrollBar(), &QScrollBar::valueChanged, m_model, &QuickOpenModel::placeExpandingWidgets); |
| 61 | |
| 62 | ui.searchLine->setFocus(); |
| 63 | |
| 64 | ui.list->setItemDelegate(new QuickOpenDelegate(m_model, ui.list)); |
| 65 | |
| 66 | if (!listOnly) { |
| 67 | const QStringList allTypes = m_model->allTypes(); |
| 68 | const QStringList allScopes = m_model->allScopes(); |
| 69 | |
| 70 | auto* itemsMenu = new QMenu(this); |
| 71 | |
| 72 | for (const QString& type : allTypes) { |
| 73 | auto* action = new QAction(type, itemsMenu); |
| 74 | action->setCheckable(true); |
| 75 | action->setChecked(initialItems.isEmpty() || initialItems.contains(type)); |
| 76 | connect(action, &QAction::toggled, this, &QuickOpenWidget::updateProviders, Qt::QueuedConnection); |
| 77 | itemsMenu->addAction(action); |
| 78 | } |
| 79 | |
| 80 | ui.itemsButton->setMenu(itemsMenu); |
| 81 | |
| 82 | auto* scopesMenu = new QMenu(this); |
| 83 | |
| 84 | for (const QString& scope : allScopes) { |
| 85 | auto* action = new QAction(scope, scopesMenu); |
| 86 | action->setCheckable(true); |
| 87 | action->setChecked(initialScopes.isEmpty() || initialScopes.contains(scope)); |
| 88 | |
| 89 | connect(action, &QAction::toggled, this, &QuickOpenWidget::updateProviders, Qt::QueuedConnection); |
| 90 | scopesMenu->addAction(action); |
| 91 | } |
| 92 | |
| 93 | ui.scopesButton->setMenu(scopesMenu); |
| 94 | } else { |
| 95 | ui.list->setFocusPolicy(Qt::StrongFocus); |
| 96 | ui.scopesButton->hide(); |
| 97 | ui.itemsButton->hide(); |
| 98 | ui.label->hide(); |
| 99 | ui.label_2->hide(); |
| 100 | } |
| 101 | |
| 102 | showSearchField(!noSearchField); |
| 103 | |
| 104 | ui.okButton->hide(); |