void WebViewAbstraction::triggerNavigationAction(QtWebKit::NavigationAction which)
{
    QAction* touchAction = touchWebView()->page()->navigationController()->navigationAction(which);
    touchAction->trigger();
    QAction* desktopAction = desktopWebView()->navigationController()->navigationAction(which);
    desktopAction->trigger();
}
void tst_QToolBar::toggleViewAction()
{
    {
        QToolBar tb;
        QAction *toggleViewAction = tb.toggleViewAction();
        QVERIFY(tb.isHidden());
        toggleViewAction->trigger();
        QVERIFY(!tb.isHidden());
        toggleViewAction->trigger();
        QVERIFY(tb.isHidden());
    }

    {
        QMainWindow mw;
        QToolBar tb(&mw);
        mw.addToolBar(&tb);
        mw.show();
        QAction *toggleViewAction = tb.toggleViewAction();
        QVERIFY(!tb.isHidden());
        toggleViewAction->trigger();
        QVERIFY(tb.isHidden());
        toggleViewAction->trigger();
        QVERIFY(!tb.isHidden());
        toggleViewAction->trigger();
        QVERIFY(tb.isHidden());
    }
}
Example #3
0
void KateFoldingTest::testFolding_py_lang()
{
  KTemporaryFile file;
  file.setSuffix(".py");
  file.open();
  QTextStream stream(&file);
  stream << "if customerName == x\n"
         << "  print x\n"
         << "elif customerName == y\n"
         << "  print y\n"
         << "else print z\n";
  stream << flush;
  file.close();

  KateDocument doc(false, false, false);
  QVERIFY(doc.openUrl(KUrl(file.fileName())));

  KateView* view = new KateView(&doc, 0);

  // is set to allow kate's hl to be called
  view->config()->setDynWordWrap(true);

  QCOMPARE(doc.visibleLines(), 6u);

  QAction* action = view->action("folding_toplevel");
  QVERIFY(action);
  action->trigger();
  QCOMPARE(doc.visibleLines(), 4u);

  action = view->action("folding_expandtoplevel");
  QVERIFY(action);
  action->trigger();
  QCOMPARE(doc.visibleLines(), 6u);
}
Example #4
0
void KateFoldingTest::testFolding_collapse_expand_local()
{
  KTemporaryFile file;
  file.setSuffix(".c");
  file.open();
  QTextStream stream(&file);
  stream << "if () {\n"
         << "  if () {\n"
         << "     if () {\n"
         << "        if () {\n"
         << "              }\n"
         << "           }\n"
         << "        }\n"
         << "  if () {\n"
         << "     foo()\n"
         << "        }\n"
         << " }\n";
  stream << flush;
  file.close();

  KateDocument doc(false, false, false);
  QVERIFY(doc.openUrl(KUrl(file.fileName())));

  KateView* view = new KateView(&doc, 0);

  // is set to allow kate's hl to be called
  view->config()->setDynWordWrap(true);

  QCOMPARE(doc.visibleLines(), 12u);

  view->setCursorPosition(KTextEditor::Cursor(2,12));

  QAction* action = view->action("folding_collapselocal");
  QVERIFY(action);
  action->trigger();
  QCOMPARE(doc.visibleLines(), 9u);

  view->setCursorPosition(KTextEditor::Cursor(2,11));

  action = view->action("folding_collapselocal");
  QVERIFY(action);
  action->trigger();
  QCOMPARE(doc.visibleLines(), 7u);

  view->setCursorPosition(KTextEditor::Cursor(1,9));

  action = view->action("folding_expandlocal");
  QVERIFY(action);
  action->trigger();
  QCOMPARE(doc.visibleLines(), 9u);

}
Example #5
0
void tst_QDockWidget::toggleViewAction()
{
    QMainWindow mw;
    QDockWidget dw(&mw);
    mw.addDockWidget(Qt::LeftDockWidgetArea, &dw);
    mw.show();
    QAction *toggleViewAction = dw.toggleViewAction();
    QVERIFY(!dw.isHidden());
    toggleViewAction->trigger();
    QVERIFY(dw.isHidden());
    toggleViewAction->trigger();
    QVERIFY(!dw.isHidden());
    toggleViewAction->trigger();
    QVERIFY(dw.isHidden());
}
Example #6
0
void TestGui::triggerAction(const QString& name)
{
    QAction* action = m_mainWindow->findChild<QAction*>(name);
    QVERIFY(action);
    QVERIFY(action->isEnabled());
    action->trigger();
}
QMenu * MainWindowBase::getLanguageMenu(const QString &qmFileDirPath, const QString &local){
    qDebug()<<"--setupLanguageMenu(...) "<<" qmFileDirPath:"<<qmFileDirPath<<" local:"<<local;

    qmPath = qmFileDirPath;
    qmLocale = local;
    if(!m_languageMenu){
        m_languageMenu = new QMenu(tr("&Language"), this);
        //Language
        actionLanguageDefaultEnglish = new QAction(tr("Default(English)"), this);
        actionLanguageDefaultEnglish->setData("en_US");
        actionLanguageDefaultEnglish->setCheckable(true);
        m_languageMenu->addAction(actionLanguageDefaultEnglish);

        QActionGroup *languageActionGroup = new QActionGroup(this);
        languageActionGroup->addAction(actionLanguageDefaultEnglish);
        QObject::connect(languageActionGroup, SIGNAL(triggered(QAction *)), this,
                         SLOT(slotChangeLanguage(QAction*)));

        QStringList translationLanguages = Utilities::availableTranslationLanguages(qmPath);
        //如果没有找到语言文件或者首选语言是英语,则将"en_US"置为选中
        //If no language file is found or the preferred language is English, set the "en_US" menu checked
        if (translationLanguages.isEmpty()) {
            actionLanguageDefaultEnglish->setChecked(true);
            m_preferedLanguage = "en_US";
            return m_languageMenu;
        }

        if (!translationLanguages.contains(qmLocale)){
            qmLocale = "en_US";
        }

        if(qmLocale == "en_US"){
            actionLanguageDefaultEnglish->setChecked(true);
        }

        //为每一个语言文件生成动作为菜单
        //Make action and menu for each language file
        for (int i = 0; i < translationLanguages.size(); i++){
            QString translationLanguage = translationLanguages[i];
            QLocale local(translationLanguage);
            QString LanguageName = QLocale::languageToString(local.language());
            QString regionName = QLocale::countryToString(local.country());

            //QAction *action = new QAction(tr("&%1 %2") .arg(i + 1).arg(translationLanguage), this);
            QAction *action = new QAction(tr("%1(%2)") .arg(LanguageName).arg(regionName), this);

            action->setCheckable(true);
            action->setData(translationLanguage);

            m_languageMenu->addAction(action);
            languageActionGroup->addAction(action);

            if (qmLocale == translationLanguage) {
                action->setChecked(true);
                action->trigger();
            }

        }

    }
Example #8
0
 void MacroLinkItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event)
 {
   QAction* macroWatch = Resource::action(Resource::MACRO_WATCHOUTPUT);
   macroWatch->setData(reinterpret_cast<qulonglong>(edge().srcPin().data()));
   macroWatch->trigger();
   event->accept();
 }
