Пример #1
0
StatusBar::StatusBar(QStatusBar *bar)
    : m_bar(bar)
{
    qApp->setStyleSheet("QStatusBar::item { border-width: 0; }");

    BitTorrent::Session *const session = BitTorrent::Session::instance();
    connect(session, SIGNAL(speedLimitModeChanged(bool)), this, SLOT(updateAltSpeedsBtn(bool)));
    m_container = new QWidget(bar);
    m_layout = new QHBoxLayout(m_container);
    m_layout->setContentsMargins(0,0,0,0);

    m_container->setLayout(m_layout);
    m_connecStatusLblIcon = new QPushButton(bar);
    m_connecStatusLblIcon->setFlat(true);
    m_connecStatusLblIcon->setFocusPolicy(Qt::NoFocus);
    m_connecStatusLblIcon->setCursor(Qt::PointingHandCursor);
    m_connecStatusLblIcon->setIcon(QIcon(":/icons/skin/firewalled.png"));
    m_connecStatusLblIcon->setToolTip(QString::fromUtf8("<b>") + tr("Connection status:") + QString::fromUtf8("</b><br>") + QString::fromUtf8("<i>") + tr("No direct connections. This may indicate network configuration problems.") + QString::fromUtf8("</i>"));

    m_dlSpeedLbl = new QPushButton(bar);
    m_dlSpeedLbl->setIcon(QIcon(":/icons/skin/download.png"));
    connect(m_dlSpeedLbl, SIGNAL(clicked()), this, SLOT(capDownloadSpeed()));
    m_dlSpeedLbl->setFlat(true);
    m_dlSpeedLbl->setFocusPolicy(Qt::NoFocus);
    m_dlSpeedLbl->setCursor(Qt::PointingHandCursor);
    m_dlSpeedLbl->setStyleSheet("text-align:left;");
    m_dlSpeedLbl->setMinimumWidth(200);

    m_upSpeedLbl = new QPushButton(bar);
    m_upSpeedLbl->setIcon(QIcon(":/icons/skin/seeding.png"));
    connect(m_upSpeedLbl, SIGNAL(clicked()), this, SLOT(capUploadSpeed()));
    m_upSpeedLbl->setFlat(true);
    m_upSpeedLbl->setFocusPolicy(Qt::NoFocus);
    m_upSpeedLbl->setCursor(Qt::PointingHandCursor);
    m_upSpeedLbl->setStyleSheet("text-align:left;");
    m_upSpeedLbl->setMinimumWidth(200);

    m_DHTLbl = new QLabel(tr("DHT: %1 nodes").arg(0), bar);
    m_DHTLbl->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);

    m_altSpeedsBtn = new QPushButton(bar);
    m_altSpeedsBtn->setFlat(true);
    m_altSpeedsBtn->setFocusPolicy(Qt::NoFocus);
    m_altSpeedsBtn->setCursor(Qt::PointingHandCursor);
    updateAltSpeedsBtn(session->isAltGlobalSpeedLimitEnabled());
    connect(m_altSpeedsBtn, SIGNAL(clicked()), this, SLOT(toggleAlternativeSpeeds()));

    // Because on some platforms the default icon size is bigger
    // and it will result in taller/fatter statusbar, even if the
    // icons are actually 16x16
    m_connecStatusLblIcon->setIconSize(QSize(16, 16));
    m_dlSpeedLbl->setIconSize(QSize(16, 16));
    m_upSpeedLbl->setIconSize(QSize(16, 16));
    m_altSpeedsBtn->setIconSize(QSize(28, 16));

    // Set to the known maximum width(plus some padding)
    // so the speed widgets will take the rest of the space
    m_connecStatusLblIcon->setMaximumWidth(16 + 6);
    m_altSpeedsBtn->setMaximumWidth(28 + 6);

    m_statusSep1 = new QFrame(bar);
    m_statusSep1->setFrameStyle(QFrame::VLine);
    m_statusSep1->setFrameShadow(QFrame::Raised);
    m_statusSep2 = new QFrame(bar);
    m_statusSep2->setFrameStyle(QFrame::VLine);
    m_statusSep2->setFrameShadow(QFrame::Raised);
    m_statusSep3 = new QFrame(bar);
    m_statusSep3->setFrameStyle(QFrame::VLine);
    m_statusSep3->setFrameShadow(QFrame::Raised);
    m_statusSep4 = new QFrame(bar);
    m_statusSep4->setFrameStyle(QFrame::VLine);
    m_statusSep4->setFrameShadow(QFrame::Raised);
    m_layout->addWidget(m_DHTLbl);
    m_layout->addWidget(m_statusSep1);
    m_layout->addWidget(m_connecStatusLblIcon);
    m_layout->addWidget(m_statusSep2);
    m_layout->addWidget(m_altSpeedsBtn);
    m_layout->addWidget(m_statusSep4);
    m_layout->addWidget(m_dlSpeedLbl);
    m_layout->addWidget(m_statusSep3);
    m_layout->addWidget(m_upSpeedLbl);

    bar->addPermanentWidget(m_container);
    bar->setStyleSheet("QWidget {margin: 0;}");
    m_container->adjustSize();
    bar->adjustSize();
    // Is DHT enabled
    m_DHTLbl->setVisible(session->isDHTEnabled());
    m_refreshTimer = new QTimer(bar);
    refreshStatusBar();
    connect(m_refreshTimer, SIGNAL(timeout()), this, SLOT(refreshStatusBar()));
    m_refreshTimer->start(1500);
}
Пример #2
0
StatusBar::StatusBar(QStatusBar *bar)
  : m_bar(bar)
{
  Preferences* const pref = Preferences::instance();
  connect(QBtSession::instance(), SIGNAL(alternativeSpeedsModeChanged(bool)), this, SLOT(updateAltSpeedsBtn(bool)));
  container = new QWidget(bar);
  layout = new QHBoxLayout(container);
  layout->setContentsMargins(0,0,0,0);

  container->setLayout(layout);
  connecStatusLblIcon = new QPushButton(bar);
  connecStatusLblIcon->setFlat(true);
  connecStatusLblIcon->setFocusPolicy(Qt::NoFocus);
  connecStatusLblIcon->setFixedWidth(32);
  connecStatusLblIcon->setCursor(Qt::PointingHandCursor);
  connecStatusLblIcon->setIcon(QIcon(":/Icons/skin/firewalled.png"));
  connecStatusLblIcon->setToolTip(QString::fromUtf8("<b>")+tr("Connection status:")+QString::fromUtf8("</b><br>")+QString::fromUtf8("<i>")+tr("No direct connections. This may indicate network configuration problems.")+QString::fromUtf8("</i>"));
  dlSpeedLbl = new QPushButton(bar);
  dlSpeedLbl->setIconSize(QSize(16,16));
  dlSpeedLbl->setIcon(QIcon(":/Icons/skin/download.png"));
  //dlSpeedLbl->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
  connect(dlSpeedLbl, SIGNAL(clicked()), this, SLOT(capDownloadSpeed()));
  dlSpeedLbl->setFlat(true);
  dlSpeedLbl->setFocusPolicy(Qt::NoFocus);
  dlSpeedLbl->setCursor(Qt::PointingHandCursor);

  altSpeedsBtn = new QPushButton(bar);
  altSpeedsBtn->setFixedWidth(36);
  altSpeedsBtn->setIconSize(QSize(32,32));
  altSpeedsBtn->setFlat(true);
  altSpeedsBtn->setFocusPolicy(Qt::NoFocus);
  altSpeedsBtn->setCursor(Qt::PointingHandCursor);
  updateAltSpeedsBtn(pref->isAltBandwidthEnabled());

  connect(altSpeedsBtn, SIGNAL(clicked()), this, SLOT(toggleAlternativeSpeeds()));

  upSpeedLbl = new QPushButton(bar);
  upSpeedLbl->setIconSize(QSize(16,16));
  upSpeedLbl->setIcon(QIcon(":/Icons/skin/seeding.png"));
  //upSpeedLbl->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
  connect(upSpeedLbl, SIGNAL(clicked()), this, SLOT(capUploadSpeed()));
  upSpeedLbl->setFlat(true);
  upSpeedLbl->setFocusPolicy(Qt::NoFocus);
  upSpeedLbl->setCursor(Qt::PointingHandCursor);
  DHTLbl = new QLabel(tr("DHT: %1 nodes").arg(0), bar);
  DHTLbl->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
  statusSep1 = new QFrame(bar);
  statusSep1->setFixedSize(3, dlSpeedLbl->fontMetrics().height());
  statusSep1->setFrameStyle(QFrame::VLine);
  statusSep1->setFrameShadow(QFrame::Raised);
  statusSep2 = new QFrame(bar);
  statusSep2->setFixedSize(3, dlSpeedLbl->fontMetrics().height());
  statusSep2->setFrameStyle(QFrame::VLine);
  statusSep2->setFrameShadow(QFrame::Raised);
  statusSep3 = new QFrame(bar);
  statusSep3->setFixedSize(3, dlSpeedLbl->fontMetrics().height());
  statusSep3->setFrameStyle(QFrame::VLine);
  statusSep3->setFrameShadow(QFrame::Raised);
  statusSep4 = new QFrame(bar);
  statusSep4->setFixedSize(3, dlSpeedLbl->fontMetrics().height());
  statusSep4->setFrameStyle(QFrame::VLine);
  statusSep4->setFrameShadow(QFrame::Raised);
  layout->addWidget(DHTLbl);
  layout->addWidget(statusSep1);
  layout->addWidget(connecStatusLblIcon);
  layout->addWidget(statusSep2);
  layout->addWidget(altSpeedsBtn);
  layout->addWidget(statusSep4);
  layout->addWidget(dlSpeedLbl);
  layout->addWidget(statusSep3);
  layout->addWidget(upSpeedLbl);

  bar->addPermanentWidget(container);
  container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
  //bar->setStyleSheet("QWidget {padding-top: 0; padding-bottom: 0; margin-top: 0; margin-bottom: 0;}\n");
  container->setContentsMargins(0, 0, 0, 1);
  bar->setContentsMargins(0, 0, 0, 0);
  container->setFixedHeight(dlSpeedLbl->fontMetrics().height()+7);
  bar->setFixedHeight(dlSpeedLbl->fontMetrics().height()+9);
  // Is DHT enabled
  DHTLbl->setVisible(pref->isDHTEnabled());
  refreshTimer = new QTimer(bar);
  refreshStatusBar();
  connect(refreshTimer, SIGNAL(timeout()), this, SLOT(refreshStatusBar()));
  refreshTimer->start(1500);
}