More implementation of ShortcutsDialog and settings
This commit is contained in:
parent
eb5d4cc309
commit
f9711d414f
@ -1,5 +1,7 @@
|
||||
#include "shortcutsdialog.h"
|
||||
|
||||
#include <QtDebug>
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
@ -1,11 +1,42 @@
|
||||
#ifndef SHORTCUTSDIALOG_H
|
||||
#define SHORTCUTSDIALOG_H
|
||||
|
||||
#include <QDialogButtonBox>
|
||||
#include <QDialog>
|
||||
#include <QKeyEvent>
|
||||
#include <QMessageBox>
|
||||
#include <QSettings>
|
||||
|
||||
#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
|
@ -13,7 +13,7 @@
|
||||
<property name="windowTitle">
|
||||
<string>Configure Shortcuts</string>
|
||||
</property>
|
||||
<widget class="QTableWidget" name="tableWidget">
|
||||
<widget class="QTableWidget" name="table">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
@ -46,66 +46,21 @@
|
||||
<attribute name="horizontalHeaderStretchLastSection">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>Play</string>
|
||||
</property>
|
||||
</row>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>Pause</string>
|
||||
</property>
|
||||
</row>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>Play/Pause</string>
|
||||
</property>
|
||||
</row>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>Stop</string>
|
||||
</property>
|
||||
</row>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>Stop Playing After Current Track</string>
|
||||
</property>
|
||||
</row>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>Next Track</string>
|
||||
</property>
|
||||
</row>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>Previous Track</string>
|
||||
</property>
|
||||
</row>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>Increase Volume</string>
|
||||
</property>
|
||||
</row>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>Decrease Volume</string>
|
||||
</property>
|
||||
</row>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>Mute Volume</string>
|
||||
</property>
|
||||
</row>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>Seek Forwards</string>
|
||||
</property>
|
||||
</row>
|
||||
<row>
|
||||
<property name="text">
|
||||
<string>Seek Backwards</string>
|
||||
</property>
|
||||
</row>
|
||||
<attribute name="horizontalHeaderShowSortIndicator" stdset="0">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderStretchLastSection">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderCascadingSectionResizes">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderMinimumSectionSize">
|
||||
<number>24</number>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderDefaultSectionSize">
|
||||
<number>116</number>
|
||||
</attribute>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Shortcut</string>
|
||||
@ -117,19 +72,6 @@
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="button_defaults">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>330</y>
|
||||
<width>80</width>
|
||||
<height>31</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Defaults</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QGroupBox" name="shortcut_options">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
@ -154,17 +96,20 @@
|
||||
<x>10</x>
|
||||
<y>30</y>
|
||||
<width>91</width>
|
||||
<height>22</height>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&None</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QRadioButton" name="radio_default">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>110</x>
|
||||
<x>190</x>
|
||||
<y>30</y>
|
||||
<width>93</width>
|
||||
<height>22</height>
|
||||
@ -177,9 +122,9 @@
|
||||
<widget class="QRadioButton" name="radio_custom">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>220</x>
|
||||
<x>360</x>
|
||||
<y>30</y>
|
||||
<width>111</width>
|
||||
<width>81</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
@ -187,22 +132,6 @@
|
||||
<string>&Custom</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="button_custom">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>340</x>
|
||||
<y>30</y>
|
||||
<width>101</width>
|
||||
<height>26</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Non&e</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
@ -213,84 +142,36 @@
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Default key:</string>
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QDialogButtonBox" name="button_box">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>300</x>
|
||||
<x>15</x>
|
||||
<y>330</y>
|
||||
<width>166</width>
|
||||
<width>451</width>
|
||||
<height>32</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::Reset</set>
|
||||
</property>
|
||||
<property name="centerButtons">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>tableWidget</tabstop>
|
||||
<tabstop>table</tabstop>
|
||||
<tabstop>radio_none</tabstop>
|
||||
<tabstop>radio_default</tabstop>
|
||||
<tabstop>radio_custom</tabstop>
|
||||
<tabstop>button_custom</tabstop>
|
||||
<tabstop>button_defaults</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>radio_custom</sender>
|
||||
<signal>clicked(bool)</signal>
|
||||
<receiver>button_custom</receiver>
|
||||
<slot>setEnabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>299</x>
|
||||
<y>273</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>378</x>
|
||||
<y>286</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>radio_default</sender>
|
||||
<signal>clicked(bool)</signal>
|
||||
<receiver>button_custom</receiver>
|
||||
<slot>setDisabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>175</x>
|
||||
<y>281</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>418</x>
|
||||
<y>276</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>radio_none</sender>
|
||||
<signal>clicked(bool)</signal>
|
||||
<receiver>button_custom</receiver>
|
||||
<slot>setDisabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>79</x>
|
||||
<y>276</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>431</x>
|
||||
<y>290</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<buttongroups>
|
||||
<buttongroup name="buttonGroup"/>
|
||||
</buttongroups>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
Loading…
x
Reference in New Issue
Block a user