Blokkal
an Extendable KDE Blogging Client
SourceForge.net Logo

stdaction.cpp

00001 /***************************************************************************
00002  *   Copyright (C) 2006 by Martin Mueller                                  *
00003  *   orvio@orvio.de                                                        *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 #include "stdaction.h"
00021 
00022 #include "globalsettings.h"
00023 
00024 #include <kaction.h>
00025 #include <kactioncollection.h>
00026 #include <klocale.h>
00027 #include <ksettings/dialog.h>
00028 
00029 KSettings::Dialog * Blokkal::Ui::StdAction::m_preferencesDialog = 0;
00030 
00031 Blokkal::Ui::StdAction::StdAction( void )
00032 {}
00033 
00034 Blokkal::Ui::StdAction::~StdAction( void )
00035 {}
00036 
00037 KAction * Blokkal::Ui::StdAction::create( Blokkal::Ui::StdAction::StdActions id, const char * name, const QObject * receiver, const char * slot, KActionCollection * parent )
00038 {
00039         KAction * action = new KAction( parent );
00040 
00041         switch( id ) {
00042         case Bold:
00043                 action->setText( i18n( "&Bold" ) );
00044                 action->setShortcut( i18n( "Ctrl+B" ) );
00045                 //action->setIcon( KIcon( "blokkal_textbold" ) );
00046                 action->setIcon( KIcon( "format-text-bold" ) );
00047                 break;
00048         case Italic:
00049                 action->setText( i18n( "&Italic" ) );
00050                 action->setShortcut( i18n( "Ctrl+I" ) );
00051                 //action->setIcon( KIcon( "blokkal_textitalic" ) );
00052                 action->setIcon( KIcon( "format-text-italic" ) );
00053                 break;
00054         case Underline:
00055                 action->setText( i18n( "&Underline" ) );
00056                 action->setShortcut( i18n( "Ctrl+U" ) );
00057                 //action->setIcon( KIcon( "blokkal_textunderline" ) );
00058                 action->setIcon( KIcon( "format-text-underline" ) );
00059                 break;
00060         case Strike:
00061                 action->setText( i18n( "Strike &out" ) );
00062                 action->setShortcut( i18n( "Ctrl+O" ) );
00063                 //action->setIcon( KIcon( "blokkal_textstrike" ) );
00064                 action->setIcon( KIcon( "format-text-strikethrough" ) );
00065                 break;
00066         case Link:
00067                 action->setText( i18n( "Insert &Link" ) );
00068                 action->setShortcut( i18n( "Ctrl+L" ) );
00069                 action->setIcon( KIcon( "blokkal_insertlink" ) );
00070                 break;
00071         case Image:
00072                 action->setText( i18n( "Insert Ima&ge" ) );
00073                 action->setShortcut( i18n( "Ctrl+G" ) );
00074                 //action->setIcon( KIcon( "blokkal_insertimage" ) );
00075                 action->setIcon( KIcon( "insert-image" ) );
00076                 break;
00077         case Post:
00078                 action->setText( i18n( "&Post Entry" ) );
00079                 action->setShortcut( i18n( "Ctrl+P" ) );
00080                 action->setIcon( KIcon( "blokkal" ) );
00081                 break;
00082         }
00083 
00084         if( receiver && slot ) {
00085                 QObject::connect( action, SIGNAL( triggered (Qt::MouseButtons, Qt::KeyboardModifiers ) ),
00086                                   receiver, slot );
00087         }
00088 
00089         if( parent && name ) {
00090                 parent->addAction( name, action );
00091         }
00092 
00093         return action;
00094 }
00095 
00096 KAction * Blokkal::Ui::StdAction::bold( const QObject * receiver, const char * slot, KActionCollection * parent, const char * name )
00097 {
00098         return create( Bold, name, receiver, slot, parent );
00099 }
00100 
00101 KAction * Blokkal::Ui::StdAction::italic( const QObject * receiver, const char * slot, KActionCollection * parent, const char * name )
00102 {
00103         return create( Italic, name, receiver, slot, parent );
00104 }
00105 
00106 KAction * Blokkal::Ui::StdAction::underline( const QObject * receiver, const char * slot, KActionCollection * parent, const char * name )
00107 {
00108         return create( Underline, name, receiver, slot, parent );
00109 }
00110 
00111 KAction * Blokkal::Ui::StdAction::strike( const QObject * receiver, const char * slot, KActionCollection * parent, const char * name )
00112 {
00113         return create( Strike, name, receiver, slot, parent );
00114 }
00115 
00116 KAction * Blokkal::Ui::StdAction::link( const QObject * receiver, const char * slot, KActionCollection * parent, const char * name )
00117 {
00118         return create( Link, name, receiver, slot, parent );
00119 }
00120 
00121 KAction * Blokkal::Ui::StdAction::image( const QObject * receiver, const char * slot, KActionCollection * parent, const char * name )
00122 {
00123         return create( Image, name, receiver, slot, parent );
00124 }
00125 
00126 KAction * Blokkal::Ui::StdAction::post( const QObject * receiver, const char * slot, KActionCollection * parent, const char * name )
00127 {
00128         return create( Post, name, receiver, slot, parent );
00129 }
00130 
00131 KAction * Blokkal::Ui::StdAction::preferences( KActionCollection * parent, const char * name )
00132 {
00133         if( !m_preferencesDialog ) {
00134                 m_preferencesDialog = new KSettings::Dialog( Blokkal::Ui::GlobalSettings::self()->mainWidget() );
00135         }
00136 
00137         KAction * action = KStandardAction::preferences( m_preferencesDialog,
00138                                                          SLOT( show( void ) ),
00139                                                          parent );
00140         action->setObjectName( name );
00141         return action;
00142 }