Skip to content

Commit

Permalink
feat(browser,sidebar,ui): implement real tabs (zealdocs#1081)
Browse files Browse the repository at this point in the history
Adds actual independent tabs instead of swapping sidebar and webview.
  • Loading branch information
trollixx authored Mar 25, 2019
1 parent b106938 commit 0b45d6e
Show file tree
Hide file tree
Showing 26 changed files with 1,439 additions and 628 deletions.
1 change: 1 addition & 0 deletions src/libs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
add_subdirectory(browser)
add_subdirectory(core)
add_subdirectory(registry)
add_subdirectory(sidebar)
add_subdirectory(ui)
add_subdirectory(util)
3 changes: 2 additions & 1 deletion src/libs/browser/webview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <core/application.h>
#include <core/settings.h>
#include <ui/browsertab.h>
#include <ui/mainwindow.h>

#include <QCheckBox>
Expand Down Expand Up @@ -101,7 +102,7 @@ void WebView::resetZoom()
QWebView *WebView::createWindow(QWebPage::WebWindowType type)
{
Q_UNUSED(type)
return Core::Application::instance()->mainWindow()->createTab()->m_webView;
return Core::Application::instance()->mainWindow()->createTab()->webControl()->m_webView;
}

void WebView::contextMenuEvent(QContextMenuEvent *event)
Expand Down
11 changes: 11 additions & 0 deletions src/libs/sidebar/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
add_library(Sidebar
container.cpp
proxyview.cpp
view.cpp
viewprovider.cpp
)

target_link_libraries(Sidebar)

find_package(Qt5 COMPONENTS Widgets REQUIRED)
target_link_libraries(Sidebar Qt5::Widgets)
70 changes: 70 additions & 0 deletions src/libs/sidebar/container.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/****************************************************************************
**
** Copyright (C) 2019 Oleg Shparber
** Contact: https://go.zealdocs.org/l/contact
**
** This file is part of Zeal.
**
** Zeal is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Zeal is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Zeal. If not, see <https://www.gnu.org/licenses/>.
**
****************************************************************************/

#include "container.h"

#include "view.h"

#include <core/application.h>
#include <core/settings.h>
#include <ui/widgets/layouthelper.h>

#include <QLabel>
#include <QSplitter>
#include <QVBoxLayout>

#include <type_traits>

using namespace Zeal;
using namespace Zeal::Sidebar;

Container::Container(QWidget *parent)
: QWidget(parent)
{
setMinimumWidth(150);

// Setup splitter.
m_splitter = new QSplitter();
m_splitter->setOrientation(Qt::Vertical);
connect(m_splitter, &QSplitter::splitterMoved, this, [this]() {
Core::Application::instance()->settings()->tocSplitterState = m_splitter->saveState();
});

// Setup main layout.
auto layout = WidgetUi::LayoutHelper::createBorderlessLayout<QVBoxLayout>();
layout->addWidget(m_splitter);
setLayout(layout);
}

Container::~Container()
{

}

void Container::addView(View *view)
{
if (m_views.contains(view))
return;

m_views.append(view);
m_splitter->addWidget(view);
}
60 changes: 60 additions & 0 deletions src/libs/sidebar/container.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/****************************************************************************
**
** Copyright (C) 2019 Oleg Shparber
** Contact: https://go.zealdocs.org/l/contact
**
** This file is part of Zeal.
**
** Zeal is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Zeal is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Zeal. If not, see <https://www.gnu.org/licenses/>.
**
****************************************************************************/

#ifndef ZEAL_SIDEBAR_CONTAINER_H
#define ZEAL_SIDEBAR_CONTAINER_H

#include <QWidget>

class QSplitter;

namespace Zeal {
namespace Sidebar {

class View;

// TODO: Implement view groups (alt. naming: tabs, pages) (move splitter into a group?).
class Container : public QWidget
{
Q_OBJECT
public:
explicit Container(QWidget *parent = nullptr);
~Container() override;

void addView(View *view);

public slots:

signals:

private:
Q_DISABLE_COPY(Container)

QSplitter *m_splitter = nullptr;

QList<View *> m_views;
};

} // namespace Sidebar
} // namespace Zeal

#endif // ZEAL_SIDEBAR_CONTAINER_H
73 changes: 73 additions & 0 deletions src/libs/sidebar/proxyview.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/****************************************************************************
**
** Copyright (C) 2019 Oleg Shparber
** Contact: https://go.zealdocs.org/l/contact
**
** This file is part of Zeal.
**
** Zeal is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Zeal is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Zeal. If not, see <https://www.gnu.org/licenses/>.
**
****************************************************************************/

#include "proxyview.h"

#include "viewprovider.h"

#include <ui/widgets/layouthelper.h>

#include <QVBoxLayout>

using namespace Zeal;
using namespace Zeal::Sidebar;

ProxyView::ProxyView(ViewProvider *provider, const QString &id, QWidget *parent)
: View(parent)
, m_viewProvider(provider)
, m_viewId(id)
{
setLayout(WidgetUi::LayoutHelper::createBorderlessLayout<QVBoxLayout>());

connect(m_viewProvider, &ViewProvider::viewChanged, this, [this]() {
auto view = m_viewProvider->view(m_viewId);
if (view == nullptr) {
qWarning("ViewProvider returned invalid view!");
return;
}

if (m_view == view)
return;

clearCurrentView();
layout()->addWidget(view);
view->show();
m_view = view;
});
}

ProxyView::~ProxyView()
{
clearCurrentView();
}

void ProxyView::clearCurrentView()
{
// Unparent the view, because we don't own it.
QLayout *l = layout();
if (l->isEmpty())
return;

m_view->hide();
l->removeWidget(m_view);
m_view->setParent(nullptr);
}
54 changes: 54 additions & 0 deletions src/libs/sidebar/proxyview.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/****************************************************************************
**
** Copyright (C) 2019 Oleg Shparber
** Contact: https://go.zealdocs.org/l/contact
**
** This file is part of Zeal.
**
** Zeal is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Zeal is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Zeal. If not, see <https://www.gnu.org/licenses/>.
**
****************************************************************************/

#ifndef ZEAL_SIDEBAR_PROXYVIEW_H
#define ZEAL_SIDEBAR_PROXYVIEW_H

#include "view.h"

namespace Zeal {
namespace Sidebar {

class ViewProvider;

class ProxyView final : public View
{
Q_OBJECT
public:
explicit ProxyView(ViewProvider *provider, const QString &id = QString(), QWidget *parent = nullptr);
~ProxyView() override;

private:
Q_DISABLE_COPY(ProxyView)

void clearCurrentView();

ViewProvider *m_viewProvider = nullptr;
QString m_viewId;

View *m_view = nullptr;
};

} // namespace Sidebar
} // namespace Zeal

#endif // ZEAL_SIDEBAR_PROXYVIEW_H
30 changes: 30 additions & 0 deletions src/libs/sidebar/view.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/****************************************************************************
**
** Copyright (C) 2019 Oleg Shparber
** Contact: https://go.zealdocs.org/l/contact
**
** This file is part of Zeal.
**
** Zeal is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Zeal is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Zeal. If not, see <https://www.gnu.org/licenses/>.
**
****************************************************************************/

#include "view.h"

using namespace Zeal::Sidebar;

View::View(QWidget *parent)
: QWidget(parent)
{
}
44 changes: 44 additions & 0 deletions src/libs/sidebar/view.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/****************************************************************************
**
** Copyright (C) 2019 Oleg Shparber
** Contact: https://go.zealdocs.org/l/contact
**
** This file is part of Zeal.
**
** Zeal is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Zeal is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Zeal. If not, see <https://www.gnu.org/licenses/>.
**
****************************************************************************/

#ifndef ZEAL_SIDEBAR_VIEW_H
#define ZEAL_SIDEBAR_VIEW_H

#include <QWidget>

namespace Zeal {
namespace Sidebar {

class View : public QWidget
{
Q_OBJECT
public:
explicit View(QWidget *parent = nullptr);

private:
Q_DISABLE_COPY(View)
};

} // namespace Sidebar
} // namespace Zeal

#endif // ZEAL_SIDEBAR_VIEW_H
Loading

0 comments on commit 0b45d6e

Please sign in to comment.