Skip to content
This repository has been archived by the owner on Jul 14, 2019. It is now read-only.
/ Miam-Player Public archive

Commit

Permalink
Fix shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
MBach committed Feb 13, 2017
1 parent e32969c commit 8bfc997
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 68 deletions.
1 change: 0 additions & 1 deletion src/core/mediaplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ void MediaPlayer::setVolume(qreal v)
} else {
_localPlayer->audio()->setVolume(v);
}
qDebug() << Q_FUNC_INFO << "emit volumeChanged(" << v << ")";
emit volumeChanged(v);
}

Expand Down
1 change: 1 addition & 0 deletions src/core/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ void Settings::initShortcuts()
shortcuts.insert("moveTracksDown", "Maj+Down");
shortcuts.insert("removeSelectedTracks", "Delete");
setValue("shortcuts", shortcuts);
setValue("defaultShortcuts", shortcuts);
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/core/settingsprivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,7 @@ void SettingsPrivate::setShortcut(const QString &objectName, const QKeySequence

QKeySequence SettingsPrivate::shortcut(const QString &objectName) const
{
QMap<QString, QVariant> shortcuts = value("shortcuts").toMap();
return QKeySequence(shortcuts.value(objectName).toString());
return QKeySequence(value("shortcuts").toMap().value(objectName).toString());
}

int SettingsPrivate::volumeBarHideAfter() const
Expand Down
6 changes: 3 additions & 3 deletions src/player/dialogs/customizeoptionsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,10 @@ void CustomizeOptionsDialog::initPlugins()
void CustomizeOptionsDialog::initShortcuts()
{
Settings *settings = Settings::instance();
QMap<QKeySequenceEdit *, QKeySequence> *defaultShortcuts = new QMap<QKeySequenceEdit *, QKeySequence>();
QMap<QString, QVariant> shortcutMap = settings->shortcuts();
QMap<QString, QVariant> defaultShortcutMap = settings->value("defaultShortcuts").toMap();
for (QKeySequenceEdit *shortcut : shortcutsToolBox->findChildren<QKeySequenceEdit*>()) {
QKeySequence sequence = shortcut->keySequence();
defaultShortcuts->insert(shortcut, sequence);

// Init shortcuts: override default shortcuts with existing ones in settings
QString shortCutName = shortcut->objectName();
Expand All @@ -320,7 +319,8 @@ void CustomizeOptionsDialog::initShortcuts()
emit shortcut->editingFinished();
});
connect(reset, &QPushButton::clicked, this, [=]() {
shortcut->setKeySequence(defaultShortcuts->value(shortcut));
qDebug() << Q_FUNC_INFO << shortcut->objectName() << QKeySequence(defaultShortcutMap.value(shortcut->objectName()).toString());
shortcut->setKeySequence(QKeySequence(defaultShortcutMap.value(shortcut->objectName()).toString()));
emit shortcut->editingFinished();
});
}
Expand Down
75 changes: 40 additions & 35 deletions src/player/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,14 @@ void MainWindow::activateLastView()
// Find the last active view and connect database to it
SettingsPrivate *settingsPrivate = SettingsPrivate::instance();
QString actionViewName = settingsPrivate->value("lastActiveView", "actionViewPlaylists").toString();
QAction *defaultActionView = nullptr;
for (QAction *actionView : menuView->actions()) {
if (actionView->objectName() == actionViewName) {
defaultActionView = actionView;
actionView->trigger();
break;
QAction *action = this->findChild<QAction*>(actionViewName);
if (action) {
if (action->isCheckable()) {
action->setChecked(true);
}
}
// If no action was triggered, despite an entry in settings, it means some plugin was activated once, but now we couldn't find it
if (defaultActionView == nullptr) {
this->activateView(action);
} else {
// If no action was triggered, despite an entry in settings, it means some plugin was activated once, but now we couldn't find it
actionViewPlaylists->trigger();
}
}
Expand Down Expand Up @@ -153,22 +151,7 @@ void MainWindow::dispatchDrop(QDropEvent *event)

void MainWindow::init()
{
// Init shortcuts
Settings *settings = Settings::instance();
QMapIterator<QString, QVariant> it(settings->shortcuts());

while (it.hasNext()) {
it.next();

QShortcut *s = new QShortcut(this);
s->setObjectName("action" + it.key().left(1).toUpper() + it.key().mid(1));
s->setKey(it.value().value<QKeySequence>());
}

if (menuBar()->isVisible()) {
this->toggleMenuBar(true);
}

this->toggleMenuBar(SettingsPrivate::instance()->value("isMenuHidden").toBool());
this->setupActions();
}

Expand Down Expand Up @@ -367,14 +350,14 @@ bool MainWindow::event(QEvent *e)
if (keyEvent->key() == Qt::Key_Alt) {
qDebug() << Q_FUNC_INFO << "Alt was pressed";
this->setProperty("altKey", true);
this->toggleShortcutsOnMenuBar(true);
this->toggleMenuBar(false);
// Reactivate shortcuts on the menuBar

QMapIterator<QString, QVariant> it(Settings::instance()->shortcuts());
/*QMapIterator<QString, QVariant> it(Settings::instance()->shortcuts());
while (it.hasNext()) {
it.next();
this->bindShortcut(it.key(), it.value().value<QKeySequence>());
}
}*/

} else {
this->setProperty("altKey", false);
Expand Down Expand Up @@ -428,11 +411,6 @@ void MainWindow::initQuickStart()
this->resize(400, 500);
}

void MainWindow::toggleShortcutsOnMenuBar(bool enabled)
{
qDebug() << Q_FUNC_INFO << enabled;
}

void MainWindow::createCustomizeOptionsDialog()
{
CustomizeOptionsDialog *dialog = new CustomizeOptionsDialog(_pluginManager, this);
Expand Down Expand Up @@ -640,6 +618,7 @@ void MainWindow::activateView(QAction *menuAction)
actionPlaybackCurrentItemInLoop->setEnabled(b);
if (b) {
AbstractViewPlaylists *viewPlaylists = static_cast<AbstractViewPlaylists*>(_currentView);
qDebug() << Q_FUNC_INFO;
connect(actionOpenFiles, &QAction::triggered, viewPlaylists, &AbstractViewPlaylists::openFiles);
connect(actionOpenFolder, &QAction::triggered, viewPlaylists, &AbstractViewPlaylists::openFolderPopup);
connect(actionAddPlaylist, &QAction::triggered, viewPlaylists, &AbstractViewPlaylists::addPlaylist);
Expand Down Expand Up @@ -808,7 +787,33 @@ void MainWindow::syncLibrary(const QStringList &oldLocations, const QStringList

void MainWindow::toggleMenuBar(bool checked)
{
auto settings = Settings::instance();
auto settingsPrivate = SettingsPrivate::instance();
settingsPrivate->setValue("isMenuHidden", checked);
menuBar()->setVisible(!checked);
SettingsPrivate::instance()->setValue("isMenuHidden", checked);
this->toggleShortcutsOnMenuBar(!checked);

// Attach shortcuts to visible menu or "invisible" handler
qDeleteAll(_menuShortcuts);
_menuShortcuts.clear();

QMapIterator<QString, QVariant> it(settings->shortcuts());
while (it.hasNext()) {
it.next();

QKeySequence sequence = settingsPrivate->shortcut(it.key());
QString actionName = "action" + it.key().left(1).toUpper() + it.key().mid(1);
QAction *action = this->findChild<QAction*>(actionName);
if (!action) {
continue;
}
if (checked) {
QShortcut *s = new QShortcut(sequence, this);
s->setObjectName(actionName);

connect(s, &QShortcut::activated, action, &QAction::trigger);
_menuShortcuts.insert(s);
} else {
action->setShortcut(sequence);
}
}
}
4 changes: 2 additions & 2 deletions src/player/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <QCommandLineParser>
#include <QMainWindow>
#include <QShortcut>
#include <QStack>

#include <qxt/qxtglobalshortcut.h>
Expand Down Expand Up @@ -39,6 +40,7 @@ class MainWindow : public QMainWindow, public Ui::MainWindow
QxtGlobalShortcut *_shortcutPlayPause;
QxtGlobalShortcut *_shortcutSkipForward;
QTranslator _translator;
QSet<QShortcut*> _menuShortcuts;

public:
explicit MainWindow(QWidget *parent = nullptr);
Expand Down Expand Up @@ -80,8 +82,6 @@ class MainWindow : public QMainWindow, public Ui::MainWindow
private:
void initQuickStart();

void toggleShortcutsOnMenuBar(bool enabled);

public slots:
void createCustomizeOptionsDialog();

Expand Down
9 changes: 2 additions & 7 deletions src/tabplaylists/viewplaylists.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ ViewPlaylists::ViewPlaylists(MediaPlayer *mediaPlayer, QWidget *parent)
searchBar->setText(QString());
_searchDialog->clear();
library->scrollToTop();
qDebug() << "ViewPlaylists -> lambda reload";
library->model()->load();
this->update();
};
Expand Down Expand Up @@ -137,7 +136,6 @@ ViewPlaylists::ViewPlaylists(MediaPlayer *mediaPlayer, QWidget *parent)
mediaPlayer->setVolume((qreal)value / 100.0);
});
connect(mediaPlayer, &MediaPlayer::volumeChanged, this, [=](qreal v) {
qDebug() << Q_FUNC_INFO;
volumeSlider->blockSignals(true);
volumeSlider->setValue(v * 100);
volumeSlider->blockSignals(false);
Expand All @@ -164,7 +162,6 @@ ViewPlaylists::ViewPlaylists(MediaPlayer *mediaPlayer, QWidget *parent)
});

connect(this, &AbstractView::modelReloadRequested, this, [=]() {
qDebug() << "AbstractView::modelReloadRequested";
library->model()->load();
for (Playlist *p : tabPlaylists->playlists()) {
p->model()->reload();
Expand Down Expand Up @@ -287,10 +284,8 @@ void ViewPlaylists::setMusicSearchEngine(MusicSearchEngine *musicSearchEngine)
if (library->layout()) {
delete library->layout();
}
foreach (QWidget *w, library->findChildren<QWidget*>()) {
if (w && w->objectName() == "paintable") {
delete w;
}
if (PaintableWidget *w = findChild<PaintableWidget*>("paintable")) {
w->deleteLater();
}
});
}
Expand Down
22 changes: 4 additions & 18 deletions src/uniquelibrary/uniquelibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ UniqueLibrary::~UniqueLibrary()
disconnect(_mediaPlayerControl->mediaPlayer(), &MediaPlayer::positionChanged, seekSlider, &SeekBar::setPosition);
_mediaPlayerControl->mediaPlayer()->stop();
if (_currentTrack) {
SettingsPrivate::instance()->setValue("uniqueLibraryLastPlayed", _currentTrack->row());
qDebug() << _currentTrack << _currentTrack->row();
//SettingsPrivate::instance()->setValue("uniqueLibraryLastPlayed", _currentTrack->row());
}
this->disconnect();
}
Expand Down Expand Up @@ -251,26 +252,11 @@ void UniqueLibrary::setMusicSearchEngine(MusicSearchEngine *musicSearchEngine)
});

connect(musicSearchEngine, &MusicSearchEngine::searchHasEnded, this, [=]() {
/*auto l = uniqueTable->layout();
while (!l->isEmpty()) {
if (QLayoutItem *i = l->takeAt(0)) {
if (QWidget *w = i->widget()) {
delete w;
}
delete i;
}
}
delete uniqueTable->layout();
uniqueTable->model()->load();
uniqueTable->adjust();*/

if (uniqueTable->layout()) {
delete uniqueTable->layout();
}
foreach (QWidget *w, uniqueTable->findChildren<QWidget*>()) {
if (w && w->objectName() == "paintable") {
delete w;
}
if (PaintableWidget *w = findChild<PaintableWidget*>("paintable")) {
w->deleteLater();
}
});
}
Expand Down

0 comments on commit 8bfc997

Please sign in to comment.