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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
|
/***************************************************************************
* Copyright (C) 2004-2009 by Thomas Fischer *
* [email protected] *
* *
* 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. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <ntqlayout.h>
#include <ntqheader.h>
#include <ntqlabel.h>
#include <ntqtooltip.h>
#include <kdialog.h>
#include <kdialogbase.h>
#include <klineedit.h>
#include <kcombobox.h>
#include <tdelistview.h>
#include <kdialog.h>
#include <kiconloader.h>
#include <kpushbutton.h>
#include <tdemessagebox.h>
#include <tdelocale.h>
#include <settings.h>
#include <fieldlineedit.h>
#include "settingsuserdefinedinput.h"
namespace KBibTeX
{
SettingsUserDefinedInput::SettingsUserDefinedInput( TQWidget *parent, const char *name ) : TQWidget( parent, name )
{
setupGUI();
}
SettingsUserDefinedInput::~SettingsUserDefinedInput()
{
// nothing
}
void SettingsUserDefinedInput::applyData()
{
Settings *settings = Settings::self( NULL );
settings->userDefinedInputFields.clear();
for ( TQListViewItemIterator it( m_listFields ); it.current(); ++it )
{
Settings::UserDefinedInputFields *udif = new Settings::UserDefinedInputFields();
udif->name = it.current()->text( 0 );
udif->label = it.current()->text( 1 );
udif->inputType = it.current()->text( 2 ) == i18n( "Single line" ) ? FieldLineEdit::itSingleLine : FieldLineEdit::itMultiLine;
settings->userDefinedInputFields << udif;
}
}
void SettingsUserDefinedInput::readData()
{
m_listFields->clear();
Settings *settings = Settings::self( NULL );
TDEListViewItem *prev = NULL;
for ( TQValueList<Settings::UserDefinedInputFields*>::iterator it = settings->userDefinedInputFields.begin(); it != settings->userDefinedInputFields.end(); ++it )
{
prev = new TDEListViewItem( m_listFields, prev, ( *it )->name, ( *it )->label, ( *it )->inputType == FieldLineEdit::itMultiLine ? i18n( "Multiple lines" ) : i18n( "Single line" ) );
}
}
void SettingsUserDefinedInput::slotNewField()
{
fieldDialog();
emit configChanged();
updateGUI();
}
void SettingsUserDefinedInput::slotEditField()
{
TQListViewItem * item = m_listFields->selectedItem();
if ( item != NULL )
{
fieldDialog( item );
emit configChanged();
}
updateGUI();
}
void SettingsUserDefinedInput::slotDeleteField()
{
TQListViewItem * item = m_listFields->selectedItem();
if ( item != NULL )
{
m_listFields->removeItem( item );
emit configChanged();
}
updateGUI();
}
void SettingsUserDefinedInput::slotMoveUpField()
{
TQListViewItem *item = m_listFields->selectedItem();
if ( item != NULL && item -> itemAbove() != NULL )
{
TQListViewItem *itemAbove = item->itemAbove();
for ( int i = 0; i < 3; ++i )
{
TQString text = item->text( i );
item->setText( i, itemAbove->text( i ) );
itemAbove->setText( i, text );
}
m_listFields->setCurrentItem( itemAbove );
m_listFields->ensureItemVisible( itemAbove );
updateGUI();
}
}
void SettingsUserDefinedInput::slotMoveDownField()
{
TQListViewItem *item = m_listFields->selectedItem();
if ( item != NULL && item -> itemBelow() != NULL )
{
TQListViewItem *itemBelow = item->itemBelow();
for ( int i = 0; i < 3; ++i )
{
TQString text = item->text( i );
item->setText( i, itemBelow->text( i ) );
itemBelow->setText( i, text );
}
m_listFields->setCurrentItem( itemBelow );
m_listFields->ensureItemVisible( itemBelow );
updateGUI();
}
}
void SettingsUserDefinedInput::updateGUI()
{
TQListViewItem *item = m_listFields->selectedItem();
bool selected = item != NULL;
m_buttonEditField->setEnabled( selected );
m_buttonDeleteField->setEnabled( selected );
m_buttonMoveDownField->setEnabled( selected && item->itemBelow() != NULL );
m_buttonMoveUpField->setEnabled( selected && item->itemAbove() != NULL );
}
void SettingsUserDefinedInput::updateDialogGUI()
{
bool enable = !m_lineEditName->text().isEmpty() && !m_lineEditLabel->text().isEmpty();
fieldDlg->enableButtonOK( enable );
fieldDlg->enableButtonApply( enable );
}
void SettingsUserDefinedInput::setupGUI()
{
TQGridLayout * gridLayout = new TQGridLayout( this, 6, 2, 0, KDialog::spacingHint(), "gridLayout" );
gridLayout->setRowStretch( 5, 1 );
gridLayout->setColStretch( 0, 1 );
m_listFields = new TDEListView( this );
m_listFields->setSorting( -1, FALSE );
m_listFields->addColumn( i18n( "Name" ) );
m_listFields->header()->setClickEnabled( FALSE );
m_listFields->addColumn( i18n( "Label" ) );
m_listFields->header()->setClickEnabled( FALSE );
m_listFields->addColumn( i18n( "Type" ) );
m_listFields->header()->setClickEnabled( FALSE );
m_listFields->header()->setClickEnabled( FALSE );
m_listFields->setFullWidth( true );
m_listFields->setMinimumWidth( 128 );
m_listFields->setAllColumnsShowFocus( TRUE );
gridLayout->addMultiCellWidget( m_listFields, 0, 5, 0, 0 );
m_buttonNewField = new KPushButton( i18n( "user-defined input", "New" ), this );
m_buttonNewField->setIconSet( TQIconSet( SmallIcon( "add" ) ) );
gridLayout->addWidget( m_buttonNewField, 0, 1 );
m_buttonEditField = new KPushButton( i18n( "user-defined input", "Edit" ), this );
m_buttonEditField->setIconSet( TQIconSet( SmallIcon( "edit" ) ) );
gridLayout->addWidget( m_buttonEditField, 1, 1 );
m_buttonDeleteField = new KPushButton( i18n( "user-defined input", "Delete" ), this );
m_buttonDeleteField->setIconSet( TQIconSet( SmallIcon( "editdelete" ) ) );
gridLayout->addWidget( m_buttonDeleteField, 2, 1 );
m_buttonMoveUpField = new KPushButton( i18n( "user-defined input", "Up" ), this );
m_buttonMoveUpField->setIconSet( TQIconSet( SmallIcon( "up" ) ) );
gridLayout->addWidget( m_buttonMoveUpField, 3, 1 );
connect( m_buttonMoveUpField, SIGNAL( clicked() ), this, SLOT( slotMoveUpField() ) );
m_buttonMoveDownField = new KPushButton( i18n( "user-defined input", "Down" ), this );
m_buttonMoveDownField->setIconSet( TQIconSet( SmallIcon( "down" ) ) );
gridLayout->addWidget( m_buttonMoveDownField, 4, 1 );
connect( m_buttonMoveDownField, SIGNAL( clicked() ), this, SLOT( slotMoveDownField() ) );
connect( m_buttonNewField, SIGNAL( clicked() ), this, SLOT( slotNewField() ) );
connect( m_buttonEditField, SIGNAL( clicked() ), this, SLOT( slotEditField() ) );
connect( m_buttonDeleteField, SIGNAL( clicked() ), this, SLOT( slotDeleteField() ) );
connect( m_listFields, SIGNAL( selectionChanged() ), this, SLOT( updateGUI() ) );
connect( m_listFields, SIGNAL( doubleClicked( TQListViewItem*, const TQPoint &, int ) ), this, SLOT( slotEditField() ) );
connect( m_listFields, SIGNAL( currentChanged( TQListViewItem * ) ), this, SLOT( updateGUI() ) );
updateGUI();
}
void SettingsUserDefinedInput::fieldDialog( TQListViewItem * item )
{
fieldDlg = new KDialogBase( this, "fieldDialog", TRUE, item == NULL ? i18n( "New Field" ) : i18n( "Edit Field" ), KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, TRUE );
TQWidget *container = new TQWidget( fieldDlg, "container" );
TQGridLayout *layout = new TQGridLayout( container, 3, 2, 0, KDialog::spacingHint() );
TQLabel *label = new TQLabel( i18n( "Name:" ), container );
layout->addWidget( label, 0, 0 );
m_lineEditName = new KLineEdit( container );
label->setBuddy( m_lineEditName );
layout->addWidget( m_lineEditName, 0, 1 );
label = new TQLabel( i18n( "Label:" ), container );
layout->addWidget( label, 1, 0 );
m_lineEditLabel = new KLineEdit( container );
layout->addWidget( m_lineEditLabel, 1, 1 );
label->setBuddy( m_lineEditLabel );
m_lineEditLabel->setMinimumWidth( 384 );
label = new TQLabel( i18n( "Input Type:" ), container );
layout->addWidget( label, 2, 0 );
KComboBox *comboBoxInputType = new KComboBox( FALSE, container );
layout->addWidget( comboBoxInputType, 2, 1 );
label->setBuddy( comboBoxInputType );
comboBoxInputType->insertItem( i18n( "Single line" ) );
comboBoxInputType->insertItem( i18n( "Multiple lines" ) );
fieldDlg->setMainWidget( container );
if ( item != NULL )
{
m_lineEditName->setText( item->text( 0 ) );
m_lineEditLabel->setText( item->text( 1 ) );
comboBoxInputType->setCurrentItem( item->text( 2 ) == i18n( "Single line" ) ? 0 : 1 );
fieldDlg->enableButton( KDialogBase::Ok, true );
}
else
fieldDlg->enableButton( KDialogBase::Ok, false );
connect( m_lineEditName, SIGNAL( textChanged( const TQString & ) ), this, SLOT( updateDialogGUI() ) );
connect( m_lineEditLabel, SIGNAL( textChanged( const TQString & ) ), this, SLOT( updateDialogGUI() ) );
if ( fieldDlg->exec() == TQDialog::Accepted )
{
if ( item == NULL )
{
/*TDEListViewItem *item = */
new TDEListViewItem( m_listFields, m_lineEditName->text(), m_lineEditLabel->text(), comboBoxInputType->currentItem() == 0 ? i18n( "Single line" ) : i18n( "Multiple lines" ) );
}
else
{
item->setText( 0, m_lineEditName->text() );
item->setText( 1, m_lineEditLabel->text() );
item->setText( 2, comboBoxInputType->currentItem() == 0 ? i18n( "Single line" ) : i18n( "Multiple lines" ) );
}
}
delete fieldDlg;
}
}
#include "settingsuserdefinedinput.moc"
|