kmail
snippetdlg.cppGo to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "snippetdlg.h"
00015
00016 #include <kdialog.h>
00017 #include <klocale.h>
00018
00019 #include <qlabel.h>
00020 #include <qlayout.h>
00021 #include <kpushbutton.h>
00022 #include <ktextedit.h>
00023 #include "kkeybutton.h"
00024 #include "kactioncollection.h"
00025 #include "kmessagebox.h"
00026
00027
00028
00029
00030
00031
00032
00033
00034 SnippetDlg::SnippetDlg( KActionCollection* ac, QWidget* parent, const char* name, bool modal, WFlags fl )
00035 : SnippetDlgBase( parent, name, modal, fl ), actionCollection( ac )
00036 {
00037 if ( !name )
00038 setName( "SnippetDlg" );
00039
00040 textLabel3 = new QLabel( this, "textLabel3" );
00041 keyButton = new KKeyButton( this );
00042 connect( keyButton, SIGNAL( capturedShortcut( const KShortcut& ) ),
00043 this, SLOT( slotCapturedShortcut( const KShortcut& ) ) );
00044
00045 layout3->addWidget( textLabel3, 7, 0 );
00046 layout3->addWidget( keyButton, 7, 1 );
00047
00048
00049 setTabOrder( snippetText, keyButton );
00050 setTabOrder( keyButton, btnAdd );
00051 setTabOrder( btnAdd, btnCancel );
00052
00053 textLabel3->setBuddy( keyButton );
00054 languageChange();
00055 }
00056
00057
00058
00059
00060 SnippetDlg::~SnippetDlg()
00061 {
00062
00063 }
00064
00065
00066
00067
00068
00069 void SnippetDlg::languageChange()
00070 {
00071 textLabel3->setText( tr2i18n( "Sh&ortcut:" ) );
00072 }
00073
00074 static bool shortcutIsValid( const KActionCollection* actionCollection, const KShortcut &sc )
00075 {
00076 KActionPtrList actions = actionCollection->actions();
00077 KActionPtrList::Iterator it( actions.begin() );
00078 for ( ; it != actions.end(); it++ ) {
00079 if ( (*it)->shortcut() == sc ) return false;
00080 }
00081 return true;
00082 }
00083
00084 void SnippetDlg::slotCapturedShortcut( const KShortcut& sc )
00085 {
00086
00087 if ( sc == keyButton->shortcut() ) return;
00088 if ( sc.toString().isNull() ) {
00089
00090 keyButton->setShortcut( KShortcut::null(), false );
00091 } else {
00092 if( !shortcutIsValid( actionCollection, sc ) ) {
00093 QString msg( i18n( "The selected shortcut is already used, "
00094 "please select a different one." ) );
00095 KMessageBox::sorry( this, msg );
00096 } else {
00097 keyButton->setShortcut( sc, false );
00098 }
00099 }
00100 }
00101
00102 void SnippetDlg::setShowShortcut( bool show )
00103 {
00104 textLabel3->setShown( show );
00105 keyButton->setShown( show );
00106 }
00107
00108 #include "snippetdlg.moc"
|