~ubuntu-branches/ubuntu/vivid/psi/vivid

« back to all changes in this revision

Viewing changes to src/widgets/iconaction.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2008-08-28 18:46:52 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080828184652-iiik12dl91nq7cdi
Tags: 0.12-2
Uploading to unstable (Closes: Bug#494352)

Show diffs side-by-side

added added

removed removed

Lines of Context:
166
166
 
167
167
bool IconAction::addTo(QWidget *w)
168
168
{
 
169
        w->addAction(this);
 
170
        return true;
 
171
 
169
172
        QStringList supportedContainers;
170
173
        supportedContainers << "QWidget";
171
 
        if ( w->inherits("QToolBar") || w->inherits("Q3ToolBar") ||
172
 
             supportedContainers.contains(w->metaObject()->className()) ) {
 
174
        if (w->inherits("QToolBar") ||
 
175
            supportedContainers.contains(w->metaObject()->className()))
 
176
        {
173
177
                QString bname = objectName() + "_action_button";
174
 
                IconToolButton *btn = new IconToolButton ( w );
175
 
                btn->setObjectName( bname );
176
 
                d->buttons.append ( btn );
 
178
                IconToolButton *btn = new IconToolButton(w);
 
179
                btn->setObjectName(bname);
 
180
                d->buttons.append(btn);
177
181
 
178
182
                btn->setDefaultAction(this);
179
 
                
180
 
                btn->setText( text() );
181
 
                btn->setPsiIcon( d->icon, false );
 
183
 
 
184
                btn->setText(text());
 
185
                btn->setPsiIcon(d->icon, false);
182
186
 
183
187
                btn->setDefaultAction(this);
184
188
 
185
189
                // need to explicitly update popupMode,
186
190
                // because setDefaultAction resets it
187
 
                btn->setPopupMode( QToolButton::InstantPopup );
 
191
                btn->setPopupMode(QToolButton::InstantPopup);
188
192
 
189
193
                btn->setToolTip(toolTipFromMenuText());
190
194
 
191
195
                btn->setAutoRaise(true);
192
196
                btn->setFocusPolicy(Qt::NoFocus);
193
197
 
194
 
                if ( supportedContainers.contains(w->metaObject()->className()) )
195
 
                        if ( w->layout() )
196
 
                                w->layout()->addWidget( btn );
 
198
                if (supportedContainers.contains(w->metaObject()->className()))
 
199
                        if (w->layout())
 
200
                                w->layout()->addWidget(btn);
197
201
 
198
202
                connect(btn, SIGNAL(toggled(bool)), this, SLOT(setChecked(bool)));
199
203
                connect(btn, SIGNAL(destroyed()), SLOT(objectDestroyed()));
202
206
        }
203
207
        else
204
208
                w->addAction(this);
205
 
        
 
209
 
206
210
        return true;
207
211
}
208
212
 
267
271
 
268
272
void IconAction::setMenu( QMenu *p )
269
273
{
270
 
        QAction::setMenu( p );
271
 
 
272
 
        IconToolButton *btn;
273
 
        foreach ( btn, d->buttons ) {
274
 
                btn->setMenu (0);
275
 
 
276
 
                if ( menu() )
277
 
                        btn->setMenu ( menu() );
 
274
        doSetMenu(p);
 
275
}
 
276
 
 
277
void IconAction::doSetMenu(QMenu* p)
 
278
{
 
279
        QAction::setMenu(p);
 
280
 
 
281
        IconToolButton* btn;
 
282
        foreach(btn, d->buttons) {
 
283
                btn->setMenu(0);
 
284
 
 
285
                if (menu())
 
286
                        btn->setMenu(menu());
278
287
        }
279
288
}
280
289
 
352
361
 
353
362
void IconActionGroup::Private::updatePopup()
354
363
{
355
 
        if ( !dirty )
 
364
        if (!dirty)
356
365
                return;
357
366
 
358
 
        if ( !usesDropDown )
 
367
        if (!usesDropDown)
359
368
                qWarning("IconActionGroup does not support !usesDropDown yet");
360
369
 
361
370
        popup->clear();
362
371
 
363
372
        QList<QAction *> list = group->findChildren<QAction *>();
364
 
        foreach ( QAction *action, list ) {
365
 
                if ( !group->psiIcon() && action->inherits( "IconAction" ) )
366
 
                        group->setIcon( ((IconAction * )action)->icon() );
 
373
        foreach(QAction *action, list) {
 
374
                if (!group->psiIcon() && action->inherits("IconAction"))
 
375
                        group->setIcon(((IconAction *)action)->icon());
367
376
 
368
377
                popup->addAction(action);
369
378
        }
370
379
 
371
 
        group->setMenu( popup );
 
380
        group->setMenu(popup);
372
381
        dirty = false;
373
382
}
374
383
 
377
386
{
378
387
        d = new Private(this);
379
388
        d->popup = new QMenu();
 
389
        d->dirty = true;
 
390
        setUsesDropDown(true);
 
391
        d->updatePopup();
380
392
 
381
393
        d->exclusive = exclusive;
382
394
}
390
402
void IconActionGroup::childEvent(QChildEvent *e)
391
403
{
392
404
        IconAction::childEvent(e);
393
 
        
 
405
 
394
406
        d->dirty = true;
395
407
        QTimer::singleShot( 0, d, SLOT( updatePopup() ) );
396
408
}
420
432
                return true;
421
433
        }
422
434
 
423
 
        return IconAction::addTo( w );
 
435
        w->addAction(this);
 
436
        return true;
424
437
}
425
438
 
426
439
IconAction *IconActionGroup::copy() const