kdeui: format and indent

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2023-08-27 07:08:35 +03:00
parent 97b1ea46c1
commit 2bf47096e8
10 changed files with 316 additions and 315 deletions

View file

@ -50,9 +50,9 @@ void TabConnectedWidget::paintEvent(QPaintEvent *e)
ShortcutEditWidget::ShortcutEditWidget(QWidget *viewport, const QKeySequence &defaultSeq,
const QKeySequence &activeSeq, bool allowLetterShortcuts)
: TabConnectedWidget(viewport),
m_defaultKeySequence(defaultSeq),
m_isUpdating(false)
: TabConnectedWidget(viewport),
m_defaultKeySequence(defaultSeq),
m_isUpdating(false)
{
QGridLayout *layout = new QGridLayout(this);
@ -75,12 +75,18 @@ ShortcutEditWidget::ShortcutEditWidget(QWidget *viewport, const QKeySequence &de
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*)));
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*))
);
}
@ -92,11 +98,12 @@ KKeySequenceWidget::ShortcutTypes ShortcutEditWidget::checkForConflictsAgainst()
//slot
void ShortcutEditWidget::defaultToggled(bool checked)
{
if (m_isUpdating)
if (m_isUpdating) {
return;
}
m_isUpdating = true;
if (checked) {
if (checked) {
// The default key sequence should be activated. We check first if this is
// possible.
if (m_customEditor->isKeySequenceAvailable(m_defaultKeySequence)) {
@ -116,8 +123,7 @@ void ShortcutEditWidget::defaultToggled(bool checked)
}
void ShortcutEditWidget::setCheckActionCollections(
const QList<KActionCollection*> checkActionCollections)
void ShortcutEditWidget::setCheckActionCollections(const QList<KActionCollection*> &checkActionCollections)
{
// We just forward them to out KKeySequenceWidget.
m_customEditor->setCheckActionCollections(checkActionCollections);
@ -130,7 +136,7 @@ void ShortcutEditWidget::setCheckForConflictsAgainst(KKeySequenceWidget::Shortcu
}
void ShortcutEditWidget::setComponentName(const QString componentName)
void ShortcutEditWidget::setComponentName(const QString &componentName)
{
m_customEditor->setComponentName(componentName);
}
@ -169,7 +175,6 @@ void ShortcutEditWidget::setCustom(const QKeySequence &seq)
m_isUpdating = false;
}
void ShortcutEditWidget::setKeySequence(const QKeySequence &activeSeq)
{
if (activeSeq == m_defaultLabel->text()) {
@ -184,4 +189,3 @@ void ShortcutEditWidget::setKeySequence(const QKeySequence &activeSeq)
}
}
}

View file

@ -95,23 +95,26 @@ KShortcutSchemesEditor::KShortcutSchemesEditor(KShortcutsDialog *parent)
void KShortcutSchemesEditor::newScheme()
{
bool ok;
const QString newName = KInputDialog::getText(i18n("Name for New Scheme"),
i18n("Name for new scheme:"), i18n("New Scheme"), &ok,this);
if (!ok )
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)
{
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))
if (!schemeFile.open(QFile::WriteOnly | QFile::Truncate)) {
return;
}
QDomDocument doc;
QDomElement docElem = doc.createElement("kpartgui");
@ -142,8 +145,9 @@ Note that this will not remove any system wide shortcut schemes.", currentScheme
foreach (KActionCollection *collection, m_dialog->actionCollections())
{
const KXMLGUIClient *client = collection->parentGUIClient();
if (!client)
if (!client) {
continue;
}
QFile::remove(KShortcutSchemesHelper::shortcutSchemeFileName(client, currentScheme()));
}
@ -161,15 +165,16 @@ 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());
QString exportTo = QFileDialog::getExistingDirectory(
this, i18n("Export to Location"),
QDir::currentPath()
);
if (exportTo.isEmpty())
return;
QDir schemeRoot(exportTo);
if (!schemeRoot.exists(exportTo))
{
if (!schemeRoot.exists(exportTo)) {
KMessageBox::error(this, i18n("Could not export shortcuts scheme because the location is invalid."));
return;
}
@ -177,20 +182,22 @@ void KShortcutSchemesEditor::exportShortcutsScheme()
foreach (KActionCollection *collection, m_dialog->actionCollections())
{
const KXMLGUIClient *client = collection->parentGUIClient();
if (!client) continue;
KShortcutSchemesHelper::exportActionCollection(collection,
currentScheme(), exportTo + '/');
if (!client) {
continue;
}
KShortcutSchemesHelper::exportActionCollection(collection, currentScheme(), exportTo + '/');
}
}
void KShortcutSchemesEditor::saveAsDefaultsForScheme()
{
foreach (KActionCollection *collection, m_dialog->actionCollections())
foreach (KActionCollection *collection, m_dialog->actionCollections()) {
KShortcutSchemesHelper::exportActionCollection(collection, currentScheme());
}
}
void KShortcutSchemesEditor::updateDeleteButton()
{
m_deleteScheme->setEnabled(m_schemesList->count()>=1);
m_deleteScheme->setEnabled(m_schemesList->count() >= 1);
}

