Esempio n. 1
0
// public bool showTabBarWhenOneTab() const
void tst_TabBar::showTabBarWhenOneTab()
{
    QFETCH(bool, showTabBarWhenOneTab);

    SubTabBar bar;
    bar.show();
    bar.setShowTabBarWhenOneTab(showTabBarWhenOneTab);
    QAction *action = bar.viewTabBarAction();
    QVERIFY(action);
    QCOMPARE(action->text(), (showTabBarWhenOneTab ? QString("Hide Tab Bar") : QString("Show Tab Bar")));
    QCOMPARE(bar.showTabBarWhenOneTab(), showTabBarWhenOneTab);

    bar.addTab("one");
    QCOMPARE(bar.count(), 1);
    QCOMPARE(bar.isVisible(), showTabBarWhenOneTab);

    bar.addTab("two");
    QCOMPARE(bar.count(), 2);
    QCOMPARE(bar.isVisible(), true);
    QCOMPARE(action->text(), QString("Hide Tab Bar"));
    QCOMPARE(action->isEnabled(), false);

    bar.removeTab(0);
    QCOMPARE(bar.count(), 1);
    QCOMPARE(bar.isVisible(), showTabBarWhenOneTab);
    QCOMPARE(action->isEnabled(), true);
    QCOMPARE(action->text(), (showTabBarWhenOneTab ? QString("Hide Tab Bar") : QString("Show Tab Bar")));
}
Esempio n. 2
0
void HelpViewer::actionChanged()
{
    QAction *a = qobject_cast<QAction *>(sender());
    if (a == pageAction(QWebPage::Back))
        emit backwardAvailable(a->isEnabled());
    else if (a == pageAction(QWebPage::Forward))
        emit forwardAvailable(a->isEnabled());
}
Esempio n. 3
0
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);
}
Esempio n. 4
0
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);
}
Esempio n. 5
0
void HelpWindowWidget::documentChanged()
{
    // A new help document has been selected, resulting in the previous or next
    // help document becoming either available or not

    QAction *action = qobject_cast<QAction *>(sender());

    if (action == pageAction(QWebPage::Back))
        emit backEnabled(action->isEnabled());
    else if (action == pageAction(QWebPage::Forward))
        emit forwardEnabled(action->isEnabled());
}
Esempio n. 6
0
void KviConnectAction::activeContextStateChanged()
{

	KviPointerList<QAction> * bl = actionList();
	if(!bl)return;

	bool bIconVisibleInMenu = KVI_OPTION_BOOL(KviOption_boolShowIconsInPopupMenus);
	QPixmap * p;
	QString txt;
	KviIrcContext * c = g_pMainWindow->activeContext();
	if(c)
	{
		switch(c->state())
		{
			case KviIrcContext::Idle:
				p = g_pIconManager->getBigIcon(KVI_BIGICON_DISCONNECTED);
				txt = m_szConnectString;
			break;
			case KviIrcContext::PendingReconnection:
			case KviIrcContext::Connecting:
			case KviIrcContext::LoggingIn:
				p = g_pIconManager->getBigIcon(KVI_BIGICON_CONNECTING);
				txt = m_szAbortConnectionString;
			break;
			case KviIrcContext::Connected:
				p = g_pIconManager->getBigIcon(KVI_BIGICON_CONNECTED);
				txt = m_szDisconnectString;
			break;
			default:
				p = 0;
			break;
		}
	} else {
		p = 0;
	}

	if(p)
	{
		for(QAction * b = bl->first();b;b =bl->next())
		{
			if(!b->isEnabled())b->setEnabled(true);
			b->setIcon(QIcon(*p));
			b->setText(txt);
			b->setIconVisibleInMenu(bIconVisibleInMenu);
		}
	} else {
		for(QAction * b = bl->first();b;b = bl->next())
		{
			if(b->isEnabled())b->setEnabled(false);
			b->setIconVisibleInMenu(bIconVisibleInMenu);
		}
	}
}
Esempio n. 7
0
void MainWindow::updateActions()
{
	QAction *undoAction = m_windowsManager->getAction(UndoAction);

	if (undoAction)
	{
		m_actionsManager->getAction(QLatin1String("Undo"))->setEnabled(undoAction->isEnabled());
		m_actionsManager->getAction(QLatin1String("Undo"))->setText(undoAction->text());
	}
	else
	{
		m_actionsManager->getAction(QLatin1String("Undo"))->setEnabled(false);
		m_actionsManager->getAction(QLatin1String("Undo"))->setText(tr("Undo"));
	}

	QAction *redoAction = m_windowsManager->getAction(RedoAction);

	if (redoAction)
	{
		m_actionsManager->getAction(QLatin1String("Redo"))->setEnabled(redoAction->isEnabled());
		m_actionsManager->getAction(QLatin1String("Redo"))->setText(redoAction->text());
	}
	else
	{
		m_actionsManager->getAction(QLatin1String("Redo"))->setEnabled(false);
		m_actionsManager->getAction(QLatin1String("Redo"))->setText(tr("Redo"));
	}

	updateAction(m_windowsManager->getAction(CutAction), m_actionsManager->getAction(QLatin1String("Cut")));
	updateAction(m_windowsManager->getAction(CopyAction), m_actionsManager->getAction(QLatin1String("Copy")));
	updateAction(m_windowsManager->getAction(PasteAction), m_actionsManager->getAction(QLatin1String("Paste")));
	updateAction(m_windowsManager->getAction(DeleteAction), m_actionsManager->getAction(QLatin1String("Delete")));
	updateAction(m_windowsManager->getAction(SelectAllAction), m_actionsManager->getAction(QLatin1String("SelectAll")));
	updateAction(m_windowsManager->getAction(FindAction), m_actionsManager->getAction(QLatin1String("Find")));
	updateAction(m_windowsManager->getAction(FindNextAction), m_actionsManager->getAction(QLatin1String("FindNext")));
	updateAction(m_windowsManager->getAction(FindPreviousAction), m_actionsManager->getAction(QLatin1String("FindPrevious")));
	updateAction(m_windowsManager->getAction(ReloadAction), m_actionsManager->getAction(QLatin1String("Reload")));
	updateAction(m_windowsManager->getAction(StopAction), m_actionsManager->getAction(QLatin1String("Stop")));
	updateAction(m_windowsManager->getAction(ViewSourceAction), m_actionsManager->getAction(QLatin1String("ViewSource")));
	updateAction(m_windowsManager->getAction(InspectPageAction), m_actionsManager->getAction(QLatin1String("InspectPage")));
	updateAction(m_windowsManager->getAction(GoBackAction), m_actionsManager->getAction(QLatin1String("GoBack")));
	updateAction(m_windowsManager->getAction(RewindAction), m_actionsManager->getAction(QLatin1String("Rewind")));
	updateAction(m_windowsManager->getAction(GoForwardAction), m_actionsManager->getAction(QLatin1String("GoForward")));
	updateAction(m_windowsManager->getAction(FastForwardAction), m_actionsManager->getAction(QLatin1String("FastForward")));

	const bool canZoom = m_windowsManager->canZoom();

	m_actionsManager->getAction(QLatin1String("ZoomOut"))->setEnabled(canZoom);
	m_actionsManager->getAction(QLatin1String("ZoomIn"))->setEnabled(canZoom);
	m_actionsManager->getAction(QLatin1String("ZoomOriginal"))->setEnabled(canZoom);
}
Esempio n. 8
0
void MainWindow::updateActions()
{
	QAction *undoAction = m_windowsManager->getAction(UndoAction);

	if (undoAction)
	{
		m_ui->actionUndo->setEnabled(undoAction->isEnabled());
		m_ui->actionUndo->setText(undoAction->text());
	}
	else
	{
		m_ui->actionUndo->setEnabled(false);
		m_ui->actionUndo->setText(tr("Undo"));
	}

	QAction *redoAction = m_windowsManager->getAction(RedoAction);

	if (redoAction)
	{
		m_ui->actionRedo->setEnabled(redoAction->isEnabled());
		m_ui->actionRedo->setText(redoAction->text());
	}
	else
	{
		m_ui->actionRedo->setEnabled(false);
		m_ui->actionRedo->setText(tr("Redo"));
	}

	updateAction(m_windowsManager->getAction(CutAction), m_ui->actionCut);
	updateAction(m_windowsManager->getAction(CopyAction), m_ui->actionCopy);
	updateAction(m_windowsManager->getAction(PasteAction), m_ui->actionPaste);
	updateAction(m_windowsManager->getAction(DeleteAction), m_ui->actionDelete);
	updateAction(m_windowsManager->getAction(SelectAllAction), m_ui->actionSelectAll);
	updateAction(m_windowsManager->getAction(FindAction), m_ui->actionFind);
	updateAction(m_windowsManager->getAction(FindNextAction), m_ui->actionFindNext);
	updateAction(m_windowsManager->getAction(FindPreviousAction), m_ui->actionFindPrevious);
	updateAction(m_windowsManager->getAction(ReloadAction), m_ui->actionReload);
	updateAction(m_windowsManager->getAction(StopAction), m_ui->actionStop);
	updateAction(m_windowsManager->getAction(ViewSourceAction), m_ui->actionViewSource);
	updateAction(m_windowsManager->getAction(InspectPageAction), m_ui->actionInspectPage);
	updateAction(m_windowsManager->getAction(GoBackAction), m_ui->actionGoBack);
	updateAction(m_windowsManager->getAction(RewindAction), m_ui->actionRewind);
	updateAction(m_windowsManager->getAction(GoForwardAction), m_ui->actionGoForward);
	updateAction(m_windowsManager->getAction(FastForwardAction), m_ui->actionFastForward);

	const bool canZoom = m_windowsManager->canZoom();

	m_ui->actionZoomOut->setEnabled(canZoom);
	m_ui->actionZoomIn->setEnabled(canZoom);
	m_ui->actionZoomOriginal->setEnabled(canZoom);
}
Esempio n. 9
0
void PopupMenu::mouseReleaseEvent(QMouseEvent *e)
{
  DEBUG_PRST_ROUTES(stderr, "PopupMenu::mouseReleaseEvent this:%p\n", this);
   if(_contextMenu && _contextMenu->isVisible())
     return;
     
// Removed by Tim. Why not stay-open scrollable menus?
//    if(MusEGlobal::config.scrollableSubMenus)
//    {
//      QMenu::mouseReleaseEvent(e);
//      return;
//    }
   
   QAction* action = actionAt(e->pos());
   if (!(action && action == activeAction() && !action->isSeparator() && action->isEnabled()))
      action=NULL;

#ifdef POPUP_MENU_DISABLE_STAY_OPEN
   if (action && action->menu() != NULL  &&  action->isCheckable())
      action->activate(QAction::Trigger);

   QMenu::mouseReleaseEvent(e);

   if (action && action->menu() != NULL  &&  action->isCheckable())
      close();

   return;

#else
   
  // Check for Ctrl to stay open.
  const bool stay_open = _stayOpen && (MusEGlobal::config.popupsDefaultStayOpen || (e->modifiers() & Qt::ControlModifier));
  // Stay open? Or does the action have a submenu, but also a checkbox of its own?
  if(action && (stay_open || (action->isEnabled() && action->menu() && action->isCheckable())))
  {
    DEBUG_PRST_ROUTES(stderr, "PopupMenu::mouseReleaseEvent: stay open\n");
    action->trigger();  // Trigger the action. 
    e->accept();
    if(!stay_open)
      closeUp();
    return;     // We handled it.
  }
  // Otherwise let ancestor QMenu handle it...
  e->ignore();
  QMenu::mouseReleaseEvent(e);

#endif   // POPUP_MENU_DISABLE_STAY_OPEN
}
Esempio n. 10
0
void InventoryTreeView::contextMenuEvent(QContextMenuEvent *event)
{
    // Do mousePressEvent so that the right item gets selected before we show the menu
    // (right-click doesn't do this automatically).
    QMouseEvent mouseEvent(QEvent::MouseButtonPress, event->pos(), event->globalPos(),
        Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);

    mousePressEvent(&mouseEvent);

    QModelIndex index = selectionModel()->currentIndex();
    if (!index.isValid())
        return;

    QMenu *menu = new QMenu(this);
    QListIterator<QAction *> it(actions());
    while(it.hasNext())
    {
        QAction *action = it.next();
        if (action->isEnabled())
        {
            // This is kind of hack, but we might have case that base language is not english. 
            InventoryAction* act = qobject_cast<InventoryAction* >(action);
            QString text = QApplication::translate("Inventory::InventoryWindow", act->GetText().toStdString().c_str());
            action->setText(text);

            menu->addAction(action);
        } 
   }

    if (menu->actions().size() > 1) // separator "action" is always enabled, hence the 1
        menu->popup(event->globalPos());
}
Esempio n. 11
0
void TestGui::triggerAction(const QString& name)
{
    QAction* action = m_mainWindow->findChild<QAction*>(name);
    QVERIFY(action);
    QVERIFY(action->isEnabled());
    action->trigger();
}
Esempio n. 12
0
QMap<QAction*, QtilitiesCategory> Qtilities::CoreGui::ActionProvider::actionMap(IActionProvider::ActionFilterFlags action_filter, const QtilitiesCategory& category_filter) const {
    // Loop through all actions and inspect them:
    QMap<QAction*, QtilitiesCategory> filtered_map;
    for (int i = 0; i < d->actions.count(); i++) {
        QAction* action = d->actions.keys().at(i);
        bool add_action = true;

        // Check the category:
        if (d->actions.values().at(i) != category_filter && !category_filter.isEmpty())
            add_action = false;

        // Check for IActionProvider::FilterDisabled
        if (action_filter & IActionProvider::FilterDisabled && add_action) {
            if (!action->isEnabled())
                add_action = false;
        }

        // Check for IActionProvider::FilterHidden
        if (action_filter & IActionProvider::FilterHidden && add_action) {
            if (!action->isVisible())
                add_action = false;
        }

        if (add_action)
            filtered_map[d->actions.keys().at(i)] = d->actions.values().at(i);
    }

    return filtered_map;
}
Esempio n. 13
0
bool QActionProto::isEnabled() const
{
  QAction *item = qscriptvalue_cast<QAction*>(thisObject());
  if (item)
    return item->isEnabled();
  return false;
}
Esempio n. 14
0
void Menu::mouseReleaseEvent(QMouseEvent *event)
{
	if (m_role == BookmarksMenuRole && (event->button() == Qt::LeftButton || event->button() == Qt::MiddleButton))
	{
		QAction *action = actionAt(event->pos());

		if (action && action->isEnabled() && action->data().type() == QVariant::ModelIndex)
		{
			QWidget *menu = this;

			while (menu)
			{
				menu->close();
				menu = menu->parentWidget();

				if (!menu || !menu->inherits(QLatin1String("QMenu").data()))
				{
					break;
				}
			}

			MainWindow *mainWindow = MainWindow::findMainWindow(parent());

			if (mainWindow)
			{
				mainWindow->getWindowsManager()->open(dynamic_cast<BookmarksItem*>(BookmarksManager::getModel()->itemFromIndex(action->data().toModelIndex())), WindowsManager::calculateOpenHints(event->modifiers(), event->button()));

				return;
			}
		}
	}

	QMenu::mouseReleaseEvent(event);
}
Esempio n. 15
0
void
ChronoShareGui::openFile()
{
  // figure out who sent the signal
  QAction* pAction = qobject_cast<QAction*>(sender());
  if (pAction->isEnabled()) {
// we stored full path of the file in this toolTip field
#ifdef Q_WS_MAC
    // we do some hack so we could show the file in Finder highlighted
    QStringList args;
    args << "-e";
    args << "tell application \"Finder\"";
    args << "-e";
    args << "activate";
    args << "-e";
    args << "select POSIX file \"" + pAction->toolTip() + "/" + pAction->text() + "\"";
    args << "-e";
    args << "end tell";
    QProcess::startDetached("osascript", args);
#else
    // too bad qt couldn't do highlighting for Linux (or Mac)
    QDesktopServices::openUrl(QUrl("file:///" + pAction->toolTip()));
#endif
  }
}
void WidgetMenuBarMapEditor::mousePressEvent(QMouseEvent *event) {
    QAction *action = this->actionAt(event->pos());
    if (m_selection) {
        if (action != nullptr && action->isEnabled()) {
            updateSelection(action);

            emit selectionChanged();
        }
    }
    else {
        if (action != nullptr && action->text() != "|" && action->isEnabled())
            updateRight(action);
    }

    QMenuBar::mousePressEvent(event);
}
Esempio n. 17
0
void Menu::contextMenuEvent(QContextMenuEvent *event)
{
	if (m_role == BookmarksMenuRole)
	{
		QAction *action = actionAt(event->pos());

		if (action && action->isEnabled() && action->data().type() == QVariant::ModelIndex)
		{
			m_bookmark = dynamic_cast<BookmarksItem*>(BookmarksManager::getModel()->itemFromIndex(action->data().toModelIndex()));

			QMenu contextMenu(this);
			contextMenu.addAction(Utils::getIcon(QLatin1String("document-open")), tr("Open"), this, SLOT(openBookmark()));
			contextMenu.addAction(tr("Open in New Tab"), this, SLOT(openBookmark()))->setData(WindowsManager::NewTabOpen);
			contextMenu.addAction(tr("Open in New Background Tab"), this, SLOT(openBookmark()))->setData(static_cast<int>(WindowsManager::NewTabOpen | WindowsManager::BackgroundOpen));
			contextMenu.addSeparator();
			contextMenu.addAction(tr("Open in New Window"), this, SLOT(openBookmark()))->setData(WindowsManager::NewWindowOpen);
			contextMenu.addAction(tr("Open in New Background Window"), this, SLOT(openBookmark()))->setData(static_cast<int>(WindowsManager::NewWindowOpen | WindowsManager::BackgroundOpen));
			contextMenu.exec(event->globalPos());

			return;
		}
	}

	QMenu::contextMenuEvent(event);
}
Esempio n. 18
0
void ActionsManager::setupLocalAction(QAction *localAction, const QLatin1String &globalAction, bool connectTrigger)
{
	if (!localAction)
	{
		return;
	}

	QAction *action = getAction(globalAction);

	if (action)
	{
		localAction->setCheckable(action->isCheckable());
		localAction->setChecked(action->isChecked());
		localAction->setEnabled(action->isEnabled());
		localAction->setIcon(action->icon());
		localAction->setText(action->text());
		localAction->setShortcut(action->shortcut());
		localAction->setObjectName(action->objectName());

		if (connectTrigger)
		{
			connect(localAction, SIGNAL(triggered()), action, SLOT(trigger()));
		}
	}
}
Esempio n. 19
0
void MenuCallback::actionInvoked()
{
   QAction* action = qobject_cast<QAction*>(sender());
   QString commandId = action->data().toString();
   manageCommand(commandId, action);
   if (action->isEnabled())
      commandInvoked(commandId);
}
Esempio n. 20
0
void OptionsPopup::actionChanged()
{
    QAction *action = qobject_cast<QAction *>(sender());
    QTC_ASSERT(action, return);
    QCheckBox *checkbox = m_checkboxMap.value(action);
    QTC_ASSERT(checkbox, return);
    checkbox->setEnabled(action->isEnabled());
}
Esempio n. 21
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();
}
Esempio n. 22
0
bool KoPageNavigator::eventFilter(QObject *watched, QEvent *event)
{
    if (event->type() == QEvent::FocusOut && watched == d->pageNumberEdit) {
        if (! underMouse()) {
            setCurrentIndex(Display);
        }

        // reset editor in any case
        KoPADocument *const kopaDocument = d->view->kopaDocument();
        KoPAPageBase *const activePage = d->view->activePage();
        const int pageNumber = kopaDocument->pageIndex(activePage) + 1;
        const QString text = (pageNumber > 0) ? QString::number(pageNumber) : QString();
        d->pageNumberEdit->setText(text);
    } else if (event->type() == QEvent::Wheel) {
        // Scroll the pages by the wheel
        // Because the numbers are representatives of the actual pages
        // and the list of pages is ordered by smaller number first,
        // here an increasing delta means going up in the list, so go to
        // smaller page numbers, and vice versa.
        QWheelEvent *wheelEvent = static_cast<QWheelEvent*>(event);
        const int delta = wheelEvent->delta();

        // trigger the respective actions
        if (delta > 0) {
            QAction *gotoPreviousPageAction = d->gotoPreviousPageButton->action();
            if (gotoPreviousPageAction->isEnabled()) {
                gotoPreviousPageAction->activate(QAction::Trigger);
            }
        } else if (delta < 0) {
            QAction *gotoNextPageAction = d->gotoNextPageButton->action();
            if (gotoNextPageAction->isEnabled()) {
                gotoNextPageAction->activate(QAction::Trigger);
            }
        }

        // scroll wheel events also cancel the editing,
        // so move focus out of the pageNumberEdit
        if (d->pageNumberEdit->hasFocus()) {
            d->view->setFocus();
        }
    }

    return false;
}
 void addActionToMenu(KMenu& popup, const char* name)
 {
     QAction* action = mActionCollection->action(name);
     if (!action) {
         kWarning() << "Unknown action" << name;
         return;
     }
     if (action->isEnabled()) {
         popup.addAction(action);
     }
 }
