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.
krename/krename/helpdialog.cpp

152 lines
4.9 KiB

/***************************************************************************
helpdialog.cpp - description
-------------------
begin : Fr Nov 15 13:44:19 CEST 2001
copyright : (C) 2002 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 "helpdialog.h"
#include "krenameimpl.h"
// TQt includes
#include <tqcombobox.h>
#include <tqlayout.h>
#include <tqlineedit.h>
// KDE includes
#include <klocale.h>
#include <klistview.h>
#include <kpushbutton.h>
#include <kstdguiitem.h>
void HelpDialogData::remove( const TQString & headline )
{
if( m_map.contains( headline ) ) {
m_map.remove( headline );
m_icons.remove( headline );
emit updateHeadline();
emit updateItems();
}
}
void HelpDialogData::add( const TQString & headline, TQStringList* commands, const TQPixmap & icon, bool first )
{
m_map.insert( headline, *commands );
m_icons.insert( headline, icon );
if( first )
m_first = headline;
emit updateHeadline();
emit updateItems();
}
TQStringList HelpDialogData::tokens() const
{
TQStringList list;
TQStringList keys = m_map.keys();
for( unsigned int i = 0; i < keys.count(); i++ )
for( unsigned int z = 0; z < m_map[keys[i]].count(); z++ )
list.append( m_map[keys[i]][z].section( ";;", 0, 0 ) );
return list;
}
HelpDialog::HelpDialog( HelpDialogData* data, TQWidget* parent,
const char* name, bool modal, WFlags fl )
: TQDialog( parent, name, modal, fl )
{
text = NULL;
resize( 500, 400 );
setCaption( i18n( "Help" ) );
HelpDialogLayout = new TQVBoxLayout( this, 11, 6, "HelpDialogLayout");
comboHeadline = new TQComboBox( FALSE, this, "comboHeadline" );
HelpDialogLayout->addWidget( comboHeadline );
list = new KListView( this, "list" );
list->addColumn( i18n( "Token" ) );
list->addColumn( i18n( "Description" ) );
HelpDialogLayout->addWidget( list );
Layout1 = new TQHBoxLayout( 0, 0, 6, "Layout1");
TQSpacerItem* spacer = new TQSpacerItem( 91, 0, TQSizePolicy::Expanding, TQSizePolicy::Minimum );
Layout1->addItem( spacer );
buttonAdd = new KPushButton( this, "buttonAdd" );
buttonAdd->setText( i18n( "&Add" ) );
Layout1->addWidget( buttonAdd );
buttonClose = createButton( KStdGuiItem::close(), this );
Layout1->addWidget( buttonClose );
HelpDialogLayout->addLayout( Layout1 );
// signals and slots connections
connect( buttonClose, TQT_SIGNAL( clicked() ), this, TQT_SLOT( accept() ) );
connect( buttonAdd, TQT_SIGNAL( clicked() ), this, TQT_SLOT( execute() ) );
connect( list, TQT_SIGNAL( executed(TQListViewItem*) ), this, TQT_SLOT( execute() ) );
connect( comboHeadline, TQT_SIGNAL( activated(int) ), this, TQT_SLOT(updateItems() ) );
m_data = data;
connect( m_data, TQT_SIGNAL( updateItems() ), this, TQT_SLOT( updateItems() ) );
connect( m_data, TQT_SIGNAL( updateHeadline() ), this, TQT_SLOT( updateHeadline() ) );
}
HelpDialog::~HelpDialog()
{
disconnect( m_data, TQT_SIGNAL( updateItems() ), this, TQT_SLOT( updateItems() ) );
disconnect( m_data, TQT_SIGNAL( updateHeadline() ), this, TQT_SLOT( updateHeadline() ) );
}
void HelpDialog::execute()
{
if(!list->currentItem())
return;
TQString t = text->text();
t.insert( text->cursorPosition(), list->currentItem()->text( 0 ) );
text->setText( t );
if( isModal() )
accept();
}
void HelpDialog::updateItems()
{
list->clear();
TQStringList items = m_data->map()[comboHeadline->currentText()];
for( unsigned int i = 0; i < items.count(); i++ ) {
TQString tmp = items[i];
new KListViewItem( list, tmp.section( ";;", 0, 0 ), tmp.section( ";;", 1, 1 ) );
}
}
void HelpDialog::updateHeadline()
{
comboHeadline->clear();
TQMap<TQString,TQStringList> m = m_data->map();
TQMap<TQString,TQPixmap> ic = m_data->icons();
comboHeadline->insertItem( ic[m_data->first()], m_data->first() );
TQMap<TQString, TQStringList>::Iterator it;
for ( it = m.begin(); it != m.end(); ++it )
if( it.key() != m_data->first() )
comboHeadline->insertItem( ic[it.key()], it.key() );
}