qBittorrent
PropTabBar Class Reference

#include <proptabbar.h>

Inheritance diagram for PropTabBar:
Collaboration diagram for PropTabBar:

Public Types

enum  PropertyTab {
  MainTab , TrackersTab , PeersTab , URLSeedsTab ,
  FilesTab , SpeedTab
}
 

Public Slots

void setCurrentIndex (int index)
 

Signals

void tabChanged (int index)
 
void visibilityToggled (bool visible)
 

Public Member Functions

 PropTabBar (QWidget *parent=nullptr)
 
int currentIndex () const
 

Private Attributes

QButtonGroup * m_btnGroup
 
int m_currentIndex
 

Detailed Description

Definition at line 35 of file proptabbar.h.

Member Enumeration Documentation

◆ PropertyTab

Enumerator
MainTab 
TrackersTab 
PeersTab 
URLSeedsTab 
FilesTab 
SpeedTab 

Definition at line 41 of file proptabbar.h.

42  {
43  MainTab,
45  PeersTab,
47  FilesTab,
48  SpeedTab
49  };

Constructor & Destructor Documentation

◆ PropTabBar()

PropTabBar::PropTabBar ( QWidget *  parent = nullptr)
explicit

Definition at line 39 of file proptabbar.cpp.

40  : QHBoxLayout(parent)
41  , m_currentIndex(-1)
42 {
43  setAlignment(Qt::AlignLeft | Qt::AlignCenter);
44  setSpacing(3);
45  m_btnGroup = new QButtonGroup(this);
46  // General tab
47  QPushButton *mainInfosButton = new QPushButton(
48 #ifndef Q_OS_MACOS
49  UIThemeManager::instance()->getIcon("document-properties"),
50 #endif
51  tr("General"), parent);
52  mainInfosButton->setShortcut(Qt::ALT + Qt::Key_G);
53  addWidget(mainInfosButton);
54  m_btnGroup->addButton(mainInfosButton, MainTab);
55  // Trackers tab
56  QPushButton *trackersButton = new QPushButton(
57 #ifndef Q_OS_MACOS
58  UIThemeManager::instance()->getIcon("network-server"),
59 #endif
60  tr("Trackers"), parent);
61  trackersButton->setShortcut(Qt::ALT + Qt::Key_C);
62  addWidget(trackersButton);
63  m_btnGroup->addButton(trackersButton, TrackersTab);
64  // Peers tab
65  QPushButton *peersButton = new QPushButton(
66 #ifndef Q_OS_MACOS
67  UIThemeManager::instance()->getIcon("edit-find-user"),
68 #endif
69  tr("Peers"), parent);
70  peersButton->setShortcut(Qt::ALT + Qt::Key_R);
71  addWidget(peersButton);
72  m_btnGroup->addButton(peersButton, PeersTab);
73  // URL seeds tab
74  QPushButton *URLSeedsButton = new QPushButton(
75 #ifndef Q_OS_MACOS
76  UIThemeManager::instance()->getIcon("network-server"),
77 #endif
78  tr("HTTP Sources"), parent);
79  URLSeedsButton->setShortcut(Qt::ALT + Qt::Key_B);
80  addWidget(URLSeedsButton);
81  m_btnGroup->addButton(URLSeedsButton, URLSeedsTab);
82  // Files tab
83  QPushButton *filesButton = new QPushButton(
84 #ifndef Q_OS_MACOS
85  UIThemeManager::instance()->getIcon("inode-directory"),
86 #endif
87  tr("Content"), parent);
88  filesButton->setShortcut(Qt::ALT + Qt::Key_Z);
89  addWidget(filesButton);
90  m_btnGroup->addButton(filesButton, FilesTab);
91  // Spacer
92  addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Fixed));
93  // Speed tab
94  QPushButton *speedButton = new QPushButton(
95 #ifndef Q_OS_MACOS
96  UIThemeManager::instance()->getIcon("office-chart-line"),
97 #endif
98  tr("Speed"), parent);
99  speedButton->setShortcut(Qt::ALT + Qt::Key_D);
100  addWidget(speedButton);
101  m_btnGroup->addButton(speedButton, SpeedTab);
102  // SIGNAL/SLOT
103  connect(m_btnGroup, &QButtonGroup::idClicked
104  , this, &PropTabBar::setCurrentIndex);
105  // Disable buttons focus
106  for (QAbstractButton *btn : asConst(m_btnGroup->buttons()))
107  btn->setFocusPolicy(Qt::NoFocus);
108 }
QButtonGroup * m_btnGroup
Definition: proptabbar.h:63
void setCurrentIndex(int index)
Definition: proptabbar.cpp:115
int m_currentIndex
Definition: proptabbar.h:64
static UIThemeManager * instance()
constexpr std::add_const_t< T > & asConst(T &t) noexcept
Definition: global.h:42

References asConst(), FilesTab, UIThemeManager::instance(), m_btnGroup, MainTab, PeersTab, setCurrentIndex(), SpeedTab, TrackersTab, and URLSeedsTab.

Here is the call graph for this function:

Member Function Documentation

◆ currentIndex()

int PropTabBar::currentIndex ( ) const

Definition at line 110 of file proptabbar.cpp.

111 {
112  return m_currentIndex;
113 }

References m_currentIndex.

Referenced by PropertiesWidget::saveSettings().

Here is the caller graph for this function:

◆ setCurrentIndex

void PropTabBar::setCurrentIndex ( int  index)
slot

Definition at line 115 of file proptabbar.cpp.

116 {
117  if (index >= m_btnGroup->buttons().size())
118  index = 0;
119  // If asked to hide or if the currently selected tab is clicked
120  if ((index < 0) || (m_currentIndex == index))
121  {
122  if (m_currentIndex >= 0)
123  {
124  m_btnGroup->button(m_currentIndex)->setDown(false);
125  m_currentIndex = -1;
126  emit visibilityToggled(false);
127  }
128  return;
129  }
130  // Unselect previous tab
131  if (m_currentIndex >= 0)
132  {
133  m_btnGroup->button(m_currentIndex)->setDown(false);
134  }
135  else
136  {
137  // Nothing was selected, show!
138  emit visibilityToggled(true);
139  }
140  // Select the new button
141  m_btnGroup->button(index)->setDown(true);
142  m_currentIndex = index;
143  // Emit the signal
144  emit tabChanged(index);
145 }
void tabChanged(int index)
void visibilityToggled(bool visible)

References m_btnGroup, m_currentIndex, tabChanged(), and visibilityToggled().

Referenced by PropTabBar(), and PropertiesWidget::readSettings().

Here is the caller graph for this function:

◆ tabChanged

void PropTabBar::tabChanged ( int  index)
signal

Referenced by PropertiesWidget::PropertiesWidget(), and setCurrentIndex().

Here is the caller graph for this function:

◆ visibilityToggled

void PropTabBar::visibilityToggled ( bool  visible)
signal

Referenced by PropertiesWidget::PropertiesWidget(), and setCurrentIndex().

Here is the caller graph for this function:

Member Data Documentation

◆ m_btnGroup

QButtonGroup* PropTabBar::m_btnGroup
private

Definition at line 63 of file proptabbar.h.

Referenced by PropTabBar(), and setCurrentIndex().

◆ m_currentIndex

int PropTabBar::m_currentIndex
private

Definition at line 64 of file proptabbar.h.

Referenced by currentIndex(), and setCurrentIndex().


The documentation for this class was generated from the following files: