diff --git a/src/shortcutsdialog.cpp b/src/shortcutsdialog.cpp index e05e6857c..dfb9b9371 100644 --- a/src/shortcutsdialog.cpp +++ b/src/shortcutsdialog.cpp @@ -1,5 +1,7 @@ #include "shortcutsdialog.h" +#include + const char* ShortcutsDialog::kSettingsGroup = "Shortcuts"; ShortcutsDialog::ShortcutsDialog(QWidget* parent) : QDialog(parent) { @@ -7,18 +9,77 @@ ShortcutsDialog::ShortcutsDialog(QWidget* parent) ui_.shortcut_options->setEnabled(false); // Load settings - // Check if settings exist first, if not create them + + int i = 0; + QStringList rowLabels; + QString str; + + keys_ << "play" << "pause" << "play_pause" << "stop" << "stop_after"; + keys_ << "next_track" << "prev_track" << "inc_volume" << "dec_volume"; + keys_ << "mute" << "seek_forwards" << "seek_backwards"; + + settings_.beginGroup(kSettingsGroup); + foreach(str, keys_) { + if (settings_.contains(str)) { + if (QString::compare(str, "play_pause") == 0) { + rowLabels << SD_ROW_PLAY_PAUSE; + } + else if (QString::compare(str, "stop_after") == 0) { + rowLabels << SD_ROW_STOP_AFTER; + } + else if (QString::compare(str, "next_track") == 0) { + rowLabels << SD_ROW_NEXT_TRACK; + } + else if (QString::compare(str, "prev_track") == 0) { + rowLabels << SD_ROW_PREV_TRACK; + } + else if (QString::compare(str, "inc_volume") == 0) { + rowLabels << SD_ROW_INC_VOLUME; + } + else if (QString::compare(str, "dec_volume") == 0) { + rowLabels << SD_ROW_DEC_VOLUME; + } + else if (QString::compare(str, "seek_forwards") == 0) { + rowLabels << SD_ROW_SEEK_FORWARDS; + } + else if (QString::compare(str, "seek_backwards") == 0) { + rowLabels << SD_ROW_SEEK_BACKWARDS; + } + else { + // Uppercase first letter + str[0] = str[0].toUpper(); + rowLabels << str; + } + } + else { + settings_.setValue(str, ""); + } + } + + ui_.table->setRowCount(rowLabels.length()); + ui_.table->setVerticalHeaderLabels(rowLabels); + + + // TODO: QKeySequence::toString() to load/save values - connect(ui_.button_defaults, SIGNAL(clicked()), SLOT(DefaultShortcuts())); + //connect(ui_.button_box->button(QDialogButtonBox::Reset), SIGNAL(clicked()), SLOT(ResetShortcuts())); connect(ui_.button_box, SIGNAL(accepted()), SLOT(SaveShortcuts())); connect(ui_.button_box, SIGNAL(rejected()), SLOT(CancelEvent())); + connect(ui_.table, SIGNAL(cellClicked(int, int)), SLOT(CellClickedEvent())); + connect(ui_.radio_default, SIGNAL(clicked()), SLOT(DefaultRadioClickedEvent())); } /** * Reset shortcuts to defaults (none for now). */ -void ShortcutsDialog::DefaultShortcuts() { +void ShortcutsDialog::ResetShortcuts() { + int ret = QMessageBox::warning(this, tr("Warning"), + tr("You are about to reset to global shortcuts default values. Are you sure you want to continue?"), + QMessageBox::Yes, + QMessageBox::No); + if (ret != QMessageBox::No) { + } } void ShortcutsDialog::SaveShortcuts() { @@ -30,4 +91,79 @@ void ShortcutsDialog::SaveShortcuts() { */ void ShortcutsDialog::CancelEvent() { close(); -} \ No newline at end of file +} + +void ShortcutsDialog::DefaultText(QString str) { + if (QString::compare(str, SD_ROW_PLAY) == 0) { + currentDefault_ = tr(SD_DEFAULT_PLAY); + ui_.label->setText(tr("Default: %1").arg(SD_DEFAULT_PLAY)); + } + else if (QString::compare(str, SD_ROW_PLAY_PAUSE) == 0) { + currentDefault_ = tr(SD_DEFAULT_PLAY_PAUSE); + ui_.label->setText(tr("Default: %1").arg(SD_DEFAULT_PLAY_PAUSE)); + } + else if (QString::compare(str, SD_ROW_STOP) == 0) { + currentDefault_ = tr(SD_DEFAULT_STOP); + ui_.label->setText(tr("Default: %1").arg(SD_DEFAULT_STOP)); + } + else if (QString::compare(str, SD_ROW_STOP_AFTER) == 0) { + currentDefault_ = tr(SD_DEFAULT_STOP_AFTER); + ui_.label->setText(tr("Default: %1").arg(SD_DEFAULT_STOP_AFTER)); + } + else if (QString::compare(str, SD_ROW_NEXT_TRACK) == 0) { + currentDefault_ = tr(SD_DEFAULT_NEXT_TRACK); + ui_.label->setText(tr("Default: %1").arg(SD_DEFAULT_NEXT_TRACK)); + } + else if (QString::compare(str, SD_ROW_PREV_TRACK) == 0) { + currentDefault_ = tr(SD_DEFAULT_PREV_TRACK); + ui_.label->setText(tr("Default: %1").arg(SD_DEFAULT_PREV_TRACK)); + } + else if (QString::compare(str, SD_ROW_INC_VOLUME) == 0) { + currentDefault_ = tr(SD_DEFAULT_INC_VOLUME); + ui_.label->setText(tr("Default: %1").arg(SD_DEFAULT_INC_VOLUME)); + } + else if (QString::compare(str, SD_ROW_DEC_VOLUME) == 0) { + currentDefault_ = tr(SD_DEFAULT_DEC_VOLUME); + ui_.label->setText(tr("Default: %1").arg(SD_DEFAULT_DEC_VOLUME)); + } + else if (QString::compare(str, SD_ROW_MUTE) == 0) { + currentDefault_ = tr(SD_DEFAULT_MUTE_VOLUME); + ui_.label->setText(tr("Default: %1").arg(SD_DEFAULT_MUTE_VOLUME)); + } + else if (QString::compare(str, SD_ROW_SEEK_FORWARDS) == 0) { + currentDefault_ = tr(SD_DEFAULT_SEEK_FORWARDS); + ui_.label->setText(tr("Default: %1").arg(SD_DEFAULT_SEEK_FORWARDS)); + } + else if (QString::compare(str, SD_ROW_SEEK_BACKWARDS) == 0) { + currentDefault_ = tr(SD_DEFAULT_SEEK_BACKWARDS); + ui_.label->setText(tr("Default: %1").arg(SD_DEFAULT_SEEK_BACKWARDS)); + } + else { + currentDefault_ = tr(""); + ui_.label->setText(tr("Default: None")); + } +} + +void ShortcutsDialog::CellClickedEvent() { + ui_.shortcut_options->setEnabled(true); + DefaultText(ui_.table->verticalHeaderItem(ui_.table->currentRow())->text()); + + currentKey_ = keys_.at(ui_.table->currentRow()); + + //TODO: Read setting and set correct radio button + + /* + Where should this go? + If uncommented, and a cell is clicked, segfault + QKeyEvent* event; + GetShortcut(event); + */ +} + +void ShortcutsDialog::DefaultRadioClickedEvent() { + settings_.setValue(currentKey_, currentDefault_); +} + +void ShortcutsDialog::GetShortcut(QKeyEvent* event) { + qDebug() << event->text(); +} diff --git a/src/shortcutsdialog.h b/src/shortcutsdialog.h index 6eccdc6c0..4556ba797 100644 --- a/src/shortcutsdialog.h +++ b/src/shortcutsdialog.h @@ -1,11 +1,42 @@ #ifndef SHORTCUTSDIALOG_H #define SHORTCUTSDIALOG_H +#include #include +#include +#include #include #include "ui_shortcutsdialog.h" +// Proper row names +#define SD_ROW_PLAY "Play" +#define SD_ROW_PAUSE "Pause" +#define SD_ROW_PLAY_PAUSE "Play/Pause" +#define SD_ROW_STOP "Stop" +#define SD_ROW_STOP_AFTER "Stop Playing After Current Track" +#define SD_ROW_NEXT_TRACK "Next Track" +#define SD_ROW_PREV_TRACK "Previous Track" +#define SD_ROW_INC_VOLUME "Increase Volume" +#define SD_ROW_DEC_VOLUME "Decrease Volume" +#define SD_ROW_MUTE "Mute" +#define SD_ROW_SEEK_FORWARDS "Seek Forwards" +#define SD_ROW_SEEK_BACKWARDS "Seek Backwards" + +// Defaults from Amarok 1.4 +// Meta = Windows key or Apple key +#define SD_DEFAULT_PLAY "Meta+X" +#define SD_DEFAULT_PLAY_PAUSE "Meta+C" +#define SD_DEFAULT_STOP "Meta+V" +#define SD_DEFAULT_STOP_AFTER "Meta+Ctrl+V" +#define SD_DEFAULT_NEXT_TRACK "Meta+B" +#define SD_DEFAULT_PREV_TRACK "Meta+Z" +#define SD_DEFAULT_INC_VOLUME "Meta+KP_Add" +#define SD_DEFAULT_DEC_VOLUME "Meta+KP_Subtract" +#define SD_DEFAULT_MUTE_VOLUME "Meta+M" +#define SD_DEFAULT_SEEK_FORWARDS "Meta+Shift+KP_Add" +#define SD_DEFAULT_SEEK_BACKWARDS "Meta+Shift+KP_Subtract" + class ShortcutsDialog : public QDialog { Q_OBJECT @@ -13,15 +44,22 @@ class ShortcutsDialog : public QDialog { ShortcutsDialog(QWidget* parent = 0); private slots: - void DefaultShortcuts(); + void ResetShortcuts(); void SaveShortcuts(); void CancelEvent(); - + void GetShortcut(QKeyEvent* event); + void CellClickedEvent(); + void DefaultText(QString str); + void DefaultRadioClickedEvent(); private: Ui::ShortcutsDialog ui_; QSettings settings_; static const char* kSettingsGroup; + QTableWidgetItem *item; // current cell + QString currentDefault_; + QString currentKey_; + QStringList keys_; }; #endif // SHORTCUTSDIALOG_H \ No newline at end of file diff --git a/src/shortcutsdialog.ui b/src/shortcutsdialog.ui index bf1cbd568..fdc408e8d 100644 --- a/src/shortcutsdialog.ui +++ b/src/shortcutsdialog.ui @@ -13,7 +13,7 @@ Configure Shortcuts - + 10 @@ -46,66 +46,21 @@ true - - - Play - - - - - Pause - - - - - Play/Pause - - - - - Stop - - - - - Stop Playing After Current Track - - - - - Next Track - - - - - Previous Track - - - - - Increase Volume - - - - - Decrease Volume - - - - - Mute Volume - - - - - Seek Forwards - - - - - Seek Backwards - - + + false + + + true + + + false + + + 24 + + + 116 + Shortcut @@ -117,19 +72,6 @@ - - - - 10 - 330 - 80 - 31 - - - - &Defaults - - true @@ -154,17 +96,20 @@ 10 30 91 - 22 + 21 &None + + true + - 110 + 190 30 93 22 @@ -177,9 +122,9 @@ - 220 + 360 30 - 111 + 81 22 @@ -187,22 +132,6 @@ &Custom - - - false - - - - 340 - 30 - 101 - 26 - - - - Non&e - - @@ -213,84 +142,36 @@ - Default key: + - 300 + 15 330 - 166 + 451 32 + + Qt::Horizontal + - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::Reset + + + false - tableWidget + table radio_none radio_default radio_custom - button_custom - button_defaults - - - radio_custom - clicked(bool) - button_custom - setEnabled(bool) - - - 299 - 273 - - - 378 - 286 - - - - - radio_default - clicked(bool) - button_custom - setDisabled(bool) - - - 175 - 281 - - - 418 - 276 - - - - - radio_none - clicked(bool) - button_custom - setDisabled(bool) - - - 79 - 276 - - - 431 - 290 - - - - - - - +