File indexing completed on 2024-05-12 04:58:09

0001 /* ============================================================
0002 * Falkon - Qt web browser
0003 * Copyright (C) 2013-2018 David Rosca <nowrep@gmail.com>
0004 *
0005 * This program is free software: you can redistribute it and/or modify
0006 * it under the terms of the GNU General Public License as published by
0007 * the Free Software Foundation, either version 3 of the License, or
0008 * (at your option) any later version.
0009 *
0010 * This program is distributed in the hope that it will be useful,
0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 * GNU General Public License for more details.
0014 *
0015 * You should have received a copy of the GNU General Public License
0016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017 * ============================================================ */
0018 #include "navigationcontainer.h"
0019 #include "qzsettings.h"
0020 #include "tabbar.h"
0021 
0022 #include <QPainter>
0023 #include <QVBoxLayout>
0024 
0025 NavigationContainer::NavigationContainer(QWidget* parent)
0026     : QWidget(parent)
0027     , m_tabBar(nullptr)
0028 {
0029     m_layout = new QVBoxLayout(this);
0030     m_layout->setContentsMargins(0, 0, 0, 0);
0031     m_layout->setSpacing(0);
0032     setLayout(m_layout);
0033 
0034     setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
0035 }
0036 
0037 void NavigationContainer::addWidget(QWidget* widget)
0038 {
0039     m_layout->addWidget(widget);
0040 }
0041 
0042 void NavigationContainer::setTabBar(TabBar* tabBar)
0043 {
0044     m_tabBar = tabBar;
0045     m_layout->addWidget(m_tabBar);
0046 
0047     toggleTabsOnTop(qzSettings->tabsOnTop);
0048 }
0049 
0050 void NavigationContainer::toggleTabsOnTop(bool enable)
0051 {
0052     setUpdatesEnabled(false);
0053 
0054     m_layout->removeWidget(m_tabBar);
0055     m_layout->insertWidget(enable ? 0 : m_layout->count(), m_tabBar);
0056     m_layout->setContentsMargins(0, enable ? 2 : 0, 0, enable ? 2 : 0);
0057 
0058     setUpdatesEnabled(true);
0059 }
0060 
0061 void NavigationContainer::paintEvent(QPaintEvent* event)
0062 {
0063     QWidget::paintEvent(event);
0064 
0065     // Draw line at the bottom of navigation bar if tabs are on top
0066     // To visually distinguish navigation bar from the page
0067 
0068     if (qzSettings->tabsOnTop) {
0069         QPainter p(this);
0070         QRect lineRect(0, height() - 1, width(), 1);
0071         QColor c = palette().window().color().darker(125);
0072         p.fillRect(lineRect, c);
0073     }
0074 }