Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonzqt/tabbar.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/dvdialog.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <qpainter></qpainter>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace DVGui;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// TabBar
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TabBar::TabBar(QWidget *parent) : QTabBar(parent) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TabBar::~TabBar() { m_pixmaps.clear(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TabBar::paintEvent(QPaintEvent *event) {
Shinya Kitaoka 120a6e
  QTabBar::paintEvent(event);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QPainter p(this);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Paint tab Icons
Shinya Kitaoka 120a6e
  int tabCount      = count();
Shinya Kitaoka 120a6e
  int selectedIndex = currentIndex();
Shinya Kitaoka 120a6e
  for (int i = 0; i < tabCount; i++) {
Shinya Kitaoka 120a6e
    QRect tabRectangle = tabRect(i).adjusted(2, 1, -4, 0);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (selectedIndex == i) {
Shinya Kitaoka 120a6e
      tabRectangle = tabRectangle.adjusted(0, -2, 0, 0);
Shinya Kitaoka 120a6e
      if (!m_pixmaps[(i * 2) + 1]) continue;
Shinya Kitaoka 120a6e
      p.drawPixmap(tabRectangle.x(), tabRectangle.y(), m_pixmaps[(i * 2) + 1]);
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      if (!m_pixmaps[(i * 2)]) continue;
Shinya Kitaoka 120a6e
      p.drawPixmap(tabRectangle.x(), tabRectangle.y(), m_pixmaps[(i * 2)]);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TabBar::addIconTab(const char *iconPrefixName, const QString &tooltip) {
Shinya Kitaoka 120a6e
  QString normal = QString(":Resources/") + iconPrefixName + "_off.svg";
Shinya Kitaoka 120a6e
  QString over   = QString(":Resources/") + iconPrefixName + "_on.svg";
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int indexTab = addTab("");
Shinya Kitaoka 120a6e
  setTabToolTip(indexTab, tooltip);
Shinya Kitaoka 120a6e
  m_pixmaps.push_back(QPixmap(normal));
Shinya Kitaoka 120a6e
  m_pixmaps.push_back(QPixmap(over));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TabBar::addSimpleTab(const QString &text) {
Shinya Kitaoka 120a6e
  addTab(text);
Shinya Kitaoka 120a6e
  m_pixmaps.push_back(QPixmap(""));
Shinya Kitaoka 120a6e
  m_pixmaps.push_back(QPixmap(""));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TabBar::clearTabBar() {
Shinya Kitaoka 120a6e
  int i, n = count();
Shinya Kitaoka 120a6e
  for (i = 0; i < n; i++) removeTab(0);
Shinya Kitaoka 120a6e
  if (!m_pixmaps.empty()) m_pixmaps.clear();
Toshihiro Shimizu 890ddd
}