KiwixApp::newTab()

It's more natural for the handling of the NewTabAction action to be
set up in `KiwixApp` rather than in `TabBar`.
This commit is contained in:
Veloman Yunkan 2024-03-12 17:45:04 +04:00
parent 837619cb55
commit bbceea3d5e
3 changed files with 14 additions and 10 deletions

View File

@ -82,7 +82,9 @@ void KiwixApp::init()
createActions();
mp_mainWindow = new MainWindow;
getTabWidget()->setContentManagerView(mp_manager->getView());
getTabWidget()->setNewTabButton(getAction(KiwixApp::NewTabAction));
const auto newTabAction = getAction(KiwixApp::NewTabAction);
getTabWidget()->setNewTabButton(newTabAction);
connect(newTabAction, &QAction::triggered, this, &KiwixApp::newTab);
postInit();
mp_errorDialog = new QErrorMessage(mp_mainWindow);
setActivationWindow(mp_mainWindow);
@ -128,6 +130,16 @@ KiwixApp::~KiwixApp()
}
}
void KiwixApp::newTab()
{
getTabWidget()->createNewTab(true, false);
auto& searchBar = mp_mainWindow->getTopWidget()->getSearchBar();
searchBar.setFocus(Qt::MouseFocusReason);
searchBar.clear();
searchBar.clearSuggestions();
searchBar.hideSuggestions();
}
QString KiwixApp::findLibraryDirectory()
{
// Check for library.xml in the same directory than the executable (portable kiwix-desktop)

View File

@ -89,6 +89,7 @@ public:
QString parseStyleFromFile(QString filePath);
public slots:
void newTab();
void openZimFile(const QString& zimfile="");
void openUrl(const QString& url, bool newTab=true);
void openUrl(const QUrl& url, bool newTab=true);

View File

@ -28,15 +28,6 @@ TabBar::TabBar(QWidget *parent) :
connect(app->getAction(KiwixApp::NextTabAction), &QAction::triggered, this, &TabBar::moveToNextTab);
connect(app->getAction(KiwixApp::PreviousTabAction), &QAction::triggered, this, &TabBar::moveToPreviousTab);
connect(app->getAction(KiwixApp::NewTabAction), &QAction::triggered,
this, [=]() {
this->createNewTab(true, false);
auto topWidget = KiwixApp::instance()->getMainWindow()->getTopWidget();
topWidget->getSearchBar().setFocus(Qt::MouseFocusReason);
topWidget->getSearchBar().clear();
topWidget->getSearchBar().clearSuggestions();
topWidget->getSearchBar().hideSuggestions();
});
connect(app->getAction(KiwixApp::CloseTabAction), &QAction::triggered,
this, [=]() {
this->closeTab(currentIndex());