void ToolButton::showMenu() { if (!m_showMenuInside) { QToolButton::showMenu(); return; } QMenu* m = menu(); if (!m) { return; } emit aboutToShowMenu(); QPoint pos = mapToGlobal(rect().bottomRight()); if (QApplication::layoutDirection() == Qt::RightToLeft) { pos.setX(pos.x() - rect().width()); } else { pos.setX(pos.x() - m->sizeHint().width()); } m->popup(pos); }
/** Redefined. */ void AddressBarButton::mouseMoveEvent(QMouseEvent *) { // We are sure that parent is a QWidget qobject_cast<QWidget *>(this->parent())->update(); if (_addressBar->isDown()) { emit aboutToShowMenu(); } }
void AddressBarButton::setHighlighted(bool b) { _highlighted = b; if (b) { emit aboutToShowMenu(); } repaint(); }
QgsDataDefinedButton::QgsDataDefinedButton( QWidget* parent, const QgsVectorLayer* vl, const QgsDataDefined* datadefined, DataTypes datatypes, QString description ) : QToolButton( parent ) { // set up static icons if ( mIconDataDefine.isNull() ) { mIconDataDefine = QgsApplication::getThemeIcon( "/mIconDataDefine.svg" ); mIconDataDefineOn = QgsApplication::getThemeIcon( "/mIconDataDefineOn.svg" ); mIconDataDefineError = QgsApplication::getThemeIcon( "/mIconDataDefineError.svg" ); mIconDataDefineExpression = QgsApplication::getThemeIcon( "/mIconDataDefineExpression.svg" ); mIconDataDefineExpressionOn = QgsApplication::getThemeIcon( "/mIconDataDefineExpressionOn.svg" ); mIconDataDefineExpressionError = QgsApplication::getThemeIcon( "/mIconDataDefineExpressionError.svg" ); } setFocusPolicy( Qt::StrongFocus ); // set default tool button icon properties setFixedSize( 30, 26 ); setStyleSheet( QString( "QToolButton{ background: none; border: 1px solid rgba(0, 0, 0, 0%);} QToolButton:focus { border: 1px solid palette(highlight); }" ) ); setIconSize( QSize( 24, 24 ) ); setPopupMode( QToolButton::InstantPopup ); mDefineMenu = new QMenu( this ); connect( mDefineMenu, SIGNAL( aboutToShow() ), this, SLOT( aboutToShowMenu() ) ); connect( mDefineMenu, SIGNAL( triggered( QAction* ) ), this, SLOT( menuActionTriggered( QAction* ) ) ); setMenu( mDefineMenu ); mFieldsMenu = new QMenu( this ); mActionDataTypes = new QAction( this ); // list fields and types in submenu, since there may be many mActionDataTypes->setMenu( mFieldsMenu ); mActionActive = new QAction( this ); QFont f = mActionActive->font(); f.setBold( true ); mActionActive->setFont( f ); mActionDescription = new QAction( tr( "Description..." ), this ); mActionExpDialog = new QAction( tr( "Edit..." ), this ); mActionExpression = 0; mActionPasteExpr = new QAction( tr( "Paste" ), this ); mActionCopyExpr = new QAction( tr( "Copy" ), this ); mActionClearExpr = new QAction( tr( "Clear" ), this ); mActionAssistant = new QAction( tr( "Assistant..." ), this ); // set up sibling widget connections connect( this, SIGNAL( dataDefinedActivated( bool ) ), this, SLOT( disableEnabledWidgets( bool ) ) ); connect( this, SIGNAL( dataDefinedActivated( bool ) ), this, SLOT( checkCheckedWidgets( bool ) ) ); init( vl, datadefined, datatypes, description ); }
/** Redefined. */ void AddressBarButton::mousePressEvent(QMouseEvent *event) { // mouse press in arrow rect => immediate popup menu // in text rect => goto dir, mouse release not relevant if (_arrowRect.contains(event->pos())) { //_arrowPressed = true; emit aboutToShowMenu(); } }
ButtonWithMenu::ButtonWithMenu(QWidget* parent) : ToolButton(parent) , m_menu(new QMenu(this)) { setCursor(Qt::ArrowCursor); setFocusPolicy(Qt::NoFocus); connect(this, SIGNAL(aboutToShowMenu()), this, SLOT(generateMenu())); connect(m_menu, &QMenu::aboutToShow, this, std::bind(&ButtonWithMenu::setDown, this, true)); connect(m_menu, &QMenu::aboutToHide, this, std::bind(&ButtonWithMenu::setDown, this, false)); }
void PsiTabWidget::menu_aboutToShow() { clearMenu(menu_); bool vis = false; for (int i = 0; i < tabBar_->count(); i++) { QRect r = tabBar_->tabRect(i); bool newvis = tabBar_->rect().contains(r); if (newvis != vis) { menu_->addSeparator (); vis = newvis; } menu_->addAction(tabBar_->tabText(i))->setData(i+1); } emit aboutToShowMenu(menu_); }
WebSearchBar::WebSearchBar(BrowserWindow* window) : LineEdit(window) , m_window(window) , m_reloadingEngines(false) { setObjectName("websearchbar"); setDragEnabled(true); m_buttonSearch = new WebSearchBar_Button(this); m_boxSearchType = new ButtonWithMenu(this); m_boxSearchType->setObjectName("websearchbar-searchprovider-comobobox"); // RTL Support // If we don't add 'm_boxSearchType' by following code, then we should use suitable padding-left value // but then, when typing RTL text the layout dynamically changed and within RTL layout direction // padding-left is equivalent to padding-right and vice versa, and because style sheet is // not changed dynamically this create padding problems. addWidget(m_boxSearchType, LineEdit::LeftSide); addWidget(m_buttonSearch, LineEdit::RightSide); connect(m_buttonSearch, SIGNAL(clicked(QPoint)), this, SLOT(search())); connect(m_buttonSearch, SIGNAL(middleClicked(QPoint)), this, SLOT(searchInNewTab())); connect(m_boxSearchType, SIGNAL(activeItemChanged(ButtonWithMenu::Item)), this, SLOT(searchChanged(ButtonWithMenu::Item))); setWidgetSpacing(0); m_searchManager = mApp->searchEnginesManager(); connect(m_boxSearchType->menu(), SIGNAL(aboutToShow()), this, SLOT(aboutToShowMenu())); m_completer = new QCompleter(this); m_completer->setCompletionMode(QCompleter::UnfilteredPopupCompletion); m_completerModel = new QStringListModel(this); m_completer->setModel(m_completerModel); m_completer->popup()->setMinimumHeight(90); setCompleter(m_completer); m_openSearchEngine = new OpenSearchEngine(this); m_openSearchEngine->setNetworkAccessManager(mApp->networkManager()); connect(m_openSearchEngine, SIGNAL(suggestions(QStringList)), this, SLOT(addSuggestions(QStringList))); connect(this, SIGNAL(textEdited(QString)), m_openSearchEngine, SLOT(requestSuggestions(QString))); editAction(PasteAndGo)->setText(tr("Paste And &Search")); editAction(PasteAndGo)->setIcon(QIcon::fromTheme(QSL("edit-paste"))); connect(editAction(PasteAndGo), SIGNAL(triggered()), this, SLOT(pasteAndGo())); QTimer::singleShot(0, this, SLOT(setupEngines())); }
SimpleTableOfContentsWidget::SimpleTableOfContentsWidget(ReferencesTool *tool, QWidget *parent) : QWidget(parent), m_blockSignals(false), m_referenceTool(tool), m_signalMapper(0) { widget.setupUi(this); Q_ASSERT(tool); m_templateGenerator = new TableOfContentsTemplate(KoTextDocument(m_referenceTool->editor()->document()).styleManager()); widget.addToC->setIcon(koIcon("insert-tableofcontents")); widget.addToC->setNumColumns(1); connect(widget.addToC, SIGNAL(clicked(bool)), this, SIGNAL(doneWithFocus())); connect(widget.addToC, SIGNAL(aboutToShowMenu()), this, SLOT(prepareTemplateMenu())); connect(widget.addToC, SIGNAL(itemTriggered(int)), this, SLOT(applyTemplate(int))); }
/* ToolbarSearch is a very basic search widget that also contains a small history. Searches are turned into urls that use Google to perform search */ ToolbarSearch::ToolbarSearch(QWidget *parent) : SearchLineEdit(parent) , m_autosaver(new AutoSaver(this)) , m_maxSavedSearches(10) , m_stringListModel(new QStringListModel(this)) { QMenu *m = menu(); connect(m, SIGNAL(aboutToShow()), this, SLOT(aboutToShowMenu())); connect(m, SIGNAL(triggered(QAction*)), this, SLOT(triggeredMenuAction(QAction*))); QCompleter *completer = new QCompleter(m_stringListModel, this); completer->setCompletionMode(QCompleter::InlineCompletion); lineEdit()->setCompleter(completer); connect(lineEdit(), SIGNAL(returnPressed()), SLOT(searchNow())); setInactiveText(tr("Google")); load(); }
QgsMultiEditToolButton::QgsMultiEditToolButton( QWidget* parent ) : QToolButton( parent ) , mIsMixedValues( false ) , mIsChanged( false ) , mState( Default ) , mMenu( nullptr ) { setFocusPolicy( Qt::StrongFocus ); // set default tool button icon properties setFixedSize( 22, 22 ); setStyleSheet( QStringLiteral( "QToolButton{ background: none; border: 1px solid rgba(0, 0, 0, 0%);} QToolButton:focus { border: 1px solid palette(highlight); }" ) ); setIconSize( QSize( 16, 16 ) ); setPopupMode( QToolButton::InstantPopup ); mMenu = new QMenu( this ); connect( mMenu, SIGNAL( aboutToShow() ), this, SLOT( aboutToShowMenu() ) ); setMenu( mMenu ); // sets initial appearance updateState(); }
void ToolButton::showMenu() { if (!m_menu || m_menu->isVisible()) return; emit aboutToShowMenu(); QPoint pos; if (m_options & ShowMenuInsideOption) { pos = mapToGlobal(rect().bottomRight()); if (QApplication::layoutDirection() == Qt::RightToLeft) pos.setX(pos.x() - rect().width()); else pos.setX(pos.x() - m_menu->sizeHint().width()); } else { pos = mapToGlobal(rect().bottomLeft()); } m_menu->popup(pos); }
void MenuCallback::beginMenu(QString label) { #ifdef Q_OS_MAC if (label == "&Help") { pMainMenu_->addMenu(new WindowMenu(pMainMenu_)); } #endif QMenu* pMenu = new QMenu(label, pMainMenu_); if (menuStack_.count() == 0) pMainMenu_->addMenu(pMenu); else menuStack_.top()->addMenu(pMenu); menuStack_.push(pMenu); menuActions_[pMenu] = QList<QAction*>(); connect(pMenu, SIGNAL(aboutToShow()), this, SLOT(aboutToShowMenu())); }
SimpleCitationBibliographyWidget::SimpleCitationBibliographyWidget(ReferencesTool *tool, QWidget *parent) : QWidget(parent), m_blockSignals(false), m_referenceTool(tool), m_signalMapper(0) { widget.setupUi(this); Q_ASSERT(tool); m_templateGenerator = new BibliographyTemplate(KoTextDocument(m_referenceTool->editor()->document()).styleManager()); widget.addCitation->setDefaultAction(tool->action("insert_citation")); connect(widget.addCitation,SIGNAL(clicked(bool)),this,SIGNAL(doneWithFocus())); widget.addBibliography->setDefaultAction(tool->action("insert_bibliography")); widget.addBibliography->setNumColumns(1); connect(widget.addBibliography,SIGNAL(clicked(bool)),this,SIGNAL(doneWithFocus())); connect(widget.addBibliography, SIGNAL(aboutToShowMenu()), this, SLOT(prepareTemplateMenu())); connect(widget.addBibliography, SIGNAL(itemTriggered(int)), this, SLOT(applyTemplate(int))); widget.configureBibliography->setDefaultAction(tool->action("configure_bibliography")); connect(widget.configureBibliography,SIGNAL(clicked(bool)),this,SIGNAL(doneWithFocus())); }
void QgsDataDefinedButton::init( const QgsVectorLayer* vl, const QgsDataDefined* datadefined, DataTypes datatypes, QString description ) { mVectorLayer = vl; // construct default property if none or incorrect passed in if ( !datadefined ) { mProperty.insert( "active", "0" ); mProperty.insert( "useexpr", "0" ); mProperty.insert( "expression", "" ); mProperty.insert( "field", "" ); } else { mProperty.insert( "active", datadefined->isActive() ? "1" : "0" ); mProperty.insert( "useexpr", datadefined->useExpression() ? "1" : "0" ); mProperty.insert( "expression", datadefined->expressionString() ); mProperty.insert( "field", datadefined->field() ); } mDataTypes = datatypes; mInputDescription = description; mFullDescription = QString( "" ); mUsageInfo = QString( "" ); mCurrentDefinition = QString( "" ); mActionExpression = 0; if ( mIconDataDefine.isNull() ) { mIconDataDefine = QgsApplication::getThemeIcon( "/mIconDataDefine.svg" ); mIconDataDefineOn = QgsApplication::getThemeIcon( "/mIconDataDefineOn.svg" ); mIconDataDefineError = QgsApplication::getThemeIcon( "/mIconDataDefineError.svg" ); mIconDataDefineExpression = QgsApplication::getThemeIcon( "/mIconDataDefineExpression.svg" ); mIconDataDefineExpressionOn = QgsApplication::getThemeIcon( "/mIconDataDefineExpressionOn.svg" ); mIconDataDefineExpressionError = QgsApplication::getThemeIcon( "/mIconDataDefineExpressionError.svg" ); } // set default icon properties setFixedSize( 28, 24 ); setStyleSheet( QString( "QToolButton{ background: none; border: none;}" ) ); setIconSize( QSize( 24, 24 ) ); setPopupMode( QToolButton::InstantPopup ); mDefineMenu = new QMenu( this ); connect( mDefineMenu, SIGNAL( aboutToShow() ), this, SLOT( aboutToShowMenu() ) ); connect( mDefineMenu, SIGNAL( triggered( QAction* ) ), this, SLOT( menuActionTriggered( QAction* ) ) ); mFieldsMenu = new QMenu( this ); mActionActive = new QAction( this ); QFont f = mActionActive->font(); f.setBold( true ); mActionActive->setFont( f ); mActionDescription = new QAction( tr( "Description..." ), this ); mActionExpDialog = new QAction( tr( "Edit..." ), this ); mActionPasteExpr = new QAction( tr( "Paste" ), this ); mActionCopyExpr = new QAction( tr( "Copy" ), this ); mActionClearExpr = new QAction( tr( "Clear" ), this ); // set up data types string mActionDataTypes = 0; mDataTypesString = QString( "" ); QStringList ts; if ( mDataTypes.testFlag( AnyType ) || mDataTypes.testFlag( String ) ) { ts << tr( "string" ); } if ( mDataTypes.testFlag( AnyType ) || mDataTypes.testFlag( Int ) ) { ts << tr( "int" ); } if ( mDataTypes.testFlag( AnyType ) || mDataTypes.testFlag( Double ) ) { ts << tr( "double" ); } if ( !ts.isEmpty() ) { mDataTypesString = ts.join( ", " ); mActionDataTypes = new QAction( tr( "Field type: " ) + mDataTypesString, this ); // list fields and types in submenu, since there may be many mActionDataTypes->setMenu( mFieldsMenu ); } if ( mVectorLayer ) { // store just a list of fields of unknown type or those that match the expected type const QgsFields& fields = mVectorLayer->pendingFields(); for ( int i = 0; i < fields.count(); ++i ) { const QgsField& f = fields.at( i ); bool fieldMatch = false; // NOTE: these are the only QVariant enums supported at this time (see QgsField) QString fieldType; switch ( f.type() ) { case QVariant::String: fieldMatch = mDataTypes.testFlag( String ); fieldType = tr( "string" ); break; case QVariant::Int: fieldMatch = mDataTypes.testFlag( Int ); fieldType = tr( "integer" ); break; case QVariant::Double: fieldMatch = mDataTypes.testFlag( Double ); fieldType = tr( "double" ); break; case QVariant::Invalid: default: fieldMatch = true; // field type is unknown fieldType = tr( "unknown type" ); } if ( fieldMatch || mDataTypes.testFlag( AnyType ) ) { mFieldNameList << f.name(); mFieldTypeList << fieldType; } } } setMenu( mDefineMenu ); // set up sibling widget connections connect( this, SIGNAL( dataDefinedActivated( bool ) ), this, SLOT( disableEnabledWidgets( bool ) ) ); connect( this, SIGNAL( dataDefinedActivated( bool ) ), this, SLOT( checkCheckedWidgets( bool ) ) ); updateGui(); }
void KopeteSystemTray::slotAboutToShowMenu() { emit aboutToShowMenu(qobject_cast<KMenu *>(contextMenu())); }
NavigationBar::NavigationBar(BrowserWindow* window) : QWidget(window) , m_window(window) { setObjectName(QSL("navigationbar")); m_layout = new QHBoxLayout(this); m_layout->setMargin(style()->pixelMetric(QStyle::PM_ToolBarItemMargin, 0, this)); m_layout->setSpacing(style()->pixelMetric(QStyle::PM_ToolBarItemSpacing, 0, this)); setLayout(m_layout); m_buttonBack = new ToolButton(this); m_buttonBack->setObjectName("navigation-button-back"); m_buttonBack->setToolTip(tr("Back")); m_buttonBack->setToolButtonStyle(Qt::ToolButtonIconOnly); m_buttonBack->setToolbarButtonLook(true); m_buttonBack->setAutoRaise(true); m_buttonBack->setEnabled(false); m_buttonBack->setFocusPolicy(Qt::NoFocus); m_buttonForward = new ToolButton(this); m_buttonForward->setObjectName("navigation-button-next"); m_buttonForward->setToolTip(tr("Forward")); m_buttonForward->setToolButtonStyle(Qt::ToolButtonIconOnly); m_buttonForward->setToolbarButtonLook(true); m_buttonForward->setAutoRaise(true); m_buttonForward->setEnabled(false); m_buttonForward->setFocusPolicy(Qt::NoFocus); QHBoxLayout* backNextLayout = new QHBoxLayout(); backNextLayout->setContentsMargins(0, 0, 0, 0); backNextLayout->setSpacing(0); backNextLayout->addWidget(m_buttonBack); backNextLayout->addWidget(m_buttonForward); m_reloadStop = new ReloadStopButton(this); m_buttonHome = new ToolButton(this); m_buttonHome->setObjectName("navigation-button-home"); m_buttonHome->setToolTip(tr("Home")); m_buttonHome->setToolButtonStyle(Qt::ToolButtonIconOnly); m_buttonHome->setToolbarButtonLook(true); m_buttonHome->setAutoRaise(true); m_buttonHome->setFocusPolicy(Qt::NoFocus); m_buttonAddTab = new ToolButton(this); m_buttonAddTab->setObjectName("navigation-button-addtab"); m_buttonAddTab->setToolTip(tr("New Tab")); m_buttonAddTab->setToolButtonStyle(Qt::ToolButtonIconOnly); m_buttonAddTab->setToolbarButtonLook(true); m_buttonAddTab->setAutoRaise(true); m_buttonAddTab->setFocusPolicy(Qt::NoFocus); m_menuBack = new Menu(this); m_menuBack->setCloseOnMiddleClick(true); m_buttonBack->setMenu(m_menuBack); connect(m_buttonBack, SIGNAL(aboutToShowMenu()), this, SLOT(aboutToShowHistoryBackMenu())); m_menuForward = new Menu(this); m_menuForward->setCloseOnMiddleClick(true); m_buttonForward->setMenu(m_menuForward); connect(m_buttonForward, SIGNAL(aboutToShowMenu()), this, SLOT(aboutToShowHistoryNextMenu())); m_supMenu = new ToolButton(this); m_supMenu->setObjectName("navigation-button-supermenu"); m_supMenu->setPopupMode(QToolButton::InstantPopup); m_supMenu->setToolbarButtonLook(true); m_supMenu->setToolTip(tr("Main Menu")); m_supMenu->setAutoRaise(true); m_supMenu->setFocusPolicy(Qt::NoFocus); m_supMenu->setMenu(m_window->superMenu()); m_supMenu->setShowMenuInside(true); m_searchLine = new WebSearchBar(m_window); m_navigationSplitter = new QSplitter(this); m_navigationSplitter->addWidget(m_window->tabWidget()->locationBars()); m_navigationSplitter->addWidget(m_searchLine); m_navigationSplitter->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); m_navigationSplitter->setCollapsible(0, false); m_exitFullscreen = new ToolButton(this); m_exitFullscreen->setObjectName("navigation-button-exitfullscreen"); m_exitFullscreen->setToolTip(tr("Exit Fullscreen")); m_exitFullscreen->setToolButtonStyle(Qt::ToolButtonIconOnly); m_exitFullscreen->setToolbarButtonLook(true); m_exitFullscreen->setFocusPolicy(Qt::NoFocus); m_exitFullscreen->setAutoRaise(true); m_exitFullscreen->setVisible(false); m_layout->addLayout(backNextLayout); m_layout->addWidget(m_reloadStop); m_layout->addWidget(m_buttonHome); m_layout->addWidget(m_buttonAddTab); m_layout->addWidget(m_navigationSplitter); m_layout->addWidget(m_supMenu); m_layout->addWidget(m_exitFullscreen); setContextMenuPolicy(Qt::CustomContextMenu); connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequested(QPoint))); connect(m_buttonBack, SIGNAL(clicked()), this, SLOT(goBack())); connect(m_buttonBack, SIGNAL(middleMouseClicked()), this, SLOT(goBackInNewTab())); connect(m_buttonBack, SIGNAL(controlClicked()), this, SLOT(goBackInNewTab())); connect(m_buttonForward, SIGNAL(clicked()), this, SLOT(goForward())); connect(m_buttonForward, SIGNAL(middleMouseClicked()), this, SLOT(goForwardInNewTab())); connect(m_buttonForward, SIGNAL(controlClicked()), this, SLOT(goForwardInNewTab())); connect(m_reloadStop, SIGNAL(stopClicked()), this, SLOT(stop())); connect(m_reloadStop, SIGNAL(reloadClicked()), this, SLOT(reload())); connect(m_buttonHome, SIGNAL(clicked()), m_window, SLOT(goHome())); connect(m_buttonHome, SIGNAL(middleMouseClicked()), m_window, SLOT(goHomeInNewTab())); connect(m_buttonHome, SIGNAL(controlClicked()), m_window, SLOT(goHomeInNewTab())); connect(m_buttonAddTab, SIGNAL(clicked()), m_window, SLOT(addTab())); connect(m_buttonAddTab, SIGNAL(middleMouseClicked()), m_window->tabWidget(), SLOT(addTabFromClipboard())); connect(m_exitFullscreen, SIGNAL(clicked(bool)), m_window, SLOT(toggleFullScreen())); }