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
)
42 setAlignment(Qt::AlignLeft
| Qt::AlignCenter
);
44 m_btnGroup
= new QButtonGroup(this);
46 QPushButton
*mainInfosButton
= new QPushButton(
48 UIThemeManager::instance()->getIcon(u
"help-about"_s
, u
"document-properties"_s
),
50 tr("General"), parent
);
51 mainInfosButton
->setShortcut(Qt::ALT
| Qt::Key_G
);
52 addWidget(mainInfosButton
);
53 m_btnGroup
->addButton(mainInfosButton
, MainTab
);
55 QPushButton
*trackersButton
= new QPushButton(
57 UIThemeManager::instance()->getIcon(u
"trackers"_s
, u
"network-server"_s
),
59 tr("Trackers"), parent
);
60 trackersButton
->setShortcut(Qt::ALT
| Qt::Key_C
);
61 addWidget(trackersButton
);
62 m_btnGroup
->addButton(trackersButton
, TrackersTab
);
64 QPushButton
*peersButton
= new QPushButton(
66 UIThemeManager::instance()->getIcon(u
"peers"_s
),
69 peersButton
->setShortcut(Qt::ALT
| Qt::Key_R
);
70 addWidget(peersButton
);
71 m_btnGroup
->addButton(peersButton
, PeersTab
);
73 QPushButton
*URLSeedsButton
= new QPushButton(
75 UIThemeManager::instance()->getIcon(u
"network-server"_s
),
77 tr("HTTP Sources"), parent
);
78 URLSeedsButton
->setShortcut(Qt::ALT
| Qt::Key_B
);
79 addWidget(URLSeedsButton
);
80 m_btnGroup
->addButton(URLSeedsButton
, URLSeedsTab
);
82 QPushButton
*filesButton
= new QPushButton(
84 UIThemeManager::instance()->getIcon(u
"directory"_s
),
86 tr("Content"), parent
);
87 filesButton
->setShortcut(Qt::ALT
| Qt::Key_Z
);
88 addWidget(filesButton
);
89 m_btnGroup
->addButton(filesButton
, FilesTab
);
91 addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding
, QSizePolicy::Fixed
));
93 QPushButton
*speedButton
= new QPushButton(
95 UIThemeManager::instance()->getIcon(u
"chart-line"_s
),
98 speedButton
->setShortcut(Qt::ALT
| Qt::Key_D
);
99 addWidget(speedButton
);
100 m_btnGroup
->addButton(speedButton
, SpeedTab
);
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())
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);
122 emit
visibilityToggled(false);
126 // Unselect previous tab
127 if (m_currentIndex
>= 0)
129 m_btnGroup
->button(m_currentIndex
)->setDown(false);
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
;
140 emit
tabChanged(index
);