Merge pull request #266 from olive-editor/actionsearch
implemented action search
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
#include "actionsearch.h"
|
||||
|
||||
#include <QVBoxLayout>
|
||||
#include <QKeyEvent>
|
||||
#include <QMenuBar>
|
||||
#include <QLabel>
|
||||
|
||||
#include "mainwindow.h"
|
||||
|
||||
ActionSearch::ActionSearch(QWidget *parent) :
|
||||
QDialog(parent)
|
||||
{
|
||||
setObjectName("ASDiag");
|
||||
setStyleSheet("#ASDiag{border: 2px solid #808080;}");
|
||||
|
||||
resize(parent->width()/3, parent->height()/3);
|
||||
|
||||
setWindowFlags(Qt::Popup);
|
||||
|
||||
QVBoxLayout* layout = new QVBoxLayout();
|
||||
|
||||
ActionSearchEntry* entry_field = new ActionSearchEntry();
|
||||
QFont entry_field_font = entry_field->font();
|
||||
entry_field_font.setPointSize(entry_field_font.pointSize()*2);
|
||||
entry_field->setFont(entry_field_font);
|
||||
entry_field->setPlaceholderText("Search for action...");
|
||||
connect(entry_field, SIGNAL(textChanged(const QString&)), this, SLOT(search_update(const QString &)));
|
||||
connect(entry_field, SIGNAL(returnPressed()), this, SLOT(perform_action()));
|
||||
connect(entry_field, SIGNAL(moveSelectionUp()), this, SLOT(move_selection_up()));
|
||||
connect(entry_field, SIGNAL(moveSelectionDown()), this, SLOT(move_selection_down()));
|
||||
layout->addWidget(entry_field);
|
||||
|
||||
list_widget = new ActionSearchList();
|
||||
QFont list_widget_font = list_widget->font();
|
||||
list_widget_font.setPointSize(list_widget_font.pointSize()*1.5);
|
||||
list_widget->setFont(list_widget_font);
|
||||
layout->addWidget(list_widget);
|
||||
connect(list_widget, SIGNAL(dbl_click()), this, SLOT(perform_action()));
|
||||
|
||||
setLayout(layout);
|
||||
|
||||
entry_field->setFocus();
|
||||
}
|
||||
|
||||
void ActionSearch::search_update(const QString &s, const QString &p, QMenu *parent) {
|
||||
if (parent == NULL) {
|
||||
list_widget->clear();
|
||||
QList<QAction*> menus = mainWindow->menuBar()->actions();
|
||||
for (int i=0;i<menus.size();i++) {
|
||||
QMenu* menu = menus.at(i)->menu();
|
||||
search_update(s, p, menu);
|
||||
}
|
||||
if (list_widget->count() > 0)
|
||||
list_widget->item(0)->setSelected(true);
|
||||
} else {
|
||||
QString menu_text;
|
||||
if (!p.isEmpty()) menu_text += p + " > ";
|
||||
menu_text += parent->title().replace("&", "");
|
||||
QList<QAction*> actions = parent->actions();
|
||||
for (int i=0;i<actions.size();i++) {
|
||||
QAction* a = actions.at(i);
|
||||
if (!a->isSeparator()) {
|
||||
if (a->menu() != NULL) {
|
||||
search_update(s, menu_text, a->menu());
|
||||
} else {
|
||||
QString comp = a->text().replace("&", "");
|
||||
if (comp.contains(s, Qt::CaseInsensitive)) {
|
||||
QListWidgetItem* item = new QListWidgetItem(comp + "\n(" + menu_text + ")");
|
||||
item->setData(Qt::UserRole+1, reinterpret_cast<quintptr>(a));
|
||||
list_widget->addItem(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ActionSearch::perform_action() {
|
||||
QList<QListWidgetItem*> selected_items = list_widget->selectedItems();
|
||||
if (list_widget->count() > 0 && selected_items.size() > 0) {
|
||||
QListWidgetItem* item = selected_items.at(0);
|
||||
QAction* a = reinterpret_cast<QAction*>(item->data(Qt::UserRole+1).value<quintptr>());
|
||||
a->trigger();
|
||||
}
|
||||
accept();
|
||||
}
|
||||
|
||||
void ActionSearch::move_selection_up() {
|
||||
int lim = list_widget->count();
|
||||
for (int i=1;i<lim;i++) {
|
||||
if (list_widget->item(i)->isSelected()) {
|
||||
// list_widget->item(i)->setSelected(false);
|
||||
list_widget->item(i-1)->setSelected(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ActionSearch::move_selection_down() {
|
||||
int lim = list_widget->count()-1;
|
||||
for (int i=0;i<lim;i++) {
|
||||
if (list_widget->item(i)->isSelected()) {
|
||||
// list_widget->item(i)->setSelected(false);
|
||||
list_widget->item(i+1)->setSelected(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ActionSearchEntry::keyPressEvent(QKeyEvent * event) {
|
||||
switch (event->key()) {
|
||||
case Qt::Key_Up:
|
||||
emit moveSelectionUp();
|
||||
break;
|
||||
case Qt::Key_Down:
|
||||
emit moveSelectionDown();
|
||||
break;
|
||||
default:
|
||||
QLineEdit::keyPressEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
void ActionSearchList::mouseDoubleClickEvent(QMouseEvent *event) {
|
||||
emit dbl_click();
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
#ifndef ACTIONSEARCH_H
|
||||
#define ACTIONSEARCH_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QLineEdit>
|
||||
#include <QListWidget>
|
||||
|
||||
class QListWidget;
|
||||
class QMenu;
|
||||
|
||||
class ActionSearchList : public QListWidget {
|
||||
Q_OBJECT
|
||||
protected:
|
||||
void mouseDoubleClickEvent(QMouseEvent *event);
|
||||
signals:
|
||||
void dbl_click();
|
||||
};
|
||||
|
||||
class ActionSearch : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ActionSearch(QWidget* parent = 0);
|
||||
private slots:
|
||||
void search_update(const QString& s, const QString &p = 0, QMenu *parent = NULL);
|
||||
void perform_action();
|
||||
void move_selection_up();
|
||||
void move_selection_down();
|
||||
private:
|
||||
ActionSearchList* list_widget;
|
||||
};
|
||||
|
||||
class ActionSearchEntry : public QLineEdit {
|
||||
Q_OBJECT
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent * event);
|
||||
signals:
|
||||
void moveSelectionUp();
|
||||
void moveSelectionDown();
|
||||
};
|
||||
|
||||
#endif // ACTIONSEARCH_H
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "dialogs/preferencesdialog.h"
|
||||
#include "dialogs/demonotice.h"
|
||||
#include "dialogs/speeddialog.h"
|
||||
#include "dialogs/actionsearch.h"
|
||||
|
||||
#include "playback/audio.h"
|
||||
#include "playback/playback.h"
|
||||
@@ -804,6 +805,10 @@ void MainWindow::setup_menus() {
|
||||
|
||||
QMenu* help_menu = menuBar->addMenu("&Help");
|
||||
|
||||
help_menu->addAction("A&ction Search", this, SLOT(show_action_search()));
|
||||
|
||||
help_menu->addSeparator();
|
||||
|
||||
help_menu->addAction("&About...", this, SLOT(show_about()));
|
||||
|
||||
QFile shortcut_path(get_config_path() + "/shortcuts");
|
||||
@@ -927,6 +932,11 @@ void MainWindow::load_with_launch() {
|
||||
open_project_worker(project_url, false);
|
||||
}
|
||||
|
||||
void MainWindow::show_action_search() {
|
||||
ActionSearch as(this);
|
||||
as.exec();
|
||||
}
|
||||
|
||||
void MainWindow::reset_layout() {
|
||||
setup_layout(true);
|
||||
}
|
||||
|
||||
@@ -117,6 +117,8 @@ private slots:
|
||||
|
||||
void load_with_launch();
|
||||
|
||||
void show_action_search();
|
||||
|
||||
private:
|
||||
void setup_layout(bool reset);
|
||||
bool can_close_project();
|
||||
|
||||
@@ -116,7 +116,8 @@ SOURCES += \
|
||||
ui/keyframedrawing.cpp \
|
||||
ui/clickablelabel.cpp \
|
||||
project/keyframe.cpp \
|
||||
ui/rectangleselect.cpp
|
||||
ui/rectangleselect.cpp \
|
||||
dialogs/actionsearch.cpp
|
||||
|
||||
HEADERS += \
|
||||
mainwindow.h \
|
||||
@@ -202,7 +203,8 @@ HEADERS += \
|
||||
ui/keyframedrawing.h \
|
||||
ui/clickablelabel.h \
|
||||
project/keyframe.h \
|
||||
ui/rectangleselect.h
|
||||
ui/rectangleselect.h \
|
||||
dialogs/actionsearch.h
|
||||
|
||||
FORMS +=
|
||||
|
||||
|
||||
Reference in New Issue
Block a user