~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to kdevdesigner/designer/wizardeditorimpl.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2010-05-05 07:21:55 UTC
  • mfrom: (1.2.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505072155-h78lx19pu04sbhtn
Tags: 4:4.0.0-2
* Upload to unstable (Closes: #579947, #481832).
* Acknowledge obsolete NMU fixes (Closes: #562410, #546961).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**********************************************************************
2
 
** Copyright (C) 2000 Trolltech AS.  All rights reserved.
3
 
**
4
 
** This file is part of Qt Designer.
5
 
**
6
 
** This file may be distributed and/or modified under the terms of the
7
 
** GNU General Public License version 2 as published by the Free Software
8
 
** Foundation and appearing in the file LICENSE.GPL included in the
9
 
** packaging of this file.
10
 
**
11
 
** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
12
 
** licenses may use this file in accordance with the Qt Commercial License
13
 
** Agreement provided with the Software.
14
 
**
15
 
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16
 
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17
 
**
18
 
** See http://www.trolltech.com/gpl/ for GPL licensing information.
19
 
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
20
 
**   information about Qt Commercial License Agreements.
21
 
**
22
 
** Contact info@trolltech.com if any conditions of this licensing are
23
 
** not clear to you.
24
 
**
25
 
**********************************************************************/
26
 
 
27
 
#include "wizardeditorimpl.h"
28
 
#include "formwindow.h"
29
 
#include "mainwindow.h"
30
 
#include "command.h"
31
 
#include "listboxdnd.h"
32
 
#include "listboxrename.h"
33
 
 
34
 
#include <qwizard.h>
35
 
#include <qlistbox.h>
36
 
#include <qpushbutton.h>
37
 
#include <qinputdialog.h>
38
 
 
39
 
#include <klocale.h>
40
 
 
41
 
WizardEditor::WizardEditor( QWidget *parent, QWizard *w, FormWindow *fw )
42
 
    : WizardEditorBase( parent, 0 ), formwindow( fw ), wizard( w ), draggedItem( 0 )
43
 
{
44
 
    connect( buttonHelp, SIGNAL( clicked() ), MainWindow::self, SLOT( showDialogHelp() ) );
45
 
    fillListBox();
46
 
 
47
 
    // Add drag and drop
48
 
    ListBoxDnd *listBoxDnd = new ListBoxDnd( listBox );
49
 
    listBoxDnd->setDragMode( ListBoxDnd::Internal | ListBoxDnd::Move );
50
 
    QObject::connect( listBoxDnd, SIGNAL( dropped( QListBoxItem * ) ),
51
 
                      listBoxDnd, SLOT( confirmDrop( QListBoxItem * ) ) );
52
 
 
53
 
    QObject::connect( listBoxDnd, SIGNAL( dragged( QListBoxItem * ) ),
54
 
                      this, SLOT( itemDragged( QListBoxItem * ) ) );
55
 
    QObject::connect( listBoxDnd, SIGNAL( dropped( QListBoxItem * ) ),
56
 
                      this, SLOT( itemDropped( QListBoxItem * ) ) );
57
 
 
58
 
    // Add in-place rename
59
 
    new ListBoxRename( listBox );
60
 
}
61
 
 
62
 
WizardEditor::~WizardEditor()
63
 
{
64
 
    commands.setAutoDelete( TRUE );
65
 
}
66
 
 
67
 
void WizardEditor::okClicked()
68
 
{
69
 
    applyClicked();
70
 
    accept();
71
 
}
72
 
 
73
 
void WizardEditor::cancelClicked()
74
 
{
75
 
    reject();
76
 
}
77
 
 
78
 
void WizardEditor::applyClicked()
79
 
{
80
 
    if ( commands.isEmpty() ) return;
81
 
 
82
 
    // schedule macro command
83
 
    MacroCommand* cmd = new MacroCommand( i18n( "Edit Wizard Pages" ), formwindow, commands );
84
 
    formwindow->commandHistory()->addCommand( cmd );
85
 
    cmd->execute();
86
 
 
87
 
    // clear command list
88
 
    commands.clear();
89
 
 
90
 
    // fix wizard buttons
91
 
    for ( int i = 0; i < wizard->pageCount(); i++ ) {
92
 
 
93
 
        QWidget * page = wizard->page( i );
94
 
        if ( i == 0 ) { // first page
95
 
 
96
 
            wizard->setBackEnabled( page, FALSE );
97
 
            wizard->setNextEnabled( page, TRUE );
98
 
        }
99
 
        else if ( i == wizard->pageCount() - 1 ) { // last page
100
 
 
101
 
            wizard->setBackEnabled( page, TRUE );
102
 
            wizard->setNextEnabled( page, FALSE );
103
 
        }
104
 
        else {
105
 
 
106
 
            wizard->setBackEnabled( page, TRUE );
107
 
            wizard->setNextEnabled( page, TRUE );
108
 
        }
109
 
        wizard->setFinishEnabled( page, FALSE );
110
 
    }
111
 
 
112
 
    // update listbox
113
 
    int index = listBox->currentItem();
114
 
    fillListBox();
115
 
    listBox->setCurrentItem( index );
116
 
 
117
 
    // show current page
118
 
    wizard->showPage( wizard->page( 0 ) );
119
 
}
120
 
 
121
 
void WizardEditor::helpClicked()
122
 
{
123
 
 
124
 
}
125
 
 
126
 
void WizardEditor::addClicked()
127
 
{
128
 
    int index = listBox->currentItem() + 1;
129
 
    // update listbox
130
 
    listBox->insertItem( i18n( "Page" ), index );
131
 
 
132
 
    // schedule add command
133
 
    AddWizardPageCommand *cmd = new AddWizardPageCommand( i18n( "Add Page to %1" ).arg( wizard->name() ),
134
 
                                                          formwindow, wizard, "Page", index, FALSE);
135
 
    commands.append( cmd );
136
 
 
137
 
    // update buttons
138
 
    updateButtons();
139
 
}
140
 
 
141
 
void WizardEditor::removeClicked()
142
 
{
143
 
    if ( listBox->count() < 2 ) return;
144
 
 
145
 
    int index = listBox->currentItem();
146
 
 
147
 
    // update listbox
148
 
    listBox->removeItem( index );
149
 
 
150
 
    // schedule remove command
151
 
    DeleteWizardPageCommand *cmd = new DeleteWizardPageCommand( i18n( "Delete Page %1 of %2" )
152
 
                                                                .arg( listBox->text( index ) ).arg( wizard->name() ),
153
 
                                                                formwindow, wizard, index, FALSE );
154
 
    commands.append( cmd );
155
 
 
156
 
    // update buttons
157
 
    updateButtons();
158
 
}
159
 
 
160
 
void WizardEditor::upClicked()
161
 
{
162
 
    int index1 = listBox->currentItem();
163
 
    int index2 = index1 - 1;
164
 
 
165
 
    // swap listbox items
166
 
    QString item1 = listBox->text( index1 );
167
 
    listBox->removeItem( index1 );
168
 
    listBox->insertItem( item1, index2 );
169
 
    listBox->setCurrentItem( index2 );
170
 
 
171
 
    // schedule swap command
172
 
    SwapWizardPagesCommand *cmd = new SwapWizardPagesCommand( i18n( "Swap Pages %1 and %2 of %3" ).arg( index1 ).arg( index2 )
173
 
                                                             .arg( wizard->name() ), formwindow, wizard, index1, index2);
174
 
    commands.append( cmd );
175
 
 
176
 
    // update buttons
177
 
    updateButtons();
178
 
}
179
 
 
180
 
void WizardEditor::downClicked()
181
 
{
182
 
    int index1 = listBox->currentItem();
183
 
    int index2 = index1 + 1;
184
 
 
185
 
    // swap listbox items
186
 
    QString item1 = listBox->text( index1 );
187
 
    listBox->removeItem( index1 );
188
 
    listBox->insertItem( item1, index2 );
189
 
    listBox->setCurrentItem( index2 );
190
 
 
191
 
    // schedule swap command
192
 
    SwapWizardPagesCommand *cmd = new SwapWizardPagesCommand( i18n( "Swap Pages %1 and %2 of %3" ).arg( index1 ).arg( index2 ).arg( wizard->name() ), formwindow, wizard, index2, index1);
193
 
    commands.append( cmd );
194
 
 
195
 
    // update buttons
196
 
    updateButtons();
197
 
}
198
 
 
199
 
void WizardEditor::fillListBox()
200
 
{
201
 
    listBox->clear();
202
 
 
203
 
    if ( !wizard ) return;
204
 
    for ( int i = 0; i < wizard->pageCount(); i++ )
205
 
        listBox->insertItem( wizard->title( wizard->page( i ) ) );
206
 
 
207
 
    updateButtons();
208
 
}
209
 
 
210
 
void WizardEditor::itemHighlighted( int )
211
 
{
212
 
    updateButtons();
213
 
}
214
 
 
215
 
void WizardEditor::itemSelected( int index )
216
 
{
217
 
    if ( index < 0 ) return;
218
 
    // Called when Qt::Key_Enter was pressed.
219
 
    // ListBoxRename has renamed the list item, so we only need to rename the page to the same name.
220
 
    QString pn( i18n( "Rename page %1 of %2" ).arg( wizard->title( wizard->page( index ) ) ).arg( wizard->name() ) );
221
 
        RenameWizardPageCommand *cmd = new RenameWizardPageCommand( pn, formwindow, wizard, index, listBox->text( index ) );
222
 
        commands.append( cmd );
223
 
}
224
 
 
225
 
void WizardEditor::updateButtons()
226
 
{
227
 
    int index = listBox->currentItem();
228
 
 
229
 
    buttonUp->setEnabled( index > 0 );
230
 
    buttonDown->setEnabled( index < (int)listBox->count() - 1 );
231
 
    buttonRemove->setEnabled( index >= 0 );
232
 
 
233
 
    if ( listBox->count() < 2 )
234
 
        buttonRemove->setEnabled( FALSE );
235
 
}
236
 
 
237
 
void WizardEditor::itemDragged( QListBoxItem * i )
238
 
{
239
 
    // Store item index
240
 
    draggedItem = listBox->index( i );
241
 
}
242
 
 
243
 
void WizardEditor::itemDropped( QListBoxItem * i )
244
 
{
245
 
    if ( draggedItem < 0 ) return;
246
 
    // The reorder the pages acording to the listBox list of items
247
 
    // Assumes that only one item has been moved.
248
 
    int droppedItem = listBox->index( i );
249
 
 
250
 
    //qDebug( "Moving page %d -> %d", draggedItem, droppedItem );
251
 
    MoveWizardPageCommand *cmd = new MoveWizardPageCommand( i18n( "Move Page %1 to %2 in %3" ).arg( draggedItem ).arg( droppedItem ).arg( wizard->name() ), formwindow, wizard, draggedItem, droppedItem );
252
 
    commands.append( cmd );
253
 
}