File indexing completed on 2024-05-12 05:54:36

0001 /*
0002     SPDX-FileCopyrightText: 2020-2022 Krusader Krew <https://krusader.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "viewertabbar.h"
0008 
0009 // QtGui
0010 #include <QMouseEvent>
0011 
0012 #include <KConfigCore/KSharedConfig>
0013 
0014 #include "../defaults.h"
0015 #include "../krglobal.h"
0016 
0017 ViewerTabWidget::ViewerTabWidget(QWidget *parent)
0018     : QTabWidget(parent)
0019 {
0020     setTabBar(new ViewerTabBar(this));
0021 }
0022 
0023 void ViewerTabWidget::adjustViewerTabBarVisibility()
0024 {
0025     if (count() > 1) {
0026         tabBar()->show();
0027     } else if (count() == 1) {
0028         KConfigGroup group(krConfig, "General");
0029         bool hideSingleTab = group.readEntry("Viewer Hide Single Tab", _ViewerHideSingleTab);
0030         if (hideSingleTab)
0031             tabBar()->hide();
0032     }
0033     return;
0034 }
0035 
0036 ViewerTabBar *ViewerTabWidget::tabBar() const
0037 {
0038     return dynamic_cast<ViewerTabBar *>(QTabWidget::tabBar());
0039 }
0040 
0041 void ViewerTabBar::mousePressEvent(QMouseEvent *e)
0042 {
0043     int clickedTab = tabAt(e->pos());
0044 
0045     if (-1 == clickedTab) { // clicked on nothing ...
0046         QTabBar::mousePressEvent(e);
0047         return;
0048     }
0049 
0050     setCurrentIndex(clickedTab);
0051 
0052     if (e->button() == Qt::MidButton) {
0053         // close the current tab
0054         emit closeTabSignal(clickedTab);
0055     }
0056 
0057     QTabBar::mousePressEvent(e);
0058 }