void tst_QToolBar::task197996_visibility() { QMainWindow mw; QToolBar *toolBar = new QToolBar(&mw); mw.addToolBar(toolBar); toolBar->addAction(new QAction("Foo", &mw)); QAction *pAction = new QAction("Test", &mw); toolBar->addAction(pAction); pAction->setVisible(false); toolBar->setVisible(false); toolBar->setVisible(true); pAction->setVisible(true); mw.show(); QVERIFY(toolBar->widgetForAction(pAction)->isVisible()); toolBar->setVisible(false); pAction->setVisible(false); toolBar->setVisible(true); pAction->setVisible(true); QTest::qWait(100); QVERIFY(toolBar->widgetForAction(pAction)->isVisible()); }
void TestGui::testAddEntry() { EntryView* entryView = m_dbWidget->findChild<EntryView*>("entryView"); QAction* entryNewAction = m_mainWindow->findChild<QAction*>("actionEntryNew"); QVERIFY(entryNewAction->isEnabled()); QToolBar* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar"); QWidget* entryNewWidget = toolBar->widgetForAction(entryNewAction); QVERIFY(entryNewWidget->isVisible()); QVERIFY(entryNewWidget->isEnabled()); QTest::mouseClick(entryNewWidget, Qt::LeftButton); QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::EditMode); EditEntryWidget* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget"); QLineEdit* titleEdit = editEntryWidget->findChild<QLineEdit*>("titleEdit"); QTest::keyClicks(titleEdit, "test"); QDialogButtonBox* editEntryWidgetButtonBox = editEntryWidget->findChild<QDialogButtonBox*>("buttonBox"); QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton); QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::ViewMode); QModelIndex item = entryView->model()->index(1, 1); Entry* entry = entryView->entryFromIndex(item); QCOMPARE(entry->title(), QString("test")); QCOMPARE(entry->historyItems().size(), 0); // wait for modified timer QTRY_COMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), QString("%1*").arg(m_orgDbFileName)); QAction* entryEditAction = m_mainWindow->findChild<QAction*>("actionEntryEdit"); QVERIFY(entryEditAction->isEnabled()); QWidget* entryEditWidget = toolBar->widgetForAction(entryEditAction); QVERIFY(entryEditWidget->isVisible()); QVERIFY(entryEditWidget->isEnabled()); QTest::mouseClick(entryEditWidget, Qt::LeftButton); QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::EditMode); QTest::keyClicks(titleEdit, "something"); QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton); QCOMPARE(entry->title(), QString("testsomething")); QCOMPARE(entry->historyItems().size(), 1); QTest::mouseClick(entryNewWidget, Qt::LeftButton); QTest::keyClicks(titleEdit, "something 2"); QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton); QTest::mouseClick(entryNewWidget, Qt::LeftButton); QTest::keyClicks(titleEdit, "something 3"); QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton); QTRY_COMPARE(entryView->model()->rowCount(), 4); }
void TestGui::testSearch() { QAction* searchAction = m_mainWindow->findChild<QAction*>("actionSearch"); QVERIFY(searchAction->isEnabled()); QToolBar* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar"); QWidget* searchActionWidget = toolBar->widgetForAction(searchAction); QVERIFY(searchActionWidget->isVisible()); QVERIFY(searchActionWidget->isEnabled()); QTest::mouseClick(searchActionWidget, Qt::LeftButton); EntryView* entryView = m_dbWidget->findChild<EntryView*>("entryView"); QLineEdit* searchEdit = m_dbWidget->findChild<QLineEdit*>("searchEdit"); QToolButton* clearSearch = m_dbWidget->findChild<QToolButton*>("clearButton"); QTest::keyClicks(searchEdit, "ZZZ"); QTRY_COMPARE(entryView->model()->rowCount(), 0); QTest::mouseClick(clearSearch, Qt::LeftButton); QTest::keyClicks(searchEdit, "some"); QTRY_COMPARE(entryView->model()->rowCount(), 2); QModelIndex item = entryView->model()->index(0, 1); QRect itemRect = entryView->visualRect(item); QTest::mouseClick(entryView->viewport(), Qt::LeftButton, Qt::NoModifier, itemRect.center()); QAction* entryEditAction = m_mainWindow->findChild<QAction*>("actionEntryEdit"); QVERIFY(entryEditAction->isEnabled()); QWidget* entryEditWidget = toolBar->widgetForAction(entryEditAction); QVERIFY(entryEditWidget->isVisible()); QVERIFY(entryEditWidget->isEnabled()); QTest::mouseClick(entryEditWidget, Qt::LeftButton); QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::EditMode); EditEntryWidget* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget"); QDialogButtonBox* editEntryWidgetButtonBox = editEntryWidget->findChild<QDialogButtonBox*>("buttonBox"); QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton); QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::ViewMode); QModelIndex item2 = entryView->model()->index(1, 0); QRect itemRect2 = entryView->visualRect(item2); QTest::mouseClick(entryView->viewport(), Qt::LeftButton, Qt::NoModifier, itemRect2.center()); QAction* entryDeleteAction = m_mainWindow->findChild<QAction*>("actionEntryDelete"); QWidget* entryDeleteWidget = toolBar->widgetForAction(entryDeleteAction); QVERIFY(entryDeleteWidget->isVisible()); QVERIFY(entryDeleteWidget->isEnabled()); QTest::mouseClick(entryDeleteWidget, Qt::LeftButton); QWidget* closeSearchButton = m_dbWidget->findChild<QToolButton*>("closeSearchButton"); QTest::mouseClick(closeSearchButton, Qt::LeftButton); QCOMPARE(entryView->model()->rowCount(), 1); }
void KSelectAction_UnitTest::testRequestWidgetMenuModeWidgetParentSeveralActions() { KSelectAction selectAction("selectAction", 0); selectAction.setToolBarMode(KSelectAction::MenuMode); selectAction.addAction(new QAction("action1", &selectAction)); selectAction.addAction(new QAction("action2", &selectAction)); selectAction.addAction(new QAction("action3", &selectAction)); QToolBar toolBar; toolBar.addAction(&selectAction); QWidget* widget = toolBar.widgetForAction(&selectAction); QVERIFY(widget); QToolButton* toolButton = qobject_cast<QToolButton*>(widget); QVERIFY(toolButton); QVERIFY(toolButton->isEnabled()); QVERIFY(toolButton->autoRaise()); QCOMPARE((int)toolButton->focusPolicy(), (int)Qt::NoFocus); QCOMPARE(toolButton->defaultAction(), (QAction*)&selectAction); QCOMPARE(toolButton->actions().count(), 4); QCOMPARE(toolButton->actions().at(0)->text(), QString("selectAction")); QCOMPARE(toolButton->actions().at(1)->text(), QString("action1")); QCOMPARE(toolButton->actions().at(2)->text(), QString("action2")); QCOMPARE(toolButton->actions().at(3)->text(), QString("action3")); }
void KSelectAction_UnitTest::testRequestWidgetMenuModeWidgetParentRemoveActions() { KSelectAction selectAction("selectAction", 0); selectAction.setToolBarMode(KSelectAction::MenuMode); QToolBar toolBar; toolBar.addAction(&selectAction); QWidget* widget = toolBar.widgetForAction(&selectAction); QVERIFY(widget); QAction* action1 = new QAction("action1", &selectAction); selectAction.addAction(action1); QAction* action2 = new QAction("action2", &selectAction); selectAction.addAction(action2); QAction* action3 = new QAction("action3", &selectAction); selectAction.addAction(action3); delete selectAction.removeAction(action1); delete selectAction.removeAction(action2); delete selectAction.removeAction(action3); QVERIFY(!widget->isEnabled()); QCOMPARE(widget->actions().count(), 1); QCOMPARE(widget->actions().at(0)->text(), QString("selectAction")); }
QWidget * QToolBarProto::widgetForAction ( QAction * action ) const { QToolBar *item = qscriptvalue_cast<QToolBar*>(thisObject()); if (item) return item->widgetForAction(action); return 0; }
void KSelectAction_UnitTest::testRequestWidgetComboBoxModeWidgetParent() { KSelectAction selectAction("selectAction", 0); selectAction.setToolBarMode(KSelectAction::ComboBoxMode); QToolBar toolBar; toolBar.addAction(&selectAction); QWidget* widget = toolBar.widgetForAction(&selectAction); QVERIFY(widget); KComboBox* comboBox = qobject_cast<KComboBox*>(widget); QVERIFY(comboBox); QVERIFY(!comboBox->isEnabled()); }
void tst_QToolBar::widgetAction() { // ensure that a QWidgetAction without widget behaves like a normal action QToolBar tb; QWidgetAction *a = new QWidgetAction(0); a->setIconText("Blah"); tb.addAction(a); QWidget *w = tb.widgetForAction(a); QVERIFY(w); QToolButton *button = qobject_cast<QToolButton *>(w); QVERIFY(button); QCOMPARE(a->iconText(), button->text()); delete a; }
void KviIrcContextDisplayAction::activeContextStateChanged() { if(m_pActionList) { for(QAction * a = m_pActionList->first();a;a = m_pActionList->next()) { QToolBar *t = (QToolBar*) a->parentWidget(); if(t) { KviIrcContextDisplay * w = (KviIrcContextDisplay *) t->widgetForAction(a); if(w) w->update(); } } } }
void tst_QToolBar::task191727_layout() { QMainWindow mw; QToolBar *toolBar = mw.addToolBar("test"); toolBar->addAction("one"); QAction *action = toolBar->addAction("two"); QLineEdit *lineedit = new QLineEdit; lineedit->setMaximumWidth(50); toolBar->addWidget(lineedit); mw.resize(400, 400); mw.show(); QWidget *actionwidget = toolBar->widgetForAction(action); QVERIFY(qAbs(lineedit->pos().x() - (actionwidget->geometry().right() + 1 + toolBar->layout()->spacing())) < 2); }
void lmcChatRoomWindow::createToolBar(void) { QToolBar* pLeftBar = new QToolBar(ui.wgtToolBar); pLeftBar->setStyleSheet("QToolBar { border: 0px }"); pLeftBar->setIconSize(QSize(16, 16)); ui.toolBarLayout->addWidget(pLeftBar); pFontAction = pLeftBar->addAction(QIcon(QPixmap(IDR_FONT, "PNG")), "Change Font...", this, SLOT(btnFont_clicked())); pFontColorAction = pLeftBar->addAction(QIcon(QPixmap(IDR_FONTCOLOR, "PNG")), "Change Color...", this, SLOT(btnFontColor_clicked())); pLeftBar->addSeparator(); pbtnSmiley = new lmcToolButton(pLeftBar); pbtnSmiley->setIcon(QIcon(QPixmap(IDR_SMILEY, "PNG"))); pbtnSmiley->setPopupMode(QToolButton::InstantPopup); pbtnSmiley->setMenu(pSmileyMenu); pLeftBar->addWidget(pbtnSmiley); pLeftBar->addSeparator(); pSaveAction = pLeftBar->addAction(QIcon(QPixmap(IDR_SAVE, "PNG")), "&Save As...", this, SLOT(btnSave_clicked())); pSaveAction->setShortcut(QKeySequence::Save); pSaveAction->setEnabled(false); ui.lblDividerTop->setBackgroundRole(QPalette::Light); ui.lblDividerTop->setAutoFillBackground(true); ui.lblDividerBottom->setBackgroundRole(QPalette::Dark); ui.lblDividerBottom->setAutoFillBackground(true); if(groupMode) { QToolBar* pContactsBar = new QToolBar(ui.wgtContactsBar); pContactsBar->setStyleSheet("QToolBar { border: 0px }"); pContactsBar->setIconSize(QSize(24, 24)); ui.contactsBarLayout->addWidget(pContactsBar); addContactAction = pContactsBar->addAction(QIcon(QPixmap(IDR_ADDCONTACT, "PNG")), "&Add Contacts...", this, SLOT(addContactAction_triggered())); QToolButton* pButton = (QToolButton*)pContactsBar->widgetForAction(addContactAction); pButton->setAutoRaise(false); } }
void KSelectAction_UnitTest::testSetToolTipBeforeRequestingToolButtonWidget() { KSelectAction selectAction("selectAction", 0); selectAction.setToolBarMode(KSelectAction::MenuMode); selectAction.setToolTip("Test"); QToolBar toolBar; //Don't use requestWidget, as it needs a releaseWidget when used in MenuMode //(in ComboBoxMode the widget is released automatically when it is //destroyed). When the action is added to the QToolBar, it requests and //releases the widget as needed. toolBar.addAction(&selectAction); QWidget* widget = toolBar.widgetForAction(&selectAction); QVERIFY(widget); QToolButton* toolButton = qobject_cast<QToolButton*>(widget); QVERIFY(toolButton); QCOMPARE(toolButton->toolTip(), QString("Test")); }
void ToolbarEditor::load(QWidget *w, QStringList l, QList<QAction *> actions_list) { qDebug("ToolbarEditor::load: '%s'", w->objectName().toUtf8().data()); QAction *action; for (int n = 0; n < l.count(); n++) { qDebug("ToolbarEditor::load: loading action %s", l[n].toUtf8().data()); if (l[n] == "separator") { qDebug("ToolbarEditor::load: adding separator"); QAction *sep = new QAction(w); sep->setSeparator(true); w->addAction(sep); } else { action = findAction(l[n], actions_list); if (action) { w->addAction(action); if (action->objectName().endsWith("_menu")) { // If the action is a menu and is in a toolbar, as a toolbutton, change some of its properties QToolBar *toolbar = qobject_cast<QToolBar *>(w); if (toolbar) { QToolButton *button = qobject_cast<QToolButton *>(toolbar->widgetForAction(action)); if (button) { //qDebug("ToolbarEditor::load: action %s is a toolbutton", action->objectName().toUtf8().constData()); button->setPopupMode(QToolButton::InstantPopup); //button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); } } } } else { qWarning("ToolbarEditor::load: action %s not found", l[n].toUtf8().data()); } } } }
void KSelectAction_UnitTest::testRequestWidgetMenuModeWidgetParentAddActions() { KSelectAction selectAction("selectAction", 0); selectAction.setToolBarMode(KSelectAction::MenuMode); QToolBar toolBar; toolBar.addAction(&selectAction); QWidget* widget = toolBar.widgetForAction(&selectAction); QVERIFY(widget); QVERIFY(!widget->isEnabled()); selectAction.addAction(new QAction("action1", &selectAction)); selectAction.addAction(new QAction("action2", &selectAction)); selectAction.addAction(new QAction("action3", &selectAction)); QVERIFY(widget->isEnabled()); QCOMPARE(widget->actions().count(), 4); QCOMPARE(widget->actions().at(0)->text(), QString("selectAction")); QCOMPARE(widget->actions().at(1)->text(), QString("action1")); QCOMPARE(widget->actions().at(2)->text(), QString("action2")); QCOMPARE(widget->actions().at(3)->text(), QString("action3")); }
void TestGui::testEditEntry() { EntryView* entryView = m_dbWidget->findChild<EntryView*>("entryView"); QModelIndex item = entryView->model()->index(0, 1); QRect itemRect = entryView->visualRect(item); QTest::mouseClick(entryView->viewport(), Qt::LeftButton, Qt::NoModifier, itemRect.center()); QAction* entryEditAction = m_mainWindow->findChild<QAction*>("actionEntryEdit"); QVERIFY(entryEditAction->isEnabled()); QToolBar* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar"); QWidget* entryEditWidget = toolBar->widgetForAction(entryEditAction); QVERIFY(entryEditWidget->isVisible()); QVERIFY(entryEditWidget->isEnabled()); QTest::mouseClick(entryEditWidget, Qt::LeftButton); EditEntryWidget* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget"); QVERIFY(m_dbWidget->currentWidget() == editEntryWidget); QDialogButtonBox* editEntryWidgetButtonBox = editEntryWidget->findChild<QDialogButtonBox*>("buttonBox"); QVERIFY(editEntryWidgetButtonBox); QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton); // make sure the database isn't marked as modified // wait for modified timer QTRY_COMPARE(m_tabWidget->tabText(m_tabWidget->currentIndex()), m_orgDbFileName); }
void TestGui::testDeleteEntry() { GroupView* groupView = m_dbWidget->findChild<GroupView*>("groupView"); EntryView* entryView = m_dbWidget->findChild<EntryView*>("entryView"); QToolBar* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar"); QAction* entryDeleteAction = m_mainWindow->findChild<QAction*>("actionEntryDelete"); QWidget* entryDeleteWidget = toolBar->widgetForAction(entryDeleteAction); QCOMPARE(groupView->currentGroup(), m_db->rootGroup()); QModelIndex rootGroupIndex = groupView->model()->index(0, 0); clickIndex(groupView->model()->index(groupView->model()->rowCount(rootGroupIndex) - 1, 0, rootGroupIndex), groupView, Qt::LeftButton); QCOMPARE(groupView->currentGroup()->name(), m_db->metadata()->recycleBin()->name()); clickIndex(entryView->model()->index(0, 0), entryView, Qt::LeftButton); MessageBox::setNextAnswer(QMessageBox::No); QTest::mouseClick(entryDeleteWidget, Qt::LeftButton); QCOMPARE(entryView->model()->rowCount(), 3); QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 3); MessageBox::setNextAnswer(QMessageBox::Yes); QTest::mouseClick(entryDeleteWidget, Qt::LeftButton); QCOMPARE(entryView->model()->rowCount(), 2); QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 2); clickIndex(entryView->model()->index(0, 0), entryView, Qt::LeftButton); clickIndex(entryView->model()->index(1, 0), entryView, Qt::LeftButton, Qt::ControlModifier); MessageBox::setNextAnswer(QMessageBox::Yes); QTest::mouseClick(entryDeleteWidget, Qt::LeftButton); QCOMPARE(entryView->model()->rowCount(), 0); QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 0); clickIndex(groupView->model()->index(0, 0), groupView, Qt::LeftButton); QCOMPARE(groupView->currentGroup(), m_db->rootGroup()); }
ObjectsDock::ObjectsDock(QWidget *parent) : QDockWidget(parent) , mObjectsView(new ObjectsView) , mMapDocument(nullptr) { setObjectName(QLatin1String("ObjectsDock")); mActionObjectProperties = new QAction(this); mActionObjectProperties->setIcon(QIcon(QLatin1String(":/images/16x16/document-properties.png"))); connect(mActionObjectProperties, SIGNAL(triggered()), SLOT(objectProperties())); MapDocumentActionHandler *handler = MapDocumentActionHandler::instance(); QWidget *widget = new QWidget(this); QVBoxLayout *layout = new QVBoxLayout(widget); layout->setMargin(0); layout->setSpacing(0); layout->addWidget(mObjectsView); mActionNewLayer = new QAction(this); mActionNewLayer->setIcon(QIcon(QLatin1String(":/images/16x16/document-new.png"))); connect(mActionNewLayer, SIGNAL(triggered()), handler->actionAddObjectGroup(), SIGNAL(triggered())); mActionMoveToGroup = new QAction(this); mActionMoveToGroup->setIcon(QIcon(QLatin1String(":/images/16x16/layer-object.png"))); mActionMoveUp = new QAction(this); mActionMoveUp->setIcon(QIcon(QLatin1String(":/images/16x16/go-up.png"))); mActionMoveDown = new QAction(this); mActionMoveDown->setIcon(QIcon(QLatin1String(":/images/16x16/go-down.png"))); Utils::setThemeIcon(mActionObjectProperties, "document-properties"); Utils::setThemeIcon(mActionMoveUp, "go-up"); Utils::setThemeIcon(mActionMoveDown, "go-down"); QToolBar *toolBar = new QToolBar; toolBar->setFloatable(false); toolBar->setMovable(false); toolBar->setIconSize(QSize(16, 16)); toolBar->addAction(mActionNewLayer); toolBar->addAction(handler->actionDuplicateObjects()); toolBar->addAction(handler->actionRemoveObjects()); toolBar->addAction(mActionMoveUp); toolBar->addAction(mActionMoveDown); toolBar->addAction(mActionMoveToGroup); QToolButton *button; button = dynamic_cast<QToolButton*>(toolBar->widgetForAction(mActionMoveToGroup)); mMoveToMenu = new QMenu(this); button->setPopupMode(QToolButton::InstantPopup); button->setMenu(mMoveToMenu); connect(mMoveToMenu, SIGNAL(aboutToShow()), SLOT(aboutToShowMoveToMenu())); connect(mMoveToMenu, SIGNAL(triggered(QAction*)), SLOT(triggeredMoveToMenu(QAction*))); toolBar->addAction(mActionObjectProperties); layout->addWidget(toolBar); setWidget(widget); retranslateUi(); connect(DocumentManager::instance(), &DocumentManager::documentAboutToClose, this, &ObjectsDock::documentAboutToClose); connect(mActionMoveUp, &QAction::triggered, this, &ObjectsDock::moveObjectsUp); connect(mActionMoveDown, &QAction::triggered, this, &ObjectsDock::moveObjectsDown); }
void Widgets::createToolbar() { QToolBar* standardBar = new QToolBar(tr("StandardBar"), this); standardBar->setAllowedAreas(Qt::AllToolBarAreas); standardBar->addAction(m_actNew); standardBar->addAction(m_actOpen); standardBar->addAction(m_actSave); standardBar->addSeparator(); standardBar->addAction(m_actPrint); standardBar->addAction(m_actPrintPreview); addToolBar(standardBar); QToolBar* customBar = new QToolBar(tr("CustomStyle"), this); customBar->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); customBar->setAllowedAreas(Qt::AllToolBarAreas); customBar->addAction(m_actDefaultStyle); customBar->addAction(m_actOffice2007Style); customBar->addAction(m_actRibbonStyle); customBar->addSeparator(); QAction* actTheme = new QAction(QIcon(":/res/customthemes.png"), tr("Custom Themes"), this); actTheme->setMenu(m_menuTheme); customBar->addAction(actTheme); if (QToolButton* button = qobject_cast<QToolButton*>(customBar->widgetForAction(actTheme))) { button->setPopupMode(QToolButton::InstantPopup); button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); } addToolBar(customBar); QToolBar* explorerBar = new QToolBar(tr("Explorer"), this); explorerBar->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); explorerBar->setAllowedAreas(Qt::AllToolBarAreas); QAction* act = explorerBar->addAction(QIcon(":/res/back.png"), tr("Back")); act->setStatusTip(tr("Back")); act = explorerBar->addAction(QIcon(":/res/forward.png"), tr("Forward")); act->setStatusTip(tr("Forward")); explorerBar->addSeparator(); act = explorerBar->addAction(QIcon(":/res/up.png"), tr("Up")); act->setStatusTip(tr("Up")); act = explorerBar->addAction(QIcon(":/res/viewsearch.png"), tr("Search")); act->setStatusTip(tr("Search")); act = explorerBar->addAction(QIcon(":/res/viewfolders.png"), tr("Folders")); act->setStatusTip(tr("Folders")); act = explorerBar->addAction(QIcon(":/res/viewhistory.png"), tr("History")); act->setStatusTip(tr("History")); explorerBar->addSeparator(); act = explorerBar->addAction(QIcon(":/res/moveto.png"), tr("Move To")); act->setStatusTip(tr("Move To")); act = explorerBar->addAction(QIcon(":/res/copyto.png"), tr("Copy To")); act->setStatusTip(tr("Copy To")); act = explorerBar->addAction(QIcon(":/res/delete.png"), tr("Delete")); act->setStatusTip(tr("Delete")); act = explorerBar->addAction(QIcon(":/res/undo.png"), tr("Undo")); act->setStatusTip(tr("Undo")); explorerBar->addSeparator(); act = explorerBar->addAction(QIcon(":/res/views.png"), tr("Views")); act->setStatusTip(tr("Views")); addToolBar(explorerBar); }
Player::Player(QWidget *parent) : QWidget(parent) , m_position(0) , m_isMeltedPlaying(-1) , m_zoomToggleFactor(Settings.playerZoom() == 0.0f? 1.0f : Settings.playerZoom()) , m_pauseAfterOpen(false) , m_monitorScreen(-1) , m_currentTransport(0) { setObjectName("Player"); Mlt::Controller::singleton(); setupActions(this); m_playIcon = actionPlay->icon(); m_pauseIcon = actionPause->icon(); // Create a layout. QVBoxLayout *vlayout = new QVBoxLayout(this); vlayout->setObjectName("playerLayout"); vlayout->setContentsMargins(0, 0, 0, 0); vlayout->setSpacing(4); // Add tab bar to indicate/select what is playing: clip, playlist, timeline. m_tabs = new QTabBar; m_tabs->setShape(QTabBar::RoundedSouth); m_tabs->addTab(tr("Source")); m_tabs->addTab(tr("Program")); m_tabs->setTabEnabled(ProgramTabIndex, false); QHBoxLayout* tabLayout = new QHBoxLayout; tabLayout->addWidget(m_tabs); tabLayout->addStretch(); connect(m_tabs, SIGNAL(tabBarClicked(int)), SLOT(onTabBarClicked(int))); // Add the layouts for managing video view, scroll bars, and audio controls. m_videoLayout = new QHBoxLayout; m_videoLayout->setSpacing(4); m_videoLayout->setContentsMargins(0, 0, 0, 0); vlayout->addLayout(m_videoLayout, 10); vlayout->addStretch(); m_videoScrollWidget = new QWidget; m_videoLayout->addWidget(m_videoScrollWidget, 10); m_videoLayout->addStretch(); QGridLayout* glayout = new QGridLayout(m_videoScrollWidget); glayout->setSpacing(0); glayout->setContentsMargins(0, 0, 0, 0); // Add the video widgets. m_videoWidget = QWidget::createWindowContainer(qobject_cast<QWindow*>(MLT.videoWidget())); m_videoWidget->setMinimumSize(QSize(320, 180)); glayout->addWidget(m_videoWidget, 0, 0); m_verticalScroll = new QScrollBar(Qt::Vertical); glayout->addWidget(m_verticalScroll, 0, 1); m_verticalScroll->hide(); m_horizontalScroll = new QScrollBar(Qt::Horizontal); glayout->addWidget(m_horizontalScroll, 1, 0); m_horizontalScroll->hide(); // Add the volume and signal level meter m_volumePopup = new QFrame(this, Qt::Popup); QVBoxLayout *volumeLayoutV = new QVBoxLayout(m_volumePopup); volumeLayoutV->setContentsMargins(0, 0, 0, 0); volumeLayoutV->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding)); QBoxLayout *volumeLayoutH = new QHBoxLayout; volumeLayoutH->setSpacing(0); volumeLayoutH->setContentsMargins(0, 0, 0, 0); volumeLayoutH->addWidget(new AudioScale); m_volumeSlider = new QSlider(Qt::Vertical); m_volumeSlider->setFocusPolicy(Qt::NoFocus); m_volumeSlider->setMinimumHeight(VOLUME_SLIDER_HEIGHT); m_volumeSlider->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); volumeLayoutH->addWidget(m_volumeSlider); volumeLayoutV->addLayout(volumeLayoutH); m_volumeSlider->setRange(0, 99); m_volumeSlider->setValue(Settings.playerVolume()); onVolumeChanged(m_volumeSlider->value()); m_savedVolume = MLT.volume(); m_volumeSlider->setToolTip(tr("Adjust the audio volume")); connect(m_volumeSlider, SIGNAL(valueChanged(int)), this, SLOT(onVolumeChanged(int))); // Add mute-volume buttons layout #ifdef Q_OS_MAC if (Settings.theme() == "system") volumeLayoutH = new QVBoxLayout; else #endif volumeLayoutH = new QHBoxLayout; volumeLayoutH->setContentsMargins(0, 0, 0, 0); volumeLayoutH->setSpacing(0); volumeLayoutV->addLayout(volumeLayoutH); // Add mute button QPushButton* muteButton = new QPushButton(this); muteButton->setFocusPolicy(Qt::NoFocus); muteButton->setObjectName(QString::fromUtf8("muteButton")); muteButton->setIcon(QIcon::fromTheme("dialog-cancel", QIcon(":/icons/oxygen/16x16/actions/dialog-cancel.png"))); muteButton->setToolTip(tr("Silence the audio")); muteButton->setCheckable(true); muteButton->setChecked(Settings.playerMuted()); onMuteButtonToggled(Settings.playerMuted()); volumeLayoutH->addWidget(muteButton); connect(muteButton, SIGNAL(toggled(bool)), this, SLOT(onMuteButtonToggled(bool))); // This hack realizes the volume popup geometry for on_actionVolume_triggered(). m_volumePopup->show(); m_volumePopup->hide(); // Add the scrub bar. m_scrubber = new ScrubBar(this); m_scrubber->setFocusPolicy(Qt::NoFocus); m_scrubber->setObjectName("scrubBar"); m_scrubber->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); vlayout->addWidget(m_scrubber); // Add toolbar for transport controls. QToolBar* toolbar = new QToolBar(tr("Transport Controls"), this); int s = style()->pixelMetric(QStyle::PM_SmallIconSize); toolbar->setIconSize(QSize(s, s)); toolbar->setContentsMargins(0, 0, 0, 0); QWidget *spacer = new QWidget(this); spacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); m_positionSpinner = new TimeSpinBox(this); m_positionSpinner->setToolTip(tr("Current position")); m_positionSpinner->setEnabled(false); m_positionSpinner->setKeyboardTracking(false); m_durationLabel = new QLabel(this); m_durationLabel->setToolTip(tr("Total Duration")); m_durationLabel->setText(" / 00:00:00:00"); m_durationLabel->setFixedWidth(m_positionSpinner->width()); m_inPointLabel = new QLabel(this); m_inPointLabel->setText("--:--:--:--"); m_inPointLabel->setToolTip(tr("In Point")); m_inPointLabel->setFixedWidth(m_inPointLabel->width()); m_selectedLabel = new QLabel(this); m_selectedLabel->setText("--:--:--:--"); m_selectedLabel->setToolTip(tr("Selected Duration")); m_selectedLabel->setFixedWidth(m_selectedLabel->width()); toolbar->addWidget(m_positionSpinner); toolbar->addWidget(m_durationLabel); toolbar->addWidget(spacer); toolbar->addAction(actionSkipPrevious); toolbar->addAction(actionRewind); toolbar->addAction(actionPlay); toolbar->addAction(actionFastForward); toolbar->addAction(actionSkipNext); // Add zoom button to toolbar. m_zoomButton = new QToolButton; QMenu* zoomMenu = new QMenu(this); m_zoomFitAction = zoomMenu->addAction( QIcon::fromTheme("zoom-fit-best", QIcon(":/icons/oxygen/32x32/actions/zoom-fit-best")), tr("Zoom Fit"), this, SLOT(zoomFit())); m_zoomOriginalAction = zoomMenu->addAction( QIcon::fromTheme("zoom-original", QIcon(":/icons/oxygen/32x32/actions/zoom-original")), tr("Zoom 100%"), this, SLOT(zoomOriginal())); m_zoomOutAction = zoomMenu->addAction( QIcon::fromTheme("zoom-out", QIcon(":/icons/oxygen/32x32/actions/zoom-out")), tr("Zoom 50%"), this, SLOT(zoomOut())); m_zoomInAction = zoomMenu->addAction( QIcon::fromTheme("zoom-in", QIcon(":/icons/oxygen/32x32/actions/zoom-in")), tr("Zoom 200%"), this, SLOT(zoomIn())); connect(m_zoomButton, SIGNAL(toggled(bool)), SLOT(toggleZoom(bool))); m_zoomButton->setMenu(zoomMenu); m_zoomButton->setPopupMode(QToolButton::MenuButtonPopup); m_zoomButton->setCheckable(true); m_zoomButton->setToolTip(tr("Toggle zoom")); toolbar->addWidget(m_zoomButton); toolbar->addAction(actionVolume); m_volumeWidget = toolbar->widgetForAction(actionVolume); // Add in-point and selected duration labels to toolbar. spacer = new QWidget(this); spacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); toolbar->addWidget(spacer); toolbar->addWidget(m_inPointLabel); toolbar->addWidget(m_selectedLabel); vlayout->addWidget(toolbar); vlayout->addLayout(tabLayout); connect(MLT.videoWidget(), SIGNAL(frameDisplayed(const SharedFrame&)), this, SLOT(onFrameDisplayed(const SharedFrame&))); connect(actionPlay, SIGNAL(triggered()), this, SLOT(togglePlayPaused())); connect(actionPause, SIGNAL(triggered()), this, SLOT(pause())); connect(actionFastForward, SIGNAL(triggered()), this, SLOT(fastForward())); connect(actionRewind, SIGNAL(triggered()), this, SLOT(rewind())); connect(m_scrubber, SIGNAL(seeked(int)), this, SLOT(seek(int))); connect(m_scrubber, SIGNAL(inChanged(int)), this, SLOT(onInChanged(int))); connect(m_scrubber, SIGNAL(outChanged(int)), this, SLOT(onOutChanged(int))); connect(m_positionSpinner, SIGNAL(valueChanged(int)), this, SLOT(seek(int))); connect(m_positionSpinner, SIGNAL(editingFinished()), this, SLOT(setFocus())); connect(this, SIGNAL(endOfStream()), this, SLOT(pause())); connect(this, SIGNAL(zoomChanged(float)), MLT.videoWidget(), SLOT(setZoom(float))); connect(m_horizontalScroll, SIGNAL(valueChanged(int)), MLT.videoWidget(), SLOT(setOffsetX(int))); connect(m_verticalScroll, SIGNAL(valueChanged(int)), MLT.videoWidget(), SLOT(setOffsetY(int))); setFocusPolicy(Qt::StrongFocus); }
ToolbarMenu::ToolbarMenu(QWidget *parent) : QMenu(parent) { MainWindow *w = MainWindow::instance(); addAction(w->getAction("stopafterthis")); addSeparator(); #ifdef APP_SNAPSHOT addAction(w->getAction("snapshot")); #endif addAction(w->getAction("findVideoParts")); addSeparator(); addAction(w->getAction("webpage")); addAction(w->getAction("videolink")); addAction(w->getAction("openInBrowser")); addAction(w->getAction("download")); addSeparator(); QWidgetAction *widgetAction = new QWidgetAction(this); ShareToolbar *shareToolbar = new ShareToolbar(); connect(this, &ToolbarMenu::leftMarginChanged, shareToolbar, &ShareToolbar::setLeftMargin); widgetAction->setDefaultWidget(shareToolbar); addAction(widgetAction); addSeparator(); addAction(w->getAction("compactView")); addAction(w->getAction("ontop")); addSeparator(); QToolBar *definitionToolbar = new QToolBar(); definitionToolbar->setStyleSheet("QToolButton { padding: 0}"); definitionToolbar->setToolButtonStyle(Qt::ToolButtonTextOnly); definitionToolbar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); QActionGroup *definitionGroup = new QActionGroup(this); const VideoDefinition &preferredDefinition = YT3::instance().maxVideoDefinition(); int counter = 0; for (auto defName : VideoDefinition::getDefinitionNames()) { QAction *a = new QAction(defName); a->setCheckable(true); a->setChecked(preferredDefinition.getName() == defName); connect(a, &QAction::triggered, this, [this, defName] { MainWindow::instance()->setDefinitionMode(defName); close(); }); definitionGroup->addAction(a); definitionToolbar->addAction(a); if (counter == 0) { QWidget *w = definitionToolbar->widgetForAction(a); w->setProperty("first", true); counter++; } } QWidgetAction *definitionAction = new QWidgetAction(this); definitionAction->setDefaultWidget(definitionToolbar); addAction(definitionAction); addSeparator(); addAction(w->getAction("clearRecentKeywords")); #ifndef APP_MAC addSeparator(); addAction(w->getAction("toggleMenu")); addSeparator(); addMenu(w->getMenu("help")); #endif }
void TestGui::testSearch() { QAction* searchAction = m_mainWindow->findChild<QAction*>("actionSearch"); QVERIFY(searchAction->isEnabled()); QToolBar* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar"); QWidget* searchActionWidget = toolBar->widgetForAction(searchAction); EntryView* entryView = m_dbWidget->findChild<EntryView*>("entryView"); QLineEdit* searchEdit = m_dbWidget->findChild<QLineEdit*>("searchEdit"); QToolButton* clearSearch = m_dbWidget->findChild<QToolButton*>("clearButton"); QVERIFY(!searchEdit->hasFocus()); // Enter search QTest::mouseClick(searchActionWidget, Qt::LeftButton); QTRY_VERIFY(searchEdit->hasFocus()); // Search for "ZZZ" QTest::keyClicks(searchEdit, "ZZZ"); QTRY_COMPARE(entryView->model()->rowCount(), 0); // Escape QTest::keyClick(m_mainWindow, Qt::Key_Escape); QTRY_VERIFY(!searchEdit->hasFocus()); // Enter search again QTest::mouseClick(searchActionWidget, Qt::LeftButton); QTRY_VERIFY(searchEdit->hasFocus()); // Input and clear QTest::keyClicks(searchEdit, "ZZZ"); QTRY_COMPARE(searchEdit->text(), QString("ZZZ")); QTest::mouseClick(clearSearch, Qt::LeftButton); QTRY_COMPARE(searchEdit->text(), QString("")); // Triggering search should select the existing text QTest::keyClicks(searchEdit, "ZZZ"); QTest::mouseClick(searchActionWidget, Qt::LeftButton); QTRY_VERIFY(searchEdit->hasFocus()); // Search for "some" QTest::keyClicks(searchEdit, "some"); QTRY_COMPARE(entryView->model()->rowCount(), 4); clickIndex(entryView->model()->index(0, 1), entryView, Qt::LeftButton); QAction* entryEditAction = m_mainWindow->findChild<QAction*>("actionEntryEdit"); QVERIFY(entryEditAction->isEnabled()); QWidget* entryEditWidget = toolBar->widgetForAction(entryEditAction); QVERIFY(entryEditWidget->isVisible()); QVERIFY(entryEditWidget->isEnabled()); QTest::mouseClick(entryEditWidget, Qt::LeftButton); QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::EditMode); EditEntryWidget* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget"); QDialogButtonBox* editEntryWidgetButtonBox = editEntryWidget->findChild<QDialogButtonBox*>("buttonBox"); QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton); QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::ViewMode); clickIndex(entryView->model()->index(1, 0), entryView, Qt::LeftButton); QAction* entryDeleteAction = m_mainWindow->findChild<QAction*>("actionEntryDelete"); QWidget* entryDeleteWidget = toolBar->widgetForAction(entryDeleteAction); QVERIFY(entryDeleteWidget->isVisible()); QVERIFY(entryDeleteWidget->isEnabled()); QVERIFY(!m_db->metadata()->recycleBin()); QTest::mouseClick(entryDeleteWidget, Qt::LeftButton); QCOMPARE(entryView->model()->rowCount(), 3); QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 1); clickIndex(entryView->model()->index(1, 0), entryView, Qt::LeftButton); clickIndex(entryView->model()->index(2, 0), entryView, Qt::LeftButton, Qt::ControlModifier); QCOMPARE(entryView->selectionModel()->selectedRows().size(), 2); MessageBox::setNextAnswer(QMessageBox::No); QTest::mouseClick(entryDeleteWidget, Qt::LeftButton); QCOMPARE(entryView->model()->rowCount(), 3); QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 1); MessageBox::setNextAnswer(QMessageBox::Yes); QTest::mouseClick(entryDeleteWidget, Qt::LeftButton); QCOMPARE(entryView->model()->rowCount(), 1); QCOMPARE(m_db->metadata()->recycleBin()->entries().size(), 3); QWidget* closeSearchButton = m_dbWidget->findChild<QToolButton*>("closeSearchButton"); QTest::mouseClick(closeSearchButton, Qt::LeftButton); QCOMPARE(entryView->model()->rowCount(), 1); }