Example #9
0
int ChoqokTabBar::insertTab( int index , QWidget *widget , const QIcon & input_icon , const QString & name )
{
    KIcon icon( input_icon );
    if( icon.isNull() )
        icon = KIcon( "edit-find" );
    
    QAction *action = new QAction( icon , name , this );
        action->setCheckable( true );

    p->actions_list.insert( index , action );
    p->st_widget->insertWidget( index , widget );
    
    connect( widget , SIGNAL(destroyed(QObject*)) , SLOT(widget_destroyed(QObject*)) );

    for( int i=0 ; i<p->history_list.count() ; i++ )
        if( p->history_list.at(i) >= index )
            p->history_list[ i ]++;

    refreshTabBar();
    
    if( count() == 1 )
    {
        action->trigger();
	p->history_list << 0;
    }

    return index;
}
Example #10
0
void KateFoldingTest::testFolding_collapse_dsComments_XML()
{
  KTemporaryFile file;
  file.setSuffix(".xml");
  file.open();
  QTextStream stream(&file);
  stream << "<test1>\n"
         << "</test1>\n"
         << "<!--\n"
         << "<test2>\n"
         << "</test2>\n"
         << "-->\n"
         << "<!--\n"
         << "-->\n";
  stream << flush;
  file.close();

  KateDocument doc(false, false, false);
  QVERIFY(doc.openUrl(KUrl(file.fileName())));

  KateView* view = new KateView(&doc, 0);

  // is set to allow kate's hl to be called
  view->config()->setDynWordWrap(true);

  QCOMPARE(doc.visibleLines(), 9u);

  QAction* action = view->action("folding_collapse_dsComment");
  QVERIFY(action);
  action->trigger();
  QCOMPARE(doc.visibleLines(), 5u);
}
Example #11
0
void MuseScore::oscAction()
      {
      PathObject* pathObject = qobject_cast<PathObject*>(sender());
      QString path = pathObject->path().mid(9);
      QAction* a = getAction(path.toLocal8Bit().data());
      a->trigger();
      }
