void CLoginButton::menuCreate() { QMenu* menu = new QMenu(this); QWidget *w = new QWidget(this); ui = new Ui::loginWidget; ui->setupUi(w); ui->toolButton->setEnabled(false); connect(ui->lineEdit, &QLineEdit::textChanged, this, &CLoginButton::usernameCheck); connect(ui->toolButton, &QToolButton::clicked, this, &CLoginButton::login); QVBoxLayout *vlayout = new QVBoxLayout; vlayout->addWidget(w); menu->setLayout(vlayout); QPixmap pixmap(":/back/ui/back/combox.png"); menu->setMask(pixmap.mask()); menu->setStyleSheet("color:white; background-color: rgb(85, 92, 120);"); menu->installEventFilter(this); setMenu(menu); }
void KrBookmarkHandler::buildMenu(KrBookmark *parent, QMenu *menu) { static int inSecondaryMenu = 0; // used to know if we're on the top menu // run the loop twice, in order to put the folders on top. stupid but easy :-) // note: this code drops the separators put there by the user QListIterator<KrBookmark *> it(parent->children()); while (it.hasNext()) { KrBookmark *bm = it.next(); if (!bm->isFolder()) continue; QMenu *newMenu = new QMenu(menu); newMenu->setIcon(QIcon(krLoader->loadIcon(bm->iconName(), KIconLoader::Small))); newMenu->setTitle(bm->text()); QAction *menuAction = menu->addMenu(newMenu); QVariant v; v.setValue<KrBookmark *>(bm); menuAction->setData(v); ++inSecondaryMenu; buildMenu(bm, newMenu); --inSecondaryMenu; } it.toFront(); while (it.hasNext()) { KrBookmark *bm = it.next(); if (bm->isFolder()) continue; if (bm->isSeparator()) { menu->addSeparator(); continue; } menu->addAction(bm); CONNECT_BM(bm); } if (!inSecondaryMenu) { KConfigGroup group(krConfig, "Private"); bool hasPopularURLs = group.readEntry("BM Popular URLs", true); bool hasTrash = group.readEntry("BM Trash", true); bool hasLan = group.readEntry("BM Lan", true); bool hasVirtualFS = group.readEntry("BM Virtual FS", true); bool hasJumpback = group.readEntry("BM Jumpback", true); if (hasPopularURLs) { menu->addSeparator(); // add the popular links submenu QMenu *newMenu = new QMenu(menu); newMenu->setTitle(i18n("Popular URLs")); newMenu->setIcon(QIcon(krLoader->loadIcon("folder-bookmark", KIconLoader::Small))); QAction *bmfAct = menu->addMenu(newMenu); _specialBookmarks.append(bmfAct); // add the top 15 urls #define MAX 15 QList<QUrl> list = _mainWindow->popularUrls()->getMostPopularUrls(MAX); QList<QUrl>::Iterator it; for (it = list.begin(); it != list.end(); ++it) { QString name; if ((*it).isLocalFile()) name = (*it).path(); else name = (*it).toDisplayString(); // note: these bookmark are put into the private collection // as to not spam the general collection KrBookmark *bm = KrBookmark::getExistingBookmark(name, _privateCollection); if (!bm) bm = new KrBookmark(name, *it, _privateCollection); newMenu->addAction(bm); CONNECT_BM(bm); } newMenu->addSeparator(); newMenu->addAction(krPopularUrls); newMenu->installEventFilter(this); } // do we need to add special bookmarks? if (SPECIAL_BOOKMARKS) { if (hasTrash || hasLan || hasVirtualFS || hasJumpback) menu->addSeparator(); KrBookmark *bm; // note: special bookmarks are not kept inside the _bookmarks list and added ad-hoc if (hasTrash) { bm = KrBookmark::trash(_collection); menu->addAction(bm); _specialBookmarks.append(bm); CONNECT_BM(bm); } if (hasLan) { bm = KrBookmark::lan(_collection); menu->addAction(bm); _specialBookmarks.append(bm); CONNECT_BM(bm); } if (hasVirtualFS) { bm = KrBookmark::virt(_collection); menu->addAction(bm); _specialBookmarks.append(bm); CONNECT_BM(bm); } if (hasJumpback) { // add the jump-back button ListPanelActions *actions = _mainWindow->listPanelActions(); menu->addAction(actions->actJumpBack); _specialBookmarks.append(actions->actJumpBack); menu->addSeparator(); menu->addAction(actions->actSetJumpBack); _specialBookmarks.append(actions->actSetJumpBack); } } if (!hasJumpback) menu->addSeparator(); menu->addAction(KrActions::actAddBookmark); _specialBookmarks.append(KrActions::actAddBookmark); QAction *bmAct = menu->addAction(krLoader->loadIcon("bookmarks", KIconLoader::Small), i18n("Manage Bookmarks"), manager, SLOT(slotEditBookmarks())); _specialBookmarks.append(bmAct); // make sure the menu is connected to us disconnect(menu, SIGNAL(triggered(QAction *)), 0, 0); }
void MainWindow::menuBookmarksAboutToShow() { QMenu *menu = qobject_cast<QMenu*>(sender()); if (!menu || !menu->menuAction()) { return; } menu->setObjectName(QLatin1String("bookmarks")); menu->installEventFilter(this); const int folder = menu->menuAction()->data().toInt(); if ((folder == 0 && menu->actions().count() == 3) || (folder != 0 && menu->actions().isEmpty())) { WebBackend *backend = WebBackendsManager::getBackend(); const QList<BookmarkInformation*> bookmarks = BookmarksManager::getFolder(folder); if (folder != 0 && bookmarks.count() > 1) { QAction *openAllAction = menu->addAction(Utils::getIcon(QLatin1String("document-open-folder")), tr("Open All")); openAllAction->setData(folder); connect(openAllAction, SIGNAL(triggered()), this, SLOT(actionOpenBookmarkFolder())); menu->addSeparator(); } for (int i = 0; i < bookmarks.count(); ++i) { if (bookmarks.at(i)->type == FolderBookmark || bookmarks.at(i)->type == UrlBookmark) { QAction *action = menu->addAction(((bookmarks.at(i)->type == FolderBookmark) ? Utils::getIcon(QLatin1String("inode-directory")) : backend->getIconForUrl(QUrl(bookmarks.at(i)->url))), (bookmarks.at(i)->title.isEmpty() ? tr("(Untitled)") : Utils::elideText(QString(bookmarks.at(i)->title).replace(QLatin1Char('&'), QLatin1String("&&")), menu))); action->setToolTip(bookmarks.at(i)->description); if (bookmarks.at(i)->type == FolderBookmark) { action->setData(bookmarks.at(i)->identifier); if (!bookmarks.at(i)->children.isEmpty()) { action->setMenu(new QMenu()); connect(action->menu(), SIGNAL(aboutToShow()), this, SLOT(menuBookmarksAboutToShow())); } } else { action->setData(bookmarks.at(i)->url); connect(action, SIGNAL(triggered()), this, SLOT(actionOpenBookmark())); } } else { menu->addSeparator(); } } } }