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); }
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); } }
QFont QActionProto::font() const { QAction *item = qscriptvalue_cast<QAction*>(thisObject()); if (item) return item->font(); return QFont(); }
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; }
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; }
/** 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); } }
QVariant pActionsModel::data( const QModelIndex& index, int role ) const { QAction* action = this->action( index ); if ( !action ) { return QVariant(); } switch ( role ) { case Qt::DecorationRole: switch ( index.column() ) { case 0: return action->icon(); default: break; } break; case Qt::DisplayRole: case Qt::ToolTipRole: switch ( index.column() ) { case pActionsModel::Action: return cleanText( action->text() ); case pActionsModel::Shortcut: return action->shortcut().toString( QKeySequence::NativeText ); case pActionsModel::DefaultShortcut: return defaultShortcut( action ).toString( QKeySequence::NativeText ); } break; case Qt::FontRole: { QFont font = action->font(); if ( action->menu() ) { font.setBold( true ); } return font; } /*case Qt::BackgroundRole: return action->menu() ? QBrush( QColor( 0, 0, 255, 20 ) ) : QVariant();*/ case pActionsModel::MenuRole: return QVariant::fromValue( action->menu() ); case pActionsModel::ActionRole: return QVariant::fromValue( action ); } return QVariant(); }
void PopupProxy::tryInsertItem( HistoryItem const * const item, int& remainingHeight, const int index ) { QAction *action = new QAction(m_proxy_for_menu); QPixmap image( item->image() ); if ( image.isNull() ) { // Squeeze text strings so that do not take up the entire screen (or more) QString text = m_proxy_for_menu->fontMetrics().elidedText( item->text().simplified(), Qt::ElideMiddle, m_menu_width ); text.replace( '&', "&&" ); action->setText(text); } else { #if 0 // not used because QAction#setIcon does not respect this size; it does scale anyway. TODO: find a way to set a bigger image const QSize max_size( m_menu_width,m_menu_height/4 ); if ( image.height() > max_size.height() || image.width() > max_size.width() ) { image = image.scaled( max_size, Qt::KeepAspectRatio, Qt::SmoothTransformation ); } #endif action->setIcon(QIcon(image)); } action->setData(item->uuid()); // if the m_proxy_for_menu is a submenu (aka a "More" menu) then it may the case, that there is no other action in that menu yet. QAction *before = index < m_proxy_for_menu->actions().count() ? m_proxy_for_menu->actions().at(index) : 0; // insert the new action to the m_proxy_for_menu m_proxy_for_menu->insertAction(before, action); // Determine height of a menu item. QStyleOptionMenuItem style_options; // It would be much easier to use QMenu::initStyleOptions. But that is protected, so until we have a better // excuse to subclass that, I'd rather implement this manually. // Note 2 properties, tabwidth and maxIconWidth, are not available from the public interface, so those are left out (probably not // important for height. Also, Exlsive checkType is disregarded as I don't think we will ever use it) style_options.initFrom(m_proxy_for_menu); style_options.checkType = action->isCheckable() ? QStyleOptionMenuItem::NonExclusive : QStyleOptionMenuItem::NotCheckable; style_options.checked = action->isChecked(); style_options.font = action->font(); style_options.icon = action->icon(); style_options.menuHasCheckableItems = true; style_options.menuRect = m_proxy_for_menu->rect(); style_options.text = action->text(); int font_height = QFontMetrics(m_proxy_for_menu->fontMetrics()).height(); int itemheight = m_proxy_for_menu->style()->sizeFromContents(QStyle::CT_MenuItem, &style_options, QSize( 0, font_height ), m_proxy_for_menu).height(); // Subtract the used height remainingHeight -= itemheight; }
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); } }
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 ); } } }
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; }
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); } }
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; }
// 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 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); }
void game_list_frame::ShowSpecifiedContextMenu(const QPoint &pos, int row) { if (row == -1) { return; // invalid } QPoint globalPos; if (m_isListLayout) { globalPos = gameList->mapToGlobal(pos); } else { globalPos = m_xgrid->mapToGlobal(pos); } QMenu myMenu; // Make Actions QAction* boot = myMenu.addAction(tr("&Boot")); QFont f = boot->font(); f.setBold(true); boot->setFont(f); QAction* configure = myMenu.addAction(tr("&Configure")); myMenu.addSeparator(); QAction* removeGame = myMenu.addAction(tr("&Remove")); QAction* removeConfig = myMenu.addAction(tr("&Remove Custom Configuration")); myMenu.addSeparator(); QAction* openGameFolder = myMenu.addAction(tr("&Open Install Folder")); QAction* openConfig = myMenu.addAction(tr("&Open Config Folder")); myMenu.addSeparator(); QAction* checkCompat = myMenu.addAction(tr("&Check Game Compatibility")); connect(boot, &QAction::triggered, [=]() {Boot(row); }); connect(configure, &QAction::triggered, [=]() { settings_dialog(xgui_settings, m_Render_Creator, this, &m_game_data[row].info).exec(); }); connect(removeGame, &QAction::triggered, [=]() { if (QMessageBox::question(this, tr("Confirm Delete"), tr("Permanently delete files?")) == QMessageBox::Yes) { fs::remove_all(Emu.GetGameDir() + m_game_data[row].info.root); m_game_data.erase(m_game_data.begin() + row); Refresh(); } }); connect(removeConfig, &QAction::triggered, [=]() {RemoveCustomConfiguration(row); }); connect(openGameFolder, &QAction::triggered, [=]() {open_dir(Emu.GetGameDir() + m_game_data[row].info.root); }); connect(openConfig, &QAction::triggered, [=]() {open_dir(fs::get_config_dir() + "data/" + m_game_data[row].info.serial); }); connect(checkCompat, &QAction::triggered, [=]() { QString serial = qstr(m_game_data[row].info.serial); QString link = "https://rpcs3.net/compatibility?g=" + serial; QDesktopServices::openUrl(QUrl(link)); }); //Disable options depending on software category QString category = qstr(m_game_data[row].info.category); if (category == category::disc_Game) { removeGame->setEnabled(false); } else if (category == category::audio_Video) { configure->setEnabled(false); removeConfig->setEnabled(false); openConfig->setEnabled(false); checkCompat->setEnabled(false); } else if (category == category::home || category == category::game_Data) { boot->setEnabled(false), f.setBold(false), boot->setFont(f); configure->setEnabled(false); removeConfig->setEnabled(false); openConfig->setEnabled(false); checkCompat->setEnabled(false); } myMenu.exec(globalPos); }
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()); } }
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 ); } }
QWidget* GCF::ActionContainerWidget::createWidget(QAction* action, int rowSpan, int colSpan) { QWidget* ret = 0; int gSize=int((fontMetrics().height()+fontMetrics().ascent())*1.2); int minWidth = gSize*colSpan; QWidgetAction* wAction = qobject_cast<QWidgetAction*>(action); if(wAction) ret = wAction->requestWidget(this); else { QToolButton* tb = new QToolButton(this); tb->setDefaultAction(action); tb->setAutoRaise(true); /*if(action->menu()) tb->setMenu(action->menu());*/ tb->setIconSize(QSize(gSize-4,gSize-4)); if(action->icon().isNull()) tb->setToolButtonStyle(Qt::ToolButtonTextOnly); else if(colSpan == rowSpan && colSpan >= 2) tb->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); else if(colSpan == rowSpan && colSpan == 1) tb->setToolButtonStyle(Qt::ToolButtonIconOnly); else if(colSpan >= 2 || rowSpan == 1) tb->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); else if(rowSpan >= 3) tb->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); int mw = 0; if(tb->toolButtonStyle() != Qt::ToolButtonIconOnly) mw += fontMetrics().width(action->iconText())+2*fontMetrics().width("_"); if(!action->icon().isNull()) { switch(tb->toolButtonStyle()) { case Qt::ToolButtonTextUnderIcon: if(mw < gSize-4) mw = gSize-4; break; case Qt::ToolButtonTextBesideIcon: mw += gSize-4; break; } } if(minWidth < mw) minWidth = mw; if(action->menu()) { // Connect the default action object to the tool button. This way // when the toolbutton with menu is clicked, the default action is // shown. QList<QAction*> actions = action->menu()->actions(); QAction* defAction = 0; for(int i=0; i<actions.count(); i++) { QAction* action = actions[i]; QList<QByteArray> propNames = action->dynamicPropertyNames(); if(propNames.contains("_default_")) { bool val = action->property("_default_").toBool(); if(val) { defAction = action; break; } } } if(defAction) { if(defAction->isCheckable()) connect(tb, SIGNAL(clicked()), defAction, SLOT(toggle())); else connect(tb, SIGNAL(clicked()), defAction, SLOT(trigger())); QFont font = defAction->font(); font.setBold(true); defAction->setFont(font); } } ret = tb; } ret->setMinimumSize(minWidth, gSize*rowSpan); if(!action->icon().isNull()) { QFont font = ret->font(); // font.setPointSize(font.pointSize()-1); ret->setFont(font); } /*static QPlastiqueStyle Style; ret->setStyle(&Style);*/ return ret; }
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(); bool fieldActive = false; 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() ); fieldActive = !useExpression(); } } } else { QAction* act = mFieldsMenu->addAction( tr( "No matching field types found" ) ); act->setEnabled( false ); } mDefineMenu->addSeparator(); } mFieldsMenu->menuAction()->setCheckable( true ); mFieldsMenu->menuAction()->setChecked( fieldActive ); QAction* exprTitleAct = mDefineMenu->addAction( tr( "Expression" ) ); exprTitleAct->setFont( titlefont ); exprTitleAct->setEnabled( false ); mVariablesMenu->clear(); bool variableActive = false; if ( mExpressionContextCallback ) { QgsExpressionContext context = mExpressionContextCallback( mExpressionContextCallbackContext ); QStringList variables = context.variableNames(); Q_FOREACH ( const QString& variable, variables ) { if ( context.isReadOnly( variable ) ) //only want to show user-set variables continue; if ( variable.startsWith( '_' ) ) //no hidden variables continue; QAction* act = mVariablesMenu->addAction( variable ); act->setData( QVariant( variable ) ); if ( useExpression() && hasExp && getExpression() == '@' + variable ) { act->setCheckable( true ); act->setChecked( true ); variableActive = true; } } } if ( mVariablesMenu->actions().isEmpty() ) { QAction* act = mVariablesMenu->addAction( tr( "No variables set" ) ); act->setEnabled( false ); } mDefineMenu->addAction( mActionVariables ); mVariablesMenu->menuAction()->setCheckable( true ); mVariablesMenu->menuAction()->setChecked( variableActive ); 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() && !variableActive ); mDefineMenu->addAction( mActionExpDialog ); mDefineMenu->addAction( mActionCopyExpr ); mDefineMenu->addAction( mActionPasteExpr ); mDefineMenu->addAction( mActionClearExpr ); } else { mDefineMenu->addAction( mActionExpDialog ); mDefineMenu->addAction( mActionPasteExpr ); } if ( mAssistant.data() ) { mDefineMenu->addSeparator(); mDefineMenu->addAction( mActionAssistant ); } }
void MainWindow::setMainWidget() { listBar_ = new QToolBar(this); listBar_->setAllowedAreas(Qt::NoToolBarArea); listBar_->setIconSize(QSize(64, 64)); listBar_->setMovable(false); listBar_->setFloatable(false); listBar_->setStyleSheet(".QToolBar{border: none;}"); //listBar_->setToolButtonStyle(Qt::ToolButtonTextOnly); listBar_->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); listBar_->setOrientation(Qt::Vertical); connect(listBar_, SIGNAL(actionTriggered(QAction *)), this, SLOT(listToggled(QAction *))); actionGroup_ = new QActionGroup(this); QAction * act = listBar_->addAction(QIcon(":/images/card.png"), tr("Range")); act->setCheckable(true); act->setShortcut(QKeySequence("F5")); act->setToolTip(tr("Specify the playing card range")); QFont fn = act->font(); fn.setPointSize(10); act->setFont(fn); actionGroup_->addAction(act); act = listBar_->addAction(QIcon(":/images/settings.png"), tr("Settings")); act->setCheckable(true); act->setShortcut(QKeySequence("F6")); act->setFont(fn); actionGroup_->addAction(act); act->setToolTip(tr("Additional settings")); act = listBar_->addAction(QIcon(":/images/support.png"), tr("Support")); act->setCheckable(true); act->setShortcut(QKeySequence("F8")); act->setFont(fn); actionGroup_->addAction(act); act->setToolTip(tr("Support Information, Help")); #ifdef DEMO_MODE act = listBar_->addAction(QIcon(":/images/credit_card.png"), tr("Get Now")); act->setCheckable(true); act->setShortcut(QKeySequence("F7")); act->setFont(fn); actionGroup_->addAction(act); act->setToolTip(tr("Get the Full Version")); #endif act = listBar_->addAction(QIcon(":/images/poker.png"), tr("Start")); act->setShortcut(QKeySequence("F9")); act->setFont(fn); act->setToolTip(tr("Start Playing")); actionGroup_->addAction(act); connect(act, SIGNAL(triggered()), this, SLOT(startPlay())); //listBar_->addSeparator(); QWidget * widStretch = new QWidget(this); //widStretch->setMinimumHeight(64); widStretch->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); listBar_->addWidget(widStretch); //listBar_->addSeparator(); //act = listBar_->addAction(QIcon(":/images/save.png"), tr("Save")); //act->setCheckable(false); //act->setShortcut(QKeySequence("F9")); //act->setFont(fn); //act->setToolTip(tr("Save settings")); //actionGroup_->addAction(act); //connect(act, SIGNAL(triggered()), this, SLOT(saveConf())); act = listBar_->addAction(QIcon(":/images/exit2.png"), tr("Exit")); act->setCheckable(false); act->setShortcut(QKeySequence("F10")); act->setFont(fn); act->setToolTip(tr("Exit")); actionGroup_->addAction(act); connect(act, SIGNAL(triggered()), this, SLOT(cancel())); spectrum_ = new SpectrumEditor(this); spectrum_->setFont(fn); QFrame * gbx = new QFrame(this); QVBoxLayout * vl = new QVBoxLayout; vl->setMargin(0); vl->addWidget(listBar_); gbx->setLayout(vl); stacked_ = new QStackedWidget(this); stacked_->addWidget(spectrum_); settingsPage_ = new SettingsPage(this); settingsPage_->setFont(fn); stacked_->addWidget(settingsPage_); SupportPage * supportPage = new SupportPage(this); supportPage->setFont(fn); stacked_->addWidget(supportPage); #ifdef DEMO_MODE OrderPage * orderPage = new OrderPage(this); orderPage->setFont(fn); connect(orderPage, SIGNAL(unlock()), this, SLOT(unlock())); stacked_->addWidget(orderPage); #endif //stacked_->addWidget(new QWidget()); QHBoxLayout * hl = new QHBoxLayout; hl->setMargin(6); hl->setSpacing(2); hl->addWidget(gbx, 0); hl->addWidget(stacked_, 1); QVBoxLayout * vlmain = new QVBoxLayout; vlmain->setSizeConstraint(QLayout::SetFixedSize); vlmain->setMargin(0); vlmain->addLayout(hl); setLayout(vlmain); }
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; }
void QgsPropertyOverrideButton::aboutToShowMenu() { mDefineMenu->clear(); // update fields so that changes made to layer's fields are reflected updateFieldLists(); bool hasExp = !mExpressionString.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 ( mProperty.propertyType() == QgsProperty::ExpressionBasedProperty && hasExp ) { QgsExpression exp( mExpressionString ); // whether expression is parse-able addActiveAction = !exp.hasParserError(); } else if ( mProperty.propertyType() == QgsProperty::FieldBasedProperty ) { // whether field exists addActiveAction = mFieldNameList.contains( mFieldName ); } if ( addActiveAction ) { ddTitleAct->setText( ddTitle + " (" + ( mProperty.propertyType() == QgsProperty::ExpressionBasedProperty ? tr( "expression" ) : tr( "field" ) ) + ')' ); mDefineMenu->addAction( mActionActive ); mActionActive->setText( mProperty.isActive() ? tr( "Deactivate" ) : tr( "Activate" ) ); mActionActive->setData( QVariant( !mProperty.isActive() ) ); } if ( !mFullDescription.isEmpty() ) { mDefineMenu->addAction( mActionDescription ); } mDefineMenu->addSeparator(); // deactivate button if field already exists if ( mAuxiliaryStorageEnabled && mVectorLayer ) { mDefineMenu->addAction( mActionCreateAuxiliaryField ); const QgsAuxiliaryLayer *alayer = mVectorLayer->auxiliaryLayer(); mActionCreateAuxiliaryField->setEnabled( true ); mActionCreateAuxiliaryField->setChecked( false ); int index = mVectorLayer->fields().indexFromName( mFieldName ); int srcIndex; if ( index >= 0 && alayer && mVectorLayer->isAuxiliaryField( index, srcIndex ) ) { mActionCreateAuxiliaryField->setEnabled( false ); mActionCreateAuxiliaryField->setChecked( true ); } } bool fieldActive = false; if ( !mDataTypesString.isEmpty() ) { QAction *fieldTitleAct = mDefineMenu->addAction( tr( "Attribute field" ) ); fieldTitleAct->setFont( titlefont ); fieldTitleAct->setEnabled( false ); mDefineMenu->addAction( mActionDataTypes ); mFieldsMenu->clear(); if ( !mFieldNameList.isEmpty() ) { 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 ( mFieldName == fldname ) { act->setCheckable( true ); act->setChecked( mProperty.propertyType() == QgsProperty::FieldBasedProperty ); fieldActive = mProperty.propertyType() == QgsProperty::FieldBasedProperty; } } } else { QAction *act = mFieldsMenu->addAction( tr( "No matching field types found" ) ); act->setEnabled( false ); } mDefineMenu->addSeparator(); } mFieldsMenu->menuAction()->setCheckable( true ); mFieldsMenu->menuAction()->setChecked( fieldActive && mProperty.propertyType() == QgsProperty::FieldBasedProperty && !mProperty.transformer() ); QAction *exprTitleAct = mDefineMenu->addAction( tr( "Expression" ) ); exprTitleAct->setFont( titlefont ); exprTitleAct->setEnabled( false ); mVariablesMenu->clear(); bool variableActive = false; if ( mExpressionContextGenerator ) { QgsExpressionContext context = mExpressionContextGenerator->createExpressionContext(); QStringList variables = context.variableNames(); Q_FOREACH ( const QString &variable, variables ) { if ( context.isReadOnly( variable ) ) //only want to show user-set variables continue; if ( variable.startsWith( '_' ) ) //no hidden variables continue; QAction *act = mVariablesMenu->addAction( variable ); act->setData( QVariant( variable ) ); if ( mProperty.propertyType() == QgsProperty::ExpressionBasedProperty && hasExp && mExpressionString == '@' + variable ) { act->setCheckable( true ); act->setChecked( true ); variableActive = true; } } } if ( mVariablesMenu->actions().isEmpty() ) { QAction *act = mVariablesMenu->addAction( tr( "No variables set" ) ); act->setEnabled( false ); } mDefineMenu->addAction( mActionVariables ); mVariablesMenu->menuAction()->setCheckable( true ); mVariablesMenu->menuAction()->setChecked( variableActive && !mProperty.transformer() ); if ( hasExp ) { QString expString = mExpressionString; if ( expString.length() > 35 ) { expString.truncate( 35 ); expString.append( QChar( 0x2026 ) ); } expString.prepend( tr( "Current: " ) ); if ( !mActionExpression ) { mActionExpression = new QAction( expString, this ); mActionExpression->setCheckable( true ); } else { mActionExpression->setText( expString ); } mDefineMenu->addAction( mActionExpression ); mActionExpression->setChecked( mProperty.propertyType() == QgsProperty::ExpressionBasedProperty && !variableActive && !mProperty.transformer() ); mDefineMenu->addAction( mActionExpDialog ); mDefineMenu->addAction( mActionCopyExpr ); mDefineMenu->addAction( mActionPasteExpr ); mDefineMenu->addAction( mActionClearExpr ); } else { mDefineMenu->addAction( mActionExpDialog ); mDefineMenu->addAction( mActionPasteExpr ); } if ( !mDefinition.name().isEmpty() && mDefinition.supportsAssistant() ) { mDefineMenu->addSeparator(); mActionAssistant->setCheckable( mProperty.transformer() ); mActionAssistant->setChecked( mProperty.transformer() ); mDefineMenu->addAction( mActionAssistant ); } }