1
/**********************************************************************
2
** Copyright (C) 2000 Trolltech AS. All rights reserved.
4
** This file is part of Qt Designer.
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.
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.
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.
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.
22
** Contact info@trolltech.com if any conditions of this licensing are
25
**********************************************************************/
27
#include "wizardeditorimpl.h"
28
#include "formwindow.h"
29
#include "mainwindow.h"
31
#include "listboxdnd.h"
32
#include "listboxrename.h"
36
#include <qpushbutton.h>
37
#include <qinputdialog.h>
41
WizardEditor::WizardEditor( QWidget *parent, QWizard *w, FormWindow *fw )
42
: WizardEditorBase( parent, 0 ), formwindow( fw ), wizard( w ), draggedItem( 0 )
44
connect( buttonHelp, SIGNAL( clicked() ), MainWindow::self, SLOT( showDialogHelp() ) );
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 * ) ) );
53
QObject::connect( listBoxDnd, SIGNAL( dragged( QListBoxItem * ) ),
54
this, SLOT( itemDragged( QListBoxItem * ) ) );
55
QObject::connect( listBoxDnd, SIGNAL( dropped( QListBoxItem * ) ),
56
this, SLOT( itemDropped( QListBoxItem * ) ) );
58
// Add in-place rename
59
new ListBoxRename( listBox );
62
WizardEditor::~WizardEditor()
64
commands.setAutoDelete( TRUE );
67
void WizardEditor::okClicked()
73
void WizardEditor::cancelClicked()
78
void WizardEditor::applyClicked()
80
if ( commands.isEmpty() ) return;
82
// schedule macro command
83
MacroCommand* cmd = new MacroCommand( i18n( "Edit Wizard Pages" ), formwindow, commands );
84
formwindow->commandHistory()->addCommand( cmd );
91
for ( int i = 0; i < wizard->pageCount(); i++ ) {
93
QWidget * page = wizard->page( i );
94
if ( i == 0 ) { // first page
96
wizard->setBackEnabled( page, FALSE );
97
wizard->setNextEnabled( page, TRUE );
99
else if ( i == wizard->pageCount() - 1 ) { // last page
101
wizard->setBackEnabled( page, TRUE );
102
wizard->setNextEnabled( page, FALSE );
106
wizard->setBackEnabled( page, TRUE );
107
wizard->setNextEnabled( page, TRUE );
109
wizard->setFinishEnabled( page, FALSE );
113
int index = listBox->currentItem();
115
listBox->setCurrentItem( index );
118
wizard->showPage( wizard->page( 0 ) );
121
void WizardEditor::helpClicked()
126
void WizardEditor::addClicked()
128
int index = listBox->currentItem() + 1;
130
listBox->insertItem( i18n( "Page" ), index );
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 );
141
void WizardEditor::removeClicked()
143
if ( listBox->count() < 2 ) return;
145
int index = listBox->currentItem();
148
listBox->removeItem( index );
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 );
160
void WizardEditor::upClicked()
162
int index1 = listBox->currentItem();
163
int index2 = index1 - 1;
165
// swap listbox items
166
QString item1 = listBox->text( index1 );
167
listBox->removeItem( index1 );
168
listBox->insertItem( item1, index2 );
169
listBox->setCurrentItem( index2 );
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 );
180
void WizardEditor::downClicked()
182
int index1 = listBox->currentItem();
183
int index2 = index1 + 1;
185
// swap listbox items
186
QString item1 = listBox->text( index1 );
187
listBox->removeItem( index1 );
188
listBox->insertItem( item1, index2 );
189
listBox->setCurrentItem( index2 );
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 );
199
void WizardEditor::fillListBox()
203
if ( !wizard ) return;
204
for ( int i = 0; i < wizard->pageCount(); i++ )
205
listBox->insertItem( wizard->title( wizard->page( i ) ) );
210
void WizardEditor::itemHighlighted( int )
215
void WizardEditor::itemSelected( int index )
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 );
225
void WizardEditor::updateButtons()
227
int index = listBox->currentItem();
229
buttonUp->setEnabled( index > 0 );
230
buttonDown->setEnabled( index < (int)listBox->count() - 1 );
231
buttonRemove->setEnabled( index >= 0 );
233
if ( listBox->count() < 2 )
234
buttonRemove->setEnabled( FALSE );
237
void WizardEditor::itemDragged( QListBoxItem * i )
240
draggedItem = listBox->index( i );
243
void WizardEditor::itemDropped( QListBoxItem * i )
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 );
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 );