void BookmarksToolbar::subfolderAdded(const QString &name) { ToolButton* b = new ToolButton(this); b->setPopupMode(QToolButton::InstantPopup); b->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); b->setIcon(style()->standardIcon(QStyle::SP_DirIcon)); b->setText(name); Menu* menu = new Menu(name); b->setMenu(menu); connect(menu, SIGNAL(aboutToShow()), this, SLOT(aboutToShowFolderMenu())); m_layout->insertWidget(m_layout->count() - 2, b); }
void BookmarksToolbar::refreshBookmarks() { QSqlQuery query; query.exec("SELECT id, title, url, icon FROM bookmarks WHERE folder='bookmarksToolbar' ORDER BY toolbar_position"); while (query.next()) { Bookmark bookmark; bookmark.id = query.value(0).toInt(); bookmark.title = query.value(1).toString(); bookmark.url = query.value(2).toUrl(); bookmark.icon = IconProvider::iconFromBase64(query.value(3).toByteArray()); bookmark.folder = "bookmarksToolbar"; QString title = bookmark.title; if (title.length() > 15) { title.truncate(13); title += ".."; } QVariant v; v.setValue<Bookmark>(bookmark); ToolButton* button = new ToolButton(this); button->setText(title); button->setData(v); button->setIcon(bookmark.icon); button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); button->setToolTip(bookmark.url.toEncoded()); button->setWhatsThis(bookmark.title); button->setAutoRaise(true); button->setContextMenuPolicy(Qt::CustomContextMenu); connect(button, SIGNAL(clicked()), this, SLOT(loadClickedBookmark())); connect(button, SIGNAL(middleMouseClicked()), this, SLOT(loadClickedBookmarkInNewTab())); connect(button, SIGNAL(controlClicked()), this, SLOT(loadClickedBookmarkInNewTab())); connect(button, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showBookmarkContextMenu(QPoint))); m_layout->addWidget(button); } query.exec("SELECT name FROM folders WHERE subfolder='yes'"); while (query.next()) { ToolButton* b = new ToolButton(this); b->setPopupMode(QToolButton::InstantPopup); b->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); b->setIcon(style()->standardIcon(QStyle::SP_DirIcon)); b->setText(query.value(0).toString()); Menu* menu = new Menu(query.value(0).toString()); b->setMenu(menu); connect(menu, SIGNAL(aboutToShow()), this, SLOT(aboutToShowFolderMenu())); m_layout->addWidget(b); } m_mostVis = new ToolButton(this); m_mostVis->setPopupMode(QToolButton::InstantPopup); m_mostVis->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); m_mostVis->setIcon(style()->standardIcon(QStyle::SP_DirIcon)); m_mostVis->setText(tr("Most visited")); m_mostVis->setToolTip(tr("Sites you visited the most")); m_menuMostVisited = new Menu(); m_mostVis->setMenu(m_menuMostVisited); connect(m_menuMostVisited, SIGNAL(aboutToShow()), this, SLOT(refreshMostVisited())); m_layout->addWidget(m_mostVis); m_layout->addStretch(); m_mostVis->setVisible(m_bookmarksModel->isShowingMostVisited()); }
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) + style()->pixelMetric(QStyle::PM_ToolBarFrameWidth, 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->setShowMenuOnRightClick(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->setShowMenuOnRightClick(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); QWidget *backNextWidget = new QWidget(this); backNextWidget->setLayout(backNextLayout); m_reloadStop = new ReloadStopButton(this); ToolButton *buttonHome = new ToolButton(this); buttonHome->setObjectName("navigation-button-home"); buttonHome->setToolTip(tr("Home")); buttonHome->setToolButtonStyle(Qt::ToolButtonIconOnly); buttonHome->setToolbarButtonLook(true); buttonHome->setAutoRaise(true); buttonHome->setFocusPolicy(Qt::NoFocus); ToolButton *buttonAddTab = new ToolButton(this); buttonAddTab->setObjectName("navigation-button-addtab"); buttonAddTab->setToolTip(tr("New Tab")); buttonAddTab->setToolButtonStyle(Qt::ToolButtonIconOnly); buttonAddTab->setToolbarButtonLook(true); buttonAddTab->setAutoRaise(true); 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())); ToolButton *buttonTools = new ToolButton(this); buttonTools->setObjectName("navigation-button-tools"); buttonTools->setPopupMode(QToolButton::InstantPopup); buttonTools->setToolbarButtonLook(true); buttonTools->setToolTip(tr("Tools")); buttonTools->setAutoRaise(true); buttonTools->setFocusPolicy(Qt::NoFocus); buttonTools->setShowMenuInside(true); m_menuTools = new Menu(this); buttonTools->setMenu(m_menuTools); connect(buttonTools, &ToolButton::aboutToShowMenu, this, &NavigationBar::aboutToShowToolsMenu); 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); 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(buttonHome, SIGNAL(clicked()), m_window, SLOT(goHome())); connect(buttonHome, SIGNAL(middleMouseClicked()), m_window, SLOT(goHomeInNewTab())); connect(buttonHome, SIGNAL(controlClicked()), m_window, SLOT(goHomeInNewTab())); connect(buttonAddTab, SIGNAL(clicked()), m_window, SLOT(addTab())); connect(buttonAddTab, SIGNAL(middleMouseClicked()), m_window->tabWidget(), SLOT(addTabFromClipboard())); connect(m_exitFullscreen, SIGNAL(clicked(bool)), m_window, SLOT(toggleFullScreen())); addWidget(backNextWidget, QSL("button-backforward"), tr("Back and Forward buttons")); addWidget(m_reloadStop, QSL("button-reloadstop"), tr("Reload button")); addWidget(buttonHome, QSL("button-home"), tr("Home button")); addWidget(buttonAddTab, QSL("button-addtab"), tr("Add tab button")); addWidget(m_navigationSplitter, QSL("locationbar"), tr("Address and Search bar")); addWidget(buttonTools, QSL("button-tools"), tr("Tools button")); addWidget(m_exitFullscreen, QSL("button-exitfullscreen"), tr("Exit Fullscreen button")); loadSettings(); }
ToolButton* Gui::findOrCreateToolButton(const PluginGroupNodePtr & treeNode) { // Do not create an action for non user creatable plug-ins bool isUserCreatable = true; PluginPtr internalPlugin = treeNode->getPlugin(); if (internalPlugin && treeNode->getChildren().empty() && !internalPlugin->getIsUserCreatable()) { isUserCreatable = false; } if (!isUserCreatable) { return 0; } // Check for existing toolbuttons for (std::size_t i = 0; i < _imp->_toolButtons.size(); ++i) { if (_imp->_toolButtons[i]->getPluginToolButton() == treeNode) { return _imp->_toolButtons[i]; } } // Check for parent toolbutton ToolButton* parentToolButton = NULL; if ( treeNode->getParent() ) { assert(treeNode->getParent() != treeNode); if (treeNode->getParent() != treeNode) { parentToolButton = findOrCreateToolButton( treeNode->getParent() ); } } QString resourcesPath; if (internalPlugin) { resourcesPath = QString::fromUtf8(internalPlugin->getProperty<std::string>(kNatronPluginPropResourcesPath).c_str()); } QString iconFilePath = resourcesPath; StrUtils::ensureLastPathSeparator(iconFilePath); iconFilePath += treeNode->getTreeNodeIconFilePath(); QIcon toolButtonIcon, menuIcon; // Create tool icon if ( !iconFilePath.isEmpty() && QFile::exists(iconFilePath) ) { QPixmap pix(iconFilePath); int menuSize = TO_DPIX(NATRON_MEDIUM_BUTTON_ICON_SIZE); int toolButtonSize = !treeNode->getParent() ? TO_DPIX(NATRON_TOOL_BUTTON_ICON_SIZE) : TO_DPIX(NATRON_MEDIUM_BUTTON_ICON_SIZE); QPixmap menuPix = pix, toolbuttonPix = pix; if ( (std::max( menuPix.width(), menuPix.height() ) != menuSize) && !menuPix.isNull() ) { menuPix = menuPix.scaled(menuSize, menuSize, Qt::KeepAspectRatio, Qt::SmoothTransformation); } if ( (std::max( toolbuttonPix.width(), toolbuttonPix.height() ) != toolButtonSize) && !toolbuttonPix.isNull() ) { toolbuttonPix = toolbuttonPix.scaled(toolButtonSize, toolButtonSize, Qt::KeepAspectRatio, Qt::SmoothTransformation); } menuIcon.addPixmap(menuPix); toolButtonIcon.addPixmap(toolbuttonPix); } else { // Set default icon only if it has no parent, otherwise leave action without an icon if ( !treeNode->getParent() ) { QPixmap toolbuttonPix, menuPix; getPixmapForGrouping( &toolbuttonPix, TO_DPIX(NATRON_TOOL_BUTTON_ICON_SIZE), treeNode->getTreeNodeName() ); toolButtonIcon.addPixmap(toolbuttonPix); getPixmapForGrouping( &menuPix, TO_DPIX(NATRON_TOOL_BUTTON_ICON_SIZE), treeNode->getTreeNodeName() ); menuIcon.addPixmap(menuPix); } } // If the tool-button has no children, this is a leaf, we must create an action // At this point any plug-in MUST be in a toolbutton, so it must have a parent. assert(!treeNode->getChildren().empty() || treeNode->getParent()); int majorVersion = internalPlugin ? internalPlugin->getProperty<unsigned int>(kNatronPluginPropVersion, 0) : 1; int minorVersion = internalPlugin ? internalPlugin->getProperty<unsigned int>(kNatronPluginPropVersion, 1) : 0; ToolButton* pluginsToolButton = new ToolButton(getApp(), treeNode, treeNode->getTreeNodeID(), majorVersion, minorVersion, treeNode->getTreeNodeName(), toolButtonIcon, menuIcon); if (!treeNode->getChildren().empty()) { // For grouping items, create the menu Menu* menu = new Menu(this); menu->setTitle( pluginsToolButton->getLabel() ); menu->setIcon(menuIcon); pluginsToolButton->setMenu(menu); pluginsToolButton->setAction( menu->menuAction() ); } else { // This is a leaf (plug-in) assert(internalPlugin); assert(parentToolButton); // If this is the highest major version for this plug-in use normal label, otherwise also append the major version bool isHighestMajorVersionForPlugin = internalPlugin->getIsHighestMajorVersion(); std::string pluginLabel = !isHighestMajorVersionForPlugin ? internalPlugin->getLabelVersionMajorEncoded() : internalPlugin->getLabelWithoutSuffix(); QKeySequence defaultNodeShortcut; QString shortcutGroup = QString::fromUtf8(kShortcutGroupNodes); std::vector<std::string> groupingSplit = internalPlugin->getPropertyN<std::string>(kNatronPluginPropGrouping); for (std::size_t j = 0; j < groupingSplit.size(); ++j) { shortcutGroup.push_back( QLatin1Char('/') ); shortcutGroup.push_back(QString::fromUtf8(groupingSplit[j].c_str())); } { // If the plug-in has a shortcut get it std::list<QKeySequence> keybinds = getKeybind(shortcutGroup, QString::fromUtf8(internalPlugin->getPluginID().c_str())); if (!keybinds.empty()) { defaultNodeShortcut = keybinds.front(); } } QAction* defaultPresetAction = new QAction(this); defaultPresetAction->setShortcut(defaultNodeShortcut); defaultPresetAction->setShortcutContext(Qt::WidgetShortcut); defaultPresetAction->setText(QString::fromUtf8(pluginLabel.c_str())); defaultPresetAction->setIcon( pluginsToolButton->getMenuIcon() ); QObject::connect( defaultPresetAction, SIGNAL(triggered()), pluginsToolButton, SLOT(onTriggered()) ); const std::vector<PluginPresetDescriptor>& presets = internalPlugin->getPresetFiles(); if (presets.empty()) { // If the node has no presets, just make an action, otherwise make a menu pluginsToolButton->setAction(defaultPresetAction); } else { Menu* menu = new Menu(this); menu->setTitle( pluginsToolButton->getLabel() ); menu->setIcon(menuIcon); pluginsToolButton->setMenu(menu); pluginsToolButton->setAction( menu->menuAction() ); defaultPresetAction->setText(QString::fromUtf8(pluginLabel.c_str()) + tr(" (Default)")); menu->addAction(defaultPresetAction); for (std::vector<PluginPresetDescriptor>::const_iterator it = presets.begin(); it!=presets.end(); ++it) { QKeySequence presetShortcut; { // If the preset has a shortcut get it std::string shortcutKey = internalPlugin->getPluginID(); shortcutKey += "_preset_"; shortcutKey += it->presetLabel.toStdString(); std::list<QKeySequence> keybinds = getKeybind(shortcutGroup, QString::fromUtf8(shortcutKey.c_str())); if (!keybinds.empty()) { presetShortcut = keybinds.front(); } } QString presetLabel = QString::fromUtf8(pluginLabel.c_str()); presetLabel += QLatin1String(" ("); presetLabel += it->presetLabel; presetLabel += QLatin1String(")"); QAction* presetAction = new QAction(this); QPixmap presetPix; if (getPresetIcon(it->presetFilePath, it->presetIconFile, TO_DPIX(NATRON_MEDIUM_BUTTON_ICON_SIZE), &presetPix)) { presetAction->setIcon( presetPix ); } presetAction->setShortcut(presetShortcut); presetAction->setShortcutContext(Qt::WidgetShortcut); presetAction->setText(presetLabel); presetAction->setData(it->presetLabel); QObject::connect( presetAction, SIGNAL(triggered()), pluginsToolButton, SLOT(onTriggered()) ); menu->addAction(presetAction); } } } // if (!treeNode->getChildren().empty()) // If it has a parent, add the new tool button as a child if (parentToolButton) { parentToolButton->tryAddChild(pluginsToolButton); } _imp->_toolButtons.push_back(pluginsToolButton); return pluginsToolButton; } // findOrCreateToolButton