Ejemplo n.º 1
2
void PdfViewer::showToolBarStylePopupMenu(const QPoint &pos)
{
	QMenu *popupMenu = new QMenu(this);
	popupMenu->setAttribute(Qt::WA_DeleteOnClose);
	popupMenu->move(mapToGlobal(QPoint(0,0)) + pos);

	QWidgetAction *iconOnlyAction = new QWidgetAction(popupMenu);
	QRadioButton *iconOnlyRadio = new QRadioButton(tr("&Icons Only"), popupMenu);
	iconOnlyAction->setDefaultWidget(iconOnlyRadio);

	QWidgetAction *textOnlyAction = new QWidgetAction(popupMenu);
	QRadioButton *textOnlyRadio = new QRadioButton(tr("&Text Only"), popupMenu);
	textOnlyAction->setDefaultWidget(textOnlyRadio);

	QWidgetAction *textBesideIconAction = new QWidgetAction(popupMenu);
	QRadioButton *textBesideIconRadio = new QRadioButton(tr("Text &Alongside Icons"), popupMenu);
	textBesideIconAction->setDefaultWidget(textBesideIconRadio);

	QWidgetAction *textUnderIconAction = new QWidgetAction(popupMenu);
	QRadioButton *textUnderIconRadio = new QRadioButton(tr("Text &Under Icons"), popupMenu);
	textUnderIconAction->setDefaultWidget(textUnderIconRadio);

	QButtonGroup *popupButtonGroup = new QButtonGroup(popupMenu);
	popupButtonGroup->addButton(iconOnlyRadio);
	popupButtonGroup->addButton(textOnlyRadio);
	popupButtonGroup->addButton(textBesideIconRadio);
	popupButtonGroup->addButton(textUnderIconRadio);
	popupButtonGroup->setId(iconOnlyRadio, 0);
	popupButtonGroup->setId(textOnlyRadio, 1);
	popupButtonGroup->setId(textBesideIconRadio, 2);
	popupButtonGroup->setId(textUnderIconRadio, 3);
	connect(popupButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(slotChangeToolBarStyle(int)));

	popupMenu->addAction(iconOnlyAction);
	popupMenu->addAction(textOnlyAction);
	popupMenu->addAction(textBesideIconAction);
	popupMenu->addAction(textUnderIconAction);
	popupMenu->setContentsMargins(5, 0, 5, 0);

	QSettings settings;
	settings.beginGroup("MainWindow");
	const int toolBarStyleNumber = settings.value("ToolBarStyle", 0).toInt();
	switch (toolBarStyleNumber)
	{
		case 0: iconOnlyRadio->setChecked(true); break;
		case 1: textOnlyRadio->setChecked(true); break;
		case 2: textBesideIconRadio->setChecked(true); break;
		case 3: textUnderIconRadio->setChecked(true); break;
	}
	settings.endGroup();

	popupMenu->show();
	// make sure that the popupMenu stays completely inside the screen (must be done after popupMenu->show() in order to have the correct width)
	const int desktopWidth = QApplication::desktop()->availableGeometry(this).width();
	if (popupMenu->x() + popupMenu->width() > desktopWidth)
		popupMenu->move(desktopWidth - popupMenu->width(), popupMenu->y());
}
bool AnimatedVectorControl::buttonClicked(unsigned int index)
{
	bool isAnimated = m_pairedValue->isAnimated();

	QMenu* m = new QMenu(m_pAnimationButton);
	if (!isAnimated)
	{
		m->addAction(m_actSetAnimated);
	}
	else
	{
		m->addAction(m_actDeleteAnimation);
		m->addAction(m_actSetKey);
		m->addAction(m_actDeleteKey);
		m->addSeparator();

		m->addAction(m_actLinearInterpolation);
		m->addAction(m_actQuadraticInterpolation);
		m->addAction(m_actCubicInterpolation);
	}

	QSize menuSize = m->sizeHint();

	QSize buttonSize = m_pAnimationButton->geometry().size();

	m->move(m_pAnimationButton->mapToGlobal(QPoint(buttonSize.width() - menuSize.width(), buttonSize.height())));
	m->show();

	return false;
}
Ejemplo n.º 3
0
void Strings::mousePressEvent(QMouseEvent *event)
{
    if(event->button()==Qt::RightButton){
        if(reducable_ || closable_ || modifiable_){
            QMenu * menu = new QMenu(this);

            if(modifiable_){
                QAction* actionModify = menu->addAction(tr("Modify"));
                actionModify->setEnabled(false);
                //connect(actionModify,SIGNAL(triggered()),this,SLOT(()));
            }

            if(reducable_){
                QAction* actionReduce = menu->addAction(tr("Reduce"));
                connect(actionReduce,SIGNAL(triggered()),(Guitar*)this->parent(),SLOT(pressReduce()));
            }

            if(closable_){
                QAction* actionClose = menu->addAction(tr("Close"));
                connect(actionClose,SIGNAL(triggered()),(Guitar*)this->parent(),SLOT(pressClose()));
            }

            menu->move(event->globalPos());
            menu->show();
        }
    }
}
bool IndexWindow::eventFilter(QObject *obj, QEvent *e)
{
    if (obj == m_searchLineEdit && e->type() == QEvent::KeyPress) {
        QKeyEvent *ke = static_cast<QKeyEvent*>(e);
        QModelIndex idx = m_indexWidget->currentIndex();
        switch (ke->key()) {
        case Qt::Key_Up:
            idx = m_indexWidget->model()->index(idx.row()-1,
                idx.column(), idx.parent());
            if (idx.isValid())
                m_indexWidget->setCurrentIndex(idx);
            break;
        case Qt::Key_Down:
            idx = m_indexWidget->model()->index(idx.row()+1,
                idx.column(), idx.parent());
            if (idx.isValid())
                m_indexWidget->setCurrentIndex(idx);
            break;
        case Qt::Key_Escape:
            MainWindow::activateCurrentCentralWidgetTab();
            break;
        default:
            ;
        }
    } else if (obj == m_indexWidget && e->type() == QEvent::ContextMenu) {
        QContextMenuEvent *ctxtEvent = static_cast<QContextMenuEvent*>(e);
        QModelIndex idx = m_indexWidget->indexAt(ctxtEvent->pos());
        if (idx.isValid()) {
            QMenu menu;
            QAction *curTab = menu.addAction(tr("Open Link"));
            QAction *newTab = menu.addAction(tr("Open Link in New Tab"));
            menu.move(m_indexWidget->mapToGlobal(ctxtEvent->pos()));

            QAction *action = menu.exec();
            if (curTab == action)
                m_indexWidget->activateCurrentItem();
            else if (newTab == action) {
                QHelpIndexModel *model = qobject_cast<QHelpIndexModel*>(m_indexWidget->model());
                QString keyword = model->data(idx, Qt::DisplayRole).toString();
                if (model) {
                    QMap<QString, QUrl> links = model->linksForKeyword(keyword);
                    if (links.count() == 1) {
                        CentralWidget::instance()->setSourceInNewTab(links.constBegin().value());
                    } else {
                        TopicChooser tc(this, keyword, links);
                        if (tc.exec() == QDialog::Accepted) {
                            CentralWidget::instance()->setSourceInNewTab(tc.link());
                        }
                    }
                }
            }
        }
    }
    return QWidget::eventFilter(obj, e);
}
Ejemplo n.º 5
0
void QDesignerMenuBar::showMenu(int index)
{
    if (index < 0 && m_currentIndex >= 0)
        index = m_currentIndex;

    if (index < 0 || index >= realActionCount())
        return;

    m_currentIndex = index;
    QAction *action = currentAction();

    if (action && action->menu()) {
        if (m_lastMenuActionIndex != -1 && m_lastMenuActionIndex != index) {
            hideMenu(m_lastMenuActionIndex);
        }

        m_lastMenuActionIndex = index;
        QMenu *menu = action->menu();
        const QRect g = actionGeometry(action);

        if (!menu->isVisible()) {
            if ((menu->windowFlags() & Qt::Popup) != Qt::Popup)
                menu->setWindowFlags(Qt::Popup);
            menu->adjustSize();
            if (layoutDirection() == Qt::LeftToRight) {
                menu->move(mapToGlobal(g.bottomLeft()));
            } else {
                // The position is not initially correct due to the unknown width,
                // causing it to overlap a bit the first time it is invoked.
                const QSize menuSize = menu->size();
                QPoint point = g.bottomRight() - QPoint(menu->width(), 0);
                menu->move(mapToGlobal(point));
            }
            menu->setFocus(Qt::MouseFocusReason);
            menu->raise();
            menu->show();
        } else {
            menu->raise();
        }
    }
}
Ejemplo n.º 6
0
void FileFrame::contextMenuEvent(QContextMenuEvent *event) {
  QMenu menu;
  menu.move(event->globalPos());
  auto open = menu.addAction("&Open");
  auto del = menu.addAction("&Delete");

  connect(open, &QAction::triggered,
                 [=]() { emit OpenRequested(file_name_); });
  connect(del, &QAction::triggered,
                 [=]() { emit DeleteRequested(file_name_); });

  menu.exec();
}
Ejemplo n.º 7
0
void FileViewFloatItem::contextMenu( const QPoint& pos )
{
    if( !m_marbleWidget )
        return;

    QMenu *test = new QMenu( m_fileView );
    // We need the global position to move the menu.
    // pos contains the relative position.
    test->move( m_itemPosition );
    connect( test->addAction( tr( "Open file..." ) ), SIGNAL(triggered()),
             this, SLOT(addFile()) );
    connect( test->addAction( tr( "Close this file" ) ), SIGNAL(triggered()),
             this, SLOT(removeFile()) );
    m_persIndex = new QPersistentModelIndex( m_fileView->indexAt( pos ) );
    test->exec();
}
Ejemplo n.º 8
0
QMenu *Cutegram::contextMenu()
{
    QMenu *menu = new QMenu();
    menu->move( QCursor::pos() );

    menu->addAction( tr("Show"), this, SLOT(active()) );
    menu->addSeparator();
    menu->addAction( tr("Configure"), this, SLOT(configure()) );
    menu->addAction( tr("Contact"), this, SLOT(contact()) );
    menu->addSeparator();
    menu->addAction( tr("About"), this, SLOT(about()) );
    menu->addAction( tr("About Aseman"), this, SLOT(aboutAseman()) );
    menu->addSeparator();
    menu->addAction( tr("Exit"), this, SLOT(quit()) );

    return menu;
}
Ejemplo n.º 9
0
void FSTableView::contextMenuEvent(QContextMenuEvent * event)
{
    QModelIndex index = indexAt(event->pos());
    QMenu * menu = 0;
    if (index.isValid())
    {
        if (selectionModel()->selectedRows().count() > 1)
            menu = createSelectionMenu();
        else
            menu = createItemMenu();

    }
    else
        menu = createMenu();

    menu->move(event->globalPos());
    menu->exec();
    delete menu;

}
Ejemplo n.º 10
0
void ContentWindow::showContextMenu(const QPoint &pos)
{
    if (!m_contentWidget->indexAt(pos).isValid())
        return;

    QHelpContentModel *contentModel =
        qobject_cast<QHelpContentModel*>(m_contentWidget->model());
    QHelpContentItem *itm =
        contentModel->contentItemAt(m_contentWidget->currentIndex());

    QMenu menu;
    QAction *curTab = menu.addAction(tr("Open Link"));
    QAction *newTab = menu.addAction(tr("Open Link as New Page"));
    if (!HelpViewer::canOpenPage(itm->url().path()))
        newTab->setEnabled(false);

    menu.move(m_contentWidget->mapToGlobal(pos));

    QAction *action = menu.exec();
    if (curTab == action)
        emit linkActivated(itm->url());
    else if (newTab == action)
        OpenPagesManager::instance().createPage(itm->url());
}
Ejemplo n.º 11
0
void ContentWindow::showContextMenu(const QPoint &pos)
{
    if (!m_contentWidget->indexAt(pos).isValid())
        return;

    QHelpContentModel *contentModel =
        qobject_cast<QHelpContentModel*>(m_contentWidget->model());
    QHelpContentItem *itm =
        contentModel->contentItemAt(m_contentWidget->currentIndex());

    QMenu menu;
    QAction *curTab = menu.addAction(tr("Open Link"));
    QAction *newTab = menu.addAction(tr("Open Link in New Tab"));
    if (isPdfFile(itm))
        newTab->setEnabled(false);
    
    menu.move(m_contentWidget->mapToGlobal(pos));

    QAction *action = menu.exec();
    if (curTab == action)
        emit linkActivated(itm->url());
    else if (newTab == action)
        CentralWidget::instance()->setSourceInNewTab(itm->url());
}
Ejemplo n.º 12
0
bool IndexWindow::eventFilter(QObject *obj, QEvent *e)
{
    if (obj == m_searchLineEdit && e->type() == QEvent::KeyPress) {
        QKeyEvent *ke = static_cast<QKeyEvent*>(e);
        QModelIndex idx = m_indexWidget->currentIndex();
        switch (ke->key()) {
        case Qt::Key_Up:
            idx = m_indexWidget->model()->index(idx.row()-1,
                idx.column(), idx.parent());
            if (idx.isValid())
                m_indexWidget->setCurrentIndex(idx);
            break;
        case Qt::Key_Down:
            idx = m_indexWidget->model()->index(idx.row()+1,
                idx.column(), idx.parent());
            if (idx.isValid())
                m_indexWidget->setCurrentIndex(idx);
            break;
        default: ; // stop complaining
        }
    } else if (obj == m_searchLineEdit
            && e->type() == QEvent::FocusIn
            && static_cast<QFocusEvent *>(e)->reason() != Qt::MouseFocusReason) {
        m_searchLineEdit->selectAll();
        m_searchLineEdit->setFocus();
    } else if (obj == m_indexWidget && e->type() == QEvent::ContextMenu) {
        QContextMenuEvent *ctxtEvent = static_cast<QContextMenuEvent*>(e);
        QModelIndex idx = m_indexWidget->indexAt(ctxtEvent->pos());
        if (idx.isValid()) {
            QMenu menu;
            QAction *curTab = menu.addAction(tr("Open Link"));
            QAction *newTab = menu.addAction(tr("Open Link as New Page"));
            menu.move(m_indexWidget->mapToGlobal(ctxtEvent->pos()));

            QAction *action = menu.exec();
            if (curTab == action)
                m_indexWidget->activateCurrentItem();
            else if (newTab == action) {
                open(m_indexWidget, idx);
            }
        }
    } else if (m_indexWidget && obj == m_indexWidget->viewport()
        && e->type() == QEvent::MouseButtonRelease) {
        QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(e);
        QModelIndex idx = m_indexWidget->indexAt(mouseEvent->pos());
        if (idx.isValid()) {
            Qt::MouseButtons button = mouseEvent->button();
            if (((button == Qt::LeftButton) && (mouseEvent->modifiers() & Qt::ControlModifier))
                || (button == Qt::MidButton)) {
                open(m_indexWidget, idx);
            }
        }
    }
    else if (Utils::HostOsInfo::isMacHost() && obj == m_indexWidget
             && e->type() == QEvent::KeyPress) {
        QKeyEvent *ke = static_cast<QKeyEvent*>(e);
        if (ke->key() == Qt::Key_Return || ke->key() == Qt::Key_Enter)
           m_indexWidget->activateCurrentItem();
    }

    return QWidget::eventFilter(obj, e);
}
Ejemplo n.º 13
0
bool HelpIndexView::eventFilter(QObject *obj, QEvent *e)
{
  if (obj == m_SearchLineEdit && e->type() == QEvent::KeyPress)
  {
    QKeyEvent *ke = static_cast<QKeyEvent*>(e);
    QModelIndex idx = m_IndexWidget->currentIndex();
    switch (ke->key())
    {
    case Qt::Key_Up:
      idx = m_IndexWidget->model()->index(idx.row()-1,
                                          idx.column(), idx.parent());
      if (idx.isValid())
      {
        m_IndexWidget->setCurrentIndex(idx);
        return true;
      }
      break;
    case Qt::Key_Down:
      idx = m_IndexWidget->model()->index(idx.row()+1,
                                          idx.column(), idx.parent());
      if (idx.isValid())
      {
        m_IndexWidget->setCurrentIndex(idx);
        return true;
      }
      break;
    default: ; // stop complaining
    }
  }
  else if (obj == m_IndexWidget && e->type() == QEvent::ContextMenu)
  {
    QContextMenuEvent *ctxtEvent = static_cast<QContextMenuEvent*>(e);
    QModelIndex idx = m_IndexWidget->indexAt(ctxtEvent->pos());
    if (idx.isValid())
    {
      QMenu menu;
      QAction *curTab = menu.addAction(tr("Open Link"));
      QAction *newTab = menu.addAction(tr("Open Link in New Tab"));
      menu.move(m_IndexWidget->mapToGlobal(ctxtEvent->pos()));

      QAction *action = menu.exec();
      if (curTab == action)
        m_IndexWidget->activateCurrentItem();
      else if (newTab == action)
      {
        open(m_IndexWidget, idx);
      }
    }
  }
  else if (m_IndexWidget && obj == m_IndexWidget->viewport()
           && e->type() == QEvent::MouseButtonRelease)
  {
    QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(e);
    QModelIndex idx = m_IndexWidget->indexAt(mouseEvent->pos());
    if (idx.isValid())
    {
      Qt::MouseButtons button = mouseEvent->button();
      if (((button == Qt::LeftButton) && (mouseEvent->modifiers() & Qt::ControlModifier))
          || (button == Qt::MidButton))
      {
        open(m_IndexWidget, idx);
      }
    }
  }
#ifdef Q_OS_MAC
  else if (obj == m_IndexWidget && e->type() == QEvent::KeyPress)
  {
    QKeyEvent *ke = static_cast<QKeyEvent*>(e);
    if (ke->key() == Qt::Key_Return || ke->key() == Qt::Key_Enter)
      m_IndexWidget->activateCurrentItem();
  }
#endif
  return QObject::eventFilter(obj, e);
}