summaryrefslogtreecommitdiffstats
path: root/krename/helpdialog.cpp
blob: 64a4809e7f60824b5265a4d07346a02d79045408 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/***************************************************************************
                         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 <tdelocale.h>
#include <tdelistview.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 TDEListView( 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 TDEListViewItem( 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() );    
}

#include "helpdialog.moc"