Editor::Editor(QWidget *parent) : QsciScintilla(parent) { setupShortcuts(); connect(this, SIGNAL(selectionChanged()), this, SLOT(updateSelectionOrigin())); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), m_settings(), m_databaseOK(false), m_tuloksia(0), m_kilpailijoita(0), m_tuloksiaLabel(new QLabel(this)), m_serialStatus(new QLabel(this)), m_testEmitReader(0), m_serialEmitReader(new SerialEmitReaderWidget()), m_pikanappaimetForm(0), m_vuokraEmititForm(0), m_tulosnayttoForm(0) { ui->setupUi(this); connect(m_serialEmitReader, SIGNAL(readEmit(QDateTime,QString,int,int,QList<RastiData>)), this, SLOT(handleReadEmit(QDateTime,QString,int,int,QList<RastiData>))); connect(m_serialEmitReader, SIGNAL(statusChanged(QString)), m_serialStatus, SLOT(setText(QString))); connect(ui->menuSarjaportti, SIGNAL(aboutToShow()), this, SLOT(setupSerialMenu())); connect(ui->menuSarjaportti, SIGNAL(triggered(QAction*)), this, SLOT(handleSerialMenu(QAction*))); connectDatabase(); buildDatabase(); if (!Tietokanta::checkVersion(MAJOR_VERSION)) { QString v = Tietokanta::getVersion(); if (QMessageBox::question(this, _("Tulospalvelu - " VERSION), _("Tietokanta (%1) ei ole yhteensopiva. Haluatko jatkaa?") .arg(v), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes) { return; } } setupTapahtuma(); setupShortcuts(); }
/* Entrypoint */ int main(int argc, char **argv) { int result = 0; QApplication::setApplicationDisplayName("pengsh"); QApplication::setApplicationName("pengsh"); QApplication::setOrganizationName("jchadwick"); QApplication::setOrganizationDomain("jchadwick.net"); QApplication a(argc, argv); a.setQuitOnLastWindowClosed(false); settings.load(); nm = new QNetworkAccessManager(); setupActions(); setupMenu(); setupShortcuts(); if (settings.apiKey.isEmpty()) if (!loginPrompt()) return 0; trayicon = new QSystemTrayIcon(QIcon(":/icon.png")); trayicon->setContextMenu(menu); trayicon->show(); QObject::connect(trayicon, &QSystemTrayIcon::activated, &trayClicked); history(); setupMenu(); result = a.exec(); settings.flush(); return result; }
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); } }); }
PropertiesDialog::PropertiesDialog(QWidget *parent) : QDialog(parent) { setupUi(this); connect(buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(apply())); connect(changeFontButton, SIGNAL(clicked()), this, SLOT(changeFontButton_clicked())); connect(chooseBackgroundImageButton, &QPushButton::clicked, this, &PropertiesDialog::chooseBackgroundImageButton_clicked); QStringList emulations = QTermWidget::availableKeyBindings(); QStringList colorSchemes = QTermWidget::availableColorSchemes(); listWidget->setCurrentRow(0); listWidget->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContentsOnFirstShow); colorSchemaCombo->addItems(colorSchemes); int csix = colorSchemaCombo->findText(Properties::Instance()->colorScheme); if (csix != -1) colorSchemaCombo->setCurrentIndex(csix); backgroundImageLineEdit->setText(Properties::Instance()->backgroundImage); emulationComboBox->addItems(emulations); int eix = emulationComboBox->findText(Properties::Instance()->emulation); emulationComboBox->setCurrentIndex(eix != -1 ? eix : 0 ); /* shortcuts */ setupShortcuts(); /* scrollbar position */ QStringList scrollBarPosList; scrollBarPosList << tr("No scrollbar") << tr("Left") << tr("Right"); scrollBarPos_comboBox->addItems(scrollBarPosList); scrollBarPos_comboBox->setCurrentIndex(Properties::Instance()->scrollBarPos); /* tabs position */ QStringList tabsPosList; tabsPosList << tr("Top") << tr("Bottom") << tr("Left") << tr("Right"); tabsPos_comboBox->addItems(tabsPosList); tabsPos_comboBox->setCurrentIndex(Properties::Instance()->tabsPos); /* keyboard cursor shape */ QStringList keyboardCursorShapeList; keyboardCursorShapeList << tr("BlockCursor") << tr("UnderlineCursor") << tr("IBeamCursor"); keybCursorShape_comboBox->addItems(keyboardCursorShapeList); keybCursorShape_comboBox->setCurrentIndex(Properties::Instance()->keyboardCursorShape); hideTabBarCheckBox->setChecked(Properties::Instance()->hideTabBarWithOneTab); // show main menu bar showMenuCheckBox->setChecked(Properties::Instance()->menuVisible); /* actions by motion after paste */ QStringList motionAfter; motionAfter << tr("No move") << tr("Move start") << tr("Move end"); motionAfterPasting_comboBox->addItems(motionAfter); motionAfterPasting_comboBox->setCurrentIndex(Properties::Instance()->m_motionAfterPaste); // Setting windows style actions styleComboBox->addItem(tr("System Default")); styleComboBox->addItems(QStyleFactory::keys()); int ix = styleComboBox->findText(Properties::Instance()->guiStyle); if (ix != -1) styleComboBox->setCurrentIndex(ix); setFontSample(Properties::Instance()->font); appTransparencyBox->setValue(Properties::Instance()->appTransparency); termTransparencyBox->setValue(Properties::Instance()->termTransparency); highlightCurrentCheckBox->setChecked(Properties::Instance()->highlightCurrentTerminal); askOnExitCheckBox->setChecked(Properties::Instance()->askOnExit); savePosOnExitCheckBox->setChecked(Properties::Instance()->savePosOnExit); saveSizeOnExitCheckBox->setChecked(Properties::Instance()->saveSizeOnExit); useCwdCheckBox->setChecked(Properties::Instance()->useCWD); historyLimited->setChecked(Properties::Instance()->historyLimited); historyUnlimited->setChecked(!Properties::Instance()->historyLimited); historyLimitedTo->setValue(Properties::Instance()->historyLimitedTo); dropShowOnStartCheckBox->setChecked(Properties::Instance()->dropShowOnStart); dropHeightSpinBox->setValue(Properties::Instance()->dropHeight); dropHeightSpinBox->setMaximum(100); dropWidthSpinBox->setValue(Properties::Instance()->dropWidht); dropWidthSpinBox->setMaximum(100); dropShortCutEdit->setText(Properties::Instance()->dropShortCut.toString()); useBookmarksCheckBox->setChecked(Properties::Instance()->useBookmarks); bookmarksLineEdit->setText(Properties::Instance()->bookmarksFile); openBookmarksFile(Properties::Instance()->bookmarksFile); connect(bookmarksButton, SIGNAL(clicked()), this, SLOT(bookmarksButton_clicked())); terminalPresetComboBox->setCurrentIndex(Properties::Instance()->terminalsPreset); changeWindowTitleCheckBox->setChecked(Properties::Instance()->changeWindowTitle); changeWindowIconCheckBox->setChecked(Properties::Instance()->changeWindowIcon); trimPastedTrailingNewlinesCheckBox->setChecked(Properties::Instance()->trimPastedTrailingNewlines); confirmMultilinePasteCheckBox->setChecked(Properties::Instance()->confirmMultilinePaste); }
PropertiesDialog::PropertiesDialog(QWidget *parent) : QDialog(parent) { setupUi(this); connect(buttonBox->button(QDialogButtonBox::Apply), &QPushButton::clicked, this, &PropertiesDialog::apply); connect(changeFontButton, &QPushButton::clicked, this, &PropertiesDialog::changeFontButton_clicked); connect(chooseBackgroundImageButton, &QPushButton::clicked, this, &PropertiesDialog::chooseBackgroundImageButton_clicked); QStringList emulations = QTermWidget::availableKeyBindings(); QStringList colorSchemes = QTermWidget::availableColorSchemes(); colorSchemes.sort(Qt::CaseInsensitive); listWidget->setCurrentRow(0); listWidget->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContentsOnFirstShow); colorSchemaCombo->addItems(colorSchemes); int csix = colorSchemaCombo->findText(Properties::Instance()->colorScheme); if (csix != -1) colorSchemaCombo->setCurrentIndex(csix); backgroundImageLineEdit->setText(Properties::Instance()->backgroundImage); emulationComboBox->addItems(emulations); int eix = emulationComboBox->findText(Properties::Instance()->emulation); emulationComboBox->setCurrentIndex(eix != -1 ? eix : 0 ); /* set the delegate of shortcut widget as well as its contents */ Delegate *del = new Delegate(shortcutsWidget); shortcutsWidget->setItemDelegate(del); shortcutsWidget->sortByColumn(0, Qt::AscendingOrder); setupShortcuts(); /* scrollbar position */ QStringList scrollBarPosList; scrollBarPosList << tr("No scrollbar") << tr("Left") << tr("Right"); scrollBarPos_comboBox->addItems(scrollBarPosList); scrollBarPos_comboBox->setCurrentIndex(Properties::Instance()->scrollBarPos); /* tabs position */ QStringList tabsPosList; tabsPosList << tr("Top") << tr("Bottom") << tr("Left") << tr("Right"); tabsPos_comboBox->addItems(tabsPosList); tabsPos_comboBox->setCurrentIndex(Properties::Instance()->tabsPos); /* tab width */ fixedTabWidthCheckBox->setChecked(Properties::Instance()->fixedTabWidth); fixedTabWidthSpinBox->setValue(Properties::Instance()->fixedTabWidthValue); closeTabButtonCheckBox->setChecked(Properties::Instance()->showCloseTabButton); /* keyboard cursor shape */ QStringList keyboardCursorShapeList; keyboardCursorShapeList << tr("BlockCursor") << tr("UnderlineCursor") << tr("IBeamCursor"); keybCursorShape_comboBox->addItems(keyboardCursorShapeList); keybCursorShape_comboBox->setCurrentIndex(Properties::Instance()->keyboardCursorShape); hideTabBarCheckBox->setChecked(Properties::Instance()->hideTabBarWithOneTab); // show main menu bar showMenuCheckBox->setChecked(Properties::Instance()->menuVisible); /* actions by motion after paste */ QStringList motionAfter; motionAfter << tr("No move") << tr("Move start") << tr("Move end"); motionAfterPasting_comboBox->addItems(motionAfter); motionAfterPasting_comboBox->setCurrentIndex(Properties::Instance()->m_motionAfterPaste); // Setting windows style actions styleComboBox->addItem(tr("System Default")); styleComboBox->addItems(QStyleFactory::keys()); int ix = styleComboBox->findText(Properties::Instance()->guiStyle); if (ix != -1) styleComboBox->setCurrentIndex(ix); setFontSample(Properties::Instance()->font); terminalMarginSpinBox->setValue(Properties::Instance()->terminalMargin); appTransparencyBox->setValue(Properties::Instance()->appTransparency); termTransparencyBox->setValue(Properties::Instance()->termTransparency); highlightCurrentCheckBox->setChecked(Properties::Instance()->highlightCurrentTerminal); showTerminalSizeHintCheckBox->setChecked(Properties::Instance()->showTerminalSizeHint); askOnExitCheckBox->setChecked(Properties::Instance()->askOnExit); savePosOnExitCheckBox->setChecked(Properties::Instance()->savePosOnExit); saveSizeOnExitCheckBox->setChecked(Properties::Instance()->saveSizeOnExit); useCwdCheckBox->setChecked(Properties::Instance()->useCWD); termComboBox->setCurrentText(Properties::Instance()->term); historyLimited->setChecked(Properties::Instance()->historyLimited); historyUnlimited->setChecked(!Properties::Instance()->historyLimited); historyLimitedTo->setValue(Properties::Instance()->historyLimitedTo); dropShowOnStartCheckBox->setChecked(Properties::Instance()->dropShowOnStart); dropHeightSpinBox->setValue(Properties::Instance()->dropHeight); dropHeightSpinBox->setMaximum(100); dropWidthSpinBox->setValue(Properties::Instance()->dropWidht); dropWidthSpinBox->setMaximum(100); dropShortCutEdit->setText(Properties::Instance()->dropShortCut.toString()); useBookmarksCheckBox->setChecked(Properties::Instance()->useBookmarks); bookmarksLineEdit->setText(Properties::Instance()->bookmarksFile); openBookmarksFile(Properties::Instance()->bookmarksFile); connect(bookmarksButton, &QPushButton::clicked, this, &PropertiesDialog::bookmarksButton_clicked); terminalPresetComboBox->setCurrentIndex(Properties::Instance()->terminalsPreset); changeWindowTitleCheckBox->setChecked(Properties::Instance()->changeWindowTitle); changeWindowIconCheckBox->setChecked(Properties::Instance()->changeWindowIcon); enabledBidiSupportCheckBox->setChecked(Properties::Instance()->enabledBidiSupport); trimPastedTrailingNewlinesCheckBox->setChecked(Properties::Instance()->trimPastedTrailingNewlines); confirmMultilinePasteCheckBox->setChecked(Properties::Instance()->confirmMultilinePaste); // show it compact inside available desktop geometry QSize ag; if (parent != nullptr) { if (QWindow *win = parent->windowHandle()) { if (QScreen *sc = win->screen()) ag = sc->availableVirtualGeometry().size(); } } resize(sizeHint().boundedTo(ag)); }
PropertiesDialog::PropertiesDialog(QWidget *parent) : QDialog(parent) { setupUi(this); connect(buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(apply())); connect(changeFontButton, SIGNAL(clicked()), this, SLOT(changeFontButton_clicked())); QStringList emulations = QTermWidget::availableKeyBindings(); QStringList colorSchemes = QTermWidget::availableColorSchemes(); listWidget->setCurrentRow(0); colorSchemaCombo->addItems(colorSchemes); int csix = colorSchemaCombo->findText(Properties::Instance()->colorScheme); if (csix != -1) colorSchemaCombo->setCurrentIndex(csix); emulationComboBox->addItems(emulations); int eix = emulationComboBox->findText(Properties::Instance()->emulation); emulationComboBox->setCurrentIndex(eix != -1 ? eix : 0 ); /* shortcuts */ setupShortcuts(); /* scrollbar position */ QStringList scrollBarPosList; scrollBarPosList << "No scrollbar" << "Left" << "Right"; scrollBarPos_comboBox->addItems(scrollBarPosList); scrollBarPos_comboBox->setCurrentIndex(Properties::Instance()->scrollBarPos); /* tabs position */ QStringList tabsPosList; tabsPosList << "Top" << "Bottom" << "Left" << "Right"; tabsPos_comboBox->addItems(tabsPosList); tabsPos_comboBox->setCurrentIndex(Properties::Instance()->tabsPos); /* actions by motion after paste */ QStringList motionAfter; motionAfter << "No move" << "Move start" << "Move end"; motionAfterPasting_comboBox->addItems(motionAfter); motionAfterPasting_comboBox->setCurrentIndex(Properties::Instance()->m_motionAfterPaste); // Setting windows style actions styleComboBox->addItem(tr("System Default")); styleComboBox->addItems(QStyleFactory::keys()); int ix = styleComboBox->findText(Properties::Instance()->guiStyle); if (ix != -1) styleComboBox->setCurrentIndex(ix); setFontSample(Properties::Instance()->font); appOpacityBox->setValue(Properties::Instance()->appOpacity); //connect(appOpacityBox, SIGNAL(valueChanged(int)), this, SLOT(apply())); termOpacityBox->setValue(Properties::Instance()->termOpacity); //connect(termOpacityBox, SIGNAL(valueChanged(int)), this, SLOT(apply())); highlightCurrentCheckBox->setChecked(Properties::Instance()->highlightCurrentTerminal); historyLimited->setChecked(Properties::Instance()->historyLimited); historyUnlimited->setChecked(!Properties::Instance()->historyLimited); historyLimitedTo->setValue(Properties::Instance()->historyLimitedTo); dropShowOnStartCheckBox->setChecked(Properties::Instance()->dropShowOnStart); dropHeightSpinBox->setValue(Properties::Instance()->dropHeight); dropWidthSpinBox->setValue(Properties::Instance()->dropWidht); dropShortCutEdit->setText(Properties::Instance()->dropShortCut.toString()); }