1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +01:00

[BrowserWindow] Move TabBar into NavigationContainer

Simplifies entering/leaving fullscreen, as it is only needed to
update visibility of the whole container.
This commit is contained in:
nowrep 2014-03-30 16:38:34 +02:00
parent 6e71ae3c54
commit b95da97904
7 changed files with 60 additions and 54 deletions

View File

@ -301,7 +301,6 @@ void BrowserWindow::setupUi()
m_mainLayout->setSpacing(0);
m_mainSplitter = new QSplitter(this);
m_mainSplitter->setObjectName("sidebar-splitter");
m_mainSplitter->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
m_tabWidget = new TabWidget(this);
m_superMenu = new QMenu(this);
m_navigationToolbar = new NavigationBar(this);
@ -309,18 +308,16 @@ void BrowserWindow::setupUi()
m_bookmarksToolbar = new BookmarksToolbar(this);
m_navigationContainer = new NavigationContainer(this);
QVBoxLayout* l = new QVBoxLayout(m_navigationContainer);
l->setContentsMargins(0, 0, 0, 0);
l->setSpacing(0);
l->addWidget(m_navigationToolbar);
l->addWidget(m_bookmarksToolbar);
m_navigationContainer->setLayout(l);
m_navigationContainer->addWidget(m_navigationToolbar);
m_navigationContainer->addWidget(m_bookmarksToolbar);
m_navigationContainer->setTabBar(m_tabWidget->getTabBar());
m_mainSplitter->addWidget(m_tabWidget);
toggleTabsOnTop(qzSettings->tabsOnTop);
m_mainLayout->addWidget(m_mainSplitter);
m_mainSplitter->setCollapsible(0, false);
m_mainLayout->addWidget(m_navigationContainer);
m_mainLayout->addWidget(m_mainSplitter);
statusBar()->setObjectName("mainwindow-statusbar");
statusBar()->setCursor(Qt::ArrowCursor);
m_progressBar = new ProgressBar(statusBar());
@ -796,16 +793,8 @@ void BrowserWindow::toggleShowNavigationToolbar()
void BrowserWindow::toggleTabsOnTop(bool enable)
{
if (enable) {
m_mainLayout->insertWidget(0, m_tabWidget->getTabBar());
m_mainLayout->insertWidget(1, m_navigationContainer);
}
else {
m_mainLayout->insertWidget(0, m_navigationContainer);
m_mainLayout->insertWidget(1, m_tabWidget->getTabBar());
}
qzSettings->tabsOnTop = enable;
m_navigationContainer->toggleTabsOnTop(enable);
#ifdef Q_OS_WIN
// workaround for changing TabsOnTop state when sidebar is visible
@ -1081,7 +1070,6 @@ void BrowserWindow::showNavigationWithFullScreen()
}
m_navigationContainer->show();
m_tabWidget->getTabBar()->updateVisibilityWithFullscreen(true);
}
void BrowserWindow::hideNavigationWithFullScreen()
@ -1098,7 +1086,6 @@ void BrowserWindow::hideNavigationSlot()
if (isFullScreen() && mouseInView) {
m_navigationContainer->hide();
m_tabWidget->getTabBar()->updateVisibilityWithFullscreen(false);
}
}
@ -1116,10 +1103,9 @@ bool BrowserWindow::event(QEvent* event)
m_statusBarVisible = statusBar()->isVisible();
menuBar()->hide();
statusBar()->hide();
m_navigationContainer->hide();
m_tabWidget->getTabBar()->hide();
m_navigationToolbar->setSuperMenuVisible(false);
m_hideNavigationTimer->stop();
m_navigationToolbar->buttonExitFullscreen()->setVisible(true);
#ifdef Q_OS_WIN
if (m_useTransparentBackground) {
@ -1135,11 +1121,9 @@ bool BrowserWindow::event(QEvent* event)
menuBar()->setVisible(m_menuBarVisible);
statusBar()->setVisible(m_statusBarVisible);
m_navigationContainer->show();
m_tabWidget->getTabBar()->updateVisibilityWithFullscreen(true);
m_tabWidget->getTabBar()->setVisible(true);
m_navigationToolbar->setSuperMenuVisible(!m_menuBarVisible);
m_hideNavigationTimer->stop();
m_navigationToolbar->buttonExitFullscreen()->setVisible(false);
#ifdef Q_OS_WIN
if (m_useTransparentBackground) {
@ -1148,6 +1132,8 @@ bool BrowserWindow::event(QEvent* event)
}
#endif
}
m_hideNavigationTimer->stop();
break;
}
default:

View File