View file

@ -55,8 +55,10 @@ class KShortcutsDialog::KShortcutsDialogPrivate
{
public:
KShortcutsDialogPrivate(KShortcutsDialog *q): q(q), m_keyChooser(0), m_schemeEditor(0)
{}
KShortcutsDialogPrivate(KShortcutsDialog *q)
: q(q), m_keyChooser(0), m_schemeEditor(0)
{
}
QList<KActionCollection*> m_collections;
@ -76,7 +78,7 @@ public:
// passing an empty stream forces the clients to reread the XML
KXMLGUIClient *client = const_cast<KXMLGUIClient *>(collection->parentGUIClient());
if (client) {
client->setXMLGUIBuildDocument( QDomDocument() );
client->setXMLGUIBuildDocument(QDomDocument());
}
}
@ -123,28 +125,30 @@ KShortcutsDialog::KShortcutsDialog( KShortcutsEditor::ActionTypes types, KShortc
setButtonText(KDialog::User1, i18n("Print"));
setButtonIcon(KDialog::User1, KIcon("document-print"));
setModal(true);
d->m_keyChooser = new KShortcutsEditor( this, types, allowLetterShortcuts );
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)) );
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(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" );
resize( group.readEntry( "Dialog Size", sizeHint() ) );
KConfigGroup group(KGlobal::config(), "KShortcutsDialog Settings");
resize(group.readEntry( "Dialog Size", sizeHint()));
}
KShortcutsDialog::~KShortcutsDialog()
{
KConfigGroup group( KGlobal::config(), "KShortcutsDialog Settings" );
group.writeEntry( "Dialog Size", size(), KConfigGroup::Persistent|KConfigGroup::Global );
KConfigGroup group(KGlobal::config(), "KShortcutsDialog Settings");
group.writeEntry("Dialog Size", size(), KConfigGroup::Persistent|KConfigGroup::Global);
delete d;
}
@ -155,7 +159,6 @@ void KShortcutsDialog::addCollection(KActionCollection *collection, const QStrin
d->m_collections << collection;
}
QList<KActionCollection*> KShortcutsDialog::actionCollections() const
{
return d->m_collections;
@ -183,7 +186,7 @@ QSize KShortcutsDialog::sizeHint() const
}
int KShortcutsDialog::configure(KActionCollection *collection, KShortcutsEditor::LetterShortcuts allowLetterShortcuts,
QWidget *parent, bool saveSettings)
QWidget *parent, bool saveSettings)
{
kDebug(125) << "KShortcutsDialog::configureKeys( KActionCollection*, " << saveSettings << " )";
KShortcutsDialog dlg(KShortcutsEditor::AllActions, allowLetterShortcuts, parent);
@ -193,5 +196,3 @@ int KShortcutsDialog::configure(KActionCollection *collection, KShortcutsEditor:
#include "moc_kshortcutsdialog.cpp"
#include "moc_kshortcutsdialog_p.cpp"
//kate: space-indent on; indent-width 4; replace-tabs on;tab-width 4;

View file

@ -68,80 +68,77 @@
*/
class KDEUI_EXPORT KShortcutsDialog : public KDialog
{
Q_OBJECT
Q_OBJECT
public:
/**
* Constructs a KShortcutsDialog as a child of @p parent.
* Set @p allowLetterShortcuts to false if unmodified alphanumeric
* keys ('A', '1', etc.) are not permissible shortcuts.
*/
explicit KShortcutsDialog(KShortcutsEditor::ActionTypes types = KShortcutsEditor::AllActions,
KShortcutsEditor::LetterShortcuts allowLetterShortcuts = KShortcutsEditor::LetterShortcutsAllowed,
QWidget *parent = 0);
/**
* Constructs a KShortcutsDialog as a child of @p parent.
* Set @p allowLetterShortcuts to false if unmodified alphanumeric
* keys ('A', '1', etc.) are not permissible shortcuts.
*/
explicit KShortcutsDialog(KShortcutsEditor::ActionTypes types = KShortcutsEditor::AllActions,
KShortcutsEditor::LetterShortcuts allowLetterShortcuts = KShortcutsEditor::LetterShortcutsAllowed,
QWidget *parent = 0);
/**
* Destructor. Deletes all resources used by a KShortcutsDialog object.
*/
virtual ~KShortcutsDialog();
/**
* Destructor. Deletes all resources used by a KShortcutsDialog object.
*/
virtual ~KShortcutsDialog();
/**
* Add all actions of the collection to the ones displayed and configured
* by the dialog.
*
* @param title the title associated with the collection (if null, the
* KAboutData::progName() of the collection's componentData is used)
*/
void addCollection(KActionCollection *, const QString &title = QString());
/**
* Add all actions of the collection to the ones displayed and configured
* by the dialog.
*
* @param title the title associated with the collection (if null, the
* KAboutData::progName() of the collection's componentData is used)
*/
void addCollection(KActionCollection *, const QString &title = QString());
/**
* @return the list of action collections that are available for configuration in the dialog.
*/
QList<KActionCollection*> actionCollections() const;
/**
* @return the list of action collections that are available for configuration in the dialog.
*/
QList<KActionCollection*> actionCollections() const;
/**
* Run the dialog and call writeSettings() on the action collections
* that were added if @p bSaveSettings is true.
*/
bool configure(bool saveSettings = true);
/**
* Run the dialog and call writeSettings() on the action collections
* that were added if @p bSaveSettings is true.
*/
bool configure(bool saveSettings = true);
/** @see QWidget::sizeHint() */
virtual QSize sizeHint() const;
/** @see QWidget::sizeHint() */
virtual QSize sizeHint() const;
/**
* Pops up a modal dialog for configuring key settings. The new
* shortcut settings will become active if the user presses OK.
*
* @param collection the KActionCollection to configure
* @param allowLetterShortcuts set to KShortcutsEditor::LetterShortcutsDisallowed if unmodified alphanumeric
* keys ('A', '1', etc.) are not permissible shortcuts.
* @param parent the parent widget to attach to
* @param bSaveSettings if true, the settings will also be saved back
* by calling writeSettings() on the action collections that were added.
*
* @return Accept if the dialog was closed with OK, Reject otherwise.
*/
static int configure( KActionCollection *collection, KShortcutsEditor::LetterShortcuts allowLetterShortcuts =
KShortcutsEditor::LetterShortcutsAllowed, QWidget* parent = 0, bool bSaveSettings = true);
/**
* Pops up a modal dialog for configuring key settings. The new
* shortcut settings will become active if the user presses OK.
*
* @param collection the KActionCollection to configure
* @param allowLetterShortcuts set to KShortcutsEditor::LetterShortcutsDisallowed if unmodified alphanumeric
* keys ('A', '1', etc.) are not permissible shortcuts.
* @param parent the parent widget to attach to
* @param bSaveSettings if true, the settings will also be saved back
* by calling writeSettings() on the action collections that were added.
*
* @return Accept if the dialog was closed with OK, Reject otherwise.
*/
static int configure(KActionCollection *collection, KShortcutsEditor::LetterShortcuts allowLetterShortcuts =
KShortcutsEditor::LetterShortcutsAllowed, QWidget *parent = 0, bool bSaveSettings = true);
Q_SIGNALS:
/**
* emitted after ok is clicked and settings are saved
*/
void saved();
/**
* emitted after ok is clicked and settings are saved
*/
void saved();
private:
Q_PRIVATE_SLOT(d, void changeShortcutScheme(const QString &))
Q_PRIVATE_SLOT(d, void save())
Q_PRIVATE_SLOT(d, void undoChanges())
Q_PRIVATE_SLOT(d, void changeShortcutScheme(const QString &))
Q_PRIVATE_SLOT(d, void save())
Q_PRIVATE_SLOT(d, void undoChanges())
class KShortcutsDialogPrivate;
friend class KShortcutsDialogPrivate;
class KShortcutsDialogPrivate *const d;
class KShortcutsDialogPrivate;
friend class KShortcutsDialogPrivate;
class KShortcutsDialogPrivate *const d;
Q_DISABLE_COPY(KShortcutsDialog)
Q_DISABLE_COPY(KShortcutsDialog)
};
#endif // KSHORTCUTSDIALOG_H
//kate: space-indent off; indent-width 4; replace-tabs off;tab-width 4;

View file

@ -163,7 +163,7 @@ public:
bool allowLetterShortcuts);
//! @see KKeySequenceWidget::setCheckActionCollections()
void setCheckActionCollections( const QList<KActionCollection*> checkActionCollections);
void setCheckActionCollections(const QList<KActionCollection*> &checkActionCollections);
//@{
@ -179,7 +179,7 @@ public:
//@}
//! @see KKeySequenceWidget::setComponentName
void setComponentName(const QString componentName);
void setComponentName(const QString &componentName);
public Q_SLOTS:
@ -334,7 +334,7 @@ public:
KShortcutsEditorPrivate(KShortcutsEditor *q);
void initGUI( KShortcutsEditor::ActionTypes actionTypes, KShortcutsEditor::LetterShortcuts allowLetterShortcuts );
void appendToView( uint nList, const QString &title = QString() );
void appendToView(uint nList, const QString &title = QString());
//used in appendToView
QTreeWidgetItem *findOrMakeItem(QTreeWidgetItem *parent, const QString &name);
@ -369,7 +369,7 @@ public:
void printShortcuts() const;
// members
// members
QList<KActionCollection *> actionCollections;
KShortcutsEditor *q;
@ -380,9 +380,6 @@ public:
};
Q_DECLARE_METATYPE(KShortcutsEditorItem *)
Q_DECLARE_METATYPE(KShortcutsEditorItem*)
#endif /* KSHORTCUTSDIALOG_P_H */
//kate: space-indent on; indent-width 4; replace-tabs on;tab-width 4;

