Enable customizing the save statistics time interval
[qBittorrent.git] / src / gui / properties / proptabbar.cpp
blobc7b1a43025ea5133250b48b56dc388d7322a1b58
1 /*
2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2010 Christophe Dumez <chris@qbittorrent.org>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * In addition, as a special exception, the copyright holders give permission to
20 * link this program with the OpenSSL project's "OpenSSL" library (or with
21 * modified versions of it that use the same license as the "OpenSSL" library),
22 * and distribute the linked executables. You must obey the GNU General Public
23 * License in all respects for all of the code used other than "OpenSSL". If you
24 * modify file(s), you may extend this exception to your version of the file(s),
25 * but you are not obligated to do so. If you do not wish to do so, delete this
26 * exception statement from your version.
29 #include "proptabbar.h"
31 #include <QButtonGroup>
32 #include <QKeySequence>
33 #include <QPushButton>
34 #include <QSpacerItem>
36 #include "base/global.h"
37 #include "gui/uithememanager.h"
39 PropTabBar::PropTabBar(QWidget *parent)
40 : QHBoxLayout(parent)
42 setAlignment(Qt::AlignLeft | Qt::AlignCenter);
43 setSpacing(3);
44 m_btnGroup = new QButtonGroup(this);
45 // General tab
46 QPushButton *mainInfosButton = new QPushButton(
47 #ifndef Q_OS_MACOS
48 UIThemeManager::instance()->getIcon(u"help-about"_s, u"document-properties"_s),
49 #endif
50 tr("General"), parent);
51 mainInfosButton->setShortcut(Qt::ALT | Qt::Key_G);
52 addWidget(mainInfosButton);
53 m_btnGroup->addButton(mainInfosButton, MainTab);
54 // Trackers tab
55 QPushButton *trackersButton = new QPushButton(
56 #ifndef Q_OS_MACOS
57 UIThemeManager::instance()->getIcon(u"trackers"_s, u"network-server"_s),
58 #endif
59 tr("Trackers"), parent);
60 trackersButton->setShortcut(Qt::ALT | Qt::Key_C);
61 addWidget(trackersButton);
62 m_btnGroup->addButton(trackersButton, TrackersTab);
63 // Peers tab
64 QPushButton *peersButton = new QPushButton(
65 #ifndef Q_OS_MACOS
66 UIThemeManager::instance()->getIcon(u"peers"_s),
67 #endif
68 tr("Peers"), parent);
69 peersButton->setShortcut(Qt::ALT | Qt::Key_R);
70 addWidget(peersButton);
71 m_btnGroup->addButton(peersButton, PeersTab);
72 // URL seeds tab
73 QPushButton *URLSeedsButton = new QPushButton(
74 #ifndef Q_OS_MACOS
75 UIThemeManager::instance()->getIcon(u"network-server"_s),
76 #endif
77 tr("HTTP Sources"), parent);
78 URLSeedsButton->setShortcut(Qt::ALT | Qt::Key_B);
79 addWidget(URLSeedsButton);
80 m_btnGroup->addButton(URLSeedsButton, URLSeedsTab);
81 // Files tab
82 QPushButton *filesButton = new QPushButton(
83 #ifndef Q_OS_MACOS
84 UIThemeManager::instance()->getIcon(u"directory"_s),
85 #endif
86 tr("Content"), parent);
87 filesButton->setShortcut(Qt::ALT | Qt::Key_Z);
88 addWidget(filesButton);
89 m_btnGroup->addButton(filesButton, FilesTab);
90 // Spacer
91 addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Fixed));
92 // Speed tab
93 QPushButton *speedButton = new QPushButton(
94 #ifndef Q_OS_MACOS
95 UIThemeManager::instance()->getIcon(u"chart-line"_s),
96 #endif
97 tr("Speed"), parent);
98 speedButton->setShortcut(Qt::ALT | Qt::Key_D);
99 addWidget(speedButton);
100 m_btnGroup->addButton(speedButton, SpeedTab);
101 // SIGNAL/SLOT
102 connect(m_btnGroup, &QButtonGroup::idClicked
103 , this, &PropTabBar::setCurrentIndex);
106 int PropTabBar::currentIndex() const
108 return m_currentIndex;
111 void PropTabBar::setCurrentIndex(int index)
113 if (index >= m_btnGroup->buttons().size())
114 index = 0;
115 // If asked to hide or if the currently selected tab is clicked
116 if ((index < 0) || (m_currentIndex == index))
118 if (m_currentIndex >= 0)
120 m_btnGroup->button(m_currentIndex)->setDown(false);
121 m_currentIndex = -1;
122 emit visibilityToggled(false);
124 return;
126 // Unselect previous tab
127 if (m_currentIndex >= 0)
129 m_btnGroup->button(m_currentIndex)->setDown(false);
131 else
133 // Nothing was selected, show!
134 emit visibilityToggled(true);
136 // Select the new button
137 m_btnGroup->button(index)->setDown(true);
138 m_currentIndex = index;
139 // Emit the signal
140 emit tabChanged(index);