void tst_QToolBar::addWidget() { QToolBar tb; QWidget w(&tb); QAction action1(0); QAction action2(0); tb.addAction(&action1); QAction *widget = tb.addWidget(&w); tb.addAction(&action2); QCOMPARE(tb.actions().count(), 3); QCOMPARE(tb.actions()[0], &action1); QCOMPARE(tb.actions()[1], widget); QCOMPARE(tb.actions()[2], &action2); // it should be possible to reuse the action returned by // addWidget() to place the widget somewhere else in the toolbar tb.removeAction(widget); QCOMPARE(tb.actions().count(), 2); QCOMPARE(tb.actions()[0], &action1); QCOMPARE(tb.actions()[1], &action2); tb.addAction(widget); QCOMPARE(tb.actions().count(), 3); QCOMPARE(tb.actions()[0], &action1); QCOMPARE(tb.actions()[1], &action2); QCOMPARE(tb.actions()[2], widget); tb.clear(); QCOMPARE(tb.actions().count(), 0); }
void GLSLTextEditorWidget::createToolBar(GLSLEditorEditable *editable) { m_outlineCombo = new QComboBox; m_outlineCombo->setMinimumContentsLength(22); // ### m_outlineCombo->setModel(m_outlineModel); QTreeView *treeView = new QTreeView; treeView->header()->hide(); treeView->setItemsExpandable(false); treeView->setRootIsDecorated(false); m_outlineCombo->setView(treeView); treeView->expandAll(); //m_outlineCombo->setSizeAdjustPolicy(QComboBox::AdjustToContents); // Make the combo box prefer to expand QSizePolicy policy = m_outlineCombo->sizePolicy(); policy.setHorizontalPolicy(QSizePolicy::Expanding); m_outlineCombo->setSizePolicy(policy); QToolBar *toolBar = static_cast<QToolBar*>(editable->toolBar()); QList<QAction*> actions = toolBar->actions(); toolBar->insertWidget(actions.first(), m_outlineCombo); }
void specDockWidget::setupWindow(specActionLibrary* actions) { // prepare main widget QMainWindow* widget = new QMainWindow(this) ; widget->setWindowFlags(Qt::Widget); setWidget(widget) ; // // get brushes // QPalette pal = palette() ; // QBrush activeWindow = pal.brush(QPalette::Active, QPalette::Window), // inactiveWindow = pal.brush(QPalette::Inactive, QPalette::Window) ; // if (activeWindow == inactiveWindow) // inactiveWindow.setColor(inactiveWindow.color().darker()) ; // // pal.setBrush(QPalette::Inactive, QPalette::Window, inactiveWindow) ; // setPalette(pal) ; // add inner widgets QList<QWidget*> innerWidgets = mainWidgets() ; if(innerWidgets.size() == 1) widget->setCentralWidget(innerWidgets.first()) ; else { specSplitter* splitter = new specSplitter(Qt::Vertical, this) ; foreach(QWidget * innerWidget, innerWidgets) splitter->insertWidget(0, innerWidget); widget->setCentralWidget(splitter); } // add toolbars if(!actions) return ; QList<QWidget*> allWidgets ; allWidgets << this << innerWidgets ; foreach(QWidget * w, allWidgets) { specView* view = dynamic_cast<specView*>(w); specPlot* plot = dynamic_cast<specPlot*>(w) ; if(view && view->model()) { view->setActionLibrary(actions) ; actions->addDragDropPartner(view->model()); connect(view->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(selectionChanged(QItemSelection, QItemSelection))) ; // connect(view->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), // this, SLOT(currentChanged(QModelIndex,QModelIndex))) ; } if(plot) { Plot = plot ; actions->addPlot(plot) ; } QToolBar* toolbar = actions->toolBar(w) ; if(toolbar->actions().isEmpty()) delete toolbar ; else widget->addToolBar(toolbar); // w->setPalette(pal); }
void tst_QToolBar::insertSeparator() { QToolBar tb; QAction action1(0); QAction action2(0); tb.addAction(&action1); tb.addAction(&action2); QAction *sep = tb.insertSeparator(&action2); QCOMPARE(tb.actions().count(), 3); QCOMPARE(tb.actions()[0], &action1); QCOMPARE(tb.actions()[1], sep); QCOMPARE(tb.actions()[2], &action2); tb.clear(); QCOMPARE(tb.actions().count(), 0); }
void tst_QToolBar::insertWidget() { QToolBar tb; QWidget w(&tb); QAction action1(0); QAction action2(0); tb.addAction(&action1); tb.addAction(&action2); QAction *widget = tb.insertWidget(&action2, &w); QCOMPARE(tb.actions().count(), 3); QCOMPARE(tb.actions()[0], &action1); QCOMPARE(tb.actions()[1], widget); QCOMPARE(tb.actions()[2], &action2); // it should be possible to reuse the action returned by // addWidget() to place the widget somewhere else in the toolbar tb.removeAction(widget); QCOMPARE(tb.actions().count(), 2); QCOMPARE(tb.actions()[0], &action1); QCOMPARE(tb.actions()[1], &action2); tb.insertAction(&action1, widget); QCOMPARE(tb.actions().count(), 3); QCOMPARE(tb.actions()[0], widget); QCOMPARE(tb.actions()[1], &action1); QCOMPARE(tb.actions()[2], &action2); tb.clear(); QCOMPARE(tb.actions().count(), 0); { QToolBar tb; QPointer<QWidget> widget = new QWidget; QAction *action = tb.addWidget(widget); QVERIFY(action->parent() == &tb); QToolBar tb2; tb.removeAction(action); tb2.addAction(action); QVERIFY(widget && widget->parent() == &tb2); QVERIFY(action->parent() == &tb2); } }
void tst_QToolBar::insertAction() { QToolBar tb; QAction action1(0); QAction action2(0); QAction action3(0); QAction action4(0); QCOMPARE(tb.actions().count(), 0); tb.insertAction(0, &action1); tb.insertAction(&action1, &action2); tb.insertAction(&action2, &action3); tb.insertAction(&action3, &action4); QCOMPARE(tb.actions().count(), 4); QCOMPARE(tb.actions()[0], &action4); QCOMPARE(tb.actions()[1], &action3); QCOMPARE(tb.actions()[2], &action2); QCOMPARE(tb.actions()[3], &action1); tb.clear(); QCOMPARE(tb.actions().count(), 0); }
void tst_QToolBar::addAction() { QToolBar tb; { QAction action(0); QCOMPARE(tb.actions().count(), 0); tb.addAction(&action); QCOMPARE(tb.actions().count(), 1); QCOMPARE(tb.actions()[0], &action); tb.clear(); QCOMPARE(tb.actions().count(), 0); } { QString text = "text"; QPixmap pm(32, 32); pm.fill(Qt::blue); QIcon icon = pm; QAction *action1 = tb.addAction(text); QCOMPARE(text, action1->text()); QAction *action2 = tb.addAction(icon, text); QCOMPARE(icon, action2->icon()); QCOMPARE(text, action2->text()); QAction *action3 = tb.addAction(text, this, SLOT(slot())); QCOMPARE(text, action3->text()); QAction *action4 = tb.addAction(icon, text, this, SLOT(slot())); QCOMPARE(icon, action4->icon()); QCOMPARE(text, action4->text()); QCOMPARE(tb.actions().count(), 4); QCOMPARE(tb.actions()[0], action1); QCOMPARE(tb.actions()[1], action2); QCOMPARE(tb.actions()[2], action3); QCOMPARE(tb.actions()[3], action4); tb.clear(); QCOMPARE(tb.actions().count(), 0); } }