/*************************************************************************** tdeactionmap.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 "tdeactionmap.h" #include #include #include #include #include #include #include #include #include #include #include #include #if TDE_VERSION >= 0x030500 #include #endif #include class TDEListViewActionItem : public TDEListViewItem { public: TDEListViewActionItem( TDEListView* parent, TDEAction* action ) : TDEListViewItem( parent ), m_action( action ) { TQPixmap pix; TQSize size = TQIconSet::iconSize( TQIconSet::Large ); TQIconSet iconset = m_action->iconSet( TDEIcon::Panel, TDEIcon::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 alignment ) { TQColorGroup _cg( cg ); TQColor c = _cg.text(); if( m_action && !m_action->isEnabled() ) _cg.setColor( TQColorGroup::Text, TQt::gray ); TDEListViewItem::paintCell( p, _cg, column, width, alignment ); _cg.setColor( TQColorGroup::Text, c ); } inline TDEAction* action() const { return m_action; } private: TDEAction* m_action; }; TDEActionMapDlg::TDEActionMapDlg( TDEActionCollection* 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 TDEActionMap( actions, page ); show(); } void TDEActionMapDlg::updateEnabledState() { m_map->updateEnabledState(); } TDEActionMap::TDEActionMap( TDEActionCollection* actions, TQWidget* parent, const char* name ) : TQWidget( parent, name ), m_actions( actions ), m_showMenuTree( true ), m_grayOutItems( false ) { TQVBoxLayout* layout = new TQVBoxLayout( this ); m_listView = new TDEListView( this ); #if TDE_VERSION >= 0x030500 m_searchLine = new TDEListViewSearchLineWidget( 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 TDE_VERSION >= 0x030500 layout->addWidget( m_searchLine ); #endif layout->addWidget( m_listView ); connect( m_listView, TQT_SIGNAL( executed( TQListViewItem* ) ), this, TQT_SLOT( slotExecuteAction( TQListViewItem* ) ) ); connect( actions, TQT_SIGNAL( inserted( TDEAction* ) ), this, TQT_SLOT( slotActionCollectionChanged() ) ); connect( actions, TQT_SIGNAL( removed( TDEAction* ) ), this, TQT_SLOT( slotActionCollectionChanged() ) ); slotActionCollectionChanged(); } TDEActionMap::~TDEActionMap() { } void TDEActionMap::slotActionCollectionChanged() { TDEActionPtrList actions; TDEActionPtrList::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 TDEListViewActionItem( m_listView, (*it) ); connect( *it, TQT_SIGNAL( enabled(bool) ), this, TQT_SLOT( updateEnabledState() ) ); ++it; } } void TDEActionMap::slotExecuteAction( TQListViewItem* item ) { TDEListViewActionItem* action = dynamic_cast(item); if( !action ) return; if( !action->action()->isEnabled() ) return; action->action()->activate(); } void TDEActionMap::updateEnabledState() { m_listView->repaintContents(); } #include "tdeactionmap.moc"