KisShortcutsDialog_p.cpp 2.87 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 *  Copyright (c) 2015 Michael Abrahams <miabraha@gmail.com>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */


#include "KisShortcutsDialog_p.h"
21
#include "kshortcutschemeshelper_p.h"
22 23 24 25
#include "kxmlguiclient.h"
#include <QDomDocument>
#include "kactioncollection.h"
#include "kxmlguifactory.h"
26 27
#include <QAction>
#include <QApplication>
28
#include <QDebug>
29 30 31
#include "kis_action_registry.h"
#include <KSharedConfig>
#include <KConfigGroup>
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49



QKeySequence primarySequence(const QList<QKeySequence> &sequences)
{
    return sequences.isEmpty() ? QKeySequence() : sequences.at(0);
}

QKeySequence alternateSequence(const QList<QKeySequence> &sequences)
{
    return sequences.size() <= 1 ? QKeySequence() : sequences.at(1);
}


KisShortcutsDialog::KisShortcutsDialogPrivate::KisShortcutsDialogPrivate(KisShortcutsDialog *q)
    : q(q)
{ }

50
void KisShortcutsDialog::KisShortcutsDialogPrivate::changeShortcutScheme(const QString &schemeName)
51
{
52 53
    // KTreeWidgetSearchLine is unhappy if the contents of the tree change
    m_shortcutsEditor->clearSearch();
54

55
    QString dialogText = i18n("The current shortcut scheme is modified. Save before switching to the new one?");
56
    if (m_shortcutsEditor->isModified() &&
57
        KMessageBox::questionYesNo( q,dialogText ) == KMessageBox::Yes) {
58
        m_shortcutsEditor->save();
59
    } else {
60
        m_shortcutsEditor->undo();
61 62 63
    }

    QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
64
    m_shortcutsEditor->clearCollections();
65

66 67
    KConfigGroup cg = KSharedConfig::openConfig()->group("Shortcut Schemes");
    cg.writeEntry("Current Scheme", schemeName);
68
    KisActionRegistry::instance()->loadShortcutScheme(schemeName);
69

70 71 72 73 74

    // Update actions themselves, and re-add to dialog box to refresh
    auto it = m_collections.constBegin();
    while (it != m_collections.constEnd()) {
        it.value()->updateShortcuts();
75
        // TODO: BAD
76 77
        m_shortcutsEditor->addCollection(it.value(), it.key());
        it++;
78 79 80 81 82
    }

    QApplication::restoreOverrideCursor();
}

83
void KisShortcutsDialog::KisShortcutsDialogPrivate::undo()
84
{
85
    m_shortcutsEditor->undo();
86 87 88 89
}

void KisShortcutsDialog::KisShortcutsDialogPrivate::save()
{
90
    m_shortcutsEditor->save();
Boudewijn Rempt's avatar
Boudewijn Rempt committed
91
}
92 93

#include "moc_KisShortcutsDialog_p.cpp"