~ubuntu-branches/ubuntu/oneiric/psi/oneiric

« back to all changes in this revision

Viewing changes to src/options/toolbardlg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2005-01-10 17:41:43 UTC
  • mfrom: (1.2.1 upstream) (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050110174143-ltocv5zapl6blf5d
Tags: 0.9.3-1
* New upstream release
* Cleaned up debian/rules (some things are done by upstream Makefiles now)
* Fixed some lintian warnings:
  - removed executable bit from some .png files
  - moved psi.desktop to /usr/share/applications
* Updated menu files

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "toolbardlg.h"
 
2
 
 
3
#include "psicon.h"
 
4
#include "common.h"
 
5
#include "iconwidget.h"
 
6
#include "mainwin.h"
 
7
#include "psitoolbar.h"
 
8
#include "iconaction.h"
 
9
#include "psiactionlist.h"
 
10
 
 
11
#include "opt_lookfeel_toolbars.h"
 
12
#include "ui_positiontoolbar.h"
 
13
 
 
14
#include <qlayout.h>
 
15
#include <qpushbutton.h>
 
16
#include <qframe.h>
 
17
#include <qlistview.h>
 
18
#include <qcombobox.h>
 
19
#include <qaction.h>
 
20
#include <qlineedit.h>
 
21
#include <qcheckbox.h>
 
22
#include <qheader.h>
 
23
#include <qspinbox.h>
 
24
 
 
25
//----------------------------------------------------------------------------
 
26
// PositionToolbarDlg
 
27
//----------------------------------------------------------------------------
 
28
 
 
29
class PositionToolbarDlg : public PositionToolbarUI
 
30
{
 
31
        Q_OBJECT
 
32
public:
 
33
        PositionToolbarDlg(QWidget *parent, Options::ToolbarPrefs *, int);
 
34
        ~PositionToolbarDlg();
 
35
 
 
36
        int n();
 
37
        bool dirty;
 
38
 
 
39
        bool eventFilter(QObject *watched, QEvent *e);
 
40
 
 
41
signals:
 
42
        void applyPressed();
 
43
 
 
44
private slots:
 
45
        void dataChanged();
 
46
        void apply();
 
47
 
 
48
private:
 
49
        int id;
 
50
        Options::ToolbarPrefs *tb;
 
51
};
 
52
 
 
53
PositionToolbarDlg::PositionToolbarDlg(QWidget *parent, Options::ToolbarPrefs *_tb, int _id)
 
54
: PositionToolbarUI(parent, "PositionToolbarDlg", true)
 
55
{
 
56
        tb = _tb;
 
57
        id = _id;
 
58
 
 
59
        connect(pb_ok, SIGNAL(clicked()), SLOT(apply()));
 
60
        connect(pb_ok, SIGNAL(clicked()), SLOT(accept()));
 
61
        connect(pb_apply, SIGNAL(clicked()), SLOT(apply()));
 
62
        connect(pb_cancel, SIGNAL(clicked()), SLOT(reject()));
 
63
 
 
64
        connect(cb_dock, SIGNAL(highlighted(int)), SLOT(dataChanged()));
 
65
        sb_index->installEventFilter( this );
 
66
        sb_extraOffset->installEventFilter( this );
 
67
        connect(ck_nl, SIGNAL(toggled(bool)), SLOT(dataChanged()));
 
68
 
 
69
        le_name->setText( tb->name );
 
70
        if ( tb->dock >= DockUnmanaged && tb->dock <= DockTornOff ) {
 
71
                cb_dock->setCurrentItem( tb->dock + DockMinimized - DockTornOff );
 
72
        }
 
73
        else {
 
74
                cb_dock->setCurrentItem( tb->dock - DockTop );
 
75
        }
 
76
        sb_index->setValue( tb->index );
 
77
        sb_extraOffset->setValue( tb->extraOffset );
 
78
        ck_nl->setChecked( tb->nl );
 
79
 
 
80
        dirty = false;
 
81
        pb_apply->setEnabled(false);
 
82
 
 
83
        resize(sizeHint());
 
84
}
 
85
 
 
86
PositionToolbarDlg::~PositionToolbarDlg()
 
87
{
 
88
}
 
89
 
 
90
int PositionToolbarDlg::n()
 
91
{
 
92
        return id;
 
93
}
 
94
 
 
95
void PositionToolbarDlg::dataChanged()
 
96
{
 
97
        dirty = true;
 
98
        pb_apply->setEnabled(true);
 
99
}
 
100
 
 
101
void PositionToolbarDlg::apply()
 
102
{
 
103
        tb->dirty = true;
 
104
        if ( cb_dock->currentItem() >= 0 && cb_dock->currentItem() < 5 ) {
 
105
                // Top, Bottom, Left, Right and Minimised
 
106
                tb->dock = (Dock)(cb_dock->currentItem() + DockTop);
 
107
        }
 
108
        else {
 
109
                // Unmanaged and TornOff
 
110
                tb->dock = (Dock)(cb_dock->currentItem() - (DockMinimized - DockTornOff));
 
111
        }
 
112
 
 
113
        tb->index = sb_index->value();
 
114
        tb->extraOffset = sb_extraOffset->value();
 
115
        tb->nl = ck_nl->isChecked();
 
116
 
 
117
        if ( dirty )
 
118
                emit applyPressed();
 
119
        dirty = false;
 
120
        pb_apply->setEnabled(false);
 
121
}
 
122
 
 
123
bool PositionToolbarDlg::eventFilter(QObject *watched, QEvent *e)
 
124
{
 
125
        if ( watched->inherits("QSpinBox") && e->type() == QEvent::KeyRelease )
 
126
                dataChanged();
 
127
        return false;
 
128
}
 
129
 
 
130
//----------------------------------------------------------------------------
 
131
// ToolbarDlg
 
132
//----------------------------------------------------------------------------
 
133
 
 
134
class ToolbarDlg::Private
 
135
{
 
136
public:
 
137
        struct ToolbarItem {
 
138
                QString group;
 
139
                int index;
 
140
                ToolbarItem() {
 
141
                        group = "";
 
142
                        index = -1;
 
143
                }
 
144
                ToolbarItem( QString _w, int _i ) {
 
145
                        group = _w;
 
146
                        index = _i;
 
147
                }
 
148
        };
 
149
 
 
150
        QMap<int, ToolbarItem> toolbars;
 
151
 
 
152
        PsiActionList::ActionsType class2id( QString name ) {
 
153
                int ret = (int)PsiActionList::Actions_Common;
 
154
 
 
155
                if ( name == "mainWin" )
 
156
                        ret |= (int)PsiActionList::Actions_MainWin;
 
157
 
 
158
                return (PsiActionList::ActionsType)ret;
 
159
        }
 
160
};
 
161
 
 
162
ToolbarDlg::ToolbarDlg(PsiCon *_psi, QWidget *parent, const char *name)
 
163
: QDialog(parent, name, false, WDestructiveClose)
 
164
{
 
165
        p = new Private();
 
166
 
 
167
        psi  = _psi;
 
168
        psi->dialogRegister(this);
 
169
        noDirty = false;
 
170
        opt = new Options;
 
171
 
 
172
        setCaption(CAP(tr("Configure Toolbars")));
 
173
 
 
174
        connect(this, SIGNAL(dataChanged()), SLOT(dataChangedSlot()));
 
175
 
 
176
        QVBoxLayout *vbox = new QVBoxLayout(this, 11, 6);
 
177
        w = new LookFeelToolbarsUI(this);
 
178
        vbox->addWidget(w);
 
179
        LookFeelToolbarsUI *d = (LookFeelToolbarsUI *)w;
 
180
 
 
181
        connect(d->pb_addToolbar, SIGNAL(clicked()), SLOT(toolbarAdd()));
 
182
        connect(d->pb_deleteToolbar, SIGNAL(clicked()), SLOT(toolbarDelete()));
 
183
        connect(d->cb_toolbars, SIGNAL(activated(int)), SLOT(toolbarSelectionChanged(int)));
 
184
        connect(d->le_toolbarName, SIGNAL(textChanged(const QString &)), SLOT(toolbarNameChanged()));
 
185
        connect(d->pb_toolbarPosition, SIGNAL(clicked()), SLOT(toolbarPosition()));
 
186
        connect(d->tb_up, SIGNAL(clicked()), SLOT(toolbarActionUp()));
 
187
        connect(d->tb_down, SIGNAL(clicked()), SLOT(toolbarActionDown()));
 
188
        connect(d->tb_right, SIGNAL(clicked()), SLOT(toolbarAddAction()));
 
189
        connect(d->tb_left, SIGNAL(clicked()), SLOT(toolbarRemoveAction()));
 
190
 
 
191
        connect(d->ck_toolbarOn, SIGNAL(toggled(bool)), SLOT(toolbarDataChanged()));
 
192
        connect(d->ck_toolbarLocked, SIGNAL(toggled(bool)), SLOT(toolbarDataChanged()));
 
193
        connect(d->ck_toolbarStretch, SIGNAL(toggled(bool)), SLOT(toolbarDataChanged()));
 
194
        connect(d->lv_selectedActions, SIGNAL(selectionChanged(QListViewItem *)), SLOT(selAct_selectionChanged(QListViewItem *)));
 
195
        connect(d->lv_availActions, SIGNAL(selectionChanged(QListViewItem *)), SLOT(avaAct_selectionChanged(QListViewItem *)));
 
196
 
 
197
        connect(d->pb_deleteToolbar, SIGNAL(clicked()), SIGNAL(dataChanged()));
 
198
        connect(d->tb_up, SIGNAL(clicked()), SIGNAL(dataChanged()));
 
199
        connect(d->tb_down, SIGNAL(clicked()), SIGNAL(dataChanged()));
 
200
        connect(d->tb_left, SIGNAL(clicked()), SIGNAL(dataChanged()));
 
201
        connect(d->tb_right, SIGNAL(clicked()), SIGNAL(dataChanged()));
 
202
        connect(d->pb_addToolbar, SIGNAL(clicked()), SIGNAL(dataChanged()));
 
203
        connect(d->pb_deleteToolbar, SIGNAL(clicked()), SIGNAL(dataChanged()));
 
204
 
 
205
        d->lv_selectedActions->header()->hide();
 
206
        d->lv_availActions->header()->hide();
 
207
 
 
208
        d->lv_selectedActions->setSorting(-1);
 
209
        d->lv_availActions->setSorting(-1);
 
210
 
 
211
        // TODO: add QWhatsThis to all widgets
 
212
 
 
213
        QFrame *line = new QFrame( this );
 
214
        line->setFrameShape( QFrame::HLine );
 
215
        line->setFrameShadow( QFrame::Sunken );
 
216
        line->setFrameShape( QFrame::HLine );
 
217
        vbox->addWidget( line );
 
218
 
 
219
        QHBoxLayout *hbox = new QHBoxLayout( 0, 0, 6 );
 
220
        vbox->addLayout(hbox);
 
221
 
 
222
        QSpacerItem *spacer = new QSpacerItem( 40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
 
223
        hbox->addItem( spacer );
 
224
 
 
225
        IconButton *pb_ok = new IconButton( this );
 
226
        hbox->addWidget( pb_ok );
 
227
        pb_ok->setText( tr("&OK") );
 
228
        pb_ok->setIcon( "psi/ok" );
 
229
        connect(pb_ok, SIGNAL(clicked()), SLOT(doApply()));
 
230
        connect(pb_ok, SIGNAL(clicked()), SLOT(accept()));
 
231
 
 
232
        //pb_apply = 0;
 
233
        pb_apply = new IconButton( this );
 
234
        hbox->addWidget( pb_apply );
 
235
        pb_apply->setText( tr("&Apply") );
 
236
        connect(pb_apply, SIGNAL(clicked()), SLOT(doApply()));
 
237
        pb_apply->setEnabled(false);
 
238
 
 
239
        IconButton *pb_cancel = new IconButton( this );
 
240
        hbox->addWidget( pb_cancel );
 
241
        pb_cancel->setText( tr("&Cancel") );
 
242
        pb_cancel->setIcon( "psi/cancel" );
 
243
        connect(pb_cancel, SIGNAL(clicked()), SLOT(reject()));
 
244
 
 
245
        restoreOptions( &option );
 
246
        resize( minimumSize() );
 
247
}
 
248
 
 
249
ToolbarDlg::~ToolbarDlg()
 
250
{
 
251
        psi->dialogUnregister(this);
 
252
        delete opt;
 
253
        delete p;
 
254
}
 
255
 
 
256
void ToolbarDlg::setCurrentToolbar(PsiToolBar *t)
 
257
{
 
258
        LookFeelToolbarsUI *d = (LookFeelToolbarsUI *)w;
 
259
 
 
260
        if ( pb_apply->isEnabled() )
 
261
                return;
 
262
 
 
263
        QMap<int, Private::ToolbarItem>::Iterator it = p->toolbars.begin();
 
264
        for ( ; it != p->toolbars.end(); ++it ) {
 
265
                if ( it.data().group == t->group() && it.data().index == t->groupIndex() ) {
 
266
                        d->cb_toolbars->setCurrentItem( it.key() );
 
267
                        toolbarSelectionChanged( it.key() );
 
268
                        break;
 
269
                }
 
270
        }
 
271
}
 
272
 
 
273
void ToolbarDlg::applyOptions(Options *o)
 
274
{
 
275
        if ( !w )
 
276
                opt->toolbars = o->toolbars;
 
277
 
 
278
        // get current toolbars' positions
 
279
        MainWin *mainWin = (MainWin *)psi->mainWin();
 
280
        for (uint i = 0; i < opt->toolbars.count() && i < mainWin->toolbars.count(); i++) {
 
281
                //if ( toolbarPositionInProgress && posTbDlg->n() == (int)i )
 
282
                //      continue;
 
283
 
 
284
                Options::ToolbarPrefs &tbPref = opt->toolbars["mainWin"][i];
 
285
                mainWin->getLocation ( mainWin->toolbars.at(i), tbPref.dock, tbPref.index, tbPref.nl, tbPref.extraOffset );
 
286
        }
 
287
 
 
288
        // apply options
 
289
        o->toolbars = opt->toolbars;
 
290
}
 
291
 
 
292
void ToolbarDlg::rebuildToolbarList()
 
293
{
 
294
        LookFeelToolbarsUI *d = (LookFeelToolbarsUI *)w;
 
295
 
 
296
        d->cb_toolbars->clear();
 
297
        p->toolbars.clear();
 
298
 
 
299
        QMap< QString, QValueList<Options::ToolbarPrefs> >::Iterator it = opt->toolbars.begin();
 
300
        for ( ; it != opt->toolbars.end(); ++it ) {
 
301
                if ( p->toolbars.count() )
 
302
                        d->cb_toolbars->insertItem( "---" ); // TODO: think of better separator
 
303
 
 
304
                int i = 0;
 
305
                QValueList<Options::ToolbarPrefs>::Iterator it2 = it.data().begin();
 
306
                for ( ; it2 != it.data().end(); ++it2, ++i ) {
 
307
                        d->cb_toolbars->insertItem( (*it2).name );
 
308
                        p->toolbars[d->cb_toolbars->count()-1] = Private::ToolbarItem( it.key(), i );
 
309
                }
 
310
        }
 
311
}
 
312
 
 
313
void ToolbarDlg::restoreOptions(const Options *o)
 
314
{
 
315
        if ( !w )
 
316
                return;
 
317
 
 
318
        LookFeelToolbarsUI *d = (LookFeelToolbarsUI *)w;
 
319
        opt->toolbars = o->toolbars;
 
320
 
 
321
        rebuildToolbarList();
 
322
 
 
323
        if(d->cb_toolbars->count() > 0) {
 
324
                d->cb_toolbars->setCurrentItem( 0 );
 
325
                toolbarSelectionChanged( 0 );
 
326
        }
 
327
        else
 
328
                toolbarSelectionChanged( -1 );
 
329
}
 
330
 
 
331
//----------------------------------------------------------------------------
 
332
 
 
333
void ToolbarDlg::toolbarAdd()
 
334
{
 
335
        LookFeelToolbarsUI *d = (LookFeelToolbarsUI *)w;
 
336
 
 
337
        int i = d->cb_toolbars->count();
 
338
 
 
339
        Options::ToolbarPrefs tb;
 
340
        tb.name = QObject::tr("<unnamed>");
 
341
        tb.on = false;
 
342
        tb.locked = false;
 
343
        tb.stretchable = false;
 
344
        tb.keys.clear();
 
345
 
 
346
        tb.dock = Qt::DockTop;
 
347
        tb.index = i;
 
348
        tb.nl = true;
 
349
        tb.extraOffset = 0;
 
350
 
 
351
        tb.dirty = true;
 
352
 
 
353
        opt->toolbars["mainWin"].append(tb);
 
354
 
 
355
        rebuildToolbarList();
 
356
/*      TODO
 
357
        d->cb_toolbars->insertItem( tb.name );
 
358
        d->cb_toolbars->setCurrentItem( d->cb_toolbars->count() - 1 );
 
359
        toolbarSelectionChanged( d->cb_toolbars->count() - 1 );
 
360
 
 
361
        d->le_toolbarName->setFocus();
 
362
*/
 
363
}
 
364
 
 
365
void ToolbarDlg::toolbarDelete()
 
366
{
 
367
        LookFeelToolbarsUI *d = (LookFeelToolbarsUI *)w;
 
368
        int n = d->cb_toolbars->currentItem();
 
369
 
 
370
        Options::ToolbarPrefs tb = opt->toolbars[p->toolbars[n].group][p->toolbars[n].index];
 
371
        PsiToolBar *toolBar = psi->findToolBar( p->toolbars[n].group, p->toolbars[n].index );
 
372
        if ( !toolBar )
 
373
                return;
 
374
 
 
375
        // delete current toolbar
 
376
        {
 
377
                int idx = p->toolbars[n].index;
 
378
                QValueList<Options::ToolbarPrefs>::Iterator it = opt->toolbars[p->toolbars[n].group].begin();
 
379
                for (int i = 0; i < idx; i++)
 
380
                        ++it;
 
381
 
 
382
                noDirty = true;
 
383
                opt->toolbars[p->toolbars[n].group].remove(it);
 
384
 
 
385
                rebuildToolbarList();
 
386
                noDirty = false;
 
387
                toolbarSelectionChanged( n - 1 ); // TODO FIXME
 
388
        }
 
389
}
 
390
 
 
391
void ToolbarDlg::addToolbarAction(QListView *parent, QString name, int toolbarId)
 
392
{
 
393
        ActionList actions = psi->actionList()->suitableActions( (PsiActionList::ActionsType)toolbarId );
 
394
        const QAction *action = (QAction *)actions.action( name );
 
395
        if ( !action )
 
396
                return;
 
397
 
 
398
        addToolbarAction(parent, action, name);
 
399
}
 
400
 
 
401
void ToolbarDlg::addToolbarAction(QListView *parent, const QAction *action, QString name)
 
402
{
 
403
        QListViewItem *item = new QListViewItem(parent, parent->lastItem());
 
404
 
 
405
        QString n = actionName(action);
 
406
        if ( !action->whatsThis().isEmpty() )
 
407
                n += " - " + action->whatsThis();
 
408
        item->setText(0, n);
 
409
        item->setText(1, name);
 
410
        item->setPixmap(0, action->iconSet().pixmap());
 
411
}
 
412
 
 
413
void ToolbarDlg::toolbarSelectionChanged(int item)
 
414
{
 
415
        if ( noDirty )
 
416
                return;
 
417
 
 
418
        int n = item;
 
419
        Options::ToolbarPrefs tb = opt->toolbars[p->toolbars[n].group][p->toolbars[n].index];
 
420
        PsiToolBar *toolBar = psi->findToolBar( p->toolbars[n].group, p->toolbars[n].index );
 
421
 
 
422
        bool customizeable = toolBar ? toolBar->isCustomizeable() : false;
 
423
        bool moveable      = toolBar ? toolBar->isMoveable() : false;
 
424
 
 
425
        LookFeelToolbarsUI *d = (LookFeelToolbarsUI *)w;
 
426
        bool enable = (item == -1) ? false: true;
 
427
        d->le_toolbarName->setEnabled( enable );
 
428
        d->pb_toolbarPosition->setEnabled( enable && moveable );
 
429
        d->ck_toolbarOn->setEnabled( enable );
 
430
        d->ck_toolbarLocked->setEnabled( enable && moveable );
 
431
        d->ck_toolbarStretch->setEnabled( enable && moveable );
 
432
        d->lv_selectedActions->setEnabled( enable && customizeable );
 
433
        d->lv_availActions->setEnabled( enable && customizeable );
 
434
        d->tb_up->setEnabled( enable && customizeable );
 
435
        d->tb_down->setEnabled( enable && customizeable );
 
436
        d->tb_left->setEnabled( enable && customizeable );
 
437
        d->tb_right->setEnabled( enable && customizeable );
 
438
        d->pb_deleteToolbar->setEnabled( enable && p->toolbars[n].group == "mainWin" );
 
439
        d->cb_toolbars->setEnabled( enable );
 
440
 
 
441
        d->lv_availActions->clear();
 
442
        d->lv_selectedActions->clear();
 
443
 
 
444
        if ( !enable )
 
445
                return;
 
446
 
 
447
        noDirty = true;
 
448
 
 
449
        d->le_toolbarName->setText( tb.name );
 
450
        d->ck_toolbarOn->setChecked( tb.on );
 
451
        d->ck_toolbarLocked->setChecked( tb.locked || !moveable );
 
452
        d->ck_toolbarStretch->setChecked( tb.stretchable );
 
453
 
 
454
        {
 
455
                // Fill the ListView with toolbar-specific actions
 
456
                QPtrList<ActionList> actionLists = psi->actionList()->actionLists( p->class2id( p->toolbars[n].group ) );
 
457
                QPtrListIterator<ActionList> it ( actionLists );
 
458
                ActionList *actionList;
 
459
                QListView *lv = d->lv_availActions;
 
460
                QListViewItem *lastRoot = 0;
 
461
                for ( ; (actionList = it.current()); ++it ) {
 
462
                        QListViewItem *root = new QListViewItem(lv, lastRoot);
 
463
                        lastRoot = root;
 
464
                        root->setText( 0, actionList->name() );
 
465
                        root->setOpen( true );
 
466
 
 
467
                        QListViewItem *last = 0;
 
468
                        QStringList actionNames = actionList->actions();
 
469
                        QStringList::Iterator it2 = actionNames.begin();
 
470
                        for ( ; it2 != actionNames.end(); ++it2 ) {
 
471
                                IconAction *action = actionList->action( *it2 );
 
472
                                QListViewItem *item = new QListViewItem( root, last );
 
473
                                last = item;
 
474
 
 
475
                                QString n = actionName((QAction *)action);
 
476
                                if ( !action->whatsThis().isEmpty() )
 
477
                                        n += " - " + action->whatsThis();
 
478
                                item->setText(0, n);
 
479
                                item->setText(1, action->name());
 
480
                                item->setPixmap(0, action->iconSet().pixmap());
 
481
                        }
 
482
                }
 
483
        }
 
484
 
 
485
        QStringList::Iterator it = tb.keys.begin();
 
486
        for ( ; it != tb.keys.end(); ++it) {
 
487
                addToolbarAction(d->lv_selectedActions, *it, p->class2id( p->toolbars[n].group ) );
 
488
        }
 
489
        updateArrows();
 
490
 
 
491
        noDirty = false;
 
492
}
 
493
 
 
494
void ToolbarDlg::rebuildToolbarKeys()
 
495
{
 
496
        LookFeelToolbarsUI *d = (LookFeelToolbarsUI *)w;
 
497
        if ( !d->cb_toolbars->count() )
 
498
                return;
 
499
        int n = d->cb_toolbars->currentItem();
 
500
 
 
501
        QStringList keys;
 
502
        QListViewItemIterator it( d->lv_selectedActions );
 
503
        for ( ; it.current(); ++it) {
 
504
                QListViewItem *item = it.current();
 
505
 
 
506
                keys << item->text(1);
 
507
        }
 
508
 
 
509
        opt->toolbars["mainWin"][n].keys  = keys;
 
510
        opt->toolbars["mainWin"][n].dirty = true;
 
511
        emit dataChanged();
 
512
}
 
513
 
 
514
void ToolbarDlg::updateArrows()
 
515
{
 
516
        LookFeelToolbarsUI *d = (LookFeelToolbarsUI *)w;
 
517
        bool up = false, down = false, left = false, right = false;
 
518
 
 
519
        if(d->lv_availActions->selectedItem() && !d->lv_availActions->selectedItem()->text(1).isEmpty())
 
520
                right = true;
 
521
        QListViewItem *i = d->lv_selectedActions->selectedItem();
 
522
        if(i) {
 
523
                left = true;
 
524
 
 
525
                // get numeric index of item
 
526
                int n = 0;
 
527
                for(QListViewItem *it = d->lv_selectedActions->firstChild(); it != i; it = it->nextSibling()) {
 
528
                        ++n;
 
529
                }
 
530
 
 
531
                if(n > 0)
 
532
                        up = true;
 
533
                if(n < d->lv_selectedActions->childCount()-1)
 
534
                        down = true;
 
535
        }
 
536
 
 
537
        d->tb_up->setEnabled(up);
 
538
        d->tb_down->setEnabled(down);
 
539
        d->tb_left->setEnabled(left);
 
540
        d->tb_right->setEnabled(right);
 
541
}
 
542
 
 
543
void ToolbarDlg::toolbarNameChanged()
 
544
{
 
545
        LookFeelToolbarsUI *d = (LookFeelToolbarsUI *)w;
 
546
        if ( !d->cb_toolbars->count() )
 
547
                return;
 
548
 
 
549
        int n = d->cb_toolbars->currentItem();
 
550
        d->cb_toolbars->changeItem(d->le_toolbarName->text(), n);
 
551
        opt->toolbars["mainWin"][n].name = d->le_toolbarName->text();
 
552
 
 
553
        emit dataChanged();
 
554
}
 
555
 
 
556
void ToolbarDlg::toolbarActionUp()
 
557
{
 
558
        LookFeelToolbarsUI *d = (LookFeelToolbarsUI *)w;
 
559
        QListViewItem *item = d->lv_selectedActions->selectedItem();
 
560
        if ( !item )
 
561
                return;
 
562
 
 
563
        if ( item->itemAbove() )
 
564
                item->itemAbove()->moveItem(item);
 
565
        rebuildToolbarKeys();
 
566
        updateArrows();
 
567
}
 
568
 
 
569
void ToolbarDlg::toolbarActionDown()
 
570
{
 
571
        LookFeelToolbarsUI *d = (LookFeelToolbarsUI *)w;
 
572
        QListViewItem *item = d->lv_selectedActions->selectedItem();
 
573
        if ( !item )
 
574
                return;
 
575
 
 
576
        if ( item->itemBelow() )
 
577
                item->moveItem( item->itemBelow() );
 
578
        rebuildToolbarKeys();
 
579
        updateArrows();
 
580
}
 
581
 
 
582
void ToolbarDlg::toolbarAddAction()
 
583
{
 
584
        LookFeelToolbarsUI *d = (LookFeelToolbarsUI *)w;
 
585
        QListViewItem *item = d->lv_availActions->selectedItem();
 
586
        if ( !item || item->text(1).isEmpty() )
 
587
                return;
 
588
 
 
589
        addToolbarAction(d->lv_selectedActions, item->text(1), p->class2id( p->toolbars[d->cb_toolbars->currentItem()].group ) );
 
590
        rebuildToolbarKeys();
 
591
        updateArrows();
 
592
}
 
593
 
 
594
void ToolbarDlg::toolbarRemoveAction()
 
595
{
 
596
        LookFeelToolbarsUI *d = (LookFeelToolbarsUI *)w;
 
597
        QListViewItem *item = d->lv_selectedActions->selectedItem();
 
598
        if ( !item )
 
599
                return;
 
600
 
 
601
        delete item;
 
602
 
 
603
        if(d->lv_selectedActions->currentItem())
 
604
                d->lv_selectedActions->setSelected(d->lv_selectedActions->currentItem(), true);
 
605
 
 
606
        rebuildToolbarKeys();
 
607
        updateArrows();
 
608
}
 
609
 
 
610
void ToolbarDlg::toolbarDataChanged()
 
611
{
 
612
        if ( noDirty )
 
613
                return;
 
614
 
 
615
        LookFeelToolbarsUI *d = (LookFeelToolbarsUI *)w;
 
616
        if ( !d->cb_toolbars->count() )
 
617
                return;
 
618
        int n = d->cb_toolbars->currentItem();
 
619
 
 
620
        opt->toolbars["mainWin"][n].dirty = true;
 
621
        opt->toolbars["mainWin"][n].name = d->le_toolbarName->text();
 
622
        opt->toolbars["mainWin"][n].on = d->ck_toolbarOn->isChecked();
 
623
        opt->toolbars["mainWin"][n].locked = d->ck_toolbarLocked->isChecked();
 
624
        opt->toolbars["mainWin"][n].stretchable = d->ck_toolbarStretch->isChecked();
 
625
 
 
626
        emit dataChanged();
 
627
}
 
628
 
 
629
QString ToolbarDlg::actionName(const QAction *a)
 
630
{
 
631
        QString n = a->menuText(), n2;
 
632
        for (int i = 0; i < (int)n.length(); i++) {
 
633
                if ( n[i] == '&' && n[i+1] != '&' )
 
634
                        continue;
 
635
                else if ( n[i] == '&' && n[i+1] == '&' )
 
636
                        n2 += '&';
 
637
                else
 
638
                        n2 += n[i];
 
639
        }
 
640
 
 
641
        return n2;
 
642
}
 
643
 
 
644
void ToolbarDlg::toolbarPosition()
 
645
{
 
646
        LookFeelToolbarsUI *d = (LookFeelToolbarsUI *)w;
 
647
        if ( !d->cb_toolbars->count() )
 
648
                return;
 
649
        int n = d->cb_toolbars->currentItem();
 
650
 
 
651
        PositionToolbarDlg *posTbDlg = new PositionToolbarDlg(this, &opt->toolbars["mainWin"][n], n);
 
652
        connect(posTbDlg, SIGNAL(applyPressed()), SLOT(toolbarPositionApply()));
 
653
 
 
654
        posTbDlg->exec();
 
655
        delete posTbDlg;
 
656
}
 
657
 
 
658
void ToolbarDlg::toolbarPositionApply()
 
659
{
 
660
        emit dataChanged();
 
661
 
 
662
        option.toolbars = opt->toolbars;
 
663
        MainWin *mainWin = (MainWin *)psi->mainWin();
 
664
        mainWin->buildToolbars();
 
665
}
 
666
 
 
667
void ToolbarDlg::doApply()
 
668
{
 
669
        int count = 0;
 
670
        QValueList<Options::ToolbarPrefs>::Iterator it = opt->toolbars["mainWin"].begin();
 
671
        for ( ; it != opt->toolbars["mainWin"].end(); ++it) {
 
672
                if ( (*it).on )
 
673
                        count++;
 
674
        }
 
675
 
 
676
        // Undar MacOS, we have the toolbar in a menu anyway
 
677
#ifndef Q_WS_MAC
 
678
        if ( !count ) {
 
679
                QMessageBox::warning(this, tr("Warning"),
 
680
                                     tr("You can not disable <i>all</i> toolbars. If you do so, you will be unable to enable them back, when you'll change your mind.\n"
 
681
                                        "<br><br>\n"
 
682
                                        "If you really-really want to disable all toolbars, you need to edit the config.xml file by hand."),
 
683
                                     tr("I understand"));
 
684
                return;
 
685
        }
 
686
#endif
 
687
 
 
688
        applyOptions(opt);
 
689
        option.toolbars = opt->toolbars;
 
690
        MainWin *mainWin = (MainWin *)psi->mainWin();
 
691
        mainWin->buildToolbars();
 
692
 
 
693
        if ( pb_apply )
 
694
                pb_apply->setEnabled(false);
 
695
}
 
696
 
 
697
void ToolbarDlg::dataChangedSlot()
 
698
{
 
699
        if ( noDirty )
 
700
                return;
 
701
 
 
702
        if ( pb_apply )
 
703
                pb_apply->setEnabled(true);
 
704
}
 
705
 
 
706
void ToolbarDlg::selAct_selectionChanged(QListViewItem *)
 
707
{
 
708
        updateArrows();
 
709
}
 
710
 
 
711
void ToolbarDlg::avaAct_selectionChanged(QListViewItem *)
 
712
{
 
713
        updateArrows();
 
714
}
 
715
 
 
716
#include "toolbardlg.moc"