Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonzqt/styleindexlineedit.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/gutil.h"
Toshihiro Shimizu 890ddd
#include "toonz/tpalettehandle.h"
Toshihiro Shimizu 890ddd
#include "tcolorstyles.h"
Toshihiro Shimizu 890ddd
#include "tpalette.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
shun-iwasawa c86c5d
StyleIndexLineEdit::StyleIndexLineEdit() : m_pltHandle(0) {
Shinya Kitaoka d1f6c4
  // style index will not be more than 4096, but a longer text
Shinya Kitaoka d1f6c4
  // "current" may be input instead of style id + chip width + margin
shun-iwasawa 443318
  int currentWidth = std::max(fontMetrics().horizontalAdvance("current"),
shun-iwasawa 443318
                              fontMetrics().horizontalAdvance(tr("current")));
shun-iwasawa e87e08
  setMaximumWidth(currentWidth + 30);
shun-iwasawa c86c5d
  setFixedHeight(20);
shun-iwasawa c86c5d
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
StyleIndexLineEdit::~StyleIndexLineEdit() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void StyleIndexLineEdit::paintEvent(QPaintEvent *pe) {
Shinya Kitaoka 120a6e
  QLineEdit::paintEvent(pe);
Shinya Kitaoka 120a6e
shun-iwasawa 102e06
  if (!m_pltHandle->getPalette()) return;
shun-iwasawa 102e06
Shinya Kitaoka 120a6e
  TColorStyle *style;
shun-iwasawa e87e08
  // Aware of both "current" and translated string
shun-iwasawa e87e08
  if (QString("current").contains(text()) || tr("current").contains(text()))
Shinya Kitaoka 120a6e
    style = m_pltHandle->getStyle();
Shinya Kitaoka 120a6e
  else {
Shinya Kitaoka 120a6e
    int index = text().toInt();
Shinya Kitaoka 120a6e
    style     = m_pltHandle->getPalette()->getStyle(index);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (style) {
Shinya Kitaoka 120a6e
    QPainter p(this);
Shinya Kitaoka 120a6e
    int w = width();
shun-iwasawa c86c5d
    QRect chipRect(w - 18, 3, 14, 14);
Shinya Kitaoka 120a6e
    TRaster32P icon = style->getIcon(qsize2Dimension(chipRect.size()));
Shinya Kitaoka 120a6e
    p.drawPixmap(chipRect.left(), chipRect.top(), rasterToQPixmap(icon));
Shinya Kitaoka 120a6e
    p.setPen(Qt::black);
Shinya Kitaoka 120a6e
    p.drawRect(chipRect);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}