KRename – powerful batch renamer
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.

helpdialog.cpp 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /***************************************************************************
  2. helpdialog.cpp - description
  3. -------------------
  4. begin : Fr Nov 15 13:44:19 CEST 2001
  5. copyright : (C) 2002 by Dominik Seichter
  6. email : domseichter@web.de
  7. ***************************************************************************/
  8. /***************************************************************************
  9. * *
  10. * This program is free software; you can redistribute it and/or modify *
  11. * it under the terms of the GNU General Public License as published by *
  12. * the Free Software Foundation; either version 2 of the License, or *
  13. * (at your option) any later version. *
  14. * *
  15. ***************************************************************************/
  16. #include "helpdialog.h"
  17. #include "krenameimpl.h"
  18. // TQt includes
  19. #include <tqcombobox.h>
  20. #include <tqlayout.h>
  21. #include <tqlineedit.h>
  22. // KDE includes
  23. #include <tdelocale.h>
  24. #include <tdelistview.h>
  25. #include <kpushbutton.h>
  26. #include <kstdguiitem.h>
  27. void HelpDialogData::remove( const TQString & headline )
  28. {
  29. if( m_map.contains( headline ) ) {
  30. m_map.remove( headline );
  31. m_icons.remove( headline );
  32. emit updateHeadline();
  33. emit updateItems();
  34. }
  35. }
  36. void HelpDialogData::add( const TQString & headline, TQStringList* commands, const TQPixmap & icon, bool first )
  37. {
  38. m_map.insert( headline, *commands );
  39. m_icons.insert( headline, icon );
  40. if( first )
  41. m_first = headline;
  42. emit updateHeadline();
  43. emit updateItems();
  44. }
  45. TQStringList HelpDialogData::tokens() const
  46. {
  47. TQStringList list;
  48. TQStringList keys = m_map.keys();
  49. for( unsigned int i = 0; i < keys.count(); i++ )
  50. for( unsigned int z = 0; z < m_map[keys[i]].count(); z++ )
  51. list.append( m_map[keys[i]][z].section( ";;", 0, 0 ) );
  52. return list;
  53. }
  54. HelpDialog::HelpDialog( HelpDialogData* data, TQWidget* parent,
  55. const char* name, bool modal, WFlags fl )
  56. : TQDialog( parent, name, modal, fl )
  57. {
  58. text = NULL;
  59. resize( 500, 400 );
  60. setCaption( i18n( "Help" ) );
  61. HelpDialogLayout = new TQVBoxLayout( this, 11, 6, "HelpDialogLayout");
  62. comboHeadline = new TQComboBox( FALSE, this, "comboHeadline" );
  63. HelpDialogLayout->addWidget( comboHeadline );
  64. list = new TDEListView( this, "list" );
  65. list->addColumn( i18n( "Token" ) );
  66. list->addColumn( i18n( "Description" ) );
  67. HelpDialogLayout->addWidget( list );
  68. Layout1 = new TQHBoxLayout( 0, 0, 6, "Layout1");
  69. TQSpacerItem* spacer = new TQSpacerItem( 91, 0, TQSizePolicy::Expanding, TQSizePolicy::Minimum );
  70. Layout1->addItem( spacer );
  71. buttonAdd = new KPushButton( this, "buttonAdd" );
  72. buttonAdd->setText( i18n( "&Add" ) );
  73. Layout1->addWidget( buttonAdd );
  74. buttonClose = createButton( KStdGuiItem::close(), this );
  75. Layout1->addWidget( buttonClose );
  76. HelpDialogLayout->addLayout( Layout1 );
  77. // signals and slots connections
  78. connect( buttonClose, TQT_SIGNAL( clicked() ), this, TQT_SLOT( accept() ) );
  79. connect( buttonAdd, TQT_SIGNAL( clicked() ), this, TQT_SLOT( execute() ) );
  80. connect( list, TQT_SIGNAL( executed(TQListViewItem*) ), this, TQT_SLOT( execute() ) );
  81. connect( comboHeadline, TQT_SIGNAL( activated(int) ), this, TQT_SLOT(updateItems() ) );
  82. m_data = data;
  83. connect( m_data, TQT_SIGNAL( updateItems() ), this, TQT_SLOT( updateItems() ) );
  84. connect( m_data, TQT_SIGNAL( updateHeadline() ), this, TQT_SLOT( updateHeadline() ) );
  85. }
  86. HelpDialog::~HelpDialog()
  87. {
  88. disconnect( m_data, TQT_SIGNAL( updateItems() ), this, TQT_SLOT( updateItems() ) );
  89. disconnect( m_data, TQT_SIGNAL( updateHeadline() ), this, TQT_SLOT( updateHeadline() ) );
  90. }
  91. void HelpDialog::execute()
  92. {
  93. if(!list->currentItem())
  94. return;
  95. TQString t = text->text();
  96. t.insert( text->cursorPosition(), list->currentItem()->text( 0 ) );
  97. text->setText( t );
  98. if( isModal() )
  99. accept();
  100. }
  101. void HelpDialog::updateItems()
  102. {
  103. list->clear();
  104. TQStringList items = m_data->map()[comboHeadline->currentText()];
  105. for( unsigned int i = 0; i < items.count(); i++ ) {
  106. TQString tmp = items[i];
  107. new TDEListViewItem( list, tmp.section( ";;", 0, 0 ), tmp.section( ";;", 1, 1 ) );
  108. }
  109. }
  110. void HelpDialog::updateHeadline()
  111. {
  112. comboHeadline->clear();
  113. TQMap<TQString,TQStringList> m = m_data->map();
  114. TQMap<TQString,TQPixmap> ic = m_data->icons();
  115. comboHeadline->insertItem( ic[m_data->first()], m_data->first() );
  116. TQMap<TQString, TQStringList>::Iterator it;
  117. for ( it = m.begin(); it != m.end(); ++it )
  118. if( it.key() != m_data->first() )
  119. comboHeadline->insertItem( ic[it.key()], it.key() );
  120. }
  121. #include "helpdialog.moc"