20#include <QApplication>
23#include <QInputDialog>
25#include <QMdiSubWindow>
26#include <QSplashScreen>
28#ifdef BUILD_TEXT_TO_SPEECH
29#include <QTextToSpeech>
32#include "../backend/config/btconfig.h"
33#include "../backend/drivers/cswordmoduleinfo.h"
34#include "../backend/keys/cswordversekey.h"
35#include "../backend/managers/cswordbackend.h"
36#include "../util/btassert.h"
37#include "../util/cresmgr.h"
38#include "../util/directory.h"
59 -> std::enable_if_t<std::is_integral_v<std::decay_t<T>>,
T>
61 static std::mt19937 rng((std::random_device()()));
62 return std::uniform_int_distribution<std::decay_t<T>>(min, max)(rng);
66 QStringLiteral(
"startuplogo.png"),
67 QStringLiteral(
"startuplogo_christmas.png"),
68 QStringLiteral(
"startuplogo_easter.jpg"),
73 "<div style='background:transparent;color:white;font-weight:bold'>"
88 QSplashScreen * splash =
nullptr;
89 constexpr static auto const splashTextAlignment =
90 Qt::AlignHCenter | Qt::AlignTop;
92 if (
btConfig().value<bool>(QStringLiteral(
"GUI/showSplashScreen"),
true)) {
93 auto const splashNumber =
94 randInt<std::size_t>(0u,
95 std::extent_v<
decltype(splashes)> - 1u);
97 if (pm.load(DU::getPicsDir().filePath(splashes[splashNumber]))) {
98 splash =
new QSplashScreen(pm);
100 splashHtml.arg(tr(
"Initializing the SWORD engine...")),
101 splashTextAlignment);
103 qApp->processEvents();
105 qWarning(
"Can't load startuplogo! Check your installation.");
113 tr(
"Creating BibleTime's user interface...")),
114 splashTextAlignment);
115 qApp->processEvents();
121 splashHtml.arg(tr(
"Initializing menu- and toolbars...")),
122 splashTextAlignment);
123 qApp->processEvents();
124 splash->setAttribute(Qt::WA_DeleteOnClose);
125 splash->finish(
this);
132 setWindowTitle(QStringLiteral(
"BibleTime " BT_VERSION));
133 setWindowIcon(CResMgr::mainWindow::icon());
149 QList<CSwordModuleInfo *> modules,
152 qApp->setOverrideCursor(QCursor(Qt::WaitCursor));
155 switch (modules.first()->type()) {
169 qFatal(
"unknown module type");
173 displayWindow->show();
177 qApp->processEvents();
178 qApp->restoreOverrideCursor();
179 return displayWindow;
196 tr(
"Enter the unlock key for %1.").arg(module->
name()),
202 while (unlockKeyInputDialog.exec() == QDialog::Accepted) {
203 module->unlock(unlockKeyInputDialog.getUserInput());
211 auto const moduleName(module->
name());
213 backend.reloadModules();
214 module = backend.findModuleByName(moduleName);
224 tr(
"Warning: Invalid unlock key!"),
225 tr(
"The unlock key you provided did not properly unlock "
226 "this module. Please try again."));
237 dialog->setAttribute(Qt::WA_DeleteOnClose);
244 for (
auto const *
const subWindow :
m_mdi->subWindowList())
251 QString
const & bibleKey)
253 if (
btConfig().value<bool>(QStringLiteral(
"state/crashedTwoTimes"),
false))
260 if (
btConfig().value<bool>(QStringLiteral(
"state/crashedLastTime"),
false))
263 if (!bibleKey.isNull()) {
266 QStringLiteral(
"standardBible"));
267 if (bibleKey == QStringLiteral(
"random")) {
269 auto const newIndex = randInt<
decltype(vk.
index())>(0, 31100);
284 if (
btConfig().value<bool>(QStringLiteral(
"state/crashedLastTime"),
false)){
296 if (
event->type() == QEvent::PaletteChange) {
299 }
else if (
event->type() == QEvent::KeyPress) {
300 if (
static_cast<QKeyEvent *
>(
event)->modifiers() > 0)
305 return QMainWindow::event(
event);
309 if (
auto *
const activeSubWindow =
m_mdi->activeSubWindow())
310 if (
auto *
const displayWindow =
312 return displayWindow->firstModule();
317 if (
auto *
const activeSubWindow =
m_mdi->activeSubWindow())
318 if (
auto *
const displayWindow =
320 return displayWindow->displayWidget();
330 QString
const & searchText)
339#ifdef BUILD_TEXT_TO_SPEECH
340void BibleTime::speakText(QString
const & text) {
342 m_textToSpeech = createTextToSpeechInstance();
344 m_textToSpeech->say(text);
347std::unique_ptr<QTextToSpeech> BibleTime::createTextToSpeechInstance() {
348 std::unique_ptr<QTextToSpeech> tts;
351 auto const configuredEngine =
btConfig().
value<QString>(QStringLiteral(
"GUI/ttsEngine"));
352 if (QTextToSpeech::availableEngines().contains(configuredEngine)) {
353 tts = std::make_unique<QTextToSpeech>(configuredEngine);
355 tts = std::make_unique<QTextToSpeech>();
358 auto const configuredLocale =
btConfig().
value<QLocale>(QStringLiteral(
"GUI/ttsLocale"));
359 if (tts->availableLocales().contains(configuredLocale))
360 tts->setLocale(configuredLocale);
362 auto const configuredVoice =
btConfig().
value<QString>(QStringLiteral(
"GUI/ttsVoice"));
363 for (
auto const & voice : tts->availableVoices()) {
364 if (voice.name() == configuredVoice) {
365 tts->setVoice(voice);
BtConfig & btConfig()
This is a shortchand for BtConfig::getInstance().
QList< CSwordModuleInfo const * > BtConstModuleList
QPointer< QWidget > m_debugWindow
void slotModuleUnlock(CSwordModuleInfo *module)
BtBookshelfDockWidget * m_bookshelfDock
static bool moduleUnlock(CSwordModuleInfo *module, QWidget *parent=nullptr)
void moduleAbout(CSwordModuleInfo *module)
bool event(QEvent *event) override
void openSearchDialog(BtConstModuleList modules, QString const &searchText={})
static BibleTime * m_instance
BtFindWidget * m_findWidget
QPointer< Search::CSearchDialog > m_searchDialog
CSwordModuleInfo const * getCurrentModule()
BtModelViewReadDisplay * getCurrentDisplay()
void processCommandline(bool ignoreSession, QString const &bibleKey)
CDisplayWindow * createReadDisplayWindow(QList< CSwordModuleInfo * > modules, QString const &key)
Creates a new presenter in the MDI area according to the type of the module.
void refreshDisplayWindows() const
BibleTime(BibleTimeApp &app, QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::WindowFlags())
void sync()
Synchronizes the configuration to disk.
T value(QString const &key, T const &defaultValue=T()) const
Returns the settings value for the given global key.
void setValue(QString const &key, T const &value)
Sets a value for a key.
CSwordModuleInfo * getDefaultSwordModuleByType(const QString &moduleType)
Returns default sword module info class for a given module type.
The base class for all display windows of BibleTime.
The class used to display lexicons.
QMdiSubWindow * addDisplayWindow(CDisplayWindow *displayWindow)
static CSwordBackend & instance() noexcept
QString config(const CSwordModuleInfo::ConfigEntry entry) const
QString const & name() const
CSwordKey implementation for Sword's VerseKey.
QString key() const final override
auto randInt(T min, T max) -> std::enable_if_t< std::is_integral_v< std::decay_t< T > >, T >
QMessageBox::StandardButton showWarning(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)