2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
|
|
#include "toonzqt/styleindexlineedit.h"
|
|
|
|
#include "toonzqt/gutil.h"
|
|
|
|
#include "toonz/tpalettehandle.h"
|
|
|
|
#include "tcolorstyles.h"
|
|
|
|
#include "tpalette.h"
|
|
|
|
|
|
|
|
#include <QPainter>
|
|
|
|
|
|
|
|
using namespace DVGui;
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
|
2016-06-27 18:22:54 +12:00
|
|
|
StyleIndexLineEdit::StyleIndexLineEdit() : m_pltHandle(0) {
|
2016-06-29 18:17:12 +12:00
|
|
|
// style index will not be more than 4096, but a longer text
|
|
|
|
// "current" may be input instead of style id + chip width + margin
|
2018-06-04 15:18:43 +12:00
|
|
|
int currentWidth = std::max(fontMetrics().width("current"),
|
|
|
|
fontMetrics().width(tr("current")));
|
|
|
|
setMaximumWidth(currentWidth + 30);
|
2016-06-27 18:22:54 +12:00
|
|
|
setFixedHeight(20);
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
StyleIndexLineEdit::~StyleIndexLineEdit() {}
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void StyleIndexLineEdit::paintEvent(QPaintEvent *pe) {
|
|
|
|
QLineEdit::paintEvent(pe);
|
|
|
|
|
2018-11-05 18:37:12 +13:00
|
|
|
if (!m_pltHandle->getPalette()) return;
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TColorStyle *style;
|
2018-06-04 15:18:43 +12:00
|
|
|
// Aware of both "current" and translated string
|
|
|
|
if (QString("current").contains(text()) || tr("current").contains(text()))
|
2016-06-15 18:43:10 +12:00
|
|
|
style = m_pltHandle->getStyle();
|
|
|
|
else {
|
|
|
|
int index = text().toInt();
|
|
|
|
style = m_pltHandle->getPalette()->getStyle(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (style) {
|
|
|
|
QPainter p(this);
|
|
|
|
int w = width();
|
2016-06-27 18:22:54 +12:00
|
|
|
QRect chipRect(w - 18, 3, 14, 14);
|
2016-06-15 18:43:10 +12:00
|
|
|
TRaster32P icon = style->getIcon(qsize2Dimension(chipRect.size()));
|
|
|
|
p.drawPixmap(chipRect.left(), chipRect.top(), rasterToQPixmap(icon));
|
|
|
|
p.setPen(Qt::black);
|
|
|
|
p.drawRect(chipRect);
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|