void SGSelectionTool::createContextMenu(const QList<QSGItem *> &items, QPoint pos)
{
    QMenu contextMenu;
    connect(&contextMenu, SIGNAL(hovered(QAction*)),
            this, SLOT(contextMenuElementHovered(QAction*)));

    const QList<QSGItem*> selectedItems = inspector()->selectedItems();
    int shortcutKey = Qt::Key_1;

    foreach (QSGItem *item, items) {
        const QString title = inspector()->titleForItem(item);
        QAction *elementAction = contextMenu.addAction(title);
        elementAction->setData(QVariant::fromValue(item));

        connect(elementAction, SIGNAL(triggered()), this, SLOT(contextMenuElementSelected()));

        if (selectedItems.contains(item)) {
            QFont font = elementAction->font();
            font.setBold(true);
            elementAction->setFont(font);
        }

        if (shortcutKey <= Qt::Key_9) {
            elementAction->setShortcut(QKeySequence(shortcutKey));
            shortcutKey++;
        }
    }

    contextMenu.exec(pos);
}
Example #2
0
void NMainMenuBar::createThemeMenu(QMenu *parentMenu) {
    QMenu *menu = parentMenu->addMenu(tr("Theme"));
    QStringList list = global.getThemeNames();
    QFont f = global.getGuiFont(QFont());

    global.settings->beginGroup(INI_GROUP_APPEARANCE);
    QString userTheme = global.settings->value("themeName", DEFAULT_THEME_NAME).toString();
    global.settings->endGroup();


    // Setup themes (we expect to find the DEFAULT_THEME_NAME theme as first one)
    for (int i = 0; i < list.size(); i++) {
        QString themeName(list[i]);
        if ((i == 0) && (QString::compare(themeName, DEFAULT_THEME_NAME, Qt::CaseInsensitive) != 0)) {
            QLOG_ERROR() << "First theme is expected to be " << DEFAULT_THEME_NAME;
        }


        QAction *themeAction = new QAction(themeName, this);
        themeAction->setData(themeName);
        themeAction->setCheckable(true);
        themeAction->setFont(f);
        connect(themeAction, SIGNAL(triggered()), parent, SLOT(reloadIcons()));
        if (themeName == userTheme) {
            themeAction->setChecked(true);
        }
        themeActions.append(themeAction);
    }
    menu->addActions(themeActions);
    menu->setFont(f);
}
Example #3
0
void LiveSelectionTool::createContextMenu(const QList<QGraphicsItem*> &itemList, QPoint globalPos)
{
    QMenu contextMenu;
    connect(&contextMenu, SIGNAL(hovered(QAction*)),
            this, SLOT(contextMenuElementHovered(QAction*)));

    m_contextMenuItemList = itemList;

    contextMenu.addAction(tr("Items"));
    contextMenu.addSeparator();
    int shortcutKey = Qt::Key_1;
    int i = 0;

    foreach (QGraphicsItem * const item, itemList) {
        QString itemTitle = titleForItem(item);
        QAction *elementAction = contextMenu.addAction(itemTitle, this,
                                                       SLOT(contextMenuElementSelected()));

        if (inspector()->selectedItems().contains(item)) {
            QFont boldFont = elementAction->font();
            boldFont.setBold(true);
            elementAction->setFont(boldFont);
        }

        elementAction->setData(i);

        if (shortcutKey <= Qt::Key_9) {
            elementAction->setShortcut(QKeySequence(shortcutKey));
            shortcutKey++;
        }

        ++i;
    }
/** Creates a new action associated with a config page. */
QAction* ApplicationWindow::createPageAction(QIcon img, QString text, QActionGroup *group)
{
    QAction *action = new QAction(img, text, group);
    action->setCheckable(true);
    action->setFont(FONT);
    return action;
}
Example #5
0
QAction* ActionResource::toQAction() const {
    Log log( Log::LT_TRACE, Log::MOD_MAIN, "QAction* ActionResource::toQAction() const" );

    if( !( m_Type == AT_ITEM || m_Type == AT_SEPARATOR ) ) {
        return NULL;
    };

    log.write( Log::LT_TRACE, "Produce item %s", getText() );
    QAction* act = new QAction( getText(), NULL );
    act->setAutoRepeat( getAutoRepeat() );
    act->setCheckable( getCheckable() );
    act->setChecked( getChecked() );
    act->setData( getData() );
    act->setFont( getFont() );
    act->setIcon( getIcon() );
    act->setIconVisibleInMenu( getIconVisibleInMenu() );
    act->setMenuRole( getMenuRole() );
    act->setSeparator( m_Type == AT_SEPARATOR );
    act->setShortcut( getShortcut() );
    act->setShortcutContext( getShortcutContext() );
    act->setStatusTip( getStatusTip() );
    act->setToolTip( getTooltip() );
    act->setVisible( getVisible() );
    act->setWhatsThis( getWhatsThis() );

    return act;
};
Example #6
0
void Pane::on_list_customContextMenuRequested(const QPoint &pos) {
  File_info file = file_list_model.get_file_info(ui->list->indexAt(pos));
  App_info_list apps = main_window->get_apps(file.mime_type);
  QMenu* menu = new QMenu(this);
  if (file.is_folder()) {
    menu->addAction(tr("Browse"))->setEnabled(false);
  }
  if (file.is_file) {
    menu->addAction(main_window->get_ui()->action_view);
    menu->addAction(main_window->get_ui()->action_edit);
  }
  if (file.is_executable) {
    menu->addAction(main_window->get_ui()->action_execute);
  }
  if (menu->actions().count() > 0) menu->addSeparator();

  foreach(App_info app, apps) {
    QAction* a = menu->addAction(tr("Open with %1 (%2)").arg(app.name()).arg(app.command()), this, SLOT(action_launch_triggered()));
    QVariantList data;
    data << QVariant::fromValue(app) << QVariant::fromValue(file);
    a->setData(data);
    if (app == apps.default_app) {
      QFont f = a->font();
      f.setBold(true);
      a->setFont(f);
    }
  }
Example #7
0
void SessionListWidget::contextMenuEvent(QContextMenuEvent *event)
{
   QModelIndex index = indexAt(event->pos());
   if (index.isValid()) {
      JobDefinition &job = sessions[index.row()];
      qDebug() << job;

      QMenu *menu = new QMenu(this);
      QAction *action;
      switch(job.status) {
         case JobDefinition::QUEUED: {
            action = new QAction("Delete session", this);
            action->setData(qVariantFromValue(&job));
            connect(action, SIGNAL(triggered()), this, SLOT(removeSessionSlot()));
            menu->addAction(action);

            break;
         }

         case JobDefinition::HELD: {
            action = new QAction("Resume session", this);
            action->setData(qVariantFromValue(&job));
            connect(action, SIGNAL(triggered()), this, SLOT(releaseSessionSlot()));
            menu->addAction(action);

            action = new QAction("Delete session", this);
            action->setData(qVariantFromValue(&job));
            connect(action, SIGNAL(triggered()), this, SLOT(removeSessionSlot()));
            menu->addAction(action);

            break;
         }

         case JobDefinition::RUNNING: {
            action = new QAction("View session", this);
            QFont f = action->font();
            f.setBold(true);
            action->setFont(f);
            action->setData(qVariantFromValue(&job));
            connect(action, SIGNAL(triggered()), this, SLOT(viewSessionSlot()));
            menu->addAction(action);

            action = new QAction("Delete session", this);
            action->setData(qVariantFromValue(&job));
            connect(action, SIGNAL(triggered()), this, SLOT(removeSessionSlot()));
            menu->addAction(action);

            break;
         }

         case JobDefinition::FINISHED: {
            menu->addAction("Resume session [TODO]");
            break;
         }
      }

      menu->exec(QCursor::pos());
   }
}
static QAction* italicTextItem(const QString& s)
{
    QAction* act = new QAction(s, NULL);
    QFont italicFont = act->font();
    italicFont.setItalic(true);
    act->setFont(italicFont);

    return act;
}
static QAction* boldTextItem(const QString& s)
{
    QAction* act = new QAction(s, NULL);
    QFont boldFont = act->font();
    boldFont.setBold(true);
    act->setFont(boldFont);

    return act;
}
Example #10
0
void MenuFactory::createTitle(
    QMenu& menu,
    const QString& title )
{
    QAction* pItem = menu.addAction( title );
    QFont font = menu.font();
    font.setBold( true );
    pItem->setFont( font );
    pItem->setEnabled( false );
}
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
// helpers
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
void FileSystemBrowser::addGroupMarkToMenu( QString text )
{
    QFont   font;
            font.setBold( true );
            font.setStyle( QFont::StyleOblique );

    QAction* action = 0;

    action = _fileBrowserMenu.addAction( QString("~~~~~ %1 ~~~~~").arg(text) );
    action->setFont( font );
}
/** Constructor */
FeedReaderFeedItem::FeedReaderFeedItem(RsFeedReader *feedReader, FeedReaderNotify *notify, FeedHolder *parent, const FeedInfo &feedInfo, const FeedMsgInfo &msgInfo)
    : QWidget(NULL), mFeedReader(feedReader), mNotify(notify), mParent(parent), ui(new Ui::FeedReaderFeedItem)
{
    /* Invoke the Qt Designer generated object setup routine */
    ui->setupUi(this);

    setAttribute(Qt::WA_DeleteOnClose, true);

    connect(ui->expandButton, SIGNAL(clicked(void)), this, SLOT(toggle(void)));
    connect(ui->clearButton, SIGNAL(clicked(void)), this, SLOT(removeItem(void)));
    connect(ui->readAndClearButton, SIGNAL(clicked()), this, SLOT(readAndClearItem()));
    connect(ui->linkButton, SIGNAL(clicked()), this, SLOT(openLink()));

    connect(mNotify, SIGNAL(msgChanged(QString,QString,int)), this, SLOT(msgChanged(QString,QString,int)), Qt::QueuedConnection);

    ui->expandFrame->hide();

    mFeedId = feedInfo.feedId;
    mMsgId = msgInfo.msgId;

    if (feedInfo.icon.empty()) {
        ui->feedIconLabel->hide();
    } else {
        /* use icon from feed */
        QPixmap pixmap;
        if (pixmap.loadFromData(QByteArray::fromBase64(feedInfo.icon.c_str()))) {
            ui->feedIconLabel->setPixmap(pixmap.scaled(16, 16, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
        } else {
            ui->feedIconLabel->hide();
        }
    }

    ui->titleLabel->setText(QString::fromUtf8(feedInfo.name.c_str()));
    ui->msgTitleLabel->setText(QString::fromUtf8(msgInfo.title.c_str()));
    ui->descriptionLabel->setText(QString::fromUtf8((msgInfo.descriptionTransformed.empty() ? msgInfo.description : msgInfo.descriptionTransformed).c_str()));

    ui->dateTimeLabel->setText(DateTime::formatLongDateTime(msgInfo.pubDate));

    /* build menu for link button */
    mLink = QString::fromUtf8(msgInfo.link.c_str());
    if (mLink.isEmpty()) {
        ui->linkButton->setEnabled(false);
    } else {
        QMenu *menu = new QMenu(this);
        QAction *action = menu->addAction(tr("Open link in browser"), this, SLOT(openLink()));
        menu->addAction(tr("Copy link to clipboard"), this, SLOT(copyLink()));

        QFont font = action->font();
        font.setBold(true);
        action->setFont(font);

        ui->linkButton->setMenu(menu);
    }
}
Example #13
0
void Favorites::markCurrent()
{
    for (int n = FIRST_MENU_ENTRY; n < _menu->actions().count(); n++)
    {
        QAction * a = _menu->actions()[n];
        QString file = a->data().toString();
        QFont f = a->font();

        if (file == current_file)
        {
            f.setBold(true);
            a->setFont( f );
        }
        else
        {
            f.setBold(false);
            a->setFont( f );
        }
    }
}
Example #14
0
QAction * QMenuViewPrivate::makeAction(const QModelIndex &index)
{
	QIcon icon = qvariant_cast<QIcon>(index.data(Qt::DecorationRole));
	QAction * action = new QAction(icon, index.data().toString(), this);
	action->setEnabled(index.flags().testFlag(Qt::ItemIsEnabled));
	// improvements for Qlipper (petr vanek <*****@*****.**>
	action->setFont(qvariant_cast<QFont>(index.data(Qt::FontRole)));
	action->setToolTip(index.data(Qt::ToolTipRole).toString());
	// end of qlipper improvements
	QVariant v;
	v.setValue(index);
	action->setData(v);

	return action;
}
Example #15
0
void NMainMenuBar::addSortAction(QMenu *menu, QActionGroup *menuActionGroup, const QFont &f, QString name,
                                 QString code) {
    QString currentSortOrder = global.getSortOrder();

    QAction *action = new QAction(name, this);
    action->setData(code);
    action->setCheckable(true);
    if (QString::compare(code, currentSortOrder) == 0) {
        action->setChecked(true);
    }

    action->setFont(f);
    menuActionGroup->addAction(action);
    connect(action, SIGNAL(triggered()), this, SLOT(onSortMenuTriggered()));
    menu->addAction(action);
}
Example #16
0
void
ComboBox::addItemNew()
{
    if (_cascading) {
        qDebug() << "ComboBox::addItemNew unsupported when in cascading mode";

        return;
    }
    QAction* action =  new QAction(this);
    action->setText( QString::fromUtf8("New") );
    action->setData( QString::fromUtf8("New") );
    QFont f = QFont(appFont, appFontSize);
    f.setItalic(true);
    action->setFont(f);
    addActionPrivate(action);
}
Example #17
0
void Speller::populateContextMenu(QMenu* menu, const QWebHitTestResult &hitTest)
{
    m_element = hitTest.element();

    if (!m_enabled || m_element.isNull() ||
            m_element.attribute(QLatin1String("type")) == QLatin1String("password")) {
        return;
    }

    const QString text = m_element.evaluateJavaScript("this.value").toString();
    const int pos = m_element.evaluateJavaScript("this.selectionStart").toInt() + 1;

    QTextBoundaryFinder finder =  QTextBoundaryFinder(QTextBoundaryFinder::Word, text);
    finder.setPosition(pos);
    m_startPos = finder.toPreviousBoundary();
    m_endPos = finder.toNextBoundary();

    const QString &word = text.mid(m_startPos, m_endPos - m_startPos).trimmed();

    if (!isValidWord(word) || !isMisspelled(word)) {
        return;
    }

    const int limit = 6;
    QStringList suggests = suggest(word);
    int count = suggests.count() > limit ? limit : suggests.count();

    QFont boldFont = menu->font();
    boldFont.setBold(true);

    for (int i = 0; i < count; ++i) {
        QAction* act = menu->addAction(suggests.at(i), this, SLOT(replaceWord()));
        act->setData(suggests.at(i));
        act->setFont(boldFont);
    }

    if (count == 0) {
        menu->addAction(tr("No suggestions"))->setEnabled(false);
    }

    menu->addAction(tr("Add to dictionary"), this, SLOT(addToDictionary()))->setData(word);
    menu->addSeparator();
}
Example #18
0
void TabWidget::updateTabsMenu()
{
	TabsMenu->clear();

	for (int i = 0; i < count(); i++)
	{
		QAction *action = new QAction(QIcon(), tabText(i), this);
		action->setData(QVariant(i));

		if (i == tabBar()->currentIndex())
		{
			QFont font = action->font();
			font.setBold(true);
			action->setFont(font);
		}

		TabsMenu->addAction(action);
	}
}
Example #19
0
/* Create individual actions */
QAction* QMenuView::createActionFromIndex( QModelIndex index )
{
    QIcon icon = qvariant_cast<QIcon>( index.data( Qt::DecorationRole ) );
    QAction * action = new QAction( icon, index.data().toString(), this );

    /* Display in bold the active element */
    if( index.data( VLCModel::CURRENT_ITEM_ROLE ).toBool() )
    {
        QFont font; font.setBold ( true );
        action->setFont( font );
    }

    /* Some items could be hypothetically disabled */
    action->setEnabled( index.flags().testFlag( Qt::ItemIsEnabled ) );

    /* */
    QVariant variant; variant.setValue( QPersistentModelIndex( index ) );
    action->setData( variant );

    return action;
}
Example #20
0
MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
{
    setupUi(this);
    m_dict = 0;
    translationView->setDict(m_dict);

    QFont font;
    font.setPointSize(16);

    menu_File->insertActions(actionQuit, translationView->toolBar()->actions());

    QAction *actionWordsListDock = wordsListDock->toggleViewAction();
    menu_Options->insertAction(menu_Options->actions().first(), actionWordsListDock);
    actionWordsListDock->setFont(font);
    //wordsList->setProperty("FingerScrollable", true);
    //translationView->setProperty("FingerScrollable", true);
    createConnections();

    loadSettings();
}
Example #21
0
QAction* KMenu::addTitle(const QIcon &icon, const QString &text, QAction* before)
{
    QAction *buttonAction = new QAction(this);
    QFont font = buttonAction->font();
    font.setBold(true);
    buttonAction->setFont(font);
    buttonAction->setText(text);
    buttonAction->setIcon(icon);

    QWidgetAction *action = new QWidgetAction(this);
    action->setObjectName(KMENU_TITLE);
    QToolButton *titleButton = new QToolButton(this);
    titleButton->installEventFilter(d); // prevent clicks on the title of the menu
    titleButton->setDefaultAction(buttonAction);
    titleButton->setDown(true); // prevent hover style changes in some styles
    titleButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
    action->setDefaultWidget(titleButton);

    insertAction(before, action);
    return action;
}
Example #22
0
void MainStatusBar::showProfileMenu(const QPoint &global_pos, Qt::MouseButton button)
{
    const gchar *profile_name = get_profile_name();
    bool separator_added = false;
    GList *fl_entry;
    profile_def *profile;
    QAction *pa;

    init_profile_list();
    fl_entry = current_profile_list();

    profile_menu_.clear();
    while (fl_entry && fl_entry->data) {
        profile = (profile_def *) fl_entry->data;
        if (!profile->is_global || !profile_exists(profile->name, false)) {
            if (profile->is_global && !separator_added) {
                profile_menu_.addSeparator();
                separator_added = true;
            }
            pa = profile_menu_.addAction(profile->name);
            if (strcmp(profile->name, profile_name) == 0) {
                /* Bold current profile */
                QFont pa_font = pa->font();
                pa_font.setBold(true);
                pa->setFont(pa_font);
                pa->setCheckable(true);
                pa->setChecked(true);
            }
            connect(pa, SIGNAL(triggered()), this, SLOT(switchToProfile()));
        }
        fl_entry = g_list_next(fl_entry);
    }

    if (button == Qt::LeftButton) {
        profile_menu_.exec(global_pos);
    } else {
        ctx_menu_.exec(global_pos);
    }
}
Example #23
0
// Read in all of the data and build the menu.
void NotebookMenuButton::loadData() {
    rootMenu.clear();
    NotebookTable notebookTable;

    QList<qint32> lids;
    notebookTable.getAll(lids);

    if (notebookTable.findByName(currentNotebookName) <= 0)
        currentNotebookName = "";

    for (qint32 i=0; i<lids.size(); i++) {
        Notebook book;
        if (notebookTable.get(book, lids[i])) {

            QAction *action = new QAction(this);
            actions.append(action);
            action->setText(QString::fromStdString(book.name));
            action->setCheckable(true);
            connect(action, SIGNAL(triggered()), this, SLOT(notebookSelected()));
            QFont f = action->font();
            f.setPixelSize(10);
            action->setFont(f);
            QMenu *currentMenu = findStack(book);

            addNotebookMenuItem(currentMenu, action);

            if (currentNotebookName == "" && book.__isset.defaultNotebook &&
                    book.defaultNotebook) {
                currentNotebookName = QString::fromStdString(book.name);
                setText(currentNotebookName);
                currentAction = actions.size()-1;
            }
            if (QString::fromStdString(book.name) == currentNotebookName) {
                action->setChecked(true);
            }
        }
    }
}
void LiveSelectionTool::createContextMenu(QList<QGraphicsItem*> itemList, QPoint globalPos)
{
    if (!QDeclarativeViewObserverPrivate::get(observer())->mouseInsideContextItem())
        return;

    QMenu contextMenu;
    connect(&contextMenu, SIGNAL(hovered(QAction*)),
            this, SLOT(contextMenuElementHovered(QAction*)));

    m_contextMenuItemList = itemList;

    contextMenu.addAction("Items");
    contextMenu.addSeparator();
    int shortcutKey = Qt::Key_1;
    bool addKeySequence = true;
    int i = 0;

    foreach (QGraphicsItem * const item, itemList) {
        QString itemTitle = titleForItem(item);
        QAction *elementAction = contextMenu.addAction(itemTitle, this,
                                                       SLOT(contextMenuElementSelected()));

        if (observer()->selectedItems().contains(item)) {
            QFont boldFont = elementAction->font();
            boldFont.setBold(true);
            elementAction->setFont(boldFont);
        }

        elementAction->setData(i);
        if (addKeySequence)
            elementAction->setShortcut(QKeySequence(shortcutKey));

        shortcutKey++;
        if (shortcutKey > Qt::Key_9)
            addKeySequence = false;

        ++i;
    }
Example #25
0
void NewsButton::showNewsMenu()
{
    auto newsFeedMenu = new QMenu;
    auto &feed = NewsFeed::instance();

    for (const NewsItem &newsItem : feed.newsItems()) {
        QAction *action = newsFeedMenu->addAction(newsItem.title);

        if (feed.isUnread(newsItem)) {
            QFont f = action->font();
            f.setBold(true);
            action->setFont(f);
            action->setIcon(mUnreadIcon);
        } else {
            action->setIcon(mReadIcon);
        }

        connect(action, &QAction::triggered, [=] {
            QDesktopServices::openUrl(newsItem.link);
            NewsFeed::instance().markRead(newsItem);
        });
    }

    newsFeedMenu->addSeparator();
    QAction *action = newsFeedMenu->addAction(tr("News Archive"));
    connect(action, &QAction::triggered, [] {
        QDesktopServices::openUrl(QUrl(QLatin1String(newsArchiveUrl)));
        NewsFeed::instance().markAllRead();
    });

    auto size = newsFeedMenu->sizeHint();
    auto rect = QRect(mapToGlobal(QPoint(width() - size.width(), -size.height())), size);
    newsFeedMenu->setGeometry(rect);
    newsFeedMenu->exec();

    setDown(false);
}
Example #26
0
File: toolbar.cpp Project: BGmot/Qt
ToolBar::ToolBar(const QString &title, QWidget *parent)
    : QToolBar(parent), spinbox(0), spinboxAction(0)
{
    tip = 0;
    setWindowTitle(title);
    setObjectName(title);

    setIconSize(QSize(32, 32));

    QColor bg(palette().background().color());
    menu = new QMenu("One", this);
    menu->setIcon(genIcon(iconSize(), 1, Qt::black));
    menu->addAction(genIcon(iconSize(), "A", Qt::blue), "A");
    menu->addAction(genIcon(iconSize(), "B", Qt::blue), "B");
    menu->addAction(genIcon(iconSize(), "C", Qt::blue), "C");
    addAction(menu->menuAction());

    QAction *two = addAction(genIcon(iconSize(), 2, Qt::white), "Two");
    QFont boldFont;
    boldFont.setBold(true);
    two->setFont(boldFont);

    addAction(genIcon(iconSize(), 3, Qt::red), "Three");
    addAction(genIcon(iconSize(), 4, Qt::green), "Four");
    addAction(genIcon(iconSize(), 5, Qt::blue), "Five");
    addAction(genIcon(iconSize(), 6, Qt::yellow), "Six");
    orderAction = new QAction(this);
    orderAction->setText(tr("Order Items in Tool Bar"));
    connect(orderAction, SIGNAL(triggered()), SLOT(order()));

    randomizeAction = new QAction(this);
    randomizeAction->setText(tr("Randomize Items in Tool Bar"));
    connect(randomizeAction, SIGNAL(triggered()), SLOT(randomize()));

    addSpinBoxAction = new QAction(this);
    addSpinBoxAction->setText(tr("Add Spin Box"));
    connect(addSpinBoxAction, SIGNAL(triggered()), SLOT(addSpinBox()));

    removeSpinBoxAction = new QAction(this);
    removeSpinBoxAction->setText(tr("Remove Spin Box"));
    removeSpinBoxAction->setEnabled(false);
    connect(removeSpinBoxAction, SIGNAL(triggered()), SLOT(removeSpinBox()));

    movableAction = new QAction(tr("Movable"), this);
    movableAction->setCheckable(true);
    connect(movableAction, SIGNAL(triggered(bool)), SLOT(changeMovable(bool)));

    allowedAreasActions = new QActionGroup(this);
    allowedAreasActions->setExclusive(false);

    allowLeftAction = new QAction(tr("Allow on Left"), this);
    allowLeftAction->setCheckable(true);
    connect(allowLeftAction, SIGNAL(triggered(bool)), SLOT(allowLeft(bool)));

    allowRightAction = new QAction(tr("Allow on Right"), this);
    allowRightAction->setCheckable(true);
    connect(allowRightAction, SIGNAL(triggered(bool)), SLOT(allowRight(bool)));

    allowTopAction = new QAction(tr("Allow on Top"), this);
    allowTopAction->setCheckable(true);
    connect(allowTopAction, SIGNAL(triggered(bool)), SLOT(allowTop(bool)));

    allowBottomAction = new QAction(tr("Allow on Bottom"), this);
    allowBottomAction->setCheckable(true);
    connect(allowBottomAction, SIGNAL(triggered(bool)), SLOT(allowBottom(bool)));

    allowedAreasActions->addAction(allowLeftAction);
    allowedAreasActions->addAction(allowRightAction);
    allowedAreasActions->addAction(allowTopAction);
    allowedAreasActions->addAction(allowBottomAction);

    areaActions = new QActionGroup(this);
    areaActions->setExclusive(true);

    leftAction = new QAction(tr("Place on Left") , this);
    leftAction->setCheckable(true);
    connect(leftAction, SIGNAL(triggered(bool)), SLOT(placeLeft(bool)));

    rightAction = new QAction(tr("Place on Right") , this);
    rightAction->setCheckable(true);
    connect(rightAction, SIGNAL(triggered(bool)), SLOT(placeRight(bool)));

    topAction = new QAction(tr("Place on Top") , this);
    topAction->setCheckable(true);
    connect(topAction, SIGNAL(triggered(bool)), SLOT(placeTop(bool)));

    bottomAction = new QAction(tr("Place on Bottom") , this);
    bottomAction->setCheckable(true);
    connect(bottomAction, SIGNAL(triggered(bool)), SLOT(placeBottom(bool)));

    areaActions->addAction(leftAction);
    areaActions->addAction(rightAction);
    areaActions->addAction(topAction);
    areaActions->addAction(bottomAction);

    toolBarBreakAction = new QAction(tr("Insert break"), this);
    connect(toolBarBreakAction, SIGNAL(triggered(bool)), this, SLOT(insertToolBarBreak()));

    connect(movableAction, SIGNAL(triggered(bool)), areaActions, SLOT(setEnabled(bool)));

    connect(movableAction, SIGNAL(triggered(bool)), allowedAreasActions, SLOT(setEnabled(bool)));

    menu = new QMenu(title, this);
    menu->addAction(toggleViewAction());
    menu->addSeparator();
    menu->addAction(orderAction);
    menu->addAction(randomizeAction);
    menu->addSeparator();
    menu->addAction(addSpinBoxAction);
    menu->addAction(removeSpinBoxAction);
    menu->addSeparator();
    menu->addAction(movableAction);
    menu->addSeparator();
    menu->addActions(allowedAreasActions->actions());
    menu->addSeparator();
    menu->addActions(areaActions->actions());
    menu->addSeparator();
    menu->addAction(toolBarBreakAction);

    connect(menu, SIGNAL(aboutToShow()), this, SLOT(updateMenu()));

    randomize();
}
QMenu *TikzCommandInserter::getMenu(const TikzCommandList &commandList)
{
	QMenu *menu = new QMenu(commandList.title, m_parentWidget);
	const int numOfCommands = commandList.commands.size();
	QAction *action = new QAction("test", menu);
	int whichSection = 0;

	// get left margin of the menu (to be added to the minimum width of the menu)
	menu->addAction(action);
	QFont actionFont = action->font();
	actionFont.setPointSize(actionFont.pointSize() - 1);
	QFontMetrics actionFontMetrics(actionFont);
	int menuLeftMargin = menu->width() - actionFontMetrics.boundingRect(action->text()).width();
	menu->removeAction(action);
	int menuMinimumWidth = 0;

	for (int i = 0; i < numOfCommands; ++i)
	{
		const QString name = commandList.commands.at(i).name;
		if (name.isEmpty()) // add separator or submenu
		{
			if (commandList.commands.at(i).type == 0)
			{
				action = new QAction(menu);
				action->setSeparator(true);
				menu->addAction(action);
			}
			else // type == -1, so add submenu; this assumes that the i-th command with type == -1 corresponds with the i-th submenu (see getCommands())
			{
				menu->addMenu(getMenu(commandList.children.at(whichSection)));
				++whichSection;
			}
		}
		else // add command
		{
			action = new QAction(name, menu);
			action->setData(commandList.commands.at(i).number); // link to the corresponding item in m_tikzCommandsList
			action->setStatusTip(commandList.commands.at(i).description);
			menuMinimumWidth = qMax(menuMinimumWidth, actionFontMetrics.boundingRect(commandList.commands.at(i).description).width());
			connect(action, SIGNAL(triggered()), this, SLOT(insertTag()));
			connect(action, SIGNAL(hovered()), this, SLOT(updateDescriptionMenuItem()));
			menu->addAction(action);
		}
	}

	// if the menu does not only contain submenus, then we add a menu item
	// at the bottom of the menu which shows the description of the currently
	// highlighted menu item
	if (whichSection < menu->actions().size())
	{
		action = new QAction(this);
		action->setSeparator(true);
		menu->addAction(action);

		action = new QAction(this);
		QFont actionFont = action->font();
		actionFont.setPointSize(actionFont.pointSize() - 1);
		action->setFont(actionFont);
		connect(action, SIGNAL(triggered()), this, SLOT(insertTag()));
		menu->addAction(action);

		// make sure that the menu width does not change when the content
		// of the above menu item changes
		menu->setMinimumWidth(menuMinimumWidth + menuLeftMargin);
	}

	return menu;
}
Example #28
0
void WindowList::showMenu(bool onlyCurrentDesktop)
{
    QList<WId> windows = KWindowSystem::windows();
    QList<QAction*> actionList;
    QList< QList<QAction*> > windowList;
    int amount = 0;
    int number = 0;

    qDeleteAll(m_listMenu->actions());
    //m_listMenu->clear();

    if (!onlyCurrentDesktop) {
        m_listMenu->addTitle(i18n("Actions"));

        QAction *unclutterAction = m_listMenu->addAction(i18n("Unclutter Windows"));
        QAction *cascadeAction = m_listMenu->addAction(i18n("Cascade Windows"));

        connect(unclutterAction, SIGNAL(triggered()), m_listMenu, SLOT(slotUnclutterWindows()));
        connect(cascadeAction, SIGNAL(triggered()), m_listMenu, SLOT(slotCascadeWindows()));
    }

    for (int i = 0; i <= KWindowSystem::numberOfDesktops(); ++i) {
        windowList.append(QList<QAction*>());
    }

    for (int i = 0; i < windows.count(); ++i) {
        KWindowInfo window = KWindowSystem::windowInfo(windows.at(i), (NET::WMGeometry | NET::WMFrameExtents | NET::WMWindowType | NET::WMDesktop | NET::WMState | NET::XAWMState | NET::WMVisibleName));
        NET::WindowType type = window.windowType(NET::NormalMask | NET::DialogMask | NET::OverrideMask | NET::UtilityMask | NET::DesktopMask | NET::DockMask | NET::TopMenuMask | NET::SplashMask | NET::ToolbarMask | NET::MenuMask);

        if ((onlyCurrentDesktop && !window.isOnDesktop(KWindowSystem::currentDesktop())) || type == NET::Desktop || type == NET::Dock || type == NET::TopMenu || type == NET::Splash || type == NET::Menu || type == NET::Toolbar || window.hasState(NET::SkipPager)) {
            windows.removeAt(i);

            --i;

            continue;
        }

        ++amount;

        QAction *action = new QAction(QIcon(KWindowSystem::icon(windows.at(i))), window.visibleName(), this);
        action->setData((unsigned long long) windows.at(i));

        QString window_title = QString(action->text());
        window_title.truncate(55);
        action->setText(window_title);

        QFont font = QFont(action->font());

        if (window.isMinimized()) {
            font.setItalic(true);
        } else if (KWindowSystem::activeWindow() == windows.at(i)) {
            font.setUnderline(true);
            font.setBold(true);
        }

        action->setFont(font);

        number = ((onlyCurrentDesktop || window.onAllDesktops()) ? 0 : window.desktop());

        QList<QAction*> subList = windowList.value(number);
        subList.append(action);

        windowList.replace(number, subList);
    }

    const bool useSubMenus = (!onlyCurrentDesktop && KWindowSystem::numberOfDesktops() > 1 && (amount / KWindowSystem::numberOfDesktops()) > 5);

    if (amount && useSubMenus) {
        m_listMenu->addTitle(i18n("Desktops"));
    }

    for (int i = 0; i <= KWindowSystem::numberOfDesktops(); ++i) {
        if (windowList.value(i).isEmpty()) {
            continue;
        }

        KMenu *subMenu = NULL;
        QAction *subMenuAction = NULL;
        QString title = (i ? KWindowSystem::desktopName(i) : (onlyCurrentDesktop ? i18n("Current desktop") : i18n("On all desktops")));

        if (useSubMenus) {
            subMenuAction = m_listMenu->addAction(title);

            subMenu = new KMenu(m_listMenu);
            subMenu->installEventFilter(this);
        } else {
            m_listMenu->addTitle(title);
        }

        for (int j = 0; j < windowList.value(i).count(); ++j) {
            if (useSubMenus) {
                subMenu->addAction(windowList.value(i).value(j));
            } else {
                m_listMenu->addAction(windowList.value(i).value(j));
            }
        }

        if (useSubMenus) {
            subMenuAction->setMenu(subMenu);
        }
    }

    if (!amount) {
        qDeleteAll(m_listMenu->actions());

        m_listMenu->clear();

        QAction *noWindows = m_listMenu->addAction(i18n("No windows"));
        noWindows->setEnabled(false);
    }

    if (formFactor() == Plasma::Vertical || formFactor() == Plasma::Horizontal) {
        m_listMenu->popup(popupPosition(m_listMenu->sizeHint()));
    } else {
        m_listMenu->popup(QCursor::pos());
    }
}
Example #29
0
void QgsDataDefinedButton::aboutToShowMenu()
{
  mDefineMenu->clear();

  bool hasExp = !getExpression().isEmpty();
  bool hasField = !getField().isEmpty();
  QString ddTitle = tr( "Data defined override" );

  QAction* ddTitleAct = mDefineMenu->addAction( ddTitle );
  QFont titlefont = ddTitleAct->font();
  titlefont.setItalic( true );
  ddTitleAct->setFont( titlefont );
  ddTitleAct->setEnabled( false );

  bool addActiveAction = false;
  if ( useExpression() && hasExp )
  {
    QgsExpression exp( getExpression() );
    // whether expression is parse-able
    addActiveAction = !exp.hasParserError();
  }
  else if ( !useExpression() && hasField )
  {
    // whether field exists
    addActiveAction = mFieldNameList.contains( getField() );
  }

  if ( addActiveAction )
  {
    ddTitleAct->setText( ddTitle + " (" + ( useExpression() ? tr( "expression" ) : tr( "field" ) ) + ")" );
    mDefineMenu->addAction( mActionActive );
    mActionActive->setText( isActive() ? tr( "Deactivate" ) : tr( "Activate" ) );
    mActionActive->setData( QVariant( isActive() ? false : true ) );
  }

  if ( !mFullDescription.isEmpty() )
  {
    mDefineMenu->addAction( mActionDescription );
  }

  mDefineMenu->addSeparator();

  if ( !mDataTypesString.isEmpty() )
  {
    QAction* fieldTitleAct = mDefineMenu->addAction( tr( "Attribute field" ) );
    fieldTitleAct->setFont( titlefont );
    fieldTitleAct->setEnabled( false );

    mDefineMenu->addAction( mActionDataTypes );

    mFieldsMenu->clear();

    if ( mFieldNameList.size() > 0 )
    {

      for ( int j = 0; j < mFieldNameList.count(); ++j )
      {
        QString fldname = mFieldNameList.at( j );
        QAction* act = mFieldsMenu->addAction( fldname + "    (" + mFieldTypeList.at( j ) + ")" );
        act->setData( QVariant( fldname ) );
        if ( getField() == fldname )
        {
          act->setCheckable( true );
          act->setChecked( !useExpression() );
        }
      }
    }
    else
    {
      QAction* act = mFieldsMenu->addAction( tr( "No matching field types found" ) );
      act->setEnabled( false );
    }

    mDefineMenu->addSeparator();
  }

  QAction* exprTitleAct = mDefineMenu->addAction( tr( "Expression" ) );
  exprTitleAct->setFont( titlefont );
  exprTitleAct->setEnabled( false );

  if ( hasExp )
  {
    QString expString = getExpression();
    if ( expString.length() > 35 )
    {
      expString.truncate( 35 );
      expString.append( "..." );
    }

    expString.prepend( tr( "Current: " ) );

    if ( !mActionExpression )
    {
      mActionExpression = new QAction( expString, this );
      mActionExpression->setCheckable( true );
    }
    else
    {
      mActionExpression->setText( expString );
    }
    mDefineMenu->addAction( mActionExpression );
    mActionExpression->setChecked( useExpression() );

    mDefineMenu->addAction( mActionExpDialog );
    mDefineMenu->addAction( mActionCopyExpr );
    mDefineMenu->addAction( mActionPasteExpr );
    mDefineMenu->addAction( mActionClearExpr );
  }
  else
  {
    mDefineMenu->addAction( mActionExpDialog );
    mDefineMenu->addAction( mActionPasteExpr );
  }

}
Example #30
0
void MainWindow::editorContextMenuRequested ( const QPoint & pos ) {
    QString guid = getCurrentNoteGuid();
    if (guid == "main")
        return;

    QWebHitTestResult element = ui->editor->page()->mainFrame()->hitTestContent(pos);

    if (element.isNull())
        return;

    QStringList classes = allClasses(element.element());
    if (classes.contains("pdfarea"))
        return;

    QMenu * menu = new QMenu(ui->editor);

    menu->addAction(ui->editor->pageAction(QWebPage::SelectAll));

    if (element.isContentSelected()) {

        if (!menu->isEmpty())
            menu->addSeparator();

        menu->addAction(ui->editor->pageAction(QWebPage::Copy));

        if (element.isContentEditable()) {
            menu->addAction(ui->editor->pageAction(QWebPage::Cut));
            menu->addAction(ui->editor->pageAction(QWebPage::Paste));
            menu->addSeparator();

            menu->addAction(ui->editor->pageAction(QWebPage::ToggleBold));
            menu->addAction(ui->editor->pageAction(QWebPage::ToggleItalic));
            menu->addAction(ui->editor->pageAction(QWebPage::ToggleUnderline));
        }
    }

    if(!element.imageUrl().isEmpty() && (element.imageUrl().scheme() != "qrc")) {

        if (!menu->isEmpty())
            menu->addSeparator();

        menu->addAction(ui->editor->pageAction(QWebPage::DownloadImageToDisk));
        menu->addAction(ui->editor->pageAction(QWebPage::CopyImageToClipboard));

        if (element.imageUrl().scheme() == "http" || element.imageUrl().scheme() == "https")
            menu->addAction(ui->editor->pageAction(QWebPage::CopyImageUrlToClipboard));

        QAction * openImage = new QAction(this);
        openImage->setText("Open Image");
        openImage->setObjectName("openImage");
        menu->addAction(openImage);

        if (JS("editMode").toBool()) {
            menu->addSeparator();

            QAction * deleteImage = new QAction(this);
            deleteImage->setText("Delete Image");
            deleteImage->setObjectName("deleteImage");
            deleteImage->setIcon(QIcon::fromTheme("edit-delete"));
            menu->addAction(deleteImage);

            if (element.imageUrl().scheme() != "resource") {
                QAction * saveLocally = new QAction(this);
                saveLocally->setText("Save Locally");
                saveLocally->setObjectName("saveLocally");
                menu->addAction(saveLocally);
            }
        }
    }

    if (!element.linkUrl().isEmpty()) {
        if (!menu->isEmpty())
            menu->addSeparator();

        menu->addAction(ui->editor->pageAction(QWebPage::CopyLinkToClipboard));

        if (element.isContentEditable()) {
            QAction * deleteURL = new QAction(this);
            deleteURL->setText("Remove Link");
            deleteURL->setObjectName("deleteURL");
            menu->addAction(deleteURL);
        }
    }

    if (element.isContentEditable() && !element.isContentSelected() && element.imageUrl().isEmpty()) {
        Speller *speller = Speller::GetInstance();
        if (speller->initialized()) {

            QHash<QString, QString> languages = speller->availableLanguages();
            if (!languages.isEmpty()) {

                if (!menu->isEmpty())
                    menu->addSeparator();                

                QAction* act = menu->addAction(tr("Check &Spelling"));
                act->setCheckable(true);
                act->setChecked(speller->isEnabled());
                connect(act, SIGNAL(triggered(bool)), speller, SLOT(setEnabled(bool)));

                if (speller->isEnabled()) {
                    QString word = JS(QString("getSpellingWord(%1,%2);").arg(pos.x()).arg(pos.y())).toString();
                    if (!word.isEmpty() && speller->isMisspelled(word)) {
                        QStringList wordsList = speller->suggest(word);

                        QFont boldFont = menu->font();
                        boldFont.setBold(true);

                        QActionGroup *suggestGroup = new QActionGroup(menu);

                        QString suggest;
                        foreach(suggest, wordsList) {
                            QAction* act = menu->addAction(suggest);
                            act->setFont(boldFont);
                            act->setData(suggest);
                            suggestGroup->addAction(act);
                        }
                        connect(suggestGroup, SIGNAL(triggered(QAction*)), this, SLOT(replaceWord(QAction*)));
                    }