View file

@ -56,28 +56,25 @@
KShortcutsEditor::KShortcutsEditor(KActionCollection *collection, QWidget *parent, ActionTypes actionType,
LetterShortcuts allowLetterShortcuts )
: QWidget( parent )
, d(new KShortcutsEditorPrivate(this))
: QWidget(parent),
d(new KShortcutsEditorPrivate(this))
{
d->initGUI(actionType, allowLetterShortcuts);
addCollection(collection);
}
KShortcutsEditor::KShortcutsEditor(QWidget *parent, ActionTypes actionType, LetterShortcuts allowLetterShortcuts)
: QWidget(parent)
, d(new KShortcutsEditorPrivate(this))
: QWidget(parent),
d(new KShortcutsEditorPrivate(this))
{
d->initGUI(actionType, allowLetterShortcuts);
}
KShortcutsEditor::~KShortcutsEditor()
{
delete d;
}
bool KShortcutsEditor::isModified() const
{
// Iterate over all items
@ -167,46 +164,38 @@ void KShortcutsEditor::addCollection(KActionCollection *collection, const QStrin
QTimer::singleShot(0, this, SLOT(resizeColumns()));
}
void KShortcutsEditor::clearConfiguration()
{
d->clearConfiguration();
}
void KShortcutsEditor::importConfiguration( KConfigBase *config)
void KShortcutsEditor::importConfiguration(KConfigBase *config)
{
d->importConfiguration(config);
}
void KShortcutsEditor::exportConfiguration( KConfigBase *config) const
void KShortcutsEditor::exportConfiguration(KConfigBase *config) const
{
Q_ASSERT(config);
if (!config) return;
if (d->actionTypes & KShortcutsEditor::GlobalAction) {
QString groupName = "Global Shortcuts";
KConfigGroup group( config, groupName );
KConfigGroup group(config, groupName);
foreach (KActionCollection* collection, d->actionCollections) {
collection->exportGlobalShortcuts( &group, true );
collection->exportGlobalShortcuts(&group, true);
}
}
if (d->actionTypes & ~KShortcutsEditor::GlobalAction) {
QString groupName = "Shortcuts";
KConfigGroup group( config, groupName );
KConfigGroup group(config, groupName);
foreach (KActionCollection* collection, d->actionCollections) {
collection->writeSettings( &group, true );
collection->writeSettings(&group, true);
}
}
}
void KShortcutsEditor::writeConfiguration( KConfigGroup *config) const
void KShortcutsEditor::writeConfiguration(KConfigGroup *config) const
{
foreach (KActionCollection* collection, d->actionCollections)
collection->writeSettings(config);
@ -230,7 +219,6 @@ void KShortcutsEditor::commit()
}
}
void KShortcutsEditor::save()
{
writeConfiguration();
@ -241,7 +229,6 @@ void KShortcutsEditor::save()
commit();
}
// KDE5 : rename to undo()
void KShortcutsEditor::undoChanges()
{
@ -264,23 +251,23 @@ void KShortcutsEditor::allDefault()
d->allDefault();
}
void KShortcutsEditor::printShortcuts() const
{
d->printShortcuts();
}
//---------------------------------------------------------------------
// KShortcutsEditorPrivate
//---------------------------------------------------------------------
KShortcutsEditorPrivate::KShortcutsEditorPrivate( KShortcutsEditor *q )
: q(q),
delegate(0)
{}
KShortcutsEditorPrivate::KShortcutsEditorPrivate(KShortcutsEditor *q)
: q(q),
delegate(0)
{
}
void KShortcutsEditorPrivate::initGUI( KShortcutsEditor::ActionTypes types, KShortcutsEditor::LetterShortcuts allowLetterShortcuts )
void KShortcutsEditorPrivate::initGUI(KShortcutsEditor::ActionTypes types,
KShortcutsEditor::LetterShortcuts allowLetterShortcuts)
{
actionTypes = types;
@ -288,7 +275,7 @@ void KShortcutsEditorPrivate::initGUI( KShortcutsEditor::ActionTypes types, KSho
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
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)) {
@ -300,7 +287,8 @@ void KShortcutsEditorPrivate::initGUI( KShortcutsEditor::ActionTypes types, KSho
// really change the shortcuts.
delegate = new KShortcutsEditorDelegate(
ui.list,
allowLetterShortcuts == KShortcutsEditor::LetterShortcutsAllowed);
allowLetterShortcuts == KShortcutsEditor::LetterShortcutsAllowed
);
ui.list->setItemDelegate(delegate);
ui.list->setSelectionBehavior(QAbstractItemView::SelectItems);
@ -310,16 +298,19 @@ void KShortcutsEditorPrivate::initGUI( KShortcutsEditor::ActionTypes types, KSho
ui.list->setAlternatingRowColors(true);
//TODO listen to changes to global shortcuts
QObject::connect(delegate, SIGNAL(shortcutChanged(QVariant,QModelIndex)),
q, SLOT(capturedShortcut(QVariant,QModelIndex)));
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)));
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
@ -345,8 +336,9 @@ bool KShortcutsEditorPrivate::addAction(QAction *action, QTreeWidgetItem *hier[]
void KShortcutsEditorPrivate::allDefault()
{
for (QTreeWidgetItemIterator it(ui.list); (*it); ++it) {
if (!(*it)->parent() || (*it)->type() != ActionItem)
if (!(*it)->parent() || (*it)->type() != ActionItem) {
continue;
}
KShortcutsEditorItem *item = static_cast<KShortcutsEditorItem *>(*it);
KAction *act = item->m_action;
@ -379,8 +371,9 @@ QTreeWidgetItem *KShortcutsEditorPrivate::findOrMakeItem(QTreeWidgetItem *parent
{
for (int i = 0; i < parent->childCount(); i++) {
QTreeWidgetItem *child = parent->child(i);
if (child->text(0) == name)
if (child->text(0) == name) {
return child;
}
}
QTreeWidgetItem *ret = new QTreeWidgetItem(parent, NonActionItem);
ret->setText(0, name);
@ -394,14 +387,16 @@ QTreeWidgetItem *KShortcutsEditorPrivate::findOrMakeItem(QTreeWidgetItem *parent
void KShortcutsEditorPrivate::capturedShortcut(const QVariant &newShortcut, const QModelIndex &index)
{
//dispatch to the right handler
if (!index.isValid())
if (!index.isValid()) {
return;
}
int column = index.column();
KShortcutsEditorItem *item = itemFromIndex(ui.list, index);
Q_ASSERT(item);
if (column >= LocalPrimary && column <= GlobalAlternate)
if (column >= LocalPrimary && column <= GlobalAlternate) {
changeKeyShortcut(item, column, newShortcut.value<QKeySequence>());
}
}
@ -422,8 +417,9 @@ void KShortcutsEditorPrivate::changeKeyShortcut(KShortcutsEditorItem *item, uint
void KShortcutsEditorPrivate::clearConfiguration()
{
for (QTreeWidgetItemIterator it(ui.list); (*it); ++it) {
if (!(*it)->parent())
if (!(*it)->parent()) {
continue;
}
KShortcutsEditorItem *item = static_cast<KShortcutsEditorItem *>(*it);
@ -445,12 +441,11 @@ void KShortcutsEditorPrivate::importConfiguration(KConfigBase *config)
if ((actionTypes & KShortcutsEditor::GlobalAction) && globalShortcutsGroup.exists()) {
for (QTreeWidgetItemIterator it(ui.list); (*it); ++it) {
if (!(*it)->parent())
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());
@ -459,14 +454,12 @@ void KShortcutsEditorPrivate::importConfiguration(KConfigBase *config)
KConfigGroup localShortcutsGroup(config, QLatin1String("Shortcuts"));
if (actionTypes & ~KShortcutsEditor::GlobalAction) {
for (QTreeWidgetItemIterator it(ui.list); (*it); ++it) {
if (!(*it)->parent())
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());
@ -504,9 +497,13 @@ void KShortcutsEditorPrivate::printShortcuts() const
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);
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);
@ -551,8 +548,9 @@ void KShortcutsEditorPrivate::printShortcuts() const
currow++;
for (QTreeWidgetItemIterator it(item); *it; ++it) {
if ((*it)->type() != ActionItem)
if ((*it)->type() != ActionItem) {
continue;
}
KShortcutsEditorItem* editoritem = static_cast<KShortcutsEditorItem*>(*it);
table->insertRows(table->rows(),1);
@ -561,23 +559,23 @@ void KShortcutsEditorPrivate::printShortcuts() const
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();
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);
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);
}
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;

View file

@ -60,81 +60,83 @@ class KShortcutsEditorPrivate;
*/
class KDEUI_EXPORT KShortcutsEditor : public QWidget
{
Q_OBJECT
Q_OBJECT
public:
enum ActionType {
/// Actions which are triggered by any keypress in a widget which has the action added to it
WidgetAction = Qt::WidgetShortcut /*0*/,
/// Actions which are triggered by any keypress in a window which has the action added to it or its child widget(s)
WindowAction = Qt::WindowShortcut /*1*/,
/// Actions which are triggered by any keypress in the application
ApplicationAction = Qt::ApplicationShortcut /*2*/,
/// Actions which are triggered by any keypress in the windowing system
GlobalAction = 4,
/// All actions
AllActions = 0xffffffff
};
Q_DECLARE_FLAGS(ActionTypes, ActionType)
enum ActionType {
/// Actions which are triggered by any keypress in a widget which has the action added to it
WidgetAction = Qt::WidgetShortcut /*0*/,
/// Actions which are triggered by any keypress in a window which has the action added to it or its child widget(s)
WindowAction = Qt::WindowShortcut /*1*/,
/// Actions which are triggered by any keypress in the application
ApplicationAction = Qt::ApplicationShortcut /*2*/,
/// Actions which are triggered by any keypress in the windowing system
GlobalAction = 4,
/// All actions
AllActions = 0xffffffff
};
Q_DECLARE_FLAGS(ActionTypes, ActionType)
enum LetterShortcuts {
/// Shortcuts without a modifier are not allowed,
/// so 'A' would not be valid, whereas 'Ctrl+A' would be.
/// This only applies to printable characters, however.
/// 'F1', 'Insert' etc. could still be used.
LetterShortcutsDisallowed = 0,
/// Letter shortcuts are allowed
LetterShortcutsAllowed
};
enum LetterShortcuts {
/// Shortcuts without a modifier are not allowed,
/// so 'A' would not be valid, whereas 'Ctrl+A' would be.
/// This only applies to printable characters, however.
/// 'F1', 'Insert' etc. could still be used.
LetterShortcutsDisallowed = 0,
/// Letter shortcuts are allowed
LetterShortcutsAllowed
};
/**
* Constructor.
*
* @param collection the KActionCollection to configure
* @param parent parent widget
* @param actionTypes types of actions to display in this widget.
* @param allowLetterShortcuts set to LetterShortcutsDisallowed if unmodified alphanumeric
* keys ('A', '1', etc.) are not permissible shortcuts.
*/
KShortcutsEditor(KActionCollection *collection, QWidget *parent, ActionTypes actionTypes = AllActions, LetterShortcuts allowLetterShortcuts = LetterShortcutsAllowed);
/**
* Constructor.
*
* @param collection the KActionCollection to configure
* @param parent parent widget
* @param actionTypes types of actions to display in this widget.
* @param allowLetterShortcuts set to LetterShortcutsDisallowed if unmodified alphanumeric
* keys ('A', '1', etc.) are not permissible shortcuts.
*/
KShortcutsEditor(KActionCollection *collection, QWidget *parent,
ActionTypes actionTypes = AllActions,
LetterShortcuts allowLetterShortcuts = LetterShortcutsAllowed);
/**
* \overload
*
* Creates a key chooser without a starting action collection.
*
* @param parent parent widget
* @param actionTypes types of actions to display in this widget.
* @param allowLetterShortcuts set to LetterShortcutsDisallowed if unmodified alphanumeric
* keys ('A', '1', etc.) are not permissible shortcuts.
*/
explicit KShortcutsEditor( QWidget* parent, ActionTypes actionTypes = AllActions, LetterShortcuts allowLetterShortcuts = LetterShortcutsAllowed );
/**
* \overload
*
* Creates a key chooser without a starting action collection.
*
* @param parent parent widget
* @param actionTypes types of actions to display in this widget.
* @param allowLetterShortcuts set to LetterShortcutsDisallowed if unmodified alphanumeric
* keys ('A', '1', etc.) are not permissible shortcuts.
*/
explicit KShortcutsEditor(QWidget* parent, ActionTypes actionTypes = AllActions,
LetterShortcuts allowLetterShortcuts = LetterShortcutsAllowed);
/// Destructor
virtual ~KShortcutsEditor();
/// Destructor
virtual ~KShortcutsEditor();
/**
* Are the unsaved changes?
*/
bool isModified() const;
/**
* Removes all action collections from the editor
*/
void clearCollections();
/**
* Removes all action collections from the editor
*/
void clearCollections();
/**
* Insert an action collection, i.e. add all its actions to the ones
* already associated with the KShortcutsEditor object.
* @param title subtree title of this collection of shortcut.
*/
void addCollection(KActionCollection *, const QString &title = QString());
/**
* Insert an action collection, i.e. add all its actions to the ones
* already associated with the KShortcutsEditor object.
* @param title subtree title of this collection of shortcut.
*/
void addCollection(KActionCollection *, const QString &title = QString());
/**
/**
* Undo all change made since the last commit().
*/
void undoChanges();
*/
void undoChanges();
/**
* Save the changes.
@ -155,7 +157,6 @@ public:
*/
void commit();
/**
* Removes all configured shortcuts.
*/
@ -175,7 +176,7 @@ public:
* applications config object
*
*/
void writeConfiguration( KConfigGroup* config = 0 ) const;
void writeConfiguration(KConfigGroup* config = 0 ) const;
/**
* Export the current setting to configuration @p config.
@ -185,7 +186,7 @@ public:
*
* @param config Config object
*/
void exportConfiguration( KConfigBase *config) const;
void exportConfiguration(KConfigBase *config) const;
/**
* Import the settings from configuration @p config.
@ -195,39 +196,39 @@ public:
*
* @param config Config object
*/
void importConfiguration( KConfigBase *config);
void importConfiguration(KConfigBase *config);
Q_SIGNALS:
/**
* Emitted when an action's shortcut has been changed.
**/
void keyChange();
/**
* Emitted when an action's shortcut has been changed.
**/
void keyChange();
public Q_SLOTS:
/**
* Resize columns to width required
*/
void resizeColumns();
/**
* Resize columns to width required
*/
void resizeColumns();
/**
* Set all shortcuts to their default values (bindings).
**/
void allDefault();
/**
* Set all shortcuts to their default values (bindings).
**/
void allDefault();
/**
* Opens a printing dialog to print all the shortcuts
*/
void printShortcuts() const;
/**
* Opens a printing dialog to print all the shortcuts
*/
void printShortcuts() const;
private:
Q_PRIVATE_SLOT(d, void capturedShortcut(QVariant, const QModelIndex &))
Q_PRIVATE_SLOT(d, void capturedShortcut(QVariant, const QModelIndex &))
private:
friend class KShortcutsDialog;
friend class KShortcutsEditorPrivate;
KShortcutsEditorPrivate *const d;
Q_DISABLE_COPY(KShortcutsEditor)
friend class KShortcutsDialog;
friend class KShortcutsEditorPrivate;
KShortcutsEditorPrivate *const d;
Q_DISABLE_COPY(KShortcutsEditor)
};
Q_DECLARE_OPERATORS_FOR_FLAGS(KShortcutsEditor::ActionTypes)

View file

@ -35,11 +35,11 @@
#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)
: 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();
@ -234,20 +234,22 @@ bool KShortcutsEditorItem::isModified(uint column) const
return false;
case LocalPrimary:
case LocalAlternate:
if (!m_oldLocalShortcut)
if (!m_oldLocalShortcut) {
return false;
if (column == LocalPrimary)
}
if (column == LocalPrimary) {
return m_oldLocalShortcut->primary() != m_action->shortcut().primary();
else
return m_oldLocalShortcut->alternate() != m_action->shortcut().alternate();
}
return m_oldLocalShortcut->alternate() != m_action->shortcut().alternate();
case GlobalPrimary:
case GlobalAlternate:
if (!m_oldGlobalShortcut)
if (!m_oldGlobalShortcut) {
return false;
if (column == GlobalPrimary)
}
if (column == GlobalPrimary) {
return m_oldGlobalShortcut->primary() != m_action->globalShortcut().primary();
else
return m_oldGlobalShortcut->alternate() != m_action->globalShortcut().alternate();
}
return m_oldGlobalShortcut->alternate() != m_action->globalShortcut().alternate();
default:
return false;
}
@ -268,8 +270,7 @@ void KShortcutsEditorItem::undo()
}
if (m_oldGlobalShortcut) {
m_action->setGlobalShortcut(*m_oldGlobalShortcut, KAction::ActiveShortcut,
KAction::NoAutoloading);
m_action->setGlobalShortcut(*m_oldGlobalShortcut, KAction::ActiveShortcut, KAction::NoAutoloading);
}
updateModified();

View file

@ -53,14 +53,14 @@ const QDBusArgument &operator>> (const QDBusArgument &argument, KGlobalShortcutI
>> shortcut.d->contextFriendlyName;
argument.beginArray();
while (!argument.atEnd()) {
int key;
int key = 0;
argument >> key;
shortcut.d->keys.append(QKeySequence(key));
}
argument.endArray();
argument.beginArray();
while (!argument.atEnd()) {
int key;
int key = 0;
argument >> key;
shortcut.d->defaultKeys.append(QKeySequence(key));
}

View file

@ -26,11 +26,11 @@ class KShortcutWidgetPrivate
public:
KShortcutWidgetPrivate(KShortcutWidget *q) : q(q) {}
//private slots
// private slots
void priKeySequenceChanged(const QKeySequence &);
void altKeySequenceChanged(const QKeySequence &);
//members
// members
KShortcutWidget *const q;
Ui::KShortcutWidget ui;
KShortcut cut;
@ -39,24 +39,27 @@ public:
KShortcutWidget::KShortcutWidget(QWidget *parent)
: QWidget(parent),
d(new KShortcutWidgetPrivate(this))
: 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)));
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;
delete d;
}
void KShortcutWidget::setModifierlessAllowed(bool allow)
{
d->ui.priEditor->setModifierlessAllowed(allow);
@ -69,14 +72,12 @@ 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;
@ -85,26 +86,23 @@ KShortcut KShortcutWidget::shortcut() const
return ret;
}
void KShortcutWidget::setCheckActionCollections(const QList<KActionCollection *>& actionCollections)
void KShortcutWidget::setCheckActionCollections(const QList<KActionCollection *> &actionCollections)
{
d->ui.priEditor->setCheckActionCollections(actionCollections);
d->ui.altEditor->setCheckActionCollections(actionCollections);
}
//slot
void KShortcutWidget::applyStealShortcut()
{
d->ui.priEditor->applyStealShortcut();
d->ui.altEditor->applyStealShortcut();
}
//slot
void KShortcutWidget::setShortcut(const KShortcut &newSc)
{
if (newSc == d->cut)
if (newSc == d->cut) {
return;
}
d->holdChangedSignal = true;
d->ui.priEditor->setKeySequence(newSc.primary());
@ -114,29 +112,26 @@ void KShortcutWidget::setShortcut(const KShortcut &newSc)
emit shortcutChanged(d->cut);
}
//slot
void KShortcutWidget::clearShortcut()
{
setShortcut(KShortcut());
}
//private slot
void KShortcutWidgetPrivate::priKeySequenceChanged(const QKeySequence &seq)
{
cut.setPrimary(seq);
if (!holdChangedSignal)
if (!holdChangedSignal) {
emit q->shortcutChanged(cut);
}
}
//private slot
void KShortcutWidgetPrivate::altKeySequenceChanged(const QKeySequence &seq)
{
cut.setAlternate(seq);
if (!holdChangedSignal)
if (!holdChangedSignal) {
emit q->shortcutChanged(cut);
}
}
#include "moc_kshortcutwidget.cpp"