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 | connect(pb_ok, SIGNAL(clicked()), SLOT(doApply()));
|
---|
229 | connect(pb_ok, SIGNAL(clicked()), SLOT(accept()));
|
---|
230 |
|
---|
231 | //pb_apply = 0;
|
---|
232 | pb_apply = new IconButton( this );
|
---|
233 | hbox->addWidget( pb_apply );
|
---|
234 | pb_apply->setText( tr("&Apply") );
|
---|
235 | connect(pb_apply, SIGNAL(clicked()), SLOT(doApply()));
|
---|
236 | pb_apply->setEnabled(false);
|
---|
237 |
|
---|
238 | IconButton *pb_cancel = new IconButton( this );
|
---|
239 | hbox->addWidget( pb_cancel );
|
---|
240 | pb_cancel->setText( tr("&Cancel") );
|
---|
241 | connect(pb_cancel, SIGNAL(clicked()), SLOT(reject()));
|
---|
242 |
|
---|
243 | restoreOptions( &option );
|
---|
244 | resize( minimumSize() );
|
---|
245 | }
|
---|
246 |
|
---|
247 | ToolbarDlg::~ToolbarDlg()
|
---|
248 | {
|
---|
249 | psi->dialogUnregister(this);
|
---|
250 | delete opt;
|
---|
251 | delete p;
|
---|
252 | }
|
---|
253 |
|
---|
254 | void ToolbarDlg::setCurrentToolbar(PsiToolBar *t)
|
---|
255 | {
|
---|
256 | LookFeelToolbarsUI *d = (LookFeelToolbarsUI *)w;
|
---|
257 |
|
---|
258 | if ( pb_apply->isEnabled() )
|
---|
259 | return;
|
---|
260 |
|
---|
261 | QMap<int, Private::ToolbarItem>::Iterator it = p->toolbars.begin();
|
---|
262 | for ( ; it != p->toolbars.end(); ++it ) {
|
---|
263 | if ( it.data().group == t->group() && it.data().index == t->groupIndex() ) {
|
---|
264 | d->cb_toolbars->setCurrentItem( it.key() );
|
---|
265 | toolbarSelectionChanged( it.key() );
|
---|
266 | break;
|
---|
267 | }
|
---|
268 | }
|
---|
269 | }
|
---|
270 |
|
---|
271 | void ToolbarDlg::applyOptions(Options *o)
|
---|
272 | {
|
---|
273 | if ( !w )
|
---|
274 | opt->toolbars = o->toolbars;
|
---|
275 |
|
---|
276 | // get current toolbars' positions
|
---|
277 | MainWin *mainWin = (MainWin *)psi->mainWin();
|
---|
278 | for (uint i = 0; i < opt->toolbars.count() && i < mainWin->toolbars.count(); i++) {
|
---|
279 | //if ( toolbarPositionInProgress && posTbDlg->n() == (int)i )
|
---|
280 | // continue;
|
---|
281 |
|
---|
282 | Options::ToolbarPrefs &tbPref = opt->toolbars["mainWin"][i];
|
---|
283 | mainWin->getLocation ( mainWin->toolbars.at(i), tbPref.dock, tbPref.index, tbPref.nl, tbPref.extraOffset );
|
---|
284 | }
|
---|
285 |
|
---|
286 | // apply options
|
---|
287 | o->toolbars = opt->toolbars;
|
---|
288 | }
|
---|
289 |
|
---|
290 | void ToolbarDlg::rebuildToolbarList()
|
---|
291 | {
|
---|
292 | LookFeelToolbarsUI *d = (LookFeelToolbarsUI *)w;
|
---|
293 |
|
---|
294 | d->cb_toolbars->clear();
|
---|
295 | p->toolbars.clear();
|
---|
296 |
|
---|
297 | QMap< QString, QValueList<Options::ToolbarPrefs> >::Iterator it = opt->toolbars.begin();
|
---|
298 | for ( ; it != opt->toolbars.end(); ++it ) {
|
---|
299 | if ( p->toolbars.count() )
|
---|
300 | d->cb_toolbars->insertItem( "---" ); // TODO: think of better separator
|
---|
301 |
|
---|
302 | int i = 0;
|
---|
303 | QValueList<Options::ToolbarPrefs>::Iterator it2 = it.data().begin();
|
---|
304 | for ( ; it2 != it.data().end(); ++it2, ++i ) {
|
---|
305 | d->cb_toolbars->insertItem( (*it2).name );
|
---|
306 | p->toolbars[d->cb_toolbars->count()-1] = Private::ToolbarItem( it.key(), i );
|
---|
307 | }
|
---|
308 | }
|
---|
309 | }
|
---|
310 |
|
---|
311 | void ToolbarDlg::restoreOptions(const Options *o)
|
---|
312 | {
|
---|
313 | if ( !w )
|
---|
314 | return;
|
---|
315 |
|
---|
316 | LookFeelToolbarsUI *d = (LookFeelToolbarsUI *)w;
|
---|
317 | opt->toolbars = o->toolbars;
|
---|
318 | opt->hideMenubar = o->hideMenubar;
|
---|
319 |
|
---|
320 | rebuildToolbarList();
|
---|
321 |
|
---|
322 | if(d->cb_toolbars->count() > 0) {
|
---|
323 | d->cb_toolbars->setCurrentItem( 0 );
|
---|
324 | toolbarSelectionChanged( 0 );
|
---|
325 | }
|
---|
326 | else
|
---|
327 | toolbarSelectionChanged( -1 );
|
---|
328 | }
|
---|
329 |
|
---|
330 | //----------------------------------------------------------------------------
|
---|
331 |
|
---|
332 | void ToolbarDlg::toolbarAdd()
|
---|
333 | {
|
---|
334 | LookFeelToolbarsUI *d = (LookFeelToolbarsUI *)w;
|
---|
335 |
|
---|
336 | int i = d->cb_toolbars->count();
|
---|
337 |
|
---|
338 | Options::ToolbarPrefs tb;
|
---|
339 | tb.name = QObject::tr("<unnamed>");
|
---|
340 | tb.on = false;
|
---|
341 | tb.locked = false;
|
---|
342 | tb.stretchable = false;
|
---|
343 | tb.keys.clear();
|
---|
344 |
|
---|
345 | tb.dock = Qt::DockTop;
|
---|
346 | tb.index = i;
|
---|
347 | tb.nl = true;
|
---|
348 | tb.extraOffset = 0;
|
---|
349 |
|
---|
350 | tb.dirty = true;
|
---|
351 |
|
---|
352 | opt->toolbars["mainWin"].append(tb);
|
---|
353 |
|
---|
354 | rebuildToolbarList();
|
---|
355 | /* TODO
|
---|
356 | d->cb_toolbars->insertItem( tb.name );
|
---|
357 | d->cb_toolbars->setCurrentItem( d->cb_toolbars->count() - 1 );
|
---|
358 | toolbarSelectionChanged( d->cb_toolbars->count() - 1 );
|
---|
359 |
|
---|
360 | d->le_toolbarName->setFocus();
|
---|
361 | */
|
---|
362 | }
|
---|
363 |
|
---|
364 | void ToolbarDlg::toolbarDelete()
|
---|
365 | {
|
---|
366 | LookFeelToolbarsUI *d = (LookFeelToolbarsUI *)w;
|
---|
367 | int n = d->cb_toolbars->currentItem();
|
---|
368 |
|
---|
369 | Options::ToolbarPrefs tb = opt->toolbars[p->toolbars[n].group][p->toolbars[n].index];
|
---|
370 | PsiToolBar *toolBar = psi->findToolBar( p->toolbars[n].group, p->toolbars[n].index );
|
---|
371 | if ( !toolBar )
|
---|
372 | return;
|
---|
373 |
|
---|
374 | // delete current toolbar
|
---|
375 | {
|
---|
376 | int idx = p->toolbars[n].index;
|
---|
377 | QValueList<Options::ToolbarPrefs>::Iterator it = opt->toolbars[p->toolbars[n].group].begin();
|
---|
378 | for (int i = 0; i < idx; i++)
|
---|
379 | ++it;
|
---|
380 |
|
---|
381 | noDirty = true;
|
---|
382 | opt->toolbars[p->toolbars[n].group].remove(it);
|
---|
383 |
|
---|
384 | rebuildToolbarList();
|
---|
385 | noDirty = false;
|
---|
386 | toolbarSelectionChanged( n - 1 ); // TODO FIXME
|
---|
387 | }
|
---|
388 | }
|
---|
389 |
|
---|
390 | void ToolbarDlg::addToolbarAction(QListView *parent, QString name, int toolbarId)
|
---|
391 | {
|
---|
392 | ActionList actions = psi->actionList()->suitableActions( (PsiActionList::ActionsType)toolbarId );
|
---|
393 | const QAction *action = (QAction *)actions.action( name );
|
---|
394 | if ( !action )
|
---|
395 | return;
|
---|
396 |
|
---|
397 | addToolbarAction(parent, action, name);
|
---|
398 | }
|
---|
399 |
|
---|
400 | void ToolbarDlg::addToolbarAction(QListView *parent, const QAction *action, QString name)
|
---|
401 | {
|
---|
402 | QListViewItem *item = new QListViewItem(parent, parent->lastItem());
|
---|
403 |
|
---|
404 | QString n = actionName(action);
|
---|
405 | if ( !action->whatsThis().isEmpty() )
|
---|
406 | n += " - " + action->whatsThis();
|
---|
407 | item->setText(0, n);
|
---|
408 | item->setText(1, name);
|
---|
409 | item->setPixmap(0, action->iconSet().pixmap());
|
---|
410 | }
|
---|
411 |
|
---|
412 | void ToolbarDlg::toolbarSelectionChanged(int item)
|
---|
413 | {
|
---|
414 | if ( noDirty )
|
---|
415 | return;
|
---|
416 |
|
---|
417 | int n = item;
|
---|
418 | Options::ToolbarPrefs tb = opt->toolbars[p->toolbars[n].group][p->toolbars[n].index];
|
---|
419 | PsiToolBar *toolBar = psi->findToolBar( p->toolbars[n].group, p->toolbars[n].index );
|
---|
420 |
|
---|
421 | bool customizeable = toolBar ? toolBar->isCustomizeable() : false;
|
---|
422 | bool moveable = toolBar ? toolBar->isMoveable() : false;
|
---|
423 |
|
---|
424 | LookFeelToolbarsUI *d = (LookFeelToolbarsUI *)w;
|
---|
425 | bool enable = (item == -1) ? false: true;
|
---|
426 | d->le_toolbarName->setEnabled( enable );
|
---|
427 | d->pb_toolbarPosition->setEnabled( enable && moveable );
|
---|
428 | d->ck_toolbarOn->setEnabled( enable );
|
---|
429 | d->ck_toolbarLocked->setEnabled( enable && moveable );
|
---|
430 | d->ck_toolbarStretch->setEnabled( enable && moveable );
|
---|
431 | d->lv_selectedActions->setEnabled( enable && customizeable );
|
---|
432 | d->lv_availActions->setEnabled( enable && customizeable );
|
---|
433 | d->tb_up->setEnabled( enable && customizeable );
|
---|
434 | d->tb_down->setEnabled( enable && customizeable );
|
---|
435 | d->tb_left->setEnabled( enable && customizeable );
|
---|
436 | d->tb_right->setEnabled( enable && customizeable );
|
---|
437 | d->pb_deleteToolbar->setEnabled( enable && p->toolbars[n].group == "mainWin" );
|
---|
438 | d->cb_toolbars->setEnabled( enable );
|
---|
439 |
|
---|
440 | d->lv_availActions->clear();
|
---|
441 | d->lv_selectedActions->clear();
|
---|
442 |
|
---|
443 | if ( !enable )
|
---|
444 | return;
|
---|
445 |
|
---|
446 | noDirty = true;
|
---|
447 |
|
---|
448 | d->le_toolbarName->setText( tb.name );
|
---|
449 | d->ck_toolbarOn->setChecked( tb.on );
|
---|
450 | d->ck_toolbarLocked->setChecked( tb.locked || !moveable );
|
---|
451 | d->ck_toolbarStretch->setChecked( tb.stretchable );
|
---|
452 |
|
---|
453 | {
|
---|
454 | // Fill the ListView with toolbar-specific actions
|
---|
455 | QPtrList<ActionList> actionLists = psi->actionList()->actionLists( p->class2id( p->toolbars[n].group ) );
|
---|
456 | QPtrListIterator<ActionList> it ( actionLists );
|
---|
457 | ActionList *actionList;
|
---|
458 | QListView *lv = d->lv_availActions;
|
---|
459 | QListViewItem *lastRoot = 0;
|
---|
460 | for ( ; (actionList = it.current()); ++it ) {
|
---|
461 | QListViewItem *root = new QListViewItem(lv, lastRoot);
|
---|
462 | lastRoot = root;
|
---|
463 | root->setText( 0, actionList->name() );
|
---|
464 | root->setOpen( true );
|
---|
465 |
|
---|
466 | QListViewItem *last = 0;
|
---|
467 | QStringList actionNames = actionList->actions();
|
---|
468 | QStringList::Iterator it2 = actionNames.begin();
|
---|
469 | for ( ; it2 != actionNames.end(); ++it2 ) {
|
---|
470 | IconAction *action = actionList->action( *it2 );
|
---|
471 | QListViewItem *item = new QListViewItem( root, last );
|
---|
472 | last = item;
|
---|
473 |
|
---|
474 | QString n = actionName((QAction *)action);
|
---|
475 | if ( !action->whatsThis().isEmpty() )
|
---|
476 | n += " - " + action->whatsThis();
|
---|
477 | item->setText(0, n);
|
---|
478 | item->setText(1, action->name());
|
---|
479 | item->setPixmap(0, action->iconSet().pixmap());
|
---|
480 | }
|
---|
481 | }
|
---|
482 | }
|
---|
483 |
|
---|
484 | QStringList::Iterator it = tb.keys.begin();
|
---|
485 | for ( ; it != tb.keys.end(); ++it) {
|
---|
486 | addToolbarAction(d->lv_selectedActions, *it, p->class2id( p->toolbars[n].group ) );
|
---|
487 | }
|
---|
488 | updateArrows();
|
---|
489 |
|
---|
490 | noDirty = false;
|
---|
491 | }
|
---|
492 |
|
---|
493 | void ToolbarDlg::rebuildToolbarKeys()
|
---|
494 | {
|
---|
495 | LookFeelToolbarsUI *d = (LookFeelToolbarsUI *)w;
|
---|
496 | if ( !d->cb_toolbars->count() )
|
---|
497 | return;
|
---|
498 | int n = d->cb_toolbars->currentItem();
|
---|
499 |
|
---|
500 | QStringList keys;
|
---|
501 | QListViewItemIterator it( d->lv_selectedActions );
|
---|
502 | for ( ; it.current(); ++it) {
|
---|
503 | QListViewItem *item = it.current();
|
---|
504 |
|
---|
505 | keys << item->text(1);
|
---|
506 | }
|
---|
507 |
|
---|
508 | opt->toolbars["mainWin"][n].keys = keys;
|
---|
509 | opt->toolbars["mainWin"][n].dirty = true;
|
---|
510 | emit dataChanged();
|
---|
511 | }
|
---|
512 |
|
---|
513 | void ToolbarDlg::updateArrows()
|
---|
514 | {
|
---|
515 | LookFeelToolbarsUI *d = (LookFeelToolbarsUI *)w;
|
---|
516 | bool up = false, down = false, left = false, right = false;
|
---|
517 |
|
---|
518 | if(d->lv_availActions->selectedItem() && !d->lv_availActions->selectedItem()->text(1).isEmpty())
|
---|
519 | right = true;
|
---|
520 | QListViewItem *i = d->lv_selectedActions->selectedItem();
|
---|
521 | if(i) {
|
---|
522 | left = true;
|
---|
523 |
|
---|
524 | // get numeric index of item
|
---|
525 | int n = 0;
|
---|
526 | for(QListViewItem *it = d->lv_selectedActions->firstChild(); it != i; it = it->nextSibling()) {
|
---|
527 | ++n;
|
---|
528 | }
|
---|
529 |
|
---|
530 | if(n > 0)
|
---|
531 | up = true;
|
---|
532 | if(n < d->lv_selectedActions->childCount()-1)
|
---|
533 | down = true;
|
---|
534 | }
|
---|
535 |
|
---|
536 | d->tb_up->setEnabled(up);
|
---|
537 | d->tb_down->setEnabled(down);
|
---|
538 | d->tb_left->setEnabled(left);
|
---|
539 | d->tb_right->setEnabled(right);
|
---|
540 | }
|
---|
541 |
|
---|
542 | void ToolbarDlg::toolbarNameChanged()
|
---|
543 | {
|
---|
544 | LookFeelToolbarsUI *d = (LookFeelToolbarsUI *)w;
|
---|
545 | if ( !d->cb_toolbars->count() )
|
---|
546 | return;
|
---|
547 |
|
---|
548 | int n = d->cb_toolbars->currentItem();
|
---|
549 | d->cb_toolbars->changeItem(d->le_toolbarName->text(), n);
|
---|
550 | opt->toolbars["mainWin"][n].name = d->le_toolbarName->text();
|
---|
551 |
|
---|
552 | emit dataChanged();
|
---|
553 | }
|
---|
554 |
|
---|
555 | void ToolbarDlg::toolbarActionUp()
|
---|
556 | {
|
---|
557 | LookFeelToolbarsUI *d = (LookFeelToolbarsUI *)w;
|
---|
558 | QListViewItem *item = d->lv_selectedActions->selectedItem();
|
---|
559 | if ( !item )
|
---|
560 | return;
|
---|
561 |
|
---|
562 | if ( item->itemAbove() )
|
---|
563 | item->itemAbove()->moveItem(item);
|
---|
564 | rebuildToolbarKeys();
|
---|
565 | updateArrows();
|
---|
566 | }
|
---|
567 |
|
---|
568 | void ToolbarDlg::toolbarActionDown()
|
---|
569 | {
|
---|
570 | LookFeelToolbarsUI *d = (LookFeelToolbarsUI *)w;
|
---|
571 | QListViewItem *item = d->lv_selectedActions->selectedItem();
|
---|
572 | if ( !item )
|
---|
573 | return;
|
---|
574 |
|
---|
575 | if ( item->itemBelow() )
|
---|
576 | item->moveItem( item->itemBelow() );
|
---|
577 | rebuildToolbarKeys();
|
---|
578 | updateArrows();
|
---|
579 | }
|
---|
580 |
|
---|
581 | void ToolbarDlg::toolbarAddAction()
|
---|
582 | {
|
---|
583 | LookFeelToolbarsUI *d = (LookFeelToolbarsUI *)w;
|
---|
584 | QListViewItem *item = d->lv_availActions->selectedItem();
|
---|
585 | if ( !item || item->text(1).isEmpty() )
|
---|
586 | return;
|
---|
587 |
|
---|
588 | addToolbarAction(d->lv_selectedActions, item->text(1), p->class2id( p->toolbars[d->cb_toolbars->currentItem()].group ) );
|
---|
589 | rebuildToolbarKeys();
|
---|
590 | updateArrows();
|
---|
591 | }
|
---|
592 |
|
---|
593 | void ToolbarDlg::toolbarRemoveAction()
|
---|
594 | {
|
---|
595 | LookFeelToolbarsUI *d = (LookFeelToolbarsUI *)w;
|
---|
596 | QListViewItem *item = d->lv_selectedActions->selectedItem();
|
---|
597 | if ( !item )
|
---|
598 | return;
|
---|
599 |
|
---|
600 | delete item;
|
---|
601 |
|
---|
602 | if(d->lv_selectedActions->currentItem())
|
---|
603 | d->lv_selectedActions->setSelected(d->lv_selectedActions->currentItem(), true);
|
---|
604 |
|
---|
605 | rebuildToolbarKeys();
|
---|
606 | updateArrows();
|
---|
607 | }
|
---|
608 |
|
---|
609 | void ToolbarDlg::toolbarDataChanged()
|
---|
610 | {
|
---|
611 | if ( noDirty )
|
---|
612 | return;
|
---|
613 |
|
---|
614 | LookFeelToolbarsUI *d = (LookFeelToolbarsUI *)w;
|
---|
615 | if ( !d->cb_toolbars->count() )
|
---|
616 | return;
|
---|
617 | int n = d->cb_toolbars->currentItem();
|
---|
618 |
|
---|
619 | opt->toolbars["mainWin"][n].dirty = true;
|
---|
620 | opt->toolbars["mainWin"][n].name = d->le_toolbarName->text();
|
---|
621 | opt->toolbars["mainWin"][n].on = d->ck_toolbarOn->isChecked();
|
---|
622 | opt->toolbars["mainWin"][n].locked = d->ck_toolbarLocked->isChecked();
|
---|
623 | opt->toolbars["mainWin"][n].stretchable = d->ck_toolbarStretch->isChecked();
|
---|
624 |
|
---|
625 | emit dataChanged();
|
---|
626 | }
|
---|
627 |
|
---|
628 | QString ToolbarDlg::actionName(const QAction *a)
|
---|
629 | {
|
---|
630 | QString n = a->menuText(), n2;
|
---|
631 | for (int i = 0; i < (int)n.length(); i++) {
|
---|
632 | if ( n[i] == '&' && n[i+1] != '&' )
|
---|
633 | continue;
|
---|
634 | else if ( n[i] == '&' && n[i+1] == '&' )
|
---|
635 | n2 += '&';
|
---|
636 | else
|
---|
637 | n2 += n[i];
|
---|
638 | }
|
---|
639 |
|
---|
640 | return n2;
|
---|
641 | }
|
---|
642 |
|
---|
643 | void ToolbarDlg::toolbarPosition()
|
---|
644 | {
|
---|
645 | LookFeelToolbarsUI *d = (LookFeelToolbarsUI *)w;
|
---|
646 | if ( !d->cb_toolbars->count() )
|
---|
647 | return;
|
---|
648 | int n = d->cb_toolbars->currentItem();
|
---|
649 |
|
---|
650 | PositionToolbarDlg *posTbDlg = new PositionToolbarDlg(this, &opt->toolbars["mainWin"][n], n);
|
---|
651 | connect(posTbDlg, SIGNAL(applyPressed()), SLOT(toolbarPositionApply()));
|
---|
652 |
|
---|
653 | posTbDlg->exec();
|
---|
654 | delete posTbDlg;
|
---|
655 | }
|
---|
656 |
|
---|
657 | void ToolbarDlg::toolbarPositionApply()
|
---|
658 | {
|
---|
659 | emit dataChanged();
|
---|
660 |
|
---|
661 | option.toolbars = opt->toolbars;
|
---|
662 | MainWin *mainWin = (MainWin *)psi->mainWin();
|
---|
663 | mainWin->buildToolbars();
|
---|
664 | }
|
---|
665 |
|
---|
666 | void ToolbarDlg::doApply()
|
---|
667 | {
|
---|
668 | // Check if all toolbars are disabled
|
---|
669 | bool toolbarsVisible = false;
|
---|
670 | QValueList<Options::ToolbarPrefs>::ConstIterator it = opt->toolbars["mainWin"].begin();
|
---|
671 | for ( ; it != opt->toolbars["mainWin"].end() && !toolbarsVisible; ++it) {
|
---|
672 | toolbarsVisible = toolbarsVisible || (*it).on;
|
---|
673 | }
|
---|
674 |
|
---|
675 | // Undar MacOS, we have the toolbar in a menu anyway
|
---|
676 | #ifndef Q_WS_MAC
|
---|
677 | if ( !toolbarsVisible && opt->hideMenubar) {
|
---|
678 | QMessageBox::warning(this, tr("Warning"),
|
---|
679 | tr("You can not disable <i>all</i> toolbars <i>and</i> the menubar. If you do so, you will be unable to enable them back, when you'll change your mind.\n"
|
---|
680 | "<br><br>\n"
|
---|
681 | "If you really-really want to disable all toolbars and the menubar, you need to edit the config.xml file by hand."),
|
---|
682 | tr("OK"));
|
---|
683 | return;
|
---|
684 | }
|
---|
685 | #endif
|
---|
686 |
|
---|
687 | applyOptions(opt);
|
---|
688 | option.toolbars = opt->toolbars;
|
---|
689 | MainWin *mainWin = (MainWin *)psi->mainWin();
|
---|
690 | mainWin->buildToolbars();
|
---|
691 |
|
---|
692 | if ( pb_apply )
|
---|
693 | pb_apply->setEnabled(false);
|
---|
694 | }
|
---|
695 |
|
---|
696 | void ToolbarDlg::dataChangedSlot()
|
---|
697 | {
|
---|
698 | if ( noDirty )
|
---|
699 | return;
|
---|
700 |
|
---|
701 | if ( pb_apply )
|
---|
702 | pb_apply->setEnabled(true);
|
---|
703 | }
|
---|
704 |
|
---|
705 | void ToolbarDlg::selAct_selectionChanged(QListViewItem *)
|
---|
706 | {
|
---|
707 | updateArrows();
|
---|
708 | }
|
---|
709 |
|
---|
710 | void ToolbarDlg::avaAct_selectionChanged(QListViewItem *)
|
---|
711 | {
|
---|
712 | updateArrows();
|
---|
713 | }
|
---|
714 |
|
---|
715 | #include "toolbardlg.moc"
|
---|