Merge pull request #251 from olive-editor/keysaves
added saving keyboard shortcuts
This commit is contained in:
@@ -14,6 +14,11 @@
|
|||||||
#include <QDialogButtonBox>
|
#include <QDialogButtonBox>
|
||||||
#include <QTreeWidget>
|
#include <QTreeWidget>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QTreeWidgetItem>
|
||||||
|
#include <QList>
|
||||||
|
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
KeySequenceEditor::KeySequenceEditor(QWidget* parent, QAction* a)
|
KeySequenceEditor::KeySequenceEditor(QWidget* parent, QAction* a)
|
||||||
: QKeySequenceEdit(parent), action(a) {
|
: QKeySequenceEdit(parent), action(a) {
|
||||||
@@ -53,6 +58,7 @@ void PreferencesDialog::setup_kbd_shortcut_worker(QMenu* menu, QTreeWidgetItem*
|
|||||||
if (a->menu() != NULL) {
|
if (a->menu() != NULL) {
|
||||||
setup_kbd_shortcut_worker(a->menu(), item);
|
setup_kbd_shortcut_worker(a->menu(), item);
|
||||||
} else {
|
} else {
|
||||||
|
item->setData(0, Qt::UserRole + 1, reinterpret_cast<quintptr>(a));
|
||||||
key_shortcut_items.append(item);
|
key_shortcut_items.append(item);
|
||||||
key_shortcut_actions.append(a);
|
key_shortcut_actions.append(a);
|
||||||
}
|
}
|
||||||
@@ -94,6 +100,19 @@ void PreferencesDialog::save() {
|
|||||||
accept();
|
accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PreferencesDialog::reset_default_shortcut() {
|
||||||
|
QList<QTreeWidgetItem*> items = keyboard_tree->selectedItems();
|
||||||
|
for (int i=0;i<items.size();i++) {
|
||||||
|
QTreeWidgetItem* item = keyboard_tree->selectedItems().at(i);
|
||||||
|
const QVariant& data = item->data(0, Qt::UserRole + 1);
|
||||||
|
if (!data.isNull()) {
|
||||||
|
QAction* a = reinterpret_cast<QAction*>(data.value<quintptr>());
|
||||||
|
QKeySequence ks(a->property("default").toString());
|
||||||
|
static_cast<QKeySequenceEdit*>(keyboard_tree->itemWidget(item, 1))->setKeySequence(ks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void PreferencesDialog::setup_ui() {
|
void PreferencesDialog::setup_ui() {
|
||||||
QVBoxLayout* verticalLayout = new QVBoxLayout(this);
|
QVBoxLayout* verticalLayout = new QVBoxLayout(this);
|
||||||
QTabWidget* tabWidget = new QTabWidget(this);
|
QTabWidget* tabWidget = new QTabWidget(this);
|
||||||
@@ -136,17 +155,27 @@ void PreferencesDialog::setup_ui() {
|
|||||||
verticalLayout_2->addWidget(groupBox);
|
verticalLayout_2->addWidget(groupBox);
|
||||||
|
|
||||||
tabWidget->addTab(tab_4, "Playback");
|
tabWidget->addTab(tab_4, "Playback");
|
||||||
QWidget* tab_3 = new QWidget();
|
|
||||||
QHBoxLayout* horizontalLayout = new QHBoxLayout(tab_3);
|
QWidget* shortcut_tab = new QWidget();
|
||||||
horizontalLayout->setContentsMargins(0, 0, 0, 0);
|
|
||||||
|
QVBoxLayout* shortcut_layout = new QVBoxLayout(shortcut_tab);
|
||||||
|
|
||||||
keyboard_tree = new QTreeWidget();
|
keyboard_tree = new QTreeWidget();
|
||||||
QTreeWidgetItem* tree_header = keyboard_tree->headerItem();
|
QTreeWidgetItem* tree_header = keyboard_tree->headerItem();
|
||||||
tree_header->setText(0, "Action");
|
tree_header->setText(0, "Action");
|
||||||
tree_header->setText(1, "Shortcut");
|
tree_header->setText(1, "Shortcut");
|
||||||
horizontalLayout->addWidget(keyboard_tree);
|
shortcut_layout->addWidget(keyboard_tree);
|
||||||
|
|
||||||
tabWidget->addTab(tab_3, "Keyboard");
|
QHBoxLayout* reset_shortcut_layout = new QHBoxLayout();
|
||||||
|
reset_shortcut_layout->addStretch();
|
||||||
|
|
||||||
|
reset_shortcut_button = new QPushButton("Reset to Default");
|
||||||
|
reset_shortcut_layout->addWidget(reset_shortcut_button);
|
||||||
|
connect(reset_shortcut_button, SIGNAL(clicked(bool)), this, SLOT(reset_default_shortcut()));
|
||||||
|
|
||||||
|
shortcut_layout->addLayout(reset_shortcut_layout);
|
||||||
|
|
||||||
|
tabWidget->addTab(shortcut_tab, "Keyboard");
|
||||||
|
|
||||||
verticalLayout->addWidget(tabWidget);
|
verticalLayout->addWidget(tabWidget);
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ public:
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void save();
|
void save();
|
||||||
|
void reset_default_shortcut();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setup_ui();
|
void setup_ui();
|
||||||
@@ -46,6 +47,8 @@ private:
|
|||||||
QVector<QAction*> key_shortcut_actions;
|
QVector<QAction*> key_shortcut_actions;
|
||||||
QVector<QTreeWidgetItem*> key_shortcut_items;
|
QVector<QTreeWidgetItem*> key_shortcut_items;
|
||||||
QVector<KeySequenceEditor*> key_shortcut_fields;
|
QVector<KeySequenceEditor*> key_shortcut_fields;
|
||||||
|
|
||||||
|
QPushButton* reset_shortcut_button;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PREFERENCESDIALOG_H
|
#endif // PREFERENCESDIALOG_H
|
||||||
|
|||||||
@@ -443,6 +443,47 @@ bool MainWindow::can_close_project() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void kbd_shortcut_processor(QByteArray& file, QMenu* menu, bool save) {
|
||||||
|
QList<QAction*> actions = menu->actions();
|
||||||
|
for (int i=0;i<actions.size();i++) {
|
||||||
|
QAction* a = actions.at(i);
|
||||||
|
if (a->menu() != NULL) {
|
||||||
|
kbd_shortcut_processor(file, a->menu(), save);
|
||||||
|
} else if (!a->isSeparator()) {
|
||||||
|
if (save) {
|
||||||
|
// saving custom shortcuts
|
||||||
|
if (!a->property("default").isNull()) {
|
||||||
|
QKeySequence defks(a->property("default").toString());
|
||||||
|
if (a->shortcut() != defks) {
|
||||||
|
// custom shortcut
|
||||||
|
if (!file.isEmpty()) file.append('\n');
|
||||||
|
file.append(a->text().replace("&", ""));
|
||||||
|
file.append('\t');
|
||||||
|
file.append(a->shortcut().toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// loading custom shortcuts
|
||||||
|
a->setProperty("default", a->shortcut().toString());
|
||||||
|
QString comp_str = a->text().replace("&", "");
|
||||||
|
int shortcut_index = file.indexOf(comp_str);
|
||||||
|
if (shortcut_index == 0 || (shortcut_index > 0 && file.at(shortcut_index-1) == '\n')) {
|
||||||
|
shortcut_index += comp_str.size() + 1;
|
||||||
|
QString shortcut;
|
||||||
|
while (shortcut_index < file.size() && file.at(shortcut_index) != '\n') {
|
||||||
|
shortcut.append(file.at(shortcut_index));
|
||||||
|
shortcut_index++;
|
||||||
|
}
|
||||||
|
QKeySequence ks(shortcut);
|
||||||
|
if (!ks.isEmpty()) {
|
||||||
|
a->setShortcut(ks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::setup_menus() {
|
void MainWindow::setup_menus() {
|
||||||
QMenuBar* menuBar = new QMenuBar(this);
|
QMenuBar* menuBar = new QMenuBar(this);
|
||||||
setMenuBar(menuBar);
|
setMenuBar(menuBar);
|
||||||
@@ -756,6 +797,16 @@ void MainWindow::setup_menus() {
|
|||||||
QMenu* help_menu = menuBar->addMenu("&Help");
|
QMenu* help_menu = menuBar->addMenu("&Help");
|
||||||
|
|
||||||
help_menu->addAction("&About...", this, SLOT(show_about()));
|
help_menu->addAction("&About...", this, SLOT(show_about()));
|
||||||
|
|
||||||
|
QFile shortcut_path(get_config_path() + "/shortcuts");
|
||||||
|
if (shortcut_path.exists() && shortcut_path.open(QFile::ReadOnly)) {
|
||||||
|
QList<QAction*> menus = menuBar->actions();
|
||||||
|
QByteArray shortcut_bytes = shortcut_path.readAll();
|
||||||
|
for (int i=0;i<menus.size();i++) {
|
||||||
|
QMenu* menu = menus.at(i)->menu();
|
||||||
|
kbd_shortcut_processor(shortcut_bytes, menu, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::set_bool_action_checked(QAction *a) {
|
void MainWindow::set_bool_action_checked(QAction *a) {
|
||||||
@@ -807,6 +858,21 @@ void MainWindow::closeEvent(QCloseEvent *e) {
|
|||||||
} else {
|
} else {
|
||||||
dout << "[ERROR] Failed to save layout";
|
dout << "[ERROR] Failed to save layout";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// save main menu actions
|
||||||
|
QList<QAction*> menus = menuBar()->actions();
|
||||||
|
QByteArray shortcut_file;
|
||||||
|
for (int i=0;i<menus.size();i++) {
|
||||||
|
QMenu* menu = menus.at(i)->menu();
|
||||||
|
kbd_shortcut_processor(shortcut_file, menu, true);
|
||||||
|
}
|
||||||
|
QFile shortcut_file_io(config_dir + "/shortcuts");
|
||||||
|
if (shortcut_file_io.open(QFile::WriteOnly)) {
|
||||||
|
shortcut_file_io.write(shortcut_file);
|
||||||
|
shortcut_file_io.close();
|
||||||
|
} else {
|
||||||
|
dout << "[ERROR] Failed to save shortcut file";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stop_audio();
|
stop_audio();
|
||||||
|
|||||||
+3
-4
@@ -506,9 +506,8 @@ void Viewer::setup_ui() {
|
|||||||
playback_control_layout->addWidget(btnRewind);
|
playback_control_layout->addWidget(btnRewind);
|
||||||
|
|
||||||
btnPlay = new QPushButton(playback_controls);
|
btnPlay = new QPushButton(playback_controls);
|
||||||
QIcon playIcon;
|
playIcon.addFile(QStringLiteral(":/icons/play.png"), QSize(), QIcon::Normal, QIcon::On);
|
||||||
playIcon.addFile(QStringLiteral(":/icons/play.png"), QSize(), QIcon::Normal, QIcon::Off);
|
playIcon.addFile(QStringLiteral(":/icons/play-disabled.png"), QSize(), QIcon::Disabled, QIcon::On);
|
||||||
playIcon.addFile(QStringLiteral(":/icons/play-disabled.png"), QSize(), QIcon::Disabled, QIcon::Off);
|
|
||||||
btnPlay->setIcon(playIcon);
|
btnPlay->setIcon(playIcon);
|
||||||
connect(btnPlay, SIGNAL(clicked(bool)), this, SLOT(toggle_play()));
|
connect(btnPlay, SIGNAL(clicked(bool)), this, SLOT(toggle_play()));
|
||||||
playback_control_layout->addWidget(btnPlay);
|
playback_control_layout->addWidget(btnPlay);
|
||||||
@@ -725,5 +724,5 @@ void Viewer::set_sequence(bool main, Sequence *s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Viewer::set_playpause_icon(bool play) {
|
void Viewer::set_playpause_icon(bool play) {
|
||||||
btnPlay->setIcon(QIcon((play) ? ":/icons/play.png" : ":/icons/pause.png"));
|
btnPlay->setIcon(play ? playIcon : QIcon(":/icons/pause.png"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <QDockWidget>
|
#include <QDockWidget>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QIcon>
|
||||||
|
|
||||||
class Timeline;
|
class Timeline;
|
||||||
class ViewerWidget;
|
class ViewerWidget;
|
||||||
@@ -93,6 +94,8 @@ private:
|
|||||||
void set_zoom_value(double d);
|
void set_zoom_value(double d);
|
||||||
void set_sb_max();
|
void set_sb_max();
|
||||||
|
|
||||||
|
QIcon playIcon;
|
||||||
|
|
||||||
void setup_ui();
|
void setup_ui();
|
||||||
|
|
||||||
TimelineHeader* headers;
|
TimelineHeader* headers;
|
||||||
|
|||||||
Reference in New Issue
Block a user