You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kbarcode/kbarcode/kactionmap.cpp

189 lines
5.7 KiB

/***************************************************************************
kactionmap.cpp - description
-------------------
begin : Fri Mai 19 2006
copyright : (C) 2006 by Dominik Seichter
email : domseichter@web.de
***************************************************************************/
/***************************************************************************
* *
* 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 "kactionmap.h"
#include <tqimage.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqmenubar.h>
#include <tqmenudata.h>
#include <tqpixmap.h>
#include <tqpopupmenu.h>
#include <tqregexp.h>
#include <tqvbox.h>
#include <kaction.h>
#include <kapplication.h>
#include <klistview.h>
#if KDE_VERSION >= 0x030500
#include <klistviewsearchline.h>
#endif
#include <klocale.h>
class KListViewActionItem : public KListViewItem {
public:
KListViewActionItem( KListView* parent, KAction* action )
: KListViewItem( parent ), m_action( action )
{
TQPixmap pix;
TQSize size = TQIconSet::iconSize( TQIconSet::Large );
TQIconSet iconset = m_action->iconSet( KIcon::Panel, KIcon::SizeLarge );
TQRegExp regtag( "<[^>]*>" );
pix = iconset.pixmap( TQIconSet::Large, TQIconSet::Normal ); // m_action->isEnabled() ? TQIconSet::Normal : TQIconSet::Disabled );
if( pix.isNull() )
{
pix.resize( size );
pix.fill( backgroundColor() );
}
else
{
if( pix.size() != size )
{
pix = pix.convertToImage().smoothScale( size );
}
}
setText( 0, m_action->plainText() );
setText( 1, m_action->shortcutText() );
// replace HTML tags in What's this help
setText( 2, m_action->whatsThis().replace( regtag, "" ) );
setPixmap( 0, pix );
}
void paintCell( TQPainter *p, const TQColorGroup &cg,
int column, int width, int tqalignment )
{
TQColorGroup _cg( cg );
TQColor c = _cg.text();
if( m_action && !m_action->isEnabled() )
_cg.setColor( TQColorGroup::Text, TQt::gray );
KListViewItem::paintCell( p, _cg, column, width, tqalignment );
_cg.setColor( TQColorGroup::Text, c );
}
inline KAction* action() const
{
return m_action;
}
private:
KAction* m_action;
};
KActionMapDlg::KActionMapDlg( KActionCollection* actions, TQWidget* parent, const char* name )
: KDialogBase( parent, name, false, i18n("Action Map"), KDialogBase::Close, KDialogBase::Close )
{
TQVBox *page = makeVBoxMainWidget();
new TQLabel( i18n("Find and execute actions."), page );
m_map = new KActionMap( actions, page );
show();
}
void KActionMapDlg::updateEnabledState()
{
m_map->updateEnabledState();
}
KActionMap::KActionMap( KActionCollection* actions, TQWidget* parent, const char* name )
: TQWidget( parent, name ), m_actions( actions ), m_showMenuTree( true ), m_grayOutItems( false )
{
TQVBoxLayout* tqlayout = new TQVBoxLayout( this );
m_listView = new KListView( this );
#if KDE_VERSION >= 0x030500
m_searchLine = new KListViewSearchLineWidget( m_listView, this );
#endif
m_listView->addColumn( i18n("Action") );
m_listView->addColumn( i18n("Shortcut") );
m_listView->addColumn( i18n("Description") );
m_listView->setColumnWidthMode( 0, TQListView::Maximum );
m_listView->setColumnWidthMode( 1, TQListView::Maximum );
m_listView->setColumnWidthMode( 2, TQListView::Manual );
m_listView->setSorting( 0 );
m_listView->setAllColumnsShowFocus( true );
#if KDE_VERSION >= 0x030500
tqlayout->addWidget( m_searchLine );
#endif
tqlayout->addWidget( m_listView );
connect( m_listView, TQT_SIGNAL( executed( TQListViewItem* ) ), this, TQT_SLOT( slotExecuteAction( TQListViewItem* ) ) );
connect( actions, TQT_SIGNAL( inserted( KAction* ) ), this, TQT_SLOT( slotActionCollectionChanged() ) );
connect( actions, TQT_SIGNAL( removed( KAction* ) ), this, TQT_SLOT( slotActionCollectionChanged() ) );
slotActionCollectionChanged();
}
KActionMap::~KActionMap()
{
}
void KActionMap::slotActionCollectionChanged()
{
KActionPtrList actions;
KActionPtrList::const_iterator it;
m_listView->clear();
if( !m_actions )
return;
actions = m_actions->actions();
it = actions.begin();
while( it != actions.end() )
{
/*
if( m_showMenuTree )
{
}
*/
new KListViewActionItem( m_listView, (*it) );
connect( *it, TQT_SIGNAL( enabled(bool) ), this, TQT_SLOT( updateEnabledState() ) );
++it;
}
}
void KActionMap::slotExecuteAction( TQListViewItem* item )
{
KListViewActionItem* action = dynamic_cast<KListViewActionItem*>(item);
if( !action )
return;
if( !action->action()->isEnabled() )
return;
action->action()->activate();
}
void KActionMap::updateEnabledState()
{
m_listView->repaintContents();
}
#include "kactionmap.moc"