void MusicHotKeyManager::setHotKeys(const QStringList &keys) { for(int i=0; i<m_hotkeys.count(); ++i) { setHotKey(i, keys[i]); setEnabled(i, false); } }
void MusicHotKeyManager::setDefaultKey() { QStringList keys(getDefaultKeys()); for(int i=0; i<m_hotkeys.count(); ++i) { setHotKey(i, keys[i]); setEnabled(i, false); } }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), settings("Zeal", "Zeal"), settingsDialog(zealList) { trayIcon = nullptr; trayIconMenu = nullptr; // Use the platform-specific proxy settings QNetworkProxyFactory::setUseSystemConfiguration(true); // server for detecting already running instances localServer = new QLocalServer(this); connect(localServer, &QLocalServer::newConnection, [&]() { QLocalSocket *connection = localServer->nextPendingConnection(); // Wait a little while the other side writes the bytes connection->waitForReadyRead(); QString indata = connection->readAll(); if(!indata.isEmpty()) { bringToFrontAndSearch(indata); } }); QLocalServer::removeServer(serverName); // remove in case previous instance crashed localServer->listen(serverName); // initialise icons #if defined(WIN32) || defined(OSX) icon = qApp->style()->standardIcon(QStyle::SP_MessageBoxInformation); #else icon = QIcon::fromTheme("edit-find"); #endif setWindowIcon(icon); if(settings.value("hidingBehavior", "systray").toString() == "systray") createTrayIcon(); QKeySequence keySequence; if(settings.value("hotkey").isNull()) { keySequence = QKeySequence("Alt+Space"); } else { keySequence = settings.value("hotkey").value<QKeySequence>(); } // initialise key grabber connect(&nativeFilter, &ZealNativeEventFilter::gotHotKey, [&]() { if(!isVisible() || !isActiveWindow()) { bringToFront(true); } else { if(trayIcon) { hide(); } else { showMinimized(); } } }); qApp->eventDispatcher()->installNativeEventFilter(&nativeFilter); setHotKey(keySequence); // initialise docsets docsets->initialiseDocsets(); // initialise ui ui->setupUi(this); setupShortcuts(); restoreGeometry(settings.value("geometry").toByteArray()); ui->splitter->restoreState(settings.value("splitter").toByteArray()); connect(ui->splitter, &QSplitter::splitterMoved, [=](int, int) { settings.setValue("splitter", ui->splitter->saveState()); }); ui->webView->settings()->setFontSize(QWebSettings::MinimumFontSize, settings.value("minFontSize").toInt()); ZealNetworkAccessManager * zealNaManager = new ZealNetworkAccessManager(); ui->webView->page()->setNetworkAccessManager(zealNaManager); // menu ui->action_Quit->setShortcut(QKeySequence::Quit); connect(ui->action_Quit, &QAction::triggered, [=]() { settings.setValue("geometry", saveGeometry()); }); connect(ui->action_Quit, SIGNAL(triggered()), qApp, SLOT(quit())); connect(&settingsDialog, SIGNAL(refreshRequested()), this, SLOT(refreshRequest())); connect(&settingsDialog, SIGNAL(minFontSizeChanged(int)), this, SLOT(changeMinFontSize(int))); connect(ui->action_Options, &QAction::triggered, [=]() { settingsDialog.setHotKey(hotKey); nativeFilter.setEnabled(false); if(settingsDialog.exec()) { setHotKey(settingsDialog.hotKey()); if(settings.value("hidingBehavior").toString() == "systray") { createTrayIcon(); } else if(trayIcon) { trayIcon->deleteLater(); trayIconMenu->deleteLater(); trayIcon = nullptr; trayIconMenu = nullptr; } } else { // cancelled - restore previous value ui->webView->settings()->setFontSize(QWebSettings::MinimumFontSize, settings.value("minFontSize").toInt()); } nativeFilter.setEnabled(true); ui->treeView->reset(); }); ui->action_Back->setShortcut(QKeySequence::Back); ui->action_Forward->setShortcut(QKeySequence::Forward); connect(ui->action_Back, &QAction::triggered, this, &MainWindow::back); connect(ui->action_Forward, &QAction::triggered, this, &MainWindow::forward); connect(ui->action_About, &QAction::triggered, [&]() { QMessageBox::about(this, "About Zeal", QString("This is Zeal ") + ZEAL_VERSION + " - a documentation browser.\n\n" "For details see http://zealdocs.org/"); }); connect(ui->action_About_QT, &QAction::triggered, [&]() { QMessageBox::aboutQt(this); }); displayViewActions(); // treeView and lineEdit ui->lineEdit->setTreeView(ui->treeView); ui->lineEdit->setFocus(); ui->treeView->setModel(&zealList); ui->treeView->setColumnHidden(1, true); ui->treeView->setItemDelegate(new ZealSearchItemDelegate(ui->treeView, ui->lineEdit, ui->treeView)); #if QT_VERSION < QT_VERSION_CHECK(5, 1, 0) && defined(WIN32) // overriding subElementRect doesn't work with Qt 5.0.0, but is required to display // selected item frame correctly in Windows (for patch see https://codereview.qt-project.org/#change,46559) // This is a workaround for Qt < 5.1 - selecting whole rows leads to always rendering the frame. // (Only the frame is larger than the list item, which is different from default behaviour.) ui->treeView->setSelectionBehavior(QAbstractItemView::SelectRows); #endif connect(ui->treeView, &QTreeView::clicked, [&](const QModelIndex& index) { ui->treeView->activated(index); }); connect(ui->treeView, &QTreeView::activated, [&](const QModelIndex& index) { if(!index.sibling(index.row(), 1).data().isNull()) { QStringList url_l = index.sibling(index.row(), 1).data().toString().split('#'); QUrl url = QUrl::fromLocalFile(url_l[0]); if(url_l.count() > 1) { url.setFragment(url_l[1]); } ui->webView->load(url); } }); connect(ui->forwardButton, &QPushButton::clicked, this, &MainWindow::forward); connect(ui->backButton, &QPushButton::clicked, this, &MainWindow::back); connect(ui->webView, &SearchableWebView::urlChanged, [&](const QUrl &url) { QString urlPath = url.path(); QString docsetName = getDocsetName(urlPath); QPixmap docsetMap = docsets->icon(docsetName).pixmap(32,32); // paint label with the icon ui->pageIcon->setPixmap(docsetMap); displayViewActions(); }); connect(ui->webView, &SearchableWebView::titleChanged, [&](const QString &title) { if (!title.isEmpty()) { ui->pageTitle->setText(title); } }); connect(&zealSearch, &ZealSearchModel::queryCompleted, [&]() { ui->treeView->setModel(&zealSearch); ui->treeView->reset(); ui->treeView->setColumnHidden(1, true); ui->treeView->setCurrentIndex(zealSearch.index(0, 0, QModelIndex())); ui->treeView->activated(ui->treeView->currentIndex()); }); connect(ui->lineEdit, &QLineEdit::textChanged, [&](const QString& text) { zealSearch.setQuery(text); if(text.isEmpty()) { ui->treeView->setModel(&zealList); } }); }