Esempio n. 24
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;
}
Esempio n. 25
0
QCheckBox *OptionsPopup::createCheckboxForCommand(Id id)
{
    QAction *action = ActionManager::command(id)->action();
    QCheckBox *checkbox = new QCheckBox(action->text());
    checkbox->setToolTip(action->toolTip());
    checkbox->setChecked(action->isChecked());
    checkbox->setEnabled(action->isEnabled());
    checkbox->installEventFilter(this); // enter key handling
    QObject::connect(checkbox, &QCheckBox::clicked, action, &QAction::setChecked);
    QObject::connect(action, &QAction::changed, this, &OptionsPopup::actionChanged);
    m_checkboxMap.insert(action, checkbox);
    return checkbox;
}
Esempio n. 26
0
// public void addWebAction(QAction* action, QWebPage::WebAction webAction)
void tst_TabWidget::addWebAction()
{
    QFETCH(QWebPage::WebAction, webAction);

    SubTabWidget widget;

    QSignalSpy spy0(&widget, SIGNAL(linkHovered(const QString &)));
    QSignalSpy spy1(&widget, SIGNAL(loadPage(const QString &)));
    QSignalSpy spy2(&widget, SIGNAL(loadProgress(int)));
    QSignalSpy spy3(&widget, SIGNAL(setCurrentTitle(const QString &)));
    QSignalSpy spy4(&widget, SIGNAL(showStatusBarMessage(const QString &)));
    QSignalSpy spy5(&widget, SIGNAL(tabsChanged()));
    QSignalSpy spy6(&widget, SIGNAL(lastTabClosed()));

    QAction *action = new QAction(&widget);
    widget.addWebAction(action, webAction);

    widget.newTab();
    QVERIFY(!action->isEnabled());

    widget.loadUrl(QUrl("about:config"));
    QUrl url1(":/notfound.html"); //QUrl("http://www.google.com/"));
    QUrl url2(":/notfound2.html"); //QUrl("http://www.yahoo.com/"));
    widget.loadUrl(url1);
    widget.loadUrl(url2);

    QTRY_VERIFY(action->isEnabled());
    widget.newTab();
    QVERIFY(!action->isEnabled());

    QCOMPARE(spy0.count(), 0);
    QCOMPARE(spy1.count(), 0);
    QVERIFY(spy2.count() > 0);
    QCOMPARE(spy3.count(), 8);
    QVERIFY(spy4.count() > 0);
    QCOMPARE(spy5.count(), 6);
    QCOMPARE(spy6.count(), 0);
}
Esempio n. 27
0
void ViewManager::updateDetachViewState()
{
    if (!_actionCollection)
        return;


    bool splitView = _viewSplitter->containers().count() >= 2;
    bool shouldEnable = splitView || _viewSplitter->activeContainer()->views().count() >= 2;

    QAction* detachAction = _actionCollection->action("detach-view");

    if (detachAction && shouldEnable != detachAction->isEnabled())
        detachAction->setEnabled(shouldEnable);
}
Esempio n. 28
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);
    }
