| 35 | namespace OpenOrienteering { |
| 36 | |
| 37 | TextBrowserDialog::TextBrowserDialog(QWidget* parent) |
| 38 | : QDialog(parent) |
| 39 | , text_browser(new TextBrowser()) |
| 40 | { |
| 41 | if (parent) |
| 42 | { |
| 43 | setWindowModality(Qt::WindowModal); |
| 44 | } |
| 45 | |
| 46 | QVBoxLayout* layout = new QVBoxLayout(); |
| 47 | setLayout(layout); |
| 48 | |
| 49 | int left, top, right, bottom; |
| 50 | layout->getContentsMargins(&left, &top, &right, &bottom); |
| 51 | layout->setContentsMargins(0, 0, 0, 0); |
| 52 | layout->setSpacing(0); |
| 53 | |
| 54 | text_browser->setOpenExternalLinks(true); |
| 55 | layout->addWidget(text_browser); |
| 56 | |
| 57 | QHBoxLayout* buttons_layout = new QHBoxLayout(); |
| 58 | buttons_layout->setContentsMargins(left, top, right, bottom); |
| 59 | |
| 60 | QPushButton* back_button = new QPushButton(QIcon(QStringLiteral(":/images/arrow-left.png")), QApplication::translate("QFileDialog", "Back")); |
| 61 | back_button->setEnabled(false); |
| 62 | buttons_layout->addWidget(back_button); |
| 63 | |
| 64 | buttons_layout->addStretch(1); |
| 65 | |
| 66 | QPushButton* close_button = new QPushButton(QApplication::translate("QPlatformTheme", "Close")); |
| 67 | close_button->setDefault(true); |
| 68 | buttons_layout->addWidget(close_button); |
| 69 | |
| 70 | layout->addLayout(buttons_layout); |
| 71 | |
| 72 | connect(text_browser, &QTextBrowser::sourceChanged, this, &TextBrowserDialog::sourceChanged); |
| 73 | connect(text_browser, &QTextBrowser::textChanged, this, &TextBrowserDialog::updateWindowTitle); |
| 74 | connect(text_browser, &QTextBrowser::backwardAvailable, back_button, &TextBrowserDialog::setEnabled); |
| 75 | connect(text_browser, QOverload<const QString&>::of(&QTextBrowser::highlighted), this, &TextBrowserDialog::highlighted); |
| 76 | connect(back_button, &QPushButton::clicked, text_browser, &QTextBrowser::backward); |
| 77 | connect(close_button, &QPushButton::clicked, this, &TextBrowserDialog::accept); |
| 78 | |
| 79 | #if defined(Q_OS_ANDROID) |
| 80 | QScroller::grabGesture(text_browser->viewport(), QScroller::TouchGesture); |
| 81 | // Disable selection, so that it doesn't interfere with scrolling |
| 82 | text_browser->setTextInteractionFlags(Qt::TextInteractionFlags(Qt::TextBrowserInteraction) & ~Qt::TextSelectableByMouse); |
| 83 | // Note: Only the above combination of QScroller::LeftMouseButtonGesture |
| 84 | // and ~Qt::TextSelectableByMouse seems to achieve the desired behaviour |
| 85 | // (touch-scrolling without selecting text.) |
| 86 | |
| 87 | setWindowState((windowState() & ~(Qt::WindowMinimized | Qt::WindowFullScreen)) |
| 88 | | Qt::WindowMaximized); |
| 89 | #endif |
| 90 | } |
| 91 | |
| 92 | |
| 93 | TextBrowserDialog::TextBrowserDialog(const QUrl& initial_url, QWidget* parent) |
nothing calls this directly
no test coverage detected