void TestShellDocumentOperation::testKateDocumentAndViewCreation()
{
    //create one document
    IDocumentController *documentController = Core::self()->documentController();
    documentController->openDocumentFromText(QLatin1String(""));
    QCOMPARE(documentController->openDocuments().count(), 1);

    //assure we have only one kate view for the newly created document
    KTextEditor::Document *doc = documentController->openDocuments().at(0)->textDocument();
    QCOMPARE(doc->views().count(), 1);
    QCOMPARE(dynamic_cast<KTextEditor::MovingInterface*>(doc)->revision(), qint64(0));

    //also assure the view's xmlgui is plugged in
    KParts::MainWindow *main = Core::self()->uiControllerInternal()->activeMainWindow();
    QVERIFY(main);
    QVERIFY(main->guiFactory()->clients().contains(doc->views().at(0)));

    //KTextEditor::views is internally a QHash::keys() call: so the order of the views will vary
    const auto originalView = doc->views().at(0);

    //create the new view and activate it (using split action from mainwindow)
    QAction *splitAction = main->actionCollection()->action(QStringLiteral("split_vertical"));
    QVERIFY(splitAction);
    splitAction->trigger();
    const auto viewList = doc->views();
    QCOMPARE(viewList.count(), 2);

    const auto newlySplitView = originalView == viewList[0] ? viewList[1] : viewList[0];

    //check that we did switch to the new xmlguiclient
    QVERIFY(!main->guiFactory()->clients().contains(originalView));
    QVERIFY(main->guiFactory()->clients().contains(newlySplitView));

    documentController->openDocuments().at(0)->close(IDocument::Discard);
}
Example #13
0
bool AccountView::eventFilter(QObject *obj, QEvent *event)
{
    if (obj == account_menu_ && event->type() == QEvent::MouseButtonRelease) {
        QMouseEvent *ev = (QMouseEvent*)event;
        QAction *action = account_menu_->actionAt(ev->pos());
        if (action) {
            action->trigger();
        }
    }
    if (obj == mAccountBtn && event->type() == QEvent::Paint) {
        QRect rect(0, 0, AvatarService::kAvatarSize, AvatarService::kAvatarSize);
        QPainter painter(mAccountBtn);
        painter.setRenderHint(QPainter::Antialiasing);
        painter.setRenderHint(QPainter::HighQualityAntialiasing);

        // get the device pixel radio from current painter device
        double scale_factor = globalDevicePixelRatio();

        QPixmap image(mAccountBtn->icon().pixmap(rect.size()).scaled(scale_factor * rect.size()));
        QRect actualRect(QPoint(0, 0),
                         QSize(AvatarService::kAvatarSize * scale_factor,
                               AvatarService::kAvatarSize * scale_factor));

        QImage masked_image(actualRect.size(),
                            QImage::Format_ARGB32_Premultiplied);
        masked_image.fill(Qt::transparent);
        QPainter mask_painter;
        mask_painter.begin(&masked_image);
        mask_painter.setRenderHint(QPainter::Antialiasing);
        mask_painter.setRenderHint(QPainter::HighQualityAntialiasing);
        mask_painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
        mask_painter.setPen(Qt::NoPen);
        mask_painter.setBrush(Qt::white);
        mask_painter.drawEllipse(actualRect);
        mask_painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
        mask_painter.drawPixmap(actualRect, image);
        mask_painter.setCompositionMode(QPainter::CompositionMode_DestinationOver);
        mask_painter.fillRect(actualRect, Qt::transparent);
        mask_painter.end();
        masked_image.setDevicePixelRatio(scale_factor);

        painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
        painter.drawImage(QPoint(0,0), masked_image);
        return true;
    }
    if (obj == mRefreshLabel) {
        if (event->type() == QEvent::MouseButtonPress) {
            emit refresh();
            return true;
        } else if (event->type() == QEvent::Enter) {
            mRefreshLabel->setPixmap(QIcon(":/images/toolbar/refresh-orange.png").pixmap(20));
            return true;
        } else if (event->type() == QEvent::Leave) {
            mRefreshLabel->setPixmap(QIcon(":/images/toolbar/refresh-new.png").pixmap(20));
            return true;
        }
    }
    return QObject::eventFilter(obj, event);
}
Example #14
0
void SystemTrayIcon::activatedUnReadChat()
{
	QAction *act = actions_.back();
	if ( act )
	{
		act->trigger();
	}
}
Example #15
0
void triggerMainWindowActionWithObjectName(QString actionName)
{
	QAction* action = findMainWindowChildWithObjectName<QAction*>(actionName);
    if(action)
    {
        action->trigger();
    }
}
Example #16
0
void CommandLocator::accept(Locator::FilterEntry entry) const
{
    // Retrieve action via index.
    const int index = entry.internalData.toInt();
    QTC_ASSERT(index >= 0 && index < d->commands.size(), return);
    QAction *action = d->commands.at(index)->action();
    QTC_ASSERT(action->isEnabled(), return);
    action->trigger();
}
Example #17
0
void ActionsManager::triggerAction(const QString &action)
{
	QAction *object = getAction(action);

	if (object)
	{
		object->trigger();
	}
}
Example #18
0
void Menu::loadAction(Settings& settings, QAction& action) {
    QString prefix;
    for (QString group : groups) {
        prefix += group;
        prefix += "/";
    }
    if (action.isChecked() != settings.value(prefix + action.text(), action.isChecked()).toBool()) {
        action.trigger();
    }
}
Example #19
0
void KateFoldingTest::testFolding()
{
  QFETCH(QString, text);
  QFETCH(QString, fileExt);
  QFETCH(QString, firstActionName);
  QFETCH(QString, secondActionName);

  QFETCH(unsigned int, initValue);
  QFETCH(unsigned int, firstResult);
  QFETCH(unsigned int, secondResult);

  KTemporaryFile file;
  file.setSuffix("." + fileExt);
  file.open();
  QTextStream stream(&file);

  stream << text;
  stream << flush;
  file.close();

  KateDocument doc(false, false, false);
  QVERIFY(doc.openUrl(KUrl(file.fileName())));

  KateView* view = new KateView(&doc, 0);

  QAction* firstAction = view->action(qPrintable(firstActionName));
  QVERIFY(firstAction);

  QAction* secondAction = view->action(qPrintable(secondActionName));
  QVERIFY(secondAction);

  // is set to allow kate's hl to be called
  view->config()->setDynWordWrap(true);

  QCOMPARE(doc.visibleLines(), initValue);

  firstAction->trigger();
  QCOMPARE(doc.visibleLines(), firstResult);

  secondAction->trigger();
  QCOMPARE(doc.visibleLines(), secondResult);
}
Example #20
0
void KateFoldingTest::testFoldingReload()
{
  KTemporaryFile file;
  file.setSuffix(".cpp");
  file.open();
  QTextStream stream(&file);
  stream << "int main() {\n"
         << "  asdf;\n"
         << "}\n";
  stream << flush;
  file.close();

  KateDocument doc(false, false, false);
  QVERIFY(doc.openUrl(KUrl(file.fileName())));

  KateView* view = new KateView(&doc, 0);

  // is set to allow kate's hl to be called
  view->config()->setDynWordWrap(true);

  QCOMPARE(doc.visibleLines(), 4u);

  QAction* action = view->action("folding_toplevel");
  QVERIFY(action);
  action->trigger();

  doc.foldingTree()->saveFoldingState();

  QList<int> hiddenLines(doc.foldingTree()->m_hiddenLines);
  QList<int> hiddenColumns(doc.foldingTree()->m_hiddenColumns);

  QCOMPARE(doc.visibleLines(), 2u);

  action = view->action("file_reload");
  QVERIFY(action);
  action->trigger();

  QCOMPARE(doc.visibleLines(), 2u);

  QCOMPARE(hiddenLines,doc.foldingTree()->m_hiddenLines);
  QCOMPARE(hiddenColumns,doc.foldingTree()->m_hiddenColumns);
}
Example #21
0
void
MatrixTool::invokeInParentView(QString actionName)
{
    QAction *a = findActionInParentView(actionName);
    if (!a) {
        RG_WARNING << "MatrixTool::invokeInParentView: No action \"" << actionName
                  << "\" found in parent view";
    } else {
        a->trigger();
    }
}
Example #22
0
void QRibbonSection::activateAction()
{
    QAction *a;
    QRibbonButton *b = (QRibbonButton *) sender();
    if (b) {
        a = b->getAction();
        if (a) {
            a->trigger();
        }
    }
}
Example #23
0
void
MatrixTool::invokeInParentView(QString actionName)
{
    QAction *a = findActionInParentView(actionName);
    if (!a) {
        std::cerr << "MatrixTool::invokeInParentView: No action \"" << actionName
                  << "\" found in parent view" << std::endl;
    } else {
        a->trigger();
    }
}
void SceneViewer::onButtonPressed(FlipConsole::EGadget button) {
  if (m_freezedStatus != NO_FREEZED) return;
  switch (button) {
  case FlipConsole::eSaveImg: {
    if (m_previewMode == NO_PREVIEW) {
      DVGui::warning(QObject::tr(
          "It is not possible to save images in camera stand view."));
      return;
    }
    TApp *app = TApp::instance();
    int row   = app->getCurrentFrame()->getFrame();

    Previewer *previewer =
        Previewer::instance(m_previewMode == SUBCAMERA_PREVIEW);
    if (!previewer->isFrameReady(row)) {
      DVGui::warning(QObject::tr("The preview images are not ready yet."));
      return;
    }

    TRasterP ras =
        previewer->getRaster(row, m_visualSettings.m_recomputeIfNeeded);

    TImageCache::instance()->add(QString("TnzCompareImg"),
                                 TRasterImageP(ras->clone()));

    break;
  }

  case FlipConsole::eSave:
    Previewer::instance(m_previewMode == SUBCAMERA_PREVIEW)
        ->saveRenderedFrames();
    break;

  case FlipConsole::eHisto: {
    QAction *action = CommandManager::instance()->getAction(MI_Histogram);
    action->trigger();
    break;
  }

  case FlipConsole::eDefineSubCamera:
    m_editPreviewSubCamera = !m_editPreviewSubCamera;
    update();
    break;

  // open locator. Create one for the first time
  case FlipConsole::eLocator:
    if (!m_locator) m_locator = new LocatorPopup(this);
    m_locator->show();
    m_locator->raise();
    m_locator->activateWindow();
    break;
  }
}
Example #25
0
void ActionInspector::triggerAction(int row)
{
    auto model = ObjectBroker::model(QStringLiteral("com.kdab.GammaRay.ActionModel"));
    const QModelIndex index = model->index(row, 0);
    if (!index.isValid())
        return;

    QObject *obj = index.data(ActionModel::ObjectRole).value<QObject*>();
    QAction *action = qobject_cast<QAction*>(obj);

    if (action)
        action->trigger();
}
Example #26
0
bool MultiClickMenu::eventFilter(QObject *watched, QEvent *event) {
    CHECK(watched == menu, false);
    CHECK(isSelectEvent(event), false);

    QAction *action = menu->activeAction();
    CHECK(NULL != action, false);

    if (action->isEnabled()) {
        action->trigger();
        return true;
    }
    return false;
}
void TestMainWindow::triggerAction(QString text, QObject* parent) {
	QList<QAction*> actionList = parent->findChildren<QAction*>();
	QAction* action;
	for(int i = 0; i < actionList.length() ; i++) {
		if(actionList.at(i)->text() == text) {
			action = actionList.at(i);
		}
	}
	QVERIFY2(action != NULL,  (QString("action with text \"")+ text +
	                           QString("\" not found")).toLatin1().data());
	action->trigger();
	qApp->processEvents();
	QTest::qSleep(500);
}
Example #28
0
bool AccountView::eventFilter(QObject *obj, QEvent *event)
{
    if (obj == account_menu_ && event->type() == QEvent::MouseButtonRelease) {
        QMouseEvent *ev = (QMouseEvent*)event;
        QAction *action = account_menu_->actionAt(ev->pos());
        if (action) {
            action->trigger();
        }
    }
    if (obj == mAccountBtn && event->type() == QEvent::Paint) {
        QRect rect(0, 0, AvatarService::kAvatarSize, AvatarService::kAvatarSize);
        QPainter painter(mAccountBtn);
        painter.setRenderHint(QPainter::Antialiasing);
        painter.setRenderHint(QPainter::HighQualityAntialiasing);

        // get the device pixel radio from current painter device
        int scale_factor = 1;
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
        scale_factor = painter.device()->devicePixelRatio();
#endif // QT5

        QPixmap image(mAccountBtn->icon().pixmap(rect.size()).scaled(scale_factor * rect.size()));
        QRect actualRect(QPoint(0, 0), image.size());

        QImage masked_image(actualRect.size(), QImage::Format_ARGB32_Premultiplied);
        masked_image.fill(Qt::transparent);
        QPainter mask_painter;
        mask_painter.begin(&masked_image);
        mask_painter.setRenderHint(QPainter::Antialiasing);
        mask_painter.setRenderHint(QPainter::HighQualityAntialiasing);
        mask_painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
        mask_painter.setPen(Qt::NoPen);
        mask_painter.setBrush(Qt::white);
        mask_painter.drawEllipse(actualRect);
        mask_painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
        mask_painter.drawPixmap(actualRect, image);
        mask_painter.setCompositionMode(QPainter::CompositionMode_DestinationOver);
        mask_painter.fillRect(actualRect, Qt::transparent);
        mask_painter.end();
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
        masked_image.setDevicePixelRatio(scale_factor);
#endif // QT5

        painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
        painter.drawImage(QPoint(0,0), masked_image);
        return true;
    }
    return QObject::eventFilter(obj, event);
}
Example #29
0
void ActionInspector::triggerAction(int row)
{
  QAbstractItemModel *model = ObjectBroker::model("com.kdab.GammaRay.ActionModel");
  const QModelIndex index = model->index(row, 0);
  if (!index.isValid()) {
    return;
  }

  QObject *obj = index.data(ObjectModel::ObjectRole).value<QObject*>();
  QAction *action = qobject_cast<QAction*>(obj);

  if (action) {
    action->trigger();
  }
}
Example #30
0
    virtual void mouseReleaseEvent(QMouseEvent *e)
    {
        QAction *action = activeAction();
        if ( action && action->isEnabled() && !action->menu() &&
             action->property("keep_menu_open").toBool() )
        {
            action->setEnabled(false);
            QMenu::mouseReleaseEvent(e);
            action->setEnabled(true);
            action->trigger();
            return;
        }

        QMenu::mouseReleaseEvent(e);
    }