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