diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 (patch) | |
tree | 67208f7c145782a7e90b123b982ca78d88cc2c87 /kmail/snippetdlg.cpp | |
download | tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.tar.gz tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kmail/snippetdlg.cpp')
-rw-r--r-- | kmail/snippetdlg.cpp | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/kmail/snippetdlg.cpp b/kmail/snippetdlg.cpp new file mode 100644 index 000000000..76b4fe178 --- /dev/null +++ b/kmail/snippetdlg.cpp @@ -0,0 +1,108 @@ +/*************************************************************************** + * snippet feature from kdevelop/plugins/snippet/ * + * * + * Copyright (C) 2007 by Robert Gruber * + * [email protected] * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "snippetdlg.h" + +#include <kdialog.h> +#include <klocale.h> + +#include <qlabel.h> +#include <qlayout.h> +#include <kpushbutton.h> +#include <ktextedit.h> +#include "kkeybutton.h" +#include "kactioncollection.h" +#include "kmessagebox.h" + +/* + * Constructs a SnippetDlg as a child of 'parent', with the + * name 'name' and widget flags set to 'f'. + * + * The dialog will by default be modeless, unless you set 'modal' to + * TRUE to construct a modal dialog. + */ +SnippetDlg::SnippetDlg( KActionCollection* ac, QWidget* parent, const char* name, bool modal, WFlags fl ) + : SnippetDlgBase( parent, name, modal, fl ), actionCollection( ac ) +{ + if ( !name ) + setName( "SnippetDlg" ); + + textLabel3 = new QLabel( this, "textLabel3" ); + keyButton = new KKeyButton( this ); + connect( keyButton, SIGNAL( capturedShortcut( const KShortcut& ) ), + this, SLOT( slotCapturedShortcut( const KShortcut& ) ) ); + + layout3->addWidget( textLabel3, 7, 0 ); + layout3->addWidget( keyButton, 7, 1 ); + + // tab order + setTabOrder( snippetText, keyButton ); + setTabOrder( keyButton, btnAdd ); + setTabOrder( btnAdd, btnCancel ); + + textLabel3->setBuddy( keyButton ); + languageChange(); +} + +/* + * Destroys the object and frees any allocated resources + */ +SnippetDlg::~SnippetDlg() +{ + // no need to delete child widgets, Qt does it all for us +} + +/* + * Sets the strings of the subwidgets using the current + * language. + */ +void SnippetDlg::languageChange() +{ + textLabel3->setText( tr2i18n( "Sh&ortcut:" ) ); +} + +static bool shortcutIsValid( const KActionCollection* actionCollection, const KShortcut &sc ) +{ + KActionPtrList actions = actionCollection->actions(); + KActionPtrList::Iterator it( actions.begin() ); + for ( ; it != actions.end(); it++ ) { + if ( (*it)->shortcut() == sc ) return false; + } + return true; +} + +void SnippetDlg::slotCapturedShortcut( const KShortcut& sc ) +{ + + if ( sc == keyButton->shortcut() ) return; + if ( sc.toString().isNull() ) { + // null is fine, that's reset, but sc.Ń–sNull() will be false :/ + keyButton->setShortcut( KShortcut::null(), false ); + } else { + if( !shortcutIsValid( actionCollection, sc ) ) { + QString msg( i18n( "The selected shortcut is already used, " + "please select a different one." ) ); + KMessageBox::sorry( this, msg ); + } else { + keyButton->setShortcut( sc, false ); + } + } +} + +void SnippetDlg::setShowShortcut( bool show ) +{ + textLabel3->setShown( show ); + keyButton->setShown( show ); +} + +#include "snippetdlg.moc" |