diff --git a/src/doc/dev/settings.txt b/src/doc/dev/settings.txt --- a/src/doc/dev/settings.txt +++ b/src/doc/dev/settings.txt @@ -20,6 +20,11 @@ # in the Control Center. - SingleClickOpensItem [boolean] (default: true on Windows, system settings elsewhere) +# Controls display of the global search box. +# This option allows to disable the box if it crashes for reason unrelated to KEXI +# (as in bug #390794). +- GlobalSearchBoxEnabled [boolean] (default: true) + Group: PropertyEditor # Font size in pixels. Obsolete since Kexi 3. See FontPointSize instead. -FontSize [integer] (default: system settings) diff --git a/src/main/KexiMainWindow_p.h b/src/main/KexiMainWindow_p.h --- a/src/main/KexiMainWindow_p.h +++ b/src/main/KexiMainWindow_p.h @@ -1,6 +1,6 @@ /* This file is part of the KDE project Copyright (C) 2003 Lucijan Busch - Copyright (C) 2003-2016 Jarosław Staniek + Copyright (C) 2003-2018 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -254,14 +254,18 @@ void toggleMainMenu(); void updateMainMenuGeometry(); + //! Initializes global search line edit. If it is enabled, it's created, if disabled, it's deleted. + void initSearchLineEdit(); + public: KexiTabbedToolBarTabBar *customTabBar; QPointer mainMenu; KexiTabbedToolBar *q; KActionCollection *ac; int createId; KToolBar *createWidgetToolBar; + QHBoxLayout *helpLayer; #ifdef KEXI_AUTORISE_TABBED_TOOLBAR //! Used for delayed tab raising int tabToRaise; @@ -279,7 +283,7 @@ QGraphicsOpacityEffect tabBarOpacityEffect; int rolledUpIndex; KHelpMenu *helpMenu; - KexiSearchLineEdit *searchLineEdit; + KexiSearchLineEdit *searchLineEdit = nullptr; void setCurrentTab(const QString& name); void hideTab(const QString& name); void showTab(const QString& name); diff --git a/src/main/KexiMainWindow_p.cpp b/src/main/KexiMainWindow_p.cpp --- a/src/main/KexiMainWindow_p.cpp +++ b/src/main/KexiMainWindow_p.cpp @@ -1,6 +1,6 @@ /* This file is part of the KDE project Copyright (C) 2003 Lucijan Busch - Copyright (C) 2003-2015 Jarosław Staniek + Copyright (C) 2003-2018 Jarosław Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -23,6 +23,8 @@ #include #include +#include + #include #include @@ -565,8 +567,28 @@ mainWindow->height() - pos.y() + overlap /*+ q->y()*/); } +void KexiTabbedToolBar::Private::initSearchLineEdit() +{ + //! @todo use KexiConfig + KConfigGroup mainWindowGroup(KSharedConfig::openConfig()->group("MainWindow")); + const bool enabled = mainWindowGroup.readEntry("GlobalSearchBoxEnabled", true); + if (enabled && !searchLineEdit) { + searchLineEdit = new KexiSearchLineEdit; + kexiTester() << KexiTestObject(searchLineEdit, "globalSearch.lineEdit"); + searchLineEdit->installEventFilter(q); + helpLayer->addWidget(searchLineEdit); + } else if (!enabled && searchLineEdit) { + helpLayer->removeWidget(searchLineEdit); + delete searchLineEdit; + searchLineEdit = nullptr; + } +} + void KexiTabbedToolBar::activateSearchLineEdit() { + if (!d->searchLineEdit) { + return; + } d->searchLineEdit->selectAll(); d->searchLineEdit->setFocus(); } @@ -650,8 +672,8 @@ // help area QWidget *helpWidget = new QWidget(this); helpWidget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); - QHBoxLayout *helpLyr = new QHBoxLayout(helpWidget); - helpLyr->setContentsMargins(0, 0, 0, 0); + d->helpLayer = new QHBoxLayout(helpWidget); + d->helpLayer->setContentsMargins(0, 0, 0, 0); // * HELP MENU // add help menu actions... (KexiTabbedToolBar depends on them) @@ -709,13 +731,10 @@ } btn->setMinimumWidth(w); connect(action_show_help_menu, SIGNAL(triggered()), btn, SLOT(showMenu())); - helpLyr->addWidget(btn); + d->helpLayer->addWidget(btn); btn->setMenu(d->helpMenu->menu()); setCornerWidget(helpWidget, Qt::TopRightCorner); - d->searchLineEdit = new KexiSearchLineEdit; - kexiTester() << KexiTestObject(d->searchLineEdit, "globalSearch.lineEdit"); - d->searchLineEdit->installEventFilter(this); - helpLyr->addWidget(d->searchLineEdit); + d->initSearchLineEdit(); // needed e.g. for Windows style to remove the toolbar's frame QWidget *dummyWidgetForMainMenu = new QWidget(this); @@ -893,7 +912,7 @@ case QEvent::MouseButtonPress: { QWidget *mainWin = KexiMainWindowIface::global()->thisWidget(); // qDebug() << "MouseButtonPress: watched:" << watched << "window()->focusWidget():" << window()->focusWidget(); - if (watched == d->searchLineEdit) { + if (d->searchLineEdit && watched == d->searchLineEdit) { activateSearchLineEdit(); // custom setFocus() for search box, so it's possible to focus // back on Escape key press return false; @@ -1143,11 +1162,17 @@ void KexiTabbedToolBar::addSearchableModel(KexiSearchableModel *model) { + if (!d->searchLineEdit) { + return; + } d->searchLineEdit->addSearchableModel(model); } void KexiTabbedToolBar::removeSearchableModel(KexiSearchableModel *model) { + if (!d->searchLineEdit) { + return; + } d->searchLineEdit->removeSearchableModel(model); }