diff --git a/dialogs/actionsearch.cpp b/dialogs/actionsearch.cpp new file mode 100644 index 000000000..c1eafd6c2 --- /dev/null +++ b/dialogs/actionsearch.cpp @@ -0,0 +1,125 @@ +#include "actionsearch.h" + +#include +#include +#include +#include + +#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 menus = mainWindow->menuBar()->actions(); + for (int i=0;imenu(); + 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 actions = parent->actions(); + for (int i=0;iisSeparator()) { + 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(a)); + list_widget->addItem(item); + } + } + } + } + } +} + +void ActionSearch::perform_action() { + QList selected_items = list_widget->selectedItems(); + if (list_widget->count() > 0 && selected_items.size() > 0) { + QListWidgetItem* item = selected_items.at(0); + QAction* a = reinterpret_cast(item->data(Qt::UserRole+1).value()); + a->trigger(); + } + accept(); +} + +void ActionSearch::move_selection_up() { + int lim = list_widget->count(); + for (int i=1;iitem(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;iitem(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(); +} diff --git a/dialogs/actionsearch.h b/dialogs/actionsearch.h new file mode 100644 index 000000000..72d7d7153 --- /dev/null +++ b/dialogs/actionsearch.h @@ -0,0 +1,42 @@ +#ifndef ACTIONSEARCH_H +#define ACTIONSEARCH_H + +#include +#include +#include + +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 diff --git a/mainwindow.cpp b/mainwindow.cpp index cfde02bd2..e3f14fb0d 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -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); } diff --git a/mainwindow.h b/mainwindow.h index 650809298..fc578db78 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -117,6 +117,8 @@ private slots: void load_with_launch(); + void show_action_search(); + private: void setup_layout(bool reset); bool can_close_project(); diff --git a/olive.pro b/olive.pro index 48ed5688a..28e268fbe 100644 --- a/olive.pro +++ b/olive.pro @@ -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 +=