xref: /glogg/src/tabbedcrawlerwidget.cpp (revision 333b2889af311485dd0cd8ea2e394af76455e71d)
1 /*
2  * Copyright (C) 2014 Nicolas Bonnefon and other contributors
3  *
4  * This file is part of glogg.
5  *
6  * glogg is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * glogg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with glogg.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include "tabbedcrawlerwidget.h"
21 
22 #include "log.h"
23 
24 TabbedCrawlerWidget::TabbedCrawlerWidget() : QTabWidget(), myTabBar_()
25 {
26 #if WIN32
27     myTabBar_.setStyleSheet( "QTabBar::tab {\
28             height: 20px; "
29             "}" );
30 #else
31     // On GTK style, it looks better with a smaller font
32     myTabBar_.setStyleSheet(
33             "QTabBar::tab {"
34             " height: 20px; "
35             " font-size: 9pt; "
36             "} "
37             "QTabBar::close-button {\
38             height: 6px; width: 6px; }" );
39 #endif
40     setTabBar( &myTabBar_ );
41     myTabBar_.hide();
42 }
43 
44 // I know hiding non-virtual functions from the base class is bad form
45 // and I do it here out of pure laziness: I don't want to encapsulate
46 // QTabBar with all signals and all just to implement this very simple logic.
47 // Maybe one day that should be done better...
48 
49 int TabbedCrawlerWidget::addTab( QWidget* page, const QString& label )
50 {
51     int index = QTabWidget::addTab( page, label );
52 
53     LOG(logDEBUG) << "addTab, count = " << count();
54 
55     if ( count() > 1 )
56         myTabBar_.show();
57 
58     return index;
59 }
60 
61 void TabbedCrawlerWidget::removeTab( int index )
62 {
63     QTabWidget::removeTab( index );
64 
65     if ( count() <= 1 )
66         myTabBar_.hide();
67 }
68