@ -50,6 +50,7 @@ class SideBarManager;
class ProgressBar;
class StatusBarMessage;
class NavigationBar;
class NavigationContainer;
class ClickableLabel;
class WebInspectorDockWidget;
class LocationBar;
@ -191,7 +192,7 @@ private:
SideBarManager* m_sideBarManager;
StatusBarMessage* m_statusBarMessage;
QWidget* m_navigationContainer;
NavigationContainer* m_navigationContainer;
NavigationBar* m_navigationToolbar;
BookmarksToolbar* m_bookmarksToolbar;
@ -210,7 +211,7 @@ private:
bool m_useTabNumberShortcuts;
bool m_useSpeedDialNumberShortcuts;
// Used for F11 FullScreen remember visibility of menubar and statusbar
// Remember visibility of menubar and statusbar after entering Fullscreen
bool m_menuBarVisible;
bool m_statusBarVisible;
Qt::WindowStates m_windowStates;

View File

@ -49,7 +49,8 @@ NavigationBar::NavigationBar(BrowserWindow* window)
: QWidget(window)
, m_window(window)
{
setObjectName("navigationbar");
setObjectName(QSL("navigationbar"));
m_layout = new QHBoxLayout(this);
m_layout->setMargin(style()->pixelMetric(QStyle::PM_ToolBarItemMargin, 0, this));
m_layout->setSpacing(style()->pixelMetric(QStyle::PM_ToolBarItemSpacing, 0, this));

View File

@ -17,12 +17,44 @@
* ============================================================ */
#include "navigationcontainer.h"
#include "qzsettings.h"
#include "tabbar.h"
#include <QPainter>
#include <QVBoxLayout>
NavigationContainer::NavigationContainer(QWidget* parent)
: QWidget(parent)
, m_tabBar(0)
{
m_layout = new QVBoxLayout(this);
m_layout->setContentsMargins(0, 0, 0, 0);
m_layout->setSpacing(0);
setLayout(m_layout);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
}
void NavigationContainer::addWidget(QWidget* widget)
{
m_layout->addWidget(widget);
}
void NavigationContainer::setTabBar(TabBar* tabBar)
{
m_tabBar = tabBar;
m_layout->addWidget(m_tabBar);
toggleTabsOnTop(qzSettings->tabsOnTop);
}
void NavigationContainer::toggleTabsOnTop(bool enable)
{
setUpdatesEnabled(false);
m_layout->removeWidget(m_tabBar);
m_layout->insertWidget(enable ? 0 : m_layout->count(), m_tabBar);
setUpdatesEnabled(true);
}
void NavigationContainer::paintEvent(QPaintEvent* event)

View File

@ -20,16 +20,27 @@
#include <QWidget>
#include "qzsettings.h"
#include "qzcommon.h"
class QVBoxLayout;
class TabBar;
class QUPZILLA_EXPORT NavigationContainer : public QWidget
{
public:
explicit NavigationContainer(QWidget* parent = 0);
void addWidget(QWidget* widget);
void setTabBar(TabBar* tabBar);
void toggleTabsOnTop(bool enable);
private:
void paintEvent(QPaintEvent* event);
QVBoxLayout* m_layout;
TabBar* m_tabBar;
};
#endif // NAVIGATIONCONTAINER_H

View File

@ -99,25 +99,6 @@ void TabBar::loadSettings()
setUpLayout();
}
void TabBar::updateVisibilityWithFullscreen(bool visible)
{
// It is needed to save original geometry, otherwise
// tabbar will get 3px height in fullscreen once it was hidden
ComboTabBar::setVisible(visible);
// Make sure to honor user preference
if (visible) {
visible = !(count() == 1 && m_hideTabBarWithOneTab);
}
if (visible) {
setGeometry(m_originalGeometry);
}
m_tabWidget->setUpLayout();
}
void TabBar::setVisible(bool visible)
{
if (visible && m_window->isFullScreen()) {
@ -129,10 +110,6 @@ void TabBar::setVisible(bool visible)
visible = !(count() == 1 && m_hideTabBarWithOneTab);
}
if (!visible) {
m_originalGeometry = geometry();
}
hideTabPreview(false);
ComboTabBar::setVisible(visible);
}

View File

@ -38,7 +38,6 @@ public:
void loadSettings();
void setVisible(bool visible);
void updateVisibilityWithFullscreen(bool visible);
void overrideTabTextColor(int index, QColor color);
void restoreTabTextColor(int index);
@ -116,7 +115,6 @@ private:
mutable int m_activeTabWidth;
QColor m_originalTabTextColor;
QRect m_originalGeometry;
QPoint m_dragStartPosition;
};