292
bool PopupAction::addTo (QWidget *w)
312
bool PopupAction::addTo(QWidget *w)
294
if ( w->inherits("QToolBar") || w->inherits("Q3ToolBar") ) {
295
QByteArray bname((const char*) (QString(name()) + QString("_action_button")));
296
PopupActionButton *btn = new PopupActionButton ( (Q3ToolBar*)w, bname );
297
d->buttons.append ( btn );
298
btn->setMenu ( menu() );
299
btn->setLabel ( text() );
300
btn->setIcon ( d->icon, d->showText );
301
btn->setSizePolicy ( d->size );
302
btn->setEnabled ( isEnabled() );
314
QToolBar* toolbar = dynamic_cast<QToolBar*>(w);
316
QByteArray bname((const char*)(QString(name()) + QString("_action_button")));
317
PopupActionButton *btn = new PopupActionButton(w, bname);
318
d->buttons.append(btn);
319
btn->setMenu(menu());
320
btn->setLabel(text());
321
btn->setIcon(d->icon, d->showText);
322
btn->setSizePolicy(d->size);
323
btn->setEnabled(isEnabled());
324
toolbar->addWidget(btn);
304
connect( btn, SIGNAL( destroyed() ), SLOT( objectDestroyed() ) );
326
connect(btn, SIGNAL(destroyed()), SLOT(objectDestroyed()));
307
329
return IconAction::addTo(w);
376
399
//----------------------------------------------------------------------------
378
class MAction::Private : public QObject
385
Private (int _id, PsiCon *_psi, QObject *parent)
390
sm = new QSignalMapper(this, "MAction::Private::SignalMapper");
393
QMenu *subMenu(QWidget *p)
395
QMenu *pm = new QMenu (p);
397
foreach(PsiAccount* acc, psi->contactList()->enabledAccounts()) {
398
pm->insertItem( acc->name(), parent(), SLOT(itemActivated(int)), 0, id*1000 + i );
399
pm->setItemParameter ( id*1000 + i, i );
405
void updateToolButton(QToolButton *btn)
407
if (psi->contactList()->enabledAccounts().count() >= 2) {
408
btn->setMenu(subMenu(btn));
409
disconnect(btn, SIGNAL(clicked()), sm, SLOT(map()));
413
// connect exactly once:
414
disconnect(btn, SIGNAL(clicked()), sm, SLOT(map()));
415
connect(btn, SIGNAL(clicked()), sm, SLOT(map()));
420
MAction::MAction(PsiIcon i, const QString &s, int id, PsiCon *psi, QObject *parent)
421
: IconAction(s, s, 0, parent)
426
MAction::MAction(const QString &s, int id, PsiCon *psi, QObject *parent)
427
: IconAction(s, s, 0, parent)
429
init (PsiIcon(), id, psi);
432
void MAction::init(PsiIcon i, int id, PsiCon *psi)
434
d = new Private(id, psi, this);
436
connect(psi, SIGNAL(accountCountChanged()), SLOT(numAccountsChanged()));
437
setEnabled ( d->psi->contactList()->haveEnabledAccounts() );
438
connect (d->sm, SIGNAL(mapped(int)), SLOT(itemActivated(int)));
441
bool MAction::addTo(QWidget *w)
443
if ( w->inherits("QPopupMenu") || w->inherits("QMenu") )
445
QMenu *menu = (QMenu*)w;
450
if ( d->psi->contactList()->enabledAccounts().count() < 2 ) {
451
menu->insertItem ( iconset, menuText(), this, SLOT(itemActivated(int)), 0, d->id*1000 + 0 );
452
menu->setItemEnabled (d->id*1000 + 0, isEnabled());
453
menu->setItemParameter ( d->id*1000 + 0, 0 );
456
menu->insertItem(iconset, menuText(), d->subMenu(w));
459
return IconAction::addTo(w);
401
MAction::MAction(PsiIcon i, const QString& s, int id, PsiCon* psi, QObject* parent)
402
: IconActionGroup(parent)
407
MAction::MAction(const QString& s, int id, PsiCon* psi, QObject* parent)
408
: IconActionGroup(parent)
410
init(s, PsiIcon(), id, psi);
413
void MAction::init(const QString& name, PsiIcon i, int id, PsiCon* psi)
422
connect(controller_, SIGNAL(accountCountChanged()), SLOT(numAccountsChanged()));
423
connect(this, SIGNAL(activated()), SLOT(slotActivated()));
424
numAccountsChanged();
427
bool MAction::addTo(QWidget* widget)
429
widget->addAction(this);
464
void MAction::addingToolButton(IconToolButton *btn)
466
d->sm->setMapping(btn, 0);
468
d->updateToolButton(btn);
471
void MAction::itemActivated(int n)
473
QList<PsiAccount*> list = d->psi->contactList()->enabledAccounts();
475
if (n >= list.count()) // just in case
478
emit activated((PsiAccount *)list.at(n), d->id);
433
QList<PsiAccount*> MAction::accounts() const
435
return controller_->contactList()->enabledAccounts();
438
void MAction::slotActivated()
440
if (accounts().count() > 0) {
441
emit activated(accounts().first(), id_);
445
void MAction::actionActivated()
447
QAction* action = static_cast<QAction*>(sender());
448
int num = action->property("id").toInt();
449
if (num >= 0 && num < accounts().count()) {
450
emit activated(accounts().at(num), id_);
481
454
void MAction::numAccountsChanged()
483
setEnabled( d->psi->contactList()->haveEnabledAccounts() );
485
QList<IconToolButton*> btns = buttonList();
486
for ( QList<IconToolButton*>::Iterator it = btns.begin(); it != btns.end(); ++it ) {
487
QToolButton *btn = (*it);
492
d->updateToolButton(btn);
456
setEnabled(accounts().count() > 0);
458
qDeleteAll(findChildren<QAction*>());
460
foreach(PsiAccount* account, accounts()) {
461
QAction* act = new QAction(account->name(), this);
462
act->setProperty("id", accounts().indexOf(account));
463
connect(act, SIGNAL(activated()), SLOT(actionActivated()));
496
467
IconAction *MAction::copy() const
498
MAction *act = new MAction(text(), d->id, d->psi, 0);
469
MAction *act = new MAction(text(), id_, controller_, 0);