kdeui: drop KSortcut

missing proper configuration interface for the shortcuts, the old one
was borked anyway

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-04-24 09:24:13 +03:00
parent a8906fbcf5
commit 843463c95d
54 changed files with 411 additions and 3584 deletions

View file

@ -220,10 +220,8 @@ install(
KSharedConfig
KSharedPtr
KShell
KShortcut
KShortcutsDialog
KShortcutsEditor
KShortcutWidget
KSortableItem
KSortableList
KSplashScreen

View file

@ -1 +0,0 @@
#include "../kshortcut.h"

View file

@ -1 +0,0 @@
#include "../kshortcutwidget.h"

View file

@ -88,11 +88,7 @@ set(kdeui_LIB_SRCS
dialogs/knewpassworddialog.cpp
dialogs/kpassworddialog.cpp
dialogs/kprogressdialog.cpp
dialogs/kshortcuteditwidget.cpp
dialogs/kshortcutseditordelegate.cpp
dialogs/kshortcutseditoritem.cpp
dialogs/kshortcutseditor.cpp
dialogs/kshortcutschemeseditor.cpp
dialogs/kshortcutsdialog.cpp
dialogs/ksplashscreen.cpp
dialogs/kswitchlanguagedialog_p.cpp
@ -146,8 +142,6 @@ set(kdeui_LIB_SRCS
paged/kpageview_p.cpp
paged/kpagewidget.cpp
paged/kpagewidgetmodel.cpp
shortcuts/kshortcut.cpp
shortcuts/kshortcutschemeshelper.cpp
shortcuts/kstandardshortcut.cpp
shortcuts/kglobalaccel.cpp
shortcuts/kacceleratormanager.cpp
@ -202,7 +196,6 @@ set(kdeui_LIB_SRCS
widgets/kratingwidget.cpp
widgets/krestrictedline.cpp
widgets/kseparator.cpp
widgets/kshortcutwidget.cpp
widgets/ksqueezedtextlabel.cpp
widgets/kstatusbar.cpp
widgets/ktabbar.cpp
@ -392,7 +385,6 @@ install(
paged/kpageview.h
paged/kpagewidget.h
paged/kpagewidgetmodel.h
shortcuts/kshortcut.h
shortcuts/kstandardshortcut.h
shortcuts/kglobalaccel.h
shortcuts/kacceleratormanager.h
@ -451,7 +443,6 @@ install(
widgets/ktitlewidget.h
widgets/ktabbar.h
widgets/ktabwidget.h
widgets/kshortcutwidget.h
widgets/kstatusbar.h
widgets/ktoolbar.h
widgets/kurllabel.h

View file

@ -51,12 +51,6 @@ KActionPrivate::KActionPrivate(KAction *q_ptr)
q->setProperty("isShortcutConfigurable", true);
}
void KActionPrivate::setActiveGlobalShortcutNoEnable(const KShortcut &cut)
{
globalShortcut = cut;
emit q->globalShortcutChanged(cut.primary());
}
void KActionPrivate::slotTriggered()
{
emit q->triggered(QApplication::mouseButtons(), QApplication::keyboardModifiers());
@ -128,43 +122,27 @@ void KAction::setShortcutConfigurable(bool b)
setProperty("isShortcutConfigurable", b);
}
KShortcut KAction::shortcut(ShortcutTypes type) const
QKeySequence KAction::shortcut(ShortcutTypes type) const
{
Q_ASSERT(type);
if (type == DefaultShortcut) {
return KShortcut(
property("defaultPrimaryShortcut").value<QKeySequence>(),
property("defaultAlternateShortcut").value<QKeySequence>()
);
}
const QKeySequence cut = QAction::shortcut();
return KShortcut(cut[0], cut[1]);
}
void KAction::setShortcut(const KShortcut &shortcut, ShortcutTypes type)
{
Q_ASSERT(type);
if (type & KAction::DefaultShortcut) {
setProperty("defaultPrimaryShortcut", shortcut.primary());
setProperty("defaultAlternateShortcut", shortcut.alternate());
}
if (type & ActiveShortcut) {
QAction::setShortcut(QKeySequence(shortcut.primary(), shortcut.alternate()));
return d->defaultShortcut;
}
return QAction::shortcut();
}
void KAction::setShortcut(const QKeySequence &keySeq, ShortcutTypes type)
{
Q_ASSERT(type);
if (type & KAction::DefaultShortcut) {
setProperty("defaultPrimaryShortcut", keySeq);
d->defaultShortcut = keySeq;
}
if (type & KAction::ActiveShortcut) {
QAction::setShortcut(keySeq);
}
}
const KShortcut& KAction::globalShortcut(ShortcutTypes type) const
const QKeySequence& KAction::globalShortcut(ShortcutTypes type) const
{
Q_ASSERT(type);
if (type == KAction::DefaultShortcut) {
@ -173,7 +151,7 @@ const KShortcut& KAction::globalShortcut(ShortcutTypes type) const
return d->globalShortcut;
}
void KAction::setGlobalShortcut(const KShortcut &shortcut, ShortcutTypes type)
void KAction::setGlobalShortcut(const QKeySequence &shortcut, ShortcutTypes type)
{
Q_ASSERT(type);
bool changed = false;
@ -216,8 +194,8 @@ bool KAction::isGlobalShortcutEnabled() const
void KAction::forgetGlobalShortcut()
{
d->globalShortcut = KShortcut();
d->defaultGlobalShortcut = KShortcut();
d->globalShortcut = QKeySequence();
d->defaultGlobalShortcut = QKeySequence();
if (d->globalShortcutEnabled) {
d->globalShortcutEnabled = false;
d->neverSetGlobalShortcut = true; //it's a fresh start :)

View file

@ -27,9 +27,9 @@
#define KACTION_H
#include <kdeui_export.h>
#include <kshortcut.h>
#include <QtGui/QWidgetAction>
#include <QWidgetAction>
#include <QKeySequence>
class KIcon;
@ -207,10 +207,8 @@ class KIcon;
class KDEUI_EXPORT KAction : public QWidgetAction
{
Q_OBJECT
Q_PROPERTY(KShortcut shortcut READ shortcut WRITE setShortcut)
Q_PROPERTY(bool shortcutConfigurable READ isShortcutConfigurable WRITE setShortcutConfigurable)
Q_PROPERTY(KShortcut globalShortcut READ globalShortcut WRITE setGlobalShortcut)
Q_PROPERTY(QKeySequence globalShortcut READ globalShortcut WRITE setGlobalShortcut)
Q_PROPERTY(bool globalShortcutEnabled READ isGlobalShortcutEnabled)
Q_FLAGS(ShortcutType)
@ -281,24 +279,10 @@ public:
* \param types the type of shortcut to return. Should both be specified, only the
* active shortcut will be returned. Defaults to the active shortcut, if one exists.
*/
KShortcut shortcut(ShortcutTypes types = ActiveShortcut) const;
QKeySequence shortcut(ShortcutTypes types = ActiveShortcut) const;
/**
* Set the shortcut for this action.
*
* This is preferred over QAction::setShortcut(), as it allows for multiple shortcuts
* per action.
*
* \param shortcut shortcut(s) to use for this action in its specified shortcutContext()
* \param type type of shortcut to be set: active shortcut,
* default shortcut, or both (the default).
*/
void setShortcut(const KShortcut &shortcut, ShortcutTypes type = ShortcutTypes(ActiveShortcut | DefaultShortcut));
/**
* \overload void setShortcut(const KShortcut& shortcut)
*
* Set the primary shortcut only for this action.
* Set the shortcut only for this action.
*
* This function is there to explicitly override QAction::setShortcut(const QKeySequence&).
* QAction::setShortcut() will bypass everything in KAction and may lead to unexpected behavior.
@ -334,7 +318,7 @@ public:
* \sa KGlobalAccel
* \sa setGlobalShortcut()
*/
const KShortcut& globalShortcut(ShortcutTypes type = ActiveShortcut) const;
const QKeySequence& globalShortcut(ShortcutTypes type = ActiveShortcut) const;
/**
* Assign a global shortcut for this action. Global shortcuts
@ -356,7 +340,7 @@ public:
* or both (the default).
* \sa globalShortcut()
*/
void setGlobalShortcut(const KShortcut &shortcut, ShortcutTypes type =
void setGlobalShortcut(const QKeySequence &shortcut, ShortcutTypes type =
ShortcutTypes(ActiveShortcut | DefaultShortcut));
/**
@ -404,7 +388,6 @@ Q_SIGNALS:
private:
friend class KGlobalAccel; // Needs access to the component
friend class KActionCollectionPrivate; // Needs access to the component
friend class KShortcutsEditorDelegate; // Needs access to the component
Q_PRIVATE_SLOT(d, void slotTriggered())
class KActionPrivate* const d;
friend class KActionPrivate;

View file

@ -20,8 +20,8 @@
#define KACTION_P_H
#include "kglobalaccel.h"
#include <kcomponentdata.h>
#include <kicon.h>
#include "kcomponentdata.h"
#include "kicon.h"
class KAction;
@ -32,8 +32,6 @@ public:
void slotTriggered();
void setActiveGlobalShortcutNoEnable(const KShortcut &cut);
void maybeSetComponentData(const KComponentData &kcd)
{
if (neverSetGlobalShortcut) {
@ -42,12 +40,13 @@ public:
}
KComponentData componentData; // this is **way** more lightweight than it looks
KShortcut globalShortcut;
KShortcut defaultGlobalShortcut;
QKeySequence defaultShortcut;
QKeySequence globalShortcut;
QKeySequence defaultGlobalShortcut;
bool globalShortcutEnabled;
bool neverSetGlobalShortcut;
KAction *q;
};
#endif
#endif // KACTION_P_H

View file

@ -393,7 +393,7 @@ void KActionCollection::importGlobalShortcuts(KConfigGroup *config)
if (kaction->isShortcutConfigurable()) {
const QString entry = config->readEntry(actionName, QString());
if (!entry.isEmpty()) {
kaction->setGlobalShortcut(KShortcut(entry), KAction::ActiveShortcut);
kaction->setGlobalShortcut(QKeySequence(entry), KAction::ActiveShortcut);
} else {
kaction->setGlobalShortcut(kaction->shortcut(KAction::DefaultShortcut), KAction::ActiveShortcut);
}
@ -424,7 +424,7 @@ void KActionCollection::readSettings(KConfigGroup *config)
const QString actionName = it.key();
const QString entry = config->readEntry(actionName, QString());
if (!entry.isEmpty()) {
kaction->setShortcut(KShortcut(entry), KAction::ActiveShortcut);
kaction->setShortcut(QKeySequence(entry), KAction::ActiveShortcut);
} else {
kaction->setShortcut(kaction->shortcut(KAction::DefaultShortcut));
}

View file

@ -44,7 +44,7 @@
namespace KStandardAction
{
AutomaticAction::AutomaticAction(const KIcon &icon, const QString &text, const KShortcut &shortcut, const char *slot,
AutomaticAction::AutomaticAction(const KIcon &icon, const QString &text, const QKeySequence &shortcut, const char *slot,
QObject *parent)
: KAction(parent)
{
@ -190,7 +190,7 @@ KAction *create(StandardAction id, const QObject *recvr, const char *slot, QObje
}
pAction->setIcon(icon);
KShortcut cut = KStandardShortcut::shortcut(pInfo->idAccel);
QKeySequence cut = KStandardShortcut::shortcut(pInfo->idAccel);
if (!cut.isEmpty())
pAction->setShortcut(cut);

View file

@ -148,7 +148,7 @@ class AutomaticAction : public KAction
Q_OBJECT
public:
AutomaticAction(const KIcon &icon, const QString &text, const KShortcut &shortcut, const char *slot,
AutomaticAction(const KIcon &icon, const QString &text, const QKeySequence &shortcut, const char *slot,
QObject *parent);
public Q_SLOTS:
inline void cut() { invokeEditSlot( "cut" ); }

View file

@ -218,12 +218,12 @@ void KColorButton::keyPressEvent( QKeyEvent *e )
{
int key = e->key() | e->modifiers();
if ( KStandardShortcut::copy().contains( key ) ) {
if ( KStandardShortcut::copy().matches( key ) != QKeySequence::NoMatch ) {
QMimeData *mime=new QMimeData;
KColorMimeData::populateMimeData(mime,color());
QApplication::clipboard()->setMimeData( mime, QClipboard::Clipboard );
}
else if ( KStandardShortcut::paste().contains( key ) ) {
else if ( KStandardShortcut::paste().matches( key ) != QKeySequence::NoMatch ) {
QColor color=KColorMimeData::fromMimeData( QApplication::clipboard()->mimeData( QClipboard::Clipboard ));
setColor( color );
}

View file

@ -1,191 +0,0 @@
/* This file is part of the KDE libraries Copyright (C) 1998 Mark Donohoe <donohoe@kde.org>
Copyright (C) 1997 Nicolas Hadacek <hadacek@kde.org>
Copyright (C) 1998 Matthias Ettrich <ettrich@kde.org>
Copyright (C) 2001 Ellis Whitehead <ellis@kde.org>
Copyright (C) 2006 Hamish Rodda <rodda@kde.org>
Copyright (C) 2007 Roberto Raggi <roberto@kdevelop.org>
Copyright (C) 2007 Andreas Hartmetz <ahartmetz@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "kshortcutsdialog_p.h"
#include <QPainter>
#include <QPen>
#include <QGridLayout>
#include <QRadioButton>
#include <QLabel>
#include "kkeysequencewidget.h"
#include "klocale.h"
void TabConnectedWidget::paintEvent(QPaintEvent *e)
{
QWidget::paintEvent(e);
QPainter p(this);
QPen pen(QPalette().highlight().color());
pen.setWidth(6);
p.setPen(pen);
p.drawLine(0, 0, width(), 0);
if (qApp->isLeftToRight()) {
p.drawLine(0, 0, 0, height());
} else {
p.drawLine(width(), 0, width(), height());
}
}
ShortcutEditWidget::ShortcutEditWidget(QWidget *viewport, const QKeySequence &defaultSeq,
const QKeySequence &activeSeq, bool allowLetterShortcuts)
: TabConnectedWidget(viewport),
m_defaultKeySequence(defaultSeq),
m_isUpdating(false)
{
QGridLayout *layout = new QGridLayout(this);
m_defaultRadio = new QRadioButton(i18n("Default:"), this);
m_defaultLabel = new QLabel(i18nc("No shortcut defined", "None"), this);
QString defaultText = defaultSeq.toString(QKeySequence::NativeText);
if (defaultText.isEmpty())
defaultText = i18nc("No shortcut defined", "None");
m_defaultLabel->setText(defaultText);
m_customRadio = new QRadioButton(i18n("Custom:"), this);
m_customEditor = new KKeySequenceWidget(this);
m_customEditor->setModifierlessAllowed(allowLetterShortcuts);
layout->addWidget(m_defaultRadio, 0, 0);
layout->addWidget(m_defaultLabel, 0, 1);
layout->addWidget(m_customRadio, 1, 0);
layout->addWidget(m_customEditor, 1, 1);
layout->setColumnStretch(2, 1);
setKeySequence(activeSeq);
connect(
m_defaultRadio, SIGNAL(toggled(bool)),
this, SLOT(defaultToggled(bool))
);
connect(
m_customEditor, SIGNAL(keySequenceChanged(QKeySequence)),
this, SLOT(setCustom(QKeySequence))
);
connect(
m_customEditor, SIGNAL(stealShortcut(QKeySequence,KAction*)),
this, SIGNAL(stealShortcut(QKeySequence,KAction*))
);
}
KKeySequenceWidget::ShortcutTypes ShortcutEditWidget::checkForConflictsAgainst() const
{
return m_customEditor->checkForConflictsAgainst();
}
//slot
void ShortcutEditWidget::defaultToggled(bool checked)
{
if (m_isUpdating) {
return;
}
m_isUpdating = true;
if (checked) {
// The default key sequence should be activated. We check first if this is
// possible.
if (m_customEditor->isKeySequenceAvailable(m_defaultKeySequence)) {
// Clear the customs widget
m_customEditor->clearKeySequence();
emit keySequenceChanged(m_defaultKeySequence);
} else {
// We tried to switch to the default key sequence and failed. Go
// back.
m_customRadio->setChecked(true);
}
} else {
// The empty key sequence is always valid
emit keySequenceChanged(QKeySequence());
}
m_isUpdating = false;
}
void ShortcutEditWidget::setCheckActionCollections(const QList<KActionCollection*> &checkActionCollections)
{
// We just forward them to out KKeySequenceWidget.
m_customEditor->setCheckActionCollections(checkActionCollections);
}
void ShortcutEditWidget::setCheckForConflictsAgainst(KKeySequenceWidget::ShortcutTypes types)
{
m_customEditor->setCheckForConflictsAgainst(types);
}
void ShortcutEditWidget::setComponentName(const QString &componentName)
{
m_customEditor->setComponentName(componentName);
}
void ShortcutEditWidget::setMultiKeyShortcutsAllowed(bool allowed)
{
// We just forward them to out KKeySequenceWidget.
m_customEditor->setMultiKeyShortcutsAllowed(allowed);
}
bool ShortcutEditWidget::multiKeyShortcutsAllowed() const
{
return m_customEditor->multiKeyShortcutsAllowed();
}
//slot
void ShortcutEditWidget::setCustom(const QKeySequence &seq)
{
if (m_isUpdating)
return;
// seq is a const reference to a private variable of KKeySequenceWidget.
// Somewhere below we possible change that one. But we want to emit seq
// whatever happens. So we make a copy.
QKeySequence original = seq;
m_isUpdating = true;
// Check if the user typed in the default sequence into the custom field.
// We do this by calling setKeySequence which will do the right thing.
setKeySequence(original);
emit keySequenceChanged(original);
m_isUpdating = false;
}
void ShortcutEditWidget::setKeySequence(const QKeySequence &activeSeq)
{
if (activeSeq == m_defaultLabel->text()) {
m_defaultRadio->setChecked(true);
m_customEditor->clearKeySequence();
} else {
m_customRadio->setChecked(true);
// m_customEditor->setKeySequence does some stuff we only want to
// execute when the sequence really changes.
if (activeSeq!=m_customEditor->keySequence()) {
m_customEditor->setKeySequence(activeSeq);
}
}
}

View file

@ -1,203 +0,0 @@
/* This file is part of the KDE libraries
Copyright (C) 2008 Alexander Dymo <adymo@kdevelop.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "kshortcutsdialog_p.h"
#include <QDir>
#include <QLabel>
#include <QMenu>
#include <QFile>
#include <QTextStream>
#include <QtXml/qdom.h>
#include <QFileDialog>
#include <kcombobox.h>
#include <kpushbutton.h>
#include <kstandarddirs.h>
#include <kactioncollection.h>
#include <kmessagebox.h>
#include <kxmlguiclient.h>
#include <kinputdialog.h>
#include <klocale.h>
#include "kshortcutsdialog.h"
#include "kshortcutschemeshelper_p.h"
KShortcutSchemesEditor::KShortcutSchemesEditor(KShortcutsDialog *parent)
:QGroupBox(i18n("Shortcut Schemes"), parent), m_dialog(parent)
{
KConfigGroup group( KGlobal::config(), "Shortcut Schemes" );
const QStringList schemeFiles = KGlobal::dirs()->findAllResources("appdata", "*shortcuts.rc");
QStringList schemes;
schemes << "Default";
foreach (QString schemeFile, schemeFiles)
{
schemes << schemeFile.remove(QRegExp("^.*/"+KGlobal::mainComponent().componentName())).
remove("shortcuts.rc");
}
QString currentScheme = group.readEntry("Current Scheme", "Default");
QHBoxLayout *l = new QHBoxLayout(this);
l->setMargin(0);
QLabel *schemesLabel = new QLabel(i18n("Current scheme:"), this);
l->addWidget(schemesLabel);
m_schemesList = new KComboBox(this);
m_schemesList->setEditable(false);
m_schemesList->addItems(schemes);
m_schemesList->setCurrentIndex(m_schemesList->findText(currentScheme));
schemesLabel->setBuddy(m_schemesList);
l->addWidget(m_schemesList);
m_newScheme = new KPushButton(i18n("New..."));
l->addWidget(m_newScheme);
m_deleteScheme = new KPushButton(i18n("Delete"));
l->addWidget(m_deleteScheme);
KPushButton *moreActions = new KPushButton(i18n("More Actions"));
l->addWidget(moreActions);
QMenu *moreActionsMenu = new QMenu(this);
moreActionsMenu->addAction(i18n("Save as Scheme Defaults"),
this, SLOT(saveAsDefaultsForScheme()));
moreActionsMenu->addAction(i18n("Export Scheme..."),
this, SLOT(exportShortcutsScheme()));
moreActions->setMenu(moreActionsMenu);
l->addStretch(1);
connect(m_schemesList, SIGNAL(activated(QString)),
this, SIGNAL(shortcutsSchemeChanged(QString)));
connect(m_newScheme, SIGNAL(clicked()), this, SLOT(newScheme()));
connect(m_deleteScheme, SIGNAL(clicked()), this, SLOT(deleteScheme()));
updateDeleteButton();
}
void KShortcutSchemesEditor::newScheme()
{
bool ok = false;
const QString newName = KInputDialog::getText(
i18n("Name for New Scheme"),
i18n("Name for new scheme:"), i18n("New Scheme"),
&ok, this
);
if (!ok) {
return;
}
if (m_schemesList->findText(newName) != -1) {
KMessageBox::sorry(this, i18n("A scheme with this name already exists."));
return;
}
const QString newSchemeFileName = KShortcutSchemesHelper::applicationShortcutSchemeFileName(newName);
QFile schemeFile(newSchemeFileName);
if (!schemeFile.open(QFile::WriteOnly | QFile::Truncate)) {
return;
}
QDomDocument doc;
QDomElement docElem = doc.createElement("kpartgui");
doc.appendChild(docElem);
QDomElement elem = doc.createElement("ActionProperties");
docElem.appendChild(elem);
QTextStream out(&schemeFile);
out << doc.toString(4);
m_schemesList->addItem(newName);
m_schemesList->setCurrentIndex(m_schemesList->findText(newName));
updateDeleteButton();
emit shortcutsSchemeChanged(newName);
}
void KShortcutSchemesEditor::deleteScheme()
{
if (KMessageBox::questionYesNo(this,
i18n("Do you really want to delete the scheme %1?\n\
Note that this will not remove any system wide shortcut schemes.", currentScheme())) == KMessageBox::No)
return;
//delete the scheme for the app itself
QFile::remove(KShortcutSchemesHelper::applicationShortcutSchemeFileName(currentScheme()));
//delete all scheme files we can find for xmlguiclients in the user directories
foreach (KActionCollection *collection, m_dialog->actionCollections())
{
const KXMLGUIClient *client = collection->parentGUIClient();
if (!client) {
continue;
}
QFile::remove(KShortcutSchemesHelper::shortcutSchemeFileName(client, currentScheme()));
}
m_schemesList->removeItem(m_schemesList->findText(currentScheme()));
updateDeleteButton();
emit shortcutsSchemeChanged(currentScheme());
}
QString KShortcutSchemesEditor::currentScheme()
{
return m_schemesList->currentText();
}
void KShortcutSchemesEditor::exportShortcutsScheme()
{
// ask user about dir, it is not possible to use KFileDialog here because kfile links against
// kdeui. the dialog gets replaced anyway with the KDE one at runtime
QString exportTo = QFileDialog::getExistingDirectory(
this, i18n("Export to Location"),
QDir::currentPath()
);
if (exportTo.isEmpty())
return;
QDir schemeRoot(exportTo);
if (!schemeRoot.exists(exportTo)) {
KMessageBox::error(this, i18n("Could not export shortcuts scheme because the location is invalid."));
return;
}
foreach (KActionCollection *collection, m_dialog->actionCollections())
{
const KXMLGUIClient *client = collection->parentGUIClient();
if (!client) {
continue;
}
KShortcutSchemesHelper::exportActionCollection(collection, currentScheme(), exportTo + '/');
}
}
void KShortcutSchemesEditor::saveAsDefaultsForScheme()
{
foreach (KActionCollection *collection, m_dialog->actionCollections()) {
KShortcutSchemesHelper::exportActionCollection(collection, currentScheme());
}
}
void KShortcutSchemesEditor::updateDeleteButton()
{
m_deleteScheme->setEnabled(m_schemesList->count() >= 1);
}

View file

@ -26,7 +26,6 @@
*/
#include "kshortcutsdialog.h"
#include "kshortcutsdialog_p.h"
#include "kdebug.h"
#include "klocale.h"
@ -56,50 +55,12 @@ class KShortcutsDialog::KShortcutsDialogPrivate
public:
KShortcutsDialogPrivate(KShortcutsDialog *q)
: q(q), m_keyChooser(0), m_schemeEditor(0)
: q(q), m_keyChooser(0)
{
}
QList<KActionCollection*> m_collections;
void changeShortcutScheme(const QString &scheme)
{
if (m_keyChooser->isModified() && KMessageBox::questionYesNo(q,
i18n("The current shortcut scheme is modified. Save before switching to the new one?")) == KMessageBox::Yes) {
m_keyChooser->save();
} else {
m_keyChooser->undoChanges();
}
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
m_keyChooser->clearCollections();
foreach (KActionCollection *collection, m_collections) {
// passing an empty stream forces the clients to reread the XML
KXMLGUIClient *client = const_cast<KXMLGUIClient *>(collection->parentGUIClient());
if (client) {
client->setXMLGUIBuildDocument(QDomDocument());
}
}
//get xmlguifactory
if (!m_collections.isEmpty()) {
const KXMLGUIClient *client = m_collections.first()->parentGUIClient();
if (client) {
KXMLGUIFactory *factory = client->factory();
if (factory) {
factory->changeShortcutScheme(scheme);
}
}
}
foreach (KActionCollection *collection, m_collections) {
m_keyChooser->addCollection(collection);
}
QApplication::restoreOverrideCursor();
}
void undoChanges()
{
m_keyChooser->undoChanges();
@ -112,8 +73,7 @@ public:
}
KShortcutsDialog *q;
KShortcutsEditor* m_keyChooser; // ### move
KShortcutSchemesEditor* m_schemeEditor;
KShortcutsEditor* m_keyChooser;
};
@ -121,23 +81,13 @@ KShortcutsDialog::KShortcutsDialog( KShortcutsEditor::ActionTypes types, KShortc
: KDialog( parent ), d(new KShortcutsDialogPrivate(this))
{
setCaption(i18n("Configure Shortcuts"));
setButtons(Details|Reset|Ok|Cancel|KDialog::User1);
setButtonText(KDialog::User1, i18n("Print"));
setButtonIcon(KDialog::User1, KIcon("document-print"));
setButtons(Reset|Ok|Cancel);
setModal(true);
d->m_keyChooser = new KShortcutsEditor(this, types, allowLetterShortcuts);
setMainWidget( d->m_keyChooser );
setButtonText(Reset,i18n("Reset to Defaults"));
d->m_schemeEditor = new KShortcutSchemesEditor(this);
connect(
d->m_schemeEditor, SIGNAL(shortcutsSchemeChanged(QString)),
this, SLOT(changeShortcutScheme(QString))
);
setDetailsWidget(d->m_schemeEditor);
connect(this, SIGNAL(resetClicked()), d->m_keyChooser, SLOT(allDefault()));
connect(this, SIGNAL(user1Clicked()), d->m_keyChooser, SLOT(printShortcuts()));
connect(this, SIGNAL(cancelClicked()), SLOT(undoChanges()));
KConfigGroup group(KGlobal::config(), "KShortcutsDialog Settings");
@ -195,4 +145,3 @@ int KShortcutsDialog::configure(KActionCollection *collection, KShortcutsEditor:
}
#include "moc_kshortcutsdialog.cpp"
#include "moc_kshortcutsdialog_p.cpp"

View file

@ -130,7 +130,6 @@ Q_SIGNALS:
void saved();
private:
Q_PRIVATE_SLOT(d, void changeShortcutScheme(const QString &))
Q_PRIVATE_SLOT(d, void save())
Q_PRIVATE_SLOT(d, void undoChanges())

View file

@ -1,69 +0,0 @@
<?xml version="1.0" encoding="System"?>
<ui version="4.0">
<class>KShortcutsDialog</class>
<widget class="QWidget" name="KShortcutsDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>761</width>
<height>549</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="KTreeWidgetSearchLineWidget" name="searchFilter">
<property name="whatsThis">
<string>Search interactively for shortcut names (e.g. Copy) or combination of keys (e.g. Ctrl+C) by typing them here.</string>
</property>
</widget>
</item>
<item>
<widget class="QTreeWidget" name="list">
<property name="whatsThis">
<string>Here you can see a list of key bindings, i.e. associations between actions (e.g. 'Copy') shown in the left column and keys or combination of keys (e.g. Ctrl+V) shown in the right column.</string>
</property>
<property name="rootIsDecorated">
<bool>true</bool>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
<column>
<property name="text">
<string>Action</string>
</property>
</column>
<column>
<property name="text">
<string>Shortcut</string>
</property>
</column>
<column>
<property name="text">
<string>Alternate</string>
</property>
</column>
<column>
<property name="text">
<string>Global</string>
</property>
</column>
<column>
<property name="text">
<string>Global Alternate</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KTreeWidgetSearchLineWidget</class>
<extends>QWidget</extends>
<header>ktreewidgetsearchline.h</header>
</customwidget>
</customwidgets>
<connections/>
</ui>

View file

@ -1,385 +0,0 @@
/* This file is part of the KDE libraries
Copyright (C) 2006,2007 Andreas Hartmetz (ahartmetz@gmail.com)
Copyright (C) 2008 Michael Jansen <kde@michael-jansen.biz>
Copyright (C) 2008 Alexander Dymo <adymo@kdevelop.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KSHORTCUTSDIALOG_P_H
#define KSHORTCUTSDIALOG_P_H
#include "kextendableitemdelegate.h"
#include "kshortcutseditor.h"
#include "kkeysequencewidget.h"
#include <QKeySequence>
#include <QMetaType>
#include <QtCore/qabstractitemmodel.h>
#include <QTreeWidget>
#include <QtCore/QList>
#include <QGroupBox>
#include <QLabel>
#include <QTreeWidget>
#include <QTreeWidgetItem>
#include <QRadioButton>
class KAction;
class KActionCollection;
class KPushButton;
class KComboBox;
class KShortcutsDialog;
enum ColumnDesignation {
Name = 0,
LocalPrimary,
LocalAlternate,
GlobalPrimary,
GlobalAlternate,
Id
};
enum MyRoles {
ShortcutRole = Qt::UserRole,
DefaultShortcutRole,
ObjectRole
};
/**
* Type used for QTreeWidgetItems
*
* @internal
*/
enum ItemTypes {
NonActionItem = 0,
ActionItem = 1
};
/**
* Mixes the KShortcutWidget into the treeview used by KShortcutsEditor. When selecting an shortcut
* it changes the display from "CTRL-W" to the Widget.
*
* @bug That delegate uses KExtendableItemDelegate. That means a cell can be expanded. When selected
* a cell is replaced by a KShortcutsEditor. When painting the widget KExtendableItemDelegate
* reparents the widget to the viewport of the itemview it belongs to. The widget is destroyed when
* the user selects another shortcut or explicitly issues a contractItem event. But when the user
* clears the model the delegate misses that event and doesn't delete the KShortcutseditor. And
* remains as a visible artefact in your treeview. Additionally when closing your application you get
* an assertion failure from KExtendableItemDelegate.
*
* @internal
*/
class KShortcutsEditorDelegate : public KExtendableItemDelegate
{
Q_OBJECT
public:
KShortcutsEditorDelegate(QTreeWidget *parent, bool allowLetterShortcuts);
//reimplemented to have some extra height
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
/**
* Set a list of action collections to check against for conflicting
* shortcuts.
*
* @see KKeySequenceWidget::setCheckActionCollections
*/
void setCheckActionCollections(const QList<KActionCollection*> checkActionCollections );
Q_SIGNALS:
void shortcutChanged(QVariant, const QModelIndex &);
public Q_SLOTS:
void hiddenBySearchLine(QTreeWidgetItem *, bool);
protected:
virtual bool eventFilter(QObject *, QEvent *);
private:
mutable QPersistentModelIndex m_editingIndex;
bool m_allowLetterShortcuts;
QWidget *m_editor;
//! List of actionCollections to check for conflicts.
QList<KActionCollection*> m_checkActionCollections;
private Q_SLOTS:
void itemActivated(QModelIndex index);
/**
* When the user collapses a hole subtree of shortcuts then remove eventually
* extended items. Else we get that artefact bug. See above.
*/
void itemCollapsed(QModelIndex index );
/**
* If the user allowed stealing a shortcut we want to be able to undo
* that.
*/
void stealShortcut(const QKeySequence &seq, KAction *action);
void keySequenceChanged(const QKeySequence &);
};
/**
* That widget draws the decoration for KShortCutWidget. That widget is currently the only user.
*
* @internal
*/
class TabConnectedWidget : public QWidget
{
Q_OBJECT
public:
TabConnectedWidget(QWidget *parent)
: QWidget(parent) {}
protected:
void paintEvent(QPaintEvent *pe);
};
/**
* Edit a shortcut. Let you select between using the default shortcut and configuring your own.
*
* @internal
*/
class ShortcutEditWidget : public TabConnectedWidget
{
Q_OBJECT
public:
ShortcutEditWidget(QWidget *viewport, const QKeySequence &defaultSeq, const QKeySequence &activeSeq,
bool allowLetterShortcuts);
//! @see KKeySequenceWidget::setCheckActionCollections()
void setCheckActionCollections(const QList<KActionCollection*> &checkActionCollections);
//@{
//! @see KKeySequenceWidget::checkAgainstStandardShortcuts()
KKeySequenceWidget::ShortcutTypes checkForConflictsAgainst() const;
void setCheckForConflictsAgainst(KKeySequenceWidget::ShortcutTypes);
//@}
//@{
//! @see KKeySequenceWidget::checkAgainstStandardShortcuts()
bool multiKeyShortcutsAllowed() const;
void setMultiKeyShortcutsAllowed(bool);
//@}
//! @see KKeySequenceWidget::setComponentName
void setComponentName(const QString &componentName);
public Q_SLOTS:
//! Set the displayed sequences
void setKeySequence(const QKeySequence &activeSeq);
Q_SIGNALS:
//! Emitted when the key sequence is changed.
void keySequenceChanged(const QKeySequence &);
//! @see KKeySequenceWidget::stealShortcut()
void stealShortcut(const QKeySequence &seq, KAction *action);
private Q_SLOTS:
void defaultToggled(bool);
void setCustom(const QKeySequence &);
private:
QLabel *m_defaultLabel;
QKeySequence m_defaultKeySequence;
QRadioButton *m_defaultRadio;
QRadioButton *m_customRadio;
KKeySequenceWidget *m_customEditor;
bool m_isUpdating;
};
class KShortcutSchemesEditor: public QGroupBox {
Q_OBJECT
public:
KShortcutSchemesEditor(KShortcutsDialog *parent);
/** @return the currently selected scheme in the editor (may differ from current app's scheme.*/
QString currentScheme();
private Q_SLOTS:
void newScheme();
void deleteScheme();
void exportShortcutsScheme();
void saveAsDefaultsForScheme();
Q_SIGNALS:
void shortcutsSchemeChanged(const QString&);
protected:
void updateDeleteButton();
private:
KPushButton *m_newScheme;
KPushButton *m_deleteScheme;
KPushButton *m_exportScheme;
KComboBox *m_schemesList;
KShortcutsDialog *m_dialog;
};
class KAction;
class KShortcut;
/**
* A QTreeWidgetItem that can handle KActions.
*
* It provides undo, commit functionality for changes made. Changes are effective immediately. You
* have to commit them or they will be undone when deleting the item.
*
* @internal
*/
class KShortcutsEditorItem : public QTreeWidgetItem
{
public:
KShortcutsEditorItem(QTreeWidgetItem *parent, KAction *action);
/**
* Destructor
*
* Will undo pending changes. If you don't want that. Call commitChanges before
*/
virtual ~KShortcutsEditorItem();
//! Undo the changes since the last commit.
void undo();
//! Commit the changes.
void commit();
virtual QVariant data(int column, int role = Qt::DisplayRole) const;
virtual bool operator<(const QTreeWidgetItem &other) const;
QKeySequence keySequence(uint column) const;
void setKeySequence(uint column, const QKeySequence &seq);
bool isModified(uint column) const;
bool isModified() const;
void setNameBold(bool flag) { m_isNameBold = flag; }
private:
friend class KShortcutsEditorPrivate;
//! Recheck modified status - could have changed back to initial value
void updateModified();
//! The action this item is responsible for
KAction *m_action;
//! Should the Name column be painted in bold?
bool m_isNameBold;
//@{
//! The original shortcuts before user changes. 0 means no change.
KShortcut *m_oldLocalShortcut;
KShortcut *m_oldGlobalShortcut;
//@}
//! The localized action name
QString m_actionNameInTable;
//! The action id. Needed for exporting and importing
QString m_id;
};
// NEEDED FOR KShortcutsEditorPrivate
#include "ui_kshortcutsdialog.h"
#include "kstandardshortcut.h"
// Hack to make two protected methods public.
// Used by both KShortcutsEditorPrivate and KShortcutsEditorDelegate
class QTreeWidgetHack : public QTreeWidget
{
public:
QTreeWidgetItem *itemFromIndex(const QModelIndex &index) const
{ return QTreeWidget::itemFromIndex(index); }
QModelIndex indexFromItem(QTreeWidgetItem *item, int column) const
{ return QTreeWidget::indexFromItem(item, column); }
};
/**
* This class should belong into kshortcutseditor.cpp. But kshortcutseditordelegate uses a static
* function of this class. So for now it's here. But i will remove it later.
*
* @internal
*/
class KShortcutsEditorPrivate
{
public:
KShortcutsEditorPrivate(KShortcutsEditor *q);
void initGUI( KShortcutsEditor::ActionTypes actionTypes, KShortcutsEditor::LetterShortcuts allowLetterShortcuts );
void appendToView(uint nList, const QString &title = QString());
//used in appendToView
QTreeWidgetItem *findOrMakeItem(QTreeWidgetItem *parent, const QString &name);
static KShortcutsEditorItem *itemFromIndex(QTreeWidget *const w, const QModelIndex &index);
// Set all shortcuts to their default values (bindings).
void allDefault();
// clear all shortcuts
void clearConfiguration();
// Import shortcuts from file
void importConfiguration(KConfigBase *config);
//conflict resolution functions
void changeKeyShortcut(KShortcutsEditorItem *item, uint column, const QKeySequence &capture);
// private slots
//this invokes the appropriate conflict resolution function
void capturedShortcut(const QVariant &, const QModelIndex &);
//! Represents the three hierarchies the dialog handles.
enum hierarchyLevel {Root = 0, Program, Action};
/**
* Add @a action at @a level. Checks for QActions and unnamed actions
* before adding.
*
* @return true if the actions was really added, false if not
*/
bool addAction(QAction *action, QTreeWidgetItem *hier[], hierarchyLevel level);
void printShortcuts() const;
// members
QList<KActionCollection *> actionCollections;
KShortcutsEditor *q;
Ui::KShortcutsDialog ui;
KShortcutsEditor::ActionTypes actionTypes;
KShortcutsEditorDelegate *delegate;
};
Q_DECLARE_METATYPE(KShortcutsEditorItem*)
#endif /* KSHORTCUTSDIALOG_P_H */

View file

@ -25,9 +25,6 @@
#include "kshortcutseditor.h"
// The following is needed for KShortcutsEditorPrivate and QTreeWidgetHack
#include "kshortcutsdialog_p.h"
#include <QHeaderView>
#include <QList>
#include <QObject>
@ -35,7 +32,7 @@
#include <QTextDocument>
#include <QTextTable>
#include <QTextCursor>
#include <QtGui/qtextformat.h>
#include <QTextFormat>
#include <QPrinter>
#include <QPrintDialog>
@ -46,28 +43,30 @@
#include "kdeprintdialog.h"
#include "kglobalaccel.h"
#include "kmessagebox.h"
#include "kshortcut.h"
#include "kaboutdata.h"
#include "kconfiggroup.h"
//---------------------------------------------------------------------
// KShortcutsEditor
//---------------------------------------------------------------------
class KShortcutsEditorPrivate
{
public:
KShortcutsEditor::ActionTypes actionTypes;
QList<KActionCollection*> actionCollections;
};
KShortcutsEditor::KShortcutsEditor(KActionCollection *collection, QWidget *parent, ActionTypes actionType,
LetterShortcuts allowLetterShortcuts )
: QWidget(parent),
d(new KShortcutsEditorPrivate(this))
d(new KShortcutsEditorPrivate())
{
d->initGUI(actionType, allowLetterShortcuts);
d->actionTypes = actionType;
addCollection(collection);
}
KShortcutsEditor::KShortcutsEditor(QWidget *parent, ActionTypes actionType, LetterShortcuts allowLetterShortcuts)
: QWidget(parent),
d(new KShortcutsEditorPrivate(this))
d(new KShortcutsEditorPrivate())
{
d->initGUI(actionType, allowLetterShortcuts);
d->actionTypes = actionType;
}
KShortcutsEditor::~KShortcutsEditor()
@ -77,24 +76,12 @@ KShortcutsEditor::~KShortcutsEditor()
bool KShortcutsEditor::isModified() const
{
// Iterate over all items
QTreeWidgetItemIterator it(d->ui.list, QTreeWidgetItemIterator::NoChildren);
for (; (*it); ++it) {
KShortcutsEditorItem* item = dynamic_cast<KShortcutsEditorItem *>(*it);
if (item && item->isModified()) {
return true;
}
}
return false;
}
void KShortcutsEditor::clearCollections()
{
d->delegate->contractAll();
d->ui.list->clear();
d->actionCollections.clear();
QTimer::singleShot(0, this, SLOT(resizeColumns()));
}
void KShortcutsEditor::addCollection(KActionCollection *collection, const QString &title)
@ -105,73 +92,16 @@ void KShortcutsEditor::addCollection(KActionCollection *collection, const QStrin
return;
}
// We add a bunch of items. Prevent the treewidget from permanently
// updating.
setUpdatesEnabled(false);
d->actionCollections.append(collection);
// Forward our actionCollections to the delegate which does the conflict
// checking.
d->delegate->setCheckActionCollections(d->actionCollections);
QString displayTitle = title;
if (displayTitle.isEmpty()) {
// Use the programName (Translated).
if (const KAboutData *about = collection->componentData().aboutData()) {
displayTitle = about->programName();
}
// Yes it happens. Some apps don't set the programName.
if (displayTitle.isEmpty()) {
displayTitle = i18n("Unknown");
}
}
QTreeWidgetItem *hier[3];
hier[KShortcutsEditorPrivate::Root] = d->ui.list->invisibleRootItem();
hier[KShortcutsEditorPrivate::Program] = d->findOrMakeItem( hier[KShortcutsEditorPrivate::Root], displayTitle);
hier[KShortcutsEditorPrivate::Action] = NULL;
// Set to remember which actions we have seen.
QSet<QAction*> actionsSeen;
// Add all categories in their own subtree below the collections root node
QList<KActionCategory*> categories = collection->findChildren<KActionCategory*>();
foreach (KActionCategory *category, categories) {
hier[KShortcutsEditorPrivate::Action] = d->findOrMakeItem(hier[KShortcutsEditorPrivate::Program], category->text());
foreach(QAction *action, category->actions()) {
// Set a marker that we have seen this action
actionsSeen.insert(action);
d->addAction(action, hier, KShortcutsEditorPrivate::Action);
}
}
// The rest of the shortcuts is added as a direct shild of the action
// collections root node
foreach (QAction *action, collection->actions()) {
if (actionsSeen.contains(action)) {
continue;
}
d->addAction(action, hier, KShortcutsEditorPrivate::Program);
}
// sort the list
d->ui.list->sortItems(Name, Qt::AscendingOrder);
// reenable updating
setUpdatesEnabled(true);
QTimer::singleShot(0, this, SLOT(resizeColumns()));
}
void KShortcutsEditor::clearConfiguration()
{
d->clearConfiguration();
}
void KShortcutsEditor::importConfiguration(KConfigBase *config)
{
d->importConfiguration(config);
}
void KShortcutsEditor::exportConfiguration(KConfigBase *config) const
@ -180,15 +110,13 @@ void KShortcutsEditor::exportConfiguration(KConfigBase *config) const
if (!config) return;
if (d->actionTypes & KShortcutsEditor::GlobalAction) {
QString groupName = "Global Shortcuts";
KConfigGroup group(config, groupName);
KConfigGroup group(config, "Global Shortcuts");
foreach (KActionCollection* collection, d->actionCollections) {
collection->exportGlobalShortcuts(&group, true);
}
}
if (d->actionTypes & ~KShortcutsEditor::GlobalAction) {
QString groupName = "Shortcuts";
KConfigGroup group(config, groupName);
KConfigGroup group(config, "Shortcuts");
foreach (KActionCollection* collection, d->actionCollections) {
collection->writeSettings(&group, true);
}
@ -197,406 +125,28 @@ void KShortcutsEditor::exportConfiguration(KConfigBase *config) const
void KShortcutsEditor::writeConfiguration(KConfigGroup *config) const
{
foreach (KActionCollection* collection, d->actionCollections)
foreach (KActionCollection* collection, d->actionCollections) {
collection->writeSettings(config);
}
}
//slot
void KShortcutsEditor::resizeColumns()
{
for (int i = 0; i < d->ui.list->columnCount(); i++)
d->ui.list->resizeColumnToContents(i);
}
void KShortcutsEditor::commit()
{
for (QTreeWidgetItemIterator it(d->ui.list); (*it); ++it) {
if (KShortcutsEditorItem* item = dynamic_cast<KShortcutsEditorItem*>(*it)) {
item->commit();
}
}
}
void KShortcutsEditor::save()
{
writeConfiguration();
// we have to call commit. If we wouldn't do that the changes would be
// undone on deletion! That would lead to weird problems. Changes to
// Global Shortcuts would vanish completely. Changes to local shortcuts
// would vanish for this session.
commit();
}
// KDE5 : rename to undo()
void KShortcutsEditor::undoChanges()
{
//This function used to crash sometimes when invoked by clicking on "cancel"
//with Qt 4.2.something. Apparently items were deleted too early by Qt.
//It seems to work with 4.3-ish Qt versions. Keep an eye on this.
for (QTreeWidgetItemIterator it(d->ui.list); (*it); ++it) {
if (KShortcutsEditorItem* item = dynamic_cast<KShortcutsEditorItem*>(*it)) {
item->undo();
}
}
}
//We ask the user here if there are any conflicts, as opposed to undoChanges().
//They don't do the same thing anyway, this just not to confuse any readers.
//slot
void KShortcutsEditor::allDefault()
{
d->allDefault();
}
void KShortcutsEditor::printShortcuts() const
{
d->printShortcuts();
}
//---------------------------------------------------------------------
// KShortcutsEditorPrivate
//---------------------------------------------------------------------
KShortcutsEditorPrivate::KShortcutsEditorPrivate(KShortcutsEditor *q)
: q(q),
delegate(0)
{
}
void KShortcutsEditorPrivate::initGUI(KShortcutsEditor::ActionTypes types,
KShortcutsEditor::LetterShortcuts allowLetterShortcuts)
{
actionTypes = types;
ui.setupUi(q);
q->layout()->setMargin(0);
ui.searchFilter->searchLine()->setTreeWidget(ui.list); // Plug into search line
ui.list->header()->setResizeMode(QHeaderView::ResizeToContents);
ui.list->header()->hideSection(GlobalAlternate); // not expected to be very useful
if (!(actionTypes & KShortcutsEditor::GlobalAction)) {
ui.list->header()->hideSection(GlobalPrimary);
} else if (!(actionTypes & ~KShortcutsEditor::GlobalAction)) {
ui.list->header()->hideSection(LocalPrimary);
ui.list->header()->hideSection(LocalAlternate);
}
// Create the Delegate. It is responsible for the KKeySeqeunceWidgets that
// really change the shortcuts.
delegate = new KShortcutsEditorDelegate(
ui.list,
allowLetterShortcuts == KShortcutsEditor::LetterShortcutsAllowed
);
ui.list->setItemDelegate(delegate);
ui.list->setSelectionBehavior(QAbstractItemView::SelectItems);
ui.list->setSelectionMode(QAbstractItemView::SingleSelection);
//we have our own editing mechanism
ui.list->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui.list->setAlternatingRowColors(true);
//TODO listen to changes to global shortcuts
QObject::connect(
delegate, SIGNAL(shortcutChanged(QVariant,QModelIndex)),
q, SLOT(capturedShortcut(QVariant,QModelIndex))
);
//hide the editor widget chen its item becomes hidden
QObject::connect(
ui.searchFilter->searchLine(), SIGNAL(hiddenChanged(QTreeWidgetItem*,bool)),
delegate, SLOT(hiddenBySearchLine(QTreeWidgetItem*,bool))
);
ui.searchFilter->setFocus();
}
bool KShortcutsEditorPrivate::addAction(QAction *action, QTreeWidgetItem *hier[], hierarchyLevel level)
{
// If the action name starts with unnamed- spit out a warning and ignore
// it. That name will change at will and will break loading and writing
QString actionName = action->objectName();
if (actionName.isEmpty() || actionName.startsWith(QLatin1String("unnamed-"))) {
kError() << "Skipping action without name " << action->text() << "," << actionName << "!";
return false;
}
// This code doesn't allow editing of QAction. It can not distinguish
// between default and active shortcuts. This breaks many assumptions the
// editor makes.
KAction *kact;
if ((kact = qobject_cast<KAction *>(action)) && kact->isShortcutConfigurable()) {
new KShortcutsEditorItem((hier[level]), kact);
return true;
}
return false;
}
void KShortcutsEditorPrivate::allDefault()
{
for (QTreeWidgetItemIterator it(ui.list); (*it); ++it) {
if (!(*it)->parent() || (*it)->type() != ActionItem) {
continue;
}
KShortcutsEditorItem *item = static_cast<KShortcutsEditorItem *>(*it);
KAction *act = item->m_action;
if (act->shortcut() != act->shortcut(KAction::DefaultShortcut)) {
changeKeyShortcut(item, LocalPrimary, act->shortcut(KAction::DefaultShortcut).primary());
changeKeyShortcut(item, LocalAlternate, act->shortcut(KAction::DefaultShortcut).alternate());
}
if (act->globalShortcut() != act->globalShortcut(KAction::DefaultShortcut)) {
changeKeyShortcut(item, GlobalPrimary, act->globalShortcut(KAction::DefaultShortcut).primary());
changeKeyShortcut(item, GlobalAlternate, act->globalShortcut(KAction::DefaultShortcut).alternate());
}
}
}
//static
KShortcutsEditorItem *KShortcutsEditorPrivate::itemFromIndex(QTreeWidget *const w,
const QModelIndex &index)
{
QTreeWidgetItem *item = static_cast<QTreeWidgetHack *>(w)->itemFromIndex(index);
if (item && item->type() == ActionItem) {
return static_cast<KShortcutsEditorItem *>(item);
}
return 0;
}
QTreeWidgetItem *KShortcutsEditorPrivate::findOrMakeItem(QTreeWidgetItem *parent, const QString &name)
{
for (int i = 0; i < parent->childCount(); i++) {
QTreeWidgetItem *child = parent->child(i);
if (child->text(0) == name) {
return child;
}
}
QTreeWidgetItem *ret = new QTreeWidgetItem(parent, NonActionItem);
ret->setText(0, name);
ui.list->expandItem(ret);
ret->setFlags(ret->flags() & ~Qt::ItemIsSelectable);
return ret;
}
//private slot
void KShortcutsEditorPrivate::capturedShortcut(const QVariant &newShortcut, const QModelIndex &index)
{
//dispatch to the right handler
if (!index.isValid()) {
return;
}
int column = index.column();
KShortcutsEditorItem *item = itemFromIndex(ui.list, index);
Q_ASSERT(item);
if (column >= LocalPrimary && column <= GlobalAlternate) {
changeKeyShortcut(item, column, newShortcut.value<QKeySequence>());
}
}
void KShortcutsEditorPrivate::changeKeyShortcut(KShortcutsEditorItem *item, uint column, const QKeySequence &capture)
{
// The keySequence we get is cleared by KKeySequenceWidget. No conflicts.
if (capture == item->keySequence(column)) {
return;
}
item->setKeySequence(column, capture);
q->keyChange();
//force view update
item->setText(column, capture.toString(QKeySequence::NativeText));
}
void KShortcutsEditorPrivate::clearConfiguration()
{
for (QTreeWidgetItemIterator it(ui.list); (*it); ++it) {
if (!(*it)->parent()) {
continue;
}
KShortcutsEditorItem *item = static_cast<KShortcutsEditorItem *>(*it);
changeKeyShortcut(item, LocalPrimary, QKeySequence());
changeKeyShortcut(item, LocalAlternate, QKeySequence());
changeKeyShortcut(item, GlobalPrimary, QKeySequence());
changeKeyShortcut(item, GlobalAlternate, QKeySequence());
}
}
void KShortcutsEditorPrivate::importConfiguration(KConfigBase *config)
{
Q_ASSERT(config);
if (!config) return;
KConfigGroup globalShortcutsGroup(config, QLatin1String("Global Shortcuts"));
if ((actionTypes & KShortcutsEditor::GlobalAction) && globalShortcutsGroup.exists()) {
for (QTreeWidgetItemIterator it(ui.list); (*it); ++it) {
if (!(*it)->parent()) {
continue;
}
KShortcutsEditorItem *item = static_cast<KShortcutsEditorItem *>(*it);
QString actionName = item->data(Id).toString();
KShortcut sc(globalShortcutsGroup.readEntry(actionName, QString()));
changeKeyShortcut(item, GlobalPrimary, sc.primary());
}
}
KConfigGroup localShortcutsGroup(config, QLatin1String("Shortcuts"));
if (actionTypes & ~KShortcutsEditor::GlobalAction) {
for (QTreeWidgetItemIterator it(ui.list); (*it); ++it) {
if (!(*it)->parent()) {
continue;
}
KShortcutsEditorItem *item = static_cast<KShortcutsEditorItem *>(*it);
QString actionName = item->data(Name).toString();
KShortcut sc(localShortcutsGroup.readEntry(actionName, QString()));
changeKeyShortcut(item, LocalPrimary, sc.primary());
changeKeyShortcut(item, LocalAlternate, sc.alternate());
}
}
}
/*TODO for the printShortcuts function
Nice to have features (which I'm not sure I can do before may due to
more important things):
- adjust the general page borders, IMHO they're too wide
- add a custom printer options page that allows to filter out all
actions that don't have a shortcut set to reduce this list. IMHO this
should be optional as people might want to simply print all and when
they find a new action that they assign a shortcut they can simply use
a pen to fill out the empty space
- find a way to align the Main/Alternate/Global entries in the shortcuts
column without adding borders. I first did this without a nested table
but instead simply added 3 rows and merged the 3 cells in the Action
name and description column, but unfortunately I didn't find a way to
remove the borders between the 6 shortcut cells.
*/
void KShortcutsEditorPrivate::printShortcuts() const
{
// One cant print on wince
QTreeWidgetItem* root = ui.list->invisibleRootItem();
QTextDocument doc;
doc.setDefaultFont(KGlobalSettings::generalFont());
QTextCursor cursor(&doc);
cursor.beginEditBlock();
QTextCharFormat headerFormat;
headerFormat.setProperty(QTextFormat::FontSizeAdjustment, 3);
headerFormat.setFontWeight(QFont::Bold);
cursor.insertText(
i18nc(
"header for an applications shortcut list","Shortcuts for %1",
KGlobal::mainComponent().aboutData()->programName()
),
headerFormat
);
QTextCharFormat componentFormat;
componentFormat.setProperty(QTextFormat::FontSizeAdjustment, 2);
componentFormat.setFontWeight(QFont::Bold);
QTextBlockFormat componentBlockFormat = cursor.blockFormat();
componentBlockFormat.setTopMargin(16);
componentBlockFormat.setBottomMargin(16);
QTextTableFormat tableformat;
tableformat.setHeaderRowCount(1);
tableformat.setCellPadding(4.0);
tableformat.setCellSpacing(0);
tableformat.setBorderStyle(QTextFrameFormat::BorderStyle_Solid);
tableformat.setBorder(0.5);
QList<QPair<QString,ColumnDesignation> > shortcutTitleToColumn;
shortcutTitleToColumn << qMakePair(i18n("Main:"), LocalPrimary);
shortcutTitleToColumn << qMakePair(i18n("Alternate:"), LocalAlternate);
shortcutTitleToColumn << qMakePair(i18n("Global:"), GlobalPrimary);
for (int i = 0; i < root->childCount(); i++) {
QTreeWidgetItem* item = root->child(i);
cursor.insertBlock(componentBlockFormat, componentFormat);
cursor.insertText(item->text(0));
QTextTable* table = cursor.insertTable(1,3);
table->setFormat(tableformat);
int currow = 0;
QTextTableCell cell = table->cellAt(currow,0);
QTextCharFormat format = cell.format();
format.setFontWeight(QFont::Bold);
cell.setFormat(format);
cell.firstCursorPosition().insertText(i18n("Action Name"));
cell = table->cellAt(currow,1);
cell.setFormat(format);
cell.firstCursorPosition().insertText(i18n("Shortcuts"));
cell = table->cellAt(currow,2);
cell.setFormat(format);
cell.firstCursorPosition().insertText(i18n("Description"));
currow++;
for (QTreeWidgetItemIterator it(item); *it; ++it) {
if ((*it)->type() != ActionItem) {
continue;
}
KShortcutsEditorItem* editoritem = static_cast<KShortcutsEditorItem*>(*it);
table->insertRows(table->rows(),1);
QVariant data = editoritem->data(Name,Qt::DisplayRole);
table->cellAt(currow, 0).firstCursorPosition().insertText(data.toString());
QTextTable* shortcutTable = 0 ;
for(int k = 0; k < shortcutTitleToColumn.count(); k++) {
data = editoritem->data(shortcutTitleToColumn.at(k).second,Qt::DisplayRole);
QString key = data.value<QKeySequence>().toString();
if(!key.isEmpty()) {
if (!shortcutTable) {
shortcutTable = table->cellAt(currow, 1).firstCursorPosition().insertTable(1,2);
QTextTableFormat shortcutTableFormat = tableformat;
shortcutTableFormat.setCellSpacing(0.0);
shortcutTableFormat.setHeaderRowCount(0);
shortcutTableFormat.setBorder(0.0);
shortcutTable->setFormat(shortcutTableFormat);
} else {
shortcutTable->insertRows(shortcutTable->rows(),1);
}
shortcutTable->cellAt(shortcutTable->rows()-1,0).firstCursorPosition().insertText(shortcutTitleToColumn.at(k).first);
shortcutTable->cellAt(shortcutTable->rows()-1,1).firstCursorPosition().insertText(key);
}
}
KAction* action = editoritem->m_action;
cell = table->cellAt(currow, 2);
format = cell.format();
format.setProperty(QTextFormat::FontSizeAdjustment, -1);
cell.setFormat(format);
cell.firstCursorPosition().insertHtml(action->whatsThis());
currow++;
}
cursor.movePosition(QTextCursor::End);
}
cursor.endEditBlock();
QPrinter printer;
QPrintDialog *dlg = KdePrint::createPrintDialog(&printer, q);
if (dlg->exec() == QDialog::Accepted) {
doc.print(&printer);
}
delete dlg;
}
#include "moc_kshortcutseditor.cpp"

View file

@ -34,7 +34,6 @@ class KConfig;
class KConfigBase;
class KConfigGroup;
class KGlobalAccel;
class KShortcut;
class KShortcutsEditorPrivate;
// KShortcutsEditor expects that the list of existing shortcuts is already
@ -191,7 +190,7 @@ public:
* Import the settings from configuration @p config.
*
* This will remove all current setting before importing. All shortcuts
* are set to KShortcut() prior to importing from @p config!
* are set to QKeySequence() prior to importing from @p config!
*
* @param config Config object
*/
@ -204,24 +203,11 @@ Q_SIGNALS:
void keyChange();
public Q_SLOTS:
/**
* Resize columns to width required
*/
void resizeColumns();
/**
* Set all shortcuts to their default values (bindings).
**/
void allDefault();
/**
* Opens a printing dialog to print all the shortcuts
*/
void printShortcuts() const;
private:
Q_PRIVATE_SLOT(d, void capturedShortcut(QVariant, const QModelIndex &))
private:
friend class KShortcutsDialog;
friend class KShortcutsEditorPrivate;

View file

@ -1,326 +0,0 @@
/* This file is part of the KDE libraries
Copyright (C) 1998 Mark Donohoe <donohoe@kde.org>
Copyright (C) 1997 Nicolas Hadacek <hadacek@kde.org>
Copyright (C) 1998 Matthias Ettrich <ettrich@kde.org>
Copyright (C) 2001 Ellis Whitehead <ellis@kde.org>
Copyright (C) 2006 Hamish Rodda <rodda@kde.org>
Copyright (C) 2007 Roberto Raggi <roberto@kdevelop.org>
Copyright (C) 2007 Andreas Hartmetz <ahartmetz@gmail.com>
Copyright (C) 2008 Michael Jansen <kde@michael-jansen.biz>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "kshortcutsdialog_p.h"
#include "kaction_p.h"
#include <QApplication>
#include <QHeaderView>
#include <QtGui/qevent.h>
#include <QLabel>
#include <QPainter>
#include <QTreeWidgetItemIterator>
#include "kaction.h"
#include "kdebug.h"
KShortcutsEditorDelegate::KShortcutsEditorDelegate(QTreeWidget *parent, bool allowLetterShortcuts)
: KExtendableItemDelegate(parent),
m_allowLetterShortcuts(allowLetterShortcuts),
m_editor(0)
{
Q_ASSERT(qobject_cast<QAbstractItemView *>(parent));
QPixmap pixmap( 16, 16 );
pixmap.fill( QColor( Qt::transparent ) );
QPainter p( &pixmap );
QStyleOption option;
option.rect = pixmap.rect();
bool isRtl = QApplication::isRightToLeft();
QApplication::style()->drawPrimitive( isRtl ? QStyle::PE_IndicatorArrowLeft : QStyle::PE_IndicatorArrowRight, &option, &p );
p.end();
setExtendPixmap( pixmap );
pixmap.fill( QColor( Qt::transparent ) );
p.begin( &pixmap );
QApplication::style()->drawPrimitive( QStyle::PE_IndicatorArrowDown, &option, &p );
p.end();
setContractPixmap( pixmap );
parent->installEventFilter(this);
// Listen to activation signals
// connect(parent, SIGNAL(activated(QModelIndex)), this, SLOT(itemActivated(QModelIndex)));
connect(parent, SIGNAL(clicked(QModelIndex)), this, SLOT(itemActivated(QModelIndex)));
// Listen to collapse signals
connect(parent, SIGNAL(collapsed(QModelIndex)), this, SLOT(itemCollapsed(QModelIndex)));
}
void KShortcutsEditorDelegate::stealShortcut(
const QKeySequence &seq,
KAction *action)
{
QTreeWidget *view = static_cast<QTreeWidget *>(parent());
// Iterate over all items
QTreeWidgetItemIterator it(view, QTreeWidgetItemIterator::NoChildren);
for (; (*it); ++it) {
KShortcutsEditorItem* item = dynamic_cast<KShortcutsEditorItem *>(*it);
if (item && item->data(0, ObjectRole).value<QObject*>() == action) {
// We found the action, snapshot the current state. Steal the
// shortcut. We will save the change later.
KShortcut cut = action->shortcut();
if ( cut.primary().matches(seq) != QKeySequence::NoMatch
|| seq.matches(cut.primary()) != QKeySequence::NoMatch) {
item->setKeySequence(LocalPrimary, QKeySequence());
}
if ( cut.alternate().matches(seq) != QKeySequence::NoMatch
|| seq.matches(cut.alternate()) != QKeySequence::NoMatch) {
item->setKeySequence(LocalAlternate, QKeySequence());
}
break;
}
}
}
QSize KShortcutsEditorDelegate::sizeHint(const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
QSize ret(KExtendableItemDelegate::sizeHint(option, index));
ret.rheight() += 4;
return ret;
}
//slot
void KShortcutsEditorDelegate::itemActivated(QModelIndex index)
{
//As per our constructor our parent *is* a QTreeWidget
QTreeWidget *view = static_cast<QTreeWidget *>(parent());
KShortcutsEditorItem *item = KShortcutsEditorPrivate::itemFromIndex(view, index);
if (!item) {
//that probably was a non-leaf (type() !=ActionItem) item
return;
}
int column = index.column();
if (column == Name) {
// If user click in the name column activate the (Global|Local)Primary
// column if possible.
if (!view->header()->isSectionHidden(LocalPrimary)) {
column = LocalPrimary;
} else if (!view->header()->isSectionHidden(GlobalPrimary)) {
column = GlobalPrimary;
} else {
// do nothing.
}
index = index.sibling(index.row(), column);
view->selectionModel()->select(index, QItemSelectionModel::SelectCurrent);
}
// Check if the models wants us to edit the item at index
if (!index.data(ShowExtensionIndicatorRole).value<bool>()) {
return;
}
if (!isExtended(index)) {
//we only want maximum ONE extender open at any time.
if (m_editingIndex.isValid()) {
KShortcutsEditorItem *oldItem = KShortcutsEditorPrivate::itemFromIndex(view,
m_editingIndex);
Q_ASSERT(oldItem); //here we really expect nothing but a real KShortcutsEditorItem
oldItem->setNameBold(false);
contractItem(m_editingIndex);
}
m_editingIndex = index;
QWidget *viewport = static_cast<QAbstractItemView*>(parent())->viewport();
if (column >= LocalPrimary && column <= GlobalAlternate) {
ShortcutEditWidget *editor = new ShortcutEditWidget(viewport,
index.data(DefaultShortcutRole).value<QKeySequence>(),
index.data(ShortcutRole).value<QKeySequence>(),
m_allowLetterShortcuts);
if (column==GlobalPrimary) {
QObject *action = index.data(ObjectRole).value<QObject*>();
connect(
action, SIGNAL(globalShortcutChanged(QKeySequence)),
editor, SLOT(setKeySequence(QKeySequence)));
editor->setMultiKeyShortcutsAllowed(false);
KAction *kaction = qobject_cast<KAction*>(action);
if (kaction) {
editor->setComponentName(kaction->d->componentData.componentName());
}
}
m_editor = editor;
// For global shortcuts check against the kde standard shortcuts
if (column == GlobalPrimary || column == GlobalAlternate) {
editor->setCheckForConflictsAgainst(
KKeySequenceWidget::LocalShortcuts
| KKeySequenceWidget::GlobalShortcuts
| KKeySequenceWidget::StandardShortcuts );
}
editor->setCheckActionCollections(m_checkActionCollections);
connect(m_editor, SIGNAL(keySequenceChanged(QKeySequence)),
this, SLOT(keySequenceChanged(QKeySequence)));
connect(m_editor, SIGNAL(stealShortcut(QKeySequence,KAction*)),
this, SLOT(stealShortcut(QKeySequence,KAction*)));
} else
return;
m_editor->installEventFilter(this);
item->setNameBold(true);
extendItem(m_editor, index);
} else {
//the item is extended, and clicking on it again closes it
item->setNameBold(false);
contractItem(index);
view->selectionModel()->select(index, QItemSelectionModel::Clear);
m_editingIndex = QModelIndex();
m_editor = 0;
}
}
//slot
void KShortcutsEditorDelegate::itemCollapsed(QModelIndex index)
{
if (!m_editingIndex.isValid()) {
return;
}
const QAbstractItemModel *model = index.model();
for (int row = 0; row < model->rowCount(index); ++row) {
QModelIndex rowIndex = model->index(row, 0, index);
for (int col = 0; col < index.model()->columnCount(index); ++col) {
QModelIndex colIndex = model->index(row, col, index);
if (colIndex == m_editingIndex) {
itemActivated(m_editingIndex); //this will *close* the item's editor because it's already open
}
}
}
}
//slot
void KShortcutsEditorDelegate::hiddenBySearchLine(QTreeWidgetItem *item, bool hidden)
{
if (!hidden || !item) {
return;
}
QTreeWidget *view = static_cast<QTreeWidget *>(parent());
QTreeWidgetItem *editingItem = KShortcutsEditorPrivate::itemFromIndex(view, m_editingIndex);
if (editingItem == item) {
itemActivated(m_editingIndex); //this will *close* the item's editor because it's already open
}
}
bool KShortcutsEditorDelegate::eventFilter(QObject *o, QEvent *e)
{
if (o == m_editor) {
//Prevent clicks in the empty part of the editor widget from closing the editor
//because they would propagate to the itemview and be interpreted as a click in
//an item's rect. That in turn would lead to an itemActivated() call, closing
//the current editor.
switch (e->type()) {
case QEvent::MouseButtonPress:
case QEvent::MouseButtonRelease:
case QEvent::MouseButtonDblClick:
return true;
default:
return false;
}
} else if (o == parent()) {
// Make left/right cursor keys switch items instead of operate the scroll bar
// (subclassing QtreeView/Widget would be cleaner but much more of a hassle)
// Note that in our case we know that the selection mode is SingleSelection,
// so we don't have to ask QAbstractItemView::selectionCommand() et al.
if (e->type() != QEvent::KeyPress) {
return false;
}
QKeyEvent *ke = static_cast<QKeyEvent *>(e);
QTreeWidget *view = static_cast<QTreeWidget *>(parent());
QItemSelectionModel *selection = view->selectionModel();
QModelIndex index = selection->currentIndex();
switch (ke->key()) {
case Qt::Key_Space:
case Qt::Key_Select:
// we are not using the standard "open editor" mechanism of QAbstractItemView,
// so let's emulate that here.
itemActivated(index);
return true;
case Qt::Key_Left:
index = index.sibling(index.row(), index.column() - 1);
break;
case Qt::Key_Right:
index = index.sibling(index.row(), index.column() + 1);
break;
default:
return false;
}
// a cursor key was pressed
if (index.isValid()) {
selection->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect);
//### using PositionAtCenter for now;
// EnsureVisible has no effect which seems to be a bug.
view->scrollTo(index, QAbstractItemView::PositionAtCenter);
}
return true;
}
return false;
}
//slot
void KShortcutsEditorDelegate::keySequenceChanged(const QKeySequence &seq)
{
QVariant ret = QVariant::fromValue(seq);
emit shortcutChanged(ret, m_editingIndex);
}
void KShortcutsEditorDelegate::setCheckActionCollections(
const QList<KActionCollection*> checkActionCollections )
{
m_checkActionCollections = checkActionCollections;
}

View file

@ -1,292 +0,0 @@
/* This file is part of the KDE libraries Copyright (C) 1998 Mark Donohoe <donohoe@kde.org>
Copyright (C) 1997 Nicolas Hadacek <hadacek@kde.org>
Copyright (C) 1998 Matthias Ettrich <ettrich@kde.org>
Copyright (C) 2001 Ellis Whitehead <ellis@kde.org>
Copyright (C) 2006 Hamish Rodda <rodda@kde.org>
Copyright (C) 2007 Roberto Raggi <roberto@kdevelop.org>
Copyright (C) 2007 Andreas Hartmetz <ahartmetz@gmail.com>
Copyright (C) 2008 Michael Jansen <kde@michael-jansen.biz>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "kshortcutsdialog_p.h"
#include <kaction.h>
#include <kdebug.h>
#include <kstringhandler.h>
#include <klocale.h>
#include <kicon.h>
#include <kglobal.h>
#include <QtGui/qtreewidget.h>
KShortcutsEditorItem::KShortcutsEditorItem(QTreeWidgetItem *parent, KAction *action)
: QTreeWidgetItem(parent, ActionItem),
m_action(action),
m_isNameBold(false),
m_oldLocalShortcut(0),
m_oldGlobalShortcut(0)
{
// Filtering message requested by translators (scripting).
m_id = m_action->objectName();
m_actionNameInTable = i18nc("@item:intable Action name in shortcuts configuration", "%1", KGlobal::locale()->removeAcceleratorMarker(m_action->text()));
if (m_actionNameInTable.isEmpty()) {
kWarning() << "Action without text!" << m_action->objectName();
m_actionNameInTable = m_id;
}
}
KShortcutsEditorItem::~KShortcutsEditorItem()
{
delete m_oldLocalShortcut;
delete m_oldGlobalShortcut;
}
bool KShortcutsEditorItem::isModified() const
{
return m_oldLocalShortcut || m_oldGlobalShortcut;
}
QVariant KShortcutsEditorItem::data(int column, int role) const
{
switch (role) {
case Qt::DisplayRole:
switch(column) {
case Name:
return m_actionNameInTable;
case Id:
return m_id;
case LocalPrimary:
case LocalAlternate:
case GlobalPrimary:
case GlobalAlternate:
return keySequence(column);
default:
break;
}
break;
case Qt::DecorationRole:
if (column == Name)
return m_action->icon();
else
return KIcon();
break;
case Qt::WhatsThisRole:
return m_action->whatsThis();
case Qt::ToolTipRole:
// There is no such thing as a KAction::description(). So we have
// nothing to display here.
return QVariant();
case Qt::FontRole:
if (column == Name && m_isNameBold) {
QFont modifiedFont = treeWidget()->font();
modifiedFont.setBold(true);
return modifiedFont;
}
break;
case KExtendableItemDelegate::ShowExtensionIndicatorRole:
switch (column) {
case Name:
return false;
case LocalPrimary:
case LocalAlternate:
if (!m_action->isShortcutConfigurable()) {
return false;
}
return true;
case GlobalPrimary:
case GlobalAlternate:
if (!m_action->isGlobalShortcutEnabled()) {
return false;
}
return true;
default:
return false;
}
//the following are custom roles, defined in this source file only
case ShortcutRole:
switch(column) {
case LocalPrimary:
case LocalAlternate:
case GlobalPrimary:
case GlobalAlternate:
return keySequence(column);
default:
// Column not valid for this role
Q_ASSERT(false);
return QVariant();
}
case DefaultShortcutRole:
switch(column) {
case LocalPrimary:
return m_action->shortcut(KAction::DefaultShortcut).primary();
case LocalAlternate:
return m_action->shortcut(KAction::DefaultShortcut).alternate();
case GlobalPrimary:
return m_action->globalShortcut(KAction::DefaultShortcut).primary();
case GlobalAlternate:
return m_action->globalShortcut(KAction::DefaultShortcut).alternate();
default:
// Column not valid for this role
Q_ASSERT(false);
return QVariant();
}
case ObjectRole:
return qVariantFromValue((QObject*)m_action);
default:
break;
}
return QVariant();
}
bool KShortcutsEditorItem::operator<(const QTreeWidgetItem &other) const
{
const int column = treeWidget() ? treeWidget()->sortColumn() : 0;
return KStringHandler::naturalCompare(text(column), other.text(column)) < 0;
}
QKeySequence KShortcutsEditorItem::keySequence(uint column) const
{
switch (column) {
case LocalPrimary:
return m_action->shortcut().primary();
case LocalAlternate:
return m_action->shortcut().alternate();
case GlobalPrimary:
return m_action->globalShortcut().primary();
case GlobalAlternate:
return m_action->globalShortcut().alternate();
default:
return QKeySequence();
}
}
void KShortcutsEditorItem::setKeySequence(uint column, const QKeySequence &seq)
{
KShortcut ks;
if (column == GlobalPrimary || column == GlobalAlternate) {
ks = m_action->globalShortcut();
if (!m_oldGlobalShortcut)
m_oldGlobalShortcut = new KShortcut(ks);
} else {
ks = m_action->shortcut();
if (!m_oldLocalShortcut)
m_oldLocalShortcut = new KShortcut(ks);
}
if (column == LocalAlternate || column == GlobalAlternate)
ks.setAlternate(seq);
else
ks.setPrimary(seq);
//avoid also setting the default shortcut - what we are setting here is custom by definition
if (column == GlobalPrimary || column == GlobalAlternate) {
m_action->setGlobalShortcut(ks, KAction::ActiveShortcut);
} else {
m_action->setShortcut(ks, KAction::ActiveShortcut);
}
updateModified();
}
//our definition of modified is "modified since the chooser was shown".
void KShortcutsEditorItem::updateModified()
{
if (m_oldLocalShortcut && *m_oldLocalShortcut == m_action->shortcut()) {
delete m_oldLocalShortcut;
m_oldLocalShortcut = 0;
}
if (m_oldGlobalShortcut && *m_oldGlobalShortcut == m_action->globalShortcut()) {
delete m_oldGlobalShortcut;
m_oldGlobalShortcut = 0;
}
}
bool KShortcutsEditorItem::isModified(uint column) const
{
switch (column) {
case Name:
return false;
case LocalPrimary:
case LocalAlternate:
if (!m_oldLocalShortcut) {
return false;
}
if (column == LocalPrimary) {
return m_oldLocalShortcut->primary() != m_action->shortcut().primary();
}
return m_oldLocalShortcut->alternate() != m_action->shortcut().alternate();
case GlobalPrimary:
case GlobalAlternate:
if (!m_oldGlobalShortcut) {
return false;
}
if (column == GlobalPrimary) {
return m_oldGlobalShortcut->primary() != m_action->globalShortcut().primary();
}
return m_oldGlobalShortcut->alternate() != m_action->globalShortcut().alternate();
default:
return false;
}
}
void KShortcutsEditorItem::undo()
{
#ifndef NDEBUG
if (m_oldLocalShortcut || m_oldGlobalShortcut) {
kDebug(125) << "Undoing changes for " << data(Name, Qt::DisplayRole).toString();
}
#endif
if (m_oldLocalShortcut) {
// We only ever reset the active Shortcut
m_action->setShortcut(*m_oldLocalShortcut, KAction::ActiveShortcut);
}
if (m_oldGlobalShortcut) {
m_action->setGlobalShortcut(*m_oldGlobalShortcut, KAction::ActiveShortcut);
}
updateModified();
}
void KShortcutsEditorItem::commit()
{
#ifndef NDEBUG
if (m_oldLocalShortcut || m_oldGlobalShortcut) {
kDebug(125) << "Committing changes for " << data(Name, Qt::DisplayRole).toString();
}
#endif
delete m_oldLocalShortcut;
m_oldLocalShortcut = 0;
delete m_oldGlobalShortcut;
m_oldGlobalShortcut = 0;
}

View file

@ -19,9 +19,15 @@
Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "kcheckaccelerators.h"
#include <config.h>
#include "kconfig.h"
#include "kglobal.h"
#include "kcomponentdata.h"
#include "klocale.h"
#include "kacceleratormanager.h"
#include "kconfiggroup.h"
#include "kdebug.h"
#include <QApplication>
#include <QCheckBox>
@ -40,25 +46,15 @@
#include <QProcess>
#include <QTextBrowser>
#include <kconfig.h>
#include <kdebug.h>
#include <kglobal.h>
#include <kcomponentdata.h>
#include <klocale.h>
#include <kshortcut.h>
#include "kacceleratormanager.h"
#include <kconfiggroup.h>
void KCheckAccelerators::initiateIfNeeded(QObject* parent)
{
KConfigGroup cg( KGlobal::config(), "Development" );
QString sKey = cg.readEntry( "CheckAccelerators" ).trimmed();
int key=0;
if( !sKey.isEmpty() ) {
KShortcut cuts( sKey );
QKeySequence cuts( sKey );
if( !cuts.isEmpty() )
key = cuts.primary()[0];
key = cuts[0];
}
bool autoCheck = cg.readEntry( "AutoCheckAccelerators", true );
bool copyWidgetText = cg.readEntry( "CopyWidgetText", false );

View file

@ -168,10 +168,11 @@ void KGlobalAccelPrivate::updateGlobalShortcut(KAction *action)
void KGlobalAccelPrivate::doRegister(KAction *action)
{
foreach (const QKeySequence &keysequnece, action->globalShortcut().toList()) {
const QKeySequence keysequence = action->globalShortcut();
for (int i = 0; i < keysequence.count(); i++) {
uint keyModX = 0;
int keyCodeX = 0;
if (kGrabKey(keysequnece, keyModX, keyCodeX)) {
if (kGrabKey(keysequence[i], keyModX, keyCodeX)) {
KGlobalAccelStruct shortcut;
shortcut.action = action;
shortcut.keyModX = keyModX;
@ -180,7 +181,7 @@ void KGlobalAccelPrivate::doRegister(KAction *action)
kDebug() << "grabbed shortcut" << shortcut.keyModX << shortcut.keyCodeX << shortcut.action;
break;
} else {
kWarning() << "could not grab shortcut" << keysequnece << action;
kWarning() << "could not grab shortcut" << keysequence[i] << action;
}
}
}
@ -221,7 +222,7 @@ QList<KGlobalShortcutInfo> KGlobalAccel::getGlobalShortcutsByKey(const QKeySeque
{
QList<KGlobalShortcutInfo> result;
foreach (const KGlobalAccelStruct &shortcut, d->filter->shortcuts) {
if (shortcut.action->globalShortcut().contains(seq)) {
if (shortcut.action->globalShortcut().matches(seq) != QKeySequence::NoMatch) {
KGlobalShortcutInfo globalshortcutinfo;
globalshortcutinfo.componentFriendlyName = shortcut.action->d->componentData.aboutData()->programName();
globalshortcutinfo.friendlyName = KGlobal::locale()->removeAcceleratorMarker(shortcut.action->text());
@ -235,7 +236,7 @@ QList<KGlobalShortcutInfo> KGlobalAccel::getGlobalShortcutsByKey(const QKeySeque
bool KGlobalAccel::isGlobalShortcutAvailable(const QKeySequence &seq, const QString &comp)
{
foreach (const KGlobalAccelStruct &shortcut, d->filter->shortcuts) {
if (shortcut.action->globalShortcut().conflictsWith(seq)) {
if (shortcut.action->globalShortcut().matches(seq) != QKeySequence::NoMatch) {
return false;
}
}
@ -245,7 +246,7 @@ bool KGlobalAccel::isGlobalShortcutAvailable(const QKeySequence &seq, const QStr
void KGlobalAccel::stealShortcutSystemwide(const QKeySequence &seq)
{
foreach (const KGlobalAccelStruct &shortcut, d->filter->shortcuts) {
if (shortcut.action->globalShortcut().conflictsWith(seq)) {
if (shortcut.action->globalShortcut().matches(seq) != QKeySequence::NoMatch) {
d->remove(shortcut.action);
break;
}

View file

@ -1,273 +0,0 @@
/* This file is part of the KDE libraries
Copyright (C) 2001,2002 Ellis Whitehead <ellis@kde.org>
Copyright (C) 2006 Hamish Rodda <rodda@kde.org>
Copyright (C) 2006 Andreas Hartmetz <ahartmetz@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "kshortcut.h"
#include <QtGui/qevent.h>
#include <QtGui/QKeySequence>
#include <QtCore/qstring.h>
#include <QtCore/qstringlist.h>
#include "kdebug.h"
#include "kglobal.h"
#include "klocale.h"
class KShortcutPrivate
{
public:
KShortcutPrivate() {}
QKeySequence primary;
QKeySequence alternate;
};
KShortcut::KShortcut()
: d(new KShortcutPrivate())
{
qRegisterMetaType<KShortcut>();
}
KShortcut::KShortcut(const QKeySequence &primary)
: d(new KShortcutPrivate())
{
qRegisterMetaType<KShortcut>();
d->primary = primary;
}
KShortcut::KShortcut(const QKeySequence &primary, const QKeySequence &alternate)
: d(new KShortcutPrivate())
{
qRegisterMetaType<KShortcut>();
d->primary = primary;
d->alternate = alternate;
}
KShortcut::KShortcut(int keyQtPri, int keyQtAlt)
: d(new KShortcutPrivate())
{
qRegisterMetaType<KShortcut>();
d->primary = keyQtPri;
d->alternate = keyQtAlt;
}
KShortcut::KShortcut(const KShortcut &other)
: d(new KShortcutPrivate())
{
d->primary = other.d->primary;
d->alternate = other.d->alternate;
}
KShortcut::KShortcut(const QList<QKeySequence> &seqs)
: d(new KShortcutPrivate())
{
qRegisterMetaType<KShortcut>();
if (seqs.count() >= 1) {
d->primary = seqs.at(0);
}
if (seqs.count() >= 2) {
d->alternate = seqs.at(1);
}
}
KShortcut::KShortcut(const QString &s)
: d(new KShortcutPrivate)
{
qRegisterMetaType<KShortcut>();
if (s == QLatin1String("none")) {
return;
}
QStringList sCuts = s.split("; ");
if (sCuts.count() > 2) {
kWarning() << "asked to store more than two key sequences but can only hold two.";
}
//TODO: what is the "(default)" thingie used for?
for (int i = 0; i < sCuts.count(); i++) {
if (sCuts[i].startsWith(QLatin1String("default("))) {
sCuts[i] = sCuts[i].mid(8, sCuts[i].length() - 9);
}
}
if (sCuts.count() >= 1) {
QString k = sCuts.at(0);
d->primary = QKeySequence::fromString(k);
// Complain about a unusable shortcuts sequence only if we have got
// something.
if (d->primary.isEmpty() && !k.isEmpty()) {
kDebug() << "unusable primary shortcut sequence " << sCuts[0];
}
}
if (sCuts.count() >= 2) {
d->alternate = QKeySequence::fromString(sCuts.at(1));
if (d->alternate.isEmpty()) {
kDebug() << "unusable alternate shortcut sequence " << sCuts[1];
}
}
}
KShortcut::~KShortcut()
{
delete d;
}
QKeySequence KShortcut::primary() const
{
return d->primary;
}
QKeySequence KShortcut::alternate() const
{
return d->alternate;
}
bool KShortcut::isEmpty() const
{
return d->primary.isEmpty() && d->alternate.isEmpty();
}
bool KShortcut::contains(const QKeySequence &needle) const
{
if (needle.isEmpty())
return false;
return d->primary == needle || d->alternate == needle;
}
bool KShortcut::conflictsWith(const QKeySequence &needle) const
{
if (needle.isEmpty()) {
return false;
}
bool primaryConflicts = false;
bool alternateConflicts = false;
if (!d->primary.isEmpty()) {
primaryConflicts =
(d->primary.matches(needle) == QKeySequence::NoMatch
&& needle.matches(d->primary) == QKeySequence::NoMatch)
? false
: true;
}
if (!d->alternate.isEmpty()) {
alternateConflicts=
(d->alternate.matches(needle) == QKeySequence::NoMatch
&& needle.matches(d->alternate) == QKeySequence::NoMatch )
? false
: true;
}
return primaryConflicts || alternateConflicts;
}
void KShortcut::setPrimary(const QKeySequence &newPrimary)
{
d->primary = newPrimary;
}
void KShortcut::setAlternate(const QKeySequence &newAlternate)
{
d->alternate = newAlternate;
}
void KShortcut::remove(const QKeySequence &keySeq, enum EmptyHandling handleEmpty)
{
if (keySeq.isEmpty()) {
return;
}
if (d->primary == keySeq) {
if (handleEmpty == KeepEmpty) {
d->primary = QKeySequence();
} else {
d->primary = d->alternate;
d->alternate = QKeySequence();
}
}
if (d->alternate == keySeq) {
d->alternate = QKeySequence();
}
}
KShortcut &KShortcut::operator=(const KShortcut &other)
{
d->primary = other.d->primary;
d->alternate = other.d->alternate;
return *this;
}
bool KShortcut::operator==(const KShortcut &other) const
{
return (d->primary == other.d->primary && d->alternate == other.d->alternate);
}
bool KShortcut::operator!=(const KShortcut &other) const
{
return !operator==(other);
}
KShortcut::operator QList<QKeySequence>() const
{
return toList(RemoveEmpty);
}
QList<QKeySequence> KShortcut::toList(enum EmptyHandling handleEmpty) const
{
QList<QKeySequence> ret;
if (handleEmpty == RemoveEmpty) {
if (!d->primary.isEmpty()) {
ret.append(d->primary);
}
if (!d->alternate.isEmpty()) {
ret.append(d->alternate);
}
} else {
ret.append(d->primary);
ret.append(d->alternate);
}
return ret;
}
QString KShortcut::toString() const
{
return toString(QKeySequence::PortableText);
}
QString KShortcut::toString(QKeySequence::SequenceFormat format) const
{
QString ret;
foreach(const QKeySequence &seq, toList()) {
ret.append(seq.toString(format));
ret.append("; ");
}
ret.chop(2);
return ret;
}
KShortcut::operator QVariant() const
{
return qVariantFromValue(*this);
}

View file

@ -1,261 +0,0 @@
/* This file is part of the KDE libraries
Copyright (C) 2001,2002 Ellis Whitehead <ellis@kde.org>
Copyright (C) 2006 Hamish Rodda <rodda@kde.org>
Copyright (C) 2006 Andreas Hartmetz <ahartmetz@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
/**
* @file kshortcut.h
* Defines platform-independent classes for keyboard shortcut handling.
*/
#ifndef KSHORTCUT_H
#define KSHORTCUT_H
#include <kdeui_export.h>
#include <QtCore/QMetaType>
#include <QtCore/QHash>
#include <QtGui/QKeySequence>
class KShortcutPrivate;
/**
* @short Represents a keyboard shortcut
*
* The KShortcut class is used to represent a keyboard shortcut to an action.
* A shortcut is normally a single key with modifiers, such as Ctrl+V.
* A KShortcut object may also contain an alternate key sequence which will also
* activate the action it's associated with, as long as no other actions have
* defined that key as their primary key. Ex: Ctrl+V;Shift+Insert.
*
* This can be used to add additional accelerators to a KAction. For example,
* the below code binds the escape key to the close action.
*
* \code
* KAction *closeAction = KStandardAction::close(this, SLOT( close() ), actionCollection());
* KShortcut closeShortcut = closeAction->shortcut();
* closeShortcut.setAlternate(Qt::Key_Escape);
* closeAction->setShortcut(closeShortcut);
* \endcode
*/
class KDEUI_EXPORT KShortcut
{
public:
/**
* An enum about the behavior of operations that treat a KShortcut like a list of QKeySequences.
*/
enum EmptyHandling {
///if a shortcut is or becomes empty, let it stay as a placeholder
KeepEmpty = 0,
///remove empty QKeySequences, possibly changing the positions of QKeySequences due to the ensuing reshuffling.
RemoveEmpty
};
/**
* Creates a new empty shortcut.
* @see isEmpty()
* @see clear()
*/
KShortcut();
/**
* Creates a new shortcut that contains the given Qt key
* sequence as primary shortcut.
* @param primary Qt key sequence to add
*/
explicit KShortcut(const QKeySequence &primary);
/**
* Creates a new shortcut with the given Qt key sequences
* as primary and secondary shortcuts.
* @param primary Qt keycode of primary shortcut
* @param alternate Qt keycode of alternate shortcut
* @see Qt::Key
*/
KShortcut(const QKeySequence &primary, const QKeySequence &alternate);
/**
* Creates a new shortcut with the given Qt key codes
* as primary and secondary shortcuts.
* You can only assign single-key shortcuts this way.
* @param keyQtPri Qt keycode of primary shortcut
* @param keyQtAlt Qt keycode of alternate shortcut
* @see Qt::Key
*/
explicit KShortcut(int keyQtPri, int keyQtAlt = 0);
/**
* Copy constructor.
*/
KShortcut(const KShortcut &other);
/**
* Creates a new shortcut that contains the key sequences described
* in @p description. The format of description is the same as
* used in QKeySequence::fromString(const QString&).
* Up to two key sequences separated by a semicolon followed by a
* space "; " may be given.
* @param description the description of key sequence(s)
* @see QKeySequence::fromString(const QString&, SequenceFormat)
*/
explicit KShortcut(const QString &description);
/**
* Creates a new shortcut with the given Qt key sequences.
* The first sequence in the list is considered to be the primary
* sequence, the second one the alternate.
* @param seqs List of key sequeces.
*/
explicit KShortcut(const QList<QKeySequence> &seqs);
/**
* Destructor.
*/
~KShortcut();
/** @name Query methods */
/** @{ */
/**
* Returns the primary key sequence of this shortcut.
* @return primary key sequence
*/
QKeySequence primary() const;
/**
* Returns the alternate key sequence of this shortcut.
* @return alternate key sequence
*/
QKeySequence alternate() const;
/**
* Returns whether this shortcut contains any nonempty key sequences.
* @return whether this shortcut is empty
*/
bool isEmpty() const;
/**
* Returns whether at least one of the key sequences is equal to @p needle.
* @return whether this shortcut contains @p needle
*/
bool contains(const QKeySequence &needle) const;
/**
* Returns whether at least one of the key sequences conflicts witho @p needle.
* @return whether this shortcut conflicts with @p needle
*/
bool conflictsWith(const QKeySequence &needle) const;
/**
* Returns a description of the shortcut as a semicolon-separated
* list of key sequences, as returned by QKeySequence::toString().
* @return the string represenation of this shortcut
* @see QKeySequence::toString()
* @see KShortcut(const QString &description)
*/
QString toString() const;
/**
* Returns a description of the shortcut as a semicolon-separated
* list of key sequences, as returned by QKeySequence::toString().
* @return the string represenation of this shortcut
* @see QKeySequence::toString()
* @see KShortcut(const QString &description)
* @since KDE 4.2
*/
QString toString(QKeySequence::SequenceFormat format) const;
bool operator==(const KShortcut &other) const;
bool operator!=(const KShortcut &other) const;
/**
* Returns shortcut as QList\<QKeySequence\>, and is equivalent to toList(RemoveEmpty).
* Be aware that empty shortcuts will not be included in the list;
* due to this, conversion operations like
* KShortcut b = (QList\<QKeySequence\>)KShortcut a
* will not always result in b == a.
* @return the shortcut converted to a QList\<QKeySequence\>
*/
operator QList<QKeySequence>() const;
/**
* The same as operator QList\<QKeySequence\>()
* If @p handleEmpty equals RemoveEmpty, empty key sequences will be left out of the result.
* Otherwise, empy key sequences will be included; you can be sure that
* shortcut.alternate() == shortcut.toList(KeepEmpty).at(1).
* @return the shortcut converted to a QList\<QKeySequence\>
*/
QList<QKeySequence> toList(enum EmptyHandling handleEmpty = RemoveEmpty) const;
/**
* Returns shortcut as QVariant.
*/
operator QVariant() const;
/** @} */
/** @name Mutator methods */
/** @{ */
/**
* Set the primary key sequence of this shortcut to the given key sequence.
* @param keySeq set primary key sequence to this
*/
void setPrimary(const QKeySequence &keySeq);
/**
* Set the alternate key sequence of this shortcut to the given key sequence.
* @param keySeq set alternate key sequence to this
*/
void setAlternate(const QKeySequence &keySeq);
/**
* Remove @p keySeq from this shortcut.
* If @p handleEmpty equals RemoveEmpty, following key sequences will move up to take the place of
* @p keySeq. Otherwise, key sequences equal to @p keySeq will be set to empty.
* @param keySeq remove this key sequence from the shortcut
*/
void remove(const QKeySequence &keySeq, enum EmptyHandling handleEmpty = RemoveEmpty);
/**
* Assignment operator.
*/
KShortcut &operator=(const KShortcut &other);
private:
class KShortcutPrivate *const d;
};
inline uint qHash(const KShortcut &key)
{
return qHash(key.primary()[0]) + qHash(key.primary()[1]);
}
inline uint qHash(const QKeySequence &key)
{
uint hash = 0;
for(int i = 0; i < key.count(); i++) {
hash += qHash(key[i]);
}
return hash;
}
Q_DECLARE_METATYPE(KShortcut)
#endif // KSHORTCUT_H

View file

@ -1,98 +0,0 @@
/* This file is part of the KDE libraries
Copyright (C) 2008 Alexander Dymo <adymo@kdevelop.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "kshortcutschemeshelper_p.h"
#include <QFile>
#include <QTextStream>
#include <QtXml/qdom.h>
#include <kconfiggroup.h>
#include <kaction.h>
#include <kstandarddirs.h>
#include <kactioncollection.h>
#include <kxmlguiclient.h>
#include <kdebug.h>
bool KShortcutSchemesHelper::exportActionCollection(KActionCollection *collection,
const QString &schemeName, const QString dir)
{
const KXMLGUIClient *client = collection->parentGUIClient();
if (!client)
return false;
QString schemeFileName;
if (!dir.isEmpty())
schemeFileName = dir + client->componentData().componentName() + schemeName + "shortcuts.rc";
else
schemeFileName = shortcutSchemeFileName(client, schemeName);
QFile schemeFile(schemeFileName);
if (!schemeFile.open(QFile::WriteOnly | QFile::Truncate))
{
kDebug() << "COULD NOT WRITE" << schemeFileName;
return false;
}
QDomDocument doc;
QDomElement docElem = doc.createElement("kpartgui");
docElem.setAttribute("version", "1");
docElem.setAttribute("name", client->componentData().componentName());
doc.appendChild(docElem);
QDomElement elem = doc.createElement("ActionProperties");
docElem.appendChild(elem);
// now, iterate through our actions
foreach (QAction *action, collection->actions()) {
KAction *kaction = qobject_cast<KAction*>(action);
if (!kaction)
continue;
QString actionName = kaction->objectName();
QString shortcut = kaction->shortcut(KAction::ActiveShortcut).toString();
if (!shortcut.isEmpty())
{
QDomElement act_elem = doc.createElement("Action");
act_elem.setAttribute( "name", actionName );
act_elem.setAttribute( "shortcut", shortcut );
elem.appendChild(act_elem);
}
}
QTextStream out(&schemeFile);
out << doc.toString(2);
return true;
}
QString KShortcutSchemesHelper::currentShortcutSchemeName()
{
return KGlobal::config()->group( "Shortcut Schemes" ).readEntry("Current Scheme", "Default");
}
QString KShortcutSchemesHelper::shortcutSchemeFileName(const KXMLGUIClient *client, const QString &schemeName)
{
return KStandardDirs::locateLocal("data",
client->componentData().componentName() + '/' +
client->componentData().componentName() + schemeName + "shortcuts.rc" );
}
QString KShortcutSchemesHelper::applicationShortcutSchemeFileName(const QString &schemeName)
{
return KGlobal::dirs()->locateLocal("appdata",
KGlobal::mainComponent().componentName() + schemeName + "shortcuts.rc");
}

View file

@ -1,59 +0,0 @@
/* This file is part of the KDE libraries
Copyright (C) 2008 Alexander Dymo <adymo@kdevelop.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KSHORTCUTSCHEMESHELPER_P_H
#define KSHORTCUTSCHEMESHELPER_P_H
#include <kurl.h>
class KActionCollection;
class KXMLGUIClient;
class KShortcutSchemesHelper {
public:
/**
* Saves actions from the collection to shortcut scheme file.
* If the url is given, saves to that directory, otherwise saves to user appdata directory.
*
* This doesn't save anything if there's no parent xmlgui client for action collection.
*
* The name of the resulting file is: <xmlgui client component name><scheme name>shortcuts.rc .
*
* @return true if the action collection was exported
*/
static bool exportActionCollection(KActionCollection *collection, const QString &schemeName,
const QString dir = QString());
/**
* @return the current shortcut scheme name for the application.
*/
static QString currentShortcutSchemeName();
/**
* @return the name of the (writable) file to save the shortcut scheme to.
*/
static QString shortcutSchemeFileName(const KXMLGUIClient *client, const QString &schemeName);
/**
* @return the name of the scheme file for application itself.
*/
static QString applicationShortcutSchemeFileName(const QString &schemeName);
};
#endif

View file

@ -19,15 +19,13 @@
*/
#include "kstandardshortcut.h"
#include "kconfig.h"
#include "kdebug.h"
#include "kglobal.h"
#include "klocale.h"
#include "kshortcut.h"
#include <kconfiggroup.h>
#include "kconfiggroup.h"
#include "kdebug.h"
#include <QtGui/QKeySequence>
#include <QKeySequence>
#ifdef Q_WS_X11
#include <qx11info_x11.h>
#endif
@ -57,7 +55,7 @@ struct KStandardShortcutInfo
int cutDefault, cutDefault2;
//! A shortcut that is created with @a cutDefault and @cutDefault2
KShortcut cut;
QKeySequence cut;
//! If this struct is initialized. If not initialized @cut is not valid
bool isInitialized;
@ -78,104 +76,104 @@ struct KStandardShortcutInfo
static KStandardShortcutInfo g_infoStandardShortcut[] =
{
// Group File,
{AccelNone, 0 , 0 , 0 , 0 , 0 , KShortcut(), false },
{ Open , "Open" , I18N_NOOP2_NOSTRIP("@action", "Open") , CTRL(O), 0 , KShortcut(), false },
{ New , "New" , I18N_NOOP2_NOSTRIP("@action", "New") , CTRL(N), 0 , KShortcut(), false },
{ Close , "Close", I18N_NOOP2_NOSTRIP("@action", "Close"), CTRL(W), CTRL(Escape), KShortcut(), false },
{ Save , "Save" , I18N_NOOP2_NOSTRIP("@action", "Save") , CTRL(S), 0 , KShortcut(), false },
{ Print , "Print", I18N_NOOP2_NOSTRIP("@action", "Print"), CTRL(P), 0 , KShortcut(), false },
{ Quit , "Quit" , I18N_NOOP2_NOSTRIP("@action", "Quit") , CTRL(Q), 0 , KShortcut(), false },
{AccelNone, 0 , 0 , 0 , 0 , 0 , QKeySequence(), false },
{ Open , "Open" , I18N_NOOP2_NOSTRIP("@action", "Open") , CTRL(O), 0 , QKeySequence(), false },
{ New , "New" , I18N_NOOP2_NOSTRIP("@action", "New") , CTRL(N), 0 , QKeySequence(), false },
{ Close , "Close", I18N_NOOP2_NOSTRIP("@action", "Close"), CTRL(W), CTRL(Escape), QKeySequence(), false },
{ Save , "Save" , I18N_NOOP2_NOSTRIP("@action", "Save") , CTRL(S), 0 , QKeySequence(), false },
{ Print , "Print", I18N_NOOP2_NOSTRIP("@action", "Print"), CTRL(P), 0 , QKeySequence(), false },
{ Quit , "Quit" , I18N_NOOP2_NOSTRIP("@action", "Quit") , CTRL(Q), 0 , QKeySequence(), false },
// Group Edit
{ Undo , "Undo" , I18N_NOOP2_NOSTRIP("@action", "Undo") , CTRL(Z) , 0 , KShortcut(), false },
{ Redo , "Redo" , I18N_NOOP2_NOSTRIP("@action", "Redo") , CTRLSHIFT(Z) , 0 , KShortcut(), false },
{ Cut , "Cut" , I18N_NOOP2_NOSTRIP("@action", "Cut") , CTRL(X) , SHIFT(Delete), KShortcut(), false },
{ Copy , "Copy" , I18N_NOOP2_NOSTRIP("@action", "Copy") , CTRL(C) , CTRL(Insert) , KShortcut(), false },
{ Paste , "Paste" , I18N_NOOP2_NOSTRIP("@action", "Paste") , CTRL(V) , SHIFT(Insert), KShortcut(), false },
{ PasteSelection , "Paste Selection" , I18N_NOOP2_NOSTRIP("@action", "Paste Selection") , CTRLSHIFT(Insert), 0 , KShortcut(), false },
{ Undo , "Undo" , I18N_NOOP2_NOSTRIP("@action", "Undo") , CTRL(Z) , 0 , QKeySequence(), false },
{ Redo , "Redo" , I18N_NOOP2_NOSTRIP("@action", "Redo") , CTRLSHIFT(Z) , 0 , QKeySequence(), false },
{ Cut , "Cut" , I18N_NOOP2_NOSTRIP("@action", "Cut") , CTRL(X) , SHIFT(Delete), QKeySequence(), false },
{ Copy , "Copy" , I18N_NOOP2_NOSTRIP("@action", "Copy") , CTRL(C) , CTRL(Insert) , QKeySequence(), false },
{ Paste , "Paste" , I18N_NOOP2_NOSTRIP("@action", "Paste") , CTRL(V) , SHIFT(Insert), QKeySequence(), false },
{ PasteSelection , "Paste Selection" , I18N_NOOP2_NOSTRIP("@action", "Paste Selection") , CTRLSHIFT(Insert), 0 , QKeySequence(), false },
{ SelectAll , "SelectAll" , I18N_NOOP2_NOSTRIP("@action", "Select All") , CTRL(A) , 0 , KShortcut(), false },
{ Deselect , "Deselect" , I18N_NOOP2_NOSTRIP("@action", "Deselect") , CTRLSHIFT(A) , 0 , KShortcut(), false },
{ DeleteWordBack , "DeleteWordBack" , I18N_NOOP2_NOSTRIP("@action", "Delete Word Backwards"), CTRL(Backspace) , 0 , KShortcut(), false },
{ DeleteWordForward, "DeleteWordForward", I18N_NOOP2_NOSTRIP("@action", "Delete Word Forward") , CTRL(Delete) , 0 , KShortcut(), false },
{ SelectAll , "SelectAll" , I18N_NOOP2_NOSTRIP("@action", "Select All") , CTRL(A) , 0 , QKeySequence(), false },
{ Deselect , "Deselect" , I18N_NOOP2_NOSTRIP("@action", "Deselect") , CTRLSHIFT(A) , 0 , QKeySequence(), false },
{ DeleteWordBack , "DeleteWordBack" , I18N_NOOP2_NOSTRIP("@action", "Delete Word Backwards"), CTRL(Backspace) , 0 , QKeySequence(), false },
{ DeleteWordForward, "DeleteWordForward", I18N_NOOP2_NOSTRIP("@action", "Delete Word Forward") , CTRL(Delete) , 0 , QKeySequence(), false },
{ Find , "Find" , I18N_NOOP2_NOSTRIP("@action", "Find") , CTRL(F) , 0 , KShortcut(), false },
{ FindNext , "FindNext" , I18N_NOOP2_NOSTRIP("@action", "Find Next") , Qt::Key_F3 , 0 , KShortcut(), false },
{ FindPrev , "FindPrev" , I18N_NOOP2_NOSTRIP("@action", "Find Prev") , SHIFT(F3) , 0 , KShortcut(), false },
{ Replace , "Replace" , I18N_NOOP2_NOSTRIP("@action", "Replace") , CTRL(R) , 0 , KShortcut(), false },
{ Find , "Find" , I18N_NOOP2_NOSTRIP("@action", "Find") , CTRL(F) , 0 , QKeySequence(), false },
{ FindNext , "FindNext" , I18N_NOOP2_NOSTRIP("@action", "Find Next") , Qt::Key_F3 , 0 , QKeySequence(), false },
{ FindPrev , "FindPrev" , I18N_NOOP2_NOSTRIP("@action", "Find Prev") , SHIFT(F3) , 0 , QKeySequence(), false },
{ Replace , "Replace" , I18N_NOOP2_NOSTRIP("@action", "Replace") , CTRL(R) , 0 , QKeySequence(), false },
// Group Navigation
{ Home , "Home" , I18N_NOOP2_NOSTRIP("@action Go to main page" , "Home") , ALT(Home) , 0 , KShortcut(), false },
{ Begin , "Begin" , I18N_NOOP2_NOSTRIP("@action Beginning of document", "Begin") , CTRL(Home) , 0 , KShortcut(), false },
{ End , "End" , I18N_NOOP2_NOSTRIP("@action End of document" , "End") , CTRL(End) , 0 , KShortcut(), false },
{ Prior , "Prior" , I18N_NOOP2_NOSTRIP("@action" , "Prior") , Qt::Key_PageUp , 0 , KShortcut(), false },
{ Next , "Next" , I18N_NOOP2_NOSTRIP("@action Opposite to Prior" , "Next") , Qt::Key_PageDown, 0 , KShortcut(), false },
{ Home , "Home" , I18N_NOOP2_NOSTRIP("@action Go to main page" , "Home") , ALT(Home) , 0 , QKeySequence(), false },
{ Begin , "Begin" , I18N_NOOP2_NOSTRIP("@action Beginning of document", "Begin") , CTRL(Home) , 0 , QKeySequence(), false },
{ End , "End" , I18N_NOOP2_NOSTRIP("@action End of document" , "End") , CTRL(End) , 0 , QKeySequence(), false },
{ Prior , "Prior" , I18N_NOOP2_NOSTRIP("@action" , "Prior") , Qt::Key_PageUp , 0 , QKeySequence(), false },
{ Next , "Next" , I18N_NOOP2_NOSTRIP("@action Opposite to Prior" , "Next") , Qt::Key_PageDown, 0 , QKeySequence(), false },
{ Up , "Up" , I18N_NOOP2_NOSTRIP("@action" , "Up") , ALT(Up) , 0 , KShortcut(), false },
{ Back , "Back" , I18N_NOOP2_NOSTRIP("@action" , "Back") , ALT(Left) , 0 , KShortcut(), false },
{ Forward , "Forward" , I18N_NOOP2_NOSTRIP("@action" , "Forward") , ALT(Right) , 0 , KShortcut(), false },
{ Reload , "Reload" , I18N_NOOP2_NOSTRIP("@action" , "Reload") , Qt::Key_F5 , 0 , KShortcut(), false },
{ Up , "Up" , I18N_NOOP2_NOSTRIP("@action" , "Up") , ALT(Up) , 0 , QKeySequence(), false },
{ Back , "Back" , I18N_NOOP2_NOSTRIP("@action" , "Back") , ALT(Left) , 0 , QKeySequence(), false },
{ Forward , "Forward" , I18N_NOOP2_NOSTRIP("@action" , "Forward") , ALT(Right) , 0 , QKeySequence(), false },
{ Reload , "Reload" , I18N_NOOP2_NOSTRIP("@action" , "Reload") , Qt::Key_F5 , 0 , QKeySequence(), false },
{ BeginningOfLine, "BeginningOfLine" , I18N_NOOP2_NOSTRIP("@action" , "Beginning of Line") , Qt::Key_Home , 0 , KShortcut(), false },
{ EndOfLine , "EndOfLine" , I18N_NOOP2_NOSTRIP("@action" , "End of Line") , Qt::Key_End , 0 , KShortcut(), false },
{ GotoLine , "GotoLine" , I18N_NOOP2_NOSTRIP("@action" , "Go to Line") , CTRL(G) , 0 , KShortcut(), false },
{ BackwardWord , "BackwardWord" , I18N_NOOP2_NOSTRIP("@action" , "Backward Word") , CTRL(Left) , 0 , KShortcut(), false },
{ ForwardWord , "ForwardWord" , I18N_NOOP2_NOSTRIP("@action" , "Forward Word") , CTRL(Right) , 0 , KShortcut(), false },
{ BeginningOfLine, "BeginningOfLine" , I18N_NOOP2_NOSTRIP("@action" , "Beginning of Line") , Qt::Key_Home , 0 , QKeySequence(), false },
{ EndOfLine , "EndOfLine" , I18N_NOOP2_NOSTRIP("@action" , "End of Line") , Qt::Key_End , 0 , QKeySequence(), false },
{ GotoLine , "GotoLine" , I18N_NOOP2_NOSTRIP("@action" , "Go to Line") , CTRL(G) , 0 , QKeySequence(), false },
{ BackwardWord , "BackwardWord" , I18N_NOOP2_NOSTRIP("@action" , "Backward Word") , CTRL(Left) , 0 , QKeySequence(), false },
{ ForwardWord , "ForwardWord" , I18N_NOOP2_NOSTRIP("@action" , "Forward Word") , CTRL(Right) , 0 , QKeySequence(), false },
{ AddBookmark , "AddBookmark" , I18N_NOOP2_NOSTRIP("@action" , "Add Bookmark") , CTRL(B) , 0 , KShortcut(), false },
{ ZoomIn , "ZoomIn" , I18N_NOOP2_NOSTRIP("@action" , "Zoom In") , CTRL(Plus) , CTRL(Equal) , KShortcut(), false },
{ ZoomOut , "ZoomOut" , I18N_NOOP2_NOSTRIP("@action" , "Zoom Out") , CTRL(Minus) , 0 , KShortcut(), false },
{ FullScreen , "FullScreen" , I18N_NOOP2_NOSTRIP("@action" , "Full Screen Mode") , CTRLSHIFT(F) , 0 , KShortcut(), false },
{ AddBookmark , "AddBookmark" , I18N_NOOP2_NOSTRIP("@action" , "Add Bookmark") , CTRL(B) , 0 , QKeySequence(), false },
{ ZoomIn , "ZoomIn" , I18N_NOOP2_NOSTRIP("@action" , "Zoom In") , CTRL(Plus) , CTRL(Equal) , QKeySequence(), false },
{ ZoomOut , "ZoomOut" , I18N_NOOP2_NOSTRIP("@action" , "Zoom Out") , CTRL(Minus) , 0 , QKeySequence(), false },
{ FullScreen , "FullScreen" , I18N_NOOP2_NOSTRIP("@action" , "Full Screen Mode") , CTRLSHIFT(F) , 0 , QKeySequence(), false },
{ ShowMenubar , "ShowMenubar" , I18N_NOOP2_NOSTRIP("@action" , "Show Menu Bar") , CTRL(M) , 0 , KShortcut(), false },
{ TabNext , "Activate Next Tab" , I18N_NOOP2_NOSTRIP("@action" , "Activate Next Tab") , CTRL(Period) , CTRL(BracketRight), KShortcut(), false },
{ TabPrev , "Activate Previous Tab", I18N_NOOP2_NOSTRIP("@action" , "Activate Previous Tab"), CTRL(Comma) , CTRL(BracketLeft) , KShortcut(), false },
{ ShowMenubar , "ShowMenubar" , I18N_NOOP2_NOSTRIP("@action" , "Show Menu Bar") , CTRL(M) , 0 , QKeySequence(), false },
{ TabNext , "Activate Next Tab" , I18N_NOOP2_NOSTRIP("@action" , "Activate Next Tab") , CTRL(Period) , CTRL(BracketRight), QKeySequence(), false },
{ TabPrev , "Activate Previous Tab", I18N_NOOP2_NOSTRIP("@action" , "Activate Previous Tab"), CTRL(Comma) , CTRL(BracketLeft) , QKeySequence(), false },
// Group Help
{ Help , "Help" , I18N_NOOP2_NOSTRIP("@action" , "Help") , Qt::Key_F1 , 0 , KShortcut(), false },
{ WhatsThis , "WhatsThis" , I18N_NOOP2_NOSTRIP("@action" , "What's This") , SHIFT(F1) , 0 , KShortcut(), false },
{ Help , "Help" , I18N_NOOP2_NOSTRIP("@action" , "Help") , Qt::Key_F1 , 0 , QKeySequence(), false },
{ WhatsThis , "WhatsThis" , I18N_NOOP2_NOSTRIP("@action" , "What's This") , SHIFT(F1) , 0 , QKeySequence(), false },
// Group TextCompletion
{ TextCompletion , "TextCompletion" , I18N_NOOP2_NOSTRIP("@action", "Text Completion") , CTRL(E) , 0, KShortcut(), false },
{ PrevCompletion , "PrevCompletion" , I18N_NOOP2_NOSTRIP("@action", "Previous Completion Match") , CTRL(Up) , 0, KShortcut(), false },
{ NextCompletion , "NextCompletion" , I18N_NOOP2_NOSTRIP("@action", "Next Completion Match") , CTRL(Down) , 0, KShortcut(), false },
{ SubstringCompletion , "SubstringCompletion" , I18N_NOOP2_NOSTRIP("@action", "Substring Completion") , CTRL(T) , 0, KShortcut(), false },
{ TextCompletion , "TextCompletion" , I18N_NOOP2_NOSTRIP("@action", "Text Completion") , CTRL(E) , 0, QKeySequence(), false },
{ PrevCompletion , "PrevCompletion" , I18N_NOOP2_NOSTRIP("@action", "Previous Completion Match") , CTRL(Up) , 0, QKeySequence(), false },
{ NextCompletion , "NextCompletion" , I18N_NOOP2_NOSTRIP("@action", "Next Completion Match") , CTRL(Down) , 0, QKeySequence(), false },
{ SubstringCompletion , "SubstringCompletion" , I18N_NOOP2_NOSTRIP("@action", "Substring Completion") , CTRL(T) , 0, QKeySequence(), false },
{ RotateUp , "RotateUp" , I18N_NOOP2_NOSTRIP("@action", "Previous Item in List") , Qt::Key_Up , 0, KShortcut(), false },
{ RotateDown , "RotateDown" , I18N_NOOP2_NOSTRIP("@action", "Next Item in List") , Qt::Key_Down , 0, KShortcut(), false },
{ RotateUp , "RotateUp" , I18N_NOOP2_NOSTRIP("@action", "Previous Item in List") , Qt::Key_Up , 0, QKeySequence(), false },
{ RotateDown , "RotateDown" , I18N_NOOP2_NOSTRIP("@action", "Next Item in List") , Qt::Key_Down , 0, QKeySequence(), false },
{ OpenRecent , "OpenRecent" , I18N_NOOP2_NOSTRIP("@action", "Open Recent") , 0 , 0, KShortcut(), false },
{ SaveAs , "SaveAs" , I18N_NOOP2_NOSTRIP("@action", "Save As") , CTRLSHIFT(S) , 0, KShortcut(), false },
{ Revert , "Revert" , I18N_NOOP2_NOSTRIP("@action", "Revert") , 0 , 0, KShortcut(), false },
{ PrintPreview , "PrintPreview" , I18N_NOOP2_NOSTRIP("@action", "Print Preview") , 0 , 0, KShortcut(), false },
{ Mail , "Mail" , I18N_NOOP2_NOSTRIP("@action", "Mail") , 0 , 0, KShortcut(), false },
{ Clear , "Clear" , I18N_NOOP2_NOSTRIP("@action", "Clear") , 0 , 0, KShortcut(), false },
{ ActualSize , "ActualSize" , I18N_NOOP2_NOSTRIP("@action", "Actual Size") , 0 , 0, KShortcut(), false },
{ FitToPage , "FitToPage" , I18N_NOOP2_NOSTRIP("@action", "Fit To Page") , 0 , 0, KShortcut(), false },
{ FitToWidth , "FitToWidth" , I18N_NOOP2_NOSTRIP("@action", "Fit To Width") , 0 , 0, KShortcut(), false },
{ FitToHeight , "FitToHeight" , I18N_NOOP2_NOSTRIP("@action", "Fit To Height") , 0 , 0, KShortcut(), false },
{ Zoom , "Zoom" , I18N_NOOP2_NOSTRIP("@action", "Zoom") , 0 , 0, KShortcut(), false },
{ Goto , "Goto" , I18N_NOOP2_NOSTRIP("@action", "Goto") , 0 , 0, KShortcut(), false },
{ GotoPage , "GotoPage" , I18N_NOOP2_NOSTRIP("@action", "Goto Page") , 0 , 0, KShortcut(), false },
{ DocumentBack , "DocumentBack" , I18N_NOOP2_NOSTRIP("@action", "Document Back") , ALTSHIFT(Left) , 0, KShortcut(), false },
{ DocumentForward , "DocumentForward" , I18N_NOOP2_NOSTRIP("@action", "Document Forward") , ALTSHIFT(Right), 0, KShortcut(), false },
{ EditBookmarks , "EditBookmarks" , I18N_NOOP2_NOSTRIP("@action", "Edit Bookmarks") , 0 , 0, KShortcut(), false },
{ Spelling , "Spelling" , I18N_NOOP2_NOSTRIP("@action", "Spelling") , 0 , 0, KShortcut(), false },
{ ShowToolbar , "ShowToolbar" , I18N_NOOP2_NOSTRIP("@action", "Show Toolbar") , 0 , 0, KShortcut(), false },
{ ShowStatusbar , "ShowStatusbar" , I18N_NOOP2_NOSTRIP("@action", "Show Statusbar") , 0 , 0, KShortcut(), false },
{ SaveOptions , "SaveOptions" , I18N_NOOP2_NOSTRIP("@action", "Save Options") , 0 , 0, KShortcut(), false },
{ KeyBindings , "KeyBindings" , I18N_NOOP2_NOSTRIP("@action", "Key Bindings") , 0 , 0, KShortcut(), false },
{ Preferences , "Preferences" , I18N_NOOP2_NOSTRIP("@action", "Preferences") , 0 , 0, KShortcut(), false },
{ ConfigureToolbars , "ConfigureToolbars" , I18N_NOOP2_NOSTRIP("@action", "Configure Toolbars") , 0 , 0, KShortcut(), false },
{ ConfigureNotifications , "ConfigureNotifications" , I18N_NOOP2_NOSTRIP("@action", "Configure Notifications") , 0 , 0, KShortcut(), false },
{ TipofDay , "TipofDay" , I18N_NOOP2_NOSTRIP("@action", "Tip Of Day") , 0 , 0, KShortcut(), false },
{ ReportBug , "ReportBug" , I18N_NOOP2_NOSTRIP("@action", "Report Bug") , 0 , 0, KShortcut(), false },
{ SwitchApplicationLanguage, "SwitchApplicationLanguage", I18N_NOOP2_NOSTRIP("@action", "Switch Application Language"), 0 , 0, KShortcut(), false },
{ AboutApp , "AboutApp" , I18N_NOOP2_NOSTRIP("@action", "About Application") , 0 , 0, KShortcut(), false },
{ AboutKDE , "AboutKatana" , I18N_NOOP2_NOSTRIP("@action", "About Katana") , 0 , 0, KShortcut(), false },
{ OpenRecent , "OpenRecent" , I18N_NOOP2_NOSTRIP("@action", "Open Recent") , 0 , 0, QKeySequence(), false },
{ SaveAs , "SaveAs" , I18N_NOOP2_NOSTRIP("@action", "Save As") , CTRLSHIFT(S) , 0, QKeySequence(), false },
{ Revert , "Revert" , I18N_NOOP2_NOSTRIP("@action", "Revert") , 0 , 0, QKeySequence(), false },
{ PrintPreview , "PrintPreview" , I18N_NOOP2_NOSTRIP("@action", "Print Preview") , 0 , 0, QKeySequence(), false },
{ Mail , "Mail" , I18N_NOOP2_NOSTRIP("@action", "Mail") , 0 , 0, QKeySequence(), false },
{ Clear , "Clear" , I18N_NOOP2_NOSTRIP("@action", "Clear") , 0 , 0, QKeySequence(), false },
{ ActualSize , "ActualSize" , I18N_NOOP2_NOSTRIP("@action", "Actual Size") , 0 , 0, QKeySequence(), false },
{ FitToPage , "FitToPage" , I18N_NOOP2_NOSTRIP("@action", "Fit To Page") , 0 , 0, QKeySequence(), false },
{ FitToWidth , "FitToWidth" , I18N_NOOP2_NOSTRIP("@action", "Fit To Width") , 0 , 0, QKeySequence(), false },
{ FitToHeight , "FitToHeight" , I18N_NOOP2_NOSTRIP("@action", "Fit To Height") , 0 , 0, QKeySequence(), false },
{ Zoom , "Zoom" , I18N_NOOP2_NOSTRIP("@action", "Zoom") , 0 , 0, QKeySequence(), false },
{ Goto , "Goto" , I18N_NOOP2_NOSTRIP("@action", "Goto") , 0 , 0, QKeySequence(), false },
{ GotoPage , "GotoPage" , I18N_NOOP2_NOSTRIP("@action", "Goto Page") , 0 , 0, QKeySequence(), false },
{ DocumentBack , "DocumentBack" , I18N_NOOP2_NOSTRIP("@action", "Document Back") , ALTSHIFT(Left) , 0, QKeySequence(), false },
{ DocumentForward , "DocumentForward" , I18N_NOOP2_NOSTRIP("@action", "Document Forward") , ALTSHIFT(Right), 0, QKeySequence(), false },
{ EditBookmarks , "EditBookmarks" , I18N_NOOP2_NOSTRIP("@action", "Edit Bookmarks") , 0 , 0, QKeySequence(), false },
{ Spelling , "Spelling" , I18N_NOOP2_NOSTRIP("@action", "Spelling") , 0 , 0, QKeySequence(), false },
{ ShowToolbar , "ShowToolbar" , I18N_NOOP2_NOSTRIP("@action", "Show Toolbar") , 0 , 0, QKeySequence(), false },
{ ShowStatusbar , "ShowStatusbar" , I18N_NOOP2_NOSTRIP("@action", "Show Statusbar") , 0 , 0, QKeySequence(), false },
{ SaveOptions , "SaveOptions" , I18N_NOOP2_NOSTRIP("@action", "Save Options") , 0 , 0, QKeySequence(), false },
{ KeyBindings , "KeyBindings" , I18N_NOOP2_NOSTRIP("@action", "Key Bindings") , 0 , 0, QKeySequence(), false },
{ Preferences , "Preferences" , I18N_NOOP2_NOSTRIP("@action", "Preferences") , 0 , 0, QKeySequence(), false },
{ ConfigureToolbars , "ConfigureToolbars" , I18N_NOOP2_NOSTRIP("@action", "Configure Toolbars") , 0 , 0, QKeySequence(), false },
{ ConfigureNotifications , "ConfigureNotifications" , I18N_NOOP2_NOSTRIP("@action", "Configure Notifications") , 0 , 0, QKeySequence(), false },
{ TipofDay , "TipofDay" , I18N_NOOP2_NOSTRIP("@action", "Tip Of Day") , 0 , 0, QKeySequence(), false },
{ ReportBug , "ReportBug" , I18N_NOOP2_NOSTRIP("@action", "Report Bug") , 0 , 0, QKeySequence(), false },
{ SwitchApplicationLanguage, "SwitchApplicationLanguage", I18N_NOOP2_NOSTRIP("@action", "Switch Application Language"), 0 , 0, QKeySequence(), false },
{ AboutApp , "AboutApp" , I18N_NOOP2_NOSTRIP("@action", "About Application") , 0 , 0, QKeySequence(), false },
{ AboutKDE , "AboutKatana" , I18N_NOOP2_NOSTRIP("@action", "About Katana") , 0 , 0, QKeySequence(), false },
// Dummy entry to catch simple off-by-one errors. Insert new entries before this line.
{ AccelNone , 0 , 0 , 0 , 0 , 0, KShortcut(), false }
{ AccelNone , 0 , 0 , 0 , 0 , 0, QKeySequence(), false }
};
@ -217,11 +215,8 @@ static void initialize(StandardShortcut id)
if(cg.hasKey(info->name))
#endif
{
QString s = cg.readEntry(info->name);
if (s != "none")
info->cut = KShortcut(s);
else
info->cut = KShortcut();
const QString s = cg.readEntry(info->name);
info->cut = QKeySequence(s);
} else {
info->cut = hardcodedDefaultShortcut(id);
}
@ -229,7 +224,7 @@ static void initialize(StandardShortcut id)
info->isInitialized = true;
}
void saveShortcut(StandardShortcut id, const KShortcut &newShortcut)
void saveShortcut(StandardShortcut id, const QKeySequence &newShortcut)
{
KStandardShortcutInfo *info = guardedStandardShortcutInfo(id);
// If the action has no standard shortcut associated there is nothing to
@ -276,7 +271,7 @@ QString whatsThis( StandardShortcut /*id*/ )
return QString();
}
const KShortcut &shortcut(StandardShortcut id)
const QKeySequence &shortcut(StandardShortcut id)
{
KStandardShortcutInfo *info = guardedStandardShortcutInfo(id);
@ -295,7 +290,7 @@ StandardShortcut find(const QKeySequence &seq)
if (!g_infoStandardShortcut[i].isInitialized) {
initialize(id);
}
if (g_infoStandardShortcut[i].cut.contains(seq)) {
if (g_infoStandardShortcut[i].cut.matches(seq) != QKeySequence::NoMatch) {
return id;
}
}
@ -314,59 +309,59 @@ StandardShortcut find(const char *keyName)
return AccelNone;
}
KShortcut hardcodedDefaultShortcut(StandardShortcut id)
QKeySequence hardcodedDefaultShortcut(StandardShortcut id)
{
KStandardShortcutInfo *info = guardedStandardShortcutInfo(id);
return KShortcut(info->cutDefault, info->cutDefault2);
return QKeySequence(info->cutDefault, info->cutDefault2);
}
const KShortcut& open() { return shortcut( Open ); }
const KShortcut& openNew() { return shortcut( New ); }
const KShortcut& close() { return shortcut( Close ); }
const KShortcut& save() { return shortcut( Save ); }
const KShortcut& print() { return shortcut( Print ); }
const KShortcut& quit() { return shortcut( Quit ); }
const KShortcut& cut() { return shortcut( Cut ); }
const KShortcut& copy() { return shortcut( Copy ); }
const KShortcut& paste() { return shortcut( Paste ); }
const KShortcut& pasteSelection() { return shortcut( PasteSelection ); }
const KShortcut& deleteWordBack() { return shortcut( DeleteWordBack ); }
const KShortcut& deleteWordForward() { return shortcut( DeleteWordForward ); }
const KShortcut& undo() { return shortcut( Undo ); }
const KShortcut& redo() { return shortcut( Redo ); }
const KShortcut& find() { return shortcut( Find ); }
const KShortcut& findNext() { return shortcut( FindNext ); }
const KShortcut& findPrev() { return shortcut( FindPrev ); }
const KShortcut& replace() { return shortcut( Replace ); }
const KShortcut& home() { return shortcut( Home ); }
const KShortcut& begin() { return shortcut( Begin ); }
const KShortcut& end() { return shortcut( End ); }
const KShortcut& beginningOfLine() { return shortcut( BeginningOfLine ); }
const KShortcut& endOfLine() { return shortcut( EndOfLine ); }
const KShortcut& prior() { return shortcut( Prior ); }
const KShortcut& next() { return shortcut( Next ); }
const KShortcut& backwardWord() { return shortcut( BackwardWord ); }
const KShortcut& forwardWord() { return shortcut( ForwardWord ); }
const KShortcut& gotoLine() { return shortcut( GotoLine ); }
const KShortcut& addBookmark() { return shortcut( AddBookmark ); }
const KShortcut& tabNext() { return shortcut( TabNext ); }
const KShortcut& tabPrev() { return shortcut( TabPrev ); }
const KShortcut& fullScreen() { return shortcut( FullScreen ); }
const KShortcut& zoomIn() { return shortcut( ZoomIn ); }
const KShortcut& zoomOut() { return shortcut( ZoomOut ); }
const KShortcut& help() { return shortcut( Help ); }
const KShortcut& completion() { return shortcut( TextCompletion ); }
const KShortcut& prevCompletion() { return shortcut( PrevCompletion ); }
const KShortcut& nextCompletion() { return shortcut( NextCompletion ); }
const KShortcut& rotateUp() { return shortcut( RotateUp ); }
const KShortcut& rotateDown() { return shortcut( RotateDown ); }
const KShortcut& substringCompletion() { return shortcut( SubstringCompletion ); }
const KShortcut& whatsThis() { return shortcut( WhatsThis ); }
const KShortcut& reload() { return shortcut( Reload ); }
const KShortcut& selectAll() { return shortcut( SelectAll ); }
const KShortcut& up() { return shortcut( Up ); }
const KShortcut& back() { return shortcut( Back ); }
const KShortcut& forward() { return shortcut( Forward ); }
const KShortcut& showMenubar() { return shortcut( ShowMenubar ); }
const QKeySequence& open() { return shortcut( Open ); }
const QKeySequence& openNew() { return shortcut( New ); }
const QKeySequence& close() { return shortcut( Close ); }
const QKeySequence& save() { return shortcut( Save ); }
const QKeySequence& print() { return shortcut( Print ); }
const QKeySequence& quit() { return shortcut( Quit ); }
const QKeySequence& cut() { return shortcut( Cut ); }
const QKeySequence& copy() { return shortcut( Copy ); }
const QKeySequence& paste() { return shortcut( Paste ); }
const QKeySequence& pasteSelection() { return shortcut( PasteSelection ); }
const QKeySequence& deleteWordBack() { return shortcut( DeleteWordBack ); }
const QKeySequence& deleteWordForward() { return shortcut( DeleteWordForward ); }
const QKeySequence& undo() { return shortcut( Undo ); }
const QKeySequence& redo() { return shortcut( Redo ); }
const QKeySequence& find() { return shortcut( Find ); }
const QKeySequence& findNext() { return shortcut( FindNext ); }
const QKeySequence& findPrev() { return shortcut( FindPrev ); }
const QKeySequence& replace() { return shortcut( Replace ); }
const QKeySequence& home() { return shortcut( Home ); }
const QKeySequence& begin() { return shortcut( Begin ); }
const QKeySequence& end() { return shortcut( End ); }
const QKeySequence& beginningOfLine() { return shortcut( BeginningOfLine ); }
const QKeySequence& endOfLine() { return shortcut( EndOfLine ); }
const QKeySequence& prior() { return shortcut( Prior ); }
const QKeySequence& next() { return shortcut( Next ); }
const QKeySequence& backwardWord() { return shortcut( BackwardWord ); }
const QKeySequence& forwardWord() { return shortcut( ForwardWord ); }
const QKeySequence& gotoLine() { return shortcut( GotoLine ); }
const QKeySequence& addBookmark() { return shortcut( AddBookmark ); }
const QKeySequence& tabNext() { return shortcut( TabNext ); }
const QKeySequence& tabPrev() { return shortcut( TabPrev ); }
const QKeySequence& fullScreen() { return shortcut( FullScreen ); }
const QKeySequence& zoomIn() { return shortcut( ZoomIn ); }
const QKeySequence& zoomOut() { return shortcut( ZoomOut ); }
const QKeySequence& help() { return shortcut( Help ); }
const QKeySequence& completion() { return shortcut( TextCompletion ); }
const QKeySequence& prevCompletion() { return shortcut( PrevCompletion ); }
const QKeySequence& nextCompletion() { return shortcut( NextCompletion ); }
const QKeySequence& rotateUp() { return shortcut( RotateUp ); }
const QKeySequence& rotateDown() { return shortcut( RotateDown ); }
const QKeySequence& substringCompletion() { return shortcut( SubstringCompletion ); }
const QKeySequence& whatsThis() { return shortcut( WhatsThis ); }
const QKeySequence& reload() { return shortcut( Reload ); }
const QKeySequence& selectAll() { return shortcut( SelectAll ); }
const QKeySequence& up() { return shortcut( Up ); }
const QKeySequence& back() { return shortcut( Back ); }
const QKeySequence& forward() { return shortcut( Forward ); }
const QKeySequence& showMenubar() { return shortcut( ShowMenubar ); }
}

View file

@ -20,8 +20,9 @@
#ifndef KSTANDARDSHORTCUT_H
#define KSTANDARDSHORTCUT_H
#include "kshortcut.h"
#include <kdeui_export.h>
#include <QKeySequence>
/**
* \namespace KStandardShortcut
@ -122,7 +123,7 @@ namespace KStandardShortcut
* default keybinding will always be returned.
* @param id the id of the accelerator
*/
KDEUI_EXPORT const KShortcut &shortcut(StandardShortcut id);
KDEUI_EXPORT const QKeySequence &shortcut(StandardShortcut id);
/**
* Returns a unique name for the given accel.
@ -171,309 +172,309 @@ namespace KStandardShortcut
* @param id the id of the accelerator
* @return the default shortcut of the accelerator
*/
KDEUI_EXPORT KShortcut hardcodedDefaultShortcut(StandardShortcut id);
KDEUI_EXPORT QKeySequence hardcodedDefaultShortcut(StandardShortcut id);
/**
* Saves the new shortcut \a cut for standard accel \a id.
*/
KDEUI_EXPORT void saveShortcut(StandardShortcut id, const KShortcut &newShortcut);
KDEUI_EXPORT void saveShortcut(StandardShortcut id, const QKeySequence &newShortcut);
/**
* Open file. Default: Ctrl-o
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &open();
KDEUI_EXPORT const QKeySequence &open();
/**
* Create a new document (or whatever). Default: Ctrl-n
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &openNew();
KDEUI_EXPORT const QKeySequence &openNew();
/**
* Close current document. Default: Ctrl-w
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &close();
KDEUI_EXPORT const QKeySequence &close();
/**
* Save current document. Default: Ctrl-s
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &save();
KDEUI_EXPORT const QKeySequence &save();
/**
* Print current document. Default: Ctrl-p
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &print();
KDEUI_EXPORT const QKeySequence &print();
/**
* Quit the program. Default: Ctrl-q
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &quit();
KDEUI_EXPORT const QKeySequence &quit();
/**
* Undo last operation. Default: Ctrl-z
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &undo();
KDEUI_EXPORT const QKeySequence &undo();
/**
* Redo. Default: Shift-Ctrl-z
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &redo();
KDEUI_EXPORT const QKeySequence &redo();
/**
* Cut selected area and store it in the clipboard. Default: Ctrl-x
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &cut();
KDEUI_EXPORT const QKeySequence &cut();
/**
* Copy selected area into the clipboard. Default: Ctrl-c
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &copy();
KDEUI_EXPORT const QKeySequence &copy();
/**
* Paste contents of clipboard at mouse/cursor position. Default: Ctrl-v
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &paste();
KDEUI_EXPORT const QKeySequence &paste();
/**
* Paste the selection at mouse/cursor position. Default: Ctrl-Shift-Insert
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &pasteSelection();
KDEUI_EXPORT const QKeySequence &pasteSelection();
/**
* Select all. Default: Ctrl-A
* @return the shortcut of the standard accelerator
**/
KDEUI_EXPORT const KShortcut &selectAll();
KDEUI_EXPORT const QKeySequence &selectAll();
/**
* Delete a word back from mouse/cursor position. Default: Ctrl-Backspace
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &deleteWordBack();
KDEUI_EXPORT const QKeySequence &deleteWordBack();
/**
* Delete a word forward from mouse/cursor position. Default: Ctrl-Delete
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &deleteWordForward();
KDEUI_EXPORT const QKeySequence &deleteWordForward();
/**
* Find, search. Default: Ctrl-f
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &find();
KDEUI_EXPORT const QKeySequence &find();
/**
* Find/search next. Default: F3
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &findNext();
KDEUI_EXPORT const QKeySequence &findNext();
/**
* Find/search previous. Default: Shift-F3
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &findPrev();
KDEUI_EXPORT const QKeySequence &findPrev();
/**
* Find and replace matches. Default: Ctrl-r
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &replace();
KDEUI_EXPORT const QKeySequence &replace();
/**
* Zoom in. Default: Ctrl-Plus
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &zoomIn();
KDEUI_EXPORT const QKeySequence &zoomIn();
/**
* Zoom out. Default: Ctrl-Minus
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &zoomOut();
KDEUI_EXPORT const QKeySequence &zoomOut();
/**
* Toggle insert/overwrite (with visual feedback, e.g. in the statusbar). Default: Insert
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &insert();
KDEUI_EXPORT const QKeySequence &insert();
/**
* Goto home page. Default: Alt-Home
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &home();
KDEUI_EXPORT const QKeySequence &home();
/**
* Goto beginning of the document. Default: Ctrl-Home
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &begin();
KDEUI_EXPORT const QKeySequence &begin();
/**
* Goto end of the document. Default: Ctrl-End
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &end();
KDEUI_EXPORT const QKeySequence &end();
/**
* Goto beginning of current line. Default: Home
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &beginningOfLine();
KDEUI_EXPORT const QKeySequence &beginningOfLine();
/**
* Goto end of current line. Default: End
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &endOfLine();
KDEUI_EXPORT const QKeySequence &endOfLine();
/**
* Scroll up one page. Default: Prior
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &prior();
KDEUI_EXPORT const QKeySequence &prior();
/**
* Scroll down one page. Default: Next
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &next();
KDEUI_EXPORT const QKeySequence &next();
/**
* Go to line. Default: Ctrl+G
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &gotoLine();
KDEUI_EXPORT const QKeySequence &gotoLine();
/**
* Add current page to bookmarks. Default: Ctrl+B
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &addBookmark();
KDEUI_EXPORT const QKeySequence &addBookmark();
/**
* Next Tab. Default: Ctrl-<
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &tabNext();
KDEUI_EXPORT const QKeySequence &tabNext();
/**
* Previous Tab. Default: Ctrl->
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &tabPrev();
KDEUI_EXPORT const QKeySequence &tabPrev();
/**
* Full Screen Mode. Default: Ctrl+Shift+F
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &fullScreen();
KDEUI_EXPORT const QKeySequence &fullScreen();
/**
* Help the user in the current situation. Default: F1
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &help();
KDEUI_EXPORT const QKeySequence &help();
/**
* Complete text in input widgets. Default Ctrl+E
* @return the shortcut of the standard accelerator
**/
KDEUI_EXPORT const KShortcut &completion();
KDEUI_EXPORT const QKeySequence &completion();
/**
* Iterate through a list when completion returns
* multiple items. Default: Ctrl+Up
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &prevCompletion();
KDEUI_EXPORT const QKeySequence &prevCompletion();
/**
* Iterate through a list when completion returns
* multiple items. Default: Ctrl+Down
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &nextCompletion();
KDEUI_EXPORT const QKeySequence &nextCompletion();
/**
* Find a string within another string or list of strings.
* Default: Ctrl-T
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &substringCompletion();
KDEUI_EXPORT const QKeySequence &substringCompletion();
/**
* Help users iterate through a list of entries. Default: Up
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &rotateUp();
KDEUI_EXPORT const QKeySequence &rotateUp();
/**
* Help users iterate through a list of entries. Default: Down
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &rotateDown();
KDEUI_EXPORT const QKeySequence &rotateDown();
/**
* What's This button. Default: Shift+F1
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &whatsThis();
KDEUI_EXPORT const QKeySequence &whatsThis();
/**
* Reload. Default: F5
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &reload();
KDEUI_EXPORT const QKeySequence &reload();
/**
* Up. Default: Alt+Up
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &up();
KDEUI_EXPORT const QKeySequence &up();
/**
* Back. Default: Alt+Left
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &back();
KDEUI_EXPORT const QKeySequence &back();
/**
* Forward. Default: ALT+Right
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &forward();
KDEUI_EXPORT const QKeySequence &forward();
/**
* BackwardWord. Default: Ctrl+Left
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &backwardWord();
KDEUI_EXPORT const QKeySequence &backwardWord();
/**
* ForwardWord. Default: Ctrl+Right
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &forwardWord();
KDEUI_EXPORT const QKeySequence &forwardWord();
/**
* Show Menu Bar. Default: Ctrl-M
* @return the shortcut of the standard accelerator
*/
KDEUI_EXPORT const KShortcut &showMenubar();
KDEUI_EXPORT const QKeySequence &showMenubar();
}

View file

@ -42,7 +42,6 @@ KDEUI_UNIT_TESTS(
kcombobox_unittest
kdialog_unittest
kreplacetest
kshortcuttest
kstandardshortcuttest
kuniqueapptest
kstartupinfo_unittest

View file

@ -1,95 +0,0 @@
/* This file is part of the KDE libraries
Copyright 2006 Simon Hausmann <hausmann@kde.org>
Copyright 2008 David Faure <faure@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "qtest_kde.h"
#include "kshortcut.h"
class tst_KShortcut : public QObject
{
Q_OBJECT
private Q_SLOTS:
void isEmpty()
{
KShortcut cut;
QVERIFY(cut.isEmpty());
cut = KShortcut(0, 0);
QVERIFY(cut.isEmpty());
cut = KShortcut(QKeySequence());
QVERIFY(cut.isEmpty());
cut = KShortcut(QKeySequence(), QKeySequence());
QVERIFY(cut.isEmpty());
cut = KShortcut(QList<QKeySequence>());
QVERIFY(cut.isEmpty());
cut = KShortcut(Qt::Key_A);
QVERIFY(!cut.isEmpty());
}
void checkQKeySequence()
{
// Check that the valid keycode Qt::Key_unknown is handled gracefully
//
QKeySequence unknown_key(Qt::Key_unknown);
QCOMPARE(unknown_key.toString(), QString()); // What i would expect
// Check that the keycode -1 is handled gracefully.
//
// -1 happens for some keys when listening to keyPressEvent in QWidget::event()
// It means the key is not supported by Katie. It probably should be
// Qt::Key_unknown instead.
QKeySequence invalid_key(-1);
QCOMPARE(invalid_key.toString(), QString()); // What i would expect
// The famous "KDE4 eats my E key" bug: Win+E isn't parsed anymore.
QKeySequence seq("Win+E");
QVERIFY(seq.isEmpty());
QCOMPARE(seq.toString(), QString());
// KDE3 -> KDE4 migration. KDE3 used xKeycodeToKeysym or something and
// stored the result
QKeySequence seq2("Meta+Alt+Period");
QVERIFY(seq2.isEmpty());
QCOMPARE(seq2.toString(), QString());
}
void parsing()
{
KShortcut cut;
cut = KShortcut(";, Alt+;; ;, Alt+A, ;");
QVERIFY(cut.primary() == QKeySequence::fromString(";, Alt+;"));
QVERIFY(cut.alternate() == QKeySequence::fromString(";, Alt+A, ;"));
cut = KShortcut("Win+E");
//QTest::ignoreMessage(QtWarningMsg, "QKeySequence::fromString: Unknown modifier 'win+'");
QVERIFY(cut.isEmpty());
QCOMPARE(cut.toString(), QString());
cut = KShortcut("Meta+E");
QVERIFY(cut.primary()[0] == (Qt::META | Qt::Key_E));
}
};
QTEST_KDEMAIN(tst_KShortcut, NoGUI)
#include "kshortcuttest.moc"

View file

@ -73,31 +73,3 @@ void KStandardShortcutTest::testRemoveShortcut()
QVERIFY( cutShortCut.primary() == QKeySequence(Qt::SHIFT + Qt::Key_Delete) );
QVERIFY( cutShortCut.alternate().isEmpty() );
}
void KStandardShortcutTest::testKShortcut()
{
KShortcut null;
QVERIFY( null.isEmpty() );
KShortcut zero( 0 );
QVERIFY( zero.isEmpty() );
QVERIFY( zero.primary().isEmpty() );
QVERIFY( zero.alternate().isEmpty() );
KShortcut quit( "Ctrl+X, Ctrl+C; Z, Z" ); // quit in emacs vs. quit in vi :)
QCOMPARE( quit.primary().toString(), QString::fromLatin1("Ctrl+X, Ctrl+C") );
QCOMPARE( quit.alternate().toString(), QString::fromLatin1("Z, Z") );
QCOMPARE( quit.primary(), QKeySequence(Qt::CTRL + Qt::Key_X, Qt::CTRL + Qt::Key_C) );
QVERIFY( quit != null );
QVERIFY( !( quit == null ) );
QVERIFY( !quit.contains( Qt::CTRL+Qt::Key_X ) );
QVERIFY( !quit.contains( Qt::CTRL+Qt::Key_Z ) );
QVERIFY( !quit.contains( Qt::CTRL+Qt::Key_C ) );
QKeySequence seq( Qt::CTRL+Qt::Key_X, Qt::CTRL+Qt::Key_C );
QVERIFY( quit.contains( seq ) );
QVERIFY( !null.contains( seq ) );
quit.setAlternate( seq );
QCOMPARE( quit.primary().toString(), quit.alternate().toString() );
}

View file

@ -33,9 +33,6 @@ private Q_SLOTS:
void testShortcut();
void testFindStdAccel();
void testRemoveShortcut();
// KShortcut tests
void testKShortcut();
};

View file

@ -23,12 +23,12 @@
#include <kdeui_export.h>
#include <kglobalsettings.h>
#include <ksortablelist.h>
#include <kshortcut.h>
#include <QtCore/QMap>
#include <QtCore/QObject>
#include <QtCore/QStringList>
#include <QtCore/QPointer>
#include <QMap>
#include <QObject>
#include <QStringList>
#include <QPointer>
#include <QKeySequence>
class KCompTreeNode;
class KCompletionPrivate;
@ -670,7 +670,7 @@ public:
// Map for the key binding types mentioned above.
typedef QMap<KeyBindingType, KShortcut> KeyBindingMap;
typedef QMap<KeyBindingType, QKeySequence> KeyBindingMap;
/**
* Default constructor.
@ -852,7 +852,7 @@ public:
* @return true if key-binding can successfully be set.
* @see getKeyBinding
*/
bool setKeyBinding( KeyBindingType item , const KShortcut& key );
bool setKeyBinding( KeyBindingType item , const QKeySequence& key );
/**
* Returns the key-binding used for the specified item.
@ -866,7 +866,7 @@ public:
* @return the key-binding used for the feature given by @p item.
* @see setKeyBinding
*/
KShortcut getKeyBinding( KeyBindingType item ) const;
QKeySequence getKeyBinding( KeyBindingType item ) const;
/**
* Sets this object to use global values for key-bindings.

View file

@ -183,7 +183,7 @@ KGlobalSettings::Completion KCompletionBase::completionMode() const
return d->m_delegate ? d->m_delegate->completionMode() : d->m_iCompletionMode;
}
bool KCompletionBase::setKeyBinding( KeyBindingType item, const KShortcut& cut )
bool KCompletionBase::setKeyBinding( KeyBindingType item, const QKeySequence& cut )
{
if ( d->m_delegate )
return d->m_delegate->setKeyBinding( item, cut );
@ -198,7 +198,7 @@ bool KCompletionBase::setKeyBinding( KeyBindingType item, const KShortcut& cut )
return true;
}
KShortcut KCompletionBase::getKeyBinding( KeyBindingType item ) const
QKeySequence KCompletionBase::getKeyBinding( KeyBindingType item ) const
{
return d->m_delegate ? d->m_delegate->getKeyBinding( item ) : d->m_keyMap[ item ];
}
@ -211,10 +211,10 @@ void KCompletionBase::useGlobalKeyBindings()
}
d->m_keyMap.clear();
d->m_keyMap.insert( TextCompletion, KShortcut() );
d->m_keyMap.insert( PrevCompletionMatch, KShortcut() );
d->m_keyMap.insert( NextCompletionMatch, KShortcut() );
d->m_keyMap.insert( SubstringCompletion, KShortcut() );
d->m_keyMap.insert( TextCompletion, QKeySequence() );
d->m_keyMap.insert( PrevCompletionMatch, QKeySequence() );
d->m_keyMap.insert( NextCompletionMatch, QKeySequence() );
d->m_keyMap.insert( SubstringCompletion, QKeySequence() );
}
KCompletion* KCompletionBase::compObj() const

View file

@ -23,7 +23,8 @@
#ifndef KKEYSERVER_X11_H
#define KKEYSERVER_X11_H
#include "kshortcut.h"
#include <kdeui_export.h>
#include <X11/Xlib.h>
#include <fixx11h.h>

View file

@ -46,8 +46,7 @@ QAction* KUndoStack::createRedoAction(KActionCollection* actionCollection, const
action->setIcon(KIcon("edit-redo"));
action->setIconText(i18n("Redo"));
const KShortcut redocut = KStandardShortcut::redo();
action->setShortcut(QKeySequence(redocut.primary(), redocut.alternate()));
action->setShortcut(KStandardShortcut::redo());
actionCollection->addAction(action->objectName(), action);
@ -66,8 +65,7 @@ QAction* KUndoStack::createUndoAction(KActionCollection* actionCollection, const
action->setIcon(KIcon("edit-undo"));
action->setIconText(i18n("Undo"));
const KShortcut undocut = KStandardShortcut::undo();
action->setShortcut(QKeySequence(undocut.primary(), undocut.alternate()));
action->setShortcut(KStandardShortcut::undo());
actionCollection->addAction(action->objectName(), action);

View file

@ -341,9 +341,9 @@ void KHistoryComboBox::keyPressEvent( QKeyEvent *e )
{
int event_key = e->key() | e->modifiers();
if ( KStandardShortcut::rotateUp().contains(event_key) )
if ( KStandardShortcut::rotateUp().matches(event_key) != QKeySequence::NoMatch )
rotateUp();
else if ( KStandardShortcut::rotateDown().contains(event_key) )
else if ( KStandardShortcut::rotateDown().matches(event_key) != QKeySequence::NoMatch)
rotateDown();
else
KComboBox::keyPressEvent( e );

View file

@ -25,7 +25,6 @@
#include "kicon.h"
#include "klocale.h"
#include "kmessagebox.h"
#include "kshortcut.h"
#include "kaction.h"
#include "kactioncollection.h"
#include "kkeyserver.h"
@ -382,7 +381,7 @@ bool KKeySequenceWidgetPrivate::conflictWithLocalShortcuts(const QKeySequence &k
foreach(QAction * qaction , allActions ) {
KAction *kaction = qobject_cast<KAction*>(qaction);
if (kaction) {
if (kaction->shortcut().conflictsWith(keySequence)) {
if (kaction->shortcut().matches(keySequence) != QKeySequence::NoMatch) {
// A conflict with a KAction. If that action is configurable
// ask the user what to do. If not reject this keySequence.
if (kaction->isShortcutConfigurable ()) {
@ -638,7 +637,7 @@ void KKeySequenceWidget::applyStealShortcut()
Q_FOREACH (KAction *stealAction, d->stealActions) {
// Stealing a shortcut means setting it to an empty one.
stealAction->setShortcut(KShortcut(), KAction::ActiveShortcut);
stealAction->setShortcut(QKeySequence(), KAction::ActiveShortcut);
// The following code will find the action we are about to
// steal from and save it's actioncollection.

View file

@ -22,11 +22,12 @@
#ifndef KKEYSEQUENCEWIDGET_H
#define KKEYSEQUENCEWIDGET_H
#include <kdeui_export.h>
#include <QList>
#include <QAction>
#include <QPushButton>
#include <kshortcut.h>
#include <QKeySequence>
class KKeySequenceWidgetPrivate;
class KAction;

View file

@ -691,12 +691,12 @@ void KLineEdit::keyPressEvent( QKeyEvent *e )
{
const int key = e->key() | e->modifiers();
if ( KStandardShortcut::copy().contains( key ) )
if ( KStandardShortcut::copy().matches( key ) != QKeySequence::NoMatch )
{
copy();
return;
}
else if ( KStandardShortcut::paste().contains( key ) )
else if ( KStandardShortcut::paste().matches( key ) != QKeySequence::NoMatch )
{
// TODO:
// we should restore the original text (not autocompleted), otherwise the paste
@ -705,7 +705,7 @@ void KLineEdit::keyPressEvent( QKeyEvent *e )
paste();
return;
}
else if ( KStandardShortcut::pasteSelection().contains( key ) )
else if ( KStandardShortcut::pasteSelection().matches( key ) != QKeySequence::NoMatch )
{
QString text = QApplication::clipboard()->text( QClipboard::Selection);
insert( text );
@ -713,25 +713,25 @@ void KLineEdit::keyPressEvent( QKeyEvent *e )
return;
}
else if ( KStandardShortcut::cut().contains( key ) )
else if ( KStandardShortcut::cut().matches( key ) != QKeySequence::NoMatch )
{
if( !isReadOnly() )
cut();
return;
}
else if ( KStandardShortcut::undo().contains( key ) )
else if ( KStandardShortcut::undo().matches( key ) != QKeySequence::NoMatch )
{
if( !isReadOnly() )
undo();
return;
}
else if ( KStandardShortcut::redo().contains( key ) )
else if ( KStandardShortcut::redo().matches( key ) != QKeySequence::NoMatch )
{
if( !isReadOnly() )
redo();
return;
}
else if ( KStandardShortcut::deleteWordBack().contains( key ) )
else if ( KStandardShortcut::deleteWordBack().matches( key ) != QKeySequence::NoMatch )
{
cursorWordBackward(true);
if ( hasSelectedText() )
@ -740,7 +740,7 @@ void KLineEdit::keyPressEvent( QKeyEvent *e )
e->accept();
return;
}
else if ( KStandardShortcut::deleteWordForward().contains( key ) )
else if ( KStandardShortcut::deleteWordForward().matches( key ) != QKeySequence::NoMatch )
{
// Workaround for QT bug where
cursorWordForward(true);
@ -750,25 +750,25 @@ void KLineEdit::keyPressEvent( QKeyEvent *e )
e->accept();
return;
}
else if ( KStandardShortcut::backwardWord().contains( key ) )
else if ( KStandardShortcut::backwardWord().matches( key ) != QKeySequence::NoMatch )
{
cursorWordBackward(false);
e->accept();
return;
}
else if ( KStandardShortcut::forwardWord().contains( key ) )
else if ( KStandardShortcut::forwardWord().matches( key ) != QKeySequence::NoMatch )
{
cursorWordForward(false);
e->accept();
return;
}
else if ( KStandardShortcut::beginningOfLine().contains( key ) )
else if ( KStandardShortcut::beginningOfLine().matches( key ) != QKeySequence::NoMatch )
{
home(false);
e->accept();
return;
}
else if ( KStandardShortcut::endOfLine().contains( key ) )
else if ( KStandardShortcut::endOfLine().matches( key ) != QKeySequence::NoMatch )
{
end(false);
e->accept();
@ -999,13 +999,13 @@ void KLineEdit::keyPressEvent( QKeyEvent *e )
else if ( mode == KGlobalSettings::CompletionShell )
{
// Handles completion.
KShortcut cut;
QKeySequence cut;
if ( keys[TextCompletion].isEmpty() )
cut = KStandardShortcut::shortcut(KStandardShortcut::TextCompletion);
else
cut = keys[TextCompletion];
if ( cut.contains( key ) )
if ( cut.matches( key ) != QKeySequence::NoMatch )
{
// Emit completion if the completion mode is CompletionShell
// and the cursor is at the end of the string.
@ -1025,13 +1025,13 @@ void KLineEdit::keyPressEvent( QKeyEvent *e )
if ( mode != KGlobalSettings::CompletionNone )
{
// Handles previous match
KShortcut cut;
QKeySequence cut;
if ( keys[PrevCompletionMatch].isEmpty() )
cut = KStandardShortcut::shortcut(KStandardShortcut::PrevCompletion);
else
cut = keys[PrevCompletionMatch];
if ( cut.contains( key ) )
if ( cut.matches( key ) != QKeySequence::NoMatch )
{
if ( emitSignals() )
emit textRotation( KCompletionBase::PrevCompletionMatch );
@ -1046,7 +1046,7 @@ void KLineEdit::keyPressEvent( QKeyEvent *e )
else
cut = keys[NextCompletionMatch];
if ( cut.contains( key ) )
if ( cut.matches( key ) != QKeySequence::NoMatch )
{
if ( emitSignals() )
emit textRotation( KCompletionBase::NextCompletionMatch );
@ -1059,13 +1059,13 @@ void KLineEdit::keyPressEvent( QKeyEvent *e )
// substring completion
if ( compObj() )
{
KShortcut cut;
QKeySequence cut;
if ( keys[SubstringCompletion].isEmpty() )
cut = KStandardShortcut::shortcut(KStandardShortcut::SubstringCompletion);
else
cut = keys[SubstringCompletion];
if ( cut.contains( key ) )
if ( cut.matches( key ) != QKeySequence::NoMatch )
{
if ( emitSignals() )
emit substringCompletion( text() );
@ -1452,7 +1452,7 @@ void KLineEdit::userCancelled(const QString & cancelText)
bool KLineEditPrivate::overrideShortcut(const QKeyEvent* e)
{
KShortcut scKey;
QKeySequence scKey;
const int key = e->key() | e->modifiers();
const KLineEdit::KeyBindingMap keys = q->getKeyBindings();
@ -1462,7 +1462,7 @@ bool KLineEditPrivate::overrideShortcut(const QKeyEvent* e)
else
scKey = keys[KLineEdit::TextCompletion];
if (scKey.contains( key ))
if (scKey.matches( key ) != QKeySequence::NoMatch)
return true;
if (keys[KLineEdit::NextCompletionMatch].isEmpty())
@ -1470,7 +1470,7 @@ bool KLineEditPrivate::overrideShortcut(const QKeyEvent* e)
else
scKey = keys[KLineEdit::NextCompletionMatch];
if (scKey.contains( key ))
if (scKey.matches( key ) != QKeySequence::NoMatch)
return true;
if (keys[KLineEdit::PrevCompletionMatch].isEmpty())
@ -1478,31 +1478,31 @@ bool KLineEditPrivate::overrideShortcut(const QKeyEvent* e)
else
scKey = keys[KLineEdit::PrevCompletionMatch];
if (scKey.contains( key ))
if (scKey.matches( key ) != QKeySequence::NoMatch)
return true;
// Override all the text manupilation accelerators...
if ( KStandardShortcut::copy().contains( key ) )
if (KStandardShortcut::copy().matches( key ) != QKeySequence::NoMatch)
return true;
else if ( KStandardShortcut::paste().contains( key ) )
else if (KStandardShortcut::paste().matches( key ) != QKeySequence::NoMatch)
return true;
else if ( KStandardShortcut::cut().contains( key ) )
else if (KStandardShortcut::cut().matches( key ) != QKeySequence::NoMatch)
return true;
else if ( KStandardShortcut::undo().contains( key ) )
else if (KStandardShortcut::undo().matches( key ) != QKeySequence::NoMatch)
return true;
else if ( KStandardShortcut::redo().contains( key ) )
else if (KStandardShortcut::redo().matches(key) != QKeySequence::NoMatch)
return true;
else if (KStandardShortcut::deleteWordBack().contains( key ))
else if (KStandardShortcut::deleteWordBack().matches(key) != QKeySequence::NoMatch)
return true;
else if (KStandardShortcut::deleteWordForward().contains( key ))
else if (KStandardShortcut::deleteWordForward().matches(key) != QKeySequence::NoMatch)
return true;
else if (KStandardShortcut::forwardWord().contains( key ))
else if (KStandardShortcut::forwardWord().matches(key) != QKeySequence::NoMatch)
return true;
else if (KStandardShortcut::backwardWord().contains( key ))
else if (KStandardShortcut::backwardWord().matches(key) != QKeySequence::NoMatch)
return true;
else if (KStandardShortcut::beginningOfLine().contains( key ))
else if (KStandardShortcut::beginningOfLine().matches(key) != QKeySequence::NoMatch)
return true;
else if (KStandardShortcut::endOfLine().contains( key ))
else if (KStandardShortcut::endOfLine().matches(key) != QKeySequence::NoMatch)
return true;
// Shortcut overrides for shortcuts that QLineEdit handles

View file

@ -1,137 +0,0 @@
/* This file is part of the KDE libraries
Copyright (C) 2007 Andreas Hartmetz <ahartmetz@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "kshortcutwidget.h"
#include "kiconloader.h"
#include "ui_kshortcutwidget.h"
class KShortcutWidgetPrivate
{
public:
KShortcutWidgetPrivate(KShortcutWidget *q) : q(q) {}
// private slots
void priKeySequenceChanged(const QKeySequence &);
void altKeySequenceChanged(const QKeySequence &);
// members
KShortcutWidget *const q;
Ui::KShortcutWidget ui;
KShortcut cut;
bool holdChangedSignal;
};
KShortcutWidget::KShortcutWidget(QWidget *parent)
: QWidget(parent),
d(new KShortcutWidgetPrivate(this))
{
d->holdChangedSignal = false;
d->ui.setupUi(this);
connect(
d->ui.priEditor, SIGNAL(keySequenceChanged(QKeySequence)),
this, SLOT(priKeySequenceChanged(QKeySequence))
);
connect(
d->ui.altEditor, SIGNAL(keySequenceChanged(QKeySequence)),
this, SLOT(altKeySequenceChanged(QKeySequence))
);
}
KShortcutWidget::~KShortcutWidget()
{
delete d;
}
void KShortcutWidget::setModifierlessAllowed(bool allow)
{
d->ui.priEditor->setModifierlessAllowed(allow);
d->ui.altEditor->setModifierlessAllowed(allow);
}
bool KShortcutWidget::isModifierlessAllowed()
{
return d->ui.priEditor->isModifierlessAllowed();
}
void KShortcutWidget::setClearButtonsShown(bool show)
{
d->ui.priEditor->setClearButtonShown(show);
d->ui.altEditor->setClearButtonShown(show);
}
KShortcut KShortcutWidget::shortcut() const
{
KShortcut ret;
ret.setPrimary(d->ui.priEditor->keySequence());
ret.setAlternate(d->ui.altEditor->keySequence());
return ret;
}
void KShortcutWidget::setCheckActionCollections(const QList<KActionCollection *> &actionCollections)
{
d->ui.priEditor->setCheckActionCollections(actionCollections);
d->ui.altEditor->setCheckActionCollections(actionCollections);
}
void KShortcutWidget::applyStealShortcut()
{
d->ui.priEditor->applyStealShortcut();
d->ui.altEditor->applyStealShortcut();
}
void KShortcutWidget::setShortcut(const KShortcut &newSc)
{
if (newSc == d->cut) {
return;
}
d->holdChangedSignal = true;
d->ui.priEditor->setKeySequence(newSc.primary());
d->ui.altEditor->setKeySequence(newSc.alternate());
d->holdChangedSignal = false;
emit shortcutChanged(d->cut);
}
void KShortcutWidget::clearShortcut()
{
setShortcut(KShortcut());
}
void KShortcutWidgetPrivate::priKeySequenceChanged(const QKeySequence &seq)
{
cut.setPrimary(seq);
if (!holdChangedSignal) {
emit q->shortcutChanged(cut);
}
}
void KShortcutWidgetPrivate::altKeySequenceChanged(const QKeySequence &seq)
{
cut.setAlternate(seq);
if (!holdChangedSignal) {
emit q->shortcutChanged(cut);
}
}
#include "moc_kshortcutwidget.cpp"

View file

@ -1,86 +0,0 @@
/* This file is part of the KDE libraries
Copyright (C) 2007 Andreas Hartmetz <ahartmetz@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KSHORTCUTWIDGET_H
#define KSHORTCUTWIDGET_H
#include <QtGui/QWidget>
#include "kshortcut.h"
class KActionCollection;
class KShortcutWidgetPrivate;
/**
* \image html kshortcutwidget.png "KDE Shortcut Widget"
*/
class KDEUI_EXPORT KShortcutWidget : public QWidget
{
Q_OBJECT
Q_PROPERTY(bool modifierlessAllowed READ isModifierlessAllowed WRITE setModifierlessAllowed)
public:
KShortcutWidget(QWidget *parent = 0);
~KShortcutWidget();
void setModifierlessAllowed(bool allow);
bool isModifierlessAllowed();
void setClearButtonsShown(bool show);
KShortcut shortcut() const;
/**
* Set a list of action collections to check against for conflictuous shortcut.
*
* If there is a conflictuous shortcut with a KAction, and that his shortcut can be configured
* (KAction::isShortcutConfigurable() returns true) the user will be prompted for eventually steal
* the shortcut from this action
*
* Global shortcuts are automatically checked for conflicts
*
* Don't forget to call applyStealShortcut to actually steal the shortcut.
*
* @since 4.1
*/
void setCheckActionCollections(const QList<KActionCollection *>& actionCollections);
Q_SIGNALS:
void shortcutChanged(const KShortcut &cut);
public Q_SLOTS:
void setShortcut(const KShortcut &cut);
void clearShortcut();
/**
* Actually remove the shortcut that the user wanted to steal, from the
* action that was using it.
*
* To be called before you apply your changes.
* No shortcuts are stolen until this function is called.
*/
void applyStealShortcut();
private:
Q_PRIVATE_SLOT(d, void priKeySequenceChanged(const QKeySequence &))
Q_PRIVATE_SLOT(d, void altKeySequenceChanged(const QKeySequence &))
private:
friend class KShortcutWidgetPrivate;
KShortcutWidgetPrivate *const d;
};
#endif //KSHORTCUTWIDGET_H

View file

@ -1,76 +0,0 @@
<ui version="4.0" >
<class>KShortcutWidget</class>
<widget class="QWidget" name="KShortcutWidget" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>180</width>
<height>49</height>
</rect>
</property>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QLabel" name="priLabel" >
<property name="text" >
<string>Main:</string>
</property>
</widget>
</item>
<item>
<widget class="KKeySequenceWidget" native="1" name="priEditor" >
<property name="minimumSize" >
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>50</width>
<height>31</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="altLabel" >
<property name="text" >
<string>Alternate:</string>
</property>
</widget>
</item>
<item>
<widget class="KKeySequenceWidget" native="1" name="altEditor" >
<property name="minimumSize" >
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KKeySequenceWidget</class>
<extends>QWidget</extends>
<header>kkeysequencewidget.h</header>
</customwidget>
</customwidgets>
<connections/>
</ui>

View file

@ -220,46 +220,46 @@ bool KTextEdit::Private::handleShortcut(const QKeyEvent *event)
{
const int key = (event->key() | event->modifiers());
if (KStandardShortcut::copy().contains(key)) {
if (KStandardShortcut::copy().matches(key) != QKeySequence::NoMatch) {
parent->copy();
return true;
} else if (KStandardShortcut::paste().contains(key)) {
} else if (KStandardShortcut::paste().matches(key) != QKeySequence::NoMatch) {
parent->paste();
return true;
} else if (KStandardShortcut::cut().contains(key)) {
} else if (KStandardShortcut::cut().matches(key) != QKeySequence::NoMatch) {
parent->cut();
return true;
} else if (KStandardShortcut::undo().contains(key)) {
} else if (KStandardShortcut::undo().matches(key) != QKeySequence::NoMatch) {
if (!parent->isReadOnly()) {
parent->undo();
}
return true;
} else if (KStandardShortcut::redo().contains(key)) {
} else if (KStandardShortcut::redo().matches(key) != QKeySequence::NoMatch) {
if (!parent->isReadOnly()) {
parent->redo();
}
return true;
} else if (KStandardShortcut::deleteWordBack().contains(key)) {
} else if (KStandardShortcut::deleteWordBack().matches(key) != QKeySequence::NoMatch) {
if (!parent->isReadOnly()) {
parent->deleteWordBack();
}
return true;
} else if ( KStandardShortcut::deleteWordForward().contains(key)) {
} else if ( KStandardShortcut::deleteWordForward().matches(key) != QKeySequence::NoMatch) {
if (!parent->isReadOnly()) {
parent->deleteWordForward();
}
return true;
} else if ( KStandardShortcut::backwardWord().contains(key)) {
} else if ( KStandardShortcut::backwardWord().matches(key) != QKeySequence::NoMatch) {
QTextCursor cursor = parent->textCursor();
cursor.movePosition(QTextCursor::PreviousWord);
parent->setTextCursor(cursor);
return true;
} else if (KStandardShortcut::forwardWord().contains(key)) {
} else if (KStandardShortcut::forwardWord().matches(key) != QKeySequence::NoMatch) {
QTextCursor cursor = parent->textCursor();
cursor.movePosition(QTextCursor::NextWord);
parent->setTextCursor(cursor);
return true;
} else if ( KStandardShortcut::next().contains(key)) {
} else if ( KStandardShortcut::next().matches(key) != QKeySequence::NoMatch) {
QTextCursor cursor = parent->textCursor();
bool moved = false;
qreal lastY = parent->cursorRect(cursor).bottom();
@ -277,7 +277,7 @@ bool KTextEdit::Private::handleShortcut(const QKeyEvent *event)
}
parent->setTextCursor(cursor);
return true;
} else if (KStandardShortcut::prior().contains(key)) {
} else if (KStandardShortcut::prior().matches(key) != QKeySequence::NoMatch) {
QTextCursor cursor = parent->textCursor();
bool moved = false;
qreal lastY = parent->cursorRect(cursor).bottom();
@ -295,38 +295,38 @@ bool KTextEdit::Private::handleShortcut(const QKeyEvent *event)
}
parent->setTextCursor(cursor);
return true;
} else if ( KStandardShortcut::begin().contains(key)) {
} else if (KStandardShortcut::begin().matches(key) != QKeySequence::NoMatch) {
QTextCursor cursor = parent->textCursor();
cursor.movePosition(QTextCursor::Start);
parent->setTextCursor(cursor);
return true;
} else if (KStandardShortcut::end().contains(key)) {
} else if (KStandardShortcut::end().matches(key) != QKeySequence::NoMatch) {
QTextCursor cursor = parent->textCursor();
cursor.movePosition(QTextCursor::End);
parent->setTextCursor(cursor);
return true;
} else if (KStandardShortcut::beginningOfLine().contains(key)) {
} else if (KStandardShortcut::beginningOfLine().matches(key) != QKeySequence::NoMatch) {
QTextCursor cursor = parent->textCursor();
cursor.movePosition(QTextCursor::StartOfLine);
parent->setTextCursor(cursor);
return true;
} else if (KStandardShortcut::endOfLine().contains(key)) {
} else if (KStandardShortcut::endOfLine().matches(key) != QKeySequence::NoMatch) {
QTextCursor cursor = parent->textCursor();
cursor.movePosition(QTextCursor::EndOfLine);
parent->setTextCursor(cursor);
return true;
} else if (findReplaceEnabled && KStandardShortcut::find().contains(key)) {
} else if (findReplaceEnabled && KStandardShortcut::find().matches(key) != QKeySequence::NoMatch) {
parent->slotFind();
return true;
} else if (findReplaceEnabled && KStandardShortcut::findNext().contains(key)) {
} else if (findReplaceEnabled && KStandardShortcut::findNext().matches(key) != QKeySequence::NoMatch) {
parent->slotFindNext();
return true;
} else if (findReplaceEnabled && KStandardShortcut::replace().contains(key)) {
} else if (findReplaceEnabled && KStandardShortcut::replace().matches(key) != QKeySequence::NoMatch) {
if (!parent->isReadOnly()) {
parent->slotReplace();
}
return true;
} else if (KStandardShortcut::pasteSelection().contains(key)) {
} else if (KStandardShortcut::pasteSelection().matches(key) != QKeySequence::NoMatch) {
QString text = QApplication::clipboard()->text(QClipboard::Selection);
if (!text.isEmpty()) {
// TODO: check if this is html? (MiB)
@ -791,45 +791,45 @@ void KTextEdit::showTabAction(bool show)
bool KTextEdit::Private::overrideShortcut(const QKeyEvent *event)
{
const int key = (event->key() | event->modifiers());
const QKeySequence key = QKeySequence(event->key() | event->modifiers());
if (KStandardShortcut::copy().contains(key)) {
if (KStandardShortcut::copy().matches(key) != QKeySequence::NoMatch) {
return true;
} else if (KStandardShortcut::paste().contains(key)) {
} else if (KStandardShortcut::paste().matches(key) != QKeySequence::NoMatch) {
return true;
} else if (KStandardShortcut::cut().contains(key)) {
} else if (KStandardShortcut::cut().matches(key) != QKeySequence::NoMatch) {
return true;
} else if (KStandardShortcut::undo().contains(key)) {
} else if (KStandardShortcut::undo().matches(key) != QKeySequence::NoMatch) {
return true;
} else if (KStandardShortcut::redo().contains(key)) {
} else if (KStandardShortcut::redo().matches(key) != QKeySequence::NoMatch) {
return true;
} else if ( KStandardShortcut::deleteWordBack().contains(key) ) {
} else if ( KStandardShortcut::deleteWordBack().matches(key) != QKeySequence::NoMatch) {
return true;
} else if (KStandardShortcut::deleteWordForward().contains(key)) {
} else if (KStandardShortcut::deleteWordForward().matches(key) != QKeySequence::NoMatch) {
return true;
} else if (KStandardShortcut::backwardWord().contains(key)) {
} else if (KStandardShortcut::backwardWord().matches(key) != QKeySequence::NoMatch) {
return true;
} else if (KStandardShortcut::forwardWord().contains(key)) {
} else if (KStandardShortcut::forwardWord().matches(key) != QKeySequence::NoMatch) {
return true;
} else if (KStandardShortcut::next().contains(key)) {
} else if (KStandardShortcut::next().matches(key) != QKeySequence::NoMatch) {
return true;
} else if (KStandardShortcut::prior().contains(key)) {
} else if (KStandardShortcut::prior().matches(key) != QKeySequence::NoMatch) {
return true;
} else if (KStandardShortcut::begin().contains(key)) {
} else if (KStandardShortcut::begin().matches(key) != QKeySequence::NoMatch) {
return true;
} else if (KStandardShortcut::end().contains(key)) {
} else if (KStandardShortcut::end().matches(key) != QKeySequence::NoMatch) {
return true;
} else if (KStandardShortcut::beginningOfLine().contains(key)) {
} else if (KStandardShortcut::beginningOfLine().matches(key) != QKeySequence::NoMatch) {
return true;
} else if (KStandardShortcut::endOfLine().contains(key)) {
} else if (KStandardShortcut::endOfLine().matches(key) != QKeySequence::NoMatch) {
return true;
} else if (KStandardShortcut::pasteSelection().contains(key) ) {
} else if (KStandardShortcut::pasteSelection().matches(key) != QKeySequence::NoMatch) {
return true;
} else if (findReplaceEnabled && KStandardShortcut::find().contains(key)) {
} else if (findReplaceEnabled && KStandardShortcut::find().matches(key) != QKeySequence::NoMatch) {
return true;
} else if (findReplaceEnabled && KStandardShortcut::findNext().contains(key)) {
} else if (findReplaceEnabled && KStandardShortcut::findNext().matches(key) != QKeySequence::NoMatch) {
return true;
} else if (findReplaceEnabled && KStandardShortcut::replace().contains(key)) {
} else if (findReplaceEnabled && KStandardShortcut::replace().matches(key) != QKeySequence::NoMatch) {
return true;
} else if (event->matches(QKeySequence::SelectAll)) { // currently missing in QTextEdit
return true;

View file

@ -25,19 +25,17 @@
#include "kmenu.h"
#include "kaction.h"
#include "kactioncollection.h"
#include <kdialog.h>
#include <kshortcutwidget.h>
#include <klocale.h>
#include <kdebug.h>
#include "kdialog.h"
#include "kkeysequencewidget.h"
#include "klocale.h"
#include "kapplication.h"
#include "kmainwindow.h"
#include "ktoolbar.h"
#include "kselectaction.h"
#include "kdebug.h"
#include <QWidget>
#include <QtXml/qdom.h>
#include <kapplication.h>
#include <kmainwindow.h>
#include <ktoolbar.h>
#include <kselectaction.h>
namespace KDEPrivate {
@ -99,8 +97,8 @@ void KMenuMenuHandler::slotSetShortcut()
return;
KDialog dialog(m_builder->widget());
KShortcutWidget swidget(&dialog);
swidget.setShortcut(action->shortcut());
KKeySequenceWidget swidget(&dialog);
swidget.setKeySequence(action->shortcut());
dialog.setMainWidget(&swidget);
KActionCollection* parentCollection = 0;
if(dynamic_cast<KXMLGUIClient*>(m_builder))
@ -116,7 +114,7 @@ void KMenuMenuHandler::slotSetShortcut()
if(dialog.exec())
{
action->setShortcut(swidget.shortcut(), KAction::ActiveShortcut);
action->setShortcut(swidget.keySequence(), KAction::ActiveShortcut);
swidget.applyStealShortcut();
if(parentCollection)
parentCollection->writeSettings();

View file

@ -22,8 +22,13 @@
#include "kxmlguifactory_p.h"
#include "kxmlguiclient.h"
#include "kxmlguibuilder.h"
#include <assert.h>
#include "kcomponentdata.h"
#include "kglobal.h"
#include "kstandarddirs.h"
#include "kaction.h"
#include "kshortcutsdialog.h"
#include "kactioncollection.h"
#include "kdebug.h"
#include <QtCore/QDir>
#include <QtXml/qdom.h>
@ -34,15 +39,7 @@
#include <QtCore/QVariant>
#include <QTextCodec>
#include <kdebug.h>
#include <kcomponentdata.h>
#include <kglobal.h>
#include <kshortcut.h>
#include <kstandarddirs.h>
#include "kaction.h"
#include "kshortcutsdialog.h"
#include "kactioncollection.h"
#include <assert.h>
using namespace KXMLGUI;
@ -345,8 +342,8 @@ void KXMLGUIFactoryPrivate::saveDefaultActionProperties(const QList<QAction *>&
if (KAction* kaction = qobject_cast<KAction*>(action)) {
// Check if the default shortcut is set
KShortcut defaultShortcut = kaction->shortcut(KAction::DefaultShortcut);
KShortcut activeShortcut = kaction->shortcut(KAction::ActiveShortcut);
QKeySequence defaultShortcut = kaction->shortcut(KAction::DefaultShortcut);
QKeySequence activeShortcut = kaction->shortcut(KAction::ActiveShortcut);
//kDebug() << kaction->objectName() << "default=" << defaultShortcut.toString() << "active=" << activeShortcut.toString();
// Check if we have an empty default shortcut and an non empty
@ -365,7 +362,7 @@ void KXMLGUIFactoryPrivate::saveDefaultActionProperties(const QList<QAction *>&
// A QAction used with KXMLGUI? Set our property and ignore it.
if ( !action->isSeparator() )
kError() << "Attempt to use QAction" << action->objectName() << "with KXMLGUIFactory!";
action->setProperty("_k_DefaultShortcut", KShortcut());
action->setProperty("_k_DefaultShortcut", QKeySequence());
}
}
@ -626,19 +623,19 @@ void KXMLGUIFactoryPrivate::configureAction( QAction *action, const QDomAttr &at
propertyValue = QVariant( attribute.value().toInt() );
} else if ( propertyType == QVariant::UInt ) {
propertyValue = QVariant( attribute.value().toUInt() );
} else if ( propertyType == QVariant::UserType && action->property( attrName.toLatin1() ).userType() == qMetaTypeId<KShortcut>() ) {
} else if ( propertyType == QVariant::KeySequence) {
// Setting the shortcut by property also sets the default shortcut (which is incorrect), so we have to do it directly
if (KAction* ka = qobject_cast<KAction*>(action)) {
if (attrName=="globalShortcut") {
ka->setGlobalShortcut(KShortcut(attribute.value()), KAction::ActiveShortcut);
ka->setGlobalShortcut(QKeySequence(attribute.value()), KAction::ActiveShortcut);
} else {
ka->setShortcut(KShortcut(attribute.value()), KAction::ActiveShortcut);
ka->setShortcut(QKeySequence(attribute.value()), KAction::ActiveShortcut);
}
if (shortcutOption & KXMLGUIFactoryPrivate::SetDefaultShortcut)
ka->setShortcut(KShortcut(attribute.value()), KAction::DefaultShortcut);
ka->setShortcut(QKeySequence(attribute.value()), KAction::DefaultShortcut);
return;
}
propertyValue = KShortcut( attribute.value() );
propertyValue = QKeySequence( attribute.value() );
} else {
propertyValue = QVariant( attribute.value() );
}
@ -684,13 +681,13 @@ void KXMLGUIFactoryPrivate::applyShortcutScheme(KXMLGUIClient *client, const QLi
if (schemeName != "Default") {
foreach (QAction *action, actions) {
if (KAction *kaction = qobject_cast<KAction*>(action)) {
kaction->setShortcut(KShortcut(), KAction::ActiveShortcut);
kaction->setShortcut(QKeySequence(), KAction::ActiveShortcut);
// We clear the default shortcut as well because the shortcut scheme will set its own defaults
kaction->setShortcut(KShortcut(), KAction::DefaultShortcut);
kaction->setShortcut(QKeySequence(), KAction::DefaultShortcut);
continue;
}
if (action) {
action->setProperty("shortcut", KShortcut());
action->setProperty("shortcut", QKeySequence());
}
}
} else {
@ -699,7 +696,7 @@ void KXMLGUIFactoryPrivate::applyShortcutScheme(KXMLGUIClient *client, const QLi
if (KAction *kaction = qobject_cast<KAction*>(action)) {
QVariant savedDefaultShortcut = kaction->property("_k_DefaultShortcut");
if (savedDefaultShortcut.isValid()) {
KShortcut shortcut = savedDefaultShortcut.value<KShortcut>();
QKeySequence shortcut = savedDefaultShortcut.value<QKeySequence>();
//kDebug() << "scheme said" << shortcut.toString() << "for action" << kaction->objectName();
kaction->setShortcut(shortcut, KAction::ActiveShortcut);
kaction->setShortcut(shortcut, KAction::DefaultShortcut);
@ -707,7 +704,7 @@ void KXMLGUIFactoryPrivate::applyShortcutScheme(KXMLGUIClient *client, const QLi
}
}
if (action) {
action->setProperty("shortcut", KShortcut());
action->setProperty("shortcut", QKeySequence());
}
}
}

View file

@ -188,12 +188,6 @@ WhatsThis=A widget to edit a list of shortcuts.
IncludeFile=kshortcutseditor.h
Group=Input (KDE)
[KShortcutWidget]
ToolTip=Shortcut picker widget. (KDE)
WhatsThis=A widget to pick a KShortcut.
IncludeFile=kshortcutwidget.h
Group=Buttons (KDE)
[KSqueezedTextLabel]
ToolTip=A QLabel that squeezes its text (KDE)
WhatsThis=If the text is too long to fit into the label it is divided into remaining left and right parts which are separated by three dots

View file

@ -1739,13 +1739,13 @@ void KDirOperator::setupActions()
KAction* trash = new KAction(i18n("Move to Trash"), this);
d->actionCollection->addAction("trash", trash);
trash->setIcon(KIcon("user-trash"));
trash->setShortcut(KShortcut(Qt::Key_Delete));
trash->setShortcut(QKeySequence(Qt::Key_Delete));
connect(trash, SIGNAL(triggered(bool)), SLOT(trashSelected()));
KAction* action = new KAction(i18n("Delete"), this);
d->actionCollection->addAction("delete", action);
action->setIcon(KIcon("edit-delete"));
action->setShortcut(KShortcut(Qt::SHIFT + Qt::Key_Delete));
action->setShortcut(QKeySequence(Qt::SHIFT + Qt::Key_Delete));
connect(action, SIGNAL(triggered(bool)), this, SLOT(deleteSelected()));
// the sort menu actions
@ -1836,7 +1836,7 @@ void KDirOperator::setupActions()
action = new KAction(i18n("Properties"), this);
d->actionCollection->addAction("properties", action);
action->setIcon(KIcon("document-properties"));
action->setShortcut(KShortcut(Qt::ALT + Qt::Key_Return));
action->setShortcut(QKeySequence(Qt::ALT + Qt::Key_Return));
connect(action, SIGNAL(triggered(bool)), this, SLOT(_k_slotProperties()));
// the view menu actions

View file

@ -427,8 +427,7 @@ KFileWidget::KFileWidget( const KUrl& _startDir, QWidget *parent )
menu->addSeparator();
KAction * showHidden = qobject_cast<KAction*>(coll->action( "show hidden" ));
if (showHidden) {
showHidden->setShortcut(
KShortcut( QKeySequence(Qt::ALT + Qt::Key_Period), QKeySequence(Qt::Key_F8) ) );
showHidden->setShortcut(QKeySequence(Qt::ALT + Qt::Key_Period, Qt::Key_F8) );
}
menu->addAction( showHidden );
menu->addAction( showSidebarAction );

View file

@ -82,7 +82,6 @@
#include <kstandarddirs.h>
#include <kservice.h>
#include <kservicetypetrader.h>
#include <kshortcut.h>
#include <kwindowsystem.h>
#include <kpushbutton.h>
#include <krandom.h>
@ -274,7 +273,7 @@ void Applet::restore(KConfigGroup &group)
KConfigGroup shortcutConfig(&group, "Shortcuts");
QString shortcutText = shortcutConfig.readEntryUntranslated("global", QString());
if (!shortcutText.isEmpty()) {
setGlobalShortcut(KShortcut(shortcutText));
setGlobalShortcut(QKeySequence(shortcutText));
/*
kDebug() << "got global shortcut for" << name() << "of" << QKeySequence(shortcutText);
kDebug() << "set to" << d->activationAction->objectName()
@ -1423,7 +1422,7 @@ Containment *Applet::containment() const
return c;
}
void Applet::setGlobalShortcut(const KShortcut &shortcut)
void Applet::setGlobalShortcut(const QKeySequence &shortcut)
{
if (!d->activationAction) {
d->activationAction = new KAction(this);
@ -1441,7 +1440,7 @@ void Applet::setGlobalShortcut(const KShortcut &shortcut)
return;
}
//kDebug() << "before" << shortcut.primary() << d->activationAction->globalShortcut().primary();
//kDebug() << "before" << shortcut << d->activationAction->globalShortcut();
d->activationAction->setGlobalShortcut(
shortcut,
KAction::ShortcutTypes(KAction::ActiveShortcut | KAction::DefaultShortcut)
@ -1461,13 +1460,13 @@ void AppletPrivate::globalShortcutChanged()
//kDebug() << "after" << shortcut.primary() << d->activationAction->globalShortcut().primary();
}
KShortcut Applet::globalShortcut() const
QKeySequence Applet::globalShortcut() const
{
if (d->activationAction) {
return d->activationAction->globalShortcut();
}
return KShortcut();
return QKeySequence();
}
bool Applet::isPopupShowing() const
@ -1567,21 +1566,21 @@ KActionCollection* AppletPrivate::defaultActions(QObject *parent)
configAction->setAutoRepeat(false);
configAction->setText(i18n("Widget Settings"));
configAction->setIcon(KIcon("configure"));
configAction->setShortcut(KShortcut(Qt::ALT + Qt::Key_S));
configAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_S));
configAction->setData(AbstractToolBox::ConfigureTool);
KAction *closeApplet = actions->addAction("remove");
closeApplet->setAutoRepeat(false);
closeApplet->setText(i18n("Remove this Widget"));
closeApplet->setIcon(KIcon("edit-delete"));
closeApplet->setShortcut(KShortcut(Qt::ALT + Qt::Key_R));
closeApplet->setShortcut(QKeySequence(Qt::ALT + Qt::Key_R));
closeApplet->setData(AbstractToolBox::DestructiveTool);
KAction *runAssociatedApplication = actions->addAction("run associated application");
runAssociatedApplication->setAutoRepeat(false);
runAssociatedApplication->setText(i18n("Run the Associated Application"));
runAssociatedApplication->setIcon(KIcon("system-run"));
runAssociatedApplication->setShortcut(KShortcut(Qt::ALT + Qt::Key_T));
runAssociatedApplication->setShortcut(QKeySequence(Qt::ALT + Qt::Key_T));
runAssociatedApplication->setVisible(false);
runAssociatedApplication->setEnabled(false);
runAssociatedApplication->setData(AbstractToolBox::ControlTool);
@ -1811,7 +1810,7 @@ void AppletPrivate::addGlobalShortcutsPage(KConfigDialog *dialog)
QObject::connect(shortcutEditor.data(), SIGNAL(keySequenceChanged(QKeySequence)), dialog, SLOT(settingsModified()));
}
shortcutEditor.data()->setKeySequence(q->globalShortcut().primary());
shortcutEditor.data()->setKeySequence(q->globalShortcut());
layout->addWidget(shortcutEditor.data());
layout->addStretch();
dialog->addPage(page, i18n("Keyboard Shortcut"), "preferences-desktop-keyboard");
@ -1824,8 +1823,8 @@ void AppletPrivate::configDialogFinished()
{
if (shortcutEditor) {
QKeySequence sequence = shortcutEditor.data()->keySequence();
if (sequence != q->globalShortcut().primary()) {
q->setGlobalShortcut(KShortcut(sequence));
if (sequence != q->globalShortcut()) {
q->setGlobalShortcut(sequence);
emit q->configNeedsSaving();
}
}

View file

@ -27,11 +27,11 @@
#include <QIcon>
#include <QWidget>
#include <QGraphicsView>
#include <QKeySequence>
#include <kurl.h>
#include <kconfiggroup.h>
#include <kplugininfo.h>
#include <kshortcut.h>
#include <kdeversion.h>
#include <plasma/plasma.h>
@ -459,13 +459,13 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
/**
* Sets the global shorcut to associate with this widget.
*/
void setGlobalShortcut(const KShortcut &shortcut);
void setGlobalShortcut(const QKeySequence &shortcut);
/**
* @return the global shortcut associated with this wiget, or
* an empty shortcut if no global shortcut is associated.
*/
KShortcut globalShortcut() const;
QKeySequence globalShortcut() const;
/**
* @return true is there is a popup assoiated with this Applet

View file

@ -212,7 +212,7 @@ void ContainmentPrivate::addDefaultActions(KActionCollection *actions, Containme
//adjust applet actions
KAction *appAction = qobject_cast<KAction*>(actions->action("remove"));
appAction->setShortcut(KShortcut(Qt::ALT + Qt::Key_R));
appAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_R));
if (c && c->d->isPanelContainment()) {
appAction->setText(i18n("Remove this Panel"));
}
@ -222,19 +222,19 @@ void ContainmentPrivate::addDefaultActions(KActionCollection *actions, Containme
appletBrowserAction->setAutoRepeat(false);
appletBrowserAction->setText(i18n("Add Widgets..."));
appletBrowserAction->setIcon(KIcon("list-add"));
appletBrowserAction->setShortcut(KShortcut(Qt::ALT + Qt::Key_A));
appletBrowserAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_A));
appletBrowserAction->setData(AbstractToolBox::AddTool);
KAction *action = actions->addAction("next applet");
action->setText(i18n("Next Widget"));
//no icon
action->setShortcut(KShortcut(Qt::ALT + Qt::Key_N));
action->setShortcut(QKeySequence(Qt::ALT + Qt::Key_N));
action->setData(AbstractToolBox::ControlTool);
action = actions->addAction("previous applet");
action->setText(i18n("Previous Widget"));
//no icon
action->setShortcut(KShortcut(Qt::ALT + Qt::Key_P));
action->setShortcut(QKeySequence(Qt::ALT + Qt::Key_P));
action->setData(AbstractToolBox::ControlTool);
}

View file

@ -777,7 +777,7 @@ void CoronaPrivate::init()
lockAction->setAutoRepeat(true);
lockAction->setIcon(KIcon("object-locked"));
lockAction->setData(AbstractToolBox::ControlTool);
lockAction->setShortcut(KShortcut(Qt::ALT + Qt::Key_L));
lockAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_L));
lockAction->setShortcutContext(Qt::ApplicationShortcut);
// FIXME this doesn't really belong here. desktop KCM maybe?
@ -789,7 +789,7 @@ void CoronaPrivate::init()
action->setIcon(KIcon("configure-shortcuts"));
action->setAutoRepeat(false);
action->setData(AbstractToolBox::ConfigureTool);
// action->setShortcut(KShortcut(Qt::CTRL + Qt::Key_H));
// action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_H));
action->setShortcutContext(Qt::ApplicationShortcut);
// fake containment/applet actions