Esempio n. 29
0
void HelpWidget::documentChanged()
{
    // A new help document has been selected, resulting in the previous or next
    // help document becoming either available or not

    QAction *action = qobject_cast<QAction *>(sender());

    if (action) {
        // The QObject casting was successful, so we can carry on

        if (action == pageAction(QWebPage::Back)) {
            // The current action is to tell us whether the previous help
            // document is available, so send a signal to let the user know
            // about it

            emit backEnabled(action->isEnabled());
        } else if (action == pageAction(QWebPage::Forward)) {
            // The current action is to tell us whether the next help document
            // is available, so send a signal to let the user know about it

            emit forwardEnabled(action->isEnabled());
        }
    }
}
void ComposerTextEdit::contextMenuEvent(QContextMenuEvent *e)
{
    QScopedPointer<QMenu> menu(createStandardContextMenu(e->pos()));

    // We would like to place the action next to the existing "Paste" item. How to find it? These actions are created
    // in Qt4's src/gui/text/qtextcontrol.cpp, QTextControl::createStandardContextMenu.
    //
    // The first possibility is to take a look at where are these actions connected; we're looking for a connection
    // between triggered() and SLOT(paste()). Unfortunately, it seems that these are only available via QObjectPrivate.
    //
    // Another possibility is to take a look at the shortcuts. Unfortunately, these "shortcuts" are not really "shortcuts"
    // in the sense of "being available via QAction::shortcuts or QAction::shortcuts; they are instead (at least in Qt4)
    // handled via event handlers.
    //
    // Thomas suggested a nice hack, trying the QObject::disconnect. Unfortunately, the QAction is not connected to
    // QTextEdit::paste but to a QTextControl/QWidgetTextControl::paste, and these are private classes, which makes it
    // a tad complicated to find them via QObject::findChildren().
    //
    // The API of QWebView with its standard actions looks like heaven compared to this stuff.
    //
    // This is why we take a look at the action's text and look for a particular string. Yes, it's ugly; patches welcome.
    QAction *pasteAction = 0;
    QString candidateStringForPaste = QKeySequence(QKeySequence::Paste).toString();
    // Finally, the API for adding functions leaves something to be desired; QMenu::insertAction takes a pointer to the
    // "before" thing which is just... annoying here (even though it makes certain amount of sense with addAction which
    // appends).
    QAction *followingActionAfterPaste = 0;
    QList<QAction*> actions = menu->actions();
    for (QList<QAction*>::const_iterator it = actions.constBegin(); it != actions.constEnd() && !pasteAction; ++it) {
        if (!candidateStringForPaste.isEmpty() && (*it)->text().contains(candidateStringForPaste)) {
            pasteAction = *it;
            if (it + 1 != actions.constEnd()) {
                followingActionAfterPaste = *(it + 1);
            }
            break;
        }
    }

    menu->insertAction(followingActionAfterPaste, m_pasteQuoted);
    if (pasteAction) {
        m_pasteQuoted->setEnabled(pasteAction->isEnabled());
    } else {
        m_pasteQuoted->setEnabled(true);
    }
    menu->exec(e->globalPos());
}