Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support auto-selection in Fancy Menu #2001

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions plugin-fancymenu/lxqtfancymenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ void LXQtFancyMenu::settingsChanged()
bool categoriesAtRight = settings()->value(QStringLiteral("categoriesAtRight"), true).toBool();
mWindow->setCategoryPosition(categoriesAtRight ? LXQtFancyMenuCategoryPosition::Right : LXQtFancyMenuCategoryPosition::Left);

mWindow->setAutoSelection(settings()->value(QStringLiteral("autoSel"), false).toBool());
int delay = qBound(50, settings()->value(QStringLiteral("autoSelDelay"), 250).toInt(), 1000);
mWindow->setAutoSelectionDelay(delay);

realign();
}

Expand Down
12 changes: 11 additions & 1 deletion plugin-fancymenu/lxqtfancymenuconfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,14 @@ LXQtFancyMenuConfiguration::LXQtFancyMenuConfiguration(PluginSettings *settings,
connect(ui->shortcutEd->addMenuAction(tr("Reset")), &QAction::triggered, this, &LXQtFancyMenuConfiguration::shortcutReset);

connect(ui->customFontCB, &QAbstractButton::toggled, this, &LXQtFancyMenuConfiguration::customFontChanged);
connect(ui->customFontSizeSB, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &LXQtFancyMenuConfiguration::customFontSizeChanged);
connect(ui->customFontSizeSB, QOverload<int>::of(&QSpinBox::valueChanged), this, &LXQtFancyMenuConfiguration::customFontSizeChanged);

connect(ui->autoSelCB, &QAbstractButton::toggled, this, [this] (bool checked) {
this->settings().setValue(QStringLiteral("autoSel"), checked);
});
connect(ui->autoSelSB, QOverload<int>::of(&QSpinBox::valueChanged), this, [this] (int value) {
this->settings().setValue(QStringLiteral("autoSelDelay"), value);
});

connect(mShortcut, &GlobalKeyShortcut::Action::shortcutChanged, this, &LXQtFancyMenuConfiguration::globalShortcutChanged);

Expand Down Expand Up @@ -137,6 +144,9 @@ void LXQtFancyMenuConfiguration::loadSettings()
ui->customFontSizeSB->setValue(settings().value(QStringLiteral("customFontSize"), systemFont.pointSize()).toInt());
ui->filterClearCB->setChecked(settings().value(QStringLiteral("filterClear"), false).toBool());

ui->autoSelSB->setValue(settings().value(QStringLiteral("autoSelDelay"), 250).toInt());
ui->autoSelCB->setChecked(settings().value(QStringLiteral("autoSel"), false).toBool());

bool buttonsAtTop = settings().value(QStringLiteral("buttonsAtTop"), false).toBool();
int buttRowPosIdx = ui->buttRowPosCB->findData(buttonsAtTop ? LXQtFancyMenuButtonPosition::Top : LXQtFancyMenuButtonPosition::Bottom);
ui->buttRowPosCB->setCurrentIndex(buttRowPosIdx);
Expand Down
45 changes: 45 additions & 0 deletions plugin-fancymenu/lxqtfancymenuconfiguration.ui
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,35 @@
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="autoSelCB">
<property name="text">
<string>Auto-select after:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="autoSelSB">
<property name="enabled">
<bool>false</bool>
</property>
<property name="suffix">
<string> ms</string>
</property>
<property name="minimum">
<number>50</number>
</property>
<property name="maximum">
<number>1000</number>
</property>
<property name="singleStep">
<number>50</number>
</property>
<property name="value">
<number>250</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -293,5 +322,21 @@
</hint>
</hints>
</connection>
<connection>
<sender>autoSelCB</sender>
<signal>toggled(bool)</signal>
<receiver>autoSelSB</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>78</x>
<y>132</y>
</hint>
<hint type="destinationlabel">
<x>311</x>
<y>132</y>
</hint>
</hints>
</connection>
</connections>
</ui>
37 changes: 37 additions & 0 deletions plugin-fancymenu/lxqtfancymenuwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ LXQtFancyMenuWindow::LXQtFancyMenuWindow(QWidget *parent)
connect(&mSearchTimer, &QTimer::timeout, this, &LXQtFancyMenuWindow::doSearch);
mSearchTimer.setInterval(350); // typing speed (not very fast)

mAutoSelTimer.setSingleShot(true);
connect(&mAutoSelTimer, &QTimer::timeout, this, &LXQtFancyMenuWindow::autoSelect);

mSearchEdit = new QLineEdit;
mSearchEdit->setPlaceholderText(tr("Search..."));
mSearchEdit->setClearButtonEnabled(true);
Expand Down Expand Up @@ -218,6 +221,12 @@ LXQtFancyMenuWindow::LXQtFancyMenuWindow(QWidget *parent)
mAppView->setFocusProxy(mSearchEdit);
mCategoryView->setFocusProxy(mSearchEdit);

// for auto-selection
mAppView->viewport()->setMouseTracking(true);
mAppView->viewport()->installEventFilter(this);
mCategoryView->viewport()->setMouseTracking(true);
mCategoryView->viewport()->installEventFilter(this);

// Filter navigation keys
mSearchEdit->installEventFilter(this);
}
Expand Down Expand Up @@ -389,6 +398,14 @@ bool LXQtFancyMenuWindow::eventFilter(QObject *watched, QEvent *e)
return true;
}
}
else if (mAutoSel
&& (watched == mCategoryView->viewport() || watched == mAppView->viewport()))
{
if (e->type() == QEvent::MouseMove)
mAutoSelTimer.start();
else if (e->type() == QEvent::Leave)
mAutoSelTimer.stop();
}

return QWidget::eventFilter(watched, e);
}
Expand Down Expand Up @@ -627,3 +644,23 @@ void LXQtFancyMenuWindow::paintEvent(QPaintEvent *)
opt.initFrom(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}

void LXQtFancyMenuWindow::autoSelect()
{
QModelIndex idx = mCategoryView->indexAt(mCategoryView->viewport()->mapFromGlobal(QCursor::pos()));
if (idx.isValid())
{
if (!SeparatorDelegate::isSeparator(idx) && !mCategoryView->selectionModel()->isSelected(idx))
{
activateCategory(idx);
}
}
else
{
idx = mAppView->indexAt(mAppView->viewport()->mapFromGlobal(QCursor::pos()));
if (idx.isValid() && !mAppView->selectionModel()->isSelected(idx))
{
mAppView->selectionModel()->setCurrentIndex(idx, QItemSelectionModel::SelectCurrent);
}
}
}
13 changes: 13 additions & 0 deletions plugin-fancymenu/lxqtfancymenuwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ class LXQtFancyMenuWindow : public QWidget

void setCustomFont(const QFont& f);

void setAutoSelection(bool autoSel) {
mAutoSel = autoSel;
if (!mAutoSel)
mAutoSelTimer.stop();
}
void setAutoSelectionDelay(int delay) {
mAutoSelTimer.setInterval(delay);
}

signals:
void aboutToShow();
void aboutToHide();
Expand All @@ -103,6 +112,8 @@ private slots:

void onAppViewCustomMenu(const QPoint &p);

void autoSelect();

private:
void runCommandHelper(const QString& cmd);

Expand Down Expand Up @@ -131,6 +142,8 @@ private slots:
LXQtFancyMenuCategoriesModel *mCategoryModel;

QTimer mSearchTimer;
QTimer mAutoSelTimer;
bool mAutoSel = false;
bool mFilterClear = false;
};

Expand